|
FAUST compiler
0.9.9.6b8
|
00001 /************************************************************************ 00002 ************************************************************************ 00003 FAUST compiler 00004 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale 00005 --------------------------------------------------------------------- 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 ************************************************************************ 00020 ************************************************************************/ 00021 00022 00023 #include "blockSchema.h" 00024 #include <assert.h> 00025 00026 using namespace std; 00027 00028 static double quantize(int n) 00029 { 00030 int q = 3; 00031 return dLetter * (q *((n+q-1)/q)); 00032 } 00033 00040 schema* makeBlockSchema ( unsigned int inputs, 00041 unsigned int outputs, 00042 const string& text, 00043 const string& color, 00044 const string& link ) 00045 { 00046 // determine the optimal size of the box 00047 double minimal = 3*dWire; 00048 double w = 2*dHorz + max( minimal, quantize(text.size()) ); 00049 double h = 2*dVert + max( minimal, max(inputs, outputs) * dWire ); 00050 00051 return new blockSchema(inputs, outputs, w, h, text, color, link); 00052 } 00053 00060 blockSchema::blockSchema ( unsigned int inputs, 00061 unsigned int outputs, 00062 double width, 00063 double height, 00064 const string& text, 00065 const string& color, 00066 const string& link ) 00067 00068 : schema( inputs, outputs, width, height ), 00069 fText(text), 00070 fColor(color), 00071 fLink(link) 00072 { 00073 for (unsigned int i=0; i<inputs; i++) fInputPoint.push_back(point(0,0)); 00074 for (unsigned int i=0; i<outputs; i++) fOutputPoint.push_back(point(0,0)); 00075 } 00076 00082 void blockSchema::place(double x, double y, int orientation) 00083 { 00084 beginPlace(x, y, orientation); 00085 00086 placeInputPoints(); 00087 placeOutputPoints(); 00088 00089 endPlace(); 00090 } 00091 00095 point blockSchema::inputPoint(unsigned int i) const 00096 { 00097 assert (placed()); 00098 assert (i < inputs()); 00099 return fInputPoint[i]; 00100 } 00101 00105 point blockSchema::outputPoint(unsigned int i) const 00106 { 00107 assert (placed()); 00108 assert (i < outputs()); 00109 return fOutputPoint[i]; 00110 } 00111 00116 void blockSchema::placeInputPoints() 00117 { 00118 int N = inputs(); 00119 00120 if (orientation() == kLeftRight) { 00121 00122 double px = x(); 00123 double py = y() + (height() - dWire*(N-1))/2; 00124 00125 for (int i=0; i<N; i++) { 00126 fInputPoint[i] = point(px, py+i*dWire); 00127 } 00128 00129 } else { 00130 00131 double px = x() + width(); 00132 double py = y() + height() - (height() - dWire*(N-1))/2; 00133 00134 for (int i=0; i<N; i++) { 00135 fInputPoint[i] = point(px, py-i*dWire); 00136 } 00137 } 00138 } 00139 00140 00145 void blockSchema::placeOutputPoints() 00146 { 00147 int N = outputs(); 00148 00149 if (orientation() == kLeftRight) { 00150 00151 double px = x() + width(); 00152 double py = y() + (height() - dWire*(N-1))/2; 00153 00154 for (int i=0; i<N; i++) { 00155 fOutputPoint[i] = point(px, py + i*dWire); 00156 } 00157 00158 } else { 00159 00160 double px = x(); 00161 double py = y() + height() - (height() - dWire*(N-1))/2; 00162 00163 for (int i=0; i<N; i++) { 00164 fOutputPoint[i] = point(px, py - i*dWire); 00165 } 00166 } 00167 } 00168 00169 00174 void blockSchema::draw(device& dev) 00175 { 00176 assert(placed()); 00177 00178 drawRectangle(dev); 00179 drawText(dev); 00180 drawOrientationMark(dev); 00181 drawInputWires(dev); 00182 drawOutputWires(dev); 00183 } 00184 00188 void blockSchema::drawRectangle(device& dev) 00189 { 00190 dev.rect( x() + dHorz, 00191 y() + dVert, 00192 width() - 2*dHorz, 00193 height() - 2*dVert, 00194 fColor.c_str(), 00195 fLink.c_str() 00196 ); 00197 } 00198 00199 00203 void blockSchema::drawText(device& dev) 00204 { 00205 dev.text( x() + width()/2, 00206 y() + height()/2, 00207 fText.c_str(), 00208 fLink.c_str() 00209 ); 00210 } 00211 00212 00217 void blockSchema::drawOrientationMark(device& dev) 00218 { 00219 double px, py; 00220 00221 if (orientation() == kLeftRight) { 00222 px = x() + dHorz; 00223 py = y() + dVert; 00224 } else { 00225 px = x() + width() - dHorz; 00226 py = y() + height() - dVert; 00227 } 00228 00229 dev.markSens( px, py, orientation() ); 00230 } 00231 #if 1 00232 00236 void blockSchema::drawInputWires(device& dev) 00237 { 00238 double dx = (orientation() == kLeftRight) ? dHorz : -dHorz; 00239 00240 for (unsigned int i=0; i<inputs(); i++) { 00241 point p = fInputPoint[i]; 00242 //dev.trait(p.x, p.y, p.x+dx, p.y); 00243 dev.fleche(p.x+dx, p.y, 0, orientation()); 00244 } 00245 } 00246 00251 void blockSchema::drawOutputWires(device& dev) 00252 { 00253 //double dx = (orientation() == kLeftRight) ? dHorz : -dHorz; 00254 00255 for (unsigned int i=0; i<outputs(); i++) { 00256 point p = fOutputPoint[i]; 00257 //dev.trait(p.x, p.y, p.x-dx, p.y); 00258 } 00259 } 00260 #endif 00261 00266 void blockSchema::collectTraits(collector& c) 00267 { 00268 collectInputWires(c); 00269 collectOutputWires(c); 00270 } 00271 00276 void blockSchema::collectInputWires(collector& c) 00277 { 00278 double dx = (orientation() == kLeftRight) ? dHorz : -dHorz; 00279 00280 for (unsigned int i=0; i<inputs(); i++) { 00281 point p = fInputPoint[i]; 00282 c.addTrait(trait(point(p.x, p.y), point(p.x+dx, p.y))); // in->out direction 00283 c.addInput(point(p.x+dx, p.y)); 00284 } 00285 } 00286 00291 void blockSchema::collectOutputWires(collector& c) 00292 { 00293 double dx = (orientation() == kLeftRight) ? dHorz : -dHorz; 00294 00295 for (unsigned int i=0; i<outputs(); i++) { 00296 point p = fOutputPoint[i]; 00297 c.addTrait(trait(point(p.x-dx, p.y), point(p.x, p.y))); // in->out direction 00298 c.addOutput(point(p.x-dx, p.y)); 00299 } 00300 } 00301 00302
1.8.0