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