516 lines
13 KiB
C++
516 lines
13 KiB
C++
// UndergroundRampDlg.cpp : 实现文件
|
||
//
|
||
|
||
#include "stdafx.h"
|
||
#include "UndergroundRampDlg.h"
|
||
#include "UnderGroundView.h"
|
||
#include "GlwGlobalVariable.h"
|
||
#include "GlwUGRampDataManage.h"
|
||
#define UIFRAME_API __declspec( dllimport )
|
||
#include "DataLoadAndSave.h"
|
||
|
||
namespace
|
||
{
|
||
#define TARCH20_SYMBOL_KEY_UNDERGROUNDRAMP _T("UnderGroundRamp_CString") //注册表项
|
||
#define TARCH20_SYMBOL_TERMNAME _T("AllControlWndData\\SymbolWndData") //键
|
||
#define DIVSTRING _T("^@^")
|
||
|
||
#if ADS <= 18
|
||
double _ttof(LPCTSTR psz)
|
||
{
|
||
if (!psz) return .0;
|
||
USES_CONVERSION;
|
||
return atof(W2A(psz));
|
||
}
|
||
#endif
|
||
|
||
CString format(int i)
|
||
{
|
||
CString str;
|
||
str.Format(_T("%d"), i);
|
||
return str;
|
||
}
|
||
CString format(bool bValue)
|
||
{
|
||
CString str;
|
||
str.Format(_T("%d"), (int)bValue);
|
||
return str;
|
||
}
|
||
CString format(double dValue)
|
||
{
|
||
CString str;
|
||
str.Format(_T("%.f"),dValue);
|
||
return str;
|
||
}
|
||
CString MergeStr(const std::vector<CString>& subStr)
|
||
{
|
||
CString str = _T("");
|
||
CString strTemp = _T("");
|
||
std::vector<CString>::const_iterator iter = subStr.begin();
|
||
if (iter == subStr.end())
|
||
return str;
|
||
strTemp = *iter;
|
||
if (strTemp.IsEmpty()) strTemp = _T(" ");
|
||
str += strTemp;
|
||
++iter;
|
||
for (iter; iter != subStr.end(); ++iter)
|
||
{
|
||
strTemp = *iter;
|
||
if (strTemp.IsEmpty()) strTemp = _T(" ");
|
||
str += DIVSTRING + strTemp;
|
||
}
|
||
return str;
|
||
}
|
||
int SplitString(LPCTSTR pszOri, LPCTSTR pszSplit, std::vector<CString> &vec)
|
||
{
|
||
do
|
||
{
|
||
if (!pszOri) break;
|
||
vec.clear();
|
||
|
||
if (!pszSplit)
|
||
{
|
||
vec.push_back(pszOri);
|
||
return 1;
|
||
}
|
||
|
||
CString sOri(pszOri), sSplit(pszSplit), sRel(_T(""));
|
||
int nSplitLen(sSplit.GetLength()), nFindPos(0), nRel(0);
|
||
while ((nFindPos = sOri.Find(sSplit, 0)) != -1)
|
||
{
|
||
sRel = sOri.Mid(0, nFindPos);
|
||
vec.push_back(sRel);
|
||
sOri = sOri.Right(sOri.GetLength() - nFindPos - nSplitLen);
|
||
++nRel;
|
||
}
|
||
|
||
if (!sOri.IsEmpty())
|
||
{
|
||
vec.push_back(sOri);
|
||
++nRel;
|
||
}
|
||
|
||
return nRel;
|
||
} while (false);
|
||
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
CUndergroundRampDlg* CUndergroundRampDlg::g_pCurDlg = NULL;
|
||
double CUndergroundRampDlg::m_wndEdtWidth(4000.0); //宽度
|
||
double CUndergroundRampDlg::m_wndEdtRadius (6000.0); //转弯半径
|
||
int CUndergroundRampDlg::m_iLocationLine(0);
|
||
int CUndergroundRampDlg::m_iLocation(3);
|
||
int CUndergroundRampDlg::m_iViewStyle(6);
|
||
BOOL CUndergroundRampDlg::m_bRoadMidline = FALSE;
|
||
BOOL CUndergroundRampDlg::m_bLableArrow = FALSE;
|
||
// CUndergroundRampDlg 对话框
|
||
|
||
IMPLEMENT_DYNAMIC(CUndergroundRampDlg, CModelessDialog)
|
||
|
||
CUndergroundRampDlg::CUndergroundRampDlg(CWnd* pParent /*=NULL*/)
|
||
: CModelessDialog(CUndergroundRampDlg::IDD, pParent)
|
||
{
|
||
g_pCurDlg = this;
|
||
LoadRegeditSaveData();
|
||
if (DocGetMeterUnitDraw())
|
||
{
|
||
m_wndEdtWidth = m_wndEdtWidth / 1000 + (m_wndEdtWidth - (m_wndEdtWidth / 1000) * 1000);
|
||
m_wndEdtRadius = m_wndEdtRadius / 1000 + (m_wndEdtRadius - (m_wndEdtRadius / 1000) * 1000);
|
||
}
|
||
}
|
||
|
||
CUndergroundRampDlg::~CUndergroundRampDlg()
|
||
{
|
||
if (DocGetMeterUnitDraw())
|
||
{
|
||
m_wndEdtWidth = m_wndEdtWidth * 1000;
|
||
m_wndEdtRadius = m_wndEdtRadius * 1000;
|
||
}
|
||
SaveToRegeditData();
|
||
}
|
||
|
||
void CUndergroundRampDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CModelessDialog::DoDataExchange(pDX);
|
||
DDX_Text(pDX, IDC_EDT_UNGR_WIDTH, m_wndEdtWidth);
|
||
DDX_Text(pDX, IDC_EDT_UNGR_RADIUS, m_wndEdtRadius);
|
||
DDX_Control(pDX, IDC_CHK_UNGR_MIDLINE, m_wndChkMidline);
|
||
DDX_Control(pDX, IDC_CHK_UNGR_LABLEARROW, m_wndChkLableArrow);
|
||
DDX_Control(pDX, IDC_PIC_UNGR_VIEWS, m_wndPreview);
|
||
DDX_Radio(pDX, IDC_RAD_UNGR_MIDLINE, m_iLocationLine);
|
||
}
|
||
|
||
|
||
BEGIN_MESSAGE_MAP(CUndergroundRampDlg, CModelessDialog)
|
||
ON_BN_CLICKED(IDC_RAD_UNGR_MIDLINE, OnBnClickedRadUngrMidline)
|
||
ON_BN_CLICKED(IDC_RAD_UNGR_LEFTLINE, OnBnClickedRadUngrLeftline)
|
||
ON_BN_CLICKED(IDC_RAD_UNGR_RIGHTLINE, OnBnClickedRadUngrRightline)
|
||
ON_BN_CLICKED(IDC_CHK_UNGR_MIDLINE, OnBnClickedChkUngrMidline)
|
||
ON_BN_CLICKED(IDC_CHK_UNGR_LABLEARROW, OnBnClickedChkUngrLablearrow)
|
||
ON_BN_CLICKED(IDC_RAD_UNGR_ENTER, OnBnClickedRadUngrEnter)
|
||
ON_BN_CLICKED(IDC_RAD_UNGR_EXIT, OnBnClickedRadUngrExit)
|
||
ON_EN_KILLFOCUS(IDC_EDT_UNGR_WIDTH, OnEnKillfocusEdtUngrWidth)
|
||
ON_EN_KILLFOCUS(IDC_EDT_UNGR_RADIUS, OnEnKillfocusEdtUngrRadius)
|
||
ON_WM_CTLCOLOR()
|
||
ON_STN_CLICKED(IDC_PIC_UNGR_STYLES, OnStnClickedPicUngrStyles)
|
||
ON_STN_CLICKED(IDC_PIC_UNGR_VIEWS, OnStnClickedPicUngrViews)
|
||
ON_WM_SETCURSOR()
|
||
ON_WM_CLOSE()
|
||
END_MESSAGE_MAP()
|
||
|
||
|
||
// CUndergroundRampDlg 消息处理程序
|
||
|
||
|
||
BOOL CUndergroundRampDlg::OnInitDialog()
|
||
{
|
||
CModelessDialog::OnInitDialog();
|
||
/*UpdateData(FALSE);*/
|
||
// 获取当前的绘图单位 bIsMetre=true:M;bIsMetre=false:mm
|
||
BOOL bIsMetre = DocGetMeterUnitDraw();
|
||
if (bIsMetre)
|
||
this->SetWindowText(_T("地下坡道(单位:M)")); // 对话框标题设置
|
||
else
|
||
this->SetWindowText(_T("地下坡道(单位:mm)"));
|
||
if (m_bLableArrow)
|
||
{
|
||
m_wndChkLableArrow.SetCheck(1);
|
||
((CButton*)GetDlgItem(IDC_RAD_UNGR_ENTER))->EnableWindow(TRUE);
|
||
((CButton*)GetDlgItem(IDC_RAD_UNGR_EXIT))->EnableWindow(TRUE);
|
||
}
|
||
else
|
||
{
|
||
m_wndChkLableArrow.SetCheck(0);
|
||
((CButton*)GetDlgItem(IDC_RAD_UNGR_ENTER))->EnableWindow(FALSE);
|
||
((CButton*)GetDlgItem(IDC_RAD_UNGR_EXIT))->EnableWindow(FALSE);
|
||
}
|
||
|
||
if (m_bRoadMidline)
|
||
m_wndChkMidline.SetCheck(1);
|
||
//switch (m_iLocationLine)//定位线位置
|
||
//{
|
||
//case MIDLINE:
|
||
// ((CButton*)GetDlgItem(IDC_RAD_UNGR_MIDLINE))->SetCheck(1);
|
||
// break;
|
||
//case LEFTLINE:
|
||
// ((CButton*)GetDlgItem(IDC_RAD_UNGR_LEFTLINE))->SetCheck(1);
|
||
// break;
|
||
//case RIGHTLINE:
|
||
// ((CButton*)GetDlgItem(IDC_RAD_UNGR_RIGHTLINE))->SetCheck(1);
|
||
// break;
|
||
//}
|
||
|
||
switch (m_iLocation)//箭头位置
|
||
{
|
||
case ENTER:
|
||
((CButton*)GetDlgItem(IDC_RAD_UNGR_ENTER))->SetCheck(1);
|
||
break;
|
||
case EXITS:
|
||
((CButton*)GetDlgItem(IDC_RAD_UNGR_EXIT))->SetCheck(1);
|
||
break;
|
||
}
|
||
UpdateData(FALSE);
|
||
SetView();
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
void CUndergroundRampDlg::OnBnClickedRadUngrMidline()
|
||
{
|
||
m_iLocationLine = MIDLINE;
|
||
GlwUGRampDataManage* pRampDataManage = GET_GLOBAL_VARIABLE(GlwUGRampDataManage);
|
||
pRampDataManage->SetLOPLoc(m_iLocationLine);
|
||
}
|
||
|
||
|
||
void CUndergroundRampDlg::OnBnClickedRadUngrLeftline()
|
||
{
|
||
m_iLocationLine = LEFTLINE;
|
||
GlwUGRampDataManage* pRampDataManage = GET_GLOBAL_VARIABLE(GlwUGRampDataManage);
|
||
pRampDataManage->SetLOPLoc(m_iLocationLine);
|
||
}
|
||
|
||
|
||
void CUndergroundRampDlg::OnBnClickedRadUngrRightline()
|
||
{
|
||
m_iLocationLine = RIGHTLINE;
|
||
GlwUGRampDataManage* pRampDataManage = GET_GLOBAL_VARIABLE(GlwUGRampDataManage);
|
||
pRampDataManage->SetLOPLoc(m_iLocationLine);
|
||
}
|
||
|
||
//点击 绘制道路中线
|
||
void CUndergroundRampDlg::OnBnClickedChkUngrMidline()
|
||
{
|
||
if (m_wndChkMidline.GetCheck())
|
||
{
|
||
m_wndChkMidline.SetCheck(1);
|
||
m_bRoadMidline = TRUE;
|
||
}
|
||
else
|
||
{
|
||
m_wndChkMidline.SetCheck(0);
|
||
m_bRoadMidline = FALSE;
|
||
}
|
||
GlwUGRampDataManage* pRampDataManage = GET_GLOBAL_VARIABLE(GlwUGRampDataManage);
|
||
pRampDataManage->SetIsDrawMidLine(m_bRoadMidline);
|
||
}
|
||
|
||
//箭头
|
||
void CUndergroundRampDlg::OnBnClickedChkUngrLablearrow()
|
||
{
|
||
if (m_wndChkLableArrow.GetCheck())
|
||
{
|
||
m_wndChkLableArrow.SetCheck(1);
|
||
m_bLableArrow = TRUE;
|
||
((CButton*)GetDlgItem(IDC_RAD_UNGR_ENTER))->EnableWindow(TRUE);
|
||
((CButton*)GetDlgItem(IDC_RAD_UNGR_EXIT))->EnableWindow(TRUE);
|
||
}
|
||
else
|
||
{
|
||
m_wndChkLableArrow.SetCheck(0);
|
||
m_bLableArrow = FALSE;
|
||
((CButton*)GetDlgItem(IDC_RAD_UNGR_ENTER))->EnableWindow(FALSE);
|
||
((CButton*)GetDlgItem(IDC_RAD_UNGR_EXIT))->EnableWindow(FALSE);
|
||
}
|
||
GlwUGRampDataManage* pRampDataManage = GET_GLOBAL_VARIABLE(GlwUGRampDataManage);
|
||
pRampDataManage->SetIsDimArrow(m_bLableArrow);
|
||
}
|
||
|
||
//点击 入口
|
||
void CUndergroundRampDlg::OnBnClickedRadUngrEnter()
|
||
{
|
||
m_iLocation = ENTER;
|
||
GlwUGRampDataManage* pRampDataManage = GET_GLOBAL_VARIABLE(GlwUGRampDataManage);
|
||
pRampDataManage->SetArrowDrec(m_iLocation);
|
||
}
|
||
|
||
|
||
void CUndergroundRampDlg::OnBnClickedRadUngrExit()
|
||
{
|
||
m_iLocation = EXITS;
|
||
GlwUGRampDataManage* pRampDataManage = GET_GLOBAL_VARIABLE(GlwUGRampDataManage);
|
||
pRampDataManage->SetArrowDrec(m_iLocation);
|
||
}
|
||
|
||
|
||
void CUndergroundRampDlg::OnEnKillfocusEdtUngrWidth()
|
||
{
|
||
double dTmp = m_wndEdtWidth;
|
||
UpdateData(TRUE);
|
||
if (m_wndEdtWidth <= 0)
|
||
{
|
||
MessageBox(_T("请输入大于0的数值!"), _T("AutoCAD"));
|
||
m_wndEdtWidth = dTmp;
|
||
}
|
||
UpdateData(FALSE);
|
||
if(!GET_GLOBAL_VARIABLE(GlwUGRampDataManage))
|
||
SET_GLOBAL_VARIABLE(GlwUGRampDataManage, new GlwUGRampDataManage);
|
||
GlwUGRampDataManage* pRampDataManage = GET_GLOBAL_VARIABLE(GlwUGRampDataManage);
|
||
pRampDataManage->SetRampWidth(m_wndEdtWidth);
|
||
}
|
||
|
||
|
||
void CUndergroundRampDlg::OnEnKillfocusEdtUngrRadius()
|
||
{
|
||
double dTmp = m_wndEdtRadius;
|
||
UpdateData(TRUE);
|
||
if (m_wndEdtRadius <= 0)
|
||
{
|
||
MessageBox(_T("请输入大于0的数值!"), _T("AutoCAD"));
|
||
m_wndEdtRadius = dTmp;
|
||
}
|
||
UpdateData(FALSE);
|
||
if(!GET_GLOBAL_VARIABLE(GlwUGRampDataManage))
|
||
SET_GLOBAL_VARIABLE(GlwUGRampDataManage, new GlwUGRampDataManage);
|
||
GlwUGRampDataManage* pRampDataManage = GET_GLOBAL_VARIABLE(GlwUGRampDataManage);
|
||
pRampDataManage->SetTurningRad(m_wndEdtRadius);
|
||
}
|
||
|
||
|
||
HBRUSH CUndergroundRampDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
||
{
|
||
HBRUSH hbr = CModelessDialog::OnCtlColor(pDC, pWnd, nCtlColor);
|
||
|
||
// TODO: 在此更改 DC 的任何特性
|
||
// if (pWnd->m_hWnd == ((CButton*)GetDlgItem(IDC_GRP_UNGR_LOCATION))->m_hWnd)
|
||
// {
|
||
// CRect rc;
|
||
// ((CButton*)GetDlgItem(IDC_GRP_UNGR_LOCATION))->GetClientRect(&rc);
|
||
// pDC->SetBkMode(TRANSPARENT);
|
||
// pDC->SetTextColor(RGB(255, 0, 0));//红色字体
|
||
// // Return our CBrush object
|
||
// hbr = 0;//m_brushRed;//red
|
||
// }
|
||
// return (HBRUSH)::GetStockObject(NULL_BRUSH);
|
||
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
|
||
return hbr;
|
||
}
|
||
|
||
//点击图片弹窗
|
||
void CUndergroundRampDlg::OnStnClickedPicUngrStyles()
|
||
{
|
||
CUnderGroundView dlg;
|
||
if(IDOK == dlg.DoModal())
|
||
{
|
||
m_iViewStyle = dlg.GetViewStyle();
|
||
if (m_iViewStyle < 0 || m_iViewStyle > 8)//安全检查
|
||
m_iViewStyle = 1;
|
||
SetView();
|
||
if(!GET_GLOBAL_VARIABLE(GlwUGRampDataManage))
|
||
SET_GLOBAL_VARIABLE(GlwUGRampDataManage, new GlwUGRampDataManage);
|
||
GlwUGRampDataManage* pRampDataManage = GET_GLOBAL_VARIABLE(GlwUGRampDataManage);
|
||
pRampDataManage->SetDrawStyle(m_iViewStyle);
|
||
}
|
||
}
|
||
void CUndergroundRampDlg::OnStnClickedPicUngrViews()
|
||
{
|
||
OnStnClickedPicUngrStyles();
|
||
}
|
||
|
||
// 设置图片
|
||
void CUndergroundRampDlg::SetView()
|
||
{
|
||
CAcModuleResourceOverride vTemp;
|
||
CBitmap bmp;
|
||
switch (m_iViewStyle)//预览图片
|
||
{
|
||
case VIEW1:
|
||
bmp.LoadBitmap(IDB_BMP_UNGR1);
|
||
break;
|
||
case VIEW2:
|
||
bmp.LoadBitmap(IDB_BMP_UNGR2);
|
||
break;
|
||
case VIEW3:
|
||
bmp.LoadBitmap(IDB_BMP_UNGR3);
|
||
break;
|
||
case VIEW4:
|
||
bmp.LoadBitmap(IDB_BMP_UNGR4);
|
||
break;
|
||
case VIEW5:
|
||
bmp.LoadBitmap(IDB_BMP_UNGR5);
|
||
break;
|
||
case VIEW6:
|
||
bmp.LoadBitmap(IDB_BMP_UNGR6);
|
||
break;
|
||
case VIEW7:
|
||
bmp.LoadBitmap(IDB_BMP_UNGR7);
|
||
break;
|
||
case VIEW8:
|
||
bmp.LoadBitmap(IDB_BMP_UNGR8);
|
||
break;
|
||
case VIEW9:
|
||
bmp.LoadBitmap(IDB_BMP_UNGR9);
|
||
break;
|
||
default:
|
||
bmp.LoadBitmap(IDB_BMP_UNGR1);
|
||
break;
|
||
}
|
||
HBITMAP hBmp = m_wndPreview.SetBitmap(bmp);
|
||
::DeleteObject(hBmp);
|
||
bmp.Detach();
|
||
}
|
||
|
||
BOOL CUndergroundRampDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
|
||
{
|
||
CWnd *pSlideWnd = GetDlgItem(IDC_PIC_UNGR_VIEWS);
|
||
if (pWnd && pWnd->m_hWnd == pSlideWnd->m_hWnd)
|
||
{
|
||
CAcModuleResourceOverride vTemp;
|
||
HCURSOR hIcon = AfxGetApp()->LoadCursor(IDC_CURSOR_HAND);//标准鼠标箭头图标IDC_HAND无效
|
||
SetCursor(hIcon);
|
||
return TRUE;
|
||
}
|
||
return CModelessDialog::OnSetCursor(pWnd, nHitTest, message);
|
||
}
|
||
|
||
|
||
int CUndergroundRampDlg::GetViewStyle()
|
||
{
|
||
return m_iViewStyle;
|
||
}
|
||
|
||
double CUndergroundRampDlg::GetWidth()
|
||
{
|
||
return m_wndEdtWidth;
|
||
}
|
||
|
||
double CUndergroundRampDlg::GetRadius()
|
||
{
|
||
return m_wndEdtRadius;
|
||
}
|
||
|
||
int CUndergroundRampDlg::GetLocationLine()
|
||
{
|
||
return m_iLocationLine;
|
||
}
|
||
|
||
BOOL CUndergroundRampDlg::GetMidline()
|
||
{
|
||
return m_bRoadMidline;
|
||
}
|
||
|
||
BOOL CUndergroundRampDlg::GetLableArrow()
|
||
{
|
||
return m_bLableArrow;
|
||
}
|
||
|
||
int CUndergroundRampDlg::GetArrowLoc()
|
||
{
|
||
return m_iLocation;
|
||
}
|
||
|
||
void CUndergroundRampDlg::UpdataLoctionLine(int nLocationLine)
|
||
{
|
||
m_iLocationLine = nLocationLine;
|
||
UpdateData(FALSE);
|
||
}
|
||
void CUndergroundRampDlg::OnClose()
|
||
{
|
||
acedPostCommand(_T("\33\33"));
|
||
}
|
||
void CUndergroundRampDlg::LoadRegeditSaveData()
|
||
{
|
||
CString strTmp;
|
||
DataLoadAndSave::readRecordDataCString(TARCH20_SYMBOL_KEY_UNDERGROUNDRAMP, strTmp, TARCH20_SYMBOL_TERMNAME);
|
||
if (strTmp.IsEmpty())
|
||
return;
|
||
|
||
//将str划分为vector<CString>使用 DIVSTRING 为分隔符
|
||
std::vector<CString> strWndData;
|
||
SplitString(strTmp, DIVSTRING, strWndData);
|
||
|
||
if (strWndData.size() <7)
|
||
{
|
||
return;
|
||
}
|
||
m_wndEdtWidth = _ttoi(strWndData[0]);
|
||
m_wndEdtRadius = _ttof(strWndData[1]);
|
||
m_iLocationLine = _ttoi(strWndData[2]); //3
|
||
m_iLocation = _ttoi(strWndData[3]);
|
||
m_bRoadMidline = _ttoi(strWndData[4]);
|
||
m_bLableArrow = _ttoi(strWndData[5]); //6
|
||
m_iViewStyle = _ttoi(strWndData[6]);
|
||
|
||
}
|
||
|
||
void CUndergroundRampDlg::SaveToRegeditData()
|
||
{
|
||
std::vector<CString> strWndData;
|
||
strWndData.clear();
|
||
strWndData.push_back(format(m_wndEdtWidth));
|
||
strWndData.push_back(format(m_wndEdtRadius));
|
||
strWndData.push_back(format(m_iLocationLine));
|
||
strWndData.push_back(format(m_iLocation));
|
||
strWndData.push_back(format(m_bRoadMidline));
|
||
strWndData.push_back(format(m_bLableArrow));
|
||
strWndData.push_back(format(m_iViewStyle));
|
||
CString strTmp = MergeStr(strWndData);//组合字符串
|
||
DataLoadAndSave::writeRecordDataCString(TARCH20_SYMBOL_KEY_UNDERGROUNDRAMP, strTmp, TARCH20_SYMBOL_TERMNAME);
|
||
}
|
||
|
||
|
||
|
||
|