FAUST compiler  0.9.9.6b8
decorateSchema.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 #include "decorateSchema.h"
23 #include <iostream>
24 #include <assert.h>
25 
26 using namespace std;
27 
31 schema* makeDecorateSchema ( schema* s, double margin, const string& text )
32 {
33  return new decorateSchema (s, margin, text);
34 }
35 
36 
43 decorateSchema::decorateSchema( schema* s, double margin, const string& text )
44  : schema(s->inputs(), s->outputs(), s->width()+2*margin, s->height()+2*margin),
45  fSchema(s),
46  fMargin(margin),
47  fText(text)
48 {
49  for (unsigned int i=0; i<inputs(); i++) fInputPoint.push_back(point(0,0));
50  for (unsigned int i=0; i<outputs(); i++) fOutputPoint.push_back(point(0,0));
51 }
52 
53 
59 void decorateSchema::place(double ox, double oy, int orientation)
60 {
61  beginPlace(ox, oy, orientation);
62 
63  fSchema->place(ox+fMargin, oy+fMargin, orientation);
64 
65  double m = fMargin;
66  if (orientation == kRightLeft) {
67  m = -m;
68  }
69 
70  for (unsigned int i=0; i < inputs(); i++) {
71  point p = fSchema->inputPoint(i);
72  fInputPoint[i] = point(p.x-m, p.y); //, p.z);
73  }
74 
75  for (unsigned int i=0; i < outputs(); i++) {
76  point p = fSchema->outputPoint(i);
77  fOutputPoint[i] = point(p.x+m, p.y); //, p.z);
78  }
79 
80  endPlace();
81 }
82 
86 point decorateSchema::inputPoint(unsigned int i) const
87 {
88  assert (placed());
89  assert (i < inputs());
90  return fInputPoint[i];
91 }
92 
96 point decorateSchema::outputPoint(unsigned int i) const
97 {
98  assert (placed());
99  assert (i < outputs());
100  return fOutputPoint[i];
101 }
102 
108 {
109  assert(placed());
110 
111  fSchema->draw(dev);
112 #if 0
113  // draw enlarge input wires
114  for (unsigned int i=0; i<inputs(); i++) {
115  point p = inputPoint(i);
116  point q = fSchema->inputPoint(i);
117  dev.trait(p.x, p.y, q.x, q.y);
118  }
119 
120  // draw enlarge output wires
121  for (unsigned int i=0; i<outputs(); i++) {
122  point p = outputPoint(i);
123  point q = fSchema->outputPoint(i);
124  dev.trait(p.x, p.y, q.x, q.y);
125  }
126 #endif
127  // define the coordinates of the frame
128  double tw = (2+fText.size())*dLetter*0.75;
129  double x0 = x() + fMargin/2; // left
130  double y0 = y() + fMargin/2; // top
131  double x1 = x() + width() - fMargin/2; // right
132  double y1 = y() + height() - fMargin/2; // bottom
133  //double tl = x0 + 2*dWire; // left of text zone
134  double tl = x() + fMargin; // left of text zone
135  double tr = min(tl+tw, x1); // right of text zone
136 
137  // draw the surronding frame
138  dev.dasharray(x0, y0, x0, y1); // left line
139  dev.dasharray(x0, y1, x1, y1); // bottom line
140  dev.dasharray(x1, y1, x1, y0); // right line
141  dev.dasharray(x0, y0, tl, y0); // top segment before text
142  dev.dasharray(tr, y0, x1, y0); // top segment after text
143 
144  // draw the label
145  dev.label(tl, y0, fText.c_str()); //
146 }
147 
153 {
154  assert(placed());
155 
157 
158  // draw enlarge input wires
159  for (unsigned int i=0; i<inputs(); i++) {
160  point p = inputPoint(i);
161  point q = fSchema->inputPoint(i);
162  c.addTrait(trait(p,q)); // in->out direction
163  }
164 
165  // draw enlarge output wires
166  for (unsigned int i=0; i<outputs(); i++) {
167  point p = fSchema->outputPoint(i);
168  point q = outputPoint(i);
169  c.addTrait(trait(p,q)); // in->out direction
170  }
171 }
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
virtual point inputPoint(unsigned int i) const =0
void beginPlace(double x, double y, int orientation)
Definition: schema.h:132
A decorateSchema is a schema surrounded by a dashed rectangle with a label on the top left...
virtual void draw(device &dev)
Draw the enlarged schema.
virtual void draw(device &dev)=0
virtual point inputPoint(unsigned int i) const
Returns an input point.
virtual void collectTraits(collector &c)=0
virtual void label(double x, double y, const char *name)=0
decorateSchema(schema *s1, double margin, const string &text)
A decorateSchema is a schema surrounded by a dashed rectangle with a label on the top left...
unsigned int inputs() const
Definition: schema.h:128
double y() const
Definition: schema.h:139
double width() const
Definition: schema.h:126
double y
Definition: schema.h:43
schema * fSchema
bool placed() const
Definition: schema.h:137
virtual void place(double ox, double oy, int orientation)
Define the graphic position of the schema.
schema * makeDecorateSchema(schema *s, double margin, const string &text)
Creates a new decorated schema.
Definition: device.h:32
double x() const
Definition: schema.h:138
virtual void place(double x, double y, int orientation)=0
vector< point > fInputPoint
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 point outputPoint(unsigned int i) const
Returns an output point.
virtual void collectTraits(collector &c)
Draw the enlarged schema.
const double dLetter
width of a letter
Definition: schema.h:35
double min(double x, double y)
Definition: interval.hh:59
Tree tl(Tree l)
Definition: list.hh:134
virtual void dasharray(double x1, double y1, double x2, double y2)=0
virtual void trait(double x1, double y1, double x2, double y2)=0
vector< point > fOutputPoint