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