|
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 #include "enlargedSchema.h" 00023 #include <assert.h> 00024 #include <iostream> 00025 00026 using namespace std; 00027 00032 schema* makeEnlargedSchema ( schema* s, double width ) 00033 { 00034 if (width > s->width()) { 00035 return new enlargedSchema(s, width); 00036 } else { 00037 return s; 00038 } 00039 } 00040 00045 enlargedSchema::enlargedSchema( schema* s, double width ) 00046 : schema(s->inputs(), s->outputs(), width, s->height()), 00047 fSchema(s) 00048 { 00049 for (unsigned int i=0; i<inputs(); i++) fInputPoint.push_back(point(0,0)); 00050 for (unsigned int i=0; i<outputs(); i++) fOutputPoint.push_back(point(0,0)); 00051 } 00052 00053 00059 void enlargedSchema::place(double ox, double oy, int orientation) 00060 { 00061 beginPlace(ox, oy, orientation); 00062 00063 double dx = (width() - fSchema->width())/2; 00064 fSchema->place(ox+dx, oy, orientation); 00065 00066 if (orientation == kRightLeft) { 00067 dx = -dx; 00068 } 00069 00070 for (unsigned int i=0; i < inputs(); i++) { 00071 point p = fSchema->inputPoint(i); 00072 fInputPoint[i] = point(p.x-dx, p.y); //, p.z); 00073 } 00074 00075 for (unsigned int i=0; i < outputs(); i++) { 00076 point p = fSchema->outputPoint(i); 00077 fOutputPoint[i] = point(p.x+dx, p.y); //, p.z); 00078 } 00079 00080 endPlace(); 00081 } 00082 00086 point enlargedSchema::inputPoint(unsigned int i) const 00087 { 00088 assert (placed()); 00089 assert (i < inputs()); 00090 return fInputPoint[i]; 00091 } 00092 00096 point enlargedSchema::outputPoint(unsigned int i) const 00097 { 00098 assert (placed()); 00099 assert (i < outputs()); 00100 return fOutputPoint[i]; 00101 } 00102 00107 void enlargedSchema::draw(device& dev) 00108 { 00109 assert(placed()); 00110 00111 fSchema->draw(dev); 00112 #if 0 00113 // draw enlarge input wires 00114 for (unsigned int i=0; i<inputs(); i++) { 00115 point p = inputPoint(i); 00116 point q = fSchema->inputPoint(i); 00117 if ( (p.z>=0) && (q.z>=0) ) dev.trait(p.x, p.y, q.x, q.y); 00118 } 00119 00120 // draw enlarge output wires 00121 for (unsigned int i=0; i<outputs(); i++) { 00122 point p = outputPoint(i); 00123 point q = fSchema->outputPoint(i); 00124 if ( (p.z>=0) && (q.z>=0) ) dev.trait(p.x, p.y, q.x, q.y); 00125 } 00126 #endif 00127 } 00128 00133 void enlargedSchema::collectTraits(collector& c) 00134 { 00135 assert(placed()); 00136 00137 fSchema->collectTraits(c); 00138 00139 // draw enlarge input wires 00140 for (unsigned int i=0; i<inputs(); i++) { 00141 point p = inputPoint(i); 00142 point q = fSchema->inputPoint(i); 00143 c.addTrait(trait(p,q)); // in->out direction 00144 } 00145 00146 // draw enlarge output wires 00147 for (unsigned int i=0; i<outputs(); i++) { 00148 point q = fSchema->outputPoint(i); 00149 point p = outputPoint(i); 00150 c.addTrait(trait(q,p)); // in->out direction 00151 } 00152 }
1.8.0