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;
27 /// the plane edge width
28 #define SKETCH_WIDTH "4"
30 /// face of the square-face displayed for selection of general plane
31 #define PLANE_SIZE "200"
35 * A model widget implementation for a label which provides specific behaviour
36 * for sketcher starting and launching operations
38 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 theParentId is Id of a parent of the current attribute
47 /// \param toShowConstraints a current show constraints state
48 PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
49 const Config_WidgetAPI* theData,
50 const std::string& theParentId, bool toShowConstraints);
52 virtual ~PartSet_WidgetSketchLabel();
54 /// Set the given wrapped value to the current widget
55 /// This value should be processed in the widget according to the needs
56 /// The method is called by the current operation to process the operation preselection.
57 /// It is redefined to do nothing if the plane of the sketch has been already set.
58 /// \param theValues the wrapped selection values
59 /// \param theToValidate a validation flag
60 virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
61 const bool theToValidate);
63 /// Returns list of widget controls
64 /// \return a control list
65 virtual QList<QWidget*> getControls() const;
67 /// The methiod called when widget is deactivated
68 virtual void deactivate();
70 /// Returns sketcher plane
71 std::shared_ptr<GeomAPI_Pln> plane() const;
73 /// This control accepts focus
74 virtual bool focusTo();
75 virtual void setHighlighted(bool) { /*do nothing*/ };
76 virtual void enableFocusProcessing();
78 /// Set show constraints state
79 /// \param theOn a flag show constraints or not
80 void showConstraints(bool theOn);
83 /// Signal on plane selection
84 void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
86 /// A show constraint toggled signal
87 void showConstraintToggled(bool);
90 /// Creates a backup of the current values of the attribute
91 /// It should be realized in the specific widget because of different
92 /// parameters of the current attribute
93 virtual void storeAttributeValue();
95 /// Creates a backup of the current values of the attribute
96 /// It should be realized in the specific widget because of different
97 /// parameters of the current attribute
98 /// \param theValid a boolean flag, if restore happens for valid parameters
99 virtual void restoreAttributeValue(const bool theValid);
101 /// Fills the attribute with the value of the selected owner
102 /// \param thePrs a selected owner
103 virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
105 /// Saves the internal parameters to the given feature
106 /// \return True in success
107 virtual bool storeValueCustom() const
112 virtual bool restoreValueCustom()
117 /// The methiod called when widget is activated
118 virtual void activateCustom();
120 /// Erase preview planes, disconnect widget, change the view projection
121 /// \param thePrs a selected presentation
122 void updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs);
125 /// Activate or deactivate selection
126 void activateSelection(bool toActivate);
129 /// Slot on change selection
130 void onSelectionChanged();
132 /// A slot called on set sketch plane view
133 void onSetPlaneView();
136 /// Create preview of planes for sketch plane selection
137 /// \param theOrigin an origin of the plane
138 /// \param theNorm a normal vector of the plane
139 /// \param theRGB a color of plane presentation [r, g, b] array
140 AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin,
141 std::shared_ptr<GeomAPI_Dir> theNorm,
142 const int theRGB[3]);
145 XGUI_Workshop* workshop() const;
147 /// Set sketch plane by shape
148 /// \param theShape a planar face
149 std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
151 /// Erase preview planes
152 void erasePreviewPlanes();
154 /// Show preview planes
155 void showPreviewPlanes();
158 AISObjectPtr myYZPlane;
159 AISObjectPtr myXZPlane;
160 AISObjectPtr myXYPlane;
161 bool myPreviewDisplayed;
163 QCheckBox* myShowConstraints;
164 QCheckBox* myViewInverted;
166 QStackedWidget* myStackWidget;