From: asv Date: Mon, 13 Feb 2006 14:51:58 +0000 (+0000) Subject: implementing save/restore visual parameters.. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=68003668a37f07e679cd79df84ef68abbf47306f;p=modules%2Fvisu.git implementing save/restore visual parameters.. --- diff --git a/src/VISUGUI/VisuGUI_Module.cxx b/src/VISUGUI/VisuGUI_Module.cxx index aab64028..fa14f5fd 100644 --- a/src/VISUGUI/VisuGUI_Module.cxx +++ b/src/VISUGUI/VisuGUI_Module.cxx @@ -1675,9 +1675,10 @@ const char gSeparator = '_'; // character used to separate parameter names void VisuGUI_Module::storeVisualParameters(int savePoint) { SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if( !study ) + if( !study || !study->studyDS() ) return; - _PTR(AttributeParameter) ap = study->studyDS()->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint); + _PTR(Study) studyDS = study->studyDS(); + _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint); SALOMEDS_IParameters ip(ap); QPtrList lst; @@ -1701,32 +1702,42 @@ void VisuGUI_Module::storeVisualParameters(int savePoint) allActors->InitTraversal(); while ( vtkActor* actor = allActors->GetNextActor() ) { if ( actor->GetVisibility() ) { // store only visible actors - if ( SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor ) ) { - if ( salomeActor->hasIO() ) { // actor corresponds to existing obj + 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 = salomeActor->getIO(); - const char* entry = io->getEntry(); - const char* aName = salomeActor->getName(); - int repMode = salomeActor->GetRepresentation(); - float opacity = salomeActor->GetOpacity(); - float r, g, b; - salomeActor->GetColor(r, g, b); - QString colorStr = QString::number( r ); colorStr += ","; - colorStr += QString::number( g ); colorStr += ","; - colorStr += QString::number( b ); + 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; param = vtkParam + "Visibility"; ip.setParameter( entry, param.latin1(), "true" ); param = vtkParam + "Name"; - ip.setParameter( entry, param.latin1(), aName ); + ip.setParameter( entry, param.latin1(), vActor->getName() ); param = vtkParam + "RepresentationMode"; - ip.setParameter( entry, param.latin1(), QString::number( repMode ).latin1() ); + ip.setParameter( entry, param.latin1(), QString::number( vActor->GetRepresentation() ).latin1() ); param = vtkParam + "Opacity"; - ip.setParameter( entry, param.latin1(), QString::number( opacity ).latin1() ); + ip.setParameter( entry, param.latin1(), 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 += ","; + colorStr += QString::number( b ); param = vtkParam + "Color"; ip.setParameter( entry, param.latin1(), 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() ); } // hasIO } // salome_actor successfull downcast @@ -1739,18 +1750,18 @@ void VisuGUI_Module::storeVisualParameters(int savePoint) } } -// returns SALOME_Actor with IO with given entry -SALOME_Actor* getActor( std::string entry, SVTK_ViewWindow* vtkView ) +// returns VISU_Actor with IO with given entry +VISU_Actor* getActor( const QString& entry, SVTK_ViewWindow* vtkView ) { - if ( vtkView && !entry.empty() ) { + if ( vtkView && !entry.isEmpty() ) { vtkActorCollection* allActors = vtkView->getRenderer()->GetActors(); allActors->InitTraversal(); while ( vtkActor* actor = allActors->GetNextActor() ) { - if ( SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor ) ) { - if ( salomeActor->hasIO() ) { // actor corresponds to existing obj - Handle(SALOME_InteractiveObject) io = salomeActor->getIO(); + if ( VISU_Actor* vActor = VISU_Actor::SafeDownCast( actor ) ) { + if ( vActor->hasIO() ) { // actor corresponds to existing obj + Handle(SALOME_InteractiveObject) io = vActor->getIO(); if ( entry == io->getEntry() ) - return salomeActor; + return vActor; } } } @@ -1784,18 +1795,19 @@ std::string getParam( const std::string& paramName, const int index ) void VisuGUI_Module::restoreVisualParameters(int savePoint) { SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if( !study ) + if( !study || !study->studyDS() ) return; - _PTR(AttributeParameter) ap = study->studyDS()->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint); + _PTR(Study) studyDS = study->studyDS(); + _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint); SALOMEDS_IParameters ip(ap); // actors are stored in a map after displaying of them for quicker access in future - QMap > vtkActors; // map: entry to map: view_id to actor + QMap > vtkActors; // map: entry to map: view_id to actor std::vector entries = ip.getEntries(); for ( std::vector::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt ) { - QString entry( (*entIt).c_str() ); + QString entry( ip.decodeEntry( *entIt ).c_str() ); std::vector paramNames = ip.getAllParameterNames( *entIt ); std::vector paramValues = ip.getAllParameterValues( *entIt ); std::vector::iterator namesIt = paramNames.begin(); @@ -1831,39 +1843,51 @@ void VisuGUI_Module::restoreVisualParameters(int savePoint) // vtkView->Repaint(); // store displayed actor so setting of color, opacity, etc. will be much faster - QMap viewActorMap; + QMap viewActorMap; if ( vtkActors.contains( entry ) ) viewActorMap = vtkActors[ entry ]; - viewActorMap[ viewIndex ] = getActor( *entIt, vtkView ); + viewActorMap[ viewIndex ] = getActor( entry, vtkView ); vtkActors[ entry ] = viewActorMap; } } - else { // the rest properties "work" with SALOME_Actor, so we initialize it at first - SALOME_Actor* actor = 0; + else { // the rest properties "work" with VISU_Actor, so we initialize it at first + VISU_Actor* vActor = 0; if ( vtkActors.contains( entry ) ) { - QMap viewActorMap = vtkActors[ entry ]; + QMap viewActorMap = vtkActors[ entry ]; if ( viewActorMap.contains( viewIndex ) ) - actor = viewActorMap[ viewIndex ]; + vActor = viewActorMap[ viewIndex ]; } - if ( !actor ) + if ( !vActor ) continue; QString val( (*valuesIt).c_str() ); if ( paramName == "Name" ) - actor->setName( val.latin1() ); + vActor->setName( val.latin1() ); else if ( paramName == "RepresentationMode" ) - actor->SetRepresentation( val.toInt() ); + vActor->SetRepresentation( val.toInt() ); else if ( paramName == "Opacity" ) - actor->SetOpacity( val.toFloat() ); + vActor->SetOpacity( val.toFloat() ); else if ( paramName == "Color" ) { QStringList colors = QStringList::split( ',', val ); if ( colors.count() == 3 ) - actor->SetColor( colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat() ); + vActor->SetColor( colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat() ); } + + else if ( paramName == "LineWidth" ) + vActor->SetLineWidth( val.toFloat() ); + + else if ( paramName == "IsShrunk" ) { + vActor->SetShrinkable( true ); + vActor->SetShrink(); + } + + else if ( paramName == "ShrunkFactor" ) + vActor->SetShrinkFactor( val.toFloat() ); + } // else .. } // if SVTK