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, ModuleBase_IWorkshop* theWorkshop,
46 const Config_WidgetAPI* theData,
47 const std::string& theParentId, bool toShowConstraints);
49 virtual ~PartSet_WidgetSketchLabel();
51 /// Set the given wrapped value to the current widget
52 /// This value should be processed in the widget according to the needs
53 /// The method is called by the current operation to process the operation preselection.
54 /// It is redefined to do nothing if the plane of the sketch has been already set.
55 /// \param theValues the wrapped selection values
56 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
57 const bool theToValidate);
59 /// Returns list of widget controls
60 /// \return a control list
61 virtual QList<QWidget*> getControls() const;
63 /// The methiod called when widget is deactivated
64 virtual void deactivate();
66 /// Returns sketcher plane
67 std::shared_ptr<GeomAPI_Pln> plane() const;
69 /// This control accepts focus
70 virtual bool focusTo();
71 virtual void setHighlighted(bool) { /*do nothing*/ };
72 virtual void enableFocusProcessing();
74 void showConstraints(bool theOn);
77 /// Signal on plane selection
78 void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
80 void showConstraintToggled(bool);
83 /// Creates a backup of the current values of the attribute
84 /// It should be realized in the specific widget because of different
85 /// parameters of the current attribute
86 virtual void storeAttributeValue();
88 /// Creates a backup of the current values of the attribute
89 /// It should be realized in the specific widget because of different
90 /// parameters of the current attribute
91 /// \param theValid a boolean flag, if restore happens for valid parameters
92 virtual void restoreAttributeValue(const bool theValid);
94 /// Fills the attribute with the value of the selected owner
95 /// \param theOwner a selected owner
96 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
98 /// Saves the internal parameters to the given feature
99 /// \return True in success
100 virtual bool storeValueCustom() const
105 virtual bool restoreValueCustom()
110 /// The methiod called when widget is activated
111 virtual void activateCustom();
113 /// Erase preview planes, disconnect widget, change the view projection
114 /// \param thePrs a selected presentation
115 void updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs);
118 /// Activate or deactivate selection
119 void activateSelection(bool toActivate);
122 /// Slot on change selection
123 void onSelectionChanged();
126 /// Create preview of planes for sketch plane selection
127 /// \param theOrigin an origin of the plane
128 /// \param theNorm a normal vector of the plane
129 /// \param theRGB a color of plane presentation [r, g, b] array
130 AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin,
131 std::shared_ptr<GeomAPI_Dir> theNorm,
132 const int theRGB[3]);
135 XGUI_Workshop* workshop() const;
137 /// Set sketch plane by shape
138 /// \param theShape a planar face
139 std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
141 /// Erase preview planes
142 void erasePreviewPlanes();
144 /// Show preview planes
145 void showPreviewPlanes();
152 AISObjectPtr myYZPlane;
153 AISObjectPtr myXZPlane;
154 AISObjectPtr myXYPlane;
155 bool myPreviewDisplayed;
157 QCheckBox* myShowConstraints;