Salome HOME
IPAL52460: Optimal Axes button is inert when edit body fitting parameters
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
index 5a3702c6438178afd84ee654d72abf7175c01c52..de77540c6bfa3c24555e0f8b9c41e6f6dbf17914 100644 (file)
@@ -398,7 +398,8 @@ char* SMESHGUI_MeshOp::isSubmeshIgnored() const
       THypList    algoList;
       existingHyps(3, Algo, pMesh, algoNames, algoList);
       if (!algoList.empty()) {
-        HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
+        HypothesisData* algo =
+          SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
         if ( algo &&
              algo->InputTypes.empty() && // builds all dimensions it-self
              !algo->IsSupportSubmeshes )
@@ -412,7 +413,8 @@ char* SMESHGUI_MeshOp::isSubmeshIgnored() const
 //       if ( !geom->_is_nil() && geom->GetShapeType() >= GEOM::FACE ) { // WIRE, EDGE as well
         existingHyps(2, Algo, pMesh, algoNames, algoList);
         if (!algoList.empty()) {
-          HypothesisData* algo = SMESH::GetHypothesisData( algoList[0].first->GetName() );
+          HypothesisData* algo =
+            SMESH::GetHypothesisData( SMESH::toQStr( algoList[0].first->GetName() ));
           if ( algo &&
                algo->InputTypes.empty() && // builds all dimensions it-self
                !algo->IsSupportSubmeshes )
@@ -1031,6 +1033,71 @@ SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
   return hyp;
 }
 
+//================================================================================
+/*!
+ * \brief initialize a hypothesis creator
+ */
+//================================================================================
+
+void SMESHGUI_MeshOp::initHypCreator( SMESHGUI_GenericHypothesisCreator* theCreator )
+{
+  if ( !theCreator ) return;
+
+  // Set shapes, of mesh and sub-mesh if any
+
+  // get Entry of the Geom object
+  QString aGeomEntry = "";
+  QString aMeshEntry = "";
+  QString anObjEntry = "";
+  aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+  aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+  anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
+
+  if ( myToCreate && myIsMesh )
+    aMeshEntry = aGeomEntry;
+
+  if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
+    _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
+    GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
+    aMeshEntry = ( aGeomVar->_is_nil() ) ? QString() : SMESH::toQStr( aGeomVar->GetStudyEntry() );
+  }
+
+  if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
+    _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
+    bool isMesh;
+    GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
+    if ( !aGeomVar->_is_nil() )
+    {
+      aGeomEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
+      if ( isMesh )
+        aMeshEntry = aGeomEntry;
+    }
+  }
+
+  if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
+    // take geometry from submesh being created
+    _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
+    if ( pObj ) {
+      // if current object is sub-mesh
+      SMESH::SMESH_subMesh_var aSubMeshVar =
+        SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
+      if ( !aSubMeshVar->_is_nil() ) {
+        SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
+        if ( !aMeshVar->_is_nil() ) {
+          _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
+          GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
+          if ( !aGeomVar->_is_nil() )
+            aMeshEntry = SMESH::toQStr( aGeomVar->GetStudyEntry() );
+        }
+      }
+    }
+  }
+
+  theCreator->setShapeEntry( aGeomEntry );
+  if ( aMeshEntry != "" )
+    theCreator->setMainShapeEntry( aMeshEntry );
+}
+
 //================================================================================
 /*!
  * \Brief Returns tab dimention
@@ -1138,64 +1205,17 @@ void SMESHGUI_MeshOp::createHypothesis(const int theDim,
     SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(theTypeName);
 
     // Create hypothesis
-    if (aCreator) {
+    if (aCreator)
+    {
       // Get parameters appropriate to initialize a new hypothesis
       SMESH::SMESH_Hypothesis_var initParamHyp =
         getInitParamsHypothesis(theTypeName, aData->ServerLibName);
 
       removeCustomFilters(); // Issue 0020170
 
-      // Get Entry of the Geom object
-      QString aGeomEntry = "";
-      QString aMeshEntry = "";
-      QString anObjEntry = "";
-      aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
-      aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
-      anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
-
-      if ( myToCreate && myIsMesh )
-        aMeshEntry = aGeomEntry;
-
-      if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
-        _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
-        GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
-        aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
-      }
-
-      if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
-        _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
-        bool isMesh;
-        GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
-        if ( !aGeomVar->_is_nil() )
-        {
-          aGeomEntry = aGeomVar->GetStudyEntry();
-          if ( isMesh )
-            aMeshEntry = aGeomEntry;
-        }
-      }
+      // set shapes, of mesh and sub-mesh if any
+      initHypCreator( aCreator );
 
-      if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
-        // take geometry from submesh being created
-        _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
-        if ( pObj ) {
-          // if current object is sub-mesh
-          SMESH::SMESH_subMesh_var aSubMeshVar =
-            SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
-          if ( !aSubMeshVar->_is_nil() ) {
-            SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
-            if ( !aMeshVar->_is_nil() ) {
-              _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
-              GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
-              if ( !aGeomVar->_is_nil() )
-                aMeshEntry = aGeomVar->GetStudyEntry();
-            }
-          }
-        }
-      }
-
-      aCreator->setShapeEntry( aGeomEntry );
-      if ( aMeshEntry != "" )
-        aCreator->setMainShapeEntry( aMeshEntry );
       myDlg->setEnabled( false );
       aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
       dialog = true;
@@ -1270,67 +1290,22 @@ void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
   if ( aHyp->_is_nil() )
     return;
 
-  SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHyp->GetName());
+  SMESHGUI_GenericHypothesisCreator* aCreator =
+    SMESH::GetHypothesisCreator( SMESH::toQStr( aHyp->GetName() ));
   if ( aCreator )
   {
-    // Get initial parameters
+    // set initial parameters
     SMESH::SMESH_Hypothesis_var initParamHyp =
-      getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
+      getInitParamsHypothesis( SMESH::toQStr( aHyp->GetName() ),
+                               SMESH::toQStr( aHyp->GetLibName() ));
     aCreator->setInitParamsHypothesis( initParamHyp );
 
-    // Get Entry of the Geom object
-    QString aGeomEntry = "";
-    QString aMeshEntry = "";
-    QString anObjEntry = "";
-    aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
-    aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
-    anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
-
-    if ( myToCreate && myIsMesh )
-      aMeshEntry = aGeomEntry;
-
-    if ( aMeshEntry != aGeomEntry ) { // Get Geom object from Mesh of a sub-mesh being edited
-      _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
-      GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
-      aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
-    }
-
-    if ( aMeshEntry == "" && aGeomEntry == "" ) { // get geom of an object being edited
-      _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
-      bool isMesh;
-      GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj, &isMesh );
-      if ( !aGeomVar->_is_nil() )
-      {
-        aGeomEntry = aGeomVar->GetStudyEntry();
-        if ( isMesh )
-          aMeshEntry = aGeomEntry;
-      }
-    }
-
-    if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) {
-      // take geometry from submesh being created
-      _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
-      if ( pObj ) {
-        // if current object is sub-mesh
-        SMESH::SMESH_subMesh_var aSubMeshVar =
-          SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
-        if ( !aSubMeshVar->_is_nil() ) {
-          SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
-          if ( !aMeshVar->_is_nil() ) {
-            _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
-            GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
-            if ( !aGeomVar->_is_nil() )
-              aMeshEntry = aGeomVar->GetStudyEntry();
-          }
-        }
-      }
-    }
+    // set shapes, of mesh and sub-mesh if any
+    initHypCreator( aCreator );
 
-    aCreator->setShapeEntry( aGeomEntry );
-    if ( aMeshEntry != "" )
-      aCreator->setMainShapeEntry( aMeshEntry );
     removeCustomFilters(); // Issue 0020170
     myDlg->setEnabled( false );
+
     aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
   }
 }
@@ -1396,7 +1371,6 @@ void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
 
   const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
 
-  // if ( aDim >= SMESH::DIM_2D ) myAvailableHypData[ aDim ][ Algo ] = myFilteredAlgoData[aDim];
   HypothesisData* algoData = hypData( aDim, Algo, theIndex );
   HypothesisData* algoByDim[4];
   algoByDim[ aDim ] = algoData;
@@ -1522,10 +1496,10 @@ void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
       if ( !myToCreate && !curAlgo && !curHyp->_is_nil() ) { // edition, algo not selected
         // try to find algo by selected hypothesis in order to keep it selected
         bool algoDeselectedByUser = ( theDim < 0 && aDim == dim );
-        CORBA::String_var curHypType = curHyp->GetName();
+        QString curHypType = SMESH::toQStr( curHyp->GetName() );
         if ( !algoDeselectedByUser &&
-            myObjHyps[ dim ][ type ].count() > 0 &&
-            !strcmp( curHypType, myObjHyps[ dim ][ type ].first().first->GetName()) )
+             myObjHyps[ dim ][ type ].count() > 0 &&
+             curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
         {
           HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
           for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
@@ -1995,8 +1969,7 @@ SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
   for ( ; anIter != aHypVarList.end(); anIter++)
   {
     SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
-    CORBA::String_var aName = aHypVar->GetName();
-    if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
+    if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
     {
       anAlgoVar = aHypVar;
       break;
@@ -2039,8 +2012,7 @@ SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim )
     for ( anIter = aNewHypVarList.begin(); anIter != aNewHypVarList.end(); ++anIter )
     {
       SMESH::SMESH_Hypothesis_var aHypVar = (*anIter).first;
-      CORBA::String_var aName = aHypVar->GetName();
-      if ( !aHypVar->_is_nil() && !strcmp(aHypName.toLatin1().data(), aName) )
+      if ( !aHypVar->_is_nil() && aHypName == SMESH::toQStr( aHypVar->GetName() ))
       {
         anAlgoVar = aHypVar;
         break;
@@ -2082,13 +2054,9 @@ void SMESHGUI_MeshOp::readMesh()
     }
 
     // Get name of geometry object
-    GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
-    if ( !aGeomVar->_is_nil() )
-    {
-      _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
-      QString aShapeName = name( aGeomSO );
-      myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
-    }
+    CORBA::String_var name = SMESH::GetGeomName( pObj );
+    if ( name.in() )
+      myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
   }
 
   // Get hypotheses and algorithms assigned to the mesh/sub-mesh
@@ -2435,7 +2403,7 @@ void SMESHGUI_MeshOp::onPublishShapeByMeshDlg(SUIT_Operation* op)
     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
     if ( !aGeomVar->_is_nil() )
     {
-      QString ID = aGeomVar->GetStudyEntry();
+      QString ID = SMESH::toQStr( aGeomVar->GetStudyEntry() );
       if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID.toLatin1().data() )) {
         selectObject( aGeomSO );
         selectionDone();
@@ -2572,7 +2540,7 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
 
   if ( anCompareType == "ANY" )
   {
-    for ( int dim = SMESH::DIM_2D; dim <= SMESH::DIM_3D; dim++ )
+    for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
     {
       isNone = currentHyp( dim, Algo ) < 0;
       isAvailableChoiceAlgo = false;
@@ -2585,30 +2553,35 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
       }
       myAvailableHypData[dim][Algo].clear();
       anAvailableAlgs.clear();
-      for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
+      if ( dim != SMESH::DIM_2D || currentHyp( SMESH::DIM_3D, Algo ) < 0 ||
+           myAvailableHypData[SMESH::DIM_3D][Algo].empty() ||
+           !myAvailableHypData[SMESH::DIM_3D][Algo].at( currentHyp( SMESH::DIM_3D, Algo ) )->InputTypes.isEmpty() )
       {
-        HypothesisData* curAlgo = anAvailableAlgsData.at(i);
-        if ( aGeomVar->_is_nil() ||
-             SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, toCheckIsApplicableToAll ))
+        for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
         {
-          anAvailableAlgs.append( curAlgo->Label );
-          myAvailableHypData[dim][Algo].append( curAlgo );
+          HypothesisData* curAlgo = anAvailableAlgsData.at(i);
+          if ( aGeomVar->_is_nil() ||
+              SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, toCheckIsApplicableToAll ))
+          {
+            anAvailableAlgs.append( curAlgo->Label );
+            myAvailableHypData[dim][Algo].append( curAlgo );
+          }
         }
-      }
-      if ( !isNone && algoCur ) {
-        for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
-        {
-          HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
-          if ( algoAny->Label == algoCur->Label ){
-            isAvailableChoiceAlgo = true;
-            anCurrentAvailableAlgo = i;
-            break;
+        if ( !isNone && algoCur ) {
+          for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
+          {
+            HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
+            if ( algoAny->Label == algoCur->Label ){
+              isAvailableChoiceAlgo = true;
+              anCurrentAvailableAlgo = i;
+              break;
+            }
           }
         }
-      }
-      else if ( !isNone ) {
-        isAvailableChoiceAlgo = true;
-        anCurrentAvailableAlgo = currentHyp( dim, Algo );
+        else if ( !isNone ) {
+          isAvailableChoiceAlgo = true;
+          anCurrentAvailableAlgo = currentHyp( dim, Algo );
+        }
       }
       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
       if ( isAvailableChoiceAlgo )
@@ -2689,9 +2662,8 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
         setCurrentHyp( dim, Algo, -1 );
     }
 
-    int aMaxShapeDim = ( myMaxShapeDim != aDim) ? aDim : myMaxShapeDim;
     if ( isNone || isReqDisBound ) {
-      for ( int i = SMESH::DIM_0D; i <= aMaxShapeDim; i++ ) {
+      for ( int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++ ) {
         if ( aDim != i ) {
           myDlg->disableTab( i );
           setCurrentHyp(i, Algo, -1);
@@ -2703,7 +2675,7 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
         myDlg->disableTab( SMESH::DIM_3D );
         setCurrentHyp( SMESH::DIM_3D, Algo, -1);
       }
-      for ( int i = aMaxShapeDim; i > SMESH::DIM_0D; i-- )
+      for ( int i = myMaxShapeDim; i > SMESH::DIM_0D; i-- )
       {
         isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
             myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
@@ -2733,13 +2705,26 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
       isAvailable = false;
       if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
       {
-        for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
+        for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++)
         {
-          for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
-            HypothesisData* aCurAlgo =  hypData( i, Algo, j );
-            if ( aCurAlgo->Label == algoDataIn->Label ){
-              isAvailable = true;
-              break;
+          if ( myAvailableHypData[i][Algo].count() == 0 ) {
+            availableHyps( i, Algo, anAvailableAlgs, anAvailableAlgsData );
+            for ( int j = 0 ; j < anAvailableAlgsData.count(); j++ )
+            {
+              HypothesisData* aCurAlgo = anAvailableAlgsData.at( j );
+              if ( aCurAlgo->Label == algoDataIn->Label ){
+                isAvailable = true;
+                break;
+              }
+            }
+          }
+          else {
+            for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
+              HypothesisData* aCurAlgo = hypData( i, Algo, j );
+              if ( aCurAlgo->Label == algoDataIn->Label ){
+                isAvailable = true;
+                break;
+              }
             }
           }
           if ( isAvailable ) break;