]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_SketcherMgr.h
Salome HOME
Update code documentation
[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 Module
35 * A class for management of sketch operations
36 */
37 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
38 {
39   Q_OBJECT
40   /// Struct to define gp point, with the state is the point is initialized
41   struct Point
42   {
43     /// Constructor
44     Point()
45     {
46       myIsInitialized = false;
47     }
48     /// Destructor
49     ~Point()
50     {
51     }
52
53     /// clear the initialized flag.
54     void clear()
55     {
56       myIsInitialized = false;
57     }
58     /// set the point and switch on the initialized flag
59     /// \param thePoint the point
60     void setValue(const double theX, const double theY)
61     {
62       myIsInitialized = true;
63       myCurX = theX;
64       myCurY = theY;
65     }
66
67     bool myIsInitialized;  /// the state whether the point is set
68     double myCurX, myCurY; /// the point coordinates
69   };
70 public:
71   /// Constructor
72   /// \param theModule a pointer to PartSet module
73   PartSet_SketcherMgr(PartSet_Module* theModule);
74
75   virtual ~PartSet_SketcherMgr();
76
77   /// Returns list of strings which contains id's of sketch operations
78   static QStringList sketchOperationIdList();
79
80   /// Launches the operation from current highlighting
81   void launchEditing();
82
83   /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
84   CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
85
86   /// Starts sketch operation
87   void startSketch(ModuleBase_Operation* );
88
89   /// Stops sketch operation
90   void stopSketch(ModuleBase_Operation* );
91
92 public slots:
93   /// Process sketch plane selected event
94   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
95
96
97 private slots:
98   void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
99   void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
100   void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
101   void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
102   void onApplicationStarted();
103   void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
104
105 private:
106   /// Returns whethe the current operation is a sketch distance - lenght, distance or radius
107   /// \param the operation
108   /// \return a boolean value
109   bool isDistanceOperation(ModuleBase_Operation* theOperation) const;
110
111   /// Converts mouse position to 2d coordinates. 
112   /// Member myCurrentSketch has to be correctly defined
113   void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
114                   Point& thePoint);
115
116   typedef QList<AttributePtr> AttributeList;
117   typedef QMap<FeaturePtr, AttributeList> FeatureToAttributesMap;
118   typedef std::map<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
119                                                                        FeatureToSelectionMap;
120   /// Obtains the current selection of the object in the workshop viewer by a map of feature to attributes
121   /// It calls the next method for each feature
122   /// \param theFeatureToAttributes a map of feature to attributes
123   /// \param theSketch a current sketch feature
124   /// \param theWorkshop a workshop to have an access to AIS context and displayer
125   /// \param theSelection a container for the selection, to save results and attributres for a feature
126   static void getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
127                                   const FeaturePtr& theSketch,
128                                   ModuleBase_IWorkshop* theWorkshop,
129                                   FeatureToSelectionMap& theSelection);
130
131   /// Obtains the current selection of the object in the workshop viewer 
132   /// It includes the selection in all modes of activation, even local context - vertices, edges
133   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
134   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
135   /// the feature, if the owner is edge, the current result is added to the container of results.
136   /// \param theFeature a feature or result object
137   /// \param theSketch a current sketch feature
138   /// \param theWorkshop a workshop to have an access to AIS context and displayer
139   /// \param theSelection a container for the selection, to save results and attributres for a feature
140   static void getCurrentSelection(const FeaturePtr& theFeature,
141                                   const FeaturePtr& theSketch,
142                                   ModuleBase_IWorkshop* theWorkshop,
143                                   FeatureToSelectionMap& theSelection);
144
145   /// Applyes the current selection to the object in the workshop viewer 
146   /// It includes the selection in all modes of activation, even local context - vertexes, edges
147   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
148   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
149   /// the feature and if it is in the container of selected attributes, the owner is put in the
150   /// out container. If the owner is edge and the current result is in the container of selected
151   /// results, the owner is put in the out container.
152   /// \param theFeature a feature or result object
153   /// \param theSketch a current sketch feature
154   /// \param theWorkshop a workshop to have an access to AIS context and displayer
155   /// \param theSelection a container of the selection, it has results and attributres for a feature
156   /// \param theOwnersToSelect an out container of found owners
157   static void getSelectionOwners(const FeaturePtr& theFeature,
158                                   const FeaturePtr& theSketch,
159                                   ModuleBase_IWorkshop* theWorkshop,
160                                   const FeatureToSelectionMap& theSelection,
161                                   SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
162
163 private:
164   PartSet_Module* myModule;
165
166   bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
167   bool myIsDragging;
168   bool myDragDone;
169   Point myCurrentPoint;
170   Point myClickedPoint;
171
172   CompositeFeaturePtr myCurrentSketch;
173
174   FeatureToAttributesMap myFeature2AttributeMap; /// a map of a feature to attributes
175
176   Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
177 };
178
179
180 #endif