LightWrap++
AC++wrapperfortheLightWave3DSDK
mod_command.h
Go to the documentation of this file.
1 
4 #ifndef LWPP_MOD_COMMAND_H
5 #define LWPP_MOD_COMMAND_H
6 
7 #include <lwpp/global.h>
8 
9 #include <lwmodeler.h>
10 #include <lwcmdseq.h>
11 
12 namespace lwpp
13 {
14 
16  {
17  public:
18  static EDError doScan (void*p, const EDPointInfo* info)
19  {
20  PointScanner *host = static_cast<PointScanner *>(p);
21  return host->Scan(info);
22  }
23  virtual EDError Scan(const EDPointInfo* info) {return EDERR_NONE;}
24  };
25 
27  {
28  public:
29  static EDError doScan (void*p, LWPntID id)
30  {
31  FastPointScanner *host = static_cast<FastPointScanner *>(p);
32  return host->Scan(id);
33  }
34  virtual EDError Scan(LWPntID id) {return EDERR_NONE;}
35  };
36 
38  {
39  public:
40  static EDError doScan (void*p, const EDEdgeInfo* info)
41  {
42  EdgeScanner *host = static_cast<EdgeScanner *>(p);
43  return host->Scan(info);
44  }
45  virtual EDError Scan(const EDEdgeInfo* info) {return EDERR_NONE;}
46  };
47 
49  {
50  public:
51  static EDError doScan (void*p, LWEdgeID id)
52  {
53  FastEdgeScanner *host = static_cast<FastEdgeScanner *>(p);
54  return host->Scan(id);
55  }
56  virtual EDError Scan(LWEdgeID id) {return EDERR_NONE;}
57  };
58 
60  {
61  public:
62  static EDError doScan (void*p, const EDPolygonInfo* info)
63  {
64  PolyScanner *host = static_cast<PolyScanner *>(p);
65  return host->Scan(info);
66  }
67  virtual EDError Scan(const EDPolygonInfo* info) {return EDERR_NONE;}
68  };
69 
71  {
72  public:
73  static EDError doScan (void*p, LWPolID id)
74  {
75  FastPolyScanner *host = static_cast<FastPolyScanner *>(p);
76  return host->Scan(id);
77  }
78  virtual EDError Scan(LWPolID id) {return EDERR_NONE;}
79  };
80 
82  {
83  protected:
84  const MeshEditOp *me;
85  public:
86  MeshEditOperator(const MeshEditOp *_me = 0)
87  : me(_me)
88  {}
89 
90  MeshEditOperator(const MeshEditOp &_me)
91  : me(&_me)
92  {}
93 
94  void SetMeshEditOp(const MeshEditOp *_me)
95  {
96  me = _me;
97  }
98 
100  {
101  if (this != &from)
102  {
103  me = from.me;
104  }
105  }
106  int getLayer() {assert(me!=0); return me->layerNum;}
108 
133  void Done (EDError err, int selm)
134  {
135  assert(me!=0);
136  if(me) me->done(me->state, err, selm);
137  }
138 
139  int GetPointCount (EltOpLayer lyr, int mode)
140  {
141  assert(me!=0);
142  if(me) return me->pointCount(me->state, lyr, mode);
143  return 0;
144  }
145 
146  int GetPolyCount (EltOpLayer lyr, int mode)
147  {
148  assert(me!=0);
149  if(me) return me->polyCount(me->state, lyr, mode);
150  return 0;
151  }
152 
153  EDError Scan(PointScanner &scanner, EltOpLayer lyr)
154  {
155  assert(me!=0);
156  if(me) return me->pointScan (me->state, &PointScanner::doScan, &scanner, lyr);
157  return 0;
158  }
159 
160  EDError Scan(FastPointScanner &scanner, EltOpLayer lyr, bool selOnly)
161  {
162  assert(me!=0);
163  if(me) return me->fastPointScan (me->state, &FastPointScanner::doScan, &scanner, lyr, selOnly ? 1 : 0);
164  return 0;
165  }
166 
167  EDError Scan(PolyScanner &scanner, EltOpLayer lyr)
168  {
169  assert(me!=0);
170  if(me) return me->polyScan (me->state, &PolyScanner::doScan, &scanner, lyr);
171  return 0;
172  }
173 
174  EDError Scan(FastPolyScanner &scanner, EltOpLayer lyr, bool selOnly)
175  {
176  assert(me!=0);
177  if(me) return me->fastPolyScan (me->state, &FastPolyScanner::doScan, &scanner, lyr, selOnly ? 1 : 0);
178  return 0;
179  }
180 
181  EDPointInfo *GetInfo (LWPntID id)
182  {
183  assert(me!=0);
184  if(me) return me->pointInfo (me->state, id);
185  return 0;
186  }
187 
188  EDPolygonInfo *GetInfo (LWPolID id)
189  {
190  assert(me!=0);
191  if (me) return me->polyInfo (me->state, id);
192  return 0;
193  }
194 
195  bool GetPolyNormal(LWPolID id, double n[3])
196  {
197  assert(me!=0);
198  if (me)
199  {
200  return (me->polyNormal(me->state, id, n) != 0);
201  }
202  return false;
203  }
204 
205  LWPntID AddPoint(double *xyz)
206  {
207  assert(me!=0);
208  if (me) return me->addPoint(me->state, xyz);
209  return 0;
210  }
211 
212  LWPolID AddFace(const char *surf, int numPnt, const LWPntID *pnts)
213  {
214  assert(me!=0);
215  if (me) return me->addFace(me->state, surf, numPnt, pnts);
216  return 0;
217  }
218 
219  LWPolID AddCurve(const char *surf, int numPnt, const LWPntID *pnts, int flags)
220  {
221  assert(me!=0);
222  if (me) return me->addCurve(me->state, surf, numPnt, pnts, flags);
223  return 0;
224  }
225 
226  EDError AddQuad(LWPntID p1, LWPntID p2, LWPntID p3, LWPntID p4)
227  {
228  assert(me!=0);
229  if (me) return me->addQuad(me->state, p1, p2, p3, p4);
230  return 0;
231  }
232 
233  EDError AddTri(LWPntID p1, LWPntID p2, LWPntID p3)
234  {
235  assert(me!=0);
236  if (me) return me->addTri(me->state, p1, p2, p3);
237  return 0;
238  }
239 
240  EDError AddPatch(int nr, int nc, int lr, int lc, EDBoundCv *r0, EDBoundCv *r1, EDBoundCv *c0, EDBoundCv *c1)
241  {
242  assert(me!=0);
243  if (me) return me->addPatch(me->state, nr, nc, lr, lc, r0, r1, c0, c1);
244  return 0;
245  }
246 
247  EDError Remove (LWPntID id)
248  {
249  assert(me!=0);
250  if (me) return me->remPoint (me->state, id);
251  return 0;
252  }
253 
254  EDError Remove (LWPolID id)
255  {
256  assert(me!=0);
257  if (me) return me->remPoly (me->state, id);
258  return 0;
259  }
260 
261  EDError Move (LWPntID id, const double *delta)
262  {
263  assert(me!=0);
264  if (me) return me->pntMove (me->state, id, delta);
265  return 0;
266  }
267 
269  EDError SetSurface (LWPolID id, const char *name)
270  {
271  assert(me!=0);
272  if (me) return me->polSurf (me->state, id, name);
273  return 0;
274  }
275 
277  EDError ReplacePolyPoints (LWPolID id, int n, const LWPntID *p)
278  {
279  assert(me!=0);
280  if (me) return me->polPnts (me->state, id, n, p);
281  return 0;
282  }
283 
285 
291  EDError SetPolyFlags (LWPolID id, int mask, int value)
292  {
293  assert(me!=0);
294  if (me) return me->polFlag (me->state, id, mask, value);
295  return 0;
296  }
297 
299 
306  EDError SetPolTag (LWPolID id, LWID type, const char *name = 0)
307  {
308  assert(me!=0);
309  if (me) return me->polTag (me->state, id, type, name);
310  return 0;
311  }
312 
314 
326  EDError SetVMap (LWPntID id, LWID vmap, const char *c = 0, int i = 0, float *f = 0)
327  {
328  assert(me!=0);
329  if (me) return me->pntVMap (me->state, id, vmap, c, i, f);
330  return 0;
331  }
332 
334 
342  LWPolID AddPoly (LWID type, int numPnt, const LWPntID *pnt, LWPolID tmpl = 0, const char *surf = 0 )
343  {
344  assert(me!=0);
345  if (me) return me->addPoly (me->state, type, tmpl, surf, numPnt, pnt);
346  return 0;
347  }
348 
350 
357  LWPntID AddIPoint (double *xyz, int numPnt, const LWPntID *ids, const double *wt = 0)
358  {
359  assert(me!=0);
360  if (me) return me->addIPnt (me->state, xyz, numPnt, ids, wt);
361  return 0;
362  }
363  LWPntID AddIPoint (int numPnt, const LWPntID *ids, const double *wt = 0)
364  {
365  return AddIPoint(0, numPnt, ids, wt);
366  }
367 
369 
390  EDError InitUV (float *uv)
391  {
392  assert(me!=0);
393  if (me) return me->initUV (me->state, uv);
394  return 0;
395  }
396 
398 
405  void *Select (void *vmapID, LWID vmaptype, const char *vmapname)
406  {
407  assert(me!=0);
408  if (me) return me->pointVSet (me->state, vmapID, vmaptype, vmapname);
409  return 0;
410  }
411  void *Select (LWID vmaptype, const char *vmapname)
412  {
413  return Select(0, vmaptype, vmapname);
414  }
416 
430  bool ReadVMap (LWPntID point, float *val)
431  {
432  assert(me!=0);
433  if (me) return (me->pointVGet (me->state, point, val) != 0);
434  return 0;
435  }
436 
438 
441  const char *GetPolyTag (LWPolID polygon, LWID tagtype)
442  {
443  assert(me!=0);
444  if (me) return me->polyTag (me->state, polygon, tagtype);
445  return "";
446  }
447 
449 
453  EDError Select (LWPntID pnt, bool sel)
454  {
455  assert(me!=0);
456  if (me) return me->pntSelect (me->state, pnt, sel ? 1 : 0);
457  return 0;
458  }
459 
461 
465  EDError Select (LWPolID pol, bool sel)
466  {
467  assert(me!=0);
468  if (me) return me->polSelect (me->state, pol, sel ? 1 : 0);
469  return 0;
470  }
471 
473 
477  bool ReadVMap (LWPntID point, LWPolID pol, float *val)
478  {
479  assert(me!=0);
480  if (me) return (me->pointVPGet (me->state, point, pol, val) != 0);
481  return 0;
482  }
483 
485 
488  bool EvaluateVMap (LWPntID point, LWPolID pol, float *val)
489  {
490  assert(me!=0);
491  if (me) return (me->pointVEval (me->state, point, pol, val) != 0);
492  return 0;
493  }
495 
499  EDError AddDiscoVMap (LWPntID point, LWPolID pol, LWID type, const char *name, int dim, float *val)
500  {
501  assert(me!=0);
502  if (me) return me->pntVPMap (me->state, point, pol, type, name, dim, val);
503  return 0;
504  }
505 
506  /*
507  LWPntID (*edgePoint1) (EDStateRef, LWEdgeID);
508  LWPntID (*edgePoint2) (EDStateRef, LWEdgeID);
509  LWEdgeID (*edgeFromPoints) (EDStateRef, LWPntID, LWPntID);
510  void (*edgeFlip) (EDStateRef, LWEdgeID);
511  */
512  int GetEdgeCount (EltOpLayer lyr, int mode)
513  {
514  assert(me!=0);
515  if (me) return me->edgeCount (me->state, lyr, mode);
516  return 0;
517  }
518 
519  EDError Scan(EdgeScanner &scanner, EltOpLayer lyr)
520  {
521  assert(me!=0);
522  if(me) return me->edgeScan (me->state, &EdgeScanner::doScan, &scanner, lyr);
523  return 0;
524  }
525 
526  EDError Scan(FastEdgeScanner &scanner, EltOpLayer lyr, bool selOnly)
527  {
528  assert(me!=0);
529  if(me) return me->fastEdgeScan (me->state, &FastEdgeScanner::doScan, &scanner, lyr, selOnly ? 1 : 0);
530  return 0;
531  }
532 
533  EDEdgeInfo *GetInfo (LWEdgeID id)
534  {
535  assert(me!=0);
536  if (me) return me->edgeInfo (me->state, id);
537  return 0;
538  }
539 
541 
545  EDError Select (LWEdgeID edge, bool sel)
546  {
547  assert(me!=0);
548  if (me) return me->edgeSelect (me->state, edge, sel ? 1 : 0);
549  return 0;
550  }
551 
552  int GetEdgePolys (LWEdgeID edge, const LWPolID**pols)
553  {
554  assert(me!=0);
555  if (me) return me->edgePolys (me->state, edge, pols);
556  return 0;
557  }
558 
559  LWPntID GetEdgePoint1 (LWEdgeID edge)
560  {
561  assert(me!=0);
562  if (me) return me->edgePoint1 (me->state, edge);
563  return 0;
564  }
565 
566  LWPntID GetEdgePoint2 (LWEdgeID edge)
567  {
568  assert(me!=0);
569  if (me) return me->edgePoint2 (me->state, edge);
570  return 0;
571  }
572 
574 
577  LWEdgeID GetEdge (LWPntID p1, LWPntID p2)
578  {
579  assert(me!=0);
580  if (me) return me->edgeFromPoints (me->state, p1, p2);
581  return 0;
582  }
583 
584  void FlipEdge (LWEdgeID edge)
585  {
586  assert(me!=0);
587  if (me) me->edgeFlip (me->state, edge);
588  }
589 
591  void GetPointPosition (LWPntID pnt, double pos[3])
592  {
593  assert(me!=0);
594  if (me) me->pointPos (me->state, pnt, pos);
595  }
596 
598  int GetPointEdges (LWPntID pnt, const LWEdgeID **edges)
599  {
600  assert(me!=0);
601  if (me) return me->pointEdges (me->state, pnt, edges);
602  return 0;
603  }
604 
605  unsigned int GetPolyType (LWPolID pol)
606  {
607  assert(me!=0);
608  if (me) return me->polyType (me->state, pol);
609  return 0;
610  }
611 
612  int GetPolyPoints (LWPolID pol, const LWPntID **pnts)
613  {
614  assert(me!=0);
615  if (me) return me->polyPoints (me->state, pol, pnts);
616  return 0;
617  }
618 
619  int GetFlags (LWPntID pnt)
620  {
621  assert(me!=0);
622  if (me) return me->pointFlags (me->state, pnt);
623  return 0;
624  }
625 
626  int GetFlags (LWEdgeID edg)
627  {
628  assert(me!=0);
629  if (me) return me->edgeFlags (me->state, edg);
630  return 0;
631  }
632 
633  int GetFlags (LWPolID pol)
634  {
635  assert(me!=0);
636  if (me) return me->polyFlags (me->state, pol);
637  return 0;
638  }
639 
640  void *GetData (LWPntID pnt)
641  {
642  assert(me!=0);
643  if (me) return me->pointData (me->state, pnt);
644  return 0;
645  }
646 
647  void *GetData (LWEdgeID edg)
648  {
649  assert(me!=0);
650  if (me) return me->edgeData (me->state, edg);
651  return 0;
652  }
653 
654  void *GetData (LWPolID pol)
655  {
656  assert(me!=0);
657  if (me) return me->polyData (me->state, pol);
658  return 0;
659  }
660 
661  int GetLayer (LWPntID pnt)
662  {
663  assert(me!=0);
664  if (me) return me->pointLayer (me->state, pnt);
665  return 0;
666  }
667 
668  int GetLayer (LWEdgeID edg)
669  {
670  assert(me!=0);
671  if (me) return me->edgeLayer (me->state, edg);
672  return 0;
673  }
674 
675  int GetLayer (LWPolID pol)
676  {
677  assert(me!=0);
678  if (me) return me->polyLayer (me->state, pol);
679  return 0;
680  }
681 
682  int SetLayer (int lyr)
683  {
684  assert(me!=0);
685  if (me) return me->setLayer (me->state, lyr);
686  return 0;
687  }
689  {
690  assert(me!=0);
691  if (me) return me->advanceLayer (me->state);
692  return 0;
693  }
694 
695  int PointNew (LWPntID pnt)
696  {
697  assert(me!=0);
698  if (me) return me->pointNew (me->state, pnt);
699  return 0;
700  }
701 
702  int EdgeNew (LWEdgeID edg)
703  {
704  assert(me!=0);
705  if (me) return me->edgeNew (me->state, edg);
706  return 0;
707  }
708 
709  int PolyNew (LWPolID pol)
710  {
711  assert(me!=0);
712  if (me) return me->polyNew (me->state, pol);
713  return 0;
714  }
715 
716  /*
717  // new in Lightwave 9.6 - LWMESHEDIT_VERSION 6
718  void * (*vMapSelect) (EDStateRef es, const char* name, LWID type, int dim);
719  int (*vMapExists) (EDStateRef es, const char* name, LWID type);
720  unsigned int (*vMapGetDimension)(EDStateRef es);
721  void (*vMapSet) (EDStateRef es, LWPntID point_id, LWPolID polygon_id, const float *value);
722  void (*vMapSetIdeal) (EDStateRef es, LWPntID point_id, LWPolID polygon_id, const float *value);
723  void (*vMapRename) (EDStateRef es, const char *new_name);
724  void (*vMapRemove) (EDStateRef es);
725  */
726 
727  };
728 
729 
731  {
732  LWModCommand *mc;
733 
734  MeshEditBegin* editBegin()
735  {
736  assert(mc!=0);
737  return mc->editBegin;
738  }
739  MeshEditBegin2* editBegin2()
740  {
741  assert(mc!=0);
742  return mc->editBegin2;
743  }
744 
745  protected:
746  int version;
747  const char *GetArgument()
748  {
749  assert(mc!=0);
750  return mc->argument;
751  }
752  LWCommandCode Lookup (const char *cmdName)
753  {
754  assert(mc!=0);
755  return mc->lookup(mc->data, cmdName);
756  }
757  int Execute (LWCommandCode cmd, int argc, const DynaValue *argv, EltOpSelect op, DynaValue *result)
758  {
759  assert(mc!=0);
760  return mc->execute(mc->data, cmd, argc, argv, op, result);
761  }
762  int Evaluate (const char *command)
763  {
764  assert(mc!=0);
765  return mc->evaluate(mc->data, command);
766  }
768  {
769  assert(mc!=0);
770  mc->undoGroupBegin();
771  }
773  {
774  assert(mc!=0);
775  mc->undoGroupEnd();
776  }
777 
778  void EditBegin (int pntBuf, int polBuf, EltOpSelect opsel)
779  {
780  assert(mc!=0);
781  SetMeshEditOp(mc->editBegin(pntBuf, polBuf, opsel));
782  }
783 
784  void EditBegin (int pntBuf, int edgeBuf, int polBuf, EltOpSelect opsel)
785  {
786  assert(mc!=0);
787  return SetMeshEditOp(mc->editBegin2(pntBuf, edgeBuf, polBuf, opsel));
788  }
789  public:
790  ModelerCommand(int _version, LWModCommand *_mc)
791  : mc(_mc), version(_version)
792  {
793  }
794 
795  virtual int Activate (void* p) = 0;
796 
797  };
798 
800  template <typename T>
802  {
803  public:
804  ModelerCommandAdaptor(const char *name, ServerTagInfo *tags = 0)
805  {
806  LWServer::AddPlugin(LWMODCOMMAND_CLASS, name, Activate, tags);
807  }
809  static int Activate ( int version, GlobalFunc* global, LWInstance inst, void* serverData)
810  {
811  LWModCommand *local = static_cast<LWModCommand *>(inst);
812  lwpp::SetSuperGlobal(global);
813  T plugin(version, local);
814  return plugin.Activate(serverData);
815  }
816  };
817 
818 } // end namespace lwpp
819 
820 #endif // LWPP_MOD_COMMAND_H