Back to index

salome-geom  6.5.0
GEOM_Gen_i.cc
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifdef WNT
00024 #pragma warning( disable:4786 )
00025 #endif
00026 
00027 #include <Standard_Stream.hxx>
00028 
00029 #include "GEOM_Gen_i.hh"
00030 #include "GEOM_Object_i.hh"
00031 
00032 #include <set>
00033 #include <sstream>
00034 
00035 #include "Utils_CorbaException.hxx"
00036 #include "OpUtil.hxx"
00037 #include "Utils_ExceptHandlers.hxx"
00038 #include "utilities.h"
00039 
00040 #include "GEOM_Object_i.hh"
00041 #include "GEOM_Object.hxx"
00042 #include "GEOM_Function.hxx"
00043 #include "GEOM_ISubShape.hxx"
00044 #include <GEOM_PythonDump.hxx>
00045 #include "GEOMImpl_Types.hxx"
00046 #include "GEOMImpl_CopyDriver.hxx"
00047 
00048 // Cascade headers
00049 #include <BRep_Builder.hxx>
00050 #include <BRepTools.hxx>
00051 #include <TDF_Label.hxx>
00052 #include <TDF_Tool.hxx>
00053 #include <TDF_ChildIDIterator.hxx>
00054 #include <TNaming_NamedShape.hxx>
00055 #include <TDataStd_Name.hxx>
00056 #include <TCollection_AsciiString.hxx>
00057 #include <TColStd_HArray1OfInteger.hxx>
00058 #include <TopAbs_ShapeEnum.hxx>
00059 //#include <TopTools_IndexedMapOfShape.hxx>
00060 #include <TopExp.hxx>
00061 #include <OSD.hxx>
00062 
00063 #include "SALOMEDS_Tool.hxx"
00064 
00065 //============================================================================
00066 // function : GEOM_Gen_i()
00067 // purpose  : constructor to be called for servant creation.
00068 //============================================================================
00069 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr            orb,
00070                        PortableServer::POA_ptr   poa,
00071                        PortableServer::ObjectId* contId,
00072                        const char*               instanceName,
00073                        const char*               interfaceName) :
00074   Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
00075 {
00076   _thisObj = this;
00077   _id = _poa->activate_object(_thisObj);
00078   name_service = new SALOME_NamingService(_orb);
00079 
00080   _impl = new ::GEOMImpl_Gen;
00081 
00082   //PAL10867: disable signals catching with "noexcepthandler" option
00083   char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
00084   if (!envNoCatchSignals || !atoi(envNoCatchSignals))
00085   {
00086     //work around PAL12004, PAL12628
00087     //OSD::SetSignal( true );
00088     bool raiseFPE;
00089 #ifdef _DEBUG_
00090     raiseFPE = true;
00091     char* envDisableFPE = getenv("DISABLE_FPE");
00092     if (envDisableFPE && atoi(envDisableFPE))
00093       raiseFPE = false;
00094 #else
00095     raiseFPE = false;
00096 #endif
00097     OSD::SetSignal( raiseFPE );
00098   }
00099 }
00100 
00101 //============================================================================
00102 // function : ~GEOM_Gen_i()
00103 // purpose  : destructor
00104 //============================================================================
00105 GEOM_Gen_i::~GEOM_Gen_i() {
00106   delete name_service;
00107   delete _impl;
00108 }
00109 
00110 
00111 //============================================================================
00112 // function : IORToLocalPersistentID()
00113 // purpose  :
00114 //============================================================================
00115 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
00116                                          const char* IORString,
00117                                          CORBA::Boolean isMultiFile,
00118                                          CORBA::Boolean isASCII)
00119 {
00120   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
00121   if (!CORBA::is_nil(anObject)) {
00122     return CORBA::string_dup(anObject->GetEntry());
00123   }
00124   return 0;
00125 }
00126 
00127 
00128 //============================================================================
00129 // function : LocalPersistentIDToIOR()
00130 // purpose  : Create/Load CORBA object from a persistent ref (an entry)
00131 //          : Used when a study is loaded
00132 //          : The IOR (IORName) of object created is returned
00133 //============================================================================
00134 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
00135                                          const char* aLocalPersistentID,
00136                                          CORBA::Boolean isMultiFile,
00137                                          CORBA::Boolean isASCII)
00138 {
00139   SALOMEDS::Study_var aStudy = theSObject->GetStudy();
00140 
00141   Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
00142   TCollection_AsciiString anEntry;
00143   TDF_Tool::Entry(anObject->GetEntry(), anEntry);
00144   GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
00145 
00146   CORBA::String_var aPersRefString = _orb->object_to_string(obj);
00147   return CORBA::string_dup(aPersRefString);
00148 }
00149 
00150 //============================================================================
00151 // function : CanPublishInStudy
00152 // purpose  :
00153 //============================================================================
00154 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
00155 {
00156   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
00157   return !(anObject->_is_nil());
00158 }
00159 
00160 
00161 //============================================================================
00162 // function : PublishInStudy
00163 // purpose  :
00164 //============================================================================
00165 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
00166                                                  SALOMEDS::SObject_ptr theSObject,
00167                                                  CORBA::Object_ptr theObject,
00168                                                  const char* theName) throw (SALOME::SALOME_Exception)
00169 {
00170   Unexpect aCatch(SALOME_SalomeException);
00171   SALOMEDS::SObject_var aResultSO;
00172   if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
00173   GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
00174   if(aShape->_is_nil()) return aResultSO;
00175 
00176   SALOMEDS::GenericAttribute_var anAttr;
00177   SALOMEDS::StudyBuilder_var     aStudyBuilder = theStudy->NewBuilder();
00178 
00179   SALOMEDS::SComponent_var       aFather = theStudy->FindComponent("GEOM");
00180   if (aFather->_is_nil()) {
00181     aFather = aStudyBuilder->NewComponent("GEOM");
00182     anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
00183     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
00184     aName->SetValue("Geometry");
00185     aName->UnRegister();
00186     anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
00187     SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr);
00188     aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry");
00189     aPixMap->UnRegister();
00190     aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this());
00191   }
00192   if (aFather->_is_nil()) return aResultSO;
00193 
00194   if (CORBA::is_nil(theSObject)) {
00195     aResultSO = aStudyBuilder->NewObject(aFather);
00196   } else {
00197     if (!theSObject->ReferencedObject(aResultSO))
00198       aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for  the method AddInStudy with theFather argumenet != NULL
00199       //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
00200   }
00201   CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
00202   aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
00203 
00204   TCollection_AsciiString aShapeName("Shape_");
00205 
00206   CORBA::Long mytype=aShape->GetType();
00207   if ( mytype == GEOM_GROUP ) {
00208     GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
00209     switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
00210     case TopAbs_VERTEX:
00211       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" );
00212       aShapeName = "Group_Of_Vertices_";
00213       break;
00214     case TopAbs_EDGE:
00215       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE");
00216       aShapeName = "Group_Of_Edges_";
00217       break;
00218     case TopAbs_FACE:
00219       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE");
00220       aShapeName = "Group_Of_Faces_";
00221       break;
00222     case TopAbs_SOLID:
00223       aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID");
00224       aShapeName = "Group_Of_Solids_";
00225       break;
00226     }
00227   } else if ( mytype == GEOM_MARKER ) {
00228     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
00229     aShapeName = "LocalCS_";
00230   } else if ( mytype > ADVANCED_BASE ) {
00231     char buf[20];
00232     sprintf( buf, "%d", aShape->GetType() );
00233     std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
00234     aResultSO->SetAttrString("AttributePixMap",advId.c_str());
00235     aShapeName = "Advanced_";
00236   } else {
00237     GEOM::shape_type myshapetype=aShape->GetShapeType();
00238     if ( myshapetype == GEOM::COMPOUND ) {
00239     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" );
00240     aShapeName = "Compound_";
00241   } else if ( myshapetype == GEOM::COMPSOLID ) {
00242     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID");
00243     aShapeName = "Compsolid_";
00244   } else if ( myshapetype == GEOM::SOLID ) {
00245     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID");
00246     aShapeName = "Solid_";
00247   } else if ( myshapetype == GEOM::SHELL ) {
00248     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL");
00249     aShapeName = "Shell_";
00250   } else if ( myshapetype == GEOM::FACE ) {
00251     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE");
00252     aShapeName = "Face_";
00253   } else if ( myshapetype == GEOM::WIRE ) {
00254     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE");
00255     aShapeName = "Wire_";
00256   } else if ( myshapetype == GEOM::EDGE ) {
00257     aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE");
00258     aShapeName = "Edge_";
00259   } else if ( myshapetype == GEOM::VERTEX ) {
00260     aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_VERTEX" );
00261     aShapeName = "Vertex_";
00262   }
00263   }
00264   //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
00265   //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
00266 
00267   // BEGIN: try to find existed name for current shape
00268   bool HasName = false;
00269   // recieve current TopoDS shape
00270   CORBA::String_var entry = aShape->GetEntry();
00271   Handle(GEOM_Object) aGShape = _impl->GetObject(aShape->GetStudyID(), entry);
00272   TopoDS_Shape TopoSh = aGShape->GetValue();
00273   // find label of main shape
00274   GEOM::GEOM_Object_var aMainSh = aShape;
00275   while( !aMainSh->IsMainShape() ) {
00276     aMainSh = aMainSh->GetMainShape();
00277   }
00278   entry = aMainSh->GetEntry();
00279   Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry);
00280   TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
00281 
00282   // check all named shapes using iterator
00283   TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
00284 
00285   for (; anIt.More() && !HasName; anIt.Next()) {
00286     Handle(TNaming_NamedShape) anAttr =
00287       Handle(TNaming_NamedShape)::DownCast(anIt.Value());
00288     if (anAttr.IsNull()) continue;
00289     TopoDS_Shape S = anAttr->Get();
00290     if (S.IsEqual(TopoSh)) {
00291       TDF_Label L = anAttr->Label();
00292       Handle(TDataStd_Name) aName;
00293       if (L.FindAttribute(TDataStd_Name::GetID(), aName)) {
00294         aShapeName = aName->Get();
00295         HasName = true;
00296       }
00297     }
00298   }
00299   // END: try to find existed name for current shape
00300 
00301   if (!HasName) {
00302     // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
00303     //       it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
00304     //       of objects in the study, but compute a number of objects with the same prefix
00305     //       and build a new name as Prefix_N+1
00306     if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
00307       int i = 0;                    // (WITH EMPTY NEW NAME)
00308       SALOMEDS::SObject_var obj;
00309       TCollection_AsciiString aNewShapeName;
00310       do {
00311         aNewShapeName = aShapeName + TCollection_AsciiString(++i);
00312         obj = theStudy->FindObject( aNewShapeName.ToCString() );
00313       }
00314       while ( !obj->_is_nil() );
00315       aShapeName = aNewShapeName;
00316     }
00317     else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
00318       aShapeName = TCollection_AsciiString((char*)theName);
00319   }
00320 
00321   //Set the study entry as a name of  the published GEOM_Object
00322   CORBA::String_var anID =aResultSO->GetID();
00323   aShape->SetStudyEntry(anID.in());
00324 
00325   //Set a name of the added shape
00326   aResultSO->SetAttrString("AttributeName",aShapeName.ToCString());
00327 
00328   //Set NoteBook variables used in the object creation
00329   TCollection_AsciiString aVars;
00330   CORBA::String_var aString=aShape->GetParameters();
00331   SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString);
00332   for(int i = 0, n = aSections->length(); i < n; i++) {
00333     SALOMEDS::ListOfStrings aListOfVars = aSections[i];
00334     for(int j = 0, m = aListOfVars.length(); j < m; j++) {
00335       if(theStudy->IsVariable(aListOfVars[j].in()))
00336         aVars += TCollection_AsciiString(aListOfVars[j].in());
00337       if(j != m-1)
00338         aVars += ":";
00339     }
00340     if(i != n-1)
00341       aVars += "|";
00342   }
00343   aResultSO->SetAttrString("AttributeString",aVars.ToCString());
00344 
00345   aFather->UnRegister();
00346 
00347   //Set a name of the GEOM object
00348   aShape->SetName(aShapeName.ToCString());
00349 
00350   return aResultSO._retn();
00351 }
00352 
00353 
00354 //============================================================================
00355 // function : CreateAndPublishGroup
00356 // purpose  : auxilary for PublishNamedShapesInStudy
00357 //============================================================================
00358 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
00359                                        GEOM::GEOM_Object_var theMainShape,
00360                                        const TopTools_IndexedMapOfShape& anIndices,
00361                                        const TopTools_SequenceOfShape& SeqS,
00362                                        const TColStd_SequenceOfAsciiString& SeqN,
00363                                        const Standard_CString& GrName,
00364                                        GEOM::ListOfGO_var aResList)
00365 {
00366   CORBA::String_var entry = theMainShape->GetEntry();
00367   Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
00368   Handle(TColStd_HArray1OfInteger) anArray;
00369   if(SeqS.Length()>0) {
00370     // create a group
00371     GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
00372     GEOM::GEOM_Object_ptr GrObj =
00373       GOp->CreateGroup( theMainShape, SeqS.Value(1).ShapeType() );
00374     AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
00375     CORBA::String_var GrEntry = GrObj->GetEntry();
00376     Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
00377     // add named objects
00378     //Handle(GEOM_Object) anObj;
00379     for(int i=1; i<=SeqS.Length(); i++) {
00380       TopoDS_Shape aValue = SeqS.Value(i);
00381       //anArray = new TColStd_HArray1OfInteger(1,1);
00382       Standard_Integer anIndex = anIndices.FindIndex(aValue);
00383       //anArray->SetValue(1, anIndex);
00384       GOp->AddObject(GrObj,anIndex);
00385       //anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
00386       //if (anObj.IsNull()) continue;
00387       //Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
00388       //if (aFunction.IsNull()) continue;
00389       //GEOM_ISubShape aSSI(aFunction);
00390       //aSSI.SetMainShape(aMainShape->GetLastFunction());
00391       //aSSI.SetIndices(anArray);
00392       //aFunction->SetValue(aValue);
00393       //GOp->UnionIDs(GrObj, anIndex);
00394       //SALOMEDS::SObject_var aResultSO;
00395       //TCollection_AsciiString anEntry;
00396       //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
00397       //GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
00398       //AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
00399     }
00400   }
00401 }
00402 
00403 
00404 //============================================================================
00405 // function : PublishNamedShapesInStudy
00406 // purpose  :
00407 //============================================================================
00408 GEOM::ListOfGO* GEOM_Gen_i::
00409             PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
00410                                       //SALOMEDS::SObject_ptr theSObject,
00411                                       CORBA::Object_ptr theObject)
00412 {
00413   //Unexpect aCatch(SALOME_SalomeException);
00414   GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
00415 
00416   //CORBA::Object_var theObject = theSObject->GetObject();
00417   GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
00418   if(theMainShape->_is_nil()) return aResList._retn();
00419 
00420   CORBA::String_var entry = theMainShape->GetEntry();
00421   Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
00422   if (aMainShape.IsNull()) return aResList._retn();
00423   TopoDS_Shape MainSh = aMainShape->GetValue();
00424 
00425   TDF_Label aMainLbl = aMainShape->GetEntry();
00426   TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
00427   TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
00428   TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
00429   for(; anIt.More(); anIt.Next()) {
00430     Handle(TNaming_NamedShape) anAttr =
00431       Handle(TNaming_NamedShape)::DownCast(anIt.Value());
00432     if(anAttr.IsNull()) continue;
00433     TopoDS_Shape S = anAttr->Get();
00434     TDF_Label L = anAttr->Label();
00435     //if(S.IsEqual(MainSh)) continue;
00436     Handle(TDataStd_Name) aName;
00437     if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
00438       TCollection_ExtendedString EName = aName->Get();
00439       if(S.ShapeType()==TopAbs_SOLID) {
00440         SolidSeqS.Append(S);
00441         SolidSeqN.Append(aName->Get());
00442       }
00443       else if(S.ShapeType()==TopAbs_FACE) {
00444         FaceSeqS.Append(S);
00445         FaceSeqN.Append(aName->Get());
00446       }
00447       else if(S.ShapeType()==TopAbs_EDGE) {
00448         EdgeSeqS.Append(S);
00449         EdgeSeqN.Append(aName->Get());
00450       }
00451       else if(S.ShapeType()==TopAbs_VERTEX) {
00452         VertSeqS.Append(S);
00453         VertSeqN.Append(aName->Get());
00454       }
00455     }
00456   }
00457 
00458   TopTools_IndexedMapOfShape anIndices;
00459   TopExp::MapShapes(MainSh, anIndices);
00460 
00461   CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
00462                         "Group_Of_Named_Solids", aResList);
00463 
00464   CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
00465                         "Group_Of_Named_Faces", aResList);
00466 
00467   CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
00468                         "Group_Of_Named_Edges", aResList);
00469 
00470   CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
00471                         "Group_Of_Named_Vertices", aResList);
00472 
00473   return aResList._retn();
00474 }
00475 
00476 
00477 //============================================================================
00478 // function : Save()
00479 // purpose  : save OCAF/Geom document
00480 //============================================================================
00481 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
00482                                     const char* theURL,
00483                                     bool isMultiFile) {
00484   SALOMEDS::TMPFile_var aStreamFile;
00485   // Get a temporary directory to store a file
00486   std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
00487 
00488   // OCCT BUG: cannot save a document (in current folder)
00489   // if directory name is empty
00490   if (aTmpDir.size() == 0) {
00491 #ifdef WNT
00492     aTmpDir = ".\\";
00493 #else
00494     aTmpDir = "./";
00495 #endif
00496   }
00497 
00498   // Create a list to store names of created files
00499   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
00500   aSeq->length(1);
00501   // Prepare a file name to open
00502   TCollection_AsciiString aNameWithExt("");
00503   if (isMultiFile)
00504     aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
00505                                                    (theComponent->GetStudy()->URL())).c_str());
00506   aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
00507   aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
00508   // Build a full file name of temporary file
00509   TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
00510   // Save GEOM component in this file
00511   _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
00512   // Conver a file to the byte stream
00513   aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
00514   // Remove the created file and tmp directory
00515   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
00516 
00517   // Return the created byte stream
00518   return aStreamFile._retn();
00519 }
00520 
00521 
00522 //============================================================================
00523 // function : SaveASCII()
00524 // purpose  :
00525 //============================================================================
00526 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
00527                                          const char* theURL,
00528                                          bool isMultiFile) {
00529   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
00530   return aStreamFile._retn();
00531 }
00532 
00533 
00534 //============================================================================
00535 // function : Load()
00536 // purpose  :
00537 //============================================================================
00538 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
00539                                 const SALOMEDS::TMPFile& theStream,
00540                                 const char* theURL,
00541                                 bool isMultiFile) {
00542 
00543   if (theStream.length() <= 9) {
00544     MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
00545     return false;
00546   }
00547 
00548   // Get a temporary directory for a file
00549   std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
00550 
00551   // OCCT BUG: cannot load a document (from current folder)
00552   // if directory name is empty
00553   if (aTmpDir.size() == 0) {
00554 #ifdef WNT
00555     aTmpDir = ".\\";
00556 #else
00557     aTmpDir = "./";
00558 #endif
00559   }
00560 
00561   // Conver the byte stream theStream to a file and place it in tmp directory
00562   SALOMEDS::ListOfFileNames_var aSeq =
00563     SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
00564 
00565   // Prepare a file name to open
00566   TCollection_AsciiString aNameWithExt("");
00567   if (isMultiFile)
00568     aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
00569                                                    (theComponent->GetStudy()->URL())).c_str());
00570   aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
00571   TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
00572 
00573   // Open document
00574   if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
00575 
00576   // Remove the created file and tmp directory
00577   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
00578 
00579   SALOMEDS::Study_var Study = theComponent->GetStudy();
00580   TCollection_AsciiString name (Study->Name());
00581 
00582   return true;
00583 }
00584 
00585 
00586 //============================================================================
00587 // function : LoadASCII()
00588 // purpose  :
00589 //============================================================================
00590 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
00591                                      const SALOMEDS::TMPFile& theStream,
00592                                      const char* theURL,
00593                                      bool isMultiFile) {
00594   return Load(theComponent, theStream, theURL, isMultiFile);
00595 }
00596 
00597 
00598 //============================================================================
00599 // function : Close()
00600 // purpose  :
00601 //============================================================================
00602 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
00603 {
00604   SALOMEDS::Study_var aStudy= theComponent->GetStudy();
00605   _impl->Close(aStudy->StudyId());
00606 }
00607 
00608 //============================================================================
00609 // function : CanCopy()
00610 // purpose  :
00611 //============================================================================
00612 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
00613   // Try to retrieve known by Geometry component GEOM_Object by given IOR
00614   SALOMEDS::GenericAttribute_var anAttr;
00615   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
00616 
00617   SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
00618 
00619   CORBA::String_var aString=anIOR->Value();
00620   anIOR->UnRegister();
00621   CORBA::Object_var anObj = _orb->string_to_object(aString);
00622   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
00623   // If the object is null one it can't be copied: return false
00624   if (anObject->_is_nil()) return false;
00625   return true;
00626 }
00627 
00628 //============================================================================
00629 // function : CopyFrom()
00630 // purpose  :
00631 //============================================================================
00632 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
00633 {
00634   // Declare a sequence of the byte to store the copied object
00635   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
00636 
00637   // Try to get GEOM_Object object by given SObject
00638   SALOMEDS::GenericAttribute_var anAttr;
00639   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
00640   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
00641     (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
00642   if (anObject->_is_nil()) return aStreamFile._retn();
00643 
00644   aStreamFile = anObject->GetShapeStream();
00645 
00646   // Assign an ID  the type of  GEOM_Object
00647   theObjectID = anObject->GetType();
00648 
00649   // Return created TMPFile
00650   return aStreamFile._retn();
00651 }
00652 
00653 //============================================================================
00654 // function : CanPaste()
00655 // purpose  :
00656 //============================================================================
00657 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
00658   // The Geometry component can paste only objects copied by Geometry component
00659   // and with the object type = 1
00660   if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
00661   return true;
00662 }
00663 
00664 //============================================================================
00665 // function : PasteInto()
00666 // purpose  :
00667 //============================================================================
00668 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
00669                                             CORBA::Long theObjectID,
00670                                             SALOMEDS::SObject_ptr theObject) {
00671   // Find the current Study and StudyBuilder
00672   SALOMEDS::Study_var aStudy = theObject->GetStudy();
00673   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
00674 
00675   // Retrieve a TopoDS_Shape from byte stream
00676   TopoDS_Shape aTopology;
00677   std::istringstream aStreamedBrep((char*) &theStream[0]);
00678   BRep_Builder aBuilder;
00679   try {
00680     BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
00681   } catch (Standard_Failure) {
00682     return false;
00683   }
00684 
00685   // SObject of the created shape is theObject or new Child of Component if theObject == geom component
00686   SALOMEDS::SObject_var aNewSO;
00687   if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
00688     aNewSO = aStudyBuilder->NewObject(theObject);
00689   } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
00690 
00691 
00692   //Create a new GEOM_Object
00693   Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
00694   Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
00695   aFunction->SetValue(aTopology);
00696 
00697   TCollection_AsciiString anEntry;
00698   TDF_Tool::Entry(anObj->GetEntry(), anEntry);
00699   GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
00700 
00701   //Set the study entry of the published GEOM_Object
00702   obj->SetStudyEntry(aNewSO->GetID());
00703 
00704   // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
00705   SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
00706   SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
00707   CORBA::String_var objStr = _orb->object_to_string(obj);
00708   anIOR->SetValue(objStr.in());
00709   anIOR->UnRegister();
00710 
00711   // Return the created in the Study SObject
00712   return aNewSO._retn();
00713 }
00714 
00715 //============================================================================
00716 // function : ComponentDataType()
00717 // purpose  :
00718 //============================================================================
00719 char* GEOM_Gen_i::ComponentDataType()
00720 {
00721   return CORBA::string_dup("GEOM");
00722 }
00723 
00724 //============================================================================
00725 // function : AddInStudy
00726 // purpose  :
00727 //============================================================================
00728 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
00729                                               GEOM::GEOM_Object_ptr theObject,
00730                                               const char* theName,
00731                                               GEOM::GEOM_Object_ptr theFather)
00732 {
00733   SALOMEDS::SObject_var aResultSO;
00734   if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
00735 
00736   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
00737   CORBA::String_var IOR;
00738 
00739   if(!theFather->_is_nil()) {
00740     IOR = _orb->object_to_string(theFather);
00741     SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
00742     if(aFatherSO->_is_nil()) return aResultSO._retn();
00743     aResultSO = aStudyBuilder->NewObject(aFatherSO);
00744     aFatherSO->UnRegister();
00745     //aStudyBuilder->Addreference(aResultSO, aResultSO);
00746   }
00747 
00748   aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
00749   if(aResultSO->_is_nil()) return aResultSO._retn();
00750 
00751   GEOM::ListOfGO_var aList = theObject->GetDependency();
00752   Standard_Integer aLength = aList->length();
00753   if(aLength < 1) return aResultSO._retn();
00754 
00755   //Publish the arguments
00756   for(Standard_Integer i = 0; i< aLength; i++) {
00757     GEOM::GEOM_Object_var anObject = aList[i];
00758     if(anObject->_is_nil()) continue;
00759     IOR = _orb->object_to_string(anObject);
00760     SALOMEDS::SObject_var aSO =  theStudy->FindObjectIOR(IOR.in());
00761     if(aSO->_is_nil()) continue;
00762     SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
00763     aStudyBuilder->Addreference(aSubSO, aSO);
00764     aSO->UnRegister();
00765     aSubSO->UnRegister();
00766   }
00767 
00768   return aResultSO._retn();
00769 }
00770 
00771 //============================================================================
00772 // function : RestoreSubShapesO
00773 // purpose  : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
00774 //            To be used from python scripts out of geompy.addToStudy (non-default usage)
00775 //============================================================================
00776 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr     theStudy,
00777                                                GEOM::GEOM_Object_ptr   theObject,
00778                                                const GEOM::ListOfGO&   theArgs,
00779                                                GEOM::find_shape_method theFindMethod,
00780                                                CORBA::Boolean          theInheritFirstArg,
00781                                                CORBA::Boolean          theAddPrefix)
00782 {
00783   GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
00784   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
00785     return aParts._retn();
00786 
00787   // find SObject in the study if it is already published
00788   CORBA::String_var anIORo = _orb->object_to_string(theObject);
00789   SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
00790   //PTv, IMP 0020001, The salome object <aSO>
00791   // is not obligatory in case of invokation from script
00792   // if (CORBA::is_nil(aSO))
00793   //  return aParts._retn();
00794 
00795   aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs,
00796                             theFindMethod, theInheritFirstArg, theAddPrefix);
00797   if (!CORBA::is_nil(aSO)) aSO->UnRegister();
00798   return aParts._retn();
00799 }
00800 
00801 //============================================================================
00802 // function : RestoreGivenSubShapesO
00803 // purpose  : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
00804 //            To be used from python scripts, generated by Dump Python.
00805 //============================================================================
00806 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr     theStudy,
00807                                                     GEOM::GEOM_Object_ptr   theObject,
00808                                                     const GEOM::ListOfGO&   theArgs,
00809                                                     GEOM::find_shape_method theFindMethod,
00810                                                     CORBA::Boolean          theInheritFirstArg,
00811                                                     CORBA::Boolean          theAddPrefix)
00812 {
00813   GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
00814   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
00815     return aParts._retn();
00816 
00817   // find SObject in the study if it is already published
00818   CORBA::String_var anIORo = _orb->object_to_string(theObject);
00819   SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
00820   //PTv, IMP 0020001, The salome object <aSO>
00821   // is not obligatory in case of invokation from script
00822   // if (CORBA::is_nil(aSO))
00823   //  return aParts._retn();
00824 
00825   aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs,
00826                                  theFindMethod, theInheritFirstArg, theAddPrefix);
00827   if (!CORBA::is_nil(aSO)) aSO->UnRegister();
00828   return aParts._retn();
00829 }
00830 
00831 //============================================================================
00832 // function : RestoreSubShapesSO
00833 // purpose  : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
00834 //            To be used from GUI and from geompy.addToStudy
00835 //============================================================================
00836 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr     theStudy,
00837                                                 SALOMEDS::SObject_ptr   theSObject,
00838                                                 const GEOM::ListOfGO&   theArgs,
00839                                                 GEOM::find_shape_method theFindMethod,
00840                                                 CORBA::Boolean          theInheritFirstArg,
00841                                                 CORBA::Boolean          theAddPrefix)
00842 {
00843   GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
00844   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
00845     return aParts._retn();
00846 
00847   SALOMEDS::GenericAttribute_var anAttr;
00848   if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
00849     return aParts._retn();
00850 
00851   SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
00852   CORBA::String_var anIORso = anAttrIOR->Value();
00853 
00854   // get Object from SObject
00855   GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
00856   if (CORBA::is_nil(anO))
00857     return aParts._retn();
00858 
00859   aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs,
00860                             theFindMethod, theInheritFirstArg, theAddPrefix);
00861   return aParts._retn();
00862 }
00863 
00864 //============================================================================
00865 // function : addToListOfGO
00866 // purpose  : static local function
00867 //============================================================================
00868 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
00869                            GEOM::ListOfGO& theList )
00870 {
00871   const int oldLen = theList.length();
00872   theList.length(oldLen + 1);
00873   theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
00874 }
00875 
00876 //============================================================================
00877 // function : addToListOfGO
00878 // purpose  : static local function
00879 //============================================================================
00880 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
00881                            GEOM::ListOfGO& theTrgList )
00882 {
00883   const int oldLen = theTrgList.length();
00884   const int srcLen = theSrcList.length();
00885   theTrgList.length(oldLen + srcLen);
00886   for( int i = 0; i < srcLen; i++ )
00887     theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
00888 }
00889 
00890 //============================================================================
00891 // function : RestoreSubShapes
00892 // purpose  : Private method. Works only if both theObject and theSObject
00893 //            are defined, and does not check, if they correspond to each other.
00894 //============================================================================
00895 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr     theStudy,
00896                                              GEOM::GEOM_Object_ptr   theObject,
00897                                              SALOMEDS::SObject_ptr   theSObject,
00898                                              const GEOM::ListOfGO&   theArgs,
00899                                              GEOM::find_shape_method theFindMethod,
00900                                              CORBA::Boolean          theInheritFirstArg,
00901                                              CORBA::Boolean          theAddPrefix)
00902 {
00903   GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
00904   //PTv, IMP 0020001, The salome object <theSObject>
00905   //     is not obligatory in case of invokation from script
00906   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
00907     return aParts._retn();
00908 
00909   // For Dump Python (mantis issue 0020768)
00910   GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
00911 
00912   // Arguments to be published
00913   GEOM::ListOfGO_var aList;
00914 
00915   // If theArgs list is empty, we try to publish all arguments,
00916   // otherwise publish only passed args
00917   Standard_Integer nbArgsActual = -1; // -1 means unknown
00918   Standard_Integer aLength = theArgs.length();
00919   if (aLength > 0) {
00920     aList = new GEOM::ListOfGO;
00921     aList->length(aLength);
00922     for (int i = 0; i < aLength; i++) {
00923       aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
00924     }
00925   }
00926   else {
00927     // Get all arguments
00928     aList = theObject->GetDependency();
00929     aLength = aList->length();
00930     nbArgsActual = aLength;
00931   }
00932 
00933   if (aLength < 1)
00934     return aParts._retn();
00935 
00936   if (theInheritFirstArg || (nbArgsActual == 1)) {
00937     // Do not publish argument's reflection,
00938     // but only reconstruct its published sub-shapes
00939 
00940     CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
00941     SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
00942 
00943     // remember restored objects for Python Dump
00944     addToListOfGO(aList[0], anOutArgs);
00945 
00946     aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
00947                                       anOutArgs, theFindMethod, theAddPrefix);
00948 
00949     // set the color of the transformed shape to the color of initial shape
00950     theObject->SetColor(aList[0]->GetColor());
00951     // set the texture
00952     if (theObject->GetShapeType() == GEOM::VERTEX) {
00953       theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
00954       if (aList[0]->GetMarkerType() == GEOM::MT_USER)
00955         theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
00956     }
00957 
00958     anArgSO->UnRegister();
00959   }
00960   else {
00961     // Get interface, containing method, which we will use to reconstruct sub-shapes
00962     GEOM::GEOM_IShapesOperations_var  aShapesOp = GetIShapesOperations(theStudy->StudyId());
00963     GEOM::GEOM_IGroupOperations_var    aGroupOp = GetIGroupOperations(theStudy->StudyId());
00964     GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
00965 
00966     // Reconstruct arguments and tree of sub-shapes of the arguments
00967     CORBA::String_var anIOR;
00968     SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
00969     for (Standard_Integer i = 0; i < aLength; i++)
00970     {
00971       GEOM::GEOM_Object_var anArgO = aList[i];
00972       if (!CORBA::is_nil(anArgO)) {
00973         anIOR = _orb->object_to_string(anArgO);
00974         SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
00975         TCollection_AsciiString anArgName;
00976         if (CORBA::is_nil(anArgSO)) {
00977           anArgName = "arg_";
00978           anArgName += TCollection_AsciiString(i);
00979         }
00980         else {
00981           anArgName = anArgSO->GetName();
00982         }
00983 
00984         // Find a sub-shape of theObject in place of the argument
00985         GEOM::GEOM_Object_var aSubO;
00986         switch (theFindMethod) {
00987         case GEOM::FSM_GetInPlace:
00988           {
00989             // Use GetInPlace
00990             aSubO = aShapesOp->GetInPlace(theObject, anArgO);
00991           }
00992           break;
00993         case GEOM::FSM_MultiTransformed:
00994           {
00995             // Only for Multi-transformations
00996             GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anArgO, theObject);
00997             if (!CORBA::is_nil(anArgOTrsf)) {
00998               CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
00999               Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
01000               Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
01001               anArgOTrsfFun->SetDescription("");
01002               aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
01003             }
01004             /*
01005             Handle(GEOM_Function) anOFun = theObject->GetLastFunction();
01006             if (!anOFun.IsNull()) {
01007               CORBA::String_var entryArg = anArgO->GetEntry();
01008               Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg);
01009               if (!anArgOImpl.IsNull()) {
01010                 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
01011                 TopoDS_Shape aMultiArgShape;
01012                 //GEOM::GEOM_Object_var anArgOMulti; // ???
01013                 switch (anOFun->GetType()) {
01014                 case TRANSLATE_1D:
01015                   {
01016                     GEOMImpl_ITranslate aTI (anOFun);
01017                     aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
01018                     //anArgOMulti = aTrsfOp->Translate1D(anArgO, , , );
01019                   }
01020                   break;
01021                 case TRANSLATE_2D:
01022                   {
01023                     GEOMImpl_ITranslate aTI (anOFun);
01024                     aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
01025                   }
01026                   break;
01027                 case ROTATE_1D:
01028                   {
01029                     GEOMImpl_IRotate aTI (anOFun);
01030                     //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
01031                   }
01032                   break;
01033                 case ROTATE_2D:
01034                   {
01035                     GEOMImpl_IRotate aTI (anOFun);
01036                     //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
01037                   }
01038                   break;
01039                 default:
01040                   {}
01041                 }
01042                 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
01043                 Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
01044                 anArgOMultiFun->SetDescription("");
01045                 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
01046               }
01047             }
01048             */
01049           }
01050           break;
01051         case GEOM::FSM_Transformed:
01052           {
01053             // transformation, cannot use GetInPlace, operate with indices
01054             GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
01055             if (anIDs->length() > 1) {
01056               // group
01057               aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
01058               if (!CORBA::is_nil(aSubO))
01059                 aGroupOp->UnionIDs(aSubO, anIDs);
01060             }
01061             else if (anIDs->length() > 0) {
01062               // single sub-shape
01063               aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
01064             }
01065           }
01066           break;
01067         case GEOM::FSM_GetSame:
01068           {
01069             // Use GetSame
01070             aSubO = aShapesOp->GetSame(theObject, anArgO);
01071           }
01072           break;
01073         case GEOM::FSM_GetShapesOnShape:
01074           {
01075             // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
01076             aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
01077               (short)GEOM::SOLID, GEOM::ST_ONIN);
01078           }
01079           break;
01080         case GEOM::FSM_GetInPlaceByHistory:
01081           {
01082             // Use GetInPlaceByHistory
01083             aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
01084           }
01085           break;
01086         default:
01087           {}
01088         }
01089 
01090         if (!CORBA::is_nil(aSubO)) {
01091           // remember restored objects for Python Dump
01092           addToListOfGO(anArgO, anOutArgs);
01093 
01094           // add to parts list
01095           addToListOfGO( aSubO, aParts );
01096 
01097           // Publish the sub-shape
01098           SALOMEDS::SObject_var aSubSO;
01099           if (!CORBA::is_nil(theSObject)) {
01100             TCollection_AsciiString aSubName;
01101             if (theAddPrefix) {
01102               aSubName = "from_";
01103             }
01104             aSubName += anArgName;
01105             aSubSO = aStudyBuilder->NewObject(theSObject);
01106             aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
01107             // Restore color
01108             aSubO->SetColor(anArgO->GetColor());
01109             // set the texture
01110             if (aSubO->GetShapeType() == GEOM::VERTEX) {
01111               aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
01112               if (anArgO->GetMarkerType() == GEOM::MT_USER)
01113                 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
01114             }
01115           }
01116 
01117           if (!CORBA::is_nil(anArgSO)) {
01118             // Restore published sub-shapes of the argument
01119             GEOM::ListOfGO_var aSubParts;
01120             if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
01121               // pass theObject, because only it has the history
01122               aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
01123                                                    theObject, anOutArgs, theFindMethod, theAddPrefix);
01124             else
01125               aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
01126                                                    aSubO, anOutArgs, theFindMethod, theAddPrefix);
01127             // add to parts list
01128             addToListOfGO( aSubParts, aParts );
01129           }
01130         }
01131         else { // GetInPlace failed, try to build from published parts
01132           if (!CORBA::is_nil(anArgSO)) {
01133             SALOMEDS::SObject_var aSubSO;
01134             if (!CORBA::is_nil(theSObject))
01135               aSubSO = aStudyBuilder->NewObject(theSObject);
01136 
01137             // Restore published sub-shapes of the argument
01138             GEOM::ListOfGO_var aSubParts =
01139               RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
01140                                        theObject, anOutArgs, theFindMethod, theAddPrefix);
01141 
01142             // add to parts list
01143             addToListOfGO( aSubParts, aParts );
01144 
01145             if (aSubParts->length() > 0) {
01146               // remember restored objects for Python Dump
01147               addToListOfGO(anArgO, anOutArgs);
01148 
01149               // try to build an argument from a set of its sub-shapes,
01150               // that published and will be reconstructed
01151               if (aSubParts->length() > 1) {
01152                 aSubO = aShapesOp->MakeCompound(aSubParts);
01153                 // add to parts list
01154                 addToListOfGO( aSubO, aParts );
01155               }
01156               else {
01157                 aSubO = aSubParts[0];
01158               }
01159               if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
01160                 // Publish the sub-shape
01161                 TCollection_AsciiString aSubName;
01162                 if (theAddPrefix) {
01163                   aSubName = "from_parts_of_";
01164                 }
01165                 aSubName += anArgName;
01166                 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
01167                 // Restore color
01168                 aSubO->SetColor(anArgO->GetColor());
01169                 // set the texture
01170                 if (aSubO->GetShapeType() == GEOM::VERTEX) {
01171                   aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
01172                   if (anArgO->GetMarkerType() == GEOM::MT_USER)
01173                     aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
01174                 }
01175               }
01176             }
01177             else if (!CORBA::is_nil(aSubSO)) {
01178               // remove created aSubSO, because no parts have been found
01179               aStudyBuilder->RemoveObject(aSubSO);
01180             }
01181           }
01182         } // try to build from published parts
01183         anArgSO->UnRegister();
01184       }
01185     } // process arguments
01186   }
01187   std::set<std::string> anObjEntryMap;
01188   GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
01189   int nbRes = 0;
01190   int nb = aParts->length();
01191   aResParts->length(nb);
01192   if (nb > 0)
01193   {
01194     Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
01195     Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
01196     GEOM::TPythonDump pd (aFunction, true);
01197     pd <<"[";
01198     int i = 0, j = 0;
01199     for ( ; i < nb; i++ )
01200     {
01201       GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
01202       if (CORBA::is_nil(anObj))
01203         continue;
01204       char* anEntry = anObj->GetEntry();
01205       if (anObjEntryMap.count(anEntry))
01206         continue; // already treated
01207       anObjEntryMap.insert(anEntry);
01208       aResParts[nbRes++] = anObj;
01209       // clear python dump of object
01210       Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
01211       Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
01212       if ( !anObjFun.IsNull() )
01213         anObjFun->SetDescription( "" );
01214       if ( j > 0 )
01215         pd << ", ";
01216       pd << aGeomObj;
01217       j++;
01218     }
01219     pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
01220     //i = 0; nb = theArgs.length(); j = 0;
01221     i = 0; nb = anOutArgs->length(); j = 0;
01222     for ( ; i < nb; i++ )
01223     {
01224       //GEOM::GEOM_Object_var anObj = theArgs[ i ];
01225       GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
01226       if (CORBA::is_nil(anObj))
01227         continue;
01228       Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
01229       if ( j > 0 )
01230         pd << ", ";
01231       pd << aGeomObj;
01232       j++;
01233     }
01234     pd <<"]" << ", " <<"geompy.GEOM.";
01235     switch (theFindMethod) {
01236     case GEOM::FSM_GetInPlace:
01237       pd << "FSM_GetInPlace"; break;
01238     case GEOM::FSM_MultiTransformed:
01239       pd << "FSM_MultiTransformed"; break;
01240     case GEOM::FSM_Transformed:
01241       pd << "FSM_Transformed"; break;
01242     case GEOM::FSM_GetSame:
01243       pd << "FSM_GetSame"; break;
01244     case GEOM::FSM_GetShapesOnShape:
01245       pd << "FSM_GetShapesOnShape"; break;
01246     case GEOM::FSM_GetInPlaceByHistory:
01247     default:
01248       pd << "FSM_GetInPlaceByHistory"; break;
01249     }
01250     pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
01251   }
01252   aResParts->length(nbRes);
01253   return aResParts._retn();
01254 }
01255 
01256 //============================================================================
01257 // function : RestoreSubShapesOneLevel
01258 // purpose  : Private method
01259 //============================================================================
01260 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr     theStudy,
01261                                                       SALOMEDS::SObject_ptr   theOldSO,
01262                                                       SALOMEDS::SObject_ptr   theNewSO,
01263                                                       GEOM::GEOM_Object_ptr   theNewO,
01264                                                       GEOM::ListOfGO&         theOutArgs,
01265                                                       GEOM::find_shape_method theFindMethod,
01266                                                       CORBA::Boolean          theAddPrefix)
01267 {
01268   int i = 0;
01269   GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
01270   GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
01271   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
01272       CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
01273     return aParts._retn();
01274 
01275   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
01276 
01277   // Get interface, containing method, which we will use to reconstruct sub-shapes
01278   GEOM::GEOM_IShapesOperations_var  aShapesOp = GetIShapesOperations(theStudy->StudyId());
01279   GEOM::GEOM_IGroupOperations_var    aGroupOp = GetIGroupOperations(theStudy->StudyId());
01280   GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
01281 
01282   // Reconstruct published sub-shapes
01283   SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
01284 
01285   int aLen = 0;
01286   for (it->Init(); it->More(); it->Next()) {
01287     aLen++;
01288   }
01289   aParts->length(aLen);
01290 
01291   for (it->Init(); it->More(); it->Next()) {
01292     SALOMEDS::SObject_var anOldSubSO = it->Value();
01293 
01294     TCollection_AsciiString anArgName = anOldSubSO->GetName();
01295 
01296     SALOMEDS::GenericAttribute_var anAttr;
01297     if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
01298       SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
01299       GEOM::GEOM_Object_var anOldSubO =
01300         GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
01301       if (!CORBA::is_nil(anOldSubO)) {
01302         // Find a sub-shape of theNewO in place of anOldSubO
01303         GEOM::GEOM_Object_var aNewSubO;
01304         switch (theFindMethod) {
01305         case GEOM::FSM_GetInPlace:
01306           {
01307             // Use GetInPlace
01308             aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
01309           }
01310           break;
01311         case GEOM::FSM_MultiTransformed:
01312           {
01313             // Only for Multi-transformations
01314             GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anOldSubO, theNewO);
01315             if (!CORBA::is_nil(anArgOTrsf)) {
01316               CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
01317               Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
01318               Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
01319               anArgOTrsfFun->SetDescription("");
01320               aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
01321             }
01322           }
01323           break;
01324         case GEOM::FSM_Transformed:
01325           {
01326             // transformation, cannot use GetInPlace, operate with indices
01327             GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
01328             if (anIDs->length() > 1) {
01329               // group
01330               aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
01331               if (!CORBA::is_nil(aNewSubO))
01332                 aGroupOp->UnionIDs(aNewSubO, anIDs);
01333             }
01334             else {
01335               // single sub-shape
01336               aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
01337             }
01338           }
01339           break;
01340         case GEOM::FSM_GetSame:
01341           {
01342             // Use GetSame
01343             aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
01344           }
01345           break;
01346         case GEOM::FSM_GetShapesOnShape:
01347           {
01348             // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
01349             aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
01350                                                              (short)GEOM::SOLID, GEOM::ST_ONIN);
01351           }
01352           break;
01353         case GEOM::FSM_GetInPlaceByHistory:
01354           {
01355             // Use GetInPlaceByHistory
01356             aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
01357           }
01358           break;
01359         default:
01360           {}
01361         }
01362 
01363         if (!CORBA::is_nil(aNewSubO)) {
01364           // remember restored objects for Python Dump
01365           addToListOfGO(anOldSubO, theOutArgs);
01366 
01367           // add the part to the list
01368           aParts[i] = aNewSubO;
01369           i++;
01370           // add to parts list
01371           addToListOfGO( aNewSubO, aNewParts );
01372 
01373           SALOMEDS::SObject_var aNewSubSO;
01374           if (!CORBA::is_nil(theNewSO)) {
01375               // Publish the sub-shape
01376             TCollection_AsciiString aSubName;
01377             if (theAddPrefix) {
01378               aSubName = "from_";
01379             }
01380             aSubName += anArgName;
01381             aNewSubSO = aStudyBuilder->NewObject(theNewSO);
01382             aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
01383             // Restore color
01384             aNewSubO->SetColor(anOldSubO->GetColor());
01385             // set the texture
01386             if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
01387               aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
01388               if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
01389                 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
01390             }
01391           }
01392           // Restore published sub-shapes of the argument
01393           GEOM::ListOfGO_var aSubParts;
01394           if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
01395             // pass the main shape as Object, because only it has the history
01396             aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
01397                                                  theNewO, theOutArgs, theFindMethod, theAddPrefix);
01398           else
01399             aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
01400                                                  aNewSubO, theOutArgs, theFindMethod, theAddPrefix);
01401           // add to parts list
01402           addToListOfGO( aSubParts, aNewParts );
01403         }
01404         else { // GetInPlace failed, try to build from published parts
01405           SALOMEDS::SObject_var aNewSubSO;
01406           if (!CORBA::is_nil(theNewSO))
01407             aNewSubSO = aStudyBuilder->NewObject(theNewSO);
01408 
01409           // Restore published sub-shapes of the argument
01410           GEOM::ListOfGO_var aSubParts =
01411             RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
01412                                      theNewO, theOutArgs, theFindMethod, theAddPrefix);
01413           // add to parts list
01414           addToListOfGO( aSubParts, aNewParts );
01415 
01416           if (aSubParts->length() > 0) {
01417             // remember restored objects for Python Dump
01418             addToListOfGO(anOldSubO, theOutArgs);
01419 
01420             // try to build an object from a set of its sub-shapes,
01421             // that published and will be reconstructed
01422             if (aSubParts->length() > 1) {
01423               aNewSubO = aShapesOp->MakeCompound(aSubParts);
01424               // add to parts list
01425               addToListOfGO( aNewSubO, aNewParts );
01426             }
01427             else {
01428               aNewSubO = aSubParts[0];
01429             }
01430 
01431             if (!CORBA::is_nil(aNewSubO)) {
01432               // add the part to the list
01433               aSubParts[i] = aNewSubO;
01434               i++;
01435 
01436               // Publish the sub-shape
01437               if (!CORBA::is_nil(aNewSubSO)) {
01438                 TCollection_AsciiString aSubName;
01439                 if (theAddPrefix) {
01440                   aSubName = "from_parts_of_";
01441                 }
01442                 aSubName += anArgName;
01443                 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
01444                 // Restore color
01445                 aNewSubO->SetColor(anOldSubO->GetColor());
01446                 // set the texture
01447                 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
01448                   aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
01449                   if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
01450                     aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
01451                 }
01452               }
01453             }
01454           }
01455           else if (!CORBA::is_nil(aNewSubSO)) {
01456             // remove created aSubSO, because no parts have been found
01457             aStudyBuilder->RemoveObject(aNewSubSO);
01458           }
01459         } // try to build from published parts
01460       }
01461     }
01462   } // iterate on published sub-shapes
01463 
01464   aParts->length(i);
01465   // add to parts list
01466   addToListOfGO( aNewParts, aParts );
01467   return aParts._retn();
01468 }
01469 
01470 //============================================================================
01471 // function : RestoreGivenSubShapes
01472 // purpose  : Private method. Works only if both theObject and theSObject
01473 //            are defined, and does not check, if they correspond to each other.
01474 //            List theArgs in this case contains not only operation arguments,
01475 //            but also all subshapes, which must be published.
01476 //============================================================================
01477 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr     theStudy,
01478                                                   GEOM::GEOM_Object_ptr   theObject,
01479                                                   SALOMEDS::SObject_ptr   theSObject,
01480                                                   const GEOM::ListOfGO&   theArgs,
01481                                                   GEOM::find_shape_method theFindMethod,
01482                                                   CORBA::Boolean          theInheritFirstArg,
01483                                                   CORBA::Boolean          theAddPrefix)
01484 {
01485   GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
01486   //PTv, IMP 0020001, The salome object <theSObject>
01487   //     is not obligatory in case of invokation from script
01488   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
01489     return aParts._retn();
01490 
01491   // If theArgs list is empty, nothing to do
01492   Standard_Integer aLength = theArgs.length();
01493   if (aLength == 0)
01494     return aParts._retn();
01495 
01496   // Get all arguments
01497   GEOM::ListOfGO_var anOpArgsList = theObject->GetDependency();
01498   Standard_Integer nbArgsActual = anOpArgsList->length();
01499 
01500   // If anOpArgsList list is empty, nothing to do
01501   if (nbArgsActual == 0)
01502     return aParts._retn();
01503 
01504   // Entries of arguments and subshapes
01505   std::set<std::string> anArgs;
01506   for (int i = 0; i < aLength; i++) {
01507     CORBA::String_var anEntry = theArgs[i]->GetEntry();
01508     anArgs.insert(anEntry.in());
01509   }
01510 
01511   // Arguments to be published
01512   // We try to publish all arguments, that are in theArgs list
01513   GEOM::ListOfGO_var aList = new GEOM::ListOfGO;
01514   aList->length(nbArgsActual);
01515 
01516   int k = 0;
01517   for (int j = 0; j < nbArgsActual; j++) {
01518     CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
01519     if (anArgs.count(anEntry.in())) {
01520       aList[k] = GEOM::GEOM_Object::_duplicate(anOpArgsList[j]);
01521       k++;
01522     }
01523   }
01524   nbArgsActual = k;
01525   //aList->length(nbArgsActual);
01526 
01527   if (nbArgsActual < 1)
01528     return aParts._retn();
01529 
01530   if (theInheritFirstArg || (nbArgsActual == 1)) {
01531     // Do not publish argument's reflection,
01532     // but only reconstruct its published sub-shapes
01533 
01534     CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
01535     SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
01536 
01537     aParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
01538                                            anArgs, theFindMethod, theAddPrefix);
01539 
01540     // set the color of the transformed shape to the color of initial shape
01541     theObject->SetColor(aList[0]->GetColor());
01542     // set the texture
01543     if (theObject->GetShapeType() == GEOM::VERTEX) {
01544       theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
01545       if (aList[0]->GetMarkerType() == GEOM::MT_USER)
01546         theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
01547     }
01548 
01549     anArgSO->UnRegister();
01550   }
01551   else {
01552     // Get interface, containing method, which we will use to reconstruct sub-shapes
01553     GEOM::GEOM_IShapesOperations_var  aShapesOp = GetIShapesOperations(theStudy->StudyId());
01554     GEOM::GEOM_IGroupOperations_var    aGroupOp = GetIGroupOperations(theStudy->StudyId());
01555     GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
01556 
01557     // Reconstruct arguments and tree of sub-shapes of the arguments
01558     CORBA::String_var anIOR;
01559     SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
01560     for (Standard_Integer i = 0; i < nbArgsActual; i++)
01561     {
01562       GEOM::GEOM_Object_var anArgO = aList[i];
01563       if (!CORBA::is_nil(anArgO)) {
01564         anIOR = _orb->object_to_string(anArgO);
01565         SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
01566         TCollection_AsciiString anArgName;
01567         if (CORBA::is_nil(anArgSO)) {
01568           anArgName = "arg_";
01569           anArgName += TCollection_AsciiString(i);
01570         }
01571         else {
01572           anArgName = anArgSO->GetName();
01573         }
01574 
01575         // Find a sub-shape of theObject in place of the argument
01576         GEOM::GEOM_Object_var aSubO;
01577         switch (theFindMethod) {
01578         case GEOM::FSM_GetInPlace:
01579           {
01580             // Use GetInPlace
01581             aSubO = aShapesOp->GetInPlace(theObject, anArgO);
01582           }
01583           break;
01584         case GEOM::FSM_MultiTransformed:
01585           {
01586             // Only for Multi-transformations
01587             GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anArgO, theObject);
01588             if (!CORBA::is_nil(anArgOTrsf)) {
01589               CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
01590               Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
01591               Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
01592               anArgOTrsfFun->SetDescription("");
01593               aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
01594             }
01595           }
01596           break;
01597         case GEOM::FSM_Transformed:
01598           {
01599             // transformation, cannot use GetInPlace, operate with indices
01600             GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
01601             if (anIDs->length() > 1) {
01602               // group
01603               aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
01604               if (!CORBA::is_nil(aSubO))
01605                 aGroupOp->UnionIDs(aSubO, anIDs);
01606             }
01607             else if (anIDs->length() > 0) {
01608               // single sub-shape
01609               aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
01610             }
01611           }
01612           break;
01613         case GEOM::FSM_GetSame:
01614           {
01615             // Use GetSame
01616             aSubO = aShapesOp->GetSame(theObject, anArgO);
01617           }
01618           break;
01619         case GEOM::FSM_GetShapesOnShape:
01620           {
01621             // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
01622             aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
01623               (short)GEOM::SOLID, GEOM::ST_ONIN);
01624           }
01625           break;
01626         case GEOM::FSM_GetInPlaceByHistory:
01627           {
01628             // Use GetInPlaceByHistory
01629             aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
01630           }
01631           break;
01632         default:
01633           {}
01634         }
01635 
01636         if (!CORBA::is_nil(aSubO)) {
01637           // add to parts list
01638           addToListOfGO( aSubO, aParts );
01639 
01640           // Publish the sub-shape
01641           SALOMEDS::SObject_var aSubSO;
01642           if (!CORBA::is_nil(theSObject)) {
01643             TCollection_AsciiString aSubName;
01644             if (theAddPrefix) {
01645               aSubName = "from_";
01646             }
01647             aSubName += anArgName;
01648             aSubSO = aStudyBuilder->NewObject(theSObject);
01649             aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
01650             // Restore color
01651             aSubO->SetColor(anArgO->GetColor());
01652             // set the texture
01653             if (aSubO->GetShapeType() == GEOM::VERTEX) {
01654               aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
01655               if (anArgO->GetMarkerType() == GEOM::MT_USER)
01656                 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
01657             }
01658           }
01659 
01660           if (!CORBA::is_nil(anArgSO)) {
01661             // Restore published sub-shapes of the argument
01662             GEOM::ListOfGO_var aSubParts;
01663             if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
01664               // pass theObject, because only it has the history
01665               aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
01666                                                         theObject, anArgs, theFindMethod, theAddPrefix);
01667             else
01668               aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
01669                                                         aSubO, anArgs, theFindMethod, theAddPrefix);
01670             // add to parts list
01671             addToListOfGO( aSubParts, aParts );
01672           }
01673         }
01674         else { // GetInPlace failed, try to build from published parts
01675           if (!CORBA::is_nil(anArgSO)) {
01676             SALOMEDS::SObject_var aSubSO;
01677             if (!CORBA::is_nil(theSObject))
01678               aSubSO = aStudyBuilder->NewObject(theSObject);
01679 
01680             // Restore published sub-shapes of the argument
01681             GEOM::ListOfGO_var aSubParts =
01682               RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
01683                                             theObject, anArgs, theFindMethod, theAddPrefix);
01684 
01685             // add to parts list
01686             addToListOfGO( aSubParts, aParts );
01687 
01688             if (aSubParts->length() > 0) {
01689               // try to build an argument from a set of its sub-shapes,
01690               // that published and will be reconstructed
01691               if (aSubParts->length() > 1) {
01692                 aSubO = aShapesOp->MakeCompound(aSubParts);
01693                 // add to parts list
01694                 addToListOfGO( aSubO, aParts );
01695               }
01696               else {
01697                 aSubO = aSubParts[0];
01698               }
01699               if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
01700                 // Publish the sub-shape
01701                 TCollection_AsciiString aSubName;
01702                 if (theAddPrefix) {
01703                   aSubName = "from_parts_of_";
01704                 }
01705                 aSubName += anArgName;
01706                 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
01707                 // Restore color
01708                 aSubO->SetColor(anArgO->GetColor());
01709                 // set the texture
01710                 if (aSubO->GetShapeType() == GEOM::VERTEX) {
01711                   aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
01712                   if (anArgO->GetMarkerType() == GEOM::MT_USER)
01713                     aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
01714                 }
01715               }
01716             }
01717             else if (!CORBA::is_nil(aSubSO)) {
01718               // remove created aSubSO, because no parts have been found
01719               aStudyBuilder->RemoveObject(aSubSO);
01720             }
01721           }
01722         } // try to build from published parts
01723         anArgSO->UnRegister();
01724       }
01725     } // process arguments
01726   }
01727   std::set<std::string> anObjEntryMap;
01728   GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
01729   int nbRes = 0;
01730   int nb = aParts->length();
01731   aResParts->length(nb);
01732   if (nb > 0)
01733   {
01734     Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
01735     Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
01736     GEOM::TPythonDump pd (aFunction, true);
01737     pd <<"[";
01738     int i = 0, j = 0;
01739     for ( ; i < nb; i++ )
01740     {
01741       GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
01742       if (CORBA::is_nil(anObj))
01743         continue;
01744       char* anEntry = anObj->GetEntry();
01745       if (anObjEntryMap.count(anEntry))
01746         continue; // already treated
01747       anObjEntryMap.insert(anEntry);
01748       aResParts[nbRes++] = anObj;
01749       // clear python dump of object
01750       Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
01751       Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
01752       if ( !anObjFun.IsNull() )
01753         anObjFun->SetDescription( "" );
01754       if ( j > 0 )
01755         pd << ", ";
01756       pd << aGeomObj;
01757       j++;
01758     }
01759     pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
01760     i = 0; nb = theArgs.length(); j = 0;
01761     for ( ; i < nb; i++ )
01762     {
01763       GEOM::GEOM_Object_var anObj = theArgs[ i ];
01764       if (CORBA::is_nil(anObj))
01765         continue;
01766       Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
01767       if ( j > 0 )
01768         pd << ", ";
01769       pd << aGeomObj;
01770       j++;
01771     }
01772     pd <<"]" << ", " <<"geompy.GEOM.";
01773     switch (theFindMethod) {
01774     case GEOM::FSM_GetInPlace:
01775       pd << "FSM_GetInPlace"; break;
01776     case GEOM::FSM_MultiTransformed:
01777       pd << "FSM_MultiTransformed"; break;
01778     case GEOM::FSM_Transformed:
01779       pd << "FSM_Transformed"; break;
01780     case GEOM::FSM_GetSame:
01781       pd << "FSM_GetSame"; break;
01782     case GEOM::FSM_GetShapesOnShape:
01783       pd << "FSM_GetShapesOnShape"; break;
01784     case GEOM::FSM_GetInPlaceByHistory:
01785     default:
01786       pd << "FSM_GetInPlaceByHistory"; break;
01787     }
01788     pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
01789   }
01790   aResParts->length(nbRes);
01791   return aResParts._retn();
01792 }
01793 
01794 //============================================================================
01795 // function : RestoreGivenSubShapesOneLevel
01796 // purpose  : Private method
01797 //============================================================================
01798 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr     theStudy,
01799                                                            SALOMEDS::SObject_ptr   theOldSO,
01800                                                            SALOMEDS::SObject_ptr   theNewSO,
01801                                                            GEOM::GEOM_Object_ptr   theNewO,
01802                                                            std::set<std::string>   theArgs,
01803                                                            GEOM::find_shape_method theFindMethod,
01804                                                            CORBA::Boolean          theAddPrefix)
01805 {
01806   int i = 0;
01807   GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
01808   GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
01809   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
01810       CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
01811     return aParts._retn();
01812 
01813   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
01814 
01815   // Get interface, containing method, which we will use to reconstruct sub-shapes
01816   GEOM::GEOM_IShapesOperations_var  aShapesOp = GetIShapesOperations(theStudy->StudyId());
01817   GEOM::GEOM_IGroupOperations_var    aGroupOp = GetIGroupOperations(theStudy->StudyId());
01818   GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
01819 
01820   // Reconstruct published sub-shapes
01821   SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
01822 
01823   int aLen = 0;
01824   for (it->Init(); it->More(); it->Next()) {
01825     aLen++;
01826   }
01827   aParts->length(aLen);
01828 
01829   for (it->Init(); it->More(); it->Next()) {
01830     SALOMEDS::SObject_var anOldSubSO = it->Value();
01831 
01832     TCollection_AsciiString anArgName = anOldSubSO->GetName();
01833 
01834     SALOMEDS::GenericAttribute_var anAttr;
01835     if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
01836       SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
01837       GEOM::GEOM_Object_var anOldSubO =
01838         GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
01839 
01840       bool okToContinue = false;
01841 
01842       if (!CORBA::is_nil(anOldSubO)) {
01843         CORBA::String_var anEntry = anOldSubO->GetEntry();
01844         okToContinue = theArgs.count(anEntry.in());
01845       }
01846 
01847       if (okToContinue) {
01848         // Find a sub-shape of theNewO in place of anOldSubO
01849         GEOM::GEOM_Object_var aNewSubO;
01850         switch (theFindMethod) {
01851         case GEOM::FSM_GetInPlace:
01852           {
01853             // Use GetInPlace
01854             aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
01855           }
01856           break;
01857         case GEOM::FSM_MultiTransformed:
01858           {
01859             // Only for Multi-transformations
01860             GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anOldSubO, theNewO);
01861             if (!CORBA::is_nil(anArgOTrsf)) {
01862               CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
01863               Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
01864               Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
01865               anArgOTrsfFun->SetDescription("");
01866               aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
01867             }
01868           }
01869           break;
01870         case GEOM::FSM_Transformed:
01871           {
01872             // transformation, cannot use GetInPlace, operate with indices
01873             GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
01874             if (anIDs->length() > 1) {
01875               // group
01876               aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
01877               if (!CORBA::is_nil(aNewSubO))
01878                 aGroupOp->UnionIDs(aNewSubO, anIDs);
01879             }
01880             else {
01881               // single sub-shape
01882               aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
01883             }
01884           }
01885           break;
01886         case GEOM::FSM_GetSame:
01887           {
01888             // Use GetSame
01889             aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
01890           }
01891           break;
01892         case GEOM::FSM_GetShapesOnShape:
01893           {
01894             // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
01895             aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
01896                                                              (short)GEOM::SOLID, GEOM::ST_ONIN);
01897           }
01898           break;
01899         case GEOM::FSM_GetInPlaceByHistory:
01900           {
01901             // Use GetInPlaceByHistory
01902             aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
01903           }
01904           break;
01905         default:
01906           {}
01907         }
01908 
01909         if (!CORBA::is_nil(aNewSubO)) {
01910           // add the part to the list
01911           aParts[i] = aNewSubO;
01912           i++;
01913           // add to parts list
01914           addToListOfGO( aNewSubO, aNewParts );
01915 
01916           SALOMEDS::SObject_var aNewSubSO;
01917           if (!CORBA::is_nil(theNewSO)) {
01918               // Publish the sub-shape
01919             TCollection_AsciiString aSubName;
01920             if (theAddPrefix) {
01921               aSubName = "from_";
01922             }
01923             aSubName += anArgName;
01924             aNewSubSO = aStudyBuilder->NewObject(theNewSO);
01925             aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
01926             // Restore color
01927             aNewSubO->SetColor(anOldSubO->GetColor());
01928             // set the texture
01929             if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
01930               aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
01931               if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
01932                 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
01933             }
01934           }
01935           // Restore published sub-shapes of the argument
01936           GEOM::ListOfGO_var aSubParts;
01937           if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
01938             // pass the main shape as Object, because only it has the history
01939             aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
01940                                                       theNewO, theArgs, theFindMethod, theAddPrefix);
01941           else
01942             aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
01943                                                       aNewSubO, theArgs, theFindMethod, theAddPrefix);
01944           // add to parts list
01945           addToListOfGO( aSubParts, aNewParts );
01946         }
01947         else { // GetInPlace failed, try to build from published parts
01948           SALOMEDS::SObject_var aNewSubSO;
01949           if (!CORBA::is_nil(theNewSO))
01950             aNewSubSO = aStudyBuilder->NewObject(theNewSO);
01951 
01952           // Restore published sub-shapes of the argument
01953           GEOM::ListOfGO_var aSubParts =
01954             RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
01955                                           theNewO, theArgs, theFindMethod, theAddPrefix);
01956           // add to parts list
01957           addToListOfGO( aSubParts, aNewParts );
01958 
01959           if (aSubParts->length() > 0) {
01960             // try to build an object from a set of its sub-shapes,
01961             // that published and will be reconstructed
01962             if (aSubParts->length() > 1) {
01963               aNewSubO = aShapesOp->MakeCompound(aSubParts);
01964               // add to parts list
01965               addToListOfGO( aNewSubO, aNewParts );
01966             }
01967             else {
01968               aNewSubO = aSubParts[0];
01969             }
01970 
01971             if (!CORBA::is_nil(aNewSubO)) {
01972               // add the part to the list
01973               aSubParts[i] = aNewSubO;
01974               i++;
01975 
01976               // Publish the sub-shape
01977               if (!CORBA::is_nil(aNewSubSO)) {
01978                 TCollection_AsciiString aSubName;
01979                 if (theAddPrefix) {
01980                   aSubName = "from_parts_of_";
01981                 }
01982                 aSubName += anArgName;
01983                 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
01984                 // Restore color
01985                 aNewSubO->SetColor(anOldSubO->GetColor());
01986                 // set the texture
01987                 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
01988                   aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
01989                   if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
01990                     aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
01991                 }
01992               }
01993             }
01994           }
01995           else if (!CORBA::is_nil(aNewSubSO)) {
01996             // remove created aSubSO, because no parts have been found
01997             aStudyBuilder->RemoveObject(aNewSubSO);
01998           }
01999         } // try to build from published parts
02000       }
02001     }
02002   } // iterate on published sub-shapes
02003 
02004   aParts->length(i);
02005   // add to parts list
02006   addToListOfGO( aNewParts, aParts );
02007   return aParts._retn();
02008 }
02009 
02010 //============================================================================
02011 // function : register()
02012 // purpose  : register 'name' in 'name_service'
02013 //============================================================================
02014 void GEOM_Gen_i::register_name(char * name)
02015 {
02016   GEOM::GEOM_Gen_var g = _this();
02017   name_service->Register(g, name);
02018 }
02019 
02020 //============================================================================
02021 // function : Undo
02022 // purpose  :
02023 //============================================================================
02024 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
02025 {
02026   _impl->Undo(theStudyID);
02027 }
02028 
02029 //============================================================================
02030 // function : Redo
02031 // purpose  :
02032 //============================================================================
02033 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
02034 {
02035   _impl->Redo(theStudyID);
02036 }
02037 
02038 //============================================================================
02039 // function : GetIBasicOperations
02040 // purpose  :
02041 //============================================================================
02042 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
02043      throw ( SALOME::SALOME_Exception )
02044 {
02045   Unexpect aCatch(SALOME_SalomeException);
02046   MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
02047 
02048   GEOM::GEOM_Gen_ptr engine = _this();
02049 
02050   //transfer reference on engine
02051   GEOM_IBasicOperations_i* aServant =
02052     new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
02053 
02054   PortableServer::ObjectId_var id = _poa->activate_object(aServant);
02055   // activate the CORBA servant
02056   GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
02057   return operations._retn();
02058 }
02059 
02060 //============================================================================
02061 // function : GetITransformOperations
02062 // purpose  :
02063 //============================================================================
02064 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
02065      throw ( SALOME::SALOME_Exception )
02066 {
02067   Unexpect aCatch(SALOME_SalomeException);
02068   MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
02069 
02070   GEOM::GEOM_Gen_ptr engine = _this();
02071 
02072   GEOM_ITransformOperations_i* aServant =
02073     new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
02074 
02075   // activate the CORBA servant
02076   GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
02077   return operations._retn();
02078 }
02079 
02080 //============================================================================
02081 // function : GetI3DPrimOperations
02082 // purpose  :
02083 //============================================================================
02084 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
02085      throw ( SALOME::SALOME_Exception )
02086 {
02087   Unexpect aCatch(SALOME_SalomeException);
02088   MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
02089 
02090   GEOM::GEOM_Gen_ptr engine = _this();
02091 
02092   GEOM_I3DPrimOperations_i* aServant =
02093     new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
02094   PortableServer::ObjectId_var id = _poa->activate_object(aServant);
02095 
02096   // activate the CORBA servant
02097   GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
02098   return operations._retn();
02099 }
02100 
02101 //============================================================================
02102 // function : GetIShapesOperations
02103 // purpose  :
02104 //============================================================================
02105 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
02106      throw ( SALOME::SALOME_Exception )
02107 {
02108   Unexpect aCatch(SALOME_SalomeException);
02109   MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
02110 
02111   GEOM::GEOM_Gen_ptr engine = _this();
02112 
02113   GEOM_IShapesOperations_i* aServant =
02114     new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
02115 
02116   // activate the CORBA servant
02117   GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
02118   return operations._retn();
02119 }
02120 
02121 //============================================================================
02122 // function : GetIBlocksOperations
02123 // purpose  :
02124 //============================================================================
02125 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
02126      throw ( SALOME::SALOME_Exception )
02127 {
02128   Unexpect aCatch(SALOME_SalomeException);
02129   MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
02130 
02131   GEOM::GEOM_Gen_ptr engine = _this();
02132 
02133   GEOM_IBlocksOperations_i* aServant =
02134     new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
02135 
02136   // activate the CORBA servant
02137   GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
02138   return operations._retn();
02139 }
02140 
02141 //============================================================================
02142 // function : GetIBooleanOperations
02143 // purpose  :
02144 //============================================================================
02145 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
02146      throw ( SALOME::SALOME_Exception )
02147 {
02148   Unexpect aCatch(SALOME_SalomeException);
02149   MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
02150 
02151   GEOM::GEOM_Gen_ptr engine = _this();
02152 
02153   GEOM_IBooleanOperations_i* aServant =
02154     new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
02155 
02156   // activate the CORBA servant
02157   GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
02158   return operations._retn();
02159 }
02160 
02161 //============================================================================
02162 // function : GetICurvesOperations
02163 // purpose  :
02164 //============================================================================
02165 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
02166      throw ( SALOME::SALOME_Exception )
02167 {
02168   Unexpect aCatch(SALOME_SalomeException);
02169   MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
02170 
02171   GEOM::GEOM_Gen_ptr engine = _this();
02172 
02173   GEOM_ICurvesOperations_i* aServant =
02174     new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
02175 
02176   // activate the CORBA servant
02177   GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
02178   return operations._retn();
02179 }
02180 
02181 //============================================================================
02182 // function : GetILocalOperations
02183 // purpose  :
02184 //============================================================================
02185 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
02186      throw ( SALOME::SALOME_Exception )
02187 {
02188   Unexpect aCatch(SALOME_SalomeException);
02189   MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
02190 
02191   GEOM::GEOM_Gen_ptr engine = _this();
02192 
02193   GEOM_ILocalOperations_i* aServant =
02194     new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
02195 
02196   // activate the CORBA servant
02197   GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
02198   return operations._retn();
02199 }
02200 
02201 //============================================================================
02202 // function : GetIHealingOperations
02203 // purpose  :
02204 //============================================================================
02205 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
02206      throw ( SALOME::SALOME_Exception )
02207 {
02208   Unexpect aCatch(SALOME_SalomeException);
02209   MESSAGE( "GEOM_Gen_i::IHealingOperations" );
02210 
02211   GEOM::GEOM_Gen_ptr engine = _this();
02212 
02213   GEOM_IHealingOperations_i* aServant =
02214     new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
02215 
02216   // activate the CORBA servant
02217   GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
02218   return operations._retn();
02219 }
02220 
02221 //============================================================================
02222 // function : GetIInsertOperations
02223 // purpose  :
02224 //============================================================================
02225 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
02226      throw ( SALOME::SALOME_Exception )
02227 {
02228   Unexpect aCatch(SALOME_SalomeException);
02229   MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
02230 
02231   GEOM::GEOM_Gen_ptr engine = _this();
02232 
02233   GEOM_IInsertOperations_i* aServant =
02234     new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
02235 
02236   // activate the CORBA servant
02237   GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
02238   return operations._retn();
02239 }
02240 
02241 //============================================================================
02242 // function : GetIMeasureOperations
02243 // purpose  :
02244 //============================================================================
02245 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
02246      throw ( SALOME::SALOME_Exception )
02247 {
02248   Unexpect aCatch(SALOME_SalomeException);
02249   MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
02250 
02251   GEOM::GEOM_Gen_ptr engine = _this();
02252 
02253   GEOM_IMeasureOperations_i* aServant =
02254     new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
02255 
02256   // activate the CORBA servant
02257   GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
02258   return operations._retn();
02259 }
02260 
02261 //============================================================================
02262 // function : GetIGroupOperations
02263 // purpose  :
02264 //============================================================================
02265 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
02266      throw ( SALOME::SALOME_Exception )
02267 {
02268   Unexpect aCatch(SALOME_SalomeException);
02269   MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
02270 
02271   GEOM::GEOM_Gen_ptr engine = _this();
02272 
02273   GEOM_IGroupOperations_i* aServant =
02274     new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
02275 
02276   // activate the CORBA servant
02277   GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
02278   return operations._retn();
02279 }
02280 
02281 //============================================================================
02282 // function : GetIAdvancedOperations
02283 // purpose  :
02284 //============================================================================
02285 GEOM::GEOM_IAdvancedOperations_ptr GEOM_Gen_i::GetIAdvancedOperations(CORBA::Long theStudyID)
02286      throw ( SALOME::SALOME_Exception )
02287 {
02288   Unexpect aCatch(SALOME_SalomeException);
02289   MESSAGE( "GEOM_Gen_i::GetIAdvancedOperations" );
02290 
02291   GEOM::GEOM_Gen_ptr engine = _this();
02292 
02293   GEOM_IAdvancedOperations_i* aServant =
02294     new GEOM_IAdvancedOperations_i(_poa, engine, _impl->GetIAdvancedOperations(theStudyID));
02295 
02296   // activate the CORBA servant
02297   GEOM::GEOM_IAdvancedOperations_var operations = aServant->_this();
02298   return operations._retn();
02299 }
02300 
02301 //=============================================================================
02305 //=============================================================================
02306 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
02307                                                const GEOM::ListOfLong& theIndices)
02308 {
02309   if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
02310     return GEOM::GEOM_Object::_nil();
02311   CORBA::String_var entry = theMainShape->GetEntry();
02312   Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
02313   if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
02314 
02315   Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
02316   for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
02317 
02318   Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true);
02319   if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
02320 
02321   TCollection_AsciiString anEntry;
02322   TDF_Tool::Entry(anObject->GetEntry(), anEntry);
02323   return GetObject(anObject->GetDocID(), anEntry.ToCString());
02324 }
02325 
02326 //=============================================================================
02330 //=============================================================================
02331 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
02332 {
02333   CORBA::String_var anEntry = theObject->GetEntry();
02334   Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
02335   if (anObject.IsNull()) return;
02336   _impl->RemoveObject(anObject);
02337   return;
02338 }
02339 
02340 
02341 //=================================================================================
02342 // function : GetStringFromIOR()
02343 // purpose  : returns a string that represents  a 'GEOM::GEOM_Object_var'
02344 //=================================================================================
02345 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
02346   return _orb->object_to_string(theObject);
02347 }
02348 
02349 
02350 //=================================================================================
02351 // function : GetIORFromString()
02352 // purpose  : returns a 'GEOM::GEOM_Object_var' from a string representing it
02353 //=================================================================================
02354 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
02355   GEOM::GEOM_Object_var aGeomObject;
02356   if(strcmp(stringIOR,"") != 0){
02357     CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
02358     if(!CORBA::is_nil(anObject))
02359       aGeomObject =  GEOM::GEOM_Object::_narrow(anObject.in());
02360   }
02361   return aGeomObject._retn();
02362 }
02363 
02364 //=================================================================================
02365 // function : GetObject()
02366 // purpose  :
02367 //=================================================================================
02368 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
02369 {
02370   GEOM::GEOM_Object_var obj;
02371   Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
02372   if (handle_object.IsNull()) return obj._retn();
02373 
02374   TCollection_AsciiString stringIOR = handle_object->GetIOR();
02375   if (stringIOR.Length() > 1) {
02376     CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
02377     if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
02378     return obj._retn();
02379   }
02380 
02381   GEOM::GEOM_Gen_ptr engine = _this();
02382   //transfer the reference to GEOM_Object_i
02383   GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
02384   PortableServer::ObjectId_var id = _poa->activate_object(servant);
02385 
02386   obj = servant->_this();
02387   CORBA::String_var objStr = _orb->object_to_string(obj);
02388   TCollection_AsciiString anAscii( (char *)objStr.in() );
02389   handle_object->SetIOR( anAscii );
02390   return obj._retn();
02391 }
02392 
02393 //=================================================================================
02394 // function : hasObjectInfo()
02395 // purpose  : shows if module provides information for its objects
02396 //=================================================================================
02397 bool GEOM_Gen_i::hasObjectInfo()
02398 {
02399   return true;
02400 }
02401 
02402 //=================================================================================
02403 // function : getObjectInfo()
02404 // purpose  : returns an information for a given object by its entry
02405 //=================================================================================
02406 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
02407 {
02408   GEOM::GEOM_Object_var aGeomObject;
02409 
02410   CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
02411   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
02412   SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
02413   SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
02414   SALOMEDS::SObject_var aResultSObj;
02415   if (aSObj->ReferencedObject(aResultSObj))
02416     aSObj = aResultSObj;
02417 
02418   SALOMEDS::GenericAttribute_var anAttr;
02419   if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
02420     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
02421     CORBA::String_var aVal = anIOR->Value();
02422     anIOR->UnRegister();
02423     CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
02424     aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
02425   }
02426   if (!aSObj->_is_nil() )
02427     aSObj->UnRegister();
02428 
02429   const char* aTypeInfo = "Object";
02430   if ( !aGeomObject->_is_nil() ) {
02431     GEOM::GEOM_IKindOfShape::shape_kind aKind;
02432     GEOM::ListOfLong_var anInts;
02433     GEOM::ListOfDouble_var aDbls;
02434 
02435     GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
02436     aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
02437 
02438     if ( anOp->IsDone() ) {
02439       switch ( aKind ) {
02440       case GEOM::GEOM_IKindOfShape::COMPOUND:
02441         aTypeInfo = "Compound";
02442         break;
02443       case GEOM::GEOM_IKindOfShape::COMPSOLID:
02444         aTypeInfo = "CompSolid";
02445         break;
02446       case GEOM::GEOM_IKindOfShape::SHELL:
02447         aTypeInfo = "Shell";
02448         break;
02449       case GEOM::GEOM_IKindOfShape::WIRE:
02450         if ( anInts[0] == 1 )
02451           aTypeInfo = "Closed Wire";
02452         else if ( anInts[0] == 2 )
02453           aTypeInfo = "Opened Wire";
02454         else
02455           aTypeInfo = "Wire";
02456         break;
02457         // SOLIDs
02458       case GEOM::GEOM_IKindOfShape::SPHERE:
02459         aTypeInfo = "Sphere";
02460         break;
02461       case GEOM::GEOM_IKindOfShape::CYLINDER:
02462         aTypeInfo = "Cylinder";
02463         break;
02464       case GEOM::GEOM_IKindOfShape::BOX:
02465       case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
02466         aTypeInfo = "Box";
02467         break;
02468       case GEOM::GEOM_IKindOfShape::TORUS:
02469         aTypeInfo = "Torus";
02470         break;
02471       case GEOM::GEOM_IKindOfShape::CONE:
02472         aTypeInfo = "Cone";
02473         break;
02474       case GEOM::GEOM_IKindOfShape::POLYHEDRON:
02475         aTypeInfo = "Polyhedron";
02476         break;
02477       case GEOM::GEOM_IKindOfShape::SOLID:
02478         aTypeInfo = "Solid";
02479         break;
02480         // FACEs
02481       case GEOM::GEOM_IKindOfShape::SPHERE2D:
02482         aTypeInfo = "Spherical Face";
02483         break;
02484       case GEOM::GEOM_IKindOfShape::CYLINDER2D:
02485         aTypeInfo = "Cylindrical Face";
02486         break;
02487       case GEOM::GEOM_IKindOfShape::TORUS2D:
02488         aTypeInfo = "Toroidal Face";
02489         break;
02490       case GEOM::GEOM_IKindOfShape::CONE2D:
02491         aTypeInfo = "Conical Face";
02492         break;
02493       case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
02494         aTypeInfo = "Disk";
02495         break;
02496       case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
02497         aTypeInfo = "Elliptical Face";
02498         break;
02499       case GEOM::GEOM_IKindOfShape::POLYGON:
02500         aTypeInfo = "Polygon";
02501         break;
02502       case GEOM::GEOM_IKindOfShape::PLANE:
02503         aTypeInfo = "Plane";
02504         break;
02505       case GEOM::GEOM_IKindOfShape::PLANAR:
02506         aTypeInfo = "Planar Face";
02507         break;
02508       case GEOM::GEOM_IKindOfShape::FACE:
02509         aTypeInfo = "Face";
02510         break;
02511         // EDGEs
02512       case GEOM::GEOM_IKindOfShape::CIRCLE:
02513         aTypeInfo = "Circle";
02514         break;
02515       case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
02516         aTypeInfo = "Arc Circle";
02517         break;
02518       case GEOM::GEOM_IKindOfShape::ELLIPSE:
02519         aTypeInfo = "Ellipse";
02520         break;
02521       case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
02522         aTypeInfo = "Arc Ellipse";
02523         break;
02524       case GEOM::GEOM_IKindOfShape::LINE:
02525         aTypeInfo = "Line";
02526         break;
02527       case GEOM::GEOM_IKindOfShape::SEGMENT:
02528         aTypeInfo = "Segment";
02529         break;
02530       case GEOM::GEOM_IKindOfShape::EDGE:
02531         aTypeInfo = "Edge";
02532         break;
02533       case GEOM::GEOM_IKindOfShape::VERTEX:
02534         aTypeInfo = "Vertex";
02535         break;
02536       default:
02537         break;
02538       }
02539     }
02540   }
02541 
02542   char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
02543   sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
02544 
02545   char* ret = CORBA::string_dup(anInfo);
02546   delete [] anInfo;
02547   return ret;
02548 }
02549 
02550 //=====================================================================================
02551 // EXPORTED METHODS
02552 //=====================================================================================
02553 extern "C"
02554 {
02555   /*
02556   GEOM_I_EXPORT
02557   PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
02558   */
02559 
02560   GEOM_I_EXPORT
02561   PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr            orb,
02562                                                PortableServer::POA_ptr   poa,
02563                                                PortableServer::ObjectId* contId,
02564                                                const char*               instanceName,
02565                                                const char*               interfaceName)
02566   {
02567     GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
02568     return myGEOM_Gen_i->getId();
02569   }
02570 }