FAUST compiler  0.9.9.6b8
splitSchema.cpp
Go to the documentation of this file.
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 "splitSchema.h"
00024 #include <iostream>
00025 #include <assert.h>
00026 
00027 using namespace std;
00028 
00034 schema* makeSplitSchema (schema* s1, schema* s2)
00035 {
00036     // make sure a and b are at least dWire large
00037     schema * a = makeEnlargedSchema(s1, dWire);
00038     schema * b = makeEnlargedSchema(s2, dWire);
00039 
00040     // horizontal gap to avaoid too slopy connections
00041     double  hgap = (a->height()+b->height())/4;
00042 
00043     return new splitSchema(a,b,hgap);
00044 }
00045 
00046 
00052 splitSchema::splitSchema (schema* s1, schema* s2, double hgap)
00053     :   schema( s1->inputs(),
00054                 s2->outputs(),
00055                 s1->width() + s2->width() + hgap,
00056                 max(s1->height(), s2->height()) ),
00057         fSchema1(s1),
00058         fSchema2(s2),
00059         fHorzGap(hgap)
00060 {
00061 }
00062 
00063 
00068 void splitSchema::place(double ox, double oy, int orientation)
00069 {
00070     beginPlace(ox, oy, orientation);
00071 
00072     double dy1 = max(0.0, fSchema2->height()-fSchema1->height()) / 2.0;
00073     double dy2 = max(0.0, fSchema1->height()-fSchema2->height()) / 2.0;
00074 
00075     if (orientation == kLeftRight) {
00076         fSchema1->place(ox, oy+dy1, orientation);
00077         fSchema2->place(ox+fSchema1->width()+fHorzGap, oy+dy2, orientation);
00078     } else {
00079         fSchema2->place(ox, oy+dy2, orientation);
00080         fSchema1->place(ox+fSchema2->width()+fHorzGap, oy+dy1, orientation);
00081     }
00082     endPlace();
00083 }
00084 
00085 
00089 point splitSchema::inputPoint(unsigned int i) const
00090 {
00091     return fSchema1->inputPoint(i);
00092 }
00093 
00094 
00098 point splitSchema::outputPoint(unsigned int i) const
00099 {
00100     return fSchema2->outputPoint(i);
00101 }
00102 
00103 
00107 void splitSchema::draw(device& dev)
00108 {
00109     assert(placed());
00110 
00111     // draw the two subdiagrams
00112     fSchema1->draw(dev);
00113     fSchema2->draw(dev);
00114 
00115     unsigned int r = fSchema1->outputs();
00116     assert(r>0);
00117 #if 0
00118     // draw the connections between them
00119     for (unsigned int i=0; i<fSchema2->inputs(); i++) {
00120         point p = fSchema1->outputPoint(i%r);
00121         point q = fSchema2->inputPoint(i);
00122         if(p.z>0) {
00123             dev.trait(p.x, p.y, q.x, q.y);
00124         }
00125     }
00126 #endif
00127 }
00128 
00129 
00133 void splitSchema::collectTraits(collector& c)
00134 {
00135     assert(placed());
00136 
00137     // draw the two subdiagrams
00138     fSchema1->collectTraits(c);
00139     fSchema2->collectTraits(c);
00140 
00141     unsigned int r = fSchema1->outputs();
00142     assert(r>0);
00143 
00144     // draw the connections between them
00145     for (unsigned int i=0; i<fSchema2->inputs(); i++) {
00146         point p = fSchema1->outputPoint(i%r);
00147         point q = fSchema2->inputPoint(i);
00148         c.addTrait(trait(point(p.x, p.y), point(q.x, q.y)));
00149     }
00150 }
00151 
00152