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