1 /************************************************************************
2 ************************************************************************
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.
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.
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 ************************************************************************/
22 * @file boxcomplexity.cpp
23 * Implement complexity computation for box diagrams.
29 // construction des representations graphiques
34 #include "boxcomplexity.h"
39 * property Key used to store box complexity
41 Tree BCOMPLEXITY
= tree ("BCOMPLEXITY");
43 static int computeBoxComplexity (Tree box
);
46 * Return the complexity propety of a box expression tree.
47 * Return the complexity propety of a box expression tree. If no
48 * complexity property exist, it is created an computeBoxComplexity
49 * is called do to the job.
51 * @param box an evaluated box expression tree
52 * @return the complexity of box
54 * @see computeBoxComplexity
56 int boxComplexity (Tree box
)
58 Tree prop
= box
->getProperty(BCOMPLEXITY
);
61 return tree2int(prop
);
64 int v
= computeBoxComplexity(box
);
65 box
->setProperty(BCOMPLEXITY
,tree(v
));
71 * internal shortcut to simplify computeBoxComplexity code
73 #define BC boxComplexity
77 * Compute the complexity of a box expression.
79 * Compute the complexity of a box expression tree according to the
80 * complexity of its subexpressions. Basically it counts the number
81 * of boxes to be drawn. The box-diagram expression is supposed
82 * to be evaluated. It will exit with an error if it is not the case.
84 * @param box an evaluated box expression tree
85 * @return the complexity of box
87 int computeBoxComplexity (Tree box
)
98 Tree t1
, t2
, ff
, label
, cur
, min
, max
, step
, type
, name
, file
;
100 xtended
* xt
= (xtended
*) getUserData(box
);
105 else if (isBoxInt(box
, &i
)) return 1;
106 else if (isBoxReal(box
, &r
)) return 1;
108 else if (isBoxCut(box
)) return 0;
109 else if (isBoxWire(box
)) return 0;
111 else if (isBoxPrim0(box
, &p0
)) return 1;
112 else if (isBoxPrim1(box
, &p1
)) return 1;
113 else if (isBoxPrim2(box
, &p2
)) return 1;
114 else if (isBoxPrim3(box
, &p3
)) return 1;
115 else if (isBoxPrim4(box
, &p4
)) return 1;
116 else if (isBoxPrim5(box
, &p5
)) return 1;
119 else if (isBoxFFun(box
, ff
)) return 1;
120 else if (isBoxFConst(box
, type
, name
, file
))
122 else if (isBoxFVar(box
, type
, name
, file
))
124 // slots and symbolic boxes
125 else if (isBoxSlot(box
, &i
)) return 1;
126 else if (isBoxSymbolic(box
,t1
,t2
)) return 1 + BC(t2
);
128 // block diagram binary operator
129 else if (isBoxSeq(box
, t1
, t2
)) return BC(t1
) + BC(t2
);
130 else if (isBoxSplit(box
, t1
, t2
)) return BC(t1
) + BC(t2
);
131 else if (isBoxMerge(box
, t1
, t2
)) return BC(t1
) + BC(t2
);
132 else if (isBoxPar(box
, t1
, t2
)) return BC(t1
) + BC(t2
);
133 else if (isBoxRec(box
, t1
, t2
)) return BC(t1
) + BC(t2
);
135 // user interface widgets
136 else if (isBoxButton(box
, label
)) return 1;
137 else if (isBoxCheckbox(box
, label
)) return 1;
138 else if (isBoxVSlider(box
, label
, cur
, min
, max
, step
)) return 1;
139 else if (isBoxHSlider(box
, label
, cur
, min
, max
, step
)) return 1;
140 else if (isBoxHBargraph(box
, label
, min
, max
)) return 1;
141 else if (isBoxVBargraph(box
, label
, min
, max
)) return 1;
142 else if (isBoxNumEntry(box
, label
, cur
, min
, max
, step
))return 1;
144 // user interface groups
145 else if (isBoxVGroup(box
, label
, t1
)) return BC(t1
);
146 else if (isBoxHGroup(box
, label
, t1
)) return BC(t1
);
147 else if (isBoxTGroup(box
, label
, t1
)) return BC(t1
);
151 //fout << tree2str(box);
152 cerr
<< "ERROR in boxComplexity : not an evaluated box [[ " << *box
<< " ]]";