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_Pnt.h>
18 #include <GeomAPI_Dir.h>
19 #include <GeomAPI_AISObject.h>
21 #include <TopoDS_Shape.hxx>
26 class XGUI_OperationMgr;
31 /// the plane edge width
32 #define SKETCH_WIDTH "4"
34 /// face of the square-face displayed for selection of general plane
35 #define PLANE_SIZE "200"
39 * A model widget implementation for a label which provides specific behaviour
40 * for sketcher starting and launching operations
42 class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
48 /// \param theParent the parent object
49 /// \param theWorkshop a reference to workshop
50 /// \param theData the widget configuation. The attribute of the model widget is obtained from
51 /// \param toShowConstraints a current show constraints state
52 PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
53 const Config_WidgetAPI* theData,
54 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints);
56 virtual ~PartSet_WidgetSketchLabel();
58 /// Set the given wrapped value to the current widget
59 /// This value should be processed in the widget according to the needs
60 /// The method is called by the current operation to process the operation preselection.
61 /// It is redefined to do nothing if the plane of the sketch has been already set.
62 /// \param theValues the wrapped selection values
63 /// \param theToValidate a validation flag
64 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
65 const bool theToValidate);
67 /// Returns list of widget controls
68 /// \return a control list
69 virtual QList<QWidget*> getControls() const;
71 /// The methiod called when widget is deactivated
72 virtual void deactivate();
74 /// Returns sketcher plane
75 std::shared_ptr<GeomAPI_Pln> plane() const;
77 /// This control accepts focus
78 virtual bool focusTo();
79 virtual void setHighlighted(bool) { /*do nothing*/ };
80 virtual void enableFocusProcessing();
83 /// Signal on plane selection
84 void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
86 /// A show constraint toggled signal
87 /// \param theType a ConstraintVisibleState value
88 /// \param theState a state of the check box
89 void showConstraintToggled(int theType, bool theState);
92 /// Creates a backup of the current values of the attribute
93 /// It should be realized in the specific widget because of different
94 /// parameters of the current attribute
95 virtual void storeAttributeValue();
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 theValid a boolean flag, if restore happens for valid parameters
101 virtual void restoreAttributeValue(const bool theValid);
103 /// Fills the attribute with the value of the selected owner
104 /// \param thePrs a selected owner
105 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
107 /// Saves the internal parameters to the given feature
108 /// \return True in success
109 virtual bool storeValueCustom() const
114 virtual bool restoreValueCustom()
119 /// The methiod called when widget is activated
120 virtual void activateCustom();
122 /// Block the model flush of update and intialization of attribute
123 /// In additional to curstom realization it blocks initialization for all feature attributes
124 /// as the current attribute is selection but its modification leads to other attributes change
125 /// \param theToBlock flag whether the model is blocked or unblocked
126 /// \param isActive out value if model is blocked, in value if model is unblocked
127 /// to be used to restore flush state when unblocked
128 /// \param isAttributeSetInitializedBlocked out value if model is blocked
129 /// in value if model is unblocked to be used to restore previous state when unblocked
130 virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
131 bool& isAttributeSetInitializedBlocked);
133 /// Erase preview planes, disconnect widget, change the view projection
134 /// \param thePrs a selected presentation
135 void updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs);
138 /// Activate or deactivate selection
139 void activateSelection(bool toActivate);
142 /// Slot on change selection
143 void onSelectionChanged();
145 /// A slot called on set sketch plane view
146 void onSetPlaneView();
148 /// Emits signal about check box state changed with information about ConstraintVisibleState
149 /// \param theOn a flag show constraints or not
150 void onShowConstraint(bool theOn);
153 /// Create preview of planes for sketch plane selection
154 /// \param theOrigin an origin of the plane
155 /// \param theNorm a normal vector of the plane
156 /// \param theRGB a color of plane presentation [r, g, b] array
157 AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin,
158 std::shared_ptr<GeomAPI_Dir> theNorm,
159 const int theRGB[3]);
162 XGUI_Workshop* workshop() const;
164 /// Set sketch plane by shape
165 /// \param theShape a planar face
166 std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
168 /// Erase preview planes
169 void erasePreviewPlanes();
171 /// Show preview planes
172 void showPreviewPlanes();
175 AISObjectPtr myYZPlane;
176 AISObjectPtr myXZPlane;
177 AISObjectPtr myXYPlane;
178 bool myPreviewDisplayed;
180 QCheckBox* myViewInverted;
182 QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;
184 QStackedWidget* myStackWidget;