]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetPoint2d.h
Salome HOME
#2027 Sketcher Trim feature; Reference attribute in Point2D control instead of immedi...
[modules/shaper.git] / src / PartSet / PartSet_WidgetPoint2d.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetPoint2d.h
4 // Created:     25 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef PartSet_WidgetPoint2D_H
8 #define PartSet_WidgetPoint2D_H
9
10 #include "PartSet.h"
11 #include "PartSet_MouseProcessor.h"
12
13 #include <ModelAPI_CompositeFeature.h>
14 #include <ModuleBase_ModelWidget.h>
15
16 #include <QObject>
17
18 #include <TopoDS_Shape.hxx>
19 #include <V3d_View.hxx>
20
21 class ModelAPI_Feature;
22 class ModelAPI_AttributeRefAttr;
23 class ModuleBase_IWorkshop;
24 class ModuleBase_ParamSpinBox;
25 class ModuleBase_IViewWindow;
26 class ModuleBase_LabelValue;
27 class GeomAPI_Pnt2d;
28 class ModuleBase_IWorkshop;
29
30 class QGroupBox;
31 class QMouseEvent;
32
33 /**\class PartSet_WidgetPoint2D
34  * \ingroup Modules
35  * \brief Implementation of model widget to provide widget to input point 2d
36  * In XML can be defined as folloung:
37  * \code
38  * <sketch-2dpoint_selector id="CircleCenter" title="Center" tooltip="Center coordinates"/>
39  * \endcode
40  */
41 class PARTSET_EXPORT PartSet_WidgetPoint2D : public ModuleBase_ModelWidget,
42                                              public PartSet_MouseProcessor
43 {
44 Q_OBJECT
45  public:
46   /// Constructor
47   /// \param theParent the parent object
48   /// \param theWorkshop a current workshop
49   /// \param theData the widget configuation. The attribute of the model widget is obtained from
50   PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
51                         const Config_WidgetAPI* theData);
52   /// Destructor
53   virtual ~PartSet_WidgetPoint2D();
54
55   /// Checks if the selection presentation is valid in widget
56   /// \param theValue a selected presentation in the view
57   /// \return a boolean value
58   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
59
60   /// Set the given wrapped value to the current widget
61   /// This value should be processed in the widget according to the needs
62   /// \param theValues the wrapped widget values
63   /// \param theToValidate a validation flag
64   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
65                             const bool theToValidate);
66
67   /// Select the internal content if it can be selected. It is empty in the default realization
68   virtual void selectContent();
69
70   /// Returns list of widget controls
71   /// \return a control list
72   virtual QList<QWidget*> getControls() const;
73
74   //bool initFromPrevious(ObjectPtr theObject);
75
76   /// The methiod called when widget is deactivated
77   virtual void deactivate();
78
79   /// \returns the sketch instance
80   CompositeFeaturePtr sketch() const { return mySketch; }
81
82   /// Set sketch instance
83   void setSketch(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
84
85   /// Fill the widget values by given point
86   /// \param theX the X coordinate
87   /// \param theY the Y coordinate
88   /// \returns True in case of success
89   bool setPoint(double theX, double theY);
90
91   /// Returns coordinate X currently defined in the control
92   double x() const;
93
94   /// Returns coordinate Y currently defined in the control
95   double y() const;
96
97   /// Returns true if the event is processed.
98   virtual bool processEnter();
99
100   /// Returns true if the attribute can be changed using the selected shapes in the viewer
101   /// and creating a coincidence constraint to them. This control use them.
102   virtual bool useSelectedShapes() const;
103
104   /// Processing the mouse move event in the viewer
105   /// \param theWindow a view window
106   /// \param theEvent a mouse event
107   virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
108
109   /// Processing the mouse release event in the viewer
110   /// \param theWindow a view window
111   /// \param theEvent a mouse event
112   virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
113
114   /// Fill preselection used in mouseReleased
115   //virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected);
116   virtual void setPreSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
117                                ModuleBase_IViewWindow* theWnd,
118                                QMouseEvent* theEvent);
119
120 signals:
121   /// Signal about selection of an existing vertex from an object
122   void vertexSelected();
123
124 protected:
125   /// Saves the internal parameters to the given feature
126   /// \return True in success
127   virtual bool storeValueCustom();
128
129   /// Restore value from attribute data to the widget's control
130   virtual bool restoreValueCustom();
131
132   /// Store current value in cashed value
133   void storeCurentValue();
134
135   /// Restore cashed value in the model attribute
136   /// \return boolean state if the restored feature shoud be hidden
137   bool restoreCurentValue();
138
139   /// Fills the widget with default values
140   /// \return true if the widget current value is reset
141   virtual bool resetCustom();
142
143   /// The methiod called when widget is activated
144   virtual void activateCustom();
145
146   //! Switch On/Off highlighting of the widget
147   virtual void setHighlighted(bool isHighlighted);
148
149   /// Returns true if the feature contains Point2D attribute with the same coordinates
150   /// The attribute of the widget is not processed.
151   /// \param theFeature a feature
152   /// \param theX the X coordinate
153   /// \param theY the Y coordinate
154   /// \return boolean result
155   bool isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY);
156
157 //private slots:
158   /// Process value changed event
159   //void onValuesChanged();
160
161   /// Compute the feature default value and fill the controls with it
162   /// or store the control value to the feature
163   /// The widget is not initialize the attribute value in order to avoid the
164   /// incorrect visualization in Sketch. E.g. by a line creation, the line should not
165   /// be visualized immediatelly when the end point widget is activated.
166   virtual void initializeValueByActivate();
167
168  private:
169    /// Returns point 2d from selected vertex
170    /// \param theView a view window
171    /// \param theShape a vertex shape
172    /// \param theX an output value of X coordinate
173    /// \param theY an output value of Y coordinate
174    bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape,
175                    double& theX, double& theY) const;
176
177    /// Creates constrains of the clicked point
178    /// \param theClickedX the horizontal coordnate of the point
179    /// \param theClickedY the vertical coordnate of the point
180    bool setConstraintTo(double theClickedX, double theClickedY);
181
182    /// Create a coincidence constraint between the attribute and the parameter object
183    /// \theObject a result object
184    /// \return true if succed
185    bool setConstraintWith(const ObjectPtr& theObject);
186
187    /// Returns if the feature is an orphan point, circle or an arc. Returns true if it
188    /// has no a coincident to other lines. It processes point, circle and arc features
189    /// In circle an arc features, only centers are processed, for other points, it returns
190    /// that the point is not an orphan.
191    /// \param theFeature a checked feature
192    /// \param theSketch a sketch
193    /// \param theX an X coordinate of the point
194    /// \param theY an Y coordinate of the point
195    /// \return boolean result
196    static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
197                              double theX, double theY);
198
199    /// Explode the given shape by vertices and found closed to the point vertes
200    /// \param theShape a shape to be exploded
201    /// \param thePoint a point
202    /// \return boolean value
203    static bool shapeContainsPoint(const std::shared_ptr<GeomAPI_Shape>& theShape,
204                                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
205                                   const CompositeFeaturePtr& theSketch);
206
207    std::shared_ptr<ModelAPI_AttributeRefAttr> attributeRefAttr() const;
208
209 protected:
210   ModuleBase_IWorkshop* myWorkshop; ///< workshop
211
212 private:
213   QGroupBox* myGroupBox;  ///< the parent group box for all intenal widgets
214   //ModuleBase_ParamSpinBox* myXSpin;  ///< the spin box for the X coordinate
215   //ModuleBase_ParamSpinBox* myYSpin;  ///< the spin box for the Y coordinate
216   ModuleBase_LabelValue* myXSpin; ///< the label for the X coordinate
217   ModuleBase_LabelValue* myYSpin; ///< the label for the Y coordinate
218
219   /// value used as selection in mouse release method
220   std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
221
222   /// it is important during restart operation
223   CompositeFeaturePtr mySketch;
224
225   std::string myRefAttribute; /// if not empty, coincidences are not set but attribute is filled
226   bool myValueIsCashed; /// boolean state if the value is cashed during value state change
227   bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
228   double myXValueInCash; /// the cashed X value during value state change
229   double myYValueInCash; /// the cashed Y value during value state change
230 };
231
232 #endif