HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_ConRel.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_ConRel_h__
9 #define __SIM_ConRel_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_DataUtils.h"
13 #include "SIM_OptionsUser.h"
14 
15 class UT_IStream;
16 class SIM_ConAnchor;
17 class SIM_Relationship;
18 
19 /// This enumeration defines the error codes that can be set on a SIM_ConRel.
20 typedef enum {
27 
28 /// Definition of the relationship between the anchors in a constraint -
29 /// i.e., how a constraint affects its anchors.
30 ///
31 /// Also contains state information - the force applied to enforce the
32 /// constraint, and the distance separating the anchors. This can be very
33 /// useful for switching relationships in response to the constraint's
34 /// performance.
35 class SIM_API SIM_ConRel : public SIM_Data
36 {
37 public:
38 
39  /// A utility class for getting values of the constraint options.
40  /// An instance of this class is passed as an argument to buildConRelGude(..)
41  /// so that rendering of the constraint guide geometry can be done accuratly
42  /// depending on who calls it.
43  /// The diffuse attribute (color_attrib) is passed in for efficiency reasons,
44  /// so that each call of buildConRelGuide does not need to call addDiffuseAttribute
45  /// on its own
46  class ConRelData
47  {
48  public:
49  ConRelData(const SIM_Data* op, const GA_RWHandleV3 &cd)
50  : myOptions(dynamic_cast<const SIM_OptionsUser*>(op)),
51  color_attrib(cd)
52  {
53  }
54  virtual ~ConRelData() { }
55  virtual bool getDataB(const UT_StringRef &name) const
56  {
57  return myOptions ? myOptions->getOptions().getOptionB(name) : 0;
58  }
59  virtual int getDataI(const UT_StringRef &name) const
60  {
61  return myOptions ? myOptions->getOptions().getOptionI(name) : 0;
62  }
63  virtual fpreal getDataF(const UT_StringRef &name) const
64  {
65  return myOptions ? myOptions->getOptions().getOptionF(name) : 0;
66  }
67  virtual UT_Vector3 getDataV3(const UT_StringRef &name) const
68  {
69  return myOptions ? myOptions->getOptions().getOptionV3(name) : UT_Vector3D(0,0,0);
70  }
71  virtual UT_Quaternion getDataQ(const UT_StringRef &name) const
72  {
73  return myOptions ? myOptions->getOptions().getOptionQ(name) : UT_QuaternionD(0,0,0,1);
74  }
75  virtual UT_Vector2 getDataV2(const UT_StringRef &name) const
76  {
77  return myOptions ? myOptions->getOptions().getOptionV2(name) : UT_Vector2D(0,0);
78  }
79  const GA_RWHandleV3 &getColorAttrib() const { return color_attrib; }
80  protected:
83  };
84 
85  SIM_ConRel *getSubConRel();
86  /// Be careful using the const version. It should really only be used
87  /// when SIM_Constraint is generating guide geometry.
88  const SIM_ConRel *getConstSubConRel() const;
89  void makeStateTransition(const SIM_Time &time);
90 
91  /// Functions to get and set state information.
92  void setStateForce(fpreal force);
93  fpreal getStateForce() const;
94  void setStateDistance(fpreal distance);
95  fpreal getStateDistance() const;
96 
97  /// A constraint is invalid if its parameters cannot be resolved.
98  void setStateErrorCode(SIM_ConRelError errorcode);
99  SIM_ConRelError getStateErrorCode() const;
100 
101  /// Build guide geometry for the conrel, and also get the anchors to build
102  /// their own guide geometry.
103  void buildConRelGuideGeometry(
104  const GU_DetailHandle &gdh,
105  const SIM_Time &time,
106  const SIM_Relationship &rel,
107  const SIM_ConAnchor &anchor1,
108  const SIM_ConAnchor &anchor2) const;
109  virtual void buildConRelGuide(
110  const GU_DetailHandle &gdh,
111  const SIM_Options &options,
112  const UT_Vector3 &anchor_pos_1,
113  const UT_Vector3 &anchor_pos_2,
114  const UT_Quaternion &anchor_rot_1,
115  const UT_Quaternion &anchor_rot_2,
116  const ConRelData &c_data) const;
117 protected:
118  explicit SIM_ConRel(const SIM_DataFactory *factory);
119  ~SIM_ConRel() override;
120 
121  void initializeSubclass() override;
122  void makeEqualSubclass(const SIM_Data *source) override;
123  void saveSubclass(std::ostream &os) const override;
124  bool loadSubclass(UT_IStream &is) override;
125 
126  SIM_Query *createQueryObjectSubclass() const override;
127 
128  virtual SIM_ConRel *getSubConRelSubclass();
129  virtual const SIM_ConRel
130  *getConstSubConRelSubclass() const;
131  virtual void makeStateTransitionSubclass(const SIM_Time &time);
132  virtual void setStateForceSubclass(fpreal force);
133  virtual fpreal getStateForceSubclass() const;
134  virtual void setStateDistanceSubclass(fpreal distance);
135  virtual fpreal getStateDistanceSubclass() const;
136  virtual void buildConRelGuideGeometrySubclass(
137  const GU_DetailHandle &gdh,
138  const SIM_Time &time,
139  const SIM_Relationship &rel,
140  const SIM_ConAnchor &anchor1,
141  const SIM_ConAnchor &anchor2) const;
142 
143 private:
144  /// Store the error code that is part of our state.
145  SIM_ConRelError myStateErrorCode;
146  /// This value gets set to true when we are calling makeStateTransition
147  /// to avoid infinite recursions.
148  bool myMakingStateTransition;
149  /// This value gets set to true when we are calling getSubConRel
150  /// to avoid infinite recursions.
151  mutable bool myGettingConRel;
152 
155 };
156 
157 #endif
virtual void makeEqualSubclass(const SIM_Data *source)
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:50
#define DECLARE_CLASSNAME(DataClass, SuperClass)
Definition: SIM_DataUtils.h:20
virtual bool loadSubclass(UT_IStream &is)
SIM_ConRelError
This enumeration defines the error codes that can be set on a SIM_ConRel.
Definition: SIM_ConRel.h:20
GT_API const UT_StringHolder time
virtual SIM_Query * createQueryObjectSubclass() const
UT_Vector2T< fpreal64 > UT_Vector2D
virtual int getDataI(const UT_StringRef &name) const
Definition: SIM_ConRel.h:59
GA_RWHandleV3 color_attrib
Definition: SIM_ConRel.h:82
virtual fpreal getDataF(const UT_StringRef &name) const
Definition: SIM_ConRel.h:63
ConRelData(const SIM_Data *op, const GA_RWHandleV3 &cd)
Definition: SIM_ConRel.h:49
UT_QuaternionT< fpreal64 > UT_QuaternionD
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
const SIM_OptionsUser * myOptions
Definition: SIM_ConRel.h:81
virtual void saveSubclass(std::ostream &os) const
UT_Vector3T< fpreal64 > UT_Vector3D
virtual bool getDataB(const UT_StringRef &name) const
Definition: SIM_ConRel.h:55
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual UT_Vector3 getDataV3(const UT_StringRef &name) const
Definition: SIM_ConRel.h:67
SIM_API const UT_StringHolder force
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual UT_Vector2 getDataV2(const UT_StringRef &name) const
Definition: SIM_ConRel.h:75
#define SIM_API
Definition: SIM_API.h:12
const GA_RWHandleV3 & getColorAttrib() const
Definition: SIM_ConRel.h:79
#define const
Definition: zconf.h:214
SIM_API const UT_StringHolder distance
virtual void initializeSubclass()
virtual UT_Quaternion getDataQ(const UT_StringRef &name) const
Definition: SIM_ConRel.h:71