Salome HOME
SIMAN removal
[modules/geom.git] / src / GEOM_I / GEOM_Gen_i.cc
index b052e5d2481b3eb2c4e69e8a1c41162df6470b40..7f60f803e615f54ee7c08eaba9049589ea582554 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -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"
@@ -45,6 +44,7 @@
 #include "GEOMImpl_CopyDriver.hxx"
 #include "GEOMImpl_IInsertOperations.hxx"
 #include "GEOM_wrap.hxx"
+#include "GEOMUtils_XmlHandler.hxx"
 
 // Cascade headers
 #include <BRep_Builder.hxx>
 #include <OSD.hxx>
 #include <TDataStd_ChildNodeIterator.hxx>
 #include <TDocStd_Owner.hxx>
+#include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
 
 #include <SALOMEDS_Tool.hxx>
 #include <SALOMEDS_wrap.hxx>
-#include <SALOME_DataContainer_i.hxx>
 #include <Basics_DirUtils.hxx>
 
 #include <set>
@@ -121,6 +121,18 @@ GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr            orb,
 #endif
     OSD::SetSignal( raiseFPE );
   }
+
+  GEOMUtils::PluginInfo plugins = GEOMUtils::ReadPluginInfo();
+  GEOMUtils::PluginInfo::const_iterator it;
+  for (it = plugins.begin(); it != plugins.end(); ++it)
+  {
+    try {
+      LoadPlugin((*it).serverLib);
+    }
+    catch (...)  {
+      MESSAGE("Warning: can't load plugin library " << (*it).serverLib);
+    }
+  }
 }
 
 //============================================================================
@@ -130,6 +142,9 @@ GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr            orb,
 GEOM_Gen_i::~GEOM_Gen_i() {
   delete name_service;
   delete _impl;
+  std::map<std::string, GEOM_GenericOperationsCreator*>::const_iterator it;
+  for ( it = myOpCreatorMap.begin(); it != myOpCreatorMap.end(); ++it)
+    delete (*it).second;
 }
 
 
@@ -303,7 +318,27 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr   theStudy,
   } else if ( mytype == GEOM_MARKER ) {
     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
     aNamePrefix = "LocalCS_";
-  } else if ( mytype > ADVANCED_BASE ) {
+  }  else if ( mytype >= USER_TYPE_EX ) {
+    char buf[20];
+    sprintf( buf, "%d", aBaseObj->GetType() );
+    GEOM::CreationInformationSeq_var infoSeq = aBaseObj->GetCreationInformation();
+    std::string plgId;
+    for ( size_t j = 0; j < infoSeq->length(); ++j )
+      for ( size_t i = 0; i < infoSeq[j].params.length(); ++i ) {
+        std::string param_name  = infoSeq[j].params[i].name.in();
+        std::string param_value = infoSeq[j].params[i].value.in();
+        if( param_name == PLUGIN_NAME) {
+          plgId = param_value;
+          break;
+        }
+      }
+    if(plgId.length() > 0 ) {
+      plgId += "::";
+    }
+    plgId +="ICON_OBJBROWSER_";
+    plgId += buf;
+    aResultSO->SetAttrString("AttributePixMap",plgId.c_str());
+  } else if ( mytype > USER_TYPE ) {
     char buf[20];
     sprintf( buf, "%d", aBaseObj->GetType() );
     std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
@@ -648,8 +683,8 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
     useCaseBuilder->SetRootCurrent();
     useCaseBuilder->Append( theComponent ); // component object is added as the top level item
   }
-  
-  SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent ); 
+
+  SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent );
   for ( it->InitEx(true); it->More(); it->Next() ) {
     if ( !useCaseBuilder->IsUseCaseNode( it->Value() ) ) {
       useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
@@ -2404,6 +2439,40 @@ GEOM::GEOM_IFieldOperations_ptr GEOM_Gen_i::GetIFieldOperations(CORBA::Long theS
 GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyID,
                                                            const char* theLibName)
      throw ( SALOME::SALOME_Exception )
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  MESSAGE( "GEOM_Gen_i::GetPluginOperations" );
+
+  GEOM::GEOM_Gen_ptr engine = _this();
+
+  GEOM::GEOM_IOperations_var operations;
+
+  std::string aLibName = theLibName;
+
+  try {
+    // load plugin library
+    LoadPlugin(aLibName);
+    // create a new operations object, store its ref. in engine
+    if ( myOpCreatorMap.find(aLibName) != myOpCreatorMap.end() ) {
+      GEOM_IOperations_i* aServant = 0;
+      aServant = myOpCreatorMap[aLibName]->Create(_poa, theStudyID, engine, _impl);
+      // activate the CORBA servant
+      if (aServant)
+        operations = aServant->_this();
+    }
+  }
+  catch (SALOME_Exception& S_ex) {
+    THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+  }
+
+  return operations._retn();
+}
+
+//============================================================================
+// function : LoadPlugin
+// purpose  : load plugin library and retrieve an instance of operations creator
+//============================================================================
+void GEOM_Gen_i::LoadPlugin(const std::string& theLibName)
 {
   std::string aPlatformLibName;
 #ifdef WIN32
@@ -2415,62 +2484,38 @@ GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyI
   aPlatformLibName += ".so";
 #endif
 
-  Unexpect aCatch(SALOME_SalomeException);
-  MESSAGE( "GEOM_Gen_i::GetPluginOperations" );
-
-  GEOM::GEOM_Gen_ptr engine = _this();
-
-  GEOM_IOperations_i* aServant = 0;
-  GEOM::GEOM_IOperations_var operations;
-
-  try {
-    // check, if corresponding operations are already created
-    if (myOpCreatorMap.find(std::string(theLibName)) == myOpCreatorMap.end()) {
-      // load plugin library
-      LibHandle libHandle = LoadLib( aPlatformLibName.c_str()/*theLibName*/ );
-      if (!libHandle) {
-        // report any error, if occured
+  // check, if corresponding operations are already created
+  if (myOpCreatorMap.find(theLibName) == myOpCreatorMap.end()) {
+    // load plugin library
+    LibHandle libHandle = LoadLib( aPlatformLibName.c_str() );
+    if (!libHandle) {
+      // report any error, if occured
 #ifndef WIN32
-        const char* anError = dlerror();
-        throw(SALOME_Exception(anError));
+      throw(SALOME_Exception(dlerror()));
 #else
-        throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" )));
+      throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" )));
 #endif
-      }
-
-      // get method, returning operations creator
-      typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)();
-      GetOperationsCreator procHandle =
-        (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" );
-      if (!procHandle) {
-        throw(SALOME_Exception(LOCALIZED("bad geometry plugin library")));
-        UnLoadLib(libHandle);
-      }
+    }
 
-      // get operations creator
-      GEOM_GenericOperationsCreator* aCreator = procHandle();
-      if (!aCreator) {
-        throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation")));
-      }
+    // get method, returning operations creator
+    typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)();
+    GetOperationsCreator procHandle =
+      (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" );
+    if (!procHandle) {
+      UnLoadLib(libHandle);
+      throw(SALOME_Exception(LOCALIZED("bad geometry plugin library")));
+    }
 
+    // get operations creator
+    GEOM_GenericOperationsCreator* aCreator = procHandle();
+    if (aCreator) {
       // map operations creator to a plugin name
-      myOpCreatorMap[std::string(theLibName)] = aCreator;
+      myOpCreatorMap[theLibName] = aCreator;
+    }
+    else {
+      throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation")));
     }
-
-    // create a new operations object, store its ref. in engine
-    aServant = myOpCreatorMap[std::string(theLibName)]->Create(_poa, theStudyID, engine, _impl);
-    //??? aServant->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
-  }
-  catch (SALOME_Exception& S_ex) {
-    THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
   }
-
-  if (!aServant)
-    return operations._retn();
-
-  // activate the CORBA servant
-  operations = GEOM::GEOM_IOperations::_narrow( aServant->_this() );
-  return operations._retn();
 }
 
 //=============================================================================
@@ -2762,8 +2807,8 @@ char* GEOM_Gen_i::getVersion()
 // function : CreateFolder()
 // purpose  : Creates and returns a new folder object
 //=================================================================================
-SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName, 
-                                              SALOMEDS::SObject_ptr theFather)
+SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName,
+                                               SALOMEDS::SObject_ptr theFather)
 {
   SALOMEDS::SObject_var aFolderSO;
 
@@ -2815,8 +2860,8 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName,
 // function : MoveToFolder()
 // purpose  : Moves GEOM object to the specified folder
 //=================================================================================
-void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject, 
-                             SALOMEDS::SObject_ptr theFolder) {
+void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject,
+                              SALOMEDS::SObject_ptr theFolder) {
   GEOM::object_list_var objects = new GEOM::object_list();
   objects->length( 1 );
   SALOMEDS::SObject_var aSO = theFolder->GetStudy()->FindObjectID( theObject->GetStudyEntry() );
@@ -2828,8 +2873,8 @@ void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject,
 // function : MoveListToFolder()
 // purpose  : Moves list of GEOM objects to the specified folder
 //=================================================================================
-void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO, 
-                                  SALOMEDS::SObject_ptr theFolder) {
+void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
+                                   SALOMEDS::SObject_ptr theFolder) {
   int aLen = theListOfGO.length();
   GEOM::object_list_var objects = new GEOM::object_list();
   objects->length( aLen );
@@ -2846,12 +2891,12 @@ void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
 
 //=================================================================================
 // function : Move()
-// purpose  : Moves objects to the specified position. 
+// purpose  : Moves objects to the specified position.
 //            Is used in the drag-n-drop functionality.
 //=================================================================================
 void GEOM_Gen_i::Move( const GEOM::object_list& what,
-                      SALOMEDS::SObject_ptr where,
-                      CORBA::Long row )
+                       SALOMEDS::SObject_ptr where,
+                       CORBA::Long row )
 {
   if ( CORBA::is_nil( where ) ) return;
 
@@ -2861,7 +2906,7 @@ void GEOM_Gen_i::Move( const GEOM::object_list& what,
   SALOMEDS::SComponent_var father = where->GetFatherComponent();
   std::string dataType = father->ComponentDataType();
   if ( dataType != "GEOM" ) return; // not a GEOM component
-  
+
   SALOMEDS::SObject_var objAfter;
   if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
     // insert at given row -> find insertion position
@@ -2872,7 +2917,7 @@ void GEOM_Gen_i::Move( const GEOM::object_list& what,
       objAfter = useCaseIt->Value();
     }
   }
-  
+
   for ( int i = 0; i < what.length(); i++ ) {
     SALOMEDS::SObject_var sobj = what[i];
     if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
@@ -2884,169 +2929,12 @@ void GEOM_Gen_i::Move( const GEOM::object_list& what,
   }
 }
 
-//=================================================================================
-// function : importData
-// purpose  : imports geometrical data file into the GEOM internal data structure
-//=================================================================================
-Engines::ListOfIdentifiers* GEOM_Gen_i::importData(
-  CORBA::Long studyId, Engines::DataContainer_ptr data, const Engines::ListOfOptions& options)
-{
-  CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
-  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
-  SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
-
-  Engines::ListOfIdentifiers_var aResult = new Engines::ListOfIdentifiers;
-  GEOM::GEOM_IInsertOperations_var aInsOp = GetIInsertOperations(aStudy->StudyId());
-  if (aInsOp->_is_nil()) {
-    MESSAGE("No insert operations!");
-    return aResult._retn();
-  }
-
-  // Get a temporary directory to store a file
-  std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
-  std::string aFileName("file");
-  if (aFileName.rfind("/") != std::string::npos) { // remove folders from the name
-    aFileName = aFileName.substr(aFileName.rfind("/") + 1);
-  }
-
-  std::string anExtension(data->extension());
-  aFileName += "." + anExtension;
-  // convert extension to upper case
-  std::transform(anExtension.begin(), anExtension.end(), anExtension.begin(), ::toupper);
-  std::string aFullPath = aTmpDir + aFileName;
-
-  Engines::TMPFile* aFileStream = data->get();
-  const char *aBuffer = (const char*)aFileStream->NP_data();
-#ifdef WIN32
-  std::ofstream aFile(aFullPath.c_str(), std::ios::binary);
-#else
-  std::ofstream aFile(aFullPath.c_str());
-#endif
-  aFile.write(aBuffer, aFileStream->length());
-  aFile.close();
-
-  GEOM::GEOM_Object_var aShapeObj;
-  GEOM::ListOfGO_var aSubShape = new GEOM::ListOfGO;
-  GEOM::ListOfGO_var aGroups = new GEOM::ListOfGO;
-  GEOM::ListOfFields_var aFields = new GEOM::ListOfFields;
-
-  CORBA::Boolean isResultOK = aInsOp->ImportXAO(aFullPath.c_str(), aShapeObj.out(), aSubShape.out(), aGroups.out(), aFields.out());
-
-  if ( isResultOK && !aShapeObj->_is_nil() && aInsOp->IsDone() ) {
-    SALOMEDS::SObject_var aSO = PublishInStudy(aStudy, SALOMEDS::SObject::_nil(), aShapeObj, aShapeObj->GetName());
-    aResult->length(aGroups->length() + 1);
-    aResult[0] = aSO->GetID(); // unioque identifer of the object in GEOM is entry of SObject
-    //Iteration for objects of the group.
-    for (int i = 0; i < aGroups->length(); i++) {
-      SALOMEDS::SObject_var aSOChild = AddInStudy(aStudy, aGroups[i], aGroups[i]->GetName(), aShapeObj);
-      aResult[i+1] = aSOChild->GetID();
-    }
-  }
-  else {
-    if (aShapeObj->_is_nil())
-      MESSAGE("Result of the import operation is incorrect for file "<<aFullPath.c_str());
-    if (!aInsOp->IsDone())
-      MESSAGE("Import operation is not done for file "<<aFullPath.c_str());
-    if (!isResultOK)
-      MESSAGE("ImportXAO operation is failed for file "<<aFullPath.c_str());
-    return aResult._retn();
-  }
-
-  // remove temporary file and directory
-  SALOMEDS::ListOfFileNames aTmpFiles;
-  aTmpFiles.length(1);
-  aTmpFiles[0] = aFileName.c_str();
-  SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aTmpFiles, true);
-
-  _impl->DocumentModified(studyId, false);
-  return aResult._retn();
-}
-
-//=================================================================================
-// function : getModifiedData
-// purpose  : exports all geometry of this GEOM module into one BRep file
-//=================================================================================
-Engines::ListOfData* GEOM_Gen_i::getModifiedData(CORBA::Long studyId)
-{
-  Engines::ListOfData_var aResult = new Engines::ListOfData;
-
-  if (!_impl->DocumentModified(studyId)) {
-    MESSAGE("Document is not modified")
-    return aResult._retn();
-  }
-
-  CORBA::Object_var aSMObject = name_service->Resolve("/myStudyManager");
-  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
-  SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
-  SALOMEDS::SComponent_var aComponent = aStudy->FindComponent("GEOM");
-  if (CORBA::is_nil(aComponent))
-    return aResult._retn();
-  SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(aComponent); // check only published shapes
-
-  GEOM::GEOM_Object_var shapeObj;
-  GEOM::ListOfGO_var groups = new GEOM::ListOfGO;
-  GEOM::ListOfFields_var fields = new GEOM::ListOfFields;
-  std::string anAuthorName = "SIMAN Author";
-  
-  GEOM::GEOM_IShapesOperations_var  aShapesOp = GetIShapesOperations(aStudy->StudyId());
-  GEOM::GEOM_IInsertOperations_var aInsOp = GetIInsertOperations(aStudy->StudyId());
-
-  int aSeqLength = 0; // the sequence length
-  for(; anIter->More(); anIter->Next()) {
-    SALOMEDS::SObject_var aSO = anIter->Value();
-    SALOMEDS::SObject_var aRefSO;
-    // export only not referenced objects, or referenced outside of GEOM
-    if (!aSO->ReferencedObject(aRefSO) || aRefSO->GetFatherComponent()->GetID() != aComponent->GetID()) {
-      CORBA::Object_var anObj = aSO->GetObject();
-      if (!CORBA::is_nil(anObj)) {
-        GEOM::GEOM_Object_var aCORBAMainShape = GEOM::GEOM_Object::_narrow(anObj);
-        if(!aCORBAMainShape->_is_nil()) {
-          CORBA::String_var entry = aCORBAMainShape->GetEntry();
-          Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast(_impl->GetObject(studyId, entry));
-
-          GEOM::shape_type aCORBAShapeType = aCORBAMainShape->GetShapeType();
-          if (!aMainShape.IsNull() && !(aCORBAShapeType == GEOM::VERTEX) && !(aCORBAShapeType == GEOM::EDGE)) {
-            aSeqLength++;
-            shapeObj = aCORBAMainShape;
-            if (aShapesOp->_is_nil()) {
-              MESSAGE("No shapes operations!");
-              return aResult._retn();
-            }
-            groups = aShapesOp->GetExistingSubObjects(aCORBAMainShape, true);
-            break;
-          }
-        }
-      }
-    }
-  }
-
-  if (aInsOp->_is_nil()) {
-    MESSAGE("No insert operations!");
-    return aResult._retn();
-  }
-
-  if (aSeqLength > 0) { // Shape is correct, write it to the temporary file
-
-    std::string aFullXaoPath = Kernel_Utils::GetTmpFileName() + ".xao";
-    CORBA::Boolean isResultOK = aInsOp->ExportXAO(shapeObj.in(), groups.in(), fields.in(), anAuthorName.c_str(), aFullXaoPath.c_str());
-
-    aResult->length(1);
-    Engines::DataContainer_var aData = (new Engines_DataContainer_i(
-                    aFullXaoPath.c_str(), "", "", true))->_this();
-    aResult[0] = aData;
-  } else {
-    MESSAGE("No shapes to export");
-  }
-
-  return aResult._retn();
-}
-                                                               
 //=======================================================================
 // 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& theObjectEntries ) {
+                                                  const GEOM::string_array& theObjectEntries ) {
   // fill in the tree structure
   GEOMUtils::TreeModel tree;
 
@@ -3070,7 +2958,7 @@ SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( SALOMEDS::Study_ptr theStudy,
   // 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);
@@ -3086,10 +2974,10 @@ SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( SALOMEDS::Study_ptr theStudy,
 // 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, 
-                                     std::map< std::string, std::set<std::string> > &passedEntries,
-                                     int level ) {
+void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
+                                      GEOMUtils::LevelsList &upLevelList,
+                                      std::map< std::string, std::set<std::string> > &passedEntries,
+                                      int level ) {
   std::string aGboEntry = gbo->GetEntry();
   GEOMUtils::NodeLinks anEntries;
   GEOMUtils::LevelInfo aLevelMap;
@@ -3101,7 +2989,7 @@ void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
       // get the existent map
       aLevelMap = upLevelList.at(level-1);
       if ( aLevelMap.count( aGboEntry ) > 0 ) {
-       anEntries = aLevelMap[ aGboEntry ];
+        anEntries = aLevelMap[ aGboEntry ];
       }
     }
   }
@@ -3112,7 +3000,7 @@ void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
     if ( depList[j]->_is_nil() )
       continue;
     aDepEntry = depList[j]->GetEntry();
-    if ( passedEntries.count( aGboEntry ) > 0 && 
+    if ( passedEntries.count( aGboEntry ) > 0 &&
          passedEntries[aGboEntry].count( aDepEntry ) > 0 ) {
       //avoid checking the passed objects
       continue;
@@ -3134,10 +3022,10 @@ void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
 // function : getDownwardDependency
 // purpose  : Collects the entries of objects that depends on the given one
 //=======================================================================
-void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo, 
-                                       GEOMUtils::LevelsList &downLevelList, 
-                                       std::map< std::string, std::set<std::string> > &passedEntries,
-                                       int level ) {
+void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
+                                        GEOMUtils::LevelsList &downLevelList,
+                                        std::map< std::string, std::set<std::string> > &passedEntries,
+                                        int level ) {
   std::string aGboEntry = gbo->GetEntry();
   Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument(gbo->GetStudyID());
   Handle(TDataStd_TreeNode) aNode, aRoot;
@@ -3169,7 +3057,7 @@ void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
           continue;
         if ( depList[i]->_is_equivalent( gbo ) ) {
           // yes, the current object depends on the given object
-          if ( passedEntries.count( aGoEntry ) > 0 && 
+          if ( passedEntries.count( aGoEntry ) > 0 &&
                passedEntries[aGoEntry].count( aGboEntry ) > 0 ) {
             //avoid checking the passed objects
             continue;
@@ -3197,6 +3085,198 @@ void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
   }
 }
 
+//==============================================================================
+// function : GetEntriesToReduceStudy
+// purpose  : Fills 3 lists that is used to clean study of redundant objects
+//==============================================================================
+void GEOM_Gen_i::GetEntriesToReduceStudy(SALOMEDS::Study_ptr theStudy,
+                                        GEOM::string_array& theSelectedEntries,
+                                        GEOM::string_array& theParentEntries,
+                                        GEOM::string_array& theSubEntries,
+                                        GEOM::string_array& theOtherEntries)
+{
+  std::set<std::string> 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 ) {
+        includeParentDependencies( geomObj, aSelected, aParents, aChildren, anOthers );
+      } else if ( aParents.count( anEntry ) == 0 &&
+                  aChildren.count( anEntry ) == 0 ) {
+        anOthers.insert( geomObj->GetEntry() );
+      }
+    }
+
+    std::set<std::string>::iterator it;
+    std::set<std::string>::iterator foundIt;
+    TCollection_AsciiString stringIOR;
+    GEOM::GEOM_Object_var geomObj;
+
+    // filling list of sub-objects
+    for ( it = aSelected.begin(); it != aSelected.end(); ++it ) {
+      includeSubObjects( theStudy, *it, aSelected, aParents, aChildren, anOthers );
+    }
+
+    // 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<std::string> 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() );
+  }
+}
+
+//==============================================================================
+// function : includeParentDependencies
+// purpose  :
+//==============================================================================
+void GEOM_Gen_i::includeParentDependencies(GEOM::GEOM_BaseObject_ptr geomObj,
+                                           std::set<std::string>& aSelected,
+                                           std::set<std::string>& aParents,
+                                           std::set<std::string>& aChildren,
+                                           std::set<std::string>& anOthers)
+{
+  std::string anEntry = geomObj->GetEntry();
+  if ( aSelected.count( anEntry ) == 0 ) {
+    aParents.insert( anEntry );
+    std::set<std::string>::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;
+    includeParentDependencies( depList[i], aSelected, aParents, aChildren, anOthers );
+  }
+}
+
+//==============================================================================
+// function : includeSubObjects
+// purpose  :
+//==============================================================================
+void GEOM_Gen_i::includeSubObjects(SALOMEDS::Study_ptr theStudy,
+                                   const std::string& aSelectedEntry,
+                                   std::set<std::string>& aSelected,
+                                   std::set<std::string>& aParents,
+                                   std::set<std::string>& aChildren,
+                                   std::set<std::string>& anOthers)
+{
+  std::set<std::string>::iterator foundIt;
+  Handle(GEOM_BaseObject) handle_object = _impl->GetObject( theStudy->StudyId(), aSelectedEntry.c_str(), false);
+  if ( handle_object.IsNull() )
+    return;
+
+  Handle(GEOM_Function) aShapeFun = handle_object->GetFunction(1);
+  if ( aShapeFun.IsNull() || !aShapeFun->HasSubShapeReferences() )
+    return;
+
+  const TDataStd_ListOfExtendedString& aListEntries = aShapeFun->GetSubShapeReferences();
+  if ( aListEntries.IsEmpty() )
+    return;
+
+  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
+      foundIt = aSelected.find( aSubEntryStr );
+      if ( foundIt == aSelected.end() ) { // add to sub-objects if it is not in selected list
+            aChildren.insert( aSubEntryStr );
+            foundIt = anOthers.find( aSubEntryStr );
+            if ( foundIt != anOthers.end() )
+              anOthers.erase( foundIt );
+      }
+    }
+    includeSubObjects( theStudy, aSubEntryStr, aSelected, aParents, aChildren, anOthers );
+  }
+}
 //=====================================================================================
 // EXPORTED METHODS
 //=====================================================================================