00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __OP3D_InputSelector_h__
00023 #define __OP3D_InputSelector_h__
00024
00025 #include "OP3D_API.h"
00026 #include <UT/UT_IntArray.h>
00027 #include <UT/UT_StringArray.h>
00028 #include <UT/UT_UndoWorkerFinder.h>
00029 #include <UI/UI_HotkeyHelper.h>
00030 #include <UI/UI_Value.h>
00031 #include <GU/GU_SelectType.h>
00032 #include <OP/OP_Node.h>
00033 #include <DM/DM_Defines.h>
00034 #include "OP3D_InputSelectorBase.h"
00035
00036 class UT_String;
00037 class GU_Detail;
00038 class GU_Selection;
00039 class OP_Node;
00040 class OP_Network;
00041 class SOP_Node;
00042 class OBJ_Node;
00043 class UI_Event;
00044 class UI_Feel;
00045 class GUI_DetailLook;
00046 class GUI_DisplayOption;
00047 class BM_View;
00048 class DM_Viewport;
00049 class DM_Workbench;
00050 class OP3D_View;
00051 class OP3D_CustomToolbox;
00052 class OP3D_InputSelectorUndo;
00053 class OP3D_InputSelectorUndoWorker;
00054 class OP3D_EdgeLoopHelper;
00055 class op3d_BrushData;
00056
00057 typedef bool (*OP3D_ValidForPickFilter)(void *data, GUI_DetailLook *look);
00058
00059 class OP3D_API OP3D_InputSelector : public OP3D_InputSelectorBase
00060 {
00061 public:
00062 OP3D_InputSelector(OP3D_View &viewer, PI_SelectorTemplate &templ);
00063 virtual ~OP3D_InputSelector();
00064
00065 virtual const char *className() const;
00066
00067
00068
00069 virtual int handleMouseEvent(UI_Event *event);
00070
00071
00072 virtual bool handleDoubleClickEvent(UI_Event *event);
00073
00074
00075
00076 virtual int handleKeyEvent(UI_Event *event, DM_Viewport &viewport);
00077 bool willHandleKeyEvent(UI_Event *event);
00078
00079
00080
00081
00082
00083
00084 int selectionIndex() const { return mySelectionIndex; }
00085 void selectionIndex(int selection_index)
00086 { mySelectionIndex = selection_index; }
00087
00088
00089
00090
00091 bool inputRequired() const { return myInputRequiredFlag; }
00092 void inputRequired(bool onoff)
00093 { myInputRequiredFlag = onoff; }
00094
00095
00096
00097
00098 bool useAsteriskToSelectAll() const
00099 { return myUseAsteriskToSelectAll; }
00100 void useAsteriskToSelectAll(bool onoff)
00101 { myUseAsteriskToSelectAll = onoff;}
00102
00103
00104
00105 bool orderedSelector() const
00106 { return myOrderedSelectorFlag; }
00107 void orderedSelector(bool onoff)
00108 { myOrderedSelectorFlag = onoff; }
00109
00110
00111
00112
00113 void usePrimsInEdgeSelections(bool use_prims)
00114 { myUsePrimsInEdgeSelectionFlag = use_prims; }
00115
00116
00117 unsigned primMask() const { return myPrimMask; }
00118 void primMask(unsigned primmask)
00119 { myPrimMask = primmask; }
00120
00121 void setPickAtObjLevel(bool flag)
00122 { myPickAtObjLevelFlag = flag; }
00123 bool getPickAtObjLevel() const
00124 { return myPickAtObjLevelFlag; }
00125
00126
00127
00128
00129
00130 virtual void startSelecting(bool copy_cooked_selection = true);
00131 virtual void stopSelecting();
00132 void addCookedSelection( SOP_Node *sop );
00133
00134 void nodeIdForReselecting(int node_id)
00135 { myNodeIdForReselecting = node_id; }
00136
00137
00138
00139 virtual void clearSelections();
00140
00141
00142
00143
00144
00145
00146
00147 virtual void setViewer(BM_View *viewer);
00148
00149
00150
00151 void setSelectionUIValues(UI_Value *sel_type,
00152 UI_Value *sel_rule,
00153 UI_Value *sel_style,
00154 UI_Value *sel_full,
00155 UI_Value *locate_always,
00156 UI_Value *finished);
00157
00158 void setCreatorStateName(const char *state_name)
00159 { myCreatorStateName.harden(state_name); }
00160 const UT_String &creatorStateName()
00161 { return myCreatorStateName; }
00162
00163
00164 void allowDragSelect(bool yesno)
00165 { myAllowDragSelFlag = yesno; }
00166
00167
00168 void selectFullGeometry(bool yesno)
00169 { myFullSelFlag = yesno; }
00170
00171
00172 void saveUndos(bool yesno) { mySaveUndosFlag = yesno; }
00173 bool saveUndos() const { return mySaveUndosFlag; }
00174
00175
00176
00177 void renderForPicking(RE_Render *r, short x, short y);
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 bool connectOps(OP_Node &new_node, int op_input_index,
00188 const UT_String &input_parm,
00189 bool update_sel_buttons = true,
00190 int *menu_idx = 0,
00191 bool branch_off = false,
00192 bool multi_input = false,
00193 bool force_selection_string = false);
00194
00195
00196 const UT_StringArray&selectedOpPaths() const
00197 { return mySelectedOpPaths; }
00198 void setSelectedOpPaths(const UT_StringArray &paths)
00199 { mySelectedOpPaths = paths; }
00200 const UT_IntArray &selectedSelInstances() const
00201 { return mySelectedSelInstances; }
00202 void setSelectedSelInstances(const UT_IntArray &selinsts)
00203 { mySelectedSelInstances = selinsts; }
00204 void addSelectedPath(const char *path, int selinstance,
00205 GU_Selection *sel);
00206 void movePathToEnd(const char *path);
00207 void removeSelectedPath(const char *path);
00208
00209
00210
00211
00212
00213
00214 const UT_String ¤tPrompt() const { return myCurrentPrompt; }
00215 UT_String ¤tPrompt() { return myCurrentPrompt; }
00216 const UT_String &defaultPrompt() const { return myDefaultPrompt; }
00217 UT_String &defaultPrompt() { return myDefaultPrompt; }
00218
00219
00220
00221
00222 void selectorFinished(bool drag = false);
00223
00224
00225
00226 static GU_Selection *getSelection(GU_Detail &gdp,
00227 int &selinst,
00228 int selection_index,
00229 GU_SelectionType sel_type,
00230 GU_SelectionConnectivity connectivity,
00231 bool isview3d,
00232 bool create_selection);
00233
00234
00235
00236
00237
00238 static SOP_Node *createObjectMerge(OP_Network *network,
00239 UT_String &path,
00240 int &selinst,
00241 int selindex,
00242 const UT_String &creator_state_name,
00243 bool keep_original_objects,
00244 bool display_origina_objects);
00245
00246
00247
00248 void setUndoWorker(OP3D_InputSelectorUndoWorker *worker=0);
00249
00250 OP3D_InputSelectorUndoWorker *getDefaultUndoWorker();
00251
00252
00253 virtual UI_Menu *getSelectorMenu() const;
00254 virtual UI_Menu *getSelectorHotkeyMenu() const;
00255
00256 virtual void doRender(RE_Render *r, short x, short y, int ghost);
00257
00258 void setValidForPickFilter(void *data,
00259 OP3D_ValidForPickFilter filter);
00260
00261
00262
00263
00264 void setGeometryType(DM_GeometryType geo_type,
00265 bool connected,
00266 bool update_buttons);
00267 GU_SelectionType selectionType() const;
00268
00269
00270 DM_GeometryType getGeometryTypeAtFinish() const;
00271 bool getConnectedAtFinish() const;
00272 int getGroupTypeMenuValAtFinish() const;
00273 bool getKeepOriginalObjects() const;
00274
00275
00276 bool getIsView3D();
00277
00278 GU_SelectionConnectivity getConnectivity();
00279
00280 static GU_SelectionConnectivity getConnectivity(DM_Workbench &bench);
00281
00282 const DM_GeometryTypeArray &getSelectionAllowedTypes() const;
00283 void setSelectionAllowedTypes(
00284 const DM_GeometryTypeArray &allowedtypes);
00285
00286
00287
00288
00289
00290
00291 virtual void makeValidSelections(DM_GeometryType &geo_type,
00292 bool &connected,
00293 int &group_type_menu_val) = 0;
00294
00295
00296 static void makeSelectionsValid(const UT_StringArray &paths,
00297 const UT_IntArray &selinstances,
00298 int selindex,
00299 DM_GeometryType geo_type,
00300 bool connected,
00301 GU_SelectionConnectivity connect,
00302 bool isview3d,
00303 unsigned primmask,
00304 OP3D_InputSelector *selector);
00305
00306
00307
00308 virtual void generateAllSelectionStrings(UT_String &sel_string,
00309 bool destroy_selections,
00310 bool only_one_gdp);
00311
00312
00313
00314 static bool generateSelectionString(UT_String &sel_string,
00315 const GU_Detail &gdp,
00316 GU_Selection &selection,
00317 int prim_offset,
00318 int point_offset,
00319 bool collapse_where_possible,
00320 bool use_ast_to_select_all);
00321 static void generateMergedSelectionString(UT_String &sel_string,
00322 UT_StringArray &paths,
00323 UT_IntArray &selinstances,
00324 int selindex,
00325 bool collapse,
00326 bool use_ast_to_select_all);
00327
00328
00329
00330 static bool convertSelectionType(GU_Detail &gdp,
00331 GU_SelectionType stype,
00332 GU_SelectionConnectivity c,
00333 bool view3d,
00334 int selinst,
00335 int selindex);
00336
00337
00338
00339 static bool createSelectionFromObjects(
00340 const OP_NodeList &objects,
00341 DM_Viewport &viewport,
00342 DM_GeometryType geo_type,
00343 int selindex,
00344 GU_SelectionConnectivity connectivity,
00345 bool is_view3d,
00346 UT_StringArray &paths,
00347 UT_IntArray &selinsts);
00348
00349 protected:
00350
00351 virtual void handleSelectionTypeChange(UI_Event *event);
00352
00353
00354
00355
00356 virtual void addToSelection(UI_Event * ,
00357 const char * ,
00358 int ,
00359 void * )
00360 { }
00361
00362
00363
00364 virtual bool modifySelections(UI_Event *event,unsigned *pick_buffer,
00365 int num_picked, GU_SelectionRule sel_rule,
00366 int num_lasso_points, int *lasso_points,
00367 op3d_BrushData *brushdata);
00368
00369
00370
00371 virtual bool handleNoPick(UI_Event *event);
00372
00373
00374
00375 virtual void appendToLastNode(SOP_Node *&,
00376 const UT_String &,
00377 bool ) {}
00378
00379
00380 virtual void generateAdditionalInputNodes(SOP_Node & ,
00381 SOP_Node * ,
00382 const UT_String & ,
00383 const UT_String & ) {}
00384
00385
00386 virtual void setNodeParameters(OP_Node &) {}
00387
00388
00389
00390 int pickMask() const;
00391
00392
00393
00394
00395 GU_Selection *getOrCreateSelection(GU_Detail &gdp, int &selinst);
00396 GU_Selection *getExistingSelection(GU_Detail &gdp, int selinst);
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 void overrideSelectionValues(int sel_type, int sel_rule,
00407 int sel_style, int sel_full,
00408 int locate);
00409
00410 void restoreSelectionValues();
00411
00412
00413
00414 virtual OP_Node *switchToChosenOp(OP_Node *parent);
00415
00416
00417 virtual void saveForUndo();
00418
00419
00420
00421 virtual bool getPickName(const OP3D_PickId &pickid,
00422 UT_String &name,
00423 bool descriptivename) const;
00424
00425 virtual bool needObjectPick() const;
00426
00427
00428
00429 bool emptySelections(const char *path_to_skip = 0,
00430 bool refresh = true);
00431
00432
00433 void destroySelection(GU_Detail &gdp, int selinst);
00434 void dirtySelection(GU_Detail &gdp, int selinst);
00435
00436
00437 void clearSelectionArrays();
00438
00439
00440 private:
00441 void handleStartSelecting(UI_Event *event);
00442
00443
00444 friend class OP3D_InputSelectorUndo;
00445
00446
00447 bool singleSelectGeometry(UI_Event *event, bool save_undo);
00448 bool boxSelectGeometry(UI_Event *event,
00449 short xcenter, short ycenter,
00450 short xsize, short ysize);
00451 bool lassoSelectGeometry(UI_Event *event,
00452 int *lasso_points);
00453 bool brushSelectGeometry(UI_Event *event,
00454 char *enablemap,
00455 int minx, int miny,
00456 int maxx, int maxy);
00457 bool selectGeometry(UI_Event *event,
00458 short xcenter=0, short ycenter=0,
00459 short xsize=0, short ysize=0,
00460 bool box_pick=false,
00461 int num_lasso_points=0,
00462 int *lasso_points=0,
00463 op3d_BrushData *brushdata = 0);
00464
00465
00466 void fullSelectionChanged(UI_Event *);
00467
00468
00469
00470
00471 void copyAllSelections(GU_Detail &dest_gdp,
00472 GU_Detail &source_gdp,
00473 int &selinst);
00474 void copySelection(GU_Detail &dest_gdp,
00475 GU_Detail &source_gdp,
00476 int selection_index,
00477 int &selinst);
00478
00479
00480
00481 void selectAllOrNoneOrToggle(OP3D_SelectionAction action,
00482 DM_Viewport &viewport);
00483
00484
00485
00486
00487 void selectBoundary(DM_Viewport &viewport);
00488 void shrinkSelection(DM_Viewport &viewport);
00489 void growSelection(DM_Viewport &viewport);
00490
00491
00492
00493
00494 void uvSelectAllByWinding(DM_Viewport &viewport,
00495 bool front_facing,
00496 bool back_facing);
00497
00498 virtual void handleBoxPickEvent(UI_Event *event);
00499 virtual void handleLassoPickEvent(UI_Event *event);
00500 virtual void handleBrushPickEvent(UI_Event *event);
00501
00502
00503
00504 void handleGroupSelectorAction(UI_Event *event);
00505 void handleGroupSelection(UI_Event *event);
00506 void handleSelectionHideOrExpose(UI_Event *);
00507
00508
00509
00510
00511 bool validForPickRender(GUI_DetailLook *detail,
00512 const GUI_DisplayOption &dopt);
00513
00514
00515 bool isAnythingSelected();
00516
00517
00518
00519 void setVisibilitySopParameters(SOP_Node &visibility_sop,
00520 bool exposing,
00521 bool applying_to_selection,
00522 int viewport_type,
00523 bool cumulative,
00524 const UT_String &sel_string);
00525
00526 OP3D_EdgeLoopHelper &getEdgeLoopHelper();
00527
00528 SOP_Node * findChosenSop(bool &need_object_pick);
00529 void handleSwitchToChosenOp(UI_Event *event);
00530
00531 int doPick(UI_Event *event,
00532 short xcenter, short ycenter,
00533 short xsize, short ysize,
00534 bool box_or_lasso_pick,
00535 bool pick_objects_only,
00536 bool pick_alternate_objects,
00537 uint prim_mask, int pick_mask,
00538 uint *&pick_buffer);
00539
00540 void doneNormalSelection();
00541
00542
00543
00544
00545
00546 bool addOpPathsForVisibleSelection(SOP_Node *chosen_sop,
00547 bool &have_temp_sel);
00548
00549 void handleGeoChanged(UI_Event *event);
00550
00551 void updateSelectMask();
00552
00553 static OP_Node * mergeViaCombine(float t,
00554 OP_Network *network,
00555 UT_String &path,
00556 int &selinst,
00557 int selindex,
00558 const UT_String &creator_state_name);
00559
00560
00561 static UI_HotkeyHelper::Entry theHotkeyList[];
00562
00563 bool acceptKey(UI_Event *event);
00564 bool fullSelectionKey(UI_Event *event);
00565 bool keepOriginalObjKey(UI_Event *event);
00566 bool locateKey(UI_Event *event);
00567 bool selectAllKey(UI_Event *event);
00568 bool invertSelectionKey(UI_Event *event);
00569 bool selectNoneKey(UI_Event *event);
00570 bool selectBoundaryKey(UI_Event *event);
00571 bool shrinkSelectionKey(UI_Event *event);
00572 bool growSelectionKey(UI_Event *event);
00573 bool selectUVSelectAllFrontKey(UI_Event *event);
00574 bool selectUVSelectAllBackKey(UI_Event *event);
00575
00576 private:
00577
00578 UI_HotkeyHelper myHotkeyHelper;
00579 DM_Viewport *myHotkeyViewport;
00580
00581 UT_String myCurrentPrompt;
00582 UT_String myDefaultPrompt;
00583
00584 UT_String myCreatorStateName;
00585
00586 UI_Value *myGeoChangedValue;
00587 UI_Value *mySelectionType;
00588 UI_Value *myFullSelection;
00589 UI_Value *myAlwaysLocate;
00590
00591
00592
00593 bool myCustomSelValFlag;
00594 int mySavedSelType;
00595 int mySavedSelRule;
00596 int mySavedSelStyle;
00597 int mySavedFullSel;
00598 int mySavedAlwaysLocate;
00599
00600 unsigned myPrimMask;
00601
00602 UT_StringArray mySelectedOpPaths;
00603 UT_IntArray mySelectedSelInstances;
00604 int mySelectionIndex;
00605
00606 int myLastMouseDown;
00607 int myLastMouseStartX;
00608 int myLastMouseStartY;
00609
00610 UT_String myGroupName;
00611
00612 int myNodeIdForReselecting;
00613
00614 bool myInputRequiredFlag;
00615 bool myAllowDragSelFlag;
00616 bool myFullSelFlag;
00617 bool mySaveUndosFlag;
00618 bool myOrderedSelectorFlag;
00619 bool myUseAsteriskToSelectAll;
00620 bool myUsePrimsInEdgeSelectionFlag;
00621
00622 bool myPickAtObjLevelFlag;
00623
00624
00625 DM_GeometryType myFinishGeometryType;
00626 bool myFinishConnected;
00627 int myFinishGroupTypeMenuVal;
00628
00629
00630 DM_GeometryType myLastGeometryType;
00631 bool myLastConnected;
00632
00633 bool myPickObjectsOnly;
00634 bool myCopyCookedSelection;
00635 bool myHadDoubleClick;
00636 bool myAlternatePick;
00637
00638 OP3D_InputSelectorUndoWorker *myUndoWorker;
00639 bool myOwnUndoWorker;
00640 DM_GeometryTypeArray myAllowedTypes;
00641
00642
00643 OP3D_EdgeLoopHelper *myEdgeLoopHelper;
00644 OP3D_ValidForPickFilter myValidForPickFilter;
00645 void *myValidForPickFilterData;
00646 };
00647
00648 #endif