Salome HOME
e821f22bae849129ab103e61ddff1f6aca23d173
[modules/kernel.git] / src / SALOME_PYQT / SalomePyQt.cxx
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : SalomePyQt.cxx
6 //  Module : SALOME
7
8 using namespace std;
9 #include "SalomePyQt.hxx"
10
11 #include <qapplication.h>
12
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "QAD_Study.h"
16 #include "QAD_FileDlg.h"
17 #include "QAD_ViewFrame.h"
18 #include "QAD_RightFrame.h"
19 #include "QAD_Tools.h"
20
21 #include "QAD_Config.h"
22 #include "QAD_Settings.h"
23
24 QWidget* SalomePyQt::getDesktop()
25 {
26   return (QWidget*)(QAD_Application::getDesktop());
27 }
28
29 QWorkspace* SalomePyQt::getMainFrame()
30 {
31   return (QWorkspace*)(QAD_Application::getDesktop()->getMainFrame());
32 }
33
34 QMenuBar* SalomePyQt::getMainMenuBar() 
35 {
36   return (QMenuBar*)(QAD_Application::getDesktop()->getMainMenuBar());
37 }
38
39 int SalomePyQt::getStudyId()
40 {
41   return QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()->getStudyId();
42 }
43
44 SALOME_Selection* SalomePyQt::getSelection()
45 {
46   return SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()->getSelection());
47 }
48
49 void SalomePyQt::putInfo( const QString& msg )
50 {
51   QAD_Application::getDesktop()->putInfo(msg);
52 }
53
54 void SalomePyQt::putInfo( const QString& msg, int ms )
55 {
56   QAD_Application::getDesktop()->putInfo(msg, ms);
57 }
58
59 void SalomePyQt::updateObjBrowser( int studyId, bool updateSelection)
60 {  
61   QList<QAD_Study>& studies = QAD_Application::getDesktop()->getActiveApp()->getStudies();
62   for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
63     if ( study->getStudyId() == studyId ) {
64       study->updateObjBrowser( updateSelection );
65       break;
66     }
67   }
68 }
69
70 const QString& SalomePyQt::getActiveComponent()
71 {
72   return QAD_Application::getDesktop()->getActiveComponent();
73 }
74
75 void SalomePyQt::addStringSetting(QString _name, QString _value, bool _autoValue)
76 {
77   QAD_CONFIG->addSetting(_name, _value, _autoValue);
78 }
79
80 void SalomePyQt::addIntSetting(QString _name, int _value, bool _autoValue)
81 {
82   QAD_CONFIG->addSetting(_name, _value, _autoValue);
83 }
84
85 void SalomePyQt::addDoubleSetting(QString _name, double _value, bool _autoValue)
86 {
87   QAD_CONFIG->addSetting(_name, _value, _autoValue);
88 }
89
90 bool SalomePyQt::removeSettings(QString name)
91 {
92   return QAD_CONFIG->removeSettings( name );
93 }
94
95 QString SalomePyQt::getSetting(QString name)
96 {
97   return QAD_CONFIG->getSetting(name);
98 }
99
100 QString SalomePyQt::getFileName(QWidget*           parent, 
101                                 const QString&     initial, 
102                                 const QStringList& filters, 
103                                 const QString&     caption,
104                                 bool               open)
105 {
106   return QAD_FileDlg::getFileName(parent, initial, filters, caption, open);
107 }
108
109 QStringList SalomePyQt::getOpenFileNames(QWidget*           parent, 
110                                          const QString&     initial, 
111                                          const QStringList& filters, 
112                                          const QString&     caption)
113 {
114   return QAD_FileDlg::getOpenFileNames(parent, initial, filters, caption);
115 }
116
117 QString SalomePyQt::getExistingDirectory(QWidget*       parent,
118                                          const QString& initial,
119                                          const QString& caption)
120 {
121   return QAD_FileDlg::getExistingDirectory(parent, initial, caption);
122 }
123
124 void SalomePyQt::helpContext(const QString& source, const QString& context) {
125   //QAD_Application::getDesktop()->helpContext(source, context);
126 }
127
128 bool SalomePyQt::dumpView(const QString& filename)
129 {
130   QAD_Study* activeStudy = QAD_Application::getDesktop()->getActiveApp()->getActiveStudy();
131   if ( !activeStudy )
132     return false;
133   QAD_ViewFrame* activeViewFrame = activeStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
134   if ( !activeViewFrame )
135     return false;
136   if ( !activeViewFrame->getViewWidget() )
137     return false;
138
139   qApp->processEvents();
140   QPixmap px = QPixmap::grabWindow( activeViewFrame->getViewWidget()->winId() );
141   if ( !filename.isNull() ) {
142     QString fmt = QAD_Tools::getFileExtensionFromPath( filename ).upper();
143     if ( fmt.isEmpty() )
144       fmt = QString( "PNG" ); // default format
145     if ( fmt == "JPG" )
146       fmt = "JPEG";
147     bool bOk = px.save( filename, fmt.latin1() );
148     return bOk;
149   }
150   return false;
151 }