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);
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()
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 theAttribute an attribute
128 /// \param theToBlock flag whether the model is blocked or unblocked
129 /// \param isFlushesActived out value if model is blocked, in value if model is unblocked
130 /// to be used to restore flush state when unblocked
131 /// \param isAttributeSetInitializedBlocked out value if model is blocked
132 /// in value if model is unblocked to be used to restore previous state when unblocked
133 /// \param isAttributeSendUpdatedBlocked out value if model signal is blocked
134 virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
135 bool& isFlushesActived,
136 bool& isAttributeSetInitializedBlocked,
137 bool& isAttributeSendUpdatedBlocked);
139 /// Set the given wrapped value to the current widget
140 /// This value should be processed in the widget according to the needs
141 /// The method is called by the current operation to process the operation preselection.
142 /// It is redefined to do nothing if the plane of the sketch has been already set.
143 /// \param theValues the wrapped selection values
144 /// \param theToValidate a validation flag
145 bool setSelectionInternal(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
146 const bool theToValidate);
148 /// Erase preview planes, disconnect widget, change the view projection
149 /// \param thePrs a selected presentation
150 void updateByPlaneSelected(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
152 /// Set sketch plane from selected object
153 /// \param theFeature a feature of sketch
154 /// \param thePrs a presentation
155 bool fillSketchPlaneBySelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
158 /// Activate or deactivate selection
159 void activateSelection(bool toActivate);
162 /// Slot on change selection
163 void onSelectionChanged();
165 /// A slot called on set sketch plane view
166 void onSetPlaneView();
168 /// Emits signal about check box state changed with information about ConstraintVisibleState
169 /// \param theOn a flag show constraints or not
170 void onShowConstraint(bool theOn);
173 /// Set sketch plane by shape
174 /// \param theShape a planar face
175 std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
178 /// \param thePlane a plane
179 std::shared_ptr<GeomAPI_Dir> setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane);
182 /// class to show/hide preview planes
183 PartSet_PreviewPlanes* myPreviewPlanes;
185 QCheckBox* myViewInverted;
187 QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
189 QWidget* mySizeOfViewWidget; ///< Size of view widget, visualized if preview planes are shown
190 QLineEdit* mySizeOfView; ///< Value of square of size of View
191 QStackedWidget* myStackWidget;