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;
37 /**\class PartSet_WidgetBSplinePoints
39 * \brief Implementation of model widget to provide widget to input a list of 2D poles
40 * of B-spline curve in association with weights
41 * In XML can be defined as following:
43 * <sketch-bspline_selector id="poles" weights="weights"/>
46 class PARTSET_EXPORT PartSet_WidgetBSplinePoints : public ModuleBase_ModelWidget,
47 public PartSet_MouseProcessor
52 /// \param theParent the parent object
53 /// \param theWorkshop a current workshop
54 /// \param theData the widget configuation. The attribute of the model widget is obtained from
55 PartSet_WidgetBSplinePoints(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
56 const Config_WidgetAPI* theData);
58 virtual ~PartSet_WidgetBSplinePoints();
60 /// Fills given container with selection modes if the widget has it
61 /// \param [out] theModuleSelectionModes module additional modes, -1 means all default modes
62 /// \param theModes [out] a container of modes
63 virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes);
65 /// Checks if the selection presentation is valid in widget
66 /// \param theValue a selected presentation in the view
67 /// \return a boolean value
68 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
70 /// Checks all attribute validators returns valid. It tries on the given selection
71 /// to current attribute by setting the value inside and calling validators. After this,
72 /// the previous attribute value is restored.The valid/invalid value is cashed.
73 /// \param theValue a selected presentation in the view
74 /// \param theAttribute the attribute
75 /// \return a boolean value
76 bool isValidSelectionForAttribute_(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue,
77 const std::shared_ptr<ModelAPI_Attribute>& theAttribute);
79 /// Fills the attribute with the value of the selected owner
80 /// \param thePrs a selected owner
81 bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
83 /// Returns list of widget controls
84 /// \return a control list
85 virtual QList<QWidget*> getControls() const;
87 /// The methiod called when widget is deactivated
88 virtual void deactivate();
90 /// \returns the sketch instance
91 std::shared_ptr<ModelAPI_CompositeFeature> sketch() const { return mySketch; }
93 /// Set sketch instance
94 void setSketch(std::shared_ptr<ModelAPI_CompositeFeature> theSketch) { mySketch = theSketch; }
96 /// Fill the widget values by given point
97 /// \param theX the X coordinate
98 /// \param theY the Y coordinate
99 /// \returns True in case of success
100 bool setPoint(double theX, double theY);
102 /// Returns true if the event is processed.
103 virtual bool processEscape();
105 /// Returns true if the attribute can be changed using the selected shapes in the viewer
106 /// and creating a coincidence constraint to them. This control use them.
107 virtual bool useSelectedShapes() const;
109 /// Processing the mouse move event in the viewer
110 /// \param theWindow a view window
111 /// \param theEvent a mouse event
112 virtual void mouseMoved(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
114 /// Processing the mouse release event in the viewer
115 /// \param theWindow a view window
116 /// \param theEvent a mouse event
117 virtual void mouseReleased(ModuleBase_IViewWindow* theWindow, QMouseEvent* theEvent);
120 /// Saves the internal parameters to the given feature
121 /// \return True in success
122 virtual bool storeValueCustom();
124 /// Restore value from attribute data to the widget's control
125 virtual bool restoreValueCustom();
127 /// Store current value in cashed value
128 void storeCurentValue();
130 /// Restore cashed value in the model attribute
131 /// \return boolean state if the restored feature shoud be hidden
132 bool restoreCurentValue();
134 /// Fills the widget with default values
135 /// \return true if the widget current value is reset
136 virtual bool resetCustom();
139 /// Create labels for the next B-spline point
140 void createNextPoint();
141 /// Remove labels for the last B-spline point
142 void removeLastPoint();
144 /// Save B-spline poles and weights to corresponding attributes
145 void storePolesAndWeights() const;
147 /// Returns attribute reference if the key is defined in XML definition of this control
148 /// \return found attribute or null
149 std::shared_ptr<ModelAPI_AttributeRefAttrList> attributeRefAttrList() const;
151 void fillRefAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
152 void fillRefAttribute(std::shared_ptr<GeomAPI_Pnt2d> theClickedPoint,
153 const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
154 void fillRefAttribute(const ObjectPtr& theObject);
156 ObjectPtr getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
159 ModuleBase_IWorkshop* myWorkshop; ///< workshop
163 QWidget* myGroupBox; ///< the parent group box for all intenal widgets
164 QScrollArea* myScrollArea;
165 std::vector<ModuleBase_LabelValue*> myXSpin; ///< the label for the X coordinate
166 std::vector<ModuleBase_LabelValue*> myYSpin; ///< the label for the Y coordinate
167 PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager
169 /// value used as selection in mouse release method
170 std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
172 /// it is important during restart operation
173 CompositeFeaturePtr mySketch;
175 std::string myRefAttribute; /// if not empty, coincidences are not set but attribute is filled
177 bool myValueIsCashed; /// boolean state if the value is cashed during value state change
178 bool myIsFeatureVisibleInCash; /// boolean value if the feature was visible when cash if filled
179 std::vector<double> myXValueInCash; /// the cashed X value during value state change
180 std::vector<double> myYValueInCash; /// the cashed Y value during value state change
181 std::vector<double> myWeightInCash; /// the cached Weight value during valude state change
183 std::string myWeightsAttr;
185 int myPointIndex; /// index of the changing point
187 bool myFinished; /// \c true if building the B-spline is finished (escape pressed)