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;
34 * A model widget implementation for a label which provides specific behaviour
35 * for sketcher starting and launching operations
37 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
43 /// \param theParent the parent object
44 /// \param theWorkshop a reference to workshop
45 /// \param theData the widget configuation. The attribute of the model widget is obtained from
46 /// \param toShowConstraints a current show constraints state
47 PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
48 const Config_WidgetAPI* theData,
49 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
51 virtual ~PartSet_WidgetSketchLabel();
53 /// Set the given wrapped value to the current widget
54 /// This value should be processed in the widget according to the needs
55 /// The method is called by the current operation to process the operation preselection.
56 /// It is redefined to do nothing if the plane of the sketch has been already set.
57 /// \param theValues the wrapped selection values
58 /// \param theToValidate a validation flag
59 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
60 const bool theToValidate);
62 /// Returns list of widget controls
63 /// \return a control list
64 virtual QList<QWidget*> getControls() const;
66 /// The methiod called when widget is deactivated
67 virtual void deactivate();
69 /// Returns sketcher plane
70 std::shared_ptr<GeomAPI_Pln> plane() const;
72 /// This control accepts focus
73 virtual bool focusTo();
74 virtual void setHighlighted(bool) { /*do nothing*/ };
75 virtual void enableFocusProcessing();
77 /// Returns True if the selected presentation can be used for plane definition
78 /// \param thePrs a presentation
79 static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
81 /// Set sketch plane from selected object
82 /// \param theFeature a feature of sketch
83 /// \param thePrs a presentation
84 static bool fillSketchPlaneBySelection(const FeaturePtr& theFeature,
85 const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
88 /// Signal on plane selection
89 void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
91 /// A show constraint toggled signal
92 /// \param theType a ConstraintVisibleState value
93 /// \param theState a state of the check box
94 void showConstraintToggled(int theType, bool theState);
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 stored
101 virtual void storeAttributeValue(const AttributePtr& theAttribute);
103 /// Creates a backup of the current values of the attribute
104 /// It should be realized in the specific widget because of different
105 /// parameters of the current attribute
106 /// \param theAttribute an attribute to be restored
107 /// \param theValid a boolean flag, if restore happens for valid parameters
108 virtual void restoreAttributeValue(const AttributePtr& theAttribute,
109 const bool theValid);
111 /// Fills the attribute with the value of the selected owner
112 /// \param thePrs a selected owner
113 virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
115 /// Saves the internal parameters to the given feature
116 /// \return True in success
117 virtual bool storeValueCustom()
122 virtual bool restoreValueCustom()
127 /// The methiod called when widget is activated
128 virtual void activateCustom();
130 /// Block the model flush of update and intialization of attribute
131 /// In additional to curstom realization it blocks initialization for all feature attributes
132 /// as the current attribute is selection but its modification leads to other attributes change
133 /// \param theAttribute an attribute
134 /// \param theToBlock flag whether the model is blocked or unblocked
135 /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
136 /// to be used to restore flush state when unblocked
137 /// \param isAttributeSetInitializedBlocked out value if model is blocked
138 /// in value if model is unblocked to be used to restore previous state when unblocked
139 virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
140 bool& isFlushesActived,
141 bool& isAttributeSetInitializedBlocked);
143 /// Set the given wrapped value to the current widget
144 /// This value should be processed in the widget according to the needs
145 /// The method is called by the current operation to process the operation preselection.
146 /// It is redefined to do nothing if the plane of the sketch has been already set.
147 /// \param theValues the wrapped selection values
148 /// \param theToValidate a validation flag
149 bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
150 const bool theToValidate);
152 /// Erase preview planes, disconnect widget, change the view projection
153 /// \param thePrs a selected presentation
154 void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
157 /// Activate or deactivate selection
158 void activateSelection(bool toActivate);
161 /// Slot on change selection
162 void onSelectionChanged();
164 /// A slot called on set sketch plane view
165 void onSetPlaneView();
167 /// Emits signal about check box state changed with information about ConstraintVisibleState
168 /// \param theOn a flag show constraints or not
169 void onShowConstraint(bool theOn);
172 /// Set sketch plane by shape
173 /// \param theShape a planar face
174 static std::shared_ptr<GeomAPI_Dir> setSketchPlane(const FeaturePtr& theFeature,
175 const TopoDS_Shape& theShape);
179 /// class to show/hide preview planes
180 PartSet_PreviewPlanes* myPreviewPlanes;
182 QCheckBox* myViewInverted;
184 QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
186 QWidget* mySizeOfViewWidget; ///< Size of view widget, visualized if preview planes are shown
187 QLineEdit* mySizeOfView; ///< Value of square of size of View
188 QStackedWidget* myStackWidget;