LightWrap++
AC++wrapperfortheLightWave3DSDK
surface.h
Go to the documentation of this file.
1 #ifndef LWPP_SURFACE_H
2 #define LWPP_SURFACE_H
3 
4 #include <lwpp/global.h>
5 #include <lwsurf.h>
6 #include <set>
7 #include <lwpp/wrapper.h>
8 
9 namespace lwpp
10 {
11  class LWSurface : public GlobalBase<LWSurfaceFuncs>
12  {
13  protected:
14  LWSurfaceID id;
15  public:
17  LWSurface() : id(0)
18  {
19  first();
20  }
22  LWSurface(LWSurfaceID _id) : id(_id){;}
24  LWSurface(const char *objName, const char *surfName) : id(0)
25  {
26  id = globPtr->create(objName, surfName);
27  }
28  const char *name() const {return globPtr->name(id);}
29  void first ()
30  {
31  id = globPtr->first();
32  }
33  bool next()
34  {
35  id = globPtr->next(id);
36  return (id != 0);
37  }
38  bool exists()
39  {
40  return (id != 0);
41  }
42  LWSurfaceID getID() const
43  {
44  return id;
45  }
46  bool operator<(const LWSurface &s) const {return id < s.id;}
47  const char *sceneObject() const {return globPtr->sceneObject(id);}
48 
49  LWTextureID getTexture(const char *channel) const { return globPtr->getTex(id, channel);}
50  int getInteger(const char *channel) const { return globPtr->getInt(id, channel);}
51  double *getDouble(const char *channel) const { return globPtr->getFlt(id, channel);}
52  LWEnvelopeID getEnvelope(const char *channel) const { return globPtr->getEnv(id, channel);}
53  LWImageID getImage(const char *channel) const { return globPtr->getImg(id, channel);}
54  LWChanGroupID getChannelGroup() const { return globPtr->chanGrp(id);}
55  const char *getColorVMap() const {return globPtr->getColorVMap(id);}
56  void setColorVMap(const char *vmapName, int type) {globPtr->setColorVMap(id, vmapName, type);}
57  NodeEditorID getNodeEditor( )
58  {
59  return globPtr->getNodeEditor(id);
60  }
61  typedef std::set<LWSurface> SurfaceSet;
62  typedef SurfaceSet::iterator iterSurfaceSet;
63  SurfaceSet byName(std::string name, std::string obj) const;
64  SurfaceSet byName(std::string name) const;
65  SurfaceSet byObject(std::string name) const;
66  };
67 
69 
74  template <bool showNone = true>
75  class SurfaceReference : public PopUpCallback, public LWSurface
76  {
77  protected:
79  virtual size_t popCount (void)
80  {
81  LWSurface surf;
82  surf.first();
83  int count = 0;
84  while (surf.exists())
85  {
86  ++count;
87  surf.next();
88  }
89  return count + (showNone ? 1 : 0);
90  }
92  virtual const char *popName (int idx)
93  {
94  if (showNone)
95  {
96  if (idx == 0) return "(none)";
97  --idx;
98  }
99  LWSurface surf(GetIndexID (idx));
100  if (surf.exists())
101  {
102  return surf.name();
103  }
104  return "";
105  }
106  public:
108  SurfaceReference(LWSurfaceID _id = 0)
109  : LWSurface(_id)
110  {
111  if (id != 0)
112  {
113  index = GetIndex();
114  }
115  }
117  LWSurfaceID GetIndexID (int idx)
118  {
119  if (showNone)
120  {
121  if (idx == 0)
122  {
123  id = 0;
124  return 0;
125  }
126  --idx;
127  }
128  LWSurface surf;
129  surf.first();
130  for (int i = 1; i <= idx; ++i)
131  {
132  surf.next();
133  }
134  id = surf.getID();
135 
136  return id;
137  }
138  int GetIndex()
139  {
140  if (id == 0) return 0;
141  int idx = (showNone ? 1 : 0);
142  LWSurface surf;
143  surf.first();
144  while (surf.exists())
145  {
146  if (id == surf.getID()) return idx;
147  ++idx;
148  surf.next();
149  }
150  return 0;
151  }
153  int *DataGet ()
154  {
155  index = GetIndex();
156  return &index;
157  }
159  void DataSet(void *value)
160  {
161  index = *((int *)value);
162  GetIndexID(index);
163  }
164  };
165 }
166 
167 /*
168  typedef struct st_LWSurfaceFuncs {
169  LWSurfaceID (*create) (const char *objName,
170  const char *surfName);
171  LWSurfaceID * (*byName) (const char *name, const char *obj);
172  LWSurfaceID * (*byObject) (const char *name);
173 
174  int (*getInt)(LWSurfaceID surf,const char *channel);
175  double *(*getFlt)(LWSurfaceID surf,const char *channel);
176  LWEnvelopeID (*getEnv)(LWSurfaceID surf,const char *channel);
177  LWTextureID (*getTex)(LWSurfaceID surf,const char *channel);
178  LWImageID (*getImg)(LWSurfaceID surf,const char *channel);
179 
180  LWChanGroupID (*chanGrp)(LWSurfaceID surf);
181  const char *(*getColorVMap)(LWSurfaceID surf);
182  void (*setColorVMap)(LWSurfaceID surf,const char *vmapName,int type);
183 
184  LWSurfLibID (*createLib)(void);
185  void (*destroyLib)(LWSurfLibID lib);
186  void (*copyLib)(LWSurfLibID to, LWSurfLibID from);
187  LWSurfLibID (*objectLib)(const char *objname);
188  LWSurfLibID (*loadLib)(const char *name);
189  LWError (*saveLib)(LWSurfLibID lib, const char *name);
190  int (*slibCount)(LWSurfLibID lib);
191  LWSurfaceID (*slibByIndex)(LWSurfLibID lib,int idx);
192  NodeEditorID (*getNodeEditor)( LWSurfaceID surf);
193  } LWSurfaceFuncs;
194 */
195 
196 #endif // LWPP_SURFACE_H