Adding new source file faustio.ml, including class waveio and class csvio.
[Faustine.git] / interpretor / faust-0.9.47mr3 / compiler / draw / schema / topSchema.cpp
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
30 /**
31 * Creates a new top schema
32 */
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
39 /**
40 * A topSchema is a schema surrounded by a dashed rectangle with a
41 * label on the top left. The rectangle is placed at half the margin
42 * parameter. Arrows are added to the outputs. The constructor is
43 * made private to enforce the usage of makeTopSchema.
44 */
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
55 /**
56 * Define the graphic position of the schema. Computes the graphic
57 * position of all the elements, in particular the inputs and outputs.
58 * This method must be called before draw(), otherwise draw is not allowed
59 */
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
68 /**
69 * Top schema has no input
70 */
71 point topSchema::inputPoint(unsigned int i) const
72 {
73 assert (placed());
74 assert (i < inputs());
75 exit(1);
76 }
77
78 /**
79 * Top schema has no output
80 */
81 point topSchema::outputPoint(unsigned int i) const
82 {
83 assert (placed());
84 assert (i < outputs());
85 exit(1);
86 }
87
88 /**
89 * Draw the enlarged schema. This methos can only
90 * be called after the block have been placed
91 */
92 void topSchema::draw(device& dev)
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
111 /**
112 * Draw the enlarged schema. This methos can only
113 * be called after the block have been placed
114 */
115 void topSchema::collectTraits(collector& c)
116 {
117 assert(placed());
118 fSchema->collectTraits(c);
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 }