Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: extrusion cut.
[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   /// Editing mode depends on mode of current operation. This value is defined by it.
56   virtual void setEditingMode(bool isEditing);
57
58   /// Check if the current and the parent operations are a composite. If the parent operation contains
59   /// attribute selection list, the method returns false if it is invalid in this attibute validator
60   /// \param theWorkshop a current workshop
61   /// \return boolean value
62   static bool canCommitCurrentSketch(ModuleBase_IWorkshop* theWorkshop);
63
64 protected:
65   /// Saves the internal parameters to the given feature
66   /// \return True in success
67   virtual bool storeValueCustom() const;
68
69   virtual bool restoreValueCustom();
70
71   /// Sets the selection control visible and set the current widget as active in property panel
72   /// It leads to connect to onSelectionChanged slot
73   void activateSelectionControl();
74
75   /// Visualization of the current control or others in PP
76   /// \param theSelectionControl state whether the control should be shown/hidden
77   void setVisibleSelectionControl(const bool theSelectionControl);
78
79   /// Retunrs a list of possible shape types
80   /// \return a list of shapes
81   virtual QIntList getShapeTypes() const;
82
83   /// Store the values to the model attribute of the widget. It casts this attribute to
84   /// the specific type and set the given values
85   /// \param theObject an object
86   /// \param theShape a selected shape, which is used in the selection attribute
87   /// \return true if it is succeed
88   virtual void setObject(ObjectPtr theObject, GeomShapePtr theShape);
89
90 private:
91   /// Returns true if the selection mode is active. This is when composition feature has no
92   ///  a sub-object and the attribute list is empty
93   /// \return boolean value
94   bool isSelectionMode() const;
95
96 protected slots:
97   /// Slot which is called on selection event
98   // NDS: virtual is temporary
99   virtual void onSelectionChanged();
100
101 private slots:
102   void onResumed(ModuleBase_Operation* theOp);
103
104 private:
105   /// Append new Sketch, set the selected plane for the sketch and start Edit operation.
106   /// \param theValues a selection list
107   /// \return true if the sketch is started
108   bool startSketchOperation(const QList<ModuleBase_ViewerPrs>& theValues);
109
110   /// Appends the selection to the sketch base attribute 
111   /// \param theValue a selection value from the viewer
112   /// \return true if the value is set
113   bool setBaseAttributeSelection(const ModuleBase_ViewerPrs& theValue);
114
115 private:
116   std::string myAttributeListID;
117
118   PartSet_Module* myModule;
119
120   /// Label of the widget
121   QLabel* myLabel;
122
123   /// Input control of the widget
124   QLineEdit* myTextLine;
125
126   /// List of accepting shapes types
127   QStringList myShapeTypes;
128
129   /// class to show/hide preview planes
130   PartSet_PreviewPlanes* myPreviewPlanes;
131 };
132
133 #endif