00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __GU_Selection_h__
00023 #define __GU_Selection_h__
00024
00025 #include "GU_API.h"
00026 #include "GU_SelectType.h"
00027 #include <UT/UT_BoundingBox.h>
00028 #include <UT/UT_Color.h>
00029 #include <UT/UT_Defines.h>
00030 #include <UT/UT_IntArray.h>
00031 #include <UT/UT_String.h>
00032 #include <UT/UT_Vector4Array.h>
00033 #include <UT/UT_VectorTypes.h>
00034 #include <GA/GA_EdgeGroup.h>
00035 #include <GA/GA_ElementGroup.h>
00036 #include <GA/GA_BreakpointGroup.h>
00037 #include <GEO/GEO_Vertex.h>
00038 #include "GU_SelectType.h"
00039
00040 class UT_JSONWriter;
00041 class UT_JSONParser;
00042 class GA_Edge;
00043 class GA_GBPointRefArray;
00044 class GA_VertexGroup;
00045 class GEO_Point;
00046 class GA_Breakpoint;
00047 class GEO_Breakpoint;
00048 class GEO_Primitive;
00049 class GEO_Vertex;
00050 class GU_PolyRaster;
00051 class GU_CurveNetworkParms;
00052 class GU_Detail;
00053 class GU_BreakpointSelection;
00054 class GU_PointSelection;
00055 class GU_PrimSelection;
00056 class GU_EdgeSelection;
00057 class GU_VertexSelection;
00058 class GU_PointGroupSelection;
00059 class GU_PrimGroupSelection;
00060 class GU_PrimGroupClosure;
00061 class GU_LassoInfo;
00062 class GU_RayIntersect;
00063 class GU_PrimGroupClosure;
00064 class GU_Selection;
00065
00066 class GU_API GU_SelectResult
00067 {
00068 public:
00069 GU_SelectResult()
00070 : mySet(false)
00071 , myPrimitive(0)
00072 , myPoint(0)
00073 , myGroupType(GA_GROUP_INVALID)
00074 {}
00075 ~GU_SelectResult() {}
00076
00077 void set(const GA_Breakpoint &b)
00078 {
00079 myBreakpoint = b;
00080 myGroupType = GA_GROUP_BREAKPOINT;
00081 }
00082 void set(const GA_Edge &e, GA_Primitive *prim = 0)
00083 {
00084 myEdge = e;
00085 myPrimitive = prim;
00086 myGroupType = GA_GROUP_EDGE;
00087 }
00088 void set(GA_Primitive *prim)
00089 {
00090 myPrimitive = prim;
00091 myGroupType = GA_GROUP_PRIMITIVE;
00092 }
00093 void set(GEO_Point *pt)
00094 {
00095 myPoint = pt;
00096 myGroupType = GA_GROUP_POINT;
00097 }
00098 void set(const GEO_Vertex &v)
00099 {
00100 myVertex = v;
00101 myGroupType = GA_GROUP_VERTEX;
00102 }
00103
00104 const GA_Breakpoint &getBreakpoint() const { return myBreakpoint; }
00105 const GA_Edge &getEdge() const { return myEdge; }
00106 GA_Primitive *getPrimitive() const { return myPrimitive; }
00107 GEO_Point *getPoint() const { return myPoint; }
00108 GA_Offset getPointOffset() const
00109 {
00110 return (myPoint
00111 ? myPoint->getMapOffset()
00112 : GA_INVALID_OFFSET);
00113 }
00114 const GEO_Vertex &getVertex() const { return myVertex; }
00115
00116 bool isSet() const { return myGroupType != GA_GROUP_INVALID; }
00117 GA_GroupType getSelectType() const { return myGroupType; }
00118 void clear() { myGroupType = GA_GROUP_INVALID; }
00119 private:
00120 GA_Breakpoint myBreakpoint;
00121 GA_Edge myEdge;
00122 GA_Primitive *myPrimitive;
00123 GEO_Point *myPoint;
00124 GEO_Vertex myVertex;
00125 GA_GroupType myGroupType;
00126 bool mySet;
00127 };
00128
00129 class GU_API GU_SelectionList : public UT_PtrArray<GU_Selection *>
00130 {
00131 public:
00132 GU_SelectionList()
00133 { }
00134 virtual ~GU_SelectionList()
00135 { }
00136 };
00137
00138 class GU_API GU_Selection
00139 {
00140 public:
00141
00142
00143 GU_Selection(GU_Detail &gdp, const char *prefix);
00144 virtual ~GU_Selection(void);
00145
00146
00147
00148
00149
00150 static GU_Selection *newSelection(GU_Detail &gdp,
00151 GU_SelectionType stype,
00152 const char *creator_prefix,
00153 const char *suffix = 0);
00154 static GU_Selection *newSelection(GU_Detail &gdp,
00155 const GA_Group &group,
00156 const char *creator_prefix,
00157 const char *suffix = 0);
00158
00159 static GU_Selection *newSelection(GU_Detail &dst_gdp,
00160 const GU_Detail &src_gdp,
00161 const GU_Selection &src_sel,
00162 const char *creator_prefix,
00163 const char *suffix = 0);
00164
00165
00166
00167
00168
00169
00170 static bool changeSelectionType(GU_Detail &gdp,
00171 GU_SelectionType stype,
00172 GU_SelectionConnectivity ctype,
00173 bool view_3d,
00174 const char *creator_prefix,
00175 const char *suffix = 0,
00176 int list_index = -1,
00177 int sel_instance = -1);
00178
00179
00180
00181 static void copySelection(GU_Selection &destination,
00182 GU_Selection &source);
00183
00184
00185 static int pickMaskForSelType(GU_SelectionType stype);
00186
00187
00188
00189
00190 static GU_SelectionType baseSelectionType(GU_SelectionType stype,
00191 bool &out_connected);
00192
00193
00194
00195
00196 static GU_SelectionType baseSelectionType(GU_SelectionType stype)
00197 {
00198 bool f;
00199 return baseSelectionType(stype, f);
00200 }
00201
00202
00203 static GU_SelectionType fullSelectionType(GU_SelectionType base_type,
00204 bool connected);
00205
00206
00207
00208 virtual GU_Selection &operator=(GU_PointSelection &) = 0;
00209 virtual GU_Selection &operator=(GU_PrimSelection &) = 0;
00210 virtual GU_Selection &operator=(GU_EdgeSelection &) = 0;
00211 virtual GU_Selection &operator=(GU_BreakpointSelection &) = 0;
00212 virtual GU_Selection &operator=(GU_VertexSelection &) = 0;
00213 virtual GU_Selection &operator=(GU_PointGroupSelection &);
00214 virtual GU_Selection &operator=(GU_PrimGroupSelection &);
00215
00216
00217
00218 virtual int pickMask(void) const = 0;
00219
00220
00221
00222
00223
00224 virtual int selfSnapMask(void) const;
00225
00226
00227
00228
00229
00230 virtual int select(uint *pickbuf, long npicked,
00231 GU_SelectResult &added,
00232 GU_SelectionRule rule = GU_AddSelect,
00233 unsigned *pickid = 0,
00234 GU_LassoInfo *linfo = 0,
00235 const UT_IntArray *prfx = 0) = 0;
00236 virtual int selectEntireGeometry(uint *pickbuf,
00237 long npicked,
00238 GU_SelectResult &added,
00239 GU_SelectionRule rule = GU_AddSelect,
00240 unsigned *pickid = 0,
00241 GU_LassoInfo *linfo = 0,
00242 const UT_IntArray *prfx = 0) = 0;
00243
00244
00245
00246
00247
00248
00249 virtual int selectNext(GU_SelectResult &added,
00250 GU_SelectionRule rule = GU_AddSelect,
00251 int shiftstate = 0,
00252 int vstate = 0) = 0;
00253
00254 virtual int selectPrev(GU_SelectResult &added,
00255 GU_SelectionRule rule = GU_AddSelect,
00256 int shiftstate = 0,
00257 int vstate = 0) = 0;
00258
00259
00260
00261
00262
00263 virtual GU_SelectionResult selectEmpty(uint *pickbuf, long npicked,
00264 GU_SelectionRule rule = GU_AddSelect,
00265 unsigned *pickid = 0,
00266 GU_LassoInfo *linfo = 0,
00267 const UT_IntArray *prfx = 0) const = 0;
00268
00269
00270
00271
00272 virtual bool siftThrough(GU_SelectResult &result,
00273 uint *pickbuf, long npicked,
00274 int look_for_existing = 1,
00275 unsigned *pickid = 0,
00276 GU_LassoInfo *linfo = 0,
00277 const UT_IntArray *prfx = 0) const = 0;
00278
00279
00280
00281
00282
00283
00284
00285
00286 virtual int selectionPoint(const GU_SelectResult &added,
00287 unsigned *pickid,
00288 UT_Vector3 &xsect) const = 0;
00289 virtual int selectionPoint(const GU_SelectResult &added,
00290 unsigned *pickid,
00291 UT_Vector3 rayorig,
00292 UT_Vector3 &raydir,
00293 UT_Vector3 &xsect,
00294 int &normal,
00295 UT_Vector3 &vector,
00296 int accurate, float *u,
00297 float *v) const = 0;
00298
00299
00300
00301
00302
00303 virtual int selectGroup(const GA_Group &group, int ref=0)=0;
00304 int addGroup(const GA_Group &group);
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 virtual int add(const GEO_Point &point, int order=0) = 0;
00315 virtual int add(const GEO_Primitive &pr, int order=0) = 0;
00316 virtual int add(const GA_Edge &edge, int order=0) = 0;
00317 virtual int add(const GA_Edge &edge, GEO_Primitive &prim,
00318 int order=0) = 0;
00319 virtual int add(const GA_Breakpoint &bkp, int order=0) = 0;
00320 virtual int add(const GEO_Vertex &vtx, int order=0) = 0;
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 virtual int remove(const GEO_Point &point, int order=0) = 0;
00331 virtual int remove(const GEO_Primitive &prim, int order=0) = 0;
00332 virtual int remove(const GA_Edge &edge, int order=0) = 0;
00333 virtual int remove(const GA_Edge &edge, GEO_Primitive &prim,
00334 int order=0) = 0;
00335 virtual int remove(const GA_Breakpoint &bkp, int order=0) = 0;
00336 virtual int remove(const GEO_Vertex &vtx, int order=0) = 0;
00337
00338
00339
00340 virtual int removeLast(void) = 0;
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350 virtual int toggle(const GEO_Point &point, int order=0) = 0;
00351 virtual int toggle(const GEO_Primitive &prim, int order=0) = 0;
00352 virtual int toggle(const GA_Edge &edge, int order=0) = 0;
00353 virtual int toggle(const GA_Edge &edge, GEO_Primitive &prim,
00354 int order=0) = 0;
00355 virtual int toggle(const GA_Breakpoint &bkp, int order=0) = 0;
00356 virtual int toggle(const GEO_Vertex &vtx, int order=0) = 0;
00357
00358
00359
00360 enum { WITHIN_CLOSURE, EXCLUDE_CLOSURE };
00361 int selectAll()
00362 { return selectAllUsingClosure(0, WITHIN_CLOSURE); }
00363
00364
00365
00366 int toggleAll()
00367 { return toggleAllUsingClosure(0, WITHIN_CLOSURE); }
00368
00369
00370 int selectAllExcept(GU_PrimGroupClosure &closure)
00371 { return selectAllUsingClosure(&closure, EXCLUDE_CLOSURE); }
00372 int selectAllWithin(GU_PrimGroupClosure &closure)
00373 { return selectAllUsingClosure(&closure, WITHIN_CLOSURE); }
00374 int toggleExcept(GU_PrimGroupClosure &closure)
00375 { return toggleAllUsingClosure(&closure, EXCLUDE_CLOSURE); }
00376 int toggleWithin(GU_PrimGroupClosure &closure)
00377 { return toggleAllUsingClosure(&closure, WITHIN_CLOSURE); }
00378
00379
00380
00381 virtual int selectBoundary(bool )
00382 { return 0; }
00383 virtual int shrinkSelection(bool )
00384 { return 0; }
00385
00386
00387
00388
00389 int uvSelectAllFrontFace()
00390 { return uvSelectAllByWindingUsingClosure( 0, WITHIN_CLOSURE,
00391 true, false); }
00392 int uvSelectAllBackFace()
00393 { return uvSelectAllByWindingUsingClosure( 0, WITHIN_CLOSURE,
00394 false, true); }
00395 int uvSelectAllFrontFaceWithin(GU_PrimGroupClosure &closure)
00396 { return uvSelectAllByWindingUsingClosure( &closure,
00397 WITHIN_CLOSURE,
00398 true, false); }
00399 int uvSelectAllBackFaceWithin(GU_PrimGroupClosure &closure)
00400 { return uvSelectAllByWindingUsingClosure( &closure,
00401 WITHIN_CLOSURE,
00402 false, true); }
00403
00404
00405 GA_PointGroup *points(void) const;
00406 GA_PrimitiveGroup *primitives(void) const;
00407 virtual GA_VertexGroup *vertices(void) const;
00408 virtual const GA_EdgeGroup *edges(void) const;
00409 virtual const GA_BreakpointGroup *breakpoints(void) const;
00410
00411
00412
00413
00414
00415 void updateCachedPoints();
00416 void updateCachedPrimitives();
00417 GA_PointGroup *cachedPoints() const
00418 { return myCachedPointGroup; }
00419 GA_PrimitiveGroup *cachedPrimitives() const
00420 { return myCachedPrimitiveGroup; }
00421
00422
00423
00424
00425
00426
00427 virtual GA_PointGroup *updatePoints(void) = 0;
00428 virtual GA_PrimitiveGroup *updatePrimitives(void) = 0;
00429 virtual void updateStashed(void);
00430
00431
00432
00433
00434 virtual int applyStashed(void);
00435
00436
00437
00438 virtual void clear(void);
00439 virtual void clearAndDestroy(void);
00440
00441
00442
00443 virtual void topologyChanged() {}
00444
00445
00446
00447 virtual int destroyGeometry(void) = 0;
00448
00449
00450
00451 virtual int copyGeometry(int copies = 1, UT_Vector3 *delta = 0,
00452 const char *groupname = 0) = 0;
00453
00454
00455 virtual void reverse();
00456
00457
00458 virtual int entries(void) const = 0;
00459
00460
00461
00462 virtual int getBoundingBox(UT_BoundingBox &bbox) const = 0;
00463 virtual int getBoundingBox(UT_BoundingBox &bbox,
00464 const UT_Matrix4R &transform) const = 0;
00465
00466
00467
00468 virtual int getBoundingBoxUV(UT_BoundingBox &bbox,
00469 const char *name,
00470 int isvertex) const = 0;
00471
00472
00473 bool saveSelection(ostream &os, bool binary) const;
00474 bool loadSelection(UT_IStream &is);
00475
00476
00477 void dump(ostream &os) const;
00478
00479
00480
00481 virtual GU_Detail *createGeometry();
00482
00483
00484 virtual int classType(void) const = 0;
00485 int baseClassType() const
00486 { return GU_Selection::baseSelectionType((GU_SelectionType)classType()); }
00487
00488
00489
00490 virtual GU_Selection *newSpecies(GU_Detail &gdp) = 0;
00491
00492
00493 virtual const GA_Group *mainGroup() const = 0;
00494
00495
00496
00497
00498 GU_SelectionConnectivity getConnectivity() const
00499 { return myConnectivity; }
00500 void setConnectivity(GU_SelectionConnectivity c,
00501 bool view_3d);
00502
00503
00504
00505
00506 bool get3DVisibilityFlag() const
00507 { return my3DVisibilityFlag; }
00508
00509
00510
00511
00512 virtual void setUsePrimEdges(bool ) { }
00513 virtual bool getUsePrimEdges() const { return false; }
00514
00515 void setPickOrder(int pick_order)
00516 { myPickOrder = pick_order; }
00517 int getPickOrder() const
00518 { return myPickOrder; }
00519
00520 protected:
00521
00522 void setOrdered(GA_ElementGroup &g, int ordered)
00523 {
00524 if (ordered)
00525 g.makeOrdered();
00526 else
00527 g.clearOrdered();
00528 }
00529
00530
00531
00532 bool jsonSave(UT_JSONWriter &w,
00533 const GA_SaveMap &map) const;
00534 bool jsonLoad(UT_JSONParser &p,
00535 const GA_LoadMap &map);
00536
00537
00538
00539 virtual bool savePrivate(UT_JSONWriter &w,
00540 const GA_SaveMap &map) const;
00541 virtual bool loadPrivate(UT_JSONParser &p,
00542 const GA_LoadMap &map);
00543
00544
00545
00546 GU_Selection(GU_Detail &gdp, const GU_Selection &s);
00547
00548
00549
00550 virtual int selectAllUsingClosure(
00551 GU_PrimGroupClosure *closure,
00552 int how_to_treat_closure) = 0;
00553 virtual int toggleAllUsingClosure(
00554 GU_PrimGroupClosure *closure,
00555 int how_to_treat_closure) = 0;
00556
00557 virtual int uvSelectAllByWindingUsingClosure(
00558 GU_PrimGroupClosure *closure,
00559 int how_to_treat_closure,
00560 bool front_facing,
00561 bool back_facing);
00562
00563 GU_Detail &gdp(void) { return myGdp; }
00564 const GU_Detail &gdp(void) const { return myGdp; }
00565
00566 GA_PointGroup *safePoints() const;
00567 GA_PrimitiveGroup *safePrimitives() const;
00568
00569 UT_Vector4Array *stashed(void) const { return myStashed; }
00570
00571 void createStashed(int size);
00572
00573 int isPointInLasso(const UT_Vector4 &pos,
00574 GU_LassoInfo *linfo,
00575 GU_PolyRaster *&praster) const;
00576 int isPointInLasso(const GEO_Point &point,
00577 GU_LassoInfo *linfo,
00578 GU_PolyRaster *&praster,
00579 const GA_GBPointRefArray *ptref
00580 = 0) const;
00581 int isVertexInLasso(const GEO_Vertex &vtx,
00582 GU_LassoInfo *linfo,
00583 GU_PolyRaster *&praster) const;
00584
00585 static bool getPrefixIsValid(const UT_IntArray *prfx,
00586 int items, int minrealitems,
00587 uint *&pickidstart);
00588
00589 private:
00590
00591
00592
00593 class io_deprecated {};
00594 virtual io_deprecated save(ostream &os, int binary) const;
00595 virtual io_deprecated load(UT_IStream &is);
00596
00597
00598 GU_Detail &myGdp;
00599 UT_String myPoints;
00600 UT_String myPrims;
00601 UT_Vector4Array *myStashed;
00602
00603 GA_PointGroup *myCachedPointGroup;
00604 GA_PrimitiveGroup *myCachedPrimitiveGroup;
00605
00606 GU_SelectionConnectivity myConnectivity;
00607
00608
00609
00610 bool my3DVisibilityFlag;
00611
00612 int myPickOrder;
00613 };
00614
00615
00616 class GU_API GU_LassoInfo
00617 {
00618 public:
00619 GU_LassoInfo() { myPolyRaster = NULL; }
00620 ~GU_LassoInfo() {}
00621
00622
00623 void assign(int *lasso_points, int lasso_size,
00624 void (*ptmap)(const UT_Vector3 &, float &,float &, void *),
00625 void *viewer, void *workbench,
00626 bool (*zmap)(const GU_Detail *, float, float,
00627 const UT_Vector3 &, void *, void *,
00628 GU_PrimGroupClosure *,
00629 const GEO_Primitive *),
00630 int use_uv, int is_vertex)
00631 {
00632 myLassoPoints = lasso_points;
00633 myEnableMap = 0;
00634 myLassoSize = lasso_size;
00635 myMapFct = ptmap;
00636 myViewer = viewer;
00637 myWorkbench = workbench;
00638 myZDepthFct = zmap;
00639 myHidden = 0;
00640 myUseUV = use_uv;
00641 myIsVertexAttrib = is_vertex;
00642 myAttribOffset.clear();
00643 }
00644
00645
00646 void assign(char *enablemap, int minx, int miny, int maxx, int maxy,
00647 void (*ptmap)(const UT_Vector3 &, float &,float &, void *),
00648 void *viewer, void *workbench,
00649 bool (*zmap)(const GU_Detail *, float, float,
00650 const UT_Vector3 &, void *, void *,
00651 GU_PrimGroupClosure *,
00652 const GEO_Primitive *),
00653 int use_uv, int is_vertex)
00654 {
00655 myLassoPoints = 0;
00656 myEnableMap = enablemap;
00657 myMinX = minx;
00658 myMinY = miny;
00659 myMaxX = maxx;
00660 myMaxY = maxy;
00661 myMapFct = ptmap;
00662 myViewer = viewer;
00663 myWorkbench = workbench;
00664 myZDepthFct = zmap;
00665 myHidden = 0;
00666 myUseUV = use_uv;
00667 myIsVertexAttrib = is_vertex;
00668 myAttribOffset.clear();
00669 }
00670
00671 void setHidden(GU_PrimGroupClosure *hidden) { myHidden = hidden; }
00672
00673
00674 int *myLassoPoints;
00675 int myLassoSize;
00676
00677
00678 char *myEnableMap;
00679 int myMinX, myMinY, myMaxX, myMaxY;
00680
00681 void *myViewer, *myWorkbench;
00682 GU_PrimGroupClosure *myHidden;
00683
00684
00685 int myUseUV;
00686 int myIsVertexAttrib;
00687 GA_ROAttributeRef myAttribOffset;
00688
00689 void (*myMapFct)(const UT_Vector3 &, float &,float &, void *);
00690 bool (*myZDepthFct)(const GU_Detail *, float, float, const UT_Vector3 &,
00691 void *, void *, GU_PrimGroupClosure *,
00692 const GEO_Primitive *);
00693
00694 GU_PolyRaster * createPolyRaster();
00695 void buildPolyRaster();
00696 void destroyPolyRaster();
00697 int polyRasterContains( const UT_Vector3 &pos );
00698
00699 private:
00700 GU_PolyRaster * myPolyRaster;
00701 };
00702
00703 #endif