1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetSketchLabel.h
4 // Created: 07 July 2014
5 // Author: Vitaly SMETANNIKOV
7 #ifndef PartSet_WidgetSketchLabel_H
8 #define PartSet_WidgetSketchLabel_H
12 #include "PartSet_Tools.h"
14 #include <ModuleBase_WidgetValidated.h>
15 #include <ModuleBase_ViewerFilters.h>
17 #include <GeomAPI_Dir.h>
19 #include <TopoDS_Shape.hxx>
23 class PartSet_PreviewPlanes;
26 class XGUI_OperationMgr;
33 * A model widget implementation for a label which provides specific behaviour
34 * for sketcher starting and launching operations
36 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
42 /// \param theParent the parent object
43 /// \param theWorkshop a reference to workshop
44 /// \param theData the widget configuation. The attribute of the model widget is obtained from
45 /// \param toShowConstraints a current show constraints state
46 PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
47 const Config_WidgetAPI* theData,
48 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
50 virtual ~PartSet_WidgetSketchLabel();
52 /// Set the given wrapped value to the current widget
53 /// This value should be processed in the widget according to the needs
54 /// The method is called by the current operation to process the operation preselection.
55 /// It is redefined to do nothing if the plane of the sketch has been already set.
56 /// \param theValues the wrapped selection values
57 /// \param theToValidate a validation flag
58 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
59 const bool theToValidate);
61 /// Returns list of widget controls
62 /// \return a control list
63 virtual QList<QWidget*> getControls() const;
65 /// The methiod called when widget is deactivated
66 virtual void deactivate();
68 /// Returns sketcher plane
69 std::shared_ptr<GeomAPI_Pln> plane() const;
71 /// This control accepts focus
72 virtual bool focusTo();
73 virtual void setHighlighted(bool) { /*do nothing*/ };
74 virtual void enableFocusProcessing();
76 static bool canFillSketch(const ModuleBase_ViewerPrs& thePrs);
78 static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature,
79 const ModuleBase_ViewerPrs& thePrs);
82 /// Signal on plane selection
83 void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
85 /// A show constraint toggled signal
86 /// \param theType a ConstraintVisibleState value
87 /// \param theState a state of the check box
88 void showConstraintToggled(int theType, bool theState);
91 /// Creates a backup of the current values of the attribute
92 /// It should be realized in the specific widget because of different
93 /// parameters of the current attribute
94 virtual void storeAttributeValue();
96 /// Creates a backup of the current values of the attribute
97 /// It should be realized in the specific widget because of different
98 /// parameters of the current attribute
99 /// \param theValid a boolean flag, if restore happens for valid parameters
100 virtual void restoreAttributeValue(const bool theValid);
102 /// Fills the attribute with the value of the selected owner
103 /// \param thePrs a selected owner
104 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
106 /// Saves the internal parameters to the given feature
107 /// \return True in success
108 virtual bool storeValueCustom() const
113 virtual bool restoreValueCustom()
118 /// The methiod called when widget is activated
119 virtual void activateCustom();
121 /// Block the model flush of update and intialization of attribute
122 /// In additional to curstom realization it blocks initialization for all feature attributes
123 /// as the current attribute is selection but its modification leads to other attributes change
124 /// \param theToBlock flag whether the model is blocked or unblocked
125 /// \param isActive out value if model is blocked, in value if model is unblocked
126 /// to be used to restore flush state when unblocked
127 /// \param isAttributeSetInitializedBlocked out value if model is blocked
128 /// in value if model is unblocked to be used to restore previous state when unblocked
129 virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
130 bool& isAttributeSetInitializedBlocked);
132 /// Set the given wrapped value to the current widget
133 /// This value should be processed in the widget according to the needs
134 /// The method is called by the current operation to process the operation preselection.
135 /// It is redefined to do nothing if the plane of the sketch has been already set.
136 /// \param theValues the wrapped selection values
137 /// \param theToValidate a validation flag
138 bool setSelectionInternal(const QList<ModuleBase_ViewerPrs>& theValues,
139 const bool theToValidate);
141 /// Erase preview planes, disconnect widget, change the view projection
142 /// \param thePrs a selected presentation
143 void updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs);
146 /// Activate or deactivate selection
147 void activateSelection(bool toActivate);
150 /// Slot on change selection
151 void onSelectionChanged();
153 /// A slot called on set sketch plane view
154 void onSetPlaneView();
156 /// Emits signal about check box state changed with information about ConstraintVisibleState
157 /// \param theOn a flag show constraints or not
158 void onShowConstraint(bool theOn);
161 /// Set sketch plane by shape
162 /// \param theShape a planar face
163 static std::shared_ptr<GeomAPI_Dir> setSketchPlane(const FeaturePtr& theFeature,
164 const TopoDS_Shape& theShape);
168 /// class to show/hide preview planes
169 PartSet_PreviewPlanes* myPreviewPlanes;
171 QCheckBox* myViewInverted;
173 QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
175 QStackedWidget* myStackWidget;