Salome HOME
PAL10953. Use GUI to create hypothesis from a hypotheses set
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
index f7d370d9e880a3ca668902f65341d209838e018e..716d21e612280ff73d788a93f47ac4b4c9615825 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 
+// 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.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
 /**
 *  SMESH SMESHGUI
 *
@@ -33,8 +52,8 @@
 #include "SALOMEDS_SObject.hxx"
 
 
-#include "SalomeApp_SelectionMgr.h"
-#include "SalomeApp_UpdateFlags.h"
+#include "LightApp_SelectionMgr.h"
+#include "LightApp_UpdateFlags.h"
 #include "SUIT_MessageBox.h"
 #include "SUIT_Desktop.h"
 #include "SUIT_OverrideCursor.h"
@@ -80,10 +99,10 @@ SMESHGUI_MeshOp::~SMESHGUI_MeshOp()
 //================================================================================
 /*!
  * \brief Gets dialog of this operation
-  * \retval SalomeApp_Dialog* - pointer to dialog of this operation
+  * \retval LightApp_Dialog* - pointer to dialog of this operation
 */
 //================================================================================
-SalomeApp_Dialog* SMESHGUI_MeshOp::dlg() const
+LightApp_Dialog* SMESHGUI_MeshOp::dlg() const
 {
   return myDlg;
 }
@@ -276,49 +295,51 @@ void SMESHGUI_MeshOp::selectionDone()
   // Enable tabs according to shape dimension
 
   int shapeDim = 3;
-  if ( myToCreate )
+  try
   {
-    try
-    {
-      QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
-      _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
-      if ( pGeom ) {
-        GEOM::GEOM_Object_var aGeomVar =
-          GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
-        if ( !aGeomVar->_is_nil() ) {
-          shapeDim = 0;
-          switch ( aGeomVar->GetShapeType() ) {
-          case GEOM::SOLID:
-          case GEOM::SHELL:  shapeDim = 3; break;
-          case GEOM::FACE:   shapeDim = 2; break;
-          case GEOM::WIRE:   
-          case GEOM::EDGE:   shapeDim = 1; break;
-          case GEOM::VERTEX: shapeDim = 0; break;
-          default:
-            TopoDS_Shape aShape;
-            if ( GEOMBase::GetShape(aGeomVar, aShape)) {
-              TopExp_Explorer exp( aShape, TopAbs_SHELL );
-              if ( exp.More() )
-                shapeDim = 3;
-              else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
-                shapeDim = 2;
-              else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
-                shapeDim = 1;
-              else
-                shapeDim = 0;
-            }
-          }
-        }
-      }
+    GEOM::GEOM_Object_var aGeomVar;
+    QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+    _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
+    if ( pGeom ) {
+      aGeomVar = GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
     }
-    catch ( const SALOME::SALOME_Exception& S_ex )
-    {
-      SalomeApp_Tools::QtCatchCorbaException( S_ex );
+    else {
+      QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
+      _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() );
+      aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
     }
-    catch ( ... )
-    {
+    if ( !aGeomVar->_is_nil() ) {
+      shapeDim = 0;
+      switch ( aGeomVar->GetShapeType() ) {
+      case GEOM::SOLID:
+      case GEOM::SHELL:  shapeDim = 3; break;
+      case GEOM::FACE:   shapeDim = 2; break;
+      case GEOM::WIRE:   
+      case GEOM::EDGE:   shapeDim = 1; break;
+      case GEOM::VERTEX: shapeDim = 0; break;
+      default:
+        TopoDS_Shape aShape;
+        if ( GEOMBase::GetShape(aGeomVar, aShape)) {
+          TopExp_Explorer exp( aShape, TopAbs_SHELL );
+          if ( exp.More() )
+            shapeDim = 3;
+          else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
+            shapeDim = 2;
+          else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
+            shapeDim = 1;
+          else
+            shapeDim = 0;
+        }
+      }
     }
   }
+  catch ( const SALOME::SALOME_Exception& S_ex )
+  {
+    SalomeApp_Tools::QtCatchCorbaException( S_ex );
+  }
+  catch ( ... )
+  {
+  }
   myDlg->setMaxHypoDim( shapeDim );
 }
 
@@ -611,6 +632,7 @@ void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
     {
       const QString& aHypoTypeName = (*aHypoList)[ i ];
       HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
+      if ( !aHypData ) continue;
       int aDim = aHypData->Dim[0];
       // create or/and set
       int index = -1;
@@ -636,12 +658,23 @@ void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
         }
         if ( index >= 0 ) // found
         {
+          // select an algorithm
           setCurrentHyp ( aDim, aHypType, index );
         }
         else
         {
-          // silently create a hypothesis
-          SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
+          // create a hypothesis
+          QString aClientLibName = aHypData->ClientLibName;
+          if ( aClientLibName == "" ) {
+            // Call hypothesis creation server method (without GUI)
+            SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
+          }
+          else {
+            // Get hypotheses creator client (GUI)
+            SMESHGUI_GenericHypothesisCreator* aCreator =
+              SMESH::GetHypothesisCreator( aHypoTypeName );
+            aCreator->CreateHypothesis( false, myDlg );
+          }
           QStringList aNewHyps;
           _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
           existingHyps( aDim, aHypType, aFather, aNewHyps, aList );