Salome HOME
Merge branch 'master' into cgt/devCEA
[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_Tools.h"
8 #include "PartSet_OverconstraintListener.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 <Events_Listener.h>
17
18 //#include <StdSelect_FaceFilter.hxx>
19 #include <TopoDS_Shape.hxx>
20 #include <SelectMgr_ListOfFilter.hxx>
21
22 #include <QMap>
23 #include <QMenu>
24 #include <QObject>
25 #include <QModelIndex>
26
27 #include <string>
28
29 #include <memory>
30
31 class ModuleBase_Operation;
32 class ModuleBase_IViewWindow;
33 class ModuleBase_ViewerPrs;
34
35 class XGUI_Workshop;
36 class PartSet_MenuMgr;
37 class PartSet_CustomPrs;
38 class PartSet_SketcherMgr;
39 class PartSet_SketcherReentrantMgr;
40 class ModelAPI_Result;
41
42 class QAction;
43
44 /**
45 * \ingroup Modules
46 * Implementation of Partset module
47 */
48 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule, public Events_Listener
49 {
50 Q_OBJECT
51
52 /// Enumeration to specify the restart operation properties.
53 enum RestartingMode {
54   RM_None, /// the operation should not be restarted
55   RM_Forbided, /// the operation should not be restarted after there is no active widget
56   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature
57                       /// for own initialization
58   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
59 };
60
61 public:
62
63   /// Constructor
64   /// \param theWshop a pointer to a workshop
65   PartSet_Module(ModuleBase_IWorkshop* theWshop);
66   virtual ~PartSet_Module();
67
68   // Add default selection filters of the module to the current viewer
69   virtual void activateSelectionFilters();
70   // Remove default selection filters of the module from the current viewer
71   virtual void deactivateSelectionFilters();
72
73   // Stores the current selection
74   virtual void storeSelection();
75
76   // Restores the current selection
77   virtual void restoreSelection();
78
79   /// Creates custom widgets for property panel
80   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
81                                                      Config_WidgetAPI* theWidgetApi);
82
83   /// Returns the active widget, by default it is the property panel active widget
84   /// If the internal edit operation is started, this is the first widget of the operation
85   virtual ModuleBase_ModelWidget* activeWidget() const;
86
87   /// Call back forlast tuning of property panel before operation performance
88   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
89
90   /// If there is found selected attribute, widgets are created and contains
91   /// only a widget for the attribute
92   /// It is important for Property Panel filling by sketch point attribute
93   /// \param theOperation a started operation
94   /// \param theWidgets a list of created widgets
95   /// \return boolean result, false by default
96   virtual bool createWidgets(ModuleBase_Operation* theOperation,
97                              QList<ModuleBase_ModelWidget*>& theWidgets) const;
98
99   /// Launching of a edit operation on the feature
100   /// \param theFeature feature for editing
101   virtual void editFeature(FeaturePtr theFeature);
102
103   /// Returns true if the operation can be committed. Result in default implementation is true.
104   /// \return boolean value
105   virtual bool canCommitOperation() const;
106
107   /// Creates an operation and send it to loop
108   /// \param theCmdId the operation name
109   virtual void launchOperation(const QString& theCmdId);
110
111   /// Realizes some functionality by an operation start
112   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
113   /// Activate the operation presentation
114   /// \param theOperation a started operation
115   virtual void operationStarted(ModuleBase_Operation* theOperation);
116
117   /// Realizes some functionality by an operation resume
118   /// Activate the operation presentation
119   /// \param theOperation a resumed operation
120   virtual void operationResumed(ModuleBase_Operation* theOperation);
121
122   /// Realizes some functionality by an operation commit
123   /// Restarts sketcher operation automatically of it is necessary
124   /// \param theOperation a committed operation
125   virtual void operationCommitted(ModuleBase_Operation* theOperation);
126
127   /// Realizes some functionality by an operation abort
128   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
129   /// \param theOperation an aborted operation
130   virtual void operationAborted(ModuleBase_Operation* theOperation);
131
132   /// Realizes some functionality by an operation stop
133   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
134   /// \param theOperation a stopped operation
135   virtual void operationStopped(ModuleBase_Operation* theOperation);
136
137   /// Returns current operation
138   virtual ModuleBase_Operation* currentOperation() const;
139
140   /// Returns True if there are available Undos and the sketch manager allows undo
141   /// \return the boolean result
142   virtual bool canUndo() const;
143
144   //! Returns True if there are available Redos and the sketch manager allows redo
145   /// \return the boolean result
146   virtual bool canRedo() const;
147
148   /// Returnas true if the action can be applyed to the object
149   /// \param theObject a checked object
150   /// \param theActionId an identifier of action, to be found in the menu manager like "DELETE_CMD"
151   /// \return the a booean result
152   virtual bool canApplyAction(const ObjectPtr& theObject, const QString& theActionId) const;
153
154   /// Returns True if the current operation can be committed. Asks the sketch manager.
155   /// \return a boolean value
156   //virtual bool canCommitOperation() const;
157
158   /// Returns whether the object can be erased at the bounds of the active operation.
159   /// The sub-objects of the current operation can not be erased
160   /// \param theObject a model object
161   virtual bool canEraseObject(const ObjectPtr& theObject) const;
162
163   /// Returns whether the object can be displayed at the bounds of the active operation.
164   /// Display only current operation results for usual operation and ask the sketcher manager
165   /// if it is a sketch operation
166   /// \param theObject a model object
167   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
168
169   /// Make some functionality after the objects are hidden in viewer
170   /// \param theObjects a list of hidden objects
171   //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
172
173   /// Returns true if selection for the object can be activate.
174   /// For sketch operation allow the selection activation if the operation is edit, for other
175   /// operation uses the default result
176   /// \param theObject a model object
177   virtual bool canActivateSelection(const ObjectPtr& theObject) const;
178
179   /// Add menu atems for object browser into the given menu
180   /// \param theMenu a popup menu to be shown in the object browser
181   virtual void addObjectBrowserMenu(QMenu* theMenu) const;
182
183   /// Add menu items for viewer into the actions map
184   /// \param theStdActions a map of standard actions
185   /// \param theParent a parent widget
186   /// \param theMenuActions map of action/menu for the desirable index in the viewer menu
187   /// \return true if items are added and there is no necessity to provide standard menu
188   virtual bool addViewerMenu(const QMap<QString, QAction*>& theStdActions,
189                              QWidget* theParent,
190                              QMap<int, QAction*>& theMenuActions) const;
191
192   /// Returns a list of modes, where the AIS objects should be activated
193   /// \param theModes a list of modes
194   virtual void activeSelectionModes(QIntList& theModes);
195
196   /// Appends specific selection modes for the module to the list of types
197   /// \param theTypes a selection modes to be extended
198   virtual void customSubShapesSelectionModes(QIntList& theTypes);
199
200   /// Returns whether the mouse enter the viewer's window
201   /// \return true if items are added and there is no necessity to provide standard menu
202   bool isMouseOverWindow();
203
204   /// Returns sketch manager object
205   PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
206
207   /// Returns sketch reentrant manager
208   PartSet_SketcherReentrantMgr* sketchReentranceMgr() const { return mySketchReentrantMgr; }
209
210   /// Find object and attribute(if selected) for the given viewer selection
211   /// \param theSelected a viewer selection
212   /// \param theObject a selected model object
213   /// \param theAttribute a selected model attribute
214   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
215                                 ObjectPtr& theObject, AttributePtr& theAttribute);
216
217   /// Returns listener of overconstraint signal
218   /// \return the listener
219   PartSet_OverconstraintListener* overconstraintListener() { return myOverconstraintListener; }
220
221   /// Returns true if the current operation is not reentrant and the current state of the
222   /// application is not in launch operation mode
223   /// \return boolean value
224   bool isSketchNeutralPointActivated() const;
225
226   /// Performs functionality on closing document
227   virtual void closeDocument();
228
229   /// Clears specific presentations in the viewer
230   virtual void clearViewer();
231
232   /// Event Listener method
233   /// \param theMessage an event message
234   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
235
236   /// Set the object with the object results are customized
237   /// \param theFeature a feature
238   void setCustomized(const FeaturePtr& theFeature);
239
240   /// Return true if the custom presentation is activated
241   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
242   /// \return boolean value
243   virtual bool isCustomPrsActivated(const ModuleBase_CustomizeFlag& theFlag) const;
244
245   /// Activate custom presentation for the object
246   /// \param theFeature a feature instance
247   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
248   /// \param theUpdateViewer the parameter whether the viewer should be update immediately
249   virtual void activateCustomPrs(const FeaturePtr& theFeature,
250                                  const ModuleBase_CustomizeFlag& theFlag,
251                                  const bool theUpdateViewer);
252
253   /// Deactivate custom presentation for the object
254   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
255   /// \param theUpdateViewer the parameter whether the viewer should be update immediately
256   virtual void deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
257                                    const bool theUpdateViewer);
258
259   /// Modifies the given presentation in the custom way.
260   virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
261                                      AISObjectPtr thePrs,
262                                      std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
263
264   /// Modifies the given presentation in the custom way after usual customize is performed.
265   virtual bool afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
266                                           AISObjectPtr thePrs,
267                                           GeomCustomPrsPtr theCustomPrs);
268
269   /// Update the object presentable properties such as color, lines width and other
270   /// If the object is result with the color attribute value set, it is used,
271   /// otherwise the customize is applyed to the object's feature if it is a custom prs
272   /// \param theObject an object instance
273   /// \param theFlag a flag of level of customization, which means that only part of sub-elements
274   /// should be updated(e.g. only highlighted elements)
275   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
276   /// \returns true if the object is modified
277   virtual bool customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
278                                const bool theUpdateViewer);
279
280   /// This method is called on object browser creation for customisation of module specific features
281   /// \param theObjectBrowser a pinter on Object Browser widget
282   virtual void customizeObjectBrowser(QWidget* theObjectBrowser);
283
284   /// Returns the viewer Z layer
285   int getVisualLayerId() const { return myVisualLayerId; }
286
287   /// Create specific for the module presentation
288   /// \param theResult an object for presentation
289   /// \return created presentation or NULL(default value)
290   virtual Handle(AIS_InteractiveObject) createPresentation(
291                               const std::shared_ptr<ModelAPI_Result>& theResult);
292
293   //! Returns data object by AIS
294   virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
295
296   //! Returns true if the presentation can be shown in shading mode
297   //! \param theAIS presentation to be checked
298   //! \return boolean value
299   virtual bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) const;
300
301   /// Update state of pop-up menu items in viewer
302   /// \param theStdActions - a map of standard actions
303   virtual void updateViewerMenu(const QMap<QString, QAction*>& theStdActions);
304
305   /// Returns true if the action should be always enabled
306   /// \param theActionId an action index: Accept or Accept All
307   /// \return boolean value
308   virtual bool isActionEnableStateFixed(const int theActionId) const;
309
310   //! Returns the feature error if the current state of the feature in the module is not correct
311   //! If the feature is correct, it returns an empty value
312   //! \return string value
313   virtual QString getFeatureError(const FeaturePtr& theFeature);
314
315   /// Returns list of granted operation indices
316   virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
317
318   /// Validates the current operation and send the state change to sketch manager
319   /// \param thePreviousState the previous widget value state
320   virtual void widgetStateChanged(int thePreviousState);
321
322   /// Returns true if the event is processed. It gives the reentrance manager to process the enter.
323   /// \param thePreviousAttributeID an index of the previous active attribute
324   virtual bool processEnter(const std::string& thePreviousAttributeID);
325
326   /// Performs some GUI actions before an operation transaction is stopped
327   /// Default realization is empty
328   virtual void beforeOperationStopped(ModuleBase_Operation* theOperation);
329
330   /// Finds a shape by attribute if it is possible
331   /// \param theAttribute an attribute
332   /// \return a geom shape
333   virtual GeomShapePtr findShape(const AttributePtr& theAttribute);
334
335   /// Finds an attribute by geom shape if it is possible
336   /// \param theObject an object of the attribute
337   /// \param theGeomShape a geom shape
338   /// \return theAttribute
339   virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
340
341   /// Returns reentrant message if it was accepted
342   virtual std::shared_ptr<Events_Message> reentrantMessage();
343
344   /// Put current selection into reentrant message
345   /// \param theMessage a message of reentrant operation
346   virtual void setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage);
347
348   /// Returns the workshop
349   XGUI_Workshop* getWorkshop() const;
350
351 public slots:
352   /// Redefines the parent method in order to customize the next case:
353   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
354   /// the operation should be always aborted.
355   virtual void onFeatureTriggered();
356
357   /// Slolt called on object display
358   /// \param theObject a data object
359   /// \param theAIS a presentation object
360   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
361
362   /// Slot called on before object erase
363   /// \param theObject a data object
364   /// \param theAIS a presentation object
365   virtual void onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
366
367   /// Called on transformation in current viewer
368   /// \param theTrsfType type of tranformation
369   void onViewTransformed(int theTrsfType = 2);
370
371 protected slots:
372   /// Called when previous operation is finished
373   virtual void onSelectionChanged();
374
375   /// SLOT, that is called by key release in the viewer.
376   /// \param theWnd a view window
377   /// \param theEvent the key event
378   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
379
380   /// A slot called on view window creation
381   void onViewCreated(ModuleBase_IViewWindow*);
382
383   /// A slot to change property panel title by choice type change if the title information
384   /// exists in the XML definition of this control attribute
385   /// \param theWidget a sender
386   /// \param theIndex the current choice index
387   void onChoiceChanged(ModuleBase_ModelWidget* theWidget, int theIndex);
388
389 protected:
390   /// Sets the constraints states in internal map. If the feature kind is a dimensional constraint
391   /// other dimensions are shown.
392   /// \param theFeatureKindId a feature kind
393   void storeConstraintsState(const std::string& theFeatureKindId);
394
395   /// If the feature kind is a geometrical or dimensional constraint, set visible state for
396   /// all types of constraints
397   /// \param theFeatureKindId a feature kind
398   void updateConstraintsState(const std::string& theFeatureKind);
399
400   /// Register validators for this module
401   virtual void registerValidators();
402
403   /// Connects or disconnects to the value changed signal of the property panel widgets
404   /// \param theWidget a property contol widget
405   /// \param isToConnect a boolean value whether connect or disconnect
406   virtual void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
407
408   /// Updates reentrant manager state or sketcher operations for the started operation
409   /// \param theOperation the started operation
410   void updateSketcherOnStart(ModuleBase_Operation* theOperation);
411
412   /// Updates presetnations of results and arguments by operation start
413   /// \param theOperation the started operation
414   void updatePresentationsOnStart(ModuleBase_Operation* theOperation);
415
416  private slots:
417    void onTreeViewDoubleClick(const QModelIndex&);
418
419    void onActiveDocPopup(const QPoint&);
420
421  private:
422   //! Delete features
423   virtual bool deleteObjects();
424
425   void setDefaultConstraintShown();
426
427 private:
428   bool myIsOperationIsLaunched; /// state of application between launch and stop operation
429   SelectMgr_ListOfFilter mySelectionFilters;
430
431   PartSet_SketcherMgr* mySketchMgr;
432   PartSet_SketcherReentrantMgr* mySketchReentrantMgr;
433   PartSet_MenuMgr* myMenuMgr;
434   /// A default custom presentation, which is used for references objects of started operation
435   PartSet_CustomPrs* myCustomPrs;
436   PartSet_OverconstraintListener* myOverconstraintListener;
437   int myVisualLayerId;
438
439   /// backup of the visible state to restore them by operation stop
440   QMap<PartSet_Tools::ConstraintVisibleState, bool> myHasConstraintShown;
441
442   QModelIndex myActivePartIndex;
443 };
444
445 #endif