Salome HOME
Issue #3073: Show inspection panel for features
[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   /// Returns True in case if the widget contains useful information for inspection tool
87   virtual bool isInformative() const { return false; }
88
89 protected:
90   /// If there is no operation in current session, start operation for modify parameters
91   /// \return true if the operation was not opened
92   void openExtrusionTransaction();
93
94   /// Checks whether the selection presentation contains preview planes
95   /// \param theValue a selection information
96   /// \return a boolean value
97   virtual bool isValidSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
98
99   /// Saves the internal parameters to the given feature
100   /// \return True in success
101   virtual bool storeValueCustom();
102
103   virtual bool restoreValueCustom();
104
105   /// Retunrs attribute, which should be validated. In default implementation,
106   /// this is an attribute of ID
107   /// \return an attribute
108   virtual AttributePtr attribute() const;
109
110   /// Sets the selection control visible and set the current widget as active in property panel
111   /// It leads to connect to onSelectionChanged slot
112   void activateSelectionControl();
113
114   /// Visualization of the current control or others in PP
115   /// \param theSelectionControl state whether the control should be shown/hidden
116   void setVisibleSelectionControl(const bool theSelectionControl);
117
118   /// Retunrs a list of possible shape types
119   /// \return a list of shapes
120   virtual QIntList shapeTypes() const;
121
122   /// Emits model changed info, updates the current control by selection change
123   /// \param theDone a state whether the selection is set
124   void updateOnSelectionChanged(const bool theDone);
125
126 protected:
127   /// Returns true if envent is processed.
128   virtual bool processSelection();
129
130 private:
131   /// Returns true if the selection mode is active. This is when composition feature has no
132   ///  a sub-object and the attribute list is empty
133   /// \return boolean value
134   bool isSelectionMode() const;
135
136   /// Returns true if the current composite feature contains at least one sub-object
137   /// \return boolean value
138   bool hasSubObjects() const;
139
140 private slots:
141   void onResumed(ModuleBase_Operation* theOp);
142
143 private:
144   /// Append new Sketch, set the selected plane for the sketch and start Edit operation.
145   /// \param theValues a selection list
146   /// \return true if the sketch is started
147   bool startSketchOperation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
148
149   /// Sets the sub-object to list of base.
150   static void setSketchObjectToList(const CompositeFeaturePtr& theFeature,
151                                     const AttributePtr& theAttribute);
152
153   /// Calls validator for attribute list and warn if it is not valid
154   /// \return true if validation succeed
155   bool validateSelectionList() const;
156
157   /// Change enable state of controls in the model widget by the attribute identifier
158   /// \param theModelWidget a model widget
159   /// \param theEnabled a state if the controls should be enabled/disabled
160   void setEnabledModelWidget(ModuleBase_ModelWidget* theModelWidget,
161                              const bool theEnabled);
162
163 private:
164   std::string myAttributeListID;
165
166   PartSet_Module* myModule;
167
168   /// Flag if the attribute() should return the attribute list ID or XML attribute
169   /// to store selection and check validation
170   bool myIsCustomAttribute;
171
172   QWidget* mySizeOfViewWidget;///< Size of view widget, visualized if preview planes are shown
173   QLineEdit* mySizeOfView; ///< Value of square of size of View
174   /// Label of the widget
175   QLabel* myLabel;
176
177   /// List of accepting shapes types
178   QStringList myShapeTypes;
179
180   /// class to show/hide preview planes
181   PartSet_PreviewPlanes* myPreviewPlanes;
182 };
183
184 #endif