Salome HOME
Update translation files from Crowdin
[modules/smesh.git] / src / SMDS / SMDS_Mesh.cxx
index 9f45f3a044cf2c9255ab18f490afd368be4578f5..29f119e5089058bf8615f3d2e30fec1750409581 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -53,6 +53,7 @@
 #include <map>
 #include <iostream>
 #include <fstream>
+#include <iterator>
 using namespace std;
 
 #ifndef WIN32
@@ -124,24 +125,17 @@ int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
 /// Create a new mesh object
 ///////////////////////////////////////////////////////////////////////////////
 SMDS_Mesh::SMDS_Mesh()
-        :myParent(NULL),
-         myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
-         myElementIDFactory(new SMDS_MeshElementIDFactory()),
-         myHasConstructionEdges(false), myHasConstructionFaces(false),
-         myHasInverseElements(true),
-         myNodeMin(0), myNodeMax(0),
-         myNodePool(0), myEdgePool(0), myFacePool(0), myVolumePool(0),myBallPool(0),
-         myModified(false), myModifTime(0), myCompactTime(0),
-         xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0)
+  :myParent(NULL),
+   myNodeIDFactory(new SMDS_MeshNodeIDFactory()),
+   myElementIDFactory(new SMDS_MeshElementIDFactory()),
+   myHasConstructionEdges(false), myHasConstructionFaces(false),
+   myHasInverseElements(true),
+   myNodeMin(0), myNodeMax(0),
+   myNodePool(0), myEdgePool(0), myFacePool(0), myVolumePool(0),myBallPool(0),
+   myModified(false), myModifTime(0), myCompactTime(0),
+   xmin(0), xmax(0), ymin(0), ymax(0), zmin(0), zmax(0)
 {
   myMeshId = _meshList.size();         // --- index of the mesh to push back in the vector
-  MESSAGE("myMeshId=" << myMeshId);
-  MESSAGE("sizeof(SMDS_MeshElement) " << sizeof(SMDS_MeshElement) );
-  MESSAGE("sizeof(SMDS_MeshNode) " << sizeof(SMDS_MeshNode) );
-  MESSAGE("sizeof(SMDS_MeshCell) " << sizeof(SMDS_MeshCell) );
-  MESSAGE("sizeof(SMDS_VtkVolume) " << sizeof(SMDS_VtkVolume) );
-  MESSAGE("sizeof(SMDS_Position) " << sizeof(SMDS_Position) );
-  MESSAGE("sizeof(SMDS_SpacePosition) " << sizeof(SMDS_SpacePosition) );
   myNodeIDFactory->SetMesh(this);
   myElementIDFactory->SetMesh(this);
   _meshList.push_back(this);
@@ -1597,6 +1591,9 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceFromVtkIdsWithID(const std::vector<vtkIdType>&
     case VTK_BIQUADRATIC_QUAD:
       myInfo.myNbBiQuadQuadrangles++;
       break;
+    case VTK_BIQUADRATIC_TRIANGLE:
+      myInfo.myNbBiQuadTriangles++;
+      break;
     case VTK_POLYGON:
       myInfo.myNbPolygons++;
       break;
@@ -1638,6 +1635,17 @@ bool SMDS_Mesh::registerElement(int ID, SMDS_MeshElement* element)
   return true;
 }
 
+//=======================================================================
+//function : MoveNode
+//purpose  : 
+//=======================================================================
+
+void SMDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
+{
+  SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
+  node->setXYZ(x,y,z);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 /// Return the node whose SMDS ID is 'ID'.
 ///////////////////////////////////////////////////////////////////////////////
@@ -2446,7 +2454,7 @@ const SMDS_MeshElement* SMDS_Mesh::FindElement (const vector<const SMDS_MeshNode
             e = 0;
         }
         if ( e )
-          return static_cast<const SMDS_MeshFace *> (e);
+          return e;
       }
     }
   }
@@ -2929,6 +2937,11 @@ SMDS_ElemIteratorPtr SMDS_Mesh::elementGeomIterator(SMDSAbs_GeometryType type) c
 
 SMDS_ElemIteratorPtr SMDS_Mesh::elementEntityIterator(SMDSAbs_EntityType type) const
 {
+  if ( type == SMDSEntity_Node )
+  {
+    typedef ElemVecIterator<const SMDS_MeshElement*, SMDS_MeshNode*> TIterator;
+    return SMDS_ElemIteratorPtr( new TIterator(myNodes));
+  }
   // naturally always sorted by ID
   typedef ElemVecIterator
     < const SMDS_MeshElement*, SMDS_MeshCell*, SMDS_MeshElement::EntityFilter > TIterator;
@@ -3356,6 +3369,7 @@ void SMDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elem)
       myNodes[elemId] = 0;
       myInfo.myNbNodes--;
       ((SMDS_MeshNode*) n)->SetPosition(SMDS_SpacePosition::originSpacePosition());
+      ((SMDS_MeshNode*) n)->SMDS_MeshElement::init( -1, -1, -1 ); // avoid reuse
       myNodePool->destroy(static_cast<SMDS_MeshNode*>(todest));
       myNodeIDFactory->ReleaseID(elemId, vtkId);
     }
@@ -3690,6 +3704,94 @@ SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
 }
 
 
+//=======================================================================
+//function : AddFace
+//purpose  :
+//=======================================================================
+SMDS_MeshFace* SMDS_Mesh::AddFace(const SMDS_MeshNode * n1,
+                                  const SMDS_MeshNode * n2,
+                                  const SMDS_MeshNode * n3,
+                                  const SMDS_MeshNode * n12,
+                                  const SMDS_MeshNode * n23,
+                                  const SMDS_MeshNode * n31,
+                                  const SMDS_MeshNode * nCenter)
+{
+  return SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,nCenter,
+                                  myElementIDFactory->GetFreeID());
+}
+
+//=======================================================================
+//function : AddFaceWithID
+//purpose  :
+//=======================================================================
+SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
+                                        int n12,int n23,int n31, int nCenter, int ID)
+{
+  return SMDS_Mesh::AddFaceWithID
+    ((SMDS_MeshNode *)myNodeIDFactory->MeshElement(n1) ,
+     (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n2) ,
+     (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n3) ,
+     (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n12),
+     (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n23),
+     (SMDS_MeshNode *)myNodeIDFactory->MeshElement(n31),
+     (SMDS_MeshNode *)myNodeIDFactory->MeshElement(nCenter),
+     ID);
+}
+
+//=======================================================================
+//function : AddFaceWithID
+//purpose  :
+//=======================================================================
+SMDS_MeshFace* SMDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
+                                        const SMDS_MeshNode * n2,
+                                        const SMDS_MeshNode * n3,
+                                        const SMDS_MeshNode * n12,
+                                        const SMDS_MeshNode * n23,
+                                        const SMDS_MeshNode * n31,
+                                        const SMDS_MeshNode * nCenter,
+                                        int ID)
+{
+  if ( !n1 || !n2 || !n3 || !n12 || !n23 || !n31 || !nCenter) return 0;
+  if(hasConstructionEdges()) {
+    // creation quadratic edges - not implemented
+    return 0;
+  }
+  else
+  {
+    // --- retrieve nodes ID
+    vector<vtkIdType> nodeIds;
+    nodeIds.clear();
+    nodeIds.push_back(n1->getVtkId());
+    nodeIds.push_back(n2->getVtkId());
+    nodeIds.push_back(n3->getVtkId());
+    nodeIds.push_back(n12->getVtkId());
+    nodeIds.push_back(n23->getVtkId());
+    nodeIds.push_back(n31->getVtkId());
+    nodeIds.push_back(nCenter->getVtkId());
+
+    SMDS_MeshFace * face = 0;
+    SMDS_VtkFace *facevtk = myFacePool->getNew();
+    facevtk->init(nodeIds, this);
+    if (!this->registerElement(ID,facevtk))
+      {
+        this->myGrid->GetCellTypesArray()->SetValue(facevtk->getVtkId(), VTK_EMPTY_CELL);
+        myFacePool->destroy(facevtk);
+        return 0;
+      }
+    face = facevtk;
+    adjustmyCellsCapacity(ID);
+    myCells[ID] = face;
+    myInfo.myNbBiQuadTriangles++;
+
+//    if (!registerElement(ID, face)) {
+//      RemoveElement(face, false);
+//      face = NULL;
+//    }
+    return face;
+  }
+}
+
+
 //=======================================================================
 //function : AddFace
 //purpose  :