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