Salome HOME
9f7247fb033061ed649ec0fa9b5f350694726c2e
[modules/gui.git] / src / SALOME_PYQT / SalomePyQt / SalomePyQt.h
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : SalomePyQt.h
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 //
26 #ifndef SALOME_PYQT_H
27 #define SALOME_PYQT_H
28
29 #include <Python.h>
30
31 #include <QObject>
32 #include <QString>
33 #include <QColor>
34
35 #include <LightApp_Application.h>
36 #include <LightApp_Preferences.h>
37 #include <Plot2d_ViewFrame.h>
38
39 class LightApp_SelectionMgr;
40 class QMenuBar;
41 class QMenu;
42 class QWidget;
43 class QAction;
44 class QTreeView;
45 class QtxActionGroup;
46 class Plot2d_Curve;
47
48 class SALOME_Selection : public QObject
49 {
50   Q_OBJECT
51
52 public:
53   ~SALOME_Selection();
54   static SALOME_Selection* GetSelection( LightApp_Application* );
55
56   void Clear();
57   void ClearIObjects();
58   void ClearFilters();
59
60 signals:
61   void currentSelectionChanged();
62
63 private slots:
64   void onSelMgrDestroyed();
65
66 private:
67   LightApp_SelectionMgr* mySelMgr;
68   SALOME_Selection( QObject* );
69 };
70
71 enum MenuName {
72   File        = 1,
73   View        = 2,
74   Edit        = 3,
75   Preferences = 4,
76   Tools       = 5,
77   Window      = 6,
78   Help        = 7  
79 };
80
81 enum {
82   WT_ObjectBrowser = LightApp_Application::WT_ObjectBrowser,
83   WT_PyConsole     = LightApp_Application::WT_PyConsole,
84   WT_LogWindow     = LightApp_Application::WT_LogWindow,
85   WT_User          = LightApp_Application::WT_User
86 };
87
88 enum { 
89   PT_Auto     = LightApp_Preferences::Auto,
90   PT_Space    = LightApp_Preferences::Space,
91   PT_Bool     = LightApp_Preferences::Bool, 
92   PT_Color    = LightApp_Preferences::Color,
93   PT_String   = LightApp_Preferences::String, 
94   PT_Selector = LightApp_Preferences::Selector, 
95   PT_DblSpin  = LightApp_Preferences::DblSpin, 
96   PT_IntSpin  = LightApp_Preferences::IntSpin, 
97   PT_Double   = LightApp_Preferences::Double, 
98   PT_Integer  = LightApp_Preferences::Integer, 
99   PT_GroupBox = LightApp_Preferences::GroupBox, 
100   PT_Tab      = LightApp_Preferences::Tab, 
101   PT_Frame    = LightApp_Preferences::Frame, 
102   PT_Font     = LightApp_Preferences::Font, 
103   PT_DirList  = LightApp_Preferences::DirList, 
104   PT_File     = LightApp_Preferences::File, 
105 };
106
107 //! Orientation
108 enum Orientation {
109   Horizontal = 0, //!< Horizontal orientation 
110   Vertical   = 1  //!< Vertical orientation
111 };
112
113 //! Action of splitting corresponding to QtxWorkstack::SplitType enumeration
114 enum Action {
115   MoveWidget   = 0, //!< move specified widget to the new area, other views stay in the previous area
116   LeaveWidget  = 1, //!< specified widget stays in the old area, all other views are moved to the new area
117   SplitAt      = 2  //!< the view area is splitted in such a way, that specified view and all views which follow it, are moved to the new area
118 };
119
120 //! Type of titles in Plot3d View
121 enum ObjectType
122 {
123   MainTitle = Plot2d_ViewFrame::MainTitle,
124   XTitle = Plot2d_ViewFrame::XTitle,
125   YTitle = Plot2d_ViewFrame::YTitle,
126   Y2Title = Plot2d_ViewFrame::Y2Title,
127   XAxis = Plot2d_ViewFrame::XAxis,
128   YAxis = Plot2d_ViewFrame::YAxis,
129   Y2Axis = Plot2d_ViewFrame::Y2Axis
130 };
131
132 class SalomePyQt
133 {
134 public:
135   static QWidget*          getDesktop();
136   static QWidget*          getMainFrame();
137   static QMenuBar*         getMainMenuBar();
138   static QMenu*            getPopupMenu( const MenuName );
139   static QMenu*            getPopupMenu( const QString& );
140   static QTreeView*        getObjectBrowser();
141   static SALOME_Selection* getSelection();
142   static int               getStudyId();
143   static void              putInfo( const QString&, const int = 0 );
144   static const QString     getActiveComponent();
145   static PyObject*         getActivePythonModule();
146   static bool              activateModule( const QString& );
147   static void              updateObjBrowser( const int = 0, bool = true );
148
149   static bool              isModified();
150   static void              setModified( bool );
151
152   static QString           getFileName         ( QWidget*, const QString&, const QStringList&, const QString&, bool );
153   static QStringList       getOpenFileNames    ( QWidget*, const QString&, const QStringList&, const QString& );
154   static QString           getExistingDirectory( QWidget*, const QString&, const QString& );
155
156   static QString           createObject( const QString& parent = QString() );
157   static QString           createObject( const QString&, const QString&, const QString&, const QString& = QString() );
158
159   static void              removeObject( const QString&);
160   static void              removeChildren( const QString& = QString() );
161   static QStringList       getChildren( const QString& = QString(), const bool = false );
162   static void              setName( const QString&, const QString& );
163   static void              setIcon( const QString&, const QString& );
164   static void              setToolTip( const QString&, const QString& );
165   static QString           getName( const QString& );
166   static QString           getToolTip( const QString& );
167
168   static void              setColor( const QString&, const QColor& );
169   static QColor            getColor( const QString& );
170
171   static void              setReference( const QString&, const QString& ); 
172   static QString           getReference( const QString& );
173
174   static QIcon             loadIcon( const QString&, const QString& );
175
176   static void              helpContext( const QString&, const QString& );
177
178   static bool              dumpView( const QString&, const int = 0 );
179
180   static int               defaultMenuGroup();
181
182   static int               createTool( const QString& );
183   static int               createTool( const int,  const int,      const int = -1 );
184   static int               createTool( const int,  const QString&, const int = -1 );
185   static int               createTool( QAction*, const int,      const int = -1, const int = -1 );
186   static int               createTool( QAction*, const QString&, const int = -1, const int = -1 );
187
188   static int               createMenu( const QString&, const int = -1,
189                                        const int = -1, const int = -1, const int = -1 );
190   static int               createMenu( const QString&, const QString& = QString(), 
191                                        const int = -1, const int = -1, const int = -1 );
192   static int               createMenu( const int,      const int = -1,
193                                        const int = -1, const int = -1 );
194   static int               createMenu( const int,      const QString& = QString(), 
195                                        const int = -1, const int = -1 );
196   static int               createMenu( QAction*,     const int,      const int = -1, 
197                                        const int = -1, const int = -1 );
198   static int               createMenu( QAction*,     const QString&, const int = -1, 
199                                        const int = -1, const int = -1 );
200
201   static QAction*          createSeparator();
202
203   static QAction*          createAction( const int, const QString&,
204                                          const QString& = QString(), const QString& = QString(), 
205                                          const QString& = QString(), const int = 0, const bool = false );
206   
207   static QtxActionGroup*   createActionGroup( const int, const bool = true );
208
209   static QAction*          action( const int );
210   static int               actionId( const QAction* );
211
212   static void              addSetting    ( const QString&, const QString&, const double );
213   static void              addSetting    ( const QString&, const QString&, const int );
214   static void              addSetting    ( const QString&, const QString&, const bool, const int );
215   static void              addSetting    ( const QString&, const QString&, const QString& );
216   static void              addSetting    ( const QString&, const QString&, const QColor& );
217   static int               integerSetting( const QString&, const QString&, const int = 0 );
218   static double            doubleSetting ( const QString&, const QString&, const double = 0 );
219   static bool              boolSetting   ( const QString&, const QString&, const bool = 0 );
220   static QString           stringSetting ( const QString&, const QString&, const QString& = QString("") );
221   static QColor            colorSetting  ( const QString&, const QString&, const QColor& = QColor() );
222   static void              removeSetting ( const QString&, const QString& );
223   static bool              hasSetting    ( const QString&, const QString& );
224
225   static int               addGlobalPreference( const QString& );
226   static int               addPreference( const QString& );
227   static int               addPreference( const QString&,
228                                           const int, const int = PT_Auto,
229                                           const QString& = QString(),
230                                           const QString& = QString() );
231   static QVariant          preferenceProperty( const int, const QString& );
232   static void              setPreferenceProperty( const int, const QString&, const QVariant& );
233   static void              addPreferenceProperty( const int, const QString&, const int, const QVariant& );
234
235   static void              message( const QString&, bool = true );
236   static void              clearMessages();
237   
238   static QList<int>        getViews();
239   static int               getActiveView();
240   static QString           getViewType( const int );
241   static bool              setViewTitle( const int, const QString& );
242   static QString           getViewTitle( const int );
243   static QList<int>        findViews( const QString& );
244   static bool              activateView( const int );
245   static int               createView( const QString&, bool visible = true, const int width = 0, const int height = 0 );
246   static int               createView( const QString&, QWidget* );
247   static bool              closeView( const int );
248   static int               cloneView( const int );
249   static void              setViewVisible( const int id, bool visible = true );
250   static bool              isViewVisible( const int );
251   static void              setViewClosable( const int, const bool );
252   static bool              isViewClosable( const int );
253
254   static bool              groupAllViews();
255   static bool              splitView( const int, const Orientation, const Action );
256   static bool              moveView( const int, const int, const bool );
257   static QList<int>        neighbourViews( const int );
258
259   static void              displayCurve(const int, Plot2d_Curve*);
260   static void              eraseCurve(const int, Plot2d_Curve*);
261   static void              eraseCurve(Plot2d_Curve*);
262   static void              updateCurves( const int );
263   static QString           getPlot2dTitle(const int, ObjectType = MainTitle);
264   static void              setPlot2dTitle(const int, const QString&, ObjectType = MainTitle, bool = true);
265   static QList<double>     getPlot2dFitRangeByCurves(const int);
266   static QList<double>     getPlot2dFitRangeCurrent(const int);
267   static void              setPlot2dFitRange(const int, const double XMin, const double XMax, const double YMin, const double YMax);
268
269   // the following methods are obsolete
270   static void              addStringSetting( const QString&, const QString&, bool = true );
271   static void              addIntSetting   ( const QString&, const int,      bool = true );
272   static void              addBoolSetting  ( const QString&, const bool,     bool = true );
273   static void              addDoubleSetting( const QString&, const double,   bool = true );
274   static void              removeSettings  ( const QString& );
275   static QString           getSetting      ( const QString& );
276
277   static void              removeChild( const QString& = QString() );
278 };
279
280 #endif // SALOME_PYQT_H