Salome HOME
a345a1e90b66d0f5c62a72e2e1d348ba9b2db45a
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchCreator.h
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef PartSet_WidgetSketchCreator_H
21 #define PartSet_WidgetSketchCreator_H
22
23 #include "PartSet.h"
24
25 #include <ModuleBase_WidgetSelector.h>
26
27 class QLabel;
28 class QLineEdit;
29 class PartSet_Module;
30 class ModuleBase_Operation;
31 class ModuleBase_IWorkshop;
32 class PartSet_PreviewPlanes;
33 class ModuleBase_ChoiceCtrl;
34
35 /**
36 * \ingroup Modules
37 * A widget which allow creation of a sketch in another operation.
38 * It creates sketch on aqctivation of this widget. If sketch object is already created then
39 * it will transfer a focus to next widget. It is supposed that the widget will be placed as 
40 * a first widget in property panel
41 */
42 class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_WidgetSelector
43 {
44 Q_OBJECT
45
46 public:
47   /// Constructor
48   /// \param theParent the parent object
49   /// \param theModule a reference to a module object
50   /// \param theData the widget configuation. The attribute of the model widget is obtained from
51   PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule,
52                               const Config_WidgetAPI* theData);
53
54   virtual ~PartSet_WidgetSketchCreator();
55
56   /// Returns list of widget controls
57   /// \return a control list
58   virtual QList<QWidget*> getControls() const;
59
60   /// Set focus to the first control of the current widget.
61   /// The focus policy of the control is checked.
62   /// If the widget has the NonFocus focus policy, it is skipped.
63   /// \return the state whether the widget can accept the focus
64   virtual bool focusTo();
65
66   /// The methiod called when widget is deactivated
67   virtual void deactivate();
68
69   /// Set the given wrapped value to the current widget
70   /// This value should be processed in the widget according to the needs
71   /// \param theValues the wrapped selection values
72   /// \param theToValidate a validation of the values flag
73   virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
74                             const bool theToValidate);
75
76   /// Editing mode depends on mode of current operation. This value is defined by it.
77   virtual void setEditingMode(bool isEditing);
78
79   /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
80   /// next, the attribute's validating. It trying on the give selection to current attribute by
81   /// setting the value inside and calling validators. After this, the previous attribute value is
82   /// restored.The valid/invalid value is cashed.
83   /// \param theValue a selected presentation in the view
84   /// \return a boolean value
85   virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
86
87   /// Returns True in case if the widget contains useful information for inspection tool
88   virtual bool isInformative() const { return false; }
89
90 protected:
91   /// If there is no operation in current session, start operation for modify parameters
92   /// \return true if the operation was not opened
93   void openExtrusionTransaction();
94
95   /// Checks whether the selection presentation contains preview planes
96   /// \param theValue a selection information
97   /// \return a boolean value
98   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
99
100   /// Saves the internal parameters to the given feature
101   /// \return True in success
102   virtual bool storeValueCustom();
103
104   virtual bool restoreValueCustom();
105
106   /// Retunrs attribute, which should be validated. In default implementation,
107   /// this is an attribute of ID
108   /// \return an attribute
109   virtual AttributePtr attribute() const;
110
111   /// Sets the selection control visible and set the current widget as active in property panel
112   /// It leads to connect to onSelectionChanged slot
113   void activateSelectionControl();
114
115   /// Visualization of the current control or others in PP
116   /// \param theSelectionControl state whether the control should be shown/hidden
117   void setVisibleSelectionControl(const bool theSelectionControl);
118
119   /// Retunrs a list of possible shape types
120   /// \return a list of shapes
121   virtual QIntList shapeTypes() const;
122
123   /// Emits model changed info, updates the current control by selection change
124   /// \param theDone a state whether the selection is set
125   void updateOnSelectionChanged(const bool theDone);
126
127 protected:
128   /// Returns true if envent is processed.
129   virtual bool processSelection();
130
131 private:
132   /// Returns true if the selection mode is active. This is when composition feature has no
133   ///  a sub-object and the attribute list is empty
134   /// \return boolean value
135   bool isSelectionMode() const;
136
137   /// Returns true if the current composite feature contains at least one sub-object
138   /// \return boolean value
139   bool hasSubObjects() const;
140
141 private slots:
142   void onResumed(ModuleBase_Operation* theOp);
143
144   /// Slot is called on selection type changed
145   void onSelectionTypeChanged();
146
147 private:
148   /// Append new Sketch, set the selected plane for the sketch and start Edit operation.
149   /// \param theValues a selection list
150   /// \return true if the sketch is started
151   bool startSketchOperation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
152
153   /// Sets the sub-object to list of base.
154   static void setSketchObjectToList(const CompositeFeaturePtr& theFeature,
155                                     const AttributePtr& theAttribute);
156
157   /// Calls validator for attribute list and warn if it is not valid
158   /// \return true if validation succeed
159   bool validateSelectionList() const;
160
161   /// Change enable state of controls in the model widget by the attribute identifier
162   /// \param theModelWidget a model widget
163   /// \param theEnabled a state if the controls should be enabled/disabled
164   void setEnabledModelWidget(ModuleBase_ModelWidget* theModelWidget,
165                              const bool theEnabled);
166
167 private:
168   std::string myAttributeListID;
169
170   PartSet_Module* myModule;
171
172   /// Flag if the attribute() should return the attribute list ID or XML attribute
173   /// to store selection and check validation
174   bool myIsCustomAttribute;
175
176   QWidget* mySizeOfViewWidget;///< Size of view widget, visualized if preview planes are shown
177   QLineEdit* mySizeOfView; ///< Value of square of size of View
178   /// Label of the widget
179   QLabel* myLabel;
180
181   /// List of accepting shapes types
182   QStringList myShapeTypes;
183
184   /// class to show/hide preview planes
185   PartSet_PreviewPlanes* myPreviewPlanes;
186
187   bool myIsUseChoice; ///< A flag to store use_choice parameter state
188
189   /// Control for types
190   ModuleBase_ChoiceCtrl* myTypeCtrl;
191   std::string myDefMode;
192 };
193
194 #endif