Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 list of strings which contains id's of sketch operations
81   static QStringList sketchOperationIdList();
82
83   /// Launches the operation from current highlighting
84   void launchEditing();
85
86   /// Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
87   CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
88
89   /// Starts sketch operation
90   void startSketch(ModuleBase_Operation* );
91
92   /// Stops sketch operation
93   void stopSketch(ModuleBase_Operation* );
94
95 public slots:
96   /// Process sketch plane selected event
97   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
98
99
100 private slots:
101   void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
102   void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
103   void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
104   void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
105   void onApplicationStarted();
106   void onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget);
107
108 private:
109   /// Returns whethe the current operation is a sketch distance - lenght, distance or radius
110   /// \param the operation
111   /// \return a boolean value
112   bool isDistanceOperation(ModuleBase_Operation* theOperation) const;
113
114   /// Converts mouse position to 2d coordinates. 
115   /// Member myCurrentSketch has to be correctly defined
116   void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
117                   Point& thePoint);
118
119   typedef QList<AttributePtr> AttributeList;
120   typedef QMap<FeaturePtr, AttributeList> FeatureToAttributesMap;
121   typedef std::map<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
122                                                                        FeatureToSelectionMap;
123   /// Obtains the current selection of the object in the workshop viewer by a map of feature to attributes
124   /// It calls the next method for each feature
125   /// \param theFeatureToAttributes a map of feature to attributes
126   /// \param theSketch a current sketch feature
127   /// \param theWorkshop a workshop to have an access to AIS context and displayer
128   /// \param theSelection a container for the selection, to save results and attributres for a feature
129   static void getCurrentSelection(const FeatureToAttributesMap& theFeatureToAttributes,
130                                   const FeaturePtr& theSketch,
131                                   ModuleBase_IWorkshop* theWorkshop,
132                                   FeatureToSelectionMap& theSelection);
133
134   /// Obtains the current selection of the object in the workshop viewer 
135   /// It includes the selection in all modes of activation, even local context - vertices, edges
136   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
137   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
138   /// the feature, if the owner is edge, the current result is added to the container of results.
139   /// \param theFeature a feature or result object
140   /// \param theSketch a current sketch feature
141   /// \param theWorkshop a workshop to have an access to AIS context and displayer
142   /// \param theSelection a container for the selection, to save results and attributres for a feature
143   static void getCurrentSelection(const FeaturePtr& theFeature,
144                                   const FeaturePtr& theSketch,
145                                   ModuleBase_IWorkshop* theWorkshop,
146                                   FeatureToSelectionMap& theSelection);
147
148   /// Applyes the current selection to the object in the workshop viewer 
149   /// It includes the selection in all modes of activation, even local context - vertexes, edges
150   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
151   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
152   /// the feature and if it is in the container of selected attributes, the owner is put in the
153   /// out container. If the owner is edge and the current result is in the container of selected
154   /// results, the owner is put in the out container.
155   /// \param theFeature a feature or result object
156   /// \param theSketch a current sketch feature
157   /// \param theWorkshop a workshop to have an access to AIS context and displayer
158   /// \param theSelection a container of the selection, it has results and attributres for a feature
159   /// \param theOwnersToSelect an out container of found owners
160   static void getSelectionOwners(const FeaturePtr& theFeature,
161                                   const FeaturePtr& theSketch,
162                                   ModuleBase_IWorkshop* theWorkshop,
163                                   const FeatureToSelectionMap& theSelection,
164                                   SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
165
166 private:
167   PartSet_Module* myModule;
168
169   bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
170   bool myIsDragging;
171   bool myDragDone;
172   Point myCurrentPoint;
173   Point myClickedPoint;
174
175   CompositeFeaturePtr myCurrentSketch;
176
177   FeatureToAttributesMap myFeature2AttributeMap; /// a map of a feature to attributes
178
179   Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
180 };
181
182
183 #endif