FAUST compiler  0.9.9.6b8
connectorSchema.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 "connectorSchema.h"
24 #include <assert.h>
25 
26 using namespace std;
27 
28 
34 {
35  return new connectorSchema();
36 }
37 
43 {
44  fInputPoint.push_back(point(0,0));
45  fOutputPoint.push_back(point(0,0));
46 }
47 
53 void connectorSchema::place(double x, double y, int orientation)
54 {
55  beginPlace(x, y, orientation);
56 
59 
60  endPlace();
61 }
62 
66 point connectorSchema::inputPoint(unsigned int i) const
67 {
68  assert (placed());
69  assert (i < inputs());
70  return fInputPoint[i];
71 }
72 
76 point connectorSchema::outputPoint(unsigned int i) const
77 {
78  assert (placed());
79  assert (i < outputs());
80  return fOutputPoint[i];
81 }
82 
88 {
89  int N = inputs();
90 
91  if (orientation() == kLeftRight) {
92 
93  double px = x();
94  double py = y() + (height() - dWire*(N-1))/2;
95 
96  for (int i=0; i<N; i++) {
97  fInputPoint[i] = point(px, py+i*dWire);
98  }
99 
100  } else {
101 
102  double px = x() + width();
103  double py = y() + height() - (height() - dWire*(N-1))/2;
104 
105  for (int i=0; i<N; i++) {
106  fInputPoint[i] = point(px, py-i*dWire);
107  }
108  }
109 }
110 
111 
117 {
118  int N = outputs();
119 
120  if (orientation() == kLeftRight) {
121 
122  double px = x() + width();
123  double py = y() + (height() - dWire*(N-1))/2;
124 
125  for (int i=0; i<N; i++) {
126  fOutputPoint[i] = point(px, py + i*dWire);
127  }
128 
129  } else {
130 
131  double px = x();
132  double py = y() + height() - (height() - dWire*(N-1))/2;
133 
134  for (int i=0; i<N; i++) {
135  fOutputPoint[i] = point(px, py - i*dWire);
136  }
137  }
138 }
139 
140 
146 {
147  assert(placed());
148  // nothing to do
149 }
150 
156 {
159 }
160 
161 
167 {
168  double dx = (orientation() == kLeftRight) ? dHorz : -dHorz;
169 
170  for (unsigned int i=0; i<inputs(); i++) {
171  point p = fInputPoint[i];
172  c.addTrait(trait(point(p.x, p.y), point(p.x+dx, p.y))); // in->out direction
173  c.addInput(point(p.x+dx, p.y));
174  }
175 }
176 
177 
183 {
184  double dx = (orientation() == kLeftRight) ? dHorz : -dHorz;
185 
186  for (unsigned int i=0; i<outputs(); i++) {
187  point p = fOutputPoint[i];
188  c.addTrait(trait(point(p.x-dx, p.y), point(p.x, p.y))); // in->out direction
189  c.addOutput(point(p.x-dx, p.y));
190  }
191 }
192 
193 
void addOutput(const point &p)
Definition: schema.h:82
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
void beginPlace(double x, double y, int orientation)
Definition: schema.h:132
vector< point > fOutputPoint
output connection points
A simple rectangular box with a text and inputs and outputs.
virtual point inputPoint(unsigned int i) const
Returns an input point.
void collectOutputWires(collector &c)
Draw horizontal line from the connectorSchema rectangle to the output points.
unsigned int inputs() const
Definition: schema.h:128
schema * makeConnectorSchema()
Connectors are used to ensure unused inputs and outputs are drawn.
void placeOutputPoints()
Computes the output points according to the position and the orientation of the connectorSchema.
void placeInputPoints()
Computes the input points according to the position and the orientation of the connectorSchema.
double y() const
Definition: schema.h:139
double width() const
Definition: schema.h:126
double y
Definition: schema.h:43
bool placed() const
Definition: schema.h:137
vector< point > fInputPoint
input connection points
virtual point outputPoint(unsigned int i) const
Returns an output point.
Definition: device.h:32
double x() const
Definition: schema.h:138
int orientation() const
Definition: schema.h:140
virtual void draw(device &dev)
Draw the connectorSchema on the device.
virtual void collectTraits(collector &c)
Draw horizontal arrows from the input points to the connectorSchema rectangle.
double x
Definition: schema.h:42
void collectInputWires(collector &c)
Draw horizontal arrows from the input points to the connectorSchema rectangle.
Definition: schema.h:40
An abstract block diagram schema.
Definition: schema.h:97
virtual void place(double x, double y, int orientation)
Define the graphic position of the connectorSchema.
double height() const
Definition: schema.h:127
const double dHorz
marge horizontale
Definition: schema.h:36
void addInput(const point &p)
Definition: schema.h:83
connectorSchema()
A connector is an invisible square fo dWire size with 1 input and 1 output.