FAUST compiler  0.9.9.6b8
mergeSchema.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 "mergeSchema.h"
00024 #include <iostream>
00025 #include <assert.h>
00026 
00027 using namespace std;
00028 
00029 
00035 schema* makeMergeSchema (schema* s1, schema* s2)
00036 {
00037     // avoid ugly diagram by ensuring at least dWire width
00038     schema * a = makeEnlargedSchema(s1, dWire);
00039     schema * b = makeEnlargedSchema(s2, dWire);
00040     double  hgap = (a->height()+b->height())/4;
00041     return new mergeSchema(a,b,hgap);
00042 }
00043 
00044 
00050 mergeSchema::mergeSchema (schema* s1, schema* s2, double hgap)
00051     :   schema( s1->inputs(),
00052                 s2->outputs(),
00053                 s1->width() + s2->width() + hgap,
00054                 max(s1->height(), s2->height()) ),
00055         fSchema1(s1),
00056         fSchema2(s2),
00057         fHorzGap(hgap)
00058 {
00059 }
00060 
00061 
00066 void mergeSchema::place(double ox, double oy, int orientation)
00067 {
00068     beginPlace(ox, oy, orientation);
00069 
00070     double dy1 = max(0.0, fSchema2->height()-fSchema1->height()) / 2.0;
00071     double dy2 = max(0.0, fSchema1->height()-fSchema2->height()) / 2.0;
00072 
00073     if (orientation == kLeftRight) {
00074         fSchema1->place(ox, oy+dy1, orientation);
00075         fSchema2->place(ox+fSchema1->width()+fHorzGap, oy+dy2, orientation);
00076     } else {
00077         fSchema2->place(ox, oy+dy2, orientation);
00078         fSchema1->place(ox+fSchema2->width()+fHorzGap, oy+dy1, orientation);
00079     }
00080     endPlace();
00081 }
00082 
00083 
00087 point mergeSchema::inputPoint(unsigned int i) const
00088 {
00089     return fSchema1->inputPoint(i);
00090 }
00091 
00092 
00096 point mergeSchema::outputPoint(unsigned int i) const
00097 {
00098     return fSchema2->outputPoint(i);
00099 }
00100 
00101 
00105 void mergeSchema::draw(device& dev)
00106 {
00107     assert(placed());
00108 
00109     // draw the two subdiagrams
00110     fSchema1->draw(dev);
00111     fSchema2->draw(dev);
00112 
00113 #if 0
00114     unsigned int r = fSchema2->inputs();
00115     assert(r>0);
00116 
00117     // draw the connections between them
00118     for (unsigned int i=0; i<fSchema1->outputs(); i++) {
00119         point p = fSchema1->outputPoint(i);
00120         point q = fSchema2->inputPoint(i%r);
00121         dev.trait(p.x, p.y, q.x, q.y);
00122     }
00123 #endif
00124 }
00125 
00126 
00130 void mergeSchema::collectTraits(collector& c)
00131 {
00132     assert(placed());
00133 
00134     // draw the two subdiagrams
00135     fSchema1->collectTraits(c);
00136     fSchema2->collectTraits(c);
00137 
00138     unsigned int r = fSchema2->inputs();
00139     assert(r>0);
00140 
00141     // draw the connections between them
00142     for (unsigned int i=0; i<fSchema1->outputs(); i++) {
00143         point p = fSchema1->outputPoint(i);
00144         point q = fSchema2->inputPoint(i%r);
00145         c.addTrait(trait(p,q));
00146     }
00147 }
00148 
00149