<commit_before>// Copyright (C) 2007-2013  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
//
// 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.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// 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.salome-platform.org/ or email : <EMAIL>
//

//  SMESH SMESHDS : management of mesh data and SMESH document
//  File   : SMESH_SubMesh.cxx
//  Author : <NAME>, OCC
//  Module : SMESH
//  $Header: 
//
#include "SMESHDS_SubMesh.hxx"
#include "SMESHDS_Mesh.hxx"

#include "utilities.h"
#include "SMDS_SetIterator.hxx"
#include <iostream>
#include <cassert>

using namespace std;


//================================================================================
/*!
 * \brief Constructor
 */
//================================================================================

SMESHDS_SubMesh::SMESHDS_SubMesh(SMESHDS_Mesh *parent, int index)
{
  myParent = parent;
  myElements.clear();
  myNodes.clear();
  myIndex = index;
  myUnusedIdNodes = 0;
  myUnusedIdElements = 0;
}

//================================================================================
/*!
 * \brief Destructor
 */
//================================================================================

SMESHDS_SubMesh::~SMESHDS_SubMesh()
{
}

//=======================================================================
//function : AddElement
//purpose  : 
//=======================================================================
void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME)
{
  if (!IsComplexSubmesh())
    {
      if ( ME->GetType() == SMDSAbs_Node )
      {
        AddNode( static_cast< const SMDS_MeshNode* >( ME ));
        return;
      }
      //MESSAGE("in " << myIndex << " AddElement "<< ME->GetID());
      int oldShapeId = ME->getshapeId();
      if ( oldShapeId > 0 )
        {
          if (oldShapeId != myIndex)
            {
              MESSAGE("add element in subshape already belonging to another subshape "
                << ME->GetID() << " " << oldShapeId << " " << myIndex);
              throw SALOME_Exception(LOCALIZED("add element in subshape already belonging to a subshape"));
            }
          else
            {
              int idInSubShape = ME->getIdInShape();
              if (idInSubShape >= 0)
                {
                  MESSAGE("add element in subshape already belonging to that subshape "
                      << ME->GetID() << " " << oldShapeId << " " << idInSubShape);
                  // check if ok: do nothing if ok
                  if (idInSubShape >= myElements.size())
                    {
                      MESSAGE("out of bounds " << idInSubShape << " " << myElements.size());
                      throw SALOME_Exception(LOCALIZED("out of bounds"));
                    }
                  if (ME != myElements[idInSubShape])
                    {
                      MESSAGE("not the same element");
                      throw SALOME_Exception(LOCALIZED("not the same element"));
                    }
                  MESSAGE("already done, OK, nothing to do");
                  return;
                }
            }
        }

      SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME);
      elem->setShapeId(myIndex);
      elem->setIdInShape(myElements.size());
      myElements.push_back(ME);
    }
}

//=======================================================================
//function : RemoveElement
//purpose  : 
//=======================================================================
bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME, bool isElemDeleted)
{
  if (!ME)
    {
      MESSAGE("-----------------> Remove Null Element " << isElemDeleted);
      return false;
    }
  //MESSAGE("-----------------> RemoveElement "<< ME->GetID() << " " << isElemDeleted);
  if (!IsComplexSubmesh())
    {
      if ( ME->getshapeId() != myIndex )
        return false;
      int idInSubShape = ME->getIdInShape();
      //MESSAGE("in "<< myIndex << " RemoveElement " << ME->GetID() << " " << idInSubShape << " " << myUnusedIdElements);
      SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME);
      elem->setShapeId(0);
      elem->setIdInShape(-1);
      if ((idInSubShape >= 0) && (idInSubShape < myElements.size()))
        {
          myElements[idInSubShape] = 0; // this vector entry is no more used
          myUnusedIdElements++;
          return true;
        }
      return false;
      //  }
    }
  MESSAGE("Try to remove an element from a complex submesh ");
  return false;
}

//=======================================================================
//function : AddNode
//purpose  : 
//=======================================================================

void SMESHDS_SubMesh::AddNode(const SMDS_MeshNode * N)
{
  if ( !IsComplexSubmesh() )
  {
    int idInSubShape = N->getIdInShape();
    int shapeId = N->getshapeId();
    if ((shapeId > 0) && (idInSubShape >= 0))
    {
      if ( shapeId != myIndex )
        throw SALOME_Exception
          (LOCALIZED("a node being in sub-mesh is added to another sub-mesh"));
      if ( idInSubShape >= NbNodes() || myNodes[ idInSubShape ] != N )
        throw SALOME_Exception
          (LOCALIZED("a node with wrong idInSubShape is re-added to the same sub-mesh"));
      return; // already in
    }
    SMDS_MeshNode* node = (SMDS_MeshNode*)(N);
    node->setShapeId(myIndex);
    node->setIdInShape(myNodes.size());
    myNodes.push_back(N);
  }
}

//=======================================================================
//function : RemoveNode
//purpose  : 
//=======================================================================

bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N, bool isNodeDeleted)
{
  if (!IsComplexSubmesh())
    {
      // if (!isNodeDeleted) // alive node has valid ID and can be found
      // {
      if ( N->getshapeId() != myIndex )
        return false;
      int idInSubShape = N->getIdInShape();
      //int shapeId = N->getshapeId();
      //MESSAGE("in "<< myIndex << " RemoveNode " << shapeId << " " << idInSubShape << " " << N->GetID());
      SMDS_MeshNode* node = (SMDS_MeshNode*) (N);<commit_msg>0022100: EDF 2413 SMESH: Take into account TRIA7<commit_after>// Copyright (C) 2007-2013  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
//
// 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.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// 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.salome-platform.org/ or email : webmaster.<EMAIL>
//

//  SMESH SMESHDS : management of mesh data and SMESH document
//  File   : SMESH_SubMesh.cxx
//  Author : <NAME>, OCC
//  Module : SMESH
//  $Header: 
//
#include "SMESHDS_SubMesh.hxx"
#include "SMESHDS_Mesh.hxx"

#include "utilities.h"
#include "SMDS_SetIterator.hxx"
#include <iostream>
#include <cassert>

using namespace std;


//================================================================================
/*!
 * \brief Constructor
 */
//================================================================================

SMESHDS_SubMesh::SMESHDS_SubMesh(SMESHDS_Mesh *parent, int index)
{
  myParent = parent;
  myElements.clear();
  myNodes.clear();
  myIndex = index;
  myUnusedIdNodes = 0;
  myUnusedIdElements = 0;
}

//================================================================================
/*!
 * \brief Destructor
 */
//================================================================================

SMESHDS_SubMesh::~SMESHDS_SubMesh()
{
}

//=======================================================================
//function : AddElement
//purpose  : 
//=======================================================================
void SMESHDS_SubMesh::AddElement(const SMDS_MeshElement * ME)
{
  if (!IsComplexSubmesh())
    {
      if ( ME->GetType() == SMDSAbs_Node )
      {
        AddNode( static_cast< const SMDS_MeshNode* >( ME ));
        return;
      }
      //MESSAGE("in " << myIndex << " AddElement "<< ME->GetID());
      int oldShapeId = ME->getshapeId();
      if ( oldShapeId > 0 )
        {
          if (oldShapeId != myIndex)
            {
              MESSAGE("add element in subshape already belonging to another subshape "
                << ME->GetID() << " " << oldShapeId << " " << myIndex);
              throw SALOME_Exception(LOCALIZED("add element in subshape already belonging to a subshape"));
            }
          else
            {
              int idInSubShape = ME->getIdInShape();
              if (idInSubShape >= 0)
                {
                  MESSAGE("add element in subshape already belonging to that subshape "
                      << ME->GetID() << " " << oldShapeId << " " << idInSubShape);
                  // check if ok: do nothing if ok
                  if (idInSubShape >= myElements.size())
                    {
                      MESSAGE("out of bounds " << idInSubShape << " " << myElements.size());
                      throw SALOME_Exception(LOCALIZED("out of bounds"));
                    }
                  if (ME != myElements[idInSubShape])
                    {
                      MESSAGE("not the same element");
                      throw SALOME_Exception(LOCALIZED("not the same element"));
                    }
                  MESSAGE("already done, OK, nothing to do");
                  return;
                }
            }
        }

      SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME);
      elem->setShapeId(myIndex);
      elem->setIdInShape(myElements.size());
      myElements.push_back(ME);
    }
}

//=======================================================================
//function : RemoveElement
//purpose  : 
//=======================================================================
bool SMESHDS_SubMesh::RemoveElement(const SMDS_MeshElement * ME, bool isElemDeleted)
{
  if (!ME)
    {
      MESSAGE("-----------------> Remove Null Element " << isElemDeleted);
      return false;
    }
  //MESSAGE("-----------------> RemoveElement "<< ME->GetID() << " " << isElemDeleted);
  if (!IsComplexSubmesh())
    {
      if ( ME->getshapeId() != myIndex )
        return false;
      int idInSubShape = ME->getIdInShape();
      //MESSAGE("in "<< myIndex << " RemoveElement " << ME->GetID() << " " << idInSubShape << " " << myUnusedIdElements);
      SMDS_MeshElement* elem = (SMDS_MeshElement*) (ME);
      elem->setShapeId(0);
      elem->setIdInShape(-1);
      if ((idInSubShape >= 0) && (idInSubShape < myElements.size()))
        {
          myElements[idInSubShape] = 0; // this vector entry is no more used
          myUnusedIdElements++;
          return true;
        }
      return false;
      //  }
    }
  MESSAGE("Try to remove an element from a complex submesh ");
  return false;
}

//=======================================================================
//function : AddNode
//purpose  : 
//=======================================================================

void SMESHDS_SubMesh::AddNode(const SMDS_MeshNode * N)
{
  if ( !IsComplexSubmesh() )
  {
    const int idInSubShape = N->getIdInShape();
    const int shapeId      = N->getshapeId();
    if ((shapeId > 0) && (idInSubShape >= 0))
    {
      if ( shapeId != myIndex )
        throw SALOME_Exception
          (LOCALIZED("a node being in sub-mesh is added to another sub-mesh"));
      if ( idInSubShape >= myNodes.size() || myNodes[ idInSubShape ] != N )
        throw SALOME_Exception
          (LOCALIZED("a node with wrong idInSubShape is re-added to the same sub-mesh"));
      return; // already in
    }
    SMDS_MeshNode* node = (SMDS_MeshNode*)(N);
    node->setShapeId(myIndex);
    node->setIdInShape(myNodes.size());
    myNodes.push_back(N);
  }
}

//=======================================================================
//function : RemoveNode
//purpose  : 
//=======================================================================

bool SMESHDS_SubMesh::RemoveNode(const SMDS_MeshNode * N, bool isNodeDeleted)
{
  if (!IsComplexSubmesh())
    {
      // if (!isNodeDeleted) // alive node has valid ID and can be found
      // {
      if ( N->getshapeId() != myIndex )
        return false;
      int idInSubShape = N->getIdInShape();
      //int shapeId = N->getshapeId();
      //MESSAGE("in "<< myIndex << " RemoveNode " << shapeId << " " << idInSubShape << " " << N->GetID());
      SMDS_MeshNode* node = (SMDS_MeshNode*) (N);
{'fraction_non_alphanumeric': 0.25067523176874223, 'fraction_numerical': 0.007153806847215125, 'mean_word_length': 2.6877523553162854, 'pattern_counts': {'":': 0, '<': 151, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4099616', 'n_tokens_mistral': 4035, 'n_tokens_neox': 3717, 'n_words': 982}