Salome HOME
updated copyright message
[modules/shaper.git] / src / PartSet / PartSet_WidgetFeaturePointSelector.h
1 // Copyright (C) 2014-2023  CEA, EDF
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 #include <ModuleBase_ViewerPrs.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 class PartSet_ExternalObjectsMgr;
41
42 class GeomAPI_Pnt;
43 class GeomAPI_Pnt2d;
44 class GeomDataAPI_Point2D;
45
46 class QWidget;
47 class QMouseEvent;
48
49 /**
50 * \ingroup Modules
51 * Customosation of PartSet_WidgetFeaturePointSelector in order to visualize sub-shape
52 * by mouse move over shape in the viewer. Split of the object is performed by
53 * coincident points to the object. Segment between nearest coincidence is highlighted
54 */
55 class PARTSET_EXPORT PartSet_WidgetFeaturePointSelector: public ModuleBase_WidgetShapeSelector,
56                                                          public PartSet_MouseProcessor
57 {
58 Q_OBJECT
59  public:
60   /// Constructor
61   /// \param theParent the parent object
62   /// \param theWorkshop instance of workshop interface
63   /// \param theData the widget configuation. The attribute of the model widget is obtained from
64   PartSet_WidgetFeaturePointSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
65                                  const Config_WidgetAPI* theData);
66
67   virtual ~PartSet_WidgetFeaturePointSelector();
68
69   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget
70   /// validating, next, the attribute's validating. It trying on the give selection to current
71   /// attribute by setting the value inside and calling validators. After this, the previous
72   /// attribute value is restored.The valid/invalid value is cashed.
73   /// \param theValue a selected presentation in the view
74   /// \return a boolean value
75   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
76
77   /// Set sketcher
78   /// \param theSketch a sketcher object
79   void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
80
81   /// Retrurns installed sketcher
82   CompositeFeaturePtr sketch() const { return mySketch; }
83
84   /// The methiod called when widget is deactivated
85   virtual void deactivate();
86
87   /// Processing the mouse move event in the viewer
88   /// \param theWindow a view window
89   /// \param theEvent a mouse event
90   virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
91
92   /// Processing the mouse release event in the viewer
93   /// \param theWindow a view window
94   /// \param theEvent a mouse event
95   virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
96
97
98   /// Fills the attribute with the value of the selected owner
99   /// \param thePrs a selected owner
100   virtual bool setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs);
101
102   /// Fill preselection used in mouseReleased
103   virtual void setPreSelection(const ModuleBase_ViewerPrsPtr& thePreSelected,
104                                ModuleBase_IViewWindow* theWnd,
105                                QMouseEvent* theEvent);
106 protected:
107   /// Return the attribute values wrapped in a list of viewer presentations
108   /// \return a list of viewer presentations, which contains an attribute result and
109   /// a shape. If the attribute do not uses the shape, it is empty
110   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
111
112   /// The methiod called when widget is activated
113   virtual void activateCustom();
114
115   /// Return an object and geom shape by the viewer presentation
116   /// \param thePrs a selection
117   /// \param theObject an output object
118   /// \param theShape a shape of the selection
119   virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
120     ObjectPtr& theObject, GeomShapePtr& theShape);
121
122   /// Creates a backup of the current values of the attribute
123   /// It should be realized in the specific widget because of different
124   /// parameters of the current attribute
125   /// \param theAttribute an attribute
126   /// \param theValid a boolean flag, if restore happens for valid parameters
127   void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
128
129 protected:
130   bool fillFeature();
131
132   /// Pointer to a sketch
133   CompositeFeaturePtr mySketch;
134   Quantity_Color myHighlightColor;
135   Quantity_Color mySelectionColor;
136
137   std::string mySelectedObjectAttribute;
138   std::string mySelectedPointAttribute;
139   std::string myPreviewObjectAttribute;
140   std::string myPreviewPointAttribute;
141
142   bool myHasPreview;
143   std::shared_ptr<ModelAPI_Object> myPreviewObject;
144   std::shared_ptr<GeomAPI_Pnt2d>   myPreviewPoint;
145   PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager
146 };
147
148 #endif