1023 lines
25 KiB
C++
1023 lines
25 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : 导出全局函数实现文件
|
|
// = Version : ver2.0
|
|
// = Author : lfy
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: 全局函数的声明
|
|
// = Maintainers:
|
|
//
|
|
//-------------------------------------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TchSubGlobalFunc.h"
|
|
#include "TGRegionEx2D.h"
|
|
#include "TGPolygon2D.h"
|
|
#include "TGPoint2D.h"
|
|
#include "TPGeCurveMesh.h"
|
|
#include "TGMesh.h"
|
|
#include "TPushMemVar.h"
|
|
#include "TProductid.h"
|
|
#include "TGMLine2D.h"
|
|
#include "TGPLine2D.h"
|
|
#include "TGMCurve2D.h"
|
|
#include "TGPolygon2D.h"
|
|
#include "TGPolygonEx2D.h"
|
|
#include "TGRegionEx2D.h"
|
|
#include "TGPoint3D.h"
|
|
#include "TPGeGLine3D.h"
|
|
#include "TPGeGLineRay3D.h"
|
|
#include "TPGeGLineSeg3D.h"
|
|
#include "TGPCurve3D.h"
|
|
#include "TGMLine3D.h"
|
|
#include "TGMCurve3D.h"
|
|
#include "TGPlane3D.h"
|
|
#include "TPGeGraph.h"
|
|
#include "TGGeRegion2D.h"
|
|
#include "TchGlobalCurveFunc.h"
|
|
|
|
extern int g_nProductId;
|
|
|
|
void TchSubExport::RegisterClassId()
|
|
{
|
|
REGISTER_CID(TGPoint2D,CID_GPoint2D);
|
|
REGISTER_CID(TPGeGLine2D,CID_GLine2D);
|
|
REGISTER_CID(TPGeGLineRay2D,CID_GLineRay2D);
|
|
REGISTER_CID(TPGeGLineSeg2D,CID_GLineSeg2D);
|
|
REGISTER_CID(TPGeCircle2D,CID_GCircle2D);
|
|
REGISTER_CID(TPGeArc2D,CID_GArc2D);
|
|
REGISTER_CID(TGMLine2D,CID_GMLine2D);
|
|
REGISTER_CID(TGPLine2D,CID_GPLine2D);
|
|
REGISTER_CID(TGMCurve2D,CID_GMCurve2D);
|
|
REGISTER_CID(TGPolygon2D,CID_GPolygon2D);
|
|
REGISTER_CID(TGPolygonEx2D,CID_GPolygonEx2D);
|
|
REGISTER_CID(TGRegionEx2D,CID_GRegionEx2D);
|
|
REGISTER_CID(TGPoint3D,CID_GPoint3D);
|
|
REGISTER_CID(TPGeGLine3D,CID_GLine3D);
|
|
REGISTER_CID(TPGeGLineRay3D,CID_GLineRay3D);
|
|
REGISTER_CID(TPGeGLineSeg3D,CID_GLineSeg3D);
|
|
REGISTER_CID(TGPCurve3D,CID_GPCurve3D);
|
|
REGISTER_CID(TGMLine3D,CID_GMLine3D);
|
|
REGISTER_CID(TGMCurve3D,CID_GMCurve3D);
|
|
REGISTER_CID(TGPlane3D,CID_GPlane3D);
|
|
|
|
TGObjectList ss;
|
|
{
|
|
TPGeFitGraph a;
|
|
a.MakeEdge();
|
|
a.MakeTriangle();
|
|
a.Fit(0);
|
|
a.CreateCurve(ss);
|
|
a.Reset();
|
|
|
|
NA(0);
|
|
}
|
|
}
|
|
|
|
void TchSubExport::GOutput(const TGObject*pObj,int color)
|
|
{
|
|
AcDbEntity *pEnt = TchSubExport::Obj2Entity((TGObject*)pObj);
|
|
if (pEnt != NULL)
|
|
{
|
|
pEnt->setColorIndex(color);
|
|
TchExport::AddToModelSpace(pEnt,Adesk::kTrue);
|
|
}
|
|
}
|
|
|
|
BOOL TchSubExport::Offset(double dist,TGGePoly2D &poly)//poly是输入也是输出
|
|
{
|
|
TGPLine2D polyNew;
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly,polyNew);
|
|
|
|
if (!polyNew.Offset(dist))
|
|
{
|
|
return FALSE;
|
|
}
|
|
poly.Reset();
|
|
TchSubExport::TGMLine2DToTGGePoly2D(polyNew,poly);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void TchSubExport::Offset(double dist,TGGePoly2D poly,TDPtrList<TGGePoly2D>&lstRes)
|
|
{
|
|
if (poly.Length() < 1 || !poly.IsClosed())
|
|
{
|
|
return;
|
|
}
|
|
|
|
double elev = poly[0]->z;
|
|
TchSubExport::Offset(dist,poly);
|
|
|
|
if (poly.IsSelfIntersect())
|
|
{
|
|
TDPtrList<TGGeCurveSegment> lstSeg;
|
|
ExplodePoly2D(poly,lstSeg);
|
|
|
|
TGObjectList oList,oList1;
|
|
for (long i = 0; i < lstSeg.Length(); i++)
|
|
{
|
|
oList << TchSubExport::TGGeCurveSegmentToTPGeCurve2D(*lstSeg[i]);
|
|
}
|
|
oList.InterBreakCurve2D(oList1);
|
|
|
|
TPGeCurveMesh mesh(oList1);
|
|
mesh.FindAllMesh();
|
|
for (mesh.m_allMesh.MoveToFirst();!mesh.m_allMesh.IsOut();mesh.m_allMesh.MoveToNext())
|
|
{
|
|
TPGeCurve2D* pCurve = mesh.m_allMesh.GetCurData()->CreateCurve();
|
|
if (pCurve != NULL)
|
|
{
|
|
if (pCurve->IsClockwise())//内环
|
|
{
|
|
TGMLine2D *pPline = pCurve->PLinearize();
|
|
if (pPline != NULL)
|
|
{
|
|
TGGePoly2D polyTemp(1);
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pPline,polyTemp);
|
|
delete pPline;
|
|
polyTemp.Reverse();
|
|
polyTemp.Compress();
|
|
polyTemp.SetElevation(elev);
|
|
lstRes.Append(new TGGePoly2D(polyTemp));
|
|
}
|
|
}
|
|
delete pCurve;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lstRes.Append(new TGGePoly2D(poly));
|
|
}
|
|
}
|
|
|
|
|
|
TPGeCurve2D* TchSubExport::TGGeCurveSegmentToTPGeCurve2D(TGGeCurveSegment cv)
|
|
{
|
|
if (cv.Is(CURVE_LINE))
|
|
{
|
|
return new TPGeGLineSeg2D(TGPoint((double*)cv.GetStartPoint()),(TGPoint((double*)cv.GetEndPoint())));
|
|
}
|
|
else
|
|
{
|
|
return new TPGeArc2D((double*)cv.GetStartPoint(),(double*)cv.GetEndPoint(),cv.GetBulge());
|
|
}
|
|
}
|
|
|
|
void TchSubExport::SearchOutline(const TDPtrList<TGGeCurveSegment>&lstSeg,TDPtrList<TGGePoly2D>&lstPoly)
|
|
{
|
|
TGObjectList oList,oList1;
|
|
for (long i = 0; i < lstSeg.Length(); i++)
|
|
{
|
|
oList << TchSubExport::TGGeCurveSegmentToTPGeCurve2D(lstSeg[i]);
|
|
}
|
|
oList.InterBreakCurve2D(oList1);
|
|
oList.Clear();
|
|
|
|
TPGeCurveMesh mesh(oList1);
|
|
mesh.FindAllMesh();
|
|
for (mesh.m_allMesh.MoveToFirst();!mesh.m_allMesh.IsOut();mesh.m_allMesh.MoveToNext())
|
|
{
|
|
TPGeCurve2D* pCurve = mesh.m_allMesh.GetCurData()->CreateCurve();
|
|
if (!pCurve->IsClockwise())
|
|
{
|
|
TGMLine2D *pPline = pCurve->PLinearize();
|
|
if (pPline != NULL)
|
|
{
|
|
TGGePoly2D poly(1);
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pPline,poly);
|
|
delete pPline;
|
|
poly.Compress();
|
|
lstPoly.Append(new TGGePoly2D(poly));
|
|
}
|
|
}
|
|
delete pCurve;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void TchSubExport::TGGePoly2DToTGPLine2D(const TGGePoly2D&poly0,TGPLine2D&poly)
|
|
{
|
|
poly.SetVertexNum(poly0.Length());
|
|
poly.SetClosed(poly0.IsClosed() == TRUE);
|
|
for (long i = 0;i<poly0.Length();i++)
|
|
{
|
|
poly[i] = (double*)(poly0[i]);
|
|
poly(i) = poly0.GetBulge(i);
|
|
}
|
|
}
|
|
|
|
TGGeRegion2D* TchSubExport::TGRegion2DToTGGeRegion2D(const TGRegion2D&r1)
|
|
{
|
|
if (r1.GetBoundaryNum() < 1)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
TPGeCurve2D &curve = r1.Outline();
|
|
TGMLine2D* pMLine = curve.PLinearize();
|
|
if (pMLine == NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
TGGeRegion2D *pNewRegion = new TGGeRegion2D;
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pMLine,*pNewRegion);
|
|
delete pMLine;
|
|
|
|
for (long i = 0;i<r1.GetHoleNum();i++)
|
|
{
|
|
pMLine = r1.Hole(i).PLinearize();
|
|
if (pMLine == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
TGGePoly2D *pHole = new TGGePoly2D(1);
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pMLine,*pHole);
|
|
delete pMLine;
|
|
|
|
pNewRegion->AppendHole(pHole);
|
|
}
|
|
|
|
if (pNewRegion->IsValid())
|
|
{
|
|
return pNewRegion;
|
|
}
|
|
else
|
|
{
|
|
delete pNewRegion;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
void TchSubExport::TGMLine2DToTGGePoly2D(const TGMLine2D&poly0,TGGePoly2D&poly)
|
|
{
|
|
poly.Reset();
|
|
if (IS_TYPE(&poly0,TGMLine2D))
|
|
{
|
|
for (long i = 0;i<poly0.GetVertexNum();i++)
|
|
{
|
|
const TGPoint&pt = poly0.GetVertex(i);
|
|
poly.AppendNode(TADSGePoint3d(pt.x,pt.y,pt.z));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
const TGPLine2D&poly1 = (const TGPLine2D&)poly0;
|
|
for (long i = 0;i<poly1.GetVertexNum();i++)
|
|
{
|
|
const TGPoint&pt = poly1.GetVertex(i);
|
|
poly.AppendNode(TADSGePoint3d(pt.x,pt.y,pt.z),poly1.GetBulge(i));
|
|
}
|
|
}
|
|
|
|
poly.SetFlag(poly0.IsClosed() ? 1 : 0);
|
|
}
|
|
|
|
bool TchSubExport::IsInter(const TGGePoly2D& poly1,const TGGePoly2D& poly2)
|
|
{
|
|
TGPLine2D pline1,pline2;
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly1,pline1);
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly2,pline2);
|
|
|
|
TGObjectList buf;
|
|
return pline1.Intersect(pline2,buf);
|
|
}
|
|
|
|
bool TchSubExport::IsInclude(const TGGePoly2D& poly1,const TGGePoly2D& poly2)
|
|
{
|
|
TGPLine2D pline1,pline2;
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly1,pline1);
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly2,pline2);
|
|
|
|
TGRegionEx2D region1(pline1);
|
|
if (region1.IsValid() && region1.IsInclude(pline2))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void TchSubExport::CutPoly2D(const TGGePoly2D&poly2d,double dist,TGObjectList &res)
|
|
{
|
|
//准备切割
|
|
TGPLine2D poly;
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly2d,poly);
|
|
|
|
TPGeExtend2D ext;
|
|
poly.GetExtend2D(ext);
|
|
|
|
TGObjectList buf,right,left;
|
|
buf.AddTail(new TGRegionEx2D(poly));
|
|
|
|
//横向切割
|
|
TPGeGLine2D lineX(TGVector2D(1,0),TGPoint(0,ext.m_yExt.m_fMin));
|
|
double& Y = lineX.basePoint.y, maxY = ext.m_yExt.m_fMax-0.001;
|
|
for (Y += dist; Y < maxY; Y += dist)//从下往上切
|
|
{
|
|
buf.CutBy(lineX,left,right,left);
|
|
buf.Clear();
|
|
buf.Conbine(left);
|
|
}
|
|
buf.Conbine(right);
|
|
|
|
TPGeGLine2D lineY(TGVector2D(0,1),TGPoint(ext.m_xExt.m_fMin,0));
|
|
double& X = lineY.basePoint.x, maxX = ext.m_xExt.m_fMax-0.001;
|
|
for (X += dist; X < maxX; X += dist)//从左向右切
|
|
{
|
|
buf.CutBy(lineY,left,right,right);
|
|
buf.Clear();
|
|
buf.Conbine(right);
|
|
}
|
|
buf.Conbine(left);
|
|
res.Conbine(buf);
|
|
}
|
|
|
|
bool TchSubExport::GetSubPoly(const TGGePoly2D&poly,TADSGePoint3d pt1,TADSGePoint3d pt2,TGGePoly2D&subPoly)
|
|
{
|
|
TGPLine2D pline;
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly,pline);
|
|
|
|
double pa1,pa2;
|
|
pline.Pt2Pa(TGPoint(pt1.x,pt1.y),pa1);
|
|
pline.Pt2Pa(TGPoint(pt2.x,pt2.y),pa2);
|
|
|
|
if (UPEQUAL_ZERO(pa1) && UPEQUAL_ZERO(pa2))
|
|
{
|
|
TPGeCurve2D *pCurve = pline.GetSubCurve(pa1,pa2);
|
|
if (pCurve != NULL)
|
|
{
|
|
TGMLine2D *pMLine = pCurve->PLinearize();
|
|
delete pCurve;
|
|
|
|
if (pMLine != NULL)
|
|
{
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pMLine,subPoly);
|
|
delete pMLine;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
// 区域的减法
|
|
// what? poly1-poly2 = ?
|
|
int TchSubExport::Subtract(const TGGePoly2D &poly1, const TGGePoly2D &poly2, TDPtrList<TGGePoly2D> &lstResult)
|
|
{
|
|
if (g_nProductId != kTSUN)
|
|
{
|
|
//注意:日照计算时不需要启动这两行
|
|
TPushMemVar<double> vPrec(g_distZero,_DIST_SNAP);
|
|
TPushMemVar<double> vPrec1(g_fZero,1E-6);
|
|
|
|
TGPLine2D newPoly1,newPoly2;
|
|
// modify by xlc on 101105 在当前精度下压缩区域,解决在此精度下区域边界有重合点不合法的问题
|
|
//TchSubExport::TGGePoly2DToTGPLine2D(poly1,newPoly1);
|
|
//TchSubExport::TGGePoly2DToTGPLine2D(poly2,newPoly2);
|
|
TGGePoly2D polyOld1(poly1),polyOld2(poly2);
|
|
polyOld1.Compress();
|
|
polyOld2.Compress();
|
|
TGGePoly2DToTGPLine2D(polyOld1,newPoly1);
|
|
TGGePoly2DToTGPLine2D(polyOld2,newPoly2);
|
|
|
|
TGRegionEx2D region1(newPoly1),region2(newPoly2);
|
|
if (!region1.IsValid() || !region2.IsValid())
|
|
{
|
|
return RTERROR;
|
|
}
|
|
TGObjectList res;
|
|
region1.SubtractBy(region2,res);
|
|
for (res.MoveToFirst();!res.IsOut();res.MoveToNext())
|
|
{
|
|
TGObject *pObj = res.GetCurData();
|
|
if (IS_CLASS(pObj,TGRegion2D))
|
|
{
|
|
TGRegion2D *pRegion = (TGRegion2D*)pObj;
|
|
TGMLine2D* pMLine = pRegion->Outline().PLinearize();
|
|
TGGePoly2D *pNewPoly = new TGGePoly2D(1);
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pMLine,*pNewPoly);
|
|
delete pMLine;
|
|
|
|
//add by xlc on 100813 消除重合点,解决墙体造型和弧墙加粗不显示的问题
|
|
pNewPoly->Compress(false);
|
|
|
|
lstResult.Append(pNewPoly);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TGPLine2D newPoly1,newPoly2;
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly1,newPoly1);
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly2,newPoly2);
|
|
TGRegionEx2D region1(newPoly1),region2(newPoly2);
|
|
if (!region1.IsValid() || !region2.IsValid())
|
|
{
|
|
return RTERROR;
|
|
}
|
|
TGObjectList res;
|
|
region1.SubtractBy(region2,res);
|
|
for (res.MoveToFirst();!res.IsOut();res.MoveToNext())
|
|
{
|
|
TGObject *pObj = res.GetCurData();
|
|
if (IS_CLASS(pObj,TGRegion2D))
|
|
{
|
|
TGRegion2D *pRegion = (TGRegion2D*)pObj;
|
|
TGMLine2D* pMLine = pRegion->Outline().PLinearize();
|
|
TGGePoly2D *pNewPoly = new TGGePoly2D(1);
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pMLine,*pNewPoly);
|
|
delete pMLine;
|
|
lstResult.Append(pNewPoly);
|
|
}
|
|
}
|
|
}
|
|
return RTNORM;
|
|
}
|
|
|
|
void TchSubExport::Subtract(TDPtrList<TGGeRegion2D> &lst1,const TDPtrList<TGGeRegion2D> &lst2)
|
|
{
|
|
TGObjectList oList1,oList2,oList3;
|
|
for (long i = 0;i<lst1.Length();i++)
|
|
{
|
|
TGRegion2D *pRegion = TchSubExport::TGGeRegion2DToTGRegion2D(*lst1[i]);
|
|
if (pRegion != NULL)
|
|
{
|
|
oList1<<pRegion;
|
|
}
|
|
}
|
|
|
|
for (i = 0;i<lst2.Length();i++)
|
|
{
|
|
TGRegion2D *pRegion = TchSubExport::TGGeRegion2DToTGRegion2D(lst2[i]);
|
|
if (pRegion != NULL)
|
|
{
|
|
oList2<<pRegion;
|
|
}
|
|
}
|
|
oList1.SubtractBy(oList2,oList3);
|
|
|
|
lst1.Reset();
|
|
for (i = 0;i<oList3.GetLength();i++)
|
|
{
|
|
TGGeRegion2D *pRegion = TchSubExport::TGRegion2DToTGGeRegion2D((const TGRegion2D&)(*oList3[i]));
|
|
if (pRegion != NULL)
|
|
{
|
|
lst1.Append(pRegion);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void TchSubExport::Union(TDPtrList<TGGeRegion2D> &lst1)
|
|
{
|
|
TGObjectList oList;
|
|
for (long i = 0; i < lst1.Length(); i++)
|
|
{
|
|
TGRegion2D *pRegion = TchSubExport::TGGeRegion2DToTGRegion2D(*lst1[i]);
|
|
if (pRegion != NULL)
|
|
{
|
|
oList << pRegion;
|
|
}
|
|
}
|
|
lst1.Reset();
|
|
|
|
oList.Union();
|
|
|
|
for (i = 0; i < oList.GetLength(); i++)
|
|
{
|
|
TGGeRegion2D *pRegion = TchSubExport::TGRegion2DToTGGeRegion2D((const TGRegion2D&)(*oList[i]));
|
|
if (pRegion != NULL)
|
|
{
|
|
lst1.Append(pRegion);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 区域的并
|
|
// what? poly1+poly2 = ?
|
|
// Modify on 2002/11/15解决2个完全一样的poly的并集问题
|
|
int TchSubExport::Union(const TGGePoly2D &poly1, const TGGePoly2D &poly2, TDPtrList<TGGePoly2D> &lstResult)
|
|
{
|
|
if (g_nProductId != kTSUN)
|
|
{
|
|
//注意:日照计算时不需要启动这两行
|
|
TPushMemVar<double> vPrec(g_distZero,_DIST_SNAP);
|
|
TPushMemVar<double> vPrec1(g_fZero,1E-6);
|
|
|
|
TGPLine2D newPoly1,newPoly2;
|
|
// modify by xlc on 101105 在当前精度下压缩区域,解决在此精度下区域边界有重合点不合法的问题
|
|
//TchSubExport::TGGePoly2DToTGPLine2D(poly1,newPoly1);
|
|
//TchSubExport::TGGePoly2DToTGPLine2D(poly2,newPoly2);
|
|
TGGePoly2D polyOld1(poly1),polyOld2(poly2);
|
|
polyOld1.Compress();
|
|
polyOld2.Compress();
|
|
TGGePoly2DToTGPLine2D(polyOld1,newPoly1);
|
|
TGGePoly2DToTGPLine2D(polyOld2,newPoly2);
|
|
|
|
TGRegionEx2D region1(newPoly1),region2(newPoly2);
|
|
if (!region1.IsValid() || !region2.IsValid())
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
TGRegion2D *pRegion = region1.Union(region2);
|
|
if (pRegion != NULL)
|
|
{
|
|
TGMLine2D* pMLine = pRegion->Outline().PLinearize();
|
|
TGGePoly2D *pNewPoly = new TGGePoly2D(1);
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pMLine,*pNewPoly);
|
|
delete pMLine;
|
|
delete pRegion;
|
|
lstResult.Append(pNewPoly);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TGPLine2D newPoly1,newPoly2;
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly1,newPoly1);
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly2,newPoly2);
|
|
TGRegionEx2D region1(newPoly1),region2(newPoly2);
|
|
|
|
if (!region1.IsValid() || !region2.IsValid())
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
TGRegion2D *pRegion = region1.Union(region2);
|
|
if (pRegion != NULL)
|
|
{
|
|
TGMLine2D* pMLine = pRegion->Outline().PLinearize();
|
|
TGGePoly2D *pNewPoly = new TGGePoly2D(1);
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pMLine,*pNewPoly);
|
|
delete pMLine;
|
|
delete pRegion;
|
|
lstResult.Append(pNewPoly);
|
|
}
|
|
}
|
|
|
|
return RTNORM;
|
|
}
|
|
|
|
// Pline表示的区域的交集
|
|
int TchSubExport::Intersect(const TGGePoly2D &poly1, const TGGePoly2D &poly2, TDPtrList<TGGePoly2D> &lstDest)
|
|
{
|
|
//注意:日照计算时不需要启动这两行
|
|
// sg modify 091202,建议恢复下面这两行,7.5时,以下两行是打开的,布尔运算相对稳定
|
|
if (g_nProductId != kTSUN)
|
|
{
|
|
TPushMemVar<double> vPrec(g_distZero,_DIST_SNAP);
|
|
TPushMemVar<double> vPrec1(g_fZero,1E-6);
|
|
|
|
TGPLine2D newPoly1,newPoly2;
|
|
|
|
// modify by xlc on 101105 在当前精度下压缩区域,解决在此精度下区域边界有重合点不合法的问题
|
|
//TGGePoly2DToTGPLine2D(poly1,newPoly1);
|
|
//TGGePoly2DToTGPLine2D(poly2,newPoly2);
|
|
TGGePoly2D polyOld1(poly1),polyOld2(poly2);
|
|
polyOld1.Compress();
|
|
polyOld2.Compress();
|
|
TGGePoly2DToTGPLine2D(polyOld1,newPoly1);
|
|
TGGePoly2DToTGPLine2D(polyOld2,newPoly2);
|
|
|
|
TGRegionEx2D region1(newPoly1),region2(newPoly2);
|
|
if (!region1.IsValid()||!region2.IsValid())
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
TGObjectList res;
|
|
region1.Inter(region2,res);
|
|
for (res.MoveToFirst();!res.IsOut();res.MoveToNext())
|
|
{
|
|
TGObject *pObj = res.GetCurData();
|
|
if (IS_CLASS(pObj,TGRegion2D))
|
|
{
|
|
TGRegion2D *pRegion = (TGRegion2D*)pObj;
|
|
TGMLine2D* pMLine = pRegion->Outline().PLinearize();
|
|
|
|
TGGePoly2D *pNewPoly = new TGGePoly2D(1);
|
|
TGMLine2DToTGGePoly2D(*pMLine,*pNewPoly);
|
|
|
|
delete pMLine;
|
|
lstDest.Append(pNewPoly);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TGPLine2D newPoly1,newPoly2;
|
|
TGGePoly2DToTGPLine2D(poly1,newPoly1);
|
|
TGGePoly2DToTGPLine2D(poly2,newPoly2);
|
|
|
|
TGRegionEx2D region1(newPoly1),region2(newPoly2);
|
|
if (!region1.IsValid()||!region2.IsValid())
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
TGObjectList res;
|
|
region1.Inter(region2,res);
|
|
for (res.MoveToFirst();!res.IsOut();res.MoveToNext())
|
|
{
|
|
TGObject *pObj = res.GetCurData();
|
|
if (IS_CLASS(pObj,TGRegion2D))
|
|
{
|
|
TGRegion2D *pRegion = (TGRegion2D*)pObj;
|
|
TGMLine2D* pMLine = pRegion->Outline().PLinearize();
|
|
|
|
TGGePoly2D *pNewPoly = new TGGePoly2D(1);
|
|
TGMLine2DToTGGePoly2D(*pMLine,*pNewPoly);
|
|
|
|
delete pMLine;
|
|
lstDest.Append(pNewPoly);
|
|
}
|
|
}
|
|
}
|
|
return RTNORM;
|
|
}
|
|
|
|
void TchSubExport::Intersect(const TGGeRegion2D &r1,const TGGeRegion2D &r2,TDPtrList<TGGeRegion2D> &res)
|
|
{
|
|
TGRegion2D *pRegion1 = TchSubExport::TGGeRegion2DToTGRegion2D(r1);
|
|
if (pRegion1 != NULL)
|
|
{
|
|
TGRegion2D *pRegion2 = TchSubExport::TGGeRegion2DToTGRegion2D(r2);
|
|
if (pRegion2 != NULL)
|
|
{
|
|
TGObjectList oList;
|
|
pRegion1->Inter(*pRegion2,oList);
|
|
for (long i = 0;i<oList.GetLength();i++)
|
|
{
|
|
TGGeRegion2D *pRegion = TchSubExport::TGRegion2DToTGGeRegion2D((const TGRegion2D&)*oList[i]);
|
|
if (pRegion != NULL)
|
|
{
|
|
res.Append(pRegion);
|
|
}
|
|
}
|
|
|
|
delete pRegion2;
|
|
}
|
|
delete pRegion1;
|
|
}
|
|
}
|
|
|
|
TGRegion2D* TchSubExport::TGGeRegion2DToTGRegion2D(const TGGeRegion2D&r1)
|
|
{
|
|
TGObjectList oList;
|
|
TGPLine2D*pNewPoly = new TGPLine2D;
|
|
|
|
TchSubExport::TGGePoly2DToTGPLine2D(r1,*pNewPoly);
|
|
oList << (TGObject*)pNewPoly;
|
|
|
|
for (long i = 0;i<r1.GetHoleNum();i++)
|
|
{
|
|
pNewPoly = new TGPLine2D;
|
|
TchSubExport::TGGePoly2DToTGPLine2D(r1.GetHole(i),*pNewPoly);
|
|
oList<<pNewPoly;
|
|
}
|
|
|
|
TGRegion2D* pNewRegion = new TGRegionEx2D(oList,true);//自动纠正方向
|
|
|
|
bool bHasArc = r1.HasArcSegment() == TRUE;
|
|
if (!bHasArc)
|
|
{
|
|
for (long i = 0;i<r1.GetHoleNum();i++)
|
|
{
|
|
if (r1.GetHole(i).HasArcSegment())
|
|
{
|
|
bHasArc = true;
|
|
}
|
|
}
|
|
}
|
|
if (!bHasArc)
|
|
{
|
|
TGRegion2D *pPolygon = pNewRegion->MLinearize();
|
|
if (pPolygon != NULL)
|
|
{
|
|
delete pNewRegion;
|
|
pNewRegion = pPolygon;
|
|
}
|
|
}
|
|
|
|
if (pNewRegion->IsValid())
|
|
{
|
|
return pNewRegion;
|
|
}
|
|
else
|
|
{
|
|
delete pNewRegion;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
//GObject转换为对应AcDbEntity
|
|
AcDbEntity * TchSubExport::Obj2Entity(TGObject *pObj)
|
|
{
|
|
if (pObj == NULL)
|
|
{
|
|
return NULL;
|
|
}
|
|
long i = 0;
|
|
switch(pObj->GetClassID())
|
|
{
|
|
case CID_GPoint2D:
|
|
{
|
|
TGPoint2D* pPt = (TGPoint2D*)pObj;
|
|
return new AcDbPoint(TchSubPrivate::GP3AP(*pPt));
|
|
}
|
|
case CID_GLineSeg2D:
|
|
{
|
|
TPGeGLineSeg2D *pSeg = (TPGeGLineSeg2D*)pObj;
|
|
return new AcDbLine(GP3AP(pSeg->GetStartPoint()),GP3AP(pSeg->GetEndPoint()));
|
|
}
|
|
case CID_GCircle2D:
|
|
{
|
|
TPGeCircle2D *pCircle = (TPGeCircle2D*)pObj;
|
|
return new AcDbCircle(GP3AP(pCircle->center), pCircle->IsClockwise() ? AcGeVector3d(0,0,-1) : AcGeVector3d(0,0,1),pCircle->r);
|
|
}
|
|
case CID_GArc2D:
|
|
{
|
|
TPGeArc2D *pArc = (TPGeArc2D*)pObj;
|
|
if (pArc->IsClockwise())
|
|
{
|
|
return new AcDbArc(GP3AP(pArc->circle.center),pArc->circle.r,-pArc->GetEndAngle(),-pArc->startAngle);
|
|
}
|
|
else
|
|
{
|
|
return new AcDbArc(GP3AP(pArc->circle.center),pArc->circle.r,pArc->startAngle,pArc->GetEndAngle());
|
|
}
|
|
}
|
|
case CID_GMLine2D:
|
|
{
|
|
TGMLine2D*pMLine = (TGMLine2D*)pObj;
|
|
AcDbPolyline*pLine = new AcDbPolyline(pMLine->GetVertexNum());
|
|
for (i = 0;i<pMLine->GetVertexNum();i++)
|
|
{
|
|
pLine->addVertexAt(i,TchSubPrivate::GP2AP((*pMLine)[i]));
|
|
}
|
|
pLine->setClosed(pMLine->IsClosed()?Adesk::kTrue:Adesk::kFalse);
|
|
return pLine;
|
|
}
|
|
case CID_GPLine2D:
|
|
{
|
|
TGPLine2D*pPLine = (TGPLine2D*)pObj;
|
|
AcDbPolyline*pLine = new AcDbPolyline(pPLine->GetVertexNum());
|
|
for (i = 0;i<pPLine->GetVertexNum();i++)
|
|
{
|
|
pLine->addVertexAt(i,GP2AP((*pPLine)[i]),tan(((*pPLine)(i)/4)));
|
|
}
|
|
pLine->setClosed(pPLine->IsClosed()?Adesk::kTrue:Adesk::kFalse);
|
|
return pLine;
|
|
}
|
|
break;
|
|
case CID_GPolygon2D:
|
|
{
|
|
TGPolygon2D*pPoly = (TGPolygon2D*)pObj;
|
|
TGMLine2D *pMLine = &(pPoly->Outline());
|
|
AcDbPolyline*pLine = new AcDbPolyline(pMLine->GetVertexNum());
|
|
|
|
for (i = 0;i<pMLine->GetVertexNum();i++)
|
|
{
|
|
pLine->addVertexAt(i,GP2AP((*pMLine)[i]));
|
|
}
|
|
|
|
pLine->setClosed(pMLine->IsClosed()?Adesk::kTrue:Adesk::kFalse);
|
|
return pLine;
|
|
}
|
|
break;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
void TchSubExport::PolyClip(const TDPtrList<TGGePoly2D> &ss,const TGGePoly2D& poly,TDPtrList<TGGePoly2D> &ssIn,TDPtrList<TGGePoly2D> &ssOut,TDPtrList<TGGePoly2D> &ssEdge)
|
|
{
|
|
TGPLine2D polyClip;
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly,polyClip);
|
|
|
|
TGObjectList lstCurve,lstIn,lstEdge,lstOut;
|
|
for (long i = 0;i<ss.Length();i++)
|
|
{
|
|
const TGGePoly2D& poly = ss[i];
|
|
TGPLine2D *pNewPoly = new TGPLine2D;
|
|
TchSubExport::TGGePoly2DToTGPLine2D(poly,*pNewPoly);
|
|
lstCurve<<pNewPoly;
|
|
}
|
|
lstCurve.CutBy(polyClip,lstIn,lstOut,lstEdge);
|
|
|
|
for (lstIn.MoveToFirst();!lstIn.IsOut();lstIn.MoveToNext())
|
|
{
|
|
TGMLine2D *pMLine = lstIn.GetCurCurve2D().PLinearize();
|
|
TGGePoly2D *pNewPoly = new TGGePoly2D;
|
|
ssIn.Append(pNewPoly);
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pMLine,*pNewPoly);
|
|
delete pMLine;
|
|
}
|
|
|
|
for (lstOut.MoveToFirst();!lstOut.IsOut();lstOut.MoveToNext())
|
|
{
|
|
TGMLine2D *pMLine = lstOut.GetCurCurve2D().PLinearize();
|
|
TGGePoly2D *pNewPoly = new TGGePoly2D;
|
|
ssOut.Append(pNewPoly);
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pMLine,*pNewPoly);
|
|
delete pMLine;
|
|
}
|
|
|
|
for (lstEdge.MoveToFirst();!lstEdge.IsOut();lstEdge.MoveToNext())
|
|
{
|
|
TGMLine2D *pMLine = lstEdge.GetCurCurve2D().PLinearize();
|
|
TGGePoly2D *pNewPoly = new TGGePoly2D;
|
|
ssEdge.Append(pNewPoly);
|
|
TchSubExport::TGMLine2DToTGGePoly2D(*pMLine,*pNewPoly);
|
|
delete pMLine;
|
|
}
|
|
}
|
|
|
|
bool TchSubExport::PrepareFit(TSqTable2<TADSGePoint3d> &ptArray0,TPGeFitGraph&graphFit)
|
|
{
|
|
long rowNum = ptArray0.GetLength(),colNum = ptArray0[0].GetLength();
|
|
acedSetStatusBarProgressMeter(_T("曲线拟合"), 0, rowNum*2-1);
|
|
|
|
//构造节点
|
|
TSqTable2<TPGeDscPoint*> ptArray;
|
|
ptArray.Realloc(rowNum,colNum,false);
|
|
for (long i = 0;i<rowNum;i++)
|
|
{
|
|
for (long j = 0;j<colNum;j++)
|
|
{
|
|
TADSGePoint3d& pt = ptArray0[i][j];
|
|
ptArray[i][j] = new TPGeDscPoint(pt.x,pt.y,pt.z);
|
|
graphFit.AppendPoint(ptArray[i][j]);
|
|
}
|
|
}
|
|
|
|
//构造边
|
|
TSqTable2<TPGeDscEdge*> eArrayX(rowNum,colNum-1),eArrayY(rowNum-1,colNum),eArrayXY(rowNum-1,colNum-1);
|
|
for (i = 0;i<rowNum;i++)
|
|
{
|
|
if (acedUsrBrk())
|
|
{
|
|
acedRestoreStatusBar();
|
|
return false;
|
|
}
|
|
acedSetStatusBarProgressMeterPos(i);
|
|
|
|
for (long j = 0;j<colNum;j++)
|
|
{
|
|
TPGeDscPoint*pPt = ptArray[i][j];
|
|
|
|
if (j+1<colNum)
|
|
{
|
|
TPGeDscEdge*pEdge = new TPGeDscEdge(pPt,ptArray[i][j+1]);
|
|
graphFit.AppendEdge(pEdge);
|
|
eArrayX[i][j] = pEdge;
|
|
}
|
|
if (i+1<rowNum)
|
|
{
|
|
TPGeDscEdge*pEdge = new TPGeDscEdge(pPt,ptArray[i+1][j]);
|
|
graphFit.AppendEdge(pEdge);
|
|
eArrayY[i][j] = pEdge;
|
|
}
|
|
if (i+1<rowNum&&j+1<colNum)
|
|
{
|
|
TPGeDscEdge*pEdge = new TPGeDscEdge(pPt,ptArray[i+1][j+1]);
|
|
graphFit.AppendEdge(pEdge);
|
|
eArrayXY[i][j] = pEdge;
|
|
}
|
|
}
|
|
}
|
|
|
|
//构造三角形
|
|
rowNum--;
|
|
colNum--;
|
|
for (i = 0;i<rowNum;i++)
|
|
{
|
|
if (acedUsrBrk())
|
|
{
|
|
acedRestoreStatusBar();
|
|
return false;
|
|
}
|
|
acedSetStatusBarProgressMeterPos(i+rowNum);
|
|
|
|
for (long j = 0;j<colNum;j++)
|
|
{
|
|
graphFit.AppendTriangle(eArrayX[i][j],eArrayY[i][j+1],eArrayXY[i][j]);
|
|
graphFit.AppendTriangle(eArrayX[i+1][j],eArrayY[i][j],eArrayXY[i][j]);
|
|
}
|
|
eArrayX[i].Clear();
|
|
eArrayY[i].Clear();
|
|
eArrayXY[i].Clear();
|
|
}
|
|
acedRestoreStatusBar();
|
|
return true;
|
|
}
|
|
|
|
//准备拟合
|
|
bool TchSubExport::PrepareFit(TADSGePoint3d ptMin,double nDist,int rowNum,int colNum,TSqTable2<float>& array,TPGeFitGraph&graphFit)
|
|
|
|
{
|
|
//构造节点
|
|
TSqTable2<TPGeDscPoint*> ptArray(rowNum,colNum);
|
|
for (long i = 0;i<rowNum;i++)
|
|
{
|
|
for (long j = 0;j<colNum;j++)
|
|
{
|
|
TPGeDscPoint* pPt = new TPGeDscPoint(ptMin.x+j*nDist,ptMin.y+i*nDist,array[i][j]);
|
|
graphFit.AppendPoint(pPt);
|
|
ptArray[i][j] = pPt;
|
|
}
|
|
array[i].Clear();
|
|
}
|
|
array.Clear();
|
|
|
|
acedSetStatusBarProgressMeter(_T("曲线拟合"), 0, rowNum*2-1);
|
|
//构造边
|
|
TSqTable2<TPGeDscEdge*> eArrayX(rowNum,colNum-1),eArrayY(rowNum-1,colNum),eArrayXY(rowNum-1,colNum-1);
|
|
for (i = 0;i<rowNum;i++)
|
|
{
|
|
if (acedUsrBrk())
|
|
{
|
|
acedRestoreStatusBar();
|
|
return false;
|
|
}
|
|
acedSetStatusBarProgressMeterPos(i);
|
|
|
|
for (long j = 0;j<colNum;j++)
|
|
{
|
|
TPGeDscPoint*pPt = ptArray[i][j];
|
|
|
|
if (j+1<colNum)
|
|
{
|
|
TPGeDscEdge*pEdge = new TPGeDscEdge(pPt,ptArray[i][j+1]);
|
|
graphFit.AppendEdge(pEdge);
|
|
eArrayX[i][j] = pEdge;
|
|
}
|
|
if (i+1<rowNum)
|
|
{
|
|
TPGeDscEdge*pEdge = new TPGeDscEdge(pPt,ptArray[i+1][j]);
|
|
graphFit.AppendEdge(pEdge);
|
|
eArrayY[i][j] = pEdge;
|
|
}
|
|
if (i+1<rowNum&&j+1<colNum)
|
|
{
|
|
TPGeDscEdge*pEdge = new TPGeDscEdge(pPt,ptArray[i+1][j+1]);
|
|
graphFit.AppendEdge(pEdge);
|
|
eArrayXY[i][j] = pEdge;
|
|
}
|
|
}
|
|
ptArray[i].Clear();
|
|
}
|
|
ptArray.Clear();
|
|
|
|
//构造三角形
|
|
rowNum--;
|
|
colNum--;
|
|
for (i = 0;i<rowNum;i++)
|
|
{
|
|
if (acedUsrBrk())
|
|
{
|
|
acedRestoreStatusBar();
|
|
return false;
|
|
}
|
|
acedSetStatusBarProgressMeterPos(i+rowNum);
|
|
|
|
for (long j = 0;j<colNum;j++)
|
|
{
|
|
graphFit.AppendTriangle(eArrayX[i][j],eArrayY[i][j+1],eArrayXY[i][j]);
|
|
graphFit.AppendTriangle(eArrayX[i+1][j],eArrayY[i][j],eArrayXY[i][j]);
|
|
}
|
|
eArrayX[i].Clear();
|
|
eArrayY[i].Clear();
|
|
eArrayXY[i].Clear();
|
|
}
|
|
acedRestoreStatusBar();
|
|
return true;
|
|
}
|
|
|
|
bool TchSubExport::LB_Clip(const double &left,const double &top,const double &right,const double& bot,
|
|
const double &x1,const double &y1,const double &dx,const double &dy,
|
|
double &tMin,double &tMax)
|
|
{
|
|
double tl = 0.0,tu = 1.0;
|
|
if (TchSubPrivate::LB_IsOk(dx,left - x1,tl,tu))
|
|
{
|
|
if (TchSubPrivate::LB_IsOk(-dx,x1 - right,tl,tu))
|
|
{
|
|
if (TchSubPrivate::LB_IsOk(dy,bot - y1,tl,tu))
|
|
{
|
|
if (TchSubPrivate::LB_IsOk(-dy,y1 - top,tl,tu))
|
|
{
|
|
tMin = tl;
|
|
tMax = tu;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|