344 lines
7.6 KiB
C++
344 lines
7.6 KiB
C++
#include "stdafx.h"
|
|
#include "StdArx.h"
|
|
#include "AecSupportFunc.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
static void FreeBuffer(AcDbVoidPtrArray& arCurves)
|
|
{
|
|
for (int i = 0;i < arCurves.length();i++)
|
|
{
|
|
AcDbEntity* pEnt = (AcDbEntity*)arCurves.at(i);
|
|
if (pEnt != NULL)
|
|
{
|
|
DELETE_PTR(pEnt);
|
|
}
|
|
}
|
|
arCurves.setLogicalLength(0);
|
|
}
|
|
|
|
AcGePoint3d TSupportFunc::Mid(AcGePoint3d ptGe1,AcGePoint3d ptGe2)
|
|
{
|
|
return AcGePoint3d((ptGe1.x + ptGe2.x) / 2.0,(ptGe1.y + ptGe2.y) / 2.0,(ptGe1.z + ptGe2.z) / 2.0);
|
|
}
|
|
|
|
double TSupportFunc::PixelToWcs(int nPixel)
|
|
{
|
|
ads_point ptScreenSize;
|
|
double nViewSize;
|
|
struct resbuf rb1,rb2;
|
|
acedGetVar(_T("ScreenSize"), &rb1);
|
|
acedGetVar(_T("ViewSize"), &rb2);
|
|
nViewSize = rb2.resval.rreal;
|
|
ads_point_set(rb1.resval.rpoint,ptScreenSize);
|
|
|
|
if (ptScreenSize[1] < 1.0E-6 || nViewSize < 1.0E-6)
|
|
return 0.0;
|
|
|
|
double hight = (nViewSize / ptScreenSize[Y]) * nPixel;
|
|
return hight;
|
|
}
|
|
|
|
AcGePoint3d TSupportFunc::Mid(AcDbCurve* pCurve)
|
|
{
|
|
AcGePoint3d ptSta,ptEnd;
|
|
pCurve->getStartPoint(ptSta);
|
|
pCurve->getEndPoint(ptEnd);
|
|
|
|
AcDbLine* pLine = AcDbLine::cast(pCurve);
|
|
if (pLine != NULL)
|
|
{
|
|
return Mid(ptSta,ptEnd);
|
|
}
|
|
|
|
AcDbArc* pArc = AcDbArc::cast(pCurve);
|
|
if (pArc != NULL)
|
|
{
|
|
AcGePoint3d ptMid = Mid(ptSta,ptEnd);
|
|
AcGePoint3d ptCen = pArc->center();
|
|
|
|
AcGeVector3d vt = ptEnd - ptSta;
|
|
vt.normalize();
|
|
vt.rotateBy(PI / 2.0,pArc->normal());
|
|
ptSta = ptCen + pArc->radius() * 2.0 * vt;
|
|
ptEnd = ptCen - pArc->radius() * 2.0 * vt;
|
|
|
|
AcDbLine line(ptSta,ptEnd);
|
|
|
|
AcGePoint3dArray pts;
|
|
line.intersectWith(pArc,AcDb::kOnBothOperands,pts);
|
|
|
|
if (pts.length() > 0)
|
|
return pts.first();
|
|
}
|
|
|
|
//判断 pcurve的中点是否在 other 上
|
|
double dSta = 0.0,dEnd = 0.0;
|
|
pCurve->getStartParam(dSta);
|
|
pCurve->getEndParam(dEnd);
|
|
pCurve->getPointAtParam(dSta + (dEnd - dSta) / 2.0,ptSta);
|
|
return ptSta;
|
|
}
|
|
|
|
AcDbArc* TSupportFunc::FormatArc(AcGePoint3d& ptGe1,AcGePoint3d& ptGe2,AcGePoint3d& ptGe3)
|
|
{
|
|
AcDbArc* pArcThis = NULL;
|
|
AcGeCircArc3d cirArc3d;
|
|
cirArc3d.set(ptGe1,ptGe2,ptGe3);
|
|
|
|
AcDbCircle cir;
|
|
cir.setCenter(cirArc3d.center());
|
|
cir.setRadius(cirArc3d.radius());
|
|
cir.setNormal(cirArc3d.normal());
|
|
|
|
AcGePoint3dArray arPts;
|
|
arPts.append(ptGe1);
|
|
arPts.append(ptGe3);
|
|
|
|
AcDbVoidPtrArray arCurPtrs;
|
|
cir.getSplitCurves(arPts,arCurPtrs);
|
|
|
|
double dPara = 0.0;
|
|
AcDbCurve* pCurve = NULL;
|
|
for (int j = 0;j < arCurPtrs.length();j++)
|
|
{
|
|
pCurve = (AcDbCurve*)arCurPtrs.at(j);
|
|
if (pCurve != NULL)
|
|
{
|
|
if (Acad::eOk == pCurve->getParamAtPoint(ptGe2,dPara))
|
|
{
|
|
AcDbArc* pArc = AcDbArc::cast(pCurve);
|
|
if (pArc != NULL)
|
|
{
|
|
pArcThis = pArc;
|
|
arCurPtrs.removeAt(j);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
FreeBuffer(arCurPtrs);
|
|
return pArcThis;
|
|
}
|
|
|
|
// 获取垂足点
|
|
// BOOL TSupportFunc::GetVerticalFootPoint(const TComplexCurve& compCurve, const AcGePoint3d& pickPoint, const AcGePoint3d& lastPoint, AcGePoint3d& ptVerFoot) const
|
|
// {
|
|
// BOOL bIsSuc = FALSE;
|
|
//
|
|
// Aec::TCurveElement el;
|
|
// memset(&el,0,sizeof(Aec::TCurveElement));
|
|
//
|
|
// double dDisToLine = 0.0,dDisOld = 10000.0;
|
|
// AcDbArc* pArc = NULL;
|
|
// AcGePoint3d ptOnLine;
|
|
// AcDbLine line;
|
|
// int nIndex = -1;
|
|
//
|
|
// // 挑选离pick点最近的线
|
|
// for (int i = 0;i < compCurve.length();i++)
|
|
// {
|
|
// el = compCurve.at(i);
|
|
//
|
|
// if (el.ptGe[1].distanceTo(el.ptGe[2]) < 1e-3) // 直线
|
|
// {
|
|
// line.setStartPoint(el.ptGe[0]);
|
|
// line.setEndPoint(el.ptGe[1]);
|
|
//
|
|
// if (line.getClosestPointTo(pickPoint, ptOnLine, Adesk::kTrue) == Acad::eOk)
|
|
// {
|
|
// ptOnLine.z = pickPoint.z;
|
|
// dDisToLine = pickPoint.distanceTo(ptOnLine);
|
|
// if (dDisOld > dDisToLine)
|
|
// {
|
|
// dDisOld = dDisToLine;
|
|
// nIndex = i;
|
|
// }
|
|
// }
|
|
// }
|
|
// else // 曲线
|
|
// {
|
|
// pArc = TCoverBooleanOper::FormatArc(el.ptGe[0],el.ptGe[1],el.ptGe[2]);
|
|
// if (pArc != NULL)
|
|
// {
|
|
// if (pArc->getClosestPointTo(pickPoint, ptOnLine, Adesk::kTrue) == Acad::eOk)
|
|
// {
|
|
// dDisToLine = pickPoint.distanceTo(ptOnLine);
|
|
// if (dDisOld > dDisToLine)
|
|
// {
|
|
// dDisOld = dDisToLine;
|
|
// nIndex = i;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// // 找到第一次取的点到该线的垂点
|
|
// if (nIndex != -1)
|
|
// {
|
|
// el = compCurve.at(nIndex);
|
|
//
|
|
// if (el.ptGe[1].distanceTo(el.ptGe[2]) < 1e-3) // 直线
|
|
// {
|
|
// line.setStartPoint(el.ptGe[0]);
|
|
// line.setEndPoint(el.ptGe[1]);
|
|
//
|
|
// if (line.getClosestPointTo(lastPoint, ptOnLine, Adesk::kTrue) == Acad::eOk)
|
|
// {
|
|
// ptVerFoot = ptOnLine;
|
|
// bIsSuc = TRUE;
|
|
// }
|
|
// }
|
|
// else // 曲线
|
|
// {
|
|
// pArc = TCoverBooleanOper::FormatArc(el.ptGe[0],el.ptGe[1],el.ptGe[2]);
|
|
// if (pArc != NULL)
|
|
// {
|
|
// if (pArc->getClosestPointTo(lastPoint, ptOnLine, Adesk::kTrue) == Acad::eOk)
|
|
// {
|
|
// ptVerFoot = ptOnLine;
|
|
// bIsSuc = TRUE;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// return bIsSuc;
|
|
// }
|
|
|
|
// 获取最近点
|
|
// BOOL TSupportFunc::GetNearestPoint(const TComplexCurve& compCurve, const AcGePoint3d& pickPoint, AcGePoint3d& ptNear) const
|
|
// {
|
|
// BOOL bFind = FALSE;
|
|
// AcDbLine line;
|
|
// AcDbArc* pArc = NULL;
|
|
// double dDisToLine = 0.0,dDisOld = 10000.0;
|
|
// AcGePoint3d ptOnLine;
|
|
//
|
|
// // 挑选离pick点最近的线
|
|
// Aec::TCurveElement el;
|
|
// memset(&el,0,sizeof(Aec::TCurveElement));
|
|
//
|
|
// for (int i = 0;i < compCurve.length();i++)
|
|
// {
|
|
// el = compCurve.at(i);
|
|
//
|
|
// if (el.ptGe[1].distanceTo(el.ptGe[2]) < 1e-3) // 直线
|
|
// {
|
|
// line.setStartPoint(el.ptGe[0]);
|
|
// line.setEndPoint(el.ptGe[1]);
|
|
//
|
|
// if (line.getClosestPointTo(pickPoint, ptOnLine) == Acad::eOk)
|
|
// {
|
|
// ptOnLine.z = pickPoint.z;
|
|
// dDisToLine = pickPoint.distanceTo(ptOnLine);
|
|
// if (dDisOld > dDisToLine)
|
|
// {
|
|
// dDisOld = dDisToLine;
|
|
// ptNear = ptOnLine;
|
|
// bFind = TRUE;
|
|
// }
|
|
// }
|
|
// }
|
|
// else // 曲线
|
|
// {
|
|
// pArc = TCoverBooleanOper::FormatArc(el.ptGe[0],el.ptGe[1],el.ptGe[2]);
|
|
// if (pArc != NULL)
|
|
// {
|
|
// if (pArc->getClosestPointTo(pickPoint, ptOnLine) == Acad::eOk)
|
|
// {
|
|
// dDisToLine = pickPoint.distanceTo(ptOnLine);
|
|
// if (dDisOld > dDisToLine)
|
|
// {
|
|
// dDisOld = dDisToLine;
|
|
// ptNear = ptOnLine;
|
|
// bFind = TRUE;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// return bFind;
|
|
// }
|
|
|
|
// abc@bcd@ : sRetData = abc,sSrc = bcd@
|
|
BOOL TSupportFunc::SplitString(LPCTSTR pszKey, CString& sRetData, CString& sSrc) const
|
|
{
|
|
sRetData.Empty();
|
|
if (sSrc.IsEmpty() || pszKey == NULL)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
int nPos = sSrc.Find(pszKey, 0);
|
|
if (nPos > 0)
|
|
{
|
|
sRetData = sSrc.Left(nPos);
|
|
sSrc = sSrc.Right(sSrc.GetLength() - nPos - 1);
|
|
|
|
return TRUE;
|
|
}
|
|
else
|
|
{
|
|
sRetData = sSrc;
|
|
sRetData.TrimLeft();
|
|
sRetData.TrimRight();
|
|
if (!sRetData.IsEmpty())
|
|
{
|
|
sSrc.Empty();
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
// abc@bcd@ = 2;
|
|
int TSupportFunc::GetSplitedCount(LPCTSTR pszKey, LPCTSTR pszSrc) const
|
|
{
|
|
int nCount = 0;
|
|
|
|
CString sTmp;
|
|
CString sSrc(pszSrc);
|
|
while (SplitString(pszKey, sTmp, sSrc))
|
|
{
|
|
nCount++;
|
|
}
|
|
|
|
return nCount;
|
|
}
|
|
|
|
// int TSupportFunc::GetClapboardDimension(TDbObjXDataMap* pXdMap, AcGeDoubleArray& arDimen,LPCTSTR pszClapType) const
|
|
// {
|
|
// arDimen.setLogicalLength(0);
|
|
//
|
|
// if (pXdMap != NULL)
|
|
// {
|
|
// CString scbData,sData,sOffset;
|
|
// if(pXdMap->GetAt(pszClapType, scbData))
|
|
// {
|
|
// while (SplitString(KEY_CLP_MAIN_KEY,sData,scbData))
|
|
// {
|
|
// if (SplitString(KEY_CLP_SUB_KEY,sOffset,sData))
|
|
// {
|
|
// arDimen.append(_tstof(sOffset));
|
|
// }
|
|
// }
|
|
//
|
|
// if (arDimen.length() > 0)
|
|
// {
|
|
// arDimen.removeLast();
|
|
// }
|
|
// }
|
|
// }
|
|
// return arDimen.length();
|
|
// }
|
|
|
|
|