450 lines
8.3 KiB
C++
450 lines
8.3 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TGObjectList.cpp
|
|
// = Version : ver2.0
|
|
// = Author : xlc
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: ÀàµÄ¶¨Òå
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TGObjectList.h"
|
|
#include "TPGeCurve3D.h"
|
|
#include "TGSolid.h"
|
|
#include "TPGeFace3D.h"
|
|
#include "TGRegion2D.h"
|
|
#include "TPGeCurve2D.h"
|
|
#include "TGPoint2D.h"
|
|
#include "TGRegionEx2D.h"
|
|
#include "TPGeCurveMesh.h"
|
|
#include "TPDList.h"
|
|
|
|
TGObjectList::TGObjectList()
|
|
{
|
|
|
|
}
|
|
|
|
TGObjectList::TGObjectList(const TGObject&obj)
|
|
{
|
|
AddTail(obj.Clone());
|
|
}
|
|
|
|
TGObjectList::TGObjectList(const TGObjectList&oList)
|
|
{
|
|
for (TGObject*const*pCur = oList.GetFirst();pCur != NULL;pCur = oList.GetNext(pCur))
|
|
{
|
|
AddTail((*pCur)->Clone());
|
|
}
|
|
}
|
|
|
|
TGObjectList::~TGObjectList()
|
|
{
|
|
|
|
}
|
|
TGObject2D& TGObjectList::GetCurObject2D()
|
|
{
|
|
return (TGObject2D&)GetCurPData();
|
|
}
|
|
|
|
TPGeCurve2D& TGObjectList::GetCurCurve2D()
|
|
{
|
|
return (TPGeCurve2D&)GetCurPData();
|
|
}
|
|
|
|
TPGeCurve2D& TGObjectList::GetCurCurveSeg2D()
|
|
{
|
|
return (TPGeCurve2D&)GetCurPData();
|
|
}
|
|
|
|
TGRegion2D& TGObjectList::GetCurRegion2D()
|
|
{
|
|
return (TGRegion2D&)GetCurPData();
|
|
}
|
|
|
|
TGObject3D& TGObjectList::GetCurObject3D()
|
|
{
|
|
return (TGObject3D&)GetCurPData();
|
|
}
|
|
|
|
TPGeCurve3D& TGObjectList::GetCurCurve3D()
|
|
{
|
|
return (TPGeCurve3D&)GetCurPData();
|
|
}
|
|
|
|
TPGeFace3D& TGObjectList::GetCurFace3D()
|
|
{
|
|
return (TPGeFace3D&)GetCurPData();
|
|
}
|
|
|
|
TGSolid& TGObjectList::GetCurSolid()
|
|
{
|
|
return (TGSolid&)GetCurPData();
|
|
}
|
|
|
|
void TGObjectList::TransformBy(const TGMatrix&mat)
|
|
{
|
|
for (MoveToFirst();!IsOut();MoveToNext())
|
|
{
|
|
GetCurData()->TransformBy(mat);
|
|
}
|
|
}
|
|
|
|
void TGObjectList::ExplodeEx()
|
|
{
|
|
TGObjectList buf,buf1;
|
|
for (MoveToFirst();!IsOut();MoveToNext())
|
|
{
|
|
if (GetCurData()->Explode(buf))
|
|
{
|
|
DelCur();
|
|
buf.ExplodeEx();
|
|
buf1.Conbine(buf);
|
|
}
|
|
}
|
|
Conbine(buf1);
|
|
}
|
|
|
|
void TGObjectList::CutBy(const TPGeCurve2D&curve,TGObjectList &left,TGObjectList&right,TGObjectList&mid) const
|
|
{
|
|
for (TGObject*const*pCur = GetFirst();pCur != NULL;pCur = GetNext(pCur))
|
|
{
|
|
curve.Cut(**pCur,left,right,mid);
|
|
}
|
|
}
|
|
|
|
void TGObjectList::ClipBy(const TGRegion2D& face,TGObjectList&in,TGObjectList&out,TGObjectList&mid) const
|
|
{
|
|
for (TGObject*const*pCur = GetFirst();pCur != NULL;pCur = GetNext(pCur))
|
|
{
|
|
face.Clip(**pCur,in,out,mid);
|
|
}
|
|
}
|
|
|
|
void TGObjectList::Intersect(const TGObject&obj,TGObjectList&res) const
|
|
{
|
|
for (TGObject*const*pCur = GetFirst(); pCur != NULL; pCur = GetNext(pCur))
|
|
{
|
|
obj.Intersect(**pCur,res);
|
|
}
|
|
}
|
|
|
|
bool TGObjectList::GetExtend2D(TPGeExtend2D&ext) const
|
|
{
|
|
TGObject*const*pCur = GetFirst();
|
|
if (pCur == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!(**pCur).GetExtend2D(ext))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
TPGeExtend2D ext1;
|
|
for (pCur = GetNext(pCur); pCur != NULL; pCur = GetNext(pCur))
|
|
{
|
|
if ((**pCur).GetExtend2D(ext1))
|
|
{
|
|
ext += ext1;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TGObjectList::GetExtend3D(TPGeExtend3D&ext) const
|
|
{
|
|
TGObject*const*pCur = GetFirst();
|
|
if (pCur == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!(**pCur).GetExtend3D(ext))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
TPGeExtend3D ext1;
|
|
for (pCur = GetNext(pCur); pCur != NULL; pCur = GetNext(pCur))
|
|
{
|
|
if ((**pCur).GetExtend3D(ext1))
|
|
{
|
|
ext += ext1;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TGObjectList::Convert2D()
|
|
{
|
|
for (MoveToFirst();!IsOut();MoveToNext())
|
|
if (IS_CLASS(GetCurData(),TGObject3D))
|
|
{
|
|
TGObject3D&obj = GetCurObject3D();
|
|
TGObject2D*pObj2d = obj.Convert2D();
|
|
if (pObj2d == NULL)
|
|
{
|
|
DelCur();
|
|
}
|
|
else
|
|
{
|
|
SetCurData(pObj2d);
|
|
delete &obj;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TGObjectList::Convert3D()
|
|
{
|
|
for (MoveToFirst();!IsOut();MoveToNext())
|
|
{
|
|
if (IS_CLASS(GetCurData(),TGObject2D))
|
|
{
|
|
TGObject2D&obj = GetCurObject2D();
|
|
SetCurData(obj.Convert3D());
|
|
delete &obj;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool TGObjectList::CheckIn(TGObject *pObj)
|
|
{
|
|
for (MoveToFirst();!IsOut();MoveToNext())
|
|
{
|
|
if (GetCurPData().IsInclude(*pObj))
|
|
{
|
|
return false;
|
|
}
|
|
if (pObj->IsInclude(GetCurPData()))
|
|
{
|
|
DelCur();
|
|
}
|
|
}
|
|
AddTail(pObj);
|
|
return true;
|
|
}
|
|
|
|
void TGObjectList::CheckIn(TGObjectList&oList)
|
|
{
|
|
for (oList.MoveToFirst();!oList.IsOut();oList.MoveToNext())
|
|
{
|
|
if (CheckIn(oList.GetCurData()))
|
|
{
|
|
oList.FetchCur();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TGObjectList::RemoveSubObj()
|
|
{
|
|
TGObjectList oList;
|
|
oList.Conbine(*this);
|
|
CheckIn(oList);
|
|
}
|
|
|
|
void TGObjectList::RemoveDup()
|
|
{
|
|
}
|
|
|
|
void TGObjectList::InterBreakCurve2D(TGObjectList&res)
|
|
{
|
|
TArray<TDualPtrList<double> > allPa(GetLength());
|
|
for (long i = GetLastIndex();i>=0;i--)
|
|
{
|
|
TPGeCurve2D *pCurve1 = (TPGeCurve2D*)(*this)[i];
|
|
TPGeExtend2D cutExt;
|
|
if (pCurve1->GetExtend2D(cutExt))
|
|
{
|
|
for (long j = 0;j<i;j++)
|
|
{
|
|
TPGeCurve2D *pCurve2 = (TPGeCurve2D*)(*this)[j];
|
|
if (!pCurve2->IsExtendInter(cutExt))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
TGObjectList buf;
|
|
pCurve1->Intersect(*pCurve2,buf);
|
|
for (buf.MoveToFirst();!buf.IsOut();buf.MoveToNext())
|
|
{
|
|
if (IS_TYPE(buf.GetCurData(),TGPoint2D))
|
|
{
|
|
const TGPoint2D& pt = (const TGPoint2D&)buf.GetCurPData();
|
|
double pa1,pa2;
|
|
pCurve1->Pt2Pa(pt,pa1);
|
|
pCurve2->Pt2Pa(pt,pa2);
|
|
allPa[i].SortIn(pa1);
|
|
allPa[j].SortIn(pa2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (long j = 0;j<i;j++)
|
|
{
|
|
TPGeCurve2D *pCurve2 = (TPGeCurve2D*)(*this)[j];
|
|
TGObjectList buf;
|
|
pCurve1->Intersect(*pCurve2,buf);
|
|
for (buf.MoveToFirst();!buf.IsOut();buf.MoveToNext())
|
|
{
|
|
if (IS_TYPE(buf.GetCurData(),TGPoint2D))
|
|
{
|
|
const TGPoint2D& pt = (const TGPoint2D&)buf.GetCurPData();
|
|
double pa1,pa2;
|
|
pCurve1->Pt2Pa(pt,pa1);
|
|
pCurve2->Pt2Pa(pt,pa2);
|
|
allPa[i].SortIn(pa1);
|
|
allPa[j].SortIn(pa2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!allPa[i].IsEmpty())
|
|
{
|
|
pCurve1->Split(allPa[i],res);
|
|
allPa[i].Clear();
|
|
}
|
|
else
|
|
{
|
|
res<<pCurve1->Clone();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TGObjectList::Union(const TGRegion2D&face)
|
|
{
|
|
TGRegion2D *pFace = pFace = (TGRegion2D*)face.Clone();
|
|
|
|
for (MoveToFirst();!IsOut();)
|
|
{
|
|
TGRegion2D* pFace1 = pFace->Union(GetCurRegion2D());
|
|
if (pFace1 != NULL)
|
|
{
|
|
DelCur();
|
|
delete pFace;
|
|
pFace = pFace1;
|
|
MoveToFirst();
|
|
}
|
|
else
|
|
{
|
|
MoveToNext();
|
|
}
|
|
}
|
|
AddTail(pFace);
|
|
}
|
|
|
|
void TGObjectList::Union()
|
|
{
|
|
TGObjectList curveList;
|
|
for (MoveToFirst();!IsOut();MoveToNext())
|
|
{
|
|
TGRegion2D& reg = GetCurRegion2D();
|
|
for (long i = 0;i<reg.GetBoundaryNum();i++)
|
|
{
|
|
TPGeCurve2D *pCurve = reg.GetBoundary(i);
|
|
if (pCurve != NULL)
|
|
{
|
|
curveList<<pCurve->Clone();
|
|
}
|
|
}
|
|
}
|
|
Clear();
|
|
|
|
TGObjectList curveList1;
|
|
curveList.InterBreakCurve2D(curveList1);
|
|
curveList.Clear();
|
|
|
|
TGObjectList lstRegion,lstHole;
|
|
|
|
for (curveList1.MoveToFirst();!curveList1.IsOut();curveList1.MoveToNext())
|
|
{
|
|
TPGeCurve2D &curve = curveList1.GetCurCurve2D();
|
|
if (curve.IsClosed())
|
|
{
|
|
if (!curve.IsClockwise())
|
|
{
|
|
lstRegion << new TGRegionEx2D(curve,false);
|
|
}
|
|
else
|
|
{
|
|
lstHole << new TGRegionEx2D(curve,true);
|
|
}
|
|
|
|
curveList1.DelCur();
|
|
}
|
|
}
|
|
|
|
TPGeCurveMesh mesh(curveList1);
|
|
TPDList<TPGeCurveMesh> lstMesh;
|
|
mesh.Explode(lstMesh);
|
|
for (lstMesh.MoveToFirst();!lstMesh.IsOut();lstMesh.MoveToNext())
|
|
{
|
|
TPGeCurveMesh *pMesh = lstMesh.GetCurData();
|
|
pMesh->FindAllSDMesh();
|
|
pMesh->CreateRegion(lstRegion,lstHole);
|
|
}
|
|
|
|
for (lstRegion.MoveToFirst();!lstRegion.IsOut();lstRegion.MoveToNext())
|
|
{
|
|
Union(lstRegion.GetCurRegion2D());
|
|
}
|
|
|
|
for (lstHole.MoveToFirst();!lstHole.IsOut();lstHole.MoveToNext())
|
|
{
|
|
TGObjectList buf;
|
|
SubtractBy(lstHole.GetCurRegion2D(),buf);
|
|
Clear();
|
|
Conbine(buf);
|
|
}
|
|
}
|
|
|
|
void TGObjectList::SubtractBy(const TGRegion2D&face,TGObjectList&res) const
|
|
{
|
|
TGObjectList buf;
|
|
for (TGObject*const*p = GetFirst();p != NULL;p = GetNext(p))
|
|
{
|
|
if (IS_CLASS(*p,TGRegion2D))
|
|
{
|
|
((const TGRegion2D*)(*p))->SubtractBy(face,res);
|
|
}
|
|
else
|
|
{
|
|
face.Clip(**p,buf,res,buf);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TGObjectList::SubtractBy(const TGObjectList&faces,TGObjectList&res) const
|
|
{
|
|
TGObjectList buf(*this);
|
|
for (TGObject*const*p = faces.GetFirst();p != NULL;p = faces.GetNext(p))
|
|
{
|
|
TGObjectList buf1;
|
|
const TGRegion2D* pRegion = (const TGRegion2D*)(*p);
|
|
buf.SubtractBy(*pRegion,buf1);
|
|
|
|
buf.Clear();
|
|
buf.Conbine(buf1);
|
|
}
|
|
|
|
res.Conbine(buf);
|
|
}
|
|
|
|
void TGObjectList::ReverseCurve2D()
|
|
{
|
|
for (MoveToFirst();!IsOut();MoveToNext())
|
|
{
|
|
GetCurCurve2D().Reverse();
|
|
}
|
|
} |