Salome HOME
Integrated to V7_main: 0022366: EDF SMESH: Create Mesh dialog box improvement: create...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
index 187f12d9d67d40c7d946caa633501ff91f9725df..96a6c2647b9f0ae740ea30d81a8794598fcc01f2 100644 (file)
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(SMESH_Gen)
 
-//To disable automatic genericobj management, the following line should be commented.
-//Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
-#define WITHGENERICOBJ
-
 //================================================================================
 /*!
  * \brief Constructor
@@ -737,7 +733,14 @@ bool SMESHGUI_MeshOp::isValid( QString& theMess ) const
     if ( aGeomEntry == "" )
     {
       theMess = tr( "GEOMETRY_OBJECT_IS_NOT_DEFINED" );
-      return false;
+      dlg()->show();
+      if ( SUIT_MessageBox::warning( myDlg, tr( "SMESH_WRN_WARNING" ), theMess,
+           SUIT_MessageBox::Yes, SUIT_MessageBox::No ) == SUIT_MessageBox::No )
+      {
+       theMess = "";
+           return false;
+      }
+      return true;
     }
     _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.toLatin1().data() );
     if ( !pGeom || GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() )->_is_nil() )
@@ -1103,14 +1106,10 @@ void SMESHGUI_MeshOp::createHypothesis(const int theDim,
     // Call hypothesis creation server method (without GUI)
     SMESH::SMESH_Hypothesis_var aHyp =
       SMESH::CreateHypothesis(theTypeName, aHypName, false);
-#ifdef WITHGENERICOBJ
-    if (!CORBA::is_nil(aHyp))
-      aHyp->UnRegister();
-#endif
-  } else {
+    aHyp.out();
+  }
+  else {
     // Get hypotheses creator client (GUI)
-    // BUG 0020378
-    //SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
     SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
 
     // Create hypothesis
@@ -1179,10 +1178,7 @@ void SMESHGUI_MeshOp::createHypothesis(const int theDim,
     else {
      SMESH::SMESH_Hypothesis_var aHyp =
        SMESH::CreateHypothesis(theTypeName, aHypName, false);
-#ifdef WITHGENERICOBJ
-     if (!CORBA::is_nil(aHyp))
-       aHyp->UnRegister();
-#endif
+     aHyp.out();
     }
   }
 
@@ -1612,6 +1608,23 @@ bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
 
   QStringList aList;
   myDlg->selectedObject( SMESHGUI_MeshDlg::Geom, aList );
+  if ( aList.isEmpty() )
+  {
+    SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
+    if ( aSMESHGen->_is_nil() )
+      return false;
+
+    SMESH::SMESH_Mesh_var aMeshVar= aSMESHGen->CreateEmptyMesh();
+    if ( aMeshVar->_is_nil() )
+      return false;
+
+    _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar.in() );
+    if ( aMeshSO ) {
+      SMESH::SetName( aMeshSO, myDlg->objectText( SMESHGUI_MeshDlg::Obj ) );
+      theEntryList.append( aMeshSO->GetID().c_str() );
+    }
+    return true;
+  }
   QStringList::Iterator it = aList.begin();
   for ( ; it!=aList.end(); it++)
   {
@@ -1653,13 +1666,6 @@ bool SMESHGUI_MeshOp::createMesh( QString& theMess, QStringList& theEntryList )
       if ( !anAlgoVar->_is_nil() )
         SMESH::AddHypothesisOnMesh( aMeshVar, anAlgoVar );
     }
-#ifdef WITHGENERICOBJ
-    // obj has been published in study. Its refcount has been incremented.
-    // It is safe to decrement its refcount
-    // so that it will be destroyed when the entry in study will be removed
-    if (aMeshSO)
-      aMeshVar->UnRegister();
-#endif
   }
   return true;
 }
@@ -1741,8 +1747,9 @@ bool SMESHGUI_MeshOp::createSubMesh( QString& theMess, QStringList& theEntryList
         GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(mainGeom, aGroupType);
         op->UnionList(aGroupVar, aSeq);
 
-        if (op->IsDone()) {
-          aGeomVar = aGroupVar.in();
+        if (op->IsDone())
+        {
+          aGeomVar = GEOM::GEOM_Object::_duplicate( aGroupVar.in() );
 
           // publish the GEOM group in study
           QString aNewGeomGroupName ("Auto_group_for_");
@@ -1918,32 +1925,25 @@ SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
     if (aHypData)
     {
       QString aClientLibName = aHypData->ClientLibName;
-      if (aClientLibName == "")
+      if ( aClientLibName.isEmpty() )
       {
         // Call hypothesis creation server method (without GUI)
         SMESH::SMESH_Hypothesis_var aHyp =
           SMESH::CreateHypothesis(aHypName, aHypName, true);
-#ifdef WITHGENERICOBJ
-        if (!CORBA::is_nil(aHyp))
-          aHyp->UnRegister();
-#endif
+        aHyp.out();
       }
       else
       {
         // Get hypotheses creator client (GUI)
-        // BUG 0020378
         SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypName);
 
         // Create algorithm
         if (aCreator)
-          aCreator->create(true, aHypName, myDlg, 0, QString::null );
+          aCreator->create( true, aHypName, myDlg, 0, QString::null );
         else {
           SMESH::SMESH_Hypothesis_var aHyp =
             SMESH::CreateHypothesis(aHypName, aHypName, true);
-#ifdef WITHGENERICOBJ
-          if (!CORBA::is_nil(aHyp))
-            aHyp->UnRegister();
-#endif
+          aHyp.out();
         }
       }
       QStringList tmpList;