306 lines
6.8 KiB
C++
306 lines
6.8 KiB
C++
#include "stdafx.h"
|
|
#include "PingFaDimDlg.h"
|
|
#include "AecDbColumn.h"
|
|
#include "AecDbBeam.h"
|
|
#include "AecDbPingFaDim.h"
|
|
#include "coretools.h"
|
|
#include "KTCadUtility.h"
|
|
|
|
DLLIMPEXP bool GetDoubleClickEnt(LPCTSTR pszCmd,AcDbObjectId& id);
|
|
|
|
IMPLEMENT_DYNAMIC(CPingFaDimDlg, CDialog)
|
|
|
|
CPingFaDimDlg::CPingFaDimDlg(CWnd *pParent)
|
|
: CDialog(IDD_PINGFA_DLG, pParent)
|
|
, m_dHeight(2.5)
|
|
, m_idStyle(AcDbObjectId::kNull)
|
|
, m_sTexts(_T(""))
|
|
, m_idxStyle(0)
|
|
{
|
|
GET_CACHE(CPingFaDimDlg, %f%d, &m_dHeight, &m_idxStyle);
|
|
}
|
|
|
|
CPingFaDimDlg::~CPingFaDimDlg()
|
|
{
|
|
}
|
|
|
|
void CPingFaDimDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Text(pDX, IDC_EDIT_HEIGHT, m_dHeight);
|
|
DDX_CBIndex(pDX, IDC_COMBO_STYLE, m_idxStyle);
|
|
DDX_Control(pDX, IDC_COMBO_STYLE, m_cmbStyle);
|
|
DDX_Control(pDX, IDC_TEXTS, m_cedtTexts);
|
|
}
|
|
|
|
BOOL CPingFaDimDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
m_cedtTexts.SetWindowText(m_sTexts);
|
|
initTextStyle();
|
|
UpdateData(FALSE);
|
|
if (m_idStyle.isValid()) // 说明是双击操作
|
|
{
|
|
AcDbTextStyleTableRecordPointer rec(m_idStyle, AcDb::kForRead);
|
|
if (rec.openStatus() == Acad::eOk)
|
|
{
|
|
AcString s;
|
|
rec->getName(s);
|
|
int idx = m_cmbStyle.FindString(0, s);
|
|
if (idx != -1)
|
|
m_cmbStyle.SetCurSel(idx);
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CPingFaDimDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CPingFaDimDlg::OnBnClickedOk)
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
void CPingFaDimDlg::OnBnClickedOk()
|
|
{
|
|
if (!UpdateData()) return;
|
|
|
|
SET_CACHE(CPingFaDimDlg, %f%d, m_dHeight, m_idxStyle);
|
|
|
|
m_sTexts = getTexts();
|
|
int idx = m_cmbStyle.GetCurSel();
|
|
if (idx != -1)
|
|
m_idStyle.setFromOldId(m_cmbStyle.GetItemData(idx));
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void CPingFaDimDlg::initTextStyle()
|
|
{
|
|
AcDbTextStyleTablePointer textStyleTable(acdbCurDwg(), AcDb::kForRead);
|
|
if (textStyleTable.openStatus() != Acad::eOk) return;
|
|
|
|
AcDbTextStyleTableIterator *pIter(NULL);
|
|
textStyleTable->newIterator(pIter);
|
|
if (!pIter) return;
|
|
|
|
m_cmbStyle.ResetContent();
|
|
|
|
int idx(-1);
|
|
AcDbObjectId id;
|
|
AcString sName(_T(""));
|
|
for (; !pIter->done(); pIter->step())
|
|
{
|
|
if (pIter->getRecordId(id) != Acad::eOk) continue;
|
|
|
|
AcDbTextStyleTableRecordPointer pointer(id, AcDb::kForRead);
|
|
if (pointer.openStatus() != Acad::eOk) continue;
|
|
|
|
pointer->getName(sName);
|
|
if (sName.isEmpty()) continue;
|
|
idx = m_cmbStyle.AddString(sName);
|
|
if (idx != -1)
|
|
m_cmbStyle.SetItemData(idx, id.asOldId());
|
|
}
|
|
|
|
m_cmbStyle.SetCurSel(0);
|
|
|
|
delete pIter;
|
|
}
|
|
|
|
AcDbObjectId CPingFaDimDlg::getTextStyle()
|
|
{
|
|
int idx = m_cmbStyle.GetCurSel();
|
|
if (idx == -1) return AcDbObjectId::kNull;
|
|
|
|
AcDbObjectId id;
|
|
id.setFromOldId(m_cmbStyle.GetItemData(idx));
|
|
|
|
return id;
|
|
}
|
|
|
|
void CPingFaDimDlg::getTexts(AcArray<CString> &texts)
|
|
{
|
|
texts.removeAll();
|
|
CString str;
|
|
int cnt;
|
|
for (int i(0); m_cedtTexts.GetLineCount(); ++i)
|
|
{
|
|
cnt = m_cedtTexts.LineLength(i);
|
|
m_cedtTexts.GetLine(i, str.GetBuffer(cnt));
|
|
str.ReleaseBuffer(cnt);
|
|
texts.append(str);
|
|
}
|
|
}
|
|
|
|
CString CPingFaDimDlg::getTexts()
|
|
{
|
|
CString s;
|
|
m_cedtTexts.GetWindowText(s);
|
|
return s;
|
|
}
|
|
|
|
namespace
|
|
{
|
|
CString getColumnData(const AcGePoint3d &pt, const ColumnParam ¶m)
|
|
{
|
|
CString sAll, str = _T("柱子");
|
|
// 只处理方圆
|
|
if (param.m_nShape == 0)
|
|
{
|
|
str.Format(_T("柱子 %.2f X %.2f\r\n"), param.m_dXScale, param.m_dYScale);
|
|
}
|
|
else if (param.m_nShape == 1)
|
|
{
|
|
str.Format(_T("柱子 %.2f\r\n"), param.m_dXScale);
|
|
}
|
|
sAll += str;
|
|
str.Format(_T("柱顶标高%.2f"), param.m_dBomEl + param.m_dH);
|
|
sAll += str;
|
|
return sAll;
|
|
}
|
|
|
|
CString getBeamData(const AcGePoint3d &pt, const ColumnParam ¶m)
|
|
{
|
|
|
|
CString sAll, str = _T("梁");
|
|
// 只处理方圆
|
|
if (param.m_nShape == 0)
|
|
{
|
|
str.Format(_T("梁 %.2f X %.2f\r\n"), param.m_dXScale, param.m_dYScale);
|
|
}
|
|
else if (param.m_nShape == 1)
|
|
{
|
|
str.Format(_T("梁 %.2f\r\n"), param.m_dXScale);
|
|
}
|
|
sAll += str;
|
|
str.Format(_T("梁顶标高%.2f"), param.m_dBomEl);
|
|
sAll += str;
|
|
return sAll;
|
|
}
|
|
}
|
|
|
|
void inertPingFaDim()
|
|
{
|
|
ads_point adspt;
|
|
ads_name ent;
|
|
struct resbuf* pRb = acutBuildList(RTDXF0, _T("AEC_DBCOLMN,AEC_DBBEAM,LINE"), 0);
|
|
if (CKTCadUtility::SelectEntity(_T("\n选择梁实体或柱实体:"), ent, pRb, adspt) != RTNORM) return;
|
|
acutRelRb(pRb);
|
|
|
|
AcDbObjectId id;
|
|
acdbGetObjectId(id, ent);
|
|
if (!id.isValid()) return;
|
|
|
|
AcDbEntityPointer entPtr(id, AcDb::kForRead);
|
|
if (entPtr.openStatus() != Acad::eOk) return;
|
|
|
|
AcGePoint3d pt1(AcGePoint3d::kOrigin);
|
|
|
|
CString str(_T("")), sAll;
|
|
|
|
AcDbLine *pLine = AcDbLine::cast(entPtr);
|
|
AecDbColumn *pColu = AecDbColumn::cast(entPtr);
|
|
AecDbBeam *pBeam = AecDbBeam::cast(entPtr);
|
|
ColumnParam col;
|
|
::memset(&col, 0, sizeof(ColumnParam));
|
|
if (pLine)
|
|
{
|
|
pt1 = CoreTools::MidPt(pLine->startPoint(), pLine->endPoint());
|
|
AecDbObjXDataMap xData;
|
|
if (!xData.Read(pLine, _T("BIMDATA"))) return;
|
|
CString sName(_T(""));
|
|
if (!xData.GetAt(_T("NAME"), sName)) return;
|
|
if (sName == _T("柱"))
|
|
{
|
|
xData.GetAt(KEY_XS, col.m_dXScale);
|
|
xData.GetAt(KEY_YS, col.m_dYScale);
|
|
xData.GetAt(KEY_SHAPE, col.m_nShape);
|
|
xData.GetAt(KEY_B, col.m_dBomEl);
|
|
xData.GetAt(KEY_H, col.m_dH);
|
|
sAll = getColumnData(pt1, col);
|
|
}
|
|
else if (sName == _T("梁"))
|
|
{
|
|
xData.GetAt(KEY_XS, col.m_dXScale);
|
|
xData.GetAt(KEY_YS, col.m_dYScale);
|
|
xData.GetAt(KEY_SHAPE, col.m_nShape);
|
|
xData.GetAt(KEY_B, col.m_dBomEl);
|
|
xData.GetAt(KEY_H, col.m_dH);
|
|
sAll = getBeamData(pt1, col);
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
else if (pColu)
|
|
{
|
|
pColu->GetColumnData(col);
|
|
pt1 = pColu->GetPosition();
|
|
pt1.z = .0;
|
|
sAll = getColumnData(pt1, col);
|
|
}
|
|
else if (pBeam)
|
|
{
|
|
pt1 = asPnt3d(adspt);
|
|
pBeam->GetBeamData(col);
|
|
CoreTools::UCS2WCS(pt1, pt1);
|
|
AcDbCurve *pCurve = pBeam->GetBaseCurve();
|
|
if (pCurve)
|
|
{
|
|
pCurve->getClosestPointTo(pt1, pt1);
|
|
DELETE_PTR(pCurve);
|
|
}
|
|
pt1.z = .0;
|
|
|
|
sAll = getBeamData(pt1, col);
|
|
}
|
|
else
|
|
return;
|
|
|
|
CAcModuleResourceOverride myResources;
|
|
CPingFaDimDlg dlg;
|
|
dlg.m_sTexts = sAll;
|
|
|
|
if (dlg.DoModal() != IDOK) return;
|
|
|
|
AecDbPingFaDim *pDim(new AecDbPingFaDim);
|
|
pDim->SetStartPoint(pt1);
|
|
pDim->SetAllText(dlg.m_sTexts);
|
|
pDim->SetTextHeight(dlg.m_dHeight);
|
|
pDim->SetTextStyle(dlg.m_idStyle);
|
|
|
|
CPingFaDimJig jig;
|
|
jig.m_pEnt = pDim;
|
|
jig.m_pt1 = pt1;
|
|
if (pBeam)
|
|
jig.m_pBeamCurve = pBeam;
|
|
jig.DoIt();
|
|
|
|
CoreTools::AddToModelSpace(pDim);
|
|
}
|
|
|
|
void DBL_AEC_PFDIM()
|
|
{
|
|
AcDbObjectId id;
|
|
bool bIsOk = GetDoubleClickEnt(_T("DBL_AEC_PFDIM"), id);
|
|
|
|
if (!bIsOk || !id.isValid()) return;
|
|
|
|
AcDbObjectPointer<AecDbPingFaDim> ent(id, AcDb::kForWrite);
|
|
if (ent.openStatus() != Acad::eOk) return;
|
|
|
|
CString sAll = ent->GetAllText();
|
|
double dTextH = ent->GetTextHeight();
|
|
AcDbObjectId idStyle = ent->GetTextStyle();
|
|
|
|
CAcModuleResourceOverride myResources;
|
|
CPingFaDimDlg dlg;
|
|
dlg.m_sTexts = sAll;
|
|
dlg.m_dHeight = dTextH;
|
|
dlg.m_idStyle = idStyle;
|
|
if (dlg.DoModal() != IDOK) return;
|
|
|
|
ent->SetAllText(dlg.m_sTexts);
|
|
ent->SetTextHeight(dlg.m_dHeight);
|
|
ent->SetTextStyle(dlg.getTextStyle());
|
|
}
|