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 theData the widget configuation. The attribute of the model widget is obtained from
44 /// \param theParentId is Id of a parent of the current attribute
45 PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData,
46 const std::string& theParentId, bool toShowConstraints);
48 virtual ~PartSet_WidgetSketchLabel();
50 /// Set the given wrapped value to the current widget
51 /// This value should be processed in the widget according to the needs
52 /// The method is called by the current operation to process the operation preselection.
53 /// It is redefined to do nothing if the plane of the sketch has been already set.
54 /// \param theValues the wrapped selection values
55 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
57 virtual bool restoreValue()
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 pointer to workshop
70 XGUI_Workshop* workshop() const { return myWorkshop; }
72 /// Set pointer to workshop
73 /// \param theWork a pointer to workshop
74 void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; }
76 /// Returns sketcher plane
77 std::shared_ptr<GeomAPI_Pln> plane() const;
79 /// This control accepts focus
80 virtual bool focusTo();
81 virtual void setHighlighted(bool) { /*do nothing*/ };
82 virtual void enableFocusProcessing();
84 void showConstraints(bool theOn);
87 /// Signal on plane selection
88 void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
90 void showConstraintToggled(bool);
93 /// Creates a backup of the current values of the attribute
94 /// It should be realized in the specific widget because of different
95 /// parameters of the current attribute
96 virtual void storeAttributeValue();
98 /// Creates a backup of the current values of the attribute
99 /// It should be realized in the specific widget because of different
100 /// parameters of the current attribute
101 /// \param theValid a boolean flag, if restore happens for valid parameters
102 virtual void restoreAttributeValue(const bool theValid);
104 /// Fills the attribute with the value of the selected owner
105 /// \param theOwner a selected owner
106 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
108 /// Saves the internal parameters to the given feature
109 /// \return True in success
110 virtual bool storeValueCustom() const
115 /// The methiod called when widget is activated
116 virtual void activateCustom();
119 /// Activate or deactivate selection
120 void activateSelection(bool toActivate);
123 /// Slot on change selection
124 void onSelectionChanged();
127 /// Create preview of planes for sketch plane selection
128 /// \param theOrigin an origin of the plane
129 /// \param theNorm a normal vector of the plane
130 /// \param theRGB a color of plane presentation [r, g, b] array
131 AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin,
132 std::shared_ptr<GeomAPI_Dir> theNorm,
133 const int theRGB[3]);
135 /// Set sketch plane by shape
136 /// \param theShape a planar face
137 std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
139 /// Erase preview planes
140 void erasePreviewPlanes();
142 /// Show preview planes
143 void showPreviewPlanes();
150 XGUI_Workshop* myWorkshop;
152 AISObjectPtr myYZPlane;
153 AISObjectPtr myXZPlane;
154 AISObjectPtr myXYPlane;
155 bool myPreviewDisplayed;
157 QCheckBox* myShowConstraints;