|
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 #ifndef __SCHEMA__ 00023 #define __SCHEMA__ 00024 00025 00026 #include "device.h" 00027 #include <vector> 00028 #include <string> 00029 #include <set> 00030 00031 using namespace std; 00032 00033 const double dWire = 8; 00034 //const double dLetter = 6; ///< width of a letter 00035 const double dLetter = 4.3; 00036 const double dHorz = 4; 00037 const double dVert = 4; 00038 00039 00040 struct point 00041 { 00042 double x; 00043 double y; 00044 00045 point(double u, double v) : x(u), y(v) {} 00046 point(const point& p) : x(p.x), y(p.y) {} 00047 00048 bool operator<(const point& p) const { 00049 if (x < p.x) return true; 00050 else if (x > p.x) return false; 00051 else if (y < p.y) return true; 00052 else return false; 00053 } 00054 }; 00055 00056 struct trait 00057 { 00058 point start; 00059 point end; 00060 bool hasRealInput; 00061 bool hasRealOutput; 00062 00063 trait(const point& p1, const point& p2) : start(p1), end(p2) {} 00064 void draw(device& dev) const { dev.trait(start.x, start.y, end.x, end.y); } 00065 00066 bool operator<(const trait& t) const { 00067 if (start < t.start) return true; 00068 else if (t.start < start) return false; 00069 else if (end < t.end) return true; 00070 else return false; 00071 } 00072 }; 00073 00074 struct collector 00075 { 00076 set<point> fOutputs; // collect real outputs 00077 set<point> fInputs; // collect real inputs 00078 set<trait> fTraits; // collect traits to draw 00079 set<trait> fWithInput; // collect traits with a real input 00080 set<trait> fWithOutput; // collect traits with a real output 00081 00082 void addOutput(const point& p) { fOutputs.insert(p); } 00083 void addInput(const point& p) { fInputs.insert(p); } 00084 void addTrait(const trait& t) { fTraits.insert(t); } 00085 void computeVisibleTraits(); 00086 bool isVisible(const trait& t); 00087 void draw(device& dev); 00088 }; 00089 00090 enum { kLeftRight=1, kRightLeft=-1 }; 00091 00092 00093 00097 class schema 00098 { 00099 private: 00100 const unsigned int fInputs; 00101 const unsigned int fOutputs; 00102 const double fWidth; 00103 const double fHeight; 00104 00105 // fields only defined after place() is called 00106 bool fPlaced; 00107 double fX; 00108 double fY; 00109 int fOrientation; 00110 00111 public: 00112 00113 schema(unsigned int inputs, unsigned int outputs, double width, double height) 00114 : fInputs(inputs), 00115 fOutputs(outputs), 00116 fWidth(width), 00117 fHeight(height), 00118 fPlaced(false), 00119 fX(0), 00120 fY(0), 00121 fOrientation(0) 00122 {} 00123 virtual ~schema() {} 00124 00125 // constant fields 00126 double width() const { return fWidth; } 00127 double height() const { return fHeight; } 00128 unsigned int inputs() const { return fInputs; } 00129 unsigned int outputs() const { return fOutputs; } 00130 00131 // starts and end placement 00132 void beginPlace (double x, double y, int orientation) 00133 { fX = x; fY = y; fOrientation = orientation; } 00134 void endPlace () { fPlaced = true; } 00135 00136 // fields available after placement 00137 bool placed() const { return fPlaced; } 00138 double x() const { return fX; } 00139 double y() const { return fY; } 00140 int orientation() const { return fOrientation; } 00141 00142 00143 // abstract interface for subclasses 00144 virtual void place(double x, double y, int orientation) = 0; 00145 virtual void draw(device& dev) = 0; 00146 virtual void collectTraits(collector& c) = 0; 00147 virtual point inputPoint(unsigned int i) const = 0; 00148 virtual point outputPoint(unsigned int i)const = 0; 00149 }; 00150 00151 // various functions to create schemas 00152 00153 schema* makeBlockSchema (unsigned int inputs, 00154 unsigned int outputs, 00155 const string& name, 00156 const string& color, 00157 const string& link); 00158 00159 schema* makeCableSchema (unsigned int n=1); 00160 schema* makeInverterSchema (const string& color); 00161 schema* makeCutSchema (); 00162 schema* makeEnlargedSchema (schema* s, double width); 00163 schema* makeParSchema (schema* s1, schema* s2); 00164 schema* makeSeqSchema (schema* s1, schema* s2); 00165 schema* makeMergeSchema (schema* s1, schema* s2); 00166 schema* makeSplitSchema (schema* s1, schema* s2); 00167 schema* makeRecSchema (schema* s1, schema* s2); 00168 schema* makeTopSchema (schema* s1, double margin, const string& text, const string& link); 00169 schema* makeDecorateSchema (schema* s1, double margin, const string& text); 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 #endif 00180 00181
1.8.0