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