]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetSketchCreator.h
Salome HOME
Issue #1343. Improvement of Extrusion and Revolution operations: setSketchObjectToLis...
[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 ModelAPI_Tools;
18 class ModuleBase_Operation;
19 class ModuleBase_IWorkshop;
20 class PartSet_PreviewPlanes;
21
22 /**
23 * \ingroup Modules
24 * A widget which allow creation of a sketch in another operation.
25 * It creates sketch on aqctivation of this widget. If sketch object is already created then
26 * it will transfer a focus to next widget. It is supposed that the widget will be placed as 
27 * a first widget in property panel
28 */
29 class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_WidgetSelector
30 {
31 Q_OBJECT
32
33 public:
34   /// Constructor
35   /// \param theParent the parent object
36   /// \param theModule a reference to a module object
37   /// \param theData the widget configuation. The attribute of the model widget is obtained from
38   PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule,
39                               const Config_WidgetAPI* theData);
40
41   virtual ~PartSet_WidgetSketchCreator();
42
43   /// Returns list of widget controls
44   /// \return a control list
45   virtual QList<QWidget*> getControls() const;
46
47   /// Set focus to the first control of the current widget. 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<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 ModuleBase_ViewerPrs& theValue);
72
73   /// Check if the current and the parent operations are a composite. If the parent operation contains
74   /// attribute selection list, the method returns false if it is invalid in this attibute validator
75   /// \param theWorkshop a current workshop
76   /// \return boolean value
77   static bool canCommitCurrentSketch(ModuleBase_IWorkshop* theWorkshop);
78
79   /// Sets the sub-object to list of base.
80   static void setSketchObjectToList(const CompositeFeaturePtr& theFeature,
81                                     const AttributePtr& theAttribute);
82
83 protected:
84   /// If there is no operation in current session, start operation for modify parameters
85   void openTransaction();
86
87   /// Checks whether the selection presentation contains preview planes
88   /// \param theValue a selection information
89   /// \return a boolean value
90   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& theValue);
91
92   /// Saves the internal parameters to the given feature
93   /// \return True in success
94   virtual bool storeValueCustom() const;
95
96   virtual bool restoreValueCustom();
97
98   /// Retunrs attribute, which should be validated. In default implementation,
99   /// this is an attribute of ID
100   /// \return an attribute
101   virtual AttributePtr attribute() const;
102
103   /// Sets the selection control visible and set the current widget as active in property panel
104   /// It leads to connect to onSelectionChanged slot
105   void activateSelectionControl();
106
107   /// Visualization of the current control or others in PP
108   /// \param theSelectionControl state whether the control should be shown/hidden
109   void setVisibleSelectionControl(const bool theSelectionControl);
110
111   /// Retunrs a list of possible shape types
112   /// \return a list of shapes
113   virtual QIntList getShapeTypes() const;
114
115   /// Emits model changed info, updates the current control by selection change
116   /// \param theDone a state whether the selection is set
117   void updateOnSelectionChanged(const bool theDone);
118
119 protected slots:
120   /// Slot which is called on selection event
121   virtual void onSelectionChanged();
122
123 private:
124   /// Returns true if the selection mode is active. This is when composition feature has no
125   ///  a sub-object and the attribute list is empty
126   /// \return boolean value
127   bool isSelectionMode() const;
128
129 private slots:
130   void onResumed(ModuleBase_Operation* theOp);
131
132 private:
133   /// Append new Sketch, set the selected plane for the sketch and start Edit operation.
134   /// \param theValues a selection list
135   /// \return true if the sketch is started
136   bool startSketchOperation(const QList<ModuleBase_ViewerPrs>& theValues);
137
138 private:
139   std::string myAttributeListID;
140
141   PartSet_Module* myModule;
142
143   /// Flag if the attribute() should return the attribute list ID or XML attribute
144   /// to store selection and check validation
145   bool myIsCustomAttribute;
146
147   /// Label of the widget
148   QLabel* myLabel;
149
150   /// Input control of the widget
151   QLineEdit* myTextLine;
152
153   /// List of accepting shapes types
154   QStringList myShapeTypes;
155
156   /// class to show/hide preview planes
157   PartSet_PreviewPlanes* myPreviewPlanes;
158 };
159
160 #endif