1 //
2 //  FLNodes.h
3 //
4 
5 #ifndef _FLNodes_h
6 #define _FLNodes_h
7 
8 #include <QString>
9 #include <QRect>
10 
11 #include "smartpointer.h"
12 
13 class FLComponentItem;
14 
15 /****************************LAYOUT OPTIMIZATION TREE*****************/
16 class binaryNode : public smartable
17 {
18     public :
19         SMARTP<binaryNode> left;
20         SMARTP<binaryNode> right;
21 
binaryNode(binaryNode * l,binaryNode * r)22         binaryNode(binaryNode* l, binaryNode* r): left(l), right(r) {}
23 
24         //  Representing the surface of the interface
25         virtual QRect 	rectSurface() = 0;
26         virtual QString renderToFaust(const QString& faustOperator, const QString& layoutIndex) = 0;
27 
surface()28         int surface() {
29             int surface =  rectSurface().width() * rectSurface().height();
30             printf("SURFACE CALCULATED = %i\n", surface);
31             return surface;
32         }
33 };
34 
35 class treeNode : public binaryNode
36 {
37     public:
38         QRect rect;
39 
treeNode(binaryNode * l,binaryNode * r)40 		treeNode(binaryNode* l, binaryNode* r): binaryNode(l,r) {}
rectSurface()41         virtual QRect rectSurface()			{ return rect; }
42 };
43 
44 class verticalNode : public treeNode
45 {
46 	public:
verticalNode(binaryNode * node1,binaryNode * node2,QRect r)47         verticalNode(binaryNode* node1, binaryNode* node2, QRect r) : treeNode(node1, node2) { rect = r; }
48 
renderToFaust(const QString & faustOperator,const QString & layoutIndex)49         virtual QString renderToFaust(const QString& faustOperator, const QString& layoutIndex){
50             QString faustCode = "vgroup(\"["+ layoutIndex + "]\"," + left->renderToFaust(faustOperator, "1") + faustOperator + right->renderToFaust(faustOperator, "2")+")";
51 
52             return faustCode;
53         }
54 };
55 
56 class horizontalNode : public treeNode
57 {
58     public:
horizontalNode(binaryNode * node1,binaryNode * node2,QRect r)59         horizontalNode(binaryNode* node1, binaryNode* node2, QRect r) : treeNode(node1, node2) { rect = r; }
60 
renderToFaust(const QString & faustOperator,const QString & layoutIndex)61         virtual QString renderToFaust (const QString& faustOperator, const QString& layoutIndex) {
62             QString faustCode = "hgroup(\"["+ layoutIndex + "]\"," + left->renderToFaust(faustOperator, "1") + faustOperator + right->renderToFaust(faustOperator, "2")+")";
63             return faustCode;
64         }
65 };
66 
67 class leafNode : public binaryNode
68 {
69     public:
70         FLComponentItem* item;
71 
leafNode(FLComponentItem * i)72         leafNode(FLComponentItem* i) : binaryNode(NULL, NULL) { item = i; }
73 
renderToFaust(const QString &,const QString & layoutIndex)74         virtual QString renderToFaust(const QString& /*faustOperator*/, const QString& layoutIndex){
75             return item->faustComponent(layoutIndex);
76         }
77 
rectSurface()78         virtual QRect rectSurface() 	{ return item->rect(); }
79 };
80 
81 binaryNode* 		createBestContainerTree(binaryNode* node1, binaryNode* node2);
82 QList<binaryNode*> 	createListTrees(QList<FLComponentItem*> components);
83 QList<binaryNode*> 	dispatchComponentOnListOfTrees(FLComponentItem* component, QList<binaryNode*> existingTrees);
84 binaryNode* 		calculateBestDisposition(QList<FLComponentItem*> components);
85 
86 
87 #endif
88