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