1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_WidgetSketchCreator.h
4 // Created: 08 June 2015
5 // Author: Vitaly SMETANNIKOV
7 #ifndef PartSet_WidgetSketchCreator_H
8 #define PartSet_WidgetSketchCreator_H
12 #include <ModuleBase_WidgetSelector.h>
16 class ModuleBase_Operation;
17 class ModuleBase_IWorkshop;
18 class PartSet_PreviewPlanes;
22 * A widget which allow creation of a sketch in another operation.
23 * It creates sketch on aqctivation of this widget. If sketch object is already created then
24 * it will transfer a focus to next widget. It is supposed that the widget will be placed as
25 * a first widget in property panel
27 class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_WidgetSelector
33 /// \param theParent the parent object
34 /// \param theModule a reference to a module object
35 /// \param theData the widget configuation. The attribute of the model widget is obtained from
36 PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule,
37 const Config_WidgetAPI* theData);
39 virtual ~PartSet_WidgetSketchCreator();
41 /// Returns list of widget controls
42 /// \return a control list
43 virtual QList<QWidget*> getControls() const;
45 /// Set focus to the first control of the current widget.
46 /// The focus policy of the control is checked.
47 /// If the widget has the NonFocus focus policy, it is skipped.
48 /// \return the state whether the widget can accept the focus
49 virtual bool focusTo();
51 /// The methiod called when widget is deactivated
52 virtual void deactivate();
54 /// Set the given wrapped value to the current widget
55 /// This value should be processed in the widget according to the needs
56 /// \param theValues the wrapped selection values
57 /// \param theToValidate a validation of the values flag
58 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
59 const bool theToValidate);
61 /// Editing mode depends on mode of current operation. This value is defined by it.
62 virtual void setEditingMode(bool isEditing);
64 /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
65 /// next, the attribute's validating. It trying on the give selection to current attribute by
66 /// setting the value inside and calling validators. After this, the previous attribute value is
67 /// restored.The valid/invalid value is cashed.
68 /// \param theValue a selected presentation in the view
69 /// \return a boolean value
70 virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
73 /// If there is no operation in current session, start operation for modify parameters
74 /// \return true if the operation was not opened
75 void openExtrusionTransaction();
77 /// Checks whether the selection presentation contains preview planes
78 /// \param theValue a selection information
79 /// \return a boolean value
80 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
82 /// Saves the internal parameters to the given feature
83 /// \return True in success
84 virtual bool storeValueCustom();
86 virtual bool restoreValueCustom();
88 /// Retunrs attribute, which should be validated. In default implementation,
89 /// this is an attribute of ID
90 /// \return an attribute
91 virtual AttributePtr attribute() const;
93 /// Sets the selection control visible and set the current widget as active in property panel
94 /// It leads to connect to onSelectionChanged slot
95 void activateSelectionControl();
97 /// Visualization of the current control or others in PP
98 /// \param theSelectionControl state whether the control should be shown/hidden
99 void setVisibleSelectionControl(const bool theSelectionControl);
101 /// Retunrs a list of possible shape types
102 /// \return a list of shapes
103 virtual QIntList shapeTypes() const;
105 /// Emits model changed info, updates the current control by selection change
106 /// \param theDone a state whether the selection is set
107 void updateOnSelectionChanged(const bool theDone);
110 /// Slot which is called on selection event
111 virtual void onSelectionChanged();
114 /// Returns true if the selection mode is active. This is when composition feature has no
115 /// a sub-object and the attribute list is empty
116 /// \return boolean value
117 bool isSelectionMode() const;
119 /// Returns true if the current composite feature contains at least one sub-object
120 /// \return boolean value
121 bool hasSubObjects() const;
124 void onResumed(ModuleBase_Operation* theOp);
127 /// Append new Sketch, set the selected plane for the sketch and start Edit operation.
128 /// \param theValues a selection list
129 /// \return true if the sketch is started
130 bool startSketchOperation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
132 /// Sets the sub-object to list of base.
133 static void setSketchObjectToList(const CompositeFeaturePtr& theFeature,
134 const AttributePtr& theAttribute);
136 /// Calls validator for attribute list and warn if it is not valid
137 /// \return true if validation succeed
138 bool validateSelectionList() const;
140 /// Change enable state of controls in the model widget by the attribute identifier
141 /// \param theModelWidget a model widget
142 /// \param theEnabled a state if the controls should be enabled/disabled
143 void setEnabledModelWidget(ModuleBase_ModelWidget* theModelWidget,
144 const bool theEnabled);
147 std::string myAttributeListID;
149 PartSet_Module* myModule;
151 /// Flag if the attribute() should return the attribute list ID or XML attribute
152 /// to store selection and check validation
153 bool myIsCustomAttribute;
155 /// Label of the widget
158 /// List of accepting shapes types
159 QStringList myShapeTypes;
161 /// class to show/hide preview planes
162 PartSet_PreviewPlanes* myPreviewPlanes;