1 // Copyright (C) 2019-2020 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef PartSet_WidgetBSplinePoints_H
21 #define PartSet_WidgetBSplinePoints_H
24 #include "PartSet_MouseProcessor.h"
26 #include <ModuleBase_ModelWidget.h>
31 class ModelAPI_CompositeFeature;
32 class ModuleBase_LabelValue;
33 class PartSet_ExternalObjectsMgr;
36 /**\class PartSet_WidgetBSplinePoints
38 * \brief Implementation of model widget to provide widget to input a list of 2D poles
39 * of B-spline curve in association with weights
40 * In XML can be defined as following:
42 * <sketch-bspline_selector id="poles" weights="weights"/>
45 class PARTSET_EXPORT PartSet_WidgetBSplinePoints : public ModuleBase_ModelWidget,
46 public PartSet_MouseProcessor
51 /// \param theParent the parent object
52 /// \param theWorkshop a current workshop
53 /// \param theData the widget configuation. The attribute of the model widget is obtained from
54 PartSet_WidgetBSplinePoints(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
55 const Config_WidgetAPI* theData);
57 virtual ~PartSet_WidgetBSplinePoints();
59 /// Fills given container with selection modes if the widget has it
60 /// \param [out] theModuleSelectionModes module additional modes, -1 means all default modes
61 /// \param theModes [out] a container of modes
62 virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes);
64 /// Checks if the selection presentation is valid in widget
65 /// \param theValue a selected presentation in the view
66 /// \return a boolean value
67 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
69 /// Checks all attribute validators returns valid. It tries on the given selection
70 /// to current attribute by setting the value inside and calling validators. After this,
71 /// the previous attribute value is restored.The valid/invalid value is cashed.
72 /// \param theValue a selected presentation in the view
73 /// \param theAttribute the attribute
74 /// \return a boolean value
75 bool isValidSelectionForAttribute_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
76 const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
78 /// Fills the attribute with the value of the selected owner
79 /// \param thePrs a selected owner
80 bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
82 /// Returns list of widget controls
83 /// \return a control list
84 virtual QList<QWidget*> getControls() const;
86 /// The methiod called when widget is deactivated
87 virtual void deactivate();
89 /// \returns the sketch instance
90 std::shared_ptr<ModelAPI_CompositeFeature> sketch() const { return mySketch; }
92 /// Set sketch instance
93 void setSketch(std::shared_ptr<ModelAPI_CompositeFeature> theSketch) { mySketch = theSketch; }
95 /// Fill the widget values by given point
96 /// \param theX the X coordinate
97 /// \param theY the Y coordinate
98 /// \returns True in case of success
99 bool setPoint(double theX, double theY);
101 /// Returns true if the event is processed.
102 virtual bool processEscape();
104 /// Returns true if the attribute can be changed using the selected shapes in the viewer
105 /// and creating a coincidence constraint to them. This control use them.
106 virtual bool useSelectedShapes() const;
108 /// Processing the mouse move event in the viewer
109 /// \param theWindow a view window
110 /// \param theEvent a mouse event
111 virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
113 /// Processing the mouse release event in the viewer
114 /// \param theWindow a view window
115 /// \param theEvent a mouse event
116 virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
119 /// Saves the internal parameters to the given feature
120 /// \return True in success
121 virtual bool storeValueCustom();
123 /// Restore value from attribute data to the widget's control
124 virtual bool restoreValueCustom();
126 /// Store current value in cashed value
127 void storeCurentValue();
129 /// Restore cashed value in the model attribute
130 /// \return boolean state if the restored feature shoud be hidden
131 bool restoreCurentValue();
133 /// Fills the widget with default values
134 /// \return true if the widget current value is reset
135 virtual bool resetCustom();
138 /// Create labels for the next B-spline point
139 void createNextPoint();
140 /// Remove labels for the last B-spline point
141 void removeLastPoint();
143 /// Save B-spline poles and weights to corresponding attributes
144 void storePolesAndWeights() const;
146 /// Returns attribute reference if the key is defined in XML definition of this control
147 /// \return found attribute or null
148 std::shared_ptr<ModelAPI_AttributeRefAttrList> attributeRefAttrList() const;
150 void fillRefAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
151 void fillRefAttribute(std::shared_ptr<GeomAPI_Pnt2d> theClickedPoint,
152 const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
153 void fillRefAttribute(const ObjectPtr& theObject);
155 ObjectPtr getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
158 ModuleBase_IWorkshop* myWorkshop; ///< workshop
161 QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets
162 std::vector<ModuleBase_LabelValue*> myXSpin; ///< the label for the X coordinate
163 std::vector<ModuleBase_LabelValue*> myYSpin; ///< the label for the Y coordinate
164 PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager
166 /// value used as selection in mouse release method
167 std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
169 /// it is important during restart operation
170 CompositeFeaturePtr mySketch;
172 std::string myRefAttribute; /// if not empty, coincidences are not set but attribute is filled
174 bool myValueIsCashed; /// boolean state if the value is cashed during value state change
175 bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
176 std::vector<double> myXValueInCash; /// the cashed X value during value state change
177 std::vector<double> myYValueInCash; /// the cashed Y value during value state change
178 std::vector<double> myWeightInCash; /// the cached Weight value during valude state change
180 std::string myWeightsAttr;
182 int myPointIndex; /// index of the changing point
184 bool myFinished; /// \c true if building the B-spline is finished (escape pressed)