X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOM_I%2FGEOM_Gen_i.cc;h=f4da6559580e882eb24336f21e96feb2f9c9e7e7;hb=cfc267474fbe4c092b88a40e8d28031a00950450;hp=001a989a57d7702cff582230b16a1ff268b42c2e;hpb=c03d6100434b811c1c0bd00fd161e8b55933b1f7;p=modules%2Fgeom.git diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 001a989a5..f4da65595 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -6,7 +6,7 @@ // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -18,8 +18,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// -#ifdef WNT +#ifdef WIN32 #pragma warning( disable:4786 ) #endif @@ -27,23 +28,23 @@ #include "GEOM_Gen_i.hh" #include "GEOM_Object_i.hh" +#include "GEOM_Field_i.hh" #include "GEOM_version.h" -#include -#include - #include "Utils_CorbaException.hxx" #include "OpUtil.hxx" #include "Utils_ExceptHandlers.hxx" #include "utilities.h" -#include "GEOM_Object_i.hh" #include "GEOM_Object.hxx" #include "GEOM_Function.hxx" #include "GEOM_ISubShape.hxx" -#include +#include "GEOM_PythonDump.hxx" #include "GEOMImpl_Types.hxx" #include "GEOMImpl_CopyDriver.hxx" +#include "GEOMImpl_IInsertOperations.hxx" +#include "GEOM_wrap.hxx" +#include "GEOMUtils_XmlHandler.hxx" // Cascade headers #include @@ -56,28 +57,35 @@ #include #include #include -//#include #include #include +#include +#include +#include #include #include +#include +#include -#ifdef WNT +#include +#include + +#ifdef WIN32 #include #include #else #include #endif -#ifdef WNT +#ifdef WIN32 #define LibHandle HMODULE #define LoadLib( name ) LoadLibrary( name ) #define GetProc GetProcAddress #define UnLoadLib( handle ) FreeLibrary( handle ); #else #define LibHandle void* - #define LoadLib( name ) dlopen( name, RTLD_LAZY ) + #define LoadLib( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL ) #define GetProc dlsym #define UnLoadLib( handle ) dlclose( handle ); #endif @@ -90,13 +98,12 @@ 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) + const char* interfaceName, + bool withRegistry) : + Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, withRegistry) { _thisObj = this; _id = _poa->activate_object(_thisObj); - name_service = new SALOME_NamingService(_orb); - _impl = new ::GEOMImpl_Gen; //PAL10867: disable signals catching with "noexcepthandler" option @@ -105,17 +112,26 @@ GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb, { //work around PAL12004, PAL12628 //OSD::SetSignal( true ); - bool raiseFPE; -#ifdef _DEBUG_ - raiseFPE = true; - char* envDisableFPE = getenv("DISABLE_FPE"); - if (envDisableFPE && atoi(envDisableFPE)) - raiseFPE = false; -#else - raiseFPE = false; + bool raiseFPE = false; +#if defined(_DEBUG_) | defined(_DEBUG) //the Last for WIN32 default settings + char* envEnableFPE = getenv("ENABLE_FPE"); + if (envEnableFPE && atoi(envEnableFPE)) + raiseFPE = true; #endif OSD::SetSignal( raiseFPE ); } + + GEOMUtils::PluginInfo plugins = GEOMUtils::ReadPluginInfo(); + GEOMUtils::PluginInfo::const_iterator it; + for (it = plugins.begin(); it != plugins.end(); ++it) + { + try { + LoadPlugin((*it).serverLib); + } + catch (...) { + MESSAGE("Warning: can't load plugin library " << (*it).serverLib); + } + } } //============================================================================ @@ -123,8 +139,9 @@ GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb, // purpose : destructor //============================================================================ GEOM_Gen_i::~GEOM_Gen_i() { - delete name_service; delete _impl; + for (auto it = myOpCreatorMap.cbegin(); it != myOpCreatorMap.cend(); ++it) + delete (*it).second; } @@ -132,14 +149,15 @@ GEOM_Gen_i::~GEOM_Gen_i() { // function : IORToLocalPersistentID() // purpose : //============================================================================ -char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, +char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr /*theSObject*/, const char* IORString, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII) + CORBA::Boolean /*isMultiFile*/, + CORBA::Boolean /*isASCII*/) { - GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString)); + GEOM::GEOM_BaseObject_var anObject = + GEOM::GEOM_BaseObject::_narrow(_orb->string_to_object(IORString)); if (!CORBA::is_nil(anObject)) { - return CORBA::string_dup(anObject->GetEntry()); + return anObject->GetEntry(); } return 0; } @@ -151,20 +169,26 @@ char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, // : Used when a study is loaded // : The IOR (IORName) of object created is returned //============================================================================ -char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, +char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr /*theSObject*/, const char* aLocalPersistentID, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII) + CORBA::Boolean /*isMultiFile*/, + CORBA::Boolean /*isASCII*/) { - SALOMEDS::Study_var aStudy = theSObject->GetStudy(); - - Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast(aLocalPersistentID)); - TCollection_AsciiString anEntry; - TDF_Tool::Entry(anObject->GetEntry(), anEntry); - GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString()); + Handle(::GEOM_BaseObject) anObject = + _impl->GetObject(aLocalPersistentID); + if ( !anObject.IsNull() ) + { + TCollection_AsciiString anEntry; + TDF_Tool::Entry(anObject->GetEntry(), anEntry); + GEOM::GEOM_BaseObject_var obj = GetObject(anEntry.ToCString()); - CORBA::String_var aPersRefString = _orb->object_to_string(obj); - return CORBA::string_dup(aPersRefString); + CORBA::String_var aPersRefString = _orb->object_to_string(obj); + return CORBA::string_dup(aPersRefString); + } + else + { + return CORBA::string_dup(""); + } } //============================================================================ @@ -182,38 +206,24 @@ bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) // function : PublishInStudy // purpose : //============================================================================ -SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, - SALOMEDS::SObject_ptr theSObject, - CORBA::Object_ptr theObject, - const char* theName) throw (SALOME::SALOME_Exception) +SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theObject, + const char* theName) + { Unexpect aCatch(SALOME_SalomeException); SALOMEDS::SObject_var aResultSO; - if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO; - GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject); - if(aShape->_is_nil()) return aResultSO; + SALOMEDS::Study_var aStudy = getStudyServant(); + if(CORBA::is_nil(theObject) || aStudy->_is_nil()) return aResultSO; + GEOM::GEOM_BaseObject_var aBaseObj = GEOM::GEOM_BaseObject::_narrow(theObject); + GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject); + if(aBaseObj->_is_nil()) return aResultSO; SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); - SALOMEDS::UseCaseBuilder_var useCaseBuilder = theStudy->GetUseCaseBuilder(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder(); - SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM"); - if (aFather->_is_nil()) { - aFather = aStudyBuilder->NewComponent("GEOM"); - anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName"); - SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue("Geometry"); - aName->UnRegister(); - anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap"); - SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr); - aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry"); - aPixMap->UnRegister(); - aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this()); - // add component to the use case tree - // (to support tree representation customization and drag-n-drop) - useCaseBuilder->SetRootCurrent(); - useCaseBuilder->Append( aFather ); // component object is added as the top level item - } + SALOMEDS::SComponent_var aFather = findOrCreateComponent(); if (aFather->_is_nil()) return aResultSO; if (CORBA::is_nil(theSObject)) { @@ -221,109 +231,151 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, } else { if (!theSObject->ReferencedObject(aResultSO)) aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL - //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM); + //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM); } CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject); aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR); - TCollection_AsciiString aShapeName("Shape_"); + TCollection_AsciiString anObjectName, aNamePrefix("Shape_"); + CORBA::Long mytype=aBaseObj->GetType(); + + // BEGIN: try to find existed name for current shape + if ( !aShape->_is_nil() && mytype != GEOM_GROUP) + { + // receive current TopoDS shape + CORBA::String_var entry = aShape->GetEntry(); + Handle(::GEOM_Object) aGShape = Handle(::GEOM_Object)::DownCast + ( _impl->GetObject( entry )); + TopoDS_Shape TopoSh = aGShape->GetValue(); + // find label of main shape + GEOM::GEOM_Object_var aMainSh = aShape; + while( !aMainSh->IsMainShape() ) { + aMainSh = aMainSh->GetMainShape(); + } + entry = aMainSh->GetEntry(); + Handle(::GEOM_BaseObject) anObj = _impl->GetObject( entry ); + TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry(); + + // check all named shapes using iterator + TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True); + + for (; anIt.More() && anObjectName.IsEmpty(); anIt.Next()) { + Handle(TNaming_NamedShape) anAttr = + Handle(TNaming_NamedShape)::DownCast(anIt.Value()); + if (anAttr.IsNull()) continue; + TopoDS_Shape S = anAttr->Get(); + if (S.IsEqual(TopoSh)) { + TDF_Label L = anAttr->Label(); + Handle(TDataStd_Name) aName; + if (L.FindAttribute(TDataStd_Name::GetID(), aName)) + anObjectName = aName->Get(); + } + } + } + // END: try to find existed name for current shape - CORBA::Long mytype=aShape->GetType(); if ( mytype == GEOM_GROUP ) { - GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() ); - switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) { + GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations(); + switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape )) { case TopAbs_VERTEX: aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" ); - aShapeName = "Group_Of_Vertices_"; + aNamePrefix = "Group_Of_Vertices_"; break; case TopAbs_EDGE: aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE"); - aShapeName = "Group_Of_Edges_"; + aNamePrefix = "Group_Of_Edges_"; break; case TopAbs_FACE: aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE"); - aShapeName = "Group_Of_Faces_"; + aNamePrefix = "Group_Of_Faces_"; break; case TopAbs_SOLID: aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID"); - aShapeName = "Group_Of_Solids_"; + aNamePrefix = "Group_Of_Solids_"; break; + default: + aNamePrefix = "Group_"; } } else if ( mytype == GEOM_MARKER ) { aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS"); - aShapeName = "LocalCS_"; - } else if ( mytype > ADVANCED_BASE ) { + aNamePrefix = "LocalCS_"; + } else if ( mytype >= USER_TYPE_EX ) { + char buf[20]; + sprintf( buf, "%d", aBaseObj->GetType() ); + GEOM::CreationInformationSeq_var infoSeq = aBaseObj->GetCreationInformation(); + std::string plgId; + for ( size_t j = 0; j < infoSeq->length(); ++j ) + for ( size_t i = 0; i < infoSeq[j].params.length(); ++i ) { + std::string param_name = infoSeq[j].params[i].name.in(); + std::string param_value = infoSeq[j].params[i].value.in(); + if( param_name == PLUGIN_NAME) { + plgId = param_value; + break; + } + } + if(plgId.length() > 0 ) { + plgId += "::"; + } + plgId +="ICON_OBJBROWSER_"; + plgId += buf; + aResultSO->SetAttrString("AttributePixMap",plgId.c_str()); + } else if ( mytype > USER_TYPE ) { char buf[20]; - sprintf( buf, "%d", aShape->GetType() ); + sprintf( buf, "%d", aBaseObj->GetType() ); std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf; aResultSO->SetAttrString("AttributePixMap",advId.c_str()); - aShapeName = "Advanced_"; - } else { + aNamePrefix = "Advanced_"; + } else if ( mytype == GEOM_FIELD ) { + aNamePrefix = "Field_"; + GEOM::GEOM_Field_var aField = GEOM::GEOM_Field::_narrow(theObject); + if ( !aField->_is_nil() ) + switch( aField->GetDimension() ) { + case 0: + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_PNT" ); break; + case 1: + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_EDGE"); break; + case 2: + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_FACE"); break; + case 3: + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID"); break; + default: + aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID"); + } + } else if ( mytype == GEOM_FIELD_STEP ) { + aNamePrefix = "Step_"; + } else if ( !aShape->_is_nil() ) { GEOM::shape_type myshapetype=aShape->GetShapeType(); if ( myshapetype == GEOM::COMPOUND ) { aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" ); - aShapeName = "Compound_"; + aNamePrefix = "Compound_"; } else if ( myshapetype == GEOM::COMPSOLID ) { aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID"); - aShapeName = "Compsolid_"; + aNamePrefix = "Compsolid_"; } else if ( myshapetype == GEOM::SOLID ) { aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID"); - aShapeName = "Solid_"; + aNamePrefix = "Solid_"; } else if ( myshapetype == GEOM::SHELL ) { aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL"); - aShapeName = "Shell_"; + aNamePrefix = "Shell_"; } else if ( myshapetype == GEOM::FACE ) { aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE"); - aShapeName = "Face_"; + aNamePrefix = "Face_"; } else if ( myshapetype == GEOM::WIRE ) { aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE"); - aShapeName = "Wire_"; + aNamePrefix = "Wire_"; } else if ( myshapetype == GEOM::EDGE ) { aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE"); - aShapeName = "Edge_"; + aNamePrefix = "Edge_"; } else if ( myshapetype == GEOM::VERTEX ) { aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_VERTEX" ); - aShapeName = "Vertex_"; - } - } - //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag()); - //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName)); - - // BEGIN: try to find existed name for current shape - bool HasName = false; - // recieve current TopoDS shape - CORBA::String_var entry = aShape->GetEntry(); - Handle(GEOM_Object) aGShape = _impl->GetObject(aShape->GetStudyID(), entry); - TopoDS_Shape TopoSh = aGShape->GetValue(); - // find label of main shape - GEOM::GEOM_Object_var aMainSh = aShape; - while( !aMainSh->IsMainShape() ) { - aMainSh = aMainSh->GetMainShape(); - } - entry = aMainSh->GetEntry(); - Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry); - TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry(); - - // check all named shapes using iterator - TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True); - - for (; anIt.More() && !HasName; anIt.Next()) { - Handle(TNaming_NamedShape) anAttr = - Handle(TNaming_NamedShape)::DownCast(anIt.Value()); - if (anAttr.IsNull()) continue; - TopoDS_Shape S = anAttr->Get(); - if (S.IsEqual(TopoSh)) { - TDF_Label L = anAttr->Label(); - Handle(TDataStd_Name) aName; - if (L.FindAttribute(TDataStd_Name::GetID(), aName)) { - aShapeName = aName->Get(); - HasName = true; - } + aNamePrefix = "Vertex_"; } } - // END: try to find existed name for current shape + if ( anObjectName.IsEmpty() ) + { + //if (strlen(theName) == 0) aNamePrefix += TCollection_AsciiString(aResultSO->Tag()); + //else anObjectName = TCollection_AsciiString(CORBA::string_dup(theName)); - if (!HasName) { // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number // of objects in the study, but compute a number of objects with the same prefix @@ -331,34 +383,33 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR int i = 0; // (WITH EMPTY NEW NAME) SALOMEDS::SObject_var obj; - TCollection_AsciiString aNewShapeName; do { - aNewShapeName = aShapeName + TCollection_AsciiString(++i); - obj = theStudy->FindObject( aNewShapeName.ToCString() ); + anObjectName = aNamePrefix + TCollection_AsciiString(++i); + obj = aStudy->FindObject( anObjectName.ToCString() ); } while ( !obj->_is_nil() ); - aShapeName = aNewShapeName; } - else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME) - aShapeName = TCollection_AsciiString((char*)theName); + else { // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME) + anObjectName = theName; + } } //Set the study entry as a name of the published GEOM_Object - CORBA::String_var anID =aResultSO->GetID(); - aShape->SetStudyEntry(anID.in()); + CORBA::String_var anID = aResultSO->GetID(); + aBaseObj->SetStudyEntry(anID.in()); //Set a name of the added shape - aResultSO->SetAttrString("AttributeName",aShapeName.ToCString()); + aResultSO->SetAttrString("AttributeName",anObjectName.ToCString()); //Set NoteBook variables used in the object creation TCollection_AsciiString aVars; - CORBA::String_var aString=aShape->GetParameters(); - SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString); + CORBA::String_var aString=aBaseObj->GetParameters(); + SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aString); for(int i = 0, n = aSections->length(); i < n; i++) { SALOMEDS::ListOfStrings aListOfVars = aSections[i]; for(int j = 0, m = aListOfVars.length(); j < m; j++) { - if(theStudy->IsVariable(aListOfVars[j].in())) - aVars += TCollection_AsciiString(aListOfVars[j].in()); + if(aStudy->IsVariable(aListOfVars[j].in())) + aVars += aListOfVars[j].in(); if(j != m-1) aVars += ":"; } @@ -370,7 +421,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, aFather->UnRegister(); //Set a name of the GEOM object - aShape->SetName(aShapeName.ToCString()); + aBaseObj->SetName(anObjectName.ToCString()); // add object to the use case tree // (to support tree representation customization and drag-n-drop) @@ -379,41 +430,38 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, return aResultSO._retn(); } - //============================================================================ // function : CreateAndPublishGroup -// purpose : auxilary for PublishNamedShapesInStudy +// purpose : auxiliary for PublishNamedShapesInStudy //============================================================================ -void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy, - GEOM::GEOM_Object_var theMainShape, +void GEOM_Gen_i::CreateAndPublishGroup(GEOM::GEOM_Object_var theMainShape, const TopTools_IndexedMapOfShape& anIndices, const TopTools_SequenceOfShape& SeqS, - const TColStd_SequenceOfAsciiString& SeqN, + const TColStd_SequenceOfAsciiString& /*SeqN*/, const Standard_CString& GrName, - GEOM::ListOfGO_var aResList) + GEOM::ListOfGO_var /*aResList*/) { CORBA::String_var entry = theMainShape->GetEntry(); - Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry); + //Handle(::GEOM_Object) aMainShape = _impl->GetObject(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); + GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(); + GEOM::GEOM_Object_wrap GrObj = GOp->CreateGroup( theMainShape, SeqS(1).ShapeType() ); + AddInStudy(GrObj, GrName, theMainShape._retn()); + //CORBA::String_var GrEntry = GrObj->GetEntry(); + //Handle(::GEOM_Object) HGrObj = _impl->GetObject(GrEntry); // add named objects - //Handle(GEOM_Object) anObj; + //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); + //anObj = GEOM_Engine::GetEngine()->AddObject(GEOM_SUBSHAPE); //if (anObj.IsNull()) continue; - //Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1); + //Handle(::GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1); //if (aFunction.IsNull()) continue; //GEOM_ISubShape aSSI(aFunction); //aSSI.SetMainShape(aMainShape->GetLastFunction()); @@ -423,8 +471,8 @@ void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy, //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); + //GEOM::GEOM_Object_var aGObj = GetObject(anEntry.ToCString()); + //AddInStudy(aGObj._retn(), SeqN.Value(i).ToCString(), GrObj); } } } @@ -435,8 +483,7 @@ void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy, // purpose : //============================================================================ GEOM::ListOfGO* GEOM_Gen_i:: - PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy, - //SALOMEDS::SObject_ptr theSObject, + PublishNamedShapesInStudy(//SALOMEDS::SObject_ptr theSObject, CORBA::Object_ptr theObject) { //Unexpect aCatch(SALOME_SalomeException); @@ -447,7 +494,8 @@ GEOM::ListOfGO* GEOM_Gen_i:: if(theMainShape->_is_nil()) return aResList._retn(); CORBA::String_var entry = theMainShape->GetEntry(); - Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry); + Handle(::GEOM_Object) aMainShape = Handle(::GEOM_Object)::DownCast + ( _impl->GetObject( entry )); if (aMainShape.IsNull()) return aResList._retn(); TopoDS_Shape MainSh = aMainShape->GetValue(); @@ -487,16 +535,16 @@ GEOM::ListOfGO* GEOM_Gen_i:: TopTools_IndexedMapOfShape anIndices; TopExp::MapShapes(MainSh, anIndices); - CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN, + CreateAndPublishGroup(theMainShape, anIndices, SolidSeqS, SolidSeqN, "Group_Of_Named_Solids", aResList); - CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN, + CreateAndPublishGroup(theMainShape, anIndices, FaceSeqS, FaceSeqN, "Group_Of_Named_Faces", aResList); - CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN, + CreateAndPublishGroup(theMainShape, anIndices, EdgeSeqS, EdgeSeqN, "Group_Of_Named_Edges", aResList); - CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN, + CreateAndPublishGroup(theMainShape, anIndices, VertSeqS, VertSeqN, "Group_Of_Named_Vertices", aResList); return aResList._retn(); @@ -507,7 +555,7 @@ GEOM::ListOfGO* GEOM_Gen_i:: // function : Save() // purpose : save OCAF/Geom document //============================================================================ -SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, +SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr /*theComponent*/, const char* theURL, bool isMultiFile) { SALOMEDS::TMPFile_var aStreamFile; @@ -517,7 +565,7 @@ SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, // OCCT BUG: cannot save a document (in current folder) // if directory name is empty if (aTmpDir.size() == 0) { -#ifdef WNT +#ifdef WIN32 aTmpDir = ".\\"; #else aTmpDir = "./"; @@ -525,24 +573,24 @@ SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, } // Create a list to store names of created files - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - aSeq->length(1); + SALOMEDS_Tool::ListOfFiles aSeq; + aSeq.reserve(1); // 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("_GEOM.sgd"); - aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString()); + if (isMultiFile) + aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath( + Kernel_Utils::encode(getStudyServant()->URL())).c_str())); + aNameWithExt += TCollection_AsciiString("_GEOM.cbf"); + aSeq.push_back(CORBA::string_dup(aNameWithExt.ToCString())); // Build a full file name of temporary file TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt; // Save GEOM component in this file - _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString()); - // Conver a file to the byte stream - aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile); - // Remove the created file and tmp directory - if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); - + if (_impl->Save((char*) aFullName.ToCString())) { + // Convert a file to the byte stream + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq, isMultiFile); + // Remove the created file and tmp directory + if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq, true); + } // Return the created byte stream return aStreamFile._retn(); } @@ -580,7 +628,7 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, // OCCT BUG: cannot load a document (from current folder) // if directory name is empty if (aTmpDir.size() == 0) { -#ifdef WNT +#ifdef WIN32 aTmpDir = ".\\"; #else aTmpDir = "./"; @@ -588,24 +636,36 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, } // Conver the byte stream theStream to a file and place it in tmp directory - SALOMEDS::ListOfFileNames_var aSeq = + SALOMEDS_Tool::ListOfFiles aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile); // Prepare a file name to open TCollection_AsciiString aNameWithExt(""); - SALOMEDS::Study_var study = theComponent->GetStudy(); - if (isMultiFile) { - CORBA::String_var url = study->URL(); - aNameWithExt = (char*)SALOMEDS_Tool::GetNameFromPath(url.in()).c_str(); + SALOMEDS::Study_var study = getStudyServant(); + + // Get the file name. + int i; + int aLength = aSeq.size(); + const char *aGeomSgd = "_GEOM.sgd"; + const char *aGeomcbf = "_GEOM.cbf"; + + for(i = 0; i < aLength; i++) { + std::string aName(aSeq[i]); + + if (aName.rfind(aGeomSgd) != std::string::npos || + aName.rfind(aGeomcbf) != std::string::npos) { + aNameWithExt = aName.c_str(); + break; + } } - aNameWithExt += "_GEOM.sgd"; + TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt); // Open document - if (!_impl->Load(study->StudyId(),(char*) aFullName.ToCString())) return false; + if (!_impl->Load((char*) aFullName.ToCString())) return false; // Remove the created file and tmp directory - if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); + if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq, true); // creation of tree nodes for all data objects in the study // to support tree representation customization and drag-n-drop: @@ -614,8 +674,8 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, useCaseBuilder->SetRootCurrent(); useCaseBuilder->Append( theComponent ); // component object is added as the top level item } - - SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent ); + + SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent ); for ( it->InitEx(true); it->More(); it->Next() ) { if ( !useCaseBuilder->IsUseCaseNode( it->Value() ) ) { useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() ); @@ -642,10 +702,9 @@ CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent, // function : Close() // purpose : //============================================================================ -void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent) +void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr /*theComponent*/) { - SALOMEDS::Study_var aStudy= theComponent->GetStudy(); - _impl->Close(aStudy->StudyId()); + _impl->Close(); } //============================================================================ @@ -697,7 +756,7 @@ SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA:: // function : CanPaste() // purpose : //============================================================================ -CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) { +CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long /*theObjectID*/) { // The Geometry component can paste only objects copied by Geometry component // and with the object type = 1 if (strcmp(theComponentName, ComponentDataType()) != 0) return false; @@ -712,8 +771,9 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, CORBA::Long theObjectID, SALOMEDS::SObject_ptr theObject) { // Find the current Study and StudyBuilder - SALOMEDS::Study_var aStudy = theObject->GetStudy(); + SALOMEDS::Study_var aStudy = getStudyServant(); SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + SALOMEDS::UseCaseBuilder_var anUseCaseBuilder = aStudy->GetUseCaseBuilder(); SALOMEDS::SObject_var aNewSO; // Retrieve a TopoDS_Shape from byte stream TopoDS_Shape aTopology; @@ -721,7 +781,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, BRep_Builder aBuilder; try { BRepTools::Read(aTopology, aStreamedBrep, aBuilder); - } catch (Standard_Failure) { + } catch (Standard_Failure&) { return aNewSO._retn(); } @@ -732,13 +792,13 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, //Create a new GEOM_Object - Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID); - Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF); + Handle(::GEOM_Object) anObj = _impl->AddObject(theObjectID); + Handle(::GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF); aFunction->SetValue(aTopology); TCollection_AsciiString anEntry; TDF_Tool::Entry(anObj->GetEntry(), anEntry); - GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString()); + GEOM::GEOM_BaseObject_var obj = GetObject(anEntry.ToCString()); //Set the study entry of the published GEOM_Object obj->SetStudyEntry(aNewSO->GetID()); @@ -750,6 +810,10 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, anIOR->SetValue(objStr.in()); anIOR->UnRegister(); + // add object to the use case tree + // (to support tree representation customization and drag-n-drop) + anUseCaseBuilder->AppendTo( aNewSO->GetFather(), aNewSO ); + // Return the created in the Study SObject return aNewSO._retn(); } @@ -767,46 +831,46 @@ char* GEOM_Gen_i::ComponentDataType() // function : AddInStudy // purpose : //============================================================================ -SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy, - GEOM::GEOM_Object_ptr theObject, - const char* theName, - GEOM::GEOM_Object_ptr theFather) +SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (GEOM::GEOM_BaseObject_ptr theObject, + const char* theName, + GEOM::GEOM_BaseObject_ptr theFather) { SALOMEDS::SObject_var aResultSO; - if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO; + SALOMEDS::Study_var aStudy = getStudyServant(); + if(theObject->_is_nil() || aStudy->_is_nil()) return aResultSO; - SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); CORBA::String_var IOR; if(!theFather->_is_nil()) { IOR = _orb->object_to_string(theFather); - SALOMEDS::SObject_wrap aFatherSO = theStudy->FindObjectIOR(IOR.in()); + SALOMEDS::SObject_wrap aFatherSO = aStudy->FindObjectIOR(IOR.in()); if(aFatherSO->_is_nil()) return aResultSO._retn(); aResultSO = aStudyBuilder->NewObject(aFatherSO); //aStudyBuilder->Addreference(aResultSO, aResultSO); } - aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName); + aResultSO = PublishInStudy(aResultSO, theObject, theName); if(aResultSO->_is_nil()) return aResultSO._retn(); - GEOM::ListOfGO_var aList = theObject->GetDependency(); + GEOM::ListOfGBO_var aList = theObject->GetDependency(); Standard_Integer aLength = aList->length(); if(aLength < 1) return aResultSO._retn(); //Publish the arguments TCollection_AsciiString aPrevID; // to avoid multiple references to same object for(Standard_Integer i = 0; i< aLength; i++) { - GEOM::GEOM_Object_var anObject = aList[i]; + GEOM::GEOM_BaseObject_var anObject = aList[i]; if(anObject->_is_nil()) continue; IOR = _orb->object_to_string(anObject); - SALOMEDS::SObject_wrap aSO = theStudy->FindObjectIOR(IOR.in()); + SALOMEDS::SObject_wrap aSO = aStudy->FindObjectIOR(IOR.in()); if(aSO->_is_nil()) continue; CORBA::String_var anID = aSO->GetID(); if ( aPrevID == anID.in() ) continue; aPrevID = anID.in(); SALOMEDS::SObject_wrap aSubSO = aStudyBuilder->NewObject(aResultSO); aStudyBuilder->Addreference(aSubSO, aSO); - theStudy->GetUseCaseBuilder()->AppendTo( aResultSO, aSubSO ); + aStudy->GetUseCaseBuilder()->AppendTo( aResultSO, aSubSO ); } return aResultSO._retn(); @@ -817,26 +881,26 @@ 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) //============================================================================ -GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy, - GEOM::GEOM_Object_ptr theObject, +GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (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)) + SALOMEDS::Study_var aStudy = getStudyServant(); + if (CORBA::is_nil(aStudy) || 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()); + SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(anIORo.in()); //PTv, IMP 0020001, The salome object - // is not obligatory in case of invokation from script + // is not obligatory in case of invocation from script // if (CORBA::is_nil(aSO)) // return aParts._retn(); - aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs, + aParts = RestoreSubShapes(theObject, aSO, theArgs, theFindMethod, theInheritFirstArg, theAddPrefix); if (!CORBA::is_nil(aSO)) aSO->UnRegister(); return aParts._retn(); @@ -847,26 +911,25 @@ 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 python scripts, generated by Dump Python. //============================================================================ -GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr theStudy, - GEOM::GEOM_Object_ptr theObject, +GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (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)) + if (CORBA::is_nil(getStudyServant()) || 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()); + SALOMEDS::SObject_var aSO = getStudyServant()->FindObjectIOR(anIORo.in()); //PTv, IMP 0020001, The salome object - // is not obligatory in case of invokation from script + // is not obligatory in case of invocation from script // if (CORBA::is_nil(aSO)) // return aParts._retn(); - aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs, + aParts = RestoreGivenSubShapes(theObject, aSO, theArgs, theFindMethod, theInheritFirstArg, theAddPrefix); if (!CORBA::is_nil(aSO)) aSO->UnRegister(); return aParts._retn(); @@ -877,15 +940,14 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr theS // 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, +GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (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)) + if (CORBA::is_nil(getStudyServant()) || CORBA::is_nil(theSObject)) return aParts._retn(); SALOMEDS::GenericAttribute_var anAttr; @@ -900,7 +962,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy if (CORBA::is_nil(anO)) return aParts._retn(); - aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs, + aParts = RestoreSubShapes(anO, theSObject, theArgs, theFindMethod, theInheritFirstArg, theAddPrefix); return aParts._retn(); } @@ -936,8 +998,7 @@ static void addToListOfGO( const GEOM::ListOfGO& theSrcList, // purpose : Private method. Works only if both theObject and theSObject // 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, +GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(GEOM::GEOM_Object_ptr theObject, SALOMEDS::SObject_ptr theSObject, const GEOM::ListOfGO& theArgs, GEOM::find_shape_method theFindMethod, @@ -945,9 +1006,10 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, CORBA::Boolean theAddPrefix) { GEOM::ListOfGO_var aParts = new GEOM::ListOfGO; + SALOMEDS::Study_var aStudy = getStudyServant(); //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)*/) + // is not obligatory in case of invocation from script + if (CORBA::is_nil(aStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/) return aParts._retn(); // For Dump Python (mantis issue 0020768) @@ -969,8 +1031,12 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, } else { // Get all arguments - aList = theObject->GetDependency(); - aLength = aList->length(); + GEOM::ListOfGBO_var boList = theObject->GetDependency(); + aLength = boList->length(); + aList = new GEOM::ListOfGO; + aList->length(aLength); + for (int i = 0; i < aLength; i++) + aList[i] = GEOM::GEOM_Object::_narrow( boList[i] ); nbArgsActual = aLength; } @@ -982,12 +1048,12 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, // 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()); + SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in()); // remember restored objects for Python Dump addToListOfGO(aList[0], anOutArgs); - aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, + aParts = RestoreSubShapesOneLevel(anArgSO, theSObject, theObject, anOutArgs, theFindMethod, theAddPrefix); // set the color of the transformed shape to the color of initial shape @@ -998,27 +1064,28 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, if (aList[0]->GetMarkerType() == GEOM::MT_USER) theObject->SetMarkerTexture(aList[0]->GetMarkerTexture()); } - - anArgSO->UnRegister(); + if (!CORBA::is_nil(anArgSO)) + 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()); + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(); PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in()); GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast(aServant); // Reconstruct arguments and tree of sub-shapes of the arguments CORBA::String_var anIOR; - SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder(); 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()); + SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in()); TCollection_AsciiString anArgName; if (CORBA::is_nil(anArgSO)) { anArgName = "arg_"; @@ -1043,16 +1110,16 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject); if (!CORBA::is_nil(anArgOTrsf)) { CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); - Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); - Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + Handle(::GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry); + Handle(::GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); anArgOTrsfFun->SetDescription(""); aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf); } /* - Handle(GEOM_Function) anOFun = theObject->GetLastFunction(); + Handle(::GEOM_Function) anOFun = theObject->GetLastFunction(); if (!anOFun.IsNull()) { CORBA::String_var entryArg = anArgO->GetEntry(); - Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg); + Handle(::GEOM_Object) anArgOImpl = _impl->GetObject(entryArg); if (!anArgOImpl.IsNull()) { TopoDS_Shape anArgOShape = anArgOImpl->GetValue(); TopoDS_Shape aMultiArgShape; @@ -1087,7 +1154,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, {} } GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO - Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction(); + Handle(::GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction(); anArgOMultiFun->SetDescription(""); aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti); } @@ -1150,7 +1217,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, } aSubName += anArgName; aSubSO = aStudyBuilder->NewObject(theSObject); - aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString()); + aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString()); // Restore color aSubO->SetColor(anArgO->GetColor()); // set the texture @@ -1166,10 +1233,10 @@ 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, + aSubParts = RestoreSubShapesOneLevel(anArgSO, aSubSO, theObject, anOutArgs, theFindMethod, theAddPrefix); else - aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, + aSubParts = RestoreSubShapesOneLevel(anArgSO, aSubSO, aSubO, anOutArgs, theFindMethod, theAddPrefix); // add to parts list addToListOfGO( aSubParts, aParts ); @@ -1179,11 +1246,14 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, if (!CORBA::is_nil(anArgSO)) { SALOMEDS::SObject_var aSubSO; if (!CORBA::is_nil(theSObject)) + { aSubSO = aStudyBuilder->NewObject(theSObject); + useCaseBuilder->AppendTo( theSObject, aSubSO ); + } // Restore published sub-shapes of the argument GEOM::ListOfGO_var aSubParts = - RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, + RestoreSubShapesOneLevel(anArgSO, aSubSO, theObject, anOutArgs, theFindMethod, theAddPrefix); // add to parts list @@ -1210,7 +1280,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, aSubName = "from_parts_of_"; } aSubName += anArgName; - aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString()); + aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString()); // Restore color aSubO->SetColor(anArgO->GetColor()); // set the texture @@ -1227,7 +1297,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, } } } // try to build from published parts - anArgSO->UnRegister(); + if (!CORBA::is_nil(anArgSO)) + anArgSO->UnRegister(); } } // process arguments } @@ -1238,8 +1309,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, aResParts->length(nb); if (nb > 0) { - Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry()); - Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction(); + Handle(::GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetEntry()); + Handle(::GEOM_Function) aFunction = aMainObj->GetLastFunction(); GEOM::TPythonDump pd (aFunction, true); pd <<"["; int i = 0, j = 0; @@ -1254,8 +1325,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, anObjEntryMap.insert(anEntry); aResParts[nbRes++] = anObj; // clear python dump of object - Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry); - Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction(); + Handle(::GEOM_BaseObject) aGeomObj = _impl->GetObject(anEntry); + Handle(::GEOM_Function) anObjFun = aGeomObj->GetLastFunction(); if ( !anObjFun.IsNull() ) anObjFun->SetDescription( "" ); if ( j > 0 ) @@ -1272,7 +1343,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_var anObj = anOutArgs[ i ]; if (CORBA::is_nil(anObj)) continue; - Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry()); + Handle(::GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetEntry()); if ( j > 0 ) pd << ", "; pd << aGeomObj; @@ -1304,8 +1375,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, // function : RestoreSubShapesOneLevel // purpose : Private method //============================================================================ -GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy, - SALOMEDS::SObject_ptr theOldSO, +GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::SObject_ptr theOldSO, SALOMEDS::SObject_ptr theNewSO, GEOM::GEOM_Object_ptr theNewO, GEOM::ListOfGO& theOutArgs, @@ -1313,24 +1383,26 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th CORBA::Boolean theAddPrefix) { int i = 0; + SALOMEDS::Study_var aStudy = getStudyServant(); GEOM::ListOfGO_var aParts = new GEOM::ListOfGO; GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO; - if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) || + if (CORBA::is_nil(aStudy) || CORBA::is_nil(theOldSO) || CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/) return aParts._retn(); - SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder(); // 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()); + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(); PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in()); GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast(aServant); // Reconstruct published sub-shapes - SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO); + SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(theOldSO); int aLen = 0; for (it->Init(); it->More(); it->Next()) { @@ -1364,8 +1436,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO); if (!CORBA::is_nil(anArgOTrsf)) { CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); - Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); - Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + Handle(::GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry); + Handle(::GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); anArgOTrsfFun->SetDescription(""); aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf); } @@ -1429,7 +1501,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th } aSubName += anArgName; aNewSubSO = aStudyBuilder->NewObject(theNewSO); - aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString()); + aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString()); // Restore color aNewSubO->SetColor(anOldSubO->GetColor()); // set the texture @@ -1438,15 +1510,19 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th if (anOldSubO->GetMarkerType() == GEOM::MT_USER) aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture()); } + // reference to arg + SALOMEDS::SObject_wrap aReferenceSO = aStudyBuilder->NewObject( aNewSubSO ); + aStudyBuilder->Addreference( aReferenceSO, anOldSubSO ); + useCaseBuilder->AppendTo( theNewSO, aReferenceSO ); } // 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, + aSubParts = RestoreSubShapesOneLevel(anOldSubSO, aNewSubSO, theNewO, theOutArgs, theFindMethod, theAddPrefix); else - aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + aSubParts = RestoreSubShapesOneLevel(anOldSubSO, aNewSubSO, aNewSubO, theOutArgs, theFindMethod, theAddPrefix); // add to parts list addToListOfGO( aSubParts, aNewParts ); @@ -1454,11 +1530,13 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th else { // GetInPlace failed, try to build from published parts SALOMEDS::SObject_var aNewSubSO; if (!CORBA::is_nil(theNewSO)) + { aNewSubSO = aStudyBuilder->NewObject(theNewSO); - + useCaseBuilder->AppendTo( theNewSO, aNewSubSO ); + } // Restore published sub-shapes of the argument GEOM::ListOfGO_var aSubParts = - RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + RestoreSubShapesOneLevel(anOldSubSO, aNewSubSO, theNewO, theOutArgs, theFindMethod, theAddPrefix); // add to parts list addToListOfGO( aSubParts, aNewParts ); @@ -1490,7 +1568,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th aSubName = "from_parts_of_"; } aSubName += anArgName; - aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString()); + aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString()); // Restore color aNewSubO->SetColor(anOldSubO->GetColor()); // set the texture @@ -1524,8 +1602,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th // 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, +GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(GEOM::GEOM_Object_ptr theObject, SALOMEDS::SObject_ptr theSObject, const GEOM::ListOfGO& theArgs, GEOM::find_shape_method theFindMethod, @@ -1533,9 +1610,10 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu CORBA::Boolean theAddPrefix) { GEOM::ListOfGO_var aParts = new GEOM::ListOfGO; + SALOMEDS::Study_var aStudy = getStudyServant(); //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)*/) + // is not obligatory in case of invocation from script + if (CORBA::is_nil(aStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/) return aParts._retn(); // If theArgs list is empty, nothing to do @@ -1544,8 +1622,9 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu return aParts._retn(); // Get all arguments - GEOM::ListOfGO_var anOpArgsList = theObject->GetDependency(); - Standard_Integer nbArgsActual = anOpArgsList->length(); + GEOM::ListOfGBO_var anOpArgsList = theObject->GetDependency(); + Standard_Integer nbOpArgs = anOpArgsList->length(); + Standard_Integer nbArgsActual = nbOpArgs; // If anOpArgsList list is empty, nothing to do if (nbArgsActual == 0) @@ -1567,7 +1646,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu for (int j = 0; j < nbArgsActual; j++) { CORBA::String_var anEntry = anOpArgsList[j]->GetEntry(); if (anArgs.count(anEntry.in())) { - aList[k] = GEOM::GEOM_Object::_duplicate(anOpArgsList[j]); + aList[k] = GEOM::GEOM_Object::_narrow(anOpArgsList[j]); k++; } } @@ -1577,14 +1656,14 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu if (nbArgsActual < 1) return aParts._retn(); - if (theInheritFirstArg || (nbArgsActual == 1)) { + if (theInheritFirstArg || (nbOpArgs == 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()); + SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in()); - aParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, + aParts = RestoreGivenSubShapesOneLevel(anArgSO, theSObject, theObject, anArgs, theFindMethod, theAddPrefix); // set the color of the transformed shape to the color of initial shape @@ -1600,22 +1679,23 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu } 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()); + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(); PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in()); GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast(aServant); // Reconstruct arguments and tree of sub-shapes of the arguments CORBA::String_var anIOR; - SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder(); 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()); + SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in()); TCollection_AsciiString anArgName; if (CORBA::is_nil(anArgSO)) { anArgName = "arg_"; @@ -1640,8 +1720,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject); if (!CORBA::is_nil(anArgOTrsf)) { CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); - Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); - Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + Handle(::GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry); + Handle(::GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); anArgOTrsfFun->SetDescription(""); aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf); } @@ -1699,7 +1779,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu } aSubName += anArgName; aSubSO = aStudyBuilder->NewObject(theSObject); - aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString()); + aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString()); // Restore color aSubO->SetColor(anArgO->GetColor()); // set the texture @@ -1715,10 +1795,10 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu GEOM::ListOfGO_var aSubParts; if (theFindMethod == GEOM::FSM_GetInPlaceByHistory) // pass theObject, because only it has the history - aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO, + aSubParts = RestoreGivenSubShapesOneLevel(anArgSO, aSubSO, theObject, anArgs, theFindMethod, theAddPrefix); else - aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO, + aSubParts = RestoreGivenSubShapesOneLevel(anArgSO, aSubSO, aSubO, anArgs, theFindMethod, theAddPrefix); // add to parts list addToListOfGO( aSubParts, aParts ); @@ -1728,11 +1808,13 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu if (!CORBA::is_nil(anArgSO)) { SALOMEDS::SObject_var aSubSO; if (!CORBA::is_nil(theSObject)) + { aSubSO = aStudyBuilder->NewObject(theSObject); - + useCaseBuilder->AppendTo( theSObject, aSubSO ); + } // Restore published sub-shapes of the argument GEOM::ListOfGO_var aSubParts = - RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO, + RestoreGivenSubShapesOneLevel(anArgSO, aSubSO, theObject, anArgs, theFindMethod, theAddPrefix); // add to parts list @@ -1756,7 +1838,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu aSubName = "from_parts_of_"; } aSubName += anArgName; - aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString()); + aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString()); // Restore color aSubO->SetColor(anArgO->GetColor()); // set the texture @@ -1784,8 +1866,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu aResParts->length(nb); if (nb > 0) { - Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry()); - Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction(); + Handle(::GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetEntry()); + Handle(::GEOM_Function) aFunction = aMainObj->GetLastFunction(); GEOM::TPythonDump pd (aFunction, true); pd <<"["; int i = 0, j = 0; @@ -1800,8 +1882,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu anObjEntryMap.insert(anEntry); aResParts[nbRes++] = anObj; // clear python dump of object - Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry); - Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction(); + Handle(::GEOM_BaseObject) aGeomObj = _impl->GetObject(anEntry); + Handle(::GEOM_Function) anObjFun = aGeomObj->GetLastFunction(); if ( !anObjFun.IsNull() ) anObjFun->SetDescription( "" ); if ( j > 0 ) @@ -1816,7 +1898,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu GEOM::GEOM_Object_var anObj = theArgs[ i ]; if (CORBA::is_nil(anObj)) continue; - Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry()); + Handle(::GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetEntry()); if ( j > 0 ) pd << ", "; pd << aGeomObj; @@ -1848,8 +1930,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu // function : RestoreGivenSubShapesOneLevel // purpose : Private method //============================================================================ -GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr theStudy, - SALOMEDS::SObject_ptr theOldSO, +GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::SObject_ptr theOldSO, SALOMEDS::SObject_ptr theNewSO, GEOM::GEOM_Object_ptr theNewO, std::set theArgs, @@ -1857,24 +1938,26 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr CORBA::Boolean theAddPrefix) { int i = 0; + SALOMEDS::Study_var aStudy = getStudyServant(); GEOM::ListOfGO_var aParts = new GEOM::ListOfGO; GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO; - if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) || + if (CORBA::is_nil(aStudy) || CORBA::is_nil(theOldSO) || CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/) return aParts._retn(); - SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder(); // 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()); + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(); PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in()); GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast(aServant); // Reconstruct published sub-shapes - SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO); + SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(theOldSO); int aLen = 0; for (it->Init(); it->More(); it->Next()) { @@ -1916,8 +1999,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO); if (!CORBA::is_nil(anArgOTrsf)) { CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); - Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); - Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + Handle(::GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry); + Handle(::GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); anArgOTrsfFun->SetDescription(""); aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf); } @@ -1978,7 +2061,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr } aSubName += anArgName; aNewSubSO = aStudyBuilder->NewObject(theNewSO); - aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString()); + aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString()); // Restore color aNewSubO->SetColor(anOldSubO->GetColor()); // set the texture @@ -1987,15 +2070,19 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr if (anOldSubO->GetMarkerType() == GEOM::MT_USER) aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture()); } + // reference to arg + SALOMEDS::SObject_wrap aReferenceSO = aStudyBuilder->NewObject( aNewSubSO ); + aStudyBuilder->Addreference( aReferenceSO, anOldSubSO ); + useCaseBuilder->AppendTo( theNewSO, aReferenceSO ); } // 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, + aSubParts = RestoreGivenSubShapesOneLevel(anOldSubSO, aNewSubSO, theNewO, theArgs, theFindMethod, theAddPrefix); else - aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + aSubParts = RestoreGivenSubShapesOneLevel(anOldSubSO, aNewSubSO, aNewSubO, theArgs, theFindMethod, theAddPrefix); // add to parts list addToListOfGO( aSubParts, aNewParts ); @@ -2003,11 +2090,13 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr else { // GetInPlace failed, try to build from published parts SALOMEDS::SObject_var aNewSubSO; if (!CORBA::is_nil(theNewSO)) + { aNewSubSO = aStudyBuilder->NewObject(theNewSO); - + useCaseBuilder->AppendTo( theNewSO, aNewSubSO ); + } // Restore published sub-shapes of the argument GEOM::ListOfGO_var aSubParts = - RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, + RestoreGivenSubShapesOneLevel(anOldSubSO, aNewSubSO, theNewO, theArgs, theFindMethod, theAddPrefix); // add to parts list addToListOfGO( aSubParts, aNewParts ); @@ -2036,7 +2125,7 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr aSubName = "from_parts_of_"; } aSubName += anArgName; - aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString()); + aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString()); // Restore color aNewSubO->SetColor(anOldSubO->GetColor()); // set the texture @@ -2064,39 +2153,63 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr } //============================================================================ -// function : register() -// purpose : register 'name' in 'name_service' +// function : findOrCreateComponent() +// purpose : Find root study component; create if it does not exist //============================================================================ -void GEOM_Gen_i::register_name(char * name) +SALOMEDS::SComponent_var GEOM_Gen_i::findOrCreateComponent() { - GEOM::GEOM_Gen_var g = _this(); - name_service->Register(g, name); + SALOMEDS::SComponent_var aComponent; + + SALOMEDS::Study_var aStudy = getStudyServant(); + if (aStudy->_is_nil()) return aComponent; + + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder(); + + aComponent = aStudy->FindComponent(ComponentDataType()); + if (aComponent->_is_nil()) { + aComponent = aStudyBuilder->NewComponent(ComponentDataType()); + anAttr = aStudyBuilder->FindOrCreateAttribute(aComponent.in(), "AttributeName"); + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + aName->SetValue("Geometry"); + aName->UnRegister(); + anAttr = aStudyBuilder->FindOrCreateAttribute(aComponent.in(), "AttributePixMap"); + SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr); + aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry"); + aPixMap->UnRegister(); + aStudyBuilder->DefineComponentInstance(aComponent.in(), (GEOM::GEOM_Gen_var)GEOM_Gen::_this()); + // add component to the use case tree + // (to support tree representation customization and drag-n-drop) + useCaseBuilder->SetRootCurrent(); + useCaseBuilder->Append(aComponent.in()); // component object is added as the top level item + } + return aComponent; } //============================================================================ // function : Undo // purpose : //============================================================================ -void GEOM_Gen_i::Undo(CORBA::Long theStudyID) +void GEOM_Gen_i::Undo() { - _impl->Undo(theStudyID); + _impl->Undo(); } //============================================================================ // function : Redo // purpose : //============================================================================ -void GEOM_Gen_i::Redo(CORBA::Long theStudyID) +void GEOM_Gen_i::Redo() { - _impl->Redo(theStudyID); + _impl->Redo(); } //============================================================================ // function : GetIBasicOperations // purpose : //============================================================================ -GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations() { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetIBasicOperations" ); @@ -2105,7 +2218,7 @@ GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theS //transfer reference on engine GEOM_IBasicOperations_i* aServant = - new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID)); + new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations()); PortableServer::ObjectId_var id = _poa->activate_object(aServant); // activate the CORBA servant @@ -2117,8 +2230,7 @@ GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theS // function : GetITransformOperations // purpose : //============================================================================ -GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations() { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetITransformOperations" ); @@ -2126,7 +2238,7 @@ GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::L GEOM::GEOM_Gen_ptr engine = _this(); GEOM_ITransformOperations_i* aServant = - new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID)); + new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations()); // activate the CORBA servant GEOM::GEOM_ITransformOperations_var operations = aServant->_this(); @@ -2137,8 +2249,8 @@ GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::L // function : GetI3DPrimOperations // purpose : //============================================================================ -GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations() + { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" ); @@ -2146,7 +2258,7 @@ GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long th GEOM::GEOM_Gen_ptr engine = _this(); GEOM_I3DPrimOperations_i* aServant = - new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID)); + new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations()); PortableServer::ObjectId_var id = _poa->activate_object(aServant); // activate the CORBA servant @@ -2158,8 +2270,8 @@ GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long th // function : GetIShapesOperations // purpose : //============================================================================ -GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations() + { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetIShapesOperations" ); @@ -2167,7 +2279,7 @@ GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long th GEOM::GEOM_Gen_ptr engine = _this(); GEOM_IShapesOperations_i* aServant = - new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID)); + new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations()); // activate the CORBA servant GEOM::GEOM_IShapesOperations_var operations = aServant->_this(); @@ -2178,8 +2290,8 @@ GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long th // function : GetIBlocksOperations // purpose : //============================================================================ -GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations() + { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" ); @@ -2187,7 +2299,7 @@ GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long th GEOM::GEOM_Gen_ptr engine = _this(); GEOM_IBlocksOperations_i* aServant = - new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID)); + new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations()); // activate the CORBA servant GEOM::GEOM_IBlocksOperations_var operations = aServant->_this(); @@ -2198,8 +2310,8 @@ GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long th // function : GetIBooleanOperations // purpose : //============================================================================ -GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations() + { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" ); @@ -2207,7 +2319,7 @@ GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long GEOM::GEOM_Gen_ptr engine = _this(); GEOM_IBooleanOperations_i* aServant = - new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID)); + new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations()); // activate the CORBA servant GEOM::GEOM_IBooleanOperations_var operations = aServant->_this(); @@ -2218,8 +2330,8 @@ GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long // function : GetICurvesOperations // purpose : //============================================================================ -GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations() + { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetICurvesOperations" ); @@ -2227,7 +2339,7 @@ GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long th GEOM::GEOM_Gen_ptr engine = _this(); GEOM_ICurvesOperations_i* aServant = - new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID)); + new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations()); // activate the CORBA servant GEOM::GEOM_ICurvesOperations_var operations = aServant->_this(); @@ -2238,8 +2350,8 @@ GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long th // function : GetILocalOperations // purpose : //============================================================================ -GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations() + { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetILocalOperations" ); @@ -2247,7 +2359,7 @@ GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theS GEOM::GEOM_Gen_ptr engine = _this(); GEOM_ILocalOperations_i* aServant = - new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID)); + new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations()); // activate the CORBA servant GEOM::GEOM_ILocalOperations_var operations = aServant->_this(); @@ -2258,8 +2370,8 @@ GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theS // function : GetIHealingOperations // purpose : //============================================================================ -GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations() + { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::IHealingOperations" ); @@ -2267,7 +2379,7 @@ GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long GEOM::GEOM_Gen_ptr engine = _this(); GEOM_IHealingOperations_i* aServant = - new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID)); + new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations()); // activate the CORBA servant GEOM::GEOM_IHealingOperations_var operations = aServant->_this(); @@ -2278,8 +2390,8 @@ GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long // function : GetIInsertOperations // purpose : //============================================================================ -GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations() + { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetIInsertOperations" ); @@ -2287,7 +2399,7 @@ GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long th GEOM::GEOM_Gen_ptr engine = _this(); GEOM_IInsertOperations_i* aServant = - new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID)); + new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations()); // activate the CORBA servant GEOM::GEOM_IInsertOperations_var operations = aServant->_this(); @@ -2298,8 +2410,8 @@ GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long th // function : GetIMeasureOperations // purpose : //============================================================================ -GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations() + { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" ); @@ -2307,7 +2419,7 @@ GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long GEOM::GEOM_Gen_ptr engine = _this(); GEOM_IMeasureOperations_i* aServant = - new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID)); + new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations()); // activate the CORBA servant GEOM::GEOM_IMeasureOperations_var operations = aServant->_this(); @@ -2318,8 +2430,8 @@ GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long // function : GetIGroupOperations // purpose : //============================================================================ -GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations() + { Unexpect aCatch(SALOME_SalomeException); MESSAGE( "GEOM_Gen_i::GetIGroupOperations" ); @@ -2327,7 +2439,7 @@ GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theS GEOM::GEOM_Gen_ptr engine = _this(); GEOM_IGroupOperations_i* aServant = - new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID)); + new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations()); // activate the CORBA servant GEOM::GEOM_IGroupOperations_var operations = aServant->_this(); @@ -2335,104 +2447,185 @@ GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theS } //============================================================================ -// function : GetPluginOperations +// function : GetIFieldOperations // purpose : //============================================================================ -GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyID, - const char* theLibName) - throw ( SALOME::SALOME_Exception ) +GEOM::GEOM_IFieldOperations_ptr GEOM_Gen_i::GetIFieldOperations() + { - std::string aPlatformLibName; -#ifdef WNT - aPlatformLibName = theLibName; - aPlatformLibName += ".dll" ; -#else - aPlatformLibName = "lib"; - aPlatformLibName += theLibName; - aPlatformLibName += ".so"; -#endif + Unexpect aCatch(SALOME_SalomeException); + MESSAGE( "GEOM_Gen_i::GetIFieldOperations" ); + + GEOM::GEOM_Gen_ptr engine = _this(); + + GEOM_IFieldOperations_i* aServant = + new GEOM_IFieldOperations_i(_poa, engine, _impl->GetIFieldOperations()); + + // activate the CORBA servant + GEOM::GEOM_IFieldOperations_var operations = aServant->_this(); + return operations._retn(); +} +//============================================================================ +// function : GetITestOperations +// purpose : +//============================================================================ +GEOM::GEOM_ITestOperations_ptr GEOM_Gen_i::GetITestOperations() +{ Unexpect aCatch(SALOME_SalomeException); - MESSAGE( "GEOM_Gen_i::GetPluginOperations" ); + MESSAGE( "GEOM_Gen_i::GetITestOperations" ); GEOM::GEOM_Gen_ptr engine = _this(); - GEOM_IOperations_i* aServant = 0; - GEOM::GEOM_IOperations_var operations; + GEOM_ITestOperations_i* aServant = + new GEOM_ITestOperations_i(_poa, engine, _impl->GetITestOperations()); - try { - // check, if corresponding operations are already created - if (myOpCreatorMap.find(std::string(theLibName)) == myOpCreatorMap.end()) { - // load plugin library - LibHandle libHandle = LoadLib( aPlatformLibName.c_str()/*theLibName*/ ); - if (!libHandle) { - // report any error, if occured -#ifndef WNT - const char* anError = dlerror(); - throw(SALOME_Exception(anError)); -#else - throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" ))); -#endif - } + // activate the CORBA servant + GEOM::GEOM_ITestOperations_var operations = aServant->_this(); + return operations._retn(); +} - // get method, returning operations creator - typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)(); - GetOperationsCreator procHandle = - (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" ); - if (!procHandle) { - throw(SALOME_Exception(LOCALIZED("bad geometry plugin library"))); - UnLoadLib(libHandle); - } +//============================================================================ +// function : GetICanonicalRecognition +// purpose : +//============================================================================ +GEOM::GEOM_ICanonicalRecognition_ptr GEOM_Gen_i::GetICanonicalRecognition() +{ + Unexpect aCatch(SALOME_SalomeException); + MESSAGE("GEOM_Gen_i::GetICanonicalRecognition"); - // get operations creator - GEOM_GenericOperationsCreator* aCreator = procHandle(); - if (!aCreator) { - throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation"))); - } + GEOM::GEOM_Gen_ptr engine = _this(); - // map operations creator to a plugin name - myOpCreatorMap[std::string(theLibName)] = aCreator; - } + GEOM_ICanonicalRecognition_i* aServant = + new GEOM_ICanonicalRecognition_i(_poa, engine, _impl->GetICanonicalRecognition()); + + // activate the CORBA servant + GEOM::GEOM_ICanonicalRecognition_var operations = aServant->_this(); + return operations._retn(); +} + +//============================================================================ +// function : GetPluginOperations +// purpose : +//============================================================================ +GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(const char* theLibName) + +{ + Unexpect aCatch(SALOME_SalomeException); + MESSAGE( "GEOM_Gen_i::GetPluginOperations" ); + + GEOM::GEOM_Gen_ptr engine = _this(); + + GEOM::GEOM_IOperations_var operations; + std::string aLibName = theLibName; + + try { + // load plugin library + LoadPlugin(aLibName); // create a new operations object, store its ref. in engine - aServant = myOpCreatorMap[std::string(theLibName)]->Create(_poa, theStudyID, engine, _impl); - //??? aServant->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance + if ( myOpCreatorMap.find(aLibName) != myOpCreatorMap.end() ) { + GEOM_IOperations_i* aServant = 0; + aServant = myOpCreatorMap[aLibName]->Create(_poa, engine, _impl); + // activate the CORBA servant + if (aServant) + operations = aServant->_this(); + } } catch (SALOME_Exception& S_ex) { THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM); } - if (!aServant) - return operations._retn(); - - // activate the CORBA servant - operations = GEOM::GEOM_IOperations::_narrow( aServant->_this() ); return operations._retn(); } +//============================================================================ +// function : LoadPlugin +// purpose : load plugin library and retrieve an instance of operations creator +//============================================================================ +void GEOM_Gen_i::LoadPlugin(const std::string& theLibName) +{ + std::string aPlatformLibName; +#if !defined(WIN32) + aPlatformLibName = "lib"; +#endif + aPlatformLibName += theLibName; +#if defined(WIN32) + aPlatformLibName += ".dll" ; +#elif defined(__APPLE__) + aPlatformLibName += ".dylib"; +#else + aPlatformLibName += ".so"; +#endif + + // check, if corresponding operations are already created + if (myOpCreatorMap.find(theLibName) == myOpCreatorMap.end()) { +#if WIN32 + #if UNICODE + std::wstring strL = Kernel_Utils::utf8_decode_s(aPlatformLibName); + const wchar_t* aPath = strL.c_str(); + #else + const char* aPath = aPlatformLibName.c_str(); + #endif + // load plugin library + LibHandle libHandle = LoadLib(aPath); +#else + LibHandle libHandle = LoadLib(aPlatformLibName.c_str()); +#endif + if (!libHandle) { + // report any error, if occurred +#ifndef WIN32 + throw(SALOME_Exception(dlerror())); +#else + throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" ))); +#endif + } + + // get method, returning operations creator + typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)(); + GetOperationsCreator procHandle = + (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" ); + if (!procHandle) { + UnLoadLib(libHandle); + throw(SALOME_Exception(LOCALIZED("bad geometry plugin library"))); + } + + // get operations creator + GEOM_GenericOperationsCreator* aCreator = procHandle(); + if (aCreator) { + // map operations creator to a plugin name + myOpCreatorMap[theLibName] = aCreator; + } + else { + throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation"))); + } + } +} + //============================================================================= /*! * AddSubShape */ //============================================================================= -GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape, +GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape, const GEOM::ListOfLong& theIndices) { if (CORBA::is_nil(theMainShape) || theIndices.length() < 1) return GEOM::GEOM_Object::_nil(); CORBA::String_var entry = theMainShape->GetEntry(); - Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry); + Handle(::GEOM_Object) aMainShape = Handle(::GEOM_Object)::DownCast + ( _impl->GetObject( 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]); + for(CORBA::ULong i = 0; iSetValue(i+1, theIndices[i]); - Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true); + Handle(::GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true); if(anObject.IsNull()) return GEOM::GEOM_Object::_nil(); TCollection_AsciiString anEntry; TDF_Tool::Entry(anObject->GetEntry(), anEntry); - return GetObject(anObject->GetDocID(), anEntry.ToCString()); + return GEOM::GEOM_Object::_narrow( GetObject(anEntry.ToCString())); } //============================================================================= @@ -2440,25 +2633,23 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShap * RemoveObject */ //============================================================================= -void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject) +void GEOM_Gen_i::RemoveObject(GEOM::GEOM_BaseObject_ptr theObject) { CORBA::String_var anEntry = theObject->GetEntry(); - Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false); - if (anObject.IsNull()) return; - _impl->RemoveObject(anObject); - return; + Handle(::GEOM_BaseObject) anObject = _impl->GetObject(anEntry, false); + if (!anObject.IsNull()) + _impl->RemoveObject(anObject); } - //================================================================================= // function : GetStringFromIOR() // purpose : returns a string that represents a 'GEOM::GEOM_Object_var' //================================================================================= -char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) { +char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) +{ return _orb->object_to_string(theObject); } - //================================================================================= // function : GetIORFromString() // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it @@ -2477,22 +2668,49 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) { // function : GetObject() // purpose : //================================================================================= -GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry) +GEOM::GEOM_BaseObject_ptr GEOM_Gen_i::GetObject (const char* theEntry) { - GEOM::GEOM_Object_var obj; - Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry); + GEOM::GEOM_BaseObject_var obj; + Handle(::GEOM_BaseObject) handle_object = _impl->GetObject((char*)theEntry); if (handle_object.IsNull()) return obj._retn(); TCollection_AsciiString stringIOR = handle_object->GetIOR(); if (stringIOR.Length() > 1) { CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString()); - if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object); + if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_BaseObject::_narrow(corba_object); return obj._retn(); } GEOM::GEOM_Gen_ptr engine = _this(); //transfer the reference to GEOM_Object_i - GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object); + GEOM_BaseObject_i* servant = 0; + switch( handle_object->GetType() ) { + case GEOM_FIELD: { + servant = new GEOM_Field_i (_poa, engine, Handle(::GEOM_Field)::DownCast( handle_object )); + break; + } + case GEOM_FIELD_STEP: { + Handle(::GEOM_FieldStep) step = Handle(::GEOM_FieldStep)::DownCast( handle_object ); + Handle(::GEOM_Field) field = step->GetField(); + int type = ( !field.IsNull() ? field->GetDataType() : 0 ); + switch( type ) { + case GEOM::FDT_Bool: + servant = new GEOM_BoolFieldStep_i (_poa, engine, step ); + break; + case GEOM::FDT_Int: + servant = new GEOM_IntFieldStep_i (_poa, engine, step ); + break; + case GEOM::FDT_Double: + servant = new GEOM_DoubleFieldStep_i (_poa, engine, step ); + break; + default: + servant = new GEOM_StringFieldStep_i (_poa, engine, step ); + } + break; + } + default: + servant = new GEOM_Object_i (_poa, engine, Handle(::GEOM_Object)::DownCast( handle_object )); + } PortableServer::ObjectId_var id = _poa->activate_object(servant); obj = servant->_this(); @@ -2515,14 +2733,11 @@ bool GEOM_Gen_i::hasObjectInfo() // function : getObjectInfo() // purpose : returns an information for a given object by its entry //================================================================================= -char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) +char* GEOM_Gen_i::getObjectInfo(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 ); - SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry ); + SALOMEDS::SObject_var aSObj = getStudyServant()->FindObjectID( entry ); SALOMEDS::SObject_var aResultSObj; if (aSObj->ReferencedObject(aResultSObj)) aSObj = aResultSObj; @@ -2532,7 +2747,7 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); CORBA::String_var aVal = anIOR->Value(); anIOR->UnRegister(); - CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal); + CORBA::Object_var anObject = getStudyServant()->ConvertIORToObject(aVal); aGeomObject = GEOM::GEOM_Object::_narrow(anObject); } if (!aSObj->_is_nil() ) @@ -2544,7 +2759,7 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) GEOM::ListOfLong_var anInts; GEOM::ListOfDouble_var aDbls; - GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId ); + GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations(); aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls ); if ( anOp->IsDone() ) { @@ -2639,6 +2854,18 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) case GEOM::GEOM_IKindOfShape::SEGMENT: aTypeInfo = "Segment"; break; + case GEOM::GEOM_IKindOfShape::CRV_BSPLINE: + aTypeInfo = "Crv BSpline"; + break; + case GEOM::GEOM_IKindOfShape::CRV_BEZIER: + aTypeInfo = "Crv Bezier"; + break; + case GEOM::GEOM_IKindOfShape::HYPERBOLA: + aTypeInfo = "Hyperbola"; + break; + case GEOM::GEOM_IKindOfShape::PARABOLA: + aTypeInfo = "Parabola"; + break; case GEOM::GEOM_IKindOfShape::EDGE: aTypeInfo = "Edge"; break; @@ -2651,8 +2878,9 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) } } - char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3]; - sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo); + CORBA::String_var compType = ComponentDataType(); + char* anInfo = new char[strlen("Module ") + strlen(compType.in()) + strlen(", ") + strlen(aTypeInfo) + 3]; + sprintf(anInfo, "Module %s, %s", compType.in(), aTypeInfo); char* ret = CORBA::string_dup(anInfo); delete [] anInfo; @@ -2673,11 +2901,16 @@ char* GEOM_Gen_i::getVersion() // function : CreateFolder() // purpose : Creates and returns a new folder object //================================================================================= -SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName, - SALOMEDS::SObject_ptr theFather) +SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName, + SALOMEDS::SObject_ptr theFather) { SALOMEDS::SObject_var aFolderSO; + if ( CORBA::is_nil(theFather) ) { + SALOMEDS::SComponent_var aComponent = findOrCreateComponent(); + if (aComponent->_is_nil()) return aFolderSO._retn(); + theFather = SALOMEDS::SObject::_narrow(aComponent); + } if ( CORBA::is_nil(theFather) ) return aFolderSO._retn(); SALOMEDS::GenericAttribute_var anAttr; @@ -2695,7 +2928,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName, aLocalID->UnRegister(); } - SALOMEDS::Study_var aStudy = theFather->GetStudy(); + SALOMEDS::Study_var aStudy = getStudyServant(); SALOMEDS::StudyBuilder_var aStudyBuilder( aStudy->NewBuilder() ); aFolderSO = aStudyBuilder->NewObject( theFather ); @@ -2726,11 +2959,11 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName, // function : MoveToFolder() // purpose : Moves GEOM object to the specified folder //================================================================================= -void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject, - SALOMEDS::SObject_ptr theFolder) { +void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject, + SALOMEDS::SObject_ptr theFolder) { GEOM::object_list_var objects = new GEOM::object_list(); objects->length( 1 ); - SALOMEDS::SObject_var aSO = theFolder->GetStudy()->FindObjectID( theObject->GetStudyEntry() ); + SALOMEDS::SObject_var aSO = getStudyServant()->FindObjectID( theObject->GetStudyEntry() ); objects[0] = aSO; Move( objects, theFolder, -1 ); } @@ -2739,8 +2972,8 @@ void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject, // function : MoveListToFolder() // purpose : Moves list of GEOM objects to the specified folder //================================================================================= -void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO, - SALOMEDS::SObject_ptr theFolder) { +void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO, + SALOMEDS::SObject_ptr theFolder) { int aLen = theListOfGO.length(); GEOM::object_list_var objects = new GEOM::object_list(); objects->length( aLen ); @@ -2748,7 +2981,7 @@ void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO, SALOMEDS::SObject_var aSO; for (int i = 0; i < aLen; i++) { aGO = GEOM::GEOM_Object::_duplicate( theListOfGO[i] ); - aSO = theFolder->GetStudy()->FindObjectID( aGO->GetStudyEntry() ); + aSO = getStudyServant()->FindObjectID( aGO->GetStudyEntry() ); objects[i] = aSO; } if ( objects->length() > 0 ) @@ -2757,22 +2990,22 @@ void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO, //================================================================================= // function : Move() -// purpose : Moves objects to the specified position. +// purpose : Moves objects to the specified position. // Is used in the drag-n-drop functionality. //================================================================================= void GEOM_Gen_i::Move( const GEOM::object_list& what, - SALOMEDS::SObject_ptr where, - CORBA::Long row ) + SALOMEDS::SObject_ptr where, + CORBA::Long row ) { if ( CORBA::is_nil( where ) ) return; - SALOMEDS::Study_var study = where->GetStudy(); + SALOMEDS::Study_var study = getStudyServant(); SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder(); SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder(); SALOMEDS::SComponent_var father = where->GetFatherComponent(); std::string dataType = father->ComponentDataType(); if ( dataType != "GEOM" ) return; // not a GEOM component - + SALOMEDS::SObject_var objAfter; if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) { // insert at given row -> find insertion position @@ -2783,8 +3016,8 @@ void GEOM_Gen_i::Move( const GEOM::object_list& what, objAfter = useCaseIt->Value(); } } - - for ( int i = 0; i < what.length(); i++ ) { + + for ( CORBA::ULong i = 0; i < what.length(); i++ ) { SALOMEDS::SObject_var sobj = what[i]; if ( CORBA::is_nil( sobj ) ) continue; // skip bad object // insert the object to the use case tree @@ -2795,24 +3028,350 @@ void GEOM_Gen_i::Move( const GEOM::object_list& what, } } -//===================================================================================== -// EXPORTED METHODS -//===================================================================================== -extern "C" +//======================================================================= +// function : GetDependencyTree +// purpose : Collects dependencies of the given objects from other ones +//======================================================================= +SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( const GEOM::string_array& theObjectEntries ) { - /* - 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); - return myGEOM_Gen_i->getId(); + // fill in the tree structure + GEOMUtils::TreeModel tree; + + std::string entry; + for ( CORBA::ULong i = 0; i < theObjectEntries.length(); i++ ) { + // process objects one-by-one + entry = theObjectEntries[i].in(); + GEOM::GEOM_BaseObject_var anObj = GetObject(entry.c_str() ); + if ( anObj->_is_nil() ) + continue; + std::map< std::string, std::set > passedEntries; + GEOMUtils::LevelsList upLevelList; + // get objects from which current one depends on recursively + getUpwardDependency( anObj, upLevelList, passedEntries ); + GEOMUtils::LevelsList downLevelList; + // get objects that depends on current one recursively + getDownwardDependency( anObj, downLevelList, passedEntries ); + tree.insert( std::pair >(entry, std::pair( upLevelList, downLevelList ) ) ); + } + + // translation the tree into string + std::string treeStr; + GEOMUtils::ConvertTreeToString( tree, treeStr ); + + // put string into stream + char* aBuffer = (char*)CORBA::string_dup(treeStr.c_str()); + int aBufferSize = strlen((char*)aBuffer); + + CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; + + SALOMEDS::TMPFile_var aStream = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1); + + return aStream._retn(); +} + +//======================================================================= +// function : getUpwardDependency +// purpose : Collects the entries of objects on that the given one depends +//======================================================================= +void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo, + GEOMUtils::LevelsList &upLevelList, + std::map< std::string, std::set > &passedEntries, + int level ) { + std::string aGboEntry = gbo->GetEntry(); + GEOMUtils::NodeLinks anEntries; + GEOMUtils::LevelInfo aLevelMap; + if ( level > 0 ) { + if ( level-1 >= (int)upLevelList.size() ) { + // create a new map + upLevelList.push_back( aLevelMap ); + } else { + // get the existent map + aLevelMap = upLevelList.at(level-1); + if ( aLevelMap.count( aGboEntry ) > 0 ) { + anEntries = aLevelMap[ aGboEntry ]; + } + } + } + // get objects on that the current one depends + GEOM::ListOfGBO_var depList = gbo->GetDependency(); + std::string aDepEntry; + for( CORBA::ULong j = 0; j < depList->length(); j++ ) { + if ( depList[j]->_is_nil() ) + continue; + aDepEntry = depList[j]->GetEntry(); + if ( passedEntries.count( aGboEntry ) > 0 && + passedEntries[aGboEntry].count( aDepEntry ) > 0 ) { + //avoid checking the passed objects + continue; + } + passedEntries[aGboEntry].insert( aDepEntry ); + if ( level > 0 ) { + anEntries.push_back( aDepEntry ); + } + // get dependencies recursively + getUpwardDependency(depList[j], upLevelList, passedEntries, level+1); + } + if ( level > 0 ) { + aLevelMap.insert( std::pair(aGboEntry, anEntries) ); + upLevelList[level-1] = aLevelMap; + } +} + +//======================================================================= +// function : getDownwardDependency +// purpose : Collects the entries of objects that depends on the given one +//======================================================================= +void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo, + GEOMUtils::LevelsList &downLevelList, + std::map< std::string, std::set > &passedEntries, + int level ) { + std::string aGboEntry = gbo->GetEntry(); + Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument(); + Handle(TDataStd_TreeNode) aNode, aRoot; + Handle(::GEOM_Function) aFunction; + if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) { + // go through the whole OCAF tree + TDataStd_ChildNodeIterator Itr( aRoot ); + for (; Itr.More(); Itr.Next()) { + aNode = Itr.Value(); + aFunction = GEOM_Function::GetFunction(aNode->Label()); + if (aFunction.IsNull()) { + continue; + } + TDF_Label aLabel = aFunction->GetOwnerEntry(); + if(aLabel.IsNull()) continue; + TCollection_AsciiString anEntry; + TDF_Tool::Entry(aLabel, anEntry); + GEOM::GEOM_BaseObject_var geomObj = GetObject(anEntry.ToCString() ); + if( CORBA::is_nil( geomObj ) ) + continue; + // get dependencies for current object in the tree + GEOM::ListOfGBO_var depList = geomObj->GetDependency(); + if( depList->length() == 0 ) + continue; + std::string aGoEntry = geomObj->GetEntry(); + // go through dependencies of current object to check whether it depends on the given object + for( CORBA::ULong i = 0; i < depList->length(); i++ ) { + if ( depList[i]->_is_nil() ) + continue; + if ( depList[i]->_is_equivalent( gbo ) ) { + // yes, the current object depends on the given object + if ( passedEntries.count( aGoEntry ) > 0 && + passedEntries[aGoEntry].count( aGboEntry ) > 0 ) { + //avoid checking the passed objects + continue; + } + passedEntries[aGoEntry].insert( aGboEntry ); + GEOMUtils::NodeLinks anEntries; + GEOMUtils::LevelInfo aLevelMap; + anEntries.push_back( aGboEntry ); + if ( level >= (int)downLevelList.size() ) { + downLevelList.push_back( aLevelMap ); + } else { + aLevelMap = downLevelList.at(level); + if ( aLevelMap.count( aGoEntry ) > 0 ) { + anEntries = aLevelMap[ aGoEntry ]; + } + } + aLevelMap.insert( std::pair(aGoEntry, anEntries) ); + downLevelList[level] = aLevelMap; + // get dependencies of the current object recursively + getDownwardDependency(geomObj, downLevelList, passedEntries, level+1); + break; + } + } + } + } +} + +//============================================================================== +// function : GetEntriesToReduceStudy +// purpose : Fills 3 lists that is used to clean study of redundant objects +//============================================================================== +void GEOM_Gen_i::GetEntriesToReduceStudy(GEOM::string_array& theSelectedEntries, + GEOM::string_array& theParentEntries, + GEOM::string_array& theSubEntries, + GEOM::string_array& theOtherEntries) +{ + std::set aSelected, aParents, aChildren, anOthers; + for ( CORBA::ULong i = 0; i < theSelectedEntries.length(); i++ ) { + aSelected.insert( CORBA::string_dup( theSelectedEntries[i] ) ); + } + + Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument(); + Handle(TDataStd_TreeNode) aNode, aRoot; + Handle(::GEOM_Function) aFunction; + if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) { + // go through the whole OCAF tree + TDF_Label aLabel; + std::string anEntry; + TCollection_AsciiString anAsciiEntry; + TDataStd_ChildNodeIterator Itr( aRoot ); + for (; Itr.More(); Itr.Next()) { + aNode = Itr.Value(); + aFunction = GEOM_Function::GetFunction(aNode->Label()); + if (aFunction.IsNull()) { + continue; + } + aLabel = aFunction->GetOwnerEntry(); + if(aLabel.IsNull()) + continue; + TDF_Tool::Entry(aLabel, anAsciiEntry); + anEntry = anAsciiEntry.ToCString(); + GEOM::GEOM_BaseObject_var geomObj = GetObject(anEntry.c_str() ); + if( CORBA::is_nil( geomObj ) ) + continue; + + if ( aSelected.count( anEntry ) > 0 && + aParents.count( anEntry ) == 0 ) { + includeParentDependencies( geomObj, aSelected, aParents, aChildren, anOthers ); + } else if ( aParents.count( anEntry ) == 0 && + aChildren.count( anEntry ) == 0 ) { + anOthers.insert( geomObj->GetEntry() ); + } + } + + std::set::iterator it; + std::set::iterator foundIt; + TCollection_AsciiString stringIOR; + GEOM::GEOM_Object_var geomObj; + + // filling list of sub-objects + for ( it = aSelected.begin(); it != aSelected.end(); ++it ) { + includeSubObjects( *it, aSelected, aParents, aChildren, anOthers ); + } + + // if some selected object is not a main shape, + // we move it's main shapes into 'selected' list, + // because they could not be modified anyhow. + std::set aToBeInSelected; + for ( it = aSelected.begin(); it != aSelected.end(); ++it ) { + Handle(::GEOM_BaseObject) handle_object = _impl->GetObject((*it).c_str(), false); + if ( handle_object.IsNull() ) + continue; + + stringIOR = handle_object->GetIOR(); + if ( stringIOR.Length() < 1 ) + continue; + + geomObj = GetIORFromString( stringIOR.ToCString() ); + while ( !geomObj->IsMainShape() ) { + geomObj = geomObj->GetMainShape(); + anEntry = geomObj->GetEntry(); + + foundIt = aParents.find( anEntry ); + if ( foundIt != aParents.end() ) + aParents.erase( foundIt ); + + foundIt = aChildren.find( anEntry ); + if ( foundIt != aChildren.end() ) + aChildren.erase( foundIt ); + + foundIt = anOthers.find( anEntry ); + if ( foundIt != anOthers.end() ) + anOthers.erase( foundIt ); + + aToBeInSelected.insert( anEntry ); + } + } + aSelected.insert( aToBeInSelected.begin(), aToBeInSelected.end() ); + + // fill the CORBA arrays with values from sets + int i; + theSelectedEntries.length( aSelected.size() ); + for ( i = 0, it = aSelected.begin(); it != aSelected.end(); ++it, i++ ) + theSelectedEntries[i] = CORBA::string_dup( (*it).c_str() ); + theParentEntries.length( aParents.size() ); + for ( i = 0, it = aParents.begin(); it != aParents.end(); ++it, i++ ) + theParentEntries[i] = CORBA::string_dup( (*it).c_str() ); + theSubEntries.length( aChildren.size() ); + for ( i = 0, it = aChildren.begin(); it != aChildren.end(); ++it, i++ ) + theSubEntries[i] = CORBA::string_dup( (*it).c_str() ); + theOtherEntries.length( anOthers.size() ); + for ( i = 0, it = anOthers.begin(); it != anOthers.end(); ++it, i++ ) + theOtherEntries[i] = CORBA::string_dup( (*it).c_str() ); + } +} + +//============================================================================== +// function : includeParentDependencies +// purpose : +//============================================================================== +void GEOM_Gen_i::includeParentDependencies(GEOM::GEOM_BaseObject_ptr geomObj, + std::set& aSelected, + std::set& aParents, + std::set& aChildren, + std::set& anOthers) +{ + std::string anEntry = geomObj->GetEntry(); + if ( aSelected.count( anEntry ) == 0 ) { + aParents.insert( anEntry ); + std::set::iterator it; + it = aChildren.find( anEntry ); + if ( it != aChildren.end() ) + aChildren.erase( it ); + it = anOthers.find( anEntry ); + if ( it != anOthers.end() ) + anOthers.erase( it ); + } + // get dependencies for current object in the tree + GEOM::ListOfGBO_var depList = geomObj->GetDependency(); + if( depList->length() == 0 ) + return; + // go through dependencies of current object to check whether it depends on the given object + std::string aDepEntry; + for( CORBA::ULong i = 0; i < depList->length(); i++ ) { + aDepEntry = depList[i]->GetEntry(); + if ( depList[i]->_is_nil() || + aDepEntry == anEntry || // skip self-depending + aSelected.count( aDepEntry ) > 0 || // skip selected objects + aParents.count( aDepEntry ) > 0 // skip already processed objects + ) + continue; + includeParentDependencies( depList[i], aSelected, aParents, aChildren, anOthers ); } } + +//============================================================================== +// function : includeSubObjects +// purpose : +//============================================================================== +void GEOM_Gen_i::includeSubObjects(const std::string& aSelectedEntry, + std::set& aSelected, + std::set& aParents, + std::set& aChildren, + std::set& anOthers) +{ + std::set::iterator foundIt; + Handle(::GEOM_BaseObject) handle_object = _impl->GetObject(aSelectedEntry.c_str(), false); + if ( handle_object.IsNull() ) + return; + + Handle(::GEOM_Function) aShapeFun = handle_object->GetFunction(1); + if ( aShapeFun.IsNull() || !aShapeFun->HasSubShapeReferences() ) + return; + + const TDataStd_ListOfExtendedString& aListEntries = aShapeFun->GetSubShapeReferences(); + if ( aListEntries.IsEmpty() ) + return; + + TDataStd_ListIteratorOfListOfExtendedString anIt (aListEntries); + for ( ; anIt.More(); anIt.Next() ) { + TCollection_ExtendedString aSubEntry = anIt.Value(); + Standard_Integer aStrLen = aSubEntry.LengthOfCString(); + char* aSubEntryStr = new char[aStrLen+1]; + aSubEntry.ToUTF8CString( aSubEntryStr ); + foundIt = aParents.find( aSubEntryStr ); + if ( foundIt == aParents.end() ) { // add to sub-objects if it is not in parents list + foundIt = aSelected.find( aSubEntryStr ); + if ( foundIt == aSelected.end() ) { // add to sub-objects if it is not in selected list + aChildren.insert( aSubEntryStr ); + foundIt = anOthers.find( aSubEntryStr ); + if ( foundIt != anOthers.end() ) + anOthers.erase( foundIt ); + } + } + includeSubObjects( aSubEntryStr, aSelected, aParents, aChildren, anOthers ); + } +} +