Files
envi-code/SourceCode/Code2026/Dimension/StakeDlg.cpp
T

863 lines
21 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
#include "stdafx.h"
2026-09-28 15:28:50 +08:00
#include "AcDbObjectPtr.h"
#include "globalFunc.h"
#include "StakeDlg.h"
#include "DbStake.h"
#include "RBGroups.h"
#include "TBlockEdJig.h"
#include "DbEquipment.h"
#include "XText.h"
#include <vector>
#include <map>
#include "PickEntSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern AcDbObjectId InitLayer(const TCHAR *szLayer, BOOL bApplyChange = TRUE);
extern AcDbObjectId InitTextStyle(TTextStyle ts, AcDbDatabase *pDb = NULL);
extern AcDbObjectId InitTextStyle(const TCHAR *pszStyle, AcDbDatabase *pDb = NULL);
static CString s_sBetweenDis = _T("");
static BOOL s_bImprove = TRUE;
static BOOL s_bRightDirection = TRUE;
#define LAY_STAKE _T("TWT_STAKE")
#define STAKE_FILE _T("stake.his")
2026-10-04 00:04:20 +08:00
//沿线布置桩
2026-09-28 15:28:50 +08:00
void InsStakeAlongLine()
{
CTemporaryResourceOverride vTemp;
CStakeDlg dlg;
dlg.Create(IDD_STAKE,acedGetAcadFrame());
2026-10-04 00:04:20 +08:00
dlg.SetWindowText(_T("沿线布桩"));
//初始化图层
2026-09-28 15:28:50 +08:00
InitLayer(LAY_STAKE);
RBList rbMask = ads_buildlist( -4, _T("<or"),
-4, _T("<and"), RTDXF0, _T("LINE"), -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("LWPOLYLINE"), -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("ARC"), -4, _T("and>"),
-4, _T("or>"), NULL);
RBList rbMaskEquip(RTDXF0, _T("AEC_ZT_STAKE"), NULL);
dlg.ShowWindow(SW_SHOW);
2026-10-04 00:04:20 +08:00
//用户不退出则一直布置
2026-09-28 15:28:50 +08:00
XPoint ptBefore,ptNext;
XPoint ptPick;
Entity ent;
2026-10-04 00:04:20 +08:00
double dBeforeNum = 0.0; //前一点的桩号
2026-09-28 15:28:50 +08:00
double dStakeBetween = 0.0;
while(1)
{
if (fabs(ptNext.x) < 0.001)
{
2026-10-04 00:04:20 +08:00
BOOL bStake = FALSE;//判断是否选择了桩
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
int ret = GlobalFunc::SelectEntity1(0.3, _T("\n请拾取布置桩的第一点<退出>"), ent, ptPick, rbMask);
2026-09-28 15:28:50 +08:00
if(ret != RTNORM)
break;
ptPick = GlobalFunc::Ucs2Wcs(ptPick);
ptBefore = ptPick;
2026-10-04 00:04:20 +08:00
//判断是否点在桩上
2026-09-28 15:28:50 +08:00
Entity entStake;
PickSet ssSel(SS_FREE);
XPoint ptUsc = GlobalFunc::Wcs2Ucs(ptPick);
GlobalFunc::GetPointPickSet(ptPick,ssSel,rbMaskEquip,(int)GlobalFunc::DocGetPScale());
long index = 0;
int len = ssSel.Length();
for (index = 0; index < len; index++)
{
entStake = ssSel[index];
if (entStake.Is(_T("AEC_ZT_STAKE")))
{
bStake = TRUE;
OPENOBJ_BEGIN(entStake, AcDb::kForRead, CDbStake, pEquip);
if(pEquip)
{
ptBefore = pEquip->GetLocation();
}
OPENOBJ_END();
break;
}
}
2026-10-04 00:04:20 +08:00
//得到当前桩的值
2026-09-28 15:28:50 +08:00
if (bStake)
{
CString sTextValue;
OPENOBJ_BEGIN(entStake, AcDb::kForRead, CDbStake, pEquip);
if (pEquip != NULL)
{
sTextValue.Format(_T("%.2f"),pEquip->GetStakeValue());
}
OPENOBJ_END();
if (_tstof(sTextValue) > 0.01)
{
dlg.m_sStartDis = sTextValue;
dlg.UpdateData(FALSE);
}
}
if (!GlobalFunc::DocGetMeterUnitDraw())
dBeforeNum = _tstof(dlg.m_sStartDis)*1000;
else
dBeforeNum = _tstof(dlg.m_sStartDis);
dlg.UpdateData(TRUE);
s_bRightDirection = TRUE;
2026-10-04 00:04:20 +08:00
if (!bStake) //选中桩了就不需要再重复插入桩
2026-09-28 15:28:50 +08:00
dlg.InsStakeOnPoint(ent,ptBefore,dBeforeNum,ptPick, dlg.m_sLineDis,dlg.m_sLineLen,dlg.m_sStakePrefix,dlg.m_sStartDis,dlg.m_nLablePlace);
}
2026-10-04 00:04:20 +08:00
Entity entNext; //下一个实体
2026-09-28 15:28:50 +08:00
RBList rbMask(RTDXF0, _T("LINE,LWPOLYLINE,ARC"), NULL);
2026-10-04 00:04:20 +08:00
int ret = GlobalFunc::SelectEntity1(0.3, _T("\n请拾取布置桩的下一点<退出>"), entNext, ptNext, rbMask);
2026-09-28 15:28:50 +08:00
if(ret != RTNORM)
break;
dlg.UpdateData(TRUE);
ptNext = GlobalFunc::Ucs2Wcs(ptNext);
if (!GlobalFunc::DocGetMeterUnitDraw())
dStakeBetween = _tstof(dlg.m_sStakeBetween)*1000;
else
dStakeBetween = _tstof(dlg.m_sStakeBetween);
if (!dlg.InsStakeByLine(ent,entNext,dBeforeNum,ptBefore,ptNext,dlg.m_sLineDis,dlg.m_sLineLen,dlg.m_sStakePrefix,dlg.m_sStartDis,dlg.m_nLablePlace,dStakeBetween))
break;
}
dlg.DestroyWindow();
}
2026-10-04 00:04:20 +08:00
//任意布置桩
2026-09-28 15:28:50 +08:00
void InsStakeRandom()
{
CTemporaryResourceOverride vTemp;
CStakeDlg dlg;
dlg.Create(IDD_STAKE,acedGetAcadFrame());
2026-10-04 00:04:20 +08:00
dlg.SetWindowText(_T("任意布桩"));
//初始化图层
2026-09-28 15:28:50 +08:00
InitLayer(LAY_STAKE);
RBList rbMaskStake(RTDXF0, _T("AEC_ZT_STAKE"), NULL);
RBList rbMask = ads_buildlist( -4, _T("<or"),
-4, _T("<and"), RTDXF0, _T("LINE"), -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("LWPOLYLINE"), -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("ARC"), -4, _T("and>"),
-4, _T("or>"), NULL);
dlg.ShowWindow(SW_SHOW);
dlg.GetDlgItem(IDC_EDITSTAKEBETWEEN)->EnableWindow(FALSE);
2026-10-04 00:04:20 +08:00
//用户不退出则一直布置
2026-09-28 15:28:50 +08:00
XPoint ptBefore,ptNext;
XPoint ptPick;
Entity ent,ent2,entStake;
2026-10-04 00:04:20 +08:00
double dBeforeNum = 0.0; //前一点的桩号
2026-09-28 15:28:50 +08:00
double dStakeBetween = 0.0;
BOOL bFirst = TRUE;
while(1)
{
if (bFirst)
{
XPoint ptT;
2026-10-04 00:04:20 +08:00
int ret = GlobalFunc::SelectEntity1( _T("\n请拾取前一个桩<退出>"), entStake,ptT, rbMaskStake);
2026-09-28 15:28:50 +08:00
if(ret != RTNORM)
break;
2026-10-04 00:04:20 +08:00
//判断是否点在桩上
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
//通过桩的位置得到另外的实体
2026-09-28 15:28:50 +08:00
CString sTextValue;
OPENOBJ_BEGIN(entStake, AcDb::kForRead, CDbStake, pEquip);
if (pEquip != NULL)
{
ptBefore = pEquip->GetLocation();
sTextValue.Format(_T("%.2f"),pEquip->GetStakeValue());
}
else
continue;
OPENOBJ_END();
if (_tstof(sTextValue) > 0.01)
{
dlg.m_sStartDis = sTextValue;
dlg.UpdateData(FALSE);
}
if (!GlobalFunc::DocGetMeterUnitDraw())
dBeforeNum = _tstof(dlg.m_sStartDis)*1000;
else
dBeforeNum = _tstof(dlg.m_sStartDis);
dlg.UpdateData(TRUE);
ptBefore = GlobalFunc::Ucs2Wcs(ptBefore);
PickSet ssAll(SS_FREE);
GlobalFunc::GetPointPickSet(ptBefore,ssAll,rbMask,(int)GlobalFunc::DocGetPScale());
if (ssAll.Length() < 1)
return;
long lIndex = 0;
ent = ssAll[lIndex];
bFirst = FALSE;
}
2026-10-04 00:04:20 +08:00
int ret = GlobalFunc::SelectEntity1(0.3, _T("\n请选择需要布置桩的位置<退出>"), ent2, ptPick, rbMask);
2026-09-28 15:28:50 +08:00
if(ret != RTNORM)
break;
ptPick = GlobalFunc::Ucs2Wcs(ptPick);
PickSet ss(SS_FREE);
2026-10-04 00:04:20 +08:00
//得到实体上所有的桩
2026-09-28 15:28:50 +08:00
dlg.GetCurvePickSet(ent2,ss,rbMaskStake);
Entity entTempStake;
XPoint ptLocation,ptNearMin,ptNearMax;
long lIndex = 0;
CString sXData;
int nLen = ss.Length();
if (nLen > 1)
{
dlg.GetNewPtAddDis(ent2,ss,ptBefore,ptPick,dBeforeNum);
}
else if (nLen == 1)
{
TCHAR szValue[100] = {0};
2026-10-04 00:04:20 +08:00
acedGetString(0,_T("\n请判断桩号增加还是递减(Y增加,N递减)"),szValue);
2026-09-28 15:28:50 +08:00
if(_tcsicmp(szValue, _T("N")) == 0 || _tcsicmp(szValue, _T("n")) == 0)
{
s_bImprove = FALSE;
}
}
else
{
CString sStakeNum;
TCHAR szValue[100] = {0};
2026-10-04 00:04:20 +08:00
acedGetString(1,_T("\n请输入桩号(m):"),szValue);
2026-09-28 15:28:50 +08:00
sStakeNum = szValue;
ptBefore = ptPick;
if (!GlobalFunc::DocGetMeterUnitDraw())
dBeforeNum = _tstof(sStakeNum) * 1000;
else
dBeforeNum = _tstof(sStakeNum);
}
2026-10-04 00:04:20 +08:00
//插入桩
2026-09-28 15:28:50 +08:00
dlg.UpdateData();
dlg.InsStakeOnPoint(ent2,ptBefore,dBeforeNum,ptPick, dlg.m_sLineDis,dlg.m_sLineLen,dlg.m_sStakePrefix,dlg.m_sStartDis,dlg.m_nLablePlace);
ptBefore = ptPick;
}
dlg.DestroyWindow();
}
2026-10-04 00:04:20 +08:00
//选择点布置
2026-09-28 15:28:50 +08:00
void CStakeDlg::InsStakeOnPoint(Entity ent,XPoint ptBefore,double &dBeforeNum,XPoint ptPick,
CString &sLineDis,CString &sLineLen,CString &sStakePrefix,
CString &sStartDis,int nLablePlace)
{
XCurveSegment seg;
if (ent.Is(_T("LINE")) || ent.Is(_T("ARC")))
{
seg = XCurveSegment(ent);
}
else if(ent.Is(_T("LWPOLYLINE")))
{
double dAngle;
seg = GlobalFunc::GetSegByPt(XPoly2D(ent), ptPick, dAngle);
}
AcGePoint3d ptStart,ptEnd,ptTextPosition;
2026-10-04 00:04:20 +08:00
AcGeVector3d vecTemp1,vecTemp2,vecTemp3; //左侧,右侧,中间标注方向的三个向量
2026-09-28 15:28:50 +08:00
double dTextRotate = 0.0;
CString sText;
g_Option::instance().g_nInsBlkRotate = GlobalFunc::GetInsRotate(ptPick, seg);
AcGeVector3d vecTempDir,vecTmpY(0,1,0);
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbCurve, pCurveTemp);
if(pCurveTemp)
{
pCurveTemp->getFirstDeriv(ptPick,vecTempDir);
vecTempDir = vecTempDir.perpVector();
vecTempDir.normalize();
m_vtFirst = vecTempDir;
if (!s_bRightDirection)
vecTempDir.negate();
}
OPENOBJ_END();
2026-10-04 00:04:20 +08:00
//计算文字
2026-09-28 15:28:50 +08:00
double dBeforeDis,dPickDis;
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbCurve, pCurve);
if (pCurve != NULL)
{
pCurve->getDistAtPoint((AcGePoint3d)ptBefore,dBeforeDis);
pCurve->getDistAtPoint((AcGePoint3d)ptPick,dPickDis);
}
OPENOBJ_END();
if (s_bImprove)
dBeforeNum = dBeforeNum + fabs(dPickDis-dBeforeDis);
else
dBeforeNum = dBeforeNum - fabs(dPickDis-dBeforeDis);
s_bImprove = TRUE;
double dTextValue = 0.0;
if (!GlobalFunc::DocGetMeterUnitDraw())
dTextValue = dBeforeNum/1000;
else
dTextValue = dBeforeNum;
double dTextN = dTextValue/1000;
CString sTextN;
sTextN.Format(_T("%.2f"),dTextN);
2026-10-04 00:04:20 +08:00
//文字是1000的多少倍
2026-09-28 15:28:50 +08:00
int nTextN = _ttoi(sTextN);
2026-10-04 00:04:20 +08:00
//除以1000后的余数
2026-09-28 15:28:50 +08:00
double dTextResidue = fabs(dTextValue-1000*nTextN);
sTextN.Format(_T("%.0f"),dTextResidue);
int nLen = sTextN.GetLength();
sTextN.Format(_T("%.2f"),dTextResidue);
2026-10-04 00:04:20 +08:00
//判断有没有小数
2026-09-28 15:28:50 +08:00
double dEndResidue = _tstof(sTextN.Right(2));
dEndResidue /= 100;
if (dEndResidue < 0.01)
{
if (nLen == 1)
sText.Format(_T("%s%d+00%.0f"),sStakePrefix,nTextN,dTextResidue);
else if (nLen == 2)
sText.Format(_T("%s%d+0%.0f"),sStakePrefix,nTextN,dTextResidue);
else
sText.Format(_T("%s%d+%.0f"),sStakePrefix,nTextN,dTextResidue);
}
else
{
if (nLen == 1)
sText.Format(_T("%s%d+00%.2f"),sStakePrefix,nTextN,dTextResidue);
else if (nLen == 2)
sText.Format(_T("%s%d+0%.2f"),sStakePrefix,nTextN,dTextResidue);
else
sText.Format(_T("%s%d+%.2f"),sStakePrefix,nTextN,dTextResidue);
}
CDbStake *pStake = new CDbStake;
pStake->SetPositon(ptPick);
pStake->SetStakeDir(vecTempDir);
pStake->SetStakeLablePlace(nLablePlace);
int nType = m_comboStakeStyle.GetCurSel();
if (nType == -1)
nType = 0;
pStake->SetStakeType(nType);
pStake->SetTextDecimal(_ttoi(m_sDecimalNum));
if (m_nTextAngType == 0)
pStake->SetTextAng(0.0);
else if (m_nTextAngType == 1)
pStake->SetTextAng(PI/2);
else
pStake->SetTextAng(PI);
pStake->SetText(sStakePrefix,dTextValue);
pStake->SetTextHeight(_tstof(m_sTextHeight));
pStake->SetDerviDis(_tstof(sLineDis)*GlobalFunc::DocGetPScale());
pStake->SetDerviLineLen(_tstof(sLineLen)*GlobalFunc::DocGetPScale());
pStake->SetTextLayerId(InitLayer(LAY_STAKE));
pStake->SetTextStyleId(InitTextStyle(g_Option::instance().g_csTwtDimStyle));
pStake->setLayer(LAY_STAKE);
AcDbObjectId idStake = GlobalFunc::AddToCurrentSpace(pStake,Adesk::kTrue);
}
2026-10-04 00:04:20 +08:00
//沿线布置
2026-09-28 15:28:50 +08:00
BOOL CStakeDlg::InsStakeByLine(Entity &ent,Entity ent2, double &dBeforeNum, XPoint &ptBefore,XPoint &ptEnd,CString &sLineDis,CString &sLineLen,CString &sStakePrefix,CString &sStartDis,int nLablePlace,double dStakeBetween)
{
AcGeVector3d vtDeriv1,vtDeriv2;
AcDbPolyline *pCurve = NULL;
OPENOBJ_BEGIN(ent,AcDb::kForRead,AcDbCurve,pTempCurve);
if (pTempCurve != NULL)
{
AcGePoint3d ptTempEnd,ptTempStart;
pTempCurve->getEndPoint(ptTempEnd);
pTempCurve->getStartPoint(ptTempStart);
pTempCurve->getFirstDeriv(ptBefore,vtDeriv1);
}
OPENOBJ_END();
pCurve = GlobalFunc::GetNextPloyLine(ent,ent2,ptBefore,ptEnd);
if (pCurve == NULL)
return TRUE;
double dBeforeDis = 0.0, dPickDis = 0.0,dNextDis = 0.0;
pCurve->getDistAtPoint((AcGePoint3d)ptBefore,dBeforeDis);
pCurve->getDistAtPoint((AcGePoint3d)ptEnd,dPickDis);
pCurve->getFirstDeriv(ptBefore,vtDeriv2);
if (vtDeriv1.angleTo(vtDeriv2) > 1e-3)
s_bRightDirection = FALSE;
2026-10-04 00:04:20 +08:00
//判断选取的方向和选取线的方向是否一致
2026-09-28 15:28:50 +08:00
if (dBeforeDis >= dPickDis)
{
double dT = dBeforeDis;
dBeforeDis = dPickDis;
dPickDis = dT;
XPoly2D poly;
GlobalFunc::PolyConvert(*pCurve, poly);
poly.Reverse();
GlobalFunc::PolyConvert(poly,*pCurve);
s_bRightDirection = FALSE;
}
AcDbObjectId idPoly = GlobalFunc::AddToCurrentSpace(pCurve,Adesk::kTrue);
ads_name nameCurve;
acdbGetAdsName(nameCurve,idPoly);
Entity entPoly(nameCurve);
if (pCurve != NULL)
{
/*
double dBeforeDis = 0.0, dPickDis = 0.0,dNextDis = 0.0;
es = pCurve->getDistAtPoint((AcGePoint3d)ptBefore,dBeforeDis);
es = pCurve->getDistAtPoint((AcGePoint3d)ptEnd,dPickDis);
2026-10-04 00:04:20 +08:00
//判断选取的方向和选取线的方向是否一致
2026-09-28 15:28:50 +08:00
if (dBeforeDis >= dPickDis)
{
// entPoly.Erase();
// return FALSE;
double dT = dBeforeDis;
dBeforeDis = dPickDis;
dPickDis = dT;
}
*/
AcGePoint3d ptNext;
if (pCurve->getPointAtDist(dStakeBetween+dBeforeDis,ptNext) != Acad::eOk)
{
2026-10-04 00:04:20 +08:00
AfxMessageBox(_T("桩间距太大!"));
2026-09-28 15:28:50 +08:00
{
entPoly.Erase();
return TRUE;
}
}
if (pCurve->getDistAtPoint((AcGePoint3d)ptNext,dNextDis) != Acad::eOk)
{
entPoly.Erase();
return TRUE;
}
2026-10-04 00:04:20 +08:00
//循环布置下一点
2026-09-28 15:28:50 +08:00
while (dNextDis < dPickDis)
{
InsStakeOnPoint(entPoly,ptBefore,dBeforeNum,ptNext,sLineDis,sLineLen,sStakePrefix,sStartDis,nLablePlace);
dBeforeDis += dStakeBetween;
ptBefore = ptNext;
if (pCurve->getPointAtDist(dStakeBetween+dBeforeDis,ptNext) != Acad::eOk)
break;
if (pCurve->getDistAtPoint((AcGePoint3d)ptNext,dNextDis) != Acad::eOk)
break;
}
}
else
{
entPoly.Erase();
return FALSE;
}
ent = ent2;
entPoly.Erase();
return TRUE;
}
2026-10-04 00:04:20 +08:00
//得到新的前一点和距离
2026-09-28 15:28:50 +08:00
void CStakeDlg::GetNewPtAddDis(Entity ent,PickSet &ss,XPoint &ptBefore,XPoint ptPick, double &dBeforeNum)
{
Entity entTempStake;
XPoint ptLocation,ptNearMin,ptNearMax;
long lIndex = 0;
CString sXData;
int nLen = ss.Length();
2026-10-04 00:04:20 +08:00
//找到最近和最远两个桩
2026-09-28 15:28:50 +08:00
double dMin = 0.0,dMax = 0.0;
for (lIndex = 0; lIndex < nLen; ++lIndex)
{
entTempStake = ss[lIndex];
OPENOBJ_BEGIN(entTempStake, AcDb::kForRead, CDbStake, pEquip);
if (pEquip != NULL)
{
ptLocation = pEquip->GetLocation();
sXData.Format(_T("%.2f"),pEquip->GetStakeValue());
if (lIndex == 0)
{
dMin = _tstof(sXData);
dMax = _tstof(sXData);
ptNearMin = ptLocation;
ptNearMax = ptLocation;
}
else
{
if (dMin > _tstof(sXData))
{
dMin = _tstof(sXData);
ptNearMin = ptLocation;
}
if (dMax < _tstof(sXData))
{
dMax = _tstof(sXData);
ptNearMax = ptLocation;
}
}
}
OPENOBJ_END();
}
2026-10-04 00:04:20 +08:00
//判断应该是加上距离还是减去距离
2026-09-28 15:28:50 +08:00
double dMid = 0.0,dNearMin = 0.0,dNearMax = 0.0;
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbCurve, pCurve);
if (pCurve != NULL)
{
pCurve->getParamAtPoint(ptPick,dMid);
pCurve->getParamAtPoint(ptNearMin,dNearMin);
pCurve->getParamAtPoint(ptNearMax,dNearMax);
ptBefore = ptNearMin;
if (!GlobalFunc::DocGetMeterUnitDraw())
dBeforeNum = dMin * 1000;
else
dBeforeNum = dMin;
if ((dNearMin - dMid)*(dNearMax - dMid) > 0)
{
if (fabs(dNearMin - dMid) < fabs(dNearMax - dMid))
{
s_bImprove = FALSE;
}
}
}
OPENOBJ_END();
}
2026-10-04 00:04:20 +08:00
//得到实体上的选择集
2026-09-28 15:28:50 +08:00
void CStakeDlg::GetCurvePickSet(Entity ent,PickSet &ss,RBList &rbMask)
{
if(ent.Is(_T("LINE")))
{
XLine line(ent);
2026-10-04 00:04:20 +08:00
line.TransUCS(RBGroups(0),RBGroups(1)); // 把 UCS 转为 WCS
2026-09-28 15:28:50 +08:00
RBList rbPoint = ads_buildlist(RT3DPOINT, &line.StartPoint(), RT3DPOINT,
&line.EndPoint(), NULL);
GlobalFunc::AssureInCurrentView(line.StartPoint(), line.EndPoint());
ss.Get(_T("F"), rbPoint, NULL, rbMask);
}
else if(ent.Is(_T("ARC")))
{
XArc arc(ent);
XCurveSegment seg;
seg = arc;
XPoly2D xPline;
seg.AsPoly2D(xPline);
XPoint pt1, pt2;
pt1 = *xPline[0];
xPline.Length();
pt2 = *xPline[xPline.Length()-1];
2026-10-04 00:04:20 +08:00
// xPline.TransUCS(RBGroups(0),RBGroups(1)); // 把 UCS 转为 WCS
2026-09-28 15:28:50 +08:00
RBList rbPoint = xPline.Polygon();
GlobalFunc::AssureInCurrentView(pt1, pt2);
ss.Get(_T("F"), rbPoint, NULL, rbMask);
}
else
{
XPoly2D xPline(ent);
XPoint pt1, pt2;
pt1 = *xPline[0];
xPline.Length();
pt2 = *xPline[xPline.Length()-1];
2026-10-04 00:04:20 +08:00
// xPline.TransUCS(RBGroups(0),RBGroups(1)); // 把 UCS 转为 WCS
2026-09-28 15:28:50 +08:00
RBList rbPoint = xPline.Polygon();
GlobalFunc::AssureInCurrentView(pt1, pt2);
ss.Get(_T("F"), rbPoint, NULL, rbMask);
}
}
CStakeDlg::CStakeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStakeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStakeDlg)
m_sStartDis = _T("0");
m_sLineDis = _T("0");
m_sLineLen = _T("5");
m_nLablePlace = 0;
m_sStakeBetween = _T("20");
m_sStakePrefix = _T("K");
m_sTextHeight = _T("3");
m_sDecimalNum = _T("0");
m_nTextAngType = 0;
//}}AFX_DATA_INIT
}
void CStakeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStakeDlg)
DDX_Control(pDX, IDC_COMBOSTAKESTYLE, m_comboStakeStyle);
DDX_Text(pDX, IDC_EDITSTARTDIS, m_sStartDis);
DDX_Text(pDX, IDC_EDITLINEDIS, m_sLineDis);
DDX_Text(pDX, IDC_EDITLINELEN, m_sLineLen);
DDX_CBIndex(pDX, IDC_COMBOPOSITION, m_nLablePlace);
DDX_Text(pDX, IDC_EDITSTAKEBETWEEN, m_sStakeBetween);
DDX_CBString(pDX, IDC_CMBSTAKEPREFIX, m_sStakePrefix);
DDX_CBString(pDX, IDC_CMBTEXTHEIGHT, m_sTextHeight);
DDX_CBString(pDX, IDC_CMB_DECIMAL_NUM, m_sDecimalNum);
DDX_CBIndex(pDX, IDC_CMBTEXTANG, m_nTextAngType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStakeDlg, CDialog)
//{{AFX_MSG_MAP(CStakeDlg)
ON_WM_CLOSE()
ON_EN_CHANGE(IDC_EDITSTAKEBETWEEN, OnChangeEditstakebetween)
ON_EN_CHANGE(IDC_EDITSTARTDIS, OnChangeEditstartdis)
ON_CBN_EDITCHANGE(IDC_CMBSTAKEPREFIX, OnEditchangeCmbstakeprefix)
ON_CBN_EDITCHANGE(IDC_COMBOPOSITION, OnEditchangeComboposition)
ON_WM_DESTROY()
ON_EN_KILLFOCUS(IDC_EDITSTAKEBETWEEN, OnKillfocusEditstakebetween)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_ACAD_KEEPFOCUS, onAcadKeepFocus)
END_MESSAGE_MAP()
LONG_PTR CStakeDlg::onAcadKeepFocus(UINT_PTR, LONG_PTR)
{
CPoint pt;
GetCursorPos(&pt);
CRect rc;
GetWindowRect(&rc);
return (rc.PtInRect(pt) ? TRUE : FALSE);
}
BOOL CStakeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_comboStakeStyle.SetCurSel(0);
if (_tstof(s_sBetweenDis) > 0.01)
m_sStakeBetween = s_sBetweenDis;
TCHAR strTmpPath[100] = _T("");
GetTempPath(100, strTmpPath);
_tcscat(strTmpPath, STAKE_FILE);
GetFileFrom(strTmpPath);
UpdateData(FALSE);
return TRUE;
}
void CStakeDlg::OnClose()
{
TCHAR strTmpPath[256] = _T("");
GetTempPath(255, strTmpPath);
_tcscat(strTmpPath, STAKE_FILE);
SaveFileTo(strTmpPath);
CDialog::OnClose();
acedPostCommand(_T("\33\33"));
}
void CStakeDlg::OnChangeEditstakebetween()
{
UpdateData(TRUE);
s_sBetweenDis = m_sStakeBetween;
}
void CStakeDlg::OnChangeEditstartdis()
{
UpdateData(TRUE);
}
void CStakeDlg::OnEditchangeCmbstakeprefix()
{
UpdateData(TRUE);
}
void CStakeDlg::OnEditchangeComboposition()
{
UpdateData(TRUE);
}
void CStakeDlg::SaveFileTo(LPCTSTR lpFilePath)
{
if (lpFilePath == NULL)
return;
FILE *fp = fopen(_AS(lpFilePath), "w");
if(!fp)
return;
CString csTmp1, csTmp2,csTmp3, csTmp4,csTmp5, csTmp6,csTmp7, csTmp8,csTmp9,csTmp10,csTmp11;
csTmp1 = m_sStartDis;
csTmp2.Format(_T("%d"),m_nLablePlace);
csTmp3 = m_sTextHeight;
csTmp4.Format(_T("%d"),m_comboStakeStyle.GetCurSel());
csTmp5 = m_sLineDis;
csTmp6 = m_sLineLen;
csTmp7 = m_sStakePrefix;
csTmp8 = m_sStakeBetween;
csTmp9 = m_sDecimalNum;
csTmp10.Format(_T("%d"),m_nTextAngType);
2026-10-04 00:04:20 +08:00
csTmp11 = csTmp1 + _T("-") + csTmp2 + _T("-") + csTmp3 + _T("-") + csTmp4 + _T("-") + csTmp5 + _T("-") + csTmp6 + _T("-") + csTmp7 + _T("-") + csTmp8 + _T("-") + csTmp9 + _T("-") + csTmp10 + _T("-");
2026-09-28 15:28:50 +08:00
fputs(_AS(csTmp11), fp);
fclose(fp);
}
void CStakeDlg::GetFileFrom(LPCTSTR lpFilePath)
{
if (lpFilePath == NULL)
return;
XStringList lstHis;
FILE *fp=fopen(_AS(lpFilePath), "r");
if(!fp)
return;
CString csTmp;
while(!feof(fp))
{
char sBuf[256]="";
fgets(sBuf, 255, fp);
csTmp = sBuf;
csTmp.TrimRight();
if(csTmp != _T(""))
lstHis.Append(tstrnew(csTmp));
}
fclose(fp);
int len = lstHis.Length();
if(len < 1)
return;
int idx = -1,iCharLen = 0;
CString sTempName;
2026-10-04 00:04:20 +08:00
int nCharLen = (int)_tcslen(_T("-"));;
2026-09-28 15:28:50 +08:00
for(int i=0;i<len;i++)
{
csTmp = lstHis[i];
2026-10-04 00:04:20 +08:00
idx = csTmp.Find(_T("-"));
2026-09-28 15:28:50 +08:00
sTempName = csTmp.Left(idx);
m_sStartDis = sTempName;
csTmp = csTmp.Mid(idx + nCharLen);
2026-10-04 00:04:20 +08:00
idx = csTmp.Find(_T("-"));
2026-09-28 15:28:50 +08:00
m_nLablePlace = _ttoi(csTmp.Left(idx));
csTmp = csTmp.Mid(idx + nCharLen);
2026-10-04 00:04:20 +08:00
idx = csTmp.Find(_T("-"));
2026-09-28 15:28:50 +08:00
if (idx != -1)
{
m_sTextHeight = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
2026-10-04 00:04:20 +08:00
idx = csTmp.Find(_T("-"));
2026-09-28 15:28:50 +08:00
if (idx != -1)
{
sTempName = csTmp.Left(idx);
m_comboStakeStyle.SetCurSel(_ttoi(sTempName));
}
csTmp = csTmp.Mid(idx + nCharLen);
2026-10-04 00:04:20 +08:00
idx = csTmp.Find(_T("-"));
2026-09-28 15:28:50 +08:00
if (idx != -1)
{
m_sLineDis = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
2026-10-04 00:04:20 +08:00
idx = csTmp.Find(_T("-"));
2026-09-28 15:28:50 +08:00
if (idx != -1)
{
m_sLineLen = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
2026-10-04 00:04:20 +08:00
idx = csTmp.Find(_T("-"));
2026-09-28 15:28:50 +08:00
if (idx != -1)
{
m_sStakePrefix = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
2026-10-04 00:04:20 +08:00
idx = csTmp.Find(_T("-"));
2026-09-28 15:28:50 +08:00
if (idx != -1)
{
m_sStakeBetween = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
2026-10-04 00:04:20 +08:00
idx = csTmp.Find(_T("-"));
2026-09-28 15:28:50 +08:00
if (idx != -1)
{
m_sDecimalNum = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
2026-10-04 00:04:20 +08:00
idx = csTmp.Find(_T("-"));
2026-09-28 15:28:50 +08:00
if (idx != -1)
{
m_nTextAngType = _ttoi(csTmp.Left(idx));
}
}
}
void CStakeDlg::OnDestroy()
{
TCHAR strTmpPath[256] = _T("");
GetTempPath(255, strTmpPath);
_tcscat(strTmpPath, STAKE_FILE);
UpdateData();
SaveFileTo(strTmpPath);
CDialog::OnDestroy();
}
2026-10-04 00:04:20 +08:00
// cet 2010.8.31 add 限制桩间距值的大小
2026-09-28 15:28:50 +08:00
void CStakeDlg::OnKillfocusEditstakebetween()
{
UpdateData(TRUE);
double dVal = _tstof(m_sStakeBetween);
if (dVal < 1e-9)
{
2026-10-04 00:04:20 +08:00
AfxMessageBox(_T("桩间距应大于0m!"));
2026-09-28 15:28:50 +08:00
m_sStakeBetween = _T("20");
UpdateData(FALSE);
}
}