Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_Module.h
1 #ifndef PartSet_Module_H
2 #define PartSet_Module_H
3
4 #include "PartSet.h"
5
6 #include <ModuleBase_IModule.h>
7 #include <ModuleBase_Definitions.h>
8 #include <XGUI_Command.h>
9 #include <ModelAPI_Feature.h>
10
11 #include <QMap>
12 #include <QObject>
13
14 #include <string>
15
16 #include <boost/shared_ptr.hpp>
17
18 class QMouseEvent;
19 class QKeyEvent;
20 class PartSet_Listener;
21 class ModelAPI_Feature;
22 class XGUI_ViewerPrs;
23 class ModuleBase_Operation;
24
25 class PARTSET_EXPORT PartSet_Module: public ModuleBase_IModule
26 {
27 Q_OBJECT
28
29 public:
30   PartSet_Module(XGUI_Workshop* theWshop);
31   virtual ~PartSet_Module();
32
33   /// Returns the module workshop
34   /// \returns a workshop instance
35   XGUI_Workshop* workshop() const;
36
37   /// Reads description of features from XML file 
38   virtual void createFeatures();
39
40   /// Called on creation of menu item in desktop
41   virtual void featureCreated(QAction* theFeature);
42
43   /// Returnc list of nested commands for the given feature
44   virtual QStringList nestedFeatures(QString theFeature);
45   std::string featureFile(const std::string&);
46
47   /// Creates an operation and send it to loop
48   /// \param theCmdId the operation name
49   virtual void launchOperation(const QString& theCmdId);
50
51   /// Called when it is necessary to update a command state (enable or disable it)
52   virtual bool isFeatureEnabled(const QString& theCmdId) const;
53
54   /// Displays or erase the current operation preview, if it has it.
55   /// \param theFeature the feature instance to be displayed
56   /// \param isDisplay the state whether the presentation should be displayed or erased
57   /// \param isUpdateViewer the flag whether the viewer should be updated
58   void visualizePreview(FeaturePtr theFeature, bool isDisplay,
59                         const bool isUpdateViewer = true);
60
61   /// Activates the feature in the displayer
62   /// \param theFeature the feature instance to be displayed
63   /// \param isUpdateViewer the flag whether the viewer should be updated
64   void activateFeature(FeaturePtr theFeature,
65                        const bool isUpdateViewer);
66
67   /// Updates current operation preview, if it has it.
68   /// \param theCmdId the operation name
69   void updateCurrentPreview(const std::string& theCmdId);
70
71 public slots:
72   void onFeatureTriggered();
73   /// SLOT, that is called after the operation is started. Connect on the focus activated signal
74   void onOperationStarted();
75   /// SLOT, that is called after the operation is stopped. Switched off the modfications performed
76   /// by the operation start
77   void onOperationStopped(ModuleBase_Operation* theOperation);
78   /// SLOT, that is called afetr the popup menu action clicked.
79   void onContextMenuCommand(const QString& theId, bool isChecked);
80   /// SLOT, that is called by mouse press in the viewer.
81   /// The mouse released point is sent to the current operation to be processed.
82   /// \param theEvent the mouse event
83   void onMousePressed(QMouseEvent* theEvent);
84   /// SLOT, that is called by mouse release in the viewer.
85   /// The mouse released point is sent to the current operation to be processed.
86   /// \param theEvent the mouse event
87   void onMouseReleased(QMouseEvent* theEvent);
88   /// SLOT, that is called by mouse move in the viewer.
89   /// The mouse moved point is sent to the current operation to be processed.
90   /// \param theEvent the mouse event
91   void onMouseMoved(QMouseEvent* theEvent);
92
93   /// SLOT, that is called by the key in the viewer is clicked.
94   /// \param theEvent the mouse event
95   void onKeyRelease(QKeyEvent* theEvent);
96
97   /// SLOT, that is called by the mouse double click in the viewer.
98   /// \param theEvent the mouse event
99   void onMouseDoubleClick(QMouseEvent* theEvent);
100
101   /// SLOT, to apply to the current viewer the operation
102   /// \param theX the X projection value
103   /// \param theY the Y projection value
104   /// \param theZ the Z projection value
105   void onPlaneSelected(double theX, double theY, double theZ);
106
107   /// SLOT, to fit all current viewer
108   void onFitAllView();
109
110   void onLaunchOperation(std::string theName, FeaturePtr theFeature);
111
112   /// SLOT, to switch on/off the multi selection in the viewer
113   /// \param theEnabled the enabled state
114   void onMultiSelectionEnabled(bool theEnabled);
115
116   /// SLOT, to stop or start selection mode for the features
117   /// \param theFeatures a list of features to be disabled
118   /// \param theToStop the boolean state whether it it stopped or non stopped
119   void onStopSelection(const QFeatureList& theFeatures, const bool isStop);
120
121   /// SLOT, to set selection
122   /// \param theFeatures a list of features to be selected
123   void onSetSelection(const QFeatureList& theFeatures);
124
125   /// SLOT, to close the viewer local context
126   void onCloseLocalContext();
127
128   /// SLOT, to visualize the feature in another local context mode
129   /// \param theFeature the feature to be put in another local context mode
130   /// \param theMode the mode appeared on the feature
131   void onFeatureConstructed(FeaturePtr theFeature,
132                             int theMode);
133
134   /// Slot which reacts to the point 2d set to the feature. Creates a constraint
135   /// \param the feature
136   /// \param the attribute of the feature
137   void onStorePoint2D(FeaturePtr theFeature, const std::string& theAttribute);
138
139 protected:
140   /// Creates a new operation
141   /// \param theCmdId the operation name
142   /// \param theFeatureKind a kind of feature to get the feature xml description
143   ModuleBase_Operation* createOperation(const std::string& theCmdId,
144                                         const std::string& theFeatureKind = "");
145
146   /// Sends the operation
147   /// \param theOperation the operation
148   void sendOperation(ModuleBase_Operation* theOperation);
149
150 protected:
151   //! Edits the feature
152   void editFeature(FeaturePtr theFeature);
153
154 private:
155   XGUI_Workshop* myWorkshop;
156   PartSet_Listener* myListener;
157
158   std::map<std::string, std::string> myFeaturesInFiles;
159 };
160
161 #endif