Salome HOME
Fix for bugs 10287, 9986: SIGSEGV in VISU on Views management
[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 #include "SVTK_RenderWindow.h"
50
51 #include "SPlot2d_ViewModel.h"
52 #include "Plot2d_ViewFrame.h"
53
54 #include "SalomeApp_Application.h"
55 #include "SalomeApp_Study.h"
56
57 #include <QtxWorkstack.h>
58
59 #include <qworkspace.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     View3D_i * myView3D;
1488     int        myNew;
1489
1490     typedef SUIT_ViewWindow* TResult;
1491     TResult myResult;
1492
1493     TCreateView3dEvent (View3D_i * theView3D,
1494                         const int  theNew):
1495       myView3D(theView3D),
1496       myNew(theNew),
1497       myResult(NULL)
1498     {}
1499
1500     virtual
1501     void
1502     Execute()
1503     {
1504       if (!myView3D->myApplication)
1505         return;
1506
1507       SUIT_ViewManager * aViewMgr =
1508         myView3D->myApplication->getViewManager(SVTK_Viewer::Type(), false);
1509
1510       if (aViewMgr) {
1511         if (myNew) {
1512           myResult = aViewMgr->createViewWindow();
1513         } else {
1514           myResult = aViewMgr->getActiveView();
1515         }
1516       } else {
1517         if (myNew) {
1518           aViewMgr = myView3D->myApplication->getViewManager(SVTK_Viewer::Type(), true);
1519           myResult = aViewMgr->getActiveView();
1520         } else {
1521           return; // there are no current 3D view
1522         }
1523       }
1524
1525       myView3D->myViewManager = aViewMgr;
1526     }
1527   };
1528
1529   Storable* View3D_i::Create (int theNew)
1530   {
1531     if (MYDEBUG) MESSAGE("View3D_i::Create");
1532     SUIT_ViewWindow* aVW = ProcessEvent(new TCreateView3dEvent(this, theNew));
1533     if (aVW) {
1534       SetViewWindow(aVW);
1535       return this;
1536     }
1537     return NULL;
1538   }
1539
1540   void View3D_i::Update()
1541   {
1542     class TEvent: public SALOME_Event
1543     {
1544       SUIT_ViewWindow* myVW;
1545     public:
1546       TEvent(SUIT_ViewWindow* theViewWindow):
1547         myVW(theViewWindow)
1548       {}
1549       virtual void Execute()
1550       {
1551         SVTK_ViewWindow* vf = VISU::GetViewWindow(myVW);
1552         vtkRenderer* Renderer = vf->getRenderer();
1553         vtkActorCollection* theActors = Renderer->GetActors();
1554         theActors->InitTraversal();
1555         while (vtkActor *anAct = theActors->GetNextActor()) {
1556           if (VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)) {
1557             VISU::Prs3d_i* aPrs3d  = anActor->GetPrs3d();
1558             if (anActor->GetVisibility() && aPrs3d) {
1559               aPrs3d->Update();
1560               aPrs3d->UpdateActor(anActor);
1561             }
1562           }
1563         }
1564         RepaintView(myVW);
1565       }
1566     };
1567
1568     SUIT_ViewWindow* aVW = GetViewWindow();
1569     if (aVW)
1570       ProcessVoidEvent(new TEvent(aVW));
1571   }
1572
1573   bool View3D_i::SaveViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1574   {
1575     MESSAGE("View3D_i::SaveViewParams()");
1576
1577     if (!theViewManager || !theName)
1578       return false;
1579
1580     _PTR(Study) aCStudy;
1581     if (SUIT_Study* aSStudy = theViewManager->study()) {
1582       if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1583         aCStudy = aStudy->studyDS();
1584       }
1585     }
1586     if (!aCStudy)
1587       return false;
1588
1589     if (strcmp(theName, "") != 0) {
1590       std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1591       _PTR(GenericAttribute) anAttr;
1592       int iEnd = aList.size();
1593       for (int i = 0; i < iEnd; i++) {
1594         _PTR(SObject) anObj = aList[i];
1595         string anEntry = anObj->GetID();
1596         if(MYDEBUG) MESSAGE("View3D_i::SaveViewParams - anEntry = " << anEntry);
1597         if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1598           _PTR(AttributeComment) aCmnt (anAttr);
1599           string aComm (aCmnt->Value());
1600           if (MYDEBUG) MESSAGE("View3D_i::SaveViewPoint - aComm = " << aComm);
1601           if (aComm.compare(View3D_i::myComment) >= 0) {
1602             aCmnt->SetValue(ToString(theViewManager->getActiveView()).c_str());
1603             return true;
1604           }
1605         }
1606       }
1607     }
1608     _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy);
1609     string aSComponentEntry = aSComponent->GetID();
1610     string anEntry = CreateAttributes(aCStudy, aSComponentEntry.c_str(), "", "", theName, "",
1611                                       ToString(theViewManager->getActiveView()).c_str());
1612     return true;
1613   }
1614
1615   class TSaveViewParamsEvent: public SALOME_Event
1616   {
1617     SUIT_ViewManager* myViewMgr;
1618     const char*       myName;
1619   public:
1620     TSaveViewParamsEvent (SUIT_ViewManager* theViewManager,
1621                           const char*       theName):
1622       myViewMgr(theViewManager),
1623       myName(theName)
1624     {}
1625
1626     virtual void Execute()
1627     {
1628       myResult = View3D_i::SaveViewParams(myViewMgr, myName);
1629     }
1630     typedef CORBA::Boolean TResult;
1631     TResult myResult;
1632   };
1633
1634   CORBA::Boolean View3D_i::SaveViewParams (const char* theName)
1635   {
1636     return ProcessEvent(new TSaveViewParamsEvent (myViewManager, theName));
1637   }
1638
1639   bool View3D_i::RestoreViewParams (SUIT_ViewManager* theViewManager, const char* theName)
1640   {
1641     _PTR(Study) aCStudy;
1642     if (SUIT_Study* aSStudy = theViewManager->study()) {
1643       if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
1644         aCStudy = aStudy->studyDS();
1645       }
1646     }
1647     if (!aCStudy)
1648       return false;
1649
1650     std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(theName, "VISU");
1651     _PTR(GenericAttribute) anAttr;
1652     int iEnd = aList.size();
1653     if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - iEnd = " << iEnd);
1654     for (int i = 0; i < iEnd; i++) {
1655       _PTR(SObject) anObj = aList[i];
1656       string anEntry = anObj->GetID();
1657       if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - anEntry = " << anEntry);
1658       if (anObj->FindAttribute(anAttr, "AttributeComment")) {
1659         _PTR(AttributeComment) aCmnt (anAttr);
1660         QString strIn(aCmnt->Value().c_str());
1661         Storable::TRestoringMap aMap;
1662         Storable::StrToMap(strIn, aMap);
1663         if (Storable::FindValue(aMap, "myComment").compare
1664             (View3D_i::myComment.c_str()) >= 0) {
1665           if (MYDEBUG) MESSAGE("View3D_i::RestoreViewPoint - aComm = " << strIn);
1666           Restore(theViewManager->getActiveView(), aMap);
1667           return true;
1668         }
1669       }
1670     }
1671     return false;
1672   }
1673
1674   class TRestoreViewParamsEvent: public SALOME_Event
1675   {
1676     SUIT_ViewManager* myViewMgr;
1677     const char*       myName;
1678   public:
1679     TRestoreViewParamsEvent (SUIT_ViewManager* theViewManager,
1680                              const char*       theName):
1681       myViewMgr(theViewManager),
1682       myName(theName)
1683     {}
1684
1685     virtual void Execute()
1686     {
1687       myResult = View3D_i::RestoreViewParams(myViewMgr, myName);
1688     }
1689     typedef CORBA::Boolean TResult;
1690     TResult myResult;
1691   };
1692
1693   CORBA::Boolean View3D_i::RestoreViewParams (const char* theName)
1694   {
1695     return ProcessEvent(new TRestoreViewParamsEvent (myViewManager, theName));
1696   }
1697
1698   void View3D_i::Restore (SUIT_ViewWindow* theViewWindow,
1699                           const Storable::TRestoringMap& theMap)
1700   {
1701     SALOMEDS::Color aColor;
1702     aColor.R = VISU::Storable::FindValue(theMap,"myColor.R").toDouble();
1703     aColor.G = VISU::Storable::FindValue(theMap,"myColor.G").toDouble();
1704     aColor.B = VISU::Storable::FindValue(theMap,"myColor.B").toDouble();
1705
1706     double aPosition[3];
1707     aPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble();
1708     aPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble();
1709     aPosition[2] = VISU::Storable::FindValue(theMap,"myPosition[2]").toDouble();
1710
1711     double aFocalPnt[3];
1712     aFocalPnt[0] = VISU::Storable::FindValue(theMap,"myFocalPnt[0]").toDouble();
1713     aFocalPnt[1] = VISU::Storable::FindValue(theMap,"myFocalPnt[1]").toDouble();
1714     aFocalPnt[2] = VISU::Storable::FindValue(theMap,"myFocalPnt[2]").toDouble();
1715
1716     double aViewUp[3];
1717     aViewUp[0] = VISU::Storable::FindValue(theMap,"myViewUp[0]").toDouble();
1718     aViewUp[1] = VISU::Storable::FindValue(theMap,"myViewUp[1]").toDouble();
1719     aViewUp[2] = VISU::Storable::FindValue(theMap,"myViewUp[2]").toDouble();
1720
1721     double aParallelScale = VISU::Storable::FindValue(theMap,"myParallelScale").toDouble();
1722
1723     double aScaleFactor[3];
1724     aScaleFactor[0] = VISU::Storable::FindValue(theMap,"myScaleFactor[0]").toDouble();
1725     aScaleFactor[1] = VISU::Storable::FindValue(theMap,"myScaleFactor[1]").toDouble();
1726     aScaleFactor[2] = VISU::Storable::FindValue(theMap,"myScaleFactor[2]").toDouble();
1727
1728     SetBackground(theViewWindow,aColor);
1729     SetPointOfView(theViewWindow,aPosition);
1730     SetViewUp(theViewWindow,aViewUp);
1731     SetFocalPoint(theViewWindow,aFocalPnt);
1732     SetParallelScale(theViewWindow,aParallelScale);
1733     ScaleView(theViewWindow,VISU::View3D::XAxis,aScaleFactor[0]);
1734     ScaleView(theViewWindow,VISU::View3D::YAxis,aScaleFactor[1]);
1735     ScaleView(theViewWindow,VISU::View3D::ZAxis,aScaleFactor[2]);
1736   }
1737
1738
1739   string View3D_i::ToString (SUIT_ViewWindow* theViewWindow)
1740   {
1741     ostringstream strOut;
1742     Storable::DataToStream(strOut, "myComment", myComment.c_str());
1743     ToStream(theViewWindow, strOut);
1744     strOut << ends;
1745     if(MYDEBUG) MESSAGE("View3D_i::ToString - " << strOut.str());
1746     return strOut.str();
1747   }
1748
1749   void View3D_i::ToStream (SUIT_ViewWindow* theViewWindow, std::ostringstream& theStr)
1750   {
1751     Storable::DataToStream(theStr,"myType",VISU::TVIEW3D);
1752
1753     float backint[3];
1754     GetRenderer(theViewWindow)->GetBackground(backint);
1755     Storable::DataToStream(theStr,"myColor.R",backint[0]);
1756     Storable::DataToStream(theStr,"myColor.G",backint[1]);
1757     Storable::DataToStream(theStr,"myColor.B",backint[2]);
1758
1759     double aPosition[3];
1760     GetPointOfView(theViewWindow,aPosition);
1761     Storable::DataToStream(theStr,"myPosition[0]",aPosition[0]);
1762     Storable::DataToStream(theStr,"myPosition[1]",aPosition[1]);
1763     Storable::DataToStream(theStr,"myPosition[2]",aPosition[2]);
1764
1765     double aFocalPnt[3];
1766     GetFocalPoint(theViewWindow,aFocalPnt);
1767     Storable::DataToStream(theStr,"myFocalPnt[0]",aFocalPnt[0]);
1768     Storable::DataToStream(theStr,"myFocalPnt[1]",aFocalPnt[1]);
1769     Storable::DataToStream(theStr,"myFocalPnt[2]",aFocalPnt[2]);
1770
1771     double aViewUp[3];
1772     GetCamera(theViewWindow)->GetViewUp(aViewUp);
1773     Storable::DataToStream(theStr,"myViewUp[0]",aViewUp[0]);
1774     Storable::DataToStream(theStr,"myViewUp[1]",aViewUp[1]);
1775     Storable::DataToStream(theStr,"myViewUp[2]",aViewUp[2]);
1776
1777     Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(theViewWindow));
1778
1779     double aScaleFactor[3];
1780     VISU::GetViewWindow(theViewWindow)->GetScale(aScaleFactor);
1781     Storable::DataToStream(theStr,"myScaleFactor[0]",aScaleFactor[0]);
1782     Storable::DataToStream(theStr,"myScaleFactor[1]",aScaleFactor[1]);
1783     Storable::DataToStream(theStr,"myScaleFactor[2]",aScaleFactor[2]);
1784   }
1785
1786   void View3D_i::ToStream(std::ostringstream& theStr)
1787   {
1788     SUIT_ViewWindow* aVW = GetViewWindow();
1789     if (aVW)
1790       ToStream(aVW, theStr);
1791   }
1792
1793   void View3D_i::Close()
1794   {
1795     //jfa: may be need to be enclosed in SALOME_Event?
1796     SUIT_ViewWindow* aVW = GetViewWindow();
1797     if (aVW)
1798       aVW->close();
1799     //QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
1800     //int aPos = aViews.find(myViewWindow);
1801     //if (aPos >= 0)
1802     //  myViewWindow->close();
1803   }
1804
1805   View3D_i::~View3D_i()
1806   {
1807     if(MYDEBUG) MESSAGE("View3D_i::~View3D_i");
1808   }
1809
1810   void View3D_i::SetTitle (const char* theTitle)
1811   {
1812     SUIT_ViewWindow* aVW = GetViewWindow();
1813     if (aVW)
1814       ProcessVoidEvent(new TVoidMemFun1ArgEvent<SUIT_ViewWindow,const QString&,QString>
1815                        (aVW,&SUIT_ViewWindow::setCaption,QString(theTitle)));
1816   }
1817
1818   char* View3D_i::GetTitle()
1819   {
1820     SUIT_ViewWindow* aVW = GetViewWindow();
1821     if (aVW)
1822       return CORBA::string_dup(aVW->caption().latin1());
1823     return CORBA::string_dup("");
1824   }
1825
1826   void View3D_i::SetBackground (SUIT_ViewWindow* theViewWindow,
1827                                 const SALOMEDS::Color& theColor)
1828   {
1829     //jfa: may be need to be enclosed in SALOME_Event?
1830     int aColor[3];
1831     aColor[0] = int(255.0*theColor.R);
1832     aColor[1] = int(255.0*theColor.G);
1833     aColor[2] = int(255.0*theColor.B);
1834     QColor aNewColor (aColor[0],aColor[1],aColor[2]);
1835     VISU::GetViewWindow(theViewWindow)->setBackgroundColor(aNewColor);
1836   }
1837
1838   SALOMEDS::Color View3D_i::GetBackground (SUIT_ViewWindow* theViewWindow)
1839   {
1840     SALOMEDS::Color aColor;
1841     float backint[3];
1842     GetRenderer(theViewWindow)->GetBackground(backint);
1843     aColor.R = backint[0];  aColor.G = backint[1];  aColor.B = backint[2];
1844     return aColor;
1845   }
1846
1847   class TUpdateViewerEvent: public SALOME_Event
1848   {
1849     SUIT_ViewWindow* myVW;
1850     Prs3d_i* myPrs3d;
1851     int myDisplaing;
1852   public:
1853     TUpdateViewerEvent(SUIT_ViewWindow* theViewWindow,
1854                        Prs3d_i* thePrs3d,
1855                        int theDisplaing):
1856       myVW(theViewWindow),
1857       myPrs3d(thePrs3d),
1858       myDisplaing(theDisplaing)
1859     {}
1860     virtual void Execute(){
1861       UpdateViewer(myVW, myDisplaing, myPrs3d);
1862     }
1863   };
1864
1865   void View3D_i::EraseAll()
1866   {
1867     if(MYDEBUG) MESSAGE("View3D_i::EraseAll");
1868     SUIT_ViewWindow* aVW = GetViewWindow();
1869     if (aVW)
1870       ProcessVoidEvent(new TUpdateViewerEvent(aVW,NULL,eEraseAll));
1871   }
1872
1873   void View3D_i::DisplayAll()
1874   {
1875     if(MYDEBUG) MESSAGE("View3D_i::DisplayAll");
1876     SUIT_ViewWindow* aVW = GetViewWindow();
1877     if (aVW)
1878       ProcessVoidEvent(new TUpdateViewerEvent(aVW,NULL,eDisplayAll));
1879   }
1880
1881   void View3D_i::Erase (PrsObject_ptr thePrsObj)
1882   {
1883     if(MYDEBUG) MESSAGE("View3D_i::Erase");
1884     SUIT_ViewWindow* aVW = GetViewWindow();
1885     CORBA::Object_ptr anObj = thePrsObj;
1886     Prs3d_i* aPrs = dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in());
1887     if (aVW && aPrs)
1888       ProcessVoidEvent(new TUpdateViewerEvent(aVW,aPrs,eErase));
1889   }
1890
1891   void View3D_i::Display (PrsObject_ptr thePrsObj)
1892   {
1893     if(MYDEBUG) MESSAGE("View3D_i::Display");
1894     SUIT_ViewWindow* aVW = GetViewWindow();
1895     CORBA::Object_ptr anObj = thePrsObj;
1896     Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in());
1897     if (aVW && aPrs)
1898       ProcessVoidEvent(new TUpdateViewerEvent(aVW,aPrs,eDisplay));
1899   }
1900
1901   void View3D_i::DisplayOnly (PrsObject_ptr thePrsObj)
1902   {
1903     if(MYDEBUG) MESSAGE("View3D_i::DisplayOnly");
1904     SUIT_ViewWindow* aVW = GetViewWindow();
1905     CORBA::Object_ptr anObj = thePrsObj;
1906     Prs3d_i* aPrs =  dynamic_cast<Prs3d_i*>(VISU::GetServant(anObj).in());
1907     if (aVW && aPrs)
1908       ProcessVoidEvent(new TUpdateViewerEvent(aVW,aPrs,eDisplayOnly));
1909   }
1910
1911   void View3D_i::FitAll()
1912   {
1913     SUIT_ViewWindow* aVW = GetViewWindow();
1914     if (aVW) {
1915       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1916                        (VISU::GetViewWindow(aVW), &SVTK_ViewWindow::onFitAll));
1917       Update();
1918     }
1919   }
1920
1921   void View3D_i::SetView (VISU::View3D::ViewType theType)
1922   {
1923     SUIT_ViewWindow* aVW = GetViewWindow();
1924     if (!aVW)
1925       return;
1926
1927     switch (theType) {
1928     case VISU::View3D::FRONT :
1929       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1930                        (VISU::GetViewWindow(aVW), &SVTK_ViewWindow::onFrontView));
1931       break;
1932     case VISU::View3D::BACK :
1933       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1934                        (VISU::GetViewWindow(aVW), &SVTK_ViewWindow::onBackView));
1935       break;
1936     case VISU::View3D::LEFT :
1937       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1938                        (VISU::GetViewWindow(aVW),&SVTK_ViewWindow::onLeftView));
1939       break;
1940     case VISU::View3D::RIGHT :
1941       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1942                        (VISU::GetViewWindow(aVW),&SVTK_ViewWindow::onRightView));
1943       break;
1944     case VISU::View3D::TOP :
1945       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1946                        (VISU::GetViewWindow(aVW),&SVTK_ViewWindow::onTopView));
1947       break;
1948     case VISU::View3D::BOTTOM :
1949       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
1950                        (VISU::GetViewWindow(aVW),&SVTK_ViewWindow::onBottomView));
1951       break;
1952     }
1953     Update();
1954   }
1955
1956   class TSet3DViewParamEvent: public SALOME_Event
1957   {
1958   public:
1959     typedef void (*TFun)(SUIT_ViewWindow* theViewWindow, const CORBA::Double theParam[3]);
1960     TSet3DViewParamEvent (TFun theFun,
1961                           SUIT_ViewWindow* theViewWindow,
1962                           const CORBA::Double theParam[3]):
1963       myFun(theFun),
1964       myVW(theViewWindow),
1965       myParam(theParam)
1966     {}
1967     virtual void Execute() {
1968       myFun(myVW,myParam);
1969     }
1970   private:
1971     TFun myFun;
1972     SUIT_ViewWindow* myVW;
1973     const CORBA::Double* myParam;
1974   };
1975
1976   void View3D_i::SetPointOfView (SUIT_ViewWindow* theViewWindow,
1977                                  const CORBA::Double thePosition[3])
1978   {
1979     //jfa: may be need to be enclosed in SALOME_Event?
1980     GetCamera(theViewWindow)->SetPosition(thePosition);
1981   }
1982
1983   void View3D_i::SetPointOfView (const VISU::View3D::XYZ thePosition)
1984   {
1985     if(MYDEBUG) MESSAGE("View3D_i::SetPointOfView");
1986     SUIT_ViewWindow* aVW = GetViewWindow();
1987     if (aVW)
1988       ProcessVoidEvent(new TSet3DViewParamEvent(&SetPointOfView,aVW,thePosition));
1989   }
1990
1991   void View3D_i::GetPointOfView (SUIT_ViewWindow* theViewWindow,
1992                                  CORBA::Double thePosition[3])
1993   {
1994     GetCamera(theViewWindow)->GetPosition(thePosition);
1995   }
1996
1997   VISU::View3D::XYZ_slice* View3D_i::GetPointOfView()
1998   {
1999     if(MYDEBUG) MESSAGE("View3D_i::GetPointOfView");
2000     CORBA::Double aPosition[3];
2001     SUIT_ViewWindow* aVW = GetViewWindow();
2002     if (aVW)
2003       GetPointOfView(aVW,aPosition);
2004     return VISU::View3D::XYZ_dup(aPosition);
2005   }
2006
2007   void View3D_i::SetViewUp (SUIT_ViewWindow* theViewWindow,
2008                             const CORBA::Double theViewUp[3])
2009   {
2010     GetCamera(theViewWindow)->SetViewUp(theViewUp);
2011   }
2012
2013   void View3D_i::SetViewUp (const VISU::View3D::XYZ theViewUp)
2014   {
2015     if(MYDEBUG) MESSAGE("View3D_i::SetViewUp");
2016     SUIT_ViewWindow* aVW = GetViewWindow();
2017     if (aVW)
2018       ProcessVoidEvent(new TSet3DViewParamEvent(&SetViewUp,aVW,theViewUp));
2019   }
2020
2021   void View3D_i::GetViewUp (SUIT_ViewWindow* theViewWindow,
2022                             CORBA::Double theViewUp[3])
2023   {
2024     GetCamera(theViewWindow)->GetViewUp(theViewUp);
2025   }
2026
2027   VISU::View3D::XYZ_slice* View3D_i::GetViewUp()
2028   {
2029     if(MYDEBUG) MESSAGE("View3D_i::GetViewUp");
2030     CORBA::Double aViewUp[3];
2031     SUIT_ViewWindow* aVW = GetViewWindow();
2032     if (aVW)
2033       GetCamera(aVW)->GetViewUp(aViewUp);
2034     return VISU::View3D::XYZ_dup(aViewUp);
2035   }
2036
2037   void View3D_i::SetFocalPoint (SUIT_ViewWindow* theViewWindow,
2038                                 const CORBA::Double theFocalPnt[3])
2039   {
2040     GetCamera(theViewWindow)->SetFocalPoint(theFocalPnt);
2041   }
2042
2043   void View3D_i::SetFocalPoint (const VISU::View3D::XYZ theCoord)
2044   {
2045     if(MYDEBUG) MESSAGE("View3D_i::SetFocalPoint");
2046     SUIT_ViewWindow* aVW = GetViewWindow();
2047     if (aVW)
2048       ProcessVoidEvent(new TSet3DViewParamEvent(&SetFocalPoint,aVW,theCoord));
2049   }
2050
2051
2052   void View3D_i::GetFocalPoint (SUIT_ViewWindow* theViewWindow,
2053                                 CORBA::Double theFocalPnt[3])
2054   {
2055     GetCamera(theViewWindow)->GetFocalPoint(theFocalPnt);
2056   }
2057
2058   VISU::View3D::XYZ_slice* View3D_i::GetFocalPoint()
2059   {
2060     if(MYDEBUG) MESSAGE("View3D_i::GetFocalPoint");
2061     CORBA::Double aFocalPnt[3];
2062     SUIT_ViewWindow* aVW = GetViewWindow();
2063     if (aVW)
2064       GetFocalPoint(aVW,aFocalPnt);
2065     return VISU::View3D::XYZ_dup(aFocalPnt);
2066   }
2067
2068   class TSetViewParamEvent: public SALOME_Event
2069   {
2070   public:
2071     typedef void (*TFun)(SUIT_ViewWindow* theViewWindow, CORBA::Double theParam);
2072     TSetViewParamEvent (TFun theFun,
2073                         SUIT_ViewWindow* theViewWindow,
2074                         CORBA::Double theParam):
2075       myFun(theFun),
2076       myVW(theViewWindow),
2077       myParam(theParam)
2078     {}
2079     virtual void Execute()
2080     {
2081       myFun(myVW,myParam);
2082     }
2083   private:
2084     TFun myFun;
2085     SUIT_ViewWindow* myVW;
2086     CORBA::Double myParam;
2087   };
2088
2089   void View3D_i::SetParallelScale (SUIT_ViewWindow* theViewWindow,
2090                                    CORBA::Double theScale)
2091   {
2092     GetCamera(theViewWindow)->SetParallelScale(theScale);
2093   }
2094
2095   void View3D_i::SetParallelScale (CORBA::Double theScale)
2096   {
2097     if(MYDEBUG) MESSAGE("View3D_i::SetParallelScale");
2098     SUIT_ViewWindow* aVW = GetViewWindow();
2099     if (aVW)
2100       ProcessVoidEvent(new TSetViewParamEvent(&SetParallelScale,aVW,theScale));
2101   }
2102
2103   CORBA::Double View3D_i::GetParallelScale (SUIT_ViewWindow* theViewWindow)
2104   {
2105     return GetCamera(theViewWindow)->GetParallelScale();
2106   }
2107
2108   CORBA::Double View3D_i::GetParallelScale()
2109   {
2110     if(MYDEBUG) MESSAGE("View3D_i::GetParallelScale");
2111     SUIT_ViewWindow* aVW = GetViewWindow();
2112     if (aVW)
2113       return GetParallelScale(aVW);
2114     return 1.0;
2115   }
2116
2117   void View3D_i::ScaleView (SUIT_ViewWindow* theViewWindow,
2118                             VISU::View3D::Axis theAxis, CORBA::Double theParam)
2119   {
2120     SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(theViewWindow);
2121     double aScaleFactor[3];
2122     aViewWindow->GetScale(aScaleFactor);
2123     aScaleFactor[theAxis] = theParam;
2124     aViewWindow->SetScale(aScaleFactor);
2125   }
2126
2127   void SetScaleView (SUIT_ViewWindow* theViewWindow, const CORBA::Double theScale[3])
2128   {
2129     double aScale[3] = {theScale[0], theScale[1], theScale[2]};
2130     VISU::GetViewWindow(theViewWindow)->SetScale(aScale);
2131   }
2132
2133   void View3D_i::ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam)
2134   {
2135     if(MYDEBUG) MESSAGE("View3D_i::ScaleView");
2136     SUIT_ViewWindow* aVW = GetViewWindow();
2137     if (aVW) {
2138       double aScale[3];
2139       VISU::GetViewWindow(aVW)->GetScale(aScale);
2140       aScale[theAxis] = theParam;
2141       ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,aVW,aScale));
2142     }
2143   }
2144
2145   void View3D_i::RemoveScale()
2146   {
2147     if(MYDEBUG) MESSAGE("View3D_i::RemoveScale");
2148     SUIT_ViewWindow* aVW = GetViewWindow();
2149     if (aVW) {
2150       double aScale[3] = {1.0, 1.0, 1.0};
2151       ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,aVW,aScale));
2152     }
2153   }
2154 }