]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_SketcherMgr.h
Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[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_Operation;
30 class QMouseEvent;
31
32 /**
33 * A class for management of sketch operations
34 */
35 class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
36 {
37   Q_OBJECT
38 public:
39   PartSet_SketcherMgr(PartSet_Module* theModule);
40
41   virtual ~PartSet_SketcherMgr();
42
43   static QStringList sketchOperationIdList();
44
45   /// Launches the operation from current highlighting
46   void launchEditing();
47
48   // Returns current Sketch feature/ Returns NULL if there is no launched sketch operation
49   CompositeFeaturePtr activeSketch() const { return myCurrentSketch; }
50
51   /// Starts sketch operation
52   void startSketch(ModuleBase_Operation* theOperation);
53
54   /// Stops sketch operation
55   void stopSketch(ModuleBase_Operation* theOperation);
56
57 public slots:
58   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
59
60
61 private slots:
62   void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
63   void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
64   void onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*);
65   void onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*);
66
67 private:
68    /// Converts mouse position to 2d coordinates. 
69    /// Member myCurrentSketch has to be correctly defined
70   void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, 
71                   double& theX, double& theY);
72
73
74   typedef std::map<FeaturePtr, std::pair<std::set<AttributePtr>, std::set<ResultPtr> > >
75                                                                        FeatureToSelectionMap;
76   /// Obtains the current selection of the object in the workshop viewer 
77   /// It includes the selection in all modes of activation, even local context - vertices, edges
78   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
79   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
80   /// the feature, if the owner is edge, the current result is added to the container of results.
81   /// \param theFeature a feature or result object
82   /// \param theSketch a current sketch feature
83   /// \param theWorkshop a workshop to have an access to AIS context and displayer
84   /// \param theSelection a container for the selection, to save results and attributres for a feature
85   static void getCurrentSelection(const FeaturePtr& theFeature,
86                                   const FeaturePtr& theSketch,
87                                   ModuleBase_IWorkshop* theWorkshop,
88                                   FeatureToSelectionMap& theSelection);
89
90   /// Applyes the current selection to the object in the workshop viewer 
91   /// It includes the selection in all modes of activation, even local context - vertexes, edges
92   /// It gets all results of the feature, find an AIS object in the viewer and takes all BRep
93   /// selection owners. If the owner is vertex, the corresponded attribute is seached in
94   /// the feature and if it is in the container of selected attributes, the owner is put in the
95   /// out container. If the owner is edge and the current result is in the container of selected
96   /// results, the owner is put in the out container.
97   /// \param theFeature a feature or result object
98   /// \param theSketch a current sketch feature
99   /// \param theWorkshop a workshop to have an access to AIS context and displayer
100   /// \param theSelection a container of the selection, it has results and attributres for a feature
101   /// \param theOwnersToSelect an out container of found owners
102   static void getSelectionOwners(const FeaturePtr& theFeature,
103                                   const FeaturePtr& theSketch,
104                                   ModuleBase_IWorkshop* theWorkshop,
105                                   const FeatureToSelectionMap& theSelection,
106                                   SelectMgr_IndexedMapOfOwner& anOwnersToSelect);
107
108 private:
109   PartSet_Module* myModule;
110
111   bool myIsDragging;
112   bool myDragDone;
113   double myCurX, myCurY;
114
115   CompositeFeaturePtr myCurrentSketch;
116
117   typedef QList<AttributePtr> AttributeList;
118   typedef QMap<FeaturePtr, AttributeList> FeatureToAttributesMap;
119   FeatureToAttributesMap myFeature2AttributeMap; /// a map of a feature to attributes
120
121   Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
122 };
123
124
125 #endif