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