1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/************************************************************************
************************************************************************
FAUST compiler
Copyright (C) 2003-2018 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
************************************************************************
************************************************************************/
#include <stdlib.h>
#include <cstdlib>
#include <iostream>
#include "exception.hh"
#include "topSchema.h"
using namespace std;
/**
* Creates a new top schema
*/
schema* makeTopSchema(schema* s, double margin, const string& text, const string& link)
{
return new topSchema(makeDecorateSchema(s, margin / 2, text), margin / 2, "", link);
}
/**
* A topSchema is a schema surrounded by a dashed rectangle with a
* label on the top left. The rectangle is placed at half the margin
* parameter. Arrows are added to the outputs. The constructor is
* made private to enforce the usage of makeTopSchema.
*/
topSchema::topSchema(schema* s, double margin, const string& text, const string& link)
: schema(0, 0, s->width() + 2 * margin, s->height() + 2 * margin),
fSchema(s),
fMargin(margin),
fText(text),
fLink(link)
{
}
/**
* Define the graphic position of the schema. Computes the graphic
* position of all the elements, in particular the inputs and outputs.
* This method must be called before draw(), otherwise draw is not allowed
*/
void topSchema::place(double ox, double oy, int orientation)
{
beginPlace(ox, oy, orientation);
fSchema->place(ox + fMargin, oy + fMargin, orientation);
endPlace();
}
/**
* Top schema has no input
*/
point topSchema::inputPoint(unsigned int i) const
{
faustassert(placed());
faustassert(i < inputs());
throw faustexception("ERROR : topSchema::inputPoint\n");
}
/**
* Top schema has no output
*/
point topSchema::outputPoint(unsigned int i) const
{
faustassert(placed());
faustassert(i < outputs());
throw faustexception("ERROR : topSchema::outputPoint\n");
}
/**
* Draw the enlarged schema. This methos can only
* be called after the block have been placed
*/
void topSchema::draw(device& dev)
{
faustassert(placed());
// draw a background white rectangle
dev.rect(x(), y(), width() - 1, height() - 1, "#ffffff", fLink.c_str());
// draw the label
dev.label(x() + fMargin, y() + fMargin / 2, fText.c_str());
fSchema->draw(dev);
// draw arrows at output points of schema
for (unsigned int i = 0; i < fSchema->outputs(); i++) {
point p = fSchema->outputPoint(i);
dev.fleche(p.x, p.y, 0, orientation());
}
}
/**
* Draw the enlarged schema. This methos can only
* be called after the block have been placed
*/
void topSchema::collectTraits(collector& c)
{
faustassert(placed());
fSchema->collectTraits(c);
// draw arrows at output points of schema
for (unsigned int i = 0; i < fSchema->inputs(); i++) {
point p = fSchema->inputPoint(i);
c.addOutput(p);
;
}
// draw arrows at output points of schema
for (unsigned int i = 0; i < fSchema->outputs(); i++) {
point p = fSchema->outputPoint(i);
c.addInput(p);
;
}
}
|