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