Salome HOME
7a341689d179dc21a371d3993e9958cfc4c1830f
[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 ModuleBase_Operation;
18 class ModuleBase_IWorkshop;
19 class PartSet_PreviewPlanes;
20
21 /**
22 * \ingroup Modules
23 * A widget which allow creation of a sketch in another operation.
24 * It creates sketch on aqctivation of this widget. If sketch object is already created then
25 * it will transfer a focus to next widget. It is supposed that the widget will be placed as 
26 * a first widget in property panel
27 */
28 class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_WidgetSelector
29 {
30 Q_OBJECT
31
32 public:
33   /// Constructor
34   /// \param theParent the parent object
35   /// \param theModule a reference to a module object
36   /// \param theData the widget configuation. The attribute of the model widget is obtained from
37   PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule,
38                               const Config_WidgetAPI* theData);
39
40   virtual ~PartSet_WidgetSketchCreator();
41
42   /// Returns list of widget controls
43   /// \return a control list
44   virtual QList<QWidget*> getControls() const;
45
46   /// Set focus to the first control of the current widget. The focus policy of the control is checked.
47   /// If the widget has the NonFocus focus policy, it is skipped.
48   /// \return the state whether the widget can accept the focus
49   virtual bool focusTo();
50
51   /// The methiod called when widget is deactivated
52   virtual void deactivate();
53
54   /// Editing mode depends on mode of current operation. This value is defined by it.
55   virtual void setEditingMode(bool isEditing);
56
57   /// Check if the current and the parent operations are a composite. If the parent operation contains
58   /// attribute selection list, the method returns false if it is invalid in this attibute validator
59   /// \param theWorkshop a current workshop
60   /// \return boolean value
61   static bool canCommitCurrentSketch(ModuleBase_IWorkshop* theWorkshop);
62
63 protected:
64   /// Saves the internal parameters to the given feature
65   /// \return True in success
66   virtual bool storeValueCustom() const;
67
68   virtual bool restoreValueCustom();
69
70   /// Sets the selection control visible and set the current widget as active in property panel
71   /// It leads to connect to onSelectionChanged slot
72   void activateSelectionControl();
73
74   /// Visualization of the current control or others in PP
75   /// \param theSelectionControl state whether the control should be shown/hidden
76   void setVisibleSelectionControl(const bool theSelectionControl);
77
78   /// Retunrs a list of possible shape types
79   /// \return a list of shapes
80   virtual QIntList getShapeTypes() const;
81
82   /// Store the values to the model attribute of the widget. It casts this attribute to
83   /// the specific type and set the given values
84   /// \param theSelectedObject an object
85   /// \param theShape a selected shape, which is used in the selection attribute
86   /// \return true if it is succeed
87   virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
88
89 private:
90   /// Returns true if the selection mode is active. This is when composition feature has no
91   ///  a sub-object and the attribute list is empty
92   /// \return boolean value
93   bool isSelectionMode() const;
94
95 protected slots:
96   /// Slot which is called on selection event
97   // NDS: virtual is temporary
98   virtual void onSelectionChanged();
99
100 private slots:
101   void onResumed(ModuleBase_Operation* theOp);
102
103 private:
104   /// Append new Sketch, set the selected plane for the sketch and start Edit operation.
105   /// \param theValues a selection list
106   /// \return true if the sketch is started
107   bool startSketchOperation(const QList<ModuleBase_ViewerPrs>& theValues);
108
109 private:
110   std::string myAttributeListID;
111
112   PartSet_Module* myModule;
113
114   /// Label of the widget
115   QLabel* myLabel;
116
117   /// Input control of the widget
118   QLineEdit* myTextLine;
119
120   /// List of accepting shapes types
121   QStringList myShapeTypes;
122
123   /// class to show/hide preview planes
124   PartSet_PreviewPlanes* myPreviewPlanes;
125 };
126
127 #endif