254 lines
5.3 KiB
C++
254 lines
5.3 KiB
C++
#include "stdafx.h"
|
|
#include "DictionaryViewerDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
#define MAXITEMS 100
|
|
#define PROMPT_DEL_NAME _T("ACAD_SCALELIST")
|
|
|
|
CDictionaryViewerDlg::CDictionaryViewerDlg(AcDbDatabase* pDb, LPCTSTR pszTitle, CWnd* pParent)
|
|
: CDialog(CDictionaryViewerDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CDictionaryViewerDlg)
|
|
m_sTitle = pszTitle;
|
|
m_pDb = pDb;
|
|
//}}AFX_DATA_INIT
|
|
}
|
|
|
|
|
|
void CDictionaryViewerDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CDictionaryViewerDlg)
|
|
DDX_Control(pDX, IDC_TREE_DICT, m_wndTreeCtrl);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CDictionaryViewerDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CDictionaryViewerDlg)
|
|
ON_BN_CLICKED(IDC_REMOVE, OnRemove)
|
|
ON_NOTIFY(TVN_KEYDOWN, IDC_TREE_DICT, OnKeydownTreeDict)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
void CDictionaryViewerDlg::OnRemove()
|
|
{
|
|
HTREEITEM hSelItem = m_wndTreeCtrl.GetSelectedItem();
|
|
if (hSelItem == NULL)
|
|
{
|
|
AfxMessageBox(_T("请选择要删除的字典名!"));
|
|
return;
|
|
}
|
|
|
|
CString sItemName = m_wndTreeCtrl.GetItemText(hSelItem);
|
|
sItemName.MakeUpper();
|
|
if (m_lstForbid.Find(sItemName) != NULL)
|
|
{
|
|
CString sTip;
|
|
sTip.Format(_T("禁止删除\"%s\"?"), sItemName);
|
|
AfxMessageBox(sTip);
|
|
return;
|
|
}
|
|
|
|
CString sTip;
|
|
sTip.Format(_T("是否确定删除\"%s\"?"), sItemName);
|
|
if (AfxMessageBox(sTip, MB_YESNO | MB_ICONQUESTION) == IDYES)
|
|
{
|
|
if (m_pDb != NULL)
|
|
{
|
|
AcDbDictionary* pRootDict = NULL;
|
|
if (m_pDb->getNamedObjectsDictionary(pRootDict, AcDb::kForWrite) == Acad::eOk)
|
|
{
|
|
if(pRootDict->has(sItemName))
|
|
{
|
|
pRootDict->remove(sItemName);
|
|
}
|
|
|
|
pRootDict->close();
|
|
|
|
m_wndTreeCtrl.DeleteItem(hSelItem);
|
|
}
|
|
else
|
|
{
|
|
AfxMessageBox(_T("删除失败!"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
BOOL CDictionaryViewerDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
m_lstForbid.AddTail(_T("ATS_DBCONFIG"));
|
|
m_lstForbid.AddTail(_T("TCH_DBPSCONFIG"));
|
|
|
|
SetWindowText(m_sTitle);
|
|
|
|
RemoveRedundancyDic();
|
|
|
|
// 初始化字典树
|
|
InitDictionaryTree();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CDictionaryViewerDlg::RemoveRedundancyDic()
|
|
{
|
|
if (m_pDb != NULL)
|
|
{
|
|
AcDbLayerTable *pLayertable = NULL;
|
|
m_pDb->getLayerTable(pLayertable, AcDb::kForRead);
|
|
if (pLayertable != NULL)
|
|
{
|
|
AcDbObjectId idExtDict = pLayertable->extensionDictionary();
|
|
if(idExtDict.isValid())
|
|
{
|
|
OPENOBJ_BEGIN(idExtDict, AcDb::kForWrite, AcDbDictionary, pDict);
|
|
if(pDict != NULL)
|
|
{
|
|
if(pDict->has(_T("ACAD_LAYERFILTERS")))
|
|
{
|
|
adsout<<_T("已经成功删除多余扩展字典:ACAD_LAYERFILTERS!\n");
|
|
pDict->remove(_T("ACAD_LAYERFILTERS"));
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
pLayertable->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
void CDictionaryViewerDlg::InitDictionaryTree()
|
|
{
|
|
HTREEITEM rootItem;
|
|
|
|
rootItem = AddTreeItem(_T("Root Dictionary"), TVI_ROOT);
|
|
|
|
if (m_pDb != NULL)
|
|
{
|
|
AcDbObjectId idDic = m_pDb->namedObjectsDictionaryId();
|
|
AddDictionary(idDic, rootItem);
|
|
}
|
|
|
|
HighlightItem(PROMPT_DEL_NAME);
|
|
|
|
m_wndTreeCtrl.Expand(m_wndTreeCtrl.GetRootItem(), TVE_EXPAND);
|
|
}
|
|
|
|
void CDictionaryViewerDlg::HighlightItem(LPCTSTR pszItemText)
|
|
{
|
|
HTREEITEM hItem;
|
|
if (GetItemByString(pszItemText, hItem))
|
|
{
|
|
if (m_wndTreeCtrl.ItemHasChildren(hItem))
|
|
{
|
|
UINT nCount = 0;
|
|
HTREEITEM hNextItem;
|
|
HTREEITEM hChildItem = m_wndTreeCtrl.GetChildItem(hItem);
|
|
while (hChildItem != NULL)
|
|
{
|
|
hNextItem = m_wndTreeCtrl.GetNextItem(hChildItem, TVGN_NEXT);
|
|
hChildItem = hNextItem;
|
|
|
|
if (++nCount > MAXITEMS)
|
|
{
|
|
m_wndTreeCtrl.SelectItem(hItem);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
hItem = m_wndTreeCtrl.GetRootItem();
|
|
if (hItem != NULL)
|
|
{
|
|
m_wndTreeCtrl.SelectItem(hItem);
|
|
}
|
|
}
|
|
|
|
BOOL CDictionaryViewerDlg::GetItemByString(LPCTSTR pszName, HTREEITEM& hDecItem)
|
|
{
|
|
if (pszName == NULL)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
HTREEITEM hItem = m_wndTreeCtrl.GetRootItem();
|
|
hItem = m_wndTreeCtrl.GetChildItem(hItem);
|
|
CString strItemText;
|
|
while (hItem != NULL)
|
|
{
|
|
strItemText = m_wndTreeCtrl.GetItemText(hItem);
|
|
if (strItemText.CompareNoCase(pszName) == 0)
|
|
{
|
|
hDecItem = hItem;
|
|
return TRUE;
|
|
}
|
|
hItem = m_wndTreeCtrl.GetNextItem(hItem, TVGN_NEXT);
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
HTREEITEM CDictionaryViewerDlg::AddTreeItem(LPCTSTR pszName, HTREEITEM parent)
|
|
{
|
|
TV_INSERTSTRUCT tvInsert;
|
|
TV_ITEM tvItem;
|
|
|
|
tvItem.mask = TVIF_TEXT | TVIF_PARAM;
|
|
tvItem.pszText = const_cast<TCHAR*>(pszName);
|
|
tvItem.cchTextMax = (int)_tcslen(pszName);
|
|
|
|
tvInsert.item = tvItem;
|
|
tvInsert.hInsertAfter = TVI_LAST;
|
|
tvInsert.hParent = parent;
|
|
|
|
return m_wndTreeCtrl.InsertItem(&tvInsert);
|
|
}
|
|
|
|
void CDictionaryViewerDlg::AddDictionary(const AcDbObjectId& idDict, HTREEITEM parent)
|
|
{
|
|
if (idDict.isValid())
|
|
{
|
|
AcDbDictionary* pDic = NULL;
|
|
if (acdbOpenObject(pDic, idDict, AcDb::kForRead) == Acad::eOk)
|
|
{
|
|
AcDbDictionaryIterator* pDictIter = pDic->newIterator();
|
|
if (pDictIter != NULL)
|
|
{
|
|
HTREEITEM hCurItem;
|
|
|
|
for (pDictIter;!pDictIter->done();pDictIter->next())
|
|
{
|
|
hCurItem = AddTreeItem(pDictIter->name(), parent);
|
|
AddDictionary(pDictIter->objectId(), hCurItem);
|
|
}
|
|
|
|
delete pDictIter;
|
|
}
|
|
|
|
pDic->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
void CDictionaryViewerDlg::OnKeydownTreeDict(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*)pNMHDR;
|
|
|
|
if (pTVKeyDown->wVKey == VK_DELETE)
|
|
{
|
|
OnRemove();
|
|
}
|
|
|
|
*pResult = 0;
|
|
}
|