Salome HOME
Temporary rollback ASCII load/save for smesh
[modules/smesh.git] / src / SMESH / SMESH_Mesh.cxx
index 1426f061d433d966ebf04606e5b2e8251a96fc76..8181e062bd6c01c532cdbe1e5fb9bf605d835a38 100644 (file)
@@ -17,7 +17,7 @@
 //  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
@@ -72,6 +72,7 @@ static int MYDEBUG = 0;
 static int MYDEBUG = 0;
 #endif
 
+#define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
 
 //=============================================================================
 /*!
@@ -359,21 +360,17 @@ SMESH_Hypothesis::Hypothesis_Status
 
   // shape 
 
-  int event;
-  if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
-    event = SMESH_subMesh::ADD_HYP;
-  else
-    event = SMESH_subMesh::ADD_ALGO;
+  bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
+  int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
+
   SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
 
   // subShapes
   if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
-      !subMesh->IsApplicableHypotesis( anHyp )) // is added on father
+      anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
   {
-    if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
-      event = SMESH_subMesh::ADD_FATHER_HYP;
-    else
-      event = SMESH_subMesh::ADD_FATHER_ALGO;
+    event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
+
     SMESH_Hypothesis::Hypothesis_Status ret2 =
       subMesh->SubMeshesAlgoStateEngine(event, anHyp);
     if (ret2 > ret)
@@ -444,14 +441,12 @@ SMESH_Hypothesis::Hypothesis_Status
   SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
   int hypType = anHyp->GetType();
   if(MYDEBUG) SCRUTE(hypType);
-  int event;
   
   // shape 
   
-  if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
-    event = SMESH_subMesh::REMOVE_HYP;
-  else
-    event = SMESH_subMesh::REMOVE_ALGO;
+  bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
+  int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
+
   SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
 
   // there may appear concurrent hyps that were covered by the removed hyp
@@ -462,12 +457,10 @@ SMESH_Hypothesis::Hypothesis_Status
 
   // subShapes
   if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
-      !subMesh->IsApplicableHypotesis( anHyp )) // is removed from father
+      anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
   {
-    if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
-      event = SMESH_subMesh::REMOVE_FATHER_HYP;
-    else
-      event = SMESH_subMesh::REMOVE_FATHER_ALGO;
+    event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
+
     SMESH_Hypothesis::Hypothesis_Status ret2 =
       subMesh->SubMeshesAlgoStateEngine(event, anHyp);
     if (ret2 > ret) // more severe
@@ -521,8 +514,13 @@ SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
 }
 
 //=======================================================================
-//function : GetHypothesis
-//purpose  : 
+/*!
+ * \brief Return the hypothesis assigned to the shape
+  * \param aSubShape - the shape to check
+  * \param aFilter - the hypothesis filter
+  * \param andAncestors - flag to check hypos assigned to ancestors of the shape
+  * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
+ */
 //=======================================================================
 
 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape &    aSubShape,
@@ -533,7 +531,7 @@ const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape &    aSubS
     const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
     list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
     for ( ; hyp != hypList.end(); hyp++ ) {
-      const SMESH_Hypothesis * h = static_cast<const SMESH_Hypothesis*>( *hyp );
+      const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
       if ( aFilter.IsOk( h, aSubShape))
         return h;
     }
@@ -546,7 +544,7 @@ const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape &    aSubS
       const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
       list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
       for ( ; hyp != hypList.end(); hyp++ ) {
-        const SMESH_Hypothesis * h = static_cast<const SMESH_Hypothesis*>( *hyp );
+        const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
         if (aFilter.IsOk( h, it.Value() ))
           return h;
       }
@@ -555,11 +553,6 @@ const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape &    aSubS
   return 0;
 }
 
-//=======================================================================
-//function : GetHypotheses
-//purpose  : 
-//=======================================================================
-
 //================================================================================
 /*!
  * \brief Return hypothesis assigned to the shape
@@ -579,21 +572,30 @@ int SMESH_Mesh::GetHypotheses(const TopoDS_Shape &                aSubShape,
   set<string> hypTypes; // to exclude same type hypos from the result list
   int nbHyps = 0;
 
+  // only one main hypothesis is allowed
+  bool mainHypFound = false;
+
   // fill in hypTypes
   list<const SMESHDS_Hypothesis*>::const_iterator hyp;
-  for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ )
+  for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
     if ( hypTypes.insert( (*hyp)->GetName() ).second )
       nbHyps++;
+    if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
+      mainHypFound = true;
+  }
 
   // get hypos from aSubShape
   {
     const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
     for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
-      if ( aFilter.IsOk (static_cast<const SMESH_Hypothesis*>( *hyp ), aSubShape) &&
+      if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
+           ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
            hypTypes.insert( (*hyp)->GetName() ).second )
       {
         aHypList.push_back( *hyp );
         nbHyps++;
+        if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
+          mainHypFound = true;
       }
   }
 
@@ -608,10 +610,14 @@ int SMESH_Mesh::GetHypotheses(const TopoDS_Shape &                aSubShape,
         continue;
       const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
       for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
-        if (aFilter.IsOk( static_cast<const SMESH_Hypothesis*>( *hyp ), it.Value() ) &&
-            hypTypes.insert( (*hyp)->GetName() ).second ) {
+        if (aFilter.IsOk( cSMESH_Hyp( *hyp ), it.Value() ) &&
+            ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
+            hypTypes.insert( (*hyp)->GetName() ).second )
+        {
           aHypList.push_back( *hyp );
           nbHyps++;
+          if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
+            mainHypFound = true;
         }
     }
   }
@@ -812,7 +818,7 @@ void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* t
 {
   Unexpect aCatch(SalomeException);
 
-  const SMESH_Hypothesis* hyp = static_cast<const SMESH_Hypothesis*>(theChangedHyp);
+  const SMESH_Hypothesis* hyp = cSMESH_Hyp(theChangedHyp);
 
   const SMESH_Algo *foundAlgo = 0;
   SMESH_HypoFilter algoKind( SMESH_HypoFilter::IsAlgo() );
@@ -1576,54 +1582,67 @@ const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) c
 //=======================================================================
 ostream& SMESH_Mesh::Dump(ostream& save)
 {
-  save << "========================== Dump contents of mesh ==========================" << endl;
-  save << "1) Total number of nodes:     " << NbNodes() << endl;
-  save << "2) Total number of edges:     " << NbEdges() << endl;
-  save << "3) Total number of faces:     " << NbFaces() << endl;
-  if ( NbFaces() > 0 ) {
-    int nb3 = NbTriangles();
-    int nb4 = NbQuadrangles();
-    save << "3.1.) Number of triangles:    " << nb3 << endl;
-    save << "3.2.) Number of quadrangles:  " << nb4 << endl;
-    if ( nb3 + nb4 !=  NbFaces() ) {
-      map<int,int> myFaceMap;
-      SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
-      while( itFaces->more( ) ) {
-       int nbNodes = itFaces->next()->NbNodes();
-       if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
-         myFaceMap[ nbNodes ] = 0;
-       myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
+  int clause = 0;
+  save << "========================== Dump contents of mesh ==========================" << endl << endl;
+  save << ++clause << ") Total number of nodes:   \t"    << NbNodes() << endl;
+  save << ++clause << ") Total number of edges:   \t"    << NbEdges() << endl;
+  save << ++clause << ") Total number of faces:   \t"    << NbFaces() << endl;
+  save << ++clause << ") Total number of polygons:\t"    << NbPolygons() << endl;
+  save << ++clause << ") Total number of volumes:\t"     << NbVolumes() << endl;
+  save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
+  for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
+  {
+    string orderStr = isQuadratic ? "quadratic" : "linear";
+    ElementOrder order  = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
+
+    save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
+    save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
+    if ( NbFaces(order) > 0 ) {
+      int nb3 = NbTriangles(order);
+      int nb4 = NbQuadrangles(order);
+      save << clause << ".1) Number of " << orderStr << " triangles:  \t" << nb3 << endl;
+      save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
+      if ( nb3 + nb4 !=  NbFaces(order) ) {
+        map<int,int> myFaceMap;
+        SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
+        while( itFaces->more( ) ) {
+          int nbNodes = itFaces->next()->NbNodes();
+          if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
+            myFaceMap[ nbNodes ] = 0;
+          myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
+        }
+        save << clause << ".3) Faces in detail: " << endl;
+        map <int,int>::iterator itF;
+        for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
+          save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
       }
-      save << "3.3.) Faces in detail: " << endl;
-      map <int,int>::iterator itF;
-      for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
-       save << "--> nb nodes: " << itF->first << " - nb elemens: " << itF->second << endl;
     }
-  }
-  save << "4) Total number of volumes:   " << NbVolumes() << endl;
-  if ( NbVolumes() > 0 ) {
-    int nb8 = NbHexas();
-    int nb4 = NbTetras();
-    int nb5 = NbPyramids();
-    int nb6 = NbPrisms();
-    save << "4.1.) Number of hexahedrons:  " << nb8 << endl;
-    save << "4.2.) Number of tetrahedrons: " << nb4 << endl;
-    save << "4.3.) Number of prisms:       " << nb6 << endl;
-    save << "4.4.) Number of pyramides:    " << nb5 << endl;
-    if ( nb8 + nb4 + nb5 + nb6 != NbVolumes() ) {
-      map<int,int> myVolumesMap;
-      SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
-      while( itVolumes->more( ) ) {
-       int nbNodes = itVolumes->next()->NbNodes();
-       if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
-         myVolumesMap[ nbNodes ] = 0;
-       myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
+    save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
+    if ( NbVolumes(order) > 0 ) {
+      int nb8 = NbHexas(order);
+      int nb4 = NbTetras(order);
+      int nb5 = NbPyramids(order);
+      int nb6 = NbPrisms(order);
+      save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
+      save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
+      save << clause << ".3) Number of " << orderStr << " prisms:      \t" << nb6 << endl;
+      save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
+      if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
+        map<int,int> myVolumesMap;
+        SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
+        while( itVolumes->more( ) ) {
+          int nbNodes = itVolumes->next()->NbNodes();
+          if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
+            myVolumesMap[ nbNodes ] = 0;
+          myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
+        }
+        save << clause << ".5) Volumes in detail: " << endl;
+        map <int,int>::iterator itV;
+        for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
+          save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
       }
-      save << "4.5.) Volumes in detail: " << endl;
-      map <int,int>::iterator itV;
-      for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
-       save << "--> nb nodes: " << itV->first << " - nb elemens: " << itV->second << endl;
     }
+    save << endl;
   }
   save << "===========================================================================" << endl;
   return save;