Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[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 "VisuGUI_TableDlg.h"
35
36 #include "VISU_Actor.h"
37
38 #include "SALOME_Event.hxx"
39
40 #include "SUIT_ViewWindow.h"
41 #include "SUIT_ViewManager.h"
42 #include "SUIT_Tools.h"
43
44 #include "STD_MDIDesktop.h"
45 #include "STD_TabDesktop.h"
46
47 #include "SVTK_ViewWindow.h"
48 #include "SVTK_ViewModel.h"
49
50 #include "SPlot2d_ViewModel.h"
51 #include "Plot2d_ViewFrame.h"
52
53 #include "SalomeApp_Application.h"
54 #include "SalomeApp_Study.h"
55
56 #include <QtxWorkstack.h>
57
58 #include <qworkspace.h>
59 #include <qimage.h>
60
61 #include <vtkCamera.h>
62 #include <vtkRenderer.h>
63
64 using namespace std;
65
66 #ifdef _DEBUG_
67 static int MYDEBUG = 0;
68 #else
69 static int MYDEBUG = 0;
70 #endif
71
72 namespace VISU {
73
74   typedef TVoidMemFunEvent<SUIT_ViewWindow> TFrameActionEvent;
75
76   struct TNewViewEvent: public SALOME_Event
77   {
78     SalomeApp_Application* myApplication;
79     typedef QWidget* TResult;
80     TResult myResult;
81
82     TNewViewEvent (SalomeApp_Application* theApplication):
83       myApplication(theApplication),
84       myResult(NULL)
85     {}
86
87     virtual
88     void
89     Execute()
90     {
91       if (STD_MDIDesktop* aDesktop = dynamic_cast<STD_MDIDesktop*>(myApplication->desktop())) {
92         myResult = aDesktop->workspace();
93       }
94     }
95   };
96
97   View_i::
98   View_i (SalomeApp_Application *theApplication,
99           SUIT_ViewManager* theViewManager):
100     myApplication(theApplication),
101     myWorkspace(NULL),
102     myViewManager(theViewManager)
103   {
104     if(MYDEBUG) MESSAGE("View_i::View_i - "<<this);
105     myWorkspace = ProcessEvent(new TNewViewEvent(theApplication));
106   }
107
108   View_i::
109   ~View_i()
110   {
111     if(MYDEBUG) MESSAGE("View_i::~View_i - "<<this);
112   }
113
114
115   struct TApplicationEvent: public SALOME_Event
116   {
117     SalomeApp_Application* myApplication;
118
119     TApplicationEvent(SalomeApp_Application* theApplication):
120       myApplication(theApplication)
121     {}
122   };
123
124   void
125   View_i::
126   ShowPart (VISU::View::ViewRepresentation theViewRepresentation,
127             CORBA::Boolean theState)
128   {
129     struct TEvent: public TApplicationEvent
130     {
131       VISU::View::ViewRepresentation myViewRepresentation;
132       CORBA::Boolean myState;
133
134       TEvent(SalomeApp_Application* theApplication,
135              VISU::View::ViewRepresentation theViewRepresentation,
136              CORBA::Boolean theState):
137         TApplicationEvent(theApplication),
138         myViewRepresentation(theViewRepresentation),
139         myState(theState)
140       {}
141
142       virtual
143       void
144       Execute()
145       {
146         switch(myViewRepresentation){
147         case VISU::View::OBJECTBROWSER:
148           myApplication->setWindowShown(SalomeApp_Application::WT_ObjectBrowser,myState);
149           break;
150         case VISU::View::PYTHON:
151           myApplication->setWindowShown(SalomeApp_Application::WT_PyConsole,myState);
152           break;
153         case VISU::View::MESSAGES:
154           myApplication->setWindowShown(SalomeApp_Application::WT_LogWindow,myState);
155           break;
156         case VISU::View::VIEWER:{
157           ViewManagerList aViewManagerList = myApplication->viewManagers();
158           // to do something
159           // ...
160           break;
161         }}
162       }
163     };
164
165     ProcessVoidEvent(new TEvent(myApplication,theViewRepresentation,theState));
166   }
167
168   struct TPartShownEvent: public TApplicationEvent
169   {
170     VISU::View::ViewRepresentation myViewRepresentation;
171     typedef bool TResult;
172     TResult myResult;
173
174     TPartShownEvent(SalomeApp_Application* theApplication,
175                     VISU::View::ViewRepresentation theViewRepresentation):
176       TApplicationEvent(theApplication),
177       myViewRepresentation(theViewRepresentation),
178       myResult(false)
179     {}
180
181     virtual
182     void
183     Execute()
184     {
185       switch(myViewRepresentation){
186       case VISU::View::OBJECTBROWSER:
187         myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_ObjectBrowser);
188         break;
189       case VISU::View::PYTHON:
190         myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_PyConsole);
191         break;
192       case VISU::View::MESSAGES:
193         myResult = myApplication->isWindowVisible(SalomeApp_Application::WT_LogWindow);
194         break;
195       case VISU::View::VIEWER:{
196         ViewManagerList aViewManagerList = myApplication->viewManagers();
197         // to do something
198         // ...
199         break;
200       }}
201     }
202   };
203
204   CORBA::Boolean
205   View_i::
206   IsPartShown (VISU::View::ViewRepresentation theViewRepresentation)
207   {
208     return ProcessEvent(new TPartShownEvent(myApplication,theViewRepresentation));
209   }
210
211   // Begin: New methods for view parameters management
212   struct TSplitEvent: public SALOME_Event
213   {
214     SalomeApp_Application * myApplication;
215     SUIT_ViewWindow       * myVW;
216     Qt::Orientation         myOrientation;
217     QtxWorkstack::SplitType mySplitType;
218
219   public:
220     TSplitEvent (SalomeApp_Application * theApplication,
221                  SUIT_ViewWindow       * theViewWindow,
222                  Qt::Orientation         theOrientation,
223                  QtxWorkstack::SplitType theSplitType):
224       myApplication(theApplication),
225       myVW(theViewWindow),
226       myOrientation(theOrientation),
227       mySplitType(theSplitType)
228     {}
229
230     virtual void Execute()
231     {
232       SUIT_Desktop* desk = myApplication->desktop();
233       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>(desk);
234       if (tabDesk) {
235         QtxWorkstack* workstack = tabDesk->workstack();
236         if (workstack) {
237           workstack->Split(myVW, myOrientation, mySplitType);
238         }
239       }
240     }
241   };
242
243   void
244   View_i::
245   SplitRight()
246   {
247     SUIT_ViewWindow* aVW = GetViewWindow();
248     if (aVW)
249       ProcessVoidEvent(new TSplitEvent(myApplication, aVW,
250                                        Qt::Horizontal, QtxWorkstack::SPLIT_MOVE));
251   }
252
253   void
254   View_i::
255   SplitLeft()
256   {
257     SUIT_ViewWindow* aVW = GetViewWindow();
258     if (aVW)
259       ProcessVoidEvent(new TSplitEvent(myApplication, aVW,
260                                        Qt::Horizontal, QtxWorkstack::SPLIT_STAY));
261   }
262
263   void
264   View_i::
265   SplitBottom()
266   {
267     SUIT_ViewWindow* aVW = GetViewWindow();
268     if (aVW)
269       ProcessVoidEvent(new TSplitEvent(myApplication, aVW,
270                                        Qt::Vertical, QtxWorkstack::SPLIT_MOVE));
271   }
272
273   void
274   View_i::
275   SplitTop()
276   {
277     SUIT_ViewWindow* aVW = GetViewWindow();
278     if (aVW)
279       ProcessVoidEvent(new TSplitEvent(myApplication, aVW,
280                                        Qt::Vertical, QtxWorkstack::SPLIT_STAY));
281   }
282
283   void
284   View_i::
285   OnTop()
286   {
287     struct TOnTopEvent: public SALOME_Event
288     {
289       SUIT_ViewWindow * myVW;
290
291     public:
292       TOnTopEvent (SUIT_ViewWindow * theViewWindow):
293         myVW(theViewWindow)
294       {}
295
296       virtual void Execute()
297       {
298         if (myVW) {
299           myVW->setFocus();
300         }
301       }
302     };
303
304     SUIT_ViewWindow* aVW = GetViewWindow();
305     if (aVW)
306       ProcessVoidEvent(new TOnTopEvent(aVW));
307   }
308
309   struct TAttractEvent: public SALOME_Event
310   {
311     SalomeApp_Application * myApplication;
312     SUIT_ViewWindow       * myVW1;
313     SUIT_ViewWindow       * myVW2;
314     bool                    myAttractAll;
315
316   public:
317     TAttractEvent (SalomeApp_Application * theApplication,
318                    SUIT_ViewWindow       * theViewWindow1,
319                    SUIT_ViewWindow       * theViewWindow2,
320                    bool                    theAttractAll):
321       myApplication(theApplication),
322       myVW1(theViewWindow1),
323       myVW2(theViewWindow2),
324       myAttractAll(theAttractAll)
325     {}
326
327     virtual void Execute()
328     {
329       SUIT_Desktop* desk = myApplication->desktop();
330       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>(desk);
331       if (tabDesk) {
332         QtxWorkstack* workstack = tabDesk->workstack();
333         if (workstack) {
334           workstack->Attract(myVW1, myVW2, myAttractAll);
335         }
336       }
337     }
338   };
339
340   void
341   View_i::
342   Attract (VISU::View_ptr theView)
343   {
344     if (!CORBA::is_nil(theView)) {
345       if (VISU::View_i* pView = dynamic_cast<VISU::View_i*>(VISU::GetServant(theView).in())) {
346         if (pView) {
347           SUIT_ViewWindow* aVW1 = GetViewWindow();
348           SUIT_ViewWindow* aVW2 = pView->GetViewWindow();
349           if (aVW1 && aVW2)
350             ProcessVoidEvent(new TAttractEvent(myApplication, aVW1, aVW2, false));
351         }
352       }
353     }
354   }
355
356   void
357   View_i::
358   AttractAll (VISU::View_ptr theView)
359   {
360     if (!CORBA::is_nil(theView)) {
361       if (VISU::View_i* pView = dynamic_cast<VISU::View_i*>(VISU::GetServant(theView).in())) {
362         if (pView) {
363           SUIT_ViewWindow* aVW1 = GetViewWindow();
364           SUIT_ViewWindow* aVW2 = pView->GetViewWindow();
365           if (aVW1 && aVW2)
366             ProcessVoidEvent(new TAttractEvent(myApplication, aVW1, aVW2, true));
367         }
368       }
369     }
370   }
371
372   struct TSizePositionEvent: public SALOME_Event
373   {
374     SalomeApp_Application * myApplication;
375     SUIT_ViewWindow       * myVW;
376     double                  myValue;
377     bool                    myIsSize;
378
379   public:
380     TSizePositionEvent (SalomeApp_Application * theApplication,
381                         SUIT_ViewWindow       * theViewWindow,
382                         double                  theValue,
383                         bool                    theIsSize):
384       myApplication(theApplication),
385       myVW(theViewWindow),
386       myValue(theValue),
387       myIsSize(theIsSize)
388     {}
389
390     virtual void Execute()
391     {
392       MESSAGE("TSizePositionEvent::Execute()");
393       SUIT_Desktop* desk = myApplication->desktop();
394       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>(desk);
395       if (tabDesk) {
396         QtxWorkstack* workstack = tabDesk->workstack();
397         if (workstack) {
398           if (myIsSize) {
399             //jfa to do:workstack->SetRelativeSizeInSplitter(myVW, myValue);
400           } else {
401             workstack->SetRelativePositionInSplitter(myVW, myValue);
402           }
403         }
404       }
405     }
406   };
407
408   void
409   View_i::
410   SetRelativePositionInSplitter (CORBA::Double thePosition)
411   {
412     if (thePosition < 0.0 || 1.0 < thePosition) {
413       return;
414     }
415     SUIT_ViewWindow* aVW = GetViewWindow();
416     if (aVW)
417       ProcessVoidEvent(new TSizePositionEvent(myApplication, aVW, thePosition, false));
418   }
419
420   void
421   View_i::
422   SetRelativeSizeInSplitter (CORBA::Double theSize)
423   {
424     if (theSize < 0.0 || 1.0 < theSize) {
425       return;
426     }
427     SUIT_ViewWindow* aVW = GetViewWindow();
428     if (aVW)
429       ProcessVoidEvent(new TSizePositionEvent(myApplication, aVW, theSize, true));
430   }
431
432   struct TWSSizePositionEvent: public SALOME_Event
433   {
434     SalomeApp_Application * myApplication;
435     SUIT_ViewWindow       * myVW;
436     Qt::Orientation         myOrientation;
437     double                  myValue;
438     bool                    myIsSize;
439
440   public:
441     TWSSizePositionEvent (SalomeApp_Application * theApplication,
442                           SUIT_ViewWindow       * theViewWindow,
443                           Qt::Orientation         theOrientation,
444                           double                  theValue,
445                           bool                    theIsSize):
446       myApplication(theApplication),
447       myVW(theViewWindow),
448       myOrientation(theOrientation),
449       myValue(theValue),
450       myIsSize(theIsSize)
451     {}
452
453     virtual void Execute()
454     {
455       MESSAGE("TWSSizePositionEvent::Execute()");
456       SUIT_Desktop* desk = myApplication->desktop();
457       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>(desk);
458       if (tabDesk) {
459         QtxWorkstack* workstack = tabDesk->workstack();
460         if (workstack) {
461           if (myIsSize) {
462             //jfa to do:workstack->SetRelativeSize(myVW, myOrientation, myValue);
463           } else {
464             workstack->SetRelativePosition(myVW, myOrientation, myValue);
465           }
466         }
467       }
468     }
469   };
470
471   void
472   View_i::
473   SetRelativePositionX (CORBA::Double thePosition)
474   {
475     if (thePosition < 0.0 || 1.0 < thePosition) {
476       return;
477     }
478     SUIT_ViewWindow* aVW = GetViewWindow();
479     if (aVW)
480       ProcessVoidEvent(new TWSSizePositionEvent(myApplication, aVW,
481                                                 Qt::Horizontal, thePosition, false));
482   }
483
484   void
485   View_i::
486   SetRelativePositionY (CORBA::Double thePosition)
487   {
488     if (thePosition < 0.0 || 1.0 < thePosition) {
489       return;
490     }
491     SUIT_ViewWindow* aVW = GetViewWindow();
492     if (aVW)
493       ProcessVoidEvent(new TWSSizePositionEvent(myApplication, aVW,
494                                                 Qt::Vertical, thePosition, false));
495   }
496
497   void
498   View_i::
499   SetRelativeSizeX (CORBA::Double theSize)
500   {
501     if (theSize < 0.0 || 1.0 < theSize) {
502       return;
503     }
504     SUIT_ViewWindow* aVW = GetViewWindow();
505     if (aVW)
506       ProcessVoidEvent(new TWSSizePositionEvent(myApplication, aVW,
507                                                 Qt::Horizontal, theSize, true));
508   }
509
510   void
511   View_i::
512   SetRelativeSizeY (CORBA::Double theSize)
513   {
514     if (theSize < 0.0 || 1.0 < theSize) {
515       return;
516     }
517     SUIT_ViewWindow* aVW = GetViewWindow();
518     if (aVW)
519       ProcessVoidEvent(new TWSSizePositionEvent(myApplication, aVW,
520                                                 Qt::Vertical, theSize, true));
521   }
522   // End: New methods for view parameters management
523
524   // Begin: Old methods for view parameters management, they don't work now
525   struct TSetViewSize: public SALOME_Event
526   {
527     SUIT_ViewWindow* myVW;
528     typedef void (QRect::* TAction)(int);
529     TAction myAction;
530     CORBA::Long mySize;
531
532   public:
533     TSetViewSize(SUIT_ViewWindow* theViewWindow,
534                  TAction theAction,
535                  CORBA::Long theSize):
536       myVW(theViewWindow),
537       myAction(theAction),
538       mySize(theSize)
539     {}
540
541     virtual
542     void
543     Execute()
544     {
545       if (QWidget* aParent = myVW->parentWidget(true)) {
546         QRect aQRect = aParent->frameGeometry();
547         (aQRect.*myAction)(mySize);
548         aParent->setGeometry(aQRect);
549       }
550     }
551   };
552
553   void
554   View_i::
555   SetViewWidth(CORBA::Long theWidth)
556   {
557     ProcessVoidEvent(new TSetViewSize(myViewWindow,&QRect::setWidth,theWidth));
558   }
559
560   void
561   View_i::
562   SetViewHeight(CORBA::Long theHeight)
563   {
564     ProcessVoidEvent(new TSetViewSize(myViewWindow,&QRect::setHeight,theHeight));
565   }
566
567
568   struct TGetViewSize: public SALOME_Event
569   {
570     SUIT_ViewWindow* myVW;
571
572     typedef int (QRect::* TAction)() const;
573     TAction myAction;
574
575     typedef CORBA::Long TResult;
576     TResult myResult;
577
578   public:
579     TGetViewSize(SUIT_ViewWindow* theViewWindow,
580                  TAction theAction):
581       myVW(theViewWindow),
582       myAction(theAction)
583     {}
584
585     virtual
586     void
587     Execute()
588     {
589       if(QWidget* aParent = myVW->parentWidget(true)){
590         QRect aQRect = aParent->frameGeometry();
591         myResult = (aQRect.*myAction)();
592       }
593     }
594   };
595
596
597   CORBA::Long
598   View_i::
599   GetViewWidth()
600   {
601     return ProcessEvent(new TGetViewSize(myViewWindow,&QRect::width));
602   }
603
604   CORBA::Long
605   View_i::
606   GetViewHeight()
607   {
608     return ProcessEvent(new TGetViewSize(myViewWindow,&QRect::height));
609   }
610
611
612   class TWorkspaceEvent: public SALOME_Event
613   {
614   protected:
615     QWidget* myVW;
616     QWidget* myWorkspace;
617
618   public:
619     TWorkspaceEvent(QWidget* theViewWindow,
620                     QWidget* theWorkspace):
621       myVW(theViewWindow),
622       myWorkspace(theWorkspace)
623     {}
624   };
625
626
627   class TAlignEvent: public TWorkspaceEvent
628   {
629   protected:
630     Qt::AlignmentFlags myAligment;
631
632   public:
633     TAlignEvent(QWidget* theViewWindow,
634                 QWidget* theWorkspace,
635                 Qt::AlignmentFlags theAligment):
636       TWorkspaceEvent(theViewWindow,theWorkspace),
637       myAligment(theAligment)
638     {}
639
640     virtual
641     void
642     Execute()
643     {
644       if(QWidget* aParent = myVW->parentWidget(true))
645         SUIT_Tools::alignWidget(aParent,myWorkspace,myAligment);
646     }
647   };
648
649
650   void
651   View_i::
652   SetViewPositionHorizontal (VISU::View::ViewPosition theViewPosition)
653   {
654     if (myWorkspace) {
655       switch (theViewPosition) {
656       case VISU::View::LEFT:
657         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignLeft));
658         break;
659       case VISU::View::CENTER:
660         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignHCenter));
661         break;
662       case VISU::View::RIGHT:
663         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignRight));
664         break;
665       }
666     }
667   }
668
669
670   void
671   View_i::
672   SetViewPositionVertical (VISU::View::ViewPosition theViewPosition)
673   {
674     if (myWorkspace) {
675       switch (theViewPosition) {
676       case VISU::View::TOP:
677         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignTop));
678         break;
679       case VISU::View::CENTER:
680         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignVCenter));
681         break;
682       case VISU::View::BOTTOM:
683         ProcessVoidEvent(new TAlignEvent(myViewWindow,myWorkspace,Qt::AlignBottom));
684         break;
685       }
686     }
687   }
688
689
690   class TXYEvent: public TWorkspaceEvent
691   {
692   protected:
693     CORBA::Double myX, myY;
694
695   public:
696     TXYEvent(QWidget* theViewWindow,
697              QWidget* theWorkspace,
698              CORBA::Double theX,
699              CORBA::Double theY):
700       TWorkspaceEvent(theViewWindow,theWorkspace),
701       myX(theX),
702       myY(theY)
703     {}
704   };
705
706
707   void
708   View_i::
709   SetRelativePosition (CORBA::Double theX, CORBA::Double theY)
710   {
711     struct TEvent: public TXYEvent
712     {
713     public:
714       TEvent(QWidget* theViewWindow,
715              QWidget* theWorkspace,
716              CORBA::Double theX,
717              CORBA::Double theY):
718         TXYEvent(theViewWindow,theWorkspace,theX,theY)
719       {}
720
721       virtual
722       void
723       Execute()
724       {
725         if(QWidget* aParent = myVW->parentWidget(true))
726           aParent->move(int(myX*myWorkspace->width()),int(myY*myWorkspace->height()));
727       }
728     };
729
730     if (myWorkspace)
731       ProcessVoidEvent(new TEvent(myViewWindow,myWorkspace,theX,theY));
732   }
733
734   void
735   View_i::
736   SetRelativeSize (CORBA::Double theX, CORBA::Double theY)
737   {
738     struct TEvent: public TXYEvent
739     {
740     public:
741       TEvent(QWidget* theViewWindow,
742              QWidget* theWorkspace,
743              CORBA::Double theX,
744              CORBA::Double theY):
745         TXYEvent(theViewWindow,theWorkspace,theX,theY)
746       {}
747
748       virtual
749       void
750       Execute()
751       {
752         if(QWidget* aParent = myVW->parentWidget(true))
753           aParent->setGeometry(aParent->x(),
754                                aParent->y(),
755                                int(myX*myWorkspace->width()),
756                                int(myY*myWorkspace->height()));
757       }
758     };
759
760     if (myWorkspace)
761       ProcessVoidEvent(new TEvent(myViewWindow,myWorkspace,theX,theY));
762   }
763   // End: Old methods for view parameters management, they don't work now
764
765   void
766   View_i::
767   SetBackground (const SALOMEDS::Color& theColor)
768   {
769     struct TEvent: public SALOME_Event
770     {
771       QWidget* myWidget;
772       SALOMEDS::Color myColor;
773     public:
774       TEvent(QWidget* theWidget,
775              const SALOMEDS::Color& theColor):
776         myWidget(theWidget),
777         myColor(theColor)
778       {}
779       virtual void Execute(){
780         int aColor[3];
781         aColor[0] = int(255.0*myColor.R);
782         aColor[1] = int(255.0*myColor.G);
783         aColor[2] = int(255.0*myColor.B);
784         myWidget->setBackgroundColor(QColor(aColor[0],aColor[1],aColor[2]));
785       }
786     };
787
788     SUIT_ViewWindow* aVW = GetViewWindow();
789     if (aVW)
790       ProcessVoidEvent(new TEvent(aVW, theColor));
791   }
792
793
794   struct TBackgroundEvent: public SALOME_Event
795   {
796     QWidget* myWidget;
797     typedef SALOMEDS::Color TResult;
798     TResult myResult;
799
800     TBackgroundEvent(QWidget* theWidget):
801       myWidget(theWidget)
802     {}
803
804     virtual
805     void
806     Execute()
807     {
808       const QColor& aColor = myWidget->backgroundColor();
809       myResult.R = aColor.red()/255.0;
810       myResult.G = aColor.green()/255.0;
811       myResult.B = aColor.blue()/255.0;
812     }
813   };
814
815   SALOMEDS::Color
816   View_i::
817   GetBackground()
818   {
819     SUIT_ViewWindow* aVW = GetViewWindow();
820     if (aVW)
821       return ProcessEvent(new TBackgroundEvent(aVW));
822
823     SALOMEDS::Color aBlack;
824     aBlack.R = 0.0;
825     aBlack.G = 0.0;
826     aBlack.B = 0.0;
827     return aBlack;
828   }
829
830   void
831   View_i::
832   Minimize()
833   {
834     SUIT_ViewWindow* aVW = GetViewWindow();
835     if (aVW)
836       ProcessVoidEvent(new TFrameActionEvent(aVW, &SUIT_ViewWindow::showMinimized));
837   }
838
839   void
840   View_i::
841   Restore()
842   {
843     SUIT_ViewWindow* aVW = GetViewWindow();
844     if (aVW)
845       ProcessVoidEvent(new TFrameActionEvent(aVW, &SUIT_ViewWindow::showNormal));
846   }
847
848   void
849   View_i::
850   Maximize()
851   {
852     SUIT_ViewWindow* aVW = GetViewWindow();
853     if (aVW)
854       ProcessVoidEvent(new TFrameActionEvent(aVW, &SUIT_ViewWindow::showMaximized));
855   }
856
857   void
858   View_i::
859   EraseAll()
860   {}
861
862   void
863   View_i::
864   DisplayAll()
865   {}
866
867   void
868   View_i::
869   Erase (PrsObject_ptr thePrsObj)
870   {}
871
872   void
873   View_i::
874   Display (PrsObject_ptr thePrsObj)
875   {}
876
877   void
878   View_i::
879   DisplayOnly (PrsObject_ptr thePrsObj)
880   {}
881
882   void
883   View_i::
884   Update()
885   {}
886
887   class TSavePictureEvent: public SALOME_Event
888   {
889     SUIT_ViewWindow * myVW;
890     const char      * myFileName;
891   public:
892     typedef CORBA::Boolean TResult;
893     TResult myResult;
894     TSavePictureEvent (SUIT_ViewWindow * theViewWindow, const char * theFileName)
895       : myVW(theViewWindow),
896         myFileName(theFileName),
897         myResult(false)
898     {
899     }
900
901     virtual void Execute()
902     {
903       if (myVW) {
904         QImage img = myVW->dumpView();
905         if (!img.isNull()) {
906           QString fileName (myFileName);
907           if (!fileName.isEmpty()) {
908             QString fmt = SUIT_Tools::extension(fileName).upper();
909             if (fmt.isEmpty()) fmt = QString("BMP"); // default format
910             if (fmt == "JPG" ) fmt = "JPEG";
911             //QApplication::setOverrideCursor(Qt::waitCursor);
912             img.save(fileName, fmt.latin1());
913             myResult = true;
914             //QApplication::restoreOverrideCursor();
915           }
916         }
917       }
918     }
919   };
920
921   CORBA::Boolean
922   View_i::SavePicture(const char* theFileName)
923   {
924     return ProcessEvent(new TSavePictureEvent (GetViewWindow(), theFileName));
925   }
926
927   const char*
928   View_i::GetComment() const
929   {
930     return "";
931   }
932
933   void
934   View_i::
935   ToStream (std::ostringstream& theStr)
936   {
937   }
938
939   SUIT_ViewWindow* View_i::GetViewWindow()
940   {
941     if (myViewWindow) {
942       QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
943       int aPos = aViews.find(myViewWindow);
944       if (aPos < 0)
945         myViewWindow = NULL;
946     }
947     return myViewWindow;
948   }
949
950   void View_i::SetViewWindow(SUIT_ViewWindow* theViewWindow)
951   {
952     myViewWindow = theViewWindow;
953   }
954
955
956   //===========================================================================
957   XYPlot_i::XYPlot_i (SalomeApp_Application* theApplication)
958     : View_i(theApplication, NULL)
959   {
960     if (MYDEBUG) MESSAGE("XYPlot_i::XYPlot_i");
961   }
962
963   struct TCreatePlot2dViewEvent: public SALOME_Event
964   {
965     XYPlot_i * myPlot2dView;
966     int        myNew;
967
968     typedef Plot2d_ViewFrame* TResult;
969     TResult myResult;
970
971     TCreatePlot2dViewEvent (XYPlot_i * thePlot2dView,
972                             const int  theNew):
973       myPlot2dView(thePlot2dView),
974       myNew(theNew),
975       myResult(NULL)
976     {}
977
978     virtual
979     void
980     Execute()
981     {
982       if (!myPlot2dView->myApplication)
983         return;
984
985       SUIT_ViewManager* aViewMgr =
986         myPlot2dView->myApplication->getViewManager(SPlot2d_Viewer::Type(), false);
987       SUIT_ViewWindow* aVW = NULL;
988
989       if (aViewMgr) {
990         if (myNew)
991           aVW = aViewMgr->createViewWindow();
992         else
993           aVW = aViewMgr->getActiveView();
994       } else {
995         if (myNew) {
996           aViewMgr = myPlot2dView->myApplication->getViewManager(SPlot2d_Viewer::Type(), true);
997           aVW = aViewMgr->getActiveView();
998         } else {
999           return; // there are no current Plot2d view
1000         }
1001       }
1002
1003       if (aVW) {
1004         Plot2d_ViewWindow* aPlot2dVW = dynamic_cast<Plot2d_ViewWindow*>(aVW);
1005         if (aPlot2dVW) {
1006           myResult = aPlot2dVW->getViewFrame();
1007           if (myResult) {
1008             myResult->Repaint();
1009           }
1010
1011           myPlot2dView->myViewManager = aViewMgr;
1012           myPlot2dView->SetViewWindow(aVW);
1013         }
1014       }
1015     }
1016   };
1017
1018   Storable* XYPlot_i::Create (int theNew)
1019   {
1020     myView = ProcessEvent(new TCreatePlot2dViewEvent(this, theNew));
1021     if (myView)
1022       return this;
1023     return NULL;
1024   }
1025
1026   void XYPlot_i::Update()
1027   {
1028     ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame>(myView,&Plot2d_ViewFrame::Repaint));
1029   }
1030
1031   void XYPlot_i::Close()
1032   {
1033     //jfa: may be need to be enclosed in SALOME_Event?
1034     SUIT_ViewWindow* aVW = GetViewWindow();
1035     if (aVW)
1036       aVW->close();
1037     //QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
1038     //int aPos = aViews.find(myViewWindow);
1039     //if (aPos >= 0)
1040     //  myViewWindow->close();
1041   }
1042
1043   XYPlot_i::~XYPlot_i() {
1044     if(MYDEBUG) MESSAGE("XYPlot_i::~XYPlot_i");
1045   }
1046
1047   void XYPlot_i::SetTitle (const char* theTitle)
1048   {
1049     SUIT_ViewWindow* aVW = GetViewWindow();
1050     if (aVW)
1051       ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
1052                        (aVW, &SUIT_ViewWindow::setCaption, QString(theTitle)));
1053   }
1054   char* XYPlot_i::GetTitle()
1055   {
1056     SUIT_ViewWindow* aVW = GetViewWindow();
1057     if (aVW)
1058       return CORBA::string_dup(aVW->caption().latin1());
1059     return CORBA::string_dup("");
1060   }
1061
1062   void XYPlot_i::SetSubTitle (const char* theTitle)
1063   {
1064     if (GetViewWindow())
1065       ProcessVoidEvent(new TVoidMemFun1ArgEvent<Plot2d_ViewFrame,const QString&,QString>
1066                        (myView, &Plot2d_ViewFrame::setTitle, QString(theTitle)));
1067   }
1068
1069   char* XYPlot_i::GetSubTitle()
1070   {
1071     if (GetViewWindow())
1072       return CORBA::string_dup(myView->getTitle());
1073     return CORBA::string_dup("");
1074   }
1075
1076   void XYPlot_i::SetCurveType (VISU::XYPlot::CurveType theType)
1077   {
1078     if (GetViewWindow())
1079       ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,int,bool>
1080                        (myView,&Plot2d_ViewFrame::setCurveType,theType,true));
1081   }
1082
1083   VISU::XYPlot::CurveType XYPlot_i::GetCurveType()
1084   {
1085     if (GetViewWindow())
1086       return (VISU::XYPlot::CurveType)myView->getCurveType();
1087     return VISU::XYPlot::POINTS;
1088   }
1089
1090   void XYPlot_i::SetMarkerSize (CORBA::Long theSize)
1091   {
1092     if (GetViewWindow())
1093       ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,int,bool>
1094                        (myView,&Plot2d_ViewFrame::setMarkerSize,theSize,true));
1095   }
1096
1097   CORBA::Long XYPlot_i::GetMarkerSize()
1098   {
1099     if (GetViewWindow())
1100       return myView->getMarkerSize();
1101     return -1;
1102   }
1103
1104   class TEnableGridEvent: public SALOME_Event
1105   {
1106   public:
1107     typedef void (Plot2d_ViewFrame::* TFun)(bool, const int, bool, const int, bool);
1108     TEnableGridEvent (Plot2d_ViewFrame* theView, TFun theFun,
1109                       CORBA::Boolean theMajor, CORBA::Long theNumMajor,
1110                       CORBA::Boolean theMinor, CORBA::Long theNumMinor):
1111       myView(theView), myFun(theFun),
1112       myMajor(theMajor), myNumMajor(theNumMajor),
1113       myMinor(theMinor), myNumMinor(theNumMinor)
1114     {}
1115
1116     virtual void Execute()
1117     {
1118       (myView->*myFun)(myMajor,myNumMajor,myMinor,myNumMinor,true);
1119     }
1120   protected:
1121     Plot2d_ViewFrame* myView;
1122     TFun myFun;
1123     CORBA::Boolean myMajor, myMinor;
1124     CORBA::Long myNumMajor, myNumMinor;
1125   };
1126
1127   void XYPlot_i::EnableXGrid (CORBA::Boolean theMajor, CORBA::Long theNumMajor,
1128                               CORBA::Boolean theMinor, CORBA::Long theNumMinor)
1129   {
1130     if (GetViewWindow())
1131       ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setXGrid,
1132                                             theMajor,theNumMajor,theMinor,theNumMinor));
1133   }
1134   void XYPlot_i::EnableYGrid(CORBA::Boolean theMajor, CORBA::Long theNumMajor,
1135                              CORBA::Boolean theMinor, CORBA::Long theNumMinor)
1136   {
1137     //asl: Plot2d_ViewFrame::setYGrid has more parameters
1138     //if (GetViewWindow())
1139     //  ProcessVoidEvent(new TEnableGridEvent(myView,&Plot2d_ViewFrame::setYGrid,
1140     //                   theMajor,theNumMajor,theMinor,theNumMinor));
1141   }
1142
1143   class TSetScaleModeEvent: public SALOME_Event
1144   {
1145   public:
1146     typedef void (Plot2d_ViewFrame::* TFun)(const int, bool);
1147     TSetScaleModeEvent (Plot2d_ViewFrame* theView, TFun theFun, int theScaling):
1148       myView(theView), myFun(theFun), myScaling(theScaling)
1149     {}
1150
1151     virtual void Execute()
1152     {
1153       (myView->*myFun)(myScaling,true);
1154     }
1155   protected:
1156     Plot2d_ViewFrame* myView;
1157     TFun myFun;
1158     int myScaling;
1159   };
1160
1161   void XYPlot_i::SetHorScaling (VISU::Scaling theScaling)
1162   {
1163     if (GetViewWindow())
1164       ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setHorScaleMode,
1165                                               theScaling == VISU::LOGARITHMIC));
1166   }
1167
1168   VISU::Scaling XYPlot_i::GetHorScaling()
1169   {
1170     //jfa: may be need to be enclosed in SALOME_Event?
1171     if (GetViewWindow())
1172       return (VISU::Scaling)myView->getHorScaleMode();
1173     return VISU::LINEAR;
1174   }
1175
1176   void XYPlot_i::SetVerScaling(VISU::Scaling theScaling)
1177   {
1178     if (GetViewWindow())
1179       ProcessVoidEvent(new TSetScaleModeEvent(myView,&Plot2d_ViewFrame::setVerScaleMode,
1180                                               theScaling == VISU::LOGARITHMIC));
1181   }
1182
1183   VISU::Scaling XYPlot_i::GetVerScaling()
1184   {
1185     if (GetViewWindow())
1186       return (VISU::Scaling)myView->getVerScaleMode();
1187     return VISU::LINEAR;
1188   }
1189
1190   class TSetTitleEvent: public SALOME_Event
1191   {
1192   public:
1193     TSetTitleEvent (Plot2d_ViewFrame* theView, Plot2d_ViewFrame::ObjectType theType, const char* theTitle):
1194       myView(theView), myType(theType), myTitle(theTitle)
1195     {}
1196     virtual void Execute()
1197     {
1198       myView->setTitle(true,myTitle,myType);
1199     }
1200   protected:
1201     Plot2d_ViewFrame* myView;
1202     Plot2d_ViewFrame::ObjectType myType;
1203     const char* myTitle;
1204   };
1205
1206   void XYPlot_i::SetXTitle (const char* theTitle)
1207   {
1208     if (GetViewWindow())
1209       ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::XTitle, theTitle));
1210   }
1211   char* XYPlot_i::GetXTitle()
1212   {
1213     if (GetViewWindow())
1214       return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::XTitle));
1215     return CORBA::string_dup("");
1216   }
1217
1218   void XYPlot_i::SetYTitle (const char* theTitle)
1219   {
1220     if (GetViewWindow())
1221       ProcessVoidEvent(new TSetTitleEvent(myView, Plot2d_ViewFrame::YTitle, theTitle));
1222   }
1223   char* XYPlot_i::GetYTitle()
1224   {
1225     if (GetViewWindow())
1226       return CORBA::string_dup(myView->getTitle(Plot2d_ViewFrame::YTitle));
1227     return CORBA::string_dup("");
1228   }
1229
1230   void XYPlot_i::ShowLegend (CORBA::Boolean theShowing)
1231   {
1232     if (GetViewWindow())
1233       ProcessVoidEvent(new TVoidMemFun2ArgEvent<Plot2d_ViewFrame,bool,bool>
1234                        (myView,&Plot2d_ViewFrame::showLegend,theShowing,true));
1235   }
1236
1237   class TXYPlotViewEvent: public SALOME_Event
1238   {
1239     SalomeApp_Application* myApplication;
1240     Plot2d_ViewFrame*      myView;
1241     PrsObject_ptr          myPrsObj;
1242     int                    myDisplaing;
1243
1244   public:
1245     TXYPlotViewEvent(SalomeApp_Application* theApplication,
1246                      Plot2d_ViewFrame*      theView,
1247                      PrsObject_ptr          thePrsObj,
1248                      int                    theDisplaing)
1249       : myApplication(theApplication),
1250       myView(theView),
1251       myPrsObj(thePrsObj),
1252       myDisplaing(theDisplaing)
1253     {
1254     }
1255
1256     virtual void Execute()
1257     {
1258       // is it Curve ?
1259       if (Curve_i* aCurve = dynamic_cast<Curve_i*>(VISU::GetServant(myPrsObj).in())) {
1260         UpdatePlot2d(myView,myDisplaing,aCurve);
1261       }
1262       // is it Container ?
1263       if (Container_i* aContainer = dynamic_cast<Container_i*>(VISU::GetServant(myPrsObj).in())) {
1264         int nbCurves = aContainer->GetNbCurves();
1265         for ( int i = 1; i <= nbCurves; i++ ) {
1266           VISU::Curve_i* aCurve = aContainer->GetCurve( i );
1267           if ( aCurve && aCurve->IsValid() ) {
1268             UpdatePlot2d(myView,myDisplaing,aCurve);
1269           }
1270         }
1271         myView->Repaint();
1272       }
1273       // is it Table ?
1274       if (Table_i* aTable = dynamic_cast<Table_i*>(VISU::GetServant(myPrsObj).in())) {
1275         _PTR(Study) aCStudy;
1276         if (SUIT_Study* aSStudy = myApplication->activeStudy()) {
1277           if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1278             aCStudy = aStudy->studyDS();
1279           }
1280         }
1281         if (!aCStudy) return;
1282         _PTR(SObject) TableSO = aCStudy->FindObjectID(aTable->GetEntry().latin1());
1283         if (TableSO) {
1284           _PTR(ChildIterator) Iter = aCStudy->NewChildIterator(TableSO);
1285           for (; Iter->More(); Iter->Next()) {
1286             CORBA::Object_var childObject = VISU::ClientSObjectToObject(Iter->Value());
1287             if (!CORBA::is_nil(childObject)) {
1288               CORBA::Object_ptr aCurve = VISU::Curve::_narrow(childObject);
1289               if (!CORBA::is_nil(aCurve))
1290                 UpdatePlot2d(myView, myDisplaing,
1291                              dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aCurve).in()));
1292             }
1293           }
1294           myView->Repaint();
1295         }
1296       }
1297     }
1298   };
1299
1300   void XYPlot_i::Display (PrsObject_ptr thePrsObj)
1301   {
1302     if (GetViewWindow())
1303       ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eDisplay));
1304   }
1305
1306   void XYPlot_i::Erase (PrsObject_ptr thePrsObj)
1307   {
1308     if (GetViewWindow())
1309       ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eErase));
1310   }
1311
1312   void XYPlot_i::DisplayOnly (PrsObject_ptr thePrsObj)
1313   {
1314     if (GetViewWindow())
1315       ProcessVoidEvent(new TXYPlotViewEvent (myApplication,myView,thePrsObj,eDisplayOnly));
1316   }
1317
1318   void XYPlot_i::EraseAll()
1319   {
1320     if (GetViewWindow())
1321       ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame> (myView,&Plot2d_ViewFrame::EraseAll));
1322   }
1323
1324   void XYPlot_i::FitAll()
1325   {
1326     if (GetViewWindow())
1327       ProcessVoidEvent(new TVoidMemFunEvent<Plot2d_ViewFrame> (myView,&Plot2d_ViewFrame::fitAll));
1328   }
1329
1330   class TFitRangeEvent: public SALOME_Event
1331   {
1332   public:
1333     TFitRangeEvent (Plot2d_ViewFrame* theView,
1334                     const int mode,
1335                     const double xMin, const double xMax,
1336                     const double yMin, const double yMax):
1337       myView(theView), 
1338       myMode(mode),
1339       myXMin(xMin),myXMax(xMax),
1340       myYMin(yMin),myYMax(yMax)
1341     {}
1342     virtual void Execute()
1343     {
1344       myView->fitData(myMode,myXMin,myXMax,myYMin,myYMax);
1345     }
1346   protected:
1347     const int myMode;
1348     const double myXMin;
1349     const double myXMax;
1350     const double myYMin;
1351     const double myYMax;
1352     Plot2d_ViewFrame* myView;
1353   };
1354   
1355   void XYPlot_i::FitXRange(const CORBA::Double xMin,const CORBA::Double xMax)
1356   {
1357     const CORBA::Long mode = 1;
1358     const CORBA::Double yMin = 0.0;
1359     const CORBA::Double yMax = 0.0;
1360     ProcessVoidEvent(new TFitRangeEvent(myView,mode,xMin,xMax,yMin,yMax));
1361   }
1362
1363   void XYPlot_i::FitYRange(const CORBA::Double yMin,const CORBA::Double yMax)
1364   {
1365     const CORBA::Long mode = 2;
1366     const CORBA::Double xMin = 0.0;
1367     const CORBA::Double xMax = 0.0;
1368     ProcessVoidEvent(new TFitRangeEvent(myView,mode,xMin,xMax,yMin,yMax));
1369   }
1370
1371   void XYPlot_i::FitRange(const CORBA::Double xMin,const CORBA::Double xMax,
1372                           const CORBA::Double yMin,const CORBA::Double yMax)
1373   {
1374     const CORBA::Long mode = 0;
1375     ProcessVoidEvent(new TFitRangeEvent(myView,mode,xMin,xMax,yMin,yMax));
1376   }
1377   
1378   void XYPlot_i::GetFitRanges(double& xMin, double& xMax, double& yMin, double& yMax)
1379   {
1380     double y2Min,y2Max;
1381     myView->getFitRanges(xMin,xMax,yMin,yMax,y2Min,y2Max);
1382   }
1383
1384   //===========================================================================
1385   TableView_i::TableView_i (SalomeApp_Application* theApplication)
1386     : View_i(theApplication, NULL)
1387   {
1388   }
1389
1390   struct TCreateTableViewEvent: public SALOME_Event
1391   {
1392     SalomeApp_Application* myApplication;
1393     VISU::Table_i*         myTable;
1394
1395     typedef VisuGUI_TableDlg* TResult;
1396     TResult myResult;
1397
1398     TCreateTableViewEvent (SalomeApp_Application* theApplication,
1399                            VISU::Table_i*         theTable):
1400       myApplication(theApplication),
1401       myTable(theTable),
1402       myResult(NULL)
1403     {}
1404
1405     virtual
1406     void
1407     Execute()
1408     {
1409       if (myTable != NULL) {
1410         if (SUIT_Study* aSStudy = myApplication->activeStudy()) {
1411           if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1412             if (_PTR(Study) aCStudy = aStudy->studyDS()) {
1413               _PTR(SObject) aSObject = aCStudy->FindObjectID(myTable->GetObjectEntry());
1414               if (aSObject) {
1415                 myResult = new VisuGUI_TableDlg (myApplication->desktop(),
1416                                                  aSObject,
1417                                                  false,
1418                                                  VisuGUI_TableDlg::ttAuto,
1419                                                  Qt::Vertical);
1420                 myResult->show();
1421               }
1422             }
1423           }
1424         }
1425       }
1426     }
1427   };
1428
1429   Storable* TableView_i::Create (VISU::Table_ptr theTable)
1430   {
1431     if (MYDEBUG) MESSAGE("TableView_i::Create - " << (!theTable->_is_nil()));
1432     if (!theTable->_is_nil()) {
1433       VISU::Table_i* table =
1434         dynamic_cast<VISU::Table_i*>(VISU::GetServant(theTable).in());
1435       if (MYDEBUG) MESSAGE("TableView_i::Create - dynamic_cast = " << table);
1436
1437       myView = ProcessEvent(new TCreateTableViewEvent(myApplication, table));
1438       if (myView)
1439         return this;
1440     }
1441     return NULL;
1442   }
1443
1444   TableView_i::~TableView_i()
1445   {
1446     if(MYDEBUG) MESSAGE("TableView_i::~TableView_i");
1447     delete myView;
1448   }
1449
1450   void TableView_i::SetTitle (const char* theTitle)
1451   {
1452     ProcessVoidEvent(new TVoidMemFun1ArgEvent<VisuGUI_TableDlg,const QString&,QString>
1453                      (myView, &VisuGUI_TableDlg::setCaption, QString(theTitle)));
1454   }
1455
1456   char* TableView_i::GetTitle()
1457   {
1458     //jfa: may be need to be enclosed in SALOME_Event?
1459     return CORBA::string_dup(myView->caption().latin1());
1460   }
1461
1462   void TableView_i::Close()
1463   {
1464     //jfa: may be need to be enclosed in SALOME_Event?
1465     myView->close();
1466   }
1467
1468
1469   //===========================================================================
1470   int View3D_i::myNbViewParams = 0;
1471   const string View3D_i::myComment = "VIEW3D";
1472   const char* View3D_i::GetComment() const { return myComment.c_str();}
1473
1474   QString View3D_i::GenerateViewParamsName()
1475   {
1476     return VISU::GenerateName("ViewParams", ++myNbViewParams);
1477   }
1478
1479   View3D_i::View3D_i (SalomeApp_Application* theApplication)
1480     : View_i(theApplication, NULL)
1481   {
1482     if (MYDEBUG) MESSAGE("View3D_i::View3D_i");
1483   }
1484
1485   struct TCreateView3dEvent: public SALOME_Event
1486   {
1487     SalomeApp_Application *myApplication;
1488     View3D_i * myView3D;
1489     int        myNew;
1490
1491     typedef SUIT_ViewWindow* TResult;
1492     TResult myResult;
1493
1494     TCreateView3dEvent (SalomeApp_Application *theApplication,
1495                         View3D_i * theView3D,
1496                         const int  theNew):
1497       myApplication(theApplication),
1498       myView3D(theView3D),
1499       myNew(theNew),
1500       myResult(NULL)
1501     {}
1502
1503     virtual
1504     void
1505     Execute()
1506     {
1507       if (!myApplication)
1508         return;
1509
1510       if(myNew){
1511         if(SUIT_ViewManager* aViewManager = myApplication->getViewManager(SVTK_Viewer::Type(),false)){
1512           myResult = aViewManager->createViewWindow();
1513           myView3D->myViewManager = aViewManager;
1514         }else{
1515           if(SUIT_ViewManager* aViewManager = myApplication->getViewManager(SVTK_Viewer::Type(),true)){
1516             myResult = aViewManager->getActiveView();
1517             myView3D->myViewManager = aViewManager;
1518           }
1519         }
1520       }else{
1521         if(SUIT_ViewManager* aViewManager = myApplication->activeViewManager()){
1522           if(SUIT_ViewWindow* aView = aViewManager->getActiveView()){
1523             if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aView)){
1524               myView3D->myViewManager = aViewManager;
1525               myResult = aViewManager->getActiveView();
1526             }
1527           }
1528         }else{
1529           if(SUIT_ViewManager* aViewManager = myApplication->getViewManager(SVTK_Viewer::Type(),false)){
1530             myView3D->myViewManager = aViewManager;
1531             myResult = aViewManager->getActiveView();
1532           }
1533         }
1534       }
1535     }
1536   };
1537
1538   Storable* View3D_i::Create (int theNew)
1539   {
1540     if (MYDEBUG) MESSAGE("View3D_i::Create");
1541     SUIT_ViewWindow* aVW = ProcessEvent(new TCreateView3dEvent(myApplication, this, theNew));
1542     if (aVW) {
1543       SetViewWindow(aVW);
1544       return this;
1545     }
1546     return NULL;
1547   }
1548
1549   void View3D_i::Update()
1550   {
1551     class TEvent: public SALOME_Event
1552     {
1553       SUIT_ViewWindow* myVW;
1554     public:
1555       TEvent(SUIT_ViewWindow* theViewWindow):
1556         myVW(theViewWindow)
1557       {}
1558       virtual void Execute()
1559       {
1560         SVTK_ViewWindow* vf = dynamic_cast<SVTK_ViewWindow*>(myVW);
1561         vtkRenderer* Renderer = vf->getRenderer();
1562         vtkActorCollection* theActors = Renderer->GetActors();
1563         theActors->InitTraversal();
1564         while (vtkActor *anAct = theActors->GetNextActor()) {
1565           if (VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)) {
1566             VISU::Prs3d_i* aPrs3d  = anActor->GetPrs3d();
1567             if (anActor->GetVisibility() && aPrs3d) {
1568               aPrs3d->Update();
1569               aPrs3d->UpdateActor(anActor);
1570             }
1571           }
1572         }
1573         RepaintView(myVW);
1574       }
1575     };
1576
1577     SUIT_ViewWindow* aVW = GetViewWindow();
1578     if (aVW)
1579       ProcessVoidEvent(new TEvent(aVW));
1580   }
1581
1582   bool View3D_i::SaveViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1583   {
1584     MESSAGE("View3D_i::SaveViewParams()");
1585
1586     if (!theViewManager || !theName)
1587       return false;
1588
1589     _PTR(Study) aCStudy;
1590     if (SUIT_Study* aSStudy = theViewManager->study()) {
1591       if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1592         aCStudy = aStudy->studyDS();
1593       }
1594     }
1595     if (!aCStudy)
1596       return false;
1597
1598     if (strcmp(theName, "") != 0) {
1599       std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1600       _PTR(GenericAttribute) anAttr;
1601       int iEnd = aList.size();
1602       for (int i = 0; i < iEnd; i++) {
1603         _PTR(SObject) anObj = aList[i];
1604         string anEntry = anObj->GetID();
1605         if(MYDEBUG) MESSAGE("View3D_i::SaveViewParams - anEntry = " << anEntry);
1606         if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1607           _PTR(AttributeComment) aCmnt (anAttr);
1608           string aComm (aCmnt->Value());
1609           if (MYDEBUG) MESSAGE("View3D_i::SaveViewPoint - aComm = " << aComm);
1610           if (aComm.compare(View3D_i::myComment) >= 0) {
1611             aCmnt->SetValue(ToString(theViewManager->getActiveView()).c_str());
1612             return true;
1613           }
1614         }
1615       }
1616     }
1617     _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy);
1618     string aSComponentEntry = aSComponent->GetID();
1619     string anEntry = CreateAttributes(aCStudy, aSComponentEntry.c_str(), "", "", theName, "",
1620                                       ToString(theViewManager->getActiveView()).c_str());
1621     return true;
1622   }
1623
1624   class TSaveViewParamsEvent: public SALOME_Event
1625   {
1626     SUIT_ViewManager* myViewMgr;
1627     const char*       myName;
1628   public:
1629     TSaveViewParamsEvent (SUIT_ViewManager* theViewManager,
1630                           const char*       theName):
1631       myViewMgr(theViewManager),
1632       myName(theName)
1633     {}
1634
1635     virtual void Execute()
1636     {
1637       myResult = View3D_i::SaveViewParams(myViewMgr, myName);
1638     }
1639     typedef CORBA::Boolean TResult;
1640     TResult myResult;
1641   };
1642
1643   CORBA::Boolean View3D_i::SaveViewParams (const char* theName)
1644   {
1645     return ProcessEvent(new TSaveViewParamsEvent (myViewManager, theName));
1646   }
1647
1648   bool View3D_i::RestoreViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1649   {
1650     _PTR(Study) aCStudy;
1651     if (SUIT_Study* aSStudy = theViewManager->study()) {
1652       if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1653         aCStudy = aStudy->studyDS();
1654       }
1655     }
1656     if (!aCStudy)
1657       return false;
1658
1659     std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1660     _PTR(GenericAttribute) anAttr;
1661     int iEnd = aList.size();
1662     if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - iEnd = " << iEnd);
1663     for (int i = 0; i < iEnd; i++) {
1664       _PTR(SObject) anObj = aList[i];
1665       string anEntry = anObj->GetID();
1666       if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - anEntry = " << anEntry);
1667       if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1668         _PTR(AttributeComment) aCmnt (anAttr);
1669         QString strIn(aCmnt->Value().c_str());
1670         Storable::TRestoringMap aMap;
1671         Storable::StrToMap(strIn, aMap);
1672         if (Storable::FindValue(aMap, "myComment").compare
1673             (View3D_i::myComment.c_str()) >= 0) {
1674           if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - aComm = " << strIn);
1675           Restore(theViewManager->getActiveView(), aMap);
1676           return true;
1677         }
1678       }
1679     }
1680     return false;
1681   }
1682
1683   class TRestoreViewParamsEvent: public SALOME_Event
1684   {
1685     SUIT_ViewManager* myViewMgr;
1686     const char*       myName;
1687   public:
1688     TRestoreViewParamsEvent (SUIT_ViewManager* theViewManager,
1689                              const char*       theName):
1690       myViewMgr(theViewManager),
1691       myName(theName)
1692     {}
1693
1694     virtual void Execute()
1695     {
1696       myResult = View3D_i::RestoreViewParams(myViewMgr, myName);
1697     }
1698     typedef CORBA::Boolean TResult;
1699     TResult myResult;
1700   };
1701
1702   CORBA::Boolean View3D_i::RestoreViewParams (const char* theName)
1703   {
1704     return ProcessEvent(new TRestoreViewParamsEvent (myViewManager, theName));
1705   }
1706
1707   void View3D_i::Restore (SUIT_ViewWindow* theViewWindow,
1708                           const Storable::TRestoringMap& theMap)
1709   {
1710     SALOMEDS::Color aColor;
1711     aColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
1712     aColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
1713     aColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
1714
1715     double aPosition[3];
1716     aPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
1717     aPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
1718     aPosition[2] = VISU::Storable::FindValue(theMap,"myPosition[2]").toDouble();
1719
1720     double aFocalPnt[3];
1721     aFocalPnt[0] = VISU::Storable::FindValue(theMap,"myFocalPnt[0]").toDouble();
1722     aFocalPnt[1] = VISU::Storable::FindValue(theMap,"myFocalPnt[1]").toDouble();
1723     aFocalPnt[2] = VISU::Storable::FindValue(theMap,"myFocalPnt[2]").toDouble();
1724
1725     double aViewUp[3];
1726     aViewUp[0] = VISU::Storable::FindValue(theMap,"myViewUp[0]").toDouble();
1727     aViewUp[1] = VISU::Storable::FindValue(theMap,"myViewUp[1]").toDouble();
1728     aViewUp[2] = VISU::Storable::FindValue(theMap,"myViewUp[2]").toDouble();
1729
1730     double aParallelScale = VISU::Storable::FindValue(theMap,"myParallelScale").toDouble();
1731
1732     double aScaleFactor[3];
1733     aScaleFactor[0] = VISU::Storable::FindValue(theMap,"myScaleFactor[0]").toDouble();
1734     aScaleFactor[1] = VISU::Storable::FindValue(theMap,"myScaleFactor[1]").toDouble();
1735     aScaleFactor[2] = VISU::Storable::FindValue(theMap,"myScaleFactor[2]").toDouble();
1736
1737     SetBackground(theViewWindow,aColor);
1738     SetPointOfView(theViewWindow,aPosition);
1739     SetViewUp(theViewWindow,aViewUp);
1740     SetFocalPoint(theViewWindow,aFocalPnt);
1741     SetParallelScale(theViewWindow,aParallelScale);
1742     ScaleView(theViewWindow,VISU::View3D::XAxis,aScaleFactor[0]);
1743     ScaleView(theViewWindow,VISU::View3D::YAxis,aScaleFactor[1]);
1744     ScaleView(theViewWindow,VISU::View3D::ZAxis,aScaleFactor[2]);
1745   }
1746
1747
1748   string View3D_i::ToString (SUIT_ViewWindow* theViewWindow)
1749   {
1750     ostringstream strOut;
1751     Storable::DataToStream(strOut, "myComment", myComment.c_str());
1752     ToStream(theViewWindow, strOut);
1753     strOut << ends;
1754     if(MYDEBUG) MESSAGE("View3D_i::ToString - " << strOut.str());
1755     return strOut.str();
1756   }
1757
1758   void View3D_i::ToStream (SUIT_ViewWindow* theViewWindow, std::ostringstream& theStr)
1759   {
1760     Storable::DataToStream(theStr,"myType",VISU::TVIEW3D);
1761
1762     float backint[3];
1763     GetRenderer(theViewWindow)->GetBackground(backint);
1764     Storable::DataToStream(theStr,"myColor.R",backint[0]);
1765     Storable::DataToStream(theStr,"myColor.G",backint[1]);
1766     Storable::DataToStream(theStr,"myColor.B",backint[2]);
1767
1768     double aPosition[3];
1769     GetPointOfView(theViewWindow,aPosition);
1770     Storable::DataToStream(theStr,"myPosition[0]",aPosition[0]);
1771     Storable::DataToStream(theStr,"myPosition[1]",aPosition[1]);
1772     Storable::DataToStream(theStr,"myPosition[2]",aPosition[2]);
1773
1774     double aFocalPnt[3];
1775     GetFocalPoint(theViewWindow,aFocalPnt);
1776     Storable::DataToStream(theStr,"myFocalPnt[0]",aFocalPnt[0]);
1777     Storable::DataToStream(theStr,"myFocalPnt[1]",aFocalPnt[1]);
1778     Storable::DataToStream(theStr,"myFocalPnt[2]",aFocalPnt[2]);
1779
1780     double aViewUp[3];
1781     GetCamera(theViewWindow)->GetViewUp(aViewUp);
1782     Storable::DataToStream(theStr,"myViewUp[0]",aViewUp[0]);
1783     Storable::DataToStream(theStr,"myViewUp[1]",aViewUp[1]);
1784     Storable::DataToStream(theStr,"myViewUp[2]",aViewUp[2]);
1785
1786     Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(theViewWindow));
1787
1788     double aScaleFactor[3];
1789     (dynamic_cast<SVTK_ViewWindow*>(theViewWindow))->GetScale(aScaleFactor);
1790     Storable::DataToStream(theStr,"myScaleFactor[0]",aScaleFactor[0]);
1791     Storable::DataToStream(theStr,"myScaleFactor[1]",aScaleFactor[1]);
1792     Storable::DataToStream(theStr,"myScaleFactor[2]",aScaleFactor[2]);
1793   }
1794
1795   void View3D_i::ToStream(std::ostringstream& theStr)
1796   {
1797     SUIT_ViewWindow* aVW = GetViewWindow();
1798     if (aVW)
1799       ToStream(aVW, theStr);
1800   }
1801
1802   void View3D_i::Close()
1803   {
1804     //jfa: may be need to be enclosed in SALOME_Event?
1805     SUIT_ViewWindow* aVW = GetViewWindow();
1806     if (aVW)
1807       aVW->close();
1808     //QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
1809     //int aPos = aViews.find(myViewWindow);
1810     //if (aPos >= 0)
1811     //  myViewWindow->close();
1812   }
1813
1814   View3D_i::~View3D_i()
1815   {
1816     if(MYDEBUG) MESSAGE("View3D_i::~View3D_i");
1817   }
1818
1819   void View3D_i::SetTitle (const char* theTitle)
1820   {
1821     SUIT_ViewWindow* aVW = GetViewWindow();
1822     if (aVW)
1823       ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
1824                        (aVW,&SUIT_ViewWindow::setCaption,QString(theTitle)));
1825   }
1826
1827   char* View3D_i::GetTitle()
1828   {
1829     SUIT_ViewWindow* aVW = GetViewWindow();
1830     if (aVW)
1831       return CORBA::string_dup(aVW->caption().latin1());
1832     return CORBA::string_dup("");
1833   }
1834
1835   void View3D_i::SetBackground (SUIT_ViewWindow* theViewWindow,
1836                                 const SALOMEDS::Color& theColor)
1837   {
1838     //jfa: may be need to be enclosed in SALOME_Event?
1839     int aColor[3];
1840     aColor[0] = int(255.0*theColor.R);
1841     aColor[1] = int(255.0*theColor.G);
1842     aColor[2] = int(255.0*theColor.B);
1843     QColor aNewColor (aColor[0],aColor[1],aColor[2]);
1844     (dynamic_cast<SVTK_ViewWindow*>(theViewWindow))->setBackgroundColor(aNewColor);
1845   }
1846
1847   SALOMEDS::Color View3D_i::GetBackground (SUIT_ViewWindow* theViewWindow)
1848   {
1849     SALOMEDS::Color aColor;
1850     float backint[3];
1851     GetRenderer(theViewWindow)->GetBackground(backint);
1852     aColor.R = backint[0];  aColor.G = backint[1];  aColor.B = backint[2];
1853     return aColor;
1854   }
1855
1856   class TUpdateViewerEvent: public SALOME_Event
1857   {
1858     SUIT_ViewWindow* myVW;
1859     Prs3d_i* myPrs3d;
1860     int myDisplaing;
1861   public:
1862     TUpdateViewerEvent(SUIT_ViewWindow* theViewWindow,
1863                        Prs3d_i* thePrs3d,
1864                        int theDisplaing):
1865       myVW(theViewWindow),
1866       myPrs3d(thePrs3d),
1867       myDisplaing(theDisplaing)
1868     {}
1869     virtual void Execute(){
1870       UpdateViewer(myVW, myDisplaing, myPrs3d);
1871     }
1872   };
1873
1874   void View3D_i::EraseAll()
1875   {
1876     if(MYDEBUG) MESSAGE("View3D_i::EraseAll");
1877     SUIT_ViewWindow* aVW = GetViewWindow();
1878     if (aVW)
1879       ProcessVoidEvent(new TUpdateViewerEvent(aVW,NULL,eEraseAll));
1880   }
1881
1882   void View3D_i::DisplayAll()
1883   {
1884     if(MYDEBUG) MESSAGE("View3D_i::DisplayAll");
1885     SUIT_ViewWindow* aVW = GetViewWindow();
1886     if (aVW)
1887       ProcessVoidEvent(new TUpdateViewerEvent(aVW,NULL,eDisplayAll));
1888   }
1889
1890   void View3D_i::Erase (PrsObject_ptr thePrsObj)
1891   {
1892     if(MYDEBUG) MESSAGE("View3D_i::Erase");
1893     SUIT_ViewWindow* aVW = GetViewWindow();
1894     CORBA::Object_ptr anObj = thePrsObj;
1895     Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in());
1896     if (aVW && aPrs)
1897       ProcessVoidEvent(new TUpdateViewerEvent(aVW,aPrs,eErase));
1898   }
1899
1900   void View3D_i::Display (PrsObject_ptr thePrsObj)
1901   {
1902     if(MYDEBUG) MESSAGE("View3D_i::Display");
1903     SUIT_ViewWindow* aVW = GetViewWindow();
1904     CORBA::Object_ptr anObj = thePrsObj;
1905     Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in());
1906     if (aVW && aPrs)
1907       ProcessVoidEvent(new TUpdateViewerEvent(aVW,aPrs,eDisplay));
1908   }
1909
1910   void View3D_i::DisplayOnly (PrsObject_ptr thePrsObj)
1911   {
1912     if(MYDEBUG) MESSAGE("View3D_i::DisplayOnly");
1913     SUIT_ViewWindow* aVW = GetViewWindow();
1914     CORBA::Object_ptr anObj = thePrsObj;
1915     Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in());
1916     if (aVW && aPrs)
1917       ProcessVoidEvent(new TUpdateViewerEvent(aVW,aPrs,eDisplayOnly));
1918   }
1919
1920   void View3D_i::FitAll()
1921   {
1922     SUIT_ViewWindow* aVW = GetViewWindow();
1923     if (aVW) {
1924       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1925                        (dynamic_cast<SVTK_ViewWindow*>(aVW), &SVTK_ViewWindow::onFitAll));
1926       Update();
1927     }
1928   }
1929
1930   void View3D_i::SetView (VISU::View3D::ViewType theType)
1931   {
1932     SUIT_ViewWindow* aVW = GetViewWindow();
1933     if (!aVW)
1934       return;
1935
1936     switch (theType) {
1937     case VISU::View3D::FRONT :
1938       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1939                        (dynamic_cast<SVTK_ViewWindow*>(aVW), &SVTK_ViewWindow::onFrontView));
1940       break;
1941     case VISU::View3D::BACK :
1942       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1943                        (dynamic_cast<SVTK_ViewWindow*>(aVW), &SVTK_ViewWindow::onBackView));
1944       break;
1945     case VISU::View3D::LEFT :
1946       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1947                        (dynamic_cast<SVTK_ViewWindow*>(aVW),&SVTK_ViewWindow::onLeftView));
1948       break;
1949     case VISU::View3D::RIGHT :
1950       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1951                        (dynamic_cast<SVTK_ViewWindow*>(aVW),&SVTK_ViewWindow::onRightView));
1952       break;
1953     case VISU::View3D::TOP :
1954       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1955                        (dynamic_cast<SVTK_ViewWindow*>(aVW),&SVTK_ViewWindow::onTopView));
1956       break;
1957     case VISU::View3D::BOTTOM :
1958       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1959                        (dynamic_cast<SVTK_ViewWindow*>(aVW),&SVTK_ViewWindow::onBottomView));
1960       break;
1961     }
1962     Update();
1963   }
1964
1965   class TSet3DViewParamEvent: public SALOME_Event
1966   {
1967   public:
1968     typedef void (*TFun)(SUIT_ViewWindow* theViewWindow, const CORBA::Double theParam[3]);
1969     TSet3DViewParamEvent (TFun theFun,
1970                           SUIT_ViewWindow* theViewWindow,
1971                           const CORBA::Double theParam[3]):
1972       myFun(theFun),
1973       myVW(theViewWindow),
1974       myParam(theParam)
1975     {}
1976     virtual void Execute() {
1977       myFun(myVW,myParam);
1978     }
1979   private:
1980     TFun myFun;
1981     SUIT_ViewWindow* myVW;
1982     const CORBA::Double* myParam;
1983   };
1984
1985   void View3D_i::SetPointOfView (SUIT_ViewWindow* theViewWindow,
1986                                  const CORBA::Double thePosition[3])
1987   {
1988     //jfa: may be need to be enclosed in SALOME_Event?
1989     GetCamera(theViewWindow)->SetPosition(thePosition);
1990   }
1991
1992   void View3D_i::SetPointOfView (const VISU::View3D::XYZ thePosition)
1993   {
1994     if(MYDEBUG) MESSAGE("View3D_i::SetPointOfView");
1995     SUIT_ViewWindow* aVW = GetViewWindow();
1996     if (aVW)
1997       ProcessVoidEvent(new TSet3DViewParamEvent(&SetPointOfView,aVW,thePosition));
1998   }
1999
2000   void View3D_i::GetPointOfView (SUIT_ViewWindow* theViewWindow,
2001                                  CORBA::Double thePosition[3])
2002   {
2003     GetCamera(theViewWindow)->GetPosition(thePosition);
2004   }
2005
2006   VISU::View3D::XYZ_slice* View3D_i::GetPointOfView()
2007   {
2008     if(MYDEBUG) MESSAGE("View3D_i::GetPointOfView");
2009     CORBA::Double aPosition[3];
2010     SUIT_ViewWindow* aVW = GetViewWindow();
2011     if (aVW)
2012       GetPointOfView(aVW,aPosition);
2013     return VISU::View3D::XYZ_dup(aPosition);
2014   }
2015
2016   void View3D_i::SetViewUp (SUIT_ViewWindow* theViewWindow,
2017                             const CORBA::Double theViewUp[3])
2018   {
2019     GetCamera(theViewWindow)->SetViewUp(theViewUp);
2020   }
2021
2022   void View3D_i::SetViewUp (const VISU::View3D::XYZ theViewUp)
2023   {
2024     if(MYDEBUG) MESSAGE("View3D_i::SetViewUp");
2025     SUIT_ViewWindow* aVW = GetViewWindow();
2026     if (aVW)
2027       ProcessVoidEvent(new TSet3DViewParamEvent(&SetViewUp,aVW,theViewUp));
2028   }
2029
2030   void View3D_i::GetViewUp (SUIT_ViewWindow* theViewWindow,
2031                             CORBA::Double theViewUp[3])
2032   {
2033     GetCamera(theViewWindow)->GetViewUp(theViewUp);
2034   }
2035
2036   VISU::View3D::XYZ_slice* View3D_i::GetViewUp()
2037   {
2038     if(MYDEBUG) MESSAGE("View3D_i::GetViewUp");
2039     CORBA::Double aViewUp[3];
2040     SUIT_ViewWindow* aVW = GetViewWindow();
2041     if (aVW)
2042       GetCamera(aVW)->GetViewUp(aViewUp);
2043     return VISU::View3D::XYZ_dup(aViewUp);
2044   }
2045
2046   void View3D_i::SetFocalPoint (SUIT_ViewWindow* theViewWindow,
2047                                 const CORBA::Double theFocalPnt[3])
2048   {
2049     GetCamera(theViewWindow)->SetFocalPoint(theFocalPnt);
2050   }
2051
2052   void View3D_i::SetFocalPoint (const VISU::View3D::XYZ theCoord)
2053   {
2054     if(MYDEBUG) MESSAGE("View3D_i::SetFocalPoint");
2055     SUIT_ViewWindow* aVW = GetViewWindow();
2056     if (aVW)
2057       ProcessVoidEvent(new TSet3DViewParamEvent(&SetFocalPoint,aVW,theCoord));
2058   }
2059
2060
2061   void View3D_i::GetFocalPoint (SUIT_ViewWindow* theViewWindow,
2062                                 CORBA::Double theFocalPnt[3])
2063   {
2064     GetCamera(theViewWindow)->GetFocalPoint(theFocalPnt);
2065   }
2066
2067   VISU::View3D::XYZ_slice* View3D_i::GetFocalPoint()
2068   {
2069     if(MYDEBUG) MESSAGE("View3D_i::GetFocalPoint");
2070     CORBA::Double aFocalPnt[3];
2071     SUIT_ViewWindow* aVW = GetViewWindow();
2072     if (aVW)
2073       GetFocalPoint(aVW,aFocalPnt);
2074     return VISU::View3D::XYZ_dup(aFocalPnt);
2075   }
2076
2077   class TSetViewParamEvent: public SALOME_Event
2078   {
2079   public:
2080     typedef void (*TFun)(SUIT_ViewWindow* theViewWindow, CORBA::Double theParam);
2081     TSetViewParamEvent (TFun theFun,
2082                         SUIT_ViewWindow* theViewWindow,
2083                         CORBA::Double theParam):
2084       myFun(theFun),
2085       myVW(theViewWindow),
2086       myParam(theParam)
2087     {}
2088     virtual void Execute()
2089     {
2090       myFun(myVW,myParam);
2091     }
2092   private:
2093     TFun myFun;
2094     SUIT_ViewWindow* myVW;
2095     CORBA::Double myParam;
2096   };
2097
2098   void View3D_i::SetParallelScale (SUIT_ViewWindow* theViewWindow,
2099                                    CORBA::Double theScale)
2100   {
2101     GetCamera(theViewWindow)->SetParallelScale(theScale);
2102   }
2103
2104   void View3D_i::SetParallelScale (CORBA::Double theScale)
2105   {
2106     if(MYDEBUG) MESSAGE("View3D_i::SetParallelScale");
2107     SUIT_ViewWindow* aVW = GetViewWindow();
2108     if (aVW)
2109       ProcessVoidEvent(new TSetViewParamEvent(&SetParallelScale,aVW,theScale));
2110   }
2111
2112   CORBA::Double View3D_i::GetParallelScale (SUIT_ViewWindow* theViewWindow)
2113   {
2114     return GetCamera(theViewWindow)->GetParallelScale();
2115   }
2116
2117   CORBA::Double View3D_i::GetParallelScale()
2118   {
2119     if(MYDEBUG) MESSAGE("View3D_i::GetParallelScale");
2120     SUIT_ViewWindow* aVW = GetViewWindow();
2121     if (aVW)
2122       return GetParallelScale(aVW);
2123     return 1.0;
2124   }
2125
2126   void View3D_i::ScaleView (SUIT_ViewWindow* theViewWindow,
2127                             VISU::View3D::Axis theAxis, CORBA::Double theParam)
2128   {
2129     SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(theViewWindow);
2130     double aScaleFactor[3];
2131     aViewWindow->GetScale(aScaleFactor);
2132     aScaleFactor[theAxis] = theParam;
2133     aViewWindow->SetScale(aScaleFactor);
2134   }
2135
2136   void SetScaleView (SUIT_ViewWindow* theViewWindow, const CORBA::Double theScale[3])
2137   {
2138     double aScale[3] = {theScale[0], theScale[1], theScale[2]};
2139     (dynamic_cast<SVTK_ViewWindow*>(theViewWindow))->SetScale(aScale);
2140   }
2141
2142   void View3D_i::ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam)
2143   {
2144     if(MYDEBUG) MESSAGE("View3D_i::ScaleView");
2145     SUIT_ViewWindow* aVW = GetViewWindow();
2146     if (aVW) {
2147       double aScale[3];
2148       (dynamic_cast<SVTK_ViewWindow*>(aVW))->GetScale(aScale);
2149       aScale[theAxis] = theParam;
2150       ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,aVW,aScale));
2151     }
2152   }
2153
2154   void View3D_i::RemoveScale()
2155   {
2156     if(MYDEBUG) MESSAGE("View3D_i::RemoveScale");
2157     SUIT_ViewWindow* aVW = GetViewWindow();
2158     if (aVW) {
2159       double aScale[3] = {1.0, 1.0, 1.0};
2160       ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,aVW,aScale));
2161     }
2162   }
2163 }