Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISU_I / VISU_View_i.cc
index 20e75cf179df6fbd46409750d8aa8dafbb38e7fb..57a37098107b80b087638d1b0536d23cd2899dfe 100644 (file)
@@ -46,7 +46,6 @@
 
 #include "SVTK_ViewWindow.h"
 #include "SVTK_ViewModel.h"
-#include "SVTK_RenderWindow.h"
 
 #include "SPlot2d_ViewModel.h"
 #include "Plot2d_ViewFrame.h"
@@ -57,6 +56,7 @@
 #include <QtxWorkstack.h>
 
 #include <qworkspace.h>
+#include <qimage.h>
 
 #include <vtkCamera.h>
 #include <vtkRenderer.h>
@@ -1334,7 +1334,7 @@ namespace VISU {
                    const int mode,
                    const double xMin, const double xMax,
                    const double yMin, const double yMax):
-      myView(theView),
+      myView(theView), 
       myMode(mode),
       myXMin(xMin),myXMax(xMax),
       myYMin(yMin),myYMax(yMax)
@@ -1351,7 +1351,7 @@ namespace VISU {
     const double myYMax;
     Plot2d_ViewFrame* myView;
   };
-
+  
   void XYPlot_i::FitXRange(const CORBA::Double xMin,const CORBA::Double xMax)
   {
     const CORBA::Long mode = 1;
@@ -1374,7 +1374,7 @@ namespace VISU {
     const CORBA::Long mode = 0;
     ProcessVoidEvent(new TFitRangeEvent(myView,mode,xMin,xMax,yMin,yMax));
   }
-
+  
   void XYPlot_i::GetFitRanges(double& xMin, double& xMax, double& yMin, double& yMax)
   {
     double y2Min,y2Max;
@@ -1484,14 +1484,17 @@ namespace VISU {
 
   struct TCreateView3dEvent: public SALOME_Event
   {
+    SalomeApp_Application *myApplication;
     View3D_i * myView3D;
     int        myNew;
 
     typedef SUIT_ViewWindow* TResult;
     TResult myResult;
 
-    TCreateView3dEvent (View3D_i * theView3D,
+    TCreateView3dEvent (SalomeApp_Application *theApplication,
+                       View3D_i * theView3D,
                        const int  theNew):
+      myApplication(theApplication),
       myView3D(theView3D),
       myNew(theNew),
       myResult(NULL)
@@ -1501,35 +1504,41 @@ namespace VISU {
     void
     Execute()
     {
-      if (!myView3D->myApplication)
+      if (!myApplication)
        return;
 
-      SUIT_ViewManager * aViewMgr =
-       myView3D->myApplication->getViewManager(SVTK_Viewer::Type(), false);
-
-      if (aViewMgr) {
-       if (myNew) {
-         myResult = aViewMgr->createViewWindow();
-       } else {
-         myResult = aViewMgr->getActiveView();
+      if(myNew){
+       if(SUIT_ViewManager* aViewManager = myApplication->getViewManager(SVTK_Viewer::Type(),false)){
+         myResult = aViewManager->createViewWindow();
+         myView3D->myViewManager = aViewManager;
+       }else{
+         if(SUIT_ViewManager* aViewManager = myApplication->getViewManager(SVTK_Viewer::Type(),true)){
+           myResult = aViewManager->getActiveView();
+           myView3D->myViewManager = aViewManager;
+         }
        }
-      } else {
-       if (myNew) {
-         aViewMgr = myView3D->myApplication->getViewManager(SVTK_Viewer::Type(), true);
-         myResult = aViewMgr->getActiveView();
-       } else {
-         return; // there are no current 3D view
+      }else{
+       if(SUIT_ViewManager* aViewManager = myApplication->activeViewManager()){
+         if(SUIT_ViewWindow* aView = aViewManager->getActiveView()){
+           if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aView)){
+             myView3D->myViewManager = aViewManager;
+             myResult = aViewManager->getActiveView();
+           }
+         }
+       }else{
+         if(SUIT_ViewManager* aViewManager = myApplication->getViewManager(SVTK_Viewer::Type(),false)){
+           myView3D->myViewManager = aViewManager;
+           myResult = aViewManager->getActiveView();
+         }
        }
       }
-
-      myView3D->myViewManager = aViewMgr;
     }
   };
 
   Storable* View3D_i::Create (int theNew)
   {
     if (MYDEBUG) MESSAGE("View3D_i::Create");
-    SUIT_ViewWindow* aVW = ProcessEvent(new TCreateView3dEvent(this, theNew));
+    SUIT_ViewWindow* aVW = ProcessEvent(new TCreateView3dEvent(myApplication, this, theNew));
     if (aVW) {
       SetViewWindow(aVW);
       return this;
@@ -1548,7 +1557,7 @@ namespace VISU {
       {}
       virtual void Execute()
       {
-       SVTK_ViewWindow* vf = VISU::GetViewWindow(myVW);
+       SVTK_ViewWindow* vf = dynamic_cast<SVTK_ViewWindow*>(myVW);
        vtkRenderer* Renderer = vf->getRenderer();
        vtkActorCollection* theActors = Renderer->GetActors();
        theActors->InitTraversal();
@@ -1730,8 +1739,9 @@ namespace VISU {
     SetViewUp(theViewWindow,aViewUp);
     SetFocalPoint(theViewWindow,aFocalPnt);
     SetParallelScale(theViewWindow,aParallelScale);
-    SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(theViewWindow);
-    aViewWindow->SetScale(aScaleFactor);
+    ScaleView(theViewWindow,VISU::View3D::XAxis,aScaleFactor[0]);
+    ScaleView(theViewWindow,VISU::View3D::YAxis,aScaleFactor[1]);
+    ScaleView(theViewWindow,VISU::View3D::ZAxis,aScaleFactor[2]);
   }
 
 
@@ -1776,7 +1786,7 @@ namespace VISU {
     Storable::DataToStream(theStr,"myParallelScale",GetParallelScale(theViewWindow));
 
     double aScaleFactor[3];
-    VISU::GetViewWindow(theViewWindow)->GetScale(aScaleFactor);
+    (dynamic_cast<SVTK_ViewWindow*>(theViewWindow))->GetScale(aScaleFactor);
     Storable::DataToStream(theStr,"myScaleFactor[0]",aScaleFactor[0]);
     Storable::DataToStream(theStr,"myScaleFactor[1]",aScaleFactor[1]);
     Storable::DataToStream(theStr,"myScaleFactor[2]",aScaleFactor[2]);
@@ -1831,7 +1841,7 @@ namespace VISU {
     aColor[1] = int(255.0*theColor.G);
     aColor[2] = int(255.0*theColor.B);
     QColor aNewColor (aColor[0],aColor[1],aColor[2]);
-    VISU::GetViewWindow(theViewWindow)->setBackgroundColor(aNewColor);
+    (dynamic_cast<SVTK_ViewWindow*>(theViewWindow))->setBackgroundColor(aNewColor);
   }
 
   SALOMEDS::Color View3D_i::GetBackground (SUIT_ViewWindow* theViewWindow)
@@ -1912,7 +1922,7 @@ namespace VISU {
     SUIT_ViewWindow* aVW = GetViewWindow();
     if (aVW) {
       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
-                      (VISU::GetViewWindow(aVW), &SVTK_ViewWindow::onFitAll));
+                      (dynamic_cast<SVTK_ViewWindow*>(aVW), &SVTK_ViewWindow::onFitAll));
       Update();
     }
   }
@@ -1926,27 +1936,27 @@ namespace VISU {
     switch (theType) {
     case VISU::View3D::FRONT :
       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
-                      (VISU::GetViewWindow(aVW), &SVTK_ViewWindow::onFrontView));
+                      (dynamic_cast<SVTK_ViewWindow*>(aVW), &SVTK_ViewWindow::onFrontView));
       break;
     case VISU::View3D::BACK :
       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
-                      (VISU::GetViewWindow(aVW), &SVTK_ViewWindow::onBackView));
+                      (dynamic_cast<SVTK_ViewWindow*>(aVW), &SVTK_ViewWindow::onBackView));
       break;
     case VISU::View3D::LEFT :
       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
-                      (VISU::GetViewWindow(aVW),&SVTK_ViewWindow::onLeftView));
+                      (dynamic_cast<SVTK_ViewWindow*>(aVW),&SVTK_ViewWindow::onLeftView));
       break;
     case VISU::View3D::RIGHT :
       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
-                      (VISU::GetViewWindow(aVW),&SVTK_ViewWindow::onRightView));
+                      (dynamic_cast<SVTK_ViewWindow*>(aVW),&SVTK_ViewWindow::onRightView));
       break;
     case VISU::View3D::TOP :
       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
-                      (VISU::GetViewWindow(aVW),&SVTK_ViewWindow::onTopView));
+                      (dynamic_cast<SVTK_ViewWindow*>(aVW),&SVTK_ViewWindow::onTopView));
       break;
     case VISU::View3D::BOTTOM :
       ProcessVoidEvent(new TVoidMemFunEvent<SVTK_ViewWindow>
-                      (VISU::GetViewWindow(aVW),&SVTK_ViewWindow::onBottomView));
+                      (dynamic_cast<SVTK_ViewWindow*>(aVW),&SVTK_ViewWindow::onBottomView));
       break;
     }
     Update();
@@ -2116,7 +2126,7 @@ namespace VISU {
   void View3D_i::ScaleView (SUIT_ViewWindow* theViewWindow,
                            VISU::View3D::Axis theAxis, CORBA::Double theParam)
   {
-    SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(theViewWindow);
+    SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(theViewWindow);
     double aScaleFactor[3];
     aViewWindow->GetScale(aScaleFactor);
     aScaleFactor[theAxis] = theParam;
@@ -2126,7 +2136,7 @@ namespace VISU {
   void SetScaleView (SUIT_ViewWindow* theViewWindow, const CORBA::Double theScale[3])
   {
     double aScale[3] = {theScale[0], theScale[1], theScale[2]};
-    VISU::GetViewWindow(theViewWindow)->SetScale(aScale);
+    (dynamic_cast<SVTK_ViewWindow*>(theViewWindow))->SetScale(aScale);
   }
 
   void View3D_i::ScaleView(VISU::View3D::Axis theAxis, CORBA::Double theParam)
@@ -2135,7 +2145,7 @@ namespace VISU {
     SUIT_ViewWindow* aVW = GetViewWindow();
     if (aVW) {
       double aScale[3];
-      VISU::GetViewWindow(aVW)->GetScale(aScale);
+      (dynamic_cast<SVTK_ViewWindow*>(aVW))->GetScale(aScale);
       aScale[theAxis] = theParam;
       ProcessVoidEvent(new TSet3DViewParamEvent(&SetScaleView,aVW,aScale));
     }