]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
bos #19182: Additional fix for CreateFolder() service
authorvsr <vsr@opencascade.com>
Wed, 27 May 2020 15:08:52 +0000 (18:08 +0300)
committervsr <vsr@opencascade.com>
Wed, 27 May 2020 15:08:52 +0000 (18:08 +0300)
src/GEOM_I/GEOM_Gen_i.cc
src/GEOM_I/GEOM_Gen_i.hh

index 800f9ec8f9518e9e1ef44a25ae0fd70955988201..4e50c4bd6b25b02c1564ce1101d5158be47189f9 100644 (file)
@@ -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;
index 16e68220f479d883efc2ade314fd48028ea40001..cd515fe03cc4f926a9bd06f6fc37b45659259206 100644 (file)
@@ -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,