Salome HOME
Fix ID shift for testing export
[modules/smesh.git] / src / SMDS / SMDS_ElementFactory.cxx
index 1c9a3cbe3ebe8c4800567b7dff1d33a640c22812..162843db8ab09695ff5670496fc05598d2b15761 100644 (file)
@@ -113,6 +113,7 @@ smIdType SMDS_ElementFactory::GetFreeID()
   if ( myChunksWithUnused.empty() )
   {
     smIdType id0 = myChunks.size() * theChunkSize + 1;
+    id0 += idShift;
     myChunks.push_back( new SMDS_ElementChunk( this, id0 ));
   }
   SMDS_ElementChunk * chunk = (*myChunksWithUnused.begin());
@@ -169,20 +170,21 @@ smIdType SMDS_ElementFactory::GetMinID()
  */
 //================================================================================
 
-SMDS_MeshElement* SMDS_ElementFactory::NewElement( const smIdType id )
+SMDS_MeshElement* SMDS_ElementFactory::NewElement( const smIdType ID )
 {
+  smIdType id = ID > idShift ? ID - idShift : ID;
   smIdType iChunk = ( id - 1 ) / theChunkSize;
   smIdType index  = ( id - 1 ) % theChunkSize;
   while ((smIdType) myChunks.size() <= iChunk )
   {
-    smIdType id0 = myChunks.size() * theChunkSize + 1;
+    smIdType id0 = myChunks.size() * theChunkSize + 1 + idShift;
     myChunks.push_back( new SMDS_ElementChunk( this, id0 ));
   }
-  SMDS_MeshElement* e = myChunks[iChunk].Element( index );
+  SMDS_MeshElement* e = myChunks[iChunk].Element( FromIdType<int>(index) );
   if ( !e->IsNull() )
     return 0; // element with given ID already exists
 
-  myChunks[iChunk].UseElement( index );
+  myChunks[iChunk].UseElement( FromIdType<int>(index) );
   ++myNbUsedElements;
 
   e->myHolder = & myChunks[iChunk];
@@ -200,15 +202,16 @@ SMDS_MeshElement* SMDS_ElementFactory::NewElement( const smIdType id )
  */
 //================================================================================
 
-const SMDS_MeshElement* SMDS_ElementFactory::FindElement( const smIdType id ) const
+const SMDS_MeshElement* SMDS_ElementFactory::FindElement( const smIdType ID ) const
 {
+  smIdType id = ID -idShift;
   if ( id > 0 )
   {
     smIdType iChunk = ( id - 1 ) / theChunkSize;
     smIdType index  = ( id - 1 ) % theChunkSize;
     if ( iChunk < (smIdType) myChunks.size() )
     {
-      const SMDS_MeshElement* e = myChunks[iChunk].Element( index );
+      const SMDS_MeshElement* e = myChunks[iChunk].Element( FromIdType<int>(index) );
       return e->IsNull() ? 0 : e;
     }
   }
@@ -223,11 +226,12 @@ const SMDS_MeshElement* SMDS_ElementFactory::FindElement( const smIdType id ) co
  */
 //================================================================================
 
-smIdType SMDS_ElementFactory::FromVtkToSmds( vtkIdType vtkID )
+smIdType SMDS_ElementFactory::FromVtkToSmds( vtkIdType VTKID )
 {
+  vtkIdType vtkID = VTKID;
   if ( vtkID >= 0 && vtkID < (vtkIdType)mySmdsIDs.size() )
     return mySmdsIDs[vtkID] + 1;
-  return vtkID + 1;
+  return vtkID + 1 + idShift;
 }
 
 //================================================================================
@@ -244,7 +248,7 @@ void SMDS_ElementFactory::Free( const SMDS_MeshElement* e )
 
   if ( !myVtkIDs.empty() )
   {
-    size_t    id = e->GetID() - 1;
+    size_t    id = e->GetID() - 1 - idShift;
     size_t vtkID = e->GetVtkID();
     if ( id < myVtkIDs.size() )
       myVtkIDs[ id ] = -1;
@@ -314,7 +318,7 @@ void SMDS_ElementFactory::Compact( std::vector<smIdType>& theVtkIDsNewToOld )
         const SMDS_MeshElement* newElem = FindElement( newVtkID );
         if ( !newElem )
           newElem = NewElement( newVtkID );
-        if ( smIdType shapeID = oldElem->GetShapeID() )
+        if ( int shapeID = oldElem->GetShapeID() )
           const_cast< SMDS_MeshElement* >( newElem )->setShapeID( shapeID );
         if ( oldID > newNbCells )
           Free( oldElem );
@@ -616,16 +620,18 @@ smIdType SMDS_ElementChunk::GetID( const SMDS_MeshElement* e ) const
 
 void SMDS_ElementChunk::SetVTKID( const SMDS_MeshElement* e, const vtkIdType vtkID )
 {
-  if ( e->GetID() - 1 != vtkID )
+  smIdType id = e->GetID() - idShift;
+  if ( id - 1 != vtkID )
   {
-    if ((smIdType) myFactory->myVtkIDs.size() <= e->GetID() - 1 )
+    if ((smIdType) myFactory->myVtkIDs.size() <= id - 1 )
     {
-      size_t i = myFactory->myVtkIDs.size();
-      myFactory->myVtkIDs.resize( e->GetID() + 100 );
-      for ( ; i < myFactory->myVtkIDs.size(); ++i )
-        myFactory->myVtkIDs[i] = FromIdType<vtkIdType>(i);
+      vtkIdType i = (vtkIdType) myFactory->myVtkIDs.size();
+      myFactory->myVtkIDs.resize( id + 100 );
+      vtkIdType newSize = (vtkIdType) myFactory->myVtkIDs.size();
+      for ( ; i < newSize; ++i )
+        myFactory->myVtkIDs[i] = i;
     }
-    myFactory->myVtkIDs[ e->GetID() - 1 ] = vtkID;
+    myFactory->myVtkIDs[ id - 1 ] = vtkID;
 
     if ((vtkIdType) myFactory->mySmdsIDs.size() <= vtkID )
     {
@@ -646,7 +652,7 @@ void SMDS_ElementChunk::SetVTKID( const SMDS_MeshElement* e, const vtkIdType vtk
 
 vtkIdType SMDS_ElementChunk::GetVtkID( const SMDS_MeshElement* e ) const
 {
-  vtkIdType dfltVtkID = e->GetID() - 1;
+  vtkIdType dfltVtkID = FromIdType<vtkIdType>(e->GetID() - 1) - idShift;
   return ( dfltVtkID < (vtkIdType)myFactory->myVtkIDs.size() ) ? myFactory->myVtkIDs[ dfltVtkID ] : dfltVtkID;
 }