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