HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_Group.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 library (C++)
7  *
8  * COMMENTS: A group is defined by a name and an offset into the
9  * individual group bit maps which are stored with each node.
10  * Groups should only be created via an OP_GroupList which
11  * maintains the bitmap offsets. Currently we only support
12  * one group list per network.
13  *
14  * BUGS:
15  *
16  */
17 
18 #ifndef __OP_Group_h__
19 #define __OP_Group_h__
20 
21 #include "OP_API.h"
22 #include <UT/UT_Color.h>
23 #include <UT/UT_String.h>
24 #include <UT/UT_ValArray.h>
25 #include <SYS/SYS_Types.h>
26 #include <iosfwd>
27 
28 class OP_Network;
29 class OP_Node;
30 class OP_GroupList;
31 
33 {
34 public:
35  static char getGroupChar() { return '@'; }
36 
37  const UT_String &getName() const { return myName; }
38  void setName(const char *n);
39 
40  int isInternal() const;
41 
42  // these methods used for the UI of group tiles
43  // The picked flag is different between lists and worksheets, so use
44  // the extra "list" parameter to distinguish between the two.
45  int setPicked(int on_off, int list = 0);
46  int getPicked(int list = 0) const;
47  void setXY(fpreal x, fpreal y);
48  fpreal getX() const { return myPosX; }
49  fpreal getY() const { return myPosY; }
50 
51 
52  // The next two methods should be used only by OP_UndoGroup
53  short getFlags() { return myFlags; }
54  void setFlags(short f) { myFlags = f; }
55 
56  const UT_Color &getColor() const { return myColor; }
57  void setColor(const UT_Color &col) { myColor = col; }
58 
59  void saveGroupForUndo();
60  int saveContents(std::ostream &os, int binary=0);
61  bool loadContents(UT_IStream &is);
62  void clearUndoFlags() { mySavedForUndoFlag = 0; }
63 
64  // these flags operate on all the members of this group
65  void setFlag(char flagchar, bool onoff);
66  void setDisplay(bool onoff);
67  void setSelectable(bool onoff);
68  void setTemplate(bool onoff);
69  void setExposed(bool onoff);
70  void setSelected(bool onoff);
71  void setExport(bool onoff);
72  void setThumbnail(bool onoff);
73 
74 //
75 // clear will remove all members from the group.
76 // It returns the number of nodes that were removed.
77 //
78  int clear(int send_change=1);
79 //
80 // The pattern methods allow addition and subtraction of members based
81 // on a pattern string match by name. They each return the number of
82 // elements added or subtracted from the group.
83 //
84  int addPattern(const char *pat);
85  int subPattern(const char *pat);
86  int setPattern(const char *pat) { clear(); return addPattern(pat); }
87 //
88 // addMember and subMember will add and remove an individual node from
89 // the group. They return one upon success and zero upon failure (i.e.
90 // the node is null or not a member of the groups network.) If the
91 // send_change flag is set an OP_GROUP_CHANGED event is generated.
92 //
93  int addMember(OP_Node *node, int send_change=1);
94  int subMember(OP_Node *node, int send_change=1);
95 //
96 // These methods add and remove the currently picked nodes in the network
97 // to or from the group. They return the number of nodes affected. If
98 // 'or_in_picked_netbox' is set to true, then a node is also considered if it's
99 // unpicked but in a picked netbox.
100 //
101  int addPickedNodes(bool or_in_picked_netbox = false);
102  int subPickedNodes(bool or_in_picked_netbox = false);
103 
104 // These methods are for getting picked roots and such
105 //
106  int subNonPickedRootNodes();
107 
108 //
109 // isMember returns a boolean value indicating whether the given node
110 // is contained in this group or not. The "contains" method is simply
111 // an alias for "isMember" and is provided here to be consistent with
112 // the GB_Group class.
113 //
114  int isMember(const OP_Node *node) const;
115  int contains(const OP_Node *node) const
116  { return isMember(node); }
117 //
118 // getPattern returns a string pattern that matches all the elements of
119 // this group. Currently no collapsing is done. i.e. It returns a list
120 // of all the member names or "*" if the entire net is in the group.
121 // The return value is the number of elements in the group.
122 //
123  int getPattern(UT_String &str) const;
124 //
125 // getMembers will provide an array of pointers to the group members.
126 // The return value is the number of elements in the group.
127 //
128  int getMembers(UT_Array<OP_Node *> &list, int avoid_dups=0) const;
129  int countMembers() const;
130 
131  OP_Network *getNetwork() { return myNetwork; }
132 
133 //
134 // sendGroupChange should be used instead of simply sending an
135 // OP_GROUP_CHANGED event.
136 //
137  void sendGroupChange();
138 
139  /// Return the amount of memory owned by this OP_Group
140  int64 getMemoryUsage(bool inclusive) const
141  {
142  int64 mem = inclusive ? sizeof(*this) : 0;
143  mem += myName.getMemoryUsage(false);
144  return mem;
145  }
146 
147 private:
148  friend class OP_GroupList;
149 //
150 // Private constructor avoids misuse. OP_GroupList is a friend of ours.
151 //
152  OP_Group(const char *name, OP_Network *net);
153  ~OP_Group();
154 
155 //
156 // The group index is the offset into the group bitmaps that this group
157 // is using. This value should only be set by the OP_GroupList class.
158 //
159 
160  void setGroupIndex(exint index) { myGroupIndex = index; }
161  exint getGroupIndex() const { return myGroupIndex; }
162 //
163 // The initialize method is used to set all the bits in each node for
164 // this group to an initial state. This is done when new groups are
165 // created.
166 //
167  int initialize(int state=0);
168 
169  UT_String myName;
170 
171  UT_Color myColor; // For UI
172  fpreal myPosX;
173  fpreal myPosY;
174 
175  OP_Network *myNetwork;
176 
177  exint myGroupIndex;
178 
179  char mySavedForUndoFlag;
180  short myFlags;
181 };
182 
183 #endif
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
int64 exint
Definition: SYS_Types.h:125
GLint y
Definition: glcorearb.h:103
fpreal getX() const
Definition: OP_Group.h:48
void setColor(const UT_Color &col)
Definition: OP_Group.h:57
void clearUndoFlags()
Definition: OP_Group.h:62
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
short getFlags()
Definition: OP_Group.h:53
int setPattern(const char *pat)
Definition: OP_Group.h:86
fpreal getY() const
Definition: OP_Group.h:49
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
GLint GLenum GLint x
Definition: glcorearb.h:409
OP_Network * getNetwork()
Definition: OP_Group.h:131
const UT_String & getName() const
Definition: OP_Group.h:37
const UT_Color & getColor() const
Definition: OP_Group.h:56
fpreal64 fpreal
Definition: SYS_Types.h:277
int contains(const OP_Node *node) const
Definition: OP_Group.h:115
#define OP_API
Definition: OP_API.h:10
GLuint index
Definition: glcorearb.h:786
static char getGroupChar()
Definition: OP_Group.h:35
void setFlags(short f)
Definition: OP_Group.h:54
int64 getMemoryUsage(bool inclusive) const
Return the amount of memory owned by this OP_Group.
Definition: OP_Group.h:140