Salome HOME
2bf2f44b063fc17a8c866b96d4d874e1754bafbf
[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_Filters.h"
8 #include "PartSet_SketcherMgr.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 <StdSelect_FaceFilter.hxx>
17 #include <TopoDS_Shape.hxx>
18
19 #include <QMap>
20 #include <QMenu>
21 #include <QObject>
22
23 #include <string>
24
25 #include <memory>
26
27 class ModuleBase_Operation;
28 class ModuleBase_IViewWindow;
29
30 class QAction;
31
32 /**
33 * \ingroup Modules
34 * Implementation of Partset module
35 */
36 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule
37 {
38 Q_OBJECT
39
40 /// Enumeration to specify the restart operation properties.
41 enum RestartingMode {
42   RM_None, /// the operation should not be restarted
43   RM_Forbided, /// the operation should not be restarted after there is no active widget
44   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
45   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
46 };
47
48 public:
49   /// Constructor
50   /// \param theWshop a pointer to a workshop
51   PartSet_Module(ModuleBase_IWorkshop* theWshop);
52   virtual ~PartSet_Module();
53
54   /// Creates custom widgets for property panel
55   virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
56                                       Config_WidgetAPI* theWidgetApi, std::string theParentId,
57                                       QList<ModuleBase_ModelWidget*>& theModelWidgets);
58
59   /// Call back forlast tuning of property panel before operation performance
60   virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
61
62
63   /// Realizes some functionality by an operation start
64   /// Displays all sketcher sub-Objects, hides sketcher result, appends selection filters
65   /// \param theOperation a started operation
66   virtual void operationStarted(ModuleBase_Operation* theOperation);
67
68   /// Realizes some functionality by an operation commit
69   /// Restarts sketcher operation automatically of it is necessary
70   /// \param theOperation a committed operation
71   virtual void operationCommitted(ModuleBase_Operation* theOperation);
72
73   /// Realizes some functionality by an operation abort
74   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
75   /// \param theOperation an aborted operation
76   virtual void operationAborted(ModuleBase_Operation* theOperation);
77
78   /// Realizes some functionality by an operation stop
79   /// Hides all sketcher sub-Objects, displays sketcher result and removes selection filters
80   /// \param theOperation a stopped operation
81   virtual void operationStopped(ModuleBase_Operation* theOperation);
82
83   /// Returns True if there are available Undos and the sketch manager allows undo
84   /// \return the boolean result
85   virtual bool canUndo() const;
86
87   //! Returns True if there are available Redos and the sketch manager allows redo
88   /// \return the boolean result
89   virtual bool canRedo() const;
90
91   /// Returns whether the object can be displayed at the bounds of the active operation.
92   /// Display only current operation results for usual operation and ask the sketcher manager
93   /// if it is a sketch operation
94   /// \param theObject a model object
95   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
96   /// Add menu atems for viewer into the given menu
97   /// \param theMenu a popup menu to be shown in the viewer
98   virtual void addViewerItems(QMenu* theMenu) const;
99
100 public slots:
101   /// SLOT, that is called by no more widget signal emitted by property panel
102   /// Set a specific flag to restart the sketcher operation
103   void onNoMoreWidgets();
104
105   /// Processes the context menu action click
106   /// \param isChecked a state of toggle if the action is checkable
107   void onAction(bool isChecked);
108
109 protected slots:
110   /// Called when previous operation is finished
111   virtual void onSelectionChanged();
112
113   /// SLOT, that is called by key release in the viewer.
114   /// \param theWnd a view window
115   /// \param theEvent the key event
116   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
117
118   /// SLOT, that is called by enter key released
119   /// Set a specific type of restarting the current operation
120   void onEnterReleased();
121
122   /// SLOT, that is called by the current operation filling with the preselection.
123   /// It commits the operation of it is can be committed
124   void onOperationActivatedByPreselection();
125
126   //! Delete features
127   void onDeleteObjects();
128
129  protected:
130   /// Register validators for this module
131   virtual void registerValidators();
132
133   /// Register selection filters for this module
134   virtual void registerFilters();
135
136   /// Register properties of this module
137   virtual void registerProperties();
138
139  private slots:
140    /// Processing of vertex selected
141    void onVertexSelected();
142
143  private:
144   /// Breaks sequense of automatically resterted operations
145   void breakOperationSequence();
146
147   /// Create all actions for context menus. It is called on creation of module
148   /// Put the created actions into an internal map
149   void createActions();
150
151   /// Returns action according to the given ID
152   /// \param theId an action identifier, it should be uniqued in the bounds of the module
153   QAction* action(const QString& theId) const;
154
155   /// Add action to the internal map
156   /// \param theId - string ID of the item
157   /// \param theAction - action to add
158   void addAction(const QString& theId, QAction* theAction);
159
160   //! Delete features
161   void deleteObjects();
162
163  private:
164    QString myLastOperationId;
165    FeaturePtr myLastFeature;
166
167    // Automatical restarting mode flag
168    RestartingMode myRestartingMode;
169
170   /// A filter which provides selection within a current document or whole PartSet
171   Handle(PartSet_GlobalFilter) myDocumentShapeFilter;
172
173   PartSet_SketcherMgr* mySketchMgr;
174
175   QMap<QString, QAction*> myActions; // the popup menu actions
176 };
177
178 #endif