Salome HOME
SMH: 3.0.0 preparation - merged and adopted version (POLYWORK+HEAD)
[modules/visu.git] / src / VISU_I / VISU_View_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_View_i.cc
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #include "VISU_View_i.hh"
28
29 #include "VISU_Gen_i.hh"
30 #include "VISU_Prs3d_i.hh"
31 #include "VISU_Table_i.hh"
32 #include "VISU_ViewManager_i.hh"
33
34 #include "VISU_Actor.h"
35
36 #include "SALOME_Event.hxx"
37
38 #include "SUIT_ViewWindow.h"
39 #include "SUIT_ViewManager.h"
40 #include "SUIT_Tools.h"
41
42 #include "STD_MDIDesktop.h"
43
44 #include "SVTK_ViewWindow.h"
45 #include "SVTK_ViewModel.h"
46 #include "Plot2d_ViewFrame.h"
47 #include "Plot2d_ViewModel.h"
48
49 #include "SalomeApp_Application.h"
50 #include "SalomeApp_Study.h"
51
52 #include <qworkspace.h>
53
54 #include <vtkCamera.h>
55 #include <vtkRenderer.h>
56
57 using namespace std;
58
59 #ifdef _DEBUG_
60 static int MYDEBUG = 0;
61 #else
62 static int MYDEBUG = 0;
63 #endif
64
65 namespace VISU{
66
67   typedef TVoidMemFunEvent<SUIT_ViewWindow> TFrameActionEvent;
68
69   View_i::
70   View_i(SalomeApp_Application *theApplication,
71          SUIT_ViewManager* theViewManager):
72     myApplication(theApplication),
73     myWorkspace(NULL),
74     myViewManager(theViewManager)
75   {
76     if(MYDEBUG) MESSAGE("View_i::View_i - "<<this);
77     if(STD_MDIDesktop* aDesktop = dynamic_cast<STD_MDIDesktop*>(myApplication->desktop())){
78       myWorkspace = aDesktop->workspace();
79     }
80   }
81
82   View_i::
83   ~View_i()
84   {
85     if(MYDEBUG) MESSAGE("View_i::~View_i - "<<this);
86   }
87
88
89   struct TApplicationEvent: public SALOME_Event
90   {
91     SalomeApp_Application* myApplication;
92
93     TApplicationEvent(SalomeApp_Application* theApplication):
94       myApplication(theApplication)
95     {}
96   };
97
98
99   void
100   View_i::
101   ShowPart(VISU::View::ViewRepresentation theViewRepresentation,
102            CORBA::Boolean theState)
103   {
104     struct TEvent: public TApplicationEvent
105     {
106       VISU::View::ViewRepresentation myViewRepresentation;
107       CORBA::Boolean myState;
108
109       TEvent(SalomeApp_Application* theApplication,
110              VISU::View::ViewRepresentation theViewRepresentation,
111              CORBA::Boolean theState):
112         TApplicationEvent(theApplication),
113         myViewRepresentation(theViewRepresentation),
114         myState(theState)
115       {}
116
117       virtual
118       void
119       Execute()
120       {
121         switch(myViewRepresentation){
122         case VISU::View::OBJECTBROWSER:
123           myApplication->setWindowShown(SalomeApp_Application::WT_ObjectBrowser,myState);
124           break;
125         case VISU::View::PYTHON:
126           myApplication->setWindowShown(SalomeApp_Application::WT_PyConsole,myState);
127           break;
128         case VISU::View::MESSAGES:
129           myApplication->setWindowShown(SalomeApp_Application::WT_LogWindow,myState);
130           break;
131         case VISU::View::VIEWER:{
132           ViewManagerList aViewManagerList = myApplication->viewManagers();
133           // to do something
134           // ...
135           break;
136         }}
137       }
138     };
139
140     ProcessVoidEvent(new TEvent(myApplication,theViewRepresentation,theState));
141   }
142
143
144   struct TPartShownEvent: public TApplicationEvent
145   {
146     VISU::View::ViewRepresentation myViewRepresentation;
147     typedef bool TResult;
148     TResult myResult;
149
150     TPartShownEvent(SalomeApp_Application* theApplication,
151                     VISU::View::ViewRepresentation theViewRepresentation):
152       TApplicationEvent(theApplication),
153       myViewRepresentation(theViewRepresentation),
154       myResult(false)
155     {}
156
157     virtual
158     void
159     Execute()
160     {
161       switch(myViewRepresentation){
162       case VISU::View::OBJECTBROWSER:
163         myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_ObjectBrowser);
164         break;
165       case VISU::View::PYTHON:
166         myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_PyConsole);
167         break;
168       case VISU::View::MESSAGES:
169         myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_LogWindow);
170         break;
171       case VISU::View::VIEWER:{
172         ViewManagerList aViewManagerList = myApplication->viewManagers();
173         // to do something
174         // ...
175         break;
176       }}
177     }
178   };
179
180
181   CORBA::Boolean
182   View_i::
183   IsPartShown(VISU::View::ViewRepresentation theViewRepresentation)
184   {
185     return ProcessEvent(new TPartShownEvent(myApplication,theViewRepresentation));
186   }
187
188
189   struct TSetViewSize: public SALOME_Event
190   {
191     SUIT_ViewWindow* myViewWindow;
192     typedef void (QRect::* TAction)(int);
193     TAction myAction;
194     CORBA::Long mySize;
195
196   public:
197     TSetViewSize(SUIT_ViewWindow* theViewWindow,
198                  TAction theAction,
199                  CORBA::Long theSize):
200       myViewWindow(theViewWindow),
201       myAction(theAction),
202       mySize(theSize)
203     {}
204
205     virtual
206     void
207     Execute()
208     {
209       if (QWidget* aParent = myViewWindow->parentWidget(true)) {
210         QRect aQRect = aParent->frameGeometry();
211         (aQRect.*myAction)(mySize);
212         aParent->setGeometry(aQRect);
213       }
214     }
215   };
216
217
218   void
219   View_i::
220   SetViewWidth(CORBA::Long theWidth)
221   {
222     ProcessVoidEvent(new TSetViewSize(myViewWindow,&QRect::setWidth,theWidth));
223   }
224
225
226   void
227   View_i::
228   SetViewHeight(CORBA::Long theHeight)
229   {
230     ProcessVoidEvent(new TSetViewSize(myViewWindow,&QRect::setHeight,theHeight));
231   }
232
233
234   struct TGetViewSize: public SALOME_Event
235   {
236     SUIT_ViewWindow* myViewWindow;
237
238     typedef int (QRect::* TAction)() const;
239     TAction myAction;
240
241     typedef CORBA::Long TResult;
242     TResult myResult;
243
244   public:
245     TGetViewSize(SUIT_ViewWindow* theViewWindow,
246                  TAction theAction):
247       myViewWindow(theViewWindow),
248       myAction(theAction)
249     {}
250
251     virtual
252     void
253     Execute()
254     {
255       if(QWidget* aParent = myViewWindow->parentWidget(true)){
256         QRect aQRect = aParent->frameGeometry();
257         myResult = (aQRect.*myAction)();
258       }
259     }
260   };
261
262
263   CORBA::Long
264   View_i::
265   GetViewWidth()
266   {
267     return ProcessEvent(new TGetViewSize(myViewWindow,&QRect::width));
268   }
269
270   CORBA::Long
271   View_i::
272   GetViewHeight()
273   {
274     return ProcessEvent(new TGetViewSize(myViewWindow,&QRect::height));
275   }
276
277
278   class TWorkspaceEvent: public SALOME_Event
279   {
280   protected:
281     QWidget* myViewWindow;
282     QWidget* myWorkspace;
283
284   public:
285     TWorkspaceEvent(QWidget* theViewWindow,
286                     QWidget* theWorkspace):
287       myViewWindow(theViewWindow),
288       myWorkspace(theWorkspace)
289     {}
290   };
291
292
293   class TAlignEvent: public TWorkspaceEvent
294   {
295   protected:
296     Qt::AlignmentFlags myAligment;
297
298   public:
299     TAlignEvent(QWidget* theViewWindow,
300                 QWidget* theWorkspace,
301                 Qt::AlignmentFlags theAligment):
302       TWorkspaceEvent(theViewWindow,theWorkspace),
303       myAligment(theAligment)
304     {}
305
306     virtual
307     void
308     Execute()
309     {
310       if(QWidget* aParent = myViewWindow->parentWidget(true))
311         SUIT_Tools::alignWidget(aParent,myWorkspace,myAligment);
312     }
313   };
314
315
316   void
317   View_i::
318   SetViewPositionHorizontal(VISU::View::ViewPosition theViewPosition)
319   {
320     if(myWorkspace){
321       switch(theViewPosition){
322       case VISU::View::LEFT:
323         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignLeft));
324         break;
325       case VISU::View::CENTER:
326         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignHCenter));
327         break;
328       case VISU::View::RIGHT:
329         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignRight));
330         break;
331       }
332     }
333   }
334
335
336   void
337   View_i::
338   SetViewPositionVertical(VISU::View::ViewPosition theViewPosition)
339   {
340     if(myWorkspace){
341       switch(theViewPosition){
342       case VISU::View::TOP:
343         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignTop));
344         break;
345       case VISU::View::CENTER:
346         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignVCenter));
347         break;
348       case VISU::View::BOTTOM:
349         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignBottom));
350         break;
351       }
352     }
353   }
354
355
356   class TXYEvent: public TWorkspaceEvent
357   {
358   protected:
359     CORBA::Double myX, myY;
360
361   public:
362     TXYEvent(QWidget* theViewWindow,
363              QWidget* theWorkspace,
364              CORBA::Double theX,
365              CORBA::Double theY):
366       TWorkspaceEvent(theViewWindow,theWorkspace),
367       myX(theX),
368       myY(theY)
369     {}
370   };
371
372
373   void
374   View_i::
375   SetRelativePosition(CORBA::Double theX, CORBA::Double theY)
376   {
377     struct TEvent: public TXYEvent
378     {
379     public:
380       TEvent(QWidget* theViewWindow,
381              QWidget* theWorkspace,
382              CORBA::Double theX,
383              CORBA::Double theY):
384         TXYEvent(theViewWindow,theWorkspace,theX,theY)
385       {}
386
387       virtual
388       void
389       Execute()
390       {
391         if(QWidget* aParent = myViewWindow->parentWidget(true))
392           aParent->move(int(myX*myWorkspace->width()),int(myY*myWorkspace->height()));
393       }
394     };
395
396     if(myWorkspace)
397       ProcessVoidEvent(new TEvent(myViewWindow,myWorkspace,theX,theY));
398   }
399
400   void
401   View_i::
402   SetRelativeSize(CORBA::Double theX, CORBA::Double theY)
403   {
404     struct TEvent: public TXYEvent
405     {
406     public:
407       TEvent(QWidget* theViewWindow,
408              QWidget* theWorkspace,
409              CORBA::Double theX,
410              CORBA::Double theY):
411         TXYEvent(theViewWindow,theWorkspace,theX,theY)
412       {}
413
414       virtual
415       void
416       Execute()
417       {
418         if(QWidget* aParent = myViewWindow->parentWidget(true))
419           aParent->setGeometry(aParent->x(),
420                                aParent->y(),
421                                int(myX*myWorkspace->width()),
422                                int(myY*myWorkspace->height()));
423       }
424     };
425
426     if(myWorkspace)
427       ProcessVoidEvent(new TEvent(myViewWindow,myWorkspace,theX,theY));
428   }
429
430   void
431   View_i::
432   SetBackground(const SALOMEDS::Color& theColor)
433   {
434     struct TEvent: public SALOME_Event
435     {
436       QWidget* myWidget;
437       SALOMEDS::Color myColor;
438     public:
439       TEvent(QWidget* theWidget,
440              const SALOMEDS::Color& theColor):
441         myWidget(theWidget),
442         myColor(theColor)
443       {}
444       virtual void Execute(){
445         int aColor[3];
446         aColor[0] = int(255.0*myColor.R);
447         aColor[1] = int(255.0*myColor.G);
448         aColor[2] = int(255.0*myColor.B);
449         myWidget->setBackgroundColor(QColor(aColor[0],aColor[1],aColor[2]));
450       }
451     };
452
453     ProcessVoidEvent(new TEvent(myViewWindow,theColor));
454   }
455
456
457   struct TBackgroundEvent: public SALOME_Event
458   {
459     QWidget* myWidget;
460     typedef SALOMEDS::Color TResult;
461     TResult myResult;
462
463     TBackgroundEvent(QWidget* theWidget):
464       myWidget(theWidget)
465     {}
466
467     virtual
468     void
469     Execute()
470     {
471       const QColor& aColor = myWidget->backgroundColor();
472       myResult.R = aColor.red()/255.0;
473       myResult.G = aColor.green()/255.0;
474       myResult.B = aColor.blue()/255.0;
475     }
476   };
477
478   SALOMEDS::Color
479   View_i::
480   GetBackground()
481   {
482     return ProcessEvent(new TBackgroundEvent(myViewWindow));
483   }
484
485   void
486   View_i::
487   Minimize()
488   {
489     ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showMinimized));
490   }
491
492   void
493   View_i::
494   Restore()
495   {
496     ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showNormal));
497   }
498
499   void
500   View_i::
501   Maximize()
502   {
503     ProcessVoidEvent(new TFrameActionEvent(myViewWindow,&SUIT_ViewWindow::showMaximized));
504   }
505
506   void
507   View_i::
508   EraseAll()
509   {}
510
511   void
512   View_i::
513   DisplayAll()
514   {}
515
516   void
517   View_i::
518   Erase(PrsObject_ptr thePrsObj)
519   {}
520
521   void
522   View_i::
523   Display(PrsObject_ptr thePrsObj)
524   {}
525
526   void
527   View_i::
528   DisplayOnly(PrsObject_ptr thePrsObj)
529   {}
530
531   void
532   View_i::
533   Update()
534   {}
535
536   CORBA::Boolean
537   View_i::SavePicture(const char* theFileName)
538   {
539     return false;
540   }
541
542   const char*
543   View_i::
544   GetComment() const
545   {
546     return "";
547   }
548   void
549   View_i::
550   ToStream(std::ostringstream& theStr)
551   {}
552
553
554   //================= OLD CODE ===================
555
556   //QAD_Study* CheckStudy (SALOMEDS::Study_ptr theStudy)
557   //{
558   //  //QAD_Desktop* aDesktop = QAD_Application::getDesktop();
559   //  //QAD_Study* aStudy = aDesktop->findStudy(theStudy);
560   //  if (!aStudy) {
561   //    CORBA::String_var aName = theStudy->Name();
562   //    aFileInfo.setFile(aName.in());
563   //    if (aFileInfo.exists())
564   //      aStudy = aDesktop->loadStudy(aFileInfo.baseName());
565   //    else
566   //      aStudy = aDesktop->loadStudy(aName.in());
567   //    if (!aStudy) {
568   //      MESSAGE("CheckStudy()::ERROR: Can't load study");
569   //    }
570   //  }
571   //  return aStudy;
572   //}
573
574   class TSavePictureEvent: public SALOME_Event
575   {
576     QWidget* myWidget;
577     const char* myFileName;
578   public:
579     typedef CORBA::Boolean TResult;
580     TResult myResult;
581     TSavePictureEvent (QWidget* theWidget, const char* theFileName)
582       : myWidget(theWidget),
583         myFileName(theFileName),
584         myResult(false)
585     {
586     }
587
588     virtual void Execute()
589     {
590       if (myWidget) {
591         QPixmap px = QPixmap::grabWindow(myWidget->winId());
592         if (!QString(myFileName).isNull()) {
593           QString fmt = SUIT_Tools::extension(myFileName).upper();
594           if (fmt.isEmpty())
595             fmt = QString("BMP"); // default format
596           if (fmt == "JPG")
597             fmt = "JPEG";
598           myResult = px.save(myFileName, fmt.latin1());
599         }
600       }
601     }
602   };
603
604
605   //===========================================================================
606   XYPlot_i::XYPlot_i (SalomeApp_Application* theApplication)
607     : View_i(theApplication, theApplication->getViewManager(Plot2d_Viewer::Type(), true))
608   {
609     if (MYDEBUG) MESSAGE("XYPlot_i::XYPlot_i");
610   }
611
612   Storable* XYPlot_i::Create (int theNew)
613   {
614     if (theNew) {
615       myViewWindow = myViewManager->createViewWindow();
616     } else {
617       myViewWindow = myViewManager->getActiveView();
618     }
619     //jfa tmp:myView = dynamic_cast<Plot2d_ViewFrame*>(myViewWindow->getRightFrame()->getViewFrame());
620     //jfa tmp:myView->Repaint();
621     return this;
622   }
623
624   void XYPlot_i::Update()
625   {
626     ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame>(myView,&Plot2d_ViewFrame::Repaint));
627   }
628
629   void XYPlot_i::Close()
630   {
631     myViewWindow->close();
632   }
633
634   XYPlot_i::~XYPlot_i() {
635     if(MYDEBUG) MESSAGE("XYPlot_i::~XYPlot_i");
636   }
637
638   void XYPlot_i::SetTitle (const char* theTitle)
639   {
640     ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
641                      (myViewWindow, &SUIT_ViewWindow::setCaption, QString(theTitle)));
642   }
643   char* XYPlot_i::GetTitle()
644   {
645     return CORBA::string_dup(myViewWindow->caption().latin1());
646   }
647
648   void XYPlot_i::SetSubTitle (const char* theTitle)
649   {
650     ProcessVoidEvent(new TVoidMemFun1ArgEvent<Plot2d_ViewFrame,const QString&,QString>
651                      (myView, &Plot2d_ViewFrame::setTitle, QString(theTitle)));
652   }
653
654   char* XYPlot_i::GetSubTitle()
655   {
656     return CORBA::string_dup(myView->getTitle());
657   }
658
659   void XYPlot_i::SetCurveType (VISU::XYPlot::CurveType theType)
660   {
661     ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,int,bool>
662                      (myView,&Plot2d_ViewFrame::setCurveType,theType,true));
663   }
664
665   VISU::XYPlot::CurveType XYPlot_i::GetCurveType()
666   {
667     return (VISU::XYPlot::CurveType)myView->getCurveType();
668   }
669
670   void XYPlot_i::SetMarkerSize (CORBA::Long theSize)
671   {
672     ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,int,bool>
673                      (myView,&Plot2d_ViewFrame::setMarkerSize,theSize,true));
674   }
675
676   CORBA::Long XYPlot_i::GetMarkerSize()
677   {
678     return myView->getMarkerSize();
679   }
680
681   class TEnableGridEvent: public SALOME_Event
682   {
683   public:
684     typedef void (Plot2d_ViewFrame::* TFun)(bool, const int, bool, const int, bool = true);
685     TEnableGridEvent (Plot2d_ViewFrame* theView, TFun theFun,
686                       CORBA::Boolean theMajor, CORBA::Long theNumMajor,
687                       CORBA::Boolean theMinor, CORBA::Long theNumMinor):
688       myView(theView), myFun(theFun),
689       myMajor(theMajor), myNumMajor(theNumMajor),
690       myMinor(theMinor), myNumMinor(theNumMinor)
691     {}
692
693     virtual void Execute()
694     {
695       (myView->*myFun)(myMajor,myNumMajor,myMinor,myNumMinor);
696     }
697   protected:
698     Plot2d_ViewFrame* myView;
699     TFun myFun;
700     CORBA::Boolean myMajor, myNumMajor;
701     CORBA::Boolean myMinor, myNumMinor;
702   };
703
704   void XYPlot_i::EnableXGrid (CORBA::Boolean theMajor, CORBA::Long theNumMajor,
705                               CORBA::Boolean theMinor, CORBA::Long theNumMinor)
706   {
707     ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setXGrid,
708                                           theMajor,theNumMajor,theMinor,theNumMinor));
709   }
710   void XYPlot_i::EnableYGrid(CORBA::Boolean theMajor, CORBA::Long theNumMajor,
711                              CORBA::Boolean theMinor, CORBA::Long theNumMinor)
712   {
713     //jfa tmp:ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setYGrid,
714     //jfa tmp:                                      theMajor,theNumMajor,theMinor,theNumMinor));
715   }
716
717   class TSetScaleModeEvent: public SALOME_Event
718   {
719   public:
720     typedef void (Plot2d_ViewFrame::* TFun)(const int, bool = true);
721     TSetScaleModeEvent (Plot2d_ViewFrame* theView, TFun theFun, int theScaling):
722       myView(theView), myFun(theFun), myScaling(theScaling)
723     {}
724
725     virtual void Execute()
726     {
727       (myView->*myFun)(myScaling);
728     }
729   protected:
730     Plot2d_ViewFrame* myView;
731     TFun myFun;
732     int myScaling;
733   };
734
735   void XYPlot_i::SetHorScaling (VISU::Scaling theScaling)
736   {
737     ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setHorScaleMode,
738                                             theScaling == VISU::LOGARITHMIC));
739   }
740
741   VISU::Scaling XYPlot_i::GetHorScaling()
742   {
743     return (VISU::Scaling)myView->getHorScaleMode();
744   }
745
746   void XYPlot_i::SetVerScaling(VISU::Scaling theScaling)
747   {
748     ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setVerScaleMode,
749                                             theScaling == VISU::LOGARITHMIC));
750   }
751
752   VISU::Scaling XYPlot_i::GetVerScaling()
753   {
754     return (VISU::Scaling)myView->getVerScaleMode();
755   }
756
757   class TSetTitleEvent: public SALOME_Event
758   {
759   public:
760     //typedef void (Plot2d_ViewFrame::* TFun)(bool, const QString&, bool = true);
761     typedef void (Plot2d_ViewFrame::* TFun)(bool, const QString&, Plot2d_ViewFrame::ObjectType, bool = true);
762     //TSetTitleEvent (Plot2d_ViewFrame* theView, TFun theFun, const char* theTitle):
763     TSetTitleEvent (Plot2d_ViewFrame* theView, Plot2d_ViewFrame::ObjectType theType, const char* theTitle):
764       //myView(theView), myFun(theFun), myTitle(theTitle)
765       myView(theView), myType(theType), myTitle(theTitle)
766     {}
767     virtual void Execute()
768     {
769       //(myView->*myFun)(true,myTitle,myType);
770       myView->setTitle(true,myTitle,myType);
771     }
772   protected:
773     Plot2d_ViewFrame* myView;
774     //TFun myFun;
775     Plot2d_ViewFrame::ObjectType myType;
776     const char* myTitle;
777   };
778
779   void XYPlot_i::SetXTitle (const char* theTitle)
780   {
781     //ProcessVoidEvent(new TSetTitleEvent(myView, &Plot2d_ViewFrame::setXTitle, theTitle));
782     ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::XTitle, theTitle));
783   }
784   char* XYPlot_i::GetXTitle()
785   {
786     //return CORBA::string_dup(myView->getXTitle());
787     return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::XTitle));
788   }
789
790   void XYPlot_i::SetYTitle (const char* theTitle)
791   {
792     //ProcessVoidEvent(new TSetTitleEvent(myView, &Plot2d_ViewFrame::setYTitle, theTitle));
793     ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::YTitle, theTitle));
794   }
795   char* XYPlot_i::GetYTitle()
796   {
797     //return CORBA::string_dup(myView->getYTitle());
798     return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::YTitle));
799   }
800
801   void XYPlot_i::ShowLegend (CORBA::Boolean theShowing)
802   {
803     ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,bool,bool>
804                      (myView,&Plot2d_ViewFrame::showLegend,theShowing,true));
805   }
806
807   class TXYPlotViewEvent: public SALOME_Event
808   {
809     _PTR(Study)       myStudy;
810     Plot2d_ViewFrame* myView;
811     PrsObject_ptr     myPrsObj;
812     int               myDisplaing;
813
814   public:
815     TXYPlotViewEvent(_PTR(Study)       theStudy,
816                      Plot2d_ViewFrame* theView,
817                      PrsObject_ptr     thePrsObj,
818                      int               theDisplaing)
819       : myStudy(theStudy),
820       myView(theView),
821       myPrsObj(thePrsObj),
822       myDisplaing(theDisplaing)
823     {
824     }
825
826     virtual void Execute()
827     {
828       // is it Curve ?
829       if (Curve_i* aCurve = dynamic_cast<Curve_i*>(VISU::GetServant(myPrsObj).in())) {
830         UpdatePlot2d(myView,myDisplaing,aCurve);
831       }
832       // is it Container ?
833       if (Container_i* aContainer = dynamic_cast<Container_i*>(VISU::GetServant(myPrsObj).in())) {
834         int nbCurves = aContainer->GetNbCurves();
835         for ( int i = 1; i <= nbCurves; i++ ) {
836           VISU::Curve_i* aCurve = aContainer->GetCurve( i );
837           if ( aCurve && aCurve->IsValid() ) {
838             UpdatePlot2d(myView,myDisplaing,aCurve);
839           }
840         }
841         myView->Repaint();
842       }
843       // is it Table ?
844       if (Table_i* aTable = dynamic_cast<Table_i*>(VISU::GetServant(myPrsObj).in())) {
845         _PTR(SObject) TableSO = myStudy->FindObjectID(aTable->GetEntry());
846         if (TableSO) {
847           _PTR(ChildIterator) Iter = myStudy->NewChildIterator(TableSO);
848           for (; Iter->More(); Iter->Next()) {
849             CORBA::Object_var childObject = VISU::ClientSObjectToObject(Iter->Value());
850             if (!CORBA::is_nil(childObject)) {
851               CORBA::Object_ptr aCurve = VISU::Curve::_narrow(childObject);
852               if (!CORBA::is_nil(aCurve))
853                 UpdatePlot2d(myView, myDisplaing,
854                              dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in()));
855             }
856           }
857           myView->Repaint();
858         }
859       }
860     }
861   };
862
863   void XYPlot_i::Display (PrsObject_ptr thePrsObj)
864   {
865     //jfa tmp:ProcessVoidEvent(new TXYPlotViewEvent (myStudy,myView,thePrsObj,eDisplay));
866   }
867
868   void XYPlot_i::Erase (PrsObject_ptr thePrsObj)
869   {
870     //jfa tmp:ProcessVoidEvent(new TXYPlotViewEvent (myStudy,myView,thePrsObj,eErase));
871   }
872
873   void XYPlot_i::DisplayOnly (PrsObject_ptr thePrsObj)
874   {
875     //jfa tmp:ProcessVoidEvent(new TXYPlotViewEvent (myStudy,myView,thePrsObj,eDisplayOnly));
876   }
877
878   void XYPlot_i::EraseAll()
879   {
880     ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame> (myView,&Plot2d_ViewFrame::EraseAll));
881   }
882
883   void XYPlot_i::FitAll()
884   {
885     ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame> (myView,&Plot2d_ViewFrame::fitAll));
886   }
887
888   CORBA::Boolean XYPlot_i::SavePicture (const char* theFileName)
889   {
890     return ProcessEvent(new TSavePictureEvent (myView->getViewWidget(),theFileName));
891   }
892
893
894   //===========================================================================
895   TableView_i::TableView_i (SalomeApp_Application* theApplication)
896     : View_i(theApplication, theApplication->getViewManager("???"/*jfa tmp*/, true))
897   {
898   }
899
900   Storable* TableView_i::Create (VISU::Table_ptr theTable)
901   {
902     if (MYDEBUG) MESSAGE("TableView_i::Create - " << (!theTable->_is_nil()));
903     if (!theTable->_is_nil()) {
904       VISU::Table_i* table = dynamic_cast<VISU::Table_i*>(VISU::GetServant(theTable).in());
905       if (MYDEBUG) MESSAGE("TableView_i::Create - dynamic_cast = " << table);
906       if (table != NULL) {
907
908         if (SUIT_Study* aSStudy = myViewManager->study()) {
909           if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
910             if (_PTR(Study) aCStudy = aStudy->studyDS()) {
911               _PTR(SObject) aSObject = aCStudy->FindObjectID(table->GetObjectEntry());
912               if (aSObject) {
913                 //jfa tmp:myView = new SALOMEGUI_TableDlg (QAD_Application::getDesktop(),
914                 //jfa tmp:                                 aSObject,
915                 //jfa tmp:                                 false,
916                 //jfa tmp:                                 SALOMEGUI_TableDlg::ttAuto,
917                 //jfa tmp:                                 Qt::Vertical);
918                 //jfa tmp:myView->show();
919                 return this;
920               }
921             }
922           }
923         }
924       }
925     }
926     return NULL;
927   }
928
929   TableView_i::~TableView_i()
930   {
931     if(MYDEBUG) MESSAGE("TableView_i::~TableView_i");
932     //jfa tmp:delete myView;
933   }
934
935   void TableView_i::SetTitle (const char* theTitle)
936   {
937     //jfa tmp:ProcessVoidEvent(new TVoidMemFun1ArgEvent<SALOMEGUI_TableDlg,const QString&,QString>
938     //jfa tmp:                 (myView, &SALOMEGUI_TableDlg::setCaption, QString(theTitle)));
939   }
940
941   char* TableView_i::GetTitle()
942   {
943     //jfa tmp:return CORBA::string_dup(myView->caption().latin1());
944     return "";
945   }
946
947   void TableView_i::Close()
948   {
949     //jfa tmp:myView->close();
950   }
951
952
953   //===========================================================================
954   int View3D_i::myNbViewParams = 0;
955   const string View3D_i::myComment = "VIEW3D";
956   const char* View3D_i::GetComment() const { return myComment.c_str();}
957
958   QString View3D_i::GenerateViewParamsName()
959   {
960     return VISU::GenerateName("ViewParams", ++myNbViewParams);
961   }
962
963   View3D_i::View3D_i (SalomeApp_Application* theApplication)
964     : View_i(theApplication, theApplication->getViewManager(SVTK_Viewer::Type(), true))
965   {
966     if (MYDEBUG) MESSAGE("View3D_i::View3D_i");
967   }
968
969   Storable* View3D_i::Create (int theNew)
970   {
971     if (MYDEBUG) MESSAGE("View3D_i::Create");
972     if (theNew) {
973       myViewWindow = myViewManager->createViewWindow();
974     } else {
975       myViewWindow = myViewManager->getActiveView();
976     }
977     return this;
978   }
979
980   void View3D_i::Update()
981   {
982     class TEvent: public SALOME_Event
983     {
984       SUIT_ViewWindow* myViewWindow;
985     public:
986       TEvent(SUIT_ViewWindow* theStudyFrame):
987         myViewWindow(theStudyFrame)
988       {}
989       virtual void Execute()
990       {
991         SVTK_ViewWindow* vf = GetViewWindow(myViewWindow);
992         vtkRenderer* Renderer = vf->getRenderer();
993         vtkActorCollection* theActors = Renderer->GetActors();
994         theActors->InitTraversal();
995         while (vtkActor *anAct = theActors->GetNextActor()) {
996           if (VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)) {
997             VISU::Prs3d_i* aPrs3d  = anActor->GetPrs3d();
998             if (anActor->GetVisibility() && aPrs3d) {
999               aPrs3d->Update();
1000               aPrs3d->UpdateActor(anActor);
1001             }
1002           }
1003         }
1004         RepaintView(myViewWindow);
1005       }
1006     };
1007     ProcessVoidEvent(new TEvent(myViewWindow));
1008   }
1009
1010   CORBA::Boolean View3D_i::SavePicture (const char* theFileName)
1011   {
1012     //jfa tmp:return ProcessEvent(new TSavePictureEvent
1013     //jfa tmp:                    (myView->getViewWidget(), theFileName));
1014     return false;
1015   }
1016
1017   bool View3D_i::SaveViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1018   {
1019     _PTR(Study) aCStudy;
1020     if (SUIT_Study* aSStudy = theViewManager->study()) {
1021       if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1022         aCStudy = aStudy->studyDS();
1023       }
1024     }
1025     if (!aCStudy)
1026       return false;
1027
1028     if (theName) {
1029       std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1030       _PTR(GenericAttribute) anAttr;
1031       int iEnd = aList.size();
1032       for (int i = 0; i < iEnd; i++) {
1033         _PTR(SObject) anObj = aList[i];
1034         string anEntry = anObj->GetID();
1035         if(MYDEBUG) MESSAGE("View3D_i::SaveViewParams - anEntry = " << anEntry);
1036         if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1037           _PTR(AttributeComment) aCmnt (anAttr);
1038           string aComm (aCmnt->Value());
1039           if (MYDEBUG) MESSAGE("View3D_i::SaveViewPoint - aComm = " << aComm);
1040           if (aComm.compare(View3D_i::myComment) >= 0) {
1041             aCmnt->SetValue(ToString(theViewManager->getActiveView()).c_str());
1042             return true;
1043           }
1044         }
1045       }
1046     }
1047     _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy);
1048     string aSComponentEntry = aSComponent->GetID();
1049     string anEntry = CreateAttributes(aCStudy, aSComponentEntry.c_str(), "", "", theName, "",
1050                                       ToString(theViewManager->getActiveView()).c_str());
1051     return true;
1052   }
1053
1054   CORBA::Boolean View3D_i::SaveViewParams (const char* theName)
1055   {
1056     return SaveViewParams(myViewManager, theName);
1057   }
1058
1059   bool View3D_i::RestoreViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1060   {
1061     _PTR(Study) aCStudy;
1062     if (SUIT_Study* aSStudy = theViewManager->study()) {
1063       if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1064         aCStudy = aStudy->studyDS();
1065       }
1066     }
1067     if (!aCStudy)
1068       return false;
1069
1070     std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1071     _PTR(GenericAttribute) anAttr;
1072     int iEnd = aList.size();
1073     if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - iEnd = " << iEnd);
1074     for (int i = 0; i < iEnd; i++) {
1075       _PTR(SObject) anObj = aList[i];
1076       string anEntry = anObj->GetID();
1077       if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - anEntry = " << anEntry);
1078       if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1079         _PTR(AttributeComment) aCmnt (anAttr);
1080         QString strIn (aCmnt->Value());
1081         Storable::TRestoringMap aMap;
1082         Storable::StrToMap(strIn, aMap);
1083         if (Storable::FindValue(aMap, "myComment").compare
1084             (View3D_i::myComment.c_str()) >= 0) {
1085           if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - aComm = " << strIn);
1086           Restore(theViewManager->getActiveView(), aMap);
1087           return true;
1088         }
1089       }
1090     }
1091     return false;
1092   }
1093
1094   class TRestoreViewParamsEvent: public SALOME_Event
1095   {
1096     SUIT_ViewManager* myViewManager;
1097     const char*       myName;
1098   public:
1099     TRestoreViewParamsEvent (SUIT_ViewManager* theViewManager,
1100                              const char*       theName):
1101       myViewManager(theViewManager),
1102       myName(theName)
1103     {}
1104
1105     virtual void Execute()
1106     {
1107       myResult = View3D_i::RestoreViewParams(myViewManager, myName);
1108     }
1109     typedef CORBA::Boolean TResult;
1110     TResult myResult;
1111   };
1112
1113   CORBA::Boolean View3D_i::RestoreViewParams (const char* theName)
1114   {
1115     return ProcessEvent(new TRestoreViewParamsEvent (myViewManager, theName));
1116   }
1117
1118   void View3D_i::Restore (SUIT_ViewWindow* theStudyFrame,
1119                           const Storable::TRestoringMap& theMap)
1120   {
1121     SALOMEDS::Color aColor;
1122     aColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
1123     aColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
1124     aColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
1125
1126     double aPosition[3];
1127     aPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
1128     aPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
1129     aPosition[2] = VISU::Storable::FindValue(theMap,"myPosition[2]").toDouble();
1130
1131     double aFocalPnt[3];
1132     aFocalPnt[0] = VISU::Storable::FindValue(theMap,"myFocalPnt[0]").toDouble();
1133     aFocalPnt[1] = VISU::Storable::FindValue(theMap,"myFocalPnt[1]").toDouble();
1134     aFocalPnt[2] = VISU::Storable::FindValue(theMap,"myFocalPnt[2]").toDouble();
1135
1136     double aViewUp[3];
1137     aViewUp[0] = VISU::Storable::FindValue(theMap,"myViewUp[0]").toDouble();
1138     aViewUp[1] = VISU::Storable::FindValue(theMap,"myViewUp[1]").toDouble();
1139     aViewUp[2] = VISU::Storable::FindValue(theMap,"myViewUp[2]").toDouble();
1140
1141     double aParallelScale = VISU::Storable::FindValue(theMap,"myParallelScale").toDouble();
1142
1143     double aScaleFactor[3];
1144     aScaleFactor[0] = VISU::Storable::FindValue(theMap,"myScaleFactor[0]").toDouble();
1145     aScaleFactor[1] = VISU::Storable::FindValue(theMap,"myScaleFactor[1]").toDouble();
1146     aScaleFactor[2] = VISU::Storable::FindValue(theMap,"myScaleFactor[2]").toDouble();
1147
1148     SetBackground(theStudyFrame,aColor);
1149     SetPointOfView(theStudyFrame,aPosition);
1150     SetViewUp(theStudyFrame,aViewUp);
1151     SetFocalPoint(theStudyFrame,aFocalPnt);
1152     SetParallelScale(theStudyFrame,aParallelScale);
1153     ScaleView(theStudyFrame,VISU::View3D::XAxis,aScaleFactor[0]);
1154     ScaleView(theStudyFrame,VISU::View3D::YAxis,aScaleFactor[1]);
1155     ScaleView(theStudyFrame,VISU::View3D::ZAxis,aScaleFactor[2]);
1156   }
1157
1158
1159   string View3D_i::ToString (SUIT_ViewWindow* theStudyFrame)
1160   {
1161     ostringstream strOut;
1162     Storable::DataToStream( strOut, "myComment", myComment.c_str() );
1163     ToStream(theStudyFrame,strOut);
1164     strOut<<ends;
1165     if(MYDEBUG) MESSAGE("View3D_i::ToString - "<<strOut.str());
1166     return strOut.str();
1167   }
1168
1169   void View3D_i::ToStream (SUIT_ViewWindow* theStudyFrame, std::ostringstream& theStr)
1170   {
1171     Storable::DataToStream(theStr,"myType",VISU::TVIEW3D);
1172
1173     float backint[3];
1174     GetRenderer(theStudyFrame)->GetBackground(backint);
1175     Storable::DataToStream(theStr,"myColor.R",backint[0]);
1176     Storable::DataToStream(theStr,"myColor.G",backint[1]);
1177     Storable::DataToStream(theStr,"myColor.B",backint[2]);
1178
1179     double aPosition[3];
1180     GetPointOfView(theStudyFrame,aPosition);
1181     Storable::DataToStream(theStr,"myPosition[0]",aPosition[0]);
1182     Storable::DataToStream(theStr,"myPosition[1]",aPosition[1]);
1183     Storable::DataToStream(theStr,"myPosition[2]",aPosition[2]);
1184
1185     double aFocalPnt[3];
1186     GetFocalPoint(theStudyFrame,aFocalPnt);
1187     Storable::DataToStream(theStr,"myFocalPnt[0]",aFocalPnt[0]);
1188     Storable::DataToStream(theStr,"myFocalPnt[1]",aFocalPnt[1]);
1189     Storable::DataToStream(theStr,"myFocalPnt[2]",aFocalPnt[2]);
1190
1191     double aViewUp[3];
1192     GetCamera(theStudyFrame)->GetViewUp(aViewUp);
1193     Storable::DataToStream(theStr,"myViewUp[0]",aViewUp[0]);
1194     Storable::DataToStream(theStr,"myViewUp[1]",aViewUp[1]);
1195     Storable::DataToStream(theStr,"myViewUp[2]",aViewUp[2]);
1196
1197     Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(theStudyFrame));
1198
1199     double aScaleFactor[3];
1200     GetViewWindow(theStudyFrame)->GetScale(aScaleFactor);
1201     Storable::DataToStream(theStr,"myScaleFactor[0]",aScaleFactor[0]);
1202     Storable::DataToStream(theStr,"myScaleFactor[1]",aScaleFactor[1]);
1203     Storable::DataToStream(theStr,"myScaleFactor[2]",aScaleFactor[2]);
1204   }
1205
1206   void View3D_i::ToStream(std::ostringstream& theStr)
1207   {
1208     ToStream(myViewWindow,theStr);
1209   }
1210
1211   void View3D_i::Close()
1212   {
1213     myViewWindow->close();
1214   }
1215
1216   View3D_i::~View3D_i()
1217   {
1218     if(MYDEBUG) MESSAGE("View3D_i::~View3D_i");
1219   }
1220
1221   void View3D_i::SetTitle (const char* theTitle)
1222   {
1223     ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
1224                      (myViewWindow,&SUIT_ViewWindow::setCaption,QString(theTitle)));
1225   }
1226
1227   char* View3D_i::GetTitle()
1228   {
1229     return CORBA::string_dup(myViewWindow->caption().latin1());
1230   }
1231
1232   void View3D_i::SetBackground (SUIT_ViewWindow* theStudyFrame,
1233                                 const SALOMEDS::Color& theColor)
1234   {
1235     int aColor[3];
1236     aColor[0] = int(255.0*theColor.R);
1237     aColor[1] = int(255.0*theColor.G);
1238     aColor[2] = int(255.0*theColor.B);
1239     QColor aNewColor(aColor[0],aColor[1],aColor[2]);
1240     GetViewWindow(theStudyFrame)->setBackgroundColor(aNewColor);
1241   }
1242
1243   SALOMEDS::Color View3D_i::GetBackground (SUIT_ViewWindow* theStudyFrame)
1244   {
1245     SALOMEDS::Color aColor;
1246     float backint[3];
1247     GetRenderer(theStudyFrame)->GetBackground(backint);
1248     aColor.R = backint[0];  aColor.G = backint[1];  aColor.B = backint[2];
1249     return aColor;
1250   }
1251
1252   class TUpdateViewerEvent: public SALOME_Event
1253   {
1254     SUIT_ViewWindow* myViewWindow;
1255     Prs3d_i* myPrs3d;
1256     int myDisplaing;
1257   public:
1258     TUpdateViewerEvent(SUIT_ViewWindow* theStudyFrame,
1259                        Prs3d_i* thePrs3d,
1260                        int theDisplaing):
1261       myViewWindow(theStudyFrame),
1262       myPrs3d(thePrs3d),
1263       myDisplaing(theDisplaing)
1264     {}
1265     virtual void Execute(){
1266       UpdateViewer(myViewWindow,myDisplaing,myPrs3d);
1267     }
1268   };
1269
1270   void View3D_i::EraseAll()
1271   {
1272     if(MYDEBUG) MESSAGE("View3D_i::EraseAll");
1273     ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,NULL,eEraseAll));
1274   }
1275
1276   void View3D_i::DisplayAll()
1277   {
1278     if(MYDEBUG) MESSAGE("View3D_i::DisplayAll");
1279     ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,NULL,eDisplayAll));
1280   }
1281
1282   void View3D_i::Erase (PrsObject_ptr thePrsObj)
1283   {
1284     if(MYDEBUG) MESSAGE("View3D_i::Erase");
1285     CORBA::Object_ptr anObj = thePrsObj;
1286     if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1287       ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eErase));
1288     }
1289   }
1290
1291   void View3D_i::Display (PrsObject_ptr thePrsObj)
1292   {
1293     if(MYDEBUG) MESSAGE("View3D_i::Display");
1294     CORBA::Object_ptr anObj = thePrsObj;
1295     if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1296       ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eDisplay));
1297     }
1298   }
1299
1300   void View3D_i::DisplayOnly (PrsObject_ptr thePrsObj)
1301   {
1302     if(MYDEBUG) MESSAGE("View3D_i::DisplayOnly");
1303     CORBA::Object_ptr anObj = thePrsObj;
1304     if(Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in())){
1305       ProcessVoidEvent(new TUpdateViewerEvent(myViewWindow,aPrs,eDisplayOnly));
1306     }
1307   }
1308
1309   void View3D_i::FitAll()
1310   {
1311     ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1312                      (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onFitAll));
1313     Update();
1314   }
1315
1316   void View3D_i::SetView (VISU::View3D::ViewType theType)
1317   {
1318     switch (theType) {
1319     case VISU::View3D::FRONT :
1320       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1321                        (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onFrontView));
1322       break;
1323     case VISU::View3D::BACK :
1324       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1325                        (GetViewWindow(myViewWindow), &SVTK_ViewWindow::onBackView));
1326       break;
1327     case VISU::View3D::LEFT :
1328       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1329                        (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onLeftView));
1330       break;
1331     case VISU::View3D::RIGHT :
1332       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1333                        (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onRightView));
1334       break;
1335     case VISU::View3D::TOP :
1336       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1337                        (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onTopView));
1338       break;
1339     case VISU::View3D::BOTTOM :
1340       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1341                        (GetViewWindow(myViewWindow),&SVTK_ViewWindow::onBottomView));
1342       break;
1343     }
1344     Update();
1345   }
1346
1347   class TSet3DViewParamEvent: public SALOME_Event
1348   {
1349   public:
1350     typedef void (*TFun)(SUIT_ViewWindow* theStudyFrame, const CORBA::Double theParam[3]);
1351     TSet3DViewParamEvent (TFun theFun,
1352                           SUIT_ViewWindow* theStudyFrame,
1353                           const CORBA::Double theParam[3]):
1354       myFun(theFun),
1355       myViewWindow(theStudyFrame),
1356       myParam(theParam)
1357     {}
1358     virtual void Execute(){
1359       myFun(myViewWindow,myParam);
1360     }
1361   private:
1362     TFun myFun;
1363     SUIT_ViewWindow* myViewWindow;
1364     const CORBA::Double* myParam;
1365   };
1366
1367   void View3D_i::SetPointOfView (SUIT_ViewWindow* theStudyFrame,
1368                                  const CORBA::Double thePosition[3])
1369   {
1370     GetCamera(theStudyFrame)->SetPosition(thePosition);
1371   }
1372
1373   void View3D_i::SetPointOfView (const VISU::View3D::XYZ thePosition)
1374   {
1375     if(MYDEBUG) MESSAGE("View3D_i::SetPointOfView");
1376     ProcessVoidEvent(new TSet3DViewParamEvent(&SetPointOfView,myViewWindow,thePosition));
1377   }
1378
1379   void View3D_i::GetPointOfView (SUIT_ViewWindow* theStudyFrame,
1380                                  CORBA::Double thePosition[3])
1381   {
1382     GetCamera(theStudyFrame)->GetPosition(thePosition);
1383   }
1384
1385   VISU::View3D::XYZ_slice* View3D_i::GetPointOfView()
1386   {
1387     if(MYDEBUG) MESSAGE("View3D_i::GetPointOfView");
1388     CORBA::Double aPosition[3];
1389     GetPointOfView(myViewWindow,aPosition);
1390     return VISU::View3D::XYZ_dup(aPosition);
1391   }
1392
1393   void View3D_i::SetViewUp (SUIT_ViewWindow* theStudyFrame,
1394                             const CORBA::Double theViewUp[3])
1395   {
1396     GetCamera(theStudyFrame)->SetViewUp(theViewUp);
1397   }
1398
1399   void View3D_i::SetViewUp (const VISU::View3D::XYZ theViewUp)
1400   {
1401     if(MYDEBUG) MESSAGE("View3D_i::SetViewUp");
1402     ProcessVoidEvent(new TSet3DViewParamEvent(&SetViewUp,myViewWindow,theViewUp));
1403   }
1404
1405   void View3D_i::GetViewUp (SUIT_ViewWindow* theStudyFrame,
1406                             CORBA::Double theViewUp[3])
1407   {
1408     GetCamera(theStudyFrame)->GetViewUp(theViewUp);
1409   }
1410
1411   VISU::View3D::XYZ_slice* View3D_i::GetViewUp()
1412   {
1413     if(MYDEBUG) MESSAGE("View3D_i::GetViewUp");
1414     CORBA::Double aViewUp[3];
1415     GetCamera(myViewWindow)->GetViewUp(aViewUp);
1416     return VISU::View3D::XYZ_dup(aViewUp);
1417   }
1418
1419   void View3D_i::SetFocalPoint (SUIT_ViewWindow* theStudyFrame,
1420                                 const CORBA::Double theFocalPnt[3])
1421   {
1422     GetCamera(theStudyFrame)->SetFocalPoint(theFocalPnt);
1423   }
1424
1425   void View3D_i::SetFocalPoint (const VISU::View3D::XYZ theCoord)
1426   {
1427     if(MYDEBUG) MESSAGE("View3D_i::SetFocalPoint");
1428     ProcessVoidEvent(new TSet3DViewParamEvent(&SetFocalPoint,myViewWindow,theCoord));
1429   }
1430
1431
1432   void View3D_i::GetFocalPoint (SUIT_ViewWindow* theStudyFrame,
1433                                 CORBA::Double theFocalPnt[3])
1434   {
1435     GetCamera(theStudyFrame)->GetFocalPoint(theFocalPnt);
1436   }
1437
1438   VISU::View3D::XYZ_slice* View3D_i::GetFocalPoint()
1439   {
1440     if(MYDEBUG) MESSAGE("View3D_i::GetFocalPoint");
1441     CORBA::Double aFocalPnt[3];
1442     GetFocalPoint(myViewWindow,aFocalPnt);
1443     return VISU::View3D::XYZ_dup(aFocalPnt);
1444   }
1445
1446   class TSetViewParamEvent: public SALOME_Event
1447   {
1448   public:
1449     typedef void (*TFun)(SUIT_ViewWindow* theStudyFrame, CORBA::Double theParam);
1450     TSetViewParamEvent (TFun theFun,
1451                         SUIT_ViewWindow* theStudyFrame,
1452                         CORBA::Double theParam):
1453       myFun(theFun),
1454       myViewWindow(theStudyFrame),
1455       myParam(theParam)
1456     {}
1457     virtual void Execute()
1458     {
1459       myFun(myViewWindow,myParam);
1460     }
1461   private:
1462     TFun myFun;
1463     SUIT_ViewWindow* myViewWindow;
1464     CORBA::Double myParam;
1465   };
1466
1467   void View3D_i::SetParallelScale (SUIT_ViewWindow* theStudyFrame,
1468                                    CORBA::Double theScale)
1469   {
1470     GetCamera(theStudyFrame)->SetParallelScale(theScale);
1471   }
1472
1473   void View3D_i::SetParallelScale (CORBA::Double theScale)
1474   {
1475     if(MYDEBUG) MESSAGE("View3D_i::SetParallelScale");
1476     ProcessVoidEvent(new TSetViewParamEvent(&SetParallelScale,myViewWindow,theScale));
1477   }
1478
1479   CORBA::Double View3D_i::GetParallelScale (SUIT_ViewWindow* theStudyFrame)
1480   {
1481     return GetCamera(theStudyFrame)->GetParallelScale();
1482   }
1483
1484   CORBA::Double View3D_i::GetParallelScale()
1485   {
1486     if(MYDEBUG) MESSAGE("View3D_i::GetParallelScale");
1487     return GetParallelScale(myViewWindow);
1488   }
1489
1490   void View3D_i::ScaleView (SUIT_ViewWindow* theStudyFrame,
1491                             VISU::View3D::Axis theAxis, CORBA::Double theParam)
1492   {
1493     SVTK_ViewWindow* aViewFrame = GetViewWindow(theStudyFrame);
1494     double aScaleFactor[3];
1495     aViewFrame->GetScale(aScaleFactor);
1496     aScaleFactor[theAxis] = theParam;
1497     aViewFrame->SetScale(aScaleFactor);
1498   }
1499
1500   void SetScaleView (SUIT_ViewWindow* theStudyFrame, const CORBA::Double theScale[3])
1501   {
1502     double aScale[3] = {theScale[0], theScale[1], theScale[2]};
1503     GetViewWindow(theStudyFrame)->SetScale(aScale);
1504   }
1505
1506   void View3D_i::ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam)
1507   {
1508     if(MYDEBUG) MESSAGE("View3D_i::ScaleView");
1509     double aScale[3];
1510     GetViewWindow(myViewWindow)->GetScale(aScale);
1511     aScale[theAxis] = theParam;
1512     ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myViewWindow,aScale));
1513   }
1514
1515   void View3D_i::RemoveScale()
1516   {
1517     if(MYDEBUG) MESSAGE("View3D_i::RemoveScale");
1518     double aScale[3] = {1.0, 1.0, 1.0};
1519     ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,myViewWindow,aScale));
1520   }
1521 }