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

A simple rectangular box with a text and inputs and outputs. More...

#include <blockSchema.h>

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

Public Member Functions

virtual void place (double x, double y, int orientation)
 Define the graphic position of the blockSchema. More...
 
virtual void draw (device &dev)
 Draw the blockSchema on the device. More...
 
virtual point inputPoint (unsigned int i) const
 Returns an input point. More...
 
virtual point outputPoint (unsigned int i) const
 Returns an output point. More...
 
virtual void collectTraits (collector &c)
 Draw horizontal arrows from the input points to the blockSchema rectangle. 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
 

Protected Member Functions

 blockSchema (unsigned int inputs, unsigned int outputs, double width, double height, const string &name, const string &color, const string &link)
 Build a simple colored blockSchema with a certain number of inputs and outputs, a text to be displayed, and an optional link. More...
 
void placeInputPoints ()
 Computes the input points according to the position and the orientation of the blockSchema. More...
 
void placeOutputPoints ()
 Computes the output points according to the position and the orientation of the blockSchema. More...
 
void drawRectangle (device &dev)
 Draw the colored rectangle with the optional link. More...
 
void drawText (device &dev)
 Draw the text centered on the box. More...
 
void drawOrientationMark (device &dev)
 Draw the orientation mark, a small point that indicates the first input (like integrated circuits) More...
 
void drawInputArrows (device &dev)
 Draw horizontal arrows from the input points to the blockSchema rectangle. More...
 
void collectInputWires (collector &c)
 Draw horizontal arrows from the input points to the blockSchema rectangle. More...
 
void collectOutputWires (collector &c)
 Draw horizontal line from the blockSchema rectangle to the output points. More...
 

Protected Attributes

const string fText
 Text to be displayed. More...
 
const string fColor
 color of the box More...
 
const string fLink
 option URL link More...
 
vector< pointfInputPoint
 input connection points More...
 
vector< pointfOutputPoint
 output connection points More...
 

Friends

schemamakeBlockSchema (unsigned int inputs, unsigned int outputs, const string &name, const string &color, const string &link)
 Build a simple colored blockSchema with a certain number of inputs and outputs, a text to be displayed, and an optional link. More...
 

Detailed Description

A simple rectangular box with a text and inputs and outputs.

The constructor is private in order to make sure makeBlockSchema is used instead

Definition at line 35 of file blockSchema.h.

Constructor & Destructor Documentation

blockSchema::blockSchema ( unsigned int  inputs,
unsigned int  outputs,
double  width,
double  height,
const string &  text,
const string &  color,
const string &  link 
)
protected

Build a simple colored blockSchema with a certain number of inputs and outputs, a text to be displayed, and an optional link.

The length of the text as well as th number of inputs and outputs are used to compute the size of the blockSchema

Definition at line 62 of file blockSchema.cpp.

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

71  fText(text),
72  fColor(color),
73  fLink(link)
74 {
75  for (unsigned int i=0; i<inputs; i++) fInputPoint.push_back(point(0,0));
76  for (unsigned int i=0; i<outputs; i++) fOutputPoint.push_back(point(0,0));
77 }
vector< point > fInputPoint
input connection points
Definition: blockSchema.h:43
const string fLink
option URL link
Definition: blockSchema.h:40
unsigned int outputs() const
Definition: schema.h:129
const string fText
Text to be displayed.
Definition: blockSchema.h:38
vector< point > fOutputPoint
output connection points
Definition: blockSchema.h:44
unsigned int inputs() const
Definition: schema.h:128
double width() const
Definition: schema.h:126
schema(unsigned int inputs, unsigned int outputs, double width, double height)
Definition: schema.h:113
Definition: schema.h:40
double height() const
Definition: schema.h:127
const string fColor
color of the box
Definition: blockSchema.h:39

Here is the call graph for this function:

Member Function Documentation

void blockSchema::collectInputWires ( collector c)
protected

Draw horizontal arrows from the input points to the blockSchema rectangle.

Definition at line 265 of file blockSchema.cpp.

References collector::addInput(), collector::addTrait(), dHorz, fInputPoint, schema::inputs(), kLeftRight, schema::orientation(), point::x, and point::y.

Referenced by collectTraits().

266 {
267  double dx = (orientation() == kLeftRight) ? dHorz : -dHorz;
268 
269  for (unsigned int i=0; i<inputs(); i++) {
270  point p = fInputPoint[i];
271  c.addTrait(trait(point(p.x, p.y), point(p.x+dx, p.y))); // in->out direction
272  c.addInput(point(p.x+dx, p.y));
273  }
274 }
vector< point > fInputPoint
input connection points
Definition: blockSchema.h:43
void addTrait(const trait &t)
Definition: schema.h:84
Definition: schema.h:56
unsigned int inputs() const
Definition: schema.h:128
double y
Definition: schema.h:43
int orientation() const
Definition: schema.h:140
double x
Definition: schema.h:42
Definition: schema.h:40
const double dHorz
marge horizontale
Definition: schema.h:36
void addInput(const point &p)
Definition: schema.h:83

Here is the call graph for this function:

Here is the caller graph for this function:

void blockSchema::collectOutputWires ( collector c)
protected

Draw horizontal line from the blockSchema rectangle to the output points.

Definition at line 280 of file blockSchema.cpp.

References collector::addOutput(), collector::addTrait(), dHorz, fOutputPoint, kLeftRight, schema::orientation(), schema::outputs(), point::x, and point::y.

Referenced by collectTraits().

281 {
282  double dx = (orientation() == kLeftRight) ? dHorz : -dHorz;
283 
284  for (unsigned int i=0; i<outputs(); i++) {
285  point p = fOutputPoint[i];
286  c.addTrait(trait(point(p.x-dx, p.y), point(p.x, p.y))); // in->out direction
287  c.addOutput(point(p.x-dx, p.y));
288  }
289 }
void addOutput(const point &p)
Definition: schema.h:82
void addTrait(const trait &t)
Definition: schema.h:84
Definition: schema.h:56
unsigned int outputs() const
Definition: schema.h:129
vector< point > fOutputPoint
output connection points
Definition: blockSchema.h:44
double y
Definition: schema.h:43
int orientation() const
Definition: schema.h:140
double x
Definition: schema.h:42
Definition: schema.h:40
const double dHorz
marge horizontale
Definition: schema.h:36

Here is the call graph for this function:

Here is the caller graph for this function:

void blockSchema::collectTraits ( collector c)
virtual

Draw horizontal arrows from the input points to the blockSchema rectangle.

Implements schema.

Definition at line 255 of file blockSchema.cpp.

References collectInputWires(), and collectOutputWires().

256 {
259 }
void collectOutputWires(collector &c)
Draw horizontal line from the blockSchema rectangle to the output points.
void collectInputWires(collector &c)
Draw horizontal arrows from the input points to the blockSchema rectangle.

Here is the call graph for this function:

void blockSchema::draw ( device dev)
virtual

Draw the blockSchema on the device.

This methos can only be called after the blockSchema have been placed

Implements schema.

Reimplemented in inverterSchema.

Definition at line 180 of file blockSchema.cpp.

References drawInputArrows(), drawOrientationMark(), drawRectangle(), drawText(), and schema::placed().

181 {
182  assert(placed());
183 
184  drawRectangle(dev);
185  drawText(dev);
186  drawOrientationMark(dev);
187  drawInputArrows(dev);
188 }
void drawText(device &dev)
Draw the text centered on the box.
bool placed() const
Definition: schema.h:137
void drawInputArrows(device &dev)
Draw horizontal arrows from the input points to the blockSchema rectangle.
void drawOrientationMark(device &dev)
Draw the orientation mark, a small point that indicates the first input (like integrated circuits) ...
void drawRectangle(device &dev)
Draw the colored rectangle with the optional link.

Here is the call graph for this function:

void blockSchema::drawInputArrows ( device dev)
protected

Draw horizontal arrows from the input points to the blockSchema rectangle.

Definition at line 240 of file blockSchema.cpp.

References dHorz, fInputPoint, device::fleche(), schema::inputs(), kLeftRight, schema::orientation(), point::x, and point::y.

Referenced by draw().

241 {
242  double dx = (orientation() == kLeftRight) ? dHorz : -dHorz;
243 
244  for (unsigned int i=0; i<inputs(); i++) {
245  point p = fInputPoint[i];
246  dev.fleche(p.x+dx, p.y, 0, orientation());
247  }
248 }
vector< point > fInputPoint
input connection points
Definition: blockSchema.h:43
unsigned int inputs() const
Definition: schema.h:128
double y
Definition: schema.h:43
int orientation() const
Definition: schema.h:140
double x
Definition: schema.h:42
Definition: schema.h:40
virtual void fleche(double x, double y, double rotation, int sens)=0
const double dHorz
marge horizontale
Definition: schema.h:36

Here is the call graph for this function:

Here is the caller graph for this function:

void blockSchema::drawOrientationMark ( device dev)
protected

Draw the orientation mark, a small point that indicates the first input (like integrated circuits)

Definition at line 222 of file blockSchema.cpp.

References dHorz, dVert, schema::height(), kLeftRight, device::markSens(), schema::orientation(), schema::width(), schema::x(), and schema::y().

Referenced by draw().

223 {
224  double px, py;
225 
226  if (orientation() == kLeftRight) {
227  px = x() + dHorz;
228  py = y() + dVert;
229  } else {
230  px = x() + width() - dHorz;
231  py = y() + height() - dVert;
232  }
233 
234  dev.markSens( px, py, orientation() );
235 }
const double dVert
marge verticale
Definition: schema.h:37
double y() const
Definition: schema.h:139
double width() const
Definition: schema.h:126
double x() const
Definition: schema.h:138
int orientation() const
Definition: schema.h:140
double height() const
Definition: schema.h:127
const double dHorz
marge horizontale
Definition: schema.h:36
virtual void markSens(double x, double y, int sens)=0

Here is the call graph for this function:

Here is the caller graph for this function:

void blockSchema::drawRectangle ( device dev)
protected

Draw the colored rectangle with the optional link.

Definition at line 193 of file blockSchema.cpp.

References dHorz, dVert, fColor, fLink, schema::height(), device::rect(), schema::width(), schema::x(), and schema::y().

Referenced by draw().

194 {
195  dev.rect( x() + dHorz,
196  y() + dVert,
197  width() - 2*dHorz,
198  height() - 2*dVert,
199  fColor.c_str(),
200  fLink.c_str()
201  );
202 }
const string fLink
option URL link
Definition: blockSchema.h:40
const double dVert
marge verticale
Definition: schema.h:37
double y() const
Definition: schema.h:139
double width() const
Definition: schema.h:126
virtual void rect(double x, double y, double l, double h, const char *color, const char *link)=0
double x() const
Definition: schema.h:138
double height() const
Definition: schema.h:127
const double dHorz
marge horizontale
Definition: schema.h:36
const string fColor
color of the box
Definition: blockSchema.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

void blockSchema::drawText ( device dev)
protected

Draw the text centered on the box.

Definition at line 208 of file blockSchema.cpp.

References fLink, fText, schema::height(), device::text(), schema::width(), schema::x(), and schema::y().

Referenced by draw().

209 {
210  dev.text( x() + width()/2,
211  y() + height()/2,
212  fText.c_str(),
213  fLink.c_str()
214  );
215 }
const string fLink
option URL link
Definition: blockSchema.h:40
const string fText
Text to be displayed.
Definition: blockSchema.h:38
virtual void text(double x, double y, const char *name, const char *link)=0
double y() const
Definition: schema.h:139
double width() const
Definition: schema.h:126
double x() const
Definition: schema.h:138
double height() const
Definition: schema.h:127

Here is the call graph for this function:

Here is the caller graph for this function:

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

Returns an input point.

Implements schema.

Definition at line 99 of file blockSchema.cpp.

References fInputPoint, schema::inputs(), and schema::placed().

100 {
101  assert (placed());
102  assert (i < inputs());
103  return fInputPoint[i];
104 }
vector< point > fInputPoint
input connection points
Definition: blockSchema.h:43
unsigned int inputs() const
Definition: schema.h:128
bool placed() const
Definition: schema.h:137

Here is the call graph for this function:

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

Returns an output point.

Implements schema.

Definition at line 110 of file blockSchema.cpp.

References fOutputPoint, schema::outputs(), and schema::placed().

111 {
112  assert (placed());
113  assert (i < outputs());
114  return fOutputPoint[i];
115 }
unsigned int outputs() const
Definition: schema.h:129
vector< point > fOutputPoint
output connection points
Definition: blockSchema.h:44
bool placed() const
Definition: schema.h:137

Here is the call graph for this function:

void blockSchema::place ( double  x,
double  y,
int  orientation 
)
virtual

Define the graphic position of the blockSchema.

Computes the graphic position of all the elements, in particular the inputs and outputs. This method must be called before draw(), otherwise draw is not allowed

Implements schema.

Definition at line 85 of file blockSchema.cpp.

References schema::beginPlace(), schema::endPlace(), placeInputPoints(), and placeOutputPoints().

86 {
88 
91 
92  endPlace();
93 }
void endPlace()
Definition: schema.h:134
void placeInputPoints()
Computes the input points according to the position and the orientation of the blockSchema.
void beginPlace(double x, double y, int orientation)
Definition: schema.h:132
void placeOutputPoints()
Computes the output points according to the position and the orientation of the blockSchema.
double y() const
Definition: schema.h:139
double x() const
Definition: schema.h:138
int orientation() const
Definition: schema.h:140

Here is the call graph for this function:

void blockSchema::placeInputPoints ( )
protected

Computes the input points according to the position and the orientation of the blockSchema.

Definition at line 122 of file blockSchema.cpp.

References dWire, fInputPoint, schema::height(), schema::inputs(), kLeftRight, schema::orientation(), schema::width(), schema::x(), and schema::y().

Referenced by place().

123 {
124  int N = inputs();
125 
126  if (orientation() == kLeftRight) {
127 
128  double px = x();
129  double py = y() + (height() - dWire*(N-1))/2;
130 
131  for (int i=0; i<N; i++) {
132  fInputPoint[i] = point(px, py+i*dWire);
133  }
134 
135  } else {
136 
137  double px = x() + width();
138  double py = y() + height() - (height() - dWire*(N-1))/2;
139 
140  for (int i=0; i<N; i++) {
141  fInputPoint[i] = point(px, py-i*dWire);
142  }
143  }
144 }
vector< point > fInputPoint
input connection points
Definition: blockSchema.h:43
const double dWire
distance between two wires
Definition: schema.h:33
unsigned int inputs() const
Definition: schema.h:128
double y() const
Definition: schema.h:139
double width() const
Definition: schema.h:126
double x() const
Definition: schema.h:138
int orientation() const
Definition: schema.h:140
Definition: schema.h:40
double height() const
Definition: schema.h:127

Here is the call graph for this function:

Here is the caller graph for this function:

void blockSchema::placeOutputPoints ( )
protected

Computes the output points according to the position and the orientation of the blockSchema.

Definition at line 151 of file blockSchema.cpp.

References dWire, fOutputPoint, schema::height(), kLeftRight, schema::orientation(), schema::outputs(), schema::width(), schema::x(), and schema::y().

Referenced by place().

152 {
153  int N = outputs();
154 
155  if (orientation() == kLeftRight) {
156 
157  double px = x() + width();
158  double py = y() + (height() - dWire*(N-1))/2;
159 
160  for (int i=0; i<N; i++) {
161  fOutputPoint[i] = point(px, py + i*dWire);
162  }
163 
164  } else {
165 
166  double px = x();
167  double py = y() + height() - (height() - dWire*(N-1))/2;
168 
169  for (int i=0; i<N; i++) {
170  fOutputPoint[i] = point(px, py - i*dWire);
171  }
172  }
173 }
unsigned int outputs() const
Definition: schema.h:129
const double dWire
distance between two wires
Definition: schema.h:33
vector< point > fOutputPoint
output connection points
Definition: blockSchema.h:44
double y() const
Definition: schema.h:139
double width() const
Definition: schema.h:126
double x() const
Definition: schema.h:138
int orientation() const
Definition: schema.h:140
Definition: schema.h:40
double height() const
Definition: schema.h:127

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

schema* makeBlockSchema ( unsigned int  inputs,
unsigned int  outputs,
const string &  name,
const string &  color,
const string &  link 
)
friend

Build a simple colored blockSchema with a certain number of inputs and outputs, a text to be displayed, and an optional link.

Computes the size of the box according to the length of the text and the maximum number of ports.

Definition at line 41 of file blockSchema.cpp.

46 {
47  // determine the optimal size of the box
48  double minimal = 3*dWire;
49  double w = 2*dHorz + max( minimal, quantize((int)text.size()) );
50  double h = 2*dVert + max( minimal, max(inputs, outputs) * dWire );
51 
52  return new blockSchema(inputs, outputs, w, h, text, color, link);
53 }
unsigned int outputs() const
Definition: schema.h:129
const double dWire
distance between two wires
Definition: schema.h:33
const double dVert
marge verticale
Definition: schema.h:37
unsigned int inputs() const
Definition: schema.h:128
double max(double x, double y)
Definition: interval.hh:60
static double quantize(int n)
Definition: blockSchema.cpp:28
blockSchema(unsigned int inputs, unsigned int outputs, double width, double height, const string &name, const string &color, const string &link)
Build a simple colored blockSchema with a certain number of inputs and outputs, a text to be displaye...
Definition: blockSchema.cpp:62
const double dHorz
marge horizontale
Definition: schema.h:36

Member Data Documentation

const string blockSchema::fColor
protected

color of the box

Definition at line 39 of file blockSchema.h.

Referenced by inverterSchema::draw(), and drawRectangle().

vector<point> blockSchema::fInputPoint
protected

input connection points

Definition at line 43 of file blockSchema.h.

Referenced by blockSchema(), collectInputWires(), drawInputArrows(), inputPoint(), and placeInputPoints().

const string blockSchema::fLink
protected

option URL link

Definition at line 40 of file blockSchema.h.

Referenced by inverterSchema::draw(), drawRectangle(), and drawText().

vector<point> blockSchema::fOutputPoint
protected

output connection points

Definition at line 44 of file blockSchema.h.

Referenced by blockSchema(), collectOutputWires(), outputPoint(), and placeOutputPoints().

const string blockSchema::fText
protected

Text to be displayed.

Definition at line 38 of file blockSchema.h.

Referenced by drawText().


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