From 808810c38814cfbb0e7a6951540ed5dc3b16ef8d Mon Sep 17 00:00:00 2001 From: akl Date: Thu, 15 May 2014 12:25:55 +0400 Subject: [PATCH] 1st version of algorithm of collecting dependencies. --- src/GEOMToolsGUI/GEOMToolsGUI.cxx | 141 +++++++++++++++++++++++++++++- src/GEOMToolsGUI/GEOMToolsGUI.h | 14 +++ 2 files changed, 154 insertions(+), 1 deletion(-) diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index daf888e2d..ca6f6d3f2 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -29,7 +29,6 @@ #include #include "GeometryGUI_Operations.h" -#include #include #include @@ -1045,6 +1044,146 @@ void GEOMToolsGUI::deactivate() } } +//======================================================================= +// function : +// purpose : +//======================================================================= +std::string GEOMToolsGUI::getDependencyTree( QStringList rootObjectIORs ) +{ + // fill in the tree structure + DependencyTree tree; + foreach( QString ior, rootObjectIORs ) { + GEOM::GEOM_Object_ptr anObj = GEOMBase::GetObjectFromIOR( ior ); + QList upLevelList; + getUpwardDependency( anObj, upLevelList ); + QList downLevelList; + getDownwardDependency( anObj, downLevelList ); + tree.insert( ior, QPair, QList >( upLevelList, downLevelList ) ); + } + // translation the tree into string + std::string treeStr; + DependencyTree::iterator i; + for ( i = tree.begin(); i != tree.end(); ++i ) { + treeStr.append( i.key().toUtf8().constData() ); + treeStr.append( "-" ); + QList upLevelList = i.value().first; + treeStr.append( "upward" ); + treeStr.append( "{" ); + foreach( NodeLevel level, upLevelList ) { + NodeLevel::iterator upIter; + for ( upIter = level.begin(); upIter != level.end(); ++upIter ) { + treeStr.append( upIter.key().toUtf8().constData() ); + treeStr.append( "_" ); + treeStr.append( QStringList(upIter.value()).join("_").toUtf8().constData() ); + treeStr.append( upIter+1 == level.end() ? ";" : "," ); + } + } + treeStr.append( "}" ); + QList downLevelList = i.value().second; + treeStr.append( "downward" ); + treeStr.append( "{" ); + foreach( NodeLevel level, downLevelList ) { + NodeLevel::iterator downIter; + for ( downIter = level.begin(); downIter != level.end(); ++downIter ) { + treeStr.append( downIter.key().toUtf8().constData() ); + treeStr.append( "_" ); + treeStr.append( QStringList(downIter.value()).join("_").toUtf8().constData() ); + treeStr.append( downIter+1 == level.end() ? ";" : "," ); + } + } + treeStr.append("}"); + } + return treeStr; +} + +//======================================================================= +// function : +// purpose : +//======================================================================= +void GEOMToolsGUI::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo, + QList &upLevelList, + int level ) +{ + QString aGboIOR = GEOMBase::GetIORFromObject(GEOM::GEOM_Object::_narrow(gbo)); + GEOM::ListOfGBO_var depList = gbo->GetDependency(); + for( int j = 0; j < depList->length(); j++ ) { + if ( level > 0 ) { + QStringList anIORs; + NodeLevel aLevelMap; + if ( level-1 >= upLevelList.size() ) { + upLevelList.append( aLevelMap ); + } else { + aLevelMap = upLevelList.at(level-1); + if ( aLevelMap.contains( aGboIOR ) ) + anIORs = aLevelMap.value( aGboIOR ); + } + anIORs << GEOMBase::GetIORFromObject(GEOM::GEOM_Object::_narrow(depList[j])); + aLevelMap.insert( aGboIOR, anIORs ); + } + getUpwardDependency(depList[j], upLevelList, level++); + } +} + +//======================================================================= +// function : +// purpose : +//======================================================================= +void GEOMToolsGUI::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo, + QList &downLevelList, + int level ) +{ + SalomeApp_Application* app = + dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + if ( !app ) + return; + + SalomeApp_Study* appStudy = dynamic_cast( app->activeStudy() ); + if ( !appStudy ) + return; + + _PTR(Study) aStudy = appStudy->studyDS(); + + // get GEOM component + CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() ); + QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR.in() ) ); + + _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() ); + if ( !comp ) + return; + + _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) ); + for ( it->InitEx( true ); it->More(); it->Next() ) { + _PTR(SObject) child( it->Value() ); + CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child ); + GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj ); + if( CORBA::is_nil( geomObj ) ) + continue; + + GEOM::ListOfGBO_var depList = geomObj->GetDependency(); + if( depList->length() == 0 ) + continue; + QString aGoIOR = GEOMBase::GetIORFromObject( geomObj ); + + for( int i = 0; i < depList->length(); i++ ) { + if ( depList[i]->IsSame( gbo ) ) { + QStringList anIORs; + NodeLevel aLevelMap; + if ( level >= downLevelList.size() ) { + aLevelMap = NodeLevel(); + downLevelList.append( aLevelMap ); + } else { + aLevelMap = downLevelList.at(level); + if ( aLevelMap.contains( aGoIOR ) ) + anIORs = aLevelMap.value( aGoIOR ); + } + anIORs << GEOMBase::GetIORFromObject(GEOM::GEOM_Object::_narrow(depList[i])); + aLevelMap.insert( aGoIOR, anIORs ); + } + } + getDownwardDependency(geomObj, downLevelList, level++); + } +} + //===================================================================================== // EXPORTED METHODS //===================================================================================== diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.h b/src/GEOMToolsGUI/GEOMToolsGUI.h index 683fffc7c..4d27b0656 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.h +++ b/src/GEOMToolsGUI/GEOMToolsGUI.h @@ -30,6 +30,7 @@ #include "GEOM_ToolsGUI.hxx" #include +#include #include class GEOM_Displayer; @@ -42,6 +43,11 @@ class Handle_SALOME_InteractiveObject; class Handle_AIS_InteractiveContext; #include +#include +#include + +typedef QMap< QString, QStringList > NodeLevel; +typedef QMap< QString, QPair, QList > > DependencyTree; //================================================================================= // class : GEOMToolsGUI @@ -60,6 +66,14 @@ public: enum ActionType { SHOWDLG, INCR, DECR }; + std::string getDependencyTree( QStringList rootObjectIORs ); + void getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo, + QList &upLevelList, + int level = 0 ); + void getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo, + QList &downLevelList, + int level = 0 ); + private: // Import and export topology methods bool Import();