From: apo Date: Wed, 5 Oct 2005 11:37:33 +0000 (+0000) Subject: To provide save/restore view params functionality X-Git-Tag: BR-D5-38-2003_D2005-12-10~60 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=45fa9f690fa703fc7970f30b02dcc693084310f1;p=modules%2Fvisu.git To provide save/restore view params functionality --- diff --git a/src/VISUGUI/VisuGUI.h b/src/VISUGUI/VisuGUI.h index 2e985a1e..5b76de10 100644 --- a/src/VISUGUI/VisuGUI.h +++ b/src/VISUGUI/VisuGUI.h @@ -120,8 +120,8 @@ protected slots: void OnMergeScalarBars(); void OnFreeScalarBars(); - void OnSaveViewParams(); - void OnRestoreViewParams(); + virtual void OnSaveViewParams(); + virtual void OnRestoreViewParams(); void OnRename(); void OnClippingPlanes(); diff --git a/src/VISUGUI/VisuGUI_Module.cxx b/src/VISUGUI/VisuGUI_Module.cxx index 96b52791..93ecda98 100644 --- a/src/VISUGUI/VisuGUI_Module.cxx +++ b/src/VISUGUI/VisuGUI_Module.cxx @@ -63,6 +63,16 @@ #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 +#include + +#include + #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<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(aWindow); + std::string aValue = GetViewParams(aViewWindow); + + SUIT_Study* aSStudy = aViewManager->study(); + SalomeApp_Study* aStudy = dynamic_cast(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); +} diff --git a/src/VISUGUI/VisuGUI_Module.h b/src/VISUGUI/VisuGUI_Module.h index e3610450..7e86eb48 100644 --- a/src/VISUGUI/VisuGUI_Module.h +++ b/src/VISUGUI/VisuGUI_Module.h @@ -142,6 +142,10 @@ protected slots: void OnErasePrs(); + virtual + void + OnSaveViewParams(); + protected: VISU::TViewerMap myViewerMap; diff --git a/src/VVTK/VVTK_MainWindow.cxx b/src/VVTK/VVTK_MainWindow.cxx index 1feda1dd..47e53d04 100644 --- a/src/VVTK/VVTK_MainWindow.cxx +++ b/src/VVTK/VVTK_MainWindow.cxx @@ -257,6 +257,13 @@ VVTK_MainWindow1 return myRenderer; } +VISU_ImplicitFunctionWidget* +VVTK_MainWindow1 +::GetImplicitFunctionWidget() +{ + return myRenderer->GetImplicitFunctionWidget(); +} + //---------------------------------------------------------------------------- QSize VVTK_MainWindow1 diff --git a/src/VVTK/VVTK_MainWindow.h b/src/VVTK/VVTK_MainWindow.h index 5c2f0329..0b6f7995 100644 --- a/src/VVTK/VVTK_MainWindow.h +++ b/src/VVTK/VVTK_MainWindow.h @@ -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; diff --git a/src/VVTK/VVTK_ViewWindow.cxx b/src/VVTK/VVTK_ViewWindow.cxx index d2a1e564..5ba89216 100755 --- a/src/VVTK/VVTK_ViewWindow.cxx +++ b/src/VVTK/VVTK_ViewWindow.cxx @@ -136,6 +136,22 @@ VVTK_ViewWindow {} +//---------------------------------------------------------------------------- +VVTK_MainWindow1* +VVTK_ViewWindow +::getMainWindow1() +{ + return myMainWindow1; +} + +VVTK_MainWindow2* +VVTK_ViewWindow +::getMainWindow2() +{ + return myMainWindow2; +} + + //---------------------------------------------------------------------------- void VVTK_ViewWindow diff --git a/src/VVTK/VVTK_ViewWindow.h b/src/VVTK/VVTK_ViewWindow.h index bbfb50c1..a6ddca69 100755 --- a/src/VVTK/VVTK_ViewWindow.h +++ b/src/VVTK/VVTK_ViewWindow.h @@ -8,10 +8,13 @@ #include "VVTK.h" #include "SVTK_ViewWindow.h" +#include + 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