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 * 123 Front Street West, Suite 1401 00009 * Toronto, Ontario 00010 * Canada M5J 2M2 00011 * 416-504-9876 00012 */ 00013 00014 #ifndef __SIM_ConstraintIterator_h__ 00015 #define __SIM_ConstraintIterator_h__ 00016 00017 #include "SIM_API.h" 00018 #include "SIM_Constraint.h" 00019 #include <UT/UT_PtrArray.h> 00020 00021 class SIM_DataFilter; 00022 class SIM_Object; 00023 class SIM_ConAnchor; 00024 00025 /// Iterator for constraints. 00026 /// 00027 /// This class simplifies the process of scanning the constraints 00028 /// associated with an object. Constraints are complicated to iterate: you 00029 /// have to scan over the SIM_Constraints, then over each SIM_Constraint's 00030 /// SIM_Relationships, then over the anchors within the relationship. This 00031 /// class hides that complexity. 00032 /// 00033 /// The iterator is similar in principal to an STL iterator, but somewhat 00034 /// simpler. The classic STL loop 00035 /// for ( it = begin(); it != end(); ++it ) 00036 /// is done using 00037 /// for ( it.rewind(); !it.atEnd(); it.advance() ) 00038 /// 00039 /// The IterationStyle parameter in the SIM_ConstraintIterator's constructor 00040 /// affects how constraint anchors of the type SIM_ConAnchorObjPointGroupPos 00041 // are traversed: 00042 /// 00043 /// PRESENT_GROUP_AS_MULTIPLE: 00044 /// This will present each point in a group as a separate 00045 /// point anchor. That means that the iterator will point to the 00046 /// same anchor multiple times during a traversal. 00047 /// During each visit of this traversal, the anchor will pose as 00048 // a different point in the group. 00049 /// SIM_ConstraintIterator implements this iteration 00050 /// mode by using the members "reset", "nextPoint", and "atEnd" 00051 /// to manipulate the group anchor's "current point. 00052 /// 00053 /// PRESENT_GROUP_AS_SINGLE: 00054 /// This will treat a group constraint as a single constraint. 00055 /// It will only be visited once during an iteration traversal. 00056 /// The client code will have to explicitly extract the individual 00057 /// points. 00058 /// 00059 00060 class SIM_API SIM_ConstraintIterator 00061 { 00062 public: 00063 enum IterationStyle { 00064 PRESENT_GROUP_AS_MULTIPLE, 00065 PRESENT_GROUP_AS_SINGLE 00066 }; 00067 00068 /// Iterate over all constraint relationships on the given object, 00069 /// accepting only those whose relationships pass the given filter. (Note 00070 /// that relationships don't necessarily have any data "name", so filtering 00071 /// by name is meaningless.) 00072 /// The requirePinAnchor option forces the iteration to only include 00073 /// constraints that are pinned to this object. 00074 SIM_ConstraintIterator(SIM_Object &object, 00075 const SIM_DataFilter *relFilter, 00076 const SIM_DataFilter *currentFilter, 00077 const SIM_DataFilter *goalFilter, 00078 const SIM_Time &time, 00079 const IterationStyle style = 00080 PRESENT_GROUP_AS_MULTIPLE 00081 ); 00082 ~SIM_ConstraintIterator(); 00083 00084 /// Test to see if the iterator is at the end. 00085 bool atEnd() const; 00086 /// Advance the iterator to the next item. 00087 void advance(); 00088 /// Reset the iterator to the start of iteration. 00089 void rewind(); 00090 00091 /// Get the constraint associated with the current item. 00092 SIM_Constraint *getConstraint() const; 00093 00094 /// Get the relationship associated with the current constraint. 00095 SIM_ConRel *getConRel() const; 00096 const SIM_ConAnchor *getCurrentAnchor() const; 00097 const SIM_ConAnchor *getGoalAnchor() const; 00098 00099 /// Call all constraints to make state transitions based on their most 00100 /// recent state data updates. 00101 static void makeStateTransitions(SIM_Object &object, 00102 const SIM_Time &time); 00103 /// Call all constraints to set the valid state on them. 00104 static void initConstraints(SIM_Object &object, 00105 const SIM_Time &time); 00106 00107 private: 00108 /// Disallowed. 00109 SIM_ConstraintIterator( 00110 const SIM_ConstraintIterator &); 00111 SIM_ConstraintIterator &operator=(const SIM_ConstraintIterator &); 00112 00113 /// Advance indexes until we point to a valid item. 00114 /// (i.e. a constraint with a non-zero number of relationships) 00115 void skipInvalid(); 00116 00117 int myObjectId; 00118 const SIM_Time &myTime; 00119 const SIM_DataFilter *myRelFilter; 00120 const SIM_DataFilter *myCurrentFilter; 00121 const SIM_DataFilter *myGoalFilter; 00122 UT_PtrArray<SIM_Relationship *> myRelationships; 00123 UT_PtrArray<SIM_Constraint *> myConstraints; 00124 SIM_ConRel *myConRel; 00125 const SIM_ConAnchor *myCurrentAnchor; 00126 const SIM_ConAnchor *myGoalAnchor; 00127 int myConIdx; 00128 bool myIsMirrored; 00129 const IterationStyle myIterationStyle; 00130 }; 00131 00132 #endif
1.5.9