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