Salome HOME
Crossed cursor correction: it stayed in the application if the feature is aborted.
[modules/shaper.git] / src / PartSet / PartSet_WidgetSubShapeSelector.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetSubShapeSelector.h
4 // Created:     21 Jul 2016
5 // Author:      Natalia ERMOLAEVA
6
7
8 #ifndef PartSet_WidgetSubShapeSelector_H
9 #define PartSet_WidgetSubShapeSelector_H
10
11 #include "PartSet.h"
12 #include "PartSet_MouseProcessor.h"
13
14 #include <ModuleBase_WidgetShapeSelector.h>
15
16 #include <ModelAPI_CompositeFeature.h>
17
18 #include <QObject>
19
20 #include <set>
21 #include <map>
22
23 class ModuleBase_IWorkshop;
24 class Config_WidgetAPI;
25 class ModuleBase_IViewWindow;
26 class ModuleBase_ViewerPrs;
27
28 class GeomAPI_Pnt;
29 class GeomDataAPI_Point2D;
30
31 class QWidget;
32 class QMouseEvent;
33
34 /**
35 * \ingroup Modules
36 * Customosation of PartSet_WidgetSubShapeSelector in order to visualize sub-shape 
37 * by mouse move over shape in the viewer. Split of the object is performed by
38 * coincident points to the object. Segment between nearest coincidence is highlighted
39 */
40 class PARTSET_EXPORT PartSet_WidgetSubShapeSelector: public ModuleBase_WidgetShapeSelector,
41                                                      public PartSet_MouseProcessor
42 {
43 Q_OBJECT
44  public:
45   /// Constructor
46   /// \param theParent the parent object
47   /// \param theWorkshop instance of workshop interface
48   /// \param theData the widget configuation. The attribute of the model widget is obtained from
49   PartSet_WidgetSubShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
50                                  const Config_WidgetAPI* theData);
51
52   virtual ~PartSet_WidgetSubShapeSelector();
53
54   /// Set sketcher
55   /// \param theSketch a sketcher object
56   void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
57
58   /// Retrurns installed sketcher
59   CompositeFeaturePtr sketch() const { return mySketch; }
60
61   /// The methiod called when widget is deactivated
62   virtual void deactivate();
63
64   /// Processing the mouse move event in the viewer
65   /// \param theWindow a view window
66   /// \param theEvent a mouse event
67   virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
68
69   /// Returns values which should be highlighted when the whidget is active
70   /// \param theValues a list of presentations
71   virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
72
73   /// Set the given wrapped value to the current widget
74   /// This value should be processed in the widget according to the needs
75   /// The method is called by the current operation to process the operation preselection.
76   /// It is redefined to fill attributes responsible for the sub selection
77   /// \param theValues the wrapped selection values
78   /// \param theToValidate a flag on validation of the values
79   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
80                             const bool theToValidate);
81
82 protected:
83   /// Checks the widget validity. By default, it returns true.
84   /// \param thePrs a selected presentation in the view
85   /// \return a boolean value
86   //virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
87
88   /// Return an object and geom shape by the viewer presentation
89   /// \param thePrs a selection
90   /// \param theObject an output object
91   /// \param theShape a shape of the selection
92   //virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
93   //                              ObjectPtr& theObject,
94   //                              GeomShapePtr& theShape);
95   void fillObjectShapes(const ObjectPtr& theObject);
96
97   /// Return an object and geom shape by the viewer presentation
98   /// \param thePrs a selection
99   /// \param theObject an output object
100   /// \param theShape a shape of the selection
101   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
102                                 ObjectPtr& theObject,
103                                 GeomShapePtr& theShape);
104
105   /// Return the attribute values wrapped in a list of viewer presentations
106   /// \return a list of viewer presentations, which contains an attribute result and
107   /// a shape. If the attribute do not uses the shape, it is empty
108   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
109
110 protected:
111   /// The methiod called when widget is activated
112   virtual void activateCustom();
113
114 protected:
115   std::shared_ptr<ModuleBase_ViewerPrs> myCurrentSubShape;
116   std::map<ObjectPtr, std::set<GeomShapePtr> > myCashedShapes;
117
118   typedef std::map<std::shared_ptr<GeomDataAPI_Point2D>,
119                    std::shared_ptr<GeomAPI_Pnt> > PntToAttributesMap;
120   std::map<ObjectPtr, PntToAttributesMap> myCashedReferences;
121
122   /// Pointer to a sketch 
123   CompositeFeaturePtr mySketch;
124 };
125
126 #endif