Salome HOME
Sketch shape in plane selection filter should not be activated while PartSet_WidgetSh...
[modules/shaper.git] / src / PartSet / PartSet_WidgetFeaturePointSelector.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef PartSet_WidgetFeaturePointSelector_H
22 #define PartSet_WidgetFeaturePointSelector_H
23
24 #include <ModelAPI_CompositeFeature.h>
25 #include <ModuleBase_WidgetShapeSelector.h>
26
27 #include "PartSet.h"
28 #include "PartSet_MouseProcessor.h"
29
30 #include <Quantity_Color.hxx>
31
32 #include <QObject>
33
34 #include <string>
35
36 class ModuleBase_IWorkshop;
37 class Config_WidgetAPI;
38 class ModuleBase_IViewWindow;
39 class ModuleBase_ViewerPrs;
40
41 class GeomAPI_Pnt;
42 class GeomDataAPI_Point2D;
43
44 class QWidget;
45 class QMouseEvent;
46
47 /**
48 * \ingroup Modules
49 * Customosation of PartSet_WidgetFeaturePointSelector in order to visualize sub-shape
50 * by mouse move over shape in the viewer. Split of the object is performed by
51 * coincident points to the object. Segment between nearest coincidence is highlighted
52 */
53 class PARTSET_EXPORT PartSet_WidgetFeaturePointSelector: public ModuleBase_WidgetShapeSelector,
54                                                          public PartSet_MouseProcessor
55 {
56 Q_OBJECT
57  public:
58   /// Constructor
59   /// \param theParent the parent object
60   /// \param theWorkshop instance of workshop interface
61   /// \param theData the widget configuation. The attribute of the model widget is obtained from
62   PartSet_WidgetFeaturePointSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
63                                  const Config_WidgetAPI* theData);
64
65   virtual ~PartSet_WidgetFeaturePointSelector();
66
67   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget
68   /// validating, next, the attribute's validating. It trying on the give selection to current
69   /// attribute by setting the value inside and calling validators. After this, the previous
70   /// attribute value is restored.The valid/invalid value is cashed.
71   /// \param theValue a selected presentation in the view
72   /// \return a boolean value
73   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
74
75   /// Activate or deactivate selection and selection filters
76   /// \return true if the selection filter of the widget is activated in viewer context
77   virtual void updateSelectionModesAndFilters(bool toActivate);
78
79   /// Set sketcher
80   /// \param theSketch a sketcher object
81   void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
82
83   /// Retrurns installed sketcher
84   CompositeFeaturePtr sketch() const { return mySketch; }
85
86   /// The methiod called when widget is deactivated
87   virtual void deactivate();
88
89   /// Processing the mouse move event in the viewer
90   /// \param theWindow a view window
91   /// \param theEvent a mouse event
92   virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
93
94   /// Processing the mouse release event in the viewer
95   /// \param theWindow a view window
96   /// \param theEvent a mouse event
97   virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
98
99   /// Set the given wrapped value to the current widget
100   /// This value should be processed in the widget according to the needs
101   /// The method is called by the current operation to process the operation preselection.
102   /// It is redefined to fill attributes responsible for the sub selection
103   /// \param theValues the wrapped selection values
104   /// \param theToValidate a flag on validation of the values
105   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
106                             const bool theToValidate);
107
108   /// Fill preselection used in mouseReleased
109   virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
110                                ModuleBase_IViewWindow* theWnd,
111                                QMouseEvent* theEvent);
112 protected:
113   /// Return the attribute values wrapped in a list of viewer presentations
114   /// \return a list of viewer presentations, which contains an attribute result and
115   /// a shape. If the attribute do not uses the shape, it is empty
116   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
117
118 protected:
119   /// The methiod called when widget is activated
120   virtual void activateCustom();
121
122 protected:
123   bool fillFeature(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelectedPrs,
124                    ModuleBase_IViewWindow* theWnd,
125                    QMouseEvent* theEvent);
126
127   /// Pointer to a sketch
128   CompositeFeaturePtr mySketch;
129   Quantity_Color myHighlightColor;
130   Quantity_Color mySelectionColor;
131
132   std::string mySelectedObjectAttribute;
133   std::string mySelectedPointAttribute;
134   std::string myPreviewObjectAttribute;
135   std::string myPreviewPointAttribute;
136 };
137
138 #endif