From d1aec71c17291f5d4ff08eb53fd4737cf9872ae6 Mon Sep 17 00:00:00 2001 From: asv Date: Tue, 14 Feb 2006 12:22:53 +0000 Subject: [PATCH] implementing save/restore visual parameters.. --- src/VISUGUI/VisuGUI_Module.cxx | 168 ++++++++++++++++++++++++++------- 1 file changed, 136 insertions(+), 32 deletions(-) diff --git a/src/VISUGUI/VisuGUI_Module.cxx b/src/VISUGUI/VisuGUI_Module.cxx index fa14f5fd..0c998c8e 100644 --- a/src/VISUGUI/VisuGUI_Module.cxx +++ b/src/VISUGUI/VisuGUI_Module.cxx @@ -55,6 +55,9 @@ #include "SVTK_RenderWindowInteractor.h" #include "VISU_Event.h" +#include "Plot2d_ViewWindow.h" +#include "Plot2d_ViewFrame.h" + #include "VisuGUI_Prs3dTools.h" #include "VISU_GaussPoints_i.hh" @@ -66,6 +69,7 @@ #include "VISU_CutLines_i.hh" #include "VISU_Actor.h" +#include "VISU_ScalarMapAct.h" #include "VisuGUI_Tools.h" #include "VisuGUI_ActionsDef.h" @@ -84,6 +88,7 @@ #include #include #include +#include #include @@ -686,7 +691,7 @@ VisuGUI_Module setPreferenceProperty( pyramidHeightPref, "min", 1 ); setPreferenceProperty( pyramidHeightPref, "max", 100 ); - int selectionColorPref = addPreference( tr( "VISU_PICKING_PREF_SELECTION_COLOR" ), cursorGr, + /*int selectionColorPref = */addPreference( tr( "VISU_PICKING_PREF_SELECTION_COLOR" ), cursorGr, LightApp_Preferences::Color, "VISU", "picking_selection_color" ); // Tolerance @@ -1666,6 +1671,7 @@ eventFilter( QObject * theWatched, QEvent * theEvent ) } const char gSeparator = '_'; // character used to separate parameter names +const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b) /*! * \brief Virtual public * @@ -1681,9 +1687,16 @@ void VisuGUI_Module::storeVisualParameters(int savePoint) _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint); SALOMEDS_IParameters ip(ap); + // viewers counters are used for storing view_numbers in IParameters + int vtkViewers( 0 ), plotViewers( 0 ); + + // componentName is used for encoding of entries when storing them in IParameters + _PTR(SComponent) visuEng = ClientFindOrCreateVisuComponent( studyDS ); + std::string componentName = visuEng->ComponentDataType(); + + // iterating view managers and its views QPtrList lst; getApp()->viewManagers( lst ); - int vtkViewers( 0 ); for ( QPtrListIterator it( lst ); it.current(); ++it ) { SUIT_ViewManager* vman = it.current(); SUIT_ViewModel* vmodel = vman->getViewModel(); @@ -1696,48 +1709,67 @@ void VisuGUI_Module::storeVisualParameters(int savePoint) // inherits SVTK_ViewWindow) QPtrVector views = vman->getViews(); for ( int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++ ) { - SVTK_ViewWindow* vtkView = dynamic_cast( views[i] ); - if ( vtkView ) { + if ( SVTK_ViewWindow* vtkView = dynamic_cast( views[i] ) ) { vtkActorCollection* allActors = vtkView->getRenderer()->GetActors(); allActors->InitTraversal(); while ( vtkActor* actor = allActors->GetNextActor() ) { if ( actor->GetVisibility() ) { // store only visible actors if ( VISU_Actor* vActor = VISU_Actor::SafeDownCast( actor ) ) { if ( vActor->hasIO() ) { // actor corresponds to existing obj - - _PTR(SComponent) visuEng = ClientFindOrCreateVisuComponent( studyDS ); - std::string componentName = visuEng->ComponentDataType(); Handle(SALOME_InteractiveObject) io = vActor->getIO(); // entry is "ecoded" = it does NOT contain component adress, since it is a // subject to change on next component loading std::string entry = ip.encodeEntry( io->getEntry(), componentName ); - QString param, vtkParam = vmodel->getType(); vtkParam += gSeparator; - vtkParam += QString::number( vtkViewers ); vtkParam += gSeparator; + std::string param, vtkParam = vmodel->getType().latin1(); vtkParam += gSeparator; + vtkParam += QString::number( vtkViewers ).latin1(); vtkParam += gSeparator; param = vtkParam + "Visibility"; - ip.setParameter( entry, param.latin1(), "true" ); + ip.setParameter( entry, param, "On" ); param = vtkParam + "Name"; - ip.setParameter( entry, param.latin1(), vActor->getName() ); + ip.setParameter( entry, param, vActor->getName() ); param = vtkParam + "RepresentationMode"; - ip.setParameter( entry, param.latin1(), QString::number( vActor->GetRepresentation() ).latin1() ); + ip.setParameter( entry, param, QString::number( vActor->GetRepresentation() ).latin1() ); param = vtkParam + "Opacity"; - ip.setParameter( entry, param.latin1(), QString::number( vActor->GetOpacity() ).latin1() ); + ip.setParameter( entry, param, QString::number( vActor->GetOpacity() ).latin1() ); float r, g, b; vActor->GetColor(r, g, b); - QString colorStr = QString::number( r ); colorStr += ","; - colorStr += QString::number( g ); colorStr += ","; + QString colorStr = QString::number( r ); colorStr += gDigitsSep; + colorStr += QString::number( g ); colorStr += gDigitsSep; colorStr += QString::number( b ); param = vtkParam + "Color"; - ip.setParameter( entry, param.latin1(), colorStr.latin1() ); + ip.setParameter( entry, param, colorStr.latin1() ); param = vtkParam + "LineWidth"; - ip.setParameter( entry, param.latin1(), QString::number( vActor->GetLineWidth() ).latin1() ); - bool shrunk = vActor->IsShrunkable() && vActor->IsShrunk(); - param = vtkParam + "IsShrunk"; - ip.setParameter( entry, param.latin1(), QString::number( shrunk ).latin1() ); - param = vtkParam + "ShrinkFactor"; - ip.setParameter( entry, param.latin1(), QString::number( vActor->GetShrinkFactor() ).latin1() ); + ip.setParameter( entry, param, QString::number( vActor->GetLineWidth() ).latin1() ); + if ( vActor->IsShrunkable() && vActor->IsShrunk() ) { + param = vtkParam + "ShrinkMode"; + ip.setParameter( entry, param, "On" ); + param = vtkParam + "ShrinkFactor"; + ip.setParameter( entry, param, QString::number( vActor->GetShrinkFactor() ).latin1() ); + } + VISU_ScalarMapAct* scalarMapActor = dynamic_cast( vActor ); + if ( scalarMapActor && scalarMapActor->IsShading() ) { + param = vtkParam + "Shading"; + ip.setParameter( entry, param, "On" ); + } + if ( const VISU::Prs3d_i* vPrs = vActor->GetPrs3d() ) { + param = vtkParam + "ClippingPlane_"; + for ( int p = 0, nPlanes = vPrs->GetNumberOfClippingPlanes(); p < nPlanes; p++ ) { + vtkPlane* plane = vPrs->GetClippingPlane( p ); + float normal[3], origin[3]; + plane->GetNormal( normal ); + plane->GetOrigin( origin ); + std::string planeValue = QString::number( normal[0] ).latin1(); planeValue += gDigitsSep; + planeValue += QString::number( normal[1] ).latin1(); planeValue += gDigitsSep; + planeValue += QString::number( normal[2] ).latin1(); planeValue += gDigitsSep; + planeValue += QString::number( origin[0] ).latin1(); planeValue += gDigitsSep; + planeValue += QString::number( origin[1] ).latin1(); planeValue += gDigitsSep; + planeValue += QString::number( origin[2] ).latin1(); + param += QString::number( p+1 ).latin1(); + ip.setParameter( entry, param, planeValue ); + } + } } // hasIO } // salome_actor successfull downcast @@ -1747,6 +1779,36 @@ void VisuGUI_Module::storeVisualParameters(int savePoint) } // for ( views ) vtkViewers++; } // if ( SVTK view model ) + else if ( vmodel->getType() == SPlot2d_Viewer::Type() ) { // processing Plot2d viewers + QPtrVector views = vman->getViews(); + for ( int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++ ) { + if ( Plot2d_ViewWindow* plotView = dynamic_cast( views[i] ) ) { + Plot2d_ViewFrame* plotVF = plotView->getViewFrame(); + QPtrList curves; + plotVF->getCurves( curves ); + + Plot2d_Curve* curve; + for ( curve = curves.first(); curve; curve = curves.next() ) { + if ( SPlot2d_Curve* sCurve = dynamic_cast( curve ) ) { + if ( sCurve->hasIO() ) { + + Handle(SALOME_InteractiveObject) io = sCurve->getIO(); + // entry is "ecoded" = it does NOT contain component adress, since it is a + // subject to change on next component loading + std::string entry = ip.encodeEntry( io->getEntry(), componentName ); + + std::string param, plotParam = vmodel->getType().latin1(); plotParam += gSeparator; + plotParam += QString::number( plotViewers ).latin1(); plotParam += gSeparator; + + param = plotParam + "Visibility"; + ip.setParameter( entry, param, "On" ); + } + } + } // for curves + } // if ( plotView ) + } // for ( views ) + plotViewers++; + } // if ( SPlot2d view model ) } } @@ -1816,17 +1878,17 @@ void VisuGUI_Module::restoreVisualParameters(int savePoint) for ( ; namesIt != paramNames.end(); ++namesIt, ++valuesIt ) { std::string viewerType = ::getParam( *namesIt, ViewerType ); + std::string paramName = ::getParam( *namesIt, ParamName ); + bool ok; + std::string viewIndexStr = ::getParam( *namesIt, ViewIndex ); + int viewIndex = QString( viewIndexStr.c_str() ).toUInt( &ok ); + if ( !ok ) // bad conversion of view index to integer + continue; + if ( viewerType == SVTK_Viewer::Type().latin1() || viewerType == VVTK_Viewer::Type().latin1() ) { - std::string paramName = ::getParam( *namesIt, ParamName ); - bool ok; - std::string viewIndexStr = ::getParam( *namesIt, ViewIndex ); - int viewIndex = QString( viewIndexStr.c_str() ).toUInt( &ok ); - if ( !ok ) // bad conversion of view index to integer - continue; - - //cout << "--SVTK parameter: entry = " << *entIt << ", paramName = " << paramName << endl; + //cout << "--SVTK parameter: entry = " << entry.latin1() << ", paramName = " << paramName << endl; if ( paramName == "Visibility" && displayer() ) { QPtrList lst; @@ -1872,7 +1934,7 @@ void VisuGUI_Module::restoreVisualParameters(int savePoint) vActor->SetOpacity( val.toFloat() ); else if ( paramName == "Color" ) { - QStringList colors = QStringList::split( ',', val ); + QStringList colors = QStringList::split( gDigitsSep, val ); if ( colors.count() == 3 ) vActor->SetColor( colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat() ); } @@ -1880,7 +1942,7 @@ void VisuGUI_Module::restoreVisualParameters(int savePoint) else if ( paramName == "LineWidth" ) vActor->SetLineWidth( val.toFloat() ); - else if ( paramName == "IsShrunk" ) { + else if ( paramName == "ShrinkMode" ) { vActor->SetShrinkable( true ); vActor->SetShrink(); } @@ -1888,9 +1950,47 @@ void VisuGUI_Module::restoreVisualParameters(int savePoint) else if ( paramName == "ShrunkFactor" ) vActor->SetShrinkFactor( val.toFloat() ); + else if ( paramName == "Shading" ) { + if ( VISU_ScalarMapAct* scalarMapActor = dynamic_cast( vActor ) ) + scalarMapActor->SetShading(); + } + + else if ( paramName.find( "ClippingPlane" ) != std::string::npos ) { + QStringList vals = QStringList::split( gDigitsSep, val ); + if ( vals.count() == 6 && vActor->GetPrs3d() ) { + float normal[3], origin[3]; + for (int x = 0; x < 3; x++ ) { + normal[x] = vals[x].toFloat(); + origin[x] = vals[x+3].toFloat(); + } + vtkPlane* plane = vtkPlane::New(); + plane->SetNormal( normal ); + plane->SetOrigin( origin ); + vActor->GetPrs3d()->AddClippingPlane( plane ); + } + } + } // else .. } // if SVTK + else if ( viewerType == SPlot2d_Viewer::Type().latin1() ) { + + //cout << "--Plot2d parameter: entry = " << entry.latin1() << ", paramName = " << paramName << endl; + + if ( paramName == "Visibility" && displayer() ) { + QPtrList lst; + getApp()->viewManagers( viewerType, lst ); + + if ( viewIndex >= 0 && viewIndex < lst.count() ) { + SUIT_ViewManager* vman = lst.at( viewIndex ); + SUIT_ViewModel* vmodel = vman->getViewModel(); + // SVTK and VVTK view models can be casted to SALOME_View + displayer()->Display( entry, true, dynamic_cast( vmodel ) ); + } + } + + } // if SPlot2d + } // for names/parameters iterator } // for entries iterator @@ -1908,6 +2008,10 @@ void VisuGUI_Module::restoreVisualParameters(int savePoint) vtkView->getRenderer()->ResetCameraClippingRange(); vtkView->Repaint(); } + else if ( vmodel->getType() == SPlot2d_Viewer::Type().latin1() ) { + Plot2d_ViewWindow* plotView = (Plot2d_ViewWindow*) vman->getActiveView(); + plotView->getViewFrame()->Repaint(); + } } // ] end of update views } -- 2.39.2