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 <UT/UT_Defines.h>
00027 #include <UT/UT_Color.h>
00028 #include <UT/UT_IntArray.h>
00029 #include <UT/UT_String.h>
00030 #include <UT/UT_Vector4Array.h>
00031 #include <GB/GB_Group.h>
00032 #include <GB/GB_EdgeGroup.h>
00033 #include <GB/GB_BreakpointGroup.h>
00034 #include "GU_SelectType.h"
00035
00036 class UT_Vector3;
00037 class UT_Vector4;
00038 class UT_Matrix4;
00039 class UT_BoundingBox;
00040 class UT_CoordSpace;
00041 class GB_Edge;
00042 class GB_PointRefArray;
00043 class GB_VertexData;
00044 class GB_VertexGroup;
00045 class GEO_Point;
00046 class GEO_Breakpoint;
00047 class GEO_Primitive;
00048 class GEO_Vertex;
00049 class GU_PolyRaster;
00050 class GU_CurveNetworkParms;
00051 class GU_Detail;
00052 class GU_BreakpointSelection;
00053 class GU_PointSelection;
00054 class GU_PrimSelection;
00055 class GU_EdgeSelection;
00056 class GU_VertexSelection;
00057 class GU_PointGroupSelection;
00058 class GU_PrimGroupSelection;
00059 class GU_PrimGroupClosure;
00060 class GU_LassoInfo;
00061 class GU_RayIntersect;
00062 class GU_PrimGroupClosure;
00063 class GU_Selection;
00064
00065 class GU_API GU_SelectionList : public UT_PtrArray<GU_Selection *>
00066 {
00067 public:
00068 GU_SelectionList()
00069 { }
00070 virtual ~GU_SelectionList()
00071 { }
00072 };
00073
00074 class GU_API GU_Selection
00075 {
00076 public:
00077
00078
00079 GU_Selection(GU_Detail &gdp, const char *prefix);
00080 virtual ~GU_Selection(void);
00081
00082
00083
00084
00085
00086 static GU_Selection *newSelection(GU_Detail &gdp,
00087 GU_SelectionType stype,
00088 const char *creator_prefix,
00089 const char *suffix = 0);
00090 static GU_Selection *newSelection(GU_Detail &gdp,
00091 const GB_BaseGroup &group,
00092 const char *creator_prefix,
00093 const char *suffix = 0);
00094
00095 static GU_Selection *newSelection(GU_Detail &dst_gdp,
00096 const GU_Detail &src_gdp,
00097 const GU_Selection &src_sel,
00098 const char *creator_prefix,
00099 const char *suffix = 0);
00100
00101
00102
00103
00104
00105
00106 static bool changeSelectionType(GU_Detail &gdp,
00107 GU_SelectionType stype,
00108 GU_SelectionConnectivity ctype,
00109 bool view_3d,
00110 const char *creator_prefix,
00111 const char *suffix = 0,
00112 int list_index = -1,
00113 int sel_instance = -1);
00114
00115
00116
00117 static void copySelection(GU_Selection &destination,
00118 GU_Selection &source);
00119
00120
00121 static int pickMaskForSelType(GU_SelectionType stype);
00122
00123
00124
00125
00126 static GU_SelectionType baseSelectionType(GU_SelectionType stype,
00127 bool &out_connected);
00128
00129
00130
00131
00132 static GU_SelectionType baseSelectionType(GU_SelectionType stype)
00133 {
00134 bool f;
00135 return baseSelectionType(stype, f);
00136 }
00137
00138
00139 static GU_SelectionType fullSelectionType(GU_SelectionType base_type,
00140 bool connected);
00141
00142
00143
00144 virtual GU_Selection &operator=(GU_PointSelection &) = 0;
00145 virtual GU_Selection &operator=(GU_PrimSelection &) = 0;
00146 virtual GU_Selection &operator=(GU_EdgeSelection &) = 0;
00147 virtual GU_Selection &operator=(GU_BreakpointSelection &) = 0;
00148 virtual GU_Selection &operator=(GU_VertexSelection &) = 0;
00149 virtual GU_Selection &operator=(GU_PointGroupSelection &);
00150 virtual GU_Selection &operator=(GU_PrimGroupSelection &);
00151
00152
00153
00154 virtual int pickMask(void) const = 0;
00155
00156
00157
00158
00159
00160 virtual int selfSnapMask(void) const;
00161
00162
00163
00164
00165
00166 virtual int select(uint *pickbuf, long npicked,
00167 void *&added,
00168 GU_SelectionRule rule = GU_AddSelect,
00169 unsigned *pickid = 0,
00170 GU_LassoInfo *linfo = 0,
00171 const UT_IntArray *prfx = 0) = 0;
00172 virtual int selectEntireGeometry(uint *pickbuf,
00173 long npicked,
00174 void *&added,
00175 GU_SelectionRule rule = GU_AddSelect,
00176 unsigned *pickid = 0,
00177 GU_LassoInfo *linfo = 0,
00178 const UT_IntArray *prfx = 0) = 0;
00179
00180
00181
00182
00183
00184
00185 virtual int selectNext(void *&added,
00186 GU_SelectionRule rule = GU_AddSelect,
00187 int shiftstate = 0,
00188 int vstate = 0) = 0;
00189
00190 virtual int selectPrev(void *&added,
00191 GU_SelectionRule rule = GU_AddSelect,
00192 int shiftstate = 0,
00193 int vstate = 0) = 0;
00194
00195
00196
00197
00198
00199 virtual GU_SelectionResult selectEmpty(uint *pickbuf, long npicked,
00200 GU_SelectionRule rule = GU_AddSelect,
00201 unsigned *pickid = 0,
00202 GU_LassoInfo *linfo = 0,
00203 const UT_IntArray *prfx = 0) const = 0;
00204
00205
00206
00207
00208 virtual void *siftThrough(uint *pickbuf, long npicked,
00209 int look_for_existing = 1,
00210 unsigned *pickid = 0,
00211 GU_LassoInfo *linfo = 0,
00212 const UT_IntArray *prfx = 0) const = 0;
00213
00214
00215
00216
00217
00218
00219
00220
00221 virtual int selectionPoint(void *added, unsigned *pickid,
00222 UT_Vector3 &xsect) const = 0;
00223 virtual int selectionPoint(void *added, unsigned *pickid,
00224 UT_Vector3 rayorig,
00225 UT_Vector3 &raydir,
00226 UT_Vector3 &xsect,
00227 int &normal,
00228 UT_Vector3 &vector,
00229 int accurate, float *u,
00230 float *v) const = 0;
00231
00232
00233
00234
00235
00236 virtual int selectGroup(const GB_BaseGroup &group, int ref=0)=0;
00237 int addGroup(const GB_BaseGroup &group, int ordered=0);
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 virtual int add(GEO_Point &point,int ordered=0)= 0;
00248 virtual int add(GEO_Primitive &prim, int ordered=0)= 0;
00249 virtual int add(GB_Edge &edge, int ordered=0)= 0;
00250 virtual int add(GEO_Breakpoint &bkp, int ordered=0)= 0;
00251 virtual int add(GB_VertexData &vtx, int ordered=0)= 0;
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 virtual int remove(GEO_Point &point,int ordered=0)= 0;
00262 virtual int remove(GEO_Primitive &prim, int ordered=0)= 0;
00263 virtual int remove(GB_Edge &edge, int ordered=0)= 0;
00264 virtual int remove(GEO_Breakpoint &bkp, int ordered=0)= 0;
00265 virtual int remove(GB_VertexData &vtx, int ordered=0)= 0;
00266
00267
00268
00269 virtual int removeLast(void) = 0;
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 virtual int toggle(GEO_Point &point,int ordered=0)= 0;
00280 virtual int toggle(GEO_Primitive &prim, int ordered=0)= 0;
00281 virtual int toggle(GB_Edge &edge, int ordered=0)= 0;
00282 virtual int toggle(GEO_Breakpoint &bkp, int ordered=0)= 0;
00283 virtual int toggle(GB_VertexData &vtx, int ordered=0)= 0;
00284
00285
00286
00287 enum { WITHIN_CLOSURE, EXCLUDE_CLOSURE };
00288 int selectAll()
00289 { return selectAllUsingClosure(0, WITHIN_CLOSURE); }
00290
00291
00292
00293 int toggleAll()
00294 { return toggleAllUsingClosure(0, WITHIN_CLOSURE); }
00295
00296
00297 int selectAllExcept(GU_PrimGroupClosure &closure)
00298 { return selectAllUsingClosure(&closure, EXCLUDE_CLOSURE); }
00299 int selectAllWithin(GU_PrimGroupClosure &closure)
00300 { return selectAllUsingClosure(&closure, WITHIN_CLOSURE); }
00301 int toggleExcept(GU_PrimGroupClosure &closure)
00302 { return toggleAllUsingClosure(&closure, EXCLUDE_CLOSURE); }
00303 int toggleWithin(GU_PrimGroupClosure &closure)
00304 { return toggleAllUsingClosure(&closure, WITHIN_CLOSURE); }
00305
00306
00307
00308 virtual int selectBoundary(bool )
00309 { return 0; }
00310 virtual int shrinkSelection(bool )
00311 { return 0; }
00312
00313
00314
00315
00316 int uvSelectAllFrontFace()
00317 { return uvSelectAllByWindingUsingClosure( 0, WITHIN_CLOSURE,
00318 true, false); }
00319 int uvSelectAllBackFace()
00320 { return uvSelectAllByWindingUsingClosure( 0, WITHIN_CLOSURE,
00321 false, true); }
00322 int uvSelectAllFrontFaceWithin(GU_PrimGroupClosure &closure)
00323 { return uvSelectAllByWindingUsingClosure( &closure,
00324 WITHIN_CLOSURE,
00325 true, false); }
00326 int uvSelectAllBackFaceWithin(GU_PrimGroupClosure &closure)
00327 { return uvSelectAllByWindingUsingClosure( &closure,
00328 WITHIN_CLOSURE,
00329 false, true); }
00330
00331
00332 GB_PointGroup *points(void) const;
00333 GB_PrimitiveGroup *primitives(void) const;
00334 virtual const GB_EdgeGroup *edges(void) const;
00335 virtual const GB_BreakpointGroup *breakpoints(void) const;
00336 virtual const GB_VertexGroup *vertices(void) const;
00337
00338
00339
00340
00341
00342 void updateCachedPoints();
00343 void updateCachedPrimitives();
00344 GB_PointGroup *cachedPoints() const
00345 { return myCachedPointGroup; }
00346 GB_PrimitiveGroup *cachedPrimitives() const
00347 { return myCachedPrimitiveGroup; }
00348
00349
00350
00351
00352
00353
00354 virtual GB_PointGroup *updatePoints(void) = 0;
00355 virtual GB_PrimitiveGroup *updatePrimitives(void) = 0;
00356 virtual void updateStashed(void);
00357
00358
00359
00360
00361 virtual int applyStashed(void);
00362
00363
00364
00365 virtual void clear(void);
00366 virtual void clearAndDestroy(void);
00367
00368
00369
00370 virtual void topologyChanged() {}
00371
00372
00373
00374 virtual int destroyGeometry(void) = 0;
00375
00376
00377
00378 virtual int copyGeometry(int copies = 1, UT_Vector3 *delta = 0,
00379 const char *groupname = 0) = 0;
00380
00381
00382 virtual void reverse();
00383
00384
00385 virtual int entries(void) const = 0;
00386
00387
00388
00389 virtual int getBoundingBox(UT_BoundingBox &bbox) const = 0;
00390 virtual int getBoundingBox(UT_BoundingBox &bbox, const UT_Matrix4& transform ) const = 0;
00391
00392
00393
00394 virtual int getBoundingBoxUV(UT_BoundingBox &bbox,
00395 const char *name,
00396 int isvertex) const = 0;
00397
00398
00399 virtual int save(ostream &os, int binary) const;
00400 virtual bool load(UT_IStream &is);
00401
00402
00403 void dump(ostream &os) const;
00404
00405
00406
00407 virtual GU_Detail *createGeometry();
00408
00409
00410 virtual int classType(void) const = 0;
00411 int baseClassType() const
00412 { return GU_Selection::baseSelectionType((GU_SelectionType)classType()); }
00413
00414
00415 virtual void suffixName(const char *suffix);
00416
00417
00418
00419 virtual GU_Selection *newSpecies(GU_Detail &gdp) = 0;
00420
00421
00422 virtual const GB_BaseGroup *mainGroup() const = 0;
00423
00424
00425
00426
00427 GU_SelectionConnectivity getConnectivity() const
00428 { return myConnectivity; }
00429 void setConnectivity(GU_SelectionConnectivity c,
00430 bool view_3d);
00431
00432
00433
00434
00435 bool get3DVisibilityFlag() const
00436 { return my3DVisibilityFlag; }
00437
00438
00439
00440
00441 virtual void setUsePrimEdges(bool ) { }
00442 virtual bool getUsePrimEdges() const { return false; }
00443
00444 void setPickOrder(int pick_order)
00445 { myPickOrder = pick_order; }
00446 int getPickOrder() const
00447 { return myPickOrder; }
00448
00449 protected:
00450
00451 GU_Selection(GU_Detail &gdp, const GU_Selection &s);
00452
00453
00454
00455 virtual int selectAllUsingClosure(
00456 GU_PrimGroupClosure *closure,
00457 int how_to_treat_closure) = 0;
00458 virtual int toggleAllUsingClosure(
00459 GU_PrimGroupClosure *closure,
00460 int how_to_treat_closure) = 0;
00461
00462 virtual int uvSelectAllByWindingUsingClosure(
00463 GU_PrimGroupClosure *closure,
00464 int how_to_treat_closure,
00465 bool front_facing,
00466 bool back_facing);
00467
00468 GU_Detail &gdp(void) { return theGdp; }
00469 const GU_Detail &gdp(void) const { return theGdp; }
00470
00471 GB_PointGroup *safePoints(void) const;
00472 GB_PrimitiveGroup *safePrimitives(void) const;
00473 UT_Vector4Array *stashed(void) const { return theStashed; }
00474
00475 void createStashed(int size);
00476
00477 int isPointInLasso(const UT_Vector4 &pos,
00478 GU_LassoInfo *linfo,
00479 GU_PolyRaster *&praster) const;
00480 int isPointInLasso(const GEO_Point &point,
00481 GU_LassoInfo *linfo,
00482 GU_PolyRaster *&praster,
00483 const GB_PointRefArray *ptref
00484 = 0) const;
00485 int isVertexInLasso(const GEO_Vertex &vtx,
00486 GU_LassoInfo *linfo,
00487 GU_PolyRaster *&praster) const;
00488
00489 static bool getPrefixIsValid(const UT_IntArray *prfx,
00490 int items, int minrealitems,
00491 uint *&pickidstart);
00492
00493 private:
00494 GU_Detail &theGdp;
00495 UT_String thePoints;
00496 UT_String thePrims;
00497 UT_Vector4Array *theStashed;
00498
00499 GB_PointGroup *myCachedPointGroup;
00500 GB_PrimitiveGroup *myCachedPrimitiveGroup;
00501
00502 GU_SelectionConnectivity myConnectivity;
00503
00504
00505
00506 bool my3DVisibilityFlag;
00507
00508 int myPickOrder;
00509 };
00510
00511
00512 class GU_API GU_LassoInfo
00513 {
00514 public:
00515 GU_LassoInfo() { myPolyRaster = NULL; }
00516 ~GU_LassoInfo() {}
00517
00518
00519 void assign(int *lasso_points, int lasso_size,
00520 void (*ptmap)(const UT_Vector3 &, float &,float &, void *),
00521 void *viewer, void *workbench,
00522 bool (*zmap)(const GU_Detail *, float, float,
00523 const UT_Vector3 &, void *, void *,
00524 GU_PrimGroupClosure *,
00525 const GEO_Primitive *),
00526 int use_uv, int is_vertex)
00527 {
00528 myLassoPoints = lasso_points;
00529 myEnableMap = 0;
00530 myLassoSize = lasso_size;
00531 myMapFct = ptmap;
00532 myViewer = viewer;
00533 myWorkbench = workbench;
00534 myZDepthFct = zmap;
00535 myHidden = 0;
00536 myUseUV = use_uv;
00537 myIsVertexAttrib = is_vertex;
00538 myAttribOffset = -1;
00539 }
00540
00541
00542 void assign(char *enablemap, int minx, int miny, int maxx, int maxy,
00543 void (*ptmap)(const UT_Vector3 &, float &,float &, void *),
00544 void *viewer, void *workbench,
00545 bool (*zmap)(const GU_Detail *, float, float,
00546 const UT_Vector3 &, void *, void *,
00547 GU_PrimGroupClosure *,
00548 const GEO_Primitive *),
00549 int use_uv, int is_vertex)
00550 {
00551 myLassoPoints = 0;
00552 myEnableMap = enablemap;
00553 myMinX = minx;
00554 myMinY = miny;
00555 myMaxX = maxx;
00556 myMaxY = maxy;
00557 myMapFct = ptmap;
00558 myViewer = viewer;
00559 myWorkbench = workbench;
00560 myZDepthFct = zmap;
00561 myHidden = 0;
00562 myUseUV = use_uv;
00563 myIsVertexAttrib = is_vertex;
00564 myAttribOffset = -1;
00565 }
00566
00567 void setHidden(GU_PrimGroupClosure *hidden) { myHidden = hidden; }
00568
00569
00570 int *myLassoPoints;
00571 int myLassoSize;
00572
00573
00574 char *myEnableMap;
00575 int myMinX, myMinY, myMaxX, myMaxY;
00576
00577 void *myViewer, *myWorkbench;
00578 GU_PrimGroupClosure *myHidden;
00579
00580
00581 int myUseUV;
00582 int myIsVertexAttrib;
00583 int myAttribOffset;
00584
00585 void (*myMapFct)(const UT_Vector3 &, float &,float &, void *);
00586 bool (*myZDepthFct)(const GU_Detail *, float, float, const UT_Vector3 &,
00587 void *, void *, GU_PrimGroupClosure *,
00588 const GEO_Primitive *);
00589
00590 GU_PolyRaster * createPolyRaster();
00591 void buildPolyRaster();
00592 void destroyPolyRaster();
00593 int polyRasterContains( const UT_Vector3 &pos );
00594
00595 private:
00596 GU_PolyRaster * myPolyRaster;
00597 };
00598
00599 #endif