Salome HOME
Fix 17 regressions
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
index 8c1813f5636753b9da8cf4fa6521e4c69c2edf31..660be5386b2b016de1255a011d6c9d3266759ace 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include "SMESHGUI_MeshOp.h"
 
 #include "SMESHGUI.h"
+#include "SMESHGUI_GEOMGenUtils.h"
+#include "SMESHGUI_Hypotheses.h"
+#include "SMESHGUI_HypothesesUtils.h"
 #include "SMESHGUI_MeshDlg.h"
+#include "SMESHGUI_Operations.h"
 #include "SMESHGUI_ShapeByMeshDlg.h"
-#include "SMESHGUI_HypothesesUtils.h"
-#include "SMESHGUI_Hypotheses.h"
 #include "SMESHGUI_Utils.h"
-#include "SMESHGUI_GEOMGenUtils.h"
-
-#include <SMESH_TypeFilter.hxx>
-#include <SMESH_NumberFilter.hxx>
+#include "SMESH_NumberFilter.hxx"
+#include "SMESH_TypeFilter.hxx"
 
 // SALOME GEOM includes
 #include <GEOM_SelectionFilter.h>
@@ -247,8 +247,9 @@ void SMESHGUI_MeshOp::startOperation()
     myDlg->activateObject( myIsMesh ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Mesh );
   }
   else
+  {
     myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
-
+  }
   myDlg->setCurrentTab( SMESH::DIM_3D );
 
   QStringList TypeMeshList;
@@ -363,15 +364,39 @@ bool SMESHGUI_MeshOp::isSubshapeOk() const
       // skl for NPAL14695 - implementation of searching of mainObj
       GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
                                                                         mainObj already exists! */
-      while(1) {
-        if (mainObj->_is_nil())
-          return false;
+      while( !mainObj->_is_nil()) {
         CORBA::String_var entry1 = mainObj->GetEntry();
         CORBA::String_var entry2 = mainGeom->GetEntry();
         if (std::string( entry1.in() ) == entry2.in() )
           return true;
         mainObj = op->GetMainShape(mainObj);
       }
+      if ( aSubGeomVar->GetShapeType() == GEOM::COMPOUND )
+      {
+        // is aSubGeomVar a compound of sub-shapes?
+        GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations(aStudy->StudyId());
+        if (sop->_is_nil()) return false;
+        GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( aSubGeomVar,
+                                                            GEOM::SHAPE,/*sorted=*/false);
+        if ( ids->length() > 0 )
+        {
+          ids->length( 1 );
+          GEOM::GEOM_Object_var compSub = geomGen->AddSubShape( aSubGeomVar, ids );
+          if ( !compSub->_is_nil() )
+          {
+            GEOM::ListOfGO_var shared = sop->GetSharedShapes( mainGeom,
+                                                              compSub,
+                                                              compSub->GetShapeType() );
+            geomGen->RemoveObject( compSub );
+            compSub->UnRegister();
+            if ( shared->length() > 0 ) {
+              geomGen->RemoveObject( shared[0] );
+              shared[0]->UnRegister();
+            }
+            return ( shared->length() > 0 );
+          }
+        }
+      }
     }
   }
 
@@ -380,8 +405,8 @@ bool SMESHGUI_MeshOp::isSubshapeOk() const
 
 //================================================================================
 /*!
- * \brief Return name of the algorithm that does not support submeshes and makes
- * submesh creation useless
+ * \brief Return name of the algorithm that does not support sub-meshes and makes
+ * sub-mesh creation useless
  *  \retval char* - string is to be deleted!!!
  */
 //================================================================================
@@ -526,9 +551,17 @@ void SMESHGUI_MeshOp::selectionDone()
         for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++, iSubSh++) {
           QString aSubGeomEntry = (*aSubShapesIter);
           _PTR(SObject) pSubGeom = studyDS()->FindObjectID(aSubGeomEntry.toLatin1().data());
-          GEOM::GEOM_Object_var aSubGeomVar =
-            GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
-          aSeq[iSubSh] = aSubGeomVar;
+         
+          if( pSubGeom ) { 
+            SALOMEDS_SObject* sobj = _CAST(SObject,pSubGeom);
+            if( sobj ) {
+              GEOM::GEOM_Object_var aSubGeomVar =
+                GEOM::GEOM_Object::_narrow(sobj->GetObject());
+              if( !aSubGeomVar->_is_nil() ){
+                aSeq[iSubSh] = aSubGeomVar;
+              }
+            }
+          }
         }
       } else {
         // get geometry by selected sub-mesh
@@ -633,7 +666,7 @@ void SMESHGUI_MeshOp::selectionDone()
           {
             selectionMgr()->clearFilters();
             selectObject( pSubmesh );
-            SMESHGUI::GetSMESHGUI()->switchToOperation(704);
+            SMESHGUI::GetSMESHGUI()->switchToOperation( SMESHOp::OpEditMeshOrSubMesh );
             return;
           }
           else
@@ -1463,14 +1496,32 @@ void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
       if ( anAvailable.count() == 1 )
         soleCompatible = myAvailableHypData[dim][Algo][0];
       if ( dim == aTopDim && prevAlgo ) {// all available algoritms should be selectable any way
-        if (myDlg->currentMeshType() == MT_ANY)
+        if (aTopDim == SMESH::DIM_2D && myFilteredAlgoData[dim].count() > 0) {
+          anAvailable.clear();
+          for (int i = 0; i < myFilteredAlgoData[dim].count(); ++i) {
+            HypothesisData* aCurAlgo = myFilteredAlgoData[dim][ i ];
+            anAvailable.append( aCurAlgo->Label );
+          }
+        }
+        if (aTopDim == SMESH::DIM_3D && myDlg->currentMeshType() == MT_ANY)
           availableHyps( dim, Algo, anAvailable, myAvailableHypData[dim][Algo], 0 );
       }
       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailable );
       noCompatible = anAvailable.isEmpty();
 
       // restore previously selected algo
-      algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
+      if (dim == aTopDim && prevAlgo && aTopDim == SMESH::DIM_2D && myFilteredAlgoData[dim].count() > 0) {
+        algoIndex = myFilteredAlgoData[dim].indexOf( curAlgo );
+        setCurrentHyp( dim, Algo, algoIndex);
+        if (algoIndex >= 0)
+          prevAlgo = algoByDim[ dim ] = myFilteredAlgoData[dim][algoIndex];
+        else
+          prevAlgo = algoByDim[ dim ] = 0;
+        continue;
+      }
+      else {
+        algoIndex = myAvailableHypData[dim][Algo].indexOf( curAlgo );
+      }
       if ( !isSubmesh && algoIndex < 0 && soleCompatible && !forward && dim != SMESH::DIM_0D)
         // select the sole compatible algo
         algoIndex = myAvailableHypData[dim][Algo].indexOf( soleCompatible );
@@ -1520,7 +1571,7 @@ void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
              myObjHyps[ dim ][ type ].count() > 0 &&
              curHypType == SMESH::toQStr( myObjHyps[ dim ][ type ].first().first->GetName()) )
         {
-          HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
+          HypothesisData* hypData = SMESH::GetHypothesisData( SMESH::toQStr( curHyp->GetName() ));
           for (int i = 0; i < myAvailableHypData[ dim ][ Algo ].count(); ++i) {
             curAlgo = myAvailableHypData[ dim ][ Algo ][ i ];
             if (curAlgo && hypData && isCompatible(curAlgo, hypData, type))
@@ -1536,7 +1587,7 @@ void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
       {
         // check if a selected hyp is compatible with the curAlgo
         if ( !curHyp->_is_nil() ) {
-          HypothesisData* hypData = SMESH::GetHypothesisData( curHyp->GetName() );
+          HypothesisData* hypData = SMESH::GetHypothesisData( SMESH::toQStr( curHyp->GetName() ));
           if ( !isCompatible( curAlgo, hypData, type ))
             curHyp = SMESH::SMESH_Hypothesis::_nil();
         }
@@ -2129,7 +2180,7 @@ void SMESHGUI_MeshOp::readMesh()
     if ( myObjHyps[ dim ][ Algo ].count() > 0 )
     {
       SMESH::SMESH_Hypothesis_var aVar = myObjHyps[ dim ][ Algo ].first().first;
-      HypothesisData* algoData = SMESH::GetHypothesisData( aVar->GetName() );
+      HypothesisData* algoData = SMESH::GetHypothesisData( SMESH::toQStr( aVar->GetName() ));
       aHypIndex = myAvailableHypData[ dim ][ Algo ].indexOf ( algoData );
       //       if ( aHypIndex < 0 && algoData ) {
       //         // assigned algo is incompatible with other algorithms
@@ -2272,7 +2323,7 @@ bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
       SMESH::SMESH_Hypothesis_var anOldAlgo = myObjHyps[ dim ][ Algo ].first().first;
       SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
       if ( anAlgoVar->_is_nil() || // no new algo selected or
-           strcmp(anOldAlgo->GetName(), anAlgoVar->GetName()) ) // algo change
+           SMESH::toQStr(anOldAlgo->GetName()) != SMESH::toQStr(anAlgoVar->GetName())) // algo change
       {
         // remove old algorithm
         SMESH::RemoveHypothesisOrAlgorithmOnMesh ( pObj, myObjHyps[ dim ][ Algo ].first().first );
@@ -2383,7 +2434,7 @@ bool SMESHGUI_MeshOp::checkSubMeshConcurrency(SMESH::SMESH_Mesh_ptr    mesh,
         myDlg->setEnabled( false ); // disactivate selection
         selectionMgr()->clearFilters();
         selectObject( meshSO );
-        SMESHGUI::GetSMESHGUI()->OnGUIEvent( 713 ); // MESH_ORDER
+        SMESHGUI::GetSMESHGUI()->OnGUIEvent( SMESHOp::OpMeshOrder ); // MESH_ORDER
         qApp->processEvents();
 
         myDlg->setEnabled( true );
@@ -2590,11 +2641,11 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
 
   bool toCheckIsApplicableToAll = !myIsMesh;
   GEOM::GEOM_Object_var aGeomVar;
-  QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+  QString anEntry =
+    myDlg->selectedObject( myToCreate ? SMESHGUI_MeshDlg::Geom : SMESHGUI_MeshDlg::Obj );
   if ( _PTR(SObject) so = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
   {
-    CORBA::Object_var obj = _CAST( SObject,so )->GetObject();
-    aGeomVar = GEOM::GEOM_Object::_narrow( obj );
+    aGeomVar = SMESH::GetGeom( so );
     if ( !aGeomVar->_is_nil() && toCheckIsApplicableToAll )
       toCheckIsApplicableToAll = ( aGeomVar->GetType() == GEOM_GROUP );
   }
@@ -2613,6 +2664,7 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
         algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
       }
       myAvailableHypData[dim][Algo].clear();
+      myFilteredAlgoData[dim].clear();
       anAvailableAlgs.clear();
       if ( dim != SMESH::DIM_2D || currentHyp( SMESH::DIM_3D, Algo ) < 0 ||
            myAvailableHypData[SMESH::DIM_3D][Algo].empty() ||
@@ -2626,6 +2678,7 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
           {
             anAvailableAlgs.append( curAlgo->Label );
             myAvailableHypData[dim][Algo].append( curAlgo );
+            myFilteredAlgoData[dim].append( curAlgo );
           }
         }
         if ( !isNone && algoCur ) {