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  int depth);
84 
85  void getTileConnectorList(op_LayoutTile *tile);
86 
87  // This is used to move the tile (and all its children) which has
88  // multiple inputs to the left most branch it belongs.
89  void moveTilesFirstBranch(op_LayoutTree *tree,
90  op_LayoutTile *tile);
91 
92  void moveTileFirstBranch(op_LayoutTree *tree,
93  op_LayoutTile *tile,
94  int index);
95 
96  void layoutForest();
97  void layoutSingleTree(op_LayoutTree *tree);
98 
99  // This is to layout the trees which has only one tile (group or op).
100  void layoutOneTileTreeList(
101  const op_TreeList &oneTileTreeList,
102  op_TreeList &prev_tree_list);
103 
104  op_TileList *layoutSingleBranch(op_LayoutBranch *branch,
105  op_LayoutTile *listTile,
106  fpreal xleft,
107  fpreal ybottom);
108 
109  void squeezeTree(op_LayoutTree *tree,
110  op_TreeList &prev_tree_list);
111 
112  // Squeeze branches from one parent to the branches of another parent
113  // that has some branches in common.
114  void squeezeBranch(const op_BranchList &prev_branch_list,
115  op_LayoutBranch *branch);
116 
117  fpreal squeezeSubBranch(op_TileList *subBranch,
118  op_TileList *prevSubBranch,
119  bool extra_space = false);
120 
121  bool isOverlapped(op_LayoutTile *node,
122  fpreal xleft,
123  fpreal xright,
124  fpreal ybottom,
125  fpreal ytop);
126 
127  void postAdjustCorner();
128 
129  void avoidOverlap();
130 
131  void updateTiles(int treeNumber = 0);
132 
133  op_LayoutTile *getLayoutTile(OP_NetworkBoxItem *item,
134  op_TileList *search_list = 0);
135 
136  op_LayoutTile *getConnectorTile(op_LayoutTile *tile, int index,
137  int want_output, op_TileList *search_list = 0);
138 
139  void getTrunkTileList(op_TileList *trunkTileList);
140 
141  // If the given tile is a trunk tile, it will add it to the list and
142  // return true, otherwise false is returned.
143  bool appendTrunkToList(op_TileList *trunk_tile_list,
144  op_LayoutTile *tile);
145 
146  // List of all the trees
147  op_TreeList myForest;
148 
149  op_TreeList *myMergeTreeList;
150 
151  op_TileList *myTempTileList;
152  op_TileList myTileList;
153  op_TileList mySelectedTileList;
154 
155  OP_NetworkBoxItem *myCurrentItem;
156 
157  int myCurrentTreeNumber;
158 
159  // Factor is -1 if Direction is Top to Bot, else factor is +1.
160  int myFactor;
161 
162  fpreal myNodeWidth; // Width of an op node.
163  fpreal myNodeHeight; // Height of an op node.
164 
165  bool mySnapToGrid;
166  fpreal myGridSizeX;
167  fpreal myGridSizeY;
168 
169  enum OP_LayoutSort mySortedTiles;
170 
171  // The space factor is a fraction of the width and height of a tile.
172  // It is used to determine space between parent and children and cousins.
173  fpreal myChildSpaceFactor; // Space between children.
174  fpreal myParentSpaceFactor; // Space between parent and
175  // child and also between
176  // one tile trees along the
177  // parent direction.
178  fpreal myCousinSpaceFactor1; // Space between group of
179  // multi-tile trees and the
180  // group of one tile treees.
181  fpreal myCousinSpaceFactor2; // For space between trees
182  // and space between parents.
183  fpreal myCousinSpaceFactor3; // Extra space for cousin
184  // branches that contain more
185  // than one tile.
186  fpreal mySinglesFactor; // Space between single tile
187  // trees.
188 
189  bool myHitOldTree;
190  bool myHitCurrentTree;
191 
192  OP_LayoutDirection myLayoutDirection;
193  bool myStaggerSinglesFlag; // Stagger flag for one tile tree
194 
195  bool myLayoutThisTreeOnly;
196  bool mySelectedOnly;
197 
198  int debugCode;
199 };
200 #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
GU_API void snapGrid(GU_Detail &gdp, const GridSnapParms &parms)
UT_ValArray< op_LayoutBranch * > op_BranchList
Definition: OP_Layout.h:44
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:476
UT_ValArray< op_LayoutTree * > op_TreeList
Definition: OP_Layout.h:43
fpreal64 fpreal
Definition: SYS_Types.h:277
#define OP_API
Definition: OP_API.h:10
GLuint index
Definition: glcorearb.h:786
OP_LayoutDirection
Definition: OP_Layout.h:28