Salome HOME
This commit was generated by cvs2git to create tag 'V1_4_0b2'.
[modules/kernel.git] / src / SALOMEGUI / QAD_RightFrame.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : QAD_RightFrame.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include "QAD_RightFrame.h"
31 #include "QAD_Application.h"
32 #include "QAD_Desktop.h"
33 #include "QAD_StudyFrame.h"
34 #include "QAD_Tools.h"
35 #include <qvaluelist.h>
36
37 // QT Include
38 #include <qmessagebox.h>
39
40 // Open CASCADE Include
41 #include <OSD_SharedLibrary.hxx>
42
43 /*!
44   \class QAD_RightFrame QAD_RightFrame.h
45   \brief Frame window which contains QAD_ViewFrame, QAD_PyInterp and QAD_Message.
46 */
47
48 typedef QAD_ViewFrame* View(QAD_RightFrame*);
49
50
51 /*!
52     Constructor
53 */
54 QAD_RightFrame::QAD_RightFrame(QWidget *parent, const char *name,
55                                QAD_PyInterp* interp, ViewType vt)
56   : QAD_Splitter( Qt::Vertical, parent, name )
57 {
58   this->setCompressEnabled( true );
59   myViewType  = vt;
60
61   QAD_Desktop* Desktop = QAD_Application::getDesktop();
62   int DesktopHeight = Desktop->getMainFrame()->width();
63   int DesktopWidth  = Desktop->getMainFrame()->height();
64
65   _interp = interp;
66
67   OSD_SharedLibrary SharedLib = OSD_SharedLibrary();
68   QString ComponentLib;
69   QCString dir;
70   QFileInfo fileInfo ;
71   bool found = false;
72   if (myViewType == VIEW_OCC) {    
73     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
74       dir = QAD_Tools::addSlash(dir) ;
75       dir = dir + "lib" ;
76       dir = QAD_Tools::addSlash(dir) ;
77       dir = dir + "salome" ;
78       dir = QAD_Tools::addSlash(dir) ;
79 #ifdef WNT
80       dir = dir + "libOCCViewer.dll" ;
81 #else
82       dir = dir + "libOCCViewer.so" ;
83 #endif
84       MESSAGE ( " GUI library = " << dir )
85       fileInfo.setFile(dir) ;
86       if (fileInfo.exists()) {
87         ComponentLib = fileInfo.fileName();
88         found = true;
89         MESSAGE (" Found ")
90       } else
91         MESSAGE (" Not found ")
92     }
93   } else if (myViewType == VIEW_VTK) {
94     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
95       dir = QAD_Tools::addSlash(dir) ;
96       dir = dir + "lib" ;
97       dir = QAD_Tools::addSlash(dir) ;
98       dir = dir + "salome" ;
99       dir = QAD_Tools::addSlash(dir) ;
100 #ifdef WNT
101       dir = dir + "libVTKViewer.dll" ;
102 #else
103       dir = dir + "libVTKViewer.so" ;
104 #endif
105       MESSAGE ( " GUI library = " << dir );
106       fileInfo.setFile(dir) ;
107       if (fileInfo.exists()) {
108         ComponentLib = fileInfo.fileName();
109         found = true;
110         MESSAGE (" Found ");
111       } else
112         MESSAGE (" Not found ");
113     }
114   } else if (myViewType == VIEW_GRAPHSUPERV) {
115     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
116       dir = QAD_Tools::addSlash(dir) ;
117       dir = dir + "lib" ;
118       dir = QAD_Tools::addSlash(dir) ;
119       dir = dir + "salome" ;
120       dir = QAD_Tools::addSlash(dir) ;
121 #ifdef WNT
122       dir = dir + "libSUPERVGraph.dll" ;
123 #else
124       dir = dir + "libSUPERVGraph.so" ;
125 #endif
126       MESSAGE ( " GUI library = " << dir )
127       fileInfo.setFile(dir) ;
128       if (fileInfo.exists()) {
129         ComponentLib = fileInfo.fileName() ;
130         found = true;
131         MESSAGE (" Found ")
132       } else
133         MESSAGE (" Not found ")
134     }
135   } else if (myViewType == VIEW_PLOT2D) {
136     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
137       dir = QAD_Tools::addSlash(dir) ;
138       dir = dir + "lib" ;
139       dir = QAD_Tools::addSlash(dir) ;
140       dir = dir + "salome" ;
141       dir = QAD_Tools::addSlash(dir) ;
142 #ifdef WNT
143       dir = dir + "libPlot2d.dll" ;
144 #else
145       dir = dir + "libPlot2d.so" ;
146 #endif
147       MESSAGE ( " GUI library = " << dir )
148       fileInfo.setFile(dir) ;
149       if (fileInfo.exists()) {
150         ComponentLib = fileInfo.fileName() ;
151         found = true;
152         MESSAGE (" Found ")
153       } else
154         MESSAGE (" Not found ")
155     }
156   } else {
157     QMessageBox::critical( this,
158                            tr("ERR_ERROR"),
159                            tr("undefined view type") );
160     return;
161   }
162
163   SharedLib.SetName( strdup(ComponentLib) );
164   
165   bool ok = SharedLib.DlOpen(OSD_RTLD_LAZY);
166   if (!ok) {
167     QMessageBox::critical( this,
168                            tr("ERR_ERROR"),
169                            tr( SharedLib.DlError() ) );
170     return;
171   } else {
172     OSD_Function osdF = SharedLib.DlSymb("createView");
173     if ( osdF != NULL ) {
174       View (*f1) = (QAD_ViewFrame* (*) (QAD_RightFrame*)) osdF;
175       myViewFrame = (*f1)(this);
176     } else {
177       QMessageBox::critical( this,
178                              tr("ERR_ERROR"),
179                              tr("createView undefined") );
180       return;
181     }
182   }
183
184   QValueList<int> sizes;
185
186   myViewFrame->setMinimumSize( 1, 1 );
187   vsplitter = new QAD_Splitter( Qt::Horizontal, this );
188   vsplitter->setMinimumSize( 1, 1 );
189   vsplitter->setCompressEnabled( true );
190   myPyEditor = new QAD_PyEditor(_interp, vsplitter ,"Python Interpreter");
191   myPyEditor->setMinimumSize( 1, 1 );
192   myMessage  = new QAD_Message( vsplitter ,"Message");  
193   myMessage->setMinimumSize( 1, 1 );
194
195   sizes.append( (int)(0.48 * DesktopHeight) );
196   sizes.append( (int)(0.16 * DesktopHeight) );
197   setSizes( sizes );
198   sizes.clear();
199   sizes.append( (int)(0.25 * DesktopWidth) );
200   sizes.append( (int)(0.25 * DesktopWidth) );
201   vsplitter->setSizes( sizes );
202 }
203
204 /*!
205     Destructor
206 */
207 QAD_RightFrame::~QAD_RightFrame()
208 {  
209 }
210
211 QAD_ViewFrame* QAD_RightFrame::getViewFrame() const
212 {
213   return myViewFrame;
214 }
215
216 /*!
217     Returns reference to the message window [ static ]
218 */
219 QAD_Message* QAD_RightFrame::getMessage() const
220 {
221   return myMessage;
222 }
223
224 /*!
225   Returns the Python interpreter that belongs to this study
226 */
227 QAD_PyInterp* QAD_RightFrame::get_PyInterp(void)
228 {
229   return _interp;
230 }
231
232 /*!
233     Returns reference to the Python window [ static ]
234 */
235 QAD_PyEditor* QAD_RightFrame::getPyEditor() const
236 {
237   return myPyEditor;
238 }
239
240 /*!
241     Compress views
242 */
243 void QAD_RightFrame::compressUp()
244 {
245   QSplitterPHandle* h = getHandleAfter(myViewFrame);
246   if (h)
247     h->compressBefore();
248 }
249
250 /*!
251     Uncompress views
252 */
253 void QAD_RightFrame::unCompressUp()
254 {
255   QSplitterPHandle* h = getHandleAfter(myViewFrame);
256   if (h)
257     h->unCompressBefore();
258 }
259
260 /*!
261     Compress Python Interpreter and Messages windows
262 */
263 void QAD_RightFrame::compressBottom()
264 {
265   QSplitterPHandle* h = getHandleAfter(myViewFrame);
266   if (h)
267     h->compressAfter();
268 }
269
270 /*!
271     Uncompress Python Interpreter and Messages windows
272 */
273 void QAD_RightFrame::unCompressBottom()
274 {
275   QSplitterPHandle* h = getHandleAfter(myViewFrame);
276   if (h)
277     h->unCompressAfter();
278 }
279