00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Cristin Barghiel 00008 * Side Effects Software Inc. 00009 * 20 Maud St. 00010 * Toronto, Ontario, M5V 2M5 00011 * Canada 00012 * 416-366-4607 00013 * 00014 * NAME: GU_EdgeSelection (C++) 00015 * 00016 * COMMENTS: 00017 * Edge selection. 00018 * 00019 */ 00020 00021 #ifndef __GU_EdgeSelection_h__ 00022 #define __GU_EdgeSelection_h__ 00023 00024 #include "GU_API.h" 00025 #include <GB/GB_EdgeGroup.h> 00026 #include "GU_Selection.h" 00027 00028 00029 #define GU_edgeSelectName "selectedEdges" 00030 00031 class GU_API GU_EdgeSelection : public GU_Selection 00032 { 00033 public: 00034 // Class constructor and destructor. The prefix is used for naming the 00035 // two internal groups, theEdges and thePrims. 00036 GU_EdgeSelection(GU_Detail &gdp, const char *prefix = 0); 00037 virtual ~GU_EdgeSelection(void); 00038 00039 // Conversion methods. These methods update the point and primitive 00040 // closures, but not the stash array. 00041 virtual GU_Selection &operator=(GU_PointSelection &); 00042 virtual GU_Selection &operator=(GU_PrimSelection &); 00043 virtual GU_Selection &operator=(GU_EdgeSelection &); 00044 virtual GU_Selection &operator=(GU_BreakpointSelection &); 00045 virtual GU_Selection &operator=(GU_VertexSelection &); 00046 virtual GU_Selection &operator=(GU_PointGroupSelection &s) 00047 { return GU_Selection::operator=(s); } 00048 virtual GU_Selection &operator=(GU_PrimGroupSelection &s) 00049 { return GU_Selection::operator=(s); } 00050 00051 // Return the pick mask to be used to select entities that this selection 00052 // knows how to handle: 00053 virtual int pickMask(void) const; 00054 00055 // This method is static so you can retrieve the pick mask for this type 00056 // of selection without having an instance of it. 00057 static int edgePickMask(void); 00058 00059 // Return the mask of entities that, if picked, would definitely cause 00060 // us to self pick. Things that we can partially be picked on (such as 00061 // edge maybe) should not be added to this mask. We definitely can't 00062 // snap to points, prims, and guides. 00063 virtual int selfSnapMask(void) const; 00064 00065 // Use the pick buffer to update your selection according to the given 00066 // rule. Return 1 if the selection has changed and 0 otherwise. The first 00067 // edge to be added to us (if any), is returned in 'added', and so is 00068 // the pickid unless the pointer to is is zero. 00069 virtual int select(uint *pickbuf, long npicked, 00070 void *&added, 00071 GU_SelectionRule rule = GU_AddSelect, 00072 unsigned *pickid = 0, 00073 GU_LassoInfo *linfo = 0, 00074 const UT_IntArray *prfx = 0); 00075 virtual int selectEntireGeometry(uint *pickbuf, 00076 long npicked, 00077 void *&added, 00078 GU_SelectionRule rule = GU_AddSelect, 00079 unsigned *pickid = 0, 00080 GU_LassoInfo *linfo = 0, 00081 const UT_IntArray *prfx = 0); 00082 00083 virtual int selectBoundary(bool checkuv); 00084 00085 virtual int shrinkSelection(bool checkuv); 00086 00087 virtual int selectNext(void *&added, 00088 GU_SelectionRule rule = GU_AddSelect, 00089 int shiftstate = 0, 00090 int vstate = 0); 00091 00092 virtual int selectPrev(void *&added, 00093 GU_SelectionRule rule = GU_AddSelect, 00094 int shiftstate = 0, 00095 int vstate = 0); 00096 00097 // Use the pick buffer to check how the selection would be affected 00098 // by the given rule. If an add is performed it will return 00099 // GU_SelectionAdd regardless of whether any removes are performed. 00100 // The selections are not affected. 00101 virtual GU_SelectionResult selectEmpty(uint *pickbuf, long npicked, 00102 GU_SelectionRule rule = GU_AddSelect, 00103 unsigned *pickid = 0, 00104 GU_LassoInfo *linfo = 0, 00105 const UT_IntArray *prfx = 0) const; 00106 00107 // Use the pick buffer to find out if it contains something we've got 00108 // selected or anything that we don't have in the selection. We return 00109 // a pointer to that first something if found. Otherwise we return 0. 00110 virtual void *siftThrough(uint *pickbuf, long npicked, 00111 int look_for_existing = 1, 00112 unsigned *pickid = 0, 00113 GU_LassoInfo *linfo = 0, 00114 const UT_IntArray *prfx = 0) const; 00115 00116 // Find the actual point picked in the selection: this could be a GEO 00117 // point, a point on a normal, curve, edge, etc. 'added' indicates 00118 // what has been picked. 'pickid' is the type of hit that generated the 00119 // pick, and 'xsect' is the picked point (to be found). The methods return 00120 // 1 if xsect can be determined and 0 otherwise. If the 'xsect' is not 00121 // found, the 2nd method computes the bounding box of 'added' and returns 00122 // that one instead. 00123 virtual int selectionPoint(void *added, unsigned *pickid, 00124 UT_Vector3 &xsect) const; 00125 virtual int selectionPoint(void *added, unsigned *pickid, 00126 UT_Vector3 rayorig, 00127 UT_Vector3 &raydir, 00128 UT_Vector3 &xsect, 00129 int &normal, 00130 UT_Vector3 &vector, 00131 int accurate, float *u, 00132 float *v) const; 00133 00134 // Select the contents of the group even if the group type does not 00135 // match our type. Return 1 if the selection has changed, 0 otherwise. 00136 // If we can use group as our main group without further ado, do so 00137 // as long as we can reference it (ref != 0). 00138 virtual int selectGroup(const GB_BaseGroup &group, int ref=0); 00139 00140 // Add some geo entity to the selection. Each selection class will 00141 // interpret the inserion in its own way. For example, by inserting a 00142 // GEO_Point into a primitive selection we actually insert all the prims 00143 // that share that point. Conversely, by inserting a GEO_Primitive into 00144 // a point selection we actually insert all the prim's points. The methods 00145 // return 1 if something has been added and 0 otherwise. 00146 // These methods do NOT update the point and primitive closure, just in 00147 // case you are doing multiple adds. 00148 virtual int add(GEO_Point &point, int = 0); 00149 virtual int add(GEO_Primitive &prim, int = 0); 00150 virtual int add(GB_Edge &edge, int = 0); 00151 virtual int add(GEO_Breakpoint &bkp, int = 0); 00152 virtual int add(GB_VertexData &vtx, int = 0); 00153 00154 // Remove some geo entity from the selection. Each selection class will 00155 // interpret the removal in its own way. For example, by removing a 00156 // GEO_Point from a primitive selection we actually remove all the prims 00157 // that share that point. Conversely, by removing a GEO_Primitive from 00158 // a point selection we actually remove all the prim's points. The methods 00159 // return 1 if something has been removed and 0 otherwise. 00160 // These methods do NOT update the point and primitive closure, just in 00161 // case you are doing multiple removals. 00162 virtual int remove(GEO_Point &point, int = 0); 00163 virtual int remove(GEO_Primitive &prim, int = 0); 00164 virtual int remove(GB_Edge &edge, int = 0); 00165 virtual int remove(GEO_Breakpoint &bkp, int = 0); 00166 virtual int remove(GB_VertexData &vtx, int = 0); 00167 00168 // Remove the last element in the selection. Return 1 if we're removed 00169 // successfully and 0 otherwise. 00170 virtual int removeLast(void); 00171 00172 // Toggle some geo entity in the selection. Each selection class will 00173 // interpret the toggle in its own way. For example, by toggling a 00174 // GEO_Point in a primitive selection we actually toggle all the prims 00175 // that share that point. Conversely, by toggling a GEO_Primitive in 00176 // a point selection we actually toggle all the prim's points. The methods 00177 // return 1 if something has been toggled and 0 otherwise. 00178 // These methods do NOT update the point and primitive closure, just in 00179 // case you are doing multiple toggles. 00180 virtual int toggle(GEO_Point &point, int = 0); 00181 virtual int toggle(GEO_Primitive &prim, int = 0); 00182 virtual int toggle(GB_Edge &edge, int = 0); 00183 virtual int toggle(GEO_Breakpoint &bkp, int = 0); 00184 virtual int toggle(GB_VertexData &vtx, int = 0); 00185 00186 // Update (and possibly create) the internal lists of data. The points 00187 // and primitives are groups of closures, ie. points and primitives that 00188 // the selection "touches". The stashed array is used for transformations. 00189 // The updates are independent of each other, so don't rely on one taking 00190 // care of the others as well. Make sure you update the stashed array last. 00191 // Return a point ref array if one is passed in. 00192 virtual GB_PointGroup *updatePoints(void); 00193 virtual GB_PrimitiveGroup *updatePrimitives(void); 00194 00195 // Just clear the bits of the groups, or destroy the internal groups and 00196 // arrays too. 00197 virtual void clear(void); 00198 virtual void clearAndDestroy(void); 00199 00200 // Destroy the underlying geometry and update the groups. Return 0 if OK 00201 // and -1 otherwise. 00202 virtual int destroyGeometry(void); 00203 00204 // Copy the geometry found in the selection. Create n copies laid out 00205 // 'delta' units apart. Return -1 because we can't create edges. 00206 virtual int copyGeometry(int copies = 1, UT_Vector3 *delta = 0, 00207 const char *groupname = 0); 00208 00209 // Reverse the order of vertices in the selected geometry. 00210 virtual void reverse(); 00211 00212 // Find out if the selection contains this edge. WARNING: this method 00213 // is slower than what you may expect because it checks if the edges 00214 // are identical point by point. Returns the edge if found, 0 otherwise. 00215 GB_Edge *find(const GB_Edge &edge) const; 00216 00217 // How many entries does the selection contain? 00218 virtual int entries(void) const; 00219 00220 // Compute the bounding box of the selection, and return 0 if the box 00221 // is empty and 1 otherwise. 00222 virtual int getBoundingBox(UT_BoundingBox &bbox) const; 00223 virtual int getBoundingBox(UT_BoundingBox &bbox, const UT_Matrix4& transform ) const; 00224 00225 // Compute the UV bounding box of the selection, and return 0 if the 00226 // box is empty and 1 otherwise. 00227 virtual int getBoundingBoxUV(UT_BoundingBox &bbox, 00228 const char *name, 00229 int isvertex) const; 00230 00231 // Return a _const_ handle to the selected edges: 00232 const UT_LinkList &getSelection(void) const { return theSelection.list(); } 00233 00234 // I/O methods, returning 0 if OK and -1 otherwise: 00235 virtual int save(ostream &os, int binary) const; 00236 virtual bool load(UT_IStream &is); 00237 00238 // Create geometry from selection; return gdp if successful, 0 otherwise 00239 virtual GU_Detail *createGeometry(); 00240 00241 // Query the type of selection: 00242 virtual int classType(void) const; 00243 00244 // Return the group of selected edges. 00245 virtual const GB_EdgeGroup *edges() const; 00246 00247 00248 // Get/Set flag to determine whether or not this selection will store 00249 // primitive id's in the edges when available. When this flag is false, 00250 // edges are treated as a pair of points, when true, edges are a pair of 00251 // points on a specific primitive. The default is false. 00252 virtual void setUsePrimEdges(bool use_prim_edges) 00253 { myUsePrimEdges = use_prim_edges; } 00254 virtual bool getUsePrimEdges() const { return myUsePrimEdges; } 00255 00256 protected: 00257 // the the edge on the end of this poly 00258 // GB_Edge will be filled with the points of the edge, 00259 // and vtx_arr will hold the vertex#'s of the edges. 00260 // format : vtx_arr[0] : 1st vertex, vtx_arr[1] 2nd vertex for faces 00261 // vtx_arr[0],[1] hold row,col, resp. for 1st vertex, [2],[3] 00262 // hold row,col for 2nd vertex on a hull 00263 00264 int getEndEdge(GEO_Primitive &prim, int heading, 00265 int vertical, GB_Edge &edge, 00266 int vtx_arr[4]) const; 00267 00268 00269 // Gets the "next" edge on the poly. vtx_arr should already be filled 00270 // by either getEndEdge or a previous call to getNextEdge. 00271 // returns 1 if successful, 0 if the edge is off the poly. 00272 int getNextEdge(GEO_Primitive &prim, int direction, 00273 int vertical, GB_Edge &edge, 00274 int vtx_arr[4]) const; 00275 00276 int isEdgeInLasso(const GEO_Primitive *prim, 00277 const GEO_Point &p0, const GEO_Point &p1, 00278 GU_LassoInfo *linfo, 00279 GU_PolyRaster *&praster) const; 00280 00281 // Create new identical selection as this one in gdp. 00282 virtual GU_Selection *newSpecies(GU_Detail &gdp); 00283 00284 virtual const GB_BaseGroup *mainGroup() const { return &theSelection; } 00285 00286 00287 // Used to create new species. 00288 GU_EdgeSelection(GU_Detail &gdp, const GU_EdgeSelection &s); 00289 00290 // These methods return 1 if the selection has changed and 0 otherwise. 00291 virtual int selectAllUsingClosure( 00292 GU_PrimGroupClosure *closure, 00293 int how_to_treat_closure); 00294 virtual int toggleAllUsingClosure( 00295 GU_PrimGroupClosure *closure, 00296 int how_to_treat_closure); 00297 00298 GB_EdgeGroup theSelection; // the group of selected edges 00299 00300 private: 00301 // This toggle defines whether or not this selection should use primitives 00302 // when defining an edge (wherever possible) 00303 bool myUsePrimEdges; 00304 }; 00305 00306 #endif
1.5.9