567 lines
13 KiB
C++
567 lines
13 KiB
C++
// SpaceNameClassDlg.cpp: implementation of the CSpaceNameClassDlg class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "SpaceNameClassDlg.h"
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
CStringArray CSpaceDataTable::m_arSKeyWord;
|
|
|
|
void CSpaceDataTable::InitKeyWords()
|
|
{
|
|
m_arSKeyWord.RemoveAll();
|
|
m_arSKeyWord.SetSize(eNum);
|
|
|
|
m_arSKeyWord[eRoom] = _T("室");
|
|
m_arSKeyWord[eHall] = _T("厅");
|
|
m_arSKeyWord[eToilet] = _T("卫");
|
|
m_arSKeyWord[eOther] = _T("其他");
|
|
}
|
|
|
|
void CSpaceDataTable::Clear(EKeyWord eKey)
|
|
{
|
|
for (int i = 0; i < eNum; i++)
|
|
{
|
|
if ((eKey == eNum) || (eKey = EKeyWord(i)))
|
|
{
|
|
NameAry(EKeyWord(i)).RemoveAll();
|
|
}
|
|
}
|
|
}
|
|
|
|
CString CSpaceDataTable::GetKeyName(EKeyWord eKey) const
|
|
{
|
|
return _T("[") + m_arSKeyWord[eKey] + _T("]");
|
|
}
|
|
|
|
CSpaceDataTable::EKeyWord CSpaceDataTable::GetNameType(CString sName) const
|
|
{
|
|
sName.TrimLeft();
|
|
sName.TrimRight();
|
|
|
|
for (int i = 0; i < eNum; i++)
|
|
{
|
|
const CStringArray &ary = NameAry(EKeyWord(i));
|
|
for (int ii = 0; ii < ary.GetSize(); ii++)
|
|
{
|
|
if (ary[ii].CompareNoCase(sName) == 0)
|
|
{
|
|
return EKeyWord(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
return eOther;
|
|
}
|
|
|
|
BOOL CSpaceDataTable::TestKeyWord(CString sKey)
|
|
{
|
|
sKey.TrimLeft();
|
|
sKey.TrimRight();
|
|
|
|
for (int i = 0; i < eNum; i++)
|
|
{
|
|
if (sKey.CompareNoCase( GetKeyName(EKeyWord(i))) == 0)
|
|
{
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
void CSpaceDataTable::SetNameAry(CString sKey, const CStringArray &arName)
|
|
{
|
|
SetNameAry(Key(sKey), arName);
|
|
}
|
|
|
|
void CSpaceDataTable::AppendNameAry(CString sKey, const CStringArray &arName)
|
|
{
|
|
AppendNameAry(Key(sKey), arName);
|
|
}
|
|
|
|
void CSpaceDataTable::SetNameAry(CSpaceDataTable::EKeyWord eKey, const CStringArray &arName)
|
|
{
|
|
CStringArray &ary = NameAry(eKey);
|
|
ary.RemoveAll();
|
|
ary.Append(arName);
|
|
}
|
|
|
|
void CSpaceDataTable::AppendNameAry(CSpaceDataTable::EKeyWord eKey, const CStringArray &arName)
|
|
{
|
|
NameAry(eKey).Append(arName);
|
|
}
|
|
|
|
void CSpaceDataTable::AddName(EKeyWord eKey, CString sName)
|
|
{
|
|
NameAry(eKey).Add(sName);
|
|
}
|
|
|
|
int CSpaceDataTable::GetNameAry(CSpaceDataTable::EKeyWord eKey, CStringArray &ary) const
|
|
{
|
|
ary.RemoveAll();
|
|
|
|
ary.Append(NameAry(eKey));
|
|
return (int)ary.GetSize();
|
|
}
|
|
|
|
const CStringArray& CSpaceDataTable::NameAry(CSpaceDataTable::EKeyWord eKey) const
|
|
{
|
|
return m_arNames[eKey];
|
|
}
|
|
|
|
CStringArray& CSpaceDataTable::NameAry(CSpaceDataTable::EKeyWord eKey)
|
|
{
|
|
return m_arNames[eKey];
|
|
}
|
|
|
|
CSpaceDataTable::EKeyWord CSpaceDataTable::Key(CString sName) const
|
|
{
|
|
sName.TrimLeft();
|
|
sName.TrimRight();
|
|
|
|
for (int i = 0; i < eNum; i++)
|
|
{
|
|
if (sName.CompareNoCase(GetKeyName(EKeyWord(i))) == 0)
|
|
{
|
|
return EKeyWord(i);
|
|
}
|
|
}
|
|
|
|
return eOther;
|
|
}
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
CSpaceFileOperator::CSpaceFileOperator(LPCTSTR szFileName)
|
|
: m_sFileName(szFileName)
|
|
{
|
|
ASSERT(m_sFileName != _T("") );
|
|
}
|
|
|
|
// = Function Name:SplitString
|
|
// = Description: 根据回车符拆分字符串sAllName,拆分结果保存在arSName中
|
|
// = Return: 拆分之后数组的个数
|
|
int CSpaceFileOperator::SplitString(CString sAllName, CStringArray &arSName)
|
|
{
|
|
arSName.RemoveAll();
|
|
|
|
while (TRUE)
|
|
{
|
|
CString sReturn = _T("\r\n");
|
|
int nIndex = sAllName.Find(sReturn);
|
|
if (nIndex < 0)
|
|
{ // 没找到
|
|
if (sAllName != _T(""))
|
|
arSName.Add(sAllName);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
CString sDump = sAllName.Mid(0, nIndex);
|
|
sAllName = sAllName.Mid(nIndex+2, sAllName.GetLength() - nIndex - 2);
|
|
if (sDump != _T(""))
|
|
arSName.Add(sDump);
|
|
}
|
|
}
|
|
|
|
return (int)arSName.GetSize();
|
|
}
|
|
|
|
BOOL CSpaceFileOperator::ReadFile(CSpaceDataTable &dataTable) const
|
|
{
|
|
CStdioFile txtFile;
|
|
UINT uLen = 0;
|
|
if (!txtFile.Open(m_sFileName, CFile::modeRead))
|
|
return FALSE;
|
|
|
|
dataTable.Clear();
|
|
|
|
// 每一个关键字的最大长度
|
|
CString sCurKey = _T(""), sCurrString = _T("");
|
|
CStringArray arSCurName;
|
|
|
|
// 概述:
|
|
while (txtFile.ReadString(sCurrString))
|
|
{
|
|
if (sCurrString == _T(""))
|
|
continue;
|
|
if (dataTable.TestKeyWord(sCurrString))
|
|
{// 检测到了新的关键字,原有的数据就需要先保存起来。
|
|
if (arSCurName.GetSize() > 0)
|
|
{
|
|
// 关键字匹配不了则添加到其他里面
|
|
dataTable.AppendNameAry(sCurKey, arSCurName);
|
|
arSCurName.RemoveAll();
|
|
}
|
|
// 设置新的关键字
|
|
sCurKey = sCurrString;
|
|
}
|
|
else
|
|
{
|
|
arSCurName.Add(sCurrString);
|
|
}
|
|
}
|
|
|
|
// 只要有,就需要添加!
|
|
if ( arSCurName.GetSize() > 0)
|
|
dataTable.AppendNameAry(sCurKey, arSCurName);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CSpaceFileOperator::WriteFile(const CSpaceDataTable &dataTable) const
|
|
{
|
|
CStdioFile txtFile;
|
|
UINT uLen = 0;
|
|
if (!txtFile.Open(m_sFileName, CFile::modeCreate | CFile::modeWrite))
|
|
return FALSE;
|
|
|
|
// 写入顺序:
|
|
// 厅,室,卫:其他
|
|
CString sKey;
|
|
CStringArray arSName;
|
|
|
|
sKey = dataTable.GetKeyName(CSpaceDataTable::eHall);
|
|
dataTable.GetNameAry(CSpaceDataTable::eHall, arSName);
|
|
Write(txtFile, sKey, arSName);
|
|
|
|
sKey = dataTable.GetKeyName(CSpaceDataTable::eRoom);
|
|
dataTable.GetNameAry(CSpaceDataTable::eRoom, arSName);
|
|
Write(txtFile, sKey, arSName);
|
|
|
|
sKey = dataTable.GetKeyName(CSpaceDataTable::eToilet);
|
|
dataTable.GetNameAry(CSpaceDataTable::eToilet, arSName);
|
|
Write(txtFile, sKey, arSName);
|
|
|
|
sKey = dataTable.GetKeyName(CSpaceDataTable::eOther);
|
|
dataTable.GetNameAry(CSpaceDataTable::eOther, arSName);
|
|
Write(txtFile, sKey, arSName);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CSpaceFileOperator::Write(CStdioFile &txtFile, CString sKey, CStringArray &arSName) const
|
|
{
|
|
CString sRet = _T("\n");
|
|
txtFile.WriteString(sKey);
|
|
txtFile.WriteString(sRet);
|
|
for (int i = 0; i < arSName.GetSize(); i++)
|
|
{
|
|
txtFile.WriteString(arSName[i]);
|
|
txtFile.WriteString(sRet);
|
|
}
|
|
}
|
|
|
|
// 获得房间名称文件中,指定类型的数据,返回数组长度
|
|
int CSpaceFileOperator::GetTypeNameAry(CSpaceDataTable::EKeyWord eNameType, CStringArray &arName) const
|
|
{
|
|
arName.RemoveAll();
|
|
|
|
CSpaceDataTable dataTable;
|
|
// Zyu add on 101119,初始化关键字数组
|
|
dataTable.InitKeyWords();
|
|
if (ReadFile(dataTable))
|
|
{
|
|
dataTable.GetNameAry(eNameType, arName);
|
|
}
|
|
|
|
return (int)arName.GetSize();
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
static CString s_sRet = _T("\r\n");
|
|
|
|
CSpaceNameClassDlg::CSpaceNameClassDlg(bool bHideParent, CWnd* pParent /*=NULL*/)
|
|
: CModelessDialog(CSpaceNameClassDlg::IDD, pParent),
|
|
m_uLstNum(CSpaceDataTable::eNum - 1),
|
|
m_bHideParent(bHideParent)
|
|
{
|
|
CSpaceDataTable::InitKeyWords();
|
|
|
|
CString csSysPath = g_sDwbPath;
|
|
csSysPath = csSysPath.Left(csSysPath.GetLength() - 5) + _T("\\sys\\");
|
|
|
|
// 因为该文件负有写入的责任,因此即使该文件不存在,也需要建立该指针
|
|
m_pFileBase = new CSpaceFileOperator(csSysPath + _T("spacenam.txt"));
|
|
}
|
|
|
|
CSpaceNameClassDlg::~CSpaceNameClassDlg()
|
|
{
|
|
if (m_pFileBase != NULL)
|
|
{
|
|
delete m_pFileBase;
|
|
m_pFileBase = NULL;
|
|
}
|
|
}
|
|
|
|
void CSpaceNameClassDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CModelessDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_TAB_NAME_CLASS, m_tab);
|
|
DDX_Control(pDX, IDC_EDIT_HALL, m_arList[CSpaceDataTable::eHall]);
|
|
DDX_Control(pDX, IDC_EDIT_ROOM, m_arList[CSpaceDataTable::eRoom]);
|
|
DDX_Control(pDX, IDC_EDIT_TOILET, m_arList[CSpaceDataTable::eToilet]);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CSpaceNameClassDlg, CModelessDialog)
|
|
ON_BN_CLICKED(IDC_BTN_QUERY, OnBnClickedBtnQuery)
|
|
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_NAME_CLASS, OnTcnSelchangeTabNameClass)
|
|
ON_BN_CLICKED(IDOK, OnBnClickedOk)
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CSpaceNameClassDlg::OnInitDialog()
|
|
{
|
|
CModelessDialog::OnInitDialog();
|
|
|
|
m_tab.InsertItem(0, _T("厅"));
|
|
m_tab.InsertItem(1, _T("室"));
|
|
m_tab.InsertItem(2, _T("卫"));
|
|
|
|
for (UINT i = 0; i < m_uLstNum; i++)
|
|
{
|
|
m_arList[i].SetFont(this->GetFont());
|
|
}
|
|
|
|
if ((m_pFileBase != NULL) && (m_pFileBase->ReadFile(m_dataTable)))
|
|
{
|
|
CStringArray arSName;
|
|
m_dataTable.GetNameAry(CSpaceDataTable::eToilet, arSName);
|
|
SetEditString(CSpaceDataTable::eToilet, arSName);
|
|
|
|
m_dataTable.GetNameAry(CSpaceDataTable::eHall, arSName);
|
|
SetEditString(CSpaceDataTable::eHall, arSName);
|
|
|
|
m_dataTable.GetNameAry(CSpaceDataTable::eRoom, arSName);
|
|
SetEditString(CSpaceDataTable::eRoom, arSName); // 这是加载
|
|
}
|
|
|
|
ShowEdit(CSpaceDataTable::eHall);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CSpaceNameClassDlg::SetEditString(CSpaceDataTable::EKeyWord eType, const CStringArray &ary)
|
|
{
|
|
CString sText;
|
|
for (int i = 0; i < ary.GetSize(); i++)
|
|
{
|
|
sText += ary[i];
|
|
sText += s_sRet;
|
|
}
|
|
|
|
m_arList[eType].SetWindowText(sText);
|
|
m_arList[eType].SetSel(sText.GetLength(), sText.GetLength(), FALSE);
|
|
}
|
|
|
|
int CSpaceNameClassDlg::GetEditString(CSpaceDataTable::EKeyWord eType, CStringArray &ary) const
|
|
{
|
|
if (m_pFileBase != NULL)
|
|
{
|
|
ary.RemoveAll();
|
|
|
|
CString sText;
|
|
m_arList[eType].GetWindowText(sText);
|
|
m_pFileBase->SplitString(sText, ary);
|
|
}
|
|
|
|
return (int)ary.GetSize();
|
|
}
|
|
|
|
void CSpaceNameClassDlg::ShowEdit(CSpaceDataTable::EKeyWord eIndex)
|
|
{
|
|
for (UINT i = 0; i < m_uLstNum; i++)
|
|
{
|
|
m_arList[i].ShowWindow(eIndex == i);
|
|
}
|
|
}
|
|
|
|
void CSpaceNameClassDlg::OnTcnSelchangeTabNameClass(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
*pResult = 0;
|
|
|
|
int nCurr = m_tab.GetCurSel();
|
|
|
|
ShowEdit(TabIndexToKey(nCurr));
|
|
}
|
|
|
|
CSpaceDataTable::EKeyWord CSpaceNameClassDlg::TabIndexToKey(int index) const
|
|
{
|
|
if (index == 0)
|
|
return CSpaceDataTable::eHall;
|
|
else if (index == 1)
|
|
return CSpaceDataTable::eRoom;
|
|
else if (index == 2)
|
|
return CSpaceDataTable::eToilet;
|
|
else
|
|
{
|
|
ASSERT(0);
|
|
return CSpaceDataTable::eHall;
|
|
}
|
|
}
|
|
|
|
int CSpaceNameClassDlg::GetTypeNameAry(CSpaceDataTable::EKeyWord eNameType, CStringArray &arName) const
|
|
{
|
|
return GetEditString(eNameType, arName);
|
|
}
|
|
|
|
void CSpaceNameClassDlg::AddStringToEdit(CSpaceDataTable::EKeyWord eIndex, CString sName)
|
|
{
|
|
CString sEdit;
|
|
m_arList[eIndex].GetWindowText(sEdit);
|
|
sEdit.TrimRight();
|
|
|
|
if (sEdit != _T(""))
|
|
sEdit += (s_sRet + sName);
|
|
else
|
|
sEdit = sName;
|
|
|
|
m_arList[eIndex].SetWindowText(sEdit);
|
|
m_arList[eIndex].SetSel(sEdit.GetLength(), sEdit.GetLength(), FALSE);
|
|
}
|
|
|
|
void CSpaceNameClassDlg::AddStringSToCurrEdit(CStringArray &sNames)
|
|
{
|
|
int nCurr = m_tab.GetCurSel();
|
|
CSpaceDataTable::EKeyWord eIndex = TabIndexToKey(nCurr);
|
|
|
|
CString sAdd;
|
|
for (int i = 0; i < sNames.GetSize(); i++)
|
|
{
|
|
sAdd += (sNames[i] + s_sRet);
|
|
}
|
|
|
|
AddStringToEdit(eIndex, sAdd);
|
|
}
|
|
|
|
// 写入数据,并且推出该命令
|
|
void CSpaceNameClassDlg::OnBnClickedOk()
|
|
{
|
|
if (m_pFileBase != NULL)
|
|
{
|
|
CStringArray arSName;
|
|
if (GetEditString(CSpaceDataTable::eRoom, arSName))
|
|
m_dataTable.SetNameAry(CSpaceDataTable::eRoom, arSName);
|
|
|
|
if (GetEditString(CSpaceDataTable::eHall, arSName))
|
|
m_dataTable.SetNameAry(CSpaceDataTable::eHall, arSName);
|
|
|
|
if (GetEditString(CSpaceDataTable::eToilet, arSName))
|
|
m_dataTable.SetNameAry(CSpaceDataTable::eToilet, arSName);
|
|
|
|
m_pFileBase->WriteFile(m_dataTable);
|
|
}
|
|
|
|
CModelessDialog::OnOK();
|
|
}
|
|
|
|
void CSpaceNameClassDlg::HideDialog(CWnd *pDlg, bool bHide)
|
|
{
|
|
if (bHide)
|
|
{
|
|
pDlg->GetParent()->EnableWindow(TRUE);
|
|
pDlg->GetParent()->SetFocus();
|
|
pDlg->GetParent()->SetActiveWindow();
|
|
pDlg->ShowWindow(SW_HIDE);
|
|
}
|
|
else
|
|
{
|
|
pDlg->GetParent()->EnableWindow(FALSE);
|
|
pDlg->EnableWindow(TRUE);
|
|
pDlg->SetActiveWindow();
|
|
pDlg->ShowWindow(SW_SHOW);
|
|
}
|
|
}
|
|
|
|
// 屏幕取词
|
|
void CSpaceNameClassDlg::OnBnClickedBtnQuery()
|
|
{
|
|
// hide自己
|
|
HideDialog(this, true);
|
|
// hide parentWnd
|
|
if (m_bHideParent)
|
|
{
|
|
HideDialog(this->GetParent(), true);
|
|
}
|
|
|
|
CStringArray arSName;
|
|
if (PickName(*this, arSName))
|
|
{
|
|
this->AddStringSToCurrEdit(arSName);
|
|
}
|
|
|
|
if (m_bHideParent)
|
|
{
|
|
HideDialog(this->GetParent(), false);
|
|
}
|
|
HideDialog(this, false);
|
|
}
|
|
|
|
// = Function Name: DealNameSelectResult
|
|
// = Description: 处理选择集结果,选择集的MASK选项为:DXF0, TEXT, TCH_TEXT, TCH_SPACE
|
|
// = Return: 返回名字的个数
|
|
// = param1 ssArea: 选择的结果
|
|
// = param2 arSArea:选择结果处理的字符串
|
|
int CSpaceNameClassDlg::DealNameSelectResult(PickSet &ssArea, CStringArray &arSArea)
|
|
{
|
|
CString sArea;
|
|
for (long i=0;i<ssArea.Length();i++)
|
|
{
|
|
Entity ent=ssArea[i];
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbEntity, pEnt);
|
|
if (pEnt != NULL)
|
|
{
|
|
// CAD单行文字
|
|
if (pEnt->isKindOf(AcDbText::desc()))
|
|
{
|
|
sArea = ((AcDbText *)pEnt)->textString();
|
|
}
|
|
// 上华文字
|
|
else if (pEnt->isKindOf(TDbText::desc()))
|
|
{
|
|
sArea = ((TDbText *)pEnt)->GetText();
|
|
}
|
|
else if (pEnt->isKindOf(TDbSpace::desc()))
|
|
{
|
|
sArea =((TDbSpace *)pEnt)->GetName();
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
if (sArea != _T(""))
|
|
arSArea.Add(sArea);
|
|
}
|
|
|
|
return (int)arSArea.GetSize();
|
|
}
|
|
|
|
BOOL CSpaceNameClassDlg::PickName(CSpaceNameClassDlg &dlg, CStringArray &arSName)
|
|
{
|
|
g_ssPickFirst.Free();
|
|
|
|
RBList mask(RTDXF0, _T("TEXT,TCH_TEXT,TCH_SPACE"), NULL);
|
|
PickSet ssName(SS_FREE);
|
|
int nRet = SelectEntities(_T("\n请选择名称文字<返回>: "), ssName, mask);
|
|
|
|
if (nRet == RTCAN || nRet == RTERROR)
|
|
{
|
|
return FALSE;
|
|
}
|
|
else
|
|
{
|
|
// 识别实体
|
|
DealNameSelectResult(ssName, arSName);
|
|
|
|
return TRUE;
|
|
}
|
|
}
|