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

398 lines
6.1 KiB
C++

//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TGGePoly 类
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: TGGePoly 定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TGGePoly.h"
#include "TGGeLine.h"
#include "TGGeShape.h"
#include "TGGeTrianglePface.h"
#include "TchGlobalFunc.h"
#include "TGGePolygonEx.h"
#include "TchGlobalCurveFunc.h"
#include "TGGeCurveInline.h"
TGGePoly::TGGePoly()
{
}
TGGePoly::TGGePoly(resbuf *pts)
{
TGroups *ptList = (TGroups *)pts;
for (TGroups *pt = ptList; pt != NULL; pt = pt->next)
{
if (pt->type != RT3DPOINT && pt->type != RTPOINT)
{
Reset();
return;
}
else
{
Point tmp = pt->point;
tmp.z = 0.0;
Append(new TADSGePoint3d(tmp));
}
}
}
TGGePoly::TGGePoly(const TEntitySet &ent)
{
TEntitySet entPLine = ent;
TADSGePoint3d pt;
if (entPLine.Is(_T("POLYLINE")))
{
TEntitySet subEnt = entPLine;
while (TRUE)
{
TEntitySet sub_ent;
if (ads_entnext(subEnt, sub_ent) != RTNORM)
{
break;
}
subEnt = sub_ent;
subEnt.FreeGroups();
if (subEnt.Is(_T("SEQEND")))
{
break;
}
int nflg = 0;
if (subEnt.GetData(70, &nflg) == RTNORM && nflg == 128)
{
break;
}
subEnt.GetData(10, pt);
Append(new TADSGePoint3d(pt));
}
}
else if (entPLine.Is(_T("LWPOLYLINE")))
{
ads_real dElevation = 0.0;
entPLine.GetData(38, &dElevation);
resbuf *ebuf = entPLine;
while(ebuf)
{
resbuf *rb1 = GetResbufAtCode(ebuf, 10);
if (rb1)
{
pt = rb1->resval.rpoint;
pt.z = dElevation;
Append(new TADSGePoint3d(pt));
ebuf = rb1->rbnext;
}
else
{
break;
}
}
}
}
TGGePoly::TGGePoly(const TGGePoly &src)
{
*this = src;
}
TGGePoly::~TGGePoly()
{
}
void TGGePoly::CopyFrom(const TGGeEntity* pSrc)
{
if (this != pSrc && pSrc->IsKindOf(TGGeEntity::ePoly2D))
{
copyFrom(*((TGGePoly* )pSrc));
}
}
void TGGePoly::Center(ads_point ptcen)
{
Center(ptcen);
}
int TGGePoly::IsRectAngle(ads_point ptcen, ads_real *pdwidth, ads_real *pdheight)
{
if (Length() != 4)
{
return 0;
}
TGGeLine line[4];
for (int i = 0; i < 4; i++)
{
NthLine(i, line[i]);
}
if (IsOrthDrt(line[0].Direction(), line[1].Direction(), _angSnap)
&& IsOrthDrt(line[2].Direction(), line[3].Direction(), _angSnap)
&& IsSameDrt(line[0].Direction(), line[2].Direction(), _angSnap))
{
if (RealEqual(line[0].GetLength(),line[2].GetLength(),_DIST_SNAP) &&
RealEqual(line[1].GetLength(), line[3].GetLength(),_DIST_SNAP))
{
if (IsSameDrt(line[0].Direction(), 0, _angSnap))
{
TGGeLine ln(*(*this)[0], *(*this)[2]);
if (ptcen)
{
*(TADSGePoint3d*)ptcen = ln.MidPoint();
}
if (pdwidth)
{
*pdwidth = line[0].GetLength();
}
if (pdheight)
{
*pdheight = line[1].GetLength();
}
return 1;
}
else if (IsSameDrt(line[1].Direction(), 0, _angSnap))
{
TGGeLine ln(*(*this)[0], *(*this)[2]);
if (ptcen)
{
*(TADSGePoint3d*)ptcen = ln.MidPoint();
}
if (pdwidth)
{
*pdwidth = line[1].GetLength();
}
if (pdheight)
{
*pdheight = line[0].GetLength();
}
return 1;
}
}
}
return 0;
}
int TGGePoly::NthLine(int nIndex, TGGeLine& res)
{
int nlen = Length();
if (nIndex >= nlen || nIndex < 0)
{
return RTERROR;
}
TADSGePoint3d *pt1 = (*this)[nIndex];
TADSGePoint3d *pt2;
if (nIndex == nlen - 1)
{
pt2 = (*this)[0];
}
else
{
pt2 = (*this)[nIndex + 1];
}
if (!pt1 || !pt2)
{
return RTERROR;
}
res.SetPoints(*pt1, *pt2);
return RTNORM;
}
ads_real TGGePoly::PathArea()
{
TGGeLine line;
ads_real dresult = 0.0;
int nsegments = Length();
for (int i = 0; i < nsegments; i++)
{
if (NthLine(i, line) != RTNORM)
{
break;
}
dresult += line.PathArea();
}
return dresult;
}
int TGGePoly::IsPoint()
{
int nlen = Length();
if (!nlen)
{
return 0;
}
TADSGePoint3d bp = *(*this)[0];
for (int i = 0; i < nlen; i++)
{
if (!(bp == *(*this)[i]))
{
return 0;
}
}
return 1;
}
int TGGePoly::IsLinear()
{
TGGeLine xline;
int i = 0;
while(1)
{
if (NthLine(i, xline) != RTNORM)
{
return 0;
}
if (xline.GetLength() > _DIST_SNAP)
{
break;
}
i++;
}
int nlen = Length();
for (i = 0; i < nlen; i++)
{
TADSGePoint3d &pt = *(*this)[i];
if ((pt & xline) == PR_OUTSIDE)
{
return 0;
}
}
return 1;
}
resbuf* TGGePoly::Polygon()
{
return ResbufList(0);
}
resbuf* TGGePoly::Fence()
{
return ResbufList(1);
}
resbuf* TGGePoly::ResbufList(int nIsClosed)
{
int nlen = Length();
if (nIsClosed)
{
nlen++;
}
TGroups *lastrb = NULL, *result = NULL;
for (int i = 0; i < nlen; i++)
{
int ncur;
if (nIsClosed && i == nlen - 1)
{
ncur = 0;
}
else
{
ncur = i;
}
TGroups *rb = new TGroups(*(*this)[ncur]);
rb->next = NULL;
if (lastrb)
{
lastrb->next = rb;
lastrb = rb;
}
else
{
lastrb = result = rb;
}
}
return (resbuf *)result;
}
ads_real TGGePoly::Area()
{
return fabs(PathArea());
}
ShapeType TGGePoly::GetShapeType() const
{
return SHAPE_POLY;
}
TGGePoly& TGGePoly::operator = (const TGGePoly &src)
{
(TADSGePointList &)*this = src;
return *this;
//Reset();
//if (this != &src)
//{
// CopyFrom(&src);
//}
//return *this;
}
int TGGePoly::operator !()
{
return (Length() < 3 ? 1 : 0);
}
int TGGePoly::CreatePface(const TCHAR *szlay/* = NULL*/)
{
TGGePolygonEx polyEx(*this);
TGGeTrianglePface lstTris;
if (polyEx.Trianglize(lstTris, TRUE) == RTNORM)
{
return lstTris.MakePolyface(szlay);
}
return RTERROR;
}
int TGGePoly::GetExtend(TADSGePoint3d &ptlow, TADSGePoint3d &ptup) const
{
return TADSGePointList::GetExtend(ptlow, ptup);
}
bool TGGePoly::IsKindOf(TGGeEntity::TEntityId entType) const
{
switch(entType)
{
case TGGeEntity::eEntity:
case TGGeEntity::eCurve:
case TGGeEntity::eShape:
case TGGeEntity::ePoly:
return true;
}
return false;
}
TGGeEntity::TEntityId TGGePoly::Type() const
{
return TGGeEntity::ePoly;
}