From b70248e90ba88d89753f75b3c773c172715e8418 Mon Sep 17 00:00:00 2001 From: akl Date: Thu, 19 Jun 2014 18:59:59 +0400 Subject: [PATCH] Implementation of 'GetEntriesToCleanStudy' function to get categorized lists of objects. --- idl/GEOM_Gen.idl | 18 +++++ src/GEOM_I/GEOM_Gen_i.cc | 168 ++++++++++++++++++++++++++++++++++++++- src/GEOM_I/GEOM_Gen_i.hh | 15 ++++ 3 files changed, 200 insertions(+), 1 deletion(-) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 8f75248b5..a0f2020de 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -5100,6 +5100,24 @@ module GEOM SALOMEDS::TMPFile GetDependencyTree(in SALOMEDS::Study theStudy, in string_array theListOfEntries); + /*! + * \brief Fills 3 lists that is used to clean study of redundant objects: + * - dependencies of the given objects from other ones; + * - children of the given objects; + * - all other objects in study. + * \param theStudy The study in which the object was published + * \param theSelectedEntries List of GEOM object entries in OCAF tree + * \param theParentEntries List of GEOM object entries on which the given objects depend + * \param theSubEntries Children entries list of the given objects + * \param theOtherEntries List of GEOM object entries which are in the study, but not in parents and children lists + * \note This method is supposed to be used by GUI only. + */ + void GetEntriesToCleanStudy(in SALOMEDS::Study theStudy, + inout string_array theSelectedEntries, + inout string_array theParentEntries, + inout string_array theSubEntries, + inout string_array theOtherEntries); + }; }; diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index b052e5d24..8f3a876ad 100755 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -36,7 +36,6 @@ #include "Utils_ExceptHandlers.hxx" #include "utilities.h" -#include "GEOM_Object_i.hh" #include "GEOM_Object.hxx" #include "GEOM_Function.hxx" #include "GEOM_ISubShape.hxx" @@ -62,6 +61,7 @@ #include #include #include +#include #include #include @@ -3197,6 +3197,172 @@ void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo, } } +//============================================================================== +// function : GetEntriesToCleanStudy +// purpose : Fills 3 lists that is used to clean study of redundant objects +//============================================================================== +void GEOM_Gen_i::GetEntriesToCleanStudy(SALOMEDS::Study_ptr theStudy, + GEOM::string_array& theSelectedEntries, + GEOM::string_array& theParentEntries, + GEOM::string_array& theSubEntries, + GEOM::string_array& theOtherEntries) +{ + std::set aSelected, aParents, aChildren, anOthers; + for ( int i = 0; i < theSelectedEntries.length(); i++ ) { + aSelected.insert( CORBA::string_dup( theSelectedEntries[i] ) ); + } + + Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument(theStudy->StudyId()); + Handle(TDataStd_TreeNode) aNode, aRoot; + Handle(GEOM_Function) aFunction; + if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) { + // go through the whole OCAF tree + TDF_Label aLabel; + std::string anEntry; + TCollection_AsciiString anAsciiEntry; + TDataStd_ChildNodeIterator Itr( aRoot ); + for (; Itr.More(); Itr.Next()) { + aNode = Itr.Value(); + aFunction = GEOM_Function::GetFunction(aNode->Label()); + if (aFunction.IsNull()) { + continue; + } + aLabel = aFunction->GetOwnerEntry(); + if(aLabel.IsNull()) + continue; + TDF_Tool::Entry(aLabel, anAsciiEntry); + anEntry = anAsciiEntry.ToCString(); + GEOM::GEOM_BaseObject_var geomObj = GetObject( theStudy->StudyId(), anEntry.c_str() ); + if( CORBA::is_nil( geomObj ) ) + continue; + + if ( aSelected.count( anEntry ) > 0 && + aParents.count( anEntry ) == 0 ) { + getParentDependencies( geomObj, aSelected, aParents, aChildren, anOthers ); + } else if ( aParents.count( anEntry ) == 0 && + aChildren.count( anEntry ) == 0 ) { + anOthers.insert( geomObj->GetEntry() ); + } + } + + std::set::iterator it; + std::set::iterator foundIt; + TCollection_AsciiString stringIOR; + GEOM::GEOM_Object_var geomObj; + + // filling list of sub-objects + for ( it = aSelected.begin(); it != aSelected.end(); ++it ) { + Handle(GEOM_BaseObject) handle_object = _impl->GetObject( theStudy->StudyId(), (*it).c_str(), false); + if ( handle_object.IsNull() ) + continue; + + Handle(GEOM_Function) aShapeFun = handle_object->GetFunction(1); + if ( aShapeFun.IsNull() || !aShapeFun->HasSubShapeReferences() ) + continue; + + const TDataStd_ListOfExtendedString& aListEntries = aShapeFun->GetSubShapeReferences(); + if ( aListEntries.IsEmpty() ) + continue; + + TDataStd_ListIteratorOfListOfExtendedString anIt (aListEntries); + for ( ; anIt.More(); anIt.Next() ) { + TCollection_ExtendedString aSubEntry = anIt.Value(); + Standard_Integer aStrLen = aSubEntry.LengthOfCString(); + char* aSubEntryStr = new char[aStrLen+1]; + aSubEntry.ToUTF8CString( aSubEntryStr ); + foundIt = aParents.find( aSubEntryStr ); + if ( foundIt == aParents.end() ) // add to sub-objects if it is not in parents list + aChildren.insert( aSubEntryStr ); + } + } + + // if some selected object is not a main shape, + // we move it's main shapes into 'selected' list, + // because they could not be modified anyhow. + std::set aToBeInSelected; + for ( it = aSelected.begin(); it != aSelected.end(); ++it ) { + Handle(GEOM_BaseObject) handle_object = _impl->GetObject( theStudy->StudyId(), (*it).c_str(), false); + if ( handle_object.IsNull() ) + continue; + + stringIOR = handle_object->GetIOR(); + if ( !stringIOR.Length() > 1 ) + continue; + + geomObj = GetIORFromString( stringIOR.ToCString() ); + while ( !geomObj->IsMainShape() ) { + geomObj = geomObj->GetMainShape(); + anEntry = geomObj->GetEntry(); + + foundIt = aParents.find( anEntry ); + if ( foundIt != aParents.end() ) + aParents.erase( foundIt ); + + foundIt = aChildren.find( anEntry ); + if ( foundIt != aChildren.end() ) + aChildren.erase( foundIt ); + + foundIt = anOthers.find( anEntry ); + if ( foundIt != anOthers.end() ) + anOthers.erase( foundIt ); + + aToBeInSelected.insert( anEntry ); + } + } + aSelected.insert( aToBeInSelected.begin(), aToBeInSelected.end() ); + + // fill the CORBA arrays with values from sets + int i; + theSelectedEntries.length( aSelected.size() ); + for ( i = 0, it = aSelected.begin(); it != aSelected.end(); ++it, i++ ) + theSelectedEntries[i] = CORBA::string_dup( (*it).c_str() ); + theParentEntries.length( aParents.size() ); + for ( i = 0, it = aParents.begin(); it != aParents.end(); ++it, i++ ) + theParentEntries[i] = CORBA::string_dup( (*it).c_str() ); + theSubEntries.length( aChildren.size() ); + for ( i = 0, it = aChildren.begin(); it != aChildren.end(); ++it, i++ ) + theSubEntries[i] = CORBA::string_dup( (*it).c_str() ); + theOtherEntries.length( anOthers.size() ); + for ( i = 0, it = anOthers.begin(); it != anOthers.end(); ++it, i++ ) + theOtherEntries[i] = CORBA::string_dup( (*it).c_str() ); + } +} + +void GEOM_Gen_i::getParentDependencies(GEOM::GEOM_BaseObject_ptr geomObj, + std::set& aSelected, + std::set& aParents, + std::set& aChildren, + std::set& anOthers) +{ + std::string anEntry = geomObj->GetEntry(); + if ( aSelected.count( anEntry ) == 0 ) { + aParents.insert( anEntry ); + std::set::iterator it; + it = aChildren.find( anEntry ); + if ( it != aChildren.end() ) + aChildren.erase( it ); + it = anOthers.find( anEntry ); + if ( it != anOthers.end() ) + anOthers.erase( it ); + } + // get dependencies for current object in the tree + GEOM::ListOfGBO_var depList = geomObj->GetDependency(); + if( depList->length() == 0 ) + return; + // go through dependencies of current object to check whether it depends on the given object + std::string aDepEntry; + for( int i = 0; i < depList->length(); i++ ) { + aDepEntry = depList[i]->GetEntry(); + if ( depList[i]->_is_nil() || + aDepEntry == anEntry || // skip self-depending + aSelected.count( aDepEntry ) > 0 || // skip selected objects + aParents.count( aDepEntry ) > 0 // skip already processed objects + ) + continue; + getParentDependencies( depList[i], aSelected, aParents, aChildren, anOthers ); + } +} + //===================================================================================== // EXPORTED METHODS //===================================================================================== diff --git a/src/GEOM_I/GEOM_Gen_i.hh b/src/GEOM_I/GEOM_Gen_i.hh index f0690d019..27242fe5b 100644 --- a/src/GEOM_I/GEOM_Gen_i.hh +++ b/src/GEOM_I/GEOM_Gen_i.hh @@ -324,6 +324,15 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi // SIMAN-related functions (check out/check in) : get modified data virtual Engines::ListOfData* getModifiedData(CORBA::Long studyId); + /*! \brief Fills 3 lists that is used to clean study of redundant objects. + * To be used from GUI. + */ + void GetEntriesToCleanStudy(SALOMEDS::Study_ptr theStudy, + GEOM::string_array& theSelectedEntries, + GEOM::string_array& theParentEntries, + GEOM::string_array& theSubEntries, + GEOM::string_array& theOtherEntries); + //-----------------------------------------------------------------------// // Internal methods // //-----------------------------------------------------------------------// @@ -382,6 +391,12 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi std::map< std::string, std::set > &passedEntries, int level = 0 ); + void getParentDependencies(GEOM::GEOM_BaseObject_ptr gbo, + std::set& aSelected, + std::set& aParents, + std::set& aChildren, + std::set& anOthers); + private: ::GEOMImpl_Gen* _impl; -- 2.39.2