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