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