#include "StdAfx.h" #include "GePoly.h" #include "GeLine.h" #include "globalFunc.h" #include "GeShape.h" #include "GeTrianglePface.h" #include "GePolygonEx.h" #include "GeCurveInline.h" GePoly::GePoly() { } GePoly::GePoly(resbuf *pts) { RBGroups *ptList = (RBGroups *)pts; for (RBGroups *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 ADSGePoint3d(tmp)); } } } GePoly::GePoly(const EntitySet &ent) { EntitySet entPLine = ent; ADSGePoint3d pt; if (entPLine.Is(_T("POLYLINE"))) { EntitySet subEnt = entPLine; while (TRUE) { EntitySet 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 ADSGePoint3d(pt)); } } else if (entPLine.Is(_T("LWPOLYLINE"))) { ads_real dElevation = 0.0; entPLine.GetData(38, &dElevation); resbuf *ebuf = entPLine; while(ebuf) { resbuf *rb1 = GlobalFunc::GetResbufAtCode(ebuf, 10); if (rb1) { pt = rb1->resval.rpoint; pt.z = dElevation; Append(new ADSGePoint3d(pt)); ebuf = rb1->rbnext; } else { break; } } } } GePoly::GePoly(const GePoly &src) { *this = src; } GePoly::~GePoly() { } void GePoly::CopyFrom(const GeEntity* pSrc) { if (this != pSrc && pSrc->IsKindOf(GeEntity::ePoly2D)) { copyFrom(*((GePoly* )pSrc)); } } void GePoly::Center(ads_point ptcen) { Center(ptcen); } int GePoly::IsRectAngle(ads_point ptcen, ads_real *pdwidth, ads_real *pdheight) { if (Length() != 4) { return 0; } GeLine line[4]; for (int i = 0; i < 4; i++) { NthLine(i, line[i]); } if (IsOrthDrt(line[0].Direction(), line[1].Direction(), g_DimOption::instance()._angSnap) && IsOrthDrt(line[2].Direction(), line[3].Direction(), g_DimOption::instance()._angSnap) && IsSameDrt(line[0].Direction(), line[2].Direction(), g_DimOption::instance()._angSnap)) { if (RealEqual(line[0].GetLength(),line[2].GetLength(),g_Option::instance()._DIST_SNAP) && RealEqual(line[1].GetLength(), line[3].GetLength(),g_Option::instance()._DIST_SNAP)) { if (IsSameDrt(line[0].Direction(), 0, g_DimOption::instance()._angSnap)) { GeLine ln(*(*this)[0], *(*this)[2]); if (ptcen) { *(ADSGePoint3d*)ptcen = ln.MidPoint(); } if (pdwidth) { *pdwidth = line[0].GetLength(); } if (pdheight) { *pdheight = line[1].GetLength(); } return 1; } else if (IsSameDrt(line[1].Direction(), 0, g_DimOption::instance()._angSnap)) { GeLine ln(*(*this)[0], *(*this)[2]); if (ptcen) { *(ADSGePoint3d*)ptcen = ln.MidPoint(); } if (pdwidth) { *pdwidth = line[1].GetLength(); } if (pdheight) { *pdheight = line[0].GetLength(); } return 1; } } } return 0; } int GePoly::NthLine(int nIndex, GeLine& res) { int nlen = Length(); if (nIndex >= nlen || nIndex < 0) { return RTERROR; } ADSGePoint3d *pt1 = (*this)[nIndex]; ADSGePoint3d *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 GePoly::PathArea() { GeLine 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 GePoly::IsPoint() { int nlen = Length(); if (!nlen) { return 0; } ADSGePoint3d bp = *(*this)[0]; for (int i = 0; i < nlen; i++) { if (!(bp == *(*this)[i])) { return 0; } } return 1; } int GePoly::IsLinear() { GeLine xline; int i = 0; while(1) { if (NthLine(i, xline) != RTNORM) { return 0; } if (xline.GetLength() > g_Option::instance()._DIST_SNAP) { break; } i++; } int nlen = Length(); for (i = 0; i < nlen; i++) { ADSGePoint3d &pt = *(*this)[i]; if ((pt & xline) == PR_OUTSIDE) { return 0; } } return 1; } resbuf* GePoly::Polygon() { return ResbufList(0); } resbuf* GePoly::Fence() { return ResbufList(1); } resbuf* GePoly::ResbufList(int nIsClosed) { int nlen = Length(); if (nIsClosed) { nlen++; } RBGroups *lastrb = NULL, *result = NULL; for (int i = 0; i < nlen; i++) { int ncur; if (nIsClosed && i == nlen - 1) { ncur = 0; } else { ncur = i; } RBGroups *rb = new RBGroups(*(*this)[ncur]); rb->next = NULL; if (lastrb) { lastrb->next = rb; lastrb = rb; } else { lastrb = result = rb; } } return (resbuf *)result; } ads_real GePoly::Area() { return fabs(PathArea()); } ShapeType GePoly::GetShapeType() const { return SHAPE_POLY; } GePoly& GePoly::operator = (const GePoly &src) { (ADSGePointList &)*this = src; return *this; //Reset(); //if (this != &src) //{ // CopyFrom(&src); //} //return *this; } int GePoly::operator !() { return (Length() < 3 ? 1 : 0); } int GePoly::CreatePface(const TCHAR *szlay/* = NULL*/) { GePolygonEx polyEx(*this); GeTrianglePface lstTris; if (polyEx.Trianglize(lstTris, TRUE) == RTNORM) { return lstTris.MakePolyface(szlay); } return RTERROR; } int GePoly::GetExtend(ADSGePoint3d &ptlow, ADSGePoint3d &ptup) const { return ADSGePointList::GetExtend(ptlow, ptup); } bool GePoly::IsKindOf(GeEntity::TEntityId entType) const { switch(entType) { case GeEntity::eEntity: case GeEntity::eCurve: case GeEntity::eShape: case GeEntity::ePoly: return true; } return false; } GeEntity::TEntityId GePoly::Type() const { return GeEntity::ePoly; }