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 <ModuleBase_WidgetValidated.h>
13 #include <ModuleBase_ViewerFilters.h>
15 #include <GeomAPI_Pnt.h>
16 #include <GeomAPI_Dir.h>
17 #include <GeomAPI_AISObject.h>
19 #include <TopoDS_Shape.hxx>
22 class XGUI_OperationMgr;
26 /// the plane edge width
27 #define SKETCH_WIDTH "4"
29 /// face of the square-face displayed for selection of general plane
30 #define PLANE_SIZE "200"
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
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 theParentId is Id of a parent of the current attribute
46 /// \param toShowConstraints a current show constraints state
47 PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
48 const Config_WidgetAPI* theData,
49 const std::string& theParentId, 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<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 /// Set show constraints state
78 /// \param theOn a flag show constraints or not
79 void showConstraints(bool theOn);
82 /// Signal on plane selection
83 void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
85 /// A show constraint toggled signal
86 void showConstraintToggled(bool);
89 /// Creates a backup of the current values of the attribute
90 /// It should be realized in the specific widget because of different
91 /// parameters of the current attribute
92 virtual void storeAttributeValue();
94 /// Creates a backup of the current values of the attribute
95 /// It should be realized in the specific widget because of different
96 /// parameters of the current attribute
97 /// \param theValid a boolean flag, if restore happens for valid parameters
98 virtual void restoreAttributeValue(const bool theValid);
100 /// Fills the attribute with the value of the selected owner
101 /// \param thePrs a selected owner
102 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
104 /// Saves the internal parameters to the given feature
105 /// \return True in success
106 virtual bool storeValueCustom() const
111 virtual bool restoreValueCustom()
116 /// The methiod called when widget is activated
117 virtual void activateCustom();
119 /// Erase preview planes, disconnect widget, change the view projection
120 /// \param thePrs a selected presentation
121 void updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs);
124 /// Activate or deactivate selection
125 void activateSelection(bool toActivate);
128 /// Slot on change selection
129 void onSelectionChanged();
132 /// Create preview of planes for sketch plane selection
133 /// \param theOrigin an origin of the plane
134 /// \param theNorm a normal vector of the plane
135 /// \param theRGB a color of plane presentation [r, g, b] array
136 AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin,
137 std::shared_ptr<GeomAPI_Dir> theNorm,
138 const int theRGB[3]);
141 XGUI_Workshop* workshop() const;
143 /// Set sketch plane by shape
144 /// \param theShape a planar face
145 std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
147 /// Erase preview planes
148 void erasePreviewPlanes();
150 /// Show preview planes
151 void showPreviewPlanes();
158 AISObjectPtr myYZPlane;
159 AISObjectPtr myXZPlane;
160 AISObjectPtr myXYPlane;
161 bool myPreviewDisplayed;
163 QCheckBox* myShowConstraints;