Salome HOME
Color Number (Color Group) parameter is returned for compatibility
[modules/smesh.git] / src / SMESH / SMESH_subMesh.cxx
index e766df8ef2fe79bb2a510792ddff1bf746c0b75e..bbb5fa96a45e3c7f8c7e2da6dcaf1b826d6c1252 100644 (file)
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 #include <TopExp.hxx>
-#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <TopTools_ListOfShape.hxx>
-#include <TopTools_MapOfShape.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Compound.hxx>
 #include <gp_Pnt.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Iterator.hxx>
 
 #include <Standard_OutOfMemory.hxx>
 #include <Standard_ErrorHandler.hxx>
@@ -412,10 +411,12 @@ const map < int, SMESH_subMesh * >& SMESH_subMesh::DependsOn()
   case TopAbs_SOLID:
     {
       //MESSAGE("solid");
-      for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
-           exp.Next())
-      {
-        InsertDependence(exp.Current());
+      if(_father->HasShapeToMesh()) {
+        for (TopExp_Explorer exp(_subShape, TopAbs_FACE); exp.More();
+             exp.Next())
+        {
+          InsertDependence(exp.Current());
+        }
       }
       break;
     }
@@ -496,9 +497,14 @@ const TopoDS_Shape & SMESH_subMesh::GetSubShape() const
 bool SMESH_subMesh::CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const
 {
   int aHypDim   = theHypothesis->GetDim();
-  int aShapeDim = SMESH_Gen::GetShapeDim(_subShape);
-  if ( aHypDim <= aShapeDim )
-    return true;
+  if(_father->HasShapeToMesh()) {
+    int aShapeDim = SMESH_Gen::GetShapeDim(_subShape);
+    if ( aHypDim <= aShapeDim )
+      return true;
+  }
+  else
+    //Only 3D hypothesis may be assigned to the mesh w/o geometry
+    return aHypDim == 3;
 //   if ( aHypDim < aShapeDim )
 //     return ( _father->IsMainShape( _subShape ));
 
@@ -601,8 +607,9 @@ SMESH_Hypothesis::Hypothesis_Status
     // check if a shape needed by algo is present
     // -------------------------------------------
     algo = static_cast< SMESH_Algo* >( anHyp );
-    if ( !_father->HasShapeToMesh() && algo->NeedShape() )
-      return SMESH_Hypothesis::HYP_BAD_GEOMETRY;
+    if(_father->GetShapeToMesh() != SMESH_Mesh::PseudoShape())
+      if ( !_father->HasShapeToMesh() && algo->NeedShape() )
+        return SMESH_Hypothesis::HYP_BAD_GEOMETRY;
     // ----------------------
     // check mesh conformity
     // ----------------------
@@ -618,6 +625,17 @@ SMESH_Hypothesis::Hypothesis_Status
     if ( ! CanAddHypothesis( anHyp )) // check dimension
       return SMESH_Hypothesis::HYP_BAD_DIM;
 
+    if(anHyp->GetDim() == 3 && !_father->HasShapeToMesh()
+       && event == ADD_ALGO) {
+      //Only NETGEN_3D and GHS3D_3D can be assigned to the Mesh w/o geometryy
+      bool isNetgen3D = (strcmp( "NETGEN_3D", anHyp->GetName()) == 0);
+      bool  isGhs3d = (strcmp( "GHS3D_3D", anHyp->GetName()) == 0);
+      if( !isNetgen3D && !isGhs3d)
+        return SMESH_Hypothesis::HYP_BAD_DIM;
+    }
+      
+
+    
     if ( /*!anHyp->IsAuxiliary() &&*/ GetSimilarAttached( _subShape, anHyp ) )
       return SMESH_Hypothesis::HYP_ALREADY_EXIST;
 
@@ -985,6 +1003,7 @@ SMESH_Hypothesis::Hypothesis_Status
 
   if ( stateChange && oldAlgoState == HYP_OK ) { // hyp becomes KO
     DeleteOwnListeners();
+    SetIsAlwaysComputed( false );
     if (_subShape.ShapeType() == TopAbs_VERTEX ) {
       // restore default states
       _algoState = HYP_OK;
@@ -1305,8 +1324,8 @@ bool SMESH_subMesh::ComputeStateEngine(int event)
           }
         }
         // compute
-        CleanDependants();
-        RemoveSubMeshElementsAndNodes();
+//         CleanDependants(); for "UseExisting_*D" algos
+//         RemoveSubMeshElementsAndNodes();
         ret = false;
         _computeState = FAILED_TO_COMPUTE;
         _computeError = SMESH_ComputeError::New(COMPERR_OK,"",algo);
@@ -1315,8 +1334,9 @@ bool SMESH_subMesh::ComputeStateEngine(int event)
 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
           OCC_CATCH_SIGNALS;
 #endif
-          MemoryReserve aMemoryReserve;
           algo->InitComputeError();
+          MemoryReserve aMemoryReserve;
+          SMDS_Mesh::CheckMemory();
           if ( !_father->HasShapeToMesh() ) // no shape
           {
             SMESH_MesherHelper helper( *_father );
@@ -1335,7 +1355,7 @@ bool SMESH_subMesh::ComputeStateEngine(int event)
             _computeError = algo->GetComputeError();
         }
         catch ( std::bad_alloc& exc ) {
-          printf("std::bad_alloc\n");
+          printf("std::bad_alloc thrown inside algo->Compute()\n");
           if ( _computeError ) {
             _computeError->myName = COMPERR_MEMORY_PB;
             //_computeError->myComment = exc.what();
@@ -1344,7 +1364,7 @@ bool SMESH_subMesh::ComputeStateEngine(int event)
           throw exc;
         }
         catch ( Standard_OutOfMemory& exc ) {
-          printf("Standard_OutOfMemory\n");
+          printf("Standard_OutOfMemory thrown inside algo->Compute()\n");
           if ( _computeError ) {
             _computeError->myName = COMPERR_MEMORY_PB;
             //_computeError->myComment = exc.what();
@@ -1393,7 +1413,6 @@ bool SMESH_subMesh::ComputeStateEngine(int event)
         if (ret)
         {
           _computeError.reset();
-          //UpdateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
         }
         UpdateDependantsState( SUBMESH_COMPUTED ); // send event SUBMESH_COMPUTED
       }
@@ -1611,15 +1630,6 @@ bool SMESH_subMesh::CheckComputeError(SMESH_Algo* theAlgo, const TopoDS_Shape& t
       noErrors = false;
     }
   }
-  if ( !theAlgo->OnlyUnaryInput() && !theShape.IsNull() &&
-       theShape.ShapeType() == TopAbs_COMPOUND )
-  {
-    for (TopoDS_Iterator subIt( theShape ); subIt.More(); subIt.Next()) {
-      SMESH_subMesh* sm = _father->GetSubMesh( subIt.Value() );
-      if ( sm != this && !sm->CheckComputeError( theAlgo ))
-        noErrors = false;
-    }
-  }
   return noErrors;
 }
 
@@ -1916,8 +1926,9 @@ void SMESH_subMesh::SetEventListener(EventListener* listener, EventListenerData*
   map< EventListener*, EventListenerData* >::iterator l_d =
     myEventListeners.find( listener );
   if ( l_d != myEventListeners.end() ) {
-    if ( l_d->second && l_d->second->IsDeletable() )
-      delete l_d->second;
+    EventListenerData* curData = l_d->second;
+    if ( curData && curData != data && curData->IsDeletable() )
+      delete curData;
     l_d->second = data;
   }
   else 
@@ -2018,13 +2029,17 @@ void SMESH_subMeshEventListener::ProcessEvent(const int          event,
        eventType == SMESH_subMesh::COMPUTE_EVENT)
   {
     ASSERT( data->mySubMeshes.front() != subMesh );
+    list<SMESH_subMesh*>::iterator smIt = data->mySubMeshes.begin();
+    list<SMESH_subMesh*>::iterator smEnd = data->mySubMeshes.end();
     switch ( event ) {
     case SMESH_subMesh::CLEAN:
-      data->mySubMeshes.front()->ComputeStateEngine( event );
+      for ( ; smIt != smEnd; ++ smIt)
+        (*smIt)->ComputeStateEngine( event );
       break;
     case SMESH_subMesh::COMPUTE:
       if ( subMesh->GetComputeState() == SMESH_subMesh::COMPUTE_OK )
-        data->mySubMeshes.front()->ComputeStateEngine( SMESH_subMesh::SUBMESH_COMPUTED );
+        for ( ; smIt != smEnd; ++ smIt)
+          (*smIt)->ComputeStateEngine( SMESH_subMesh::SUBMESH_COMPUTED );
       break;
     default:;
     }