Salome HOME
MPV: Merge V1_2d
[modules/visu.git] / src / VISU_I / VISU_ViewManager_i.cc
1 //  VISU OBJECT : interactive object for VISU entities implementation
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 //  File   : VISU_ViewManager_i.cc
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_ViewManager_i.hh"
28
29 #include "VISU_PrsObject_i.hh"
30 #include "VISU_Result_i.hh"
31
32 #include "VISU_Prs3d_i.hh"
33 #include "VISU_Mesh_i.hh"
34 #include "VISU_ScalarMap_i.hh"
35 #include "VISU_IsoSurfaces_i.hh"
36 #include "VISU_DeformedShape_i.hh"
37 #include "VISU_CutPlanes_i.hh"
38 #include "VISU_CutLines_i.hh"
39 #include "VISU_Vectors_i.hh"
40 #include "VISU_StreamLines_i.hh"
41
42 #include "VISU_Table_i.hh"
43 #include "VISU_ScalarBarActor.hxx"
44 #include "VISU_Actor.h"
45
46 #include "QAD_Application.h"
47 #include "QAD_Desktop.h"
48 #include "QAD_Tools.h"
49 #include "QAD_Study.h"
50 #include "QAD_RightFrame.h"
51 #include "QAD_StudyFrame.h"
52
53 #include "VTKViewer_ViewFrame.h"
54 #include "SALOMEGUI_TableDlg.h"
55 #include "Plot2d_CurveContainer.h"
56 #include "Plot2d_ViewFrame.h"
57
58 #include <memory>
59
60 #include <qstring.h>
61 #include <qfileinfo.h>
62
63 #include <vtkTransformPolyDataFilter.h>
64 #include <vtkDataSetMapper.h>
65 #include <vtkRenderer.h>
66 #include <vtkCamera.h>
67
68 using namespace std;
69
70 #ifdef _DEBUG_
71 static int MYDEBUG = 0;
72 #else
73 static int MYDEBUG = 0;
74 #endif
75
76 static QFileInfo aFileInfo;
77 static int MYDELAY = 1;
78
79 namespace VISU{
80   //===========================================================================
81   VTKViewer_ViewFrame* GetViewFrame(QAD_StudyFrame* theStudyFrame){
82     return dynamic_cast<VTKViewer_ViewFrame*>(theStudyFrame->getRightFrame()->getViewFrame());
83   }
84   vtkRenderer* GetRenderer(QAD_StudyFrame* theStudyFrame){
85     return GetViewFrame(theStudyFrame)->getRenderer();
86   }
87   vtkCamera* GetCamera(QAD_StudyFrame* theStudyFrame){
88     return GetRenderer(theStudyFrame)->GetActiveCamera();
89   }
90   void RepaintView(QAD_StudyFrame* theStudyFrame){
91     GetRenderer(theStudyFrame)->ResetCameraClippingRange();
92     GetViewFrame(theStudyFrame)->getRW()->getRenderWindow()->Render();
93     //GetViewFrame(theStudyFrame)->Repaint();
94   }
95   VISU_Actor* UpdateViewer(QAD_StudyFrame* theStudyFrame, int theDisplaing, Prs3d_i* thePrs){
96     VTKViewer_ViewFrame* vf = GetViewFrame(theStudyFrame);
97     if (!vf) return NULL;
98     if(MYDEBUG) MESSAGE("UpdateViewer - theDisplaing = "<<theDisplaing<<"; thePrs = "<<thePrs);
99     vtkRenderer *aRen = vf->getRenderer();
100     vtkActorCollection *anActColl = aRen->GetActors();
101     vtkActor *anActor;
102     VISU_Actor *anVISUActor = NULL, *aResActor = NULL;
103     for(anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL;){
104       if(anActor->IsA("VISU_Actor")){ 
105         anVISUActor = VISU_Actor::SafeDownCast(anActor);
106         if (thePrs == anVISUActor->GetPrs3d()) {
107           aResActor = anVISUActor->GetParent();
108           if(theDisplaing < eErase)
109             aResActor->VisibilityOn();
110           else
111             aResActor->VisibilityOff();
112         } else {
113           if(theDisplaing > eDisplay)
114             anVISUActor->VisibilityOff();
115           else
116             anVISUActor->VisibilityOn();
117         } 
118       }
119     }
120     if (aResActor) {
121       RepaintView(theStudyFrame);
122       return aResActor;
123     }
124     if(thePrs != NULL && theDisplaing < eErase){
125       try{
126         anVISUActor = thePrs->CreateActor();
127         vf->AddActor(anVISUActor);
128       }catch(std::runtime_error& exc){
129         INFOS(exc.what());
130         return NULL;
131       }
132     }
133     RepaintView(theStudyFrame);
134     return anVISUActor;
135   }
136   void UpdatePlot2d(Plot2d_ViewFrame *theView,int theDisplaying, Curve_i* theCurve) {
137     if(MYDEBUG) MESSAGE("UpdatePlot2d - theDisplaying = "<<theDisplaying);
138     if ( !theView )
139       return;
140     QList<Plot2d_Curve> clist;
141     theView->getCurves( clist );
142     if ( theDisplaying == eEraseAll ) {
143       for ( int i = 0; i < clist.count(); i++ ) {
144         if(MYDEBUG) MESSAGE("UpdatePlot2d - erasing all : curve - "<<clist.at( i ));
145         theView->eraseCurve( clist.at( i ) );
146       }
147     }
148     else if ( theDisplaying == eErase ) {
149       for ( int i = 0; i < clist.count(); i++ ) {
150         if ( theCurve && clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) {
151           if(MYDEBUG) MESSAGE("UpdatePlot2d - erasing : curve - "<<clist.at( i ) );
152           theView->eraseCurve( clist.at( i ) );
153         }
154       }
155     }
156     else if ( theDisplaying == eDisplay ) {
157       bool bFound = false;
158       for ( int i = 0; i < clist.count(); i++ ) {
159         if ( theCurve && clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) {
160           if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve - "<<clist.at( i ) );
161           clist.at( i )->setHorTitle( strdup( theCurve->GetHorTitle().c_str() ) );
162           clist.at( i )->setVerTitle( strdup( theCurve->GetVerTitle().c_str() ) );
163           clist.at( i )->setHorUnits( strdup( theCurve->GetHorUnits().c_str() ) );
164           clist.at( i )->setVerUnits( strdup( theCurve->GetVerUnits().c_str() ) );
165           /* - DATA NOT UPDATED */
166           if ( !clist.at( i )->isAutoAssign() ) {
167             clist.at( i )->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
168             clist.at( i )->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); 
169             SALOMEDS::Color color = theCurve->GetColor();
170             clist.at( i )->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
171             clist.at( i )->setAutoAssign( theCurve->IsAuto() );
172           }
173           theView->displayCurve( clist.at( i ) );
174           bFound = true;
175         }
176       }
177       if ( !bFound ) {
178         Plot2d_Curve* crv = theCurve->CreatePresentation();
179         if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying : curve (new) - "<<crv );
180         if ( crv )
181           theView->displayCurve( crv );
182       }
183     }
184     else if ( theDisplaying == eDisplayOnly ) {
185       bool bFound = false;
186       for ( int i = 0; i < clist.count(); i++ ) {
187         if ( theCurve && clist.at( i )->hasIO() && !strcmp( clist.at( i )->getIO()->getEntry(), theCurve->GetEntry() ) ) {
188           if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying only : curve - "<<clist.at( i ) );
189           clist.at( i )->setHorTitle( strdup( theCurve->GetHorTitle().c_str() ) );
190           clist.at( i )->setVerTitle( strdup( theCurve->GetVerTitle().c_str() ) );
191           clist.at( i )->setHorUnits( strdup( theCurve->GetHorUnits().c_str() ) );
192           clist.at( i )->setVerUnits( strdup( theCurve->GetVerUnits().c_str() ) );
193           /* - DATA NOT UPDATED */
194           if ( !clist.at( i )->isAutoAssign() ) {
195             clist.at( i )->setLine( (Plot2d_Curve::LineType)theCurve->GetLine(), theCurve->GetLineWidth() );
196             clist.at( i )->setMarker( (Plot2d_Curve::MarkerType)theCurve->GetMarker() ); 
197             SALOMEDS::Color color = theCurve->GetColor();
198             clist.at( i )->setColor( QColor( (int)(color.R*255.), (int)(color.G*255.), (int)(color.B*255.) ) );
199             clist.at( i )->setAutoAssign( theCurve->IsAuto() );
200           }
201           theView->displayCurve( clist.at( i ) );
202           bFound = true;
203         }
204         else {
205           theView->eraseCurve( clist.at( i ) );
206         }
207       }
208       if ( !bFound ) {
209         Plot2d_Curve* crv = theCurve->CreatePresentation();
210         if(MYDEBUG) MESSAGE("UpdatePlot2d - displaying only : curve (new) - "<<crv );
211         if ( crv )
212           theView->displayCurve( crv );
213       }
214     }
215   }
216   //===========================================================================
217   /*
218   #include <qthread.h> 
219   class TViewManager: public QThread{
220   public:
221     TViewManager(SALOMEDS::Study_ptr theStudy) : myStudyDocument(theStudy) {};
222     virtual void run(){
223       qApp->lock();
224       QAD_Desktop* aDesktop = QAD_Application::getDesktop();
225       QAD_Study* aStudy = aDesktop->findStudy(myStudyDocument);
226       if(!aStudy){
227         CORBA::String_var aName = myStudyDocument->Name();
228         aFileInfo.setFile(aName.in());
229         aStudy = aDesktop->loadStudy(aFileInfo.baseName());
230       }
231       qApp->unlock();
232     }
233     SALOMEDS::Study_ptr myStudyDocument;
234   };
235   */
236   ViewManager_i::ViewManager_i(SALOMEDS::Study_ptr theStudy) {
237     if(MYDEBUG) MESSAGE("ViewManager_i::ViewManager_i");
238     Mutex mt(myMutex,qApp,MYDELAY);
239     myStudyDocument = SALOMEDS::Study::_duplicate(theStudy);
240     //TViewManager* aTViewManager = new TViewManager(theStudy);
241     //aTViewManager->start();
242     QAD_Desktop* aDesktop = QAD_Application::getDesktop();
243     QAD_Study* aStudy = aDesktop->findStudy(theStudy);
244     if(!aStudy){
245         CORBA::String_var aName = theStudy->Name();
246         aFileInfo.setFile(aName.in());
247         if (aFileInfo.exists()) 
248           aStudy = aDesktop->loadStudy(aFileInfo.baseName());
249         else aStudy = aDesktop->loadStudy(aName.in());
250         if (!aStudy)
251           MESSAGE("ViewManager_i::ERROR: Can't load study");
252     }
253   }
254
255
256   VISU::View3D_ptr ViewManager_i::Create3DView(){
257     Mutex mt(myMutex,qApp,MYDELAY);
258     if(MYDEBUG) MESSAGE("ViewManager_i::Create3DView");
259     VISU::View3D_i* pView = new View3D_i(myStudyDocument);
260     if(pView->Create(1) != NULL) 
261       return VISU::View3D::_duplicate(pView->_this());
262     return VISU::View3D::_nil();
263   }
264
265
266   VISU::View_ptr ViewManager_i::GetCurrentView(){
267     Mutex mt(myMutex,qApp,MYDELAY);
268     QAD_Study* Study = QAD_Application::getDesktop()->findStudy( myStudyDocument );
269     if(MYDEBUG) MESSAGE("ViewManager_i::GetCurrent3DView - Study = "<<Study);
270     QAD_StudyFrame* StudyFrame;
271     if ( Study && ( StudyFrame = Study->getActiveStudyFrame() ) ) {
272       if(MYDEBUG) 
273         MESSAGE("ViewManager_i::GetCurrent3DView - TypeView = "<<StudyFrame->getTypeView());
274       if ( StudyFrame->getTypeView() == VIEW_VTK ) {
275         VISU::View3D_i* pView = new View3D_i(myStudyDocument);
276         if(pView->Create(0) != NULL) 
277           return VISU::View3D::_duplicate(pView->_this());
278       }
279       else if ( StudyFrame->getTypeView() == VIEW_PLOT2D ) {
280         VISU::XYPlot_i* pView = new XYPlot_i(myStudyDocument);
281         if(pView->Create(0) != NULL) 
282           return VISU::XYPlot::_duplicate(pView->_this());
283       }
284     }
285     return VISU::View::_nil();
286   }
287
288
289   VISU::XYPlot_ptr ViewManager_i::CreateXYPlot(){
290     if(MYDEBUG) MESSAGE("ViewManager_i::CreateXYPlot");
291     Mutex mt(myMutex,qApp,MYDELAY);
292     VISU::XYPlot_i* pView = new XYPlot_i(myStudyDocument);
293     if(pView->Create(1) != NULL) 
294       return VISU::XYPlot::_duplicate(pView->_this());
295     return VISU::XYPlot::_nil();
296   }
297
298
299   VISU::TableView_ptr ViewManager_i::CreateTableView(VISU::Table_ptr theTable){
300     if(MYDEBUG) MESSAGE("ViewManager_i::CreateTableView");
301     Mutex mt(myMutex,qApp,MYDELAY);
302     VISU::TableView_i* pView = new TableView_i(myStudyDocument);
303     if(pView->Create(VISU::Table::_duplicate(theTable)) != NULL) 
304       return VISU::TableView::_duplicate(pView->_this());
305     return VISU::TableView::_nil();
306   }
307
308
309   void ViewManager_i::Destroy(View_ptr theView){
310     if(MYDEBUG) MESSAGE("ViewManager_i::Destroy - "<<theView->_is_nil());
311     if(theView->_is_nil()) return;
312     CORBA::Object_var aView = VISU::View::_narrow(theView);
313     if(!CORBA::is_nil(aView)){
314       if(MYDEBUG) MESSAGE("ViewManager_i::Destroy - VISU::View"<<(!CORBA::is_nil(aView)));
315       VISU::View_i* pView = dynamic_cast<VISU::View_i*>(VISU::GetServant(aView).in());
316       if(MYDEBUG) MESSAGE("ViewManager_i::Destroy - dynamic_cast"<<pView);
317       if(pView) {
318         pView->Close();
319         pView->_remove_ref();
320       }
321       //if(pView) delete pView;
322       return;
323     }
324   }
325
326
327   void ViewManager_i::ProcessEvents() {
328     while (true) {
329       qApp->lock();
330       qApp->syncX();
331       qApp->flushX(); 
332       qApp->processEvents();
333       qApp->unlock();
334       //sleep(1);
335     }
336   }
337
338
339   //===========================================================================
340   View_i::View_i(SALOMEDS::Study_ptr theStudy) {
341     if(MYDEBUG) MESSAGE("View_i::View_i");
342     CORBA::String_var aName = theStudy->Name();
343     QAD_Desktop* aDesktop = QAD_Application::getDesktop();
344     myStudy = aDesktop->findStudy(theStudy);
345     if(!myStudy){
346       aFileInfo.setFile(aName.in());
347       if ( aFileInfo.exists() )
348         myStudy = aDesktop->loadStudy(aFileInfo.baseName());
349       else myStudy = aDesktop->loadStudy(aName.in());
350     }
351     if(MYDEBUG) MESSAGE("View_i::View_i - isStudyOpened = "<<myStudy<<"; aName = "<<aName.in());
352   }
353
354   View_i::~View_i(){
355     if(MYDEBUG) MESSAGE("View_i::~View_i");
356   }
357
358   void View_i::SetBackground(const SALOMEDS::Color& theColor) {}
359   SALOMEDS::Color View_i::GetBackground() { return SALOMEDS::Color();}
360   void View_i::Minimize() {}
361   void View_i::Restore() {}
362   void View_i::Maximize() {}
363   void View_i::EraseAll() {}
364   void View_i::DisplayAll() {}
365   void View_i::Erase(PrsObject_ptr thePrsObj) {}
366   void View_i::Display(PrsObject_ptr thePrsObj) {}
367   void View_i::DisplayOnly(PrsObject_ptr thePrsObj) {}
368   void View_i::Update() {}
369
370   CORBA::Boolean View_i::SavePicture(const char* theFileName) { return false; }
371
372   const char* View_i::GetComment() const { return "";}
373   void View_i::ToStream(std::ostringstream& theStr) {}
374
375   const char* View_i::GetEntry(){ 
376     SALOMEDS::SObject_var aSObject = myStudy->getStudyDocument()->FindObjectIOR(GetID());
377     CORBA::String_var anEntry = aSObject->GetID();
378     string aString(anEntry);
379     if(MYDEBUG) MESSAGE("Result_i::GetEntry - "<<aString);
380     return aString.c_str();
381   }
382   //===========================================================================
383   XYPlot_i::XYPlot_i(SALOMEDS::Study_ptr theStudy) : View_i(theStudy) {
384     if(MYDEBUG) MESSAGE("XYPlot_i::XYPlot_i");
385   }
386   Storable* XYPlot_i::Create(int theNew){
387     if(MYDEBUG) MESSAGE("XYPlot_i::Create");
388     Mutex mt(myMutex,qApp,MYDELAY);
389     if(theNew)
390       myStudyFrame = myStudy->newWindow3d("",VIEW_PLOT2D);
391     else
392       myStudyFrame = myStudy->getActiveStudyFrame();
393     myView = dynamic_cast<Plot2d_ViewFrame*>(myStudyFrame->getRightFrame()->getViewFrame());
394     Update();
395     return this;
396   } 
397   void XYPlot_i::Update() {
398     if(MYDEBUG) MESSAGE("XYPlot_i::Update");
399     Mutex mt(myMutex,qApp,MYDELAY);
400     myName = (const char*)(myStudyFrame->title());
401     myView->Repaint();
402   }
403   void XYPlot_i::Close(){
404     if(MYDEBUG) MESSAGE("XYPlot_i::Close");
405     Mutex mt(myMutex,qApp,MYDELAY);
406     myStudyFrame->close();
407   }
408   XYPlot_i::~XYPlot_i() {
409     if(MYDEBUG) MESSAGE("XYPlot_i::~XYPlot_i");
410     Mutex mt(myMutex,qApp,MYDELAY);
411     myStudyFrame->close();
412   }
413   void XYPlot_i::SetTitle(const char* theTitle){
414     if(MYDEBUG) MESSAGE("XYPlot_i::SetTitle");
415     Mutex mt(myMutex,qApp,MYDELAY);
416     myName = theTitle;
417     myStudyFrame->setCaption(myName.c_str());
418   }
419   char* XYPlot_i::GetTitle() {
420     if(MYDEBUG) MESSAGE("XYPlot_i::GetTitle");
421     Mutex mt(myMutex,qApp);
422     myName = (const char*)(myStudyFrame->title());
423     return CORBA::string_dup(myName.c_str());
424   }
425
426   void XYPlot_i::SetSubTitle(const char* theTitle){
427     if(MYDEBUG) MESSAGE("XYPlot_i::SetSubTitle");
428     Mutex mt(myMutex,qApp,MYDELAY);
429     myView->setTitle(theTitle);
430   }
431   char* XYPlot_i::GetSubTitle() {
432     if(MYDEBUG) MESSAGE("XYPlot_i::GetSubTitle");
433     Mutex mt(myMutex,qApp,MYDELAY);
434     return CORBA::string_dup(myView->getTitle());
435   }
436
437   void XYPlot_i::SetCurveType(VISU::XYPlot::CurveType theType){
438     if(MYDEBUG) MESSAGE("XYPlot_i::SetCurveType");
439     Mutex mt(myMutex,qApp,MYDELAY);
440     myView->setCurveType(theType);
441   }
442   VISU::XYPlot::CurveType XYPlot_i::GetCurveType(){
443     if(MYDEBUG) MESSAGE("XYPlot_i::GetCurveType");
444     Mutex mt(myMutex,qApp);
445     return (VISU::XYPlot::CurveType)myView->getCurveType();
446   }
447
448   void XYPlot_i::SetMarkerSize(CORBA::Long theSize){
449     if(MYDEBUG) MESSAGE("XYPlot_i::SetMarkerSize");
450     Mutex mt(myMutex,qApp,MYDELAY);
451     myView->setMarkerSize(theSize);
452   }
453   CORBA::Long XYPlot_i::GetMarkerSize(){
454     if(MYDEBUG) MESSAGE("XYPlot_i::GetMarkerSize");
455     Mutex mt(myMutex,qApp);
456     return myView->getMarkerSize();
457   }
458
459   void XYPlot_i::EnableXGrid(CORBA::Boolean theMajor, CORBA::Long theNumMajor, 
460                              CORBA::Boolean theMinor, CORBA::Long theNumMinor){
461     if(MYDEBUG) MESSAGE("XYPlot_i::EnableXGrid");
462     Mutex mt(myMutex,qApp,MYDELAY);
463     myView->setXGrid(theMajor,theNumMajor,theMinor,theNumMinor);
464   }
465   void XYPlot_i::EnableYGrid(CORBA::Boolean theMajor, CORBA::Long theNumMajor, 
466                              CORBA::Boolean theMinor, CORBA::Long theNumMinor){
467     if(MYDEBUG) MESSAGE("XYPlot_i::EnableYGrid");
468     Mutex mt(myMutex,qApp,MYDELAY);
469     myView->setYGrid(theMajor,theNumMajor,theMinor,theNumMinor);
470   }
471
472   void XYPlot_i::SetHorScaling(VISU::Scaling theScaling){
473     if(MYDEBUG) MESSAGE("XYPlot_i::SetHorScaling");
474     Mutex mt(myMutex,qApp,MYDELAY);
475     if(theScaling == VISU::LOGARITHMIC)
476       myView->setHorScaleMode(1);
477     else
478       myView->setHorScaleMode(0);
479   }
480   VISU::Scaling XYPlot_i::GetHorScaling(){
481     if(MYDEBUG) MESSAGE("XYPlot_i::GetHorScaling");
482     Mutex mt(myMutex,qApp,MYDELAY);
483     return (VISU::Scaling)myView->getHorScaleMode();
484   }
485
486   void XYPlot_i::SetVerScaling(VISU::Scaling theScaling){
487     if(MYDEBUG) MESSAGE("XYPlot_i::SetVerScaling");
488     Mutex mt(myMutex,qApp,MYDELAY);
489     if(theScaling == VISU::LOGARITHMIC)
490       myView->setVerScaleMode(1);
491     else
492       myView->setVerScaleMode(0);
493   }
494   VISU::Scaling XYPlot_i::GetVerScaling(){
495     if(MYDEBUG) MESSAGE("XYPlot_i::SetVerScaling");
496     Mutex mt(myMutex,qApp);
497     return (VISU::Scaling)myView->getVerScaleMode();
498   }
499
500   void XYPlot_i::SetXTitle(const char* theTitle){
501     if(MYDEBUG) MESSAGE("XYPlot_i::SetXTitle");
502     Mutex mt(myMutex,qApp,MYDELAY);
503     myView->setXTitle(true,theTitle);
504   }
505   char* XYPlot_i::GetXTitle() {
506     if(MYDEBUG) MESSAGE("XYPlot_i::GetXTitle");
507     Mutex mt(myMutex,qApp);
508     return CORBA::string_dup(myView->getXTitle());
509   }
510
511   void XYPlot_i::SetYTitle(const char* theTitle){
512     if(MYDEBUG) MESSAGE("XYPlot_i::SetYTitle");
513     Mutex mt(myMutex,qApp,MYDELAY);
514     myView->setYTitle(true,theTitle);
515   }
516   char* XYPlot_i::GetYTitle() {
517     if(MYDEBUG) MESSAGE("XYPlot_i::GetYTitle");
518     Mutex mt(myMutex,qApp);
519     return CORBA::string_dup(myView->getYTitle());
520   }
521
522   void XYPlot_i::ShowLegend(CORBA::Boolean theShowing){
523     if(MYDEBUG) MESSAGE("XYPlot_i::ShowLegend");
524     Mutex mt(myMutex,qApp,MYDELAY);
525     myView->showLegend(theShowing);
526   }
527
528   void XYPlot_i::SetBackground(const SALOMEDS::Color& theColor){
529     if(MYDEBUG) MESSAGE("XYPlot_i::SetBackground");
530     Mutex mt(myMutex,qApp,MYDELAY);
531     int aColor[3];
532     aColor[0] = (int)(255.0*theColor.R);
533     aColor[1] = (int)(255.0*theColor.G);
534     aColor[2] = (int)(255.0*theColor.B);
535     QColor aNewColor(aColor[0],aColor[1],aColor[2]);
536     myView->setBackgroundColor(aNewColor);
537   }
538   SALOMEDS::Color XYPlot_i::GetBackground() {
539     if(MYDEBUG) MESSAGE("XYPlot_i::GetBackground");
540     Mutex mt(myMutex,qApp);
541     SALOMEDS::Color aColor;
542     aColor.R = myView->backgroundColor().red()/255.0;
543     aColor.G = myView->backgroundColor().green()/255.0;
544     aColor.B = myView->backgroundColor().blue()/255.0;
545     return aColor;
546   }
547   void XYPlot_i::Minimize() {
548     if(MYDEBUG) MESSAGE("XYPlot_i::Minimize");
549     Mutex mt(myMutex,qApp,MYDELAY);
550     myStudyFrame->showMinimized();
551   }
552   void XYPlot_i::Restore() {
553     if(MYDEBUG) MESSAGE("XYPlot_i::Restore");
554     Mutex mt(myMutex,qApp,MYDELAY);
555     myStudyFrame->showNormal();
556   }
557   void XYPlot_i::Maximize() {
558     if(MYDEBUG) MESSAGE("XYPlot_i::Maximize");
559     Mutex mt(myMutex,qApp,MYDELAY);
560     myStudyFrame->showMaximized();
561   }
562   void XYPlot_i::Display(PrsObject_ptr thePrsObj) {
563     if(MYDEBUG) MESSAGE("XYPlot_i::Display"); 
564     Mutex mt(myMutex,qApp,MYDELAY);
565     CORBA::Object_ptr anObj = thePrsObj;
566     // is it Curve ?
567     if(Curve_i* aCurve =  dynamic_cast<Curve_i*>(VISU::GetServant(anObj).in())) {
568       UpdatePlot2d(myView,eDisplay,aCurve);
569     }
570     // is it Container ?
571     if(Container_i* aContainer =  dynamic_cast<Container_i*>(VISU::GetServant(anObj).in())) {
572       int nbCurves = aContainer->GetNbCurves();
573       for ( int i = 1; i <= nbCurves; i++ ) {
574         VISU::Curve_i* aCurve = aContainer->GetCurve( i );
575         if ( aCurve && aCurve->IsValid() ) {
576           UpdatePlot2d(myView,eDisplay,aCurve);
577         }
578       }
579       myView->Repaint();
580     }
581     // is it Table ?
582     if(Table_i* aTable =  dynamic_cast<Table_i*>(VISU::GetServant(anObj).in())) {
583       SALOMEDS::SObject_var TableSO = myStudy->getStudyDocument()->FindObjectID( aTable->GetEntry() );
584       if ( !TableSO->_is_nil() ) {
585         SALOMEDS::ChildIterator_var Iter = myStudy->getStudyDocument()->NewChildIterator( TableSO );
586           for ( ; Iter->More(); Iter->Next() ) {
587           CORBA::Object_var childObject = VISU::SObjectToObject( Iter->Value() );
588           if( !CORBA::is_nil( childObject ) ) {
589             CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
590             if( !CORBA::is_nil( aCurve ) )
591               UpdatePlot2d(myView,eDisplay,dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aCurve).in()));
592           }
593         }
594         myView->Repaint();
595       }
596     }
597   }
598   void XYPlot_i::Erase(PrsObject_ptr thePrsObj) {
599     if(MYDEBUG) MESSAGE("XYPlot_i::Erase"); 
600     Mutex mt(myMutex,qApp,MYDELAY);
601     CORBA::Object_ptr anObj = thePrsObj;
602     // is it Curve ?
603     if(Curve_i* aCurve =  dynamic_cast<Curve_i*>(VISU::GetServant(anObj).in())) {
604       UpdatePlot2d(myView,eErase,aCurve);
605     }
606     // is it Container ?
607     if(Container_i* aContainer =  dynamic_cast<Container_i*>(VISU::GetServant(anObj).in())) {
608       int nbCurves = aContainer->GetNbCurves();
609       for ( int i = 1; i <= nbCurves; i++ ) {
610         VISU::Curve_i* aCurve = aContainer->GetCurve( i );
611         if ( aCurve && aCurve->IsValid() ) {
612           UpdatePlot2d(myView,eErase,aCurve);
613         }
614       }
615       myView->Repaint();
616     }
617     // is it Table ?
618     if(Table_i* aTable =  dynamic_cast<Table_i*>(VISU::GetServant(anObj).in())) {
619       SALOMEDS::SObject_var TableSO = myStudy->getStudyDocument()->FindObjectID( aTable->GetEntry() );
620       if ( !TableSO->_is_nil() ) {
621         SALOMEDS::ChildIterator_var Iter = myStudy->getStudyDocument()->NewChildIterator( TableSO );
622           for ( ; Iter->More(); Iter->Next() ) {
623           CORBA::Object_var childObject = VISU::SObjectToObject( Iter->Value() );
624           if( !CORBA::is_nil( childObject ) ) {
625             CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
626             if( !CORBA::is_nil( aCurve ) )
627               UpdatePlot2d(myView,eErase,dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aCurve).in()));
628           }
629         }
630         myView->Repaint();
631       }
632     }
633   }
634   void XYPlot_i::EraseAll() {
635     if(MYDEBUG) MESSAGE("XYPlot_i::EraseAll");
636     Mutex mt(myMutex,qApp,MYDELAY);
637     myView->EraseAll();
638   }
639   void XYPlot_i::DisplayOnly(PrsObject_ptr thePrsObj) {
640     if(MYDEBUG) MESSAGE("XYPlot_i::DisplayOnly"); 
641     Mutex mt(myMutex,qApp,MYDELAY);
642     CORBA::Object_ptr anObj = thePrsObj;
643     // is it Curve ?
644     if(Curve_i* aCurve =  dynamic_cast<Curve_i*>(VISU::GetServant(anObj).in())) {
645       UpdatePlot2d(myView,eDisplayOnly,aCurve);
646     }
647     // is it Container ?
648     if(Container_i* aContainer =  dynamic_cast<Container_i*>(VISU::GetServant(anObj).in())) {
649       int nbCurves = aContainer->GetNbCurves();
650       for ( int i = 1; i <= nbCurves; i++ ) {
651         VISU::Curve_i* aCurve = aContainer->GetCurve( i );
652         if ( aCurve && aCurve->IsValid() ) {
653           UpdatePlot2d(myView,eDisplayOnly,aCurve);
654         }
655       }
656       myView->Repaint();
657     }
658     // is it Table ?
659     if(Table_i* aTable =  dynamic_cast<Table_i*>(VISU::GetServant(anObj).in())) {
660       SALOMEDS::SObject_var TableSO = myStudy->getStudyDocument()->FindObjectID( aTable->GetEntry() );
661       if ( !TableSO->_is_nil() ) {
662         SALOMEDS::ChildIterator_var Iter = myStudy->getStudyDocument()->NewChildIterator( TableSO );
663           for ( ; Iter->More(); Iter->Next() ) {
664           CORBA::Object_var childObject = VISU::SObjectToObject( Iter->Value() );
665           if( !CORBA::is_nil( childObject ) ) {
666             CORBA::Object_ptr aCurve = VISU::Curve::_narrow( childObject );
667             if( !CORBA::is_nil( aCurve ) )
668               UpdatePlot2d(myView,eDisplayOnly,dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aCurve).in()));
669           }
670         }
671         myView->Repaint();
672       }
673     }
674   }
675   void XYPlot_i::FitAll() {
676     if(MYDEBUG) MESSAGE("XYPlot_i::FitAll");
677     Mutex mt(myMutex,qApp,MYDELAY);
678     myView->fitAll();
679   }
680   CORBA::Boolean XYPlot_i::SavePicture(const char* theFileName) {
681     if(MYDEBUG) MESSAGE("XYPlot_i::SavePicture");
682     Mutex mt(myMutex,qApp,MYDELAY);
683     if (!myView->getViewWidget())
684       return false;
685
686     QApplication::setOverrideCursor( Qt::waitCursor );
687     QPixmap px = QPixmap::grabWindow(myView->getViewWidget()->winId());
688     QApplication::restoreOverrideCursor();
689     
690     if (!QString(theFileName).isNull()) {
691       QApplication::setOverrideCursor( Qt::waitCursor );
692       QString fmt = QAD_Tools::getFileExtensionFromPath(theFileName).upper();
693       if (fmt.isEmpty())
694         fmt = QString("BMP"); // default format
695       if (fmt == "JPG")
696         fmt = "JPEG";
697       bool bOk = px.save(theFileName, fmt.latin1());
698       QApplication::restoreOverrideCursor();
699       return bOk;
700     }
701     return false;
702   }
703
704   //===========================================================================
705   TableView_i::TableView_i(SALOMEDS::Study_ptr theStudy) : View_i(theStudy) {}
706   Storable* TableView_i::Create(VISU::Table_var theTable){
707     if(MYDEBUG) MESSAGE("TableView_i::Create - "<<(!theTable->_is_nil()));
708     Mutex mt(myMutex,qApp,MYDELAY);
709     if(!theTable->_is_nil()){
710       VISU::Table_i* table = dynamic_cast<VISU::Table_i*>(VISU::GetServant(theTable.in()).in());
711       if(MYDEBUG) MESSAGE("TableView_i::Create - dynamic_cast = "<<table);
712       if(table != NULL) {
713         SALOMEDS::SObject_var aSObject = myStudy->getStudyDocument()->FindObjectID(table->GetObjectEntry());
714         if(!aSObject->_is_nil()) {
715           myView = new SALOMEGUI_TableDlg(QAD_Application::getDesktop(),
716                                           aSObject,
717                                           false, 
718                                           SALOMEGUI_TableDlg::ttAuto, 
719                                           Qt::Vertical);
720           myView->show();
721           myName = (myView->caption()).latin1();
722           return this;
723         }
724       }
725     }
726     return NULL;
727   }
728   void TableView_i::SetTitle(const char* theTitle){
729     if(MYDEBUG) MESSAGE("TableView_i::SetTitle");
730     Mutex mt(myMutex,qApp,MYDELAY);
731     myName = theTitle;
732     myView->setCaption(myName.c_str());
733   }
734   char* TableView_i::GetTitle() {
735     if(MYDEBUG) MESSAGE("TableView_i::GetTitle");
736     Mutex mt(myMutex,qApp);
737     myName = (myView->caption()).latin1();
738     return CORBA::string_dup(myName.c_str());
739   }
740   void TableView_i::Close(){
741     if(MYDEBUG) MESSAGE("TableView_i::Close");
742     Mutex mt(myMutex,qApp,MYDELAY);
743     myView->close();
744   }
745   TableView_i::~TableView_i() {
746     if(MYDEBUG) MESSAGE("TableView_i::~TableView_i");
747     Mutex mt(myMutex,qApp,MYDELAY);
748     Close();
749     delete myView;
750   }
751   //===========================================================================
752   int View3D_i::myNbViewParams = 0;
753   const string View3D_i::myComment = "VIEW3D";
754   const char* View3D_i::GetComment() const { return myComment.c_str();}
755   QString View3D_i::GenerateViewParamsName() { 
756     return VISU::GenerateName( "ViewParams", ++myNbViewParams ); 
757   }
758
759   View3D_i::View3D_i(SALOMEDS::Study_ptr theStudy) : View_i(theStudy) {
760     if(MYDEBUG) MESSAGE("View3D_i::View3D_i");
761   }
762
763   Storable* View3D_i::Create(int theNew){
764     if(MYDEBUG) MESSAGE("View3D_i::Create");
765     if(theNew)
766       myStudyFrame = myStudy->newWindow3d("",VIEW_VTK);
767     else
768       myStudyFrame = myStudy->getActiveStudyFrame();
769
770     //GetViewFrame(myStudyFrame)->GetScale(myScaleFactor);
771
772     return this; //Build(false);
773   }
774
775 //   Storable* View3D_i::Build(int theRestoring){
776 //     if(MYDEBUG) MESSAGE("View3D_i::Build");
777 //     if(theRestoring){
778 //       myStudyFrame->setTitle(myName.c_str());
779 //       SetBackground(myColor);
780 //       SetPointOfView(myPosition);
781 //       SetViewUp(myViewUp);
782 //       SetFocalPoint(myFocalPnt);
783 //       SetParallelScale(myParallelScale);
784 //       ScaleView(VISU::View3D::XAxis,myScaleFactor[0]);
785 //       ScaleView(VISU::View3D::YAxis,myScaleFactor[1]);
786 //       ScaleView(VISU::View3D::ZAxis,myScaleFactor[2]);
787 //       RepaintView(myStudyFrame);
788 //     }else{
789 //       Update();
790       
791 //       SALOMEDS::SComponent_var aSComponent = FindOrCreateVisuComponent(myStudyDocument);
792 //       CORBA::String_var aSComponentEntry = aSComponent->GetID(), anIOR(GetID());
793 //       string anEntry = CreateAttributes(myStudyDocument,aSComponentEntry,"",anIOR,myName.c_str(),"",GetComment());
794       
795 //     }
796 //     return this;
797 //   }
798
799   void View3D_i::Update(){
800     if(MYDEBUG) MESSAGE("View3D_i::Update");
801     Mutex mt(myMutex,qApp,MYDELAY);
802     myName = (const char*)myStudyFrame->title();
803 //     myColor = GetBackground();
804 //     GetCamera(myStudyFrame)->GetPosition(myPosition);
805 //     GetCamera(myStudyFrame)->GetViewUp(myViewUp);
806 //     GetCamera(myStudyFrame)->GetFocalPoint(myFocalPnt);
807 //     myParallelScale = GetCamera(myStudyFrame)->GetParallelScale();
808     //RepaintView(myStudyFrame);
809
810     //GetViewFrame(myStudyFrame)->GetScale(myScaleFactor);
811
812     VTKViewer_ViewFrame* vf =  GetViewFrame(myStudyFrame);
813     vtkRenderer* Renderer = vf->getRenderer();
814     vtkActorCollection* theActors = Renderer->GetActors();
815     theActors->InitTraversal();
816     vtkActor *actor;
817     while(actor = theActors->GetNextActor()){
818       if(VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(actor)){
819         VISU::Prs3d_i* aPrs3d  = anActor->GetPrs3d();
820         if(anActor->GetVisibility() && aPrs3d){
821           aPrs3d->Update();
822           aPrs3d->UpdateActor(anActor);
823         }
824       }
825     }
826   }
827
828   CORBA::Boolean View3D_i::SavePicture(const char* theFileName) {
829     if(MYDEBUG) MESSAGE("View3D_i::SavePicture");
830     Mutex mt(myMutex,qApp,MYDELAY);
831     if (!myStudyFrame->getRightFrame()->getViewFrame()->getViewWidget())
832       return false;
833
834     QApplication::setOverrideCursor( Qt::waitCursor );
835     QPixmap px = QPixmap::grabWindow(myStudyFrame->getRightFrame()->getViewFrame()->getViewWidget()->winId());
836     QApplication::restoreOverrideCursor();
837     
838     if (!QString(theFileName).isNull()) {
839       QApplication::setOverrideCursor( Qt::waitCursor );
840       QString fmt = QAD_Tools::getFileExtensionFromPath(theFileName).upper();
841       if (fmt.isEmpty())
842         fmt = QString("BMP"); // default format
843       if (fmt == "JPG")
844         fmt = "JPEG";
845       bool bOk = px.save(theFileName, fmt.latin1());
846       QApplication::restoreOverrideCursor();
847       return bOk;
848     }
849     return false;
850   }
851
852   CORBA::Boolean View3D_i::SaveViewParams(const char* theName){
853     if(MYDEBUG)  MESSAGE("View3D_i::SaveViewPoint");
854     Mutex mt(myMutex,qApp,MYDELAY);
855     if ( theName ) {
856       SALOMEDS::Study::ListOfSObject_var aList = 
857         myStudy->getStudyDocument()->FindObjectByName(theName,"VISU");
858       SALOMEDS::GenericAttribute_var anAttr;
859       int iEnd = aList->length();
860       for(int i = 0; i < iEnd; i++){
861         SALOMEDS::SObject_var anObj = aList[i];
862         CORBA::String_var aString = anObj->GetID();
863         string anEntry(aString);
864         if(MYDEBUG)  MESSAGE("View3D_i::SaveViewPoint - anEntry = "<<anEntry);
865         if(anObj->FindAttribute(anAttr, "AttributeComment")){
866           SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
867           aString = aCmnt->Value();
868           string aComm(aString);
869           if(MYDEBUG)  MESSAGE("View3D_i::SaveViewPoint - aComm = "<<aComm);
870           if(aComm.compare(View3D_i::myComment) >= 0){
871             aCmnt->SetValue(ToString().c_str());
872             return 1;
873           }
874         }
875       }
876     }
877     QString newName;
878     if ( theName )
879       newName = QString( theName );
880     else
881       newName = QString( GenerateViewParamsName() );
882     SALOMEDS::SComponent_var aSComponent = 
883       FindOrCreateVisuComponent(myStudy->getStudyDocument());
884     CORBA::String_var aSComponentEntry = aSComponent->GetID(), anIOR(GetID());
885     string anEntry = CreateAttributes(myStudy->getStudyDocument(),aSComponentEntry,"","",newName.latin1(),"",ToString().c_str());
886     return 1;
887   }
888
889   CORBA::Boolean View3D_i::RestoreViewParams(const char* theName){
890     if(MYDEBUG)  MESSAGE("View3D_i::RestoreViewPoint - "<<theName);
891     Mutex mt(myMutex,qApp,MYDELAY);
892     SALOMEDS::Study::ListOfSObject_var aList = 
893       myStudy->getStudyDocument()->FindObjectByName(theName,"VISU");
894     SALOMEDS::GenericAttribute_var anAttr;
895     int iEnd = aList->length();
896     if(MYDEBUG)  MESSAGE("View3D_i::RestoreViewPoint - iEnd = "<<iEnd);
897     for(int i = 0; i < iEnd; i++){
898       SALOMEDS::SObject_var anObj = aList[i];
899       CORBA::String_var aString = anObj->GetID();
900       string anEntry(aString);
901       if(MYDEBUG)  MESSAGE("View3D_i::RestoreViewPoint - anEntry = "<<anEntry);
902       if(anObj->FindAttribute(anAttr, "AttributeComment")){
903         SALOMEDS::AttributeComment_var aCmnt = SALOMEDS::AttributeComment::_narrow(anAttr);
904         aString = aCmnt->Value();
905         QString strIn(aString);
906         Storable::TRestoringMap aMap;
907         Storable::StrToMap(strIn,aMap);
908         if ( Storable::FindValue( aMap,"myComment").compare( View3D_i::myComment.c_str() ) >= 0 ) {
909           if(MYDEBUG)  MESSAGE("View3D_i::RestoreViewPoint - aComm = "<<strIn);
910           return Restore( aMap ) != NULL;
911         }
912       }
913     }
914     return 0;
915   }
916
917   Storable* View3D_i::Restore(const Storable::TRestoringMap& theMap) throw(std::logic_error&) {
918     //    if(MYDEBUG)  MESSAGE("View3D_i::Restore");
919     //myName = VISU::Storable::FindValue(theMap,"myName").latin1();
920     
921     SALOMEDS::Color aColor;  
922     aColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
923     aColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
924     aColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
925     
926     double aPosition[3];
927     aPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
928     aPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
929     aPosition[2] = VISU::Storable::FindValue(theMap,"myPosition[2]").toDouble();
930     
931     double aFocalPnt[3];
932     aFocalPnt[0] = VISU::Storable::FindValue(theMap,"myFocalPnt[0]").toDouble();
933     aFocalPnt[1] = VISU::Storable::FindValue(theMap,"myFocalPnt[1]").toDouble();
934     aFocalPnt[2] = VISU::Storable::FindValue(theMap,"myFocalPnt[2]").toDouble();
935     
936     double aViewUp[3];
937     aViewUp[0] = VISU::Storable::FindValue(theMap,"myViewUp[0]").toDouble();
938     aViewUp[1] = VISU::Storable::FindValue(theMap,"myViewUp[1]").toDouble();
939     aViewUp[2] = VISU::Storable::FindValue(theMap,"myViewUp[2]").toDouble();
940     
941     double aParallelScale = VISU::Storable::FindValue(theMap,"myParallelScale").toDouble();
942      
943     double aScaleFactor[3];
944     aScaleFactor[0] = VISU::Storable::FindValue(theMap,"myScaleFactor[0]").toDouble();
945     aScaleFactor[1] = VISU::Storable::FindValue(theMap,"myScaleFactor[1]").toDouble();
946     aScaleFactor[2] = VISU::Storable::FindValue(theMap,"myScaleFactor[2]").toDouble();
947     
948     //myStudyFrame->setTitle(myName.c_str());
949     SetBackground(aColor);
950     SetPointOfView(aPosition);
951     SetViewUp(aViewUp);
952     SetFocalPoint(aFocalPnt);
953     SetParallelScale(aParallelScale);
954     ScaleView(VISU::View3D::XAxis,aScaleFactor[0]);
955     ScaleView(VISU::View3D::YAxis,aScaleFactor[1]);
956     ScaleView(VISU::View3D::ZAxis,aScaleFactor[2]);
957     RepaintView(myStudyFrame);
958     return this;
959   }
960     
961
962   void View3D_i::ToStream(std::ostringstream& theStr) {
963     Storable::DataToStream(theStr,"myType",VISU::TVIEW3D);
964     
965     float backint[3];  
966     GetRenderer(myStudyFrame)->GetBackground(backint);
967     Storable::DataToStream(theStr,"myColor.R",backint[0]);
968     Storable::DataToStream(theStr,"myColor.G",backint[1]);
969     Storable::DataToStream(theStr,"myColor.B",backint[2]);
970     
971     double aPosition[3];
972     GetPointOfView(myStudyFrame,aPosition);
973     Storable::DataToStream(theStr,"myPosition[0]",aPosition[0]);
974     Storable::DataToStream(theStr,"myPosition[1]",aPosition[1]);
975     Storable::DataToStream(theStr,"myPosition[2]",aPosition[2]);
976     
977     double aFocalPnt[3];
978     GetFocalPoint(myStudyFrame,aFocalPnt);
979     Storable::DataToStream(theStr,"myFocalPnt[0]",aFocalPnt[0]);
980     Storable::DataToStream(theStr,"myFocalPnt[1]",aFocalPnt[1]);
981     Storable::DataToStream(theStr,"myFocalPnt[2]",aFocalPnt[2]);
982     
983     double aViewUp[3];
984     GetCamera(myStudyFrame)->GetViewUp(aViewUp);
985     Storable::DataToStream(theStr,"myViewUp[0]",aViewUp[0]);
986     Storable::DataToStream(theStr,"myViewUp[1]",aViewUp[1]);
987     Storable::DataToStream(theStr,"myViewUp[2]",aViewUp[2]);
988     
989     Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(myStudyFrame));
990     
991     double aScaleFactor[3];
992     GetViewFrame(myStudyFrame)->GetScale(aScaleFactor);
993     Storable::DataToStream(theStr,"myScaleFactor[0]",aScaleFactor[0]);
994     Storable::DataToStream(theStr,"myScaleFactor[1]",aScaleFactor[1]);
995     Storable::DataToStream(theStr,"myScaleFactor[2]",aScaleFactor[2]);
996   }
997
998
999 //   Storable* VISU::View3DRestore(SALOMEDS::SComponent_var& theSComponent, SALOMEDS::Study_var& theStudy,
1000 //                              const char* thePrefix, const Storable::TRestoringMap& theMap)
1001 //     {
1002 //       try{
1003 //      View3D_i* pView3D = new View3D_i(theStudy);
1004 //      return pView3D->Restore(theMap);
1005 //       }catch(std::logic_error& exc){
1006 //      MESSAGE("Follow exception was accured :\n"<<exc.what());
1007 //       }catch(...){
1008 //      MESSAGE("Unknown exception was accured!");
1009 //       }
1010 //       return NULL;
1011 //     }
1012   
1013   void View3D_i::Close(){
1014     if(MYDEBUG) MESSAGE("View3D_i::Close");
1015     Mutex mt(myMutex,qApp,MYDELAY);
1016     myStudyFrame->close();
1017   }
1018
1019   View3D_i::~View3D_i() {
1020     if(MYDEBUG) MESSAGE("View3D_i::~View3D_i");
1021     Mutex mt(myMutex,qApp,MYDELAY);
1022     myStudyFrame->close();
1023   }
1024
1025   //-------------------- View interface --------------------
1026   void View3D_i::SetTitle(const char* theTitle){
1027     if(MYDEBUG) MESSAGE("View3D_i::SetTitle");
1028     Mutex mt(myMutex,qApp,MYDELAY);
1029     myName = theTitle;
1030     myStudyFrame->setTitle(myName.c_str());
1031   }
1032   char* View3D_i::GetTitle() {
1033     if(MYDEBUG) MESSAGE("View3D_i::GetTitle");
1034     Mutex mt(myMutex,qApp,MYDELAY);
1035     myName = (const char*)myStudyFrame->title();
1036     return CORBA::string_dup(myName.c_str());
1037   }
1038
1039   void View3D_i::SetBackground(QAD_StudyFrame* theStudyFrame, const SALOMEDS::Color& theColor) {
1040     int aColor[3];
1041     aColor[0] = (int)(255.0*theColor.R);
1042     aColor[1] = (int)(255.0*theColor.G);
1043     aColor[2] = (int)(255.0*theColor.B);
1044     QColor aNewColor(aColor[0],aColor[1],aColor[2]);
1045     GetViewFrame(theStudyFrame)->setBackgroundColor(aNewColor);
1046   }
1047   void View3D_i::SetBackground(const SALOMEDS::Color& theColor) {
1048     if(MYDEBUG) MESSAGE("View3D_i::SetBackground");
1049     Mutex mt(myMutex,qApp,MYDELAY);
1050     //myColor.R = theColor.R;  myColor.G = theColor.G;  myColor.B = theColor.B;
1051     SetBackground(myStudyFrame,theColor);
1052   }
1053
1054   SALOMEDS::Color View3D_i::GetBackground(QAD_StudyFrame* theStudyFrame) { 
1055     SALOMEDS::Color aColor;
1056     float backint[3];  
1057     GetRenderer(theStudyFrame)->GetBackground(backint);
1058     aColor.R = backint[0];  aColor.G = backint[1];  aColor.B = backint[2];
1059     return aColor;
1060   }
1061   SALOMEDS::Color View3D_i::GetBackground() { 
1062     if(MYDEBUG) MESSAGE("View3D_i::GetBackground");
1063     Mutex mt(myMutex,qApp,MYDELAY);
1064     //myColor = GetBackground(myStudyFrame);
1065     return GetBackground(myStudyFrame); //myColor;
1066   }
1067
1068   void View3D_i::Minimize() {
1069     if(MYDEBUG) MESSAGE("View3D_i::Minimize");
1070     Mutex mt(myMutex,qApp,MYDELAY);
1071     myStudyFrame->showMinimized();
1072   }
1073   void View3D_i::Restore() {
1074     if(MYDEBUG) MESSAGE("View3D_i::Restore");
1075     Mutex mt(myMutex,qApp,MYDELAY);
1076     myStudyFrame->showNormal();
1077   }
1078   void View3D_i::Maximize() {
1079     if(MYDEBUG) MESSAGE("View3D_i::Maximize");
1080     Mutex mt(myMutex,qApp,MYDELAY);
1081     myStudyFrame->showMaximized();
1082   }
1083   //===========================================================================
1084   void View3D_i::EraseAll() {
1085     if(MYDEBUG) MESSAGE("View3D_i::EraseAll");
1086     Mutex mt(myMutex,qApp,MYDELAY);
1087     UpdateViewer(myStudyFrame,eEraseAll);
1088   }
1089   void View3D_i::DisplayAll() {
1090     if(MYDEBUG) MESSAGE("View3D_i::DisplayAll");
1091     Mutex mt(myMutex,qApp,MYDELAY);
1092     UpdateViewer(myStudyFrame,eDisplayAll);
1093   }
1094   void View3D_i::Erase(PrsObject_ptr thePrsObj) {
1095     if(MYDEBUG) MESSAGE("View3D_i::Erase");
1096     Mutex mt(myMutex,qApp,MYDELAY);
1097     CORBA::Object_ptr anObj = thePrsObj;
1098     if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in()))
1099       UpdateViewer(myStudyFrame,eErase,aPrs);
1100   }
1101   void View3D_i::Display(PrsObject_ptr thePrsObj) {
1102     if(MYDEBUG) MESSAGE("View3D_i::Display"); 
1103     Mutex mt(myMutex,qApp,MYDELAY);
1104     CORBA::Object_ptr anObj = thePrsObj;
1105     if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in()))
1106       UpdateViewer(myStudyFrame,eDisplay,aPrs);
1107   }
1108   void View3D_i::DisplayOnly(PrsObject_ptr thePrsObj) {
1109     if(MYDEBUG) MESSAGE("View3D_i::DisplayOnly");
1110     Mutex mt(myMutex,qApp,MYDELAY);
1111     CORBA::Object_ptr anObj = thePrsObj;
1112     if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in()))
1113       UpdateViewer(myStudyFrame,eDisplayOnly,aPrs);
1114   }
1115
1116   //-------------------- View3D interface --------------------
1117   void View3D_i::FitAll() { 
1118     if(MYDEBUG) MESSAGE("View3D_i::FitAll");
1119     Mutex mt(myMutex,qApp,MYDELAY);
1120     GetViewFrame(myStudyFrame)->onViewFitAll();
1121     Update();
1122   }
1123   void View3D_i::SetView(VISU::View3D::ViewType theType) {
1124     if(MYDEBUG) MESSAGE("View3D_i::SetView");
1125     Mutex mt(myMutex,qApp,MYDELAY);
1126     switch(theType){
1127     case VISU::View3D::FRONT : GetViewFrame(myStudyFrame)->onViewFront(); break;
1128     case VISU::View3D::BACK : GetViewFrame(myStudyFrame)->onViewBack(); break;
1129     case VISU::View3D::LEFT : GetViewFrame(myStudyFrame)->onViewLeft(); break;
1130     case VISU::View3D::RIGHT : GetViewFrame(myStudyFrame)->onViewRight(); break;
1131     case VISU::View3D::TOP : GetViewFrame(myStudyFrame)->onViewTop(); break;
1132     case VISU::View3D::BOTTOM : GetViewFrame(myStudyFrame)->onViewBottom(); break;
1133     }
1134     Update();
1135   }
1136
1137   void View3D_i::SetPointOfView(QAD_StudyFrame* theStudyFrame, const CORBA::Double thePosition[3]) {
1138     GetCamera(theStudyFrame)->SetPosition(thePosition);
1139   }
1140   void View3D_i::SetPointOfView(const VISU::View3D::XYZ theCoord) {
1141     if(MYDEBUG) MESSAGE("View3D_i::SetPointOfView");
1142     Mutex mt(myMutex,qApp,MYDELAY);
1143     //VISU::View3D::XYZ_copy(myPosition,theCoord);
1144     SetPointOfView(myStudyFrame, theCoord);
1145   }
1146
1147   void View3D_i::GetPointOfView(QAD_StudyFrame* theStudyFrame, CORBA::Double thePosition[3]) { 
1148     GetCamera(theStudyFrame)->GetPosition(thePosition);
1149   }
1150   VISU::View3D::XYZ_slice* View3D_i::GetPointOfView() { 
1151     if(MYDEBUG) MESSAGE("View3D_i::GetPointOfView");
1152     Mutex mt(myMutex,qApp,MYDELAY);
1153     CORBA::Double aPosition[3];
1154     GetPointOfView(myStudyFrame,aPosition);
1155     return VISU::View3D::XYZ_dup(aPosition);
1156   }
1157
1158   void View3D_i::SetViewUp(QAD_StudyFrame* theStudyFrame, const CORBA::Double theViewUp[3]) {
1159     GetCamera(theStudyFrame)->SetViewUp(theViewUp);
1160   }
1161   void View3D_i::SetViewUp(const VISU::View3D::XYZ theDir) {
1162     if(MYDEBUG) MESSAGE("View3D_i::SetViewUp");
1163     Mutex mt(myMutex,qApp,MYDELAY);
1164     //VISU::View3D::XYZ_copy(myViewUp,theDir);
1165     SetViewUp(myStudyFrame, theDir);
1166   }
1167
1168   void View3D_i::GetViewUp(QAD_StudyFrame* theStudyFrame, CORBA::Double theViewUp[3]) { 
1169     GetCamera(theStudyFrame)->GetViewUp(theViewUp);
1170   }
1171   VISU::View3D::XYZ_slice* View3D_i::GetViewUp() { 
1172     if(MYDEBUG) MESSAGE("View3D_i::GetViewUp");
1173     Mutex mt(myMutex,qApp,MYDELAY);
1174     CORBA::Double aViewUp[3];
1175     GetCamera(myStudyFrame)->GetViewUp(aViewUp);
1176     return VISU::View3D::XYZ_dup(aViewUp);
1177   }
1178
1179   void View3D_i::SetFocalPoint(QAD_StudyFrame* theStudyFrame, const CORBA::Double theFocalPnt[3]) {
1180     GetCamera(theStudyFrame)->SetFocalPoint(theFocalPnt);
1181   }
1182   void View3D_i::SetFocalPoint(const VISU::View3D::XYZ theCoord) {
1183     if(MYDEBUG) MESSAGE("View3D_i::SetFocalPoint");
1184     Mutex mt(myMutex,qApp,MYDELAY);
1185     //VISU::View3D::XYZ_copy(myFocalPnt,theCoord);
1186     SetFocalPoint(myStudyFrame,theCoord);
1187   }
1188
1189   void View3D_i::GetFocalPoint(QAD_StudyFrame* theStudyFrame, CORBA::Double theFocalPnt[3]) { 
1190     GetCamera(theStudyFrame)->GetFocalPoint(theFocalPnt);
1191   }
1192   VISU::View3D::XYZ_slice* View3D_i::GetFocalPoint() { 
1193     if(MYDEBUG) MESSAGE("View3D_i::GetFocalPoint");
1194     Mutex mt(myMutex,qApp,MYDELAY);
1195     CORBA::Double aFocalPnt[3];
1196     GetFocalPoint(myStudyFrame,aFocalPnt);
1197     return VISU::View3D::XYZ_dup(aFocalPnt);
1198   }
1199
1200   void View3D_i::SetParallelScale(QAD_StudyFrame* theStudyFrame, CORBA::Double theScale) {
1201     GetCamera(theStudyFrame)->SetParallelScale(theScale);
1202   }
1203   void View3D_i::SetParallelScale(CORBA::Double theScale) {
1204     if(MYDEBUG) MESSAGE("View3D_i::SetParallelScale");
1205     Mutex mt(myMutex,qApp,MYDELAY);
1206     //myParallelScale = theScale;
1207     SetParallelScale(myStudyFrame, theScale);
1208   }
1209
1210   CORBA::Double View3D_i::GetParallelScale(QAD_StudyFrame* theStudyFrame) { 
1211     return GetCamera(theStudyFrame)->GetParallelScale();
1212   }
1213   CORBA::Double View3D_i::GetParallelScale() { 
1214     if(MYDEBUG) MESSAGE("View3D_i::GetParallelScale");
1215     Mutex mt(myMutex,qApp);
1216     return GetParallelScale(myStudyFrame);
1217   }
1218
1219   void View3D_i::ScaleView(QAD_StudyFrame* theStudyFrame, VISU::View3D::Axis theAxis, CORBA::Double theParam) {
1220     VTKViewer_ViewFrame* aViewFrame =  GetViewFrame(theStudyFrame);
1221     double aScaleFactor[3];
1222     aViewFrame->GetScale(aScaleFactor);
1223     aScaleFactor[theAxis] = theParam;
1224     aViewFrame->SetScale(aScaleFactor);
1225   }
1226   void View3D_i::ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam) {
1227     if(MYDEBUG) MESSAGE("View3D_i::ScaleView");
1228     Mutex mt(myMutex,qApp);
1229     //myScaleFactor[theAxis] = theParam;
1230     ScaleView(myStudyFrame,theAxis,theParam);
1231   }
1232   void View3D_i::RemoveScale() {
1233     if(MYDEBUG) MESSAGE("View3D_i::RemoveScale");
1234     Mutex mt(myMutex,qApp);
1235     double aScaleFactor[]={1,1,1};
1236     //myScaleFactor[0] = myScaleFactor[0] = myScaleFactor[0] = 1.0;
1237     GetViewFrame(myStudyFrame)->SetScale(aScaleFactor);
1238   }
1239   //===========================================================================
1240 }