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. The focus policy of the control is checked.
46 /// If the widget has the NonFocus focus policy, it is skipped.
47 /// \return the state whether the widget can accept the focus
48 virtual bool focusTo();
50 /// The methiod called when widget is deactivated
51 virtual void deactivate();
53 /// Set the given wrapped value to the current widget
54 /// This value should be processed in the widget according to the needs
55 /// \param theValues the wrapped selection values
56 /// \param theToValidate a validation of the values flag
57 virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
58 const bool theToValidate);
60 /// Editing mode depends on mode of current operation. This value is defined by it.
61 virtual void setEditingMode(bool isEditing);
63 /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
64 /// next, the attribute's validating. It trying on the give selection to current attribute by
65 /// setting the value inside and calling validators. After this, the previous attribute value is
66 /// restored.The valid/invalid value is cashed.
67 /// \param theValue a selected presentation in the view
68 /// \return a boolean value
69 virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
72 /// If there is no operation in current session, start operation for modify parameters
73 /// \return true if the operation was not opened
74 void openExtrusionTransaction();
76 /// Checks whether the selection presentation contains preview planes
77 /// \param theValue a selection information
78 /// \return a boolean value
79 virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
81 /// Saves the internal parameters to the given feature
82 /// \return True in success
83 virtual bool storeValueCustom();
85 virtual bool restoreValueCustom();
87 /// Retunrs attribute, which should be validated. In default implementation,
88 /// this is an attribute of ID
89 /// \return an attribute
90 virtual AttributePtr attribute() const;
92 /// Sets the selection control visible and set the current widget as active in property panel
93 /// It leads to connect to onSelectionChanged slot
94 void activateSelectionControl();
96 /// Visualization of the current control or others in PP
97 /// \param theSelectionControl state whether the control should be shown/hidden
98 void setVisibleSelectionControl(const bool theSelectionControl);
100 /// Retunrs a list of possible shape types
101 /// \return a list of shapes
102 virtual QIntList shapeTypes() const;
104 /// Emits model changed info, updates the current control by selection change
105 /// \param theDone a state whether the selection is set
106 void updateOnSelectionChanged(const bool theDone);
109 /// Slot which is called on selection event
110 virtual void onSelectionChanged();
113 /// Returns true if the selection mode is active. This is when composition feature has no
114 /// a sub-object and the attribute list is empty
115 /// \return boolean value
116 bool isSelectionMode() const;
118 /// Returns true if the current composite feature contains at least one sub-object
119 /// \return boolean value
120 bool hasSubObjects() const;
123 void onResumed(ModuleBase_Operation* theOp);
126 /// Append new Sketch, set the selected plane for the sketch and start Edit operation.
127 /// \param theValues a selection list
128 /// \return true if the sketch is started
129 bool startSketchOperation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
131 /// Sets the sub-object to list of base.
132 static void setSketchObjectToList(const CompositeFeaturePtr& theFeature,
133 const AttributePtr& theAttribute);
135 /// Calls validator for attribute list and warn if it is not valid
136 /// \return true if validation succeed
137 bool validateSelectionList() const;
139 /// Change enable state of controls in the model widget by the attribute identifier
140 /// \param theModelWidget a model widget
141 /// \param theEnabled a state if the controls should be enabled/disabled
142 void setEnabledModelWidget(ModuleBase_ModelWidget* theModelWidget,
143 const bool theEnabled);
146 std::string myAttributeListID;
148 PartSet_Module* myModule;
150 /// Flag if the attribute() should return the attribute list ID or XML attribute
151 /// to store selection and check validation
152 bool myIsCustomAttribute;
154 /// Label of the widget
157 /// List of accepting shapes types
158 QStringList myShapeTypes;
160 /// class to show/hide preview planes
161 PartSet_PreviewPlanes* myPreviewPlanes;