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