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<std::shared_ptr<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 std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
78 static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature,
79 const std::shared_ptr<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 /// \param theAttribute an attribute to be stored
95 virtual void storeAttributeValue(const AttributePtr& theAttribute);
97 /// Creates a backup of the current values of the attribute
98 /// It should be realized in the specific widget because of different
99 /// parameters of the current attribute
100 /// \param theAttribute an attribute to be restored
101 /// \param theValid a boolean flag, if restore happens for valid parameters
102 virtual void restoreAttributeValue(const AttributePtr& theAttribute,
103 const bool theValid);
105 /// Fills the attribute with the value of the selected owner
106 /// \param thePrs a selected owner
107 virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
109 /// Saves the internal parameters to the given feature
110 /// \return True in success
111 virtual bool storeValueCustom() const
116 virtual bool restoreValueCustom()
121 /// The methiod called when widget is activated
122 virtual void activateCustom();
124 /// Block the model flush of update and intialization of attribute
125 /// In additional to curstom realization it blocks initialization for all feature attributes
126 /// as the current attribute is selection but its modification leads to other attributes change
127 /// \param theToBlock flag whether the model is blocked or unblocked
128 /// \param isActive out value if model is blocked, in value if model is unblocked
129 /// to be used to restore flush state when unblocked
130 /// \param isAttributeSetInitializedBlocked out value if model is blocked
131 /// in value if model is unblocked to be used to restore previous state when unblocked
132 virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
133 bool& isFlushesActived,
134 bool& isAttributeSetInitializedBlocked);
136 /// Set the given wrapped value to the current widget
137 /// This value should be processed in the widget according to the needs
138 /// The method is called by the current operation to process the operation preselection.
139 /// It is redefined to do nothing if the plane of the sketch has been already set.
140 /// \param theValues the wrapped selection values
141 /// \param theToValidate a validation flag
142 bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
143 const bool theToValidate);
145 /// Erase preview planes, disconnect widget, change the view projection
146 /// \param thePrs a selected presentation
147 void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
150 /// Activate or deactivate selection
151 void activateSelection(bool toActivate);
154 /// Slot on change selection
155 void onSelectionChanged();
157 /// A slot called on set sketch plane view
158 void onSetPlaneView();
160 /// Emits signal about check box state changed with information about ConstraintVisibleState
161 /// \param theOn a flag show constraints or not
162 void onShowConstraint(bool theOn);
165 /// Set sketch plane by shape
166 /// \param theShape a planar face
167 static std::shared_ptr<GeomAPI_Dir> setSketchPlane(const FeaturePtr& theFeature,
168 const TopoDS_Shape& theShape);
172 /// class to show/hide preview planes
173 PartSet_PreviewPlanes* myPreviewPlanes;
175 QCheckBox* myViewInverted;
177 QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
179 QStackedWidget* myStackWidget;