Salome HOME
Algorithm of dependencies definition was updated and replaced. Auxiliry convertation...
[modules/geom.git] / src / GEOM_I / GEOM_Gen_i.cc
old mode 100644 (file)
new mode 100755 (executable)
index c44b639..eca0f43
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,8 +18,9 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
-#ifdef WNT
+#ifdef WIN32
 #pragma warning( disable:4786 )
 #endif
 
 
 #include "GEOM_Gen_i.hh"
 #include "GEOM_Object_i.hh"
+#include "GEOM_Field_i.hh"
 #include "GEOM_version.h"
 
-#include <set>
-#include <sstream>
-
 #include "Utils_CorbaException.hxx"
 #include "OpUtil.hxx"
 #include "Utils_ExceptHandlers.hxx"
 #include "GEOM_Object.hxx"
 #include "GEOM_Function.hxx"
 #include "GEOM_ISubShape.hxx"
-#include <GEOM_PythonDump.hxx>
+#include "GEOM_PythonDump.hxx"
 #include "GEOMImpl_Types.hxx"
 #include "GEOMImpl_CopyDriver.hxx"
+#include "GEOMImpl_IInsertOperations.hxx"
+#include "GEOM_wrap.hxx"
 
 // Cascade headers
 #include <BRep_Builder.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TColStd_HArray1OfInteger.hxx>
 #include <TopAbs_ShapeEnum.hxx>
-//#include <TopTools_IndexedMapOfShape.hxx>
 #include <TopExp.hxx>
+#include <TopTools_SequenceOfShape.hxx>
 #include <OSD.hxx>
 
 #include <SALOMEDS_Tool.hxx>
 #include <SALOMEDS_wrap.hxx>
+#include <SALOME_DataContainer_i.hxx>
+#include <Basics_DirUtils.hxx>
 
-#ifdef WNT
+#include <set>
+#include <sstream>
+
+#ifdef WIN32
  #include <windows.h>
  #include <process.h>
 #else
  #include <dlfcn.h>
 #endif
 
-#ifdef WNT
+#ifdef WIN32
  #define LibHandle HMODULE
  #define LoadLib( name ) LoadLibrary( name )
  #define GetProc GetProcAddress
@@ -105,14 +111,11 @@ GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr            orb,
   {
     //work around PAL12004, PAL12628
     //OSD::SetSignal( true );
-    bool raiseFPE;
-#ifdef _DEBUG_
-    raiseFPE = true;
-    char* envDisableFPE = getenv("DISABLE_FPE");
-    if (envDisableFPE && atoi(envDisableFPE))
-      raiseFPE = false;
-#else
-    raiseFPE = false;
+    bool raiseFPE = false;
+#if defined(_DEBUG_) | defined(_DEBUG) //the Last for WIN32 default settings
+    char* envEnableFPE = getenv("ENABLE_FPE");
+    if (envEnableFPE && atoi(envEnableFPE))
+      raiseFPE = true;
 #endif
     OSD::SetSignal( raiseFPE );
   }
@@ -137,7 +140,8 @@ char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
                                          CORBA::Boolean isMultiFile,
                                          CORBA::Boolean isASCII)
 {
-  GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
+  GEOM::GEOM_BaseObject_var anObject =
+    GEOM::GEOM_BaseObject::_narrow(_orb->string_to_object(IORString));
   if (!CORBA::is_nil(anObject)) {
     return CORBA::string_dup(anObject->GetEntry());
   }
@@ -158,13 +162,21 @@ char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
 {
   SALOMEDS::Study_var aStudy = theSObject->GetStudy();
 
-  Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
-  TCollection_AsciiString anEntry;
-  TDF_Tool::Entry(anObject->GetEntry(), anEntry);
-  GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
+  Handle(GEOM_BaseObject) anObject =
+    _impl->GetObject(aStudy->StudyId(), aLocalPersistentID);
+  if ( !anObject.IsNull() )
+  {
+    TCollection_AsciiString anEntry;
+    TDF_Tool::Entry(anObject->GetEntry(), anEntry);
+    GEOM::GEOM_BaseObject_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
 
-  CORBA::String_var aPersRefString = _orb->object_to_string(obj);
-  return CORBA::string_dup(aPersRefString);
+    CORBA::String_var aPersRefString = _orb->object_to_string(obj);
+    return CORBA::string_dup(aPersRefString);
+  }
+  else
+  {
+    return CORBA::string_dup("");
+  }
 }
 
 //============================================================================
@@ -182,16 +194,18 @@ bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
 // function : PublishInStudy
 // purpose  :
 //============================================================================
-SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
+SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr   theStudy,
                                                  SALOMEDS::SObject_ptr theSObject,
-                                                 CORBA::Object_ptr theObject,
-                                                 const char* theName) throw (SALOME::SALOME_Exception)
+                                                 CORBA::Object_ptr     theObject,
+                                                 const char*           theName)
+  throw (SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
   SALOMEDS::SObject_var aResultSO;
   if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
-  GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
-  if(aShape->_is_nil()) return aResultSO;
+  GEOM::GEOM_BaseObject_var aBaseObj = GEOM::GEOM_BaseObject::_narrow(theObject);
+  GEOM::GEOM_Object_var       aShape = GEOM::GEOM_Object::_narrow(theObject);
+  if(aBaseObj->_is_nil()) return aResultSO;
 
   SALOMEDS::GenericAttribute_var anAttr;
   SALOMEDS::StudyBuilder_var     aStudyBuilder = theStudy->NewBuilder();
@@ -221,109 +235,129 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
   } else {
     if (!theSObject->ReferencedObject(aResultSO))
       aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for  the method AddInStudy with theFather argumenet != NULL
-      //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
+    //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
   }
   CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
   aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
 
-  TCollection_AsciiString aShapeName("Shape_");
+  TCollection_AsciiString anObjectName, aNamePrefix("Shape_");
+  CORBA::Long mytype=aBaseObj->GetType();
+
+  // BEGIN: try to find existed name for current shape
+  if ( !aShape->_is_nil() && mytype != GEOM_GROUP)
+  {
+    // recieve current TopoDS shape
+    CORBA::String_var entry = aShape->GetEntry();
+    Handle(GEOM_Object) aGShape = Handle(GEOM_Object)::DownCast
+      ( _impl->GetObject( aShape->GetStudyID(), entry ));
+    TopoDS_Shape TopoSh = aGShape->GetValue();
+    // find label of main shape
+    GEOM::GEOM_Object_var aMainSh = aShape;
+    while( !aMainSh->IsMainShape() ) {
+      aMainSh = aMainSh->GetMainShape();
+    }
+    entry = aMainSh->GetEntry();
+    Handle(GEOM_BaseObject) anObj = _impl->GetObject( aMainSh->GetStudyID(), entry );
+    TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
+
+    // check all named shapes using iterator
+    TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
+
+    for (; anIt.More() && anObjectName.IsEmpty(); anIt.Next()) {
+      Handle(TNaming_NamedShape) anAttr =
+        Handle(TNaming_NamedShape)::DownCast(anIt.Value());
+      if (anAttr.IsNull()) continue;
+      TopoDS_Shape S = anAttr->Get();
+      if (S.IsEqual(TopoSh)) {
+        TDF_Label L = anAttr->Label();
+        Handle(TDataStd_Name) aName;
+        if (L.FindAttribute(TDataStd_Name::GetID(), aName))
+          anObjectName = aName->Get();
+      }
+    }
+  }
+  // END: try to find existed name for current shape
 
-  CORBA::Long mytype=aShape->GetType();
   if ( mytype == GEOM_GROUP ) {
     GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
-    switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
+    switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape )) {
     case TopAbs_VERTEX:
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" );
-      aShapeName = "Group_Of_Vertices_";
+      aNamePrefix = "Group_Of_Vertices_";
       break;
     case TopAbs_EDGE:
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE");
-      aShapeName = "Group_Of_Edges_";
+      aNamePrefix = "Group_Of_Edges_";
       break;
     case TopAbs_FACE:
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE");
-      aShapeName = "Group_Of_Faces_";
+      aNamePrefix = "Group_Of_Faces_";
       break;
     case TopAbs_SOLID:
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID");
-      aShapeName = "Group_Of_Solids_";
+      aNamePrefix = "Group_Of_Solids_";
       break;
     }
   } else if ( mytype == GEOM_MARKER ) {
     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
-    aShapeName = "LocalCS_";
+    aNamePrefix = "LocalCS_";
   } else if ( mytype > ADVANCED_BASE ) {
     char buf[20];
-    sprintf( buf, "%d", aShape->GetType() );
+    sprintf( buf, "%d", aBaseObj->GetType() );
     std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
     aResultSO->SetAttrString("AttributePixMap",advId.c_str());
-    aShapeName = "Advanced_";
-  } else {
+    aNamePrefix = "Advanced_";
+  } else if ( mytype == GEOM_FIELD ) {
+    aNamePrefix = "Field_";
+    GEOM::GEOM_Field_var aField = GEOM::GEOM_Field::_narrow(theObject);
+    if ( !aField->_is_nil() )
+      switch( aField->GetDimension() ) {
+      case 0:
+        aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_PNT" ); break;
+      case 1:
+        aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_EDGE"); break;
+      case 2:
+        aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_FACE"); break;
+      case 3:
+        aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID"); break;
+      default:
+        aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID");
+      }
+  } else if ( mytype == GEOM_FIELD_STEP ) {
+    aNamePrefix = "Step_";
+  } else if ( !aShape->_is_nil() ) {
     GEOM::shape_type myshapetype=aShape->GetShapeType();
     if ( myshapetype == GEOM::COMPOUND ) {
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" );
-      aShapeName = "Compound_";
+      aNamePrefix = "Compound_";
     } else if ( myshapetype == GEOM::COMPSOLID ) {
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID");
-      aShapeName = "Compsolid_";
+      aNamePrefix = "Compsolid_";
     } else if ( myshapetype == GEOM::SOLID ) {
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID");
-      aShapeName = "Solid_";
+      aNamePrefix = "Solid_";
     } else if ( myshapetype == GEOM::SHELL ) {
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL");
-      aShapeName = "Shell_";
+      aNamePrefix = "Shell_";
     } else if ( myshapetype == GEOM::FACE ) {
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE");
-      aShapeName = "Face_";
+      aNamePrefix = "Face_";
     } else if ( myshapetype == GEOM::WIRE ) {
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE");
-      aShapeName = "Wire_";
+      aNamePrefix = "Wire_";
     } else if ( myshapetype == GEOM::EDGE ) {
       aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE");
-      aShapeName = "Edge_";
+      aNamePrefix = "Edge_";
     } else if ( myshapetype == GEOM::VERTEX ) {
       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_VERTEX" );
-      aShapeName = "Vertex_";
-    }
-  }
-  //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
-  //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
-
-  // BEGIN: try to find existed name for current shape
-  bool HasName = false;
-  // recieve current TopoDS shape
-  CORBA::String_var entry = aShape->GetEntry();
-  Handle(GEOM_Object) aGShape = _impl->GetObject(aShape->GetStudyID(), entry);
-  TopoDS_Shape TopoSh = aGShape->GetValue();
-  // find label of main shape
-  GEOM::GEOM_Object_var aMainSh = aShape;
-  while( !aMainSh->IsMainShape() ) {
-    aMainSh = aMainSh->GetMainShape();
-  }
-  entry = aMainSh->GetEntry();
-  Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry);
-  TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
-
-  // check all named shapes using iterator
-  TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
-
-  for (; anIt.More() && !HasName; anIt.Next()) {
-    Handle(TNaming_NamedShape) anAttr =
-      Handle(TNaming_NamedShape)::DownCast(anIt.Value());
-    if (anAttr.IsNull()) continue;
-    TopoDS_Shape S = anAttr->Get();
-    if (S.IsEqual(TopoSh)) {
-      TDF_Label L = anAttr->Label();
-      Handle(TDataStd_Name) aName;
-      if (L.FindAttribute(TDataStd_Name::GetID(), aName)) {
-        aShapeName = aName->Get();
-        HasName = true;
-      }
+      aNamePrefix = "Vertex_";
     }
   }
-  // END: try to find existed name for current shape
+  if ( anObjectName.IsEmpty() )
+  {
+    //if (strlen(theName) == 0) aNamePrefix += TCollection_AsciiString(aResultSO->Tag());
+    //else anObjectName = TCollection_AsciiString(CORBA::string_dup(theName));
 
-  if (!HasName) {
     // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
     //       it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
     //       of objects in the study, but compute a number of objects with the same prefix
@@ -331,34 +365,33 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
     if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
       int i = 0;                    // (WITH EMPTY NEW NAME)
       SALOMEDS::SObject_var obj;
-      TCollection_AsciiString aNewShapeName;
       do {
-        aNewShapeName = aShapeName + TCollection_AsciiString(++i);
-        obj = theStudy->FindObject( aNewShapeName.ToCString() );
+        anObjectName = aNamePrefix + TCollection_AsciiString(++i);
+        obj = theStudy->FindObject( anObjectName.ToCString() );
       }
       while ( !obj->_is_nil() );
-      aShapeName = aNewShapeName;
     }
-    else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
-      aShapeName = TCollection_AsciiString((char*)theName);
+    else { // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
+      anObjectName = theName;
+    }
   }
 
   //Set the study entry as a name of  the published GEOM_Object
-  CORBA::String_var anID =aResultSO->GetID();
-  aShape->SetStudyEntry(anID.in());
+  CORBA::String_var anID = aResultSO->GetID();
+  aBaseObj->SetStudyEntry(anID.in());
 
   //Set a name of the added shape
-  aResultSO->SetAttrString("AttributeName",aShapeName.ToCString());
+  aResultSO->SetAttrString("AttributeName",anObjectName.ToCString());
 
   //Set NoteBook variables used in the object creation
   TCollection_AsciiString aVars;
-  CORBA::String_var aString=aShape->GetParameters();
+  CORBA::String_var aString=aBaseObj->GetParameters();
   SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString);
   for(int i = 0, n = aSections->length(); i < n; i++) {
     SALOMEDS::ListOfStrings aListOfVars = aSections[i];
     for(int j = 0, m = aListOfVars.length(); j < m; j++) {
       if(theStudy->IsVariable(aListOfVars[j].in()))
-        aVars += TCollection_AsciiString(aListOfVars[j].in());
+        aVars += aListOfVars[j].in();
       if(j != m-1)
         aVars += ":";
     }
@@ -370,7 +403,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
   aFather->UnRegister();
 
   //Set a name of the GEOM object
-  aShape->SetName(aShapeName.ToCString());
+  aBaseObj->SetName(anObjectName.ToCString());
 
   // add object to the use case tree
   // (to support tree representation customization and drag-n-drop)
@@ -379,7 +412,6 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
   return aResultSO._retn();
 }
 
-
 //============================================================================
 // function : CreateAndPublishGroup
 // purpose  : auxilary for PublishNamedShapesInStudy
@@ -393,16 +425,15 @@ void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
                                        GEOM::ListOfGO_var aResList)
 {
   CORBA::String_var entry = theMainShape->GetEntry();
-  Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
+  //Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
   Handle(TColStd_HArray1OfInteger) anArray;
   if(SeqS.Length()>0) {
     // create a group
     GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
-    GEOM::GEOM_Object_ptr GrObj =
-      GOp->CreateGroup( theMainShape, SeqS.Value(1).ShapeType() );
+    GEOM::GEOM_Object_wrap GrObj = GOp->CreateGroup( theMainShape, SeqS(1).ShapeType() );
     AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
-    CORBA::String_var GrEntry = GrObj->GetEntry();
-    Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
+    //CORBA::String_var GrEntry = GrObj->GetEntry();
+    //Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
     // add named objects
     //Handle(GEOM_Object) anObj;
     for(int i=1; i<=SeqS.Length(); i++) {
@@ -447,7 +478,8 @@ GEOM::ListOfGO* GEOM_Gen_i::
   if(theMainShape->_is_nil()) return aResList._retn();
 
   CORBA::String_var entry = theMainShape->GetEntry();
-  Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
+  Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast
+    ( _impl->GetObject( theMainShape->GetStudyID(), entry ));
   if (aMainShape.IsNull()) return aResList._retn();
   TopoDS_Shape MainSh = aMainShape->GetValue();
 
@@ -517,7 +549,7 @@ SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
   // OCCT BUG: cannot save a document (in current folder)
   // if directory name is empty
   if (aTmpDir.size() == 0) {
-#ifdef WNT
+#ifdef WIN32
     aTmpDir = ".\\";
 #else
     aTmpDir = "./";
@@ -580,7 +612,7 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
   // OCCT BUG: cannot load a document (from current folder)
   // if directory name is empty
   if (aTmpDir.size() == 0) {
-#ifdef WNT
+#ifdef WIN32
     aTmpDir = ".\\";
 #else
     aTmpDir = "./";
@@ -714,6 +746,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
   // Find the current Study and StudyBuilder
   SALOMEDS::Study_var aStudy = theObject->GetStudy();
   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
+  SALOMEDS::UseCaseBuilder_var anUseCaseBuilder = aStudy->GetUseCaseBuilder();
   SALOMEDS::SObject_var aNewSO;
   // Retrieve a TopoDS_Shape from byte stream
   TopoDS_Shape aTopology;
@@ -738,7 +771,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
 
   TCollection_AsciiString anEntry;
   TDF_Tool::Entry(anObj->GetEntry(), anEntry);
-  GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
+  GEOM::GEOM_BaseObject_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
 
   //Set the study entry of the published GEOM_Object
   obj->SetStudyEntry(aNewSO->GetID());
@@ -750,6 +783,10 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
   anIOR->SetValue(objStr.in());
   anIOR->UnRegister();
 
+  // add object to the use case tree
+  // (to support tree representation customization and drag-n-drop)
+  anUseCaseBuilder->AppendTo( aNewSO->GetFather(), aNewSO );
+
   // Return the created in the Study SObject
   return aNewSO._retn();
 }
@@ -767,10 +804,10 @@ char* GEOM_Gen_i::ComponentDataType()
 // function : AddInStudy
 // purpose  :
 //============================================================================
-SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
-                                              GEOM::GEOM_Object_ptr theObject,
-                                              const char* theName,
-                                              GEOM::GEOM_Object_ptr theFather)
+SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr       theStudy,
+                                              GEOM::GEOM_BaseObject_ptr theObject,
+                                              const char*               theName,
+                                              GEOM::GEOM_BaseObject_ptr theFather)
 {
   SALOMEDS::SObject_var aResultSO;
   if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
@@ -789,14 +826,14 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
   aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
   if(aResultSO->_is_nil()) return aResultSO._retn();
 
-  GEOM::ListOfGO_var aList = theObject->GetDependency();
+  GEOM::ListOfGBO_var aList = theObject->GetDependency();
   Standard_Integer aLength = aList->length();
   if(aLength < 1) return aResultSO._retn();
 
   //Publish the arguments
   TCollection_AsciiString aPrevID; // to avoid multiple references to same object
   for(Standard_Integer i = 0; i< aLength; i++) {
-    GEOM::GEOM_Object_var anObject = aList[i];
+    GEOM::GEOM_BaseObject_var anObject = aList[i];
     if(anObject->_is_nil()) continue;
     IOR = _orb->object_to_string(anObject);
     SALOMEDS::SObject_wrap aSO =  theStudy->FindObjectIOR(IOR.in());
@@ -806,6 +843,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
     aPrevID = anID.in();
     SALOMEDS::SObject_wrap aSubSO = aStudyBuilder->NewObject(aResultSO);
     aStudyBuilder->Addreference(aSubSO, aSO);
+    theStudy->GetUseCaseBuilder()->AppendTo( aResultSO, aSubSO );
   }
 
   return aResultSO._retn();
@@ -968,8 +1006,12 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr     theStudy,
   }
   else {
     // Get all arguments
-    aList = theObject->GetDependency();
-    aLength = aList->length();
+    GEOM::ListOfGBO_var boList = theObject->GetDependency();
+    aLength = boList->length();
+    aList = new GEOM::ListOfGO;
+    aList->length(aLength);
+    for (int i = 0; i < aLength; i++)
+      aList[i] = GEOM::GEOM_Object::_narrow( boList[i] );
     nbArgsActual = aLength;
   }
 
@@ -1042,7 +1084,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr     theStudy,
             GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
             if (!CORBA::is_nil(anArgOTrsf)) {
               CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
-              Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
+              Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
               Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
               anArgOTrsfFun->SetDescription("");
               aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
@@ -1237,7 +1279,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr     theStudy,
   aResParts->length(nb);
   if (nb > 0)
   {
-    Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
+    Handle(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
     Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
     GEOM::TPythonDump pd (aFunction, true);
     pd <<"[";
@@ -1253,8 +1295,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr     theStudy,
       anObjEntryMap.insert(anEntry);
       aResParts[nbRes++] = anObj;
       // clear python dump of object
-      Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
-      Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
+      Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
+      Handle(GEOM_Function)   anObjFun = aGeomObj->GetLastFunction();
       if ( !anObjFun.IsNull() )
         anObjFun->SetDescription( "" );
       if ( j > 0 )
@@ -1271,7 +1313,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr     theStudy,
       GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
       if (CORBA::is_nil(anObj))
         continue;
-      Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
+      Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
       if ( j > 0 )
         pd << ", ";
       pd << aGeomObj;
@@ -1363,7 +1405,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr     th
             GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
             if (!CORBA::is_nil(anArgOTrsf)) {
               CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
-              Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
+              Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
               Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
               anArgOTrsfFun->SetDescription("");
               aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
@@ -1543,8 +1585,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr     theStu
     return aParts._retn();
 
   // Get all arguments
-  GEOM::ListOfGO_var anOpArgsList = theObject->GetDependency();
-  Standard_Integer nbArgsActual = anOpArgsList->length();
+  GEOM::ListOfGBO_var anOpArgsList = theObject->GetDependency();
+  Standard_Integer    nbArgsActual = anOpArgsList->length();
 
   // If anOpArgsList list is empty, nothing to do
   if (nbArgsActual == 0)
@@ -1566,7 +1608,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr     theStu
   for (int j = 0; j < nbArgsActual; j++) {
     CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
     if (anArgs.count(anEntry.in())) {
-      aList[k] = GEOM::GEOM_Object::_duplicate(anOpArgsList[j]);
+      aList[k] = GEOM::GEOM_Object::_narrow(anOpArgsList[j]);
       k++;
     }
   }
@@ -1639,7 +1681,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr     theStu
             GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
             if (!CORBA::is_nil(anArgOTrsf)) {
               CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
-              Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
+              Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
               Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
               anArgOTrsfFun->SetDescription("");
               aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
@@ -1783,7 +1825,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr     theStu
   aResParts->length(nb);
   if (nb > 0)
   {
-    Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
+    Handle(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
     Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
     GEOM::TPythonDump pd (aFunction, true);
     pd <<"[";
@@ -1799,8 +1841,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr     theStu
       anObjEntryMap.insert(anEntry);
       aResParts[nbRes++] = anObj;
       // clear python dump of object
-      Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
-      Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
+      Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
+      Handle(GEOM_Function)   anObjFun = aGeomObj->GetLastFunction();
       if ( !anObjFun.IsNull() )
         anObjFun->SetDescription( "" );
       if ( j > 0 )
@@ -1815,7 +1857,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr     theStu
       GEOM::GEOM_Object_var anObj = theArgs[ i ];
       if (CORBA::is_nil(anObj))
         continue;
-      Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
+      Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
       if ( j > 0 )
         pd << ", ";
       pd << aGeomObj;
@@ -1915,7 +1957,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr
             GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
             if (!CORBA::is_nil(anArgOTrsf)) {
               CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
-              Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
+              Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
               Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
               anArgOTrsfFun->SetDescription("");
               aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
@@ -2333,6 +2375,26 @@ GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theS
   return operations._retn();
 }
 
+//============================================================================
+// function : GetIFieldOperations
+// purpose  :
+//============================================================================
+GEOM::GEOM_IFieldOperations_ptr GEOM_Gen_i::GetIFieldOperations(CORBA::Long theStudyID)
+     throw ( SALOME::SALOME_Exception )
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  MESSAGE( "GEOM_Gen_i::GetIFieldOperations" );
+
+  GEOM::GEOM_Gen_ptr engine = _this();
+
+  GEOM_IFieldOperations_i* aServant =
+    new GEOM_IFieldOperations_i(_poa, engine, _impl->GetIFieldOperations(theStudyID));
+
+  // activate the CORBA servant
+  GEOM::GEOM_IFieldOperations_var operations = aServant->_this();
+  return operations._retn();
+}
+
 //============================================================================
 // function : GetPluginOperations
 // purpose  :
@@ -2342,7 +2404,7 @@ GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyI
      throw ( SALOME::SALOME_Exception )
 {
   std::string aPlatformLibName;
-#ifdef WNT
+#ifdef WIN32
   aPlatformLibName = theLibName;
   aPlatformLibName += ".dll" ;
 #else
@@ -2366,7 +2428,7 @@ GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyI
       LibHandle libHandle = LoadLib( aPlatformLibName.c_str()/*theLibName*/ );
       if (!libHandle) {
         // report any error, if occured
-#ifndef WNT
+#ifndef WIN32
         const char* anError = dlerror();
         throw(SALOME_Exception(anError));
 #else
@@ -2414,13 +2476,14 @@ GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyI
  *  AddSubShape
  */
 //=============================================================================
-GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
+GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr   theMainShape,
                                                const GEOM::ListOfLong& theIndices)
 {
   if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
     return GEOM::GEOM_Object::_nil();
   CORBA::String_var entry = theMainShape->GetEntry();
-  Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
+  Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast
+    ( _impl->GetObject( theMainShape->GetStudyID(), entry ));
   if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
 
   Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
@@ -2431,7 +2494,7 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShap
 
   TCollection_AsciiString anEntry;
   TDF_Tool::Entry(anObject->GetEntry(), anEntry);
-  return GetObject(anObject->GetDocID(), anEntry.ToCString());
+  return GEOM::GEOM_Object::_narrow( GetObject(anObject->GetDocID(), anEntry.ToCString()));
 }
 
 //=============================================================================
@@ -2439,25 +2502,23 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShap
  *  RemoveObject
  */
 //=============================================================================
-void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
+void GEOM_Gen_i::RemoveObject(GEOM::GEOM_BaseObject_ptr theObject)
 {
   CORBA::String_var anEntry = theObject->GetEntry();
-  Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
-  if (anObject.IsNull()) return;
-  _impl->RemoveObject(anObject);
-  return;
+  Handle(GEOM_BaseObject) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
+  if (!anObject.IsNull())
+    _impl->RemoveObject(anObject);
 }
 
-
 //=================================================================================
 // function : GetStringFromIOR()
 // purpose  : returns a string that represents  a 'GEOM::GEOM_Object_var'
 //=================================================================================
-char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
+char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject)
+{
   return _orb->object_to_string(theObject);
 }
 
-
 //=================================================================================
 // function : GetIORFromString()
 // purpose  : returns a 'GEOM::GEOM_Object_var' from a string representing it
@@ -2476,22 +2537,49 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
 // function : GetObject()
 // purpose  :
 //=================================================================================
-GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
+GEOM::GEOM_BaseObject_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
 {
-  GEOM::GEOM_Object_var obj;
-  Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
+  GEOM::GEOM_BaseObject_var obj;
+  Handle(GEOM_BaseObject) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
   if (handle_object.IsNull()) return obj._retn();
 
   TCollection_AsciiString stringIOR = handle_object->GetIOR();
   if (stringIOR.Length() > 1) {
     CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
-    if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
+    if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_BaseObject::_narrow(corba_object);
     return obj._retn();
   }
 
   GEOM::GEOM_Gen_ptr engine = _this();
   //transfer the reference to GEOM_Object_i
-  GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
+  GEOM_BaseObject_i* servant = 0;
+  switch( handle_object->GetType() ) {
+  case GEOM_FIELD: {
+    servant = new GEOM_Field_i (_poa, engine, Handle(GEOM_Field)::DownCast( handle_object ));
+    break;
+  }
+  case GEOM_FIELD_STEP: {
+    Handle(GEOM_FieldStep) step = Handle(GEOM_FieldStep)::DownCast( handle_object );
+    Handle(GEOM_Field)    field = step->GetField();
+    int type = ( !field.IsNull() ? field->GetDataType() : 0 );
+    switch( type ) {
+    case GEOM::FDT_Bool:
+      servant = new GEOM_BoolFieldStep_i (_poa, engine, step );
+      break;
+    case GEOM::FDT_Int:
+      servant = new GEOM_IntFieldStep_i (_poa, engine, step );
+      break;
+    case GEOM::FDT_Double:
+      servant = new GEOM_DoubleFieldStep_i (_poa, engine, step );
+      break;
+    default:
+      servant = new GEOM_StringFieldStep_i (_poa, engine, step );
+    }
+    break;
+  }
+  default:
+    servant = new GEOM_Object_i (_poa, engine, Handle(GEOM_Object)::DownCast( handle_object ));
+  }
   PortableServer::ObjectId_var id = _poa->activate_object(servant);
 
   obj = servant->_this();
@@ -2794,6 +2882,270 @@ 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 : 
+// purpose  : 
+//=======================================================================
+SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( SALOMEDS::Study_ptr theStudy,
+                                                 const GEOM::string_array& theObjectIORs ) {
+  // 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_Object_ptr anObj = GetIORFromString( ior.c_str() );
+    GEOMUtils::LevelsList upLevelList;
+    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 ) ) );
+  }
+
+  // translation the tree into string
+  std::string treeStr;
+  GEOMUtils::ConvertTreeToString( tree, treeStr );
+  
+  char* aBuffer = (char*)CORBA::string_dup(treeStr.c_str());
+  int aBufferSize = strlen((char*)aBuffer);
+
+  CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
+
+  SALOMEDS::TMPFile_var aStream = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
+
+  return aStream._retn();
+}
+
+//=======================================================================
+// function : 
+// purpose  : 
+//=======================================================================
+void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo, 
+                                     GEOMUtils::LevelsList &upLevelList, 
+                                     int level ) {
+  std::string aGboIOR = GetStringFromIOR(GEOM::GEOM_Object::_narrow(gbo));
+  GEOM::ListOfGBO_var depList = gbo->GetDependency();
+  for( int j = 0; j < depList->length(); j++ ) {
+    if ( level > 0 ) {
+      GEOMUtils::NodeLinks anIORs;
+      GEOMUtils::LevelInfo aLevelMap;
+      if ( level-1 >= upLevelList.size() ) {
+        upLevelList.push_back( aLevelMap );
+      } else {
+        aLevelMap = upLevelList.at(level-1);
+        if ( aLevelMap.count( aGboIOR ) > 0 )
+          anIORs = aLevelMap[ aGboIOR ];
+      }
+      anIORs.push_back( GetStringFromIOR(GEOM::GEOM_Object::_narrow(depList[j])) );
+      aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGboIOR, anIORs) );
+    }
+    getUpwardDependency(depList[j], upLevelList, level++);
+  }
+}
+
+//=======================================================================
+// function : 
+// purpose  : 
+//=======================================================================
+void GEOM_Gen_i::getDownwardDependency( SALOMEDS::Study_ptr theStudy,
+                                       GEOM::GEOM_BaseObject_ptr gbo, 
+                                       GEOMUtils::LevelsList &downLevelList, 
+                                       int level ) {
+  SALOMEDS::SComponent_var comp = theStudy->FindComponent("GEOM");
+  if ( !comp )
+    return;
+
+  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;
+
+    GEOM::ListOfGBO_var depList = geomObj->GetDependency();
+    if( depList->length() == 0 )
+      continue;
+    std::string aGoIOR = GetStringFromIOR( geomObj );
+
+    for( int i = 0; i < depList->length(); i++ ) {
+      if ( depList[i]->IsSame( gbo ) ) {
+       GEOMUtils::NodeLinks anIORs;
+        GEOMUtils::LevelInfo aLevelMap;
+        if ( level >= downLevelList.size() ) {
+          aLevelMap = GEOMUtils::LevelInfo();
+          downLevelList.push_back( aLevelMap );
+        } else {
+          aLevelMap = downLevelList.at(level);
+          if ( aLevelMap.count( aGoIOR ) > 0 )
+            anIORs = aLevelMap[ aGoIOR ];
+        }
+        anIORs.push_back( GetStringFromIOR(GEOM::GEOM_Object::_narrow(depList[i])));
+        aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGoIOR, anIORs) );
+      }
+    }
+    getDownwardDependency(theStudy, geomObj, downLevelList, level++);
+  }
+}
+
 //=====================================================================================
 // EXPORTED METHODS
 //=====================================================================================