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