From 8647067a5b819fe9cf746cc0855b65c48cb6a2ae Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 27 May 2020 18:08:52 +0300 Subject: [PATCH] bos #19182: Additional fix for CreateFolder() service --- src/GEOM_I/GEOM_Gen_i.cc | 58 ++++++++++++++++++++++++++++------------ src/GEOM_I/GEOM_Gen_i.hh | 2 ++ 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 800f9ec8f..4e50c4bd6 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -226,23 +226,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObjec SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder(); - SALOMEDS::SComponent_var aFather = aStudy->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)) { @@ -2195,6 +2179,41 @@ SALOMEDS::Study_var GEOM_Gen_i::getStudyServant() return aStudy; } +//============================================================================ +// function : findOrCreateComponent() +// purpose : Find root study component; create if it does not exist +//============================================================================ +SALOMEDS::SComponent_var GEOM_Gen_i::findOrCreateComponent() +{ + 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 : @@ -2866,6 +2885,11 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName, { 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; diff --git a/src/GEOM_I/GEOM_Gen_i.hh b/src/GEOM_I/GEOM_Gen_i.hh index 16e68220f..cd515fe03 100644 --- a/src/GEOM_I/GEOM_Gen_i.hh +++ b/src/GEOM_I/GEOM_Gen_i.hh @@ -325,6 +325,8 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi virtual GEOM::GEOM_BaseObject_ptr GetObject(const char* theEntry); private: + SALOMEDS::SComponent_var findOrCreateComponent(); + GEOM::ListOfGO* RestoreSubShapes (GEOM::GEOM_Object_ptr theObject, SALOMEDS::SObject_ptr theSObject, const GEOM::ListOfGO& theArgs, -- 2.39.2