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