Salome HOME
cfb6329db434cfa06b72ef1f975dc0d7104fb75d
[modules/shaper.git] / src / PartSet / PartSet_WidgetFeaturePointSelector.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetFeaturePointSelector.h
4 // Created:     28 Feb 2017
5 // Author:      Natalia ERMOLAEVA
6
7
8 #ifndef PartSet_WidgetFeaturePointSelector_H
9 #define PartSet_WidgetFeaturePointSelector_H
10
11 #include <ModelAPI_CompositeFeature.h>
12 #include <ModuleBase_WidgetShapeSelector.h>
13
14 #include "PartSet.h"
15 #include "PartSet_MouseProcessor.h"
16
17 #include <Quantity_Color.hxx>
18
19 #include <QObject>
20
21 class ModuleBase_IWorkshop;
22 class Config_WidgetAPI;
23 class ModuleBase_IViewWindow;
24 class ModuleBase_ViewerPrs;
25
26 class GeomAPI_Pnt;
27 class GeomDataAPI_Point2D;
28
29 class QWidget;
30 class QMouseEvent;
31
32 /**
33 * \ingroup Modules
34 * Customosation of PartSet_WidgetFeaturePointSelector in order to visualize sub-shape
35 * by mouse move over shape in the viewer. Split of the object is performed by
36 * coincident points to the object. Segment between nearest coincidence is highlighted
37 */
38 class PARTSET_EXPORT PartSet_WidgetFeaturePointSelector: public ModuleBase_WidgetShapeSelector,
39                                                          public PartSet_MouseProcessor
40 {
41 Q_OBJECT
42  public:
43   /// Constructor
44   /// \param theParent the parent object
45   /// \param theWorkshop instance of workshop interface
46   /// \param theData the widget configuation. The attribute of the model widget is obtained from
47   PartSet_WidgetFeaturePointSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
48                                  const Config_WidgetAPI* theData);
49
50   virtual ~PartSet_WidgetFeaturePointSelector();
51
52   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
53   /// next, the attribute's validating. It trying on the give selection to current attribute by
54   /// setting the value inside and calling validators. After this, the previous attribute value is
55   /// restored.The valid/invalid value is cashed.
56   /// \param theValue a selected presentation in the view
57   /// \return a boolean value
58   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
59
60   /// Set sketcher
61   /// \param theSketch a sketcher object
62   void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
63
64   /// Retrurns installed sketcher
65   CompositeFeaturePtr sketch() const { return mySketch; }
66
67   /// The methiod called when widget is deactivated
68   virtual void deactivate();
69
70   /// Processing the mouse move event in the viewer
71   /// \param theWindow a view window
72   /// \param theEvent a mouse event
73   virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
74
75   /// Processing the mouse release event in the viewer
76   /// \param theWindow a view window
77   /// \param theEvent a mouse event
78   virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
79
80   /// Returns values which should be highlighted when the whidget is active
81   /// \param theValues a list of presentations
82   //virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
83
84   /// Set the given wrapped value to the current widget
85   /// This value should be processed in the widget according to the needs
86   /// The method is called by the current operation to process the operation preselection.
87   /// It is redefined to fill attributes responsible for the sub selection
88   /// \param theValues the wrapped selection values
89   /// \param theToValidate a flag on validation of the values
90   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
91                             const bool theToValidate);
92
93   /// Fill preselection used in mouseReleased
94   //virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected);
95   virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
96                                ModuleBase_IViewWindow* theWnd,
97                                QMouseEvent* theEvent);
98 protected:
99   /// Return the attribute values wrapped in a list of viewer presentations
100   /// \return a list of viewer presentations, which contains an attribute result and
101   /// a shape. If the attribute do not uses the shape, it is empty
102   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
103
104 protected:
105   /// The methiod called when widget is activated
106   virtual void activateCustom();
107
108 protected:
109   bool fillFeature(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelectedPrs,
110                    ModuleBase_IViewWindow* theWnd,
111                    QMouseEvent* theEvent);
112
113   /// Pointer to a sketch
114   CompositeFeaturePtr mySketch;
115   Quantity_Color myHighlightColor;
116   Quantity_Color mySelectionColor;
117 };
118
119 #endif