FAUST compiler  0.9.9.6b8
decorateSchema.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 #include "decorateSchema.h"
00023 #include <iostream>
00024 #include <assert.h>
00025 
00026 using namespace std;
00027 
00031 schema* makeDecorateSchema ( schema* s, double margin, const string& text )
00032 {
00033     return new decorateSchema (s, margin, text);
00034 }
00035 
00036 
00043 decorateSchema::decorateSchema( schema* s, double margin, const string& text )
00044     :   schema(s->inputs(), s->outputs(), s->width()+2*margin, s->height()+2*margin),
00045         fSchema(s),
00046         fMargin(margin),
00047         fText(text)
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 decorateSchema::place(double ox, double oy, int orientation)
00060 {
00061     beginPlace(ox, oy, orientation);
00062 
00063     fSchema->place(ox+fMargin, oy+fMargin, orientation);
00064 
00065     double m = fMargin;
00066     if (orientation == kRightLeft) {
00067         m = -m;
00068     }
00069 
00070     for (unsigned int i=0; i < inputs(); i++) {
00071         point p = fSchema->inputPoint(i);
00072         fInputPoint[i] = point(p.x-m, 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+m, p.y); //, p.z);
00078     }
00079 
00080     endPlace();
00081 }
00082 
00086 point decorateSchema::inputPoint(unsigned int i) const
00087 {
00088     assert (placed());
00089     assert (i < inputs());
00090     return fInputPoint[i];
00091 }
00092 
00096 point decorateSchema::outputPoint(unsigned int i) const
00097 {
00098     assert (placed());
00099     assert (i < outputs());
00100     return fOutputPoint[i];
00101 }
00102 
00107 void decorateSchema::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         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         dev.trait(p.x, p.y, q.x, q.y);
00125     }
00126 #endif
00127     // define the coordinates of the frame
00128     double tw = (2+fText.size())*dLetter*0.75;
00129     double x0 = x() + fMargin/2;                // left
00130     double y0 = y() + fMargin/2;                // top
00131     double x1 = x() + width() - fMargin/2;      // right
00132     double y1 = y() + height() - fMargin/2;     // bottom
00133     //double tl = x0 + 2*dWire;                 // left of text zone
00134     double tl = x() + fMargin;                  // left of text zone
00135     double tr = min(tl+tw, x1);                 // right of text zone
00136 
00137     // draw the surronding frame
00138     dev.dasharray(x0, y0, x0, y1);              // left line
00139     dev.dasharray(x0, y1, x1, y1);              // bottom line
00140     dev.dasharray(x1, y1, x1, y0);              // right line
00141     dev.dasharray(x0, y0, tl, y0);              // top segment before text
00142     dev.dasharray(tr, y0, x1, y0);              // top segment after text
00143 
00144     // draw the label
00145     dev.label(tl, y0, fText.c_str());   //
00146 }
00147 
00152 void decorateSchema::collectTraits(collector& c)
00153 {
00154     assert(placed());
00155 
00156     fSchema->collectTraits(c);
00157 
00158     // draw enlarge input wires
00159     for (unsigned int i=0; i<inputs(); i++) {
00160         point p = inputPoint(i);
00161         point q = fSchema->inputPoint(i);
00162         c.addTrait(trait(p,q));     // in->out direction
00163     }
00164 
00165     // draw enlarge output wires
00166     for (unsigned int i=0; i<outputs(); i++) {
00167         point p = fSchema->outputPoint(i);
00168         point q = outputPoint(i);
00169         c.addTrait(trait(p,q));     // in->out direction
00170     }
00171 }