FAUST compiler  0.9.9.6b8
topSchema.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 <stdlib.h>
23 #include "topSchema.h"
24 #include <iostream>
25 #include <assert.h>
26 #include <cstdlib>
27 
28 using namespace std;
29 
33 schema* makeTopSchema (schema* s, double margin, const string& text, const string& link)
34 {
35  return new topSchema (makeDecorateSchema(s, margin/2, text), margin/2, "", link);
36 }
37 
38 
45 topSchema::topSchema( schema* s, double margin, const string& text, const string& link )
46  : schema(0, 0, s->width()+2*margin, s->height()+2*margin),
47  fSchema(s),
48  fMargin(margin),
49  fText(text),
50  fLink(link)
51 {
52 }
53 
54 
60 void topSchema::place(double ox, double oy, int orientation)
61 {
62  beginPlace(ox, oy, orientation);
63 
64  fSchema->place(ox+fMargin, oy+fMargin, orientation);
65  endPlace();
66 }
67 
71 point topSchema::inputPoint(unsigned int i) const
72 {
73  assert (placed());
74  assert (i < inputs());
75  exit(1);
76 }
77 
81 point topSchema::outputPoint(unsigned int i) const
82 {
83  assert (placed());
84  assert (i < outputs());
85  exit(1);
86 }
87 
93 {
94  assert(placed());
95 
96  // draw a background white rectangle
97  dev.rect(x(), y(), width()-1, height()-1, "#ffffff", fLink.c_str());
98 
99  // draw the label
100  dev.label(x()+fMargin, y()+fMargin/2, fText.c_str());
101 
102  fSchema->draw(dev);
103 
104  // draw arrows at output points of schema
105  for (unsigned int i=0; i<fSchema->outputs(); i++) {
106  point p = fSchema->outputPoint(i);
107  dev.fleche(p.x, p.y, 0, orientation());
108  }
109 }
110 
116 {
117  assert(placed());
119 
120  // draw arrows at output points of schema
121  for (unsigned int i=0; i<fSchema->inputs(); i++) {
122  point p = fSchema->inputPoint(i);
123  c.addOutput(p);;
124  }
125 
126  // draw arrows at output points of schema
127  for (unsigned int i=0; i<fSchema->outputs(); i++) {
128  point p = fSchema->outputPoint(i);
129  c.addInput(p);;
130  }
131 
132 
133 }
void addOutput(const point &p)
Definition: schema.h:82
void endPlace()
Definition: schema.h:134
unsigned int outputs() const
Definition: schema.h:129
double fMargin
Definition: topSchema.h:37
topSchema(schema *s1, double margin, const string &text, const string &link)
A topSchema is a schema surrounded by a dashed rectangle with a label on the top left.
Definition: topSchema.cpp:45
virtual point inputPoint(unsigned int i) const =0
void beginPlace(double x, double y, int orientation)
Definition: schema.h:132
virtual point outputPoint(unsigned int i) const
Top schema has no output.
Definition: topSchema.cpp:81
virtual void draw(device &dev)=0
string fLink
Definition: topSchema.h:39
A topSchema is a schema surrounded by a dashed rectangle with a label on the top left.
Definition: topSchema.h:34
virtual void collectTraits(collector &c)
Draw the enlarged schema.
Definition: topSchema.cpp:115
virtual void collectTraits(collector &c)=0
virtual void label(double x, double y, const char *name)=0
virtual point inputPoint(unsigned int i) const
Top schema has no input.
Definition: topSchema.cpp:71
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
virtual void draw(device &dev)
Draw the enlarged schema.
Definition: topSchema.cpp:92
virtual void rect(double x, double y, double l, double h, const char *color, const char *link)=0
bool placed() const
Definition: schema.h:137
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
int orientation() const
Definition: schema.h:140
string fText
Definition: topSchema.h:38
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
schema * fSchema
Definition: topSchema.h:36
double height() const
Definition: schema.h:127
virtual void fleche(double x, double y, double rotation, int sens)=0
void addInput(const point &p)
Definition: schema.h:83
virtual void place(double ox, double oy, int orientation)
Define the graphic position of the schema.
Definition: topSchema.cpp:60
schema * makeTopSchema(schema *s, double margin, const string &text, const string &link)
Creates a new top schema.
Definition: topSchema.cpp:33