Salome HOME
1dea45a20aa9607f7d416951524bef3b1cc921d4
[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("SALOME_SITE_DIR")) {
74       dir = QAD_Tools::addSlash(dir) ;
75       dir = dir + "lib" ;
76       dir = QAD_Tools::addSlash(dir) ;
77 #ifdef WNT
78       dir = dir + "libOCCViewer.dll" ;
79 #else
80       dir = dir + "libOCCViewer.so" ;
81 #endif
82       MESSAGE ( " GUI library = " << dir )
83       fileInfo.setFile(dir) ;
84       if (fileInfo.exists()) {
85         ComponentLib = fileInfo.fileName();
86         found = true;
87         MESSAGE (" Found ")
88       } else
89         MESSAGE (" Not found ")
90     }
91     
92     if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
93       dir = QAD_Tools::addSlash(dir) ;
94       dir = dir + "lib" ;
95       dir = QAD_Tools::addSlash(dir) ;
96 #ifdef WNT
97       dir = dir + "libOCCViewer.dll" ;
98 #else
99       dir = dir + "libOCCViewer.so" ;
100 #endif
101       MESSAGE ( " GUI library = " << dir )
102       fileInfo.setFile(dir) ;
103       if (fileInfo.exists()) {
104         ComponentLib = fileInfo.fileName();
105         found = true;
106         MESSAGE (" Found ")
107       } else
108         MESSAGE (" Not found ")
109     }
110     
111     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
112       dir = QAD_Tools::addSlash(dir) ;
113       dir = dir + "lib" ;
114       dir = QAD_Tools::addSlash(dir) ;
115       dir = dir + "salome" ;
116       dir = QAD_Tools::addSlash(dir) ;
117 #ifdef WNT
118       dir = dir + "libOCCViewer.dll" ;
119 #else
120       dir = dir + "libOCCViewer.so" ;
121 #endif
122       MESSAGE ( " GUI library = " << dir )
123       fileInfo.setFile(dir) ;
124       if (fileInfo.exists()) {
125         ComponentLib = fileInfo.fileName();
126         found = true;
127         MESSAGE (" Found ")
128       } else
129         MESSAGE (" Not found ")
130     }
131   } else if (myViewType == VIEW_VTK) {
132     
133     if ( dir = getenv("SALOME_SITE_DIR")) {
134       dir = QAD_Tools::addSlash(dir) ;
135       dir = dir + "lib" ;
136       dir = QAD_Tools::addSlash(dir) ;
137 #ifdef WNT
138       dir = dir + "libVTKViewer.dll" ;
139 #else
140       dir = dir + "libVTKViewer.so" ;
141 #endif
142       MESSAGE ( " GUI library = " << dir );
143       fileInfo.setFile(dir) ;
144       if (fileInfo.exists()) {
145         ComponentLib = fileInfo.fileName();
146         found = true;
147         MESSAGE (" Found ");
148       } else
149         MESSAGE (" Not found ");
150     }
151         
152     if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
153       dir = QAD_Tools::addSlash(dir) ;
154       dir = dir + "lib" ;
155       dir = QAD_Tools::addSlash(dir) ;
156 #ifdef WNT
157       dir = dir + "libVTKViewer.dll" ;
158 #else
159       dir = dir + "libVTKViewer.so" ;
160 #endif
161       MESSAGE ( " GUI library = " << dir );
162       fileInfo.setFile(dir) ;
163       if (fileInfo.exists()) {
164         ComponentLib = fileInfo.fileName();
165         found = true;
166         MESSAGE (" Found ");
167       } else
168         MESSAGE (" Not found ");
169     }
170         
171     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
172       dir = QAD_Tools::addSlash(dir) ;
173       dir = dir + "lib" ;
174       dir = QAD_Tools::addSlash(dir) ;
175       dir = dir + "salome" ;
176       dir = QAD_Tools::addSlash(dir) ;
177 #ifdef WNT
178       dir = dir + "libVTKViewer.dll" ;
179 #else
180       dir = dir + "libVTKViewer.so" ;
181 #endif
182       MESSAGE ( " GUI library = " << dir );
183       fileInfo.setFile(dir) ;
184       if (fileInfo.exists()) {
185         ComponentLib = fileInfo.fileName();
186         found = true;
187         MESSAGE (" Found ");
188       } else
189         MESSAGE (" Not found ");
190     }
191   } else if (myViewType == VIEW_GRAPHSUPERV) {
192     if ( dir = getenv("SALOME_SITE_DIR")){
193       dir = QAD_Tools::addSlash(dir) ;
194       dir = dir + "lib" ;
195       dir = QAD_Tools::addSlash(dir) ;
196 #ifdef WNT
197       dir = dir + "libSUPERVGraph.dll" ;
198 #else
199       dir = dir + "libSUPERVGraph.so" ;
200 #endif
201       MESSAGE ( " GUI library = " << dir )
202       fileInfo.setFile(dir) ;
203       if (fileInfo.exists()) {
204         ComponentLib = fileInfo.fileName() ;
205         found = true;
206         MESSAGE (" Found ")
207       } else
208         MESSAGE (" Not found ")
209     }
210     
211     if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
212       dir = QAD_Tools::addSlash(dir) ;
213       dir = dir + "lib" ;
214       dir = QAD_Tools::addSlash(dir) ;
215 #ifdef WNT
216       dir = dir + "libSUPERVGraph.dll" ;
217 #else
218       dir = dir + "libSUPERVGraph.so" ;
219 #endif
220       MESSAGE ( " GUI library = " << dir )
221       fileInfo.setFile(dir) ;
222       if (fileInfo.exists()) {
223         ComponentLib = fileInfo.fileName() ;
224         found = true;
225         MESSAGE (" Found ")
226       } else
227         MESSAGE (" Not found ")
228     }
229     
230     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
231       dir = QAD_Tools::addSlash(dir) ;
232       dir = dir + "lib" ;
233       dir = QAD_Tools::addSlash(dir) ;
234       dir = dir + "salome" ;
235       dir = QAD_Tools::addSlash(dir) ;
236 #ifdef WNT
237       dir = dir + "libSUPERVGraph.dll" ;
238 #else
239       dir = dir + "libSUPERVGraph.so" ;
240 #endif
241       MESSAGE ( " GUI library = " << dir )
242       fileInfo.setFile(dir) ;
243       if (fileInfo.exists()) {
244         ComponentLib = fileInfo.fileName() ;
245         found = true;
246         MESSAGE (" Found ")
247       } else
248         MESSAGE (" Not found ")
249     }
250   } else if (myViewType == VIEW_PLOT2D) {
251     if ( dir = getenv("SALOME_SITE_DIR")){
252       dir = QAD_Tools::addSlash(dir) ;
253       dir = dir + "lib" ;
254       dir = QAD_Tools::addSlash(dir) ;
255 #ifdef WNT
256       dir = dir + "libPlot2d.dll" ;
257 #else
258       dir = dir + "libPlot2d.so" ;
259 #endif
260       MESSAGE ( " GUI library = " << dir )
261       fileInfo.setFile(dir) ;
262       if (fileInfo.exists()) {
263         ComponentLib = fileInfo.fileName() ;
264         found = true;
265         MESSAGE (" Found ")
266       } else
267         MESSAGE (" Not found ")
268     }
269     
270     if ( (dir = getenv("SALOME_ROOT_DIR")) && !found ) {
271       dir = QAD_Tools::addSlash(dir) ;
272       dir = dir + "lib" ;
273       dir = QAD_Tools::addSlash(dir) ;
274 #ifdef WNT
275       dir = dir + "libPlot2d.dll" ;
276 #else
277       dir = dir + "libPlot2d.so" ;
278 #endif
279       MESSAGE ( " GUI library = " << dir )
280       fileInfo.setFile(dir) ;
281       if (fileInfo.exists()) {
282         ComponentLib = fileInfo.fileName() ;
283         found = true;
284         MESSAGE (" Found ")
285       } else
286         MESSAGE (" Not found ")
287     }
288     
289     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
290       dir = QAD_Tools::addSlash(dir) ;
291       dir = dir + "lib" ;
292       dir = QAD_Tools::addSlash(dir) ;
293       dir = dir + "salome" ;
294       dir = QAD_Tools::addSlash(dir) ;
295 #ifdef WNT
296       dir = dir + "libPlot2d.dll" ;
297 #else
298       dir = dir + "libPlot2d.so" ;
299 #endif
300       MESSAGE ( " GUI library = " << dir )
301       fileInfo.setFile(dir) ;
302       if (fileInfo.exists()) {
303         ComponentLib = fileInfo.fileName() ;
304         found = true;
305         MESSAGE (" Found ")
306       } else
307         MESSAGE (" Not found ")
308     }
309   } else {
310     QMessageBox::critical( this,
311                            tr("ERR_ERROR"),
312                            tr("undefined view type") );
313     return;
314   }
315
316   SharedLib.SetName( strdup(ComponentLib) );
317   
318   bool ok = SharedLib.DlOpen(OSD_RTLD_LAZY);
319   if (!ok) {
320     QMessageBox::critical( this,
321                            tr("ERR_ERROR"),
322                            tr( SharedLib.DlError() ) );
323     return;
324   } else {
325     OSD_Function osdF = SharedLib.DlSymb("createView");
326     if ( osdF != NULL ) {
327       View (*f1) = (QAD_ViewFrame* (*) (QAD_RightFrame*)) osdF;
328       myViewFrame = (*f1)(this);
329     } else {
330       QMessageBox::critical( this,
331                              tr("ERR_ERROR"),
332                              tr("createView undefined") );
333       return;
334     }
335   }
336
337   QValueList<int> sizes;
338
339   myViewFrame->setMinimumSize( 1, 1 );
340   vsplitter = new QAD_Splitter( Qt::Horizontal, this );
341   vsplitter->setMinimumSize( 1, 1 );
342   vsplitter->setCompressEnabled( true );
343   myPyEditor = new QAD_PyEditor(_interp, vsplitter ,"Python Interpreter");
344   myPyEditor->setMinimumSize( 1, 1 );
345   myMessage  = new QAD_Message( vsplitter ,"Message");  
346   myMessage->setMinimumSize( 1, 1 );
347
348   sizes.append( (int)(0.48 * DesktopHeight) );
349   sizes.append( (int)(0.16 * DesktopHeight) );
350   setSizes( sizes );
351   sizes.clear();
352   sizes.append( (int)(0.25 * DesktopWidth) );
353   sizes.append( (int)(0.25 * DesktopWidth) );
354   vsplitter->setSizes( sizes );
355 }
356
357 /*!
358     Destructor
359 */
360 QAD_RightFrame::~QAD_RightFrame()
361 {  
362 }
363
364 QAD_ViewFrame* QAD_RightFrame::getViewFrame() const
365 {
366   return myViewFrame;
367 }
368
369 /*!
370     Returns reference to the message window [ static ]
371 */
372 QAD_Message* QAD_RightFrame::getMessage() const
373 {
374   return myMessage;
375 }
376
377 /*!
378   Returns the Python interpreter that belongs to this study
379 */
380 QAD_PyInterp* QAD_RightFrame::get_PyInterp(void)
381 {
382   return _interp;
383 }
384
385 /*!
386     Returns reference to the Python window [ static ]
387 */
388 QAD_PyEditor* QAD_RightFrame::getPyEditor() const
389 {
390   return myPyEditor;
391 }
392
393 /*!
394     Compress views
395 */
396 void QAD_RightFrame::compressUp()
397 {
398   QSplitterPHandle* h = getHandleAfter(myViewFrame);
399   if (h)
400     h->compressBefore();
401 }
402
403 /*!
404     Uncompress views
405 */
406 void QAD_RightFrame::unCompressUp()
407 {
408   QSplitterPHandle* h = getHandleAfter(myViewFrame);
409   if (h)
410     h->unCompressBefore();
411 }
412
413 /*!
414     Compress Python Interpreter and Messages windows
415 */
416 void QAD_RightFrame::compressBottom()
417 {
418   QSplitterPHandle* h = getHandleAfter(myViewFrame);
419   if (h)
420     h->compressAfter();
421 }
422
423 /*!
424     Uncompress Python Interpreter and Messages windows
425 */
426 void QAD_RightFrame::unCompressBottom()
427 {
428   QSplitterPHandle* h = getHandleAfter(myViewFrame);
429   if (h)
430     h->unCompressAfter();
431 }
432