Salome HOME
Merge branch 'Dev_1.2.0' of newgeom:newgeom.git into Dev_1.2.0
[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
9 #include <ModuleBase_IModule.h>
10 #include <ModuleBase_Definitions.h>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_Attribute.h>
13 #include <ModelAPI_CompositeFeature.h>
14
15 //#include <StdSelect_FaceFilter.hxx>
16 #include <TopoDS_Shape.hxx>
17
18 #include <QMap>
19 #include <QMenu>
20 #include <QObject>
21
22 #include <string>
23
24 #include <memory>
25
26 class ModuleBase_Operation;
27 class ModuleBase_IViewWindow;
28 class PartSet_MenuMgr;
29 class PartSet_SketcherMgr;
30
31 class QAction;
32
33 /**
34 * \ingroup Modules
35 * Implementation of Partset module
36 */
37 class PARTSET_EXPORT PartSet_Module : public ModuleBase_IModule
38 {
39 Q_OBJECT
40
41 /// Enumeration to specify the restart operation properties.
42 enum RestartingMode {
43   RM_None, /// the operation should not be restarted
44   RM_Forbided, /// the operation should not be restarted after there is no active widget
45   RM_LastFeatureUsed, /// the operation is restarted and use the previous feature for own initialization
46   RM_EmptyFeatureUsed /// the operation is restarted and does not use the previous feature
47 };
48
49 public:
50   /// Constructor
51   /// \param theWshop a pointer to a workshop
52   PartSet_Module(ModuleBase_IWorkshop* theWshop);
53   virtual ~PartSet_Module();
54
55   /// Creates custom widgets for property panel
56   virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
57                                                      Config_WidgetAPI* theWidgetApi, std::string theParentId);
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 current operation
84   virtual ModuleBase_Operation* currentOperation() const;
85
86   /// Returns True if there are available Undos and the sketch manager allows undo
87   /// \return the boolean result
88   virtual bool canUndo() const;
89
90   //! Returns True if there are available Redos and the sketch manager allows redo
91   /// \return the boolean result
92   virtual bool canRedo() const;
93
94   /// Returns whether the object can be displayed at the bounds of the active operation.
95   /// Display only current operation results for usual operation and ask the sketcher manager
96   /// if it is a sketch operation
97   /// \param theObject a model object
98   virtual bool canDisplayObject(const ObjectPtr& theObject) const;
99
100   /// Add menu atems for viewer into the given menu
101   /// \param theMenu a popup menu to be shown in the viewer
102   /// \param theStdActions a map of standard actions
103   /// \return true if items are added and there is no necessity to provide standard menu
104   virtual bool addViewerItems(QMenu* theMenu, const QMap<QString, QAction*>& theStdActions) const;
105
106   /// Returns a list of modes, where the AIS objects should be activated
107   /// \param theModes a list of modes
108   virtual void activeSelectionModes(QIntList& theModes);
109
110   /// Returns whether the mouse enter the viewer's window
111   /// \return true if items are added and there is no necessity to provide standard menu
112   bool isMouseOverWindow();
113
114   PartSet_SketcherMgr* sketchMgr() const { return mySketchMgr; }
115
116 public slots:
117   /// SLOT, that is called by no more widget signal emitted by property panel
118   /// Set a specific flag to restart the sketcher operation
119   void onNoMoreWidgets();
120
121   /// Slolt called on object display
122   /// \param theObject a data object
123   /// \param theAIS a presentation object
124   virtual void onObjectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
125
126 protected slots:
127   /// Called when previous operation is finished
128   virtual void onSelectionChanged();
129
130   /// SLOT, that is called by key release in the viewer.
131   /// \param theWnd a view window
132   /// \param theEvent the key event
133   void onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
134
135   /// SLOT, that is called by enter key released
136   /// Set a specific type of restarting the current operation
137   void onEnterReleased();
138
139   /// SLOT, that is called by the current operation filling with the preselection.
140   /// It commits the operation of it is can be committed
141   void onOperationActivatedByPreselection();
142
143  protected:
144   /// Register validators for this module
145   virtual void registerValidators();
146
147   /// Register selection filters for this module
148   virtual void registerFilters();
149
150   /// Register properties of this module
151   virtual void registerProperties();
152
153   /// Sends the operation for launching
154   /// \param theOperation the operation
155   virtual void sendOperation(ModuleBase_Operation* theOperation);
156
157  private slots:
158    /// Processing of vertex selected
159    void onVertexSelected();
160
161    /// Called on transformation in current viewer
162    /// \param theTrsfType type of tranformation
163    void onViewTransformed(int theTrsfType = 2);
164
165  private:
166   /// Breaks sequense of automatically resterted operations
167   void breakOperationSequence();
168
169   //! Delete features
170   virtual bool deleteObjects();
171
172  private:
173    QString myLastOperationId;
174    FeaturePtr myLastFeature;
175
176    // Automatical restarting mode flag
177    RestartingMode myRestartingMode;
178
179   /// A filter which provides selection within a current document or whole PartSet
180   Handle(PartSet_GlobalFilter) myDocumentShapeFilter;
181
182   PartSet_SketcherMgr* mySketchMgr;
183
184   PartSet_MenuMgr* myMenuMgr;
185
186   int myVisualLayerId;
187 };
188
189 #endif