943 lines
22 KiB
C++
943 lines
22 KiB
C++
#include "StdAfx.h"
|
|
#include "tapi.h"
|
|
#include "XDbOsnapPoint.h"
|
|
|
|
bool g_bAssisitantSnap = true; // 是否使用辅助捕捉
|
|
|
|
int GetSnapPoint(double *ptFrom, const TCHAR *prompt, XPoint &pt, int nFlag, double dAngle,
|
|
const TCHAR *pKeyWord, int *pNKeyIndex, bool bCloseSnap)
|
|
{
|
|
bool bSnapOpen = false; // cad捕捉是否打开
|
|
if (bCloseSnap) // 关闭cad捕捉
|
|
{
|
|
int nOsMode;
|
|
TGGetVar(_T("OSMODE"), &nOsMode); // cad当前捕捉状态
|
|
bSnapOpen = (nOsMode & 0x4000) > 0;
|
|
if (bSnapOpen)
|
|
{
|
|
nOsMode |= 0x4000;
|
|
TGSetVar(_T("OSMODE"), nOsMode);
|
|
}
|
|
}
|
|
XOsPointEdJig jig;
|
|
jig.SetKeyWord(pKeyWord);
|
|
jig.SetPrompt(prompt);
|
|
jig.SetptTo(pt);
|
|
jig.SetUsageFlag(nFlag);
|
|
if(ptFrom)
|
|
jig.SetptFrom(ptFrom);
|
|
jig.SetRectAngle(dAngle);
|
|
jig.doIt();
|
|
|
|
int nKeyword = -1;
|
|
int nRetCode=jig.GetRetCode(&nKeyword);
|
|
if(nRetCode==RTNORM)
|
|
{
|
|
pt = jig.GetptTo();
|
|
}
|
|
else if (nRetCode == RTKWORD && pNKeyIndex != NULL)
|
|
{
|
|
*pNKeyIndex = nKeyword;
|
|
}
|
|
// 打开cad捕捉
|
|
if (bSnapOpen)
|
|
{
|
|
int nOsMode;
|
|
TGGetVar(_T("OSMODE"), &nOsMode); // cad当前捕捉状态
|
|
nOsMode &= ~0x4000;
|
|
TGSetVar(_T("OSMODE"), nOsMode);
|
|
}
|
|
|
|
return nRetCode;
|
|
}
|
|
|
|
int SelRectByWall(double dAngle,double& dLength,double& dWidth)
|
|
{
|
|
|
|
int nRet = 0;
|
|
XPoint ptStart,ptEnd;
|
|
CString sPrompt1 = _T("\n请输入起始点<退出>:");
|
|
|
|
|
|
int nKeyIndex = 0;
|
|
nRet = GetSnapPoint(NULL,sPrompt1,ptStart,0,0.0,NULL,NULL,false);
|
|
if (nRet == RTNORM)
|
|
{
|
|
nRet = GetSnapPoint(ptStart,_T("\n选择终点<退出>:"),ptEnd,2,dAngle,NULL,NULL,false);
|
|
if (nRet == RTNORM)
|
|
{
|
|
AcGeVector3d vtX = AcGeVector3d::kXAxis;
|
|
vtX.rotateBy(Wcs2Ucs(dAngle),AcGeVector3d::kZAxis);
|
|
AcGeVector3d vtDir = ptEnd - ptStart;
|
|
double dDist = ptEnd.Distance(ptStart);
|
|
double dAng = vtDir.angleTo(vtX);
|
|
|
|
dLength = fabs(dDist * cos(dAng));
|
|
dWidth = fabs(dDist * sin(dAng));
|
|
}
|
|
}
|
|
return nRet;
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
// 获取输入点, 自动进行模糊捕捉 bCloseSnap控制cad捕捉的开关 nFlag(0--不带橡皮巾; 1--待橡皮巾; 2--矩形拖曳)
|
|
int GetSnapPoint(double *ptFrom, const TCHAR *prompt, XPoint &pt, int nFlag = 0, double dAngle = 0.0,const TCHAR *pKeyWord = NULL, int *pNKeyIndex = NULL, bool bCloseSnap = true)
|
|
{
|
|
bool bSnapOpen = false; // cad捕捉是否打开
|
|
if (bCloseSnap) // 关闭cad捕捉
|
|
{
|
|
int nOsMode;
|
|
TGGetVar(_T("OSMODE"), &nOsMode); // cad当前捕捉状态
|
|
bSnapOpen = (nOsMode & 0x4000) > 0;
|
|
if (bSnapOpen)
|
|
{
|
|
nOsMode |= 0x4000;
|
|
TGSetVar(_T("OSMODE"), nOsMode);
|
|
}
|
|
}
|
|
XOsPointEdJig jig;
|
|
jig.SetKeyWord(pKeyWord);
|
|
jig.SetPrompt(prompt);
|
|
jig.SetptTo(pt);
|
|
jig.SetUsageFlag(nFlag);
|
|
if(ptFrom)
|
|
jig.SetptFrom(ptFrom);
|
|
jig.SetRectAngle(dAngle);
|
|
jig.doIt();
|
|
|
|
int nKeyword = -1;
|
|
int nRetCode=jig.GetRetCode(&nKeyword);
|
|
if(nRetCode==RTNORM)
|
|
{
|
|
pt = jig.GetptTo();
|
|
}
|
|
else if (nRetCode == RTKWORD && pNKeyIndex != NULL)
|
|
{
|
|
*pNKeyIndex = nKeyword;
|
|
}
|
|
// 打开cad捕捉
|
|
if (bSnapOpen)
|
|
{
|
|
int nOsMode;
|
|
TGGetVar(_T("OSMODE"), &nOsMode); // cad当前捕捉状态
|
|
nOsMode &= ~0x4000;
|
|
TGSetVar(_T("OSMODE"), nOsMode);
|
|
}
|
|
|
|
return nRetCode;
|
|
}
|
|
*/
|
|
|
|
///////////////////////////////////////////
|
|
const int g_nSnapPixelNum = 10; // 捕捉点距离
|
|
// 捕捉端点
|
|
bool SnapEnd(DList<XCurveSegment> &lst, const XRectAngle &box, XPoint &ptWcs);
|
|
// 捕捉最近点
|
|
bool SnapNear(DList<XCurveSegment> &lst, XPoint &ptWcs, XCurveSegment &seg);
|
|
// 捕捉交点
|
|
bool SnapInt(DList<XCurveSegment> &lst, XPoint &ptWcs);
|
|
// 获得区域内指定的实体信息
|
|
void GetXCurveSegment(const XPoint &ptLow, const XPoint &ptUp, DList<XCurveSegment> &lst);
|
|
// 自动捕捉点
|
|
int AutoSnapPoint(XPoint &ptWcs, XPoint *ptBase=NULL);
|
|
// nOsShape: 0--没有捕捉; 1--墙基线端点; 2--轴线交点; 3--墙基线最近点; 4--轴线最近点
|
|
int AsOsnapMask(int nOsShape);
|
|
// 需要捕捉的实体
|
|
void GetSnapEntity(DList<AcRxClass> &lstClass);
|
|
|
|
// nOsShape: 0--没有捕捉; 1--端点; 2--交点; 3--最近点; 4--垂足
|
|
// 对应: 的捕捉代码
|
|
int AsOsnapMask(int nOsShape)
|
|
{
|
|
int nRet=0;
|
|
switch(nOsShape)
|
|
{
|
|
case 1:
|
|
nRet=AcDb::kOsMaskEnd;
|
|
break;
|
|
case 2:
|
|
nRet=AcDb::kOsMaskInt;
|
|
break;
|
|
case 3:
|
|
nRet=AcDb::kOsMaskNear;
|
|
break;
|
|
case 4:
|
|
nRet=AcDb::kOsMaskPerp;
|
|
break;
|
|
}
|
|
return nRet;
|
|
}
|
|
|
|
// 捕捉顺序: 端点,交点,垂足,最近点
|
|
// ptWcs -- I/O
|
|
// 返回: 0--没有捕捉; 1--端点; 2--交点; 3--最近点; 4--垂足
|
|
int AutoSnapPoint(XPoint &ptWcs, XPoint *ptBase)
|
|
{
|
|
double nApertureWcs=GetApertureWcs();
|
|
if(nApertureWcs<1.0E-6)
|
|
return 0;
|
|
int bSnap=0;
|
|
XPoint vtSnap(nApertureWcs, nApertureWcs);
|
|
XPoint ptLow=ptWcs-vtSnap;
|
|
XPoint ptUp = ptWcs+vtSnap;
|
|
|
|
// 获取需要获得捕捉点的线
|
|
DList<XCurveSegment> lst;
|
|
GetXCurveSegment(ptLow, ptUp, lst);
|
|
bool bNearWall = lst.Length() > 0 ? true : false;
|
|
|
|
XRectAngle box(ptLow, ptUp);
|
|
if(bNearWall) // 端点
|
|
if(SnapEnd(lst, box, ptWcs))
|
|
bSnap = 1;
|
|
|
|
if (!bSnap && bNearWall) // 交点
|
|
{
|
|
if (SnapInt(lst, ptWcs))
|
|
{
|
|
bSnap = 2;
|
|
}
|
|
}
|
|
|
|
XCurveSegment seg;
|
|
if(!bSnap && bNearWall)
|
|
{
|
|
Entity entNear;
|
|
XPoint ptCursor=ptWcs;
|
|
if(SnapNear(lst, ptWcs, seg)) // 最近点
|
|
{
|
|
bSnap = 3;
|
|
AcDbCurve *pCurve = seg.AsAcDbCurve();
|
|
if (pCurve != NULL && ptBase)
|
|
{
|
|
AcGePoint3d pt((*ptBase)[0], (*ptBase)[1], (*ptBase)[2]);
|
|
AcGePoint3d ptPrj;
|
|
if (pCurve->getClosestPointTo(pt, ptPrj) == Acad::eOk)
|
|
{
|
|
double nIntAng=CT_acute_angle(ads_angle(*ptBase, XPoint(ptPrj))-ads_angle(*ptBase, ptCursor));
|
|
if((ptPrj&(seg))==PR_INSIDE && nIntAng<5.0*PI/180.0) // 垂足
|
|
{
|
|
bSnap=4;
|
|
ptWcs=ptPrj;
|
|
}
|
|
}
|
|
delete pCurve;
|
|
pCurve = NULL;
|
|
}
|
|
}
|
|
}
|
|
return bSnap;
|
|
}
|
|
|
|
// 捕捉墙的端点
|
|
bool SnapEnd(DList<XCurveSegment> &lst, const XRectAngle &box, XPoint &ptWcs)
|
|
{
|
|
bool bRet = false;
|
|
XPoint ptNearest;
|
|
double nMinDist=0.0;
|
|
long nCount = lst.Length();
|
|
AcGePoint3d ptS, ptE;
|
|
XPoint ptEnd[2];
|
|
for(long i = 0L; i < nCount; i++)
|
|
{
|
|
ptEnd[0] = lst[i]->StartPoint();
|
|
ptEnd[1] = lst[i]->EndPoint();
|
|
ptEnd[0].z = ptWcs.z;
|
|
ptEnd[1].z = ptWcs.z;
|
|
for(int n = 0; n < 2; n++)
|
|
{
|
|
if((ptEnd[n]&box) != PR_OUTSIDE)
|
|
{
|
|
double nDist = ptEnd[n].Distance(ptWcs);
|
|
if (nDist > PixelToWcs(g_nSnapPixelNum)) // 捕捉点距离限制
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if(bRet)
|
|
{
|
|
if(nDist < nMinDist)
|
|
{
|
|
nMinDist = nDist;
|
|
ptNearest = ptEnd[n];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
nMinDist = nDist;
|
|
ptNearest = ptEnd[n];
|
|
bRet = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(bRet)
|
|
ptWcs=ptNearest;
|
|
return bRet;
|
|
}
|
|
|
|
// 捕捉最近点
|
|
bool SnapNear(DList<XCurveSegment> &lst, XPoint &ptWcs, XCurveSegment &seg)
|
|
{
|
|
bool bRet = false;
|
|
return bRet; // sr add 2012-3-7 暂时取消最近点
|
|
XPoint ptNearest;
|
|
double nMinDist=0.0;
|
|
AcDb::Intersect intType=AcDb::kOnBothOperands;
|
|
|
|
// 构造WCS到Dcs的转换矩阵
|
|
AcGeMatrix3d transWcsToDcs;
|
|
XPoint xAxesWcs(1,0,0), yAxesWcs(0,1,0), zAxesWcs(0,0,1),
|
|
xAxesDcs, yAxesDcs, zAxesDcs;
|
|
XPoint ptOrginWcs(0,0,0), ptOrginDcs(0,0,0);
|
|
Groups fromWcs(0), toDcs(2);
|
|
ads_trans(ptOrginWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 0, ptOrginDcs);
|
|
ads_trans(xAxesWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 1, xAxesDcs);
|
|
ads_trans(yAxesWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 1, yAxesDcs);
|
|
ads_trans(zAxesWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 1, zAxesDcs);
|
|
transWcsToDcs.setCoordSystem(ptOrginDcs, xAxesDcs, yAxesDcs, zAxesDcs);
|
|
|
|
XPoint ptLast;
|
|
for (int k = 0; k < lst.Length(); k++)
|
|
{
|
|
AcDbCurve *pCurve = lst[k]->AsAcDbCurve();
|
|
if(pCurve == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
AcGePoint3dArray points;
|
|
AcDbIntArray ar;
|
|
if(pCurve->getOsnapPoints(AcDb::kOsModeNear, 0, ptWcs, ptLast, transWcsToDcs, points, ar)==Acad::eOk)
|
|
{
|
|
int numPoints=points.length();
|
|
for(int i = 0; i < numPoints; i++)
|
|
{
|
|
XPoint ptCur = points[i];
|
|
ptCur.z = ptWcs.z;
|
|
double nDist = ptWcs.Distance(ptCur);
|
|
if (nDist > PixelToWcs(g_nSnapPixelNum)) // 捕捉点距离限制
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if(bRet)
|
|
{
|
|
if(nDist < nMinDist)
|
|
{
|
|
nMinDist = nDist;
|
|
ptNearest = ptCur;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
nMinDist = nDist;
|
|
ptNearest = ptCur;
|
|
bRet = true;
|
|
}
|
|
}
|
|
|
|
if (numPoints > 0)
|
|
{
|
|
seg = *lst[k];
|
|
}
|
|
}
|
|
delete pCurve;
|
|
}
|
|
|
|
if(bRet)
|
|
{
|
|
ptWcs=ptNearest;
|
|
}
|
|
return bRet;
|
|
}
|
|
|
|
// 捕捉交点
|
|
bool SnapInt(DList<XCurveSegment> &lst, XPoint &ptWcs)
|
|
{
|
|
if (lst.Length() < 2)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool bRet = false;
|
|
XPoint ptNearest;
|
|
|
|
AcGePoint3dArray arrPts;
|
|
int nLen = lst.Length();
|
|
for(int i = 0; i < nLen - 1; i++)
|
|
{
|
|
AcDbCurve *pCurve1 = lst[i]->AsAcDbCurve();
|
|
if (pCurve1 == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
for (int j = i + 1; j < nLen - 1; j++)
|
|
{
|
|
AcDbCurve *pCurve2 = lst[j]->AsAcDbCurve();
|
|
if (pCurve2 == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
pCurve1->intersectWith(pCurve2, AcDb::kExtendBoth, arrPts);
|
|
}
|
|
}
|
|
|
|
double nMinDist=0.0;
|
|
int nInters=arrPts.length();
|
|
for(int k = 0; k < nInters; k++)
|
|
{
|
|
XPoint ptCur = arrPts[k];
|
|
double nDist = ptWcs.Distance(ptCur);
|
|
if (nDist > PixelToWcs(g_nSnapPixelNum)) // 捕捉点距离限制
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if(bRet)
|
|
{
|
|
if(nDist < nMinDist)
|
|
{
|
|
nMinDist = nDist;
|
|
ptNearest = ptCur;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
nMinDist = nDist;
|
|
ptNearest = ptCur;
|
|
bRet=TRUE;
|
|
}
|
|
}
|
|
if(bRet)
|
|
ptWcs=ptNearest;
|
|
return bRet;
|
|
}
|
|
|
|
void GetSnapEntity(std::vector<AcRxClass*> &vecClass)
|
|
{
|
|
vecClass.push_back(TDbWall::desc());
|
|
vecClass.push_back(AcDbLine::desc());
|
|
}
|
|
|
|
void GetXCurveSegment(const XPoint &ptLow, const XPoint &ptUp, DList<XCurveSegment> &lst)
|
|
{
|
|
// 获取实体
|
|
std::vector<AcRxClass*> vecClass;
|
|
GetSnapEntity(vecClass);
|
|
XCurvePickSet ss;
|
|
std::vector<AcRxClass*>::iterator it;
|
|
for (it = vecClass.begin(); it != vecClass.end(); it++)
|
|
{
|
|
GetSafeSelectionEx(ss, TRUE, ptLow, ptUp, *it);
|
|
}
|
|
|
|
// 得到实体中需要捕捉的线
|
|
Entity ent;
|
|
for (long i = 0; i < ss.Length(); i++)
|
|
{
|
|
ent = ss[i];
|
|
if (ent.Is(_T("ATS_WALL")))
|
|
{
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWall, pWall);
|
|
if (pWall != NULL)
|
|
{
|
|
XCurveSegment *pLeft = new XCurveSegment;
|
|
XCurveSegment *pRight = new XCurveSegment;
|
|
pWall->GetStandardCurve(*pLeft, *pRight);
|
|
lst.Append(pLeft);
|
|
lst.Append(pRight);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if (ent.Is(_T("LINE")))
|
|
{
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbLine, pLine);
|
|
if (pLine != NULL)
|
|
{
|
|
XCurveSegment *pLeft = new XCurveSegment;
|
|
pLeft->SetLine(pLine->startPoint(), pLine->endPoint());
|
|
lst.Append(pLeft);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
XDbOsnapPoint::XDbOsnapPoint(): m_nOsShape(0), m_pEntityEx(NULL)
|
|
, m_nFlag(0), m_dRectAngle(Ucs2Wcs(0.0)), m_bDrawSnap(true)
|
|
{
|
|
|
|
}
|
|
|
|
Adesk::Boolean XDbOsnapPoint::subWorldDraw(AcGiWorldDraw *mode)
|
|
{
|
|
DrawShape(mode);
|
|
if (m_pEntityEx != NULL)
|
|
{
|
|
m_pEntityEx->worldDraw(mode);
|
|
}
|
|
return Adesk::kFalse;
|
|
}
|
|
|
|
// 由于视窗的实体不能访问, 因此本函数目前没有使用
|
|
void XDbOsnapPoint::subViewportDraw(AcGiViewportDraw *mode)
|
|
{
|
|
DrawOsnapShape(mode);
|
|
}
|
|
|
|
// 绘制点的形状
|
|
void XDbOsnapPoint::DrawOsnapShape(AcGiViewportDraw *pVd)
|
|
{
|
|
XAcGiViewDraw dc(NULL, pVd);
|
|
AcGePoint2d pixelArea;
|
|
pVd->viewport().getNumPixelsInUnitSquare(m_ptLoc,pixelArea);
|
|
double nAperture = 16/pixelArea.asVector().length();
|
|
if(nAperture<1.0E-6)
|
|
return;
|
|
XRectAngle box(m_ptLoc, nAperture, nAperture);
|
|
AcDbPolyline pline;
|
|
pVd->subEntityTraits().setColor(2);
|
|
double nWidth=1/pixelArea.asVector().length();
|
|
pline.setConstantWidth(nWidth);
|
|
|
|
ads_matrix mat;
|
|
m_ptLoc.GetRotationMatrix(Ucs2Wcs(0.0),mat);
|
|
//dc.SetColor(6); //用粉红色
|
|
switch(m_nOsShape)
|
|
{
|
|
case AcDb::kOsMaskEnd:
|
|
{
|
|
pline.addVertexAt(0, box.GetLowLeft().AsAcGePoint2d());
|
|
pline.addVertexAt(1, box.GetLowRight().AsAcGePoint2d());
|
|
pline.addVertexAt(2, box.GetUpRight().AsAcGePoint2d());
|
|
pline.addVertexAt(3, box.GetUpLeft().AsAcGePoint2d());
|
|
pline.setClosed(Adesk::kTrue);
|
|
//pline.viewportDraw(pVd);
|
|
XPoly2D poly1, poly2, poly;
|
|
PolyConvert(pline, poly);
|
|
poly.TransUCS(mat);//add by whl for ucs
|
|
poly.QuickOffset(-nWidth, poly1);
|
|
poly.QuickOffset(nWidth, poly2);
|
|
dc << poly1 << poly2;
|
|
break;
|
|
}
|
|
case AcDb::kOsMaskInt:
|
|
{
|
|
pline.setClosed(Adesk::kFalse);
|
|
pline.addVertexAt(0, box.GetLowLeft().AsAcGePoint2d());
|
|
pline.addVertexAt(1, box.GetUpRight().AsAcGePoint2d());
|
|
XPoly2D poly1, poly2, poly;
|
|
PolyConvert(pline, poly);
|
|
poly.TransUCS(mat);//add by whl for ucs
|
|
poly.QuickOffset(-nWidth, poly1);
|
|
poly.QuickOffset(nWidth, poly2);
|
|
dc << poly1 << poly2;
|
|
pline.reset(Adesk::kFalse, 0);
|
|
poly1.Reset(); poly2.Reset(); poly.Reset();
|
|
pline.addVertexAt(0, box.GetLowRight().AsAcGePoint2d());
|
|
pline.addVertexAt(1, box.GetUpLeft().AsAcGePoint2d());
|
|
PolyConvert(pline, poly);
|
|
poly.TransUCS(mat);//add by whl for ucs
|
|
poly.QuickOffset(-nWidth, poly1);
|
|
poly.QuickOffset(nWidth, poly2);
|
|
dc << poly1 << poly2;
|
|
break;
|
|
}
|
|
case AcDb::kOsMaskNear:
|
|
{
|
|
pline.addVertexAt(0, box.GetLowLeft().AsAcGePoint2d());
|
|
pline.addVertexAt(1, box.GetLowRight().AsAcGePoint2d());
|
|
pline.addVertexAt(2, box.GetUpLeft().AsAcGePoint2d());
|
|
pline.addVertexAt(3, box.GetUpRight().AsAcGePoint2d());
|
|
pline.setClosed(Adesk::kTrue);
|
|
XPoly2D poly1, poly2, poly;
|
|
PolyConvert(pline, poly);
|
|
poly.TransUCS(mat);//add by whl for ucs
|
|
poly.QuickOffset(-nWidth, poly1);
|
|
poly.QuickOffset(nWidth, poly2);
|
|
dc << poly1 << poly2;
|
|
break;
|
|
}
|
|
case AcDb::kOsMaskPerp:
|
|
{
|
|
pline.addVertexAt(0, box.GetUpLeft().AsAcGePoint2d());
|
|
pline.addVertexAt(1, box.GetLowLeft().AsAcGePoint2d());
|
|
pline.addVertexAt(2, box.GetLowRight().AsAcGePoint2d());
|
|
pline.setClosed(Adesk::kFalse);
|
|
XPoly2D poly1, poly2, poly;
|
|
PolyConvert(pline, poly);
|
|
poly.TransUCS(mat);//add by whl for ucs
|
|
poly.QuickOffset(-nWidth, poly1);
|
|
poly.QuickOffset(nWidth, poly2);
|
|
dc << poly1 << poly2;
|
|
pline.reset(Adesk::kFalse, 0);
|
|
poly1.Reset(); poly2.Reset(); poly.Reset();
|
|
XPoint pt1, pt2;
|
|
Midpoint(box.GetUpLeft(), box.GetLowLeft(), pt1);
|
|
Midpoint(box.GetLowRight(), box.GetLowLeft(), pt2);
|
|
pline.addVertexAt(0, pt1.AsAcGePoint2d());
|
|
pline.addVertexAt(1, m_ptLoc.AsAcGePoint2d());
|
|
pline.addVertexAt(2, pt2.AsAcGePoint2d());
|
|
pline.setClosed(Adesk::kFalse);
|
|
PolyConvert(pline, poly);
|
|
poly.TransUCS(mat);//add by whl for ucs
|
|
poly.QuickOffset(-nWidth, poly1);
|
|
poly.QuickOffset(nWidth, poly2);
|
|
dc << poly1 << poly2;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void XDbOsnapPoint::DrawShape(AcGiWorldDraw *mode)
|
|
{
|
|
XAcGiViewDraw dc(mode, NULL);
|
|
switch(m_nFlag)
|
|
{
|
|
case 1: // 橡皮筋
|
|
{
|
|
dc << XLine(m_ptBase, m_ptLoc);
|
|
break;
|
|
}
|
|
case 2: // 矩形框
|
|
{
|
|
AcGeVector3d vtX = AcGeVector3d::kXAxis;
|
|
vtX.rotateBy(Wcs2Ucs(m_dRectAngle), AcGeVector3d::kZAxis);
|
|
AcGeVector3d vtY;
|
|
XPoint pt1 = m_ptLoc;
|
|
XPoint pt2 = m_ptBase;
|
|
pt1.z = 0.0;
|
|
pt2.z = 0.0;
|
|
XPoint pt3, pt4;
|
|
if (fabs(Wcs2Ucs(m_dRectAngle)) < 0.001)
|
|
{
|
|
pt1 = Wcs2Ucs(pt1);
|
|
pt2 = Wcs2Ucs(pt2);
|
|
pt3.x = pt1.x;
|
|
pt3.y = pt2.y;
|
|
pt3.z = 0.0;
|
|
pt4.x = pt2.x;
|
|
pt4.y = pt1.y;
|
|
pt4.z = 0.0;
|
|
}
|
|
else
|
|
{
|
|
AcGeVector3d vtY = vtX;
|
|
vtY.rotateBy(PI / 2,AcGeVector3d::kZAxis);
|
|
|
|
int nSignX = 1,nSignY = 1;
|
|
|
|
AcGeVector3d vt = pt1 - pt2;
|
|
vt.normalize();
|
|
double dAngle = vt.angleTo(vtX);
|
|
if (dAngle > PI / 2)
|
|
{
|
|
nSignX = -1;
|
|
}
|
|
|
|
double dDist = pt1.Distance2d(pt2);
|
|
double dLen = fabs(dDist * cos(dAngle));
|
|
double dWidth = fabs(dDist * sin(dAngle));
|
|
//axc add 2014-10-16 解决16平台在UCS下崩溃问题
|
|
if (dLen <= 0 || dWidth <= 0 || vt.isZeroLength() == Adesk::kTrue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
dAngle = vt.angleTo(vtY);
|
|
if (dAngle > PI / 2)
|
|
{
|
|
nSignY = -1;
|
|
}
|
|
|
|
vtX.normalize();
|
|
vtY.normalize();
|
|
|
|
pt3 = pt2 + vtX * dLen * nSignX;
|
|
pt4 = pt2 + vtY * dWidth * nSignY;
|
|
}
|
|
|
|
dc << XLine(pt1, pt3);
|
|
dc << XLine(pt1, pt4);
|
|
dc << XLine(pt2, pt3);
|
|
dc << XLine(pt2, pt4);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void XDbOsnapPoint::SetLocation(const XPoint &ptLoc)
|
|
{
|
|
m_ptLoc = ptLoc;
|
|
}
|
|
|
|
XPoint XDbOsnapPoint::GetLocation() const
|
|
{
|
|
return m_ptLoc;
|
|
}
|
|
|
|
void XDbOsnapPoint::SetSnapShape(int nShape)
|
|
{
|
|
m_nOsShape = nShape;
|
|
}
|
|
|
|
void XDbOsnapPoint::SetEntityEx(AcDbEntity *pEnt)
|
|
{
|
|
m_pEntityEx = pEnt;
|
|
}
|
|
|
|
void XDbOsnapPoint::SetBasePoint(const XPoint &pt)
|
|
{
|
|
m_ptBase = pt;
|
|
}
|
|
|
|
void XDbOsnapPoint::SetDrawShape(int nFlag)
|
|
{
|
|
m_nFlag = nFlag;
|
|
}
|
|
|
|
void XDbOsnapPoint::SetRectAngle(double dAngle)
|
|
{
|
|
m_dRectAngle = dAngle;
|
|
}
|
|
|
|
void XDbOsnapPoint::SetDrawSnap(bool bSnap)
|
|
{
|
|
m_bDrawSnap = bSnap;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////
|
|
XOsPointEdJig::XOsPointEdJig()
|
|
:m_pszKeyword(NULL), m_pszPrompt(NULL), m_pDrawEnt(NULL),
|
|
m_nRetCode(0), m_nOsShape(0)
|
|
{
|
|
m_pDrawEnt = new XDbOsnapPoint;
|
|
}
|
|
|
|
XOsPointEdJig::~XOsPointEdJig()
|
|
{
|
|
if(m_pDrawEnt)
|
|
delete m_pDrawEnt;
|
|
}
|
|
|
|
// 开始执行拖动
|
|
void XOsPointEdJig::doIt()
|
|
{
|
|
m_pDrawEnt->SetSnapShape(AsOsnapMask(m_nOsShape));
|
|
m_pDrawEnt->SetLocation(m_ptTo);
|
|
|
|
setDispPrompt(m_pszPrompt);
|
|
if(m_pszKeyword)
|
|
{
|
|
INITGET_BEG(-1, m_pszKeyword);
|
|
try
|
|
{
|
|
m_nRetCode = drag();
|
|
}
|
|
catch(...)
|
|
{
|
|
m_nRetCode=AcEdJig::kCancel;
|
|
}
|
|
INITGET_END();
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
m_nRetCode = drag();
|
|
}
|
|
catch(...)
|
|
{
|
|
m_nRetCode=AcEdJig::kCancel;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 反馈
|
|
AcEdJig::DragStatus XOsPointEdJig::sampler()
|
|
{
|
|
DragStatus stat;
|
|
setUserInputControls((UserInputControls)
|
|
(AcEdJig::kAccept3dCoordinates | AcEdJig::kNullResponseAccepted
|
|
| AcEdJig::kNoNegativeResponseAccepted
|
|
| AcEdJig::kNoZeroResponseAccepted));
|
|
|
|
if (m_pszKeyword) setKeywordList(m_pszKeyword);
|
|
XPoint ptTemp;
|
|
stat = acquirePoint(ptTemp);
|
|
if(stat == AcEdJig::kNormal)
|
|
{
|
|
if (g_bAssisitantSnap)
|
|
{
|
|
m_nOsShape = AutoSnapPoint(ptTemp, NULL);
|
|
}
|
|
m_pDrawEnt->SetDrawSnap(g_bAssisitantSnap);
|
|
|
|
if (ads_distance(ptTemp, m_ptTo)>_DIST_SNAP)
|
|
{
|
|
m_ptTo=ptTemp;
|
|
}
|
|
else
|
|
return AcEdJig::kNoChange;
|
|
}
|
|
|
|
return stat;
|
|
}
|
|
|
|
// 更新实体数据
|
|
Adesk::Boolean XOsPointEdJig::update()
|
|
{
|
|
if(!(m_pDrawEnt->GetLocation() == m_ptTo))
|
|
{
|
|
m_pDrawEnt->SetLocation(m_ptTo);
|
|
m_pDrawEnt->SetSnapShape(AsOsnapMask(m_nOsShape));
|
|
}
|
|
return Adesk::kTrue;
|
|
}
|
|
|
|
AcDbEntity* XOsPointEdJig::entity() const
|
|
{
|
|
return m_pDrawEnt;
|
|
}
|
|
|
|
// 转换成ADS代码
|
|
int XOsPointEdJig::GetRetCode(int *kwordId) const
|
|
{
|
|
int ret = m_nRetCode;
|
|
if (ret == AcEdJig::kCancel)
|
|
ret = RTCAN;
|
|
else if(ret == AcEdJig::kNull)
|
|
ret = RTNONE;
|
|
else if (ret <= 0)
|
|
ret = RTNORM;
|
|
else
|
|
{
|
|
if(kwordId) *kwordId = ret;
|
|
ret = RTKWORD;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
AcEdJig::DragStatus XOsPointEdJig::GetRetStatus() const
|
|
{
|
|
return (AcEdJig::DragStatus)m_nRetCode;
|
|
}
|
|
|
|
void XOsPointEdJig::SetKeyWord(const TCHAR *pszKeyWord)
|
|
{
|
|
m_pszKeyword = pszKeyWord;
|
|
}
|
|
|
|
void XOsPointEdJig::SetPrompt(const TCHAR *pszPormpt)
|
|
{
|
|
m_pszPrompt = pszPormpt;
|
|
}
|
|
|
|
void XOsPointEdJig::SetptFrom(const XPoint &ptFrom)
|
|
{
|
|
m_pDrawEnt->SetBasePoint(ptFrom);
|
|
}
|
|
|
|
void XOsPointEdJig::SetptTo(const XPoint &ptTo)
|
|
{
|
|
m_ptTo = ptTo;
|
|
}
|
|
|
|
XPoint XOsPointEdJig::GetptTo() const
|
|
{
|
|
return m_ptTo;
|
|
}
|
|
|
|
void XOsPointEdJig::SetUsageFlag(int nFlag)
|
|
{
|
|
m_pDrawEnt->SetDrawShape(nFlag);
|
|
}
|
|
|
|
void XOsPointEdJig::SetRectAngle(double dAngle)
|
|
{
|
|
m_pDrawEnt->SetRectAngle(dAngle);
|
|
}
|
|
|
|
////////////////////////////////////////
|
|
XCurvePickSet::XCurvePickSet():PickSet(SS_FREE)
|
|
{
|
|
|
|
}
|
|
|
|
void XCurvePickSet::SetLayerFilter(XStringList &lstLay)
|
|
{
|
|
m_lstLayerFilter=lstLay;
|
|
}
|
|
|
|
void XCurvePickSet::SetDxfNameFilter(XStringList &lstDxf)
|
|
{
|
|
m_lstDxfNameFilter=lstDxf;
|
|
}
|
|
|
|
// 给定窗口进行搜索
|
|
int XCurvePickSet::GetByCrossing(const XPoint &ptLow, const XPoint &ptUp)
|
|
{
|
|
XDbBlockTableRec objMSpace;
|
|
if(!objMSpace)
|
|
return RTERROR;
|
|
int nRet=RTNONE;
|
|
XRectAngle rect(ptLow, ptUp);
|
|
XPoint ptMid;
|
|
Midpoint(ptLow, ptUp, ptMid);
|
|
AcDbBlockTableRecordIterator* pBlockIterator=NULL;
|
|
Acad::ErrorStatus es = objMSpace.m_pBlockTableRec->newIterator(pBlockIterator);
|
|
ASSERT(es==Acad::eOk && pBlockIterator!=NULL);
|
|
|
|
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step()) {
|
|
AcDbEntity *pEntity=NULL;
|
|
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
|
|
if(es!=Acad::eOk) continue;
|
|
ASSERT(pEntity);
|
|
XDbObject vTemp(pEntity);
|
|
//不处理不可见的实体
|
|
if (pEntity->visibility() == AcDb::kInvisible) {
|
|
continue;
|
|
}
|
|
AcDbCurve *pCurve=AcDbCurve::cast(pEntity);
|
|
if(!pCurve)
|
|
continue;
|
|
if(!!m_lstDxfNameFilter) {
|
|
const TCHAR *pszDxfName=pEntity->isA()->dxfName();
|
|
if(m_lstDxfNameFilter.Index(pszDxfName, 0)<0)
|
|
continue;
|
|
}
|
|
AcDbObjectId idLayer=pEntity->layerId();
|
|
OPENOBJ_BEGIN(idLayer, AcDb::kForRead, AcDbLayerTableRecord, pLayer);
|
|
if(pLayer) {
|
|
if(pLayer && pLayer->isFrozen() || pLayer->isOff())
|
|
continue;
|
|
}
|
|
OPENOBJ_END();
|
|
if(!!m_lstLayerFilter) {
|
|
TCHAR *pszLayer=pEntity->layer();
|
|
ASSERT(pszLayer);
|
|
if(m_lstLayerFilter.Index(pszLayer, 0)<0) {
|
|
delete pszLayer;
|
|
continue;
|
|
}
|
|
delete pszLayer;
|
|
}
|
|
XPoint ptCloseToCurve;
|
|
if(pCurve->getClosestPointTo(ptMid, ptCloseToCurve)==Acad::eOk &&
|
|
(ptCloseToCurve&rect)==PR_INSIDE) {
|
|
Entity ent;
|
|
VERIFY(acdbGetAdsName(ent.name, pCurve->objectId())==Acad::eOk);
|
|
*this += ent;
|
|
nRet=RTNORM;
|
|
}
|
|
}
|
|
delete pBlockIterator;
|
|
return nRet;
|
|
} |