Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

225 lines
3.7 KiB
C++

//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TGObject.cpp
// = Version : ver2.0
// = Author : xlc
// = CreateDate : 2002-09-09
// = Description: 类的定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TGObject.h"
#include "TGMatrix.h"
#include "TGObjectList.h"
TGObject::OutputGObject TGObject::s_pOutputFun = NULL;
IMPLEMENT_RUN_TIME_CLASS1(TGObject,"TGObject",TWRunTimeClass)
TGObject::~TGObject()
{
}
bool TGObject::operator>(const TGObject&obj) const
{
return GetClassID()>obj.GetClassID();
}
bool TGObject::operator<(const TGObject&obj) const
{
return GetClassID()<obj.GetClassID();
}
//实体有效性,如果非特殊说明,对实体的所有函数调用必须满足实体有效!
bool TGObject::IsValid() const
{
return false;
}
//实体克隆
TGObject * TGObject::Clone() const
{
return NULL;
}
//坐标变换
void TGObject::TransformBy(const TGMatrix& pMatrix)
{
}
bool TGObject::Explode(TGObjectList& res) const
{
return false;
}
//如果ECS与WCS不重合,返回实体坐标系且return true
bool TGObject::GetEcs(TPGeCoordSys&ecs) const
{
return false;
}
//采样测试点,不取端点、节点之类的不光滑点!
TGPoint TGObject::GetSamplePoint() const
{
return TGPoint();
}
void TGObject::Output(int color) const
{
if (TGObject::s_pOutputFun != NULL)
{
TGObject::s_pOutputFun(this,color);
}
}
bool TGObject::Intersect(const TGObject&obj,TGObjectList& res) const
{
TGObjectList oList;
Explode(oList);
TGObjectList buf;
for (oList.MoveToFirst();!oList.IsOut();oList.MoveToNext())
{
oList.GetCurPData().Intersect(obj,buf);
}
if (buf.IsEmpty())
{
return false;
}
else
{
res.Conbine(buf);
return true;
}
}
bool TGObject::IsInclude(const TGObject&obj) const
{
TGObjectList oList;
if (obj.Explode(oList))
{
for (oList.MoveToFirst();!oList.IsOut();oList.MoveToNext())
{
if (!IsInclude(oList.GetCurPData()))
{
return false;
}
}
return true;
}
return false;
}
GRelation TGObject::HitTest(const TGPoint&pt) const
{
TGObjectList oList;
Explode(oList);
for (oList.MoveToFirst();!oList.IsOut();oList.MoveToNext())
{
GRelation r = oList.GetCurPData().HitTest(pt);
if (r.Is(GR_IN))
{
return GR_IN;
}
}
return GR_OUT;//NULL
}
bool TGObject::GetExtend2D(TPGeExtend2D& pExt) const
{
ASSERT(pExt != NULL);
TGObjectList oList;
if (Explode(oList))
{
return oList.GetExtend2D(pExt);
}
return false;
}
bool TGObject::GetExtend3D(TPGeExtend3D& pExt) const
{
ASSERT(pExt != NULL);
TGObjectList oList;
if (Explode(oList))
{
return oList.GetExtend3D(pExt);
}
return false;
}
void TGObject::ExplodeEx(TGObjectList& pRes) const
{
TGObjectList buf;
if (Explode(buf))
{
buf.ExplodeEx();
pRes.Conbine(buf);
}
else
{
pRes << Clone();
}
}
void TGObject::TransEcs(TGObject*pObj) const
{
TPGeCoordSys ecs;
if (GetEcs(ecs))
{
TGMatrix mat;
ecs.GetMatrixTo(&mat);
pObj->TransformBy(mat);
}
}
void TGObject::TransWcs(TGObject*pObj) const
{
TPGeCoordSys ecs;
if (GetEcs(ecs))
{
TGMatrix mat;
ecs.GetMatrixFrom(&mat);
pObj->TransformBy(mat);
}
}
bool TGObject::IsExtendInter(const TPGeExtend2D& pExt) const
{
ASSERT(pExt != NULL);
TPGeExtend2D ext1;
if (!GetExtend2D(ext1))
{
return true;//无限大,因此有交
}
else
{
return pExt.IsIntersect(ext1);
}
}
bool TGObject::IsExtendInter(const TPGeExtend3D& pExt) const
{
ASSERT(pExt != NULL);
TPGeExtend3D ext1;
if (!GetExtend3D(ext1))
{
return true; //无限大,因此有交
}
else
{
return pExt.IsIntersect(ext1);
}
}