X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_MeshNode.cxx;h=20bce63695892d324ac8962a3daa3706a4ffa370;hp=78a9b70dadc1a072b813357132b3b60422019702;hb=888669652e8ebdff0161e485913c1d3b93e4b5dc;hpb=bef9beee88cac57394b8dc3bc914381c1a2fff83 diff --git a/src/SMDS/SMDS_MeshNode.cxx b/src/SMDS/SMDS_MeshNode.cxx index 78a9b70da..20bce6369 100644 --- a/src/SMDS/SMDS_MeshNode.cxx +++ b/src/SMDS/SMDS_MeshNode.cxx @@ -1,74 +1,69 @@ -using namespace std; -// File: SMDS_MeshNode.cxx -// Created: Wed Jan 23 17:02:11 2002 -// Author: Jean-Michel BOULCOURT -// - - -#include "SMDS_MeshNode.ixx" -#include "SMDS_ListIteratorOfListOfMeshElement.hxx" +// SMESH SMDS : implementaion of Salome mesh data structure +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org + + +#include "SMDS_MeshNode.hxx" #include "SMDS_SpacePosition.hxx" - -static Handle(SMDS_Position)& StaticInstancePosition() -{ - static Handle(SMDS_SpacePosition) staticpos; - if (staticpos.IsNull()) - staticpos = new SMDS_SpacePosition(); - - return staticpos; -} +#include "SMDS_IteratorOfElements.hxx" //======================================================================= //function : SMDS_MeshNode //purpose : //======================================================================= -SMDS_MeshNode::SMDS_MeshNode(const Standard_Integer ID, - const Standard_Real x, const Standard_Real y, const Standard_Real z) : - SMDS_MeshElement(ID,1,SMDSAbs_Node),myPnt(x,y,z),myPosition(StaticInstancePosition()) +SMDS_MeshNode::SMDS_MeshNode(double x, double y, double z): + myX(x), myY(y), myZ(z), + myPosition(SMDS_SpacePosition::originSpacePosition()) { } - //======================================================================= //function : RemoveInverseElement //purpose : //======================================================================= -void SMDS_MeshNode::RemoveInverseElement(const Handle(SMDS_MeshElement)& parent) +void SMDS_MeshNode::RemoveInverseElement(const SMDS_MeshElement * parent) { - - SMDS_ListIteratorOfListOfMeshElement itLstInvCnx(myInverseElements); - - for (;itLstInvCnx.More();itLstInvCnx.Next()) { - Handle(SMDS_MeshElement)& ME = itLstInvCnx.Value(); - if (ME->IsSame(parent)) - myInverseElements.Remove(itLstInvCnx); - if (!itLstInvCnx.More()) - break; - } + myInverseElements.erase(parent); } - //======================================================================= //function : Print //purpose : //======================================================================= -void SMDS_MeshNode::Print(Standard_OStream& OS) const +void SMDS_MeshNode::Print(ostream & OS) const { - OS << "Node <" << myID << "> : X = " << myPnt.X() << " Y = " << myPnt.Y() << " Z = " << myPnt.Z() << endl; + OS << "Node <" << GetID() << "> : X = " << myX << " Y = " + << myY << " Z = " << myZ << endl; } - //======================================================================= //function : SetPosition //purpose : //======================================================================= -void SMDS_MeshNode::SetPosition(const Handle(SMDS_Position)& aPos) +void SMDS_MeshNode::SetPosition(SMDS_Position * aPos) { - myPosition = aPos; + myPosition = aPos; } //======================================================================= @@ -76,8 +71,164 @@ void SMDS_MeshNode::SetPosition(const Handle(SMDS_Position)& aPos) //purpose : //======================================================================= -Handle(SMDS_Position) SMDS_MeshNode::GetPosition() const +SMDS_Position *SMDS_MeshNode::GetPosition() +{ + return myPosition; +} + +const SMDS_Position *SMDS_MeshNode::GetPosition() const +{ + return myPosition; +} +/** +*/ +SMDS_Iterator * SMDS_MeshNode:: + GetInverseElementIterator() const +{ + class SMDS_InverseElementIterator:public SMDS_Iterator + { + const set& mySet; + set::iterator myIterator; + public: + SMDS_InverseElementIterator(const set& s):mySet(s) + { + myIterator=mySet.begin(); + } + + bool more() + { + return myIterator!=mySet.end(); + } + + const SMDS_MeshElement* next() + { + const SMDS_MeshElement* current=*myIterator; + myIterator++; + return current; + } + }; + return new SMDS_InverseElementIterator(myInverseElements); +} + +SMDS_Iterator * SMDS_MeshNode:: + elementsIterator(SMDSAbs_ElementType type) const +{ + // Same as GetInverseElementIterator but the create iterator only return + // wanted type elements. + class MyIterator:public SMDS_Iterator + { + set mySet; + set::iterator myIterator; + public: + MyIterator(SMDSAbs_ElementType type, + const set& s) + { + const SMDS_MeshElement * e; + bool toInsert; + set::iterator it=s.begin(); + while(it!=s.end()) + { + e=*it; + switch(type) + { + case SMDSAbs_Edge: toInsert=true; break; + case SMDSAbs_Face: toInsert=(e->GetType()!=SMDSAbs_Edge); break; + case SMDSAbs_Volume: toInsert=(e->GetType()==SMDSAbs_Volume); break; + } + if(toInsert) mySet.insert(e); + it++; + } + myIterator=mySet.begin(); + } + + bool more() + { + return myIterator!=mySet.end(); + } + + const SMDS_MeshElement* next() + { + const SMDS_MeshElement* current=*myIterator; + myIterator++; + return current; + } + }; + + if(type==SMDSAbs_Node) + return SMDS_MeshElement::elementsIterator(SMDSAbs_Node); + else + return new SMDS_IteratorOfElements(this,type, + new MyIterator(type, myInverseElements)); +} + +int SMDS_MeshNode::NbNodes() const +{ + return 1; +} + +double SMDS_MeshNode::X() const +{ + return myX; +} + +double SMDS_MeshNode::Y() const +{ + return myY; +} + +double SMDS_MeshNode::Z() const +{ + return myZ; +} + +void SMDS_MeshNode::setXYZ(double x, double y, double z) +{ + myX=x; + myY=y; + myZ=z; +} + +SMDSAbs_ElementType SMDS_MeshNode::GetType() const +{ + return SMDSAbs_Node; +} + +//======================================================================= +//function : AddInverseElement +//purpose : +//======================================================================= +void SMDS_MeshNode::AddInverseElement(const SMDS_MeshElement* ME) +{ + myInverseElements.insert(ME); +} + +//======================================================================= +//function : ClearInverseElements +//purpose : +//======================================================================= +void SMDS_MeshNode::ClearInverseElements() +{ + myInverseElements.clear(); +} + +bool SMDS_MeshNode::emptyInverseElements() +{ + return myInverseElements.empty(); +} + +/////////////////////////////////////////////////////////////////////////////// +/// To be used with STL set +/////////////////////////////////////////////////////////////////////////////// +bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2) { - return myPosition; + return e1.GetID()