Salome HOME
#2027 Sketcher Trim Feature: 1. preview/selected attributes in trim; 2. avoid includi...
[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
53   /// validating, next, the attribute's validating. It trying on the give selection to current
54   /// attribute by setting the value inside and calling validators. After this, the previous
55   /// attribute value is 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   /// Activate or deactivate selection and selection filters
61   /// \return true if the selection filter of the widget is activated in viewer context
62   virtual bool activateSelectionAndFilters(bool toActivate);
63
64   /// Set sketcher
65   /// \param theSketch a sketcher object
66   void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
67
68   /// Retrurns installed sketcher
69   CompositeFeaturePtr sketch() const { return mySketch; }
70
71   /// The methiod called when widget is deactivated
72   virtual void deactivate();
73
74   /// Processing the mouse move event in the viewer
75   /// \param theWindow a view window
76   /// \param theEvent a mouse event
77   virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
78
79   /// Processing the mouse release event in the viewer
80   /// \param theWindow a view window
81   /// \param theEvent a mouse event
82   virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
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                                ModuleBase_IViewWindow* theWnd,
96                                QMouseEvent* theEvent);
97 protected:
98   /// Return the attribute values wrapped in a list of viewer presentations
99   /// \return a list of viewer presentations, which contains an attribute result and
100   /// a shape. If the attribute do not uses the shape, it is empty
101   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
102
103 protected:
104   /// The methiod called when widget is activated
105   virtual void activateCustom();
106
107 protected:
108   bool fillFeature(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelectedPrs,
109                    ModuleBase_IViewWindow* theWnd,
110                    QMouseEvent* theEvent);
111
112   /// Pointer to a sketch
113   CompositeFeaturePtr mySketch;
114   Quantity_Color myHighlightColor;
115   Quantity_Color mySelectionColor;
116 };
117
118 #endif