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