289 lines
4.9 KiB
C++
289 lines
4.9 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TGPCurve3D.cpp
|
|
// = Version : ver2.0
|
|
// = Author : xlc
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: 类的定义
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TGPCurve3D.h"
|
|
#include "TGPlane3D.h"
|
|
|
|
IMPLEMENT_RUN_TIME_CLASS1(TGPCurve3D,"TGPCurve3D",TPGeCurve3D)
|
|
|
|
TGPCurve3D::TGPCurve3D(TPGeCurve2D* pCurve)
|
|
: pCurve2d(pCurve)
|
|
{
|
|
|
|
}
|
|
|
|
TGPCurve3D::TGPCurve3D(const TGPCurve3D&curve)
|
|
: pCurve2d(NULL)
|
|
{
|
|
*this = curve;
|
|
}
|
|
|
|
TGPCurve3D::~TGPCurve3D()
|
|
{
|
|
Clear();
|
|
}
|
|
|
|
void TGPCurve3D::Clear()
|
|
{
|
|
if (pCurve2d != NULL)
|
|
{
|
|
delete pCurve2d;
|
|
}
|
|
pCurve2d = NULL;
|
|
}
|
|
|
|
bool TGPCurve3D::IsClosed() const
|
|
{
|
|
return pCurve2d->IsClosed();
|
|
}
|
|
|
|
bool TGPCurve3D::IsSelfCross() const
|
|
{
|
|
return pCurve2d->IsSelfCross();
|
|
}
|
|
|
|
bool TGPCurve3D::IsFinite(bool bStart) const
|
|
{
|
|
return pCurve2d->IsFinite(bStart);
|
|
}
|
|
|
|
double TGPCurve3D::Area() const
|
|
{
|
|
return pCurve2d->Area();
|
|
}
|
|
|
|
double TGPCurve3D::Length() const
|
|
{
|
|
return pCurve2d->Length();
|
|
}
|
|
|
|
void TGPCurve3D::Reverse()
|
|
{
|
|
pCurve2d->Reverse();
|
|
}
|
|
|
|
bool TGPCurve3D::GetPlane(TPGePlane&plane) const
|
|
{
|
|
ecs.GetXYPlane(plane);
|
|
return true;
|
|
}
|
|
|
|
bool TGPCurve3D::IsValid() const
|
|
{
|
|
return pCurve2d != NULL && pCurve2d->IsValid() && ecs.IsValid();
|
|
}
|
|
|
|
bool TGPCurve3D::GetEcs(TPGeCoordSys&ECS) const
|
|
{
|
|
ECS = ecs;
|
|
return true;
|
|
}
|
|
|
|
TGObject* TGPCurve3D::Clone() const
|
|
{
|
|
return new TGPCurve3D(*this);
|
|
}
|
|
|
|
TGPCurve3D& TGPCurve3D::operator = (const TGPCurve3D&curve)
|
|
{
|
|
Clear();
|
|
|
|
TPGeCurve3D::operator = (curve);
|
|
ecs = curve.ecs;
|
|
if (curve.pCurve2d != NULL)
|
|
{
|
|
pCurve2d = (TPGeCurve2D*)(curve.pCurve2d->Clone());
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
bool TGPCurve3D::Explode(TGObjectList&res) const
|
|
{
|
|
TGObjectList buf;
|
|
if (pCurve2d->Explode(buf))
|
|
{
|
|
buf.Convert3D();
|
|
|
|
TGMatrix mat;
|
|
ecs.GetMatrixFrom(&mat);
|
|
buf.TransformBy(mat);
|
|
|
|
if (!buf.IsEmpty())
|
|
{
|
|
res.Conbine(buf);
|
|
return true;
|
|
}
|
|
}
|
|
else if (IS_CLASS(pCurve2d,TPGeGLine2D))
|
|
{
|
|
TGObject3D *p3d = pCurve2d->Convert3D();
|
|
TransWcs(p3d);
|
|
res << p3d;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void TGPCurve3D::TransformBy(const TGMatrix&mat)
|
|
{
|
|
}
|
|
|
|
TGObject2D* TGPCurve3D::Convert2D() const
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
bool TGPCurve3D::GetExtend2D(TPGeExtend2D&ext) const
|
|
{
|
|
switch(pCurve2d->GetClassID())
|
|
{
|
|
case CID_GLine2D:
|
|
case CID_GLineRay2D:
|
|
return false;
|
|
case CID_GCircle2D:
|
|
return false;
|
|
case CID_GArc2D:
|
|
return false;
|
|
}
|
|
return TPGeCurve3D::GetExtend2D(ext);
|
|
}
|
|
|
|
bool TGPCurve3D::GetExtend3D(TPGeExtend3D&ext) const
|
|
{
|
|
switch(pCurve2d->GetClassID())
|
|
{
|
|
case CID_GLine2D:
|
|
case CID_GLineRay2D:
|
|
return false;
|
|
case CID_GCircle2D:
|
|
return false;
|
|
case CID_GArc2D:
|
|
return false;
|
|
}
|
|
return TPGeCurve3D::GetExtend3D(ext);
|
|
}
|
|
|
|
TPGeCurve3D* TGPCurve3D::GetSubCurve(double pa0,double pa1) const
|
|
{
|
|
TGPCurve3D* pSeg3d = new TGPCurve3D((TPGeCurve2D*)pCurve2d->GetSubCurve(pa0,pa1));
|
|
pSeg3d->ecs = ecs;
|
|
return pSeg3d;
|
|
}
|
|
|
|
void TGPCurve3D::Split(const TTable<double>&paTable,TGObjectList&res) const
|
|
{
|
|
TGObjectList buf;
|
|
pCurve2d->Split(paTable,buf);
|
|
for (buf.MoveToFirst(); !buf.IsOut(); buf.MoveToNext())
|
|
{
|
|
TGPCurve3D* pSeg3d = new TGPCurve3D((TPGeCurve2D*)buf.GetCurData());
|
|
pSeg3d->ecs = ecs;
|
|
buf.SetCurData(pSeg3d);
|
|
}
|
|
|
|
res.Conbine(buf);
|
|
}
|
|
|
|
void TGPCurve3D::Pa2Pt(double pa,TGPoint&pt) const
|
|
{
|
|
pCurve2d->Pa2Pt(pa,pt);
|
|
ecs.TransWcs(pt);
|
|
}
|
|
|
|
void TGPCurve3D::Pt2Pa(const TGPoint&pt,double&pa) const
|
|
{
|
|
TGPoint ptTest = pt;
|
|
ecs.TransUcs(ptTest);
|
|
pCurve2d->Pt2Pa(ptTest,pa);
|
|
}
|
|
|
|
bool TGPCurve3D::Intersect(const TGObject&obj,TGObjectList&res) const
|
|
{
|
|
TGPlane3D plane;
|
|
GetPlane(plane);
|
|
|
|
TGObjectList buf;
|
|
|
|
if (!plane.Intersect(obj,buf))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (IS_TYPE(buf[0],TGPlane3D))
|
|
{
|
|
res << Clone();
|
|
}
|
|
else
|
|
{
|
|
TGMatrix mat;
|
|
ecs.GetMatrixTo(&mat);
|
|
buf.TransformBy(mat);
|
|
buf.Convert2D();
|
|
|
|
TGObjectList res2d;
|
|
buf.Intersect(*pCurve2d,res2d);
|
|
if (res2d.IsEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
res2d.Convert3D();
|
|
mat.Reverse();
|
|
res2d.TransformBy(mat);
|
|
res.Conbine(res2d);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TGPCurve3D::IsInclude(const TGObject&obj) const
|
|
{
|
|
if (IS_CLASS(&obj,TPGeCurve3D))
|
|
{
|
|
const TPGeCurve3D&curve3d = (const TPGeCurve3D&)obj;
|
|
TGPlane3D plane;
|
|
GetPlane(plane);
|
|
|
|
if (plane.IsInclude(curve3d))
|
|
{
|
|
TPGeCurve3D *p3d = (TPGeCurve3D*)curve3d.Clone();
|
|
TransEcs(p3d);
|
|
|
|
TGObject2D* p2d = p3d->Convert2D();
|
|
bool bRes = pCurve2d->IsInclude(*p2d);
|
|
delete p3d;
|
|
delete p2d;
|
|
return bRes;
|
|
}
|
|
return false;
|
|
}
|
|
return TPGeCurve3D::IsInclude(obj);
|
|
}
|
|
|
|
GRelation TGPCurve3D::HitTest(const TGPoint&pt) const
|
|
{
|
|
TGPoint ptTest = pt;
|
|
ecs.TransUcs(ptTest);
|
|
|
|
GRelation r = pCurve2d->HitTest(ptTest);
|
|
if (UP_ZEROD(ptTest.z))
|
|
{
|
|
r.RemoveFlag(GR_IN);
|
|
r.AddFlag(GR_UP);
|
|
}
|
|
else if (DOWN_ZEROD(ptTest.z))
|
|
{
|
|
r.RemoveFlag(GR_IN);
|
|
r.AddFlag(GR_DOWN);
|
|
}
|
|
|
|
return r;
|
|
} |