973 lines
23 KiB
C++
973 lines
23 KiB
C++
#include "stdafx.h"
|
||
#include "LableThunderBX.h"
|
||
#include "ThunderXData.h"
|
||
#include "ktsetting.h"
|
||
|
||
CLableThunderBX::CLableThunderBX(void)
|
||
{
|
||
m_bFold = FALSE;
|
||
}
|
||
|
||
CLableThunderBX::~CLableThunderBX(void)
|
||
{
|
||
}
|
||
|
||
bool CLableThunderBX::DocGetMeterUnitDraw()
|
||
{
|
||
struct resbuf rb;
|
||
acedGetVar(_T("INSUNITS"),&rb);
|
||
|
||
if (rb.resval.rint == AcDb::kUnitsMeters)
|
||
{
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
void CLableThunderBX::LablePntBX()
|
||
{
|
||
int nUnionHeight = 1, nDis = 1, nProRange = 1;
|
||
CString sTextHeight;
|
||
CRegProperty regProp(GetRegLocation(), TEL_OBJECTKEY);
|
||
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
||
regProp.GetValue(KEY_UNIONPRO_HEIGHT,nUnionHeight);
|
||
regProp.GetValue(KEY_SPACE_BETWEEN,nDis);
|
||
regProp.GetValue(KEY_HORPRO_RANGE,nProRange);
|
||
regProp.GetValue(KEY_FONTLABLE_HEIGHT,sTextHeight);
|
||
|
||
// 获取选取的圆的圆心点
|
||
AcGePoint3d ptFir;
|
||
AcDbObjectId idCircle1;
|
||
if (!GetSelectCircleCenter(_T("\n 请选择第一个保护圆<退出>:"), ptFir, idCircle1))
|
||
{
|
||
return;
|
||
}
|
||
AcGePoint3d ptSec;
|
||
AcDbObjectId idCircle2;
|
||
if (!GetSelectCircleCenter(_T("\n 请选择第二个保护圆<退出>:"), ptSec, idCircle2))
|
||
{
|
||
return;
|
||
}
|
||
|
||
CString sTemp,sTemp2;
|
||
CThunderXData thunderXData;
|
||
thunderXData.GetXData(idCircle1,TEL_GROUP_NO,sTemp);
|
||
thunderXData.GetXData(idCircle2,TEL_GROUP_NO,sTemp2);
|
||
if (_ttoi(sTemp2) != _ttoi(sTemp))
|
||
{
|
||
AfxMessageBox(_T("请选择同一组的2个圆"));
|
||
return;
|
||
}
|
||
|
||
double dProH1 = 1,dProH2 = 2;
|
||
thunderXData.GetXData(idCircle1,TEL_CURRENT_PROHEIGHT,sTemp);
|
||
dProH1 = _tstof(sTemp);
|
||
thunderXData.GetXData(idCircle2,TEL_CURRENT_PROHEIGHT,sTemp);
|
||
dProH2 = _tstof(sTemp);
|
||
if (dProH1 > 0 && fabs(dProH1-dProH2) > 1e-3)
|
||
{
|
||
AfxMessageBox(_T("请选择同一保护高度的2个圆"));
|
||
return;
|
||
}
|
||
|
||
// 获取避雷针ID
|
||
AcDbObjectId idThunder1, idThunder2;
|
||
if (!thunderXData.GetEntityIdFromExData(idCircle1, idThunder1, TEL_THUNDER_ID))
|
||
{
|
||
acutPrintf(_T("请确保两避雷针都在屏幕范围内!"));
|
||
return;
|
||
}
|
||
if (!thunderXData.GetEntityIdFromExData(idCircle2, idThunder2, TEL_THUNDER_ID))
|
||
{
|
||
acutPrintf(_T("请确保两避雷针都在屏幕范围内!"));
|
||
return;
|
||
}
|
||
CStringArray arsXData1, arsXData2;
|
||
// 获取避雷针扩展数据
|
||
if (!thunderXData.GetBaseInformationExData(idThunder1, arsXData1, TEL_THUNDER_BASEINFOR))
|
||
{
|
||
return;
|
||
}
|
||
if (!thunderXData.GetBaseInformationExData(idThunder2, arsXData2, TEL_THUNDER_BASEINFOR))
|
||
{
|
||
return;
|
||
}
|
||
|
||
double dScale = 1.0;
|
||
if (!DocGetMeterUnitDraw())
|
||
dScale *= 1000.0;
|
||
|
||
double dProHeight = dProH1;
|
||
ptFir.z = dProHeight*dScale;
|
||
ptSec.z = dProHeight*dScale;
|
||
double dDis = ptFir.distanceTo(ptSec);
|
||
double dHeight1 = 0.0, dGroundRadius = 0.0, dHeight2 = 0.0;
|
||
if (arsXData1.GetSize() < 1) return;
|
||
dHeight1 = _tstof(arsXData1.GetAt(CThunderXData::eXDataPinHeight));
|
||
if (arsXData2.GetSize() < 1) return;
|
||
dHeight2 = _tstof(arsXData2.GetAt(CThunderXData::eXDataPinHeight));
|
||
double dTemp = 0.0;
|
||
AcGePoint3d ptTemp;
|
||
// 交换两针高,dHeight1矮针的高度
|
||
if (dHeight1 > dHeight2)
|
||
{
|
||
dTemp = dHeight1;
|
||
dHeight1 = dHeight2;
|
||
dHeight2 = dTemp;
|
||
ptTemp = ptFir;
|
||
ptFir = ptSec;
|
||
ptSec = ptTemp;
|
||
}
|
||
dGroundRadius = _tstof(arsXData2.GetAt(CThunderXData::eXDataPinRadius));
|
||
if (fabs(dHeight1 - dHeight2) < 0.01)
|
||
{
|
||
if (dDis >= 2 * pow(dHeight2 * dScale * (2 * dGroundRadius * dScale -
|
||
dHeight2 * dScale), 0.5))
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (dDis >= pow(dHeight1 * dScale * (2 * dGroundRadius * dScale -
|
||
dHeight1 * dScale), 0.5) +
|
||
pow(dHeight2 * dScale * (2 * dGroundRadius * dScale -
|
||
dHeight2 * dScale), 0.5))
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
// 计算d1
|
||
double d1 = ((dGroundRadius - dHeight2)*(dGroundRadius - dHeight2) -
|
||
(dGroundRadius - dHeight1)*(dGroundRadius - dHeight1) +
|
||
(dDis/dScale)*(dDis/dScale))/ (2 * dDis/dScale);
|
||
d1 = fabs(d1);
|
||
double dBx1 = sqrt(dHeight1 * (2 * dGroundRadius - dHeight1) - d1 * d1);
|
||
double dBx2 = sqrt(dProHeight * (2 * dGroundRadius - dProHeight));
|
||
double dBx = dBx1 - dBx2;
|
||
if (dBx < 0.0)
|
||
{
|
||
acutPrintf(_T("\n 不存在联合保护区域!"));
|
||
return;
|
||
}
|
||
// 获取区域边界点
|
||
AcGePoint3d ptReg;
|
||
if (!GetSelectRegionPoint(ptReg))
|
||
{
|
||
return;
|
||
}
|
||
if (fabs(ptReg.z-dProHeight*dScale) > 1e-3)
|
||
{
|
||
AfxMessageBox(_T("请选择同一保护高度的联合区域"));
|
||
return;
|
||
}
|
||
|
||
// 避雷针距离D向量
|
||
AcGeVector3d vtD = ptSec - ptFir;
|
||
AcDbLine* dLine = new AcDbLine(ptFir, ptSec);
|
||
// 获取在直线D上的投影点,用于确定向量
|
||
AcGePoint3d ptPro;
|
||
if (dLine->getClosestPointTo(ptReg, ptPro, Adesk::kTrue) != Acad::eOk)
|
||
{
|
||
delete dLine;
|
||
return;
|
||
}
|
||
|
||
// bx 向量
|
||
AcGePoint3d ptBxBeg;
|
||
dLine->getPointAtDist(d1 * dScale, ptBxBeg);
|
||
AcGeVector3d vtBxLine = ptReg - ptPro;
|
||
vtBxLine.normalize();
|
||
vtBxLine *= dBx * dScale;
|
||
AcGePoint3d ptBxEnd = ptBxBeg + vtBxLine;
|
||
AcDbLine* BxLine = new AcDbLine(ptBxBeg, ptBxEnd);
|
||
KTSetting::InitLayer(LAY_EL_THUNDER_DIM);
|
||
dLine->setLayer(LAY_EL_THUNDER_DIM);
|
||
AddToCurrentSpace(dLine, Adesk::kTrue);
|
||
BxLine->setLayer(LAY_EL_THUNDER_DIM);
|
||
AddToCurrentSpace(BxLine, Adesk::kTrue);
|
||
CString sTextHx = _T("");
|
||
CString sTextD = _T("");
|
||
CString sTextBx = _T("");
|
||
CString sTextDandHx = _T("");
|
||
|
||
XPoint ptHxS,ptHxE,ptBxS,ptBxE;
|
||
ptBxS = ptBxEnd;
|
||
AcGeVector3d vtBxText = ptFir - ptSec;
|
||
if (vtBxText.angleTo(AcGeVector3d::kXAxis) < PI/2)
|
||
{
|
||
vtBxText = ptSec - ptFir;
|
||
}
|
||
|
||
if (nDis && nUnionHeight)
|
||
{
|
||
sTextDandHx.Format(_T("D = %.2f, hx = %.2f"), dDis / dScale, dProHeight);
|
||
if (!sTextDandHx.IsEmpty())
|
||
{
|
||
// 画D,hx
|
||
DrawBxText(ptFir, ptSec, sTextDandHx, ptBxEnd - ptBxBeg);
|
||
}
|
||
}
|
||
else if (nDis)
|
||
{
|
||
sTextD.Format(_T("D = %.2fm"), dDis / dScale);
|
||
if (!sTextD.IsEmpty())
|
||
{
|
||
//画D
|
||
DrawBxText(ptFir, ptSec, sTextD,ptBxEnd - ptBxBeg);
|
||
}
|
||
}
|
||
else if (nUnionHeight)
|
||
{
|
||
sTextHx.Format(_T("hx = %.2fm"), dProHeight);
|
||
if (!sTextHx.IsEmpty())
|
||
{
|
||
// 画Hx
|
||
DrawBxText(ptFir, ptSec, sTextHx, ptBxEnd - ptBxBeg);
|
||
/*
|
||
// 旧版位置方向
|
||
// double dTextHight = _tstof(sTextHeight);
|
||
// double dPScale = DocGetPScale();
|
||
// if (dTextHight < 1.0E-6)
|
||
// {
|
||
// dTextHight = 3.0;
|
||
// }
|
||
// double dTextHxLen = sTextHx.GetLength()*dTextHight*dPScale;
|
||
//
|
||
// //确定HX注释文字的起始点
|
||
// vtBxText.normalize();
|
||
// ptHxE = ptBxS;
|
||
// ptHxS = ptBxS + vtBxText*dTextHxLen;
|
||
//
|
||
// DrawBxText(ptHxS, ptHxE, sTextHx, ptBxEnd - ptBxBeg);
|
||
*/
|
||
}
|
||
}
|
||
|
||
// 画Bx
|
||
if (nProRange)
|
||
{
|
||
sTextBx.Format(_T("bx = %.2fm"), dBx);
|
||
if (!sTextBx.IsEmpty())
|
||
{
|
||
DrawBxText(ptBxBeg, ptBxEnd, sTextBx, ptFir - ptSec);
|
||
|
||
/*
|
||
// 旧版位置方向
|
||
// double dTextHight = _tstof(sTextHeight);
|
||
// double dPScale = DocGetPScale();
|
||
// if (dTextHight < 1.0E-6)
|
||
// {
|
||
// dTextHight = 3.0;
|
||
// }
|
||
// double dTextBxLen = sTextBx.GetLength()*dTextHight*dPScale;
|
||
// double dTextHxLen = sTextHx.GetLength()*dTextHight*dPScale;
|
||
//
|
||
// //确定BX和HX注释文字的起始点
|
||
// vtBxText.normalize();
|
||
// ptBxE = ptBxS - vtBxText*dTextBxLen;
|
||
//
|
||
// DrawBxText(ptBxS,ptBxE,sTextBx,ptBxEnd - ptBxBeg);
|
||
*/
|
||
}
|
||
}
|
||
}
|
||
|
||
void CLableThunderBX::LabeLineBX()
|
||
{
|
||
//
|
||
int nUnionHeight = 1, nDis = 1, nProRange = 1;
|
||
CString sTextHeight;
|
||
CRegProperty regProp(GetRegLocation(), TEL_OBJECTKEY);
|
||
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
||
regProp.GetValue(KEY_UNIONPRO_HEIGHT,nUnionHeight);
|
||
regProp.GetValue(KEY_SPACE_BETWEEN,nDis);
|
||
regProp.GetValue(KEY_HORPRO_RANGE,nProRange);
|
||
regProp.GetValue(KEY_FONTLABLE_HEIGHT,sTextHeight);
|
||
|
||
//
|
||
RBList rbMask = ads_buildlist(RTDXF0, _T("LWPOLYLINE"), 8, LAY_EL_LIGHTNING_LINE, NULL);
|
||
Entity ent1,ent2;
|
||
CThunderXData thunderXdata;
|
||
if(SelectEntity(_T("\n请选择第一个避雷线:<退出>"),ent1,rbMask) != RTNORM)
|
||
{
|
||
return ;
|
||
}
|
||
|
||
if(SelectEntity(_T("\n请选择第二个避雷线:<退出>"),ent2,rbMask) != RTNORM)
|
||
{
|
||
return ;
|
||
}
|
||
|
||
CString sGroup1 = _T(""),sGroup2 = _T("");
|
||
double dProH1 = 0.0,dProH2 = 0.0;
|
||
double dLineH1 = 0.0,dLineH2 = 0.0;
|
||
double dRadius = 0.0;
|
||
AcGePoint3d ptS1,ptE1,ptS2,ptE2;
|
||
CString sLineH,sRadius;
|
||
|
||
AcDbPolyline* pLine = NULL;
|
||
OPENOBJ_BEGIN(ent1,AcDb::kForRead,AcDbEntity,pEnt1);
|
||
if (pEnt1)
|
||
{
|
||
thunderXdata.GetXData(pEnt1,KEY_LINE_GROUP_NO,sGroup1);
|
||
thunderXdata.GetXData(pEnt1,KEY_LINE_HEIGHT,sLineH);
|
||
thunderXdata.GetXData(pEnt1,KEY_LINE_PRO_RADIUS,sRadius);
|
||
dRadius = _tstof(sRadius);
|
||
dLineH1 = _tstof(sLineH);
|
||
if (pLine = AcDbPolyline::cast(pEnt1))
|
||
{
|
||
pLine->getStartPoint(ptS1);
|
||
pLine->getEndPoint(ptE1);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
pLine = NULL;
|
||
OPENOBJ_BEGIN(ent2,AcDb::kForRead,AcDbEntity,pEnt2);
|
||
if (pEnt2)
|
||
{
|
||
thunderXdata.GetXData(pEnt2,KEY_LINE_GROUP_NO,sGroup2);
|
||
thunderXdata.GetXData(pEnt2,KEY_LINE_HEIGHT,sLineH);
|
||
dLineH2 = _tstof(sLineH);
|
||
if (pLine = AcDbPolyline::cast(pEnt2))
|
||
{
|
||
pLine->getStartPoint(ptS2);
|
||
pLine->getEndPoint(ptE2);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
if (sGroup1.CompareNoCase(sGroup2))
|
||
{
|
||
::AfxMessageBox(_T("\n请选择同一组的2个避雷线!"));
|
||
return;
|
||
}
|
||
|
||
if (sGroup2.IsEmpty())
|
||
{
|
||
AfxMessageBox(_T("\n所选非避雷线,请选择2条避雷线!"));
|
||
}
|
||
|
||
//
|
||
Entity entPro;
|
||
XPoint ptPick;
|
||
RBList rbPro = ads_buildlist(RTDXF0, _T("REGION"), 8, LAY_EL_THUNDER_2D, NULL);
|
||
int nRet = SelectEntity1(_T("\n请选择联合保护区域(面域):<退出>"),entPro,ptPick,rbPro);
|
||
if (nRet != RTNORM)
|
||
{
|
||
return ;
|
||
}
|
||
double dProH = 0.0;
|
||
OPENOBJ_BEGIN(entPro,AcDb::kForRead,AcDbEntity,pPro);
|
||
if (pPro)
|
||
{
|
||
CString sProH;
|
||
thunderXdata.GetXData(pPro,TEL_CURRENT_PROHEIGHT,sProH);
|
||
dProH = _tstof(sProH);
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
AcGePoint3d ptFrist,ptSecond;
|
||
if (ptS1.distanceTo(ptPick) > ptE1.distanceTo(ptPick))
|
||
{
|
||
ptFrist = ptE1;
|
||
}
|
||
else
|
||
ptFrist = ptS1;
|
||
|
||
if (ptS2.distanceTo(ptPick) > ptE2.distanceTo(ptPick))
|
||
{
|
||
ptSecond = ptE2;
|
||
}
|
||
else
|
||
ptSecond = ptS2;
|
||
|
||
double dScale = 1.0;
|
||
if (!DocGetMeterUnitDraw())
|
||
dScale *= 1000.0;
|
||
|
||
ptFrist.z = dProH*dScale;
|
||
ptSecond.z = dProH*dScale;
|
||
|
||
double dDis = ptFrist.distanceTo(ptSecond);
|
||
|
||
// 交换两针高,dLineH1矮针的高度
|
||
if (dLineH1 > dLineH2)
|
||
{
|
||
double dTemp = dLineH1;
|
||
dLineH1 = dLineH2;
|
||
dLineH2 = dTemp;
|
||
AcGePoint3d ptTemp = ptFrist;
|
||
ptFrist = ptSecond;
|
||
}
|
||
if (fabs(dLineH1 - dLineH2) < 0.01)
|
||
{
|
||
if (dDis >= 2 * pow(dLineH1 * dScale * (2 * dRadius * dScale -
|
||
dLineH1 * dScale), 0.5))
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (dDis >= pow(dLineH1 * dScale * (2 * dRadius * dScale -
|
||
dLineH1 * dScale), 0.5) +
|
||
pow(dLineH2 * dScale * (2 * dRadius * dScale -
|
||
dLineH2 * dScale), 0.5))
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
// 计算d1
|
||
double d1 = ((dRadius - dLineH2)*(dRadius - dLineH2) -
|
||
(dRadius - dLineH1)*(dRadius - dLineH1) +
|
||
(dDis/dScale)*(dDis/dScale))/ (2 * dDis/dScale);
|
||
d1 = fabs(d1);
|
||
double dBx1 = sqrt(dLineH1 * (2 * dRadius - dLineH1) - d1 * d1);
|
||
double dBx2 = sqrt(dProH * (2 * dRadius - dProH));
|
||
double dBx = dBx1 - dBx2;
|
||
if (dBx < 0.0)
|
||
{
|
||
acutPrintf(_T("\n 不存在联合保护区域!"));
|
||
return;
|
||
}
|
||
|
||
//开始绘制
|
||
// 避雷针距离D向量
|
||
AcGeVector3d vtD = ptSecond - ptFrist;
|
||
AcDbLine* dLine = new AcDbLine(ptFrist, ptSecond);
|
||
// 获取在直线D上的投影点,用于确定向量
|
||
AcGePoint3d ptPro;
|
||
if (dLine->getClosestPointTo(ptPick, ptPro, Adesk::kTrue) != Acad::eOk)
|
||
{
|
||
delete dLine;
|
||
return;
|
||
}
|
||
|
||
// bx 向量
|
||
AcGePoint3d ptBxBeg;
|
||
dLine->getPointAtDist(d1 * dScale, ptBxBeg);
|
||
ptPick.z = ptPro.z;
|
||
AcGeVector3d vtBxLine = ptPick - ptPro;
|
||
vtBxLine.normalize();
|
||
vtBxLine *= dBx * dScale;
|
||
AcGePoint3d ptBxEnd = ptBxBeg + vtBxLine;
|
||
AcDbLine* BxLine = new AcDbLine(ptBxBeg, ptBxEnd);
|
||
KTSetting::InitLayer(LAY_EL_THUNDER_DIM);
|
||
dLine->setLayer(LAY_EL_THUNDER_DIM);
|
||
AddToCurrentSpace(dLine, Adesk::kTrue);
|
||
BxLine->setLayer(LAY_EL_THUNDER_DIM);
|
||
AddToCurrentSpace(BxLine, Adesk::kTrue);
|
||
|
||
// 绘制
|
||
CString sTextHx = _T("");
|
||
CString sTextD = _T("");
|
||
CString sTextBx = _T("");
|
||
CString sTextDandHx = _T("");
|
||
|
||
XPoint ptHxS,ptHxE,ptBxS,ptBxE;
|
||
ptBxS = ptBxEnd;
|
||
AcGeVector3d vtBxText = ptFrist - ptSecond;
|
||
if (vtBxText.angleTo(AcGeVector3d::kXAxis) < PI/2)
|
||
{
|
||
vtBxText = ptSecond - ptFrist;
|
||
}
|
||
|
||
if (nDis && nUnionHeight)
|
||
{
|
||
sTextDandHx.Format(_T("D = %.2f, hx = %.2f"), dDis/dScale, dProH);
|
||
if (!sTextDandHx.IsEmpty())
|
||
{
|
||
// 画D,hx
|
||
DrawBxText(ptFrist, ptSecond, sTextDandHx, ptBxEnd - ptBxBeg);
|
||
}
|
||
}
|
||
else if (nDis)
|
||
{
|
||
sTextD.Format(_T("D = %.2fm"), dDis / dScale);
|
||
if (!sTextD.IsEmpty())
|
||
{
|
||
// 画D
|
||
DrawBxText(ptFrist, ptSecond, sTextD,ptBxEnd - ptBxBeg);
|
||
}
|
||
}
|
||
else if (nUnionHeight)
|
||
{
|
||
sTextHx.Format(_T("hx = %.2fm"), dProH);
|
||
if (!sTextHx.IsEmpty())
|
||
{
|
||
// 画Hx
|
||
DrawBxText(ptFrist, ptSecond, sTextHx, ptBxEnd - ptBxBeg);
|
||
|
||
/*
|
||
// 旧版位置方向
|
||
// double dTextHight = _tstof(sTextHeight);
|
||
// double dPScale = DocGetPScale();
|
||
// if (dTextHight < 1.0E-6)
|
||
// {
|
||
// dTextHight = 3.0;
|
||
// }
|
||
// double dTextHxLen = sTextHx.GetLength()*dTextHight*dPScale;
|
||
//
|
||
// // 确定BX和HX注释文字的起始点
|
||
// vtBxText.normalize();
|
||
// ptHxE = ptBxS;
|
||
// ptHxS = ptBxS + vtBxText*dTextHxLen;
|
||
//
|
||
// DrawBxText(ptHxS, ptHxE, sTextHx, ptBxEnd - ptBxBeg);
|
||
*/
|
||
}
|
||
}
|
||
|
||
// 画Bx
|
||
if (nProRange)
|
||
{
|
||
sTextBx.Format(_T("bx = %.2fm"), dBx);
|
||
if (!sTextBx.IsEmpty())
|
||
{
|
||
DrawBxText(ptBxBeg, ptBxEnd ,sTextBx, ptFrist - ptSecond);
|
||
|
||
/*
|
||
// 旧版位置方向
|
||
// double dTextHight = _tstof(sTextHeight);
|
||
// double dPScale = DocGetPScale();
|
||
// if (dTextHight < 1.0E-6)
|
||
// {
|
||
// dTextHight = 3.0;
|
||
// }
|
||
// double dTextBxLen = sTextBx.GetLength()*dTextHight*dPScale;
|
||
//
|
||
// //确定BX和HX注释文字的起始点
|
||
// vtBxText.normalize();
|
||
// ptBxE = ptBxS - vtBxText*dTextBxLen;
|
||
//
|
||
// DrawBxText(ptBxS,ptBxE,sTextBx,ptBxEnd - ptBxBeg);
|
||
*/
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
void CLableThunderBX::LableFoldPntBX()
|
||
{
|
||
m_bFold = TRUE;
|
||
// 获取数据1 避雷针属性
|
||
int nUnionHeight = 1, nDis = 1, nProRange = 1;
|
||
CString sTextHeight;
|
||
CRegProperty regProp(GetRegLocation(), TEL_OBJECTKEY);
|
||
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
||
regProp.GetValue(KEY_FOLD_SPACE_BETWEEN,nDis);
|
||
regProp.GetValue(KEY_FOLD_UNIONPRO_HEIGHT,nUnionHeight);
|
||
regProp.GetValue(KEY_FOLD_HORPRO_RANGE,nProRange);
|
||
regProp.GetValue(KEY_FOLD_FONTLABLE_HEIGHT,sTextHeight);
|
||
|
||
// 获取圆心
|
||
AcGePoint3d ptFir;
|
||
AcDbObjectId idCircle1;
|
||
if (!GetSelectCircleCenter(_T("\n 请选择第一个保护圆<退出>:"), ptFir, idCircle1))
|
||
{
|
||
return;
|
||
}
|
||
AcGePoint3d ptSec;
|
||
AcDbObjectId idCircle2;
|
||
if (!GetSelectCircleCenter(_T("\n 请选择第二个保护圆<退出>:"), ptSec, idCircle2))
|
||
{
|
||
return;
|
||
}
|
||
|
||
CThunderXData thunderXData;
|
||
CString sTemp,sTemp2;
|
||
thunderXData.GetXData(idCircle1,TEL_GROUP_NO,sTemp);
|
||
thunderXData.GetXData(idCircle2,TEL_GROUP_NO,sTemp2);
|
||
if (_ttoi(sTemp2) != _ttoi(sTemp))
|
||
{
|
||
// 判断是否同组圆
|
||
AfxMessageBox(_T("请选择同一组的2个圆"));
|
||
return;
|
||
}
|
||
|
||
// 是否同一保护高度
|
||
double dProH1 = 1,dProH2 = 2;
|
||
thunderXData.GetXData(idCircle1, KEY_FOLD_CURRENT_PROHEIGHT, sTemp);
|
||
dProH1 = _tstof(sTemp);
|
||
thunderXData.GetXData(idCircle2, KEY_FOLD_CURRENT_PROHEIGHT, sTemp);
|
||
dProH2 = _tstof(sTemp);
|
||
if (dProH1 > 0 && fabs(dProH1-dProH2) > 1e-3)
|
||
{
|
||
AfxMessageBox(_T("请选择同一保护高度的2个圆"));
|
||
return;
|
||
}
|
||
|
||
// 获取避雷针ID,是否同一屏幕内 ?
|
||
AcDbObjectId idThunder1, idThunder2;
|
||
if (!thunderXData.GetEntityIdFromExData(idCircle1, idThunder1, KEY_FOLD_THUNDER_ID))
|
||
{
|
||
acutPrintf(_T("请确保两避雷针都在屏幕范围内!"));
|
||
return;
|
||
}
|
||
if (!thunderXData.GetEntityIdFromExData(idCircle2, idThunder2, KEY_FOLD_THUNDER_ID))
|
||
{
|
||
acutPrintf(_T("请确保两避雷针都在屏幕范围内!"));
|
||
return;
|
||
}
|
||
|
||
|
||
// 获取扩展数据?
|
||
CStringArray arsXData1, arsXData2;
|
||
if (!thunderXData.GetBaseInformationExData(idThunder1, arsXData1, TEL_THUNDER_BASEINFOR))
|
||
{
|
||
return;
|
||
}
|
||
if (!thunderXData.GetBaseInformationExData(idThunder2, arsXData2, TEL_THUNDER_BASEINFOR))
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
// 计算
|
||
double dScale = 1.0;
|
||
if(!DocGetMeterUnitDraw())
|
||
{
|
||
dScale *= 1000.0;
|
||
}
|
||
|
||
double dProHeight = dProH1; // 保护高度
|
||
ptFir.z = dProHeight*dScale;
|
||
ptSec.z = dProHeight*dScale;
|
||
double dDis = ptFir.distanceTo(ptSec) / dScale; // 两针距离
|
||
|
||
double dHeight1 = 0.0, dHeight2 = 0.0; // 针高
|
||
if (arsXData1.GetSize() < 1)
|
||
{
|
||
return;
|
||
}
|
||
dHeight1 = _tstof(arsXData1.GetAt(CThunderXData::eXFoldPinHeight));
|
||
|
||
if (arsXData2.GetSize() < 1)
|
||
{
|
||
return;
|
||
}
|
||
dHeight2 = _tstof(arsXData2.GetAt(CThunderXData::eXFoldPinHeight));
|
||
|
||
double dTemp = 0.0;
|
||
AcGePoint3d ptTemp;
|
||
// 交换两针高,dHeight1为矮针的高度
|
||
if (dHeight1 > dHeight2)
|
||
{
|
||
dTemp = dHeight1;
|
||
dHeight1 = dHeight2;
|
||
dHeight2 = dTemp;
|
||
ptTemp = ptFir;
|
||
ptFir = ptSec;
|
||
ptSec = ptTemp;
|
||
}
|
||
|
||
CFoldToolKit* pToolKit = CFoldToolKit::Instance();
|
||
double dBx = 0.0; // Bx
|
||
if (!pToolKit->CalcFoldBx(dHeight1, dHeight2, dDis, dProHeight, dBx))
|
||
{
|
||
acutPrintf(_T("\n 不存在联合保护区域!"));
|
||
return;
|
||
}
|
||
|
||
// 获取区域边界点
|
||
AcGePoint3d ptReg;
|
||
if (!GetSelectRegionPoint(ptReg))
|
||
{
|
||
return;
|
||
}
|
||
ptReg.z = dProH1*dScale; //dProH1*dScale dProHeight*dScale ptSec.z
|
||
if (fabs(ptReg.z-dProHeight*dScale) > 1e-3)
|
||
{
|
||
AfxMessageBox(_T("请选择同一保护高度的联合区域"));
|
||
return;
|
||
}
|
||
|
||
// 避雷针距离D向量
|
||
AcGeVector3d vtD = ptSec - ptFir;
|
||
AcDbLine* dLine = new AcDbLine(ptFir, ptSec); // 两针间直线
|
||
|
||
// 获取在直线D上的投影点,用于确定向量
|
||
AcGePoint3d ptPro;
|
||
if (dLine->getClosestPointTo(ptReg, ptPro, Adesk::kTrue) != Acad::eOk)
|
||
{
|
||
delete dLine;
|
||
return;
|
||
}
|
||
|
||
// 计算d1
|
||
double d1 = 0.0;
|
||
if (dHeight1 != dHeight2)
|
||
{
|
||
// 不等高
|
||
double dDisX = pToolKit->CalcEffectDist(dHeight1, dHeight2, dDis, dProHeight);
|
||
d1 = dDisX / 2;
|
||
}
|
||
else
|
||
{
|
||
// 等高(d1 = 两针连线一半)
|
||
double dR1 = 0.0, dR2 = 0.0;
|
||
OPENOBJ_BEGIN(idCircle1, AcDb::kForRead, AcDbCircle, pCircle1);
|
||
if (pCircle1 != NULL)
|
||
{
|
||
dR1 = pCircle1->radius();
|
||
}
|
||
OPENOBJ_END();
|
||
OPENOBJ_BEGIN(idCircle2, AcDb::kForRead, AcDbCircle, pCircle2);
|
||
if (pCircle2 != NULL)
|
||
{
|
||
dR2 = pCircle2->radius();
|
||
}
|
||
OPENOBJ_END();
|
||
d1 = (dR2 - dHeight2)*(dR2 - dHeight2) - (dR1 - dHeight1)*(dR1 - dHeight1) + dDis / 2;
|
||
d1 = fabs(d1);
|
||
}
|
||
|
||
// bx 向量
|
||
AcGePoint3d ptBxBeg; // Bx线起点
|
||
dLine->getPointAtDist(d1 * dScale, ptBxBeg);
|
||
|
||
AcGeVector3d vtBxLine = ptReg - ptPro;
|
||
vtBxLine.normalize();
|
||
vtBxLine *= dBx * dScale; // Bx大小
|
||
AcGePoint3d ptBxEnd = ptBxBeg + vtBxLine; // Bx线终点
|
||
AcDbLine* BxLine = new AcDbLine(ptBxBeg, ptBxEnd);
|
||
|
||
KTSetting::InitLayer(LAY_EL_THUNDER_DIM);
|
||
dLine->setLayer(LAY_EL_THUNDER_DIM);
|
||
AddToCurrentSpace(dLine, Adesk::kTrue);
|
||
BxLine->setLayer(LAY_EL_THUNDER_DIM);
|
||
AddToCurrentSpace(BxLine, Adesk::kTrue);
|
||
|
||
|
||
// 绘制
|
||
CString sTextHx = _T("");
|
||
CString sTextD = _T("");
|
||
CString sTextBx = _T("");
|
||
CString sTextDandHx = _T("");
|
||
|
||
XPoint ptHxS,ptHxE,ptBxS,ptBxE;
|
||
ptBxS = ptBxEnd;
|
||
AcGeVector3d vtBxText = ptFir - ptSec;
|
||
if (vtBxText.angleTo(AcGeVector3d::kXAxis) < PI/2)
|
||
{
|
||
vtBxText = ptSec - ptFir;
|
||
}
|
||
|
||
if (nDis && nUnionHeight)
|
||
{
|
||
sTextDandHx.Format(_T("D = %.2fm, hx = %.2fm"), dDis, dProHeight);
|
||
if (!sTextDandHx.IsEmpty())
|
||
{
|
||
// 画D,hx
|
||
DrawBxText(ptFir, ptSec, sTextDandHx, ptBxEnd - ptBxBeg);
|
||
}
|
||
}
|
||
else if (nDis)
|
||
{
|
||
sTextD.Format(_T("D = %.2fm"), dDis);
|
||
if (!sTextD.IsEmpty())
|
||
{
|
||
// 画D
|
||
DrawBxText(ptFir, ptSec, sTextD, ptBxEnd - ptBxBeg);
|
||
}
|
||
}
|
||
else if (nUnionHeight)
|
||
{
|
||
sTextHx.Format(_T("hx = %.2fm"), dProHeight);
|
||
if (!sTextHx.IsEmpty())
|
||
{
|
||
// 画Hx
|
||
DrawBxText(ptFir, ptSec, sTextHx, ptBxEnd - ptBxBeg);
|
||
|
||
/*
|
||
// 旧版位置方向
|
||
// double dTextHight = _tstof(sTextHeight);
|
||
// double dPScale = DocGetPScale();
|
||
// if (dTextHight < 1.0E-6)
|
||
// {
|
||
// dTextHight = 3.0;
|
||
// }
|
||
// double dTextHxLen = sTextHx.GetLength()*dTextHight*dPScale;
|
||
//
|
||
// //确定HX注释文字的起始点
|
||
// vtBxText.normalize();
|
||
// ptHxE = ptBxS;
|
||
// ptHxS = ptBxS + vtBxText*dTextHxLen * 2;
|
||
//
|
||
// DrawBxText(ptHxS, ptHxE, sTextHx, ptBxEnd - ptBxBeg);
|
||
*/
|
||
}
|
||
}
|
||
|
||
if (nProRange)
|
||
{
|
||
sTextBx.Format(_T("bx = %.2fm"), dBx);
|
||
if (!sTextBx.IsEmpty())
|
||
{
|
||
// 画Bx
|
||
DrawBxText(ptBxBeg, ptBxEnd, sTextBx, ptFir - ptSec);
|
||
|
||
/*
|
||
// 旧版位置方向
|
||
// double dTextHight = _tstof(sTextHeight);
|
||
// double dPScale = DocGetPScale();
|
||
// if (dTextHight < 1.0E-6)
|
||
// {
|
||
// dTextHight = 3.0;
|
||
// }
|
||
// double dTextBxLen = sTextBx.GetLength()*dTextHight*dPScale;
|
||
//
|
||
// //确定BX和HX注释文字的起始点
|
||
// vtBxText.normalize();
|
||
// ptBxE = ptBxS - vtBxText*dTextBxLen * 2;
|
||
//
|
||
// DrawBxText(ptBxS,ptBxE,sTextBx, ptBxEnd - ptBxBeg);
|
||
*/
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
void CLableThunderBX::LabeFoldLineBX()
|
||
{
|
||
// 获取数据1 避雷针属性
|
||
|
||
// 获取避雷线
|
||
|
||
// 判断是否同组
|
||
|
||
|
||
// 计算
|
||
|
||
|
||
// 绘制
|
||
}
|
||
|
||
// 由Entity(ads_name)获取圆中心点, ID
|
||
bool CLableThunderBX::GetSelectCircleCenter(LPCTSTR pszSelTip, AcGePoint3d& ptGetCent, AcDbObjectId& idCircle)
|
||
{
|
||
if (pszSelTip == NULL)
|
||
{
|
||
return false;
|
||
}
|
||
Entity ent;
|
||
//RBList rbMask = ads_buildlist(RTDXF0, _T("CIRCLE"), 8, LAY_EL_THUNDER_2D, NULL);
|
||
RBList rbMask = ads_buildlist( -4, _T("<or"),
|
||
-4, _T("<and"), RTDXF0, _T("CIRCLE"), 8, LAY_EL_THUNDER_2D, -4, _T("and>"),
|
||
-4, _T("<and"), RTDXF0, _T("CIRCLE"), 8, LAY_EL_THUNDER, -4, _T("and>"),
|
||
-4, _T("or>"), NULL);
|
||
if(SelectEntity(pszSelTip, ent, rbMask) != RTNORM)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
// 获取id
|
||
bool bRet = false;
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbCircle, pCircle);
|
||
if(pCircle)
|
||
{
|
||
ptGetCent = pCircle->center();
|
||
idCircle = pCircle->objectId();
|
||
bRet = true;
|
||
}
|
||
OPENOBJ_END();
|
||
return bRet;
|
||
}
|
||
|
||
// 判断选择的是否为区域并返回选择点
|
||
bool CLableThunderBX::GetSelectRegionPoint(AcGePoint3d& ptReg)
|
||
{
|
||
Entity ent;
|
||
XPoint ptTemp;
|
||
//RBList rbMask1 = ads_buildlist(RTDXF0, _T("REGION, LWPOLYLINE"), 8, LAY_EL_THUNDER_2D, NULL);
|
||
//RBList rbFoldMask(RTDXF0, _T("LWPOLYLINE"), 8, LAY_EL_THUNDER_2D, NULL);
|
||
|
||
RBList rbMask1 = ads_buildlist( -4, _T("<or"),
|
||
-4, _T("<and"), RTDXF0, _T("REGION"), 8, LAY_EL_THUNDER_2D, -4, _T("and>"),
|
||
-4, _T("<and"), RTDXF0, _T("LWPOLYLINE"), 8, LAY_EL_THUNDER_2D, -4, _T("and>"),
|
||
-4, _T("or>"), NULL);
|
||
|
||
|
||
CThunderXData thunderData;
|
||
AcDbPolyline* pLine = NULL;
|
||
if (SelectEntity1(_T("\n 请选择两保护圆之间的保护区域<退出>: "), ent, ptTemp, rbMask1) != RTNORM)
|
||
{
|
||
// 判断PLine是否是折线法联合保护线
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbEntity, pEnt);
|
||
if (pEnt != NULL && (pLine = AcDbPolyline::cast(pEnt)) != NULL)
|
||
{
|
||
m_csGroup.Empty();
|
||
thunderData.GetXData((AcDbEntity*)pLine, KEY_FOLD_GROUP_NO, m_csGroup);
|
||
}
|
||
OPENOBJ_END();
|
||
if (m_csGroup.IsEmpty())
|
||
{
|
||
return false;
|
||
}
|
||
|
||
}
|
||
|
||
// 区域选择点
|
||
ptReg = Ucs2Wcs(ptTemp);
|
||
return true;
|
||
}
|
||
|
||
|
||
// 绘制标注bx文
|
||
void CLableThunderBX::DrawBxText(const AcGePoint3d& ptST,const AcGePoint3d& ptEn,LPCTSTR pszDimName,const AcGeVector3d& vtDim)
|
||
{
|
||
if (pszDimName == NULL)
|
||
{
|
||
acutPrintf(_T("\n 标注名称不能为空!"));
|
||
return;
|
||
}
|
||
CString sTextValue = pszDimName;
|
||
int nColorIndex = 256;
|
||
CString sTextHeight;
|
||
CRegProperty regProp(GetRegLocation(), TEL_OBJECTKEY);
|
||
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
||
sTextHeight = _T("3.0");
|
||
|
||
if (m_bFold)
|
||
{
|
||
regProp.GetValue(KEY_FOLD_FONTLABLE_HEIGHT,sTextHeight);
|
||
regProp.GetValue(KEY_FOLD_FONTLABLE_COLOR,nColorIndex);
|
||
}
|
||
else
|
||
{
|
||
regProp.GetValue(KEY_FONTLABLE_HEIGHT,sTextHeight);
|
||
regProp.GetValue(KEY_FONTLABLE_COLOR,nColorIndex);
|
||
}
|
||
|
||
AcGePoint3d ptFirst(ptST.x,ptST.y,0);
|
||
AcGePoint3d ptEnd(ptEn.x,ptEn.y,0);
|
||
|
||
AcGePoint3d ptPosition;
|
||
AcGeVector3d vec = ptEnd - ptFirst;
|
||
AcGeVector3d vecH = vec/2;
|
||
AcGeVector3d vecV = vtDim;
|
||
vecV.normalize();
|
||
vecV *= DocGetPScale() * (_tstof(sTextHeight) + 1);
|
||
double dAng = vec.angleTo(AcGeVector3d::kXAxis);
|
||
|
||
if (vec.angleTo(AcGeVector3d::kYAxis) > PI/2)
|
||
dAng = 2 * PI - dAng;
|
||
|
||
if (vec.angleTo(AcGeVector3d::kXAxis) > PI/2)
|
||
dAng += PI;
|
||
|
||
AcDbObjectId idStyle = KTSetting::InitTextStyle(_T("Pipe_Dim"));
|
||
ptPosition = ptFirst + vecH;
|
||
|
||
ptPosition -= vecV;
|
||
|
||
AcDbObjectId idLay = KTSetting::InitLayer(EL_TEXT);
|
||
AcDbText* pTextR = new AcDbText(Ucs2Wcs(ptPosition),sTextValue,idStyle,_tstof(sTextHeight)*DocGetPScale(),dAng);
|
||
pTextR->setHorizontalMode(AcDb::kTextMid);
|
||
pTextR->setAlignmentPoint(ptPosition);
|
||
pTextR->setLayer(idLay);
|
||
pTextR->setColorIndex(nColorIndex);
|
||
AddToCurrentSpace(pTextR,Adesk::kTrue);
|
||
}
|