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