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