HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_Layout.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: OP_Layout.C (Operator AutoLayout, C++)
7  *
8  * COMMENT: Layout of the operators on the worksheet.
9  *
10  *
11  */
12 
13 #ifndef __OP_Layout__
14 #define __OP_Layout__
15 
16 #include "OP_API.h"
17 #include <UT/UT_ValArray.h>
18 #include <SYS/SYS_Types.h>
19 
20 class OP_Node;
21 class OP_Network;
22 class OP_IndirectInput;
23 class OP_NetworkBoxItem;
24 class op_LayoutTile;
25 class op_LayoutTree;
26 class op_LayoutBranch;
27 
29 {
30  OP_LAYOUT_BOT_TO_TOP, // root at the bottom
31  OP_LAYOUT_RIGHT_TO_LEFT, // root at the right
32  OP_LAYOUT_TOP_TO_BOT // root at the top
33 };
34 
36 {
37  OP_LAYOUT_SORT_NONE, // sort off
38  OP_LAYOUT_SORT_ABC, // sort alphabetically
39  OP_LAYOUT_SORT_OPTYPE // sort by op type
40 };
41 
45 
46 //
47 // Note: A trunk tile is a tile with no input if the direction is Top
48 // to Bottom, else it is a tile with no output. A branch starts
49 // with a trunk tile. Thus, the number of branches
50 // in a tree is the number of trunk tiles in that tree. Even
51 // though there are cycles in the graph, we call it a tree.
52 // A tile which has multiple connectors (eg. Blend object) will
53 // be considered to be part of the branch that is the left most of
54 // its input. The x and y location of a tile will be the
55 // position of the bottom left corner of the tile.
56 //
57 
59 {
60 public:
62  ~OP_Layout();
63 
64  // Add all nodes on the worksheet to the list of layout
65  // OPs using this function.
66  void addLayoutItem(OP_NetworkBoxItem *item, int selected = -1);
67  void layoutOps(OP_LayoutDirection direction,
68  OP_NetworkBoxItem *currentItem,
69  bool currentTreeOnly = false,
70  bool selectedOnly = false,
71  bool stagger = true,
72  fpreal child_space_factor = -1,
73  fpreal parent_space_factor = -1,
74  bool snapGrid = false,
75  fpreal gridSizeX = 0,
76  fpreal gridSizeY = 0);
77 
78 private:
79  void initSpaceFactor(fpreal child_s_f, fpreal parent_s_f);
80  void buildTrees();
81  void buildTree(op_LayoutTile *current_tile,
82  int tree_number);
83 
84  void getTileConnectorList(op_LayoutTile *tile);
85 
86  // This is used to move the tile (and all its children) which has
87  // multiple inputs to the left most branch it belongs.
88  void moveTilesFirstBranch(op_LayoutTree *tree,
89  op_LayoutTile *tile);
90 
91  void moveTileFirstBranch(op_LayoutTree *tree,
92  op_LayoutTile *tile,
93  int index);
94 
95  void layoutForest();
96  void layoutSingleTree(op_LayoutTree *tree);
97 
98  // This is to layout the trees which has only one tile (group or op).
99  void layoutOneTileTreeList(
100  const op_TreeList &oneTileTreeList,
101  op_TreeList &prev_tree_list);
102 
103  op_TileList *layoutSingleBranch(op_LayoutBranch *branch,
104  op_LayoutTile *listTile,
105  fpreal xleft,
106  fpreal ybottom);
107 
108  void squeezeTree(op_LayoutTree *tree,
109  op_TreeList &prev_tree_list);
110 
111  // Squeeze branches from one parent to the branches of another parent
112  // that has some branches in common.
113  void squeezeBranch(const op_BranchList &prev_branch_list,
114  op_LayoutBranch *branch);
115 
116  fpreal squeezeSubBranch(op_TileList *subBranch,
117  op_TileList *prevSubBranch,
118  bool extra_space = false);
119 
120  bool isOverlapped(op_LayoutTile *node,
121  fpreal xleft,
122  fpreal xright,
123  fpreal ybottom,
124  fpreal ytop);
125 
126  void postAdjustCorner();
127 
128  void avoidOverlap();
129 
130  void updateTiles(int treeNumber = 0);
131 
132  op_LayoutTile *getLayoutTile(OP_NetworkBoxItem *item,
133  op_TileList *search_list = 0);
134 
135  op_LayoutTile *getConnectorTile(op_LayoutTile *tile, int index,
136  int want_output, op_TileList *search_list = 0);
137 
138  void getTrunkTileList(op_TileList *trunkTileList);
139 
140  // If the given tile is a trunk tile, it will add it to the list and
141  // return true, otherwise false is returned.
142  bool appendTrunkToList(op_TileList *trunk_tile_list,
143  op_LayoutTile *tile);
144 
145  // List of all the trees
146  op_TreeList myForest;
147 
148  op_TreeList *myMergeTreeList;
149 
150  op_TileList *myTempTileList;
151  op_TileList myTileList;
152  op_TileList mySelectedTileList;
153 
154  OP_NetworkBoxItem *myCurrentItem;
155 
156  int myCurrentTreeNumber;
157 
158  // Factor is -1 if Direction is Top to Bot, else factor is +1.
159  int myFactor;
160 
161  fpreal myNodeWidth; // Width of an op node.
162  fpreal myNodeHeight; // Height of an op node.
163 
164  bool mySnapToGrid;
165  fpreal myGridSizeX;
166  fpreal myGridSizeY;
167 
168  enum OP_LayoutSort mySortedTiles;
169 
170  // The space factor is a fraction of the width and height of a tile.
171  // It is used to determine space between parent and children and cousins.
172  fpreal myChildSpaceFactor; // Space between children.
173  fpreal myParentSpaceFactor; // Space between parent and
174  // child and also between
175  // one tile trees along the
176  // parent direction.
177  fpreal myCousinSpaceFactor1; // Space between group of
178  // multi-tile trees and the
179  // group of one tile treees.
180  fpreal myCousinSpaceFactor2; // For space between trees
181  // and space between parents.
182  fpreal myCousinSpaceFactor3; // Extra space for cousin
183  // branches that contain more
184  // than one tile.
185  fpreal mySinglesFactor; // Space between single tile
186  // trees.
187 
188  bool myHitOldTree;
189  bool myHitCurrentTree;
190 
191  OP_LayoutDirection myLayoutDirection;
192  bool myStaggerSinglesFlag; // Stagger flag for one tile tree
193 
194  bool myLayoutThisTreeOnly;
195  bool mySelectedOnly;
196 
197  int debugCode;
198 };
199 #endif
UT_ValArray< op_LayoutTile * > op_TileList
Definition: OP_Layout.h:42
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
OP_LayoutSort
Definition: OP_Layout.h:35
UT_ValArray< op_LayoutBranch * > op_BranchList
Definition: OP_Layout.h:44
UT_ValArray< op_LayoutTree * > op_TreeList
Definition: OP_Layout.h:43
double fpreal
Definition: SYS_Types.h:270
#define OP_API
Definition: OP_API.h:10
GLuint index
Definition: glcorearb.h:785
OP_LayoutDirection
Definition: OP_Layout.h:28