]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_SketcherMgr.h
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git 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 whethe the current operation is a sketch distance - lenght, distance or radius
91   /// \param the operation
92   /// \return a boolean value
93   static bool isDistanceOperation(ModuleBase_Operation* theOperation);
94
95   /// Launches the operation from current highlighting
96   void launchEditing();
97
98   /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
99   CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
100
101   /// Starts sketch operation
102   void startSketch(ModuleBase_Operation* );
103
104   /// Stops sketch operation
105   void stopSketch(ModuleBase_Operation* );
106
107   /// Starts sketch operation
108   void startNestedSketch(ModuleBase_Operation* );
109
110   /// Stops sketch operation
111   void stopNestedSketch(ModuleBase_Operation* );
112
113   /// Returns whether the object can be displayed at the bounds of the active operation.
114   /// Display only current operation results for usual operation and ask the sketcher manager
115   /// if it is a sketch operation
116   /// \param theObject a model object
117   bool canDisplayObject(const ObjectPtr& theObject) const;
118
119 public slots:
120   /// Process sketch plane selected event
121   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
122
123
124 private slots:
125   /// Process the signal about mouse moving into or out of the window
126   /// \param heOverWindow true, if the moving happens to window
127   void onMouseMoveOverWindow(bool theOverWindow);
128   void onValuesChangedInPropertyPanel();
129   void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
130   void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
131   void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
132   void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
133   void onApplicationStarted();
134   void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
135
136 private:
137   /// Returns list of strings which contains id's of sketch operations
138   static QStringList sketchOperationIdList();
139
140   /// Converts mouse position to 2d coordinates. 
141   /// Member myCurrentSketch has to be correctly defined
142   void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
143                   Point& thePoint);
144
145   typedef QList<AttributePtr> AttributeList;
146   typedef QMap<FeaturePtr, AttributeList> FeatureToAttributesMap;
147   typedef std::map<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
148                                                                        FeatureToSelectionMap;
149   /// Obtains the current selection of the object in the workshop viewer by a map of feature to attributes
150   /// It calls the next method for each feature
151   /// \param theFeatureToAttributes a map of feature to attributes
152   /// \param theSketch a current sketch feature
153   /// \param theWorkshop a workshop to have an access to AIS context and displayer
154   /// \param theSelection a container for the selection, to save results and attributres for a feature
155   static void getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
156                                   const FeaturePtr& theSketch,
157                                   ModuleBase_IWorkshop* theWorkshop,
158                                   FeatureToSelectionMap& theSelection);
159
160   /// Obtains the current selection of the object in the workshop viewer 
161   /// It includes the selection in all modes of activation, even local context - vertices, edges
162   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
163   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
164   /// the feature, if the owner is edge, the current result is added to the container of results.
165   /// \param theFeature a feature or result object
166   /// \param theSketch a current sketch feature
167   /// \param theWorkshop a workshop to have an access to AIS context and displayer
168   /// \param theSelection a container for the selection, to save results and attributres for a feature
169   static void getCurrentSelection(const FeaturePtr& theFeature,
170                                   const FeaturePtr& theSketch,
171                                   ModuleBase_IWorkshop* theWorkshop,
172                                   FeatureToSelectionMap& theSelection);
173
174   /// Applyes the current selection to the object in the workshop viewer 
175   /// It includes the selection in all modes of activation, even local context - vertexes, edges
176   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
177   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
178   /// the feature and if it is in the container of selected attributes, the owner is put in the
179   /// out container. If the owner is edge and the current result is in the container of selected
180   /// results, the owner is put in the out container.
181   /// \param theFeature a feature or result object
182   /// \param theSketch a current sketch feature
183   /// \param theWorkshop a workshop to have an access to AIS context and displayer
184   /// \param theSelection a container of the selection, it has results and attributres for a feature
185   /// \param theOwnersToSelect an out container of found owners
186   static void getSelectionOwners(const FeaturePtr& theFeature,
187                                   const FeaturePtr& theSketch,
188                                   ModuleBase_IWorkshop* theWorkshop,
189                                   const FeatureToSelectionMap& theSelection,
190                                   SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
191
192   /// Connects or disconnects to the value changed signal of the property panel widgets
193   /// \param isToConnect a boolean value whether connect or disconnect
194   void connectToPropertyPanel(const bool isToConnect);
195
196   void updateVisibilityOfCreatedFeature();
197
198 private:
199   PartSet_Module* myModule;
200
201   bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
202   bool myIsDragging;
203   bool myDragDone;
204   bool myIsMouseOverWindow; /// the state that mouse is over view
205   bool myIsPropertyPanelValueChanged; /// the state that value in the property panel is changed
206   Point myCurrentPoint;
207   Point myClickedPoint;
208
209   CompositeFeaturePtr myCurrentSketch;
210
211   FeatureToAttributesMap myFeature2AttributeMap; /// a map of a feature to attributes
212
213   Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
214 };
215
216
217 #endif