LightWrap++
AC++wrapperfortheLightWave3DSDK
vparm.h
Go to the documentation of this file.
1 
7 #include <lwvparm.h>
8 #include <lwenvel.h>
9 #include "lwpp/storeable.h"
10 
11 #ifndef LW_VPARM_H
12 #define LW_VPARM_H
13 
14 #include <lwpp/Vector3d.h>
15 
16 namespace lwpp
17 {
18 
19  class ChannelGroup;
21 
25  class VParm : protected GlobalBase<LWVParmFuncs>, public Vector3d, public Storeable
26  {
27  LWVParmID vparmID;
28  bool create(int type, const std::string name, const std::string plug_name, LWChanGroupID group);
29  VParm(const VParm &from);
30 
31  void set(void)
32  {
33  (*globPtr->setVal)(vparmID, asLWVector());
34  }
35  public:
36  VParm(int type, const std::string name, std::string plug_name, LWChanGroupID group = 0, double v = 0.0);
37  VParm(int type, const std::string name, std::string plug_name, LWChanGroupID group, Vector3d &v);
38  VParm(int type, const std::string name, std::string plug_name, ChannelGroup& group, double v = 0.0);
39  VParm(int type, const std::string name, std::string plug_name, ChannelGroup& group, Vector3d &v);
40  virtual ~VParm();
42  VParm &operator=(const VParm &from);
43 
45  virtual LWError Load(const lwpp::LoadState &ls );
47  virtual LWError Save(const lwpp::SaveState &ss );
48 
50  LWVParmID ID() {return vparmID;}
52  void NewTime(LWTime t)
53  {
54  (*globPtr->getVal)(vparmID, t, 0, asLWVector() );
55  }
56 
57  void Clear()
58  {
59  (*globPtr->setState)(vparmID, 0);
60  }
61 
62  void Reset(const double d)
63  {
64  Clear();
65  x = y = z = d;
66  set();
67  }
68  void Reset(const Vector3d &v)
69  {
70  Clear();
71  x = v.x; y = v.y; z = v.z;
72  set();
73  }
75  void Set(const double d)
76  {
77  x = y = z = d;
78  set();
79  }
80  void Set(const Vector3d &v)
81  {
82  x = v.x; y = v.y; z = v.z;
83  set();
84  }
85  void Set(const LWDVector v)
86  {
87  x = v[0]; y = v[1]; z = v[2];
88  set();
89  }
90  void Set(const LWFVector v)
91  {
92  x = v[0]; y = v[1]; z = v[2];
93  set();
94  }
95 
96  double GetValue() const
97  {
98  return x;
99  }
100  float GetValuef() const
101  {
102  return static_cast<float>(x);
103  }
104  bool isEnveloped()
105  {
106  return (globPtr->getState(vparmID) & LWVPSF_ENV) == LWVPSF_ENV;
107  }
108 
109  };
110 
111  typedef std::auto_ptr<VParm> auto_VParm;
112 
113 /*
114  const char *(*channelName) ( LWChannelID chan);
115  LWChanGroupID (*channelParent) ( LWChannelID chan);
116  int (*channelType) ( LWChannelID chan);
117  double (*channelEvaluate) ( LWChannelID chan, LWTime time);
118  const LWEnvelopeID (*channelEnvelope) ( LWChannelID chan);
119  int (*setChannelEvent) ( LWChannelID chan, LWChanEventFunc ev, void *data );
120  const char *(*server) ( LWChannelID chan, const char *cls, int idx );
121  unsigned int (*serverFlags) ( LWChannelID chan, const char *cls, int idx );
122  LWInstance (*serverInstance) ( LWChannelID chan, const char *cls, int idx );
123  int (*serverApply) ( LWChannelID chan, const char *cls, const char *name, int flags );
124  void (*serverRemove) ( LWChannelID chan, const char *cls, const char *name, LWInstance inst );
125 */
126 
127  class ChannelGroup : protected GlobalBase<LWChannelInfo>
128  {
129  LWChanGroupID groupID;
131  bool destroy_on_exit;
132  public:
134  : groupID(0),
135  destroy_on_exit(false)
136  {
137  ;
138  }
139  ChannelGroup(const char *name, LWChanGroupID parent = 0, bool destroy = true)
140  : groupID(0), destroy_on_exit(destroy)
141  {
142  groupID = createUniqueGroup(name, parent);
143  }
144 
145  ChannelGroup(const char *name, ChannelGroup& parent)
146  : groupID(0), destroy_on_exit(true)
147  {
148  groupID = createUniqueGroup(name, parent.getID());
149  }
150 
151  ChannelGroup(LWChanGroupID id)
152  : groupID(id), destroy_on_exit(false)
153  {
154  ;
155  }
156 
157  void Create(const char *name, LWChanGroupID parent, bool destroy = true)
158  {
159  Reset();
160  groupID = createUniqueGroup(name, parent);
161  destroy_on_exit = destroy;
162  }
163 
164  void Reset()
165  {
166  if (groupID && destroy_on_exit)
167  {
168  envf->destroyGroup(groupID);
169  groupID = 0;
170  }
171  }
172 
173  virtual ~ChannelGroup(void)
174  {
175  Reset();
176  }
177  LWChanGroupID getID() const {return groupID;}
178  LWChanGroupID nextGroup( LWChanGroupID parent, LWChanGroupID group) {return globPtr->nextGroup(parent, group);}
179  LWChannelID nextChannel( LWChanGroupID parent, LWChannelID chan) {return globPtr->nextChannel(parent, chan);}
180  const char *groupName ( LWChanGroupID group) {return globPtr->groupName(group);}
181  const char *groupName ( void ) {return globPtr->groupName(groupID);}
182  LWChanGroupID groupParent ( LWChanGroupID group) {return globPtr->groupParent(group);}
183  LWChanGroupID groupParent (void) {return globPtr->groupParent(groupID);}
184 
185  LWChanGroupID createUniqueGroup(const char *name, LWChanGroupID parent)
186  {
187  int i = 0;
188 
189  LWChanGroupID return_group;
190  char *channel_name = new char[strlen(name) + 10];
191  //sprintf(channel_name, name); // create new name
192  strcpy(channel_name, name);
193  for ( ; ; )
194  {
195  bool chan_found = false;
196 
197  LWChanGroupID grp = nextGroup(parent, 0); // get first channel
198  // iterate through all channels
199  while (!chan_found && (grp))
200  {
201  if (strcmp(channel_name, groupName(grp)) == 0)
202  chan_found = true;
203 
204  grp = nextGroup(parent, grp);
205  }
206  // Current channel name does not exist!
207  if (chan_found)
208  {
209  sprintf(channel_name, "%s(%i)", name, i++); // create new name
210  }
211  else
212  {
213  return_group = envf->createGroup(parent, channel_name);
214  delete[] channel_name;
215  return return_group; // exit
216  }
217  }
218  }
219 
220  LWEnvelopeID findEnvelope(std::string name )
221  {
222  LWChannelID chan = nextChannel( groupID, NULL );
223  while ( chan )
224  {
225  if ( name == globPtr->channelName( chan ))
226  {
227  return globPtr->channelEnvelope( chan );
228  }
229  chan = nextChannel( groupID, chan );
230  }
231  return 0;
232  }
233 
234  };
235 }
236 #endif // LW_VPARM_H