Salome HOME
Merge with PAL/SALOME 2.1.0d
[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 #include "SalomePyQt.hxx"
9
10 #include <qapplication.h>
11 #include <qmenubar.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 using namespace std;
25
26 QWidget* SalomePyQt::getDesktop()
27 {
28   return (QWidget*)(QAD_Application::getDesktop());
29 }
30
31 QWorkspace* SalomePyQt::getMainFrame()
32 {
33   return (QWorkspace*)(QAD_Application::getDesktop()->getMainFrame());
34 }
35
36 QMenuBar* SalomePyQt::getMainMenuBar() 
37 {
38   return (QMenuBar*)(QAD_Application::getDesktop()->getMainMenuBar());
39 }
40
41 int SalomePyQt::getStudyId()
42 {
43   return QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()->getStudyId();
44 }
45
46 SALOME_Selection* SalomePyQt::getSelection()
47 {
48   return SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()->getSelection());
49 }
50
51 void SalomePyQt::putInfo( const QString& msg )
52 {
53   QAD_Application::getDesktop()->putInfo(msg);
54 }
55
56 void SalomePyQt::putInfo( const QString& msg, int ms )
57 {
58   QAD_Application::getDesktop()->putInfo(msg, ms);
59 }
60
61 void SalomePyQt::updateObjBrowser( int studyId, bool updateSelection)
62 {  
63   QList<QAD_Study>& studies = QAD_Application::getDesktop()->getActiveApp()->getStudies();
64   for ( QAD_Study* study = studies.first(); study; study = studies.next() )  {
65     if ( study->getStudyId() == studyId ) {
66       study->updateObjBrowser( updateSelection );
67       break;
68     }
69   }
70 }
71
72 const QString& SalomePyQt::getActiveComponent()
73 {
74   return QAD_Application::getDesktop()->getActiveComponent();
75 }
76
77 void SalomePyQt::addStringSetting(QString _name, QString _value, bool _autoValue)
78 {
79   QAD_CONFIG->addSetting(_name, _value, _autoValue);
80 }
81
82 void SalomePyQt::addIntSetting(QString _name, int _value, bool _autoValue)
83 {
84   QAD_CONFIG->addSetting(_name, _value, _autoValue);
85 }
86
87 void SalomePyQt::addDoubleSetting(QString _name, double _value, bool _autoValue)
88 {
89   QAD_CONFIG->addSetting(_name, _value, _autoValue);
90 }
91
92 bool SalomePyQt::removeSettings(QString name)
93 {
94   return QAD_CONFIG->removeSettings( name );
95 }
96
97 QString SalomePyQt::getSetting(QString name)
98 {
99   return QAD_CONFIG->getSetting(name);
100 }
101
102 QString SalomePyQt::getFileName(QWidget*           parent, 
103                                 const QString&     initial, 
104                                 const QStringList& filters, 
105                                 const QString&     caption,
106                                 bool               open)
107 {
108   return QAD_FileDlg::getFileName(parent, initial, filters, caption, open);
109 }
110
111 QStringList SalomePyQt::getOpenFileNames(QWidget*           parent, 
112                                          const QString&     initial, 
113                                          const QStringList& filters, 
114                                          const QString&     caption)
115 {
116   return QAD_FileDlg::getOpenFileNames(parent, initial, filters, caption);
117 }
118
119 QString SalomePyQt::getExistingDirectory(QWidget*       parent,
120                                          const QString& initial,
121                                          const QString& caption)
122 {
123   return QAD_FileDlg::getExistingDirectory(parent, initial, caption);
124 }
125
126 void SalomePyQt::helpContext(const QString& source, const QString& context) {
127   //QAD_Application::getDesktop()->helpContext(source, context);
128 }
129
130 bool SalomePyQt::dumpView(const QString& filename)
131 {
132   QAD_Study* activeStudy = QAD_Application::getDesktop()->getActiveApp()->getActiveStudy();
133   if ( !activeStudy )
134     return false;
135   QAD_ViewFrame* activeViewFrame = activeStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
136   if ( !activeViewFrame )
137     return false;
138   if ( !activeViewFrame->getViewWidget() )
139     return false;
140
141   qApp->processEvents();
142   QPixmap px = QPixmap::grabWindow( activeViewFrame->getViewWidget()->winId() );
143   if ( !filename.isNull() ) {
144     QString fmt = QAD_Tools::getFileExtensionFromPath( filename ).upper();
145     if ( fmt.isEmpty() )
146       fmt = QString( "PNG" ); // default format
147     if ( fmt == "JPG" )
148       fmt = "JPEG";
149     bool bOk = px.save( filename, fmt.latin1() );
150     return bOk;
151   }
152   return false;
153 }
154
155 QPopupMenu* SalomePyQt::getPopupMenu( const MenuName menu )
156 {
157   QMenuBar* mainMenu = QAD_Application::getDesktop()->getMainMenuBar();
158   if ( mainMenu->findItem( menu ) ) {
159     return mainMenu->findItem( menu )->popup();
160   }
161   return 0;
162 }