1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef PartSet_WidgetSketchLabel_H
22 #define PartSet_WidgetSketchLabel_H
26 #include "PartSet_Tools.h"
28 #include <ModuleBase_WidgetValidated.h>
29 #include <ModuleBase_ViewerFilters.h>
31 #include <GeomAPI_Dir.h>
33 #include <TopoDS_Shape.hxx>
37 class PartSet_PreviewPlanes;
40 class XGUI_OperationMgr;
48 * A model widget implementation for a label which provides specific behaviour
49 * for sketcher starting and launching operations
51 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
57 /// \param theParent the parent object
58 /// \param theWorkshop a reference to workshop
59 /// \param theData the widget configuation. The attribute of the model widget is obtained from
60 /// \param toShowConstraints a current show constraints state
61 PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
62 const Config_WidgetAPI* theData,
63 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
65 virtual ~PartSet_WidgetSketchLabel();
67 /// Set the given wrapped value to the current widget
68 /// This value should be processed in the widget according to the needs
69 /// The method is called by the current operation to process the operation preselection.
70 /// It is redefined to do nothing if the plane of the sketch has been already set.
71 /// \param theValues the wrapped selection values
72 /// \param theToValidate a validation flag
73 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
74 const bool theToValidate);
76 /// Returns list of widget controls
77 /// \return a control list
78 virtual QList<QWidget*> getControls() const;
80 /// The methiod called when widget is deactivated
81 virtual void deactivate();
83 /// Returns sketcher plane
84 std::shared_ptr<GeomAPI_Pln> plane() const;
86 /// This control accepts focus
87 virtual bool focusTo();
88 virtual void setHighlighted(bool) { /*do nothing*/ };
89 virtual void enableFocusProcessing();
91 /// Returns True if the selected presentation can be used for plane definition
92 /// \param thePrs a presentation
93 static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
96 /// Signal on plane selection
97 void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
99 /// A show constraint toggled signal
100 /// \param theType a ConstraintVisibleState value
101 /// \param theState a state of the check box
102 void showConstraintToggled(int theType, bool theState);
105 /// Creates a backup of the current values of the attribute
106 /// It should be realized in the specific widget because of different
107 /// parameters of the current attribute
108 /// \param theAttribute an attribute to be stored
109 virtual void storeAttributeValue(const AttributePtr& theAttribute);
111 /// Creates a backup of the current values of the attribute
112 /// It should be realized in the specific widget because of different
113 /// parameters of the current attribute
114 /// \param theAttribute an attribute to be restored
115 /// \param theValid a boolean flag, if restore happens for valid parameters
116 virtual void restoreAttributeValue(const AttributePtr& theAttribute,
117 const bool theValid);
119 /// Fills the attribute with the value of the selected owner
120 /// \param thePrs a selected owner
121 virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
123 /// Saves the internal parameters to the given feature
124 /// \return True in success
125 virtual bool storeValueCustom()
130 virtual bool restoreValueCustom()
135 /// The methiod called when widget is activated
136 virtual void activateCustom();
138 /// Block the model flush of update and intialization of attribute
139 /// In additional to curstom realization it blocks initialization for all feature attributes
140 /// as the current attribute is selection but its modification leads to other attributes change
141 /// \param theAttribute an attribute
142 /// \param theToBlock flag whether the model is blocked or unblocked
143 /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
144 /// to be used to restore flush state when unblocked
145 /// \param isAttributeSetInitializedBlocked out value if model is blocked
146 /// in value if model is unblocked to be used to restore previous state when unblocked
147 /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
148 virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
149 bool& isFlushesActived,
150 bool& isAttributeSetInitializedBlocked,
151 bool& isAttributeSendUpdatedBlocked);
153 /// Set the given wrapped value to the current widget
154 /// This value should be processed in the widget according to the needs
155 /// The method is called by the current operation to process the operation preselection.
156 /// It is redefined to do nothing if the plane of the sketch has been already set.
157 /// \param theValues the wrapped selection values
158 /// \param theToValidate a validation flag
159 bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
160 const bool theToValidate);
162 /// Erase preview planes, disconnect widget, change the view projection
163 /// \param thePrs a selected presentation
164 void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
166 /// Set sketch plane from selected object
167 /// \param theFeature a feature of sketch
168 /// \param thePrs a presentation
169 bool fillSketchPlaneBySelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
172 /// Activate or deactivate selection
173 void activateSelection(bool toActivate);
176 /// Slot on change selection
177 void onSelectionChanged();
179 /// A slot called on set sketch plane view
180 void onSetPlaneView();
182 /// Emits signal about check box state changed with information about ConstraintVisibleState
183 /// \param theOn a flag show constraints or not
184 void onShowConstraint(bool theOn);
187 /// Set sketch plane by shape
188 /// \param theShape a planar face
189 std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
192 /// \param thePlane a plane
193 std::shared_ptr<GeomAPI_Dir> setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane);
196 /// class to show/hide preview planes
197 PartSet_PreviewPlanes* myPreviewPlanes;
199 QCheckBox* myViewInverted;
201 QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
203 QWidget* mySizeOfViewWidget; ///< Size of view widget, visualized if preview planes are shown
204 QLineEdit* mySizeOfView; ///< Value of square of size of View
205 QStackedWidget* myStackWidget;