314 lines
7.7 KiB
C++
314 lines
7.7 KiB
C++
// LayerSiftDlgEx.cpp : 实现文件
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "LayerSiftDlgEx.h"
|
|
#include "TchBaseDlg.h"
|
|
CString g_sSaveFileName; //保存文件名,需要在创建对话框之前进行赋值***********************
|
|
CString g_sdefaultLayerName; //默认图层名字符串 _T("ROAD_DOTE\r\nROAD");需要在创建对话框之前进行赋值***********************
|
|
CStringArray g_aryLayerName; //默认图层名 需要在创建对话框之前进行赋值***********************
|
|
BOOL g_bOpenLayerFile = FALSE; //add tyj 20160905:打开存储默认图层文件是否成功 true成功
|
|
//CStringArray CLayerSiftDlgEx::m_aryLayer;
|
|
extern void GetLayerNameByKeyWord(CStringArray& aryLayer, CStringArray &aryKeyWord); //根据指定的图层关键字查找图层名
|
|
extern CString GetStrLaynameByAry(CStringArray& aryLayerName);
|
|
// CLayerSiftDlgEx 对话框
|
|
void GetAllLayerNames(std::vector<CString>& allLayer)
|
|
{
|
|
XSymbolList lstLayer(_T("LAYER"));
|
|
|
|
for (long l = 0; l < lstLayer.Length(); l++)
|
|
{
|
|
CString csName = lstLayer[l];
|
|
if ((csName.Find(_T('|')) == -1) && (csName.Find(_T('$')) == -1))
|
|
{
|
|
allLayer.push_back(lstLayer[l]);
|
|
}
|
|
}
|
|
}
|
|
|
|
BOOL SplitstringToLayername(CString splitstr, CString sAllName, CStringArray &aryLayers)
|
|
{
|
|
aryLayers.RemoveAll();
|
|
while (TRUE)
|
|
{
|
|
int nIndex = sAllName.Find(splitstr);
|
|
if (nIndex < 0) // 没找到
|
|
{
|
|
if (sAllName != _T(""))
|
|
aryLayers.Add(sAllName);
|
|
return FALSE;
|
|
}
|
|
else
|
|
{
|
|
CString sDump = sAllName.Mid(0, nIndex);
|
|
if (sDump != _T(""))
|
|
{
|
|
sAllName = sAllName.Mid(nIndex + 2, sAllName.GetLength() - nIndex - 2);
|
|
aryLayers.Add(sDump);
|
|
}
|
|
else
|
|
sAllName = sAllName.Mid(3,sAllName.GetLength());
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
IMPLEMENT_DYNAMIC(CLayerSiftDlgEx, CModelessDialog)
|
|
|
|
CLayerSiftDlgEx::CLayerSiftDlgEx(CWnd* pParent /*=NULL*/, BOOL bStringCanNull/* = FALSE*/)
|
|
: CModelessDialog(CLayerSiftDlgEx::IDD, NULL)
|
|
{
|
|
GetLayerInIniFiles(m_csFileLayer, m_aryLayer, g_sSaveFileName);
|
|
if (g_bOpenLayerFile)//修改 tyj 20160905:当存储默认图层的文件成功被读取后,存储默认图层
|
|
{
|
|
g_aryLayerName.Copy(m_aryLayer);
|
|
}
|
|
if(g_aryLayerName.GetSize() == 0)
|
|
{
|
|
g_sdefaultLayerName = GetStrLaynameByAry(g_aryLayerName);
|
|
}
|
|
|
|
if (m_csLayer.IsEmpty())
|
|
{
|
|
m_csLayer = _T("");
|
|
}
|
|
|
|
if (m_csLayer.IsEmpty())
|
|
m_csLayer = g_sdefaultLayerName;
|
|
|
|
if (m_aryLayer.GetSize() == 0)
|
|
{
|
|
m_aryLayer.Copy(g_aryLayerName);
|
|
}
|
|
|
|
if (bStringCanNull) m_bStrCanNull = TRUE;
|
|
else m_bStrCanNull = FALSE;
|
|
}
|
|
|
|
CLayerSiftDlgEx::~CLayerSiftDlgEx()
|
|
{
|
|
delete m_pFileBase;
|
|
}
|
|
|
|
void CLayerSiftDlgEx::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CModelessDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_EDT_LAYERFILTEREX, m_edtLayName);
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CLayerSiftDlgEx, CModelessDialog)
|
|
ON_BN_CLICKED(IDC_BTN_LAYEREX_CHOOSE, OnBnClickedBtnLayerexChoose)
|
|
ON_BN_CLICKED(IDC_BTN_OK, OnBnClickedBtnOk)
|
|
ON_BN_CLICKED(IDC_BTN_FILTER_CAN, OnBnClickedBtnCancel)
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
// CLayerSiftDlgEx 消息处理程序
|
|
|
|
|
|
BOOL CLayerSiftDlgEx::OnInitDialog()
|
|
{
|
|
CModelessDialog::OnInitDialog();
|
|
CString sText;
|
|
for (int i = 0; i < m_aryLayer.GetSize(); i++)
|
|
{
|
|
sText += m_aryLayer[i];
|
|
sText += ENTERSYMBNOL;
|
|
}
|
|
|
|
m_edtLayName.SetFont(GetFont());
|
|
m_edtLayName.SetWindowText(sText);
|
|
m_edtLayName.SetSel(sText.GetLength(), sText.GetLength(), FALSE);
|
|
|
|
// TODO: 在此添加额外的初始化
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// 异常: OCX 属性页应返回 FALSE
|
|
}
|
|
|
|
//图中选取<
|
|
void CLayerSiftDlgEx::OnBnClickedBtnLayerexChoose()
|
|
{
|
|
CString strTmp, strLayName;
|
|
m_edtLayName.GetWindowText(strTmp);
|
|
SplitstringToLayername(_T("\r\n"), strTmp, m_aryLayer);
|
|
if (!SelectEntInDraw(m_aryLayer))
|
|
return;
|
|
CString sText;
|
|
for (int i = 0; i < m_aryLayer.GetSize(); i++)
|
|
{
|
|
sText += m_aryLayer[i];
|
|
sText += ENTERSYMBNOL;
|
|
}
|
|
|
|
m_edtLayName.SetFont(GetFont());
|
|
m_edtLayName.SetWindowText(sText);
|
|
m_edtLayName.SetSel(sText.GetLength(), sText.GetLength(), FALSE);
|
|
}
|
|
|
|
BOOL CLayerSiftDlgEx::SelectEntInDraw(CStringArray &aryAddLayer)
|
|
{
|
|
XPushAutoHide noAutoHide(this);
|
|
|
|
BeginEditorCommand();
|
|
RBList mask;
|
|
PickSet entSetInDraw;
|
|
|
|
if (SelectEntities(_T("\n请选择对象<返回>: "), entSetInDraw, /*RBList()*/mask) == RTNORM)
|
|
{
|
|
|
|
for (long i = 0; i < entSetInDraw.Length(); i++)
|
|
{
|
|
OPENOBJ_BEGIN(entSetInDraw[i], AcDb::kForRead, AcDbEntity, pEntity);
|
|
if (!pEntity)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
CString csLayText = pEntity->layer();
|
|
int j = 0;
|
|
for (j; j < aryAddLayer.GetSize(); j++)
|
|
{
|
|
if (csLayText == aryAddLayer[j])
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (j >= aryAddLayer.GetSize()) // 没有找到,添加
|
|
aryAddLayer.Add(csLayText);
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
g_ssPickFirst.Free();//SelectEntities函数优先使用全局选择集,再次点选时,要清空全局选择集
|
|
}
|
|
else
|
|
{
|
|
CompleteEditorCommand();
|
|
return FALSE;
|
|
}
|
|
CompleteEditorCommand();
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
//OK
|
|
void CLayerSiftDlgEx::OnBnClickedBtnOk()
|
|
{
|
|
CString strTmp, strLayName;
|
|
m_edtLayName.GetWindowText(strTmp);
|
|
strLayName = strTmp;
|
|
int iCount = strTmp.Replace(ENTERSYMBNOL, SPLITSYMBOL);
|
|
//del tyj 20160905:需求更改,默认图层可以设置为空
|
|
// if (strLayName.IsEmpty())
|
|
// {
|
|
// if (!m_bStrCanNull)//默认false不为空
|
|
// {
|
|
// MessageBox(_T("请至少输入一个图层!"), _T("AutoCAD"), MB_OK);
|
|
// m_csLayer = g_sdefaultLayerName;
|
|
// m_edtLayName.SetFont(GetFont());
|
|
// m_edtLayName.SetWindowText(m_csLayer);
|
|
// m_edtLayName.SetSel(m_csLayer.GetLength(), m_csLayer.GetLength(), FALSE);
|
|
// return;
|
|
// }
|
|
// }
|
|
strTmp.TrimLeft(_T("&"));
|
|
strTmp.TrimRight(_T("&"));
|
|
// 写文件
|
|
if (m_pFileBase != NULL)
|
|
{
|
|
m_pFileBase->SplitString(strTmp, m_aryLayer);
|
|
m_pFileBase->WriteFile(m_aryLayer);
|
|
m_csFileLayer = strTmp;
|
|
}
|
|
CModelessDialog::OnOK();
|
|
}
|
|
|
|
void CLayerSiftDlgEx::GetLayerInIniFiles(CString& strLayer, CStringArray& aryLayer, CString strFileName)
|
|
{
|
|
CString csSysPath = g_sDwbPath;
|
|
csSysPath = csSysPath.Left(csSysPath.GetLength() - 5) + _T("\\sys\\");
|
|
|
|
// 因为该文件负有写入的责任,因此即使该文件不存在,也需要建立该指针
|
|
m_pFileBase = new CLayerFiltrationFileOperator(csSysPath + strFileName);
|
|
//add tyj 20160905:获取文件读取是否成功,用于对默认图层的判断
|
|
g_bOpenLayerFile = m_pFileBase->ReadFile(aryLayer);
|
|
if ((m_pFileBase != NULL) && g_bOpenLayerFile /*&& aryLayer.GetSize() > 0*/)//默认图层可以为空
|
|
{
|
|
if(aryLayer.GetSize() == 0)
|
|
{
|
|
strLayer = _T("");
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < aryLayer.GetSize(); i++)
|
|
{
|
|
if (i != 0)
|
|
strLayer += SPLITSYMBOL;
|
|
strLayer += aryLayer[i];
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
CStringArray& CLayerSiftDlgEx::GetFilterLayer()
|
|
{
|
|
if ((m_aryLayer.GetSize() == 0) && !g_bOpenLayerFile)
|
|
{
|
|
// m_aryLayer[0] = _T("ROAD_DOTE");
|
|
// m_aryLayer[1] = _T("ROAD");
|
|
m_aryLayer.Copy(g_aryLayerName);
|
|
}
|
|
return m_aryLayer;
|
|
}
|
|
|
|
void CLayerSiftDlgEx::GetSelectLayers(CStringList& lstLayer)
|
|
{
|
|
for (int i = 0; i < m_aryLayer.GetSize(); ++i)
|
|
{
|
|
if (!lstLayer.Find(m_aryLayer[i]))
|
|
{
|
|
lstLayer.AddTail(m_aryLayer[i]);//唯一性添加
|
|
}
|
|
}
|
|
}
|
|
|
|
void CLayerSiftDlgEx::OnClose()
|
|
{
|
|
if (m_bModeless)
|
|
{
|
|
acedPostCommand(_T("\33\33"));
|
|
}
|
|
else
|
|
{
|
|
CModelessDialog::OnClose();
|
|
}
|
|
}
|
|
//IDC_BTN_FILTER_CAN
|
|
//点击取消
|
|
void CLayerSiftDlgEx::OnBnClickedBtnCancel()
|
|
{
|
|
// CString sText;
|
|
// for (int i = 0; i < m_aryPreLayer.GetSize(); i++)
|
|
// {
|
|
// sText += m_aryPreLayer[i];
|
|
// sText += ENTERSYMBNOL;
|
|
// }
|
|
//
|
|
// m_edtLayName.SetFont(GetFont());
|
|
// m_edtLayName.SetWindowText(sText);
|
|
// m_edtLayName.SetSel(sText.GetLength(), sText.GetLength(), FALSE);
|
|
// m_aryLayer.Copy(m_aryPreLayer);
|
|
m_aryLayer.RemoveAll();
|
|
GetLayerInIniFiles(m_csFileLayer, m_aryLayer, g_sSaveFileName);
|
|
if (m_aryLayer.GetSize() == 0)
|
|
{
|
|
m_aryLayer.Copy(g_aryLayerName);
|
|
}
|
|
CModelessDialog::OnCancel();
|
|
}
|
|
|