1 /************************************************************************
2 ************************************************************************
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.
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.
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 ************************************************************************/
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
45 point(double u
, double v
) : x(u
), y(v
) {}
46 point(const point
& p
) : x(p
.x
), y(p
.y
) {}
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;
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
); }
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;
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
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
);
90 enum { kLeftRight
=1, kRightLeft
=-1 };
95 * An abstract block diagram schema
100 const unsigned int fInputs
;
101 const unsigned int fOutputs
;
103 const double fHeight
;
105 // fields only defined after place() is called
106 bool fPlaced
; ///< false until place() is called
113 schema(unsigned int inputs
, unsigned int outputs
, double width
, double height
)
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
; }
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; }
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
; }
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;
151 // various functions to create schemas
153 schema
* makeBlockSchema (unsigned int inputs
,
154 unsigned int outputs
,
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
);