FAUST compiler  0.9.9.6b8
mergeSchema.cpp
Go to the documentation of this file.
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 
23 #include "mergeSchema.h"
24 #include <iostream>
25 #include <assert.h>
26 
27 using namespace std;
28 
29 
36 {
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);
42 }
43 
44 
50 mergeSchema::mergeSchema (schema* s1, schema* s2, double hgap)
51  : schema( s1->inputs(),
52  s2->outputs(),
53  s1->width() + s2->width() + hgap,
54  max(s1->height(), s2->height()) ),
55  fSchema1(s1),
56  fSchema2(s2),
57  fHorzGap(hgap)
58 {
59 }
60 
61 
66 void mergeSchema::place(double ox, double oy, int orientation)
67 {
68  beginPlace(ox, oy, orientation);
69 
70  double dy1 = max(0.0, fSchema2->height()-fSchema1->height()) / 2.0;
71  double dy2 = max(0.0, fSchema1->height()-fSchema2->height()) / 2.0;
72 
73  if (orientation == kLeftRight) {
74  fSchema1->place(ox, oy+dy1, orientation);
76  } else {
77  fSchema2->place(ox, oy+dy2, orientation);
79  }
80  endPlace();
81 }
82 
83 
87 point mergeSchema::inputPoint(unsigned int i) const
88 {
89  return fSchema1->inputPoint(i);
90 }
91 
92 
96 point mergeSchema::outputPoint(unsigned int i) const
97 {
98  return fSchema2->outputPoint(i);
99 }
100 
101 
106 {
107  assert(placed());
108 
109  // draw the two subdiagrams
110  fSchema1->draw(dev);
111  fSchema2->draw(dev);
112 
113 #if 0
114  unsigned int r = fSchema2->inputs();
115  assert(r>0);
116 
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);
122  }
123 #endif
124 }
125 
126 
131 {
132  assert(placed());
133 
134  // draw the two subdiagrams
137 
138  unsigned int r = fSchema2->inputs();
139  assert(r>0);
140 
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));
146  }
147 }
148 
149 
schema * makeMergeSchema(schema *s1, schema *s2)
Creates a new merge schema.
Definition: mergeSchema.cpp:35
void addTrait(const trait &t)
Definition: schema.h:84
void endPlace()
Definition: schema.h:134
virtual void draw(device &dev)
Draw the two sub schema and the connections between them.
Definition: schema.h:56
unsigned int outputs() const
Definition: schema.h:129
const double dWire
distance between two wires
Definition: schema.h:33
virtual point inputPoint(unsigned int i) const =0
mergeSchema(schema *s1, schema *s2, double hgap)
Constructor for a merge schema s1 :> s2 where the outputs of s1 are merged to the inputs of s2...
Definition: mergeSchema.cpp:50
void beginPlace(double x, double y, int orientation)
Definition: schema.h:132
virtual void draw(device &dev)=0
double fHorzGap
Definition: mergeSchema.h:37
virtual point outputPoint(unsigned int i) const
The outputs of s1 :> s2 are the outputs of s2.
Definition: mergeSchema.cpp:96
virtual void collectTraits(collector &c)=0
unsigned int inputs() const
Definition: schema.h:128
Place and connect two diagrams in merge composition.
Definition: mergeSchema.h:33
double max(double x, double y)
Definition: interval.hh:60
schema * fSchema1
Definition: mergeSchema.h:35
double width() const
Definition: schema.h:126
double y
Definition: schema.h:43
bool placed() const
Definition: schema.h:137
Definition: device.h:32
int orientation() const
Definition: schema.h:140
virtual void place(double x, double y, int orientation)=0
double x
Definition: schema.h:42
Definition: schema.h:40
virtual point outputPoint(unsigned int i) const =0
An abstract block diagram schema.
Definition: schema.h:97
double height() const
Definition: schema.h:127
virtual void place(double ox, double oy, int orientation)
Places the two subschema horizontaly, centered, with enough gap for the connections.
Definition: mergeSchema.cpp:66
virtual point inputPoint(unsigned int i) const
The inputs of s1 :> s2 are the inputs of s1.
Definition: mergeSchema.cpp:87
schema * fSchema2
Definition: mergeSchema.h:36
virtual void collectTraits(collector &c)
Draw the two sub schema and the connections between them.
virtual void trait(double x1, double y1, double x2, double y2)=0
schema * makeEnlargedSchema(schema *s, double width)
Returns an enlarged schema, but only if really needed that is if the requiered width is greater that ...