325 lines
9.6 KiB
C++
325 lines
9.6 KiB
C++
//楼梯界面实现
|
|
#include "stdafx.h"
|
|
#include "resource.h"
|
|
#include "LineStairDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CLineStairDlg dialog
|
|
CString CLineStairDlg::m_strStairWidth = _T("1200");
|
|
CString CLineStairDlg::m_strStepWidth = _T("270");
|
|
CString CLineStairDlg::m_strStairLength = _T("5130");
|
|
// --------------------------------- [9/28/2007 nsh]
|
|
BOOL CLineStairDlg::m_bgroupStatus=FALSE;
|
|
IMPLEMENT_DYNAMIC(CLineStairDlg, CBaseStairDlg)
|
|
CLineStairDlg::CLineStairDlg(CWnd* pParent /*=NULL*/)
|
|
: CBaseStairDlg(CLineStairDlg::IDD, pParent),bValidWnd(false)
|
|
{
|
|
m_strStairLength=Dist2Str(_tstof(m_strStepWidth)*(m_bAsAscent? m_nStepNum : m_nStepNum-1));
|
|
//SetNeedCapBtn(TRUE);
|
|
/*m_groups.Append(&m_group1);
|
|
m_groups.Append(&m_group2);
|
|
m_groups.Append(&m_group3);*/
|
|
//初始话
|
|
m_bEdit=FALSE;//处于非编辑状态
|
|
m_pBakObj=NULL;//为空状态
|
|
|
|
|
|
}
|
|
CLineStairDlg::CLineStairDlg(UINT id,CWnd* pParent /*=NULL*/)
|
|
: CBaseStairDlg(id, pParent),bValidWnd(false)
|
|
{
|
|
/*m_groups.Append(&m_group1);
|
|
m_groups.Append(&m_group2);
|
|
m_groups.Append(&m_group3);*/
|
|
m_strStairLength=Dist2Str(_tstof(m_strStepWidth)*(m_bAsAscent? m_nStepNum : m_nStepNum-1));
|
|
//初始话
|
|
m_bEdit=FALSE;//处于非编辑状态
|
|
m_pBakObj=NULL;//为空状态
|
|
|
|
|
|
}
|
|
CLineStairDlg::~CLineStairDlg()
|
|
{
|
|
if (m_bEdit)
|
|
delete m_pBakObj;//这个地方是不是有问题
|
|
}
|
|
AcDbEntity *CLineStairDlg::NewObject()
|
|
{
|
|
TDbLineStair *pEnt;
|
|
if (m_pBakObj==NULL)
|
|
{
|
|
pEnt=new TDbLineStair;
|
|
pEnt->setLayer(InitLayer(LAY_STAIR));
|
|
return pEnt;
|
|
}
|
|
else
|
|
{
|
|
return (AcDbEntity*)(m_pBakObj->clone());
|
|
}
|
|
}
|
|
void CLineStairDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CBaseStairDlg::DoDataExchange(pDX);
|
|
// ------------------------------------ [9/28/2007 nsh]
|
|
DDX_Control(pDX,IDC_GROUP3,m_group);
|
|
DDX_GroupStatus(pDX,IDC_GROUP3,m_bgroupStatus);
|
|
DDX_CBString(pDX,IDC_COMBO_STAIRHEIGHT1,m_strStairHeight);// [8/18/2008 nsh]
|
|
|
|
//{{AFX_DATA_MAP(CLineStairDlg)
|
|
DDX_Control(pDX,IDC_COMBO_STAIRHEIGHT1,m_ctrlStairHeight);// [8/18/2008 nsh]
|
|
//}}AFX_DATA_MAP
|
|
if (!pDX->m_bSaveAndValidate)
|
|
{
|
|
DDX_Text(pDX, IDC_STAIR_WIDTH, m_strStairWidth);
|
|
DDX_Text(pDX, IDC_STEP_WIDTH, m_strStepWidth);
|
|
DDX_Text(pDX, IDC_STAIR_LENGTH, m_strStairLength);
|
|
}
|
|
}
|
|
BEGIN_MESSAGE_MAP(CLineStairDlg, CBaseStairDlg)
|
|
//{{AFX_MSG_MAP(CLineStairDlg)
|
|
ON_BN_CLICKED(IDC_PICK_STAIRWIDTH, OnPickStairWidth)
|
|
ON_EN_KILLFOCUS(IDC_STAIR_WIDTH,OnKFStairWidth)
|
|
ON_EN_KILLFOCUS(IDC_STEP_WIDTH,OnKFStepWidth)
|
|
ON_EN_KILLFOCUS(IDC_STAIR_LENGTH,OnKFStairLength)
|
|
ON_EN_CHANGE(IDC_STAIR_WIDTH,OnChangeStairWidth)
|
|
ON_EN_CHANGE(IDC_STEP_WIDTH,OnChangeStepWidth)
|
|
ON_EN_CHANGE(IDC_STAIR_LENGTH,OnChangeStairLength)
|
|
ON_CBN_EDITCHANGE(IDC_COMBO_STAIRHEIGHT1,OnChangeStairHeight)// [8/18/2008 nsh]
|
|
ON_CBN_SELCHANGE(IDC_COMBO_STAIRHEIGHT1,OnSelChangeStairHeight)// [8/18/2008 nsh]
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
void CLineStairDlg::OnChangeStairWidth()
|
|
{
|
|
UpdateEdit(IDC_STAIR_WIDTH);
|
|
}
|
|
void CLineStairDlg::OnChangeStepWidth()
|
|
{
|
|
UpdateEdit(IDC_STEP_WIDTH);
|
|
}
|
|
void CLineStairDlg::OnChangeStairLength()
|
|
{
|
|
UpdateEdit(IDC_STAIR_LENGTH);
|
|
}
|
|
void CLineStairDlg::OnKFStairWidth()
|
|
{
|
|
if (GetDlgItem(IDCANCEL)!=GetFocus())
|
|
UpdateEdit(IDC_STAIR_WIDTH,true);
|
|
}
|
|
void CLineStairDlg::OnKFStepWidth()
|
|
{
|
|
if (GetDlgItem(IDCANCEL)!=GetFocus())
|
|
UpdateEdit(IDC_STEP_WIDTH,true);
|
|
}
|
|
void CLineStairDlg::OnKFStairLength()
|
|
{
|
|
if (GetDlgItem(IDCANCEL)!=GetFocus())
|
|
UpdateEdit(IDC_STAIR_LENGTH,true);
|
|
}
|
|
BOOL CLineStairDlg::OnInitDialog()
|
|
{
|
|
CBaseStairDlg::OnInitDialog();
|
|
//m_groups.SetMaxExtent(310);
|
|
//AddTip(IDC_STEP_WIDTH_STATIC,"踏步宽度变化将使楼梯长度同比例变化");
|
|
//AddTip(IDC_STAIR_LENGTH_STATIC,"梯段长度始终等于所有踏步的宽度总和,其变化将使踏步宽度同比例变化");
|
|
bValidWnd=true;
|
|
//UpdateData(FALSE);
|
|
UpdateImage();
|
|
return TRUE;
|
|
}
|
|
void CLineStairDlg::OnPickStairWidth()
|
|
{
|
|
double nStairWidth=_tstof(m_strStairWidth);
|
|
|
|
BeginEditorCommand();
|
|
int nRet=GetDist(_T("\n楼梯间宽度"), nStairWidth, RSG_NOZERO|RSG_NONEG);
|
|
CompleteEditorCommand();
|
|
|
|
if (nRet==RTNORM)
|
|
{
|
|
CString temp=Dist2Str(nStairWidth);
|
|
CDataExchange dxOut(this,false);
|
|
DDX_Text(&dxOut,IDC_STAIR_WIDTH,temp);
|
|
UpdateEdit(IDC_STAIR_WIDTH,true);
|
|
}
|
|
}
|
|
//数据关系:
|
|
//梯段长度变化会引起踏步宽度同比例变化;
|
|
//踏步宽度变化会引起梯段长度同比例变化;
|
|
//踏步数变化会引起踏步宽度反向变化。
|
|
// 对于坡道: 长度=步距*步数
|
|
// 对于梯段: 长度=步距*(步数-1)
|
|
bool CLineStairDlg::UpdateEdit(UINT ctrlID,bool bReportError)
|
|
{
|
|
if (!bValidWnd)
|
|
return false;
|
|
CEdit *pEdit=(CEdit*)GetDlgItem(ctrlID);
|
|
if (pEdit==NULL)
|
|
return false;
|
|
|
|
static bool bUpdating=false;
|
|
if (bUpdating)
|
|
return false;
|
|
bUpdating=true;
|
|
|
|
bool result=true;
|
|
CDataExchange dxOut(this,false);
|
|
if (ctrlID==IDC_STAIR_LENGTH||ctrlID==IDC_STEP_WIDTH||ctrlID==IDC_STAIR_WIDTH) {
|
|
CString temp;
|
|
pEdit->GetWindowText(temp);
|
|
if (ctrlID==IDC_STAIR_LENGTH) {
|
|
//if (m_bAsAscent) {
|
|
if (_tstof(temp)>0) {
|
|
m_strStairLength=temp;
|
|
int num=m_bAsAscent? m_nStepNum : (m_nStepNum-1);
|
|
if (num<1) num=1;
|
|
//m_strStepWidth=Dist2Str(_tstof(temp)/num);
|
|
m_strStepWidth.Format(_T("%.2f"),::_tstof(temp)/num);
|
|
DDX_Text(&dxOut,IDC_STEP_WIDTH,m_strStepWidth);
|
|
UpdateImage();
|
|
} else if (bReportError){
|
|
AfxMessageBox(_T("梯段长度太小!"));
|
|
DDX_Text(&dxOut,IDC_STAIR_LENGTH,m_strStairLength);
|
|
pEdit->SetFocus();
|
|
pEdit->SetSel(0,-1);
|
|
}
|
|
//}
|
|
} else if (ctrlID==IDC_STEP_WIDTH){
|
|
if (_tstof(temp)>0) {
|
|
m_strStepWidth=temp;
|
|
m_strStairLength=Dist2Str(_tstof(temp)*(m_bAsAscent? m_nStepNum : m_nStepNum-1));
|
|
DDX_Text(&dxOut,IDC_STAIR_LENGTH,m_strStairLength);
|
|
UpdateImage();
|
|
} else if (bReportError) {
|
|
AfxMessageBox(_T("踏步宽度太小!"));
|
|
DDX_Text(&dxOut,IDC_STEP_WIDTH,m_strStepWidth);
|
|
pEdit->SetFocus();
|
|
pEdit->SetSel(0,-1);
|
|
}
|
|
} else {
|
|
if (_tstof(temp)>0) {
|
|
m_strStairWidth=temp;
|
|
UpdateImage();//更新
|
|
} else if (bReportError) {
|
|
AfxMessageBox(_T("梯段宽度太小!"));
|
|
pEdit->SetFocus();
|
|
DDX_Text(&dxOut,IDC_STAIR_WIDTH,m_strStairWidth);//还原
|
|
pEdit->SetSel(0,-1);
|
|
}
|
|
}
|
|
} else if (CBaseStairDlg::UpdateEdit(ctrlID,bReportError)&&
|
|
(ctrlID==IDC_STEP_NUM||ctrlID==IDC_STEP_HEIGHT)){
|
|
if (m_bAsAscent) {
|
|
m_strStepWidth=Dist2Str(_tstof(m_strStairLength)/m_nStepNum);
|
|
DDX_Text(&dxOut,IDC_STEP_WIDTH,m_strStepWidth);
|
|
} else {
|
|
m_strStairLength=Dist2Str(_tstof(m_strStepWidth)*(m_nStepNum-1));
|
|
DDX_Text(&dxOut, IDC_STAIR_LENGTH, m_strStairLength);
|
|
}
|
|
UpdateImage();
|
|
} else
|
|
result=false;
|
|
|
|
bUpdating=false;
|
|
return result;
|
|
}
|
|
void CLineStairDlg::UpdateSel()
|
|
{
|
|
CBaseStairDlg::UpdateSel();
|
|
// [7/15/2008 nsh]
|
|
this->UpdateData(TRUE);
|
|
CDataExchange dxOut(this,false);
|
|
if (this->m_bAsAscent ==TRUE)
|
|
{
|
|
m_strStairLength=Dist2Str(m_nStepNum*::_tstof(m_strStepWidth));
|
|
DDX_Text(&dxOut,IDC_STAIR_LENGTH,m_strStairLength);
|
|
}
|
|
else
|
|
{
|
|
m_strStairLength=Dist2Str((m_nStepNum-1)*::_tstof(m_strStepWidth));
|
|
DDX_Text(&dxOut,IDC_STAIR_LENGTH,m_strStairLength);
|
|
}
|
|
//------------------------------
|
|
//GetDlgItem(IDC_STEP_WIDTH)->EnableWindow(!m_bAsAscent);
|
|
}
|
|
void CLineStairDlg::Dlg2Obj(AcDbEntity *pStep)//导出
|
|
{
|
|
CBaseStairDlg::Dlg2Obj(pStep);
|
|
TDbLineStair *pLineStair=TDbLineStair::cast(pStep);
|
|
ASSERT(pLineStair);
|
|
pLineStair->SetStepNum(m_nStepNum);
|
|
pLineStair->SetStairWidth(_tstof(m_strStairWidth));
|
|
pLineStair->SetStepWidth(_tstof(m_strStepWidth));
|
|
// [7/10/2008 nsh]
|
|
pLineStair->SetStepHeight(_tstof(m_strStepHeight));
|
|
//------------------------
|
|
if (m_bEdit)
|
|
{
|
|
delete m_pBakObj;
|
|
m_pBakObj=(TDbLineStair*)(pStep->clone());
|
|
}
|
|
//------------------------
|
|
return;
|
|
}
|
|
void CLineStairDlg::Obj2Dlg(const AcDbEntity *pStep)//导入
|
|
{
|
|
CBaseStairDlg::Obj2Dlg(pStep);
|
|
TDbLineStair *pLineStair=TDbLineStair::cast(pStep);
|
|
// [8/14/2008 nsh]
|
|
//--------------------------------
|
|
m_bEdit=TRUE;
|
|
m_pBakObj=(TDbLineStair*)(pStep->clone());//专递值
|
|
//--------------------------------
|
|
ASSERT(pLineStair);
|
|
m_nStepNum=pLineStair->GetStepNum();
|
|
m_strStairWidth=Dist2Str(pLineStair->GetStairWidth());
|
|
//m_strStepWidth=Dist2Str(pLineStair->GetStepWidth());
|
|
m_strStepWidth.Format(_T("%.2f"),pLineStair->GetStepWidth());
|
|
m_strStepHeight.Format(_T("%.2f"),pLineStair->GetStepHeight());
|
|
if (!m_bAsAscent)
|
|
m_strStepWidth=Dist2Str(pLineStair->GetStepWidth());
|
|
m_strStairLength=Dist2Str(_tstof(m_strStepWidth)*(m_bAsAscent? m_nStepNum : m_nStepNum-1));
|
|
|
|
return;
|
|
}
|
|
// [8/18/2008 nsh]
|
|
//----------------------------------------------
|
|
void CLineStairDlg::OnChangeStairHeight()
|
|
{
|
|
|
|
CString strTemp;
|
|
this->GetDlgItem(IDC_COMBO_STAIRHEIGHT1)->GetWindowText(strTemp);
|
|
if (_tstof(strTemp)>=2*_tstof(m_strStepHeight)-_DIST_SNAP)
|
|
{//最少当前两踏步高
|
|
m_strStairHeight=strTemp;
|
|
m_nStepNum=(int)(_tstof(m_strStairHeight)/_tstof(m_strStepHeight)+0.5);
|
|
m_strStepHeight.Format(_T("%.2f"),(_tstof(m_strStairHeight)/m_nStepNum));
|
|
CDataExchange dxOut(this,false);
|
|
DDX_Text(&dxOut,IDC_STEP_HEIGHT,m_strStepHeight);
|
|
DDX_Text(&dxOut,IDC_STEP_NUM,m_nStepNum);
|
|
UpdateImage();
|
|
}
|
|
}
|
|
void CLineStairDlg::OnSelChangeStairHeight()
|
|
{
|
|
CString strTemp;
|
|
CDataExchange dxIn(this,TRUE);
|
|
DDX_CBString(&dxIn,IDC_COMBO_STAIRHEIGHT1,m_strStairHeight);
|
|
m_ctrlStairHeight.GetLBText(m_ctrlStairHeight.GetCurSel(),strTemp);
|
|
if (_tstof(strTemp)>=2*_tstof(m_strStepHeight)-_DIST_SNAP)
|
|
{//最少当前两踏步高
|
|
m_strStairHeight=strTemp;
|
|
m_nStepNum=(int)(_tstof(m_strStairHeight)/_tstof(m_strStepHeight)+0.5);
|
|
m_strStepHeight.Format(_T("%.2f"),(_tstof(m_strStairHeight)/m_nStepNum));
|
|
CDataExchange dxOut(this,false);
|
|
DDX_Text(&dxOut,IDC_STEP_HEIGHT,m_strStepHeight);
|
|
DDX_Text(&dxOut,IDC_STEP_NUM,m_nStepNum);
|
|
UpdateImage();
|
|
}
|
|
}
|
|
//----------------------------------------------
|