First cleaning step in "dsp_files" directory.
[Faustine.git] / interpretor / faust-0.9.47mr3 / compiler / draw / schema / schema.h
1 /************************************************************************
2 ************************************************************************
3 FAUST compiler
4 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5 ---------------------------------------------------------------------
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ************************************************************************
20 ************************************************************************/
21
22 #ifndef __SCHEMA__
23 #define __SCHEMA__
24
25
26 #include "device.h"
27 #include <vector>
28 #include <string>
29 #include <set>
30
31 using namespace std;
32
33 const double dWire = 8; ///< distance between two wires
34 //const double dLetter = 6; ///< width of a letter
35 const double dLetter = 4.3; ///< width of a letter
36 const double dHorz = 4; ///< marge horizontale
37 const double dVert = 4; ///< marge verticale
38
39
40 struct point
41 {
42 double x;
43 double y;
44
45 point(double u, double v) : x(u), y(v) {}
46 point(const point& p) : x(p.x), y(p.y) {}
47
48 bool operator<(const point& p) const {
49 if (x < p.x) return true;
50 else if (x > p.x) return false;
51 else if (y < p.y) return true;
52 else return false;
53 }
54 };
55
56 struct trait
57 {
58 point start;
59 point end;
60 bool hasRealInput;
61 bool hasRealOutput;
62
63 trait(const point& p1, const point& p2) : start(p1), end(p2) {}
64 void draw(device& dev) const { dev.trait(start.x, start.y, end.x, end.y); }
65
66 bool operator<(const trait& t) const {
67 if (start < t.start) return true;
68 else if (t.start < start) return false;
69 else if (end < t.end) return true;
70 else return false;
71 }
72 };
73
74 struct collector
75 {
76 set<point> fOutputs; // collect real outputs
77 set<point> fInputs; // collect real inputs
78 set<trait> fTraits; // collect traits to draw
79 set<trait> fWithInput; // collect traits with a real input
80 set<trait> fWithOutput; // collect traits with a real output
81
82 void addOutput(const point& p) { fOutputs.insert(p); }
83 void addInput(const point& p) { fInputs.insert(p); }
84 void addTrait(const trait& t) { fTraits.insert(t); }
85 void computeVisibleTraits();
86 bool isVisible(const trait& t);
87 void draw(device& dev);
88 };
89
90 enum { kLeftRight=1, kRightLeft=-1 };
91
92
93
94 /**
95 * An abstract block diagram schema
96 */
97 class schema
98 {
99 private:
100 const unsigned int fInputs;
101 const unsigned int fOutputs;
102 const double fWidth;
103 const double fHeight;
104
105 // fields only defined after place() is called
106 bool fPlaced; ///< false until place() is called
107 double fX;
108 double fY;
109 int fOrientation;
110
111 public:
112
113 schema(unsigned int inputs, unsigned int outputs, double width, double height)
114 : fInputs(inputs),
115 fOutputs(outputs),
116 fWidth(width),
117 fHeight(height),
118 fPlaced(false),
119 fX(0),
120 fY(0),
121 fOrientation(0)
122 {}
123 virtual ~schema() {}
124
125 // constant fields
126 double width() const { return fWidth; }
127 double height() const { return fHeight; }
128 unsigned int inputs() const { return fInputs; }
129 unsigned int outputs() const { return fOutputs; }
130
131 // starts and end placement
132 void beginPlace (double x, double y, int orientation)
133 { fX = x; fY = y; fOrientation = orientation; }
134 void endPlace () { fPlaced = true; }
135
136 // fields available after placement
137 bool placed() const { return fPlaced; }
138 double x() const { return fX; }
139 double y() const { return fY; }
140 int orientation() const { return fOrientation; }
141
142
143 // abstract interface for subclasses
144 virtual void place(double x, double y, int orientation) = 0;
145 virtual void draw(device& dev) = 0;
146 virtual void collectTraits(collector& c) = 0;
147 virtual point inputPoint(unsigned int i) const = 0;
148 virtual point outputPoint(unsigned int i)const = 0;
149 };
150
151 // various functions to create schemas
152
153 schema* makeBlockSchema (unsigned int inputs,
154 unsigned int outputs,
155 const string& name,
156 const string& color,
157 const string& link);
158
159 schema* makeCableSchema (unsigned int n=1);
160 schema* makeInverterSchema (const string& color);
161 schema* makeCutSchema ();
162 schema* makeEnlargedSchema (schema* s, double width);
163 schema* makeParSchema (schema* s1, schema* s2);
164 schema* makeSeqSchema (schema* s1, schema* s2);
165 schema* makeMergeSchema (schema* s1, schema* s2);
166 schema* makeSplitSchema (schema* s1, schema* s2);
167 schema* makeRecSchema (schema* s1, schema* s2);
168 schema* makeTopSchema (schema* s1, double margin, const string& text, const string& link);
169 schema* makeDecorateSchema (schema* s1, double margin, const string& text);
170
171
172
173
174
175
176
177
178
179 #endif
180
181