283 lines
7.0 KiB
C++
283 lines
7.0 KiB
C++
#include "stdafx.h"
|
|
#include <map>
|
|
#include "ModifyDimDlg.h"
|
|
#include "PickEntSet.h"
|
|
#include "globalfunc.h"
|
|
#include "globalDefine.h"
|
|
#include "AcDbObjectPtr.h"
|
|
#include "AecDbEwPipeDim.h"
|
|
#include "AecDbSymbWithText.h"
|
|
#include "AecDbDrawingName.h"
|
|
#include "AecDbSymbDrawingIndex.h"
|
|
#include "aecdbsymbindexpointer.h"
|
|
#include "AecDbSymbSection.h"
|
|
|
|
namespace
|
|
{
|
|
void GetAllTextStyleRcd(std::map<AcDbObjectId, CString> &ts)
|
|
{
|
|
AcDbTextStyleTable *pTextStyleTbl = NULL;
|
|
AcDbTextStyleTableRecord *pTextStyleTblRec = NULL;
|
|
if (acdbHostApplicationServices()->workingDatabase() \
|
|
->getTextStyleTable(pTextStyleTbl, AcDb::kForRead) == Acad::eOk)
|
|
{
|
|
// 文字样式表记录
|
|
AcDbTextStyleTableIterator *pIterator = NULL;
|
|
if (pTextStyleTbl->newIterator(pIterator) == Acad::eOk)
|
|
{
|
|
for (pIterator->start(); !pIterator->done(); pIterator->step())
|
|
{
|
|
if (pIterator->getRecord(pTextStyleTblRec, AcDb::kForRead) == Acad::eOk)
|
|
{
|
|
LPCTSTR pszName = NULL;
|
|
pTextStyleTblRec->getName(pszName);
|
|
ts.insert(std::make_pair(pTextStyleTblRec->id(), pszName));
|
|
pTextStyleTblRec->close();
|
|
}
|
|
}
|
|
delete pIterator;
|
|
}
|
|
pTextStyleTbl->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
IMPLEMENT_DYNAMIC(CModifyDimDlg, CDialog)
|
|
|
|
CModifyDimDlg::CModifyDimDlg(CWnd* pParent)
|
|
: CDialog(IDD_MODIFY_DIM_DLG, pParent)
|
|
, m_bChkScale(FALSE)
|
|
, m_bChkUpStyle(FALSE)
|
|
, m_bChkDnStyle(FALSE)
|
|
, m_bChkUpHeight(FALSE)
|
|
, m_bChkDnHeight(FALSE)
|
|
, m_iNumerator(1)
|
|
, m_iDenominator(100)
|
|
, m_sUpHeight(_T("3.0"))
|
|
, m_sDnHeight(_T("3.0"))
|
|
, m_iUpStyle(0)
|
|
, m_iDnStyle(0)
|
|
{
|
|
|
|
}
|
|
|
|
CModifyDimDlg::~CModifyDimDlg()
|
|
{
|
|
}
|
|
|
|
void CModifyDimDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Check(pDX, IDC_CHK_SCALE, m_bChkScale);
|
|
DDX_Check(pDX, IDC_CHK_UP_STYLE, m_bChkUpStyle);
|
|
DDX_Check(pDX, IDC_CHK_DN_STYLE, m_bChkDnStyle);
|
|
DDX_Check(pDX, IDC_CHK_UP_HEIGHT, m_bChkUpHeight);
|
|
DDX_Check(pDX, IDC_CHK_DN_HEIGHT, m_bChkDnHeight);
|
|
DDX_Text(pDX, IDC_EDT_NUMERATOR, m_iNumerator);
|
|
DDV_MinMaxInt(pDX, m_iNumerator, 1, 100);
|
|
DDX_Text(pDX, IDC_EDT_DENOMINATOR, m_iDenominator);
|
|
DDV_MinMaxInt(pDX, m_iDenominator, 1, INT_MAX);
|
|
DDX_CBString(pDX, IDC_CMB_UP_HEIGHT, m_sUpHeight);
|
|
DDX_CBString(pDX, IDC_CMB_DN_HEIGHT, m_sDnHeight);
|
|
DDX_CBIndex(pDX, IDC_CMB_UP_STYLE, m_iUpStyle);
|
|
DDX_CBIndex(pDX, IDC_CMB_DN_STYLE, m_iDnStyle);
|
|
}
|
|
|
|
BOOL CModifyDimDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
std::map<AcDbObjectId, CString> rcds;
|
|
GetAllTextStyleRcd(rcds);
|
|
CComboBox *pBox1((CComboBox*)GetDlgItem(IDC_CMB_UP_STYLE));
|
|
CComboBox *pBox2((CComboBox*)GetDlgItem(IDC_CMB_DN_STYLE));
|
|
for (std::map<AcDbObjectId, CString>::const_iterator it(rcds.begin());
|
|
it != rcds.end();
|
|
++it)
|
|
{
|
|
pBox1->SetItemData(pBox1->AddString(it->second), it->first.asOldId());
|
|
pBox2->SetItemData(pBox2->AddString(it->second), it->first.asOldId());
|
|
}
|
|
|
|
UpdateData(FALSE);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CModifyDimDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CModifyDimDlg::OnBnClickedOk)
|
|
ON_WM_CTLCOLOR()
|
|
END_MESSAGE_MAP()
|
|
|
|
AcDbObjectId CModifyDimDlg::getStyleId(const int &cid, const int &idx) const
|
|
{
|
|
AcDbObjectId id(AcDbObjectId::kNull);
|
|
CComboBox *p((CComboBox*)GetDlgItem(cid));
|
|
if (p && idx != -1)
|
|
id.setFromOldId(p->GetItemData(idx));
|
|
return id;
|
|
}
|
|
|
|
void CModifyDimDlg::OnBnClickedOk()
|
|
{
|
|
if (!UpdateData(TRUE)) return;
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
AcDbObjectId CModifyDimDlg::getUpStyle() const
|
|
{
|
|
return getStyleId(IDC_CMB_UP_STYLE, m_iUpStyle);
|
|
}
|
|
|
|
AcDbObjectId CModifyDimDlg::getDnStyle() const
|
|
{
|
|
return getStyleId(IDC_CMB_DN_STYLE, m_iDnStyle);
|
|
}
|
|
|
|
double CModifyDimDlg::getScale() const
|
|
{
|
|
return (double)m_iNumerator / m_iDenominator;
|
|
}
|
|
|
|
double CModifyDimDlg::getUpHeight() const
|
|
{
|
|
return TypeConvert::s2f(m_sUpHeight);
|
|
}
|
|
|
|
double CModifyDimDlg::getDnHeight() const
|
|
{
|
|
return TypeConvert::s2f(m_sDnHeight);
|
|
}
|
|
|
|
void CModifyDimDlg::start()
|
|
{
|
|
RBList rbMaskDim(RTDXF0, _T("AEC_*"), NULL);
|
|
PickEntSet ss(SS_FREE);
|
|
if (GlobalFunc::SelectEntities(_T("\n请选择要修改的标注:"), ss, rbMaskDim) != RTNORM) return;
|
|
|
|
CTemporaryResourceOverride vTemp;
|
|
CModifyDimDlg dlg;
|
|
if (dlg.DoModal() != IDOK) return;
|
|
double dScale(1. / dlg.getScale());
|
|
AcDbObjectId idUp(dlg.getUpStyle()), idDn(dlg.getDnStyle());
|
|
double dUp(dlg.getUpHeight()), dDn(dlg.getDnHeight());
|
|
|
|
AcDbObjectId id;
|
|
Adesk::Int32 len = ss.Length();
|
|
for (int i(0); i < len; ++i)
|
|
{
|
|
if (acdbGetObjectId(id, ss[i]) != Acad::eOk) continue;
|
|
|
|
AcDbEntityPointer ent(id, AcDb::kForWrite);
|
|
if (ent.openStatus() != Acad::eOk) continue;
|
|
|
|
AecDbEwPipeDim *pPipeDim = AecDbEwPipeDim::cast(ent);
|
|
if (pPipeDim)
|
|
{
|
|
if (dlg.ChkScale()) pPipeDim->SetPScale(dScale);
|
|
if (dlg.ChkUpStyle()) pPipeDim->SetTextStyleId(idUp);
|
|
if (dlg.ChkUpHeight()) pPipeDim->SetTextHeight(dUp);
|
|
continue;
|
|
}
|
|
|
|
AecXDbDrawingName *pDN = AecXDbDrawingName::cast(ent);
|
|
if (pDN)
|
|
{
|
|
if (dlg.ChkScale()) pDN->SetPScale(dScale);
|
|
if (dlg.ChkUpStyle()) pDN->SetNameStyleId(idUp);
|
|
if (dlg.ChkUpHeight()) pDN->SetNameHeight(dUp);
|
|
if (dlg.ChkDnStyle()) pDN->SetScaleStyleId(idDn);
|
|
if (dlg.ChkDnHeight()) pDN->SetScaleHeight(dDn);
|
|
pDN->Clean2DBuffer();
|
|
continue;
|
|
}
|
|
|
|
AecXDbCurveBaseEx *pCurveBase = AecXDbCurveBaseEx::cast(ent);
|
|
AecXDbEntityBaseEx *pEntBase = AecXDbEntityBaseEx::cast(ent);
|
|
|
|
if (dlg.ChkScale())
|
|
{
|
|
if (pCurveBase)
|
|
{
|
|
pCurveBase->SetPScale(dScale);
|
|
pCurveBase->Clean2DBuffer();
|
|
}
|
|
|
|
if (pEntBase)
|
|
{
|
|
pEntBase->SetPScale(dScale);
|
|
pEntBase->Clean2DBuffer();
|
|
}
|
|
}
|
|
|
|
AecXDbSymbWithText *pText = AecXDbSymbWithText::cast(ent);
|
|
// 派生于AecXDbSymbWithText
|
|
if (dlg.ChkUpStyle())
|
|
{
|
|
if (pText)
|
|
pText->SetTextStyleId(idUp);
|
|
}
|
|
|
|
if (dlg.ChkUpHeight())
|
|
{
|
|
if (pText)
|
|
pText->SetTextHeight(dUp);
|
|
}
|
|
|
|
|
|
if (dlg.ChkDnStyle())
|
|
{
|
|
AecXDbSymbDrawingIndex *pSDI = AecXDbSymbDrawingIndex::cast(ent);
|
|
if (pSDI)
|
|
pSDI->SetScaleStyleId(idDn);
|
|
|
|
AecXDbSymbIndexPointer *pSIP = AecXDbSymbIndexPointer::cast(ent);
|
|
if (pSIP)
|
|
pSIP->SetDimTextStyle(idDn);
|
|
|
|
AecXDbSymbSection *pSS = AecXDbSymbSection::cast(ent);
|
|
if (pSS)
|
|
pSS->SetIndexStyleId(idDn);
|
|
}
|
|
|
|
|
|
if (dlg.ChkDnHeight())
|
|
{
|
|
// AecXDbSymbIndexPointer 只有一个字高
|
|
|
|
AecXDbSymbDrawingIndex *pSDI = AecXDbSymbDrawingIndex::cast(ent);
|
|
if (pSDI)
|
|
pSDI->SetScaleTextHeight(dDn);
|
|
|
|
AecXDbSymbSection *pSS = AecXDbSymbSection::cast(ent);
|
|
if (pSS)
|
|
pSS->SetIndexHeight(dDn);
|
|
}
|
|
|
|
if (pCurveBase)
|
|
pCurveBase->Clean2DBuffer();
|
|
if (pEntBase)
|
|
pEntBase->Clean2DBuffer();
|
|
}
|
|
}
|
|
|
|
#define ENABLE_WINDOW(idChk, id) \
|
|
if (pWnd->GetDlgCtrlID() == ##idChk)\
|
|
{\
|
|
CWnd *pW(GetDlgItem(##id));\
|
|
if (pW) pW->EnableWindow(((CButton*)pWnd)->GetCheck());\
|
|
}
|
|
|
|
HBRUSH CModifyDimDlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
|
|
{
|
|
ENABLE_WINDOW(IDC_CHK_UP_STYLE, IDC_CMB_UP_STYLE);
|
|
ENABLE_WINDOW(IDC_CHK_DN_STYLE, IDC_CMB_DN_STYLE);
|
|
ENABLE_WINDOW(IDC_CHK_UP_HEIGHT, IDC_CMB_UP_HEIGHT);
|
|
ENABLE_WINDOW(IDC_CHK_DN_HEIGHT, IDC_CMB_DN_HEIGHT);
|
|
ENABLE_WINDOW(IDC_CHK_SCALE, IDC_EDT_NUMERATOR);
|
|
ENABLE_WINDOW(IDC_CHK_SCALE, IDC_EDT_DENOMINATOR);
|
|
|
|
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
return hbr;
|
|
}
|