FAUST compiler  0.9.9.6b8
splitSchema.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 "splitSchema.h"
24 #include <iostream>
25 #include <assert.h>
26 
27 using namespace std;
28 
35 {
36  // make sure a and b are at least dWire large
37  schema * a = makeEnlargedSchema(s1, dWire);
38  schema * b = makeEnlargedSchema(s2, dWire);
39 
40  // horizontal gap to avaoid too slopy connections
41  double hgap = (a->height()+b->height())/4;
42 
43  return new splitSchema(a,b,hgap);
44 }
45 
46 
52 splitSchema::splitSchema (schema* s1, schema* s2, double hgap)
53  : schema( s1->inputs(),
54  s2->outputs(),
55  s1->width() + s2->width() + hgap,
56  max(s1->height(), s2->height()) ),
57  fSchema1(s1),
58  fSchema2(s2),
59  fHorzGap(hgap)
60 {
61 }
62 
63 
68 void splitSchema::place(double ox, double oy, int orientation)
69 {
70  beginPlace(ox, oy, orientation);
71 
72  double dy1 = max(0.0, fSchema2->height()-fSchema1->height()) / 2.0;
73  double dy2 = max(0.0, fSchema1->height()-fSchema2->height()) / 2.0;
74 
75  if (orientation == kLeftRight) {
76  fSchema1->place(ox, oy+dy1, orientation);
78  } else {
79  fSchema2->place(ox, oy+dy2, orientation);
81  }
82  endPlace();
83 }
84 
85 
89 point splitSchema::inputPoint(unsigned int i) const
90 {
91  return fSchema1->inputPoint(i);
92 }
93 
94 
98 point splitSchema::outputPoint(unsigned int i) const
99 {
100  return fSchema2->outputPoint(i);
101 }
102 
103 
108 {
109  assert(placed());
110 
111  // draw the two subdiagrams
112  fSchema1->draw(dev);
113  fSchema2->draw(dev);
114 
115  unsigned int r = fSchema1->outputs();
116  assert(r>0);
117 #if 0
118  // draw the connections between them
119  for (unsigned int i=0; i<fSchema2->inputs(); i++) {
120  point p = fSchema1->outputPoint(i%r);
121  point q = fSchema2->inputPoint(i);
122  if(p.z>0) {
123  dev.trait(p.x, p.y, q.x, q.y);
124  }
125  }
126 #endif
127 }
128 
129 
134 {
135  assert(placed());
136 
137  // draw the two subdiagrams
140 
141  unsigned int r = fSchema1->outputs();
142  assert(r>0);
143 
144  // draw the connections between them
145  for (unsigned int i=0; i<fSchema2->inputs(); i++) {
146  point p = fSchema1->outputPoint(i%r);
147  point q = fSchema2->inputPoint(i);
148  c.addTrait(trait(point(p.x, p.y), point(q.x, q.y)));
149  }
150 }
151 
152 
void addTrait(const trait &t)
Definition: schema.h:84
void endPlace()
Definition: schema.h:134
Definition: schema.h:56
unsigned int outputs() const
Definition: schema.h:129
const double dWire
distance between two wires
Definition: schema.h:33
double fHorzGap
Definition: splitSchema.h:37
virtual point inputPoint(unsigned int i) const =0
void beginPlace(double x, double y, int orientation)
Definition: schema.h:132
splitSchema(schema *s1, schema *s2, double hgap)
Constructor for a split schema s1 <: s2 where the outputs of s1 are distributed to the inputs of s2...
Definition: splitSchema.cpp:52
virtual void draw(device &dev)=0
virtual void collectTraits(collector &c)=0
unsigned int inputs() const
Definition: schema.h:128
double max(double x, double y)
Definition: interval.hh:60
place and connect two diagrams in split composition
Definition: splitSchema.h:33
schema * makeSplitSchema(schema *s1, schema *s2)
Creates a new split schema.
Definition: splitSchema.cpp:34
virtual void collectTraits(collector &c)
Draw the two sub schema and the connections between them.
double width() const
Definition: schema.h:126
double y
Definition: schema.h:43
bool placed() const
Definition: schema.h:137
virtual void draw(device &dev)
Draw the two sub schema and the connections between them.
Definition: device.h:32
schema * fSchema1
Definition: splitSchema.h:35
virtual point outputPoint(unsigned int i) const
The outputs of s1 <: s2 are the outputs of s2.
Definition: splitSchema.cpp:98
int orientation() const
Definition: schema.h:140
schema * fSchema2
Definition: splitSchema.h:36
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: splitSchema.cpp:68
virtual point inputPoint(unsigned int i) const
The inputs of s1 <: s2 are the inputs of s1.
Definition: splitSchema.cpp:89
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 ...