385 lines
8.6 KiB
C++
385 lines
8.6 KiB
C++
// SlopeRoofDlg.cpp : implementation file
|
|
//
|
|
#include "stdafx.h"
|
|
#include "resource.h"
|
|
#include "SlopeRoofDlg.h"
|
|
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CSlopeRoofDlg dialog
|
|
////////////////////////////////////////////////
|
|
// TLayerGrid
|
|
TSlopeRoofGrid::TSlopeRoofGrid()
|
|
{
|
|
m_bModify = FALSE;
|
|
}
|
|
|
|
void TSlopeRoofGrid::OnCellComboString(WDGridCell&cell,CComboBox&combo)
|
|
{
|
|
if (cell.GetColIndex()==1)
|
|
{
|
|
combo.AddString(_T("15.00"));
|
|
combo.AddString(_T("30.00"));
|
|
combo.AddString(_T("33.33"));
|
|
combo.AddString(_T("45.00"));
|
|
combo.AddString(_T("60.00"));
|
|
combo.AddString(_T("90.00"));
|
|
}
|
|
}
|
|
void TSlopeRoofGrid::OnDataChanged()
|
|
{
|
|
m_bModify = TRUE;
|
|
if (m_CurCol == 1)
|
|
{
|
|
CString str;
|
|
TString tstr = GetCell(m_CurRow,m_CurCol).GetText();
|
|
#ifdef _UNICODE
|
|
str = (const wchar_t*)tstr;
|
|
#else
|
|
str = (const char*)tstr;
|
|
#endif
|
|
double nAng = _tstof(LPCTSTR(str));
|
|
nAng = (nAng*PI)/180.0;
|
|
str = _T("");
|
|
if (fabs(nAng-PI/2)<1.0E-6)
|
|
str=_T("无");
|
|
else
|
|
str.Format(_T("%.1f%%"), tan(nAng)*100);
|
|
GetRow(m_CurRow)[2].SetText(LPCTSTR(str));
|
|
}
|
|
else if (m_CurCol == 2)
|
|
{
|
|
CString str;
|
|
TString tstr = GetCell(m_CurRow,m_CurCol).GetText();
|
|
#ifdef _UNICODE
|
|
str = (const wchar_t*)tstr;
|
|
#else
|
|
str = (const char*)tstr;
|
|
#endif
|
|
str.TrimLeft();
|
|
str.TrimRight();
|
|
if (str != _T("无")&&str != _T("无%"))
|
|
{
|
|
int i = str.Find(_T('%'),0);
|
|
if (i >= 0)
|
|
{
|
|
str.Delete(i);
|
|
}
|
|
else
|
|
{
|
|
CString sTemp = str;
|
|
sTemp += _T('%');
|
|
GetCell(m_CurRow,m_CurCol).SetText(LPCTSTR(sTemp));
|
|
}
|
|
double nAng = _tstof(LPCTSTR(str));
|
|
nAng = nAng / 100.0;
|
|
nAng = atan(nAng) * 180.0 / PI;
|
|
str = _T("");
|
|
str.Format(_T("%.2f"), nAng);
|
|
}
|
|
else
|
|
{
|
|
if (str == _T("无%"))
|
|
{
|
|
str.Delete(str.Find(_T('%')));
|
|
GetCell(m_CurRow,m_CurCol).SetText(LPCTSTR(str));
|
|
}
|
|
str = _T("90.00");
|
|
}
|
|
GetRow(m_CurRow)[1].SetText(LPCTSTR(str));
|
|
}
|
|
Refresh();
|
|
SendParentNotify(EN_CHANGE);
|
|
}
|
|
bool TSlopeRoofGrid::OnBeforeEdit(WDGridCell&cell,bool &bModified)
|
|
{
|
|
m_CurRow = cell.GetRowIndex();
|
|
m_CurCol = cell.GetColIndex();
|
|
GetParent()->SendMessage(WM_LBUTTONDOWN,IDC_LIST);
|
|
return TRUE;
|
|
}
|
|
bool TSlopeRoofGrid::OnModified(WDGridCell&cell,CString &text)
|
|
{
|
|
//add by xlc on 090209 解决坡角修改后回车崩溃的问题
|
|
m_CurRow = cell.GetRowIndex();
|
|
m_CurCol = cell.GetColIndex();
|
|
|
|
if (text == _T("无"))
|
|
return TRUE;
|
|
if (text.Find(_T('-')) >= 0)
|
|
return FALSE;
|
|
int i = 0;
|
|
do
|
|
{
|
|
if (text[i]< _T('0') || text[i] > _T('9'))
|
|
{
|
|
if (i == 0 && (text[i] == _T('.') || text[i] == _T('%')))
|
|
return FALSE;
|
|
if (text[i] != _T('.') || text[i] != _T('%'))
|
|
{
|
|
i++;continue;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
i++;
|
|
} while(i <text.GetLength());
|
|
return TRUE;
|
|
}
|
|
void TSlopeRoofGrid::OnCurChanged()
|
|
{
|
|
m_CurRow = GetCur();
|
|
if (m_CurRow >= 0)
|
|
GetParent()->SendMessage(WM_LBUTTONDOWN,IDC_LIST);
|
|
WDGrid::OnCurChanged();
|
|
}
|
|
void TSlopeRoofGrid::SetModify( BOOL bModify )
|
|
{
|
|
m_bModify = bModify;
|
|
}
|
|
|
|
BOOL TSlopeRoofGrid::GetModify()
|
|
{
|
|
return m_bModify;
|
|
}
|
|
|
|
IMPLEMENT_DYNAMIC(CSlopeRoofDlg, GlwCAcUiDialog)
|
|
|
|
CSlopeRoofDlg::CSlopeRoofDlg(const TSlopeRoof &src,TDbSlopeRoof *p, int nEdgePick, CWnd* pParent)
|
|
: GlwCAcUiDialog(CSlopeRoofDlg::IDD, pParent), m_nCurIndex(-1)
|
|
{
|
|
//{{AFX_DATA_INIT(CSlopeRoofDlg)
|
|
//}}AFX_DATA_INIT
|
|
m_RoofData = src;
|
|
m_pRoof = p;
|
|
m_bFlag = FALSE;
|
|
m_CurIndex=-1;
|
|
}
|
|
|
|
|
|
void CSlopeRoofDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Text(pDX,IDC_ELVEMOVE,m_dElveMove);
|
|
//{{AFX_DATA_MAP(CSlopeRoofDlg)
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CSlopeRoofDlg, GlwCAcUiDialog)
|
|
//{{AFX_MSG_MAP(CSlopeRoofDlg)
|
|
ON_BN_CLICKED(IDC_EQSLOPE, OnEqslope)
|
|
ON_BN_CLICKED(IDC_BUTTON_APP, OnButtonApp)
|
|
ON_WM_LBUTTONDOWN()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
// 配置表格界面
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CSlopeRoofDlg message handlers
|
|
|
|
BOOL CSlopeRoofDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
InitGrid();
|
|
if (!m_grid.Create(this, IDC_LIST))
|
|
return FALSE;
|
|
UpdateGrid();
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
void CSlopeRoofDlg::InitGrid()
|
|
{
|
|
m_grid.SetTreeLine();
|
|
m_grid.SetColFixLength();
|
|
m_grid.SetColPosFix();
|
|
m_grid.SetRowPosFix();
|
|
m_grid.SetRowFixLength();
|
|
m_grid.SetNoDefaultMenu();
|
|
m_grid.FitLastCol();
|
|
m_grid.AppendCol(_T("边号"),30);
|
|
m_grid.AppendCol(_T("坡角 "),60);
|
|
m_grid.AppendCol(_T("坡度"),40);
|
|
m_grid.AppendCol(_T("边长"),20);
|
|
m_grid.GetCol(0).SetReadOnly();
|
|
m_grid.GetCol(0).SetBackColor(GetSysColor(COLOR_3DFACE));
|
|
m_grid.GetCol(1).SetComboEdit();
|
|
m_grid.GetCol(3).SetReadOnly();
|
|
// [2/19/2008 nsh]
|
|
//有效数字的保留问题
|
|
m_dElveMove=m_pRoof->GetElevation();
|
|
UpdateData(FALSE);
|
|
|
|
}
|
|
void CSlopeRoofDlg::UpdateGrid()
|
|
{
|
|
m_grid.Clear();
|
|
ReadData();
|
|
m_grid.FitLastCol();
|
|
}
|
|
void CSlopeRoofDlg::ReadData()
|
|
{
|
|
if (!m_RoofData.GetEdgeNum())
|
|
{
|
|
m_grid.SetColNum(0);
|
|
return;
|
|
}
|
|
long i = 0,j = 0;
|
|
for (;i < m_RoofData.GetEdgeNum();i++)
|
|
{
|
|
WDGridRow *pRow = new WDGridRow(m_grid);
|
|
CString str;
|
|
|
|
//modify by xlc on 071011
|
|
//str.Format(_T("%d"),i);
|
|
str.Format(_T("%d"),i+1);
|
|
|
|
(*pRow)[0].SetText(LPCTSTR(str));
|
|
str.Empty();
|
|
str.Format(_T("%.2f"),m_RoofData.GetSlopeAngle(i)*180.0/PI);
|
|
(*pRow)[1].SetText(str);
|
|
str.Empty();
|
|
double nAng = m_RoofData.GetSlopeAngle(i);
|
|
if (fabs(nAng-PI/2)<1.0E-6)
|
|
str=_T("无");
|
|
else
|
|
str.Format(_T("%.1f%%"), tan(nAng)*100);
|
|
(*pRow)[2].SetText(str);
|
|
str.Empty();
|
|
str.Format(_T("%.2f"),m_RoofData.GetSlopeEdge(i).GetLength());
|
|
(*pRow)[3].SetText(str);
|
|
m_grid.AppendRow(pRow);
|
|
}
|
|
}
|
|
|
|
void CSlopeRoofDlg::OnEqslope()
|
|
{
|
|
long nRow = m_CurIndex;
|
|
if (m_grid.IsValidRow(nRow))
|
|
{
|
|
CString str;
|
|
TString tstr = m_grid.GetCell(nRow,1).GetText();
|
|
#ifdef _UNICODE
|
|
str = (const wchar_t*)tstr;
|
|
#else
|
|
str = (const char*)tstr;
|
|
#endif
|
|
double d = _tstof(LPCTSTR(str));
|
|
d = (d * PI)/180.0;
|
|
long j = 0;
|
|
for (;j < m_RoofData.GetEdgeNum();j++)
|
|
{
|
|
WDGridRow *pRow = &m_grid.GetRow(j);
|
|
if (pRow != NULL)
|
|
{
|
|
(*pRow)[1].SetText(LPCTSTR(str));
|
|
double dAngle = d;
|
|
CString sTemp;
|
|
if (fabs(dAngle-PI/2)<1.0E-6)
|
|
sTemp=_T("无");
|
|
else
|
|
sTemp.Format(_T("%.1f%%"), tan(dAngle)*100);
|
|
(*pRow)[2].SetText(sTemp);
|
|
pRow->Refresh();
|
|
}
|
|
}
|
|
m_grid.SetModify(TRUE);
|
|
}
|
|
}
|
|
void CSlopeRoofDlg::OnButtonApp()
|
|
{
|
|
UpdateData();
|
|
for (int i = 0;i < m_RoofData.GetEdgeNum();i++)
|
|
{
|
|
CString str;
|
|
TString tstr = m_grid.GetCell(i,1).GetText();
|
|
#ifdef _UNICODE
|
|
str = (const wchar_t*)tstr;
|
|
#else
|
|
str = (const char*)tstr;
|
|
#endif
|
|
double d = _tstof(LPCTSTR(str));
|
|
d = (d * PI)/180.0;
|
|
m_RoofData.SetSlopeAngle(i,d);
|
|
}
|
|
if (m_pRoof->upgradeOpen()!=Acad::eOk)
|
|
return ;
|
|
m_pRoof->assertWriteEnabled();
|
|
m_RoofData.SetElevation(m_dElveMove);
|
|
*(TSlopeRoof *)m_pRoof = m_RoofData;
|
|
m_pRoof->downgradeOpen();
|
|
m_pRoof->draw();
|
|
ads_redraw(NULL,NULL);
|
|
}
|
|
void CSlopeRoofDlg::OnLButtonDown(UINT nFlags, CPoint point)
|
|
{
|
|
// TODO: Add your message handler code here and/or call default
|
|
if (nFlags == IDC_LIST)
|
|
{
|
|
XScreenDc dc(1,0);
|
|
double nApture=GetPickBoxWcs();
|
|
ads_redraw(NULL,NULL);
|
|
int nCurIndex = m_grid.m_CurRow;
|
|
XCurveSegment seg;
|
|
m_RoofData.GetOutlinePoly().Nth(nCurIndex, seg);
|
|
XPoint pt=seg.MidPoint();
|
|
|
|
// 问题描述:UCS下画红框的位置不正确
|
|
// 修改方法:对获取的点进行WCS到UCS的转换
|
|
// 修改人,修改时间:Zyu modify on 100324
|
|
pt = Wcs2Ucs(pt);
|
|
|
|
XRectAngle box1(pt, nApture*2, nApture*2);
|
|
dc<<box1;
|
|
acedUpdateDisplay();
|
|
m_CurIndex = nCurIndex;
|
|
}
|
|
}
|
|
void CSlopeRoofDlg::OnOK()
|
|
{
|
|
OnButtonApp();
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
// 当前行发生改变时,显示当前实体
|
|
|
|
// Command:编辑屋顶
|
|
int EditSlopeRoof(AcDbObjectId id)
|
|
{
|
|
XDbObject obj(id,AcDb::kForRead);
|
|
TDbSlopeRoof *pRoof;
|
|
if (!!obj)
|
|
pRoof = TDbSlopeRoof::cast(obj.m_pObject);
|
|
if (!pRoof)
|
|
return RTERROR;
|
|
CAcModuleResourceOverride vTemp;
|
|
CWnd *pWnd = acedGetAcadFrame();
|
|
CSlopeRoofDlg dlg(*pRoof,pRoof,0, pWnd);
|
|
// Zyu modify on 100722,支持64位
|
|
//int n = dlg.DoModal();
|
|
INT_PTR n = dlg.DoModal();
|
|
if (n ==IDOK)
|
|
{
|
|
if (pRoof->upgradeOpen()!=Acad::eOk)
|
|
return RTERROR;
|
|
pRoof->assertWriteEnabled();
|
|
*(TSlopeRoof *)pRoof = dlg.m_RoofData;
|
|
pRoof->downgradeOpen();
|
|
pRoof->Close();
|
|
ads_redraw(NULL,NULL);
|
|
}
|
|
else
|
|
pRoof->Close();
|
|
return RTNORM;
|
|
}
|