Salome HOME
Porting to Mandrake 10.1 and new products:
[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 #include "QAD_PyEditor.h"  // this include must be first (see PyInterp_base.h)!
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 "QAD_PyInterp.h"
36
37 #include <qvaluelist.h>
38
39 // QT Include
40 #include <qmessagebox.h>
41
42 // Open CASCADE Include
43 #include <OSD_SharedLibrary.hxx>
44
45 using namespace std;
46
47 /*!
48   \class QAD_RightFrame QAD_RightFrame.h
49   \brief Frame window which contains QAD_ViewFrame, QAD_PyInterp and QAD_Message.
50 */
51
52 typedef QAD_ViewFrame* View(QAD_RightFrame*);
53
54
55 /*!
56     Constructor
57 */
58 QAD_RightFrame::QAD_RightFrame(QWidget *theParent, 
59                                const char *theTitle, ViewType theTypeView,
60                                QAD_PyInterp*& theInterp, QMutex* theMutex): 
61   QAD_Splitter( Qt::Vertical, theParent, theTitle ),
62   myViewType(theTypeView),
63   myInterp(theInterp)
64 {
65   this->setCompressEnabled( true );
66
67   QAD_Desktop* Desktop = QAD_Application::getDesktop();
68   int DesktopHeight = Desktop->getMainFrame()->width();
69   int DesktopWidth  = Desktop->getMainFrame()->height();
70
71   OSD_SharedLibrary SharedLib = OSD_SharedLibrary();
72   QString ComponentLib;
73   QCString dir;
74   QFileInfo fileInfo ;
75   bool found = false;
76   if (myViewType == VIEW_OCC) {    
77     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
78       dir = QAD_Tools::addSlash(dir) ;
79       dir = dir + "lib" ;
80       dir = QAD_Tools::addSlash(dir) ;
81       dir = dir + "salome" ;
82       dir = QAD_Tools::addSlash(dir) ;
83 #ifdef WNT
84       dir = dir + "libOCCViewer.dll" ;
85 #else
86       dir = dir + "libOCCViewer.so" ;
87 #endif
88       MESSAGE ( " GUI library = " << dir )
89       fileInfo.setFile(dir) ;
90       if (fileInfo.exists()) {
91         ComponentLib = fileInfo.fileName();
92         found = true;
93         MESSAGE (" Found ")
94       } else
95         MESSAGE (" Not found ")
96     }
97   } else if (myViewType == VIEW_VTK) {
98     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
99       dir = QAD_Tools::addSlash(dir) ;
100       dir = dir + "lib" ;
101       dir = QAD_Tools::addSlash(dir) ;
102       dir = dir + "salome" ;
103       dir = QAD_Tools::addSlash(dir) ;
104 #ifdef WNT
105       dir = dir + "libVTKViewer.dll" ;
106 #else
107       dir = dir + "libVTKViewer.so" ;
108 #endif
109       MESSAGE ( " GUI library = " << dir );
110       fileInfo.setFile(dir) ;
111       if (fileInfo.exists()) {
112         ComponentLib = fileInfo.fileName();
113         found = true;
114         MESSAGE (" Found ");
115       } else
116         MESSAGE (" Not found ");
117     }
118   } else if (myViewType == VIEW_GRAPHSUPERV) {
119     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
120       dir = QAD_Tools::addSlash(dir) ;
121       dir = dir + "lib" ;
122       dir = QAD_Tools::addSlash(dir) ;
123       dir = dir + "salome" ;
124       dir = QAD_Tools::addSlash(dir) ;
125 #ifdef WNT
126       dir = dir + "libSUPERVGraph.dll" ;
127 #else
128       dir = dir + "libSUPERVGraph.so" ;
129 #endif
130       MESSAGE ( " GUI library = " << dir )
131       fileInfo.setFile(dir) ;
132       if (fileInfo.exists()) {
133         ComponentLib = fileInfo.fileName() ;
134         found = true;
135         MESSAGE (" Found ")
136       } else
137         MESSAGE (" Not found ")
138     }
139   } else if (myViewType == VIEW_PLOT2D) {
140     if ( (dir = getenv("KERNEL_ROOT_DIR")) && !found ) {
141       dir = QAD_Tools::addSlash(dir) ;
142       dir = dir + "lib" ;
143       dir = QAD_Tools::addSlash(dir) ;
144       dir = dir + "salome" ;
145       dir = QAD_Tools::addSlash(dir) ;
146 #ifdef WNT
147       dir = dir + "libPlot2d.dll" ;
148 #else
149       dir = dir + "libPlot2d.so" ;
150 #endif
151       MESSAGE ( " GUI library = " << dir )
152       fileInfo.setFile(dir) ;
153       if (fileInfo.exists()) {
154         ComponentLib = fileInfo.fileName() ;
155         found = true;
156         MESSAGE (" Found ")
157       } else
158         MESSAGE (" Not found ")
159     }
160   } else {
161     QMessageBox::critical( this,
162                            tr("ERR_ERROR"),
163                            tr("undefined view type") );
164     return;
165   }
166
167   const Standard_CString aCopyCL = CORBA::string_dup(ComponentLib);
168   SharedLib.SetName( aCopyCL);
169   delete(aCopyCL);
170   
171   
172   bool ok = SharedLib.DlOpen(OSD_RTLD_LAZY);
173   if (!ok) {
174     QMessageBox::critical( this,
175                            tr("ERR_ERROR"),
176                            tr( SharedLib.DlError() ) );
177     return;
178   } else {
179     OSD_Function osdF = SharedLib.DlSymb("createView");
180     if ( osdF != NULL ) {
181       View (*f1) = (QAD_ViewFrame* (*) (QAD_RightFrame*)) osdF;
182       myViewFrame = (*f1)(this);
183     } else {
184       QMessageBox::critical( this,
185                              tr("ERR_ERROR"),
186                              tr("createView undefined") );
187       return;
188     }
189   }
190
191   QValueList<int> sizes;
192
193   myViewFrame->setMinimumSize( 1, 1 );
194   mySplitter = new QAD_Splitter( Qt::Horizontal, this );
195   mySplitter->setMinimumSize( 1, 1 );
196   mySplitter->setCompressEnabled( true );
197
198   myPyEditor = new QAD_PyEditor(myInterp, theMutex, mySplitter ,"Python Interpreter");
199   myPyEditor->setMinimumSize( 1, 1 );
200   myPyEditor->Init();
201
202   myMessage  = new QAD_Message( mySplitter ,"Message");  
203   myMessage->setMinimumSize( 1, 1 );
204
205   sizes.append( (int)(0.48 * DesktopHeight) );
206   sizes.append( (int)(0.16 * DesktopHeight) );
207   setSizes( sizes );
208   sizes.clear();
209   sizes.append( (int)(0.25 * DesktopWidth) );
210   sizes.append( (int)(0.25 * DesktopWidth) );
211   mySplitter->setSizes( sizes );
212 }
213
214 /*!
215     Destructor
216 */
217 QAD_RightFrame::~QAD_RightFrame()
218 {  
219 }
220
221 QAD_ViewFrame* QAD_RightFrame::getViewFrame() const
222 {
223   return myViewFrame;
224 }
225
226 /*!
227     Returns reference to the message window [ static ]
228 */
229 QAD_Message* QAD_RightFrame::getMessage() const
230 {
231   return myMessage;
232 }
233
234 /*!
235   Returns the Python interpreter that belongs to this study
236 */
237 QAD_PyInterp* QAD_RightFrame::get_PyInterp(void)
238 {
239   return myInterp;
240 }
241
242 /*!
243     Returns reference to the Python window [ static ]
244 */
245 QAD_PyEditor* QAD_RightFrame::getPyEditor() const
246 {
247   return myPyEditor;
248 }
249
250 /*!
251     Compress views
252 */
253 void QAD_RightFrame::compressUp()
254 {
255   QSplitterPHandle* h = getHandleAfter(myViewFrame);
256   if (h)
257     h->compressBefore();
258 }
259
260 /*!
261     Uncompress views
262 */
263 void QAD_RightFrame::unCompressUp()
264 {
265   QSplitterPHandle* h = getHandleAfter(myViewFrame);
266   if (h)
267     h->unCompressBefore();
268 }
269
270 /*!
271     Compress Python Interpreter and Messages windows
272 */
273 void QAD_RightFrame::compressBottom()
274 {
275   QSplitterPHandle* h = getHandleAfter(myViewFrame);
276   if (h)
277     h->compressAfter();
278 }
279
280 /*!
281     Uncompress Python Interpreter and Messages windows
282 */
283 void QAD_RightFrame::unCompressBottom()
284 {
285   QSplitterPHandle* h = getHandleAfter(myViewFrame);
286   if (h)
287     h->unCompressAfter();
288 }
289
290 void QAD_RightFrame::compressLeft()
291 {
292   QSplitterPHandle* h = mySplitter->getHandleAfter( getPyEditor() );
293   if( h )
294     h->compressBefore();
295 }
296
297 void QAD_RightFrame::compressRight()
298 {
299   QSplitterPHandle* h = mySplitter->getHandleAfter( getPyEditor() );
300   if( h )
301     h->compressAfter();
302 }
303
304 void QAD_RightFrame::unCompressLeft()
305 {
306   QSplitterPHandle* h = mySplitter->getHandleAfter( getPyEditor() );
307   if( h )
308     h->unCompressBefore();
309 }
310
311 void QAD_RightFrame::unCompressRight()
312 {
313   QSplitterPHandle* h = mySplitter->getHandleAfter( getPyEditor() );
314   if( h )
315     h->unCompressAfter();
316 }
317
318 bool QAD_RightFrame::isCompressedViewFrame() const
319 {
320     return isCompressed( myViewFrame );
321 }
322
323 bool QAD_RightFrame::isCompressedPython() const
324 {
325     return mySplitter->isCompressed( getPyEditor() );
326 }
327
328 bool QAD_RightFrame::isCompressedMessage() const
329 {
330     return mySplitter->isCompressed( getMessage() );
331 }
332