4556 lines
115 KiB
C++
4556 lines
115 KiB
C++
// LayerManage.cpp : 实现文件
|
||
//
|
||
|
||
#include "stdafx.h"
|
||
#include "LayerManager.h"
|
||
|
||
#include "shlwapi.h"
|
||
#include "GoalLayerDlg.h" // 图元改层对话框
|
||
#include "OpenLayer.h" // 打开图层对话框
|
||
#include "UniteLayer.h" // 合并图层对话框
|
||
|
||
#define APP_LAYERMANAGE _T("_LayerManage")
|
||
|
||
TARCH_IMPEXP void InitLayers(BOOL bTrue);
|
||
bool g_bLayerManagerModify = false;
|
||
|
||
|
||
////////////////////////////////////////////////////////////////////////////
|
||
|
||
BOOL SelectLayer(XStringList &lstSelLay, XStringList &lstOtherLay)
|
||
{
|
||
PickSet ss(SS_FREE);
|
||
if (ss.Get(_T("I"), NULL, NULL, RBList()) != RTNORM)
|
||
{
|
||
if (SelectEntities(_T("选择对象 <退出>:"), ss, RBList()) != RTNORM)
|
||
return FALSE;
|
||
}
|
||
|
||
for (long i=0; i<ss.Length(); i++)
|
||
{
|
||
Entity ent = ss[i];
|
||
TCHAR szSelLay[256];
|
||
ent.GetData(8, szSelLay);
|
||
|
||
if (lstSelLay.Index(szSelLay, 0) < 0)
|
||
lstSelLay.Append(tstrnew(szSelLay));
|
||
}
|
||
|
||
XSymbolList lstLayer(_T("LAYER"));
|
||
for (i=0; i<lstLayer.Length(); i++)
|
||
{
|
||
CString czLayer = lstLayer[i];
|
||
if (lstSelLay.Index(czLayer, 0) < 0)
|
||
lstOtherLay.Append(tstrnew(czLayer));
|
||
}
|
||
|
||
if (!XSymbolTable(_T("APPID"), APP_LAYERMANAGE))
|
||
acdbRegApp(APP_LAYERMANAGE);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL SelectLayerForT20(XStringList &lstSelLay, XStringList &lstOtherLay)
|
||
{
|
||
PickSet ss(SS_FREE);
|
||
if (ss.Get(_T("I"), NULL, NULL, RBList()) != RTNORM)
|
||
{
|
||
if (SelectEntities(_T("选择对象 <退出>:"), ss, RBList()) != RTNORM)
|
||
return FALSE;
|
||
}
|
||
|
||
/*for (long i=0; i<ss.Length(); i++)
|
||
{
|
||
Entity ent = ss[i];
|
||
TCHAR szSelLay[256];
|
||
ent.GetData(8, szSelLay);
|
||
|
||
if (lstSelLay.Index(szSelLay, 0) < 0)
|
||
lstSelLay.Append(tstrnew(szSelLay));
|
||
}*/
|
||
|
||
CString csName = _T("");
|
||
for (long i=0; i<ss.Length(); i++)
|
||
{
|
||
OPENOBJ_BEGIN(ss[i], AcDb::kForRead, AcDbEntity, pEnt);
|
||
TDocAutoLock lock;
|
||
ASSERT(pEnt);
|
||
if (pEnt->isKindOf(TDbEntity::desc()) ||
|
||
pEnt->isKindOf(TDbCurveEntity::desc()) ||
|
||
pEnt->isKindOf(TDbBlockInsert::desc()))
|
||
{
|
||
//分解对象
|
||
AcDbVoidPtrArray entitySet;
|
||
pEnt->explode(entitySet);
|
||
AcDbEntity *pEntSon;
|
||
for (long i = 0; i < entitySet.length(); i++)
|
||
{
|
||
pEntSon = (AcDbEntity*)entitySet[i];
|
||
if (pEnt != NULL)
|
||
{
|
||
csName = pEntSon->layer();
|
||
}
|
||
if (lstSelLay.Index(csName, 0) < 0)
|
||
{
|
||
lstSelLay.Append(tstrnew(csName));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pEnt != NULL)
|
||
{
|
||
csName = pEnt->layer();
|
||
}
|
||
if (lstSelLay.Index(csName, 0) < 0)
|
||
{
|
||
lstSelLay.Append(tstrnew(csName));
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
XSymbolList lstLayer(_T("LAYER"));
|
||
for (i=0; i<lstLayer.Length(); i++)
|
||
{
|
||
CString czLayer = lstLayer[i];
|
||
if (lstSelLay.Index(czLayer, 0) < 0)
|
||
lstOtherLay.Append(tstrnew(czLayer));
|
||
}
|
||
|
||
if (!XSymbolTable(_T("APPID"), APP_LAYERMANAGE))
|
||
acdbRegApp(APP_LAYERMANAGE);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL PrepareLayer(const TCHAR*szLayerName, AcDbLayerTableRecord *&pLayerRec)
|
||
{
|
||
AcDbLayerTable *pLayertable = NULL;
|
||
if (acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead) != Acad::eOk)
|
||
return FALSE;
|
||
|
||
// Acad::ErrorStatus es = pLayertable->getAt(szLayerName, pLayerRec, AcDb::kForWrite);
|
||
Acad::ErrorStatus es = pLayertable->getAt(szLayerName, pLayerRec, AcDb::kForRead);
|
||
pLayertable->close();
|
||
if (es != Acad::eOk)
|
||
return FALSE;
|
||
|
||
if (pLayerRec->xData(APP_LAYERMANAGE) == NULL)
|
||
{
|
||
Adesk::UInt16 nOff = pLayerRec->isOff();
|
||
Adesk::UInt16 nFrozen = pLayerRec->isFrozen();
|
||
Adesk::UInt16 nLocked = pLayerRec->isLocked();
|
||
resbuf *pXD = acutBuildList(1001, APP_LAYERMANAGE, 1070, nOff, 1070, nFrozen, 1070, nLocked, NULL);
|
||
if (pLayerRec->upgradeOpen() == Acad::eOk) // sg modify 101228,防止速度过慢
|
||
{
|
||
pLayerRec->setXData(pXD); // 存放扩展记录
|
||
pLayerRec->downgradeOpen();
|
||
}
|
||
acutRelRb(pXD);
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
////////////////////////////////////////////////////////////////////////////
|
||
// 判断图层是否被锁定
|
||
bool IsLockLayer(CString &csCurLayer)
|
||
{
|
||
AcDbLayerTable *pLayertable = NULL;
|
||
if (acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead)!=Acad::eOk ||
|
||
pLayertable==NULL) // 获得层表
|
||
{
|
||
return false;
|
||
}
|
||
|
||
AcDbLayerTableRecord *pLayerTblRcd = NULL;
|
||
if (pLayertable->getAt(csCurLayer, pLayerTblRcd, AcDb::kForRead)!=Acad::eOk ||
|
||
pLayerTblRcd==NULL) // 获得层表记录
|
||
{
|
||
pLayertable->close();
|
||
return false;
|
||
}
|
||
|
||
bool bIslock = pLayerTblRcd->isLocked(); // 判断层表记录的锁定状态
|
||
|
||
pLayerTblRcd->close();
|
||
pLayertable->close();
|
||
|
||
return bIslock;
|
||
}
|
||
|
||
// 创建图层 add xly 100611
|
||
void CreateLayer(const CString &csCurLayer)
|
||
{
|
||
// 获得层表
|
||
AcDbLayerTable *pLayerTab = NULL;
|
||
if (acdbCurDwg()->getLayerTable(pLayerTab, AcDb::kForWrite) != Acad::eOk)
|
||
{
|
||
return;
|
||
}
|
||
|
||
// 定义层表记录
|
||
AcDbLayerTableRecord *pLayerTblRcd = new AcDbLayerTableRecord;
|
||
|
||
// 设置层表记录信息,名称
|
||
pLayerTblRcd->setName(csCurLayer);
|
||
|
||
AcCmColor cor;
|
||
cor.setColorIndex(0);
|
||
pLayerTblRcd->setColor(cor); // 颜色
|
||
|
||
AcDbObjectId idLineType = InitLineType(_T("CONTINUOUS"));
|
||
if (!idLineType.isNull())
|
||
{
|
||
pLayerTblRcd->setLinetypeObjectId(idLineType); // 线型
|
||
}
|
||
|
||
// 层表记录添加到层表
|
||
if (pLayerTab->add(pLayerTblRcd) != Acad::eOk)
|
||
{
|
||
pLayerTab->close(); // sg add 110623,解决崩溃问题
|
||
delete pLayerTblRcd;
|
||
return;
|
||
}
|
||
|
||
pLayerTab->close();
|
||
pLayerTblRcd->close();
|
||
}
|
||
|
||
// 获得层表管理器的记录 add xly 100617
|
||
void GetLayerDes(CStringArray &curLayerNameAry, CStringArray &layerCon)
|
||
{
|
||
// 寻找层表管理器的路径
|
||
CString csFileName = _T("layerdef.dat");
|
||
|
||
CString szFullPath = g_sDwbPath;
|
||
if (_tcscmp(csFileName, _T("")) == 0)
|
||
{
|
||
szFullPath = szFullPath.Left(szFullPath.GetLength() - 5) + _T("\\sys\\");
|
||
}
|
||
else
|
||
{
|
||
szFullPath = szFullPath.Left(szFullPath.GetLength() - 5) + _T("\\sys\\") + csFileName;
|
||
if (csFileName.Find(_T(".")) == -1)
|
||
{
|
||
szFullPath += _T(".lay");
|
||
}
|
||
}
|
||
|
||
// 打开层表管理器文件
|
||
CStdioFile file;
|
||
if (!file.Open(szFullPath, CFile::modeRead))
|
||
{
|
||
AfxMessageBox(CString(_T("打开文件 \"")) + szFullPath + _T("\" 失败"));
|
||
return;
|
||
}
|
||
|
||
// 读取图层管理其中的信息
|
||
int iFind = -1;
|
||
|
||
CString sString;
|
||
while (file.ReadString(sString))
|
||
{
|
||
// 图层关键字
|
||
TCHAR sKey[256] = _T("");
|
||
|
||
// 图层名
|
||
TCHAR sName[256] = _T("");
|
||
|
||
int nColor = 0;
|
||
TCHAR sLineType[256] = _T("");
|
||
TCHAR sNote[256] = _T("");
|
||
|
||
_stscanf(sString, _T("%s%s%d%s%s"), sKey, sName, &nColor, sLineType, sNote);
|
||
|
||
// 当前图形中存在的图层
|
||
int nLength = (int)curLayerNameAry.GetSize();
|
||
for (int i = 0; i<nLength; i++)
|
||
{
|
||
if (iFind == i) // 记录图层是否被找到过
|
||
{
|
||
continue;
|
||
}
|
||
|
||
// modify by xly on 110413 如果图层是0层,不加图层描述
|
||
//if (_tcscmp(sName, curLayerNameAry[i]) == 0) // 找到当前图层的名
|
||
if (_tcscmp(sName, curLayerNameAry[i]) == 0&&_tcscmp(sName,_T("0"))) // 找到当前图层的名
|
||
{
|
||
layerCon.Add(sKey);
|
||
layerCon.Add(sName);
|
||
|
||
// 记录被找到过的层的索引
|
||
iFind = i;
|
||
continue;
|
||
}
|
||
}
|
||
}
|
||
file.Close();
|
||
}
|
||
|
||
// modify by xly on 110420 修改支持外部参照的情况,不用底层,模仿水的功能
|
||
//// 关闭、冻结图层, 添加 xly 100608 使该命令对图块和外部参照内的图层有效。
|
||
//BOOL SelectLayerOff(XStringList &lstSelLay, XStringList &lstOtherLay, int &iWhichSel)
|
||
//{
|
||
// // 图层开关状态控制
|
||
// static bool s_bIsOpen = true;
|
||
//
|
||
// // 图层冻结状态控制
|
||
// static bool s_bIsFreeze = true;
|
||
//
|
||
// CString csPromt1 = _T(""), // 状态行提示
|
||
// csPromt2 = _T("");
|
||
//
|
||
// // 定义实体选择集
|
||
// PickSet ss(SS_FREE);
|
||
//
|
||
// // add by xly on 110104 存放用户点取点
|
||
// int nRet(0);
|
||
// AcGePoint3dArray aryPts;
|
||
// if (iWhichSel == 0) // 关闭图层
|
||
// {
|
||
// csPromt1 = _T("\n选择对象[关闭块参照和外部参照内部图层(Q),当前:关闭块参照所在图层]<退出>:");
|
||
// csPromt2 = _T("\n选择对象[关闭块参照和外部参照所在图层(Q),当前:关闭内部图层]<退出>:");
|
||
// nRet = SelectEnts(csPromt1, csPromt2, ss, RBList(), _T("Q"), _T("\n选择对象<退出>:"), aryPts, s_bIsOpen, TRUE, !s_bIsOpen);
|
||
// }
|
||
// else if (iWhichSel == 1) // 冻结图层
|
||
// {
|
||
// csPromt1 = _T("\n选择对象[冻结块参照和外部参照内部图层(Q),当前:冻结块参照所在图层]<退出>:");
|
||
// csPromt2 = _T("\n选择对象[冻结块参照和外部参照所在图层(Q),当前:冻结内部图层]<退出>:");
|
||
// nRet = SelectEnts(csPromt1, csPromt2, ss, RBList(), _T("Q"), _T("\n选择对象<退出>:"), aryPts, s_bIsFreeze, TRUE, !s_bIsFreeze);
|
||
// }
|
||
//
|
||
// // 判断是否点取成功
|
||
// if (aryPts.length()<1 || nRet==RTCAN)
|
||
// {
|
||
// return FALSE;
|
||
// }
|
||
//
|
||
// // 将关闭和冻结的当前值传给一个变量控制
|
||
// bool bFlag = true;
|
||
// /*if (!s_bIsOpen || !s_bIsFreeze)
|
||
// {
|
||
// bFlag = false;
|
||
// }*/
|
||
// if (iWhichSel==0)
|
||
// {
|
||
// if (!s_bIsOpen)
|
||
// {
|
||
// bFlag = false;
|
||
// }
|
||
// }
|
||
// else if (iWhichSel == 1)
|
||
// {
|
||
// if (!s_bIsFreeze)
|
||
// {
|
||
// bFlag = false;
|
||
// }
|
||
// }
|
||
//
|
||
//
|
||
// CString csName = _T("");
|
||
// if (bFlag) // 块参照所在的图层
|
||
// {
|
||
// for (long i=0; i<ss.Length(); i++)
|
||
// {
|
||
// OPENOBJ_BEGIN(ss[i], AcDb::kForRead, AcDbEntity, pEnt);
|
||
// if (pEnt != NULL)
|
||
// {
|
||
// csName = pEnt->layer();
|
||
// }
|
||
// OPENOBJ_END();
|
||
//
|
||
// if (lstSelLay.Index(csName, 0) < 0)
|
||
// {
|
||
// lstSelLay.Append(tstrnew(csName));
|
||
// }
|
||
// }
|
||
// }
|
||
// else // 块参照内部图层
|
||
// {
|
||
// int nL = aryPts.length() - 1;
|
||
// for (int n=0; n<nL; n+=2) // 遍历所有框选的点取点,每两个一对
|
||
// {
|
||
//
|
||
// // 获得框选范围内的实体
|
||
// AcDbObjectIdArray arIds;
|
||
// GetEntityByPoly(aryPts[n], aryPts[n+1], arIds, TRUE, TRUE);
|
||
//
|
||
// AcDbEntity* pEnt = NULL;
|
||
// for (int i=0; i<arIds.length(); i++)
|
||
// {
|
||
// // 获得框选到的实体的图层
|
||
// if (Acad::eOk == acdbOpenAcDbEntity(pEnt, arIds.at(i), AcDb::kForRead))
|
||
// {
|
||
// csName = pEnt->layer();
|
||
// pEnt->close();
|
||
// }
|
||
//
|
||
// if (lstSelLay.Index(csName, 0) < 0)
|
||
// {
|
||
// lstSelLay.Append(tstrnew(csName));
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
//
|
||
// // 层表
|
||
// XSymbolList lstLayer(_T("LAYER"));
|
||
// for (long i = 0; i<lstLayer.Length(); i++)
|
||
// {
|
||
// CString czLayer = lstLayer[i];
|
||
// if (lstSelLay.Index(czLayer, 0) < 0)
|
||
// {
|
||
// lstOtherLay.Append(tstrnew(czLayer));
|
||
// }
|
||
// }
|
||
//
|
||
// if (!XSymbolTable(_T("APPID"), APP_LAYERMANAGE))
|
||
// {
|
||
// acdbRegApp(APP_LAYERMANAGE);
|
||
// }
|
||
// return TRUE;
|
||
//}
|
||
|
||
|
||
//如果参照的图块内图元图层为0层,取图块的图层
|
||
CString GetExternalBlkLayer(Entity entSel, XPoint ptPick, AcDbObjectId idOwn)
|
||
{
|
||
CString csLay;
|
||
AcDbBlockReference *pBlkRef = NULL;
|
||
AcDbObjectId id = NULL;
|
||
acdbGetObjectId(id, entSel);
|
||
acdbOpenObject(pBlkRef, id, AcDb::kForRead);
|
||
if(!pBlkRef)
|
||
return csLay;
|
||
AcGeMatrix3d mat = pBlkRef->blockTransform();
|
||
if(pBlkRef)
|
||
pBlkRef->close();
|
||
//第二步,得到块记录遍历器
|
||
TCHAR szBlkName[256];
|
||
entSel.GetData(2, szBlkName);
|
||
AcDbBlockTable* pBlockTable = NULL;
|
||
AcDbBlockTableRecord *pRecord = NULL;
|
||
acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead);
|
||
if(Acad::eOk != pBlockTable->getAt(szBlkName, pRecord, AcDb::kForRead))
|
||
return csLay;
|
||
pBlockTable->close();
|
||
if(pRecord->isFromExternalReference() == true){
|
||
XPoint ptOrigin = pRecord->origin();
|
||
AcGeMatrix3d mat2;
|
||
mat2.setToTranslation(AcGeVector3d(-ptOrigin[0], -ptOrigin[1], -ptOrigin[2]));
|
||
mat *= mat2;
|
||
}
|
||
AcDbBlockTableRecordIterator *pIterator = NULL;
|
||
pRecord->newIterator(pIterator);
|
||
if(pRecord)
|
||
pRecord->close();
|
||
|
||
for(pIterator->start(); !pIterator->done(); pIterator->step()){
|
||
AcDbEntity *pEnt;
|
||
pIterator->getEntity(pEnt, AcDb::kForRead);
|
||
AcDbBlockReference *pBlk = NULL;
|
||
if(pBlk = AcDbBlockReference::cast(pEnt)){
|
||
if(pBlk->blockTableRecord() == idOwn){
|
||
AcDbExtents extents;
|
||
pEnt->getGeomExtents(extents);
|
||
extents.transformBy(mat);
|
||
AcGePoint3d pMax = extents.maxPoint();
|
||
AcGePoint3d pMin = extents.minPoint();
|
||
pMax.x += 50;
|
||
pMax.y += 50;
|
||
pMin.x -= 50;
|
||
pMin.y -= 50;
|
||
TCHAR *chlayer = pEnt->layer();
|
||
csLay = chlayer;
|
||
delete [] chlayer;
|
||
if(ptPick.x < pMax.x && ptPick.y < pMax.y && ptPick.x > pMin.x && ptPick.y > pMin.y){
|
||
pEnt->close();
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
pEnt->close();
|
||
continue;
|
||
|
||
}
|
||
if(pIterator)
|
||
delete pIterator;
|
||
|
||
return csLay;
|
||
}
|
||
|
||
// add by xly on 110422 关闭图层
|
||
void CloseLayer(const TCHAR* szLay,int nOption)
|
||
{
|
||
CString csLayer = szLay;
|
||
if(csLayer == _T("0") || csLayer == _T("")){
|
||
adsout<< _T("\n0层不能关闭!");
|
||
return;
|
||
}
|
||
|
||
if (nOption==0)// 关闭图层
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(csLayer, pLayerRec))
|
||
{
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsOff(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
else if (nOption==1)// 冻结图层
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(csLayer, pLayerRec))
|
||
{
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsFrozen(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
|
||
if(csLayer.Find(_T("|AXIS")) > -1){
|
||
XSymbolList lstLayer2(_T("LAYER"));
|
||
int idx = csLayer.Find(_T("|AXIS"));
|
||
CString csTmp = csLayer.Left(idx);
|
||
csTmp += _T("|AXIS_TEXT");
|
||
if (nOption==0)// 关闭图层
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(csLayer, pLayerRec))
|
||
{
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsOff(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
else if (nOption==1)// 冻结
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(csLayer, pLayerRec))
|
||
{
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsFrozen(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
}
|
||
if(csLayer.Find(_T("|WINDOW")) > -1){
|
||
XSymbolList lstLayer2(_T("LAYER"));
|
||
int idx = csLayer.Find(_T("|WINDOW"));
|
||
CString csTmp = csLayer.Left(idx);
|
||
csTmp += _T("|WINDOW_TEXT");
|
||
|
||
if (nOption==0)// 关闭图层
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(csLayer, pLayerRec))
|
||
{
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsOff(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
else if (nOption==1)// 冻结
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(csLayer, pLayerRec))
|
||
{
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsFrozen(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// add by xly on 110422
|
||
void CloseLayerExtent(Entity entSel, int nOption)
|
||
{
|
||
CString csLayerRet = _T("");
|
||
if(!entSel.Is(_T("INSERT")))
|
||
return;
|
||
|
||
//外部参照
|
||
AcDbObjectId objId;
|
||
Acad::ErrorStatus es;
|
||
ads_point ptResult;
|
||
ads_name ent;
|
||
ads_matrix xformres;
|
||
resbuf* refstkres;
|
||
|
||
CString csLayer, csBlkLay;
|
||
TCHAR szLay[256];
|
||
while (1)
|
||
{
|
||
refstkres = NULL;
|
||
//直接选择子实体
|
||
int result = acedNEntSelP(_T("\n继续选择参照中要关闭的对象(注:只支持点选)<退出>:"), ent, ptResult, 0, xformres, &refstkres);
|
||
if (refstkres != NULL)
|
||
acutRelRb(refstkres);
|
||
if (result == RTNORM)
|
||
{
|
||
es = acdbGetObjectId(objId, ent);
|
||
if (es == Acad::eOk)
|
||
{
|
||
Entity ent2 = ent;
|
||
ent2.GetData(8, szLay);
|
||
csLayer = szLay;
|
||
TCHAR szClass[256];
|
||
ent2.GetData(0, szClass);
|
||
csLayerRet = szLay;
|
||
//如果参照的图块内图元图层为0层,取图块的图层
|
||
if(_tcsicmp(szLay, _T("0")) == 0)
|
||
{
|
||
AcDbObjectId ownID = NULL;
|
||
OPENOBJ_BEGIN(ent2, AcDb::kForRead, AcDbEntity, pEnt);
|
||
if(pEnt)
|
||
{
|
||
AcDbObjectId id2 = pEnt->ownerId();
|
||
OPENOBJ_BEGIN(id2, AcDb::kForRead, AcDbBlockTableRecord, pEnt2);
|
||
if(pEnt2)
|
||
{
|
||
const TCHAR *szBlkName = NULL;
|
||
pEnt2->getName(szBlkName);
|
||
CString csBlkName = szBlkName;
|
||
if(csBlkName.Find(_T("MODEL_SPACE")) < 0)
|
||
ownID = id2;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
OPENOBJ_END();
|
||
if(ownID != NULL)
|
||
csLayerRet = GetExternalBlkLayer(entSel, ptResult, ownID);
|
||
}
|
||
}
|
||
|
||
CloseLayer(csLayerRet,nOption);
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
BOOL SelectLayerOffForT20(XStringList &lstSelLay, XStringList &lstOtherLay, int &iWhichSel)
|
||
{
|
||
// 图层开关状态控制
|
||
static bool s_bIsOpen = true;
|
||
|
||
// 图层冻结状态控制
|
||
static bool s_bIsFreeze = true;
|
||
|
||
CString csPromt1 = _T(""), // 状态行提示
|
||
csPromt2 = _T("");
|
||
|
||
// 定义实体选择集
|
||
PickSet ss(SS_FREE);
|
||
|
||
// add by xly on 110104 存放用户点取点
|
||
int nRet(0);
|
||
if (iWhichSel == 0)
|
||
{
|
||
csPromt1 = _T("\n选择对象[关闭块参照或外部参照内部图层(Q)]<退出>:");
|
||
}
|
||
else if (iWhichSel==1)
|
||
{
|
||
csPromt1 = _T("\n选择对象[冻结块参照和外部参照内部图层(Q)]<退出>:");
|
||
}
|
||
while(1)
|
||
{
|
||
PickSet ssTemp(SS_FREE);
|
||
if (iWhichSel == 0) // 关闭图层
|
||
{
|
||
if (s_bIsOpen)// 关闭所在
|
||
{
|
||
TCHAR scKey = _T('Q');
|
||
nRet = SelectEnts(csPromt1,ssTemp, RBList(),_T("Q"));
|
||
if (nRet==RTKWORD)
|
||
{
|
||
s_bIsOpen = false;
|
||
Entity ent;
|
||
XPoint ptSel;
|
||
int nRet1(0);
|
||
// 定义实体的选择集
|
||
INITGET_BEG(0, _T("Q"));
|
||
nRet1 = SelectEntity1(_T("\n选择块参照或外部参照[关闭对象所在图层(Q)]<退出>:"), ent, ptSel, RBList(RTDXF0, _T("INSERT"), NULL));
|
||
INITGET_END();
|
||
if (nRet1 == RTKWORD)
|
||
{
|
||
csPromt1 = _T("\n选择对象[关闭块参照或外部参照内部图层(Q)]<退出>: ");
|
||
s_bIsOpen = true;
|
||
continue;
|
||
}
|
||
if (nRet1 == RTNORM)
|
||
{
|
||
CloseLayerExtent(ent,iWhichSel);
|
||
continue;;
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
else if (nRet == RTNORM)
|
||
{
|
||
ss += ssTemp;
|
||
ss.Redraw(3);
|
||
csPromt1 = _T("\n选择对象<退出>:");
|
||
}
|
||
else if (nRet == RTNONE)// 右键
|
||
{
|
||
break;
|
||
}
|
||
else if (nRet == RTCAN)// 取消操作退出命令
|
||
{
|
||
ss.Redraw(4);
|
||
return FALSE;
|
||
}
|
||
else if (nRet != RTERROR)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
else// 关闭内部
|
||
{
|
||
Entity ent;
|
||
XPoint ptSel;
|
||
int nRet1(0);
|
||
// 定义实体的选择集
|
||
INITGET_BEG(0, _T("Q"));
|
||
nRet1 = SelectEntity1(_T("\n选择块参照或外部参照[关闭对象所在图层(Q)]<退出>:"), ent, ptSel, RBList(RTDXF0, _T("INSERT"), NULL));
|
||
INITGET_END();
|
||
if (nRet1 == RTKWORD)
|
||
{
|
||
csPromt1 = _T("\n选择对象[关闭块参照或外部参照内部图层(Q)]<退出>: ");
|
||
s_bIsOpen = true;
|
||
continue;
|
||
}
|
||
if (nRet1 == RTNORM)
|
||
{
|
||
CloseLayerExtent(ent,iWhichSel);
|
||
continue;
|
||
}
|
||
else
|
||
break;
|
||
|
||
}
|
||
|
||
}
|
||
else if (iWhichSel == 1) // 冻结图层
|
||
{
|
||
if (s_bIsFreeze)// 冻结所在
|
||
{
|
||
TCHAR scKey = _T('Q');
|
||
nRet = SelectEnts(csPromt1,ssTemp, RBList(),_T("Q"));
|
||
if (nRet==RTKWORD)
|
||
{
|
||
s_bIsFreeze = false;
|
||
Entity ent;
|
||
XPoint ptSel;
|
||
int nRet1(0);
|
||
// 定义实体的选择集
|
||
INITGET_BEG(0, _T("Q"));
|
||
nRet1 = SelectEntity1(_T("\n选择块参照或外部参照[冻结对象所在图层(Q)]<退出>:"), ent, ptSel, RBList(RTDXF0, _T("INSERT"), NULL));
|
||
INITGET_END();
|
||
if (nRet1 == RTKWORD)
|
||
{
|
||
csPromt1 = _T("\n选择对象[冻结块参照或外部参照内部图层(Q)]<退出>: ");
|
||
s_bIsFreeze = true;
|
||
continue;
|
||
}
|
||
if (nRet1 == RTNORM)
|
||
{
|
||
CloseLayerExtent(ent,iWhichSel);
|
||
continue;
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
else if (nRet == RTNORM)
|
||
{
|
||
ss += ssTemp;
|
||
ss.Redraw(3);
|
||
csPromt1 = _T("\n选择对象<退出>:");
|
||
}
|
||
else if (nRet == RTNONE)// 右键
|
||
{
|
||
break;
|
||
}
|
||
else if (nRet == RTCAN)// 取消操作退出命令
|
||
{
|
||
ss.Redraw(4);
|
||
return FALSE;
|
||
}
|
||
else if (nRet != RTERROR)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
else// 冻结内部
|
||
{
|
||
Entity ent;
|
||
XPoint ptSel;
|
||
int nRet1(0);
|
||
// 定义实体的选择集
|
||
INITGET_BEG(0, _T("Q"));
|
||
nRet1 = SelectEntity1(_T("\n选择块参照或外部参照[冻结对象所在图层(Q)]<退出>:"), ent, ptSel, RBList(RTDXF0, _T("INSERT"), NULL));
|
||
INITGET_END();
|
||
if (nRet1 == RTKWORD)
|
||
{
|
||
csPromt1 = _T("\n选择对象[冻结块参照或外部参照内部图层(Q)]<退出>: ");
|
||
s_bIsFreeze = true;
|
||
continue;
|
||
}
|
||
if (nRet1 == RTNORM)
|
||
{
|
||
CloseLayerExtent(ent,iWhichSel);
|
||
continue;
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
// 将关闭和冻结的当前值传给一个变量控制
|
||
bool bFlag = true;
|
||
if (iWhichSel==0)
|
||
{
|
||
if (!s_bIsOpen)
|
||
{
|
||
bFlag = false;
|
||
}
|
||
}
|
||
else if (iWhichSel == 1)
|
||
{
|
||
if (!s_bIsFreeze)
|
||
{
|
||
bFlag = false;
|
||
}
|
||
}
|
||
|
||
CString csName = _T("");
|
||
if (bFlag) // 块参照所在的图层
|
||
{
|
||
for (long i=0; i<ss.Length(); i++)
|
||
{
|
||
OPENOBJ_BEGIN(ss[i], AcDb::kForRead, AcDbEntity, pEnt);
|
||
TDocAutoLock lock;
|
||
ASSERT(pEnt);
|
||
if (pEnt->isKindOf(TDbEntity::desc()) ||
|
||
pEnt->isKindOf(TDbCurveEntity::desc()) ||
|
||
pEnt->isKindOf(TDbBlockInsert::desc()))
|
||
{
|
||
//分解对象
|
||
AcDbVoidPtrArray entitySet;
|
||
pEnt->explode(entitySet);
|
||
AcDbEntity *pEntSon;
|
||
for (long i = 0; i < entitySet.length(); i++)
|
||
{
|
||
pEntSon = (AcDbEntity*)entitySet[i];
|
||
if (pEnt != NULL)
|
||
{
|
||
csName = pEntSon->layer();
|
||
}
|
||
if (lstSelLay.Index(csName, 0) < 0)
|
||
{
|
||
lstSelLay.Append(tstrnew(csName));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pEnt != NULL)
|
||
{
|
||
csName = pEnt->layer();
|
||
}
|
||
if (lstSelLay.Index(csName, 0) < 0)
|
||
{
|
||
lstSelLay.Append(tstrnew(csName));
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
|
||
// 层表
|
||
XSymbolList lstLayer(_T("LAYER"));
|
||
for (long i = 0; i<lstLayer.Length(); i++)
|
||
{
|
||
CString czLayer = lstLayer[i];
|
||
if (lstSelLay.Index(czLayer, 0) < 0)
|
||
{
|
||
lstOtherLay.Append(tstrnew(czLayer));
|
||
}
|
||
}
|
||
|
||
if (!XSymbolTable(_T("APPID"), APP_LAYERMANAGE))
|
||
{
|
||
acdbRegApp(APP_LAYERMANAGE);
|
||
}
|
||
ss.Redraw(4);
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
// 关闭、冻结图层, 添加 xly 100608 使该命令对图块和外部参照内的图层有效。
|
||
BOOL SelectLayerOff(XStringList &lstSelLay, XStringList &lstOtherLay, int &iWhichSel)
|
||
{
|
||
// 图层开关状态控制
|
||
static bool s_bIsOpen = true;
|
||
|
||
// 图层冻结状态控制
|
||
static bool s_bIsFreeze = true;
|
||
|
||
CString csPromt1 = _T(""), // 状态行提示
|
||
csPromt2 = _T("");
|
||
|
||
// 定义实体选择集
|
||
PickSet ss(SS_FREE);
|
||
|
||
// add by xly on 110104 存放用户点取点
|
||
int nRet(0);
|
||
if (iWhichSel == 0)
|
||
{
|
||
csPromt1 = _T("\n选择对象[关闭块参照或外部参照内部图层(Q)]<退出>:");
|
||
}
|
||
else if (iWhichSel==1)
|
||
{
|
||
csPromt1 = _T("\n选择对象[冻结块参照和外部参照内部图层(Q)]<退出>:");
|
||
}
|
||
while(1)
|
||
{
|
||
PickSet ssTemp(SS_FREE);
|
||
if (iWhichSel == 0) // 关闭图层
|
||
{
|
||
if (s_bIsOpen)// 关闭所在
|
||
{
|
||
TCHAR scKey = _T('Q');
|
||
nRet = SelectEnts(csPromt1,ssTemp, RBList(),_T("Q"));
|
||
if (nRet==RTKWORD)
|
||
{
|
||
s_bIsOpen = false;
|
||
Entity ent;
|
||
XPoint ptSel;
|
||
int nRet1(0);
|
||
// 定义实体的选择集
|
||
INITGET_BEG(0, _T("Q"));
|
||
nRet1 = SelectEntity1(_T("\n选择块参照或外部参照[关闭对象所在图层(Q)]<退出>:"), ent, ptSel, RBList(RTDXF0, _T("INSERT"), NULL));
|
||
INITGET_END();
|
||
if (nRet1 == RTKWORD)
|
||
{
|
||
csPromt1 = _T("\n选择对象[关闭块参照或外部参照内部图层(Q)]<退出>: ");
|
||
s_bIsOpen = true;
|
||
continue;
|
||
}
|
||
if (nRet1 == RTNORM)
|
||
{
|
||
CloseLayerExtent(ent,iWhichSel);
|
||
continue;;
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
else if (nRet == RTNORM)
|
||
{
|
||
ss += ssTemp;
|
||
ss.Redraw(3);
|
||
csPromt1 = _T("\n选择对象<退出>:");
|
||
}
|
||
else if (nRet == RTNONE)// 右键
|
||
{
|
||
break;
|
||
}
|
||
else if (nRet == RTCAN)// 取消操作退出命令
|
||
{
|
||
ss.Redraw(4);
|
||
return FALSE;
|
||
}
|
||
else if (nRet != RTERROR)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
else// 关闭内部
|
||
{
|
||
Entity ent;
|
||
XPoint ptSel;
|
||
int nRet1(0);
|
||
// 定义实体的选择集
|
||
INITGET_BEG(0, _T("Q"));
|
||
nRet1 = SelectEntity1(_T("\n选择块参照或外部参照[关闭对象所在图层(Q)]<退出>:"), ent, ptSel, RBList(RTDXF0, _T("INSERT"), NULL));
|
||
INITGET_END();
|
||
if (nRet1 == RTKWORD)
|
||
{
|
||
csPromt1 = _T("\n选择对象[关闭块参照或外部参照内部图层(Q)]<退出>: ");
|
||
s_bIsOpen = true;
|
||
continue;
|
||
}
|
||
if (nRet1 == RTNORM)
|
||
{
|
||
CloseLayerExtent(ent,iWhichSel);
|
||
continue;
|
||
}
|
||
else
|
||
break;
|
||
|
||
}
|
||
|
||
}
|
||
else if (iWhichSel == 1) // 冻结图层
|
||
{
|
||
if (s_bIsFreeze)// 冻结所在
|
||
{
|
||
TCHAR scKey = _T('Q');
|
||
nRet = SelectEnts(csPromt1,ssTemp, RBList(),_T("Q"));
|
||
if (nRet==RTKWORD)
|
||
{
|
||
s_bIsFreeze = false;
|
||
Entity ent;
|
||
XPoint ptSel;
|
||
int nRet1(0);
|
||
// 定义实体的选择集
|
||
INITGET_BEG(0, _T("Q"));
|
||
nRet1 = SelectEntity1(_T("\n选择块参照或外部参照[冻结对象所在图层(Q)]<退出>:"), ent, ptSel, RBList(RTDXF0, _T("INSERT"), NULL));
|
||
INITGET_END();
|
||
if (nRet1 == RTKWORD)
|
||
{
|
||
csPromt1 = _T("\n选择对象[冻结块参照或外部参照内部图层(Q)]<退出>: ");
|
||
s_bIsFreeze = true;
|
||
continue;
|
||
}
|
||
if (nRet1 == RTNORM)
|
||
{
|
||
CloseLayerExtent(ent,iWhichSel);
|
||
continue;
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
else if (nRet == RTNORM)
|
||
{
|
||
ss += ssTemp;
|
||
ss.Redraw(3);
|
||
csPromt1 = _T("\n选择对象<退出>:");
|
||
}
|
||
else if (nRet == RTNONE)// 右键
|
||
{
|
||
break;
|
||
}
|
||
else if (nRet == RTCAN)// 取消操作退出命令
|
||
{
|
||
ss.Redraw(4);
|
||
return FALSE;
|
||
}
|
||
else if (nRet != RTERROR)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
else// 冻结内部
|
||
{
|
||
Entity ent;
|
||
XPoint ptSel;
|
||
int nRet1(0);
|
||
// 定义实体的选择集
|
||
INITGET_BEG(0, _T("Q"));
|
||
nRet1 = SelectEntity1(_T("\n选择块参照或外部参照[冻结对象所在图层(Q)]<退出>:"), ent, ptSel, RBList(RTDXF0, _T("INSERT"), NULL));
|
||
INITGET_END();
|
||
if (nRet1 == RTKWORD)
|
||
{
|
||
csPromt1 = _T("\n选择对象[冻结块参照或外部参照内部图层(Q)]<退出>: ");
|
||
s_bIsFreeze = true;
|
||
continue;
|
||
}
|
||
if (nRet1 == RTNORM)
|
||
{
|
||
CloseLayerExtent(ent,iWhichSel);
|
||
continue;
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
// 将关闭和冻结的当前值传给一个变量控制
|
||
bool bFlag = true;
|
||
if (iWhichSel==0)
|
||
{
|
||
if (!s_bIsOpen)
|
||
{
|
||
bFlag = false;
|
||
}
|
||
}
|
||
else if (iWhichSel == 1)
|
||
{
|
||
if (!s_bIsFreeze)
|
||
{
|
||
bFlag = false;
|
||
}
|
||
}
|
||
|
||
CString csName = _T("");
|
||
if (bFlag) // 块参照所在的图层
|
||
{
|
||
for (long i=0; i<ss.Length(); i++)
|
||
{
|
||
OPENOBJ_BEGIN(ss[i], AcDb::kForRead, AcDbEntity, pEnt);
|
||
if (pEnt != NULL)
|
||
{
|
||
csName = pEnt->layer();
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
if (lstSelLay.Index(csName, 0) < 0)
|
||
{
|
||
lstSelLay.Append(tstrnew(csName));
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
// 层表
|
||
XSymbolList lstLayer(_T("LAYER"));
|
||
for (long i = 0; i<lstLayer.Length(); i++)
|
||
{
|
||
CString czLayer = lstLayer[i];
|
||
if (lstSelLay.Index(czLayer, 0) < 0)
|
||
{
|
||
lstOtherLay.Append(tstrnew(czLayer));
|
||
}
|
||
}
|
||
|
||
if (!XSymbolTable(_T("APPID"), APP_LAYERMANAGE))
|
||
{
|
||
acdbRegApp(APP_LAYERMANAGE);
|
||
}
|
||
ss.Redraw(4);
|
||
return TRUE;
|
||
}
|
||
|
||
// 将lstLayer组成一个图层列表,方便传递给-layer命令使用
|
||
CString GetAllNeedLayers(XStringList lstLayer)
|
||
{
|
||
CString csLayer = _T("");
|
||
|
||
int nLength = lstLayer.Length();
|
||
if (nLength > 0)
|
||
{
|
||
csLayer = lstLayer[0];
|
||
|
||
for (int i=1; i<nLength; i++)
|
||
{
|
||
csLayer += _T(",");
|
||
csLayer += lstLayer[i];
|
||
}
|
||
}
|
||
return csLayer;
|
||
}
|
||
|
||
// 判断一个图层是否被锁定、冻结或者关闭
|
||
bool IsNeedResetLayer(CString &csCurLayer, bool &bLock, bool &bFrozen, bool &bOff)
|
||
{
|
||
AcDbLayerTable *pLayertable = NULL;
|
||
if (acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead)!=Acad::eOk ||
|
||
pLayertable==NULL) // 获得层表
|
||
{
|
||
return false;
|
||
}
|
||
|
||
AcDbLayerTableRecord *pLayerTblRcd = NULL;
|
||
if (pLayertable->getAt(csCurLayer, pLayerTblRcd, AcDb::kForRead)!=Acad::eOk ||
|
||
pLayerTblRcd==NULL) // 获得层表记录
|
||
{
|
||
pLayertable->close();
|
||
return false;
|
||
}
|
||
|
||
bLock = pLayerTblRcd->isLocked(); // 判断层表记录是否锁定
|
||
bFrozen = pLayerTblRcd->isFrozen(); // 判断层表记录是否冻结
|
||
bOff = pLayerTblRcd->isOff(); // 判断层表记录是否关闭
|
||
|
||
pLayerTblRcd->close();
|
||
pLayertable->close();
|
||
return true;
|
||
}
|
||
|
||
// add by xly on 101229 判断图层是本地图层和外部参照图层,识别“|”“$”
|
||
bool IsExternalLayer(CString csLayerName)
|
||
{
|
||
if ((csLayerName.Find(_T('|')) == -1) && (csLayerName.Find(_T('$')) == -1)) // 本地图层
|
||
{
|
||
return false;
|
||
}
|
||
else // 外部参照图层
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
////////////////////////////////////////////////////////////////////////////
|
||
// 命令函数:关闭图层, 修改 xly 100608 使该命令对图块和外部参照内的图层有效
|
||
void OffLayer()
|
||
{
|
||
//XStringList lstSelLay, lstOtherLay;
|
||
//if (!SelectLayer(lstSelLay, lstOtherLay))
|
||
// return;
|
||
|
||
int iSel = 0; // 设置控制变量,0为关闭
|
||
XStringList lstSelLay, lstOtherLay;
|
||
|
||
// modify by xly on 110330 修改先选中后执行的错误
|
||
//if (!SelectLayerOff(lstSelLay, lstOtherLay, iSel)) // 获取选择集中的图层
|
||
// return;
|
||
if (g_ssPickFirst.Length()>0)
|
||
{
|
||
if (!SelectLayer(lstSelLay, lstOtherLay))
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
int iSel = 0; // 设置控制变量,0为关闭
|
||
if (!SelectLayerOffForT20(lstSelLay, lstOtherLay, iSel)) // 获取选择集中的图层
|
||
return;
|
||
}
|
||
|
||
for (int i=0; i<lstSelLay.Length(); i++)
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(lstSelLay[i], pLayerRec))
|
||
{
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsOff(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
}
|
||
|
||
// 命令函数:关闭其他
|
||
void OffOtherLayer()
|
||
{
|
||
XStringList lstSelLay, lstOtherLay;
|
||
if (!SelectLayerForT20(lstSelLay, lstOtherLay))
|
||
return;
|
||
|
||
for (int i=0; i<lstOtherLay.Length(); i++)
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(lstOtherLay[i], pLayerRec))
|
||
{
|
||
// sg add 110117,解决崩溃问题,为了提高速度,在PrepareLayer函数中读打开层表记录
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsOff(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
}
|
||
|
||
// 命令函数:打开图层
|
||
void OnLayer()
|
||
{
|
||
CAcModuleResourceOverride vTemp;
|
||
COpenLayer dlgOpen;
|
||
dlgOpen.m_bOpenorFreeze = true;
|
||
|
||
dlgOpen.DoModal();
|
||
}
|
||
|
||
// 命令函数:打开所有图层,[11/30/2007 nsh]
|
||
void OpenAllLayer()
|
||
{
|
||
AcDbLayerTable *pLayerTable = NULL;
|
||
AcDbLayerTableRecord *pLTRec = NULL;
|
||
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable, AcDb::kForRead);
|
||
if (pLayerTable != NULL)
|
||
{
|
||
// 使用迭代器,遍历所有的层表
|
||
AcDbLayerTableIterator *pLTIter = NULL;
|
||
pLayerTable->newIterator(pLTIter);
|
||
if (pLTIter != NULL)
|
||
{
|
||
for (pLTIter->start(); !pLTIter->done(); pLTIter->step())
|
||
{
|
||
pLTIter->getRecord(pLTRec, AcDb::kForWrite);
|
||
if (pLTRec != NULL)
|
||
{
|
||
if (pLTRec->isOff())
|
||
{
|
||
pLTRec->setIsOff(FALSE);
|
||
}
|
||
pLTRec->close();
|
||
}
|
||
}
|
||
delete pLTIter;
|
||
}
|
||
pLayerTable->close();
|
||
}
|
||
}
|
||
|
||
// 命令函数:冻结图层, 修改 xly 100609 使该命令对图块和外部参照内的图层有效
|
||
void FreezeLayer()
|
||
{
|
||
//XStringList lstSelLay, lstOtherLay;
|
||
//if (!SelectLayer(lstSelLay, lstOtherLay))
|
||
// return;
|
||
|
||
int iSel = 1; // 设置控制变量,1为冻结
|
||
XStringList lstSelLay, lstOtherLay;
|
||
|
||
// modify by xly on 110330 修改先选中后执行的错误
|
||
//if (!SelectLayerOff(lstSelLay, lstOtherLay, iSel)) // 获取选择的块中的图层
|
||
// return;
|
||
if (g_ssPickFirst.Length()>0)
|
||
{
|
||
if (!SelectLayer(lstSelLay, lstOtherLay))
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
if (!SelectLayerOff(lstSelLay, lstOtherLay, iSel)) // 获取选择的块中的图层
|
||
return;
|
||
}
|
||
for (int i=0; i<lstSelLay.Length(); i++)
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(lstSelLay[i], pLayerRec))
|
||
{
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->assertWriteEnabled();
|
||
pLayerRec->setIsFrozen(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
// 命令函数:冻结其他
|
||
void FreezeOtherLayer()
|
||
{
|
||
XStringList lstSelLay, lstOtherLay;
|
||
if (!SelectLayer(lstSelLay, lstOtherLay))
|
||
return;
|
||
|
||
for (int i=0; i<lstOtherLay.Length(); i++)
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(lstOtherLay[i], pLayerRec))
|
||
{
|
||
// sg add 110117,解决崩溃问题,为了提高速度,在PrepareLayer函数中读打开层表记录
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsFrozen(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
}
|
||
|
||
// 命令函数:解冻图层
|
||
void UnFreezeLayer()
|
||
{
|
||
CAcModuleResourceOverride vTemp;
|
||
COpenLayer dlgUnFreeze;
|
||
dlgUnFreeze.m_bOpenorFreeze = false;
|
||
|
||
dlgUnFreeze.DoModal();
|
||
}
|
||
|
||
// 命令函数:锁定图层
|
||
void LockLayer()
|
||
{
|
||
XStringList lstSelLay, lstOtherLay;
|
||
if (!SelectLayer(lstSelLay, lstOtherLay))
|
||
return;
|
||
|
||
for (int i=0; i<lstSelLay.Length(); i++)
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(lstSelLay[i], pLayerRec))
|
||
{
|
||
// sg add 110117,解决崩溃问题,为了提高速度,在PrepareLayer函数中读打开层表记录
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsLocked(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
#if ADS > 17
|
||
acedPostCommand(_T("-layer\n"));
|
||
acedPostCommand(_T("\33"));
|
||
acedPostCommand(_T("re\n"));
|
||
#endif
|
||
}
|
||
|
||
// 命令函数:锁定其他
|
||
void LockOtherLayer()
|
||
{
|
||
XStringList lstSelLay, lstOtherLay;
|
||
if (!SelectLayer(lstSelLay, lstOtherLay))
|
||
return;
|
||
|
||
for (int i=0; i<lstOtherLay.Length(); i++)
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(lstOtherLay[i], pLayerRec))
|
||
{
|
||
// sg add 110117,解决崩溃问题,为了提高速度,在PrepareLayer函数中读打开层表记录
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsLocked(true);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
for (int j=0; j<lstSelLay.Length(); j++)
|
||
{
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
if (PrepareLayer(lstSelLay[j], pLayerRec))
|
||
{
|
||
// sg add 110117,解决崩溃问题,为了提高速度,在PrepareLayer函数中读打开层表记录
|
||
pLayerRec->upgradeOpen();
|
||
pLayerRec->setIsLocked(false);
|
||
pLayerRec->close();
|
||
}
|
||
}
|
||
#if ADS > 17
|
||
acedPostCommand(_T("-layer\n"));
|
||
acedPostCommand(_T("\33"));
|
||
acedPostCommand(_T("re\n"));
|
||
#endif
|
||
}
|
||
|
||
// 命令函数:解锁图层
|
||
void UnLockLayer()
|
||
{
|
||
CString csLayer;
|
||
XStringList lstLock, lstUnLock; // 分别保存锁定,和选中的没有锁定的图层
|
||
|
||
int nRet(0);
|
||
bool bIsFirSel= true; // 标记是否是第一次选择
|
||
PickSet ss(SS_FREE), ssNew(SS_FREE);
|
||
CString csPrompt = _T("请选择要解锁图层上的对象(ESC退出) <全部>:"); // 状态行提示
|
||
|
||
while(1) // 获得选择集的结果
|
||
{
|
||
nRet = SelectEnts(csPrompt, ssNew, RBList(), _T(""));
|
||
if (bIsFirSel) // 第一次选择
|
||
{
|
||
if (nRet == RTNONE) // 全部解锁
|
||
{
|
||
ssNew.Redraw(4); // 更新显示
|
||
|
||
XSymbolList lstLayer(_T("LAYER"));
|
||
|
||
nRet = lstLayer.Length();
|
||
for (int i=0; i<nRet; i++)
|
||
{
|
||
csLayer = (const TCHAR *)lstLayer[i];
|
||
if (IsLockLayer(csLayer)) // 判断图层是否被锁定
|
||
lstLock.Append(tstrnew(csLayer));
|
||
}
|
||
break;
|
||
}
|
||
if (nRet != RTNORM) // 取消(ESC)、右键等操作
|
||
{
|
||
ssNew.Redraw(4); // 更新显示
|
||
return;
|
||
}
|
||
|
||
// 正常情况
|
||
csPrompt = _T("请选择要解锁图层上的对象<退出>:");
|
||
bIsFirSel = false;
|
||
|
||
ssNew.Redraw(3);
|
||
ss += ssNew;
|
||
continue;
|
||
}
|
||
else // 以后的选择
|
||
{
|
||
if (nRet == RTNORM) // 正常情况
|
||
{
|
||
ssNew.Redraw(3);
|
||
ss += ssNew ;
|
||
continue;
|
||
}
|
||
else if (nRet == RTCAN)// add by xly on 110427 按下ESC时退出选择
|
||
{
|
||
ss.Redraw(4);
|
||
ss.Free();
|
||
break;
|
||
}
|
||
else // 取消(ESC)、右键等操作
|
||
{
|
||
ss.Redraw(4);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
long lLength = ss.Length();
|
||
for (long j=0; j<lLength; j++) // 从选中的对象中获得锁定的图层
|
||
{
|
||
Entity ent = ss[j];
|
||
TCHAR szLay[256];
|
||
ent.GetData(8, szLay);
|
||
|
||
csLayer = szLay;
|
||
if (IsLockLayer(csLayer)) // 判断图层是否被锁定
|
||
{
|
||
if (lstLock.Index(szLay) < 0)
|
||
lstLock.Append(tstrnew(szLay));
|
||
}
|
||
else
|
||
{
|
||
if (lstUnLock.Index(szLay) < 0)
|
||
lstUnLock.Append(tstrnew(szLay));
|
||
}
|
||
}
|
||
|
||
// 获得图层列表
|
||
csLayer = GetAllNeedLayers(lstLock);
|
||
if (!csLayer.IsEmpty())
|
||
{
|
||
ads_command(RTSTR, _T("-layer"), RTSTR, _T("U"), RTSTR, csLayer, RTSTR, _T(""), RTNONE);
|
||
adsout << _T("\n") << (const TCHAR*)csLayer << _T("层已经解锁! ");
|
||
}
|
||
|
||
// 获得选中的对象所在的非锁定层
|
||
csLayer = GetAllNeedLayers(lstUnLock);
|
||
if (!csLayer.IsEmpty())
|
||
{
|
||
adsout << _T("\n") << (const TCHAR*)csLayer << _T("层本身就没有锁定! ");
|
||
}
|
||
}
|
||
|
||
// 命令函数:图层恢复1,只对上华命令操作过的层起作用
|
||
void ResetLayer()
|
||
{
|
||
TDocAutoLock lock;
|
||
AcDbLayerTable *pLayertableInUse = NULL;
|
||
Acad::ErrorStatus bError(Acad::eOk);
|
||
bError = acdbCurDwg()->getLayerTable(pLayertableInUse, AcDb::kForRead);
|
||
if (bError == Acad::eOk)
|
||
{
|
||
#if (ADS > 16)
|
||
pLayertableInUse->generateUsageData();
|
||
#endif
|
||
pLayertableInUse->close();
|
||
}
|
||
|
||
XSymbolList lstLayer(_T("LAYER"));
|
||
resbuf *pNull = acutBuildList(1001, APP_LAYERMANAGE, NULL);
|
||
bool bRegen = false;
|
||
|
||
bool bIsInUse(false);
|
||
for (int i=0; i<lstLayer.Length(); i++)
|
||
{
|
||
AcDbLayerTable *pLayertable = NULL;
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead);
|
||
if (!pLayertable)
|
||
continue;
|
||
|
||
CString szLayer = lstLayer[i];
|
||
if ((pLayertable->getAt(szLayer, pLayerRec, AcDb::kForWrite)) == Acad::eOk)
|
||
{
|
||
resbuf *pXD = pLayerRec->xData(APP_LAYERMANAGE);
|
||
if (pXD != NULL)
|
||
{
|
||
bool bOff, bFrozen, bLocked;
|
||
resbuf *pNext = pXD->rbnext;
|
||
if (pNext != NULL && pNext->restype == 1070)
|
||
{
|
||
bOff = !!pNext->resval.rint;
|
||
if (bOff != pLayerRec->isOff())
|
||
pLayerRec->setIsOff(bOff);
|
||
}
|
||
pNext = pNext->rbnext;
|
||
if (pNext != NULL && pNext->restype == 1070)
|
||
{
|
||
bFrozen = !!pNext->resval.rint;
|
||
if (bFrozen != pLayerRec->isFrozen())
|
||
{
|
||
pLayerRec->setIsFrozen(bFrozen);
|
||
bRegen = true;
|
||
}
|
||
}
|
||
pNext = pNext->rbnext;
|
||
if (pNext != NULL && pNext->restype == 1070)
|
||
{
|
||
bLocked = !!pNext->resval.rint;
|
||
if (bLocked != pLayerRec->isLocked())
|
||
{
|
||
#if (ADS > 16)
|
||
if (!bLocked && pLayerRec->isInUse())
|
||
{
|
||
bIsInUse = true;
|
||
}
|
||
#endif
|
||
pLayerRec->setIsLocked(bLocked);
|
||
}
|
||
}
|
||
acutRelRb(pXD);
|
||
pLayerRec->setXData(pNull);
|
||
}
|
||
pLayerRec->close();
|
||
}
|
||
pLayertable->close();
|
||
}
|
||
acutRelRb(pNull);
|
||
|
||
if (bRegen)
|
||
acedCommand(RTSTR, _T("REGEN"), RTNONE);
|
||
|
||
#if ADS > 17
|
||
{
|
||
if (bIsInUse)
|
||
{
|
||
acedPostCommand(_T("-layer\n"));
|
||
acedPostCommand(_T("\33"));
|
||
acedPostCommand(_T("re\n"));
|
||
}
|
||
}
|
||
#endif
|
||
|
||
}
|
||
|
||
// 命令函数:图层恢复2,对CAD操作过的层也起作用
|
||
void ResetAllLayer()
|
||
{
|
||
// modify by xly on 110506 修改图层恢复对很多个图层不起做用
|
||
//// 获得层表
|
||
//XSymbolList lstLayer(_T("LAYER"));
|
||
|
||
//CString csLayer;
|
||
//bool bLock, bFrozen, bOff;
|
||
//XStringList lstLock, lstFrozen, lstOff; // 分别保存锁定、冻结、关闭的图层
|
||
|
||
//int nLength = lstLayer.Length();
|
||
//for (int i=0; i<nLength; i++)
|
||
//{
|
||
// csLayer = (const TCHAR *)lstLayer[i];
|
||
// // 判断层表记录是否锁定、冻结、关闭
|
||
// if (IsNeedResetLayer(csLayer, bLock, bFrozen, bOff))
|
||
// {
|
||
// if (bLock) // 锁定
|
||
// lstLock.Append(tstrnew(csLayer));
|
||
// if (bFrozen) // 冻结
|
||
// lstFrozen.Append(tstrnew(csLayer));
|
||
// if (bOff) // 关闭
|
||
// lstOff.Append(tstrnew(csLayer));
|
||
// }
|
||
//}
|
||
//
|
||
//// 获得图层列表
|
||
//csLayer = GetAllNeedLayers(lstLock);
|
||
//if (!csLayer.IsEmpty())
|
||
//{
|
||
// ads_command(RTSTR, _T("-layer"), RTSTR, _T("U"), RTSTR, csLayer, RTNONE);
|
||
// ads_command(RTNONE);
|
||
// adsout << _T("\n") << (const TCHAR*)csLayer << _T("层已经解锁! ");
|
||
//}
|
||
|
||
//csLayer = GetAllNeedLayers(lstFrozen);
|
||
//if (!csLayer.IsEmpty())
|
||
//{
|
||
// ads_command(RTSTR, _T("-layer"), RTSTR, _T("T"), RTSTR, csLayer, RTNONE);
|
||
// ads_command(RTNONE);
|
||
// adsout << _T("\n") << (const TCHAR*)csLayer << _T("层已经解冻! ");
|
||
//}
|
||
|
||
//csLayer = GetAllNeedLayers(lstOff);
|
||
//if (!csLayer.IsEmpty())
|
||
//{
|
||
// ads_command(RTSTR, _T("-layer"), RTSTR, _T("ON"), RTSTR, csLayer, RTNONE);
|
||
// ads_command(RTNONE);
|
||
// adsout << _T("\n") << (const TCHAR*)csLayer << _T("层已经打开! ");
|
||
//}
|
||
// 获得层表
|
||
TDocAutoLock lock;
|
||
AcDbLayerTable *pLayertableInUse = NULL;
|
||
Acad::ErrorStatus bError(Acad::eOk);
|
||
bError = acdbCurDwg()->getLayerTable(pLayertableInUse, AcDb::kForRead);
|
||
|
||
// 定义层表遍历器
|
||
AcDbLayerTableIterator *pLayerItor = NULL;
|
||
if (bError == Acad::eOk)
|
||
{
|
||
#if (ADS > 16)
|
||
pLayertableInUse->generateUsageData();
|
||
#endif
|
||
pLayertableInUse->newIterator(pLayerItor);
|
||
pLayertableInUse->close();
|
||
}
|
||
if (!pLayerItor) return;
|
||
|
||
// 获得层表记录
|
||
AcDbLayerTableRecord *pLayerTblRcd = NULL;
|
||
bool bIsInUse(false);
|
||
// 遍历层表记录,查找冻结图层
|
||
for(; !pLayerItor->done(); pLayerItor->step())
|
||
{
|
||
pLayerItor->getRecord(pLayerTblRcd, AcDb::kForWrite);
|
||
if(pLayerTblRcd->isFrozen()) // 冻结
|
||
{
|
||
pLayerTblRcd->setIsFrozen(false);
|
||
}
|
||
if(pLayerTblRcd->isOff()) // 关闭
|
||
{
|
||
pLayerTblRcd->setIsOff(false);
|
||
}
|
||
if(pLayerTblRcd->isLocked()) // 锁定
|
||
{
|
||
#if (ADS > 16)
|
||
if (pLayerTblRcd->isInUse())
|
||
{
|
||
bIsInUse = true;
|
||
}
|
||
#endif
|
||
pLayerTblRcd->setIsLocked(false);
|
||
|
||
}
|
||
pLayerTblRcd->close();
|
||
}
|
||
delete pLayerItor;
|
||
|
||
|
||
// 更新显示
|
||
acedCommand(RTSTR, _T("REGEN"), RTNONE);
|
||
#if ADS > 17
|
||
{
|
||
if (bIsInUse)
|
||
{
|
||
acedPostCommand(_T("-layer\n"));
|
||
acedPostCommand(_T("\33"));
|
||
acedPostCommand(_T("re\n"));
|
||
}
|
||
}
|
||
#endif
|
||
}
|
||
|
||
// 命令函数:合并图层
|
||
void UniteLayer()
|
||
{
|
||
CAcModuleResourceOverride vTemp;
|
||
CUniteLayer dlgUniteLayer;
|
||
dlgUniteLayer.DoModal();
|
||
}
|
||
|
||
// 命令函数:图元改层
|
||
void ChangeLayer()
|
||
{
|
||
PickSet ssTemp(SS_FREE);
|
||
int nRet = SelectEnts(_T("\n请选择要改层的对象<退出>:"), ssTemp, RBList(), _T(""));
|
||
if (nRet == RTNORM)
|
||
{
|
||
ssTemp.Redraw(3); // 高亮显示
|
||
}
|
||
else
|
||
{
|
||
ssTemp.Redraw(4); // 取消亮显
|
||
return;
|
||
}
|
||
|
||
PickSet ss(SS_FREE);
|
||
SelectEntities(_T("\n请选择要改层的对象:"), ss, RBList());
|
||
ssTemp.Redraw(4); // 取消亮显
|
||
|
||
ss += ssTemp;
|
||
|
||
// 目标实体
|
||
TEntitySet ent;
|
||
// 点取位置
|
||
TADSGePoint3d ptSel;
|
||
|
||
// 目标图层名称
|
||
CString csGoalLayerName;
|
||
|
||
// 定义实体的选择集
|
||
INITGET_BEG(0, _T("N"));
|
||
nRet = SelectEntity1(_T("\n请选择目标图层的对象或[输入图层名(N)]<退出>:"), ent, ptSel, RBList());
|
||
INITGET_END();
|
||
if (nRet == RTKWORD) // 选择了关键字,调用目标图层对话框
|
||
{
|
||
// 调用目标图层对话框
|
||
CGoalLayerDlg dlg;
|
||
|
||
CAcModuleResourceOverride vTemp;
|
||
if (dlg.DoModal() == IDOK)
|
||
{
|
||
csGoalLayerName = dlg.GetGoalLayer();
|
||
}
|
||
else
|
||
return;
|
||
}
|
||
else if (nRet == RTNORM) // 选择正确
|
||
{
|
||
// 获得目标实体所在的图层
|
||
TCHAR szSelLay[256];
|
||
ent.GetData(8, szSelLay);
|
||
csGoalLayerName = szSelLay;
|
||
}
|
||
else
|
||
{
|
||
return;
|
||
}
|
||
|
||
// 记录多少个图元变层
|
||
nRet = 0;
|
||
|
||
// 将选择集中的实体传到对话框
|
||
bool bIsLocked = false;
|
||
for (long l = 0; l<ss.Length(); l++)
|
||
{
|
||
OPENOBJ_BEGIN(ss[l], AcDb::kForRead, AcDbEntity, pEnt);
|
||
if (pEnt != NULL)
|
||
{
|
||
// 获取层名
|
||
CString csCurLayer = pEnt->layer();
|
||
|
||
// 图层被锁定
|
||
if (::IsLockLayer(csCurLayer))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (pEnt->upgradeOpen() == Acad::eOk)
|
||
{
|
||
pEnt->setLayer(csGoalLayerName); // 设置目标图层
|
||
pEnt->downgradeOpen();
|
||
}
|
||
|
||
nRet++;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
if (bIsLocked)
|
||
{
|
||
acutPrintf(_T("\n锁定图层请解锁后再操作!"));
|
||
}
|
||
|
||
acutPrintf(_T("\n%d个对象被转换到%s图层!"), nRet, csGoalLayerName);
|
||
}
|
||
|
||
void InitNotCreatStandardLayer(CStdioFile *fp, std::vector<CString> &arNotCreatStandardLayer)
|
||
{
|
||
arNotCreatStandardLayer.clear();
|
||
CString sReadWords(_T(""));
|
||
while(fp->ReadString(sReadWords))
|
||
{
|
||
bool bAllIsBlank(false);
|
||
if (sReadWords.GetLength() > 0)
|
||
{
|
||
int i(0);
|
||
for (; i < sReadWords.GetLength(); ++i)
|
||
{
|
||
if (sReadWords.GetAt(i) != _T(' '))
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
if(i == sReadWords.GetLength())
|
||
{
|
||
bAllIsBlank = true; //不能全部为空格,必须含有一个字符
|
||
}
|
||
}
|
||
if (sReadWords.IsEmpty() || bAllIsBlank)
|
||
{
|
||
continue;
|
||
}
|
||
arNotCreatStandardLayer.push_back(sReadWords);
|
||
}
|
||
}
|
||
|
||
void ReadLayerFromTextFile(CStdioFile *fp, std::vector<SLayerStandardRecord*> &pLayerStandard, std::vector<CString> &arNotCreatStandardLayer)
|
||
{
|
||
pLayerStandard.clear();
|
||
CString sReadWords(_T(""));
|
||
CString StandardLayer[5];
|
||
int i(0), j(0), m(0); //i记录读出来的字符串的字符,j记录每行有几个词组,m记录每个词组的字符
|
||
bool bJudge(false);
|
||
while(fp->ReadString(sReadWords))
|
||
{
|
||
for (i = 0; i < 5; ++i)
|
||
{
|
||
StandardLayer[i].Format(_T(""));
|
||
}
|
||
if (!sReadWords.IsEmpty())
|
||
{
|
||
i = 0;
|
||
j = 0;
|
||
m = 0;
|
||
bJudge = false;
|
||
while(sReadWords[i] != '\0')
|
||
{
|
||
if (sReadWords[i] == ' ')
|
||
{
|
||
if (bJudge)
|
||
{
|
||
j++;
|
||
bJudge = false;
|
||
}
|
||
i++;
|
||
m = 0;
|
||
}
|
||
else
|
||
{
|
||
StandardLayer[j].Insert(m, sReadWords[i]);
|
||
i++;
|
||
m++;
|
||
bJudge = true;
|
||
}
|
||
}
|
||
//此条件需要lay文件保证图层标准信息只可以图层说明为空,其余4项均不能为空,
|
||
//如果其他项为空,则该函数实现细节需要重写
|
||
if (j >= 3)
|
||
{
|
||
bool bIsIn(false);
|
||
std::vector<CString>::iterator itrNot = arNotCreatStandardLayer.begin();
|
||
for (; itrNot != arNotCreatStandardLayer.end(); ++itrNot)
|
||
{
|
||
if (*itrNot == StandardLayer[0])
|
||
{
|
||
bIsIn = true;
|
||
break;
|
||
}
|
||
}
|
||
if (bIsIn)
|
||
{
|
||
continue;
|
||
}
|
||
SLayerStandardRecord *pStandardLayerRecord = new SLayerStandardRecord;
|
||
pStandardLayerRecord->sLayerKeyword = StandardLayer[0];
|
||
pStandardLayerRecord->sLayerName = StandardLayer[1];
|
||
pStandardLayerRecord->sColor = StandardLayer[2];
|
||
pStandardLayerRecord->sLineType = StandardLayer[3];
|
||
pStandardLayerRecord->sDescription = StandardLayer[4];
|
||
pLayerStandard.push_back(pStandardLayerRecord);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void GetAccmColorByString(CString sColor, AcCmColor &color)
|
||
{
|
||
int iColor(0);
|
||
bool bColor(false);
|
||
CString sSwap(sColor);
|
||
if (sSwap.Find(_T(',')) == -1) // 索引值
|
||
{
|
||
if(sSwap == _T("红"))
|
||
{
|
||
iColor = 1;
|
||
}
|
||
else if(sSwap == _T("黄"))
|
||
{
|
||
iColor = 2;
|
||
}
|
||
else if(sSwap == _T("绿"))
|
||
{
|
||
iColor = 3;
|
||
}
|
||
else if(sSwap == _T("青"))
|
||
{
|
||
iColor = 4;
|
||
}
|
||
else if(sSwap == _T("蓝"))
|
||
{
|
||
iColor = 5;
|
||
}
|
||
else if(sSwap == _T("洋红"))
|
||
{
|
||
iColor = 6;
|
||
}
|
||
else if(sSwap == _T("白") || sSwap == _T("黑"))
|
||
{
|
||
iColor = 7;
|
||
}
|
||
else if(sSwap == _T("BYLAYER"))
|
||
{
|
||
color.setColorMethod(AcCmEntityColor::kByLayer);
|
||
return;
|
||
}
|
||
else if(sSwap == _T("BYBLOCK"))
|
||
{
|
||
color.setColorMethod(AcCmEntityColor::kByBlock);
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
iColor = _ttoi(sColor);
|
||
}
|
||
}
|
||
else // RGB颜色值
|
||
{
|
||
bColor = true;
|
||
}
|
||
if (bColor)
|
||
{
|
||
int iIndex = sSwap.Find(',');
|
||
CString sR(sSwap.Left(iIndex));
|
||
sSwap = sSwap.Right(sSwap.GetLength() - iIndex - 1);
|
||
iIndex = sSwap.Find(',');
|
||
CString sG(sSwap.Left(iIndex));
|
||
CString sB(sSwap.Right(sSwap.GetLength() - iIndex - 1));
|
||
Acad::ErrorStatus bOk = color.setRGB(Adesk::UInt8(_ttoi(sR)), Adesk::UInt8(_ttoi(sG)), Adesk::UInt8(_ttoi(sB)));
|
||
}
|
||
else
|
||
{
|
||
color.setColorIndex(iColor);
|
||
}
|
||
}
|
||
|
||
AcDbObjectId GetIdByName(LPCTSTR name)
|
||
{
|
||
AcDbObjectId id = AcDbObjectId::kNull;
|
||
AcDbLinetypeTable *pTbl = NULL;
|
||
acdbCurDwg()->getSymbolTable(pTbl, AcDb::kForRead);
|
||
if (!pTbl) return id;
|
||
|
||
do
|
||
{
|
||
if (pTbl->has(name))
|
||
pTbl->getAt(name, id);
|
||
else
|
||
break;
|
||
} while (false);
|
||
|
||
pTbl->close();
|
||
return id;
|
||
}
|
||
|
||
bool ReadStandardLayerToJudgeWhetherPerform()
|
||
{
|
||
bool bReturn(false);
|
||
CRegProperty regProp(GetRegLocation(), _T(""));
|
||
regProp.SetTopRootKey(HKEY_LOCAL_MACHINE);
|
||
CString sInstallDirectory(_T(""));
|
||
if (!regProp.GetValue(_T("Location"), sInstallDirectory))
|
||
return false;
|
||
CFileFind finder;
|
||
CString sNotCreatStandardLayerPath = sInstallDirectory + _T("\\SYS\\TArchNotCreat.txt");
|
||
bool bIsExist = finder.FindFile(sNotCreatStandardLayerPath);
|
||
if (!bIsExist)
|
||
return true;
|
||
setlocale(0,"chs");
|
||
CStdioFile *fp(NULL);
|
||
fp = new CStdioFile(sNotCreatStandardLayerPath, CFile::modeRead);
|
||
CString sReadWords(_T(""));
|
||
fp->ReadString(sReadWords);
|
||
if (!sReadWords.CompareNoCase(_T("是否需要生成图层_No")))
|
||
bReturn = false;
|
||
else
|
||
bReturn = true;
|
||
fp->Close();
|
||
delete fp;
|
||
fp = NULL;
|
||
return bReturn;
|
||
}
|
||
|
||
void ReadStandardLayerToInitVector(std::vector<SLayerStandardRecord*> &arStandardLayerRecord)
|
||
{
|
||
CRegProperty regProp(GetRegLocation(), _T(""));
|
||
regProp.SetTopRootKey(HKEY_LOCAL_MACHINE);
|
||
CString sInstallDirectory(_T(""));
|
||
if (!regProp.GetValue(_T("Location"), sInstallDirectory))
|
||
{
|
||
return;
|
||
}
|
||
CString sStandardLayerPath = sInstallDirectory + _T("\\SYS\\LAYERDEF.DAT");
|
||
CFileFind finder;
|
||
BOOL bIsExist = finder.FindFile(sStandardLayerPath);
|
||
if (!bIsExist)
|
||
{
|
||
return;
|
||
}
|
||
CString sNotCreatStandardLayerPath = sInstallDirectory + _T("\\SYS\\TArchNotCreat.txt");
|
||
bIsExist = finder.FindFile(sNotCreatStandardLayerPath);
|
||
if (!bIsExist)
|
||
{
|
||
return;
|
||
}
|
||
setlocale(0,"chs");
|
||
CStdioFile *fp(NULL);
|
||
fp = new CStdioFile(sNotCreatStandardLayerPath, CFile::modeRead);
|
||
std::vector<CString> arNotCreatStandardLayer;
|
||
InitNotCreatStandardLayer(fp, arNotCreatStandardLayer);
|
||
fp->Close();
|
||
delete fp;
|
||
fp = NULL;
|
||
fp = new CStdioFile(sStandardLayerPath, CFile::modeRead);
|
||
ReadLayerFromTextFile(fp, arStandardLayerRecord, arNotCreatStandardLayer);
|
||
fp->Close();
|
||
delete fp;
|
||
fp = NULL;
|
||
}
|
||
|
||
void DeleteOldStandardLayerInCAD(std::vector<SLayerStandardRecord*> &arStandardBefore)
|
||
{
|
||
TDocAutoLock lock;
|
||
Acad::ErrorStatus bError(Acad::eOk);
|
||
AcDbLayerTable *pLayerTbl(NULL);
|
||
bError = acdbCurDwg()->getSymbolTable(pLayerTbl, AcDb::kForRead);
|
||
#if (ADS > 16)
|
||
pLayerTbl->generateUsageData();
|
||
#endif
|
||
pLayerTbl->close();
|
||
AcDbObjectId layerid(AcDbObjectId::kNull);
|
||
AcCmColor color;
|
||
AcDbLayerTableRecord *pLayerTableRecord(NULL);
|
||
std::vector<SLayerStandardRecord*>::iterator itrStandard = arStandardBefore.begin();
|
||
for (; itrStandard != arStandardBefore.end(); ++itrStandard)
|
||
{
|
||
bError = acdbCurDwg()->getSymbolTable(pLayerTbl, AcDb::kForWrite);
|
||
if (bError != Acad::eOk)
|
||
{
|
||
return;
|
||
}
|
||
bError = pLayerTbl->getAt((*itrStandard)->sLayerName, pLayerTableRecord, AcDb::kForWrite);
|
||
if (bError == Acad::eOk)
|
||
{
|
||
bError = pLayerTbl->close();
|
||
#if (ADS > 16)
|
||
if (!pLayerTableRecord->isInUse())
|
||
{
|
||
bError = pLayerTableRecord->erase();
|
||
}
|
||
#endif
|
||
bError = pLayerTableRecord->close();
|
||
}
|
||
else
|
||
{
|
||
bError = pLayerTbl->close();
|
||
}
|
||
}
|
||
}
|
||
|
||
void ChangeNewStandardLayerToUpdate(std::vector<SLayerStandardRecord*> &arStandardAfter)
|
||
{
|
||
TDocAutoLock lock;
|
||
Acad::ErrorStatus bError(Acad::eOk);
|
||
AcDbLayerTable *pLayerTbl(NULL);
|
||
AcDbObjectId layerid(AcDbObjectId::kNull);
|
||
AcCmColor color;
|
||
TCHAR buf[255];
|
||
AcDbLayerTableRecord *pLayerTableRecord(NULL);
|
||
std::vector<SLayerStandardRecord*>::iterator itrStandard = arStandardAfter.begin();
|
||
for (itrStandard = arStandardAfter.begin(); itrStandard != arStandardAfter.end(); ++itrStandard)
|
||
{
|
||
bError = acdbCurDwg()->getSymbolTable(pLayerTbl, AcDb::kForWrite);
|
||
if (bError != Acad::eOk)
|
||
{
|
||
return;
|
||
}
|
||
bError = pLayerTbl->getAt((*itrStandard)->sLayerName, pLayerTableRecord, AcDb::kForWrite);
|
||
if (bError == Acad::eOk)
|
||
{
|
||
bError = pLayerTbl->close();
|
||
bError = pLayerTableRecord->close();
|
||
}
|
||
else
|
||
{
|
||
AcDbLayerTableRecord *pLayerTblRcd = new AcDbLayerTableRecord;
|
||
bError = pLayerTbl->add(layerid, pLayerTblRcd);
|
||
bError = pLayerTblRcd->setName((*itrStandard)->sLayerName); //设定图层名
|
||
GetAccmColorByString((*itrStandard)->sColor, color);
|
||
pLayerTblRcd->setColor(color); //设定图层颜色
|
||
pLayerTblRcd->setLinetypeObjectId(GetIdByName((*itrStandard)->sLineType));
|
||
#if (ADS > 16)
|
||
wcscpy_s(buf, 255, (*itrStandard)->sDescription);
|
||
bError = pLayerTblRcd->setDescription(buf);
|
||
#else
|
||
_tcscpy(buf, (*itrStandard)->sDescription);
|
||
#endif
|
||
bError = pLayerTblRcd->setLineWeight(AcDb::LineWeight(AcDb::kLnWtByLwDefault)); //设定图层线宽
|
||
bError = pLayerTblRcd->setIsFrozen(false); //设定图层解冻
|
||
pLayerTblRcd->setIsOff(false); //设定图层打开
|
||
pLayerTblRcd->setIsLocked(false); //设定图层解锁
|
||
bError = pLayerTblRcd->setIsPlottable(true); //设定图层可以打印
|
||
pLayerTblRcd->setVPDFLT(false); //设定图层新视口打开
|
||
bError = pLayerTbl->close();
|
||
bError = pLayerTblRcd->close();
|
||
}
|
||
}
|
||
}
|
||
|
||
void ModifyStandardByOldLayerFile(std::vector<SLayerStandardRecord*> &arStandardAfter)
|
||
{
|
||
TDocAutoLock lock;
|
||
AcDbLayerTableRecord *pLayerTblRec(NULL);
|
||
std::vector<SLayerStandardRecord*>::iterator itrNew = arStandardAfter.begin();
|
||
AcCmColor color;
|
||
TCHAR buf[255];
|
||
Acad::ErrorStatus bError(Acad::eOk);
|
||
AcDbLayerTable *pLayerTbl(NULL);
|
||
for (; itrNew != arStandardAfter.end(); ++itrNew)
|
||
{
|
||
bError = acdbCurDwg()->getSymbolTable(pLayerTbl, AcDb::kForWrite);
|
||
if (bError != Acad::eOk)
|
||
{
|
||
return;
|
||
}
|
||
bError = pLayerTbl->getAt((*itrNew)->sLayerName, pLayerTblRec, AcDb::kForWrite);
|
||
if (bError == Acad::eOk)
|
||
{
|
||
GetAccmColorByString((*itrNew)->sColor, color);
|
||
pLayerTblRec->setColor(color); //设定图层颜色
|
||
pLayerTblRec->setLinetypeObjectId(GetIdByName((*itrNew)->sLineType));
|
||
#if (ADS > 16)
|
||
wcscpy_s(buf, 255, (*itrNew)->sDescription);
|
||
bError = pLayerTblRec->setDescription(buf);
|
||
#else
|
||
_tcscpy(buf, (*itrNew)->sDescription);
|
||
#endif
|
||
bError = pLayerTbl->close();
|
||
bError = pLayerTblRec->close();
|
||
}
|
||
else
|
||
{
|
||
bError = pLayerTbl->close();
|
||
}
|
||
//else
|
||
//{
|
||
//AcDbObjectId layerid(AcDbObjectId::kNull);
|
||
//AcDbLayerTableRecord *pLayerTblRcd = new AcDbLayerTableRecord;
|
||
//bError = pLayerTbl->add(layerid, pLayerTblRcd);
|
||
//bError = pLayerTblRcd->setName((*itrOld)->sLayerName); //设定图层名
|
||
//GetAccmColorByString((*itrOld)->sColor, color);
|
||
//pLayerTblRcd->setColor(color); //设定图层颜色
|
||
//pLayerTblRcd->setLinetypeObjectId(GetIdByName((*itrOld)->sLineType));
|
||
//wcscpy_s(buf, 255, (*itrOld)->sDescription);
|
||
//bError = pLayerTblRcd->setDescription(buf);
|
||
//bError = pLayerTblRcd->setLineWeight(AcDb::LineWeight(AcDb::kLnWtByLwDefault)); //设定图层线宽
|
||
//bError = pLayerTblRcd->setIsFrozen(false); //设定图层解冻
|
||
//pLayerTblRcd->setIsOff(false); //设定图层打开
|
||
//pLayerTblRcd->setIsLocked(false); //设定图层解锁
|
||
//bError = pLayerTblRcd->setIsPlottable(true); //设定图层可以打印
|
||
//pLayerTblRcd->setVPDFLT(false); //设定图层新视口打开
|
||
//bError = pLayerTbl->close();
|
||
//bError = pLayerTblRcd->close();
|
||
//}
|
||
}
|
||
}
|
||
|
||
|
||
void UpdateCADLayerByChangeStandardLayer(bool bNotChange, std::vector<SLayerStandardRecord*> &arStandardBefore)
|
||
{
|
||
std::vector<SLayerStandardRecord*> arStandardNew;
|
||
ReadStandardLayerToInitVector(arStandardNew);
|
||
if (bNotChange)
|
||
{
|
||
if (g_bLayerManagerModify)
|
||
{
|
||
ModifyStandardByOldLayerFile(arStandardNew);
|
||
//acedPostCommand(_T("TUpdateLayerManager\n"));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
DeleteOldStandardLayerInCAD(arStandardBefore);
|
||
ChangeNewStandardLayerToUpdate(arStandardNew);
|
||
//acedPostCommand(_T("TUpdateLayerManager\n"));
|
||
}
|
||
std::vector<SLayerStandardRecord*>::iterator itrStandard = arStandardNew.begin();
|
||
for (; itrStandard != arStandardNew.end(); ++itrStandard)
|
||
{
|
||
delete *itrStandard;
|
||
*itrStandard = NULL;
|
||
}
|
||
}
|
||
|
||
|
||
// 命令函数:图层管理 Add by lcf
|
||
void LayerManager()
|
||
{
|
||
int nCmdActive = 0;
|
||
xg_getvar(_T("CMDACTIVE"), &nCmdActive);
|
||
bool bActive = !nCmdActive ? false : true;
|
||
if (bActive)
|
||
acedPostCommand(_T("\33"));
|
||
CAcModuleResourceOverride vTemp;
|
||
if (ReadStandardLayerToJudgeWhetherPerform())
|
||
{
|
||
CString sTitleBefore(_T(""));
|
||
sTitleBefore.Format(_T("%s"),LAY_STD);
|
||
std::vector<SLayerStandardRecord*> arStandardBefore;
|
||
ReadStandardLayerToInitVector(arStandardBefore);
|
||
CLayerManager dlg;
|
||
dlg.DoModal();
|
||
CString sTitleAfter(_T(""));
|
||
sTitleAfter.Format(_T("%s"),LAY_STD);
|
||
UpdateCADLayerByChangeStandardLayer(!sTitleBefore.CompareNoCase(sTitleAfter), arStandardBefore);
|
||
std::vector<SLayerStandardRecord*>::iterator itrStandard = arStandardBefore.begin();
|
||
for (; itrStandard != arStandardBefore.end(); ++itrStandard)
|
||
{
|
||
delete *itrStandard;
|
||
*itrStandard = NULL;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
CLayerManager dlg;
|
||
dlg.DoModal();
|
||
}
|
||
}
|
||
|
||
// 命令函数:图层转换
|
||
void LayerConvert()
|
||
{
|
||
// sg modify 101112,根据8.5需求,为了提高图层转换的速度,进入命令后,临时关闭了数据库反应器
|
||
TPushMemVar<BOOL> pushVar(g_bMonitorDbAction, FALSE);
|
||
|
||
CAcModuleResourceOverride vTemp;
|
||
CLayerChangeDlg dlg;
|
||
dlg.DoModal();
|
||
}
|
||
|
||
////////////////////////////////////////////////
|
||
// TLayerGrid
|
||
TLayerGrid::TLayerGrid()
|
||
{
|
||
m_bModify = FALSE;
|
||
}
|
||
|
||
//add by whl
|
||
void TLayerGrid::OnBeforeRefresh(WDGridCell&cell)
|
||
{
|
||
if (cell.GetColIndex()==2)
|
||
{
|
||
CDC&dc=GetDC();
|
||
COLORREF color=acedGetRGB(cell.GetText());
|
||
dc.SetBkColor(color);
|
||
dc.SetTextColor(-color);
|
||
dc.SetBkMode(TRANSPARENT);
|
||
}
|
||
else
|
||
WDGrid::OnBeforeRefresh(cell);
|
||
}
|
||
|
||
bool TLayerGrid::OnCellButtonDown(WDGridCell&cell,CString&res)
|
||
{
|
||
if (cell.GetColIndex() == 2)
|
||
{
|
||
cell.Select();
|
||
int colorIndex = _ttoi(cell.GetText());
|
||
XString sCurLayer;
|
||
xg_getvar(_T("CLAYER"), sCurLayer);
|
||
AcDbObjectId idLayer = GetLayerIdFromString(sCurLayer);
|
||
int nCurColor = 7;
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer)
|
||
nCurColor = pLayer->color().colorIndex();
|
||
OPENOBJ_END();
|
||
|
||
if ( Adesk::kTrue == acedSetColorDialog(colorIndex, TRUE, nCurColor) )
|
||
{
|
||
if (colorIndex == 256)
|
||
colorIndex = nCurColor;
|
||
res.Format(_T("%d"),colorIndex);
|
||
AutoCloseCell(100);
|
||
return true;
|
||
}
|
||
else
|
||
cell.Refresh();
|
||
}
|
||
return false;
|
||
}
|
||
|
||
void ToUpper(TCHAR *p)
|
||
{
|
||
int i=0;
|
||
while(p[i++]!=_T('\0'))
|
||
{
|
||
if (p[i]>=_T('a') && p[i]<=_T('z'))
|
||
p[i]-=32;
|
||
|
||
}
|
||
}
|
||
|
||
void TLayerGrid::OnCellComboString(WDGridCell&cell,CComboBox&combo)
|
||
{
|
||
if (cell.GetColIndex()==1)
|
||
{
|
||
XSymbolList lstLayer(_T("LAYER"));
|
||
for (long i=0;i<lstLayer.Length();i++)
|
||
combo.AddString(lstLayer[i]);
|
||
}
|
||
else if (cell.GetColIndex()==3)//add by fxj 081225
|
||
{
|
||
AcDbLinetypeTable *pTable=NULL;
|
||
acdbOpenObject(pTable,acdbCurDwg()->linetypeTableId(),AcDb::kForRead);
|
||
if (pTable!=NULL)
|
||
{
|
||
AcDbLinetypeTableIterator *pIter=NULL;
|
||
pTable->newIterator(pIter);
|
||
pTable->close();
|
||
if (pIter!=NULL)
|
||
{
|
||
for (pIter->start();!pIter->done();pIter->step())
|
||
{
|
||
AcDbLinetypeTableRecord *pRecord=NULL;
|
||
pIter->getRecord(pRecord,AcDb::kForRead);
|
||
TCHAR *pszName=NULL;
|
||
pRecord->getName(pszName);
|
||
if (strcmp(_AS(pszName),"ByLayer")==0||strcmp(_AS(pszName),"ByBlock")==0)
|
||
continue;
|
||
ToUpper(pszName);
|
||
combo.AddString(pszName);
|
||
pRecord->close();
|
||
}
|
||
delete pIter;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
bool TLayerGrid::OnCellButtonTip(long row,long col,CString&res)const
|
||
{
|
||
if (col==4)
|
||
{
|
||
res=_T("选择颜色");
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
void TLayerGrid::OnDataChanged()
|
||
{
|
||
m_bModify = TRUE;
|
||
SendParentNotify(EN_CHANGE);
|
||
}
|
||
|
||
void TLayerGrid::SetModify( BOOL bModify )
|
||
{
|
||
m_bModify = bModify;
|
||
}
|
||
|
||
BOOL TLayerGrid::GetModify()
|
||
{
|
||
return m_bModify;
|
||
}
|
||
|
||
|
||
#if (ADS <= 16)
|
||
|
||
|
||
// CLayerManager 对话框
|
||
IMPLEMENT_DYNAMIC(CLayerManager, CAcUiDialog)
|
||
CLayerManager::CLayerManager(CWnd* pParent /*=NULL*/)
|
||
: CAcUiDialog(CLayerManager::IDD, pParent)
|
||
{
|
||
}
|
||
|
||
CLayerManager::~CLayerManager()
|
||
{
|
||
}
|
||
|
||
void CLayerManager::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CAcUiDialog::DoDataExchange(pDX);
|
||
DDX_Control(pDX, IDC_COMBO_STANDARD, m_standard);
|
||
}
|
||
|
||
BEGIN_MESSAGE_MAP(CLayerManager, CAcUiDialog)
|
||
ON_BN_CLICKED(IDC_BUTTON_SETCURRENT, OnBnClickedButtonSetcurrent)
|
||
ON_BN_CLICKED(IDC_BUTTON_NEW, OnBnClickedButtonNew)
|
||
ON_BN_CLICKED(IDC_BUTTON_CHANGE, OnBnClickedButtonChange)
|
||
ON_BN_CLICKED(IDC_BUTTON_COLOR, OnBnClickedButtonColor)
|
||
ON_CBN_SELCHANGE(IDC_COMBO_STANDARD, OnCbnSelchangeComboStandard)
|
||
ON_WM_CLOSE()
|
||
END_MESSAGE_MAP()
|
||
|
||
// CLayerManager 消息处理程序
|
||
BOOL CLayerManager::OnInitDialog()
|
||
{
|
||
CAcUiDialog::OnInitDialog();
|
||
|
||
m_szCurFile = GetFullPath(_T("layerdef.dat"));
|
||
InitGrid();
|
||
if (!m_grid.Create(this, IDC_LIST))
|
||
return FALSE;
|
||
|
||
UpdateGrid();
|
||
UpdateCombox();
|
||
m_standard.SetCurSel(0);
|
||
UpdateVisible();
|
||
|
||
return TRUE; // return TRUE unless you set the focus to a control
|
||
}
|
||
|
||
// 设为当前
|
||
void CLayerManager::OnBnClickedButtonSetcurrent()
|
||
{
|
||
SaveFile();
|
||
CString szCur = GetFullPath(_T("layerdef.dat"));
|
||
// Zyu modify on 100322, 将提示由"是否另存当前标准?"改为"是否保存当前标准?"
|
||
// if ( IDYES == MessageBox(_T("新图层标准将覆盖当前标准,是否另存当前标准?"), NULL, MB_YESNO) )
|
||
if ( IDYES == MessageBox(_T("新图层标准将覆盖当前标准,是否保存当前标准?"), NULL, MB_YESNO) )
|
||
{
|
||
CString szText;
|
||
m_standard.GetLBText(0,szText);
|
||
long i0=szText.Find(_T('(')),i1=szText.Find(_T(')'));
|
||
if (i1>i0)
|
||
szText=szText.Mid(i0+1,i1-i0-1);
|
||
if (szText == _T(""))
|
||
return;
|
||
|
||
CString szFullName = GetFullPath(szText);
|
||
if ( !CopyFile( szCur, szFullName, FALSE ) )
|
||
{
|
||
MessageBox(_T("保存当前标准失败!"));
|
||
return;
|
||
}
|
||
}
|
||
|
||
CopyFile( m_szCurFile, szCur, FALSE);
|
||
m_szCurFile=szCur;
|
||
UpdateCombox();
|
||
m_standard.SetCurSel(0);
|
||
UpdateVisible();
|
||
|
||
InitLayers(true);//更新内部图层数据
|
||
|
||
MessageBox(_T("当前图层标准已经改变,但原标准图层仍然存在。\n如果需要转换,请单击图层转换按钮。"));
|
||
}
|
||
|
||
// 新建标准
|
||
void CLayerManager::OnBnClickedButtonNew()
|
||
{
|
||
SaveFile();
|
||
CAcModuleResourceOverride vTemp;
|
||
CLayerStandardDlg dlg(this);
|
||
#if (ADS >= 20)
|
||
if ( IDOK != dlg.DoModal(WS_POPUP|WS_CAPTION|WS_BORDER, _T("新建标准"), this))
|
||
#else
|
||
if ( IDOK != dlg.DoModal())
|
||
#endif
|
||
return;
|
||
|
||
CString szText = _tcstok((TCHAR*)(const TCHAR*)dlg.m_szNewStandard, _T("."));
|
||
if (szText == _T(""))
|
||
return;
|
||
|
||
CString szFullName = GetFullPath(szText);
|
||
if ( PathFileExists(szFullName) )
|
||
{
|
||
MessageBox(_T("图层标准 \"") + szText + _T("\" 已存在"));
|
||
return;
|
||
}
|
||
if ( CopyFile( m_szCurFile, szFullName, FALSE ) )
|
||
{
|
||
m_szCurFile=szFullName;
|
||
m_standard.AddString( szText );
|
||
m_standard.SetCurSel(m_standard.GetCount()-1);
|
||
|
||
//add by whl
|
||
m_sStdName=szText;
|
||
WriteFile();
|
||
|
||
UpdateVisible();
|
||
}
|
||
}
|
||
|
||
// 图层转换
|
||
void CLayerManager::OnBnClickedButtonChange()
|
||
{
|
||
SaveFile();
|
||
EndDialog(IDOK);
|
||
|
||
XString sCmd=GetFullCmdName(_T("TLayerConvert"));
|
||
sCmd<<_T("\n");
|
||
acedPostCommand(sCmd);
|
||
}
|
||
|
||
// 颜色恢复
|
||
void CLayerManager::OnBnClickedButtonColor()
|
||
{
|
||
SaveFile();
|
||
EndDialog(IDOK);
|
||
|
||
XString sCmd=GetFullCmdName(_T("TResColor"));
|
||
sCmd<<_T("\n");
|
||
acedPostCommand(sCmd);
|
||
}
|
||
|
||
// 图层标准
|
||
void CLayerManager::OnCbnSelchangeComboStandard()
|
||
{
|
||
SaveFile();
|
||
CString szText;
|
||
if (m_standard.GetCurSel()>=0)
|
||
m_standard.GetLBText(m_standard.GetCurSel(), szText);
|
||
if ( m_standard.GetCurSel()==0)
|
||
m_szCurFile = GetFullPath(_T("layerdef.dat"));
|
||
else
|
||
m_szCurFile = GetFullPath(szText);
|
||
|
||
UpdateGrid();
|
||
UpdateVisible();
|
||
}
|
||
|
||
// 保存
|
||
void CLayerManager::OnOK()
|
||
{
|
||
SaveFile();
|
||
CAcUiDialog::OnOK();
|
||
}
|
||
|
||
void CLayerManager::OnClose()
|
||
{
|
||
SaveFile();
|
||
CAcUiDialog::OnClose();
|
||
}
|
||
|
||
void CLayerManager::UpdateCombox()
|
||
{
|
||
m_standard.ResetContent();
|
||
|
||
XStringList lstFiles;
|
||
CString szSysPath = GetFullPath(_T(""));
|
||
FindFiles(szSysPath, _T("*.lay"), lstFiles, TRUE);
|
||
CString sTitle;
|
||
sTitle.Format(_T("当前标准(%s)"),m_sStdName);
|
||
m_standard.AddString(sTitle);
|
||
for (int i=0; i<lstFiles.Length(); i++)
|
||
{
|
||
CString szFile = _tcstok(lstFiles[i], _T("."));
|
||
m_standard.AddString(szFile);
|
||
}
|
||
}
|
||
|
||
void CLayerManager::InitGrid()
|
||
{
|
||
m_grid.SetTreeLine();
|
||
m_grid.SetColFixLength();
|
||
m_grid.SetColPosFix();
|
||
m_grid.SetRowPosFix();
|
||
m_grid.SetRowFixLength();
|
||
m_grid.SetNoDefaultMenu();
|
||
m_grid.FitLastCol();
|
||
m_grid.AppendCol(_T("图层关键字"),100);
|
||
m_grid.AppendCol(_T("图层名"),100);
|
||
m_grid.AppendCol(_T("颜色"),45);
|
||
m_grid.AppendCol(_T("线型"),100);//add by fxj 081225
|
||
m_grid.AppendCol(_T("备注"),60);
|
||
m_grid.GetCol(0).SetReadOnly();
|
||
m_grid.GetCol(0).SetBackColor(GetSysColor(COLOR_3DFACE));
|
||
m_grid.GetCol(1).SetComboEdit();
|
||
m_grid.GetCol(2).SetRightButton();
|
||
m_grid.GetCol(3).SetComboEdit();//add by fxj 081225
|
||
}
|
||
|
||
void CLayerManager::UpdateGrid()
|
||
{
|
||
m_grid.Clear();
|
||
ReadFile();
|
||
m_grid.FitLastCol();
|
||
}
|
||
|
||
//modified by whl
|
||
void CLayerManager::UpdateVisible()
|
||
{
|
||
if (m_standard.GetCurSel()==0)
|
||
{
|
||
GetDlgItem(IDC_BUTTON_SETCURRENT)->EnableWindow(FALSE);
|
||
GetDlgItem(IDC_BUTTON_COLOR)->EnableWindow(TRUE);
|
||
}
|
||
else
|
||
{
|
||
GetDlgItem(IDC_BUTTON_SETCURRENT)->EnableWindow(TRUE);
|
||
GetDlgItem(IDC_BUTTON_COLOR)->EnableWindow(FALSE);
|
||
}
|
||
}
|
||
|
||
void CLayerManager::SaveFile()
|
||
{
|
||
if ( !m_grid.GetModify() )
|
||
return;
|
||
|
||
m_grid.SetModify( FALSE );
|
||
if ( IDYES == MessageBox(_T("是否保存当前修改?"), NULL, MB_YESNO) )
|
||
{
|
||
g_bLayerManagerModify = true;
|
||
WriteFile();
|
||
}
|
||
}
|
||
|
||
BOOL CLayerManager::ReadFile()
|
||
{
|
||
if (m_szCurFile == _T(""))
|
||
m_szCurFile = GetFullPath(_T("layerdef.dat"));
|
||
if ( !PathFileExists(m_szCurFile) )
|
||
{
|
||
CFile file(m_szCurFile, CFile::modeCreate);
|
||
file.Close();
|
||
}
|
||
|
||
CStdioFile file;
|
||
if (!file.Open(m_szCurFile, CFile::modeRead))
|
||
{
|
||
AfxMessageBox(CString(_T("打开文件 \"")) + m_szCurFile + _T("\" 失败"));
|
||
return FALSE;
|
||
}
|
||
CString sString;
|
||
while(file.ReadString(sString))
|
||
{
|
||
TCHAR sKey[256] = _T("");
|
||
TCHAR sName[256] = _T("");
|
||
int nColor = 0;
|
||
|
||
//modified by fxj 081225
|
||
|
||
TCHAR sLineType[256] = _T("");
|
||
TCHAR sNote[256] = _T("");
|
||
_stscanf(sString, _T("%s%s%d%s%s"), sKey, sName, &nColor, sLineType, sNote);
|
||
|
||
//modified by whl
|
||
if (_tcscmp(sKey,_T("图层标准"))==0)
|
||
m_sStdName=sName;
|
||
else
|
||
{
|
||
WDGridRow *pRow = new WDGridRow(m_grid);
|
||
(*pRow)[0].SetText(sKey);
|
||
(*pRow)[1].SetText(sName);
|
||
(*pRow)[2].SetText(XString(_T("%d"), nColor));
|
||
(*pRow)[3].SetText(sLineType);
|
||
(*pRow)[4].SetText(sNote);
|
||
m_grid.AppendRow(pRow);
|
||
}
|
||
}
|
||
file.Close();
|
||
return TRUE;
|
||
}
|
||
|
||
//modified by whl,解决多最后空行等问题
|
||
BOOL CLayerManager::WriteFile()
|
||
{
|
||
CStdioFile file;
|
||
if (!file.Open(m_szCurFile, CFile::modeWrite))
|
||
{
|
||
AfxMessageBox(CString(_T("无法保存,打开文件 \"")) + m_szCurFile + _T("\" 失败"));
|
||
return FALSE;
|
||
}
|
||
|
||
file.SetLength(0);
|
||
file.Flush();
|
||
|
||
//第一行写入图层标准名
|
||
CString sString;
|
||
sString.Format(_T("图层标准 %s\n"),m_sStdName);
|
||
file.WriteString(sString);
|
||
|
||
//modified by fxj 081225
|
||
for (int i=0; i<m_grid.GetRowNum(); i++)
|
||
{
|
||
CString sKey = m_grid.GetCell(i, 0).GetText();
|
||
CString sName = m_grid.GetCell(i, 1).GetText();
|
||
int nColor = _ttoi(m_grid.GetCell(i, 2).GetText());
|
||
CString sLineType = m_grid.GetCell(i, 3).GetText();
|
||
CString sNote = m_grid.GetCell(i, 4).GetText();
|
||
|
||
if (i<m_grid.GetRowNum()-1)
|
||
sString.Format(_T("%s %s %d %s %s\n"), sKey, sName, nColor, sLineType, sNote);
|
||
else
|
||
sString.Format(_T("%s %s %d %s %s"), sKey, sName, nColor, sLineType, sNote);
|
||
file.WriteString(sString);
|
||
}
|
||
file.Close();
|
||
|
||
//add by whl,当前标准更新后应实时更新内部数据
|
||
if (m_standard.GetCurSel()==0)
|
||
InitLayers(TRUE);
|
||
return TRUE;
|
||
}
|
||
|
||
CString CLayerManager::GetFullPath(const TCHAR *szFileName)
|
||
{
|
||
// Zyu modify on 100730,适应64位平台的文件夹名称变化
|
||
//CString szFullPath = g_sAppPath;
|
||
CString szFullPath = g_sDwbPath;
|
||
|
||
if(_tcscmp(szFileName, _T("")) == 0)
|
||
{
|
||
//szFullPath = szFullPath.Left(szFullPath.GetLength() - 7) + _T("\\sys\\");
|
||
szFullPath = szFullPath.Left(szFullPath.GetLength() - 5) + _T("\\sys\\");
|
||
}
|
||
else
|
||
{
|
||
//szFullPath = szFullPath.Left(szFullPath.GetLength() - 7) + _T("\\sys\\") + szFileName;
|
||
szFullPath = szFullPath.Left(szFullPath.GetLength() - 5) + _T("\\sys\\") + szFileName;
|
||
|
||
// sg modify 100514,有Bug,只需要判断文件名中是否含有“.”,全路径中应该允许有“.”
|
||
// if (szFullPath.Find(_T(".")) == -1)
|
||
CString csTmp = szFileName;
|
||
if (csTmp.Find(_T(".")) == -1)
|
||
szFullPath += _T(".lay");
|
||
}
|
||
|
||
return szFullPath;
|
||
}
|
||
#else
|
||
IMPLEMENT_DYNAMIC(CLayerManager, CModelessDialog)
|
||
|
||
BEGIN_MESSAGE_MAP(CLayerManager, CModelessDialog)
|
||
ON_BN_CLICKED(IDC_BUTTON_SETCURRENT, OnBnClickedButtonSetcurrent)
|
||
ON_BN_CLICKED(IDC_BUTTON_NEW, OnBnClickedButtonNew)
|
||
ON_BN_CLICKED(IDC_BUTTON_CHANGE, OnBnClickedButtonChange)
|
||
ON_BN_CLICKED(IDC_BUTTON_COLOR, OnBnClickedButtonColor)
|
||
ON_CBN_SELCHANGE(IDC_COMBO_STANDARD, OnCbnSelchangeComboStandard)
|
||
ON_WM_CLOSE()
|
||
END_MESSAGE_MAP()
|
||
|
||
CLayerManager::CLayerManager( CWnd *pParent /*= NULL*/ ): CModelessDialog(false)
|
||
{
|
||
g_bLayerManagerModify = false;
|
||
}
|
||
|
||
CLayerManager::~CLayerManager() { }
|
||
|
||
void CLayerManager::InitGrid()
|
||
{
|
||
m_grid.SetTreeLine();
|
||
m_grid.SetColFixLength();
|
||
m_grid.SetColPosFix();
|
||
m_grid.SetRowPosFix();
|
||
m_grid.SetRowFixLength();
|
||
m_grid.SetNoDefaultMenu();
|
||
m_grid.FitLastCol();
|
||
m_grid.AppendCol(_T("图层关键字"),100);
|
||
m_grid.AppendCol(_T("图层名"),100);
|
||
m_grid.AppendCol(_T("颜色"),45);
|
||
m_grid.AppendCol(_T("线型"),100);//add by fxj 081225
|
||
m_grid.AppendCol(_T("备注"),60);
|
||
m_grid.GetCol(0).SetReadOnly();
|
||
m_grid.GetCol(0).SetBackColor(GetSysColor(COLOR_3DFACE));
|
||
m_grid.GetCol(1).SetComboEdit();
|
||
m_grid.GetCol(2).SetRightButton();
|
||
m_grid.GetCol(3).SetComboEdit();//add by fxj 081225
|
||
}
|
||
|
||
void CLayerManager::UpdateGrid()
|
||
{
|
||
m_grid.Clear();
|
||
ReadFile();
|
||
m_grid.FitLastCol();
|
||
}
|
||
|
||
void CLayerManager::UpdateVisible()
|
||
{
|
||
if (m_standard.GetCurSel()==0)
|
||
{
|
||
GetDlgItem(IDC_BUTTON_SETCURRENT)->EnableWindow(FALSE);
|
||
GetDlgItem(IDC_BUTTON_COLOR)->EnableWindow(TRUE);
|
||
}
|
||
else
|
||
{
|
||
GetDlgItem(IDC_BUTTON_SETCURRENT)->EnableWindow(TRUE);
|
||
GetDlgItem(IDC_BUTTON_COLOR)->EnableWindow(FALSE);
|
||
}
|
||
}
|
||
|
||
void CLayerManager::UpdateCombox()
|
||
{
|
||
m_standard.ResetContent();
|
||
|
||
XStringList lstFiles;
|
||
CString szSysPath = GetFullPath(_T(""));
|
||
FindFiles(szSysPath, _T("*.lay"), lstFiles, TRUE);
|
||
CString sTitle;
|
||
sTitle.Format(_T("当前标准(%s)"),m_sStdName);
|
||
m_standard.AddString(sTitle);
|
||
for (int i=0; i<lstFiles.Length(); i++)
|
||
{
|
||
CString szFile = _tcstok(lstFiles[i], _T("."));
|
||
m_standard.AddString(szFile);
|
||
}
|
||
}
|
||
|
||
void CLayerManager::SaveFile()
|
||
{
|
||
if ( !m_grid.GetModify() )
|
||
return;
|
||
|
||
m_grid.SetModify( FALSE );
|
||
if ( IDYES == MessageBox(_T("是否保存当前修改?"), NULL, MB_YESNO) )
|
||
{
|
||
g_bLayerManagerModify = true;
|
||
WriteFile();
|
||
}
|
||
}
|
||
|
||
BOOL CLayerManager::ReadFile()
|
||
{
|
||
if (m_szCurFile == _T(""))
|
||
m_szCurFile = GetFullPath(_T("layerdef.dat"));
|
||
if ( !PathFileExists(m_szCurFile) )
|
||
{
|
||
CFile file(m_szCurFile, CFile::modeCreate);
|
||
file.Close();
|
||
}
|
||
|
||
CStdioFile file;
|
||
if (!file.Open(m_szCurFile, CFile::modeRead))
|
||
{
|
||
AfxMessageBox(CString(_T("打开文件 \"")) + m_szCurFile + _T("\" 失败"));
|
||
return FALSE;
|
||
}
|
||
CString sString;
|
||
while(file.ReadString(sString))
|
||
{
|
||
TCHAR sKey[256] = _T("");
|
||
TCHAR sName[256] = _T("");
|
||
int nColor = 0;
|
||
|
||
//modified by fxj 081225
|
||
|
||
TCHAR sLineType[256] = _T("");
|
||
TCHAR sNote[256] = _T("");
|
||
_stscanf(sString, _T("%s%s%d%s%s"), sKey, sName, &nColor, sLineType, sNote);
|
||
|
||
//modified by whl
|
||
if (_tcscmp(sKey,_T("图层标准"))==0)
|
||
m_sStdName=sName;
|
||
else
|
||
{
|
||
WDGridRow *pRow = new WDGridRow(m_grid);
|
||
(*pRow)[0].SetText(sKey);
|
||
(*pRow)[1].SetText(sName);
|
||
(*pRow)[2].SetText(XString(_T("%d"), nColor));
|
||
(*pRow)[3].SetText(sLineType);
|
||
(*pRow)[4].SetText(sNote);
|
||
m_grid.AppendRow(pRow);
|
||
}
|
||
}
|
||
file.Close();
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL CLayerManager::WriteFile()
|
||
{
|
||
CStdioFile file;
|
||
if (!file.Open(m_szCurFile, CFile::modeWrite))
|
||
{
|
||
AfxMessageBox(CString(_T("无法保存,打开文件 \"")) + m_szCurFile + _T("\" 失败"));
|
||
return FALSE;
|
||
}
|
||
|
||
file.SetLength(0);
|
||
file.Flush();
|
||
|
||
//第一行写入图层标准名
|
||
CString sString;
|
||
sString.Format(_T("图层标准 %s\n"),m_sStdName);
|
||
file.WriteString(sString);
|
||
|
||
//modified by fxj 081225
|
||
for (int i=0; i<m_grid.GetRowNum(); i++)
|
||
{
|
||
CString sKey = m_grid.GetCell(i, 0).GetText();
|
||
CString sName = m_grid.GetCell(i, 1).GetText();
|
||
int nColor = _ttoi(m_grid.GetCell(i, 2).GetText());
|
||
CString sLineType = m_grid.GetCell(i, 3).GetText();
|
||
CString sNote = m_grid.GetCell(i, 4).GetText();
|
||
|
||
if (i<m_grid.GetRowNum()-1)
|
||
sString.Format(_T("%s %s %d %s %s\n"), sKey, sName, nColor, sLineType, sNote);
|
||
else
|
||
sString.Format(_T("%s %s %d %s %s"), sKey, sName, nColor, sLineType, sNote);
|
||
file.WriteString(sString);
|
||
}
|
||
file.Close();
|
||
|
||
//add by whl,当前标准更新后应实时更新内部数据
|
||
if (m_standard.GetCurSel()==0)
|
||
InitLayers(TRUE);
|
||
return TRUE;
|
||
}
|
||
|
||
CString CLayerManager::GetFullPath( const TCHAR *szFileName )
|
||
{
|
||
// Zyu modify on 100730,适应64位平台的文件夹名称变化
|
||
//CString szFullPath = g_sAppPath;
|
||
CString szFullPath = g_sDwbPath;
|
||
|
||
if(_tcscmp(szFileName, _T("")) == 0)
|
||
{
|
||
//szFullPath = szFullPath.Left(szFullPath.GetLength() - 7) + _T("\\sys\\");
|
||
szFullPath = szFullPath.Left(szFullPath.GetLength() - 5) + _T("\\sys\\");
|
||
}
|
||
else
|
||
{
|
||
//szFullPath = szFullPath.Left(szFullPath.GetLength() - 7) + _T("\\sys\\") + szFileName;
|
||
szFullPath = szFullPath.Left(szFullPath.GetLength() - 5) + _T("\\sys\\") + szFileName;
|
||
|
||
// sg modify 100514,有Bug,只需要判断文件名中是否含有“.”,全路径中应该允许有“.”
|
||
// if (szFullPath.Find(_T(".")) == -1)
|
||
CString csTmp = szFileName;
|
||
if (csTmp.Find(_T(".")) == -1)
|
||
szFullPath += _T(".lay");
|
||
}
|
||
|
||
return szFullPath;
|
||
}
|
||
|
||
void CLayerManager::DoDataExchange( CDataExchange* pDX )
|
||
{
|
||
CDialog::DoDataExchange(pDX);
|
||
// DDX_Control(pDX, IDC_COMBO_STANDARD, m_standard);
|
||
}
|
||
|
||
BOOL CLayerManager::OnInitDialog()
|
||
{
|
||
MoveWindow(CRect(CPoint(0, 0), CSize(660, 403)));
|
||
CenterWindow();
|
||
//m_staticTxt.Create(_T("图层标准:"), WS_VISIBLE|WS_CHILD, CRect(CPoint(10, 10), CSize(60, 11)), this);
|
||
|
||
m_btnSetCur.Create(_T("置为当前标准"), WS_VISIBLE|WS_CHILD, CRect(CPoint(404, 12), CSize(95, 21)), this, IDC_BUTTON_SETCURRENT);
|
||
m_btnNewRule.Create(_T("新建标准"), WS_VISIBLE|WS_CHILD, CRect(CPoint(536, 12), CSize(72, 21)), this, IDC_BUTTON_NEW);
|
||
m_btnLayChange.Create(_T("图层转换"), WS_VISIBLE|WS_CHILD, CRect(CPoint(390, 370), CSize(75,21)), this, IDC_BUTTON_CHANGE);
|
||
m_btnClrRecover.Create(_T("颜色恢复"), WS_VISIBLE|WS_CHILD, CRect(CPoint(483, 370), CSize(75, 21)), this, IDC_BUTTON_COLOR);
|
||
m_btnClose.Create(_T("关闭"), WS_VISIBLE|WS_CHILD, CRect(CPoint(573, 370), CSize(75, 21)), this, IDOK);
|
||
m_lstBox.Create(LBS_SORT|LBS_NOINTEGRALHEIGHT|WS_VSCROLL|WS_TABSTOP, CRect(CPoint(11, 39), CSize(638, 324)), this, IDC_LIST);
|
||
m_standard.Create(WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST|WS_VSCROLL|WS_TABSTOP, CRect(CPoint(12, 12), CSize(355, 20)), this, IDC_COMBO_STANDARD);
|
||
|
||
m_szCurFile = GetFullPath(_T("layerdef.dat"));
|
||
InitGrid();
|
||
if (!m_grid.Create(this, IDC_LIST))
|
||
return FALSE;
|
||
UpdateGrid();
|
||
|
||
UpdateCombox();
|
||
m_standard.SetCurSel(0);
|
||
|
||
UpdateVisible();
|
||
|
||
return CModelessDialog::OnInitDialog();
|
||
}
|
||
|
||
void CLayerManager::OnOK()
|
||
{
|
||
SaveFile();
|
||
CModelessDialog::OnOK();
|
||
}
|
||
|
||
void CLayerManager::OnClose()
|
||
{
|
||
SaveFile();
|
||
CModelessDialog::OnClose();
|
||
}
|
||
|
||
void CLayerManager::OnBnClickedButtonSetcurrent()
|
||
{
|
||
SaveFile();
|
||
CString szCur = GetFullPath(_T("layerdef.dat"));
|
||
// Zyu modify on 100322, 将提示由"是否另存当前标准?"改为"是否保存当前标准?"
|
||
// if ( IDYES == MessageBox(_T("新图层标准将覆盖当前标准,是否另存当前标准?"), NULL, MB_YESNO) )
|
||
if ( IDYES == MessageBox(_T("新图层标准将覆盖当前标准,是否保存当前标准?"), NULL, MB_YESNO) )
|
||
{
|
||
CString szText;
|
||
m_standard.GetLBText(0,szText);
|
||
long i0=szText.Find(_T('(')),i1=szText.Find(_T(')'));
|
||
if (i1>i0)
|
||
szText=szText.Mid(i0+1,i1-i0-1);
|
||
if (szText == _T(""))
|
||
return;
|
||
|
||
CString szFullName = GetFullPath(szText);
|
||
if ( !CopyFile( szCur, szFullName, FALSE ) )
|
||
{
|
||
MessageBox(_T("保存当前标准失败!"));
|
||
return;
|
||
}
|
||
}
|
||
|
||
CopyFile( m_szCurFile, szCur, FALSE);
|
||
m_szCurFile=szCur;
|
||
UpdateCombox();
|
||
m_standard.SetCurSel(0);
|
||
UpdateVisible();
|
||
|
||
InitLayers(true);//更新内部图层数据
|
||
|
||
MessageBox(_T("当前图层标准已经改变,但原标准图层仍然存在。\n如果需要转换,请单击图层转换按钮。"));
|
||
}
|
||
|
||
void CLayerManager::OnBnClickedButtonNew()
|
||
{
|
||
SaveFile();
|
||
CAcModuleResourceOverride vTemp;
|
||
CLayerStandardDlg dlg(this);
|
||
if ( IDOK != dlg.DoModal())
|
||
return;
|
||
|
||
CString szText = _tcstok((TCHAR*)(const TCHAR*)dlg.m_szNewStandard, _T("."));
|
||
if (szText == _T(""))
|
||
return;
|
||
|
||
CString szFullName = GetFullPath(szText);
|
||
if ( PathFileExists(szFullName) )
|
||
{
|
||
MessageBox(_T("图层标准 \"") + szText + _T("\" 已存在"));
|
||
return;
|
||
}
|
||
if ( CopyFile( m_szCurFile, szFullName, FALSE ) )
|
||
{
|
||
m_szCurFile=szFullName;
|
||
m_standard.AddString( szText );
|
||
m_standard.SetCurSel(m_standard.GetCount()-1);
|
||
|
||
//add by whl
|
||
m_sStdName=szText;
|
||
WriteFile();
|
||
|
||
UpdateVisible();
|
||
}
|
||
}
|
||
|
||
void CLayerManager::OnBnClickedButtonChange()
|
||
{
|
||
SaveFile();
|
||
EndDialog(IDOK);
|
||
|
||
CString sCmd = GetFullCmdName(_T("TLayerConvert"));
|
||
sCmd += _T("\n");
|
||
acedPostCommand(sCmd);
|
||
}
|
||
|
||
void CLayerManager::OnBnClickedButtonColor()
|
||
{
|
||
SaveFile();
|
||
EndDialog(IDOK);
|
||
|
||
CString sCmd = GetFullCmdName(_T("TResColor"));
|
||
sCmd += _T("\n");
|
||
acedPostCommand(sCmd);
|
||
}
|
||
|
||
void CLayerManager::OnCbnSelchangeComboStandard()
|
||
{
|
||
SaveFile();
|
||
CString szText;
|
||
if (m_standard.GetCurSel()>=0)
|
||
m_standard.GetLBText(m_standard.GetCurSel(), szText);
|
||
if ( m_standard.GetCurSel()==0)
|
||
m_szCurFile = GetFullPath(_T("layerdef.dat"));
|
||
else
|
||
m_szCurFile = GetFullPath(szText);
|
||
|
||
UpdateGrid();
|
||
UpdateVisible();
|
||
}
|
||
#endif
|
||
|
||
|
||
|
||
|
||
//////////////////////////////////////////////////////////
|
||
//add by fxj 090108
|
||
CLayerGrid::CLayerGrid(DList<ClashLayer> *pLstLayer)
|
||
:WDGrid(false),m_pLstLayer(pLstLayer)
|
||
{
|
||
}
|
||
|
||
void CLayerGrid::OnCellComboString(WDGridCell&cell,CComboBox&combo)
|
||
{
|
||
if (cell.GetColIndex() == 1)
|
||
{
|
||
int iRow = cell.GetRowIndex();
|
||
if (iRow<0 || iRow>m_pLstLayer->Length()-1)
|
||
return;
|
||
|
||
ClashLayer &clashLayer = *(*m_pLstLayer)[iRow];
|
||
|
||
// combo.AddString(_T("请选择"));
|
||
DList<CLayerData1> &lstData = clashLayer.m_lstClashData;
|
||
for (int j=0;j<lstData.Length();j++)
|
||
{
|
||
CLayerData1 *pData=lstData[j];
|
||
combo.AddString(pData->m_szKey);
|
||
}
|
||
}
|
||
}
|
||
|
||
void CLayerGrid::OnDataChanged()
|
||
{
|
||
m_bModified = true;
|
||
long iRow = GetCurRowIndex();
|
||
CString sText = pSelCell->GetText();
|
||
ClashLayer &clashLayer = *(*m_pLstLayer)[iRow];
|
||
|
||
DList<CLayerData1> &lstData = clashLayer.m_lstClashData;
|
||
for (int i=0; i<lstData.Length(); i++)
|
||
{
|
||
CLayerData1 *pData = lstData[i];
|
||
if (pData->m_szKey == sText)
|
||
{
|
||
GetCell(iRow,2).SetText(pData->m_szName);
|
||
GetCell(iRow,3).SetText(pData->m_szNote);
|
||
break;
|
||
}
|
||
}
|
||
Refresh();
|
||
SendParentNotify(EN_CHANGE);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
CLayerNameDlg::CLayerNameDlg(DList<ClashLayer> *pLstLayer)
|
||
:GlwCAcUiDialog(CLayerNameDlg::IDD),m_pLstLayer(pLstLayer)
|
||
{
|
||
|
||
}
|
||
|
||
BOOL CLayerNameDlg:: OnInitDialog()
|
||
{
|
||
CDialog::OnInitDialog();
|
||
InitGrid();
|
||
UpdateData(FALSE);
|
||
return TRUE;
|
||
}
|
||
|
||
void CLayerNameDlg::InitGrid()
|
||
{
|
||
m_grid.Clear();
|
||
m_grid.AppendCol(_T("原图层名(冲突项)"),100);
|
||
m_grid.AppendCol(_T("图层关键字"),100);
|
||
m_grid.AppendCol(_T("目标图层名"),100);
|
||
m_grid.AppendCol(_T("图层描述"),250);
|
||
|
||
|
||
m_grid.SetColPosFix();
|
||
m_grid.SetColFixLength();
|
||
m_grid.SetRowPosFix();
|
||
m_grid.SetRowFixLength();
|
||
m_grid.Create(this, IDC_NAME_LIST);
|
||
m_grid.FitLastCol();
|
||
|
||
m_grid.GetCol(0).SetReadOnly();
|
||
m_grid.GetCol(2).SetReadOnly();
|
||
m_grid.GetCol(3).SetReadOnly();
|
||
m_grid.GetCol(0).SetBackColor(GetSysColor(COLOR_3DFACE));
|
||
m_grid.GetCol(2).SetBackColor(GetSysColor(COLOR_3DFACE));
|
||
m_grid.GetCol(3).SetBackColor(GetSysColor(COLOR_3DFACE));
|
||
|
||
m_grid.GetCol(1).SetComboEdit();
|
||
|
||
m_grid.m_pLstLayer=m_pLstLayer;
|
||
|
||
for (int i=0;i<m_pLstLayer->Length();i++)
|
||
{
|
||
ClashLayer &clashLayer=*(*m_pLstLayer)[i];
|
||
WDGridRow *pRow=new WDGridRow(m_grid);
|
||
(*pRow)[0].SetText(clashLayer.m_sClashName);
|
||
(*pRow)[1].SetText(_T("请选择"));
|
||
m_grid.AppendRow(pRow);
|
||
}
|
||
}
|
||
|
||
void CLayerNameDlg::OnOK()
|
||
{
|
||
CDialog::OnOK();
|
||
|
||
//图层转换
|
||
long nRowNum = m_grid.GetRowNum();
|
||
for (long i=0; i<nRowNum; i++)
|
||
{
|
||
CString curName = m_grid.GetCell(i,0).GetText();
|
||
CString goalName = m_grid.GetCell(i,2).GetText();
|
||
CString goalKey = m_grid.GetCell(i,1).GetText();
|
||
if (goalName == _T("请选择"))
|
||
continue;
|
||
|
||
AcDbObjectId idLayer = GetLayerIdFromString(curName);
|
||
Acad::ErrorStatus ret = Acad::eOk;
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer)
|
||
{
|
||
ret = pLayer->setName(goalName);
|
||
AcCmColor color;
|
||
// color.setColorIndex(GetLayerColor(GetLayerIdFromString(goalName)));
|
||
|
||
// sg modify 120615,解决转换后图层颜色错误的问题
|
||
int nColorIndex = 0;
|
||
ClashLayer &clashLayer = *(*m_pLstLayer)[i];
|
||
DList<CLayerData1> &lstData = clashLayer.m_lstClashData;
|
||
for (int j=0; j<lstData.Length(); j++)
|
||
{
|
||
CLayerData1 *pData = lstData[j];
|
||
if (pData->m_szKey == goalKey)
|
||
{
|
||
nColorIndex = pData->m_nColor;
|
||
break;
|
||
}
|
||
}
|
||
color.setColorIndex(nColorIndex);
|
||
|
||
pLayer->setColor(color);
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// 原图层名是A,目标图层名为B,但B图层已经在本图中存在,这种情况就无法将原A转换为B了(不允许重名),
|
||
// 这时只能将原先A图层上的所有对象,改设为B图层,这样就完成了转换
|
||
if (ret != Acad::eOk)
|
||
{
|
||
AcDbBlockTable *pBlkTable;
|
||
|
||
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTable,AcDb::kForWrite);
|
||
AcDbBlockTableIterator *pBlkTableIte = NULL;
|
||
pBlkTable->newIterator(pBlkTableIte);
|
||
for (pBlkTableIte->start();!pBlkTableIte->done();pBlkTableIte->step())
|
||
{
|
||
AcDbBlockTableRecord *pBlkTableRec;
|
||
pBlkTableIte->getRecord(pBlkTableRec,AcDb::kForRead);
|
||
AcDbBlockTableRecordIterator *pBlkTableRecIte = NULL;
|
||
pBlkTableRec->newIterator(pBlkTableRecIte);
|
||
for (pBlkTableRecIte->start();!pBlkTableRecIte->done();pBlkTableRecIte->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
pBlkTableRecIte->getEntity(pEnt,AcDb::kForRead);
|
||
if (pEnt != NULL)
|
||
{
|
||
if (_tcsicmp(pEnt->layer(),curName) == 0)
|
||
{
|
||
pEnt->upgradeOpen();
|
||
pEnt->setLayer(goalName);
|
||
}
|
||
pEnt->close();
|
||
|
||
}
|
||
}
|
||
delete pBlkTableRecIte;
|
||
pBlkTableRec->close();
|
||
}
|
||
delete pBlkTableIte;
|
||
pBlkTable->close();
|
||
}
|
||
}
|
||
}
|
||
|
||
//////////////////////////////////////////////////////////////////////////
|
||
// CLayerChangeDlg 对话框
|
||
int CLayerChangeDlg::g_iDest=0;
|
||
int CLayerChangeDlg::g_iSource=0;
|
||
#if (ADS > 16)
|
||
IMPLEMENT_DYNAMIC(CLayerChangeDlg, CModelessDialog)
|
||
CLayerChangeDlg::CLayerChangeDlg(CWnd* pParent ) : CModelessDialog(false) { }
|
||
|
||
CLayerChangeDlg::~CLayerChangeDlg() { }
|
||
|
||
void CLayerChangeDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CDialog::DoDataExchange(pDX);
|
||
// DDX_Control(pDX, IDC_COMBO_CURRENT, m_current);
|
||
// DDX_Control(pDX, IDC_COMBO_GOAL, m_goal);
|
||
|
||
// DDX_CBIndex(pDX, IDC_COMBO_RANGE, m_iFindRange);//add by fxj 090105
|
||
}
|
||
|
||
BEGIN_MESSAGE_MAP(CLayerChangeDlg, CModelessDialog)
|
||
END_MESSAGE_MAP()
|
||
|
||
BOOL CLayerChangeDlg::OnInitDialog()
|
||
{
|
||
MoveWindow(CRect(0, 0, 272, 91));
|
||
CenterWindow();
|
||
m_current.Create(WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST|WS_VSCROLL|WS_TABSTOP, CRect(CPoint(108, 11), CSize(146, 20)), this, IDC_COMBO_CURRENT);
|
||
m_goal.Create(WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST|WS_VSCROLL|WS_TABSTOP, CRect(CPoint(108, 35), CSize(146, 20)), this, IDC_COMBO_GOAL);
|
||
m_btnCancel.Create(_T("转换"), WS_CHILD|WS_VISIBLE, CRect(CPoint(50, 60), CSize(65, 21)), this, IDOK);
|
||
m_btnOK.Create(_T("取消"), WS_CHILD|WS_VISIBLE, CRect(CPoint(156, 60), CSize(65, 21)), this, IDCANCEL);
|
||
m_staCurrent.Create(_T("原图层标准:"), WS_CHILD|WS_VISIBLE, CRect(CPoint(17, 12), CSize(74, 12)), this);
|
||
m_staDest.Create(_T("目标图层标准:"), WS_CHILD|WS_VISIBLE, CRect(CPoint(17, 38), CSize(86, 12)), this);
|
||
|
||
XStringList lstFiles;
|
||
CString szSysPath = GetFullPath(_T(""));
|
||
FindFiles(szSysPath, _T("*.lay"), lstFiles, TRUE);
|
||
CString sTitle;
|
||
sTitle.Format(_T("当前标准(%s)"),LAY_STD);
|
||
m_current.AddString(sTitle);
|
||
m_goal.AddString(sTitle);
|
||
CString sCurStd=DocGetLayerStd();
|
||
for (int i=0; i<lstFiles.Length(); i++)
|
||
{
|
||
CString szFile = _tcstok(lstFiles[i], _T("."));
|
||
m_current.AddString(szFile);
|
||
if (_tcsicmp(szFile,sCurStd)==0)
|
||
m_current.SetCurSel(i+1);
|
||
m_goal.AddString(szFile);
|
||
}
|
||
CString sText;
|
||
if (m_current.GetCurSel()>=0)
|
||
m_current.GetLBText(m_current.GetCurSel(),sText);
|
||
if (sText.GetLength()<1||_tcsicmp(sText,DocGetLayerStd())!=0)
|
||
m_current.SetCurSel(g_iSource);
|
||
m_goal.SetCurSel(g_iDest);
|
||
|
||
UpdateData(FALSE);
|
||
|
||
return CModelessDialog::OnInitDialog();
|
||
}
|
||
|
||
//隐藏或者显示对话框
|
||
void CLayerChangeDlg::HideDialog(BOOL bFlag)//add by fxj 090105
|
||
{
|
||
if (bFlag)
|
||
{
|
||
GetParent()->EnableWindow(TRUE);
|
||
GetParent()->SetFocus();
|
||
GetParent()->SetActiveWindow();
|
||
ShowWindow(SW_HIDE);
|
||
GetParent()->RedrawWindow();
|
||
}
|
||
else
|
||
{
|
||
GetParent()->EnableWindow(FALSE);
|
||
EnableWindow(TRUE);
|
||
SetActiveWindow();
|
||
ShowWindow(SW_SHOW);
|
||
GetParent()->EnableWindow(TRUE);
|
||
}
|
||
}
|
||
|
||
void CLayerChangeDlg::OnOK()
|
||
{
|
||
CString szCur, szGoal;
|
||
// 原图层标准
|
||
if (m_current.GetCurSel() >= 0)
|
||
{
|
||
m_current.GetLBText(m_current.GetCurSel(), szCur);
|
||
}
|
||
|
||
// 目标图层标准
|
||
if (m_goal.GetCurSel() >= 0)
|
||
{
|
||
m_goal.GetLBText(m_goal.GetCurSel(), szGoal);
|
||
}
|
||
|
||
if (_tcsnicmp(szCur, szGoal, _tcslen(szCur)) == 0)
|
||
{
|
||
CDialog::OnOK();
|
||
return;
|
||
}
|
||
|
||
g_iSource = m_current.GetCurSel();
|
||
g_iDest = m_goal.GetCurSel();
|
||
|
||
if (m_current.GetCurSel() == 0)
|
||
{
|
||
szCur = _T("layerdef.dat"); // 当前图层标准
|
||
}
|
||
|
||
if (m_goal.GetCurSel() == 0)
|
||
{
|
||
szGoal = _T("layerdef.dat");
|
||
}
|
||
|
||
// 图层标准文件路径
|
||
szCur = GetFullPath(szCur);
|
||
szGoal = GetFullPath(szGoal);
|
||
|
||
|
||
DList<CLayerData1> lstCur;
|
||
DList<CLayerData1> lstGoal;
|
||
if (!ReadFile(szCur, lstCur) || !ReadFile(szGoal, lstGoal))
|
||
{
|
||
CDialog::OnOK();
|
||
return;
|
||
}
|
||
|
||
// 当前图纸中的图层(图层特性管理器)
|
||
XSymbolList lstLayer(_T("LAYER"));
|
||
|
||
DList<ClashLayer> lstClashLayer; // 冲突的图层
|
||
|
||
|
||
for (int j=0; j<lstLayer.Length(); j++)
|
||
{
|
||
XString curName = lstLayer[j];
|
||
|
||
// sg add 091204,以下三个图层为CAD图层,一般不会出现在图层标准中,暂时去掉,减少循环次数,提高速度
|
||
if (_tcsicmp(curName, _T("0"))==0 || _tcsicmp(curName, _T("ASHADE"))==0 || _tcsicmp(curName, _T("Defpoints"))==0)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
DList<CLayerData1> lstClashData; // 每个图层名对应多个关键字
|
||
|
||
XStringList lstKey;
|
||
|
||
int nCount = 0;
|
||
for (int i=0; i<lstCur.Length(); i++)
|
||
{
|
||
CLayerData1* pCur = lstCur[i];
|
||
if (_tcsicmp(curName, pCur->m_szName) == 0)
|
||
{
|
||
lstKey.Append(tstrnew(pCur->m_szKey));
|
||
nCount++;
|
||
}
|
||
}
|
||
|
||
if (nCount == 1)
|
||
{
|
||
for (int k=0; k<lstGoal.Length(); k++)
|
||
{
|
||
CLayerData1 *pGoal = lstGoal[k];
|
||
if (_tcsicmp(pGoal->m_szKey, lstKey[0]) == 0)
|
||
{
|
||
AcDbObjectId idLayer = GetLayerIdFromString(curName);
|
||
|
||
Acad::ErrorStatus ret = Acad::eOk;
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer != NULL)
|
||
{
|
||
ret = pLayer->setName(pGoal->m_szName);
|
||
if (ret == Acad::eOk)
|
||
{
|
||
AcCmColor color;
|
||
color.setColorIndex(pGoal->m_nColor);
|
||
pLayer->setColor(color);
|
||
//add by lgy 20120406 为图层设置线型
|
||
AcDbObjectId idLineType = GetLinetypeIdFromString(pGoal->m_strLineType);
|
||
if (idLineType.isNull())
|
||
idLineType = InitLineType(pGoal->m_strLineType);
|
||
if (idLineType.isNull())
|
||
idLineType = InitTchLineType(pGoal->m_strLineType);
|
||
pLayer->setLinetypeObjectId(idLineType);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// 原图层名是A,目标图层名为B,但B图层已经在本图中存在,这种情况就无法将原A转换为B了(不允许重名),
|
||
// 这时只能将原先A图层上的所有对象,改设为B图层,这样就完成了转换
|
||
// sg delete 091207,根据邵燕、hx反馈,遍历的方法,速度慢,容易造成死机,宁可不做修改,放弃功能
|
||
// sg modify 101112,根据8.5需求,临时关闭了反应器,因此恢复了对象图层转换的代码
|
||
if (ret != Acad::eOk)
|
||
{
|
||
AcDbBlockTable *pBlkTable = NULL;
|
||
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTable, AcDb::kForWrite);
|
||
|
||
AcDbBlockTableIterator *pBlkTableIte = NULL;
|
||
pBlkTable->newIterator(pBlkTableIte);
|
||
|
||
for (pBlkTableIte->start(); !pBlkTableIte->done(); pBlkTableIte->step())
|
||
{
|
||
AcDbBlockTableRecord *pBlkTableRec = NULL;
|
||
pBlkTableIte->getRecord(pBlkTableRec, AcDb::kForRead);
|
||
|
||
AcDbBlockTableRecordIterator *pBlkTableRecIte = NULL;
|
||
pBlkTableRec->newIterator(pBlkTableRecIte);
|
||
|
||
for (pBlkTableRecIte->start(); !pBlkTableRecIte->done(); pBlkTableRecIte->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
pBlkTableRecIte->getEntity(pEnt, AcDb::kForRead);
|
||
if (pEnt != NULL)
|
||
{
|
||
if (_tcsicmp(pEnt->layer(), curName) == 0)
|
||
{
|
||
pEnt->upgradeOpen();
|
||
pEnt->setLayer(pGoal->m_szName);
|
||
}
|
||
|
||
//modify by lgy 20120409 图层转换时如果图纸中已经存在了图层,则无法转换楼梯等的内部图层
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0 || _tcsicmp(pGoal->m_szKey, _T("扶手")) == 0)
|
||
{
|
||
AcDbObjectId id = GetLayerIdFromString(pGoal->m_szName);
|
||
TDbRectStair *pRectStair = TDbRectStair::cast(pEnt);
|
||
if (pRectStair) //双跑楼梯
|
||
{
|
||
pRectStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pRectStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pRectStair->SetLayerHand3d(id);
|
||
}
|
||
pRectStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbMultiStair *pMultiStair = TDbMultiStair::cast(pEnt);
|
||
if (pMultiStair) //多跑楼梯
|
||
{
|
||
pMultiStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pMultiStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pMultiStair->SetLayerHand3d(id);
|
||
}
|
||
pMultiStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbParallelStair *pParallelStair = TDbParallelStair::cast(pEnt);
|
||
if (pParallelStair) //双分平行楼梯
|
||
{
|
||
pParallelStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pParallelStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pParallelStair->SetLayerHand3d(id);
|
||
}
|
||
pParallelStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbCornerStair *pCornerStair = TDbCornerStair::cast(pEnt);
|
||
if (pCornerStair) //双分转角楼梯
|
||
{
|
||
pCornerStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pCornerStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pCornerStair->SetLayerHand3d(id);
|
||
}
|
||
pCornerStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbDoubleMulStair *pDoubleStair = TDbDoubleMulStair::cast(pEnt);
|
||
if (pDoubleStair) //双分三跑楼梯
|
||
{
|
||
pDoubleStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pDoubleStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pDoubleStair->SetLayerHand3d(id);
|
||
}
|
||
pDoubleStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbScissorsStair *pScissorsStair = TDbScissorsStair::cast(pEnt);
|
||
if (pScissorsStair) //交叉楼梯
|
||
{
|
||
pScissorsStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pScissorsStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pScissorsStair->SetLayerHand3d(id);
|
||
}
|
||
pScissorsStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbCrossStair *pCrossStair = TDbCrossStair::cast(pEnt);
|
||
if (pCrossStair) //剪刀楼梯
|
||
{
|
||
pCrossStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pCrossStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pCrossStair->SetLayerHand3d(id);
|
||
}
|
||
pCrossStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbTriangleStair *pTriangleStair = TDbTriangleStair::cast(pEnt);
|
||
if (pTriangleStair) //三角楼梯
|
||
{
|
||
pTriangleStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pTriangleStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pTriangleStair->SetLayerHand3d(id);
|
||
}
|
||
pTriangleStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbRectCornerStair *pRectCornerStair = TDbRectCornerStair::cast(pEnt);
|
||
if (pRectCornerStair) //矩形转角楼梯
|
||
{
|
||
pRectCornerStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pRectCornerStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pRectCornerStair->SetLayerHand3d(id);
|
||
}
|
||
pRectCornerStair->close();
|
||
continue;
|
||
}
|
||
}
|
||
pEnt->close();
|
||
}
|
||
}
|
||
|
||
delete pBlkTableRecIte;
|
||
pBlkTableRec->close();
|
||
}
|
||
|
||
delete pBlkTableIte;
|
||
pBlkTable->close();
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else if (nCount > 1)
|
||
{
|
||
XStringList lstName;
|
||
XString goalName;
|
||
//add by lgy 20120406 增加以下两个变量是为了记录线型
|
||
XString goalType;
|
||
XStringList lstType;
|
||
for (int k=0; k<lstGoal.Length(); k++)
|
||
{
|
||
CLayerData1 *pGoal = lstGoal[k];
|
||
if (lstKey.Index(pGoal->m_szKey, 0) >= 0)
|
||
{
|
||
if (lstName.Index(pGoal->m_szName, 0) < 0)
|
||
{
|
||
lstName.Append(tstrnew(pGoal->m_szName));
|
||
//modify by lgy 20120406 9.0图层转换增加线型
|
||
//lstClashData.Append(new CLayerData1(pGoal->m_szKey, pGoal->m_szName, pGoal->m_szNote, pGoal->m_nColor));
|
||
lstType.Append(tstrnew(pGoal->m_strLineType));
|
||
lstClashData.Append(new CLayerData1(pGoal->m_szKey, pGoal->m_szName, pGoal->m_szNote, pGoal->m_nColor, pGoal->m_strLineType));
|
||
}
|
||
}
|
||
}
|
||
|
||
Acad::ErrorStatus ret = Acad::eOk;
|
||
if (lstName.Length() > 1)
|
||
{
|
||
ClashLayer *pClashLayer = new ClashLayer;
|
||
for (int i=0; i<lstClashData.Length(); i++)
|
||
{
|
||
pClashLayer->m_lstClashData.Append(new CLayerData1(*lstClashData[i]));
|
||
}
|
||
|
||
pClashLayer->m_sClashName = curName;
|
||
lstClashLayer.Append(pClashLayer);
|
||
}
|
||
else if (lstName.Length() < 1)
|
||
{
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
goalName = lstName[0];
|
||
CLayerData1 *pLayerData1 = lstClashData[0];
|
||
//add by lgy 20120406 9.0获得线型
|
||
goalType = lstType[0];
|
||
|
||
AcDbObjectId idLayer = GetLayerIdFromString(curName);
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer != NULL)
|
||
{
|
||
ret = pLayer->setName(goalName);
|
||
if (ret == Acad::eOk)
|
||
{
|
||
AcCmColor color;
|
||
color.setColorIndex(pLayerData1->m_nColor);
|
||
pLayer->setColor(color);
|
||
//add by lgy 20120409 9.0要求改变图层线性
|
||
AcDbObjectId id = GetLinetypeIdFromString(pLayerData1->m_strLineType);
|
||
if (id.isNull())
|
||
id = InitLineType(pLayerData1->m_strLineType);
|
||
if (id.isNull())
|
||
id = InitTchLineType(pLayerData1->m_strLineType);
|
||
pLayer->setLinetypeObjectId(id);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// 原图层名是A,目标图层名为B,但B图层已经在本图中存在,这种情况就无法将原A转换为B了(不允许重名),
|
||
// 这时只能将原先A图层上的所有对象,改设为B图层,这样就完成了转换
|
||
// sg delete 091207,根据邵燕、hx反馈,遍历的方法,速度慢,容易造成死机,宁可不做修改,放弃功能
|
||
// sg modify 101112,根据8.5需求,临时关闭了反应器,因此恢复了对象图层转换的代码
|
||
if (ret != Acad::eOk)
|
||
{
|
||
AcDbBlockTable *pBlkTable;
|
||
|
||
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTable,AcDb::kForWrite);
|
||
AcDbBlockTableIterator *pBlkTableIte = NULL;
|
||
pBlkTable->newIterator(pBlkTableIte);
|
||
for (pBlkTableIte->start(); !pBlkTableIte->done(); pBlkTableIte->step())
|
||
{
|
||
AcDbBlockTableRecord *pBlkTableRec;
|
||
pBlkTableIte->getRecord(pBlkTableRec, AcDb::kForRead);
|
||
AcDbBlockTableRecordIterator *pBlkTableRecIte = NULL;
|
||
pBlkTableRec->newIterator(pBlkTableRecIte);
|
||
|
||
for (pBlkTableRecIte->start();!pBlkTableRecIte->done();pBlkTableRecIte->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
pBlkTableRecIte->getEntity(pEnt,AcDb::kForRead);
|
||
if (pEnt != NULL)
|
||
{
|
||
if (_tcsicmp(pEnt->layer(),curName) == 0)
|
||
{
|
||
pEnt->upgradeOpen();
|
||
pEnt->setLayer(goalName);
|
||
//add by lgy 20120406 设置线型
|
||
AcDbObjectId id = GetLinetypeIdFromString(goalType);
|
||
if (id.isNull())
|
||
id = InitLineType(goalType);
|
||
if (id.isNull())
|
||
id = InitTchLineType(goalType);
|
||
pEnt->setLinetype(id);
|
||
}
|
||
pEnt->close();
|
||
}
|
||
}
|
||
delete pBlkTableRecIte;
|
||
pBlkTableRec->close();
|
||
}
|
||
delete pBlkTableIte;
|
||
pBlkTable->close();
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
|
||
if (lstClashLayer.Length() > 0)
|
||
{
|
||
CAcModuleResourceOverride vTemp;
|
||
CLayerNameDlg nameDlg(&lstClashLayer);
|
||
if (nameDlg.DoModal() != IDOK)
|
||
{
|
||
CDialog::OnOK();
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (m_goal.GetCurSel() == 0)
|
||
{
|
||
DocSetLayerStd(LAY_STD);
|
||
}
|
||
else
|
||
{
|
||
CString sGoal;
|
||
if (m_goal.GetCurSel() >= 0)
|
||
{
|
||
m_goal.GetLBText(m_goal.GetCurSel(), sGoal);
|
||
}
|
||
|
||
DocSetLayerStd(sGoal);
|
||
}
|
||
|
||
acedCommand(RTSTR, _T("REGEN"), RTNONE);
|
||
CDialog::OnOK();
|
||
}
|
||
|
||
CString CLayerChangeDlg::GetFullPath(const TCHAR *szFileName)
|
||
{
|
||
// Zyu modify on 100730,适应64位平台的文件夹名称变化
|
||
//CString szFullPath = g_sAppPath;
|
||
CString szFullPath = g_sDwbPath;
|
||
|
||
if(_tcscmp(szFileName, _T("")) == 0)
|
||
{
|
||
//szFullPath = szFullPath.Left(szFullPath.GetLength() - 7) + _T("\\sys\\");
|
||
szFullPath = szFullPath.Left(szFullPath.GetLength() - 5) + _T("\\sys\\");
|
||
}
|
||
else
|
||
{
|
||
//szFullPath = szFullPath.Left(szFullPath.GetLength() - 7) + _T("\\sys\\") + szFileName;
|
||
szFullPath = szFullPath.Left(szFullPath.GetLength() - 5) + _T("\\sys\\") + szFileName;
|
||
// sg modify 101111,算法有问题,不支持文件路径中有“.”
|
||
// if (szFullPath.Find(_T(".")) == -1)
|
||
CString csTmp = szFileName;
|
||
if (csTmp.Find(_T(".")) == -1)
|
||
szFullPath += _T(".lay");
|
||
}
|
||
return szFullPath;
|
||
}
|
||
|
||
// modified by fxj CLayerData->CLayerData1 090206
|
||
BOOL CLayerChangeDlg::ReadFile(CString szFullName, DList<CLayerData1> &lstLayer)
|
||
{
|
||
if (!PathFileExists(szFullName))
|
||
{
|
||
AfxMessageBox(CString(_T("文件 \"")) + szFullName + _T("\" 不存在!"));
|
||
return FALSE;
|
||
}
|
||
|
||
CStdioFile file;
|
||
if (!file.Open(szFullName, CFile::modeRead))
|
||
{
|
||
AfxMessageBox(CString(_T("打开文件 \"")) + szFullName + _T("\" 失败!"));
|
||
return FALSE;
|
||
}
|
||
|
||
CString sString;
|
||
while(file.ReadString(sString))
|
||
{
|
||
TCHAR sKey[256] = _T("");
|
||
TCHAR sName[256] = _T("");
|
||
int nColor = 0;
|
||
|
||
// modified by fxj 081229
|
||
TCHAR sLineType[256] = _T("");
|
||
TCHAR sNote[256] = _T("");
|
||
_stscanf(sString, _T("%s%s%d%s%s"), sKey, sName, &nColor, sLineType, sNote);
|
||
|
||
// add by whl on 060224
|
||
if (_tcscmp(sKey,_T("图层标准"))==0 ||
|
||
_tcscmp(sKey,_T(""))==0)
|
||
continue;
|
||
if (_tcscmp(sName,_T(""))==0||
|
||
_tcscmp(sName,_T("0"))==0)
|
||
continue;
|
||
|
||
// modify by lgy 20120406,增加线型
|
||
// CLayerData1 *pData = new CLayerData1(sKey, sName, sNote, nColor);//modified by fxj (add "sNote") 090206
|
||
CLayerData1 *pData = new CLayerData1(sKey, sName, sNote, nColor, sLineType);
|
||
lstLayer.Append(pData);
|
||
}
|
||
file.Close();
|
||
return TRUE;
|
||
}
|
||
|
||
#else
|
||
CLayerChangeDlg::CLayerChangeDlg(CWnd* pParent /*=NULL*/)
|
||
: GlwCAcUiDialog(CLayerChangeDlg::IDD, pParent)//,m_ssEnt(SS_FREE)
|
||
{
|
||
}
|
||
|
||
CLayerChangeDlg::~CLayerChangeDlg() { }
|
||
|
||
void CLayerChangeDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CDialog::DoDataExchange(pDX);
|
||
DDX_Control(pDX, IDC_COMBO_CURRENT, m_current);
|
||
DDX_Control(pDX, IDC_COMBO_GOAL, m_goal);
|
||
}
|
||
|
||
// CLayerChangeDlg 消息处理程序
|
||
BOOL CLayerChangeDlg::OnInitDialog()
|
||
{
|
||
CDialog::OnInitDialog();
|
||
XStringList lstFiles;
|
||
CString szSysPath = GetFullPath(_T(""));
|
||
FindFiles(szSysPath, _T("*.lay"), lstFiles, TRUE);
|
||
CString sTitle;
|
||
sTitle.Format(_T("当前标准(%s)"),LAY_STD);
|
||
m_current.AddString(sTitle);
|
||
m_goal.AddString(sTitle);
|
||
CString sCurStd=DocGetLayerStd();
|
||
for (int i=0; i<lstFiles.Length(); i++)
|
||
{
|
||
CString szFile = _tcstok(lstFiles[i], _T("."));
|
||
m_current.AddString(szFile);
|
||
if (_tcsicmp(szFile,sCurStd)==0)
|
||
m_current.SetCurSel(i+1);
|
||
m_goal.AddString(szFile);
|
||
}
|
||
CString sText;
|
||
if (m_current.GetCurSel()>=0)
|
||
m_current.GetLBText(m_current.GetCurSel(),sText);
|
||
if (sText.GetLength()<1||_tcsicmp(sText,DocGetLayerStd())!=0)
|
||
m_current.SetCurSel(g_iSource);
|
||
m_goal.SetCurSel(g_iDest);
|
||
|
||
UpdateData(FALSE);
|
||
//-------------------------------------------
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
//BOOL CLayerChangeDlg::PreTranslateMessage(MSG* pMsg)
|
||
//{
|
||
// m_wndToolTip.RelayEvent(pMsg);
|
||
// return CDialog::PreTranslateMessage(pMsg);
|
||
//}
|
||
//隐藏或者显示对话框
|
||
void CLayerChangeDlg::HideDialog(BOOL bFlag)//add by fxj 090105
|
||
{
|
||
if (bFlag) {
|
||
|
||
GetParent()->EnableWindow(TRUE);
|
||
GetParent()->SetFocus();
|
||
GetParent()->SetActiveWindow();
|
||
ShowWindow(SW_HIDE);
|
||
GetParent()->RedrawWindow();
|
||
}
|
||
else {
|
||
|
||
GetParent()->EnableWindow(FALSE);
|
||
EnableWindow(TRUE);
|
||
SetActiveWindow();
|
||
ShowWindow(SW_SHOW);
|
||
GetParent()->EnableWindow(TRUE);
|
||
}
|
||
}
|
||
|
||
void CLayerChangeDlg::OnOK()
|
||
{
|
||
CString szCur, szGoal;
|
||
// 原图层标准
|
||
if (m_current.GetCurSel() >= 0)
|
||
{
|
||
m_current.GetLBText(m_current.GetCurSel(), szCur);
|
||
}
|
||
|
||
// 目标图层标准
|
||
if (m_goal.GetCurSel() >= 0)
|
||
{
|
||
m_goal.GetLBText(m_goal.GetCurSel(), szGoal);
|
||
}
|
||
|
||
if (_tcsnicmp(szCur, szGoal, _tcslen(szCur)) == 0)
|
||
{
|
||
CDialog::OnOK();
|
||
return;
|
||
}
|
||
|
||
g_iSource = m_current.GetCurSel();
|
||
g_iDest = m_goal.GetCurSel();
|
||
|
||
if (m_current.GetCurSel() == 0)
|
||
{
|
||
szCur = _T("layerdef.dat"); // 当前图层标准
|
||
}
|
||
|
||
if (m_goal.GetCurSel() == 0)
|
||
{
|
||
szGoal = _T("layerdef.dat");
|
||
}
|
||
|
||
// 图层标准文件路径
|
||
szCur = GetFullPath(szCur);
|
||
szGoal = GetFullPath(szGoal);
|
||
|
||
|
||
DList<CLayerData1> lstCur;
|
||
DList<CLayerData1> lstGoal;
|
||
if (!ReadFile(szCur, lstCur) || !ReadFile(szGoal, lstGoal))
|
||
{
|
||
CDialog::OnOK();
|
||
return;
|
||
}
|
||
|
||
// 当前图纸中的图层(图层特性管理器)
|
||
XSymbolList lstLayer(_T("LAYER"));
|
||
|
||
DList<ClashLayer> lstClashLayer; // 冲突的图层
|
||
|
||
|
||
for (int j=0; j<lstLayer.Length(); j++)
|
||
{
|
||
XString curName = lstLayer[j];
|
||
|
||
// sg add 091204,以下三个图层为CAD图层,一般不会出现在图层标准中,暂时去掉,减少循环次数,提高速度
|
||
if (_tcsicmp(curName, _T("0"))==0 || _tcsicmp(curName, _T("ASHADE"))==0 || _tcsicmp(curName, _T("Defpoints"))==0)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
DList<CLayerData1> lstClashData; // 每个图层名对应多个关键字
|
||
|
||
XStringList lstKey;
|
||
|
||
int nCount = 0;
|
||
for (int i=0; i<lstCur.Length(); i++)
|
||
{
|
||
CLayerData1* pCur = lstCur[i];
|
||
if (_tcsicmp(curName, pCur->m_szName) == 0)
|
||
{
|
||
lstKey.Append(tstrnew(pCur->m_szKey));
|
||
nCount++;
|
||
}
|
||
}
|
||
|
||
if (nCount == 1)
|
||
{
|
||
for (int k=0; k<lstGoal.Length(); k++)
|
||
{
|
||
CLayerData1 *pGoal = lstGoal[k];
|
||
if (_tcsicmp(pGoal->m_szKey, lstKey[0]) == 0)
|
||
{
|
||
AcDbObjectId idLayer = GetLayerIdFromString(curName);
|
||
|
||
Acad::ErrorStatus ret = Acad::eOk;
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer != NULL)
|
||
{
|
||
ret = pLayer->setName(pGoal->m_szName);
|
||
if (ret == Acad::eOk)
|
||
{
|
||
AcCmColor color;
|
||
color.setColorIndex(pGoal->m_nColor);
|
||
pLayer->setColor(color);
|
||
//add by lgy 20120406 为图层设置线型
|
||
AcDbObjectId idLineType = GetLinetypeIdFromString(pGoal->m_strLineType);
|
||
pLayer->setLinetypeObjectId(idLineType);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// 原图层名是A,目标图层名为B,但B图层已经在本图中存在,这种情况就无法将原A转换为B了(不允许重名),
|
||
// 这时只能将原先A图层上的所有对象,改设为B图层,这样就完成了转换
|
||
// sg delete 091207,根据邵燕、hx反馈,遍历的方法,速度慢,容易造成死机,宁可不做修改,放弃功能
|
||
// sg modify 101112,根据8.5需求,临时关闭了反应器,因此恢复了对象图层转换的代码
|
||
if (ret != Acad::eOk)
|
||
{
|
||
AcDbBlockTable *pBlkTable = NULL;
|
||
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTable, AcDb::kForWrite);
|
||
|
||
AcDbBlockTableIterator *pBlkTableIte = NULL;
|
||
pBlkTable->newIterator(pBlkTableIte);
|
||
|
||
for (pBlkTableIte->start(); !pBlkTableIte->done(); pBlkTableIte->step())
|
||
{
|
||
AcDbBlockTableRecord *pBlkTableRec = NULL;
|
||
pBlkTableIte->getRecord(pBlkTableRec, AcDb::kForRead);
|
||
|
||
AcDbBlockTableRecordIterator *pBlkTableRecIte = NULL;
|
||
pBlkTableRec->newIterator(pBlkTableRecIte);
|
||
|
||
for (pBlkTableRecIte->start(); !pBlkTableRecIte->done(); pBlkTableRecIte->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
pBlkTableRecIte->getEntity(pEnt, AcDb::kForRead);
|
||
if (pEnt != NULL)
|
||
{
|
||
if (_tcsicmp(pEnt->layer(), curName) == 0)
|
||
{
|
||
pEnt->upgradeOpen();
|
||
pEnt->setLayer(pGoal->m_szName);
|
||
}
|
||
|
||
//modify by lgy 20120409 图层转换时如果图纸中已经存在了图层,则无法转换楼梯等的内部图层
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0 || _tcsicmp(pGoal->m_szKey, _T("扶手")) == 0)
|
||
{
|
||
AcDbObjectId id = GetLayerIdFromString(pGoal->m_szName);
|
||
TDbRectStair *pRectStair = TDbRectStair::cast(pEnt);
|
||
if (pRectStair) //双跑楼梯
|
||
{
|
||
pRectStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pRectStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pRectStair->SetLayerHand3d(id);
|
||
}
|
||
pRectStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbMultiStair *pMultiStair = TDbMultiStair::cast(pEnt);
|
||
if (pMultiStair) //多跑楼梯
|
||
{
|
||
pMultiStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pMultiStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pMultiStair->SetLayerHand3d(id);
|
||
}
|
||
pMultiStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbParallelStair *pParallelStair = TDbParallelStair::cast(pEnt);
|
||
if (pParallelStair) //双分平行楼梯
|
||
{
|
||
pParallelStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pParallelStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pParallelStair->SetLayerHand3d(id);
|
||
}
|
||
pParallelStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbCornerStair *pCornerStair = TDbCornerStair::cast(pEnt);
|
||
if (pCornerStair) //双分转角楼梯
|
||
{
|
||
pCornerStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pCornerStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pCornerStair->SetLayerHand3d(id);
|
||
}
|
||
pCornerStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbDoubleMulStair *pDoubleStair = TDbDoubleMulStair::cast(pEnt);
|
||
if (pDoubleStair) //双分三跑楼梯
|
||
{
|
||
pDoubleStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pDoubleStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pDoubleStair->SetLayerHand3d(id);
|
||
}
|
||
pDoubleStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbScissorsStair *pScissorsStair = TDbScissorsStair::cast(pEnt);
|
||
if (pScissorsStair) //交叉楼梯
|
||
{
|
||
pScissorsStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pScissorsStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pScissorsStair->SetLayerHand3d(id);
|
||
}
|
||
pScissorsStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbCrossStair *pCrossStair = TDbCrossStair::cast(pEnt);
|
||
if (pCrossStair) //剪刀楼梯
|
||
{
|
||
pCrossStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pCrossStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pCrossStair->SetLayerHand3d(id);
|
||
}
|
||
pCrossStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbTriangleStair *pTriangleStair = TDbTriangleStair::cast(pEnt);
|
||
if (pTriangleStair) //三角楼梯
|
||
{
|
||
pTriangleStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pTriangleStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pTriangleStair->SetLayerHand3d(id);
|
||
}
|
||
pTriangleStair->close();
|
||
continue;
|
||
}
|
||
|
||
TDbRectCornerStair *pRectCornerStair = TDbRectCornerStair::cast(pEnt);
|
||
if (pRectCornerStair) //矩形转角楼梯
|
||
{
|
||
pRectCornerStair->upgradeOpen();
|
||
if (_tcsicmp(pGoal->m_szKey, _T("栏杆")) == 0)
|
||
{
|
||
pRectCornerStair->SetLayerRail3d(id);
|
||
}
|
||
else
|
||
{
|
||
pRectCornerStair->SetLayerHand3d(id);
|
||
}
|
||
pRectCornerStair->close();
|
||
continue;
|
||
}
|
||
}
|
||
pEnt->close();
|
||
}
|
||
}
|
||
|
||
delete pBlkTableRecIte;
|
||
pBlkTableRec->close();
|
||
}
|
||
|
||
delete pBlkTableIte;
|
||
pBlkTable->close();
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else if (nCount > 1)
|
||
{
|
||
XStringList lstName;
|
||
XString goalName;
|
||
//add by lgy 20120406 增加以下两个变量是为了记录线型
|
||
XString goalType;
|
||
XStringList lstType;
|
||
for (int k=0; k<lstGoal.Length(); k++)
|
||
{
|
||
CLayerData1 *pGoal = lstGoal[k];
|
||
if (lstKey.Index(pGoal->m_szKey, 0) >= 0)
|
||
{
|
||
if (lstName.Index(pGoal->m_szName, 0) < 0)
|
||
{
|
||
lstName.Append(tstrnew(pGoal->m_szName));
|
||
//modify by lgy 20120406 9.0图层转换增加线型
|
||
//lstClashData.Append(new CLayerData1(pGoal->m_szKey, pGoal->m_szName, pGoal->m_szNote, pGoal->m_nColor));
|
||
lstType.Append(tstrnew(pGoal->m_strLineType));
|
||
lstClashData.Append(new CLayerData1(pGoal->m_szKey, pGoal->m_szName, pGoal->m_szNote, pGoal->m_nColor, pGoal->m_strLineType));
|
||
}
|
||
}
|
||
}
|
||
|
||
Acad::ErrorStatus ret = Acad::eOk;
|
||
if (lstName.Length() > 1)
|
||
{
|
||
ClashLayer *pClashLayer = new ClashLayer;
|
||
for (int i=0; i<lstClashData.Length(); i++)
|
||
{
|
||
pClashLayer->m_lstClashData.Append(new CLayerData1(*lstClashData[i]));
|
||
}
|
||
|
||
pClashLayer->m_sClashName = curName;
|
||
lstClashLayer.Append(pClashLayer);
|
||
}
|
||
else if (lstName.Length() < 1)
|
||
{
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
goalName = lstName[0];
|
||
CLayerData1 *pLayerData1 = lstClashData[0];
|
||
//add by lgy 20120406 9.0获得线型
|
||
goalType = lstType[0];
|
||
|
||
AcDbObjectId idLayer = GetLayerIdFromString(curName);
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer != NULL)
|
||
{
|
||
ret = pLayer->setName(goalName);
|
||
if (ret == Acad::eOk)
|
||
{
|
||
AcCmColor color;
|
||
color.setColorIndex(pLayerData1->m_nColor);
|
||
pLayer->setColor(color);
|
||
//add by lgy 20120409 9.0要求改变图层线性
|
||
AcDbObjectId id = GetLinetypeIdFromString(pLayerData1->m_strLineType);
|
||
pLayer->setLinetypeObjectId(id);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
// 原图层名是A,目标图层名为B,但B图层已经在本图中存在,这种情况就无法将原A转换为B了(不允许重名),
|
||
// 这时只能将原先A图层上的所有对象,改设为B图层,这样就完成了转换
|
||
// sg delete 091207,根据邵燕、hx反馈,遍历的方法,速度慢,容易造成死机,宁可不做修改,放弃功能
|
||
// sg modify 101112,根据8.5需求,临时关闭了反应器,因此恢复了对象图层转换的代码
|
||
if (ret != Acad::eOk)
|
||
{
|
||
AcDbBlockTable *pBlkTable;
|
||
|
||
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTable,AcDb::kForWrite);
|
||
AcDbBlockTableIterator *pBlkTableIte = NULL;
|
||
pBlkTable->newIterator(pBlkTableIte);
|
||
for (pBlkTableIte->start(); !pBlkTableIte->done(); pBlkTableIte->step())
|
||
{
|
||
AcDbBlockTableRecord *pBlkTableRec;
|
||
pBlkTableIte->getRecord(pBlkTableRec, AcDb::kForRead);
|
||
AcDbBlockTableRecordIterator *pBlkTableRecIte = NULL;
|
||
pBlkTableRec->newIterator(pBlkTableRecIte);
|
||
|
||
for (pBlkTableRecIte->start();!pBlkTableRecIte->done();pBlkTableRecIte->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
pBlkTableRecIte->getEntity(pEnt,AcDb::kForRead);
|
||
if (pEnt != NULL)
|
||
{
|
||
if (_tcsicmp(pEnt->layer(),curName) == 0)
|
||
{
|
||
pEnt->upgradeOpen();
|
||
pEnt->setLayer(goalName);
|
||
//add by lgy 20120406 设置线型
|
||
AcDbObjectId id = GetLinetypeIdFromString(goalType);
|
||
pEnt->setLinetype(id);
|
||
}
|
||
pEnt->close();
|
||
}
|
||
}
|
||
delete pBlkTableRecIte;
|
||
pBlkTableRec->close();
|
||
}
|
||
delete pBlkTableIte;
|
||
pBlkTable->close();
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
|
||
if (lstClashLayer.Length() > 0)
|
||
{
|
||
CAcModuleResourceOverride vTemp;
|
||
CLayerNameDlg nameDlg(&lstClashLayer);
|
||
if (nameDlg.DoModal() != IDOK)
|
||
{
|
||
CDialog::OnOK();
|
||
return;
|
||
}
|
||
|
||
}
|
||
//-----------------------------------------
|
||
|
||
if (m_goal.GetCurSel() == 0)
|
||
{
|
||
DocSetLayerStd(LAY_STD);
|
||
}
|
||
else
|
||
{
|
||
CString sGoal;
|
||
if (m_goal.GetCurSel() >= 0)
|
||
{
|
||
m_goal.GetLBText(m_goal.GetCurSel(), sGoal);
|
||
}
|
||
|
||
DocSetLayerStd(sGoal);
|
||
}
|
||
|
||
acedCommand(RTSTR, _T("REGEN"), RTNONE);
|
||
CDialog::OnOK();
|
||
}
|
||
|
||
CString CLayerChangeDlg::GetFullPath(const TCHAR *szFileName)
|
||
{
|
||
// Zyu modify on 100730,适应64位平台的文件夹名称变化
|
||
//CString szFullPath = g_sAppPath;
|
||
CString szFullPath = g_sDwbPath;
|
||
|
||
if(_tcscmp(szFileName, _T("")) == 0)
|
||
{
|
||
//szFullPath = szFullPath.Left(szFullPath.GetLength() - 7) + _T("\\sys\\");
|
||
szFullPath = szFullPath.Left(szFullPath.GetLength() - 5) + _T("\\sys\\");
|
||
}
|
||
else
|
||
{
|
||
//szFullPath = szFullPath.Left(szFullPath.GetLength() - 7) + _T("\\sys\\") + szFileName;
|
||
szFullPath = szFullPath.Left(szFullPath.GetLength() - 5) + _T("\\sys\\") + szFileName;
|
||
// sg modify 101111,算法有问题,不支持文件路径中有“.”
|
||
// if (szFullPath.Find(_T(".")) == -1)
|
||
CString csTmp = szFileName;
|
||
if (csTmp.Find(_T(".")) == -1)
|
||
szFullPath += _T(".lay");
|
||
}
|
||
return szFullPath;
|
||
}
|
||
|
||
// modified by fxj CLayerData->CLayerData1 090206
|
||
BOOL CLayerChangeDlg::ReadFile(CString szFullName, DList<CLayerData1> &lstLayer)
|
||
{
|
||
if (!PathFileExists(szFullName))
|
||
{
|
||
AfxMessageBox(CString(_T("文件 \"")) + szFullName + _T("\" 不存在!"));
|
||
return FALSE;
|
||
}
|
||
|
||
CStdioFile file;
|
||
if (!file.Open(szFullName, CFile::modeRead))
|
||
{
|
||
AfxMessageBox(CString(_T("打开文件 \"")) + szFullName + _T("\" 失败!"));
|
||
return FALSE;
|
||
}
|
||
|
||
CString sString;
|
||
while(file.ReadString(sString))
|
||
{
|
||
TCHAR sKey[256] = _T("");
|
||
TCHAR sName[256] = _T("");
|
||
int nColor = 0;
|
||
|
||
// modified by fxj 081229
|
||
TCHAR sLineType[256] = _T("");
|
||
TCHAR sNote[256] = _T("");
|
||
_stscanf(sString, _T("%s%s%d%s%s"), sKey, sName, &nColor, sLineType, sNote);
|
||
|
||
// add by whl on 060224
|
||
if (_tcscmp(sKey,_T("图层标准"))==0 ||
|
||
_tcscmp(sKey,_T(""))==0)
|
||
continue;
|
||
if (_tcscmp(sName,_T(""))==0||
|
||
_tcscmp(sName,_T("0"))==0)
|
||
continue;
|
||
|
||
// modify by lgy 20120406,增加线型
|
||
// CLayerData1 *pData = new CLayerData1(sKey, sName, sNote, nColor);//modified by fxj (add "sNote") 090206
|
||
CLayerData1 *pData = new CLayerData1(sKey, sName, sNote, nColor, sLineType);
|
||
lstLayer.Append(pData);
|
||
}
|
||
file.Close();
|
||
return TRUE;
|
||
}
|
||
|
||
#endif
|
||
|
||
|
||
#if (ADS > 16)
|
||
|
||
IMPLEMENT_DYNAMIC(CLayerStandardDlg, CModelessDialog)
|
||
|
||
BEGIN_MESSAGE_MAP(CLayerStandardDlg, CModelessDialog)
|
||
END_MESSAGE_MAP()
|
||
|
||
void CLayerStandardDlg::DoDataExchange( CDataExchange* pDX )
|
||
{
|
||
CDialog::DoDataExchange(pDX);
|
||
//DDX_Text(pDX, IDC_EDIT_NEW, m_szNewStandard);
|
||
}
|
||
|
||
BOOL CLayerStandardDlg::OnInitDialog()
|
||
{
|
||
MoveWindow(CRect(0, 0, 224, 77));
|
||
CenterWindow();
|
||
m_staTxt.Create(_T("标准名称:"), WS_VISIBLE|WS_CHILD, CRect(CPoint(25, 16), CSize(60, 12)), this);
|
||
m_edt.Create(WS_VISIBLE|WS_CHILD|ES_AUTOHSCROLL|WS_BORDER|ES_MULTILINE, CRect(CPoint(94, 12), CSize(101, 21)), this, IDC_EDIT_NEW);
|
||
m_btnOk.Create(_T("确定"), WS_VISIBLE|WS_CHILD, CRect(CPoint(33, 45), CSize(75, 21)), this, IDOK);
|
||
m_btnCancel.Create(_T("取消"), WS_VISIBLE|WS_CHILD, CRect(CPoint(120, 45), CSize(75, 21)), this, IDCANCEL);
|
||
return CModelessDialog::OnInitDialog();
|
||
}
|
||
|
||
void CLayerStandardDlg::OnOK()
|
||
{
|
||
m_edt.GetWindowText(m_szNewStandard);
|
||
CModelessDialog::OnOK();
|
||
}
|
||
#else
|
||
|
||
#endif |