]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.h
Salome HOME
Introduce internal edit operation state in PartSet module in order to have a virtual...
[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
8 #include <ModuleBase_IModule.h>
9 #include <ModuleBase_Definitions.h>
10 #include <ModelAPI_Feature.h>
11 #include <ModelAPI_Attribute.h>
12 #include <ModelAPI_CompositeFeature.h>
13
14 #include <Events_Listener.h>
15
16 //#include <StdSelect_FaceFilter.hxx>
17 #include <TopoDS_Shape.hxx>
18 #include <SelectMgr_ListOfFilter.hxx>
19
20 #include <QMap>
21 #include <QMenu>
22 #include <QObject>
23 #include <QModelIndex>
24
25 #include <string>
26
27 #include <memory>
28
29 class ModuleBase_Operation;
30 class ModuleBase_IViewWindow;
31 class PartSet_MenuMgr;
32 class PartSet_CustomPrs;
33 class PartSet_SketcherMgr;
34
35 class QAction;
36
37 /**
38 * \ingroup Modules
39 * Implementation of Partset module
40 */
41 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
42 {
43 Q_OBJECT
44
45 /// Enumeration to specify the restart operation properties.
46 enum RestartingMode {
47   RM_None, /// the operation should not be restarted
48   RM_Forbided, /// the operation should not be restarted after there is no active widget
49   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
50   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
51 };
52
53 public:
54
55   /// Constructor
56   /// \param theWshop a pointer to a workshop
57   PartSet_Module(ModuleBase_IWorkshop* theWshop);
58   virtual ~PartSet_Module();
59
60   // Add default selection filters of the module to the current viewer
61   virtual void activateSelectionFilters();
62   // Remove default selection filters of the module from the current viewer
63   virtual void deactivateSelectionFilters();
64
65   /// Creates custom widgets for property panel
66   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
67                                                      Config_WidgetAPI* theWidgetApi, std::string theParentId);
68
69   /// Returns the active widget, by default it is the property panel active widget
70   /// If the internal edit operation is started, this is the first widget of the operation
71   virtual ModuleBase_ModelWidget* activeWidget() const;
72
73   /// Call back forlast tuning of property panel before operation performance
74   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
75
76   /// Creates an operation and send it to loop
77   /// \param theCmdId the operation name
78   virtual void launchOperation(const QString& theCmdId);
79
80   /// Realizes some functionality by an operation start
81   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
82   /// Activate the operation presentation
83   /// \param theOperation a started operation
84   virtual void onOperationStarted(ModuleBase_Operation* theOperation);
85
86   /// Realizes some functionality by an operation resume
87   /// Activate the operation presentation
88   /// \param theOperation a resumed operation
89   virtual void onOperationResumed(ModuleBase_Operation* theOperation);
90
91   /// Realizes some functionality by an operation commit
92   /// Restarts sketcher operation automatically of it is necessary
93   /// \param theOperation a committed operation
94   virtual void onOperationCommitted(ModuleBase_Operation* theOperation);
95
96   /// Realizes some functionality by an operation abort
97   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
98   /// \param theOperation an aborted operation
99   virtual void onOperationAborted(ModuleBase_Operation* theOperation);
100
101   /// Realizes some functionality by an operation stop
102   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
103   /// \param theOperation a stopped operation
104   virtual void onOperationStopped(ModuleBase_Operation* theOperation);
105
106   /// Returns current operation
107   virtual ModuleBase_Operation* currentOperation() const;
108
109   /// Returns True if there are available Undos and the sketch manager allows undo
110   /// \return the boolean result
111   virtual bool canUndo() const;
112
113   //! Returns True if there are available Redos and the sketch manager allows redo
114   /// \return the boolean result
115   virtual bool canRedo() const;
116
117   /// Returnas true if the action can be applyed to the object
118   /// \param theObject a checked object
119   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
120   /// \return the a booean result
121   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
122
123   /// Returns True if the current operation can be committed. Asks the sketch manager.
124   /// \return a boolean value
125   virtual bool canCommitOperation() const;
126
127   /// Returns whether the object can be erased at the bounds of the active operation.
128   /// The sub-objects of the current operation can not be erased
129   /// \param theObject a model object
130   virtual bool canEraseObject(const ObjectPtr& theObject) const;
131
132   /// Returns whether the object can be displayed at the bounds of the active operation.
133   /// Display only current operation results for usual operation and ask the sketcher manager
134   /// if it is a sketch operation
135   /// \param theObject a model object
136   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
137
138   /// Returns true if selection for the object can be activate.
139   /// For sketch operation allow the selection activation if the operation is edit, for other
140   /// operation uses the default result
141   /// \param theObject a model object
142   virtual bool canActivateSelection(const ObjectPtr& theObject) const;
143
144   /// Add menu atems for object browser into the given menu
145   /// \param theMenu a popup menu to be shown in the object browser
146   virtual void addObjectBrowserMenu(QMenu* theMenu) const;
147
148   /// Add menu atems for viewer into the given menu
149   /// \param theMenu a popup menu to be shown in the viewer
150   /// \param theStdActions a map of standard actions
151   /// \return true if items are added and there is no necessity to provide standard menu
152   virtual bool addViewerMenu(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
153
154   /// Returns a list of modes, where the AIS objects should be activated
155   /// \param theModes a list of modes
156   virtual void activeSelectionModes(QIntList& theModes);
157
158   /// Returns whether the mouse enter the viewer's window
159   /// \return true if items are added and there is no necessity to provide standard menu
160   bool isMouseOverWindow();
161
162   /// Returns sketch manager object
163   PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
164
165   /// Performs functionality on closing document
166   virtual void closeDocument();
167
168   /// Clears specific presentations in the viewer
169   virtual void clearViewer();
170
171   /// Event Listener method
172   /// \param theMessage an event message
173   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
174
175   /// Set the object with the object results are customized
176   /// \param theFeature a feature
177   void setCustomized(const FeaturePtr& theFeature);
178
179   /** Update the object presentable properties such as color, lines width and other
180   * If the object is result with the color attribute value set, it is used,
181   * otherwise the customize is applyed to the object's feature if it is a custom prs
182   * \param theObject an object instance
183   * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
184   * \returns true if the object is modified
185   */
186   virtual bool customizeObject(ObjectPtr theObject, const bool theUpdateViewer);
187
188   /// This method is called on object browser creation for customisation of module specific features
189   /// \param theObjectBrowser a pinter on Object Browser widget
190   virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
191
192   /// Returns the viewer Z layer
193   int getVisualLayerId() const { return myVisualLayerId; }
194
195   //! Returns data object by AIS
196   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
197
198   /// Update state of pop-up menu items in viewer
199   /// \param theStdActions - a map of standard actions
200   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions); 
201
202   //! Returns the feature error if the current state of the feature in the module is not correct
203   //! If the feature is correct, it returns an empty value
204   //! \return string value
205   virtual QString getFeatureError(const FeaturePtr& theFeature);
206
207   /// Returns list of granted operation indices
208   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
209
210   bool isInternalEditOperation() { return myIsInternalEditOperation; }
211
212 public slots:
213   /// SLOT, that is called by no more widget signal emitted by property panel
214   /// Set a specific flag to restart the sketcher operation
215   void onNoMoreWidgets(const std::string& thePreviousAttributeID);
216
217   void onInternalActivateFirstWidgetSelection();
218
219   /// Redefines the parent method in order to customize the next case:
220   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
221   /// the operation should be always aborted.
222   virtual void onFeatureTriggered();
223
224   /// Slolt called on object display
225   /// \param theObject a data object
226   /// \param theAIS a presentation object
227   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
228
229   /// Slot called on before object erase
230   /// \param theObject a data object
231   /// \param theAIS a presentation object
232   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
233
234   /// Called on transformation in current viewer
235   /// \param theTrsfType type of tranformation
236   void onViewTransformed(int theTrsfType = 2);
237
238 protected slots:
239   /// Called when previous operation is finished
240   virtual void onSelectionChanged();
241
242   /// SLOT, that is called by key release in the viewer.
243   /// \param theWnd a view window
244   /// \param theEvent the key event
245   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
246
247   /// SLOT, that is called by enter key released
248   /// Set a specific type of restarting the current operation
249   void onEnterReleased();
250
251   /// SLOT, that is called by the current operation filling with the preselection.
252   /// It commits the operation of it is can be committed
253   void onOperationActivatedByPreselection();
254
255   /// A slot called on view window creation
256   void onViewCreated(ModuleBase_IViewWindow*);
257
258  protected:
259   /// Register validators for this module
260   virtual void registerValidators();
261
262   /// Register selection filters for this module
263   virtual void registerFilters();
264
265   /// Register properties of this module
266   virtual void registerProperties();
267
268  private slots:
269    /// Processing of vertex selected
270    void onVertexSelected();
271
272    void onTreeViewDoubleClick(const QModelIndex&);
273
274  private:
275   /// Breaks sequense of automatically resterted operations
276   void breakOperationSequence();
277
278   //! Delete features
279   virtual bool deleteObjects();
280
281  private:
282   QString myLastOperationId;
283   FeaturePtr myLastFeature;
284
285   std::string myPreviousAttributeID;
286
287   // Automatical restarting mode flag
288   RestartingMode myRestartingMode;
289
290   bool myIsInternalEditOperation;
291
292   SelectMgr_ListOfFilter mySelectionFilters;
293
294   PartSet_SketcherMgr* mySketchMgr;
295   PartSet_MenuMgr* myMenuMgr;
296   /// A default custom presentation, which is used for references objects of started operation
297   PartSet_CustomPrs* myCustomPrs;
298   int myVisualLayerId;
299
300   bool myHasConstraintShown;
301
302   QModelIndex aActivePartIndex;
303 };
304
305 #endif