Salome HOME
Fix bug SMESH5451: SMESH_mechanic script aborts.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Swig.cxx
index 67bdff519b1bde4f31037c06bae51164a8434367..db4ce870e00e82054b593741453cc59cfb63a19c 100644 (file)
@@ -91,6 +91,8 @@ void SMESH_Swig::Init(int studyID)
   SALOMEDS::SComponent_var father = myStudy->FindComponent("MESH");
   
   if (father->_is_nil()) {
+    bool aLocked = myStudy->GetProperties()->IsLocked();
+    if (aLocked) myStudy->GetProperties()->SetLocked(false);
     father = myStudyBuilder->NewComponent("MESH");
     anAttr = myStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
     aName = SALOMEDS::AttributeName::_narrow(anAttr);
@@ -99,9 +101,11 @@ void SMESH_Swig::Init(int studyID)
     anAttr = myStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
     aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
+    myStudyBuilder->DefineComponentInstance(father, CompMesh );
+    if (aLocked) myStudy->GetProperties()->SetLocked(true);
   }
-  myStudyBuilder->DefineComponentInstance(father, CompMesh );
-  mySComponentMesh = SALOMEDS::SComponent::_narrow( father );
+
+  mySComponentMesh=father;
 
   // Tags definition 
   Tag_HypothesisRoot  = 1;
@@ -135,6 +139,7 @@ const char* SMESH_Swig::AddNewMesh(const char* IOR)
   SALOMEDS::AttributePixMap_var     aPixmap;
 
   SALOMEDS::SObject_var HypothesisRoot;
+  ASSERT(!mySComponentMesh->_is_nil());
   if (!mySComponentMesh->FindSubObject (Tag_HypothesisRoot, HypothesisRoot)) {
     HypothesisRoot = myStudyBuilder->NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot);
     anAttr = myStudyBuilder->FindOrCreateAttribute(HypothesisRoot, "AttributeName");