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 ************************************************************************/
23 #include "mergeSchema.h"
31 * Creates a new merge schema. Cables are enlarged to dWire.
32 * The horizontal gap between the two subschema is such that
33 * the connections are not too slopy.
35 schema
* makeMergeSchema (schema
* s1
, schema
* s2
)
37 // avoid ugly diagram by ensuring at least dWire width
38 schema
* a
= makeEnlargedSchema(s1
, dWire
);
39 schema
* b
= makeEnlargedSchema(s2
, dWire
);
40 double hgap
= (a
->height()+b
->height())/4;
41 return new mergeSchema(a
,b
,hgap
);
46 * Constructor for a merge schema s1 :> s2 where the outputs
47 * of s1 are merged to the inputs of s2. The constructor is
48 * private in order to enforce the usage of makeMergeSchema
50 mergeSchema::mergeSchema (schema
* s1
, schema
* s2
, double hgap
)
51 : schema( s1
->inputs(),
53 s1
->width() + s2
->width() + hgap
,
54 max(s1
->height(), s2
->height()) ),
63 * Places the two subschema horizontaly, centered, with enough gap for
66 void mergeSchema::place(double ox
, double oy
, int orientation
)
68 beginPlace(ox
, oy
, orientation
);
70 double dy1
= max(0.0, fSchema2
->height()-fSchema1
->height()) / 2.0;
71 double dy2
= max(0.0, fSchema1
->height()-fSchema2
->height()) / 2.0;
73 if (orientation
== kLeftRight
) {
74 fSchema1
->place(ox
, oy
+dy1
, orientation
);
75 fSchema2
->place(ox
+fSchema1
->width()+fHorzGap
, oy
+dy2
, orientation
);
77 fSchema2
->place(ox
, oy
+dy2
, orientation
);
78 fSchema1
->place(ox
+fSchema2
->width()+fHorzGap
, oy
+dy1
, orientation
);
85 * The inputs of s1 :> s2 are the inputs of s1
87 point
mergeSchema::inputPoint(unsigned int i
) const
89 return fSchema1
->inputPoint(i
);
94 * The outputs of s1 :> s2 are the outputs of s2
96 point
mergeSchema::outputPoint(unsigned int i
) const
98 return fSchema2
->outputPoint(i
);
103 * Draw the two sub schema and the connections between them
105 void mergeSchema::draw(device
& dev
)
109 // draw the two subdiagrams
114 unsigned int r
= fSchema2
->inputs();
117 // draw the connections between them
118 for (unsigned int i
=0; i
<fSchema1
->outputs(); i
++) {
119 point p
= fSchema1
->outputPoint(i
);
120 point q
= fSchema2
->inputPoint(i
%r
);
121 dev
.trait(p
.x
, p
.y
, q
.x
, q
.y
);
128 * Draw the two sub schema and the connections between them
130 void mergeSchema::collectTraits(collector
& c
)
134 // draw the two subdiagrams
135 fSchema1
->collectTraits(c
);
136 fSchema2
->collectTraits(c
);
138 unsigned int r
= fSchema2
->inputs();
141 // draw the connections between them
142 for (unsigned int i
=0; i
<fSchema1
->outputs(); i
++) {
143 point p
= fSchema1
->outputPoint(i
);
144 point q
= fSchema2
->inputPoint(i
%r
);
145 c
.addTrait(trait(p
,q
));