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