~ubuntu-branches/ubuntu/feisty/faust/feisty

« back to all changes in this revision

Viewing changes to compiler/draw/schema/splitSchema.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mario Lang
  • Date: 2006-10-09 11:05:30 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 edgy)
  • Revision ID: james.westby@ubuntu.com-20061009110530-zvktdvpq5zewdxso
Tags: 0.9.8-1
* New upstream release.
* Upgrade Standards-Version to 3.7.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "splitSchema.h"
 
24
#include <iostream>
 
25
#include <assert.h>
 
26
 
 
27
using namespace std;
 
28
 
 
29
/**
 
30
 * Creates a new split schema. Cables are enlarged to dWire.
 
31
 * The horizontal gap between the two subschema is such that
 
32
 * the connections are not too slopy.
 
33
 */
 
34
schema* makeSplitSchema (schema* s1, schema* s2)
 
35
{
 
36
        // make sure a and b are at least dWire large
 
37
        schema * a = makeEnlargedSchema(s1, dWire);
 
38
        schema * b = makeEnlargedSchema(s2, dWire);
 
39
 
 
40
        // horizontal gap to avaoid too slopy connections
 
41
        double  hgap = (a->height()+b->height())/4;
 
42
 
 
43
        return new splitSchema(a,b,hgap);
 
44
}
 
45
 
 
46
 
 
47
/**
 
48
 * Constructor for a split schema s1 <: s2 where the outputs
 
49
 * of s1 are distributed to the inputs of s2. The constructor is
 
50
 * private in order to enforce the usage of makeSplitSchema
 
51
 */
 
52
splitSchema::splitSchema (schema* s1, schema* s2, double hgap)
 
53
        :       schema( s1->inputs(),
 
54
                                s2->outputs(),
 
55
                                s1->width() + s2->width() + hgap,
 
56
                                max(s1->height(), s2->height()) ),
 
57
                fSchema1(s1),
 
58
                fSchema2(s2),
 
59
                fHorzGap(hgap)
 
60
{
 
61
}
 
62
 
 
63
 
 
64
/**
 
65
 * Places the two subschema horizontaly, centered, with enough gap for
 
66
 * the connections
 
67
 */
 
68
void splitSchema::place(double ox, double oy, int orientation)
 
69
{
 
70
        beginPlace(ox, oy, orientation);
 
71
 
 
72
        double dy1 = max(0.0, fSchema2->height()-fSchema1->height()) / 2.0;
 
73
        double dy2 = max(0.0, fSchema1->height()-fSchema2->height()) / 2.0;
 
74
 
 
75
        if (orientation == kLeftRight) {
 
76
                fSchema1->place(ox, oy+dy1, orientation);
 
77
                fSchema2->place(ox+fSchema1->width()+fHorzGap, oy+dy2, orientation);
 
78
        } else {
 
79
                fSchema2->place(ox, oy+dy2, orientation);
 
80
                fSchema1->place(ox+fSchema2->width()+fHorzGap, oy+dy1, orientation);
 
81
        }
 
82
        endPlace();
 
83
}
 
84
 
 
85
/**
 
86
 * The inputs of s1 <: s2 are the inputs of s1
 
87
 */
 
88
point splitSchema::inputPoint(unsigned int i)
 
89
{
 
90
        return fSchema1->inputPoint(i);
 
91
}
 
92
 
 
93
 
 
94
/**
 
95
 * The outputs of s1 <: s2 are the outputs of s2
 
96
 */
 
97
point splitSchema::outputPoint(unsigned int i)
 
98
{
 
99
        return fSchema2->outputPoint(i);
 
100
}
 
101
 
 
102
 
 
103
/**
 
104
 * Draw the two sub schema and the connections between them
 
105
 */
 
106
void splitSchema::draw(device& dev)
 
107
{
 
108
        assert(placed());
 
109
 
 
110
        // draw the two subdiagrams
 
111
        fSchema1->draw(dev);
 
112
        fSchema2->draw(dev);
 
113
 
 
114
        unsigned int r = fSchema1->outputs();
 
115
        assert(r>0);
 
116
 
 
117
        // draw the connections between them
 
118
        for (unsigned int i=0; i<fSchema2->inputs(); i++) {
 
119
                point p = fSchema1->outputPoint(i%r);
 
120
                point q = fSchema2->inputPoint(i);
 
121
                dev.trait(p.x, p.y, q.x, q.y);
 
122
        }
 
123
}
 
124
 
 
125