Add comments, remove outputs and put some things in order.

This commit is contained in:
akl 2014-06-04 15:57:33 +04:00
parent 182e941e7e
commit 633e63eb2e
4 changed files with 53 additions and 104 deletions

View File

@ -5091,17 +5091,13 @@ module GEOM
in long row );
/*!
* \brief Get dependencies of the given object from other objects in study
* \param list of IORs
* \return texture byte array
* Example of using:
* SALOMEDS::TMPFile_var SeqFile =
* myGeometryGUI->GetGeomGen()->GetDependencyTree( aStudy, aListOfIORs );
* char* buf;
* buf = (char*) &SeqFile[0];
* \brief Collects dependencies of the given objects from other ones
* \param theStudy The study in which the object is published
* \param theListOfEntries List of GEOM object entries in OCAF tree (not in study)
* \return Struct of dependent entries and its links as a byte array
*/
SALOMEDS::TMPFile GetDependencyTree(in SALOMEDS::Study theStudy,
in string_array strValues);
in string_array theListOfEntries);
};
};

View File

@ -1022,7 +1022,6 @@ LevelsList parseWard( const std::string& theData, std::size_t& theCursor )
}
LevelsList levelsListData;
for( int level = 0; level < levelsListStr.size(); level++ ) {
std::cout<<" Level" << level + 1 << ":" << std::endl;
std::vector<std::string> namesListStr;
std::stringstream ss1( levelsListStr[level] );
while ( std::getline( ss1, substr, ',' ) ) {
@ -1040,14 +1039,11 @@ LevelsList parseWard( const std::string& theData, std::size_t& theCursor )
std::string nodeItem = linksListStr[0];
if( !nodeItem.empty() ) {
NodeLinks linksListData;
std::cout<<" " << nodeItem << " - ";
for( int link = 1; link < linksListStr.size(); link++ ) {
std::string linkItem = linksListStr[link];
linksListData.push_back( linkItem );
std::cout << linkItem << ", ";
}// Links
levelInfoData[nodeItem] = linksListData;
std::cout << std::endl;
}
}// Level's objects
levelsListData.push_back(levelInfoData);
@ -1070,15 +1066,12 @@ void ConvertStringToTree( const std::string &theData,
{
std::size_t objectIndex = theData.find( '-', cursor );
std::string objectEntry = theData.substr( cursor, objectIndex - cursor );
std::cout<<"\n\nMainObject = " << objectEntry <<std::endl;
cursor = objectIndex;
std::size_t upwardIndexBegin = theData.find("{",cursor) + 1;
std::size_t upwardIndexFinish = theData.find("}",upwardIndexBegin);
std::cout<<" Upward:" << std::endl ;
LevelsList upwardList = parseWard( theData, cursor );
std::cout<<" Downward:" << std::endl;
LevelsList downwardList = parseWard( theData, cursor );
tree[objectEntry] = std::pair<LevelsList,LevelsList>( upwardList, downwardList );

View File

@ -3042,32 +3042,35 @@ Engines::ListOfData* GEOM_Gen_i::getModifiedData(CORBA::Long studyId)
}
//=======================================================================
// function :
// purpose :
// function : GetDependencyTree
// purpose : Collects dependencies of the given objects from other ones
//=======================================================================
SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( SALOMEDS::Study_ptr theStudy,
const GEOM::string_array& theObjectIORs ) {
const GEOM::string_array& theObjectEntries ) {
// fill in the tree structure
GEOMUtils::TreeModel tree;
// foreach( QString ior, theObjectIORs ) {
std::string ior;
for ( int i = 0; i < theObjectIORs.length(); i++ ) {
ior = theObjectIORs[i].in();
GEOM::GEOM_BaseObject_var anObj = GetObject( theStudy->StudyId(), ior.c_str() );
std::string entry;
for ( int i = 0; i < theObjectEntries.length(); i++ ) {
// process objects one-by-one
entry = theObjectEntries[i].in();
GEOM::GEOM_BaseObject_var anObj = GetObject( theStudy->StudyId(), entry.c_str() );
if ( anObj->_is_nil() )
continue;
GEOMUtils::LevelsList upLevelList;
// get objects from which current one depends on recursively
getUpwardDependency( anObj, upLevelList );
GEOMUtils::LevelsList downLevelList;
getDownwardDependency( theStudy, anObj, downLevelList );
tree.insert( std::pair<std::string, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList> >(ior, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList>( upLevelList, downLevelList ) ) );
// get objects that depends on current one recursively
getDownwardDependency( anObj, downLevelList );
tree.insert( std::pair<std::string, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList> >(entry, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList>( upLevelList, downLevelList ) ) );
}
// translation the tree into string
std::string treeStr;
GEOMUtils::ConvertTreeToString( tree, treeStr );
// put string into stream
char* aBuffer = (char*)CORBA::string_dup(treeStr.c_str());
int aBufferSize = strlen((char*)aBuffer);
@ -3075,98 +3078,73 @@ SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( SALOMEDS::Study_ptr theStudy,
SALOMEDS::TMPFile_var aStream = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
//std::cout << "AKL: end of get" << endl;
return aStream._retn();
}
//=======================================================================
// function :
// purpose :
// function : getUpwardDependency
// purpose : Collects the entries of objects on that the given one depends
//=======================================================================
void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
GEOMUtils::LevelsList &upLevelList,
int level ) {
std::string aGboIOR = gbo->GetEntry();
std::string aGboEntry = gbo->GetEntry();
for (int i=0; i < upLevelList.size(); i++ ) {
GEOMUtils::LevelInfo aMap = upLevelList.at(i);
if ( aMap.count( aGboIOR ) > 0 )
if ( aMap.count( aGboEntry ) > 0 )
// this object has been processed earlier
return;
}
//std::cout << "\n\nAKL: upnode IOR: " << aGboIOR << endl;
//std::cout << "AKL: level: " << level << endl;
GEOMUtils::NodeLinks anIORs;
GEOMUtils::NodeLinks anEntries;
GEOMUtils::LevelInfo aLevelMap;
if ( level > 0 ) {
if ( level-1 >= upLevelList.size() ) {
// create a new map
upLevelList.push_back( aLevelMap );
//std::cout << "AKL: new map" << endl;
} else {
// get the existent map
aLevelMap = upLevelList.at(level-1);
if ( aLevelMap.count( aGboIOR ) > 0 ) {
anIORs = aLevelMap[ aGboIOR ];
//std::cout << "AKL: get already added iors list: " << endl;
if ( aLevelMap.count( aGboEntry ) > 0 ) {
anEntries = aLevelMap[ aGboEntry ];
}
}
}
// get objects on that the current one depends
GEOM::ListOfGBO_var depList = gbo->GetDependency();
for( int j = 0; j < depList->length(); j++ ) {
if ( depList[j]->_is_nil() )
continue;
if ( level > 0 ) {
anIORs.push_back( depList[j]->GetEntry() );
//std::cout << "AKL: add link ior: " << depList[j]->GetEntry() << endl;
anEntries.push_back( depList[j]->GetEntry() );
}
//std::cout << "AKL: <<<<<<<< start next step: " << endl;
//if ( !depList[j]->IsSame( gbo ) ) {
if ( !depList[j]->_is_equivalent( gbo ) ) {
// get dependencies recursively
if ( !depList[j]->_is_equivalent( gbo ) ) { // avoid self-recursion
getUpwardDependency(depList[j], upLevelList, level+1);
}
//std::cout << "AKL: end next step >>>>>>>> : " << endl;
}
if ( level > 0 ) {
//std::cout << "AKL: insert links for node: " << aGboIOR << endl;
aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGboIOR, anIORs) );
//std::cout << "AKL: insert level map: " << endl;
aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGboEntry, anEntries) );
upLevelList[level-1] = aLevelMap;
}
}
//=======================================================================
// function :
// purpose :
// function : getDownwardDependency
// purpose : Collects the entries of objects that depends on the given one
//=======================================================================
void GEOM_Gen_i::getDownwardDependency( SALOMEDS::Study_ptr theStudy,
GEOM::GEOM_BaseObject_ptr gbo,
void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
GEOMUtils::LevelsList &downLevelList,
int level ) {
SALOMEDS::SComponent_var comp = theStudy->FindComponent("GEOM");
if ( !comp )
return;
std::string aGboIOR = gbo->GetEntry();
//cout << "for " << aGboIOR << " at level " << level << endl;
/*if ( level > 0 ) {
if ( level >= downLevelList.size() ) {
downLevelList.push_back( aLevelMap );
//std::cout << "AKL: new map" << endl;
} else {
aLevelMap = downLevelList.at(level);
if ( aLevelMap.count( aGboIOR ) > 0 ) {
anIORs = aLevelMap[ aGboIOR ];
//std::cout << "AKL: get already added iors list: " << endl;
}
}
}*/
Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument(gbo->GetStudyID());
Handle(TDataStd_TreeNode) aNode, aRoot;
Handle(GEOM_Function) aFunction;
if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
// go through the whole OCAF tree
TDataStd_ChildNodeIterator Itr( aRoot );
for (; Itr.More(); Itr.Next()) {
aNode = Itr.Value();
aFunction = GEOM_Function::GetFunction(aNode->Label());
if (aFunction.IsNull()) {
//MESSAGE ( "Null function !!!!" );
continue;
}
TDF_Label aLabel = aFunction->GetOwnerEntry();
@ -3174,59 +3152,41 @@ void GEOM_Gen_i::getDownwardDependency( SALOMEDS::Study_ptr theStudy,
TCollection_AsciiString anEntry;
TDF_Tool::Entry(aLabel, anEntry);
GEOM::GEOM_BaseObject_var geomObj = GetObject( gbo->GetStudyID(), anEntry.ToCString() );
/*
SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator( comp );
for ( it->InitEx( true ); it->More(); it->Next() ) {
SALOMEDS::SObject_var child = it->Value();
CORBA::Object_var corbaObj = child->GetObject();
GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
*/
if( CORBA::is_nil( geomObj ) )
continue;
// get dependencies for current object in the tree
GEOM::ListOfGBO_var depList = geomObj->GetDependency();
if( depList->length() == 0 )
continue;
std::string aGoIOR = geomObj->GetEntry();
//cout << "check " << aGoIOR << endl;
std::string aGoEntry = geomObj->GetEntry();
// go through dependencies of current object to check whether it depends on the given object
for( int i = 0; i < depList->length(); i++ ) {
if ( depList[i]->_is_nil() )
continue;
//cout << "depends on " << depList[i]->GetEntry() << endl;
//if ( depList[i]->IsSame( gbo ) ) {
if ( depList[i]->_is_equivalent( gbo ) ) {
//cout << " the same! " << endl;
//if ( level > 0 ) {
GEOMUtils::NodeLinks anIORs;
// yes, the current object depends on the given object
GEOMUtils::NodeLinks anEntries;
GEOMUtils::LevelInfo aLevelMap;
anIORs.push_back( gbo->GetEntry());
anEntries.push_back( gbo->GetEntry());
if ( level >= downLevelList.size() ) {
downLevelList.push_back( aLevelMap );
//std::cout << "AKL: new map" << endl;
} else {
aLevelMap = downLevelList.at(level);
if ( aLevelMap.count( aGoIOR ) > 0 ) {
anIORs = aLevelMap[ aGoIOR ];
//std::cout << "AKL: get already added iors list: " << endl;
if ( aLevelMap.count( aGoEntry ) > 0 ) {
anEntries = aLevelMap[ aGoEntry ];
}
}
aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGoIOR, anIORs) );
aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGoEntry, anEntries) );
downLevelList[level] = aLevelMap;
//}
//if ( !depList[i]->IsSame( geomObj ) ) {
if ( !depList[i]->_is_equivalent( geomObj ) ) {
//cout << " go on! " << endl;
getDownwardDependency(theStudy, geomObj, downLevelList, level+1);
// get dependencies of the current object recursively
if ( !depList[i]->_is_equivalent( geomObj ) ) { // avoid self-recursion
getDownwardDependency(geomObj, downLevelList, level+1);
}
break;
}
}
}
}
/*if ( level > 0 ) {
aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGboIOR, anIORs) );
downLevelList[level-1] = aLevelMap;
}*/
}
//=====================================================================================

View File

@ -199,8 +199,9 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi
CORBA::Boolean theInheritFirstArg,
CORBA::Boolean theAddPrefix);
//Collects dependencies of the given objects from other ones
SALOMEDS::TMPFile* GetDependencyTree(SALOMEDS::Study_ptr theStudy,
const GEOM::string_array& theObjectIORs);
const GEOM::string_array& theObjectEntries);
//-----------------------------------------------------------------------//
// Transaction methods //
@ -375,8 +376,7 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi
GEOMUtils::LevelsList &upLevelList,
int level = 0 );
void getDownwardDependency( SALOMEDS::Study_ptr theStudy,
GEOM::GEOM_BaseObject_ptr gbo,
void getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
GEOMUtils::LevelsList &downLevelList,
int level = 0 );