]> 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 11:37:33 +0000 (11:37 +0000)
committerapo <apo@opencascade.com>
Wed, 5 Oct 2005 11:37:33 +0000 (11:37 +0000)
src/VISUGUI/VisuGUI.h
src/VISUGUI/VisuGUI_Module.cxx
src/VISUGUI/VisuGUI_Module.h
src/VVTK/VVTK_MainWindow.cxx
src/VVTK/VVTK_MainWindow.h
src/VVTK/VVTK_ViewWindow.cxx
src/VVTK/VVTK_ViewWindow.h

index 2e985a1ee108e475f19fc51365a0d110c03d1e77..5b76de10432c10a31ec6d4dfbbac67b866afbb52 100644 (file)
@@ -120,8 +120,8 @@ protected slots:
   void OnMergeScalarBars();
   void OnFreeScalarBars();
 
-  void OnSaveViewParams();
-  void OnRestoreViewParams();
+  virtual void OnSaveViewParams();
+  virtual void OnRestoreViewParams();
 
   void OnRename();
   void OnClippingPlanes();
index 96b52791105bd7597ee22f602bda8b2cfa73ca8c..93ecda9831fa6c39f63bb454adac3cd95e166234 100644 (file)
 #include "VisuGUI_Tools.h"
 #include "VisuGUI_ActionsDef.h"
 
+#include "VISU_ImplicitFunctionWidget.h"
+#include "SalomeApp_Study.h"
+#include "VVTK_MainWindow.h"
+#include "VISU_View_i.hh"
+
+#include <vtkRenderer.h>
+#include <vtkCamera.h>
+
+#include <sstream>
+
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
 #else
@@ -268,6 +278,8 @@ VisuGUI_Module
     ")) and (isVisible=false)";
 
   mgr->setRule( action( VISU_DISPLAY ), aRule, true );
+
+  mgr->setRule( action( VISU_SAVE_VIEW_PARAMS ), "$client in {'VTKViewer' 'SVTK'} and selcount=0", true );
 }
 
 //---------------------------------------------------------------
@@ -844,3 +856,159 @@ VisuGUI_Module
 
   QApplication::restoreOverrideCursor();
 }
+
+
+//---------------------------------------------------------------
+namespace
+{
+  void
+  GetViewParams(VVTK_MainWindow* theViewWindow,
+               const char* theSuffix,
+               std::ostringstream& theStr)
+  {
+    float backint[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]);
+      
+    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]);
+
+    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]);
+      
+    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]);
+      
+    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]);
+  }
+
+  void
+  GetViewParams(VVTK_MainWindow1* theViewWindow,
+               std::ostringstream& theStr)
+  {
+    GetViewParams(theViewWindow,"1",theStr);
+
+    VISU_ImplicitFunctionWidget* aWidget = theViewWindow->GetImplicitFunctionWidget();
+    float anOrigin[3];
+    aWidget->GetOrigin(anOrigin);
+    Storable::DataToStream(theStr,"myCursorOrigin[0]",anOrigin[0]);
+    Storable::DataToStream(theStr,"myCursorOrigin[1]",anOrigin[1]);
+    Storable::DataToStream(theStr,"myCursorOrigin[2]",anOrigin[2]);
+
+    float aNormal[3];
+    aWidget->GetNormal(aNormal);
+    Storable::DataToStream(theStr,"myCursorNormal[0]",aNormal[0]);
+    Storable::DataToStream(theStr,"myCursorNormal[1]",aNormal[1]);
+    Storable::DataToStream(theStr,"myCursorNormal[2]",aNormal[2]);
+
+    float aDepth = aWidget->Distance();
+    Storable::DataToStream(theStr,"myCursorDepth",aDepth);
+  }
+
+  void
+  GetViewParams(VVTK_MainWindow2* theViewWindow,
+               std::ostringstream& theStr)
+  {
+    GetViewParams(theViewWindow,"2",theStr);
+  }
+
+  std::string
+  GetViewParams(VVTK_ViewWindow* theViewWindow)
+  {
+    std::ostringstream aStream;
+
+    Storable::DataToStream(aStream,"myComment","GAUSSVIEW");
+    
+    GetViewParams(theViewWindow->getMainWindow1(),aStream);
+    GetViewParams(theViewWindow->getMainWindow2(),aStream);
+
+    aStream<<ends;    
+
+    return aStream.str();
+  }
+}
+
+void
+VisuGUI_Module::
+OnSaveViewParams()
+{
+  _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
+  if (CheckLock(aCStudy))
+    return;
+
+  SalomeApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
+
+  SALOME_ListIO aListIO;
+  aSelectionMgr->selectedObjects(aListIO);
+  if(aListIO.Extent() > 1)
+    return;
+
+  std::string aName;
+  if(aListIO.Extent() == 0){
+    aName = VISU::View3D_i::GenerateViewParamsName().latin1();
+  }else{
+    const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
+    aName = anIO->getName();
+  }
+
+  SUIT_ViewManager* aViewManager = getApp()->activeViewManager();
+  if(aViewManager->getType() == SVTK_Viewer::Type())
+    VISU::View3D_i::SaveViewParams(aViewManager,aName.c_str());
+  else if(aViewManager->getType() == VVTK_Viewer::Type()){
+    SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
+    VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
+    std::string aValue = GetViewParams(aViewWindow);
+
+    SUIT_Study* aSStudy = aViewManager->study();
+    SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy);
+    _PTR(Study) aCStudy = aStudy->studyDS();
+    std::vector<_PTR(SObject)> aList = aCStudy->FindObjectByName(aName,"VISU");
+    _PTR(GenericAttribute) anAttr;
+    int iEnd = aList.size();
+    for(int i = 0; i < iEnd; i++){
+      _PTR(SObject) anObj = aList[i];
+      std::string anEntry = anObj->GetID();
+      if(anObj->FindAttribute(anAttr,"AttributeComment")){
+       _PTR(AttributeComment) aCmnt (anAttr);
+       std::string aComm (aCmnt->Value());
+       if(aComm.compare(View3D_i::myComment) >= 0){
+         aCmnt->SetValue(aValue.c_str());
+         return;
+       }
+      }
+    }
+    
+    _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy);
+    std::string aSComponentEntry = aSComponent->GetID();
+    std::string anEntry = CreateAttributes(aCStudy, 
+                                          aSComponentEntry.c_str(), 
+                                          "", 
+                                          "", 
+                                           aName.c_str(),
+                                          "",
+                                          aValue.c_str());
+  }else
+    return;
+
+  UpdateObjBrowser(this);
+}
index e361045033eaef6556df10b04b0a21ee9c0adfbc..7e86eb486c4c2679ed88322f316f7250986bb407 100644 (file)
@@ -142,6 +142,10 @@ protected slots:
   void
   OnErasePrs();
 
+  virtual
+  void
+  OnSaveViewParams();
+
 protected:
   VISU::TViewerMap myViewerMap;
 
index 1feda1dd6545840b6e5b997ba98964a2695b1de5..47e53d045e8aae8d7e5b72154f374e612ed849b2 100644 (file)
@@ -257,6 +257,13 @@ VVTK_MainWindow1
   return myRenderer;
 }
 
+VISU_ImplicitFunctionWidget* 
+VVTK_MainWindow1
+::GetImplicitFunctionWidget()
+{
+  return myRenderer->GetImplicitFunctionWidget();
+}
+
 //----------------------------------------------------------------------------
 QSize
 VVTK_MainWindow1
index 5c2f0329c2104ddecb68595929ed9ee945dba49e..0b6f7995a14ffadc5eef09ee163e005cac8932c9 100644 (file)
@@ -10,8 +10,9 @@
 
 class QSplitter;
 
-class VVTK_PickingDlg;
+class VISU_ImplicitFunctionWidget;
 class VVTK_SegmentationCursorDlg;
+class VVTK_PickingDlg;
 class VVTK_MainWindow2;
 class VVTK_Renderer1;
 class VVTK_Renderer2;
@@ -86,6 +87,9 @@ public:
   VVTK_Renderer1* 
   GetRenderer1();
 
+  VISU_ImplicitFunctionWidget*
+  GetImplicitFunctionWidget();
+
   virtual
   QSize
   sizeHint() const;
index d2a1e564ebee0ada782568d0ba4d2cfaf6bb277e..5ba89216737b82dc8901c714739f494399f4e323 100755 (executable)
@@ -136,6 +136,22 @@ VVTK_ViewWindow
 {}
 
 
+//----------------------------------------------------------------------------
+VVTK_MainWindow1* 
+VVTK_ViewWindow
+::getMainWindow1()
+{
+  return myMainWindow1;
+}
+
+VVTK_MainWindow2* 
+VVTK_ViewWindow
+::getMainWindow2()
+{
+  return myMainWindow2;
+}
+
+
 //----------------------------------------------------------------------------
 void
 VVTK_ViewWindow
index bbfb50c1146b25905d720fb6293c8d7dcdbfc8ea..a6ddca69637cc150036057e0a99b14585526d9ab 100755 (executable)
@@ -8,10 +8,13 @@
 #include "VVTK.h"
 #include "SVTK_ViewWindow.h"
 
+#include <string>
+
 class VVTK_MainWindow1;
 class VVTK_MainWindow2;
 class SVTK_View;
 
+//----------------------------------------------------------------------------
 class VVTK_EXPORT VVTK_ViewWindow : public SVTK_ViewWindow
 {
   Q_OBJECT;
@@ -26,6 +29,14 @@ public:
   void
   Initialize(SVTK_ViewModelBase* theModel);
 
+  //----------------------------------------------------------------------------
+  VVTK_MainWindow1* 
+  getMainWindow1();
+
+  VVTK_MainWindow2* 
+  getMainWindow2();
+
+  //----------------------------------------------------------------------------
   virtual
   void
   AddActor(VTKViewer_Actor* theActor,
@@ -40,6 +51,7 @@ public:
   void
   Repaint(bool theUpdateTrihedron = true);
 
+  //----------------------------------------------------------------------------
   /*  interactive object management */
   virtual
   void
@@ -50,6 +62,7 @@ public:
   void
   unHighlightAll();
 
+  //----------------------------------------------------------------------------
 public slots:
   virtual
   void
@@ -63,6 +76,7 @@ public slots:
   void 
   onFitAll();
 
+  //----------------------------------------------------------------------------
 protected:
   virtual 
   void