HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_ConstraintIterator.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_ConstraintIterator_h__
9 #define __SIM_ConstraintIterator_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_Constraint.h"
13 #include <UT/UT_ValArray.h>
14 
15 class SIM_DataFilter;
16 class SIM_Object;
17 class SIM_ConAnchor;
18 
19 /// Iterator for constraints.
20 ///
21 /// This class simplifies the process of scanning the constraints
22 /// associated with an object. Constraints are complicated to iterate: you
23 /// have to scan over the SIM_Constraints, then over each SIM_Constraint's
24 /// SIM_Relationships, then over the anchors within the relationship. This
25 /// class hides that complexity.
26 ///
27 /// The iterator is similar in principal to an STL iterator, but somewhat
28 /// simpler. The classic STL loop
29 /// for ( it = begin(); it != end(); ++it )
30 /// is done using
31 /// for ( it.rewind(); !it.atEnd(); it.advance() )
32 ///
33 /// The IterationStyle parameter in the SIM_ConstraintIterator's constructor
34 /// affects how constraint anchors of the type SIM_ConAnchorObjPointGroupPos
35 // are traversed:
36 ///
37 /// PRESENT_GROUP_AS_MULTIPLE:
38 /// This will present each point in a group as a separate
39 /// point anchor. That means that the iterator will point to the
40 /// same anchor multiple times during a traversal.
41 /// During each visit of this traversal, the anchor will pose as
42 // a different point in the group.
43 /// SIM_ConstraintIterator implements this iteration
44 /// mode by using the members "reset", "nextPoint", and "atEnd"
45 /// to manipulate the group anchor's "current point.
46 ///
47 /// PRESENT_GROUP_AS_SINGLE:
48 /// This will treat a group constraint as a single constraint.
49 /// It will only be visited once during an iteration traversal.
50 /// The client code will have to explicitly extract the individual
51 /// points.
52 ///
53 
55 {
56 public:
59  PRESENT_GROUP_AS_SINGLE
60  };
61 
62  /// Iterate over all constraint relationships on the given object,
63  /// accepting only those whose relationships pass the given filter. (Note
64  /// that relationships don't necessarily have any data "name", so filtering
65  /// by name is meaningless.)
66  /// The requirePinAnchor option forces the iteration to only include
67  /// constraints that are pinned to this object.
69  const SIM_DataFilter *relFilter,
70  const SIM_DataFilter *currentFilter,
71  const SIM_DataFilter *goalFilter,
72  const SIM_Time &time,
73  const IterationStyle style =
74  PRESENT_GROUP_AS_MULTIPLE
75  );
77 
78  /// Test to see if the iterator is at the end.
79  bool atEnd() const;
80  /// Advance the iterator to the next item.
81  void advance();
82  /// Reset the iterator to the start of iteration.
83  void rewind();
84 
85  /// Get the constraint associated with the current item.
86  SIM_Constraint *getConstraint() const;
87 
88  /// Get the relationship associated with the current constraint.
89  SIM_ConRel *getConRel() const;
90  const SIM_ConAnchor *getCurrentAnchor() const;
91  const SIM_ConAnchor *getGoalAnchor() const;
92 
93  /// Call all constraints to make state transitions based on their most
94  /// recent state data updates.
95  static void makeStateTransitions(SIM_Object &object,
96  const SIM_Time &time);
97  /// Call all constraints to set the valid state on them.
98  static void initConstraints(SIM_Object &object,
99  const SIM_Time &time);
100 
101 private:
102  /// Disallowed.
104  const SIM_ConstraintIterator &);
106 
107  /// Advance indexes until we point to a valid item.
108  /// (i.e. a constraint with a non-zero number of relationships)
109  void skipInvalid();
110 
111  int myObjectId;
112  const SIM_Time &myTime;
113  const SIM_DataFilter *myRelFilter;
114  const SIM_DataFilter *myCurrentFilter;
115  const SIM_DataFilter *myGoalFilter;
116  UT_ValArray<SIM_Relationship *> myRelationships;
117  UT_ValArray<SIM_Constraint *> myConstraints;
118  SIM_ConRel *myConRel;
119  const SIM_ConAnchor *myCurrentAnchor;
120  const SIM_ConAnchor *myGoalAnchor;
121  int myConIdx;
122  bool myIsMirrored;
123  const IterationStyle myIterationStyle;
124 };
125 
126 extern SIM_API void
128  SIM_Object &object,
131 
132 #endif
GT_API const UT_StringHolder time
SIM_API void SIMfindConstraints(SIM_Object &object, UT_ValArray< SIM_Relationship * > *rels, UT_ValArray< SIM_Constraint * > *cons)
LeafData & operator=(const LeafData &)=delete
#define SIM_API
Definition: SIM_API.h:12