Files
envi-code/SourceCode/Code2026/tg_shs/shs_kerncmd/UniteLayer.cpp
T

349 lines
8.2 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
#include "stdafx.h"
2026-09-28 15:28:50 +08:00
#include "UniteLayer.h"
#include "Resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
2026-10-04 00:04:20 +08:00
// 获得层表管理器的记录,add xly 100617
2026-09-28 15:28:50 +08:00
void GetLayerDes(CStringArray &curLayerNameAry, CStringArray &layerCon);
2026-10-04 00:04:20 +08:00
// 创建层名为csCurLayer的新图层
2026-09-28 15:28:50 +08:00
void CreateLayer(const CString &csCurLayer);
2026-10-04 00:04:20 +08:00
// 判断图层是否被锁定
2026-09-28 15:28:50 +08:00
bool IsLockLayer(CString &csCurLayer);
2026-10-04 00:04:20 +08:00
// add by xly on 101229 判断图层是本地图层和外部参照图层,识别“|”“$”
2026-09-28 15:28:50 +08:00
bool IsExternalLayer(CString csLayerName);
CUniteLayer::CUniteLayer(CWnd* pParent /*=NULL*/)
: GlwCAcUiDialog(CUniteLayer::IDD, pParent)
{
//{{AFX_DATA_INIT(CUniteLayer)
m_csCmbText = _T("");
//}}AFX_DATA_INIT
}
CUniteLayer::~CUniteLayer()
{
m_ssPickEnt.Free();
}
void CUniteLayer::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUniteLayer)
DDX_Control(pDX, IDC_LIST_LAYER, m_wndLstLayer);
DDX_Control(pDX, IDC_CMB_GOALLAYER, m_wndCmbGoal);
DDX_CBString(pDX, IDC_CMB_GOALLAYER, m_csCmbText);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUniteLayer, GlwCAcUiDialog)
ON_BN_CLICKED(IDC_BUT_OBJUNITE, OnButtonUniteObj)
ON_BN_CLICKED(IDC_BUT_OBJGOAL, OnButtonGoalObj)
ON_BN_CLICKED(IDC_OK, OnOK)
END_MESSAGE_MAP()
// CUniteLayer message handlers
BOOL CUniteLayer::OnInitDialog()
{
UpdateData(TRUE);
CDialog::OnInitDialog();
2026-10-04 00:04:20 +08:00
// 图层列表初始化设置
2026-09-28 15:28:50 +08:00
CRect rect;
m_wndLstLayer.GetClientRect(rect);
2026-10-04 00:04:20 +08:00
// 获得图层管理器的图层名以及列表
2026-09-28 15:28:50 +08:00
GetAllLayer();
2026-10-04 00:04:20 +08:00
// 设置列表控件的checkbox模式
2026-09-28 15:28:50 +08:00
m_wndLstLayer.SetExtendedStyle(LVS_EX_CHECKBOXES);
2026-10-04 00:04:20 +08:00
m_wndLstLayer.InsertColumn(0, _T("层名"), LVCFMT_LEFT, rect.Width()/2);
m_wndLstLayer.InsertColumn(1, _T("描述"), LVCFMT_LEFT, rect.Width()*7/16);
2026-09-28 15:28:50 +08:00
int nSize = m_csAryLayerAll.GetSize(),
nSize1 = m_csAryLayerCon.GetSize();
for(int i = 0; i<nSize; i++)
{
2026-10-04 00:04:20 +08:00
// 添加列表控件第一列层名
2026-09-28 15:28:50 +08:00
m_wndLstLayer.InsertItem(i, m_csAryLayerAll[i]);
2026-10-04 00:04:20 +08:00
// 目标图层下拉框
2026-09-28 15:28:50 +08:00
m_wndCmbGoal.InsertString(i, m_csAryLayerAll[i]);
2026-10-04 00:04:20 +08:00
// 查找该层名是否有图层描述
2026-09-28 15:28:50 +08:00
for(int j = 0; j<nSize1; j++)
{
2026-10-04 00:04:20 +08:00
if(m_csAryLayerAll[i] == m_csAryLayerCon[j]) //层名有描述
2026-09-28 15:28:50 +08:00
{
m_wndLstLayer.SetItemText(i, 1, m_csAryLayerCon[j-1]);
}
}
}
UpdateData(false);
return TRUE;
}
2026-10-04 00:04:20 +08:00
// 图中选取需合并图层的对象
2026-09-28 15:28:50 +08:00
void CUniteLayer::OnButtonUniteObj()
{
UpdateData(TRUE);
2026-10-04 00:04:20 +08:00
// 设置对话框隐藏
2026-09-28 15:28:50 +08:00
ShowDialog(false);
2026-10-04 00:04:20 +08:00
// 用户选择要改变图层的图元
CString csPromt = (_T("\n请选择要合并图层上的任意对象<返回>:"));
2026-09-28 15:28:50 +08:00
int iRet = SelectEntities(csPromt, m_ssPickEnt, RBList());
if(iRet != RTNORM)
{
m_ssPickEnt.Free();
ShowDialog(true);
return;
}
2026-10-04 00:04:20 +08:00
// 将选择到的图层在列表中标记
2026-09-28 15:28:50 +08:00
long l = 0;
bool bIsLocked;
long nSize = m_ssPickEnt.Length();
for(l = 0; l<nSize; l++)
{
OPENOBJ_BEGIN(m_ssPickEnt[l], AcDb::kForRead, AcDbEntity, pEnt);
if (pEnt != NULL)
{
CString csCurLayer = pEnt->layer();
bIsLocked = IsLockLayer(csCurLayer);
2026-10-04 00:04:20 +08:00
// 被选实体所在的图层在列表中被选
2026-09-28 15:28:50 +08:00
this->SetListSel(csCurLayer);
2026-10-04 00:04:20 +08:00
if(bIsLocked)// 图层被锁定
2026-09-28 15:28:50 +08:00
{
continue;
}
}
OPENOBJ_END();
}
if (bIsLocked)
{
2026-10-04 00:04:20 +08:00
acutPrintf(_T("\n锁定图层请解锁后再操作!"));
2026-09-28 15:28:50 +08:00
}
2026-10-04 00:04:20 +08:00
// modify by xly on 110331 解决操作过程中存在闪烁现象
// 更新显示
2026-09-28 15:28:50 +08:00
//acedCommand(RTSTR, _T("REGEN"), RTNONE);
acedRedraw(NULL,1);
ShowDialog(true);
}
2026-10-04 00:04:20 +08:00
// 图中选取目标图层的对象
2026-09-28 15:28:50 +08:00
void CUniteLayer::OnButtonGoalObj()
{
UpdateData(TRUE);
2026-10-04 00:04:20 +08:00
// 设置对话框隐藏
2026-09-28 15:28:50 +08:00
ShowDialog(false);
2026-10-04 00:04:20 +08:00
// 目标实体
2026-09-28 15:28:50 +08:00
TEntitySet ent;
2026-10-04 00:04:20 +08:00
// 点取位置
2026-09-28 15:28:50 +08:00
TADSGePoint3d ptSel;
2026-10-04 00:04:20 +08:00
if((SelectEntity1(_T("\n请选择目标图层的对象<返回>:"), ent, ptSel, RBList())) != RTNORM)
2026-09-28 15:28:50 +08:00
{
ShowDialog(true);
return;
}
2026-10-04 00:04:20 +08:00
// 获得目标实体的图层
2026-09-28 15:28:50 +08:00
TCHAR szSelLay[256];
ent.GetData(8, szSelLay);
2026-10-04 00:04:20 +08:00
// 设置对话框中的目标图层
2026-09-28 15:28:50 +08:00
this->SetGoalLayer(szSelLay);
ShowDialog(true);
}
2026-10-04 00:04:20 +08:00
// 确定按钮实现
2026-09-28 15:28:50 +08:00
void CUniteLayer::OnOK()
{
UpdateData(TRUE);
2026-10-04 00:04:20 +08:00
int iTaskCount = m_wndLstLayer.GetItemCount(); // 获得列表框中的列数
bool bFlagSel = false, // 标记是否有需合并的图层
bFlagGaol = false; // 标记目标图层是否是已有图层
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
// 遍历列表中的数据,查找被选中图层
2026-09-28 15:28:50 +08:00
CString csName;
int i = 0;
for (i = 0; i < iTaskCount; i++)
{
2026-10-04 00:04:20 +08:00
// 获得列表中的图层名
2026-09-28 15:28:50 +08:00
csName = m_wndLstLayer.GetItemText(i,0);
2026-10-04 00:04:20 +08:00
if(csName == m_csCmbText) // 目标图层是否存在
2026-09-28 15:28:50 +08:00
{
bFlagGaol = true;
}
2026-10-04 00:04:20 +08:00
if(m_wndLstLayer.GetCheck(i)) // 需合并图层是否存在
2026-09-28 15:28:50 +08:00
{
bFlagSel = true;
}
}
2026-10-04 00:04:20 +08:00
if(!bFlagSel) // 未设置需合并图层
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
MessageBox(_T("未设置需合并图层!"));
2026-09-28 15:28:50 +08:00
return;
}
2026-10-04 00:04:20 +08:00
if(m_csCmbText.IsEmpty()) // 未设置目标图层
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
MessageBox(_T("未设置目标图层!"));
2026-09-28 15:28:50 +08:00
return;
}
2026-10-04 00:04:20 +08:00
else // 已设置目标图层
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
if(!bFlagGaol) // 目标图层不存在
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
i = AfxMessageBox(_T("该图层不存在,是否创建?"), MB_YESNO);
if(i != IDYES) // 创建图层
2026-09-28 15:28:50 +08:00
{
return;
}
2026-10-04 00:04:20 +08:00
CreateLayer(m_csCmbText);// 创建图层函数
2026-09-28 15:28:50 +08:00
}
2026-10-04 00:04:20 +08:00
// 合并到目标图层
2026-09-28 15:28:50 +08:00
SetLayer(m_csCmbText);
m_ssPickEnt.Free();
CDialog::OnOK();
}
}
2026-10-04 00:04:20 +08:00
// 设置选中对象所在的图层被选择
2026-09-28 15:28:50 +08:00
void CUniteLayer::SetListSel(CString csName)
{
UpdateData(TRUE);
2026-10-04 00:04:20 +08:00
// 遍历列表中的数据,查找被选中图层
2026-09-28 15:28:50 +08:00
int iTaskCount = m_wndLstLayer.GetItemCount();
CString csListName;
for (int i = 0; i < iTaskCount; i++)
{
csListName = m_wndLstLayer.GetItemText(i, 0);
2026-10-04 00:04:20 +08:00
// modify by xly on 110441 忽略大小写比较
//if(csListName == csName)// 选中对象的图层在列表中
if(csListName.CompareNoCase(csName)==0)// 选中对象的图层在列表中
2026-09-28 15:28:50 +08:00
{
m_wndLstLayer.SetCheck(i, TRUE);
}
}
}
2026-10-04 00:04:20 +08:00
// 目标图层设置
2026-09-28 15:28:50 +08:00
void CUniteLayer::SetGoalLayer(CString csName)
{
UpdateData(TRUE);
2026-10-04 00:04:20 +08:00
// 遍历下拉列表中的数据,查找目标图层
2026-09-28 15:28:50 +08:00
m_csCmbText = csName;
UpdateData(FALSE);
}
2026-10-04 00:04:20 +08:00
// 获得图层管理器中的所有图层和图层描述
2026-09-28 15:28:50 +08:00
void CUniteLayer::GetAllLayer()
{
2026-10-04 00:04:20 +08:00
// 遍历图之中的层表去掉外部参照部分的层
2026-09-28 15:28:50 +08:00
XSymbolList lstLayer(_T("LAYER"));
long l = 0;
for(l = 0; l<lstLayer.Length(); l++)
{
CString csName = lstLayer[l];
bool bIsExt = IsExternalLayer(csName);
2026-10-04 00:04:20 +08:00
if (!bIsExt)// 本地图层
2026-09-28 15:28:50 +08:00
{
m_csAryLayerAll.Add(lstLayer[l]);
}
}
2026-10-04 00:04:20 +08:00
// 存储层表在层表管理器中的描述
2026-09-28 15:28:50 +08:00
GetLayerDes(m_csAryLayerAll, m_csAryLayerCon);
}
2026-10-04 00:04:20 +08:00
// 设置图层:将一组实体设置到csLayerName图层
2026-09-28 15:28:50 +08:00
void CUniteLayer::SetLayer(CString &csLayerName)
{
2026-10-04 00:04:20 +08:00
// 遍历列表中的数据,查找被选中图层
2026-09-28 15:28:50 +08:00
int iTaskCount = m_wndLstLayer.GetItemCount();
CString csLayerSelName = _T("");
bool bIsLocked(false);
for (int i = 0; i < iTaskCount; i++)
{
2026-10-04 00:04:20 +08:00
// 判断是否被选中
2026-09-28 15:28:50 +08:00
BOOL isSel = m_wndLstLayer.GetCheck(i);
if(isSel)
{
2026-10-04 00:04:20 +08:00
// 得到要改层的图层名
2026-09-28 15:28:50 +08:00
csLayerSelName = m_wndLstLayer.GetItemText(i, 0);
bIsLocked = IsLockLayer(csLayerSelName);
2026-10-04 00:04:20 +08:00
if(bIsLocked || csLayerName==csLayerSelName)// 图层被锁定,目标图层和需要改变的图层在同层
2026-09-28 15:28:50 +08:00
{
continue;
}
{
2026-10-04 00:04:20 +08:00
// sg modify 101112,根据8.5需求,为了提高图层转换的速度,进入命令后,临时关闭了数据库反应器
2026-09-28 15:28:50 +08:00
TPushMemVar<BOOL> pushVar(g_bMonitorDbAction, FALSE);
2026-10-04 00:04:20 +08:00
// 获得在csLayerSelName层中的所有对象存放在ss
2026-09-28 15:28:50 +08:00
PickSet ss(SS_FREE);
ss.Get(_T("X"), NULL, NULL, RBList(8, csLayerSelName, NULL));
for (long j=0; j<ss.Length(); j++)
{
2026-10-04 00:04:20 +08:00
// 修改对象所在的图层
2026-09-28 15:28:50 +08:00
OPENOBJ_BEGIN(ss[j], AcDb::kForRead, AcDbEntity, pEnt);
if (pEnt != NULL)
{
2026-10-04 00:04:20 +08:00
// 获取层名
2026-09-28 15:28:50 +08:00
CString csCurLayer = pEnt->layer();
if (pEnt->upgradeOpen() == Acad::eOk)
{
2026-10-04 00:04:20 +08:00
pEnt->setLayer(csLayerName); // 设置目标图层
2026-09-28 15:28:50 +08:00
pEnt->downgradeOpen();
}
}
OPENOBJ_END();
}
}
}
}
}
2026-10-04 00:04:20 +08:00
//根据bShow显示和隐藏对话框,true:显示对话框;false:隐藏对话框
2026-09-28 15:28:50 +08:00
void CUniteLayer::ShowDialog(bool bShow)
{
2026-10-04 00:04:20 +08:00
if (bShow)// 对话框显示
2026-09-28 15:28:50 +08:00
{
this->ShowWindow(SW_SHOW);
this->SetFocus();
}
2026-10-04 00:04:20 +08:00
else // 对话框隐藏
2026-09-28 15:28:50 +08:00
{
this->GetParent()->EnableWindow(true);
this->GetParent()->SetFocus();
this->GetParent()->SetActiveWindow();
this->ShowWindow(SW_HIDE);
}
}