Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

863 lines
21 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "stdafx.h"
#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")
//沿线布置桩
void InsStakeAlongLine()
{
CTemporaryResourceOverride vTemp;
CStakeDlg dlg;
dlg.Create(IDD_STAKE,acedGetAcadFrame());
dlg.SetWindowText(_T("沿线布桩"));
//初始化图层
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);
//用户不退出则一直布置
XPoint ptBefore,ptNext;
XPoint ptPick;
Entity ent;
double dBeforeNum = 0.0; //前一点的桩号
double dStakeBetween = 0.0;
while(1)
{
if (fabs(ptNext.x) < 0.001)
{
BOOL bStake = FALSE;//判断是否选择了桩
int ret = GlobalFunc::SelectEntity1(0.3, _T("\n请拾取布置桩的第一点<退出>"), ent, ptPick, rbMask);
if(ret != RTNORM)
break;
ptPick = GlobalFunc::Ucs2Wcs(ptPick);
ptBefore = ptPick;
//判断是否点在桩上
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;
}
}
//得到当前桩的值
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;
if (!bStake) //选中桩了就不需要再重复插入桩
dlg.InsStakeOnPoint(ent,ptBefore,dBeforeNum,ptPick, dlg.m_sLineDis,dlg.m_sLineLen,dlg.m_sStakePrefix,dlg.m_sStartDis,dlg.m_nLablePlace);
}
Entity entNext; //下一个实体
RBList rbMask(RTDXF0, _T("LINE,LWPOLYLINE,ARC"), NULL);
int ret = GlobalFunc::SelectEntity1(0.3, _T("\n请拾取布置桩的下一点<退出>"), entNext, ptNext, rbMask);
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();
}
//任意布置桩
void InsStakeRandom()
{
CTemporaryResourceOverride vTemp;
CStakeDlg dlg;
dlg.Create(IDD_STAKE,acedGetAcadFrame());
dlg.SetWindowText(_T("任意布桩"));
//初始化图层
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);
//用户不退出则一直布置
XPoint ptBefore,ptNext;
XPoint ptPick;
Entity ent,ent2,entStake;
double dBeforeNum = 0.0; //前一点的桩号
double dStakeBetween = 0.0;
BOOL bFirst = TRUE;
while(1)
{
if (bFirst)
{
XPoint ptT;
int ret = GlobalFunc::SelectEntity1( _T("\n请拾取前一个桩<退出>"), entStake,ptT, rbMaskStake);
if(ret != RTNORM)
break;
//判断是否点在桩上
//通过桩的位置得到另外的实体
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;
}
int ret = GlobalFunc::SelectEntity1(0.3, _T("\n请选择需要布置桩的位置<退出>"), ent2, ptPick, rbMask);
if(ret != RTNORM)
break;
ptPick = GlobalFunc::Ucs2Wcs(ptPick);
PickSet ss(SS_FREE);
//得到实体上所有的桩
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};
acedGetString(0,_T("\n请判断桩号增加还是递减(Y增加,N递减)"),szValue);
if(_tcsicmp(szValue, _T("N")) == 0 || _tcsicmp(szValue, _T("n")) == 0)
{
s_bImprove = FALSE;
}
}
else
{
CString sStakeNum;
TCHAR szValue[100] = {0};
acedGetString(1,_T("\n请输入桩号(m):"),szValue);
sStakeNum = szValue;
ptBefore = ptPick;
if (!GlobalFunc::DocGetMeterUnitDraw())
dBeforeNum = _tstof(sStakeNum) * 1000;
else
dBeforeNum = _tstof(sStakeNum);
}
//插入桩
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();
}
//选择点布置
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;
AcGeVector3d vecTemp1,vecTemp2,vecTemp3; //左侧,右侧,中间标注方向的三个向量
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();
//计算文字
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);
//文字是1000的多少倍
int nTextN = _ttoi(sTextN);
//除以1000后的余数
double dTextResidue = fabs(dTextValue-1000*nTextN);
sTextN.Format(_T("%.0f"),dTextResidue);
int nLen = sTextN.GetLength();
sTextN.Format(_T("%.2f"),dTextResidue);
//判断有没有小数
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);
}
//沿线布置
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;
//判断选取的方向和选取线的方向是否一致
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);
//判断选取的方向和选取线的方向是否一致
if (dBeforeDis >= dPickDis)
{
// entPoly.Erase();
// return FALSE;
double dT = dBeforeDis;
dBeforeDis = dPickDis;
dPickDis = dT;
}
*/
AcGePoint3d ptNext;
if (pCurve->getPointAtDist(dStakeBetween+dBeforeDis,ptNext) != Acad::eOk)
{
AfxMessageBox(_T("桩间距太大!"));
{
entPoly.Erase();
return TRUE;
}
}
if (pCurve->getDistAtPoint((AcGePoint3d)ptNext,dNextDis) != Acad::eOk)
{
entPoly.Erase();
return TRUE;
}
//循环布置下一点
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;
}
//得到新的前一点和距离
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();
//找到最近和最远两个桩
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();
}
//判断应该是加上距离还是减去距离
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();
}
//得到实体上的选择集
void CStakeDlg::GetCurvePickSet(Entity ent,PickSet &ss,RBList &rbMask)
{
if(ent.Is(_T("LINE")))
{
XLine line(ent);
line.TransUCS(RBGroups(0),RBGroups(1)); // 把 UCS 转为 WCS
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];
// xPline.TransUCS(RBGroups(0),RBGroups(1)); // 把 UCS 转为 WCS
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];
// xPline.TransUCS(RBGroups(0),RBGroups(1)); // 把 UCS 转为 WCS
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);
csTmp11 = csTmp1 + _T("-") + csTmp2 + _T("-") + csTmp3 + _T("-") + csTmp4 + _T("-") + csTmp5 + _T("-") + csTmp6 + _T("-") + csTmp7 + _T("-") + csTmp8 + _T("-") + csTmp9 + _T("-") + csTmp10 + _T("-");
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;
int nCharLen = (int)_tcslen(_T("-"));;
for(int i=0;i<len;i++)
{
csTmp = lstHis[i];
idx = csTmp.Find(_T("-"));
sTempName = csTmp.Left(idx);
m_sStartDis = sTempName;
csTmp = csTmp.Mid(idx + nCharLen);
idx = csTmp.Find(_T("-"));
m_nLablePlace = _ttoi(csTmp.Left(idx));
csTmp = csTmp.Mid(idx + nCharLen);
idx = csTmp.Find(_T("-"));
if (idx != -1)
{
m_sTextHeight = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
idx = csTmp.Find(_T("-"));
if (idx != -1)
{
sTempName = csTmp.Left(idx);
m_comboStakeStyle.SetCurSel(_ttoi(sTempName));
}
csTmp = csTmp.Mid(idx + nCharLen);
idx = csTmp.Find(_T("-"));
if (idx != -1)
{
m_sLineDis = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
idx = csTmp.Find(_T("-"));
if (idx != -1)
{
m_sLineLen = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
idx = csTmp.Find(_T("-"));
if (idx != -1)
{
m_sStakePrefix = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
idx = csTmp.Find(_T("-"));
if (idx != -1)
{
m_sStakeBetween = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
idx = csTmp.Find(_T("-"));
if (idx != -1)
{
m_sDecimalNum = csTmp.Left(idx);
}
csTmp = csTmp.Mid(idx + nCharLen);
idx = csTmp.Find(_T("-"));
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();
}
// cet 2010.8.31 add 限制桩间距值的大小
void CStakeDlg::OnKillfocusEditstakebetween()
{
UpdateData(TRUE);
double dVal = _tstof(m_sStakeBetween);
if (dVal < 1e-9)
{
AfxMessageBox(_T("桩间距应大于0m!"));
m_sStakeBetween = _T("20");
UpdateData(FALSE);
}
}