00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc. 00008 * 477 Richmond Street West, Suite 1001 00009 * Toronto, Ontario 00010 * Canada M5V 3E7 00011 * 416-504-9876 00012 */ 00013 00014 #ifndef __SIM_Relationship_h__ 00015 #define __SIM_Relationship_h__ 00016 00017 #include "SIM_API.h" 00018 #include "SIM_RootData.h" 00019 #include "SIM_ObjectArray.h" 00020 00021 class UT_IStream; 00022 class SIM_SimulationState; 00023 00024 /// This class defines a relationship between two groups of objects. 00025 /// The first group of objects, called simply the "group", is the set 00026 /// of objects that are modified or controlled by the relationship. The 00027 /// second group of objects, the "affector group", is the set of objects 00028 /// that control the "group" objects. Note that these sets of objects 00029 /// can overlap in any way. It is also possible to have a relationship 00030 /// without any affector group. A DOP Object Group is an example of this 00031 /// kind of affector-less relationship. Mutual affector relationships 00032 /// occur when one or more objects are in both the object group and the 00033 /// affector group. This also implies a self-affecting relationship. 00034 /// 00035 /// This data type is not meant to be subclassed, and does not contain any 00036 /// information about the nature or meaning of the relationship. That 00037 /// semantic information is held in the subdata of the SIM_Relationship. 00038 /// Only one subdata can be attached to this data at a time, and it must 00039 /// be a subclass of SIM_RelationshipData. Any other kind or number of 00040 /// subdata are ignored and invalidate the relationship. 00041 /// 00042 /// Any data that refers to other data should be implemented as a 00043 /// SIM_Relationship. Doing so avoids problems of having to lookup objects 00044 /// based on name, enforces proper solve order (so affector objects 00045 /// are always solved before the group objects), and allows reverse 00046 /// lookups (what objects are in a relationship, and what relationships 00047 /// refer to a particular object). 00048 /// 00049 /// Like SIM_Objects, SIM_Relationships are created and controlled by a 00050 /// SIM_SimulationState. They cannot be created and attached as subdata 00051 /// on existing data. Unlike SIM_Objects, SIM_Relationships do not have 00052 /// a unique integer identifier. Relationships must be given unique names. 00053 class SIM_API SIM_Relationship : public SIM_RootData 00054 { 00055 public: 00056 /// Returns the single subdata that defines the relationship type. 00057 SIM_Data *getRelationshipTypeData(); 00058 /// Returns the single const subdata that defines the relationship type. 00059 const SIM_Data *getConstRelationshipTypeData() const; 00060 00061 /// Sets the object group equal to the set of supplied objects. 00062 void setGroup(const SIM_ObjectArray &objects); 00063 /// Sets the object group to contain only the single specified object. 00064 void setGroup(SIM_Object *object); 00065 /// Adds a number of objects to the object group. 00066 void addGroup(const SIM_ObjectArray &objects); 00067 /// Adds a single object to the object group. 00068 void addGroup(SIM_Object *object); 00069 /// Removes a number of objects from the object group. 00070 void removeGroup(const SIM_ObjectArray &objects); 00071 /// Removes a single object from the object group. 00072 void removeGroup(SIM_Object *object); 00073 /// Removes all objects from the object group. 00074 void clearGroup(); 00075 /// Gets the number of objects in the object group. 00076 int getGroupEntries() const; 00077 /// Gets the object at position index within the object group. 00078 const SIM_Object *getGroupObject(int index) const; 00079 /// Tests whether the supplied object is in the object group. 00080 bool getGroupHasObject(const SIM_Object *object) const; 00081 /// Sets the affector group equal to the set of supplied objects. 00082 void setAffGroup(const SIM_ObjectArray &objects); 00083 /// Sets the affector group to contain only the single specified object. 00084 void setAffGroup(SIM_Object *object); 00085 /// Adds a number of objects to the affector group. 00086 void addAffGroup(const SIM_ObjectArray &objects); 00087 /// Adds a single object to the affector group. 00088 void addAffGroup(SIM_Object *object); 00089 /// Removes a number of objects from the affector group. 00090 void removeAffGroup(const SIM_ObjectArray &objects); 00091 /// Removes a single object from the affector group. 00092 void removeAffGroup(SIM_Object *object); 00093 /// Removes all objects from the affector group. 00094 void clearAffGroup(); 00095 /// Gets the number of objects in the affector group. 00096 int getAffGroupEntries() const; 00097 /// Gets the object at position index within the affector group. 00098 const SIM_Object *getAffGroupObject(int index) const; 00099 /// Tests whether the supplied object is in the affector group. 00100 bool getAffGroupHasObject(const SIM_Object *object) const; 00101 00102 protected: 00103 SIM_Relationship(const SIM_SimulationState *factory); 00104 virtual ~SIM_Relationship(); 00105 00106 /// Clears all attached objects. 00107 virtual void initializeSubclass(); 00108 /// Makes the relationship groups equal, but doesn't set the relationship 00109 /// name, which must be kept unique. 00110 virtual void makeEqualSubclass(const SIM_Data *source); 00111 /// Saves a relationship to a stream. The object groups are saved to 00112 /// the stream as arrays of object id numbers. 00113 virtual void saveSubclass(ostream &os) const; 00114 /// Loads a relationship from a stream. 00115 virtual bool loadSubclass(UT_IStream &is); 00116 /// Creates a query object specific to SIM_Relationship. 00117 virtual SIM_Query *createQueryObjectSubclass() const; 00118 /// Returns the memory usage of our group data. 00119 virtual int64 getMemorySizeSubclass() const; 00120 00121 /// Override the SIM_RootData function for matching us to a string. 00122 virtual bool getMatchesStringSubclass(const char *pattern) const; 00123 /// Override the SIM_RootData function for getting our identifier. 00124 virtual void getRootDataIdSubclass(SIM_RootDataId &id) const; 00125 00126 private: 00127 /// The function to set the name is private because it should only be 00128 /// called by the load function or by SIM_SimulationState. 00129 void setName(const char *name); 00130 /// Clear ourselves from the relationship arrays of our group objects. 00131 void clearAllGroupReferences(); 00132 /// Add ourselves to the relationship arrays of our group objects. 00133 void setAllGroupReferences(); 00134 /// Clear ourselves from the relationship arrays of our affector objects. 00135 void clearAllAffGroupReferences(); 00136 /// Add ourselves to the relationship arrays of our affector objects. 00137 void setAllAffGroupReferences(); 00138 00139 const SIM_SimulationState *mySimulationState; 00140 SIM_ObjectArray myGroup; 00141 SIM_ObjectArray myAffGroup; 00142 00143 friend class SIM_SimulationState; 00144 friend class SIM_Object; 00145 00146 DECLARE_STANDARD_GETCASTTOTYPE(); 00147 DECLARE_CLASSNAME(SIM_Relationship, SIM_RootData); 00148 }; 00149 00150 #endif 00151
1.5.9