Salome HOME
Issue #422 - Application hangs up when apply Fillet constraint on preselected segments
[modules/shaper.git] / src / PartSet / PartSet_Module.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #ifndef PartSet_Module_H
4 #define PartSet_Module_H
5
6 #include "PartSet.h"
7 #include "PartSet_Filters.h"
8 #include "PartSet_SketcherMgr.h"
9
10 #include <ModuleBase_IModule.h>
11 #include <ModuleBase_Definitions.h>
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Attribute.h>
14 #include <ModelAPI_CompositeFeature.h>
15
16 //#include <StdSelect_FaceFilter.hxx>
17 #include <TopoDS_Shape.hxx>
18
19 #include <QMap>
20 #include <QMenu>
21 #include <QObject>
22
23 #include <string>
24
25 #include <memory>
26
27 class ModuleBase_Operation;
28 class ModuleBase_IViewWindow;
29
30 class QAction;
31
32 /**
33 * \ingroup Modules
34 * Implementation of Partset module
35 */
36 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule
37 {
38 Q_OBJECT
39
40 /// Enumeration to specify the restart operation properties.
41 enum RestartingMode {
42   RM_None, /// the operation should not be restarted
43   RM_Forbided, /// the operation should not be restarted after there is no active widget
44   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
45   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
46 };
47
48 public:
49   /// Constructor
50   /// \param theWshop a pointer to a workshop
51   PartSet_Module(ModuleBase_IWorkshop* theWshop);
52   virtual ~PartSet_Module();
53
54   /// Creates custom widgets for property panel
55   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
56                                                      Config_WidgetAPI* theWidgetApi, std::string theParentId);
57
58   /// Call back forlast tuning of property panel before operation performance
59   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
60
61
62   /// Realizes some functionality by an operation start
63   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
64   /// \param theOperation a started operation
65   virtual void operationStarted(ModuleBase_Operation* theOperation);
66
67   /// Realizes some functionality by an operation commit
68   /// Restarts sketcher operation automatically of it is necessary
69   /// \param theOperation a committed operation
70   virtual void operationCommitted(ModuleBase_Operation* theOperation);
71
72   /// Realizes some functionality by an operation abort
73   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
74   /// \param theOperation an aborted operation
75   virtual void operationAborted(ModuleBase_Operation* theOperation);
76
77   /// Realizes some functionality by an operation stop
78   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
79   /// \param theOperation a stopped operation
80   virtual void operationStopped(ModuleBase_Operation* theOperation);
81
82   /// Realizes some functionality by an operation start
83   /// \param theOperation a started operation
84   virtual ModuleBase_Operation* currentOperation() const;
85
86   /// Returns action according to the given ID
87   /// \param theId an action identifier, it should be uniqued in the bounds of the module
88   QAction* action(const QString& theId) const;
89
90   /// Returns True if there are available Undos and the sketch manager allows undo
91   /// \return the boolean result
92   virtual bool canUndo() const;
93
94   //! Returns True if there are available Redos and the sketch manager allows redo
95   /// \return the boolean result
96   virtual bool canRedo() const;
97
98   /// Returns whether the object can be displayed at the bounds of the active operation.
99   /// Display only current operation results for usual operation and ask the sketcher manager
100   /// if it is a sketch operation
101   /// \param theObject a model object
102   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
103
104   /// Add menu atems for viewer into the given menu
105   /// \param theMenu a popup menu to be shown in the viewer
106   /// \param theStdActions a map of standard actions
107   /// \return true if items are added and there is no necessity to provide standard menu
108   virtual bool addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
109
110   /// Returns whether the mouse enter the viewer's window
111   /// \return true if items are added and there is no necessity to provide standard menu
112   bool isMouseOverWindow();
113
114 public slots:
115   /// SLOT, that is called by no more widget signal emitted by property panel
116   /// Set a specific flag to restart the sketcher operation
117   void onNoMoreWidgets();
118
119   /// Processes the context menu action click
120   /// \param isChecked a state of toggle if the action is checkable
121   void onAction(bool isChecked);
122
123   /// Slolt called on object display
124   /// \param theObject a data object
125   /// \param theAIS a presentation object
126   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
127
128 protected slots:
129   /// Called when previous operation is finished
130   virtual void onSelectionChanged();
131
132   /// SLOT, that is called by key release in the viewer.
133   /// \param theWnd a view window
134   /// \param theEvent the key event
135   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
136
137   /// SLOT, that is called by enter key released
138   /// Set a specific type of restarting the current operation
139   void onEnterReleased();
140
141   /// SLOT, that is called by the current operation filling with the preselection.
142   /// It commits the operation of it is can be committed
143   void onOperationActivatedByPreselection();
144
145  protected:
146   /// Register validators for this module
147   virtual void registerValidators();
148
149   /// Register selection filters for this module
150   virtual void registerFilters();
151
152   /// Register properties of this module
153   virtual void registerProperties();
154
155  private slots:
156    /// Processing of vertex selected
157    void onVertexSelected();
158
159    /// Called on transformation in current viewer
160    /// \param theTrsfType type of tranformation
161    void onViewTransformed(int theTrsfType = 2);
162
163  private:
164   /// Breaks sequense of automatically resterted operations
165   void breakOperationSequence();
166
167   /// Create all actions for context menus. It is called on creation of module
168   /// Put the created actions into an internal map
169   void createActions();
170
171   /// Add action to the internal map
172   /// \param theId - string ID of the item
173   /// \param theAction - action to add
174   void addAction(const QString& theId, QAction* theAction);
175
176   //! Delete features
177   virtual bool deleteObjects();
178
179  private:
180    QString myLastOperationId;
181    FeaturePtr myLastFeature;
182
183    // Automatical restarting mode flag
184    RestartingMode myRestartingMode;
185
186   /// A filter which provides selection within a current document or whole PartSet
187   Handle(PartSet_GlobalFilter) myDocumentShapeFilter;
188
189   PartSet_SketcherMgr* mySketchMgr;
190
191   QMap<QString, QAction*> myActions; // the popup menu actions
192
193   int myVisualLayerId;
194 };
195
196 #endif