FAUST compiler  0.9.9.6b8
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
seqSchema Class Reference

Sequential composition. More...

#include <seqSchema.h>

Inheritance diagram for seqSchema:
Inheritance graph
[legend]
Collaboration diagram for seqSchema:
Collaboration graph
[legend]

Public Member Functions

virtual void place (double ox, double oy, int orientation)
 Place the two components horizontally with enough space for the connections. More...
 
virtual void draw (device &dev)
 Draw the two components as well as the internal wires. More...
 
virtual point inputPoint (unsigned int i) const
 The input points are the input points of the first component. More...
 
virtual point outputPoint (unsigned int i) const
 The output points are the output points of the second component. More...
 
virtual void collectTraits (collector &c)
 Draw the two components as well as the internal wires. More...
 
- Public Member Functions inherited from schema
 schema (unsigned int inputs, unsigned int outputs, double width, double height)
 
virtual ~schema ()
 
double width () const
 
double height () const
 
unsigned int inputs () const
 
unsigned int outputs () const
 
void beginPlace (double x, double y, int orientation)
 
void endPlace ()
 
bool placed () const
 
double x () const
 
double y () const
 
int orientation () const
 

Private Member Functions

 seqSchema (schema *s1, schema *s2, double hgap)
 Constructor for a sequential schema (s1:s2). More...
 
void drawInternalWires (device &dev)
 Draw the internal wires aligning the vertical segments in a symetric way when possible. More...
 
void collectInternalWires (collector &c)
 Draw the internal wires aligning the vertical segments in a symetric way when possible. More...
 

Private Attributes

schemafSchema1
 
schemafSchema2
 
double fHorzGap
 

Friends

schemamakeSeqSchema (schema *s1, schema *s2)
 Make a sequential schema. More...
 

Detailed Description

Sequential composition.

Place and connect two diagrams in sequence. The constructor is private because one should use the makeSeqSchema function instead.

Definition at line 36 of file seqSchema.h.

Constructor & Destructor Documentation

seqSchema::seqSchema ( schema s1,
schema s2,
double  hgap 
)
private

Constructor for a sequential schema (s1:s2).

The components s1 and s2 are supposed to be "compatible" (s1 : n->m and s2 : m->q)

Definition at line 62 of file seqSchema.cpp.

References schema::inputs(), and schema::outputs().

63  : schema( s1->inputs(),
64  s2->outputs(),
65  s1->width() + hgap + s2->width(),
66  max(s1->height(), s2->height()) ),
67  fSchema1(s1),
68  fSchema2(s2),
69  fHorzGap(hgap)
70 {
71  assert(s1->outputs() == s2->inputs());
72 }
unsigned int outputs() const
Definition: schema.h:129
unsigned int inputs() const
Definition: schema.h:128
double max(double x, double y)
Definition: interval.hh:60
double width() const
Definition: schema.h:126
schema * fSchema2
Definition: seqSchema.h:39
schema(unsigned int inputs, unsigned int outputs, double width, double height)
Definition: schema.h:113
double height() const
Definition: schema.h:127
double fHorzGap
Definition: seqSchema.h:40
schema * fSchema1
Definition: seqSchema.h:38

Here is the call graph for this function:

Member Function Documentation

void seqSchema::collectInternalWires ( collector c)
private

Draw the internal wires aligning the vertical segments in a symetric way when possible.

Definition at line 233 of file seqSchema.cpp.

References collector::addTrait(), direction(), dWire, fHorzGap, fSchema1, fSchema2, schema::inputPoint(), schema::inputs(), kDownDir, kLeftRight, kUpDir, schema::orientation(), schema::outputPoint(), schema::outputs(), point::x, and point::y.

Referenced by collectTraits().

234 {
235  assert (fSchema1->outputs() == fSchema2->inputs());
236 
237  const int N = fSchema1->outputs();
238  double dx = 0;
239  double mx = 0;
240  int dir =-1;
241 
242  if (orientation() == kLeftRight) {
243  // draw left right cables
244  for (int i=0; i<N; i++) {
245  point src = fSchema1->outputPoint(i);
246  point dst = fSchema2->inputPoint(i);
247 
248  int d = direction(src,dst);
249  if (d != dir) {
250  // compute attributes of new direction
251  switch (d) {
252  case kUpDir : mx = 0; dx = dWire; break;
253  case kDownDir : mx = fHorzGap; dx = -dWire; break;
254  default : mx = 0; dx = 0; break;
255  }
256  dir = d;
257  } else {
258  // move in same direction
259  mx = mx +dx;
260  }
261  if (src.y == dst.y) {
262  // draw straight cable
263  c.addTrait(trait(point(src.x, src.y), point(dst.x, dst.y)));
264  } else {
265  // draw zizag cable
266  c.addTrait(trait(point(src.x, src.y), point(src.x+mx, src.y)));
267  c.addTrait(trait(point(src.x+mx, src.y), point(src.x+mx, dst.y)));
268  c.addTrait(trait(point(src.x+mx, dst.y), point(dst.x, dst.y)));
269  }
270 
271  }
272  } else {
273  // draw right left cables
274  for (int i=0; i<N; i++) {
275  point src = fSchema1->outputPoint(i);
276  point dst = fSchema2->inputPoint(i);
277 
278  int d = direction(src,dst);
279  if (d != dir) {
280  // compute attributes of new direction
281  switch (d) {
282  case kUpDir : mx = -fHorzGap; dx = dWire; break;
283  case kDownDir : mx = 0; dx = -dWire; break;
284  default : mx = 0; dx = 0; break;
285  }
286  dir = d;
287  } else {
288  // move in same direction
289  mx = mx +dx;
290  }
291  if (src.y == dst.y) {
292  // draw straight cable
293  c.addTrait(trait(point(src.x, src.y), point(dst.x, dst.y)));
294  } else {
295  // draw zizag cable
296  c.addTrait(trait(point(src.x, src.y), point(src.x+mx, src.y)));
297  c.addTrait(trait(point(src.x+mx, src.y), point(src.x+mx, dst.y)));
298  c.addTrait(trait(point(src.x+mx, dst.y), point(dst.x, dst.y)));
299  }
300 
301  }
302  }
303 }
void addTrait(const trait &t)
Definition: schema.h:84
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
unsigned int inputs() const
Definition: schema.h:128
static int direction(const point &a, const point &b)
Compute the direction of a connection.
Definition: seqSchema.cpp:313
double y
Definition: schema.h:43
schema * fSchema2
Definition: seqSchema.h:39
int orientation() const
Definition: schema.h:140
double x
Definition: schema.h:42
Definition: schema.h:40
virtual point outputPoint(unsigned int i) const =0
double fHorzGap
Definition: seqSchema.h:40
schema * fSchema1
Definition: seqSchema.h:38

Here is the call graph for this function:

Here is the caller graph for this function:

void seqSchema::collectTraits ( collector c)
virtual

Draw the two components as well as the internal wires.

Implements schema.

Definition at line 138 of file seqSchema.cpp.

References collectInternalWires(), schema::collectTraits(), fSchema1, fSchema2, schema::inputs(), schema::outputs(), and schema::placed().

139 {
140  assert(placed());
141  assert(fSchema1->outputs() == fSchema2->inputs());
142 
146 }
void collectInternalWires(collector &c)
Draw the internal wires aligning the vertical segments in a symetric way when possible.
Definition: seqSchema.cpp:233
unsigned int outputs() const
Definition: schema.h:129
virtual void collectTraits(collector &c)=0
unsigned int inputs() const
Definition: schema.h:128
schema * fSchema2
Definition: seqSchema.h:39
bool placed() const
Definition: schema.h:137
schema * fSchema1
Definition: seqSchema.h:38

Here is the call graph for this function:

void seqSchema::draw ( device dev)
virtual

Draw the two components as well as the internal wires.

Implements schema.

Definition at line 125 of file seqSchema.cpp.

References schema::draw(), fSchema1, fSchema2, schema::inputs(), schema::outputs(), and schema::placed().

126 {
127  assert(placed());
128  assert(fSchema1->outputs() == fSchema2->inputs());
129 
130  fSchema1->draw(dev);
131  fSchema2->draw(dev);
132  //drawInternalWires(dev);
133 }
unsigned int outputs() const
Definition: schema.h:129
virtual void draw(device &dev)=0
unsigned int inputs() const
Definition: schema.h:128
schema * fSchema2
Definition: seqSchema.h:39
bool placed() const
Definition: schema.h:137
schema * fSchema1
Definition: seqSchema.h:38

Here is the call graph for this function:

void seqSchema::drawInternalWires ( device dev)
private

Draw the internal wires aligning the vertical segments in a symetric way when possible.

Definition at line 154 of file seqSchema.cpp.

References direction(), dWire, fHorzGap, fSchema1, fSchema2, schema::inputPoint(), schema::inputs(), kDownDir, kLeftRight, kUpDir, schema::orientation(), schema::outputPoint(), schema::outputs(), device::trait(), point::x, and point::y.

155 {
156  assert (fSchema1->outputs() == fSchema2->inputs());
157 
158  const int N = fSchema1->outputs();
159  double dx = 0;
160  double mx = 0;
161  int dir =-1;
162 
163  if (orientation() == kLeftRight) {
164  // draw left right cables
165  for (int i=0; i<N; i++) {
166  point src = fSchema1->outputPoint(i);
167  point dst = fSchema2->inputPoint(i);
168 
169  int d = direction(src,dst);
170  if (d != dir) {
171  // compute attributes of new direction
172  switch (d) {
173  case kUpDir : mx = 0; dx = dWire; break;
174  case kDownDir : mx = fHorzGap; dx = -dWire; break;
175  default : mx = 0; dx = 0; break;
176  }
177  dir = d;
178  } else {
179  // move in same direction
180  mx = mx +dx;
181  }
182  if (src.y == dst.y) {
183  // draw straight cable
184  dev.trait(src.x, src.y, dst.x, dst.y);
185  } else {
186  // draw zizag cable
187  dev.trait(src.x, src.y, src.x+mx, src.y);
188  dev.trait(src.x+mx, src.y, src.x+mx, dst.y);
189  dev.trait(src.x+mx, dst.y, dst.x, dst.y);
190  }
191 
192  }
193  } else {
194  // draw right left cables
195  for (int i=0; i<N; i++) {
196  point src = fSchema1->outputPoint(i);
197  point dst = fSchema2->inputPoint(i);
198 
199  int d = direction(src,dst);
200  if (d != dir) {
201  // compute attributes of new direction
202  switch (d) {
203  case kUpDir : mx = -fHorzGap; dx = dWire; break;
204  case kDownDir : mx = 0; dx = -dWire; break;
205  default : mx = 0; dx = 0; break;
206  }
207  dir = d;
208  } else {
209  // move in same direction
210  mx = mx +dx;
211  }
212  if (src.y == dst.y) {
213  // draw straight cable
214  dev.trait(src.x, src.y, dst.x, dst.y);
215  } else {
216  // draw zizag cable
217  dev.trait(src.x, src.y, src.x+mx, src.y);
218  dev.trait(src.x+mx, src.y, src.x+mx, dst.y);
219  dev.trait(src.x+mx, dst.y, dst.x, dst.y);
220  }
221 
222  }
223  }
224 }
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
unsigned int inputs() const
Definition: schema.h:128
static int direction(const point &a, const point &b)
Compute the direction of a connection.
Definition: seqSchema.cpp:313
double y
Definition: schema.h:43
schema * fSchema2
Definition: seqSchema.h:39
int orientation() const
Definition: schema.h:140
double x
Definition: schema.h:42
Definition: schema.h:40
virtual point outputPoint(unsigned int i) const =0
double fHorzGap
Definition: seqSchema.h:40
virtual void trait(double x1, double y1, double x2, double y2)=0
schema * fSchema1
Definition: seqSchema.h:38

Here is the call graph for this function:

point seqSchema::inputPoint ( unsigned int  i) const
virtual

The input points are the input points of the first component.

Implements schema.

Definition at line 103 of file seqSchema.cpp.

References fSchema1, and schema::inputPoint().

104 {
105  return fSchema1->inputPoint(i);
106 }
virtual point inputPoint(unsigned int i) const =0
schema * fSchema1
Definition: seqSchema.h:38

Here is the call graph for this function:

point seqSchema::outputPoint ( unsigned int  i) const
virtual

The output points are the output points of the second component.

Implements schema.

Definition at line 112 of file seqSchema.cpp.

References fSchema2, and schema::outputPoint().

113 {
114  return fSchema2->outputPoint(i);
115 }
schema * fSchema2
Definition: seqSchema.h:39
virtual point outputPoint(unsigned int i) const =0

Here is the call graph for this function:

void seqSchema::place ( double  ox,
double  oy,
int  orientation 
)
virtual

Place the two components horizontally with enough space for the connections.

Implements schema.

Definition at line 82 of file seqSchema.cpp.

References schema::beginPlace(), schema::endPlace(), fHorzGap, fSchema1, fSchema2, schema::height(), kLeftRight, max(), schema::orientation(), schema::place(), and schema::width().

83 {
84  beginPlace(ox, oy, orientation);
85 
86  double y1 = max(0.0, 0.5*(fSchema2->height() - fSchema1->height()));
87  double y2 = max(0.0, 0.5*(fSchema1->height() - fSchema2->height()));
88 
89  if (orientation == kLeftRight) {
90  fSchema1->place(ox, oy+y1, orientation);
92  } else {
93  fSchema2->place(ox, oy+y2, orientation);
95  }
96  endPlace();
97 }
void endPlace()
Definition: schema.h:134
void beginPlace(double x, double y, int orientation)
Definition: schema.h:132
double max(double x, double y)
Definition: interval.hh:60
double width() const
Definition: schema.h:126
schema * fSchema2
Definition: seqSchema.h:39
int orientation() const
Definition: schema.h:140
virtual void place(double x, double y, int orientation)=0
double height() const
Definition: schema.h:127
double fHorzGap
Definition: seqSchema.h:40
schema * fSchema1
Definition: seqSchema.h:38

Here is the call graph for this function:

Friends And Related Function Documentation

schema* makeSeqSchema ( schema s1,
schema s2 
)
friend

Make a sequential schema.

May add cables to ensure the internal connections are between the same number of outputs and inputs. Compute an horizontal gap based on the number of upward and downward connections.

Definition at line 43 of file seqSchema.cpp.

44 {
45  unsigned int o = s1->outputs();
46  unsigned int i = s2->inputs();
47 
48  schema* a = (o < i) ? makeParSchema(s1, makeCableSchema(i-o)) : s1;
49  schema* b = (o > i) ? makeParSchema(s2, makeCableSchema(o-i)) : s2;
50 
51  return new seqSchema(a, b, computeHorzGap(a,b));
52 }
unsigned int outputs() const
Definition: schema.h:129
schema * makeParSchema(schema *s1, schema *s2)
Definition: parSchema.cpp:28
unsigned int inputs() const
Definition: schema.h:128
static double computeHorzGap(schema *a, schema *b)
Compute the horizontal gap needed to draw the internal wires.
Definition: seqSchema.cpp:325
seqSchema(schema *s1, schema *s2, double hgap)
Constructor for a sequential schema (s1:s2).
Definition: seqSchema.cpp:62
An abstract block diagram schema.
Definition: schema.h:97
schema * makeCableSchema(unsigned int n)
Build n cables in parallel.
Definition: cableSchema.cpp:32

Member Data Documentation

double seqSchema::fHorzGap
private

Definition at line 40 of file seqSchema.h.

Referenced by collectInternalWires(), drawInternalWires(), and place().

schema* seqSchema::fSchema1
private
schema* seqSchema::fSchema2
private

The documentation for this class was generated from the following files: