]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
To provide save/restore view params functionality
authorapo <apo@opencascade.com>
Wed, 5 Oct 2005 12:38:40 +0000 (12:38 +0000)
committerapo <apo@opencascade.com>
Wed, 5 Oct 2005 12:38:40 +0000 (12:38 +0000)
src/VISUGUI/VisuGUI_Module.cxx
src/VISUGUI/VisuGUI_Module.h

index 93ecda9831fa6c39f63bb454adac3cd95e166234..3e28bbc470ff061a70b0fa5e2e6e4356fda087ae 100644 (file)
@@ -279,7 +279,12 @@ VisuGUI_Module
 
   mgr->setRule( action( VISU_DISPLAY ), aRule, true );
 
-  mgr->setRule( action( VISU_SAVE_VIEW_PARAMS ), "$client in {'VTKViewer' 'SVTK'} and selcount=0", true );
+  mgr->setRule( action( VISU_SAVE_VIEW_PARAMS ), "selcount=1 and $type in {'VISU::TVIEW3D' VISU::TGAUSSVIEW}", true );
+  mgr->setRule( action( VISU_SAVE_VIEW_PARAMS_1 ), "$client in {'VTKViewer' 'SVTK'} and selcount=0", true );
+  aRule = "selcount=1 and "
+    "((type='VISU::TVIEW3D' and activeView='VTKViewer') or "
+    "(type='VISU::TGAUSSVIEW' and activeView='VVTK'))";
+  mgr->setRule( action( VISU_RESTORE_VIEW_PARAMS ), aRule, true );
 }
 
 //---------------------------------------------------------------
@@ -866,42 +871,85 @@ namespace
                const char* theSuffix,
                std::ostringstream& theStr)
   {
-    float backint[3];
+    float aColor[3];
     vtkRenderer* aRenderer = theViewWindow->getRenderer();
-    aRenderer->GetBackground(backint);
-    Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".R",backint[0]);
-    Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".G",backint[1]);
-    Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".B",backint[2]);
+    aRenderer->GetBackground(aColor);
+    Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".R",aColor[0]);
+    Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".G",aColor[1]);
+    Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".B",aColor[2]);
       
     double aPosition[3];
     vtkCamera* aCamera = aRenderer->GetActiveCamera();
     aCamera->GetPosition(aPosition);
     Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[0]",aPosition[0]);
-    Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[1]",aPosition[0]);
-    Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[2]",aPosition[0]);
+    Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[1]",aPosition[1]);
+    Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[2]",aPosition[2]);
 
     double aFocalPnt[3];
     aCamera->GetFocalPoint(aFocalPnt);
     Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[0]",aFocalPnt[0]);
-    Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[1]",aFocalPnt[0]);
-    Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[2]",aFocalPnt[0]);
+    Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[1]",aFocalPnt[1]);
+    Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[2]",aFocalPnt[2]);
       
     double aViewUp[3];
     aCamera->GetViewUp(aViewUp);
-    Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[0]",aFocalPnt[0]);
-    Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[1]",aFocalPnt[0]);
-    Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[2]",aFocalPnt[0]);
+    Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[0]",aViewUp[0]);
+    Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[1]",aViewUp[1]);
+    Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[2]",aViewUp[2]);
       
     float aParallelScale = aCamera->GetParallelScale();
     Storable::DataToStream(theStr,std::string("myParallelScale") + theSuffix,aParallelScale);
       
     double aScaleFactor[3];
     theViewWindow->GetScale(aScaleFactor);
-    Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[0]",aFocalPnt[0]);
-    Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[1]",aFocalPnt[0]);
-    Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[2]",aFocalPnt[0]);
+    Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[0]",aScaleFactor[0]);
+    Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[1]",aScaleFactor[1]);
+    Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[2]",aScaleFactor[2]);
   }
 
+  //---------------------------------------------------------------
+  void
+  SetViewParams(VVTK_MainWindow* theViewWindow,
+               const char* theSuffix,
+               const Storable::TRestoringMap& theMap)
+  {
+    float aColor[3];
+    aColor[0] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".R").toDouble();
+    aColor[1] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".G").toDouble();
+    aColor[2] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".B").toDouble();
+    vtkRenderer* aRenderer = theViewWindow->getRenderer();
+    aRenderer->SetBackground(aColor);
+      
+    double aPosition[3];
+    aPosition[0] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[0]").toDouble();
+    aPosition[1] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[1]").toDouble();
+    aPosition[2] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[2]").toDouble();
+    vtkCamera* aCamera = aRenderer->GetActiveCamera();
+    aCamera->SetPosition(aPosition);
+
+    double aFocalPnt[3];
+    aFocalPnt[0] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[0]").toDouble();
+    aFocalPnt[1] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[1]").toDouble();
+    aFocalPnt[2] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[2]").toDouble();
+    aCamera->SetFocalPoint(aFocalPnt);
+      
+    double aViewUp[3];
+    aViewUp[0] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[0]").toDouble();
+    aViewUp[1] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[1]").toDouble();
+    aViewUp[2] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[2]").toDouble();
+    aCamera->SetViewUp(aViewUp);
+
+    float aParallelScale = Storable::FindValue(theMap,std::string("myParallelScale") + theSuffix).toDouble();
+    aCamera->SetParallelScale(aParallelScale);
+      
+    double aScaleFactor[3];
+    aScaleFactor[0] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[0]").toDouble();
+    aScaleFactor[1] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[1]").toDouble();
+    aScaleFactor[2] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[2]").toDouble();
+    theViewWindow->SetScale(aScaleFactor);
+  }
+
+  //---------------------------------------------------------------
   void
   GetViewParams(VVTK_MainWindow1* theViewWindow,
                std::ostringstream& theStr)
@@ -925,6 +973,32 @@ namespace
     Storable::DataToStream(theStr,"myCursorDepth",aDepth);
   }
 
+  //---------------------------------------------------------------
+  void
+  SetViewParams(VVTK_MainWindow1* theViewWindow,
+               const Storable::TRestoringMap& theMap)
+  {
+    SetViewParams(theViewWindow,"1",theMap);
+
+    VISU_ImplicitFunctionWidget* aWidget = theViewWindow->GetImplicitFunctionWidget();
+    float anOrigin[3];
+    anOrigin[0] = Storable::FindValue(theMap,"myCursorOrigin[0]").toDouble();
+    anOrigin[1] = Storable::FindValue(theMap,"myCursorOrigin[1]").toDouble();
+    anOrigin[2] = Storable::FindValue(theMap,"myCursorOrigin[2]").toDouble();
+    aWidget->SetOrigin(anOrigin);
+
+    float aNormal[3];
+    aNormal[0] = Storable::FindValue(theMap,"myCursorNormal[0]").toDouble();
+    aNormal[1] = Storable::FindValue(theMap,"myCursorNormal[1]").toDouble();
+    aNormal[2] = Storable::FindValue(theMap,"myCursorNormal[2]").toDouble();
+    aWidget->SetNormal(aNormal);
+
+    float aDepth = Storable::FindValue(theMap,"myCursorDepth").toDouble();
+    aWidget->SetDistance(aDepth);
+  }
+
+
+  //---------------------------------------------------------------
   void
   GetViewParams(VVTK_MainWindow2* theViewWindow,
                std::ostringstream& theStr)
@@ -932,6 +1006,15 @@ namespace
     GetViewParams(theViewWindow,"2",theStr);
   }
 
+  void
+  SetViewParams(VVTK_MainWindow2* theViewWindow,
+               const Storable::TRestoringMap& theMap)
+  {
+    SetViewParams(theViewWindow,"2",theMap);
+  }
+
+
+  //---------------------------------------------------------------
   std::string
   GetViewParams(VVTK_ViewWindow* theViewWindow)
   {
@@ -942,10 +1025,18 @@ namespace
     GetViewParams(theViewWindow->getMainWindow1(),aStream);
     GetViewParams(theViewWindow->getMainWindow2(),aStream);
 
-    aStream<<ends;    
-
     return aStream.str();
   }
+
+  //---------------------------------------------------------------
+  void
+  SetViewParams(VVTK_ViewWindow* theViewWindow,
+               const Storable::TRestoringMap& theMap)
+  {
+    SetViewParams(theViewWindow->getMainWindow1(),theMap);
+    SetViewParams(theViewWindow->getMainWindow2(),theMap);
+  }
+
 }
 
 void
@@ -1012,3 +1103,39 @@ OnSaveViewParams()
 
   UpdateObjBrowser(this);
 }
+
+
+//---------------------------------------------------------------
+void
+VisuGUI_Module::
+OnRestoreViewParams()
+{
+  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+
+  SALOME_ListIO aListIO;
+  aSelectionMgr->selectedObjects(aListIO);
+  if(aListIO.Extent() > 1)
+    return;
+
+  const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
+  _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
+  _PTR(SObject) aSObj = aCStudy->FindObjectID(anIO->getEntry());
+  std::string aName = aSObj->GetName();
+
+  SUIT_ViewManager* aViewManager = getApp()->activeViewManager();
+  if(aViewManager->getType() == SVTK_Viewer::Type())
+    VISU::View3D_i::RestoreViewParams(aViewManager,aName.c_str());
+  else if(aViewManager->getType() == VVTK_Viewer::Type()){
+    _PTR(GenericAttribute) anAttr;
+    if(aSObj->FindAttribute(anAttr,"AttributeComment")){
+      _PTR(AttributeComment) aCmnt(anAttr);
+      QString aStream(aCmnt->Value().c_str());
+      Storable::TRestoringMap aMap;
+      Storable::StrToMap(aStream,aMap);
+      SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
+      VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
+      SetViewParams(aViewWindow,aMap);
+    }
+  }
+}
+
index 7e86eb486c4c2679ed88322f316f7250986bb407..33a1ec026165fd8ddd951b4785a129bfd6b1233a 100644 (file)
@@ -146,6 +146,10 @@ protected slots:
   void
   OnSaveViewParams();
 
+  virtual
+  void
+  OnRestoreViewParams();
+
 protected:
   VISU::TViewerMap myViewerMap;