963 lines
29 KiB
C++
963 lines
29 KiB
C++
#include "stdafx.h"
|
|
#include "ParallelDimStyle.h"
|
|
#include "TParallelDimJig.h"
|
|
#include "actrans.h"
|
|
#include "LayerSiftDlgEx.h"
|
|
#include "TchGlobalFunc.h"
|
|
extern int GetFullOsMode(int nFlagsAdd);
|
|
extern CString g_sSaveFileName; //保存文件名,需要在创建对话框之前进行赋值***********************
|
|
extern CString g_sdefaultLayerName; //默认图层名字符串 _T("ROAD_DOTE\r\nROAD");需要在创建对话框之前进行赋值***********************
|
|
extern CStringArray g_aryLayerName; //默认图层名 需要在创建对话框之前进行赋值***********************
|
|
extern void GetLayerNameByKeyWord(CStringArray& aryLayer, CStringArray &aryKeyWord); //根据指定的图层关键字查找图层名
|
|
extern TARCH_IMPEXP BOOL g_bTextDefaultLayer; // TRUE为使用默认图层
|
|
CParallelDimStyle::CParallelDimStyle(void)
|
|
{
|
|
}
|
|
|
|
|
|
CParallelDimStyle::~CParallelDimStyle(void)
|
|
{
|
|
}
|
|
|
|
void CParallelDimStyle::Get2DCurveFromBlock(AcDbBlockTableRecord &blockRec, ads_matrix matForInsert, TDPtrList<TGGeCurveSegment> &lstResult)
|
|
{
|
|
AcGeMatrix3d mat;
|
|
memcpy(&mat, matForInsert, sizeof(ads_matrix));
|
|
|
|
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
|
Acad::ErrorStatus es = blockRec.newIterator(pBlockIterator, Adesk::kTrue, Adesk::kFalse);
|
|
ASSERT(es == Acad::eOk && !!pBlockIterator);
|
|
|
|
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
|
|
{
|
|
AcDbEntity *pEntity;
|
|
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead, Adesk::kTrue);
|
|
ASSERT(es == Acad::eOk);
|
|
if (pEntity->visibility() == AcDb::kInvisible)
|
|
{
|
|
pEntity->close();
|
|
continue;
|
|
}
|
|
if (pEntity->isKindOf(AcDbBlockReference::desc()))
|
|
{ //嵌套图块
|
|
AcDbBlockReference *pInsert = AcDbBlockReference::cast(pEntity);
|
|
ASSERT(pInsert);
|
|
TADSGePoint3d ptLoc = pInsert->position();
|
|
double nRot = pInsert->rotation();
|
|
AcGeScale3d scale = pInsert->scaleFactors();
|
|
AcDbObjectId idBlock = pInsert->blockTableRecord();
|
|
TAcDbObjectPtr objBlock(idBlock, AcDb::kForRead);
|
|
ASSERT(!!objBlock);
|
|
AcDbBlockTableRecord *pRec = AcDbBlockTableRecord::cast(objBlock.m_pObject);
|
|
ASSERT(pRec);
|
|
TADSGePoint3d ptBase = pRec->origin();
|
|
ads_matrix mat1, mat2;
|
|
ConstructMatrix(ptBase, ptLoc, scale[0], scale[1], scale[2], nRot, mat1);
|
|
SetToProductMatrix(matForInsert, mat1, mat2);
|
|
Get2DCurveFromBlock(*pRec, mat2, lstResult);
|
|
}
|
|
else
|
|
{
|
|
if (m_lstLayer.IsEmpty())
|
|
{
|
|
AnalysisTgEntToLine(pEntity, lstResult);
|
|
}
|
|
else
|
|
{
|
|
CString strLayer = pEntity->layer();
|
|
if(m_lstLayer.Find(strLayer))
|
|
AnalysisTgEntToLine(pEntity, lstResult);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
pEntity->close();
|
|
}
|
|
delete pBlockIterator;
|
|
}
|
|
void CParallelDimStyle::AnalysisTgEntToLine(const AcDbEntity* pEnt, TDPtrList<TGGeCurveSegment> &lstResult)
|
|
{
|
|
if (pEnt->isKindOf(AcDbLine::desc()))
|
|
{
|
|
AcDbLine *pLine = AcDbLine::cast(pEnt);
|
|
lstResult.Append(new TGGeCurveSegment(pLine->startPoint(), pLine->endPoint(), 0.0));
|
|
}
|
|
else if(pEnt->isKindOf(AcDbArc::desc()))
|
|
{
|
|
AcDbArc *pArc = AcDbArc::cast(pEnt);
|
|
AcGePoint3d ptStart, ptEnd, ptThird;
|
|
pArc->getStartPoint(ptStart);
|
|
pArc->getEndPoint(ptEnd);
|
|
pArc->getPointAtDist(0.5 * (ptStart.distanceTo(ptEnd)), ptThird);
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
*pSeg = TGGeArc(ptStart, ptThird, ptEnd);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
else if(pEnt->isKindOf(AcDbCircle::desc()))
|
|
{
|
|
TEntitySet ent;
|
|
if(acdbGetAdsName(ent.name, pEnt->objectId()) == Acad::eOk)
|
|
{
|
|
TGGePoly2D poly(ent);
|
|
for (int i = 0; i < poly.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
poly.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
}
|
|
else if (pEnt->isKindOf(AcDbPolyline::desc()))
|
|
{
|
|
TEntitySet ent;
|
|
if(acdbGetAdsName(ent.name, pEnt->objectId()) == Acad::eOk)
|
|
{
|
|
TGGePoly2D poly(ent);
|
|
for (int i = 0; i < poly.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
poly.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
}
|
|
else if (pEnt->isKindOf(TDbWall::desc()))
|
|
{
|
|
TGGePoly2D poly;
|
|
TDbWall* pWall = TDbWall::cast(pEnt);
|
|
pWall->GetOutlinePoly1(pWall->GetElevation(), poly);
|
|
for (int i = 0; i < poly.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
poly.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
else if (pEnt->isKindOf(TDbColumn::desc()))
|
|
{
|
|
TGGePoly2D poly;
|
|
TDbColumn* pColumn = TDbColumn::cast(pEnt);
|
|
poly = pColumn->GetOutlinePoly();
|
|
for (int i = 0; i < poly.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
poly.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
else if (pEnt->isKindOf(TDbBalcony::desc()))//阳台
|
|
{
|
|
TGGePoly2D polyOut, polyIn;
|
|
TDbBalcony* pBalcony = TDbBalcony::cast(pEnt);
|
|
polyOut = pBalcony->GetOutline();
|
|
pBalcony->GetPolyIn(polyIn);
|
|
polyIn.SetElevation(0.0);
|
|
polyOut.SetElevation(0.0);
|
|
for (int i = 0; i < polyOut.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
polyOut.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
for (int n = 0; n < polyIn.TotalSegments(); n++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
polyIn.Nth(n, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
else if (pEnt->isKindOf(TDbApron::desc()))
|
|
{
|
|
TGGePoly2D apronPolyIn, apronPolyOut;
|
|
Array<int> aryIndex, aryShow;
|
|
TDbApron* pApron = TDbApron::cast(pEnt);
|
|
pApron->Get2DInPoly(apronPolyIn);
|
|
pApron->Get2DOutPoly(apronPolyOut, aryIndex, aryShow);
|
|
for (int i = 0; i < apronPolyIn.TotalSegments(); ++i)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
apronPolyIn.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
|
|
for (int n = 0; n < apronPolyOut.TotalSegments(); ++n)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
apronPolyOut.Nth(n, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
else if (pEnt->isKindOf(TDbStep::desc()))//台阶
|
|
{
|
|
TGGePoly2D poly;
|
|
TDbStep* pStep = TDbStep::cast(pEnt);
|
|
pStep->GetOutline2d(poly);
|
|
poly.SetElevation(0.0);
|
|
for (int i = 0; i < poly.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
poly.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
else if (pEnt->isKindOf(TDbSlab::desc()))//板
|
|
{
|
|
TGGePoly2D poly;
|
|
TDbSlab* pSLab = TDbSlab::cast(pEnt);
|
|
poly = pSLab->GetOutline();
|
|
for (int i = 0; i < poly.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
poly.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
else if (pEnt->isKindOf(TDbVertSlab::desc()))//竖板
|
|
{
|
|
XPoint ptStart, ptEnd, ptLftSt, ptLeftEnd, ptRightSt, ptRightEnd;
|
|
XLine midLine, leftLine, rightLine;
|
|
TDbVertSlab* pVertSLab = TDbVertSlab::cast(pEnt);
|
|
ptStart = pVertSLab->GetStartPoint();
|
|
ptEnd = pVertSLab->GetEndPoint();
|
|
midLine.SetStartPoint(ptStart);
|
|
midLine.SetEndPoint(ptEnd);
|
|
leftLine = midLine.Offset(0.5 * pVertSLab->GetThickness());
|
|
rightLine = midLine.Offset(-0.5 * pVertSLab->GetThickness());
|
|
leftLine.GetStartPoint(ptLftSt);
|
|
leftLine.GetEndPoint(ptLeftEnd);
|
|
rightLine.GetStartPoint(ptRightSt);
|
|
rightLine.GetEndPoint(ptRightEnd);
|
|
lstResult.Append(new TGGeCurveSegment(ptLftSt, ptLeftEnd, 0.0));
|
|
lstResult.Append(new TGGeCurveSegment(ptRightSt, ptRightEnd, 0.0));
|
|
lstResult.Append(new TGGeCurveSegment(ptLftSt, ptRightSt, 0.0));
|
|
lstResult.Append(new TGGeCurveSegment(ptLeftEnd, ptRightEnd, 0.0));
|
|
}
|
|
else if (pEnt->isKindOf(TDbAscent::desc()))//坡道
|
|
{
|
|
XPoint ptLowLeft, ptLowRight, ptUpLeft, ptUpRight;
|
|
XLine midLine, leftLine, rightLine;
|
|
TDbAscent* pAscent = TDbAscent::cast(pEnt);
|
|
ptLowLeft = pAscent->GetLowLeft2d();
|
|
ptLowRight = pAscent->GetLowRight2d();
|
|
ptUpLeft = pAscent->GetUpLeft2d();
|
|
ptUpRight = pAscent->GetUpRight2d();
|
|
lstResult.Append(new TGGeCurveSegment(ptLowLeft, ptLowRight, 0.0));
|
|
lstResult.Append(new TGGeCurveSegment(ptUpLeft, ptUpRight, 0.0));
|
|
lstResult.Append(new TGGeCurveSegment(ptLowLeft, ptUpLeft, 0.0));
|
|
lstResult.Append(new TGGeCurveSegment(ptLowRight, ptUpRight, 0.0));
|
|
}
|
|
else if (pEnt->isKindOf(TDbOpening::desc()))//窗户
|
|
{
|
|
TGGePoly2D poly;
|
|
TDbOpening* pOpenning = TDbOpening::cast(pEnt);
|
|
pOpenning->m_nQuadrant;
|
|
TADSGePoint3d ptDir;
|
|
TGGeCurveSegment segBayWin;
|
|
if(pOpenning->m_pBayWin)//凸窗
|
|
{
|
|
OPENOBJ_BEGIN(pOpenning->m_nIdOfWall, AcDb::kForRead, TDbWall, pWall);
|
|
if (pWall)
|
|
{
|
|
XPoint ptLoc = pOpenning->m_ptLocation;
|
|
ptLoc.z = pOpenning->m_ptLocation.z;
|
|
double nWallThick = pWall->GetWidth(4);
|
|
double nExtDir = pOpenning->m_nRotation + (pOpenning->m_nQuadrant<2? PI/2.0 : -PI/2.0);
|
|
|
|
ads_polar(ptLoc, nExtDir, 10000, ptDir);
|
|
double dWallInsut = 0.0;
|
|
|
|
int nSide = pWall->OnWhichSide(ptDir);
|
|
if (pWall->IsInsulateOnSide(nSide)) // 得到外保温厚度
|
|
{
|
|
dWallInsut = pWall->GetInsulateThick(nSide);
|
|
}
|
|
|
|
DList<XPoly2D> polyCurves;
|
|
pOpenning->m_pBayWin->GetPolyCurve(ptLoc, nExtDir, pOpenning->m_nWidth, nWallThick, pOpenning->HasLeftSlab(), pOpenning->HasRightSlab(), polyCurves, dWallInsut);
|
|
|
|
if (polyCurves.Length() > 1)
|
|
{
|
|
/*for (int nPolyNum = 0; nPolyNum < polyCurves.Length(); ++nPolyNum)
|
|
{*/
|
|
//最外层轮廓
|
|
XPoly2D polyBay;
|
|
if (polyCurves.Length() >=3)
|
|
{
|
|
polyBay = *polyCurves.GetAt(2);
|
|
polyBay.SetElevation(0.0);
|
|
for (int i = 0; i < polyBay.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
polyBay.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
if (i == 1)
|
|
{
|
|
segBayWin = *pSeg;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
if ((pOpenning->HasLeftSlab() || pOpenning->HasRightSlab()) && pOpenning->m_pBayWin->m_nStyle==XBayWindow::BWS_RECT)
|
|
{
|
|
XPoly2D polyLeft(1),polyRight(1);
|
|
pOpenning->m_pBayWin->GetVertSlabPoly(ptLoc, nExtDir, pOpenning->m_nWidth, nWallThick, pOpenning->m_nProWinSlabWidth, polyLeft, polyRight);
|
|
if (pOpenning->HasLeftSlab())
|
|
{
|
|
polyLeft.SetElevation(0.0);
|
|
for (int i = 0; i < polyLeft.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
polyLeft.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
if (pOpenning->HasRightSlab())
|
|
{
|
|
polyRight.SetElevation(0.0);
|
|
for (int i = 0; i < polyRight.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
polyRight.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
XPoint ptOpeningLeft, ptOpeningRight;
|
|
pOpenning->GetSidePointsOnBase(ptOpeningLeft, ptOpeningRight);
|
|
AcGeVector3d vec = ptOpeningRight - ptOpeningLeft;
|
|
AcGeVector3d vecTemp = vec;
|
|
if (pOpenning->IsDoor())
|
|
{
|
|
if (pOpenning->GetKind() == TOpeningData::OP_DOORWIN)
|
|
{
|
|
XPoint ptSt, ptEnd;
|
|
if(pOpenning->m_nQuadrant == 0 || pOpenning->m_nQuadrant == 3)
|
|
{
|
|
if (pOpenning->m_nQuadrant == 0)
|
|
vec = vec.rotateBy(0.5*PI, AcGeVector3d::kZAxis);
|
|
else
|
|
vec = vec.rotateBy(-0.5*PI, AcGeVector3d::kZAxis);
|
|
|
|
ptSt = ptOpeningRight;
|
|
ptEnd = ptOpeningRight + vec * pOpenning->m_nDoorWidth / vecTemp.length();
|
|
}
|
|
if (pOpenning->m_nQuadrant == 1 || pOpenning->m_nQuadrant == 2)
|
|
{
|
|
if (pOpenning->m_nQuadrant == 1)
|
|
vec = vec.rotateBy(0.5*PI, AcGeVector3d::kZAxis);
|
|
else
|
|
vec = vec.rotateBy(-0.5*PI, AcGeVector3d::kZAxis);
|
|
ptSt = ptOpeningLeft;
|
|
ptEnd = ptOpeningLeft + vec * pOpenning->m_nDoorWidth / vecTemp.length();
|
|
}
|
|
lstResult.Append(new TGGeCurveSegment(ptSt, ptEnd, 0.0));
|
|
}
|
|
else if(pOpenning->GetKind() == TOpeningData::OP_TWODOOR)
|
|
{
|
|
XPoint ptLine1St, ptLine1End, ptLine2St, ptLine2End;
|
|
if(pOpenning->m_nQuadrant == 0 || pOpenning->m_nQuadrant == 3)
|
|
{
|
|
if (pOpenning->m_nQuadrant == 0)
|
|
vec = vec.rotateBy(0.5*PI, AcGeVector3d::kZAxis);
|
|
else
|
|
vec = vec.rotateBy(-0.5*PI, AcGeVector3d::kZAxis);
|
|
|
|
ptLine1St = ptOpeningLeft;
|
|
ptLine1End = ptOpeningLeft + vec * pOpenning->m_nDoorWidth / vecTemp.length();
|
|
|
|
ptLine2St = ptOpeningRight;
|
|
ptLine2End = ptOpeningRight + vec * (pOpenning-> m_nWidth - pOpenning->m_nDoorWidth) / vec.length();
|
|
}
|
|
if (pOpenning->m_nQuadrant == 1 || pOpenning->m_nQuadrant == 2)
|
|
{
|
|
if (pOpenning->m_nQuadrant == 1)
|
|
vec = vec.rotateBy(0.5*PI, AcGeVector3d::kZAxis);
|
|
else
|
|
vec = vec.rotateBy(-0.5*PI, AcGeVector3d::kZAxis);
|
|
ptLine1St = ptOpeningRight;
|
|
ptLine1End = ptOpeningRight + vec * pOpenning->m_nDoorWidth / vecTemp.length();
|
|
|
|
ptLine2St = ptOpeningLeft;
|
|
ptLine2End = ptOpeningLeft + vec * (pOpenning-> m_nWidth - pOpenning->m_nDoorWidth) / vec.length();
|
|
}
|
|
lstResult.Append(new TGGeCurveSegment(ptLine1St, ptLine1End, 0.0));
|
|
lstResult.Append(new TGGeCurveSegment(ptLine2St, ptLine2End, 0.0));
|
|
}
|
|
else if(pOpenning->GetKind() == TOpeningData::OP_DOOR)
|
|
{
|
|
XPoint pt1, pt2, pt3, pt4;
|
|
if(pOpenning->m_nQuadrant == 0 || pOpenning->m_nQuadrant == 3)
|
|
{
|
|
if (pOpenning->m_nQuadrant == 0)
|
|
vec = vec.rotateBy(0.5*PI, AcGeVector3d::kZAxis);
|
|
else
|
|
vec = vec.rotateBy(-0.5*PI, AcGeVector3d::kZAxis);
|
|
pt1 = ptOpeningRight;
|
|
pt2 = pt1 + vec * 0.975 * pOpenning->m_nWidth / vecTemp.length();
|
|
pt4 = pt1 + vecTemp * 0.05 * pOpenning->m_nWidth / (-vec.length());
|
|
pt3 = pt4 + vec * 0.975 * pOpenning->m_nWidth / vecTemp.length();
|
|
|
|
}
|
|
if (pOpenning->m_nQuadrant == 1 || pOpenning->m_nQuadrant == 2)
|
|
{
|
|
if (pOpenning->m_nQuadrant == 1)
|
|
vec = vec.rotateBy(0.5*PI, AcGeVector3d::kZAxis);
|
|
else
|
|
vec = vec.rotateBy(-0.5*PI, AcGeVector3d::kZAxis);
|
|
pt1 = ptOpeningLeft;
|
|
pt2 = pt1 + vec * 0.975 * pOpenning->m_nWidth / vecTemp.length();
|
|
pt4 = pt1 + vecTemp * 0.05 * pOpenning->m_nWidth / vec.length();
|
|
pt3 = pt4 + vec * 0.975 * pOpenning->m_nWidth / vecTemp.length();
|
|
}
|
|
|
|
lstResult.Append(new TGGeCurveSegment(pt1, pt2, 0.0));
|
|
lstResult.Append(new TGGeCurveSegment(pt2, pt3, 0.0));
|
|
//lstResult.Append(new TGGeCurveSegment(pt3, pt4, 0.0));
|
|
lstResult.Append(new TGGeCurveSegment(pt4, pt1, 0.0));
|
|
|
|
}
|
|
}
|
|
pOpenning->GetOutlinePoly(pOpenning->GetElevation(), poly);
|
|
poly.SetElevation(0.0); //z轴相同,才可以判断是否相交
|
|
if(pOpenning->m_pBayWin)//凸窗
|
|
{
|
|
for (int i = 0; i < poly.TotalSegments(); i++)
|
|
{
|
|
XPoint ptOutLine = segBayWin.GetStartPoint();//获取凸窗外轮廓线上的一点
|
|
ptOutLine.z = 0;
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
poly.Nth(i, *pSeg);
|
|
if (i == 1 || i == 3)
|
|
{
|
|
if (OFFSET_LEFT == pSeg->OnWhichSide(ptOutLine))//获取凸窗的外轮廓线
|
|
lstResult.Append(pSeg);
|
|
else
|
|
delete pSeg;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < poly.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
poly.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
}
|
|
}
|
|
else if (pEnt->isKindOf(TDbCornerWin::desc()))//凸窗
|
|
{
|
|
TDbCornerWin* pCornerWin = TDbCornerWin::cast(pEnt);
|
|
double dLen1 = pCornerWin->GetProtrude();
|
|
XPoly2D polyInside(1), polyGlass1(1), polyGlass2(1), polyOutSide(1);
|
|
polyOutSide.SetElevation(0.0);
|
|
polyInside.SetElevation(0.0);
|
|
pCornerWin->GetKeyCurves(polyInside, polyGlass1, polyGlass2, polyOutSide);
|
|
for (int i = 0; i < polyOutSide.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
polyOutSide.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
for (int i = 0; i < polyInside.TotalSegments(); i++)
|
|
{
|
|
TGGeCurveSegment *pSeg = new TGGeCurveSegment;
|
|
polyInside.Nth(i, *pSeg);
|
|
lstResult.Append(pSeg);
|
|
}
|
|
// AcDbPolyline* poly1 = new AcDbPolyline;
|
|
// PolyConvert(polyInside, *poly1);
|
|
// AddToCurrentSpace(poly1, Adesk::kTrue);
|
|
// AcDbPolyline* poly2 = new AcDbPolyline;
|
|
// PolyConvert(polyOutSide, *poly2);
|
|
// AddToCurrentSpace(poly2, Adesk::kTrue);
|
|
// //AcDbPolyline* poly3 = new AcDbPolyline;
|
|
// //PolyConvert(polyGlass1, *poly3);
|
|
// //AddToCurrentSpace(poly3, Adesk::kTrue);
|
|
// //AcDbPolyline* poly4 = new AcDbPolyline;
|
|
// //PolyConvert(polyGlass2, *poly4);
|
|
// //AddToCurrentSpace(poly4, Adesk::kTrue);
|
|
|
|
}
|
|
else if(pEnt->isKindOf(AcDbBlockReference::desc()))
|
|
{
|
|
TDPtrList<TGGeCurveSegment> lstTemp;
|
|
AcDbBlockReference *pInsert = AcDbBlockReference::cast(pEnt);
|
|
ASSERT(pInsert);
|
|
TADSGePoint3d ptLoc = pInsert->position();
|
|
double nRot = pInsert->rotation();
|
|
AcGeScale3d scale = pInsert->scaleFactors();
|
|
AcDbObjectId idBlock = pInsert->blockTableRecord();
|
|
TAcDbObjectPtr objBlock(idBlock, AcDb::kForRead);
|
|
ASSERT(!!objBlock);
|
|
AcDbBlockTableRecord *pRec = AcDbBlockTableRecord::cast(objBlock.m_pObject);
|
|
ASSERT(pRec);
|
|
TGGeCurveSegment segForArc;
|
|
TADSGePoint3d ptBase = pRec->origin();
|
|
ads_matrix mat1, mat2;
|
|
ConstructMatrix(ptBase, ptLoc, scale[0], scale[1], scale[2], nRot, mat1);
|
|
Get2DCurveFromBlock(*pRec, mat2, lstTemp);
|
|
AcGeMatrix3d mat= pInsert->blockTransform();
|
|
for (int i = 0; i < lstTemp.Length(); i++)
|
|
{
|
|
TGGeCurveSegment* seg;
|
|
seg = lstTemp.GetAt(i);
|
|
seg->SetStartPoint(mat * seg->StartPoint().AsAcGePoint3d());
|
|
seg->SetEndPoint(mat * seg->EndPoint().AsAcGePoint3d());
|
|
}
|
|
lstResult.Append(new TGGeCurveSegment(GetFirstInterLine(lstTemp, m_segSelLine, segForArc)));
|
|
lstResult.Append(new TGGeCurveSegment(GetLastInterLine(lstTemp, m_segSelLine)));
|
|
}
|
|
}
|
|
|
|
TGGeCurveSegment CParallelDimStyle::GetFirstInterLine(TDPtrList<TGGeCurveSegment> &lstInput, TGGeCurveSegment& ln, TGGeCurveSegment &segForArc)
|
|
{
|
|
TGGeCurveSegment segFirst;
|
|
double minDist=1E10, distTmp = 0, distTmp1 = 0;
|
|
XPoint ptFirst;
|
|
AcGeVector3d vec = ln.GetEndPoint().AsAcGePoint3d() - ln.GetStartPoint().AsAcGePoint3d();
|
|
for(int i=0;i<lstInput.Length();i++)
|
|
{
|
|
TGGeCurveSegment* segItem;
|
|
XPoint ptInt[2];
|
|
segItem = lstInput[i];
|
|
int nInterNum = segItem->Intersection(ln,ptInt[0], ptInt[1]);
|
|
distTmp=abs(ln.StartPoint().Distance2d(ptInt[0]));
|
|
if (nInterNum == 2)
|
|
distTmp1 = abs(ln.StartPoint().Distance2d(ptInt[1]));
|
|
if(nInterNum > 0 && (distTmp <= minDist || (distTmp1 <= minDist && nInterNum == 2)))
|
|
{
|
|
if (distTmp1 > 1.0e-6)
|
|
{
|
|
if (distTmp < distTmp1)
|
|
{
|
|
ptFirst = ptInt[0];
|
|
minDist = distTmp;
|
|
}
|
|
else
|
|
{
|
|
ptFirst = ptInt[1];
|
|
minDist = distTmp1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ptFirst = ptInt[0];
|
|
minDist = distTmp;
|
|
}
|
|
segFirst = *segItem;
|
|
}
|
|
}
|
|
if (abs(segFirst.GetBulge()) > 1.0e-6)
|
|
{
|
|
XPoint ptCenter;
|
|
AcGeVector3d vecPtFirToCenter;
|
|
AcGeVector3d vec = ln.GetEndPoint().AsAcGePoint3d() - ln.GetStartPoint().AsAcGePoint3d();
|
|
ptCenter = segFirst.GetArc().GetCenterPt();
|
|
XLine xLine(ptFirst, ptCenter);
|
|
vecPtFirToCenter = ptFirst.AsAcGePoint3d() - ptCenter.AsAcGePoint3d();
|
|
if(vecPtFirToCenter.dotProduct(vec) < 1.0e-6)
|
|
vecPtFirToCenter = -vecPtFirToCenter;
|
|
XPoint ptStart, ptEnd, ptLnEnd, ptLnStart;
|
|
ln.GetEndPoint(ptLnEnd);
|
|
ln.GetStartPoint(ptLnStart);
|
|
ptEnd = ptFirst + ln.GetLength() * vecPtFirToCenter / vecPtFirToCenter.length();
|
|
ptStart = ptFirst - ln.GetLength() * vecPtFirToCenter / vecPtFirToCenter.length();
|
|
TGGeCurveSegment segDim(ptFirst, ptEnd, 0.0);
|
|
segDim.ProjectToMe(ptLnEnd, ptEnd);
|
|
segDim.ProjectToMe(ptLnStart, ptStart);
|
|
segDim.SetStartPoint(ptStart);
|
|
segDim.SetEndPoint(ptEnd);
|
|
segForArc = segDim;
|
|
}
|
|
return segFirst;
|
|
}
|
|
|
|
TGGeCurveSegment CParallelDimStyle::GetLastInterLine(TDPtrList<TGGeCurveSegment> &lstInput, const TGGeCurveSegment& ln)
|
|
{
|
|
TGGeCurveSegment segLast;
|
|
double maxDist=0, distTmp = 0;
|
|
for(int i=0;i<lstInput.Length();i++)//最近的线作为方向基准
|
|
{
|
|
TGGeCurveSegment* segItem;
|
|
XPoint ptInt[2];
|
|
segItem = lstInput[i];
|
|
int num = segItem->Intersection(ln,ptInt[0], ptInt[1]);
|
|
distTmp=abs(ln.StartPoint().Distance2d(ptInt[0]));
|
|
if(num > 0 && distTmp >= maxDist)
|
|
{
|
|
maxDist = distTmp;
|
|
segLast = *segItem;
|
|
}
|
|
}
|
|
return segLast;
|
|
}
|
|
|
|
void CParallelDimStyle::GetParallelLine(TDPtrList<TGGeCurveSegment> &lstInput, TDPtrList<TGGeCurveSegment> &lstResult, const TGGeCurveSegment& ln)
|
|
{
|
|
AcGeVector3d vtFirst = ln.StartPoint().AsAcGePoint3d() - ln.EndPoint().AsAcGePoint3d();//基准向量
|
|
vtFirst.normalize();
|
|
for(int i=0;i<lstInput.Length();i++)
|
|
{
|
|
TGGeCurveSegment* segTemp;
|
|
segTemp = lstInput[i];
|
|
if (abs(segTemp->GetBulge()) < 1.0e-6)
|
|
{
|
|
AcGeVector3d vtTemp = segTemp->StartPoint().AsAcGePoint3d() - segTemp->EndPoint().AsAcGePoint3d();
|
|
if (vtTemp.isParallelTo(vtFirst) || vtTemp.isParallelTo(-vtFirst))
|
|
{
|
|
lstResult.Append(new TGGeCurveSegment(*lstInput[i]));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//判断取得的线是否平行弧线
|
|
void CParallelDimStyle::GetParallelLineForArc(TDPtrList<TGGeCurveSegment> &lstInput, TDPtrList<TGGeCurveSegment> &lstResult, const TGGeCurveSegment& ln)
|
|
{
|
|
XPoint ptCenter;
|
|
TGGeArc tgARC = ln.GetArc();
|
|
tgARC.Center(ptCenter);
|
|
for(int i=0;i<lstInput.Length();i++)
|
|
{
|
|
XPoint pt1;
|
|
TGGeArc tgARC = lstInput[i]->GetArc();
|
|
tgARC.Center(pt1);
|
|
if (pt1.AsAcGePoint3d().isEqualTo(ptCenter.AsAcGePoint3d()))
|
|
{
|
|
lstResult.Append(new TGGeCurveSegment(*lstInput[i]));
|
|
}
|
|
}
|
|
}
|
|
|
|
int CParallelDimStyle::GetInterPt(TDPtrList<TGGeCurveSegment> &lstInterLine, TADSGePointList& lstInterPt, TGGeCurveSegment& segln)
|
|
{
|
|
TGGeCurveSegment segx;
|
|
int nCount=lstInterLine.Length();
|
|
for(int n=0; n<nCount; n++)
|
|
{
|
|
segx=*lstInterLine[n];
|
|
//segx.SetLineFlag(LS_INFINITE);
|
|
XPoint ptInt[2];
|
|
segx.SetElevation(0.0);
|
|
int nIntNum=segx.Intersection(segln, ptInt[0], ptInt[1]);//求交点
|
|
for(int k=0; k<nIntNum; k++)
|
|
{
|
|
if(segln.HitTest2d(ptInt[k]) == 5)
|
|
lstInterPt.NewAppend(ptInt[k]);
|
|
}
|
|
}
|
|
return lstInterPt.Length();
|
|
}
|
|
void CParallelDimStyle::ParallelDimensioning(BOOL bParallelDim)
|
|
{
|
|
XPoint pt1, pt2;
|
|
|
|
int iRet;
|
|
InitLayer(LAY_DIM);
|
|
|
|
if (bParallelDim)
|
|
{
|
|
CStringArray aryLayerName, aryKeyWord;
|
|
aryKeyWord.Add(_T("轴线"));
|
|
GetLayerNameByKeyWord(aryLayerName, aryKeyWord);
|
|
g_aryLayerName.Copy(aryLayerName);
|
|
g_sSaveFileName = _T("LayerFilter_Parallel.txt");
|
|
}
|
|
else
|
|
{
|
|
CStringArray aryLayerName, aryKeyWord;
|
|
aryKeyWord.Add(_T("道路中线"));
|
|
aryKeyWord.Add(_T("道路"));
|
|
GetLayerNameByKeyWord(aryLayerName, aryKeyWord);
|
|
g_aryLayerName.Copy(aryLayerName);
|
|
g_sSaveFileName = _T("LayerFilter_RoadWide.txt");
|
|
}
|
|
CLayerSiftDlgEx dlg(NULL, TRUE);
|
|
dlg.GetSelectLayers(m_lstLayer);
|
|
while(1)
|
|
{
|
|
TDPtrList<TGGeCurveSegment> lstSegs,lstParaLineSegs;
|
|
TGGeCurveSegment segFirst, segx;
|
|
while(1)
|
|
{
|
|
INITGET_BEG(0, _T("S"));
|
|
iRet = ads_getpoint(NULL, _T("\n请选择起点或 [设置图层过滤 (S)]<退出>: "), pt1);
|
|
INITGET_END();
|
|
|
|
if (iRet == RTNORM)
|
|
{
|
|
break;
|
|
}
|
|
else if (iRet == RTKWORD)
|
|
{
|
|
if(dlg.DoModal() == IDOK)
|
|
{
|
|
m_lstLayer.RemoveAll();
|
|
dlg.GetSelectLayers(m_lstLayer);
|
|
}
|
|
continue;
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
if ( ads_getpoint(pt1, _T("\n选择终点<退出>: "), pt2) != RTNORM)
|
|
{
|
|
return;
|
|
}
|
|
// pt1=Wcs2Ucs(pt1);
|
|
// pt2 = Wcs2Ucs(pt2);
|
|
lstParaLineSegs.Reset();
|
|
lstSegs.Reset();
|
|
BOOL bDrawFisrtpt = FALSE;
|
|
TPickEntSet ssDimObj(SS_FREE);
|
|
TGGeLine lineLeft, lineRight, lineSel(pt1, pt2);
|
|
lineSel.SetElevation(0.0);
|
|
lineLeft = lineSel.Offset(1); //左右向外偏移
|
|
lineRight = lineSel.Offset(-1);
|
|
XPoint ptLowLeft,ptLowRight,ptUpRight,ptUpLeft,ptInter;
|
|
double nSpace=100;
|
|
TADSGePoint3d pt1(lineLeft.GetStartPoint()),
|
|
pt2(lineRight.GetStartPoint()),
|
|
pt3(lineRight.GetEndPoint()),
|
|
pt4(lineLeft.GetEndPoint());
|
|
|
|
RBList rbFence=ads_buildlist(RT3DPOINT,&pt1,RT3DPOINT,&pt2,RT3DPOINT,&pt3,RT3DPOINT,&pt4,NULL);
|
|
|
|
RBList dimMask(RTDXF0,// , ATS_CORNER_WINDOW
|
|
_T("POLYLINE,LWPOLYLINE,LINE,ARC,CIRCLE,ATS_WALL,ATS_CORNER_WINDOW,ATS_OPENING,TCH_INSERT,INSERT,ATS_MVINSERT,AEC_BLOCK_INSERT,ATS_COLUMN,ATS_BALCONY,ATS_APRON,ATS_STEP,ATS_SLAB,ATS_VERTSLAB,ATS_ASCENT"), NULL);
|
|
if (ssDimObj.Get(_T("CP"), rbFence, NULL, dimMask) != RTNORM) //选择集
|
|
{
|
|
return;
|
|
}
|
|
int nLength = ssDimObj.Length();
|
|
long n = 0;
|
|
TGGeCurveSegment ln(Ucs2Wcs(pt1), Ucs2Wcs(pt2), 0), segForArc;
|
|
m_segSelLine = ln;//选择线曲段
|
|
ln.SetElevation(0.0);
|
|
ln.SetLineFlag(LS_INFINITE);
|
|
TADSGePointList lstDimPoints;
|
|
for (n; n < ssDimObj.Length(); ++n)
|
|
{
|
|
AcDbEntity* pEntity;
|
|
Entity ssEnt=ssDimObj[n];
|
|
OPENOBJ_BEGIN(ssEnt,AcDb::kForRead,AcDbEntity,pEntity);
|
|
if(pEntity)
|
|
{
|
|
|
|
if (m_lstLayer.IsEmpty())
|
|
{
|
|
AnalysisTgEntToLine(pEntity, lstSegs);
|
|
}
|
|
else
|
|
{
|
|
CString strLayer = pEntity->layer();
|
|
if(m_lstLayer.Find(strLayer))
|
|
AnalysisTgEntToLine(pEntity, lstSegs);
|
|
}
|
|
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
int nInterPtNum = 0;//标注线个数
|
|
segFirst = GetFirstInterLine(lstSegs, ln, segForArc);
|
|
int l = segFirst.GetLength();////////////////////////////
|
|
l = ln.GetLength();
|
|
l = segForArc.GetLength();
|
|
if (abs(segFirst.GetBulge()) < 1.0e-6)
|
|
{
|
|
GetParallelLine(lstSegs, lstParaLineSegs, segFirst);
|
|
l = lstSegs.Length();
|
|
l = lstParaLineSegs.Length();
|
|
nInterPtNum = GetInterPt(lstParaLineSegs, lstDimPoints, ln);
|
|
}
|
|
else
|
|
{
|
|
GetParallelLineForArc(lstSegs, lstParaLineSegs, segFirst);
|
|
l = lstSegs.Length();
|
|
l = lstParaLineSegs.Length();
|
|
nInterPtNum = GetInterPt(lstParaLineSegs, lstDimPoints, segForArc);
|
|
}
|
|
|
|
if(nInterPtNum < 1)
|
|
{
|
|
adsout << _T("\n选中的与第一个对象平行的对象太少, 不能进行平行标注!");
|
|
return;
|
|
}
|
|
TGGeCurveSegment segTemp = segFirst;
|
|
double nDirection=segFirst.Direction(pt1);
|
|
if (segFirst.GetBulge() > 1.0e-6)
|
|
{
|
|
AcGeVector3d vec = lstDimPoints[lstDimPoints.Length()-1]->AsAcGePoint3d() - lstDimPoints[0]->AsAcGePoint3d();
|
|
vec = vec.rotateBy(0.5 * PI, AcGeVector3d::kZAxis);
|
|
double dLength = lstDimPoints[lstDimPoints.Length()-1]->Distance(*lstDimPoints[0]);
|
|
XPoint ptEnd = *lstDimPoints[0] + dLength * vec / vec.length();
|
|
TGGeCurveSegment segDim(*lstDimPoints[0], ptEnd, 0.0);
|
|
segFirst = segDim;
|
|
nDirection = segDim.Direction(pt1);
|
|
}
|
|
XPoint ptEnd = *lstDimPoints[lstDimPoints.Length()-1], ptStart=*lstDimPoints[0];
|
|
TVector3D vt = ptEnd - ptStart;
|
|
XVector3D vtSeg(segFirst.EndPoint().x - segFirst.StartPoint().x, segFirst.EndPoint().y - segFirst.StartPoint().y);
|
|
if((vt*vtSeg).z<0)
|
|
{
|
|
nDirection+=PI/2;
|
|
}
|
|
else
|
|
{
|
|
nDirection-=PI/2;
|
|
}
|
|
TDbDimension2* pdbDim = new TDbDimension2;
|
|
pdbDim->SetDist2DimLine(0.0);
|
|
pdbDim->SetStyleId(InitDimStyle(DS_LINEAR));
|
|
pdbDim->SetLocation(ptStart);
|
|
pdbDim->SetRotation(nDirection);
|
|
double nVal = fabs(vt&XVector3D(cos(nDirection), sin(nDirection)));
|
|
if (segTemp.GetBulge() > 1.0e-6)
|
|
{
|
|
nVal = vt.Length();
|
|
}
|
|
if(nVal<_DIST_SNAP)
|
|
{
|
|
adsout << _T("\n选中的与第一个对象平行的对象太少, 不能进行平行标注!");
|
|
return;
|
|
}
|
|
//尺寸最大距离
|
|
pdbDim->AppendSegment(nVal);
|
|
if(!pdbDim->IsValid())
|
|
return;
|
|
|
|
AcEdJig::DragStatus esjig;
|
|
CTParallelDimJig jig(pdbDim, lstDimPoints);
|
|
esjig = jig.doIt();
|
|
|
|
if (esjig != AcEdJig::kNormal)
|
|
{
|
|
return;
|
|
}
|
|
TDbDimension2 *pDim=(TDbDimension2 *)pdbDim->clone();
|
|
|
|
// sg add 120410,增加布局转角的设置,解决UCS下,文字方向错误的问题
|
|
pDim->SetLayoutRotation(Ucs2Wcs(0.0));
|
|
pDim->getEndPoint(pt1);
|
|
pDim->getStartPoint(ptStart);
|
|
pDim->getEndPoint(ptEnd);
|
|
if(g_nDimAdjust) pDim->AdjustDim(g_nDimAdjust!=2);
|
|
|
|
AcDbObjectId idLayer = idLayer = InitLayer(LAY_S_MARK);
|
|
if (bParallelDim && !g_bTextDefaultLayer)
|
|
idLayer = idLayer = acdbCurDwg()->clayer();
|
|
//获取当前图层
|
|
pDim->setLayer(idLayer);
|
|
AcDbObjectId idDim = AddToModelSpace((TDbEntity *)pDim);
|
|
actrTransactionManager->flushGraphics();
|
|
acedUpdateDisplay();
|
|
TDimParallelArg dimTwo;
|
|
XPushVar<int> osmode(_T("OSMODE"), GetFullOsMode(OS_INT|OS_END));
|
|
XPoint ptBase = Wcs2Ucs(*lstDimPoints[lstDimPoints.Length() - 1]);
|
|
XPoint ptShirr = ptBase;
|
|
XPoint ptOther;
|
|
while(true)
|
|
{
|
|
if(!dimTwo.CanUndo())
|
|
{
|
|
if(XGetPoint(ptShirr, _T("\n请输入其他标注点"), ptOther)== RTNORM)
|
|
{
|
|
ptShirr = ptOther;
|
|
dimTwo.Step(ptOther);
|
|
dimTwo.AddDim(idDim, ptOther);
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
|
|
int nRet2;
|
|
INITGET_BEG(0, _T("U R"));
|
|
nRet2 = acedGetPoint(ptShirr, _T("\n请输入其他标注点或 [参考点(R)/撤消上一标注点(U)]<退出>:"), ptOther);
|
|
INITGET_END();
|
|
|
|
if(nRet2 == RTKWORD)
|
|
{
|
|
XString sKey;
|
|
acedGetInput(sKey);
|
|
if(sKey[0] == _T('R'))
|
|
acedGetPoint(NULL, _T("\n参考点:"), ptShirr);
|
|
else if(sKey[0] == _T('U'))
|
|
{
|
|
dimTwo.Undo(idDim);
|
|
if(dimTwo.CanUndo())
|
|
ptShirr = dimTwo.GetLastPoint();
|
|
else
|
|
ptShirr = ptBase;
|
|
}
|
|
}
|
|
else if(nRet2 == RTNORM)
|
|
{
|
|
ptShirr = ptOther;
|
|
dimTwo.Step(ptOther);
|
|
dimTwo.AddDim(idDim, ptOther);
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDimParallelArg::AddDim(AcDbObjectId idDim, XPoint ptNew)
|
|
{
|
|
ptNew = Ucs2Wcs(ptNew);
|
|
OPENOBJ_BEGIN(idDim, AcDb::kForWrite, TDbDimension2, pDimNew);
|
|
ASSERT(pDimNew);
|
|
pDimNew->AddSegment(ptNew);
|
|
if(g_nDimAdjust)
|
|
pDimNew->AdjustDim(g_nDimAdjust!=2);
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
void TDimParallelArg::RemoveDim(AcDbObjectId idDim, XPoint ptOld)
|
|
{
|
|
ptOld = Ucs2Wcs(ptOld);
|
|
OPENOBJ_BEGIN(idDim, AcDb::kForWrite, TDbDimension2, pDimNew);
|
|
ASSERT(pDimNew);
|
|
pDimNew->FindAndRemoveSegment(ptOld);
|
|
if(g_nDimAdjust) pDimNew->AdjustDim(g_nDimAdjust!=2);
|
|
OPENOBJ_END();
|
|
}
|
|
void TDimParallelArg::Step(XPoint ptNew)
|
|
{
|
|
m_ptStack.Push(ptNew);
|
|
}
|
|
|
|
BOOL TDimParallelArg::CanUndo()
|
|
{
|
|
return m_ptStack.GetDepth() > 0;
|
|
}
|
|
|
|
void TDimParallelArg::Undo(AcDbObjectId idDim)
|
|
{
|
|
XPoint pt;
|
|
m_ptStack.GetTopData(pt);
|
|
if(CanUndo())
|
|
RemoveDim(idDim, pt);
|
|
m_ptStack.GoBack();
|
|
}
|
|
|
|
XPoint TDimParallelArg::GetLastPoint()
|
|
{
|
|
XPoint pt;
|
|
m_ptStack.GetTopData(pt);
|
|
return pt;
|
|
}
|
|
|
|
|
|
|