HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_Relationship.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  */
7 
8 #ifndef __SIM_Relationship_h__
9 #define __SIM_Relationship_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_RootData.h"
13 #include "SIM_ObjectArray.h"
14 #include <iosfwd>
15 
16 class UT_IStream;
17 class SIM_SimulationState;
18 
19 /// This class defines a relationship between two groups of objects.
20 /// The first group of objects, called simply the "group", is the set
21 /// of objects that are modified or controlled by the relationship. The
22 /// second group of objects, the "affector group", is the set of objects
23 /// that control the "group" objects. Note that these sets of objects
24 /// can overlap in any way. It is also possible to have a relationship
25 /// without any affector group. A DOP Object Group is an example of this
26 /// kind of affector-less relationship. Mutual affector relationships
27 /// occur when one or more objects are in both the object group and the
28 /// affector group. This also implies a self-affecting relationship.
29 ///
30 /// This data type is not meant to be subclassed, and does not contain any
31 /// information about the nature or meaning of the relationship. That
32 /// semantic information is held in the subdata of the SIM_Relationship.
33 /// Only one subdata can be attached to this data at a time, and it must
34 /// be a subclass of SIM_RelationshipData. Any other kind or number of
35 /// subdata are ignored and invalidate the relationship.
36 ///
37 /// Any data that refers to other data should be implemented as a
38 /// SIM_Relationship. Doing so avoids problems of having to lookup objects
39 /// based on name, enforces proper solve order (so affector objects
40 /// are always solved before the group objects), and allows reverse
41 /// lookups (what objects are in a relationship, and what relationships
42 /// refer to a particular object).
43 ///
44 /// Like SIM_Objects, SIM_Relationships are created and controlled by a
45 /// SIM_SimulationState. They cannot be created and attached as subdata
46 /// on existing data. Unlike SIM_Objects, SIM_Relationships do not have
47 /// a unique integer identifier. Relationships must be given unique names.
49 {
50 public:
51  /// Returns the single subdata that defines the relationship type.
52  SIM_Data *getRelationshipTypeData();
53  /// Returns the single const subdata that defines the relationship type.
54  const SIM_Data *getConstRelationshipTypeData() const;
55 
56  /// Sets the object group equal to the set of supplied objects.
57  void setGroup(const SIM_ObjectArray &objects);
58  /// Sets the object group to contain only the single specified object.
59  void setGroup(SIM_Object *object);
60  /// Adds a number of objects to the object group.
61  void addGroup(const SIM_ObjectArray &objects);
62  /// Adds a single object to the object group.
63  void addGroup(SIM_Object *object);
64  /// Removes a number of objects from the object group.
65  void removeGroup(const SIM_ObjectArray &objects);
66  /// Removes a single object from the object group.
67  void removeGroup(SIM_Object *object);
68  /// Removes all objects from the object group.
69  void clearGroup();
70  /// Gets the number of objects in the object group.
71  int getGroupEntries() const;
72  /// Gets the object at position index within the object group.
73  const SIM_Object *getGroupObject(int index) const;
74  /// Tests whether the supplied object is in the object group.
75  bool getGroupHasObject(const SIM_Object *object) const;
76  /// Sets the affector group equal to the set of supplied objects.
77  void setAffGroup(const SIM_ObjectArray &objects);
78  /// Sets the affector group to contain only the single specified object.
79  void setAffGroup(SIM_Object *object);
80  /// Adds a number of objects to the affector group.
81  void addAffGroup(const SIM_ObjectArray &objects);
82  /// Adds a single object to the affector group.
83  void addAffGroup(SIM_Object *object);
84  /// Removes a number of objects from the affector group.
85  void removeAffGroup(const SIM_ObjectArray &objects);
86  /// Removes a single object from the affector group.
87  void removeAffGroup(SIM_Object *object);
88  /// Removes all objects from the affector group.
89  void clearAffGroup();
90  /// Gets the number of objects in the affector group.
91  int getAffGroupEntries() const;
92  /// Gets the object at position index within the affector group.
93  const SIM_Object *getAffGroupObject(int index) const;
94  /// Tests whether the supplied object is in the affector group.
95  bool getAffGroupHasObject(const SIM_Object *object) const;
96 
97 protected:
98  SIM_Relationship(const SIM_SimulationState *factory);
99  virtual ~SIM_Relationship();
100 
101  /// Clears all attached objects.
102  virtual void initializeSubclass();
103  /// Makes the relationship groups equal, but doesn't set the relationship
104  /// name, which must be kept unique.
105  virtual void makeEqualSubclass(const SIM_Data *source);
106  /// Saves a relationship to a stream. The object groups are saved to
107  /// the stream as arrays of object id numbers.
108  virtual void saveSubclass(std::ostream &os) const;
109  /// Loads a relationship from a stream.
110  virtual bool loadSubclass(UT_IStream &is);
111  /// Creates a query object specific to SIM_Relationship.
112  virtual SIM_Query *createQueryObjectSubclass() const;
113  /// Returns the memory usage of our group data.
114  virtual int64 getMemorySizeSubclass() const;
115 
116  /// Override the SIM_RootData function for matching us to a string.
117  virtual bool getMatchesStringSubclass(const char *pattern) const;
118  /// Override the SIM_RootData function for getting our identifier.
119  virtual void getRootDataIdSubclass(SIM_RootDataId &id) const;
120 
121 private:
122  /// The function to set the name is private because it should only be
123  /// called by the load function or by SIM_SimulationState.
124  void setName(const char *name);
125  /// Clear ourselves from the relationship arrays of our group objects.
126  void clearAllGroupReferences();
127  /// Add ourselves to the relationship arrays of our group objects.
128  void setAllGroupReferences();
129  /// Clear ourselves from the relationship arrays of our affector objects.
130  void clearAllAffGroupReferences();
131  /// Add ourselves to the relationship arrays of our affector objects.
132  void setAllAffGroupReferences();
133 
134  const SIM_SimulationState *mySimulationState;
135  SIM_ObjectArray myGroup;
136  SIM_ObjectArray myAffGroup;
137 
138  friend class SIM_SimulationState;
139  friend class SIM_Object;
140 
143 };
144 
145 #endif
146 
virtual void makeEqualSubclass(const SIM_Data *source)
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:45
#define DECLARE_CLASSNAME(DataClass, SuperClass)
Definition: SIM_DataUtils.h:20
virtual bool loadSubclass(UT_IStream &is)
virtual SIM_Query * createQueryObjectSubclass() const
virtual int64 getMemorySizeSubclass() const
virtual bool getMatchesStringSubclass(const char *pattern) const =0
long long int64
Definition: SYS_Types.h:107
Holds pointers to a number of SIM_Object objects.
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
virtual void saveSubclass(std::ostream &os) const
GLuint const GLchar * name
Definition: glcorearb.h:785
GLuint index
Definition: glcorearb.h:785
#define SIM_API
Definition: SIM_API.h:10
void setGroup(PointDataTree &tree, const PointIndexTree &indexTree, const std::vector< short > &membership, const Name &group, const bool remove=false)
Sets group membership from a PointIndexTree-ordered vector.
Definition: PointGroup.h:691
virtual void getRootDataIdSubclass(SIM_RootDataId &id) const =0
virtual void initializeSubclass()