X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOM_I%2FGEOM_Gen_i.cc;h=3dec744598d0d66bea80c39edcbf6df1f18dc184;hb=bed71e55e89040080f5b0ca691d9654b59a26a0d;hp=3bc08c7c81e54fd1dbca57fb4bb3bb5e3cb0eb84;hpb=57c06196d908503052c2c6f2e465a032a7e9dcdb;p=modules%2Fgeom.git diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 3bc08c7c8..3dec74459 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -1,23 +1,24 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2012 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 +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com #ifdef WNT #pragma warning( disable:4786 ) @@ -27,10 +28,10 @@ #include "GEOM_Gen_i.hh" #include "GEOM_Object_i.hh" +#include "GEOM_version.h" #include -#include -//#include +#include #include "Utils_CorbaException.hxx" #include "OpUtil.hxx" @@ -66,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; @@ -113,9 +114,9 @@ GEOM_Gen_i::~GEOM_Gen_i() { // purpose : //============================================================================ char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, - const char* IORString, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII) + const char* IORString, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) { GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString)); if (!CORBA::is_nil(anObject)) { @@ -132,9 +133,9 @@ char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, // : The IOR (IORName) of object created is returned //============================================================================ char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, - const char* aLocalPersistentID, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII) + const char* aLocalPersistentID, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) { SALOMEDS::Study_var aStudy = theSObject->GetStudy(); @@ -163,9 +164,9 @@ bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) // purpose : //============================================================================ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, - SALOMEDS::SObject_ptr theSObject, - CORBA::Object_ptr theObject, - const char* theName) throw (SALOME::SALOME_Exception) + SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theObject, + const char* theName) throw (SALOME::SALOME_Exception) { Unexpect aCatch(SALOME_SalomeException); SALOMEDS::SObject_var aResultSO; @@ -182,11 +183,11 @@ 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(); + aName->UnRegister(); anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap"); SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr); aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry"); - aPixMap->Destroy(); + aPixMap->UnRegister(); aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this()); } if (aFather->_is_nil()) return aResultSO; @@ -198,69 +199,73 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM); } - anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"); - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject); - anIOR->SetValue(aGeomObjIOR); - anIOR->Destroy(); + aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR); - anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap"); - SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); TCollection_AsciiString aShapeName("Shape_"); - if ( aShape->GetType() == GEOM_GROUP ) { + CORBA::Long mytype=aShape->GetType(); + if ( mytype == GEOM_GROUP ) { GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() ); switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) { case TopAbs_VERTEX: - aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" ); + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" ); aShapeName = "Group_Of_Vertices_"; break; case TopAbs_EDGE: - aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" ); + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE"); aShapeName = "Group_Of_Edges_"; break; case TopAbs_FACE: - aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" ); + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE"); aShapeName = "Group_Of_Faces_"; break; case TopAbs_SOLID: - aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" ); + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID"); aShapeName = "Group_Of_Solids_"; break; } - } else if ( aShape->GetType() == GEOM_MARKER ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" ); + } else if ( mytype == GEOM_MARKER ) { + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS"); aShapeName = "LocalCS_"; - } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" ); + } else if ( mytype > ADVANCED_BASE ) { + char buf[20]; + sprintf( buf, "%d", aShape->GetType() ); + std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf; + aResultSO->SetAttrString("AttributePixMap",advId.c_str()); + aShapeName = "Advanced_"; + } else { + GEOM::shape_type myshapetype=aShape->GetShapeType(); + if ( myshapetype == GEOM::COMPOUND ) { + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" ); aShapeName = "Compound_"; - } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" ); + } else if ( myshapetype == GEOM::COMPSOLID ) { + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID"); aShapeName = "Compsolid_"; - } else if ( aShape->GetShapeType() == GEOM::SOLID ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" ); + } else if ( myshapetype == GEOM::SOLID ) { + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID"); aShapeName = "Solid_"; - } else if ( aShape->GetShapeType() == GEOM::SHELL ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" ); + } else if ( myshapetype == GEOM::SHELL ) { + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL"); aShapeName = "Shell_"; - } else if ( aShape->GetShapeType() == GEOM::FACE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" ); + } else if ( myshapetype == GEOM::FACE ) { + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE"); aShapeName = "Face_"; - } else if ( aShape->GetShapeType() == GEOM::WIRE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" ); + } else if ( myshapetype == GEOM::WIRE ) { + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE"); aShapeName = "Wire_"; - } else if ( aShape->GetShapeType() == GEOM::EDGE ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" ); + } else if ( myshapetype == GEOM::EDGE ) { + aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE"); aShapeName = "Edge_"; - } else if ( aShape->GetShapeType() == GEOM::VERTEX ) { - aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" ); + } else if ( myshapetype == GEOM::VERTEX ) { + aResultSO->SetAttrString("AttributePixMap","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 + + // BEGIN: try to find existed name for current shape bool HasName = false; // recieve current TopoDS shape CORBA::String_var entry = aShape->GetEntry(); @@ -273,24 +278,28 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, } entry = aMainSh->GetEntry(); Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry); - TDF_Label aMainLbl = anObj->GetEntry(); + TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry(); + // check all named shapes using iterator - TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True); - for(; anIt.More(); anIt.Next()) { + TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True); + + for (; anIt.More() && !HasName; anIt.Next()) { Handle(TNaming_NamedShape) anAttr = Handle(TNaming_NamedShape)::DownCast(anIt.Value()); - if(anAttr.IsNull()) continue; + 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; + if (S.IsEqual(TopoSh)) { + TDF_Label L = anAttr->Label(); + Handle(TDataStd_Name) aName; + if (L.FindAttribute(TDataStd_Name::GetID(), aName)) { + aShapeName = aName->Get(); + HasName = true; + } } } + // END: try to find existed name for current shape - if(!HasName) { + 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 @@ -300,8 +309,8 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_var obj; TCollection_AsciiString aNewShapeName; do { - aNewShapeName = aShapeName + TCollection_AsciiString(++i); - obj = theStudy->FindObject( aNewShapeName.ToCString() ); + aNewShapeName = aShapeName + TCollection_AsciiString(++i); + obj = theStudy->FindObject( aNewShapeName.ToCString() ); } while ( !obj->_is_nil() ); aShapeName = aNewShapeName; @@ -315,10 +324,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, 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(); + aResultSO->SetAttrString("AttributeName",aShapeName.ToCString()); //Set NoteBook variables used in the object creation TCollection_AsciiString aVars; @@ -328,22 +334,19 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, SALOMEDS::ListOfStrings aListOfVars = aSections[i]; for(int j = 0, m = aListOfVars.length(); j < m; j++) { if(theStudy->IsVariable(aListOfVars[j].in())) - aVars += TCollection_AsciiString(aListOfVars[j].in()); + aVars += TCollection_AsciiString(aListOfVars[j].in()); if(j != m-1) - aVars += ":"; + aVars += ":"; } if(i != n-1) aVars += "|"; } - anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeString"); - SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr); - aStringAttrib->SetValue(aVars.ToCString()); - aStringAttrib->Destroy(); + aResultSO->SetAttrString("AttributeString",aVars.ToCString()); - aFather->Destroy(); + aFather->UnRegister(); //Set a name of the GEOM object - aShape->SetName(theName); + aShape->SetName(aShapeName.ToCString()); return aResultSO._retn(); } @@ -354,12 +357,12 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, // 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) + 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); @@ -405,8 +408,8 @@ void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy, //============================================================================ GEOM::ListOfGO* GEOM_Gen_i:: PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy, - //SALOMEDS::SObject_ptr theSObject, - CORBA::Object_ptr theObject) + //SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theObject) { //Unexpect aCatch(SALOME_SalomeException); GEOM::ListOfGO_var aResList = new GEOM::ListOfGO; @@ -435,20 +438,20 @@ GEOM::ListOfGO* GEOM_Gen_i:: if(L.FindAttribute(TDataStd_Name::GetID(),aName)) { TCollection_ExtendedString EName = aName->Get(); if(S.ShapeType()==TopAbs_SOLID) { - SolidSeqS.Append(S); - SolidSeqN.Append(aName->Get()); + SolidSeqS.Append(S); + SolidSeqN.Append(aName->Get()); } else if(S.ShapeType()==TopAbs_FACE) { - FaceSeqS.Append(S); - FaceSeqN.Append(aName->Get()); + FaceSeqS.Append(S); + FaceSeqN.Append(aName->Get()); } else if(S.ShapeType()==TopAbs_EDGE) { - EdgeSeqS.Append(S); - EdgeSeqN.Append(aName->Get()); + EdgeSeqS.Append(S); + EdgeSeqN.Append(aName->Get()); } else if(S.ShapeType()==TopAbs_VERTEX) { - VertSeqS.Append(S); - VertSeqN.Append(aName->Get()); + VertSeqS.Append(S); + VertSeqN.Append(aName->Get()); } } } @@ -457,16 +460,16 @@ GEOM::ListOfGO* GEOM_Gen_i:: TopExp::MapShapes(MainSh, anIndices); CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN, - "Group_Of_Named_Solids", aResList); + "Group_Of_Named_Solids", aResList); CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN, - "Group_Of_Named_Faces", aResList); + "Group_Of_Named_Faces", aResList); CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN, - "Group_Of_Named_Edges", aResList); + "Group_Of_Named_Edges", aResList); CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN, - "Group_Of_Named_Vertices", aResList); + "Group_Of_Named_Vertices", aResList); return aResList._retn(); } @@ -477,8 +480,8 @@ GEOM::ListOfGO* GEOM_Gen_i:: // purpose : save OCAF/Geom document //============================================================================ SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile) { + const char* theURL, + bool isMultiFile) { SALOMEDS::TMPFile_var aStreamFile; // Get a temporary directory to store a file std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir(); @@ -522,8 +525,8 @@ SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, // purpose : //============================================================================ SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile) { + const char* theURL, + bool isMultiFile) { SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile); return aStreamFile._retn(); } @@ -534,9 +537,9 @@ SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, // purpose : //============================================================================ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, - const SALOMEDS::TMPFile& theStream, - const char* theURL, - bool isMultiFile) { + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile) { if (theStream.length() <= 9) { MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes "); @@ -586,9 +589,9 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, // purpose : //============================================================================ CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent, - const SALOMEDS::TMPFile& theStream, - const char* theURL, - bool isMultiFile) { + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile) { return Load(theComponent, theStream, theURL, isMultiFile); } @@ -615,7 +618,7 @@ CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) { SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); CORBA::String_var aString=anIOR->Value(); - anIOR->Destroy(); + anIOR->UnRegister(); 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 @@ -664,15 +667,15 @@ CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long th // purpose : //============================================================================ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, - CORBA::Long theObjectID, - SALOMEDS::SObject_ptr theObject) { + CORBA::Long theObjectID, + SALOMEDS::SObject_ptr theObject) { // Find the current Study and StudyBuilder SALOMEDS::Study_var aStudy = theObject->GetStudy(); SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); // Retrieve a TopoDS_Shape from byte stream TopoDS_Shape aTopology; - istrstream aStreamedBrep((char*) &theStream[0], theStream.length()); + std::istringstream aStreamedBrep((char*) &theStream[0]); BRep_Builder aBuilder; try { BRepTools::Read(aTopology, aStreamedBrep, aBuilder); @@ -704,7 +707,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(); + anIOR->UnRegister(); // Return the created in the Study SObject return aNewSO._retn(); @@ -724,9 +727,9 @@ char* GEOM_Gen_i::ComponentDataType() // purpose : //============================================================================ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy, - GEOM::GEOM_Object_ptr theObject, - const char* theName, - GEOM::GEOM_Object_ptr theFather) + GEOM::GEOM_Object_ptr theObject, + const char* theName, + GEOM::GEOM_Object_ptr theFather) { SALOMEDS::SObject_var aResultSO; if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO; @@ -739,7 +742,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(); + aFatherSO->UnRegister(); //aStudyBuilder->Addreference(aResultSO, aResultSO); } @@ -751,16 +754,20 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy, if(aLength < 1) return aResultSO._retn(); //Publish the arguments + TCollection_AsciiString aPrevID; // to avoid multiple references to same object for(Standard_Integer i = 0; i< aLength; i++) { GEOM::GEOM_Object_var anObject = aList[i]; if(anObject->_is_nil()) continue; IOR = _orb->object_to_string(anObject); SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in()); if(aSO->_is_nil()) continue; + CORBA::String_var anID = aSO->GetID(); + if ( aPrevID == anID.in() ) continue; + aPrevID = anID.in(); SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO); aStudyBuilder->Addreference(aSubSO, aSO); - aSO->Destroy(); - aSubSO->Destroy(); + aSO->UnRegister(); + aSubSO->UnRegister(); } return aResultSO._retn(); @@ -772,10 +779,11 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy, // To be used from python scripts out of geompy.addToStudy (non-default usage) //============================================================================ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy, - GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theObject, const GEOM::ListOfGO& theArgs, GEOM::find_shape_method theFindMethod, - CORBA::Boolean theInheritFirstArg) + CORBA::Boolean theInheritFirstArg, + CORBA::Boolean theAddPrefix) { GEOM::ListOfGO_var aParts = new GEOM::ListOfGO; if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject)) @@ -789,8 +797,39 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy, // if (CORBA::is_nil(aSO)) // return aParts._retn(); - aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs, theFindMethod, theInheritFirstArg); - aSO->Destroy(); + aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs, + theFindMethod, theInheritFirstArg, theAddPrefix); + if (!CORBA::is_nil(aSO)) aSO->UnRegister(); + return aParts._retn(); +} + +//============================================================================ +// function : RestoreGivenSubShapesO +// purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments. +// To be used from python scripts, generated by Dump Python. +//============================================================================ +GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (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 aParts._retn(); + + // 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()); + //PTv, IMP 0020001, The salome object + // is not obligatory in case of invokation from script + // if (CORBA::is_nil(aSO)) + // return aParts._retn(); + + aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs, + theFindMethod, theInheritFirstArg, theAddPrefix); + if (!CORBA::is_nil(aSO)) aSO->UnRegister(); return aParts._retn(); } @@ -799,11 +838,12 @@ GEOM::ListOfGO* 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 //============================================================================ -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) +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)) @@ -821,7 +861,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy, if (CORBA::is_nil(anO)) return aParts._retn(); - aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs, theFindMethod, theInheritFirstArg); + aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs, + theFindMethod, theInheritFirstArg, theAddPrefix); return aParts._retn(); } @@ -857,11 +898,12 @@ static void addToListOfGO( const GEOM::ListOfGO& theSrcList, // are defined, and does not check, if they correspond to each other. //============================================================================ 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) + GEOM::GEOM_Object_ptr theObject, + 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; //PTv, IMP 0020001, The salome object @@ -869,6 +911,9 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/) return aParts._retn(); + // For Dump Python (mantis issue 0020768) + GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO; + // Arguments to be published GEOM::ListOfGO_var aList; @@ -900,16 +945,28 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, CORBA::String_var anIOR = _orb->object_to_string(aList[0]); SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in()); - aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, theFindMethod); + // remember restored objects for Python Dump + addToListOfGO(aList[0], anOutArgs); + + aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, + anOutArgs, theFindMethod, theAddPrefix); // set the color of the transformed shape to the color of initial shape theObject->SetColor(aList[0]->GetColor()); - anArgSO->Destroy(); + // set the texture + if (theObject->GetShapeType() == GEOM::VERTEX) { + theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize()); + if (aList[0]->GetMarkerType() == GEOM::MT_USER) + theObject->SetMarkerTexture(aList[0]->GetMarkerTexture()); + } + + anArgSO->UnRegister(); } 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()); + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId()); // Reconstruct arguments and tree of sub-shapes of the arguments CORBA::String_var anIOR; @@ -938,6 +995,64 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, aSubO = aShapesOp->GetInPlace(theObject, anArgO); } break; + case GEOM::FSM_MultiTransformed: + { + // Only for Multi-transformations + GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anArgO, theObject); + if (!CORBA::is_nil(anArgOTrsf)) { + CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); + Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); + Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + anArgOTrsfFun->SetDescription(""); + aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf); + } + /* + Handle(GEOM_Function) anOFun = theObject->GetLastFunction(); + if (!anOFun.IsNull()) { + CORBA::String_var entryArg = anArgO->GetEntry(); + Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg); + if (!anArgOImpl.IsNull()) { + TopoDS_Shape anArgOShape = anArgOImpl->GetValue(); + TopoDS_Shape aMultiArgShape; + //GEOM::GEOM_Object_var anArgOMulti; // ??? + switch (anOFun->GetType()) { + case TRANSLATE_1D: + { + GEOMImpl_ITranslate aTI (anOFun); + aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI); + //anArgOMulti = aTrsfOp->Translate1D(anArgO, , , ); + } + break; + case TRANSLATE_2D: + { + GEOMImpl_ITranslate aTI (anOFun); + aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI); + } + break; + case ROTATE_1D: + { + GEOMImpl_IRotate aTI (anOFun); + //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI); + } + break; + case ROTATE_2D: + { + GEOMImpl_IRotate aTI (anOFun); + //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI); + } + break; + default: + {} + } + GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO + Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction(); + anArgOMultiFun->SetDescription(""); + aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti); + } + } + */ + } + break; case GEOM::FSM_Transformed: { // transformation, cannot use GetInPlace, operate with indices @@ -978,18 +1093,30 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, } if (!CORBA::is_nil(aSubO)) { + // remember restored objects for Python Dump + addToListOfGO(anArgO, anOutArgs); + // add to parts list addToListOfGO( aSubO, aParts ); // Publish the sub-shape SALOMEDS::SObject_var aSubSO; if (!CORBA::is_nil(theSObject)) { - TCollection_AsciiString aSubName ("from_"); + 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()); + // set the texture + if (aSubO->GetShapeType() == GEOM::VERTEX) { + aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize()); + if (anArgO->GetMarkerType() == GEOM::MT_USER) + aSubO->SetMarkerTexture(anArgO->GetMarkerTexture()); + } } if (!CORBA::is_nil(anArgSO)) { @@ -997,9 +1124,11 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, GEOM::ListOfGO_var aSubParts; if (theFindMethod == GEOM::FSM_GetInPlaceByHistory) // pass theObject, because only it has the history - aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod); + aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, + theObject, anOutArgs, theFindMethod, theAddPrefix); else - aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, aSubO, theFindMethod); + aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, + aSubO, anOutArgs, theFindMethod, theAddPrefix); // add to parts list addToListOfGO( aSubParts, aParts ); } @@ -1012,12 +1141,16 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, // Restore published sub-shapes of the argument GEOM::ListOfGO_var aSubParts = - RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod); + RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, + theObject, anOutArgs, theFindMethod, theAddPrefix); // add to parts list addToListOfGO( aSubParts, aParts ); if (aSubParts->length() > 0) { + // remember restored objects for Python Dump + addToListOfGO(anArgO, anOutArgs); + // try to build an argument from a set of its sub-shapes, // that published and will be reconstructed if (aSubParts->length() > 1) { @@ -1030,11 +1163,20 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, } if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) { // Publish the sub-shape - TCollection_AsciiString aSubName ("from_parts_of_"); + TCollection_AsciiString aSubName; + if (theAddPrefix) { + aSubName = "from_parts_of_"; + } aSubName += anArgName; aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString()); // Restore color aSubO->SetColor(anArgO->GetColor()); + // set the texture + if (aSubO->GetShapeType() == GEOM::VERTEX) { + aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize()); + if (anArgO->GetMarkerType() == GEOM::MT_USER) + aSubO->SetMarkerTexture(anArgO->GetMarkerTexture()); + } } } else if (!CORBA::is_nil(aSubSO)) { @@ -1043,17 +1185,17 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, } } } // try to build from published parts - anArgSO->Destroy(); + anArgSO->UnRegister(); } } // process arguments } - set anObjEntryMap; - GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO; - int nbRes = 0; - int nb = aParts->length(); - aResParts->length(nb); - if (nb > 0) - { + 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); @@ -1079,11 +1221,13 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, pd << aGeomObj; j++; } - pd <<"]" << " = geompy.RestoreSubShapes(" << aMainObj << ", " << "["; - i = 0; nb = theArgs.length(); j = 0; + pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "["; + //i = 0; nb = theArgs.length(); j = 0; + i = 0; nb = anOutArgs->length(); j = 0; for ( ; i < nb; i++ ) { - GEOM::GEOM_Object_var anObj = theArgs[ i ]; + //GEOM::GEOM_Object_var anObj = theArgs[ i ]; + GEOM::GEOM_Object_var anObj = anOutArgs[ i ]; if (CORBA::is_nil(anObj)) continue; Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry()); @@ -1096,6 +1240,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, switch (theFindMethod) { case GEOM::FSM_GetInPlace: pd << "FSM_GetInPlace"; break; + case GEOM::FSM_MultiTransformed: + pd << "FSM_MultiTransformed"; break; case GEOM::FSM_Transformed: pd << "FSM_Transformed"; break; case GEOM::FSM_GetSame: @@ -1106,7 +1252,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, default: pd << "FSM_GetInPlaceByHistory"; break; } - pd << ", " << theInheritFirstArg << ")"; + pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")"; } aResParts->length(nbRes); return aResParts._retn(); @@ -1117,10 +1263,550 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, // purpose : Private method //============================================================================ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy, - SALOMEDS::SObject_ptr theOldSO, - SALOMEDS::SObject_ptr theNewSO, - GEOM::GEOM_Object_ptr theNewO, - GEOM::find_shape_method theFindMethod) + SALOMEDS::SObject_ptr theOldSO, + SALOMEDS::SObject_ptr theNewSO, + GEOM::GEOM_Object_ptr theNewO, + GEOM::ListOfGO& theOutArgs, + 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)*/) + return aParts._retn(); + + SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + + // 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()); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId()); + + // Reconstruct published sub-shapes + SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO); + + int aLen = 0; + for (it->Init(); it->More(); it->Next()) { + aLen++; + } + aParts->length(aLen); + + for (it->Init(); it->More(); it->Next()) { + SALOMEDS::SObject_var anOldSubSO = it->Value(); + + TCollection_AsciiString anArgName = anOldSubSO->GetName(); + + SALOMEDS::GenericAttribute_var anAttr; + if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) { + SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); + GEOM::GEOM_Object_var anOldSubO = + GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value())); + if (!CORBA::is_nil(anOldSubO)) { + // Find a sub-shape of theNewO in place of anOldSubO + GEOM::GEOM_Object_var aNewSubO; + switch (theFindMethod) { + case GEOM::FSM_GetInPlace: + { + // Use GetInPlace + aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO); + } + break; + case GEOM::FSM_MultiTransformed: + { + // Only for Multi-transformations + GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anOldSubO, theNewO); + if (!CORBA::is_nil(anArgOTrsf)) { + CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); + Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); + Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + anArgOTrsfFun->SetDescription(""); + aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf); + } + } + break; + case GEOM::FSM_Transformed: + { + // transformation, cannot use GetInPlace, operate with indices + GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices(); + if (anIDs->length() > 1) { + // group + aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO)); + if (!CORBA::is_nil(aNewSubO)) + aGroupOp->UnionIDs(aNewSubO, anIDs); + } + else { + // single sub-shape + aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]); + } + } + break; + case GEOM::FSM_GetSame: + { + // Use GetSame + aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO); + } + break; + case GEOM::FSM_GetShapesOnShape: + { + // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids + aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO, + (short)GEOM::SOLID, GEOM::ST_ONIN); + } + break; + case GEOM::FSM_GetInPlaceByHistory: + { + // Use GetInPlaceByHistory + aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO); + } + break; + default: + {} + } + + if (!CORBA::is_nil(aNewSubO)) { + // remember restored objects for Python Dump + addToListOfGO(anOldSubO, theOutArgs); + + // add the part to the list + aParts[i] = aNewSubO; + i++; + // 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()); + // set the texture + if (aNewSubO->GetShapeType() == GEOM::VERTEX) { + aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize()); + if (anOldSubO->GetMarkerType() == GEOM::MT_USER) + aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture()); + } + } + // 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 + aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + theNewO, theOutArgs, theFindMethod, theAddPrefix); + else + aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + aNewSubO, theOutArgs, theFindMethod, theAddPrefix); + // add to parts list + addToListOfGO( aSubParts, aNewParts ); + } + else { // GetInPlace failed, try to build from published parts + SALOMEDS::SObject_var aNewSubSO; + if (!CORBA::is_nil(theNewSO)) + aNewSubSO = aStudyBuilder->NewObject(theNewSO); + + // Restore published sub-shapes of the argument + GEOM::ListOfGO_var aSubParts = + RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + theNewO, theOutArgs, theFindMethod, theAddPrefix); + // add to parts list + addToListOfGO( aSubParts, aNewParts ); + + if (aSubParts->length() > 0) { + // remember restored objects for Python Dump + addToListOfGO(anOldSubO, theOutArgs); + + // try to build an object from a set of its sub-shapes, + // that published and will be reconstructed + if (aSubParts->length() > 1) { + aNewSubO = aShapesOp->MakeCompound(aSubParts); + // add to parts list + addToListOfGO( aNewSubO, aNewParts ); + } + else { + aNewSubO = aSubParts[0]; + } + + if (!CORBA::is_nil(aNewSubO)) { + // add the part to the list + aSubParts[i] = aNewSubO; + i++; + + // Publish the sub-shape + 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()); + // set the texture + if (aNewSubO->GetShapeType() == GEOM::VERTEX) { + aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize()); + if (anOldSubO->GetMarkerType() == GEOM::MT_USER) + aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture()); + } + } + } + } + else if (!CORBA::is_nil(aNewSubSO)) { + // remove created aSubSO, because no parts have been found + aStudyBuilder->RemoveObject(aNewSubSO); + } + } // try to build from published parts + } + } + } // iterate on published sub-shapes + + aParts->length(i); + // add to parts list + addToListOfGO( aNewParts, aParts ); + return aParts._retn(); +} + +//============================================================================ +// function : RestoreGivenSubShapes +// purpose : Private method. Works only if both theObject and theSObject +// are defined, and does not check, if they correspond to each other. +// List theArgs in this case contains not only operation arguments, +// but also all subshapes, which must be published. +//============================================================================ +GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(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 theAddPrefix) +{ + 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(); + + // If theArgs list is empty, nothing to do + Standard_Integer aLength = theArgs.length(); + if (aLength == 0) + return aParts._retn(); + + // Get all arguments + GEOM::ListOfGO_var anOpArgsList = theObject->GetDependency(); + Standard_Integer nbArgsActual = anOpArgsList->length(); + + // If anOpArgsList list is empty, nothing to do + if (nbArgsActual == 0) + return aParts._retn(); + + // Entries of arguments and subshapes + std::set anArgs; + for (int i = 0; i < aLength; i++) { + CORBA::String_var anEntry = theArgs[i]->GetEntry(); + anArgs.insert(anEntry.in()); + } + + // Arguments to be published + // We try to publish all arguments, that are in theArgs list + GEOM::ListOfGO_var aList = new GEOM::ListOfGO; + aList->length(nbArgsActual); + + int k = 0; + for (int j = 0; j < nbArgsActual; j++) { + CORBA::String_var anEntry = anOpArgsList[j]->GetEntry(); + if (anArgs.count(anEntry.in())) { + aList[k] = GEOM::GEOM_Object::_duplicate(anOpArgsList[j]); + k++; + } + } + nbArgsActual = k; + //aList->length(nbArgsActual); + + if (nbArgsActual < 1) + return aParts._retn(); + + if (theInheritFirstArg || (nbArgsActual == 1)) { + // Do not publish argument's reflection, + // but only reconstruct its published sub-shapes + + CORBA::String_var anIOR = _orb->object_to_string(aList[0]); + SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in()); + + aParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, + anArgs, theFindMethod, theAddPrefix); + + // set the color of the transformed shape to the color of initial shape + theObject->SetColor(aList[0]->GetColor()); + // set the texture + if (theObject->GetShapeType() == GEOM::VERTEX) { + theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize()); + if (aList[0]->GetMarkerType() == GEOM::MT_USER) + theObject->SetMarkerTexture(aList[0]->GetMarkerTexture()); + } + + anArgSO->UnRegister(); + } + 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()); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(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 < nbArgsActual; 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_MultiTransformed: + { + // Only for Multi-transformations + GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anArgO, theObject); + if (!CORBA::is_nil(anArgOTrsf)) { + CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); + Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); + Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + anArgOTrsfFun->SetDescription(""); + aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf); + } + } + 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()); + // set the texture + if (aSubO->GetShapeType() == GEOM::VERTEX) { + aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize()); + if (anArgO->GetMarkerType() == GEOM::MT_USER) + aSubO->SetMarkerTexture(anArgO->GetMarkerTexture()); + } + } + + 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 = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO, + theObject, anArgs, theFindMethod, theAddPrefix); + else + aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO, + aSubO, anArgs, 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 = + RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO, + theObject, anArgs, 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()); + // set the texture + if (aSubO->GetShapeType() == GEOM::VERTEX) { + aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize()); + if (anArgO->GetMarkerType() == GEOM::MT_USER) + aSubO->SetMarkerTexture(anArgO->GetMarkerTexture()); + } + } + } + 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->UnRegister(); + } + } // 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++; + } + pd <<"]" << " = geompy.RestoreGivenSubShapes(" << 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_MultiTransformed: + pd << "FSM_MultiTransformed"; 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(); +} + +//============================================================================ +// function : RestoreGivenSubShapesOneLevel +// purpose : Private method +//============================================================================ +GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theOldSO, + SALOMEDS::SObject_ptr theNewSO, + GEOM::GEOM_Object_ptr theNewO, + std::set theArgs, + GEOM::find_shape_method theFindMethod, + CORBA::Boolean theAddPrefix) { int i = 0; GEOM::ListOfGO_var aParts = new GEOM::ListOfGO; @@ -1132,8 +1818,9 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); // 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()); + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId()); // Reconstruct published sub-shapes SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO); @@ -1153,126 +1840,168 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) { SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); GEOM::GEOM_Object_var anOldSubO = - GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value())); + GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value())); + + bool okToContinue = false; + if (!CORBA::is_nil(anOldSubO)) { - // Find a sub-shape of theNewO in place of anOldSubO - GEOM::GEOM_Object_var aNewSubO; - switch (theFindMethod) { - case GEOM::FSM_GetInPlace: - { - // Use GetInPlace - aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO); - } - break; - case GEOM::FSM_Transformed: - { - // transformation, cannot use GetInPlace, operate with indices - GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices(); - if (anIDs->length() > 1) { - // group - aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO)); - if (!CORBA::is_nil(aNewSubO)) - aGroupOp->UnionIDs(aNewSubO, anIDs); - } - else { - // single sub-shape - aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]); - } - } - break; - case GEOM::FSM_GetSame: - { - // Use GetSame - aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO); - } - break; - case GEOM::FSM_GetShapesOnShape: - { - // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids - aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO, - (short)GEOM::SOLID, GEOM::ST_ONIN); - } - break; - case GEOM::FSM_GetInPlaceByHistory: - { - // Use GetInPlaceByHistory - aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO); - } - break; - default: - {} - } - - if (!CORBA::is_nil(aNewSubO)) { - // add the part to the list - aParts[i] = aNewSubO; - i++; + CORBA::String_var anEntry = anOldSubO->GetEntry(); + okToContinue = theArgs.count(anEntry.in()); + } + + if (okToContinue) { + // Find a sub-shape of theNewO in place of anOldSubO + GEOM::GEOM_Object_var aNewSubO; + switch (theFindMethod) { + case GEOM::FSM_GetInPlace: + { + // Use GetInPlace + aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO); + } + break; + case GEOM::FSM_MultiTransformed: + { + // Only for Multi-transformations + GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anOldSubO, theNewO); + if (!CORBA::is_nil(anArgOTrsf)) { + CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); + Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); + Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + anArgOTrsfFun->SetDescription(""); + aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf); + } + } + break; + case GEOM::FSM_Transformed: + { + // transformation, cannot use GetInPlace, operate with indices + GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices(); + if (anIDs->length() > 1) { + // group + aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO)); + if (!CORBA::is_nil(aNewSubO)) + aGroupOp->UnionIDs(aNewSubO, anIDs); + } + else { + // single sub-shape + aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]); + } + } + break; + case GEOM::FSM_GetSame: + { + // Use GetSame + aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO); + } + break; + case GEOM::FSM_GetShapesOnShape: + { + // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids + aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO, + (short)GEOM::SOLID, GEOM::ST_ONIN); + } + break; + case GEOM::FSM_GetInPlaceByHistory: + { + // Use GetInPlaceByHistory + aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO); + } + break; + default: + {} + } + + if (!CORBA::is_nil(aNewSubO)) { + // add the part to the list + aParts[i] = aNewSubO; + i++; // add to parts list addToListOfGO( aNewSubO, aNewParts ); SALOMEDS::SObject_var aNewSubSO; if (!CORBA::is_nil(theNewSO)) { - // Publish the sub-shape - TCollection_AsciiString aSubName ("from_"); - aSubName += anArgName; - aNewSubSO = aStudyBuilder->NewObject(theNewSO); - aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString()); - // Restore color - aNewSubO->SetColor(anOldSubO->GetColor()); + // 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()); + // set the texture + if (aNewSubO->GetShapeType() == GEOM::VERTEX) { + aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize()); + if (anOldSubO->GetMarkerType() == GEOM::MT_USER) + aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture()); + } } - // 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 - aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod); - else - aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, aNewSubO, theFindMethod); + // 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 + aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + theNewO, theArgs, theFindMethod, theAddPrefix); + else + aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + aNewSubO, theArgs, theFindMethod, theAddPrefix); // add to parts list addToListOfGO( aSubParts, aNewParts ); - } - else { // GetInPlace failed, try to build from published parts - SALOMEDS::SObject_var aNewSubSO; + } + else { // GetInPlace failed, try to build from published parts + SALOMEDS::SObject_var aNewSubSO; if (!CORBA::is_nil(theNewSO)) aNewSubSO = aStudyBuilder->NewObject(theNewSO); - // Restore published sub-shapes of the argument - GEOM::ListOfGO_var aSubParts = - RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod); + // Restore published sub-shapes of the argument + GEOM::ListOfGO_var aSubParts = + RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + theNewO, theArgs, theFindMethod, theAddPrefix); // add to parts list addToListOfGO( aSubParts, aNewParts ); - if (aSubParts->length() > 0) { - // try to build an object from a set of its sub-shapes, - // that published and will be reconstructed - if (aSubParts->length() > 1) { - aNewSubO = aShapesOp->MakeCompound(aSubParts); + if (aSubParts->length() > 0) { + // try to build an object from a set of its sub-shapes, + // that published and will be reconstructed + if (aSubParts->length() > 1) { + aNewSubO = aShapesOp->MakeCompound(aSubParts); // add to parts list addToListOfGO( aNewSubO, aNewParts ); - } - else { - aNewSubO = aSubParts[0]; - } - - if (!CORBA::is_nil(aNewSubO)) { - // add the part to the list - aSubParts[i] = aNewSubO; - i++; - - // Publish the sub-shape - if (!CORBA::is_nil(aNewSubSO)) { - TCollection_AsciiString aSubName = "from_parts_of_"; - aSubName += anArgName; - aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString()); - // Restore color - aNewSubO->SetColor(anOldSubO->GetColor()); + } + else { + aNewSubO = aSubParts[0]; + } + + if (!CORBA::is_nil(aNewSubO)) { + // add the part to the list + aSubParts[i] = aNewSubO; + i++; + + // Publish the sub-shape + 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()); + // set the texture + if (aNewSubO->GetShapeType() == GEOM::VERTEX) { + aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize()); + if (anOldSubO->GetMarkerType() == GEOM::MT_USER) + aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture()); + } } - } - } - else if (!CORBA::is_nil(aNewSubSO)) { - // remove created aSubSO, because no parts have been found - aStudyBuilder->RemoveObject(aNewSubSO); - } - } // try to build from published parts + } + } + else if (!CORBA::is_nil(aNewSubSO)) { + // remove created aSubSO, because no parts have been found + aStudyBuilder->RemoveObject(aNewSubSO); + } + } // try to build from published parts } } } // iterate on published sub-shapes @@ -1554,24 +2283,44 @@ 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 */ //============================================================================= GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape, - const GEOM::ListOfLong& theIndices) + const GEOM::ListOfLong& theIndices) { if (CORBA::is_nil(theMainShape) || theIndices.length() < 1) return GEOM::GEOM_Object::_nil(); CORBA::String_var entry = theMainShape->GetEntry(); - Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), entry); - if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil(); + Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry); + if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil(); Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length()); for(Standard_Integer i = 0; iSetValue(i+1, theIndices[i]); - Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true); + Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true); if(anObject.IsNull()) return GEOM::GEOM_Object::_nil(); TCollection_AsciiString anEntry; @@ -1587,7 +2336,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; @@ -1662,7 +2411,7 @@ bool GEOM_Gen_i::hasObjectInfo() char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) { GEOM::GEOM_Object_var aGeomObject; - + CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" ); SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject ); SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId ); @@ -1675,13 +2424,13 @@ 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(); + anIOR->UnRegister(); CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal); aGeomObject = GEOM::GEOM_Object::_narrow(anObject); } if (!aSObj->_is_nil() ) - aSObj->Destroy(); - + aSObj->UnRegister(); + const char* aTypeInfo = "Object"; if ( !aGeomObject->_is_nil() ) { GEOM::GEOM_IKindOfShape::shape_kind aKind; @@ -1694,132 +2443,143 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) if ( anOp->IsDone() ) { switch ( aKind ) { case GEOM::GEOM_IKindOfShape::COMPOUND: - aTypeInfo = "Compound"; - break; + aTypeInfo = "Compound"; + break; case GEOM::GEOM_IKindOfShape::COMPSOLID: - aTypeInfo = "CompSolid"; - break; + aTypeInfo = "CompSolid"; + break; case GEOM::GEOM_IKindOfShape::SHELL: - aTypeInfo = "Shell"; - break; + aTypeInfo = "Shell"; + break; case GEOM::GEOM_IKindOfShape::WIRE: - if ( anInts[0] == 1 ) - aTypeInfo = "Closed Wire"; - else if ( anInts[0] == 2 ) - aTypeInfo = "Opened Wire"; - else - aTypeInfo = "Wire"; - break; - // SOLIDs + if ( anInts[0] == 1 ) + aTypeInfo = "Closed Wire"; + else if ( anInts[0] == 2 ) + aTypeInfo = "Opened Wire"; + else + aTypeInfo = "Wire"; + break; + // SOLIDs case GEOM::GEOM_IKindOfShape::SPHERE: - aTypeInfo = "Sphere"; - break; + aTypeInfo = "Sphere"; + break; case GEOM::GEOM_IKindOfShape::CYLINDER: - aTypeInfo = "Cylinder"; - break; + aTypeInfo = "Cylinder"; + break; case GEOM::GEOM_IKindOfShape::BOX: case GEOM::GEOM_IKindOfShape::ROTATED_BOX: - aTypeInfo = "Box"; - break; + aTypeInfo = "Box"; + break; case GEOM::GEOM_IKindOfShape::TORUS: - aTypeInfo = "Torus"; - break; + aTypeInfo = "Torus"; + break; case GEOM::GEOM_IKindOfShape::CONE: - aTypeInfo = "Cone"; - break; + aTypeInfo = "Cone"; + break; case GEOM::GEOM_IKindOfShape::POLYHEDRON: - aTypeInfo = "Polyhedron"; - break; + aTypeInfo = "Polyhedron"; + break; case GEOM::GEOM_IKindOfShape::SOLID: - aTypeInfo = "Solid"; - break; - // FACEs + aTypeInfo = "Solid"; + break; + // FACEs case GEOM::GEOM_IKindOfShape::SPHERE2D: - aTypeInfo = "Spherical Face"; - break; + aTypeInfo = "Spherical Face"; + break; case GEOM::GEOM_IKindOfShape::CYLINDER2D: - aTypeInfo = "Cylindrical Face"; - break; + aTypeInfo = "Cylindrical Face"; + break; case GEOM::GEOM_IKindOfShape::TORUS2D: - aTypeInfo = "Toroidal Face"; - break; + aTypeInfo = "Toroidal Face"; + break; case GEOM::GEOM_IKindOfShape::CONE2D: - aTypeInfo = "Conical Face"; - break; + aTypeInfo = "Conical Face"; + break; case GEOM::GEOM_IKindOfShape::DISK_CIRCLE: - aTypeInfo = "Disk"; - break; + aTypeInfo = "Disk"; + break; case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE: - aTypeInfo = "Elliptical Face"; - break; + aTypeInfo = "Elliptical Face"; + break; case GEOM::GEOM_IKindOfShape::POLYGON: - aTypeInfo = "Polygon"; - break; + aTypeInfo = "Polygon"; + break; case GEOM::GEOM_IKindOfShape::PLANE: - aTypeInfo = "Plane"; - break; + aTypeInfo = "Plane"; + break; case GEOM::GEOM_IKindOfShape::PLANAR: - aTypeInfo = "Planar Face"; - break; + aTypeInfo = "Planar Face"; + break; case GEOM::GEOM_IKindOfShape::FACE: - aTypeInfo = "Face"; - break; - // EDGEs + aTypeInfo = "Face"; + break; + // EDGEs case GEOM::GEOM_IKindOfShape::CIRCLE: - aTypeInfo = "Circle"; - break; + aTypeInfo = "Circle"; + break; case GEOM::GEOM_IKindOfShape::ARC_CIRCLE: - aTypeInfo = "Ark"; - break; + aTypeInfo = "Arc Circle"; + break; case GEOM::GEOM_IKindOfShape::ELLIPSE: - aTypeInfo = "Ellipse"; - break; + aTypeInfo = "Ellipse"; + break; case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE: - aTypeInfo = "Arc Ellipse"; - break; + aTypeInfo = "Arc Ellipse"; + break; case GEOM::GEOM_IKindOfShape::LINE: - aTypeInfo = "Line"; - break; + aTypeInfo = "Line"; + break; case GEOM::GEOM_IKindOfShape::SEGMENT: - aTypeInfo = "Segment"; - break; + aTypeInfo = "Segment"; + break; case GEOM::GEOM_IKindOfShape::EDGE: - aTypeInfo = "Edge"; - break; + aTypeInfo = "Edge"; + break; case GEOM::GEOM_IKindOfShape::VERTEX: - aTypeInfo = "Vertex"; - break; + aTypeInfo = "Vertex"; + break; default: - break; + break; } } } - + char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3]; sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo); - + char* ret = CORBA::string_dup(anInfo); delete [] anInfo; return ret; } +// Version information +char* GEOM_Gen_i::getVersion() +{ +#if GEOM_DEVELOPMENT + return CORBA::string_dup(GEOM_VERSION_STR"dev"); +#else + return CORBA::string_dup(GEOM_VERSION_STR); +#endif +} + //===================================================================================== // EXPORTED METHODS //===================================================================================== extern "C" { -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_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(); } }