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