]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_SketcherMgr.h
Salome HOME
External points manager object created
[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 "PartSet_Filters.h"
13 #include "PartSet_Tools.h"
14
15 #include <ModelAPI_Feature.h>
16 #include <ModelAPI_Attribute.h>
17 #include <ModelAPI_CompositeFeature.h>
18 #include <ModelAPI_Result.h>
19
20 #include <ModuleBase_ViewerFilters.h>
21 #include <ModuleBase_Definitions.h>
22 #include <ModuleBase_ModelWidget.h>
23
24 #include <GeomAPI_Pln.h>
25 #include <SelectMgr_IndexedMapOfOwner.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopTools_MapOfShape.hxx>
28
29 #include <QObject>
30 #include <QList>
31 #include <QMap>
32
33 class PartSet_Module;
34 class ModuleBase_IViewWindow;
35 class ModuleBase_ModelWidget;
36 class ModuleBase_Operation;
37 class XGUI_OperationMgr;
38 class XGUI_Workshop;
39 class PartSet_ExternalPointsMgr;
40
41 class AIS_InteractiveObject;
42
43 class QMouseEvent;
44
45 /**
46 * \ingroup Modules
47 * A class for management of sketch operations
48   At the time of the sketcher operation active, only the sketch sub-feature results are
49   displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
50   are hidden, the sketch feature result is displayed
51 */
52 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
53 {
54   Q_OBJECT
55   /// Struct to define gp point, with the state is the point is initialized
56   struct Point
57   {
58     /// Constructor
59     Point()
60     {
61       myIsInitialized = false;
62     }
63     /// Destructor
64     ~Point()
65     {
66     }
67
68     /// clear the initialized flag.
69     void clear()
70     {
71       myIsInitialized = false;
72     }
73     /// set the point and switch on the initialized flag
74     /// \param thePoint the point
75     void setValue(const double theX, const double theY)
76     {
77       myIsInitialized = true;
78       myCurX = theX;
79       myCurY = theY;
80     }
81
82     bool myIsInitialized;  /// the state whether the point is set
83     double myCurX, myCurY; /// the point coordinates
84   };
85
86 public:
87   /// Struct to define selection model information to store/restore selection
88   struct SelectionInfo
89   {
90     std::set<AttributePtr> myAttributes; /// the selected attributes
91     std::set<ResultPtr> myResults; /// the selected results
92     TopoDS_Shape myFirstResultShape; /// the first shape of feature result
93     TopTools_MapOfShape myLocalSelectedShapes; /// shapes of local selection
94   };
95   typedef QMap<FeaturePtr, SelectionInfo> FeatureToSelectionMap;
96
97 public:
98   /// Constructor
99   /// \param theModule a pointer to PartSet module
100   PartSet_SketcherMgr(PartSet_Module* theModule);
101
102   virtual ~PartSet_SketcherMgr();
103
104   /// Returns true if the operation is the sketch
105   /// \param theOperation an operation
106   /// \return the boolean result
107   static bool isSketchOperation(ModuleBase_Operation* theOperation);
108
109   /// Returns true if the operation feature belongs to list of granted features of Sketch
110   /// operation. An operation of a sketch should be started before.
111   /// \param theOperation an operation
112   /// \return the boolean result
113   bool isNestedSketchOperation(ModuleBase_Operation* theOperation) const;
114
115   /// Returns true if the feature kind belongs to list of granted features of Sketch
116   /// operation. An operation of a sketch should be started before.
117   /// \param theOperation an operation
118   /// \return the boolean result
119   bool isNestedSketchFeature(const QString& theFeatureKind) const;
120
121   /// Returns true if the operation is a create and nested sketch operationn
122   /// \param theOperation a checked operation
123   /// \param theSketch a sketch feature
124   //// \return boolean value
125   bool isNestedCreateOperation(ModuleBase_Operation* theOperation,
126                                       const CompositeFeaturePtr& /*theSketch*/) const;
127
128   /// Returns true if the operation is an edit nested feature one
129   /// \param theOperation a checked operation
130   //// \return boolean value
131   bool isNestedEditOperation(ModuleBase_Operation* theOperation,
132                                     const CompositeFeaturePtr& /*theSketch*/) const;
133
134   /// Returns whether the current operation is a sketch entity - line, point, arc or circle
135   /// \param theId is an id of object
136   /// \return a boolean value
137   static bool isEntity(const std::string& theId);
138
139   /// Returns whether the feature has external attribute filled with 'true' value
140   /// \param theFeature a feature object
141   /// \return a boolean value
142   static bool isExternalFeature(const FeaturePtr& theFeature);
143
144   /// Returns whether the current operation is a sketch distance - lenght, distance or radius
145   /// \param theOperation the operation
146   /// \return a boolean value
147   static bool isDistanceOperation(ModuleBase_Operation* theOperation);
148
149   /// Returns whether the feature kind is a sketch distance - lenght, distance or radius
150   /// \param theKind the feature kind
151   /// \return a boolean value
152   static bool isDistanceKind(std::string& theKind);
153
154   /// Returns true if a mouse cursor is over viewer window
155   bool isMouseOverWindow() { return myIsMouseOverWindow; }
156
157   /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
158   CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
159
160   /// Starts sketch operation
161   void startSketch(ModuleBase_Operation* );
162
163   /// Stops sketch operation
164   void stopSketch(ModuleBase_Operation* );
165
166   /// Starts sketch operation, connects to the opeation property panel
167   /// \param theOperation a committed operation
168   void startNestedSketch(ModuleBase_Operation* theOperation);
169
170   /// Stop sketch operation, disconnects from the opeation property panel
171   /// \param theOperation a stopped operation
172   void stopNestedSketch(ModuleBase_Operation* theOperation);
173
174   /// Visualizes the operation feature if it is a creation nested feature operation
175   /// \param theOperation a committed operation
176   void commitNestedSketch(ModuleBase_Operation* theOperation);
177
178   /// Append the sketch plane filter into the current viewer
179   /// \param toActivate state whether the filter should be activated/deactivated
180   void activatePlaneFilter(const bool& toActivate);
181
182   /// Commit the operation if it is possible. If the operation is dimention constraint,
183   /// it gives widget editor to input dimention value
184   /// \return true if the operation is stopped after activation
185   bool operationActivatedByPreselection();
186
187   /// Returns True if there are available Undos and the sketch manager allows undo
188   /// \return the boolean result
189   bool canUndo() const;
190
191   //! Returns True if there are available Redos and the sketch manager allows redo
192   /// \return the boolean result
193   bool canRedo() const;
194
195   /// Returns False only if the sketch creating feature can not be visualized.
196   /// \return a boolean value
197   //bool canCommitOperation() const;
198
199   /// Returns whether the object can be erased at the bounds of the active operation.
200   /// Sketch sub-entities can not be erased during the sketch operation
201   /// \param theObject a model object
202   bool canEraseObject(const ObjectPtr& theObject) const;
203
204   /// Returns whether the object can be displayed at the bounds of the active operation.
205   /// Display only current operation results for usual operation and ask the sketcher manager
206   /// if it is a sketch operation
207   /// \param theObject a model object
208   bool canDisplayObject(const ObjectPtr& theObject) const;
209
210   /// Returns whether the constraint object can be displayed. It depends on the sketch check
211   /// box states
212   /// \param theObject a model object
213   /// \param theState the constraint visible state state to be checked
214   /// \param isProcessed an output parameter if it is processed
215   /// \return result value
216   bool canDisplayConstraint(const FeaturePtr& theObject,
217                             const PartSet_Tools::ConstraintVisibleState& theState,
218                             bool& isProcessed) const;
219
220   /// Check the given objects either there are some results of the current sketch. If so,
221   /// it suggests to delete them as there are no functionality to show back hidden sketch objects
222   /// \param theObjects a list of hidden objects
223   //virtual void processHiddenObject(const std::list<ObjectPtr>& theObjects);
224
225   /// Returns true if the mouse is over viewer or property panel value is changed
226   /// \return boolean result
227   bool canDisplayCurrentCreatedFeature() const;
228
229   /// Returns true if the current operation is nested creation or internal reentrant edit
230   /// \param theOperation an operation
231   bool canChangeCursor(ModuleBase_Operation* theOperation) const;
232
233   /// Returns state of constraints showing flag
234   const QMap<PartSet_Tools::ConstraintVisibleState, bool>& showConstraintStates();
235
236   /// Returns true if the object is a current sketch sub feature of a result of the feature
237   /// \param theObject an object
238   /// \return boolean value
239   bool isObjectOfSketch(const ObjectPtr& theObject) const;
240
241   /// Enumeration for selection mode used
242   enum SelectionType {
243     ST_HighlightType, /// Only highlighted objects
244     ST_SelectType, /// Only selected objects
245     ST_SelectAndHighlightType /// Both, highlighted and selected objects
246   };
247
248   /// Saves the current selection in the viewer into an internal container
249   /// It obtains the selected attributes.
250   /// The highlighted objects can be processes as the selected ones
251   /// \param theHighlightedOnly a boolean flag
252   /// \param theCurrentSelection a container filled by the current selection
253   void storeSelection(const SelectionType theType, FeatureToSelectionMap& theCurrentSelection);
254
255   /// Restores previously saved selection state
256   /// \param theCurrentSelection a container filled by the current selection
257   void restoreSelection(FeatureToSelectionMap& theCurrentSelection);
258
259   /// Return error state of the sketch feature, true if the error has happened
260   /// \return boolean value
261   bool sketchSolverError();
262
263   //! Returns the feature error if the current state of the feature in the sketch is not correct
264   //! If the feature is correct, it returns an empty value
265   //! Incorrect states: the feature is sketch, the solver error value
266   //! The feature value is reset, this is the flag of sketch mgr
267   //! \return string value
268   QString getFeatureError(const FeaturePtr& theFeature);
269
270   /// It nullify internal flags concerned to clicked mouse event
271   void clearClickedFlags();
272
273   /// Returns list of strings which contains id's of sketch replication operations
274   static const QStringList& replicationsIdList();
275
276   /// Returns list of strings which contains id's of constraints operations
277   static const QStringList& constraintsIdList();
278
279   /// Returns a list of modes, where the AIS objects should be activated
280   /// \param theModes a list of modes
281   static void sketchSelectionModes(QIntList& theModes);
282
283   /// Create specific for the module presentation
284   /// \param theResult an object for presentation
285   /// \return created presentation or NULL(default value)
286   virtual Handle(AIS_InteractiveObject) createPresentation(const ResultPtr& theResult);
287
288   /// Connects or disconnects to the value changed signal of the property panel widgets
289   /// \param theWidget a property contol widget
290   /// \param isToConnect a boolean value whether connect or disconnect
291   void connectToPropertyPanel(ModuleBase_ModelWidget* theWidget, const bool isToConnect);
292
293   /// Visualize the operation feature if the previous state is modified value in property panel
294   /// \param thePreviousState the previous widget value state
295   void widgetStateChanged(int thePreviousState);
296
297   /// If the current operation is a dimention one, the style of dimension visualization is send for
298   /// the current object
299   /// \param theObject an object to be customized
300   void customizePresentation(const ObjectPtr& theObject);
301
302   /// Update sketch presentations according to the the state
303   /// \param theType a type of sketch visualization style
304   /// \param theState a boolean state
305   void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
306                                 bool theState);
307
308 public slots:
309   /// Process sketch plane selected event
310   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
311
312 private slots:
313   /// Toggle show constraints
314   void onShowConstraintsToggle(int theType, bool theState);
315   /// Process the enter mouse to the view port. If the current operation is a create of
316   /// a nested sketch feature, it updates internal flags to display the feature on mouse move
317   void onEnterViewPort();
318   /// Process the leave mouse of the view port. If the current operation is a create of
319   /// a nested sketch feature, it hides the feature in the viewer
320   void onLeaveViewPort();
321   /// Listens to the value changed signal and display the current operation feature
322   //void onBeforeValuesChangedInPropertyPanel();
323   /// Listens to the signal about the modification of the values
324   /// have been done in the property panel
325   //void onAfterValuesChangedInPropertyPanel();
326
327   void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
328   void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
329   void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
330   void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
331   void onApplicationStarted();
332   //void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
333
334   void onBeforeContextMenu();
335   void onAfterContextMenu();
336
337 private:
338   /// Launches the operation from current highlighting
339   void launchEditing();
340
341   /// Converts mouse position to 2d coordinates.
342   /// Member myCurrentSketch has to be correctly defined
343   void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
344                   Point& thePoint);
345
346   /// Show distance value editor if it is a distance operation and all attribute references
347   /// are filled by preseletion
348   /// \return true if the value is accepted
349   static bool setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
350                                              ModuleBase_IWorkshop* theWorkshop,
351                                              bool& theCanCommitOperation);
352
353   /// Applyes the current selection to the object in the workshop viewer
354   /// It includes the selection in all modes of activation, even local context - vertexes, edges
355   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
356   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
357   /// the feature and if it is in the container of selected attributes, the owner is put in the
358   /// out container. If the owner is edge and the current result is in the container of selected
359   /// results, the owner is put in the out container.
360   /// \param theFeature a feature or result object
361   /// \param theSketch a current sketch feature
362   /// \param theWorkshop a workshop to have an access to AIS context and displayer
363   /// \param theSelection a container of the selection, it has results and attributres for a feature
364   /// \param theOwnersToSelect an out container of found owners
365   static void getSelectionOwners(const FeaturePtr& theFeature,
366                                   const FeaturePtr& theSketch,
367                                   ModuleBase_IWorkshop* theWorkshop,
368                                   const FeatureToSelectionMap& theSelection,
369                                   SelectMgr_IndexedMapOfOwner& theOwnersToSelect);
370
371   /// Returns true if the created feature is visible
372   /// \param
373   bool isVisibleCreatedFeature() const;
374
375   /// Returns a current operation
376   /// \return an operation
377   ModuleBase_Operation* getCurrentOperation() const;
378
379   /// Get the active widget in the property panel
380   ModuleBase_ModelWidget* getActiveWidget() const;
381
382   /// Erase or display the feature of the current operation. If the mouse over the active view or
383   /// a current value is changed by property panel, the feature is displayed otherwise it is hidden
384   /// \param theOperation an operation which feature is to be displayed,
385   ///                     it is nested create operation
386   /// \param isToDisplay a flag about the display or erase the feature
387   void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
388                         const bool isToDisplay, const bool isFlushRedisplay = true);
389
390 private:
391   /// Updates selection priority of the presentation
392   /// \param theObject object to find a presentation which will be corrected
393   /// \param theFeature a feature of the presentation
394   void updateSelectionPriority(ObjectPtr theObject, FeaturePtr theFeature);
395   /// Returns current workshop
396   XGUI_Workshop* workshop() const;
397   /// Returns operation manager
398   XGUI_OperationMgr* operationMgr() const;
399
400 private:
401   PartSet_Module* myModule;
402
403   bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
404   bool myIsEditLaunching;
405   bool myIsDragging;
406   bool myDragDone;
407   bool myIsMouseOverWindow; /// the state that the mouse over the view
408   /// the state whether the over view state is processed by mouseMove method
409   bool myIsMouseOverViewProcessed;
410   bool myIsPopupMenuActive; /// the state of the popup menu is shown
411   Point myCurrentPoint;
412   //Point myClickedPoint;
413
414   CompositeFeaturePtr myCurrentSketch;
415
416   Handle(PartSet_CirclePointFilter) myCirclePointFilter;
417   Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
418   FeatureToSelectionMap myCurrentSelection;
419   bool myPreviousUpdateViewerEnabled;
420
421   QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
422
423   PartSet_ExternalPointsMgr* myExternalPointsMgr;
424 };
425
426
427 #endif