geom/src/GEOMAlgo/GEOMAlgo_ShapeSet.cxx

178 lines
5.2 KiB
C++
Raw Normal View History

2013-04-01 18:25:01 +06:00
// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
//
2012-08-09 13:58:02 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
2012-08-09 13:58:02 +06:00
// 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.
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// 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.
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// 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
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
2012-08-09 13:58:02 +06:00
// File: GEOMAlgo_ShapeSet.cxx
// Created:
// Author: Peter KURNEV
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
#include <GEOMAlgo_ShapeSet.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_MapIteratorOfMapOfOrientedShape.hxx>
//=======================================================================
2012-08-09 13:58:02 +06:00
//function :
//purpose :
//=======================================================================
GEOMAlgo_ShapeSet::GEOMAlgo_ShapeSet()
{
}
//=======================================================================
//function : Clear
2012-08-09 13:58:02 +06:00
//purpose :
//=======================================================================
void GEOMAlgo_ShapeSet::Clear()
{
myMap.Clear();
myList.Clear();
}
//=======================================================================
//function : Add
2012-08-09 13:58:02 +06:00
//purpose :
//=======================================================================
void GEOMAlgo_ShapeSet::Add(const TopoDS_Shape& theShape)
{
if (myMap.Add(theShape)) {
myList.Append(theShape);
}
}
//=======================================================================
//function : Add
2012-08-09 13:58:02 +06:00
//purpose :
//=======================================================================
void GEOMAlgo_ShapeSet::Add(const TopoDS_Shape& theShape,
2012-08-09 13:58:02 +06:00
const TopAbs_ShapeEnum theType)
{
TopExp_Explorer aExp;
//
aExp.Init(theShape, theType);
for (; aExp.More(); aExp.Next()) {
const TopoDS_Shape& aS=aExp.Current();
if (myMap.Add(aS)) {
myList.Append(aS);
}
}
}
//=======================================================================
//function : Add
2012-08-09 13:58:02 +06:00
//purpose :
//=======================================================================
void GEOMAlgo_ShapeSet::Add(const TopTools_ListOfShape& theLS)
{
TopTools_ListIteratorOfListOfShape aIt;
//
aIt.Initialize(theLS);
for (; aIt.More(); aIt.Next()) {
const TopoDS_Shape& aS=aIt.Value();
if (myMap.Add(aS)) {
myList.Append(aS);
}
}
}
//=======================================================================
2012-08-09 13:58:02 +06:00
//function :GetSet
//purpose :
//=======================================================================
const TopTools_ListOfShape& GEOMAlgo_ShapeSet::GetSet()const
{
return myList;
}
//=======================================================================
//function : Contains
2012-08-09 13:58:02 +06:00
//purpose :
//=======================================================================
Standard_Boolean GEOMAlgo_ShapeSet::Contains(const GEOMAlgo_ShapeSet& theOther)const
{
Standard_Boolean bRet;
TopAbs_Orientation aOr;
TopTools_ListIteratorOfListOfShape aIt;
//
bRet=Standard_True;
const TopTools_ListOfShape& aLS=theOther.GetSet();
aIt.Initialize(aLS);
for (; aIt.More(); aIt.Next()) {
const TopoDS_Shape& aF=aIt.Value();
aOr=aF.Orientation();
if (aOr==TopAbs_FORWARD || aOr==TopAbs_REVERSED) {
bRet=myMap.Contains(aF);
if (!bRet) {
2012-08-09 13:58:02 +06:00
break;
}
}
}
return bRet;
}
//=======================================================================
//function : Subtract
2012-08-09 13:58:02 +06:00
//purpose :
//=======================================================================
void GEOMAlgo_ShapeSet::Subtract(const GEOMAlgo_ShapeSet& theOther)
{
TopTools_ListIteratorOfListOfShape aIt;
TopTools_ListOfShape aLS;
//
myMap.Clear();
aIt.Initialize(myList);
for (; aIt.More(); aIt.Next()) {
const TopoDS_Shape& aS=aIt.Value();
if (!theOther.myMap.Contains(aS)) {
if(myMap.Add(aS)){
2012-08-09 13:58:02 +06:00
aLS.Append(aS);
}
}
}
//
myList=aLS;
}
2012-08-09 13:58:02 +06:00
//modified by NIZNHY-PKV Wed Oct 28 13:51:36 2010f
//=======================================================================
//function : IsEqual
//purpose :
//=======================================================================
Standard_Boolean GEOMAlgo_ShapeSet::IsEqual(const GEOMAlgo_ShapeSet& theOther)const
{
Standard_Boolean bRet;
Standard_Integer aNb1, aNb2;
TopTools_ListIteratorOfListOfShape aIt;
//
bRet=Standard_True;
aNb1=myList.Extent();
const TopTools_ListOfShape& aLS2=theOther.GetSet();
aNb2=aLS2.Extent();
if (aNb1!=aNb2) {
return !bRet;
}
//
aIt.Initialize(myList);
for (; aIt.More(); aIt.Next()) {
const TopoDS_Shape& aS=aIt.Value();
if(!theOther.myMap.Contains(aS)) {
bRet=!bRet;
break;
}
}
return bRet;
}
//modified by NIZNHY-PKV Wed Oct 28 13:51:38 2010t