X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOM_I%2FGEOM_Gen_i.cc;h=76f133190a950d5fd09f95c23da7a46c08bd585b;hb=22b9c99081495ff0b7c053b9b7e779b105a73044;hp=6e8e4e430dbed26d3beec114737a3439c129ec02;hpb=392885c1a8d50369708bbe5e6b44033ed8b8ba51;p=modules%2Fgeom.git diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 6e8e4e430..76f133190 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #ifdef WNT #pragma warning( disable:4786 ) #endif @@ -28,7 +29,9 @@ #include "GEOM_Gen_i.hh" #include "GEOM_Object_i.hh" +#include #include +//#include #include "Utils_CorbaException.hxx" #include "OpUtil.hxx" @@ -38,6 +41,8 @@ #include "GEOM_Object_i.hh" #include "GEOM_Object.hxx" #include "GEOM_Function.hxx" +#include "GEOM_ISubShape.hxx" +#include #include "GEOMImpl_Types.hxx" #include "GEOMImpl_CopyDriver.hxx" @@ -46,9 +51,14 @@ #include #include #include +#include +#include +#include #include #include #include +//#include +#include #include #include "SALOMEDS_Tool.hxx" @@ -57,11 +67,11 @@ // function : GEOM_Gen_i() // purpose : constructor to be called for servant creation. //============================================================================ -GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, - const char *interfaceName) : +GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId* contId, + const char* instanceName, + const char* interfaceName) : Engines_Component_i(orb, poa, contId, instanceName, interfaceName) { _thisObj = this; @@ -173,9 +183,12 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName"); SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue("Geometry"); + aName->Destroy(); anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap"); - SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry"); - aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this()); + SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr); + aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry"); + aPixMap->Destroy(); + aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this()); } if (aFather->_is_nil()) return aResultSO; @@ -188,10 +201,9 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, } anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"); SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - //char *aGeomObjIOR = _orb->object_to_string(theObject); - CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject); - //anIOR->SetValue(CORBA::string_dup(aGeomObjIOR)); + CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject); anIOR->SetValue(aGeomObjIOR); + anIOR->Destroy(); anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); @@ -220,6 +232,12 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, } else if ( aShape->GetType() == GEOM_MARKER ) { aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" ); aShapeName = "LocalCS_"; + } else if ( aShape->GetType() > ADVANCED_BASE ) { + char buf[20]; + sprintf( buf, "%d", aShape->GetType() ); + std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf; + aPixmap->SetPixMap( advId.c_str() ); + aShapeName = "Advanced_"; } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) { aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" ); aShapeName = "Compound_"; @@ -245,38 +263,74 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" ); aShapeName = "Vertex_"; } + aPixmap->Destroy(); //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag()); //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName)); + + // try to find existed name for current shape + bool HasName = false; + // recieve current TopoDS shape + CORBA::String_var entry = aShape->GetEntry(); + Handle(GEOM_Object) aGShape = _impl->GetObject(aShape->GetStudyID(), entry); + TopoDS_Shape TopoSh = aGShape->GetValue(); + // find label of main shape + GEOM::GEOM_Object_var aMainSh = aShape; + while( !aMainSh->IsMainShape() ) { + aMainSh = aMainSh->GetMainShape(); + } + entry = aMainSh->GetEntry(); + Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry); + TDF_Label aMainLbl = anObj->GetEntry(); + // check all named shapes using iterator + TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True); + for(; anIt.More(); anIt.Next()) { + Handle(TNaming_NamedShape) anAttr = + Handle(TNaming_NamedShape)::DownCast(anIt.Value()); + if(anAttr.IsNull()) continue; + TopoDS_Shape S = anAttr->Get(); + if( !S.IsEqual(TopoSh) ) continue; + TDF_Label L = anAttr->Label(); + Handle(TDataStd_Name) aName; + if(L.FindAttribute(TDataStd_Name::GetID(),aName)) { + aShapeName = aName->Get(); + HasName = true; + } + } - // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as - // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number - // of objects in the study, but compute a number of objects with the same prefix - // and build a new name as Prefix_N+1 - if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR - int i = 0; // (WITH EMPTY NEW NAME) - SALOMEDS::SObject_var obj; - TCollection_AsciiString aNewShapeName; - do { - aNewShapeName = aShapeName + TCollection_AsciiString(++i); - obj = theStudy->FindObject( aNewShapeName.ToCString() ); + if(!HasName) { + // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as + // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number + // of objects in the study, but compute a number of objects with the same prefix + // and build a new name as Prefix_N+1 + if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR + int i = 0; // (WITH EMPTY NEW NAME) + SALOMEDS::SObject_var obj; + TCollection_AsciiString aNewShapeName; + do { + aNewShapeName = aShapeName + TCollection_AsciiString(++i); + obj = theStudy->FindObject( aNewShapeName.ToCString() ); + } + while ( !obj->_is_nil() ); + aShapeName = aNewShapeName; } - while ( !obj->_is_nil() ); - aShapeName = aNewShapeName; + else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME) + aShapeName = TCollection_AsciiString((char*)theName); } - else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME) - aShapeName = TCollection_AsciiString((char*)theName); //Set the study entry as a name of the published GEOM_Object - aShape->SetStudyEntry(aResultSO->GetID()); + CORBA::String_var anID =aResultSO->GetID(); + aShape->SetStudyEntry(anID.in()); //Set a name of the added shape anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName"); SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr); aNameAttrib->SetValue(aShapeName.ToCString()); + aNameAttrib->Destroy(); //Set NoteBook variables used in the object creation TCollection_AsciiString aVars; - SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aShape->GetParameters()); + CORBA::String_var aString=aShape->GetParameters(); + SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString); for(int i = 0, n = aSections->length(); i < n; i++) { SALOMEDS::ListOfStrings aListOfVars = aSections[i]; for(int j = 0, m = aListOfVars.length(); j < m; j++) { @@ -291,6 +345,9 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeString"); SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr); aStringAttrib->SetValue(aVars.ToCString()); + aStringAttrib->Destroy(); + + aFather->Destroy(); //Set a name of the GEOM object aShape->SetName(theName); @@ -299,6 +356,129 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, } +//============================================================================ +// function : CreateAndPublishGroup +// purpose : auxilary for PublishNamedShapesInStudy +//============================================================================ +void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy, + GEOM::GEOM_Object_var theMainShape, + const TopTools_IndexedMapOfShape& anIndices, + const TopTools_SequenceOfShape& SeqS, + const TColStd_SequenceOfAsciiString& SeqN, + const Standard_CString& GrName, + GEOM::ListOfGO_var aResList) +{ + CORBA::String_var entry = theMainShape->GetEntry(); + Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry); + Handle(TColStd_HArray1OfInteger) anArray; + if(SeqS.Length()>0) { + // create a group + GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_Object_ptr GrObj = + GOp->CreateGroup( theMainShape, SeqS.Value(1).ShapeType() ); + AddInStudy(theStudy, GrObj, GrName, theMainShape._retn()); + CORBA::String_var GrEntry = GrObj->GetEntry(); + Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry); + // add named objects + //Handle(GEOM_Object) anObj; + for(int i=1; i<=SeqS.Length(); i++) { + TopoDS_Shape aValue = SeqS.Value(i); + //anArray = new TColStd_HArray1OfInteger(1,1); + Standard_Integer anIndex = anIndices.FindIndex(aValue); + //anArray->SetValue(1, anIndex); + GOp->AddObject(GrObj,anIndex); + //anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE); + //if (anObj.IsNull()) continue; + //Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1); + //if (aFunction.IsNull()) continue; + //GEOM_ISubShape aSSI(aFunction); + //aSSI.SetMainShape(aMainShape->GetLastFunction()); + //aSSI.SetIndices(anArray); + //aFunction->SetValue(aValue); + //GOp->UnionIDs(GrObj, anIndex); + //SALOMEDS::SObject_var aResultSO; + //TCollection_AsciiString anEntry; + //TDF_Tool::Entry(anObj->GetEntry(),anEntry); + //GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString()); + //AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj); + } + } +} + + +//============================================================================ +// function : PublishNamedShapesInStudy +// purpose : +//============================================================================ +GEOM::ListOfGO* GEOM_Gen_i:: + PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy, + //SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theObject) +{ + //Unexpect aCatch(SALOME_SalomeException); + GEOM::ListOfGO_var aResList = new GEOM::ListOfGO; + + //CORBA::Object_var theObject = theSObject->GetObject(); + GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject); + if(theMainShape->_is_nil()) return aResList._retn(); + + CORBA::String_var entry = theMainShape->GetEntry(); + Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry); + if (aMainShape.IsNull()) return aResList._retn(); + TopoDS_Shape MainSh = aMainShape->GetValue(); + + TDF_Label aMainLbl = aMainShape->GetEntry(); + TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS; + TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN; + TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True); + for(; anIt.More(); anIt.Next()) { + Handle(TNaming_NamedShape) anAttr = + Handle(TNaming_NamedShape)::DownCast(anIt.Value()); + if(anAttr.IsNull()) continue; + TopoDS_Shape S = anAttr->Get(); + TDF_Label L = anAttr->Label(); + //if(S.IsEqual(MainSh)) continue; + Handle(TDataStd_Name) aName; + if(L.FindAttribute(TDataStd_Name::GetID(),aName)) { + TCollection_ExtendedString EName = aName->Get(); + if(S.ShapeType()==TopAbs_SOLID) { + SolidSeqS.Append(S); + SolidSeqN.Append(aName->Get()); + } + else if(S.ShapeType()==TopAbs_FACE) { + FaceSeqS.Append(S); + FaceSeqN.Append(aName->Get()); + } + else if(S.ShapeType()==TopAbs_EDGE) { + EdgeSeqS.Append(S); + EdgeSeqN.Append(aName->Get()); + } + else if(S.ShapeType()==TopAbs_VERTEX) { + VertSeqS.Append(S); + VertSeqN.Append(aName->Get()); + } + } + } + + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(MainSh, anIndices); + + CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN, + "Group_Of_Named_Solids", aResList); + + CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN, + "Group_Of_Named_Faces", aResList); + + CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN, + "Group_Of_Named_Edges", aResList); + + CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN, + "Group_Of_Named_Vertices", aResList); + + return aResList._retn(); +} + + //============================================================================ // function : Save() // purpose : save OCAF/Geom document @@ -326,7 +506,8 @@ SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, // Prepare a file name to open TCollection_AsciiString aNameWithExt(""); if (isMultiFile) - aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str()); + aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath + (theComponent->GetStudy()->URL())).c_str()); aNameWithExt += TCollection_AsciiString("_GEOM.sgd"); aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString()); // Build a full file name of temporary file @@ -389,7 +570,8 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, // Prepare a file name to open TCollection_AsciiString aNameWithExt(""); if (isMultiFile) - aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str()); + aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath + (theComponent->GetStudy()->URL())).c_str()); aNameWithExt += TCollection_AsciiString("_GEOM.sgd"); TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt); @@ -424,7 +606,8 @@ CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent, //============================================================================ void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent) { - _impl->Close(theComponent->GetStudy()->StudyId()); + SALOMEDS::Study_var aStudy= theComponent->GetStudy(); + _impl->Close(aStudy->StudyId()); } //============================================================================ @@ -438,7 +621,10 @@ CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) { SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value())); + CORBA::String_var aString=anIOR->Value(); + anIOR->Destroy(); + CORBA::Object_var anObj = _orb->string_to_object(aString); + GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj); // If the object is null one it can't be copied: return false if (anObject->_is_nil()) return false; return true; @@ -448,14 +634,16 @@ CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) { // function : CopyFrom() // purpose : //============================================================================ -SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) { +SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) +{ // Declare a sequence of the byte to store the copied object SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile; // Try to get GEOM_Object object by given SObject SALOMEDS::GenericAttribute_var anAttr; if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn(); - GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())); + GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow + (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())); if (anObject->_is_nil()) return aStreamFile._retn(); aStreamFile = anObject->GetShapeStream(); @@ -491,7 +679,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, // Retrieve a TopoDS_Shape from byte stream TopoDS_Shape aTopology; - istrstream aStreamedBrep((char*) &theStream[0], theStream.length()); + std::istrstream aStreamedBrep((char*) &theStream[0], theStream.length()); BRep_Builder aBuilder; try { BRepTools::Read(aTopology, aStreamedBrep, aBuilder); @@ -523,6 +711,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); CORBA::String_var objStr = _orb->object_to_string(obj); anIOR->SetValue(objStr.in()); + anIOR->Destroy(); // Return the created in the Study SObject return aNewSO._retn(); @@ -557,6 +746,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in()); if(aFatherSO->_is_nil()) return aResultSO._retn(); aResultSO = aStudyBuilder->NewObject(aFatherSO); + aFatherSO->Destroy(); //aStudyBuilder->Addreference(aResultSO, aResultSO); } @@ -576,6 +766,8 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy, if(aSO->_is_nil()) continue; SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO); aStudyBuilder->Addreference(aSubSO, aSO); + aSO->Destroy(); + aSubSO->Destroy(); } return aResultSO._retn(); @@ -586,22 +778,29 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy, // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments. // To be used from python scripts out of geompy.addToStudy (non-default usage) //============================================================================ -CORBA::Boolean GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy, - GEOM::GEOM_Object_ptr theObject, - const GEOM::ListOfGO& theArgs, - GEOM::find_shape_method theFindMethod, - CORBA::Boolean theInheritFirstArg) +GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy, + GEOM::GEOM_Object_ptr theObject, + const GEOM::ListOfGO& theArgs, + GEOM::find_shape_method theFindMethod, + CORBA::Boolean theInheritFirstArg, + CORBA::Boolean theAddPrefix) { + GEOM::ListOfGO_var aParts = new GEOM::ListOfGO; if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject)) - return false; + return aParts._retn(); - // find SObject in the study + // find SObject in the study if it is already published CORBA::String_var anIORo = _orb->object_to_string(theObject); SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in()); - if (CORBA::is_nil(aSO)) - return false; - - return RestoreSubShapes(theStudy, theObject, aSO, theArgs, theFindMethod, theInheritFirstArg); + //PTv, IMP 0020001, The salome object + // is not obligatory in case of invokation from script + // if (CORBA::is_nil(aSO)) + // return aParts._retn(); + + aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs, + theFindMethod, theInheritFirstArg, theAddPrefix); + if (!CORBA::is_nil(aSO)) aSO->Destroy(); + return aParts._retn(); } //============================================================================ @@ -609,18 +808,20 @@ CORBA::Boolean GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy, // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments. // To be used from GUI and from geompy.addToStudy //============================================================================ -CORBA::Boolean GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy, - SALOMEDS::SObject_ptr theSObject, - const GEOM::ListOfGO& theArgs, - GEOM::find_shape_method theFindMethod, - CORBA::Boolean theInheritFirstArg) +GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theSObject, + const GEOM::ListOfGO& theArgs, + GEOM::find_shape_method theFindMethod, + CORBA::Boolean theInheritFirstArg, + CORBA::Boolean theAddPrefix) { + GEOM::ListOfGO_var aParts = new GEOM::ListOfGO; if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject)) - return false; + return aParts._retn(); SALOMEDS::GenericAttribute_var anAttr; if (!theSObject->FindAttribute(anAttr, "AttributeIOR")) - return false; + return aParts._retn(); SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); CORBA::String_var anIORso = anAttrIOR->Value(); @@ -628,9 +829,37 @@ CORBA::Boolean GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy, // get Object from SObject GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso)); if (CORBA::is_nil(anO)) - return false; + return aParts._retn(); - return RestoreSubShapes(theStudy, anO, theSObject, theArgs, theFindMethod, theInheritFirstArg); + aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs, + theFindMethod, theInheritFirstArg, theAddPrefix); + return aParts._retn(); +} + +//============================================================================ +// function : addToListOfGO +// purpose : static local function +//============================================================================ +static void addToListOfGO( GEOM::GEOM_Object_ptr theObject, + GEOM::ListOfGO& theList ) +{ + const int oldLen = theList.length(); + theList.length(oldLen + 1); + theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject ); +} + +//============================================================================ +// function : addToListOfGO +// purpose : static local function +//============================================================================ +static void addToListOfGO( const GEOM::ListOfGO& theSrcList, + GEOM::ListOfGO& theTrgList ) +{ + const int oldLen = theTrgList.length(); + const int srcLen = theSrcList.length(); + theTrgList.length(oldLen + srcLen); + for( int i = 0; i < srcLen; i++ ) + theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] ); } //============================================================================ @@ -638,15 +867,19 @@ CORBA::Boolean GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy, // purpose : Private method. Works only if both theObject and theSObject // are defined, and does not check, if they correspond to each other. //============================================================================ -CORBA::Boolean GEOM_Gen_i::RestoreSubShapes (SALOMEDS::Study_ptr theStudy, +GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, SALOMEDS::SObject_ptr theSObject, const GEOM::ListOfGO& theArgs, GEOM::find_shape_method theFindMethod, - CORBA::Boolean theInheritFirstArg) + CORBA::Boolean theInheritFirstArg, + CORBA::Boolean theAddPrefix) { - if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) || CORBA::is_nil(theSObject)) - return false; + GEOM::ListOfGO_var aParts = new GEOM::ListOfGO; + //PTv, IMP 0020001, The salome object + // is not obligatory in case of invokation from script + if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/) + return aParts._retn(); // Arguments to be published GEOM::ListOfGO_var aList; @@ -659,7 +892,7 @@ CORBA::Boolean GEOM_Gen_i::RestoreSubShapes (SALOMEDS::Study_ptr theStudy, aList = new GEOM::ListOfGO; aList->length(aLength); for (int i = 0; i < aLength; i++) { - aList[i] = theArgs[i]; + aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] ); } } else { @@ -670,149 +903,234 @@ CORBA::Boolean GEOM_Gen_i::RestoreSubShapes (SALOMEDS::Study_ptr theStudy, } if (aLength < 1) - return false; + return aParts._retn(); if (theInheritFirstArg || (nbArgsActual == 1)) { // Do not publish argument's reflection, // but only reconstruct its published sub-shapes - GEOM::GEOM_Object_var anArgO = aList[0]; - CORBA::String_var anIOR = _orb->object_to_string(anArgO); + CORBA::String_var anIOR = _orb->object_to_string(aList[0]); SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in()); - GEOM::ListOfGO_var aParts = - RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, theFindMethod); + aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, theFindMethod, theAddPrefix); // set the color of the transformed shape to the color of initial shape theObject->SetColor(aList[0]->GetColor()); - - return (aParts->length() > 0); + anArgSO->Destroy(); } - - // Get interface, containing method, which we will use to reconstruct sub-shapes - GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); - GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); - - // Reconstruct arguments and tree of sub-shapes of the arguments - CORBA::String_var anIOR; - SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); - for (Standard_Integer i = 0; i < aLength; i++) - { - GEOM::GEOM_Object_var anArgO = aList[i]; - if (!CORBA::is_nil(anArgO)) { - anIOR = _orb->object_to_string(anArgO); - SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in()); - TCollection_AsciiString anArgName; - if (CORBA::is_nil(anArgSO)) { - anArgName = "arg_"; - anArgName += TCollection_AsciiString(i); - } - else { - anArgName = anArgSO->GetName(); - } - - // Find a sub-shape of theObject in place of the argument - GEOM::GEOM_Object_var aSubO; - switch (theFindMethod) { - case GEOM::FSM_GetInPlace: - { - // Use GetInPlace - aSubO = aShapesOp->GetInPlace(theObject, anArgO); - } - break; - case GEOM::FSM_Transformed: - { - // transformation, cannot use GetInPlace, operate with indices - GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices(); - if (anIDs->length() > 1) { - // group - aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO)); - if (!CORBA::is_nil(aSubO)) - aGroupOp->UnionIDs(aSubO, anIDs); - } - else { - // single sub-shape - aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]); - } - } - break; - case GEOM::FSM_GetSame: - { - // Use GetSame - aSubO = aShapesOp->GetSame(theObject, anArgO); - } - break; - case GEOM::FSM_GetShapesOnShape: - { - // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids - aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject, - (short)GEOM::SOLID, GEOM::ST_ONIN); - } - break; - case GEOM::FSM_GetInPlaceByHistory: - { - // Use GetInPlaceByHistory - aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO); - } - break; - default: - {} - } - - if (!CORBA::is_nil(aSubO)) { - // Publish the sub-shape - TCollection_AsciiString aSubName ("from_"); - aSubName += anArgName; - SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject); - aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString()); - // Restore color - aSubO->SetColor(anArgO->GetColor()); - - if (!CORBA::is_nil(anArgSO)) { - // Restore published sub-shapes of the argument - if (theFindMethod == GEOM::FSM_GetInPlaceByHistory) - // pass theObject, because only it has the history - RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod); - else - RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, aSubO, theFindMethod); - } + else { + // Get interface, containing method, which we will use to reconstruct sub-shapes + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + + // Reconstruct arguments and tree of sub-shapes of the arguments + CORBA::String_var anIOR; + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + for (Standard_Integer i = 0; i < aLength; i++) + { + GEOM::GEOM_Object_var anArgO = aList[i]; + if (!CORBA::is_nil(anArgO)) { + anIOR = _orb->object_to_string(anArgO); + SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in()); + TCollection_AsciiString anArgName; + if (CORBA::is_nil(anArgSO)) { + anArgName = "arg_"; + anArgName += TCollection_AsciiString(i); + } + else { + anArgName = anArgSO->GetName(); + } + + // Find a sub-shape of theObject in place of the argument + GEOM::GEOM_Object_var aSubO; + switch (theFindMethod) { + case GEOM::FSM_GetInPlace: + { + // Use GetInPlace + aSubO = aShapesOp->GetInPlace(theObject, anArgO); + } + break; + case GEOM::FSM_Transformed: + { + // transformation, cannot use GetInPlace, operate with indices + GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices(); + if (anIDs->length() > 1) { + // group + aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO)); + if (!CORBA::is_nil(aSubO)) + aGroupOp->UnionIDs(aSubO, anIDs); + } + else if (anIDs->length() > 0) { + // single sub-shape + aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]); + } + } + break; + case GEOM::FSM_GetSame: + { + // Use GetSame + aSubO = aShapesOp->GetSame(theObject, anArgO); + } + break; + case GEOM::FSM_GetShapesOnShape: + { + // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids + aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject, + (short)GEOM::SOLID, GEOM::ST_ONIN); + } + break; + case GEOM::FSM_GetInPlaceByHistory: + { + // Use GetInPlaceByHistory + aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO); + } + break; + default: + {} + } + + if (!CORBA::is_nil(aSubO)) { + // add to parts list + addToListOfGO( aSubO, aParts ); + + // Publish the sub-shape + SALOMEDS::SObject_var aSubSO; + if (!CORBA::is_nil(theSObject)) { + TCollection_AsciiString aSubName; + if (theAddPrefix) { + aSubName = "from_"; + } + aSubName += anArgName; + aSubSO = aStudyBuilder->NewObject(theSObject); + aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString()); + // Restore color + aSubO->SetColor(anArgO->GetColor()); + } + + if (!CORBA::is_nil(anArgSO)) { + // Restore published sub-shapes of the argument + GEOM::ListOfGO_var aSubParts; + if (theFindMethod == GEOM::FSM_GetInPlaceByHistory) + // pass theObject, because only it has the history + aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, + theObject, theFindMethod, theAddPrefix); + else + aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, + aSubO, theFindMethod, theAddPrefix); + // add to parts list + addToListOfGO( aSubParts, aParts ); + } + } + else { // GetInPlace failed, try to build from published parts + if (!CORBA::is_nil(anArgSO)) { + SALOMEDS::SObject_var aSubSO; + if (!CORBA::is_nil(theSObject)) + aSubSO = aStudyBuilder->NewObject(theSObject); + + // Restore published sub-shapes of the argument + GEOM::ListOfGO_var aSubParts = + RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, + theObject, theFindMethod, theAddPrefix); + + // add to parts list + addToListOfGO( aSubParts, aParts ); + + if (aSubParts->length() > 0) { + // try to build an argument from a set of its sub-shapes, + // that published and will be reconstructed + if (aSubParts->length() > 1) { + aSubO = aShapesOp->MakeCompound(aSubParts); + // add to parts list + addToListOfGO( aSubO, aParts ); + } + else { + aSubO = aSubParts[0]; + } + if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) { + // Publish the sub-shape + TCollection_AsciiString aSubName; + if (theAddPrefix) { + aSubName = "from_parts_of_"; + } + aSubName += anArgName; + aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString()); + // Restore color + aSubO->SetColor(anArgO->GetColor()); + } + } + else if (!CORBA::is_nil(aSubSO)) { + // remove created aSubSO, because no parts have been found + aStudyBuilder->RemoveObject(aSubSO); + } + } + } // try to build from published parts + anArgSO->Destroy(); } - else { // GetInPlace failed, try to build from published parts - if (!CORBA::is_nil(anArgSO)) { - SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject); - - // Restore published sub-shapes of the argument - GEOM::ListOfGO_var aParts = - RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod); - - if (aParts->length() > 0) { - // try to build an argument from a set of its sub-shapes, - // that published and will be reconstructed - if (aParts->length() > 1) { - aSubO = aShapesOp->MakeCompound(aParts); - } - else { - aSubO = aParts[0]; - } - if (!CORBA::is_nil(aSubO)) { - // Publish the sub-shape - TCollection_AsciiString aSubName ("from_parts_of_"); - aSubName += anArgName; - aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString()); - // Restore color - aSubO->SetColor(anArgO->GetColor()); - } - } - else { - // remove created aSubSO, because no parts have been found - aStudyBuilder->RemoveObject(aSubSO); - } - } - } // try to build from published parts + } // process arguments + } + std::set anObjEntryMap; + GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO; + int nbRes = 0; + int nb = aParts->length(); + aResParts->length(nb); + if (nb > 0) + { + Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry()); + Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction(); + GEOM::TPythonDump pd (aFunction, true); + pd <<"["; + int i = 0, j = 0; + for ( ; i < nb; i++ ) + { + GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] ); + if (CORBA::is_nil(anObj)) + continue; + char* anEntry = anObj->GetEntry(); + if (anObjEntryMap.count(anEntry)) + continue; // already treated + anObjEntryMap.insert(anEntry); + aResParts[nbRes++] = anObj; + // clear python dump of object + Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry); + Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction(); + if ( !anObjFun.IsNull() ) + anObjFun->SetDescription( "" ); + if ( j > 0 ) + pd << ", "; + pd << aGeomObj; + j++; } - } // process arguments - - return true; + pd <<"]" << " = geompy.RestoreSubShapes(" << aMainObj << ", " << "["; + i = 0; nb = theArgs.length(); j = 0; + for ( ; i < nb; i++ ) + { + GEOM::GEOM_Object_var anObj = theArgs[ i ]; + if (CORBA::is_nil(anObj)) + continue; + Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry()); + if ( j > 0 ) + pd << ", "; + pd << aGeomObj; + j++; + } + pd <<"]" << ", " <<"geompy.GEOM."; + switch (theFindMethod) { + case GEOM::FSM_GetInPlace: + pd << "FSM_GetInPlace"; break; + case GEOM::FSM_Transformed: + pd << "FSM_Transformed"; break; + case GEOM::FSM_GetSame: + pd << "FSM_GetSame"; break; + case GEOM::FSM_GetShapesOnShape: + pd << "FSM_GetShapesOnShape"; break; + case GEOM::FSM_GetInPlaceByHistory: + default: + pd << "FSM_GetInPlaceByHistory"; break; + } + pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")"; + } + aResParts->length(nbRes); + return aResParts._retn(); } //============================================================================ @@ -823,12 +1141,14 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th SALOMEDS::SObject_ptr theOldSO, SALOMEDS::SObject_ptr theNewSO, GEOM::GEOM_Object_ptr theNewO, - GEOM::find_shape_method theFindMethod) + GEOM::find_shape_method theFindMethod, + CORBA::Boolean theAddPrefix) { int i = 0; GEOM::ListOfGO_var aParts = new GEOM::ListOfGO; + GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO; if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) || - CORBA::is_nil(theNewO) || CORBA::is_nil(theNewSO)) + CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/) return aParts._retn(); SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); @@ -909,53 +1229,77 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th // add the part to the list aParts[i] = aNewSubO; i++; - - // Publish the sub-shape - TCollection_AsciiString aSubName ("from_"); - aSubName += anArgName; - SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO); - aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString()); - // Restore color - aNewSubO->SetColor(anOldSubO->GetColor()); - + // add to parts list + addToListOfGO( aNewSubO, aNewParts ); + + SALOMEDS::SObject_var aNewSubSO; + if (!CORBA::is_nil(theNewSO)) { + // Publish the sub-shape + TCollection_AsciiString aSubName; + if (theAddPrefix) { + aSubName = "from_"; + } + aSubName += anArgName; + aNewSubSO = aStudyBuilder->NewObject(theNewSO); + aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString()); + // Restore color + aNewSubO->SetColor(anOldSubO->GetColor()); + } // Restore published sub-shapes of the argument + GEOM::ListOfGO_var aSubParts; if (theFindMethod == GEOM::FSM_GetInPlaceByHistory) // pass the main shape as Object, because only it has the history - RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod); + aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + theNewO, theFindMethod, theAddPrefix); else - RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, aNewSubO, theFindMethod); + aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + aNewSubO, theFindMethod, theAddPrefix); + // add to parts list + addToListOfGO( aSubParts, aNewParts ); } else { // GetInPlace failed, try to build from published parts - SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO); + SALOMEDS::SObject_var aNewSubSO; + if (!CORBA::is_nil(theNewSO)) + aNewSubSO = aStudyBuilder->NewObject(theNewSO); // Restore published sub-shapes of the argument - GEOM::ListOfGO_var aParts = - RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod); + GEOM::ListOfGO_var aSubParts = + RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + theNewO, theFindMethod, theAddPrefix); + // add to parts list + addToListOfGO( aSubParts, aNewParts ); - if (aParts->length() > 0) { + if (aSubParts->length() > 0) { // try to build an object from a set of its sub-shapes, // that published and will be reconstructed - if (aParts->length() > 1) { - aNewSubO = aShapesOp->MakeCompound(aParts); + if (aSubParts->length() > 1) { + aNewSubO = aShapesOp->MakeCompound(aSubParts); + // add to parts list + addToListOfGO( aNewSubO, aNewParts ); } else { - aNewSubO = aParts[0]; + aNewSubO = aSubParts[0]; } if (!CORBA::is_nil(aNewSubO)) { // add the part to the list - aParts[i] = aNewSubO; + aSubParts[i] = aNewSubO; i++; // Publish the sub-shape - TCollection_AsciiString aSubName = "from_parts_of_"; - aSubName += anArgName; - aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString()); - // Restore color - aNewSubO->SetColor(anOldSubO->GetColor()); + if (!CORBA::is_nil(aNewSubSO)) { + TCollection_AsciiString aSubName; + if (theAddPrefix) { + aSubName = "from_parts_of_"; + } + aSubName += anArgName; + aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString()); + // Restore color + aNewSubO->SetColor(anOldSubO->GetColor()); + } } } - else { + else if (!CORBA::is_nil(aNewSubSO)) { // remove created aSubSO, because no parts have been found aStudyBuilder->RemoveObject(aNewSubSO); } @@ -965,6 +1309,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th } // iterate on published sub-shapes aParts->length(i); + // add to parts list + addToListOfGO( aNewParts, aParts ); return aParts._retn(); } @@ -1012,6 +1358,7 @@ GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theS GEOM_IBasicOperations_i* aServant = new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID)); + PortableServer::ObjectId_var id = _poa->activate_object(aServant); // activate the CORBA servant GEOM::GEOM_IBasicOperations_var operations = aServant->_this(); return operations._retn(); @@ -1051,6 +1398,7 @@ GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long th GEOM_I3DPrimOperations_i* aServant = new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID)); + PortableServer::ObjectId_var id = _poa->activate_object(aServant); // activate the CORBA servant GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this(); @@ -1237,6 +1585,26 @@ GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theS return operations._retn(); } +//============================================================================ +// function : GetIAdvancedOperations +// purpose : +//============================================================================ +GEOM::GEOM_IAdvancedOperations_ptr GEOM_Gen_i::GetIAdvancedOperations(CORBA::Long theStudyID) + throw ( SALOME::SALOME_Exception ) +{ + Unexpect aCatch(SALOME_SalomeException); + MESSAGE( "GEOM_Gen_i::GetIAdvancedOperations" ); + + GEOM::GEOM_Gen_ptr engine = _this(); + + GEOM_IAdvancedOperations_i* aServant = + new GEOM_IAdvancedOperations_i(_poa, engine, _impl->GetIAdvancedOperations(theStudyID)); + + // activate the CORBA servant + GEOM::GEOM_IAdvancedOperations_var operations = aServant->_this(); + return operations._retn(); +} + //============================================================================= /*! * AddSubShape @@ -1245,8 +1613,10 @@ GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theS GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape, const GEOM::ListOfLong& theIndices) { - if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil(); - Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry()); + if (CORBA::is_nil(theMainShape) || theIndices.length() < 1) + return GEOM::GEOM_Object::_nil(); + CORBA::String_var entry = theMainShape->GetEntry(); + Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), entry); if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil(); Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length()); @@ -1268,7 +1638,7 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShap void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject) { CORBA::String_var anEntry = theObject->GetEntry(); - Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry); + Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false); if (anObject.IsNull()) return; _impl->RemoveObject(anObject); return; @@ -1306,7 +1676,7 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* { GEOM::GEOM_Object_var obj; Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry); - if (handle_object.IsNull()) return NULL; + if (handle_object.IsNull()) return obj._retn(); TCollection_AsciiString stringIOR = handle_object->GetIOR(); if (stringIOR.Length() > 1) { @@ -1316,7 +1686,9 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* } GEOM::GEOM_Gen_ptr engine = _this(); + //transfer the reference to GEOM_Object_i GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object); + PortableServer::ObjectId_var id = _poa->activate_object(servant); obj = servant->_this(); CORBA::String_var objStr = _orb->object_to_string(obj); @@ -1354,11 +1726,14 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) { SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); CORBA::String_var aVal = anIOR->Value(); + anIOR->Destroy(); CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal); aGeomObject = GEOM::GEOM_Object::_narrow(anObject); } + if (!aSObj->_is_nil() ) + aSObj->Destroy(); - char* aTypeInfo = "Object"; + const char* aTypeInfo = "Object"; if ( !aGeomObject->_is_nil() ) { GEOM::GEOM_IKindOfShape::shape_kind aKind; GEOM::ListOfLong_var anInts; @@ -1445,7 +1820,7 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) aTypeInfo = "Circle"; break; case GEOM::GEOM_IKindOfShape::ARC_CIRCLE: - aTypeInfo = "Ark"; + aTypeInfo = "Arc Circle"; break; case GEOM::GEOM_IKindOfShape::ELLIPSE: aTypeInfo = "Ellipse"; @@ -1471,10 +1846,12 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) } } - char anInfo [strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo)]; + char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3]; sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo); - return CORBA::string_dup(anInfo); + char* ret = CORBA::string_dup(anInfo); + delete [] anInfo; + return ret; } //===================================================================================== @@ -1482,16 +1859,19 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) //===================================================================================== extern "C" { -GEOM_I_EXPORT - PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, - const char * interfaceName) + /* + GEOM_I_EXPORT + PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*); + */ + + GEOM_I_EXPORT + PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId* contId, + const char* instanceName, + const char* interfaceName) { - GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName); - // Don't understand the reason of this register ???? -// myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example - return myGEOM_Gen_i->getId(); + GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName); + return myGEOM_Gen_i->getId(); } }