Salome HOME
Update of transactions management after the nested operation finished in extrusion cut
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_SketcherMgr.h
4 // Created:     19 Dec 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef PartSet_SketcherMgr_H
8 #define PartSet_SketcherMgr_H
9
10 #include "PartSet.h"
11
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Attribute.h>
14 #include <ModelAPI_CompositeFeature.h>
15 #include <ModelAPI_Result.h>
16
17 #include <ModuleBase_ViewerFilters.h>
18 #include <ModuleBase_Definitions.h>
19
20 #include <GeomAPI_Pln.h>
21 #include <SelectMgr_IndexedMapOfOwner.hxx>
22
23 #include <QObject>
24 #include <QList>
25 #include <QMap>
26
27 class PartSet_Module;
28 class ModuleBase_IViewWindow;
29 class ModuleBase_ModelWidget;
30 class ModuleBase_Operation;
31 class XGUI_OperationMgr;
32 class QMouseEvent;
33
34 /**
35 * \ingroup Modules
36 * A class for management of sketch operations
37   At the time of the sketcher operation active, only the sketch sub-feature results are
38   displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
39   are hidden, the sketch feature result is displayed
40 */
41 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
42 {
43   Q_OBJECT
44   /// Struct to define gp point, with the state is the point is initialized
45   struct Point
46   {
47     /// Constructor
48     Point()
49     {
50       myIsInitialized = false;
51     }
52     /// Destructor
53     ~Point()
54     {
55     }
56
57     /// clear the initialized flag.
58     void clear()
59     {
60       myIsInitialized = false;
61     }
62     /// set the point and switch on the initialized flag
63     /// \param thePoint the point
64     void setValue(const double theX, const double theY)
65     {
66       myIsInitialized = true;
67       myCurX = theX;
68       myCurY = theY;
69     }
70
71     bool myIsInitialized;  /// the state whether the point is set
72     double myCurX, myCurY; /// the point coordinates
73   };
74 public:
75   /// Constructor
76   /// \param theModule a pointer to PartSet module
77   PartSet_SketcherMgr(PartSet_Module* theModule);
78
79   virtual ~PartSet_SketcherMgr();
80
81   /// Returns true if the operation is the sketch
82   /// \param theOperation an operation
83   /// \return the boolean result
84   static bool isSketchOperation(ModuleBase_Operation* theOperation);
85
86   /// Returns true if the operation id is in the sketch operation id list
87   /// \param theOperation an operation
88   /// \return the boolean result
89   static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
90
91   /// Returns true if the operation is a create nested feature one
92   /// \param theOperation a checked operation
93   //// \return boolean value
94   static bool isNestedCreateOperation(ModuleBase_Operation* theOperation);
95
96   /// Returns whether the current operation is a sketch entity - line, point, arc or circle
97   /// \param theId is an id of object
98   /// \return a boolean value
99   static bool isEntity(const std::string& theId);
100
101   /// Returns whether the current operation is a sketch distance - lenght, distance or radius
102   /// \param theOperation the operation
103   /// \return a boolean value
104   static bool isDistanceOperation(ModuleBase_Operation* theOperation);
105
106   /// Returns true if a mouse cursor is over viewer window
107   bool isMouseOverWindow() { return myIsMouseOverWindow; }
108
109   /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
110   CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
111
112   /// Starts sketch operation
113   void startSketch(ModuleBase_Operation* );
114
115   /// Stops sketch operation
116   void stopSketch(ModuleBase_Operation* );
117
118   /// Starts sketch operation, connects to the opeation property panel
119   /// \param theOperation a committed operation
120   void startNestedSketch(ModuleBase_Operation* theOperation);
121
122   /// Stop sketch operation, disconnects from the opeation property panel
123   /// \param theOperation a stopped operation
124   void stopNestedSketch(ModuleBase_Operation* theOperation);
125
126   /// Visualizes the operation feature if it is a creation nested feature operation
127   /// \param theOperation a committed operation
128   void commitNestedSketch(ModuleBase_Operation* theOperation);
129
130   /// Returns True if there are available Undos and the sketch manager allows undo
131   /// \return the boolean result
132   bool canUndo() const;
133
134   //! Returns True if there are available Redos and the sketch manager allows redo
135   /// \return the boolean result
136   bool canRedo() const;
137
138   /// Returns False only if the sketch creating feature can not be visualized.
139   /// \return a boolean value
140   bool canCommitOperation() const;
141
142   /// Returns whether the object can be displayed at the bounds of the active operation.
143   /// Display only current operation results for usual operation and ask the sketcher manager
144   /// if it is a sketch operation
145   /// \param theObject a model object
146   bool canDisplayObject(const ObjectPtr& theObject) const;
147
148   /// Returns true if the mouse is over viewer or property panel value is changed
149   /// \return boolean result
150   bool canDisplayCurrentCreatedFeature() const;
151
152   /// Returns state of constraints showing flag 
153   bool isConstraintsShown() const { return myIsConstraintsShown; }
154
155   /// Returns true if the object is a current sketch sub feature of a result of the feature
156   /// \param theObject an object
157   /// \return boolean value
158   bool isObjectOfSketch(const ObjectPtr& theObject) const;
159
160   /// Saves the current selection in the viewer into an internal container
161   /// It obtains the selected attributes. The highlighted objects can be processes as the selected ones
162   /// \param theHighlightedUse a boolean flag
163   void storeSelection(const bool theHighlightedOnly = false);
164
165   /// Restores previously saved selection state
166   void restoreSelection();
167
168   /// Returns list of strings which contains id's of sketch operations
169   static const QStringList& sketchOperationIdList();
170
171   /// Returns list of strings which contains id's of constraints operations
172   static const QStringList& constraintsIdList();
173
174   /// Returns a list of modes, where the AIS objects should be activated
175   /// \param theModes a list of modes
176   static void sketchSelectionModes(QIntList& theModes);
177
178 public slots:
179   /// Process sketch plane selected event
180   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
181
182 private slots:
183   /// Process the enter mouse to the view port. If the current operation is a create of
184   /// a nested sketch feature, it updates internal flags to display the feature on mouse move
185   void onEnterViewPort();
186   /// Process the leave mouse of the view port. If the current operation is a create of
187   /// a nested sketch feature, it hides the feature in the viewer
188   void onLeaveViewPort();
189   /// Listens to the value changed signal and display the current operation feature
190   void onBeforeValuesChangedInPropertyPanel();
191   /// Listens to the signal about values are to be changed in the property panel
192   void onValuesChangedInPropertyPanel();
193   /// Listens to the signal about the modification of the values have been done in the property panel
194   void onAfterValuesChangedInPropertyPanel();
195
196   void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
197   void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
198   void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
199   void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
200   void onApplicationStarted();
201   void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
202
203   void onBeforeContextMenu();
204   void onAfterContextMenu();
205
206   void onShowConstraintsToggle(bool);
207
208 private:
209   /// Launches the operation from current highlighting
210   void launchEditing();
211
212   /// Converts mouse position to 2d coordinates. 
213   /// Member myCurrentSketch has to be correctly defined
214   void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
215                   Point& thePoint);
216
217   typedef QMap<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
218                                                                        FeatureToSelectionMap;
219
220   /// Obtains the current selection of the object in the workshop viewer 
221   /// It includes the selection in all modes of activation, even local context - vertices, edges
222   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
223   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
224   /// the feature, if the owner is edge, the current result is added to the container of results.
225   /// \param theFeature a feature or result object
226   /// \param theSketch a current sketch feature
227   /// \param theWorkshop a workshop to have an access to AIS context and displayer
228   /// \param theSelection a container for the selection, to save results and attributres for a feature
229   static void getCurrentSelection(const FeaturePtr& theFeature,
230                                   const FeaturePtr& theSketch,
231                                   ModuleBase_IWorkshop* theWorkshop,
232                                   FeatureToSelectionMap& theSelection);
233
234   /// Applyes the current selection to the object in the workshop viewer 
235   /// It includes the selection in all modes of activation, even local context - vertexes, edges
236   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
237   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
238   /// the feature and if it is in the container of selected attributes, the owner is put in the
239   /// out container. If the owner is edge and the current result is in the container of selected
240   /// results, the owner is put in the out container.
241   /// \param theFeature a feature or result object
242   /// \param theSketch a current sketch feature
243   /// \param theWorkshop a workshop to have an access to AIS context and displayer
244   /// \param theSelection a container of the selection, it has results and attributres for a feature
245   /// \param theOwnersToSelect an out container of found owners
246   static void getSelectionOwners(const FeaturePtr& theFeature,
247                                   const FeaturePtr& theSketch,
248                                   ModuleBase_IWorkshop* theWorkshop,
249                                   const FeatureToSelectionMap& theSelection,
250                                   SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
251
252   /// Connects or disconnects to the value changed signal of the property panel widgets
253   /// \param isToConnect a boolean value whether connect or disconnect
254   void connectToPropertyPanel(const bool isToConnect);
255
256   /// Returns true if the created feature is visible
257   /// \param 
258   bool isVisibleCreatedFeature() const;
259
260   /// Returns a current operation
261   /// \return an operation
262   ModuleBase_Operation* getCurrentOperation() const;
263
264   /// Erase or display the feature of the current operation. If the mouse over the active view or
265   /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
266   /// \param theOperation an operation which feature is to be displayed, it is nested create operation
267   /// \param isToDisplay a flag about the display or erase the feature
268   void visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay,
269                         const bool isFlushRedisplay = true);
270 private:
271   /// Gives a debug information about internal flags myIsMouseOverWindow and myIsResetCurrentValue
272   /// \return a string value
273   QString mouseOverWindowFlagsInfo() const;
274
275   XGUI_OperationMgr* operationMgr() const;
276
277 private:
278   PartSet_Module* myModule;
279
280   bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
281   bool myIsDragging;
282   bool myDragDone;
283   bool myIsResetCurrentValue; /// the state that value in the property panel is reset
284   bool myIsMouseOverWindow; /// the state that the mouse over the view
285   bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
286   bool myIsPopupMenuActive; /// the state of the popup menu is shown
287   Point myCurrentPoint;
288   Point myClickedPoint;
289
290   CompositeFeaturePtr myCurrentSketch;
291
292   Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
293   FeatureToSelectionMap myCurrentSelection;
294   bool myPreviousUpdateViewerEnabled;
295
296   bool myIsConstraintsShown;
297 };
298
299
300 #endif