1214 lines
34 KiB
C++
1214 lines
34 KiB
C++
// LayerManBar.cpp: implementation of the CLayerManBar class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
|
|
//#include <arxtools.h>
|
|
//#include <DbObject.h>
|
|
//#include <dbwall.h>
|
|
|
|
|
|
#include "tapi.h"
|
|
#include "Resource.h"
|
|
#include "ChangeLayerDlg.h"
|
|
#include "twtdef.h"
|
|
#include "TelDef.h"
|
|
|
|
#if (ADS>16)
|
|
#include "dblstate.h"
|
|
#endif
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
|
|
XStringList g_lstCloseLay;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// 打开全部层
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
GEOAPI double g_nAcadVer;
|
|
|
|
void OpenAllLayer()
|
|
{
|
|
if(g_nProductId==14){ //给排水软件单独处理
|
|
acDocManager->sendStringToExecute(curDoc(), _T("SetAllPipeLayOpen "), true, false, false);
|
|
return;
|
|
}
|
|
XSymbolList lstLayer(_T("LAYER"));
|
|
int len = lstLayer.Length();
|
|
for(int i=0; i<len ; i++){
|
|
CString csLayer = (const TCHAR *)lstLayer[i];
|
|
if(!IsLayerOn((const TCHAR *)csLayer)){
|
|
AcDbDatabase *dwg=acdbCurDwg();
|
|
AcAxDocLock docLock(dwg);
|
|
SetLayerOnOff((const TCHAR *)csLayer, TRUE);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// 锁定图层
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
void LockSelLayer()
|
|
{
|
|
PickSet ss(SS_FREE);
|
|
if(SelectEntities(_T("请选择要锁定层上的图元 <退出>:"), ss, RBList()) != RTNORM)
|
|
return;
|
|
long length = ss.Length();
|
|
|
|
XStringList lstExist, lstLock;
|
|
for(long j=0;j<length;j++){
|
|
Entity ent = ss[j];
|
|
TCHAR szLay[256];
|
|
ent.GetData(8, szLay);
|
|
|
|
AcDbLayerTable *pLayertable = NULL;
|
|
AcDbLayerTableRecord *pLayerRec = NULL;
|
|
acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead);
|
|
if(!pLayertable)
|
|
return;
|
|
if((pLayertable->getAt(szLay, pLayerRec, AcDb::kForRead)) == Acad::eOk) {
|
|
if(pLayerRec->isLocked()){
|
|
if(lstExist.Index(szLay) < 0)
|
|
lstExist.Append(tstrnew(szLay));
|
|
}
|
|
else{
|
|
if(lstLock.Index(szLay) < 0)
|
|
lstLock.Append(tstrnew(szLay));
|
|
|
|
if(pLayerRec->upgradeOpen()==Acad::eOk && g_nProductId == 14) // 给排水
|
|
{
|
|
pLayerRec->setIsLocked(Adesk::kTrue); // 打开
|
|
pLayerRec->downgradeOpen();
|
|
}
|
|
}
|
|
pLayerRec->close();
|
|
pLayertable->close();
|
|
}
|
|
else
|
|
pLayertable->close();
|
|
}
|
|
for(int i=0;i<lstExist.Length();i++){
|
|
CString csTmp = lstExist[i];
|
|
if(lstLock.Index((const TCHAR*)csTmp) < 0)
|
|
adsout << _T("\n") << (const TCHAR*)csTmp << _T("层本身就是锁定的!");
|
|
}
|
|
//mod liaoy 171213 对于带#的图层此方式无法锁定/解锁
|
|
/*
|
|
// 2011-10-24 沈睿取消ACAD命令方式,改arx函数。08以上锁定图层会让整个图re,自定义对象重绘速度慢
|
|
if(g_nProductId != 14)
|
|
{
|
|
//非自定义实体软件(电气),还是用ads_command方法比REGEN快很多
|
|
for(i=0;i<lstLock.Length();i++){
|
|
CString csTmp = lstLock[i];
|
|
//mod liaoy 170720 20平台的命令会弹出一个界面,采用新方法
|
|
//ads_command(RTSTR, _T("_-layer"), RTSTR, _T("LO"), RTSTR, csTmp, RTNONE);
|
|
ads_command(RTSTR, _T("_-layer"), RTSTR, _T("LO"), RTSTR, csTmp, RTSTR, _T(""), RTNONE);
|
|
//mod end
|
|
adsout << _T("\n") << (const TCHAR*)csTmp << _T("层已经锁定!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
#if (ADS>16)
|
|
AcDbLayerStateManager* pLayerState = ::acdbHostApplicationServices()->workingDatabase()->getLayerStateManager();
|
|
if(pLayerState != NULL)
|
|
{
|
|
pLayerState->saveLayerState(L"TEMP_STATE", AcDbLayerStateManager::kAll, AcDbObjectId::kNull);
|
|
pLayerState->restoreLayerState(L"TEMP_STATE");
|
|
pLayerState->deleteLayerState(L"TEMP_STATE");
|
|
adsout << _T("需要手工REGEN才能更新锁定图层透明效果\n");
|
|
}
|
|
#endif
|
|
}
|
|
*/
|
|
if(g_nProductId != 14)
|
|
{
|
|
for(i=0;i<lstLock.Length();i++){
|
|
CString csTmp = lstLock[i];
|
|
SetLayerLockedTel(csTmp,true);
|
|
adsout << _T("\n") << (const TCHAR*)csTmp << _T("层已经锁定!");
|
|
}
|
|
}
|
|
UpdateLayerLockFade(TRUE);
|
|
//mod end
|
|
ads_command(RTNONE);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//void SelLayer(BOOL bOpen)
|
|
//{
|
|
// PickSet ss(SS_FREE);
|
|
// CString csPrompt;
|
|
// if(bOpen)
|
|
// csPrompt = _T("请选择打开层上的图元 <退出>:");
|
|
// else
|
|
// csPrompt = _T("请选择关闭层上的图元 <退出>:");
|
|
// if(SelectEntities(csPrompt, ss, RBList()) != RTNORM)
|
|
// return;
|
|
// long length = ss.Length();
|
|
// XStringList lstLay;
|
|
// for(long j=0;j<length;j++){
|
|
// Entity ent = ss[j];
|
|
// TCHAR szLay[256];
|
|
// ent.GetData(8, szLay);
|
|
// if(lstLay.Index(szLay, 0) < 0)
|
|
// lstLay.Append(tstrnew(szLay));
|
|
// }
|
|
//
|
|
// XSymbolList lstLayer(_T("LAYER"));
|
|
// int len = lstLayer.Length();
|
|
// for(int i=0; i<len; i++){
|
|
// CString csLayer = (const TCHAR *)lstLayer[i];
|
|
// if(bOpen){
|
|
// if(lstLay.Index(csLayer, 0) < 0)
|
|
// SetLayerOnOff((const TCHAR *)csLayer, FALSE);
|
|
// else
|
|
// SetLayerOnOff((const TCHAR *)csLayer, TRUE);
|
|
// }
|
|
// else{
|
|
// if(!(lstLay.Index((const TCHAR *)csLayer, 0) < 0))
|
|
// SetLayerOnOff((const TCHAR *)csLayer, FALSE);
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// 锁非选层
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
BOOL SetLayerLock(const TCHAR*szLayerName, BOOL bLock)
|
|
{
|
|
// if(g_nAcadVer>14.01) // ACAD2008 以上版本才有的功能 2009-8-18 sr 取消以下,非模式对话框调用无法执行
|
|
// {
|
|
// if(bLock) //利用acad命令调用锁定,可以实现图层颜色变淡
|
|
// ads_command(RTSTR, _T("_-layer"), RTSTR, _T("LO"), RTSTR, szLayerName, RTNONE);
|
|
// else
|
|
// ads_command(RTSTR, _T("_-layer"), RTSTR, _T("U"), RTSTR, szLayerName, RTNONE);
|
|
// ads_command(RTNONE);
|
|
// }
|
|
// else
|
|
// {
|
|
AcDbLayerTable *pLayertable = NULL;
|
|
AcDbLayerTableRecord *pLayerRec = NULL;
|
|
acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead);
|
|
if(!pLayertable)
|
|
return FALSE;
|
|
|
|
if((pLayertable->getAt(szLayerName, pLayerRec, AcDb::kForWrite)) == Acad::eOk) {
|
|
if(bLock)
|
|
pLayerRec->setIsLocked(Adesk::kTrue);
|
|
else
|
|
pLayerRec->setIsLocked(Adesk::kFalse);
|
|
pLayerRec->close();
|
|
pLayertable->close();
|
|
}
|
|
else
|
|
pLayertable->close();
|
|
// }
|
|
return TRUE;
|
|
}
|
|
//add liaoy 170801
|
|
BOOL SetLayerLock(XStringList& lstLayerName, BOOL bLock)
|
|
{
|
|
for (int i = 0;i < lstLayerName.Length();i++)
|
|
{
|
|
CString csLayer = (const TCHAR *)lstLayerName[i];
|
|
SetLayerLock(csLayer,bLock);
|
|
}
|
|
return TRUE;
|
|
}
|
|
//add end
|
|
|
|
BOOL IsLayerLocked(CString csLay)
|
|
{
|
|
BOOL bRet(FALSE);
|
|
AcDbLayerTable *pLayertable = NULL;
|
|
AcDbLayerTableRecord *pLayerRec = NULL;
|
|
acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead);
|
|
if(!pLayertable)
|
|
return bRet;
|
|
if((pLayertable->getAt(csLay, pLayerRec, AcDb::kForRead)) == Acad::eOk) {
|
|
if(pLayerRec->isLocked() == false){
|
|
bRet = FALSE;
|
|
}
|
|
else{
|
|
bRet = TRUE;
|
|
}
|
|
pLayerRec->close();
|
|
pLayertable->close();
|
|
}
|
|
else
|
|
pLayertable->close();
|
|
|
|
return bRet;
|
|
}
|
|
|
|
XStringList g_lstLuckLay;
|
|
void LockNoSelLayer()
|
|
{
|
|
PickSet ss(SS_FREE);
|
|
if(SelectEntities(_T("请选择要保留不被锁定层上的图元<退出>:"), ss, RBList()) != RTNORM)
|
|
return;
|
|
g_lstLuckLay.Reset();
|
|
long length = ss.Length();
|
|
XStringList lstLay;
|
|
for(long j=0;j<length;j++){
|
|
Entity ent = ss[j];
|
|
TCHAR szLay[256];
|
|
ent.GetData(8, szLay);
|
|
if(lstLay.Index(szLay, 0) < 0)
|
|
lstLay.Append(tstrnew(szLay));
|
|
if(ent.Is(_T("ATS_PIPE"))){//如果是管线,把相关的设备层也打开
|
|
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
DList<AcDbObjectId> lstAttachment;
|
|
pPipe->GetAttachments(lstAttachment);
|
|
int leng = lstAttachment.Length();
|
|
for(int m=0;m<leng;m++){
|
|
AcDbObjectId idTmp = *lstAttachment[m];
|
|
OPENOBJ_BEGIN(idTmp, AcDb::kForRead, TDbPipeAttachment, pEquip);
|
|
if(pEquip){
|
|
TCHAR *chlayer = pEquip->layer();
|
|
CString csLayer = chlayer;
|
|
delete [] chlayer;
|
|
if(lstLay.Index(csLayer, 0) < 0)
|
|
lstLay.Append(tstrnew(csLayer));
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
AcDbObjectId nodeId1(NULL), nodeId2(NULL);
|
|
nodeId1 = pPipe->GetNode(0);
|
|
nodeId2 = pPipe->GetNode(1);
|
|
OPENOBJ_BEGIN(nodeId1, AcDb::kForRead, TDbPipeNode, pEquip);
|
|
if(pEquip){
|
|
TCHAR *chlayer = pEquip->layer();
|
|
CString csLayer = chlayer;
|
|
delete [] chlayer;
|
|
if(lstLay.Index(csLayer, 0) < 0)
|
|
lstLay.Append(tstrnew(csLayer));
|
|
}
|
|
OPENOBJ_END();
|
|
OPENOBJ_BEGIN(nodeId2, AcDb::kForRead, TDbPipeNode, pEquip);
|
|
if(pEquip){
|
|
TCHAR *chlayer = pEquip->layer();
|
|
CString csLayer = chlayer;
|
|
delete [] chlayer;
|
|
if(lstLay.Index(csLayer, 0) < 0)
|
|
lstLay.Append(tstrnew(csLayer));
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
|
|
XStringList lstLayLock,lstLayUnLock;//add liaoy 170801
|
|
XSymbolList lstLayer(_T("LAYER"));
|
|
int len = lstLayer.Length();
|
|
for(int i=0; i<len; i++){
|
|
CString csLayer = (const TCHAR *)lstLayer[i];
|
|
if(lstLay.Index(csLayer, 0) < 0){
|
|
if(!IsLayerLocked(csLayer))
|
|
g_lstLuckLay.Append(tstrnew(csLayer));
|
|
//mod liaoy 170801
|
|
//SetLayerLock((const TCHAR *)csLayer, TRUE);
|
|
lstLayLock.Append(tstrnew(csLayer));
|
|
//mod end
|
|
}
|
|
else
|
|
//mod liaoy 170801
|
|
//SetLayerLock((const TCHAR *)csLayer, FALSE);
|
|
lstLayUnLock.Append(tstrnew(csLayer));
|
|
//mod end
|
|
}
|
|
len = lstLay.Length();
|
|
for(i=0;i<len;i++){
|
|
CString csLay = lstLay[i];
|
|
csLay.Format(_T("%s 层打开\n"), csLay);
|
|
adsout << (const TCHAR*)csLay;
|
|
}
|
|
adsout << _T("\n其它层已经锁定。您可以用【解锁图层】命令打开他们。");
|
|
//mod liaoy 170801
|
|
/*
|
|
#if (ADS>=20)
|
|
SetLayerLockedTel(lstLayLock,true);
|
|
SetLayerLockedTel(lstLayUnLock,false);
|
|
#else
|
|
AcAxDocLock docLock(acdbCurDwg());
|
|
SetLayerLock(lstLayLock,TRUE);
|
|
SetLayerLock(lstLayUnLock,FALSE);
|
|
#if (ADS>16) //2011-11-1 SR ADD ADN 梁晓冬的方法(需要REGEN)
|
|
AcDbLayerStateManager* pLayerState = ::acdbHostApplicationServices()->workingDatabase()->getLayerStateManager();
|
|
if(pLayerState != NULL)
|
|
{
|
|
pLayerState->saveLayerState(L"TEMP_STATE", AcDbLayerStateManager::kAll, AcDbObjectId::kNull);
|
|
pLayerState->restoreLayerState(L"TEMP_STATE");
|
|
pLayerState->deleteLayerState(L"TEMP_STATE");
|
|
adsout << _T("需要手工REGEN才能更新锁定图层透明效果\n");
|
|
}
|
|
#endif
|
|
#endif
|
|
*/
|
|
SetLayerLockedTel(lstLayLock,true);
|
|
SetLayerLockedTel(lstLayUnLock,false);
|
|
UpdateLayerLockFade(TRUE);
|
|
//mod end
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// 解锁图层
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
void UnLockSelLayer()
|
|
{
|
|
PickSet ss(SS_FREE);
|
|
int len = g_lstLuckLay.Length();
|
|
BOOL flag = FALSE;
|
|
if(len > 0){
|
|
for(int i=0;i<len;i++){
|
|
CString csLayer = (const TCHAR *)g_lstLuckLay[i];
|
|
if(!IsLayerLocked(csLayer)){
|
|
flag = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if(flag == FALSE && len > 0){
|
|
TCHAR szYes[256];
|
|
int ret = ads_getstring(0, _T("\n执行【锁非选层】后,锁定了若干图层,是否全部打开?(N继续执行)<Y>:"), szYes);
|
|
if(_tcsicmp(szYes, _T("N")) != 0){
|
|
//mod liaoy 170801
|
|
//for(int i=0;i<len;i++){
|
|
// CString csLayer = (const TCHAR *)g_lstLuckLay[i];
|
|
// SetLayerLock((const TCHAR *)csLayer, FALSE);
|
|
//}
|
|
//g_lstLuckLay.Reset();
|
|
/*
|
|
#if (ADS>=20)
|
|
SetLayerLockedTel(g_lstLuckLay,false);
|
|
#else
|
|
AcAxDocLock docLock(acdbCurDwg());
|
|
SetLayerLock(g_lstLuckLay,false);
|
|
#if (ADS>16)
|
|
AcDbLayerStateManager* pLayerState = ::acdbHostApplicationServices()->workingDatabase()->getLayerStateManager();
|
|
if(pLayerState != NULL)
|
|
{
|
|
pLayerState->saveLayerState(L"TEMP_STATE", AcDbLayerStateManager::kAll, AcDbObjectId::kNull);
|
|
pLayerState->restoreLayerState(L"TEMP_STATE");
|
|
pLayerState->deleteLayerState(L"TEMP_STATE");
|
|
adsout << _T("需要手工REGEN才能更新锁定图层透明效果\n");
|
|
}
|
|
#endif
|
|
#endif
|
|
*/
|
|
SetLayerLockedTel(g_lstLuckLay,false);
|
|
UpdateLayerLockFade(TRUE);
|
|
g_lstLuckLay.Reset();
|
|
//mod end
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
int ret = SelectEntities(_T("请选择要解锁层上的图元(ESC退出,空格解开全部层) <全部>:"), ss, RBList());
|
|
if(ret == RTCAN)
|
|
return;
|
|
else if(ret != RTNORM){//解开全部层
|
|
XSymbolList lstLayer(_T("LAYER"));
|
|
XStringList lstLayerDeal;
|
|
int len = lstLayer.Length();
|
|
for(int i=0; i<len; i++){
|
|
CString csLayer = (const TCHAR *)lstLayer[i];
|
|
//mod liaoy 170801
|
|
//SetLayerLock((const TCHAR *)csLayer, FALSE);
|
|
lstLayerDeal.Append(tstrnew(csLayer));
|
|
//mod end
|
|
}
|
|
g_lstLuckLay.Reset();
|
|
//mod liaoy 170801
|
|
/*
|
|
#if (ADS>=20)
|
|
SetLayerLockedTel(lstLayerDeal,false);
|
|
#else
|
|
AcAxDocLock docLock(acdbCurDwg());
|
|
SetLayerLock(lstLayerDeal,false);
|
|
#if (ADS>16)
|
|
AcDbLayerStateManager* pLayerState = ::acdbHostApplicationServices()->workingDatabase()->getLayerStateManager();
|
|
if(pLayerState != NULL)
|
|
{
|
|
pLayerState->saveLayerState(L"TEMP_STATE", AcDbLayerStateManager::kAll, AcDbObjectId::kNull);
|
|
pLayerState->restoreLayerState(L"TEMP_STATE");
|
|
pLayerState->deleteLayerState(L"TEMP_STATE");
|
|
adsout << _T("需要手工REGEN才能更新锁定图层透明效果\n");
|
|
}
|
|
#endif
|
|
#endif
|
|
*/
|
|
SetLayerLockedTel(lstLayerDeal,false);
|
|
UpdateLayerLockFade(TRUE);
|
|
//mod end
|
|
return;
|
|
}
|
|
g_lstLuckLay.Reset();
|
|
|
|
long length = ss.Length();
|
|
XStringList lstExist, lstLock;
|
|
|
|
for(long j=0;j<length;j++){
|
|
Entity ent = ss[j];
|
|
TCHAR szLay[256];
|
|
ent.GetData(8, szLay);
|
|
|
|
AcDbLayerTable *pLayertable = NULL;
|
|
AcDbLayerTableRecord *pLayerRec = NULL;
|
|
acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead);
|
|
if(!pLayertable)
|
|
return;
|
|
if((pLayertable->getAt(szLay, pLayerRec, AcDb::kForRead)) == Acad::eOk) {
|
|
if(pLayerRec->isLocked() == false){
|
|
if(lstExist.Index(szLay) < 0)
|
|
lstExist.Append(tstrnew(szLay));
|
|
}
|
|
else{
|
|
if(lstLock.Index(szLay) < 0)
|
|
lstLock.Append(tstrnew(szLay));
|
|
|
|
if(pLayerRec->upgradeOpen()==Acad::eOk && g_nProductId == 14) // 给排水
|
|
{
|
|
pLayerRec->setIsLocked(Adesk::kFalse); // 打开
|
|
pLayerRec->downgradeOpen();
|
|
}
|
|
}
|
|
pLayerRec->close();
|
|
pLayertable->close();
|
|
}
|
|
else
|
|
pLayertable->close();
|
|
}
|
|
for(int i=0;i<lstExist.Length();i++){
|
|
CString csTmp = lstExist[i];
|
|
if(lstLock.Index((const TCHAR*)csTmp) < 0)
|
|
adsout << _T("\n") << (const TCHAR*)csTmp << _T("层本身就没有锁定!");
|
|
}
|
|
|
|
//mod liaoy 171213对于带#的图层此方式无法锁定/解锁
|
|
/*
|
|
// 2011-10-24 沈睿取消ACAD命令方式,改arx函数。08以上锁定图层会让整个图re,自定义对象重绘速度慢
|
|
if(g_nProductId != 14)
|
|
{
|
|
//非自定义实体软件(电气),还是用ads_command方法比REGEN快很多
|
|
for(i=0;i<lstLock.Length();i++){
|
|
CString csTmp = lstLock[i];
|
|
//mod liaoy 170720 20平台的命令会弹出一个界面,采用新方法
|
|
//ads_command(RTSTR, _T("_-layer"), RTSTR, _T("U"), RTSTR, csTmp, RTNONE);
|
|
ads_command(RTSTR, _T("_-layer"), RTSTR, _T("U"), RTSTR, csTmp, RTSTR, _T(""), RTNONE);
|
|
//mod end
|
|
adsout << _T("\n") << (const TCHAR*)csTmp << _T("层已经解锁!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
#if (ADS>16) //2011-11-1 SR ADD ADN 梁晓冬的方法(需要REGEN)
|
|
AcDbLayerStateManager* pLayerState = ::acdbHostApplicationServices()->workingDatabase()->getLayerStateManager();
|
|
if(pLayerState != NULL)
|
|
{
|
|
pLayerState->saveLayerState(L"TEMP_STATE", AcDbLayerStateManager::kAll, AcDbObjectId::kNull);
|
|
pLayerState->restoreLayerState(L"TEMP_STATE");
|
|
pLayerState->deleteLayerState(L"TEMP_STATE");
|
|
adsout << _T("需要手工REGEN才能更新锁定图层透明效果\n");
|
|
}
|
|
#endif
|
|
}
|
|
*/
|
|
if(g_nProductId != 14)
|
|
{
|
|
for(i=0;i<lstLock.Length();i++){
|
|
CString csTmp = lstLock[i];
|
|
SetLayerLockedTel(csTmp,false);
|
|
adsout << _T("\n") << (const TCHAR*)csTmp << _T("层已经解锁!");
|
|
}
|
|
}
|
|
UpdateLayerLockFade(TRUE);
|
|
//mod end
|
|
ads_command(RTNONE);
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// 改为上华层(电气)
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
void ChangeLayer()
|
|
{
|
|
PickSet ss(SS_FREE);
|
|
if(SelectEntities(_T("请选择要改层的图元 <退出>:"), ss, RBList()) != RTNORM)
|
|
return;
|
|
CAcModuleResourceOverride exm;
|
|
CChangeLayerDlg dlg;
|
|
if(dlg.DoModal() != IDOK)
|
|
return;
|
|
long sslen = ss.Length();
|
|
if(dlg.m_csRet == "tg"){ //把图元打上建筑标记,不去修改图层
|
|
XStringList lst;
|
|
|
|
for(long j=0;j<sslen;j++){
|
|
Entity entTmp = ss[j];
|
|
TCHAR szLayer[256];
|
|
entTmp.GetData(8, szLayer);
|
|
// if(lst.Index(szLayer) < 0){
|
|
WriteXdata(entTmp, _T("TG-LAYER"), _T("TArch"));
|
|
// }
|
|
}
|
|
return;
|
|
}
|
|
|
|
|
|
InitLayer(dlg.m_csRet);
|
|
for(long j=0;j<sslen;j++){
|
|
Entity entTmp = ss[j];
|
|
AcDbObjectId eId;
|
|
AcDbEntity *pEnt = NULL;
|
|
acdbGetObjectId(eId, entTmp);
|
|
acdbOpenObject(pEnt, eId, AcDb::kForWrite);
|
|
if(pEnt){
|
|
pEnt->setLayer(dlg.m_csRet);
|
|
pEnt->close();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// 删除选择层
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
void EraseSelLayer()
|
|
{
|
|
PickSet ss(SS_FREE);
|
|
if(SelectEntities(_T("请选择删除层上的图元 <退出>:"), ss, RBList()) != RTNORM)
|
|
return;
|
|
long length = ss.Length();
|
|
|
|
for(long j=0;j<length;j++){
|
|
Entity ent = ss[j];
|
|
TCHAR szLay[256];
|
|
ent.GetData(8, szLay);
|
|
RBList rbMask(RTDXF0, _T("*"), 8, szLay, NULL);
|
|
PickSet ssLay(SS_FREE);
|
|
ssLay.Get(_T("X"), NULL, NULL, rbMask);
|
|
long jj = ssLay.Length();
|
|
ssLay.Erase();
|
|
}
|
|
}
|
|
|
|
|
|
void SelLayer(BOOL bOpen)
|
|
{
|
|
PickSet ss(SS_FREE);
|
|
CString csPrompt;
|
|
if(bOpen)
|
|
csPrompt = _T("请选择打开层上的图元 <退出>:");
|
|
else
|
|
csPrompt = _T("请选择关闭层上的图元 <退出>:");
|
|
if(SelectEntities(csPrompt, ss, RBList()) != RTNORM)
|
|
return;
|
|
if(bOpen)
|
|
g_lstCloseLay.Reset();
|
|
long length = ss.Length();
|
|
XStringList lstLay;
|
|
CString csCurLay;
|
|
for(long j=0;j<length;j++){
|
|
Entity ent = ss[j];
|
|
TCHAR szLay[256];
|
|
ent.GetData(8, szLay);
|
|
csCurLay = szLay;
|
|
if(lstLay.Index(szLay, 0) < 0)
|
|
lstLay.Append(tstrnew(szLay));
|
|
}
|
|
|
|
XSymbolList lstLayer(_T("LAYER"));
|
|
int len = lstLayer.Length();
|
|
for(int i=0; i<len; i++){
|
|
CString csLayer = (const TCHAR *)lstLayer[i];
|
|
if(bOpen){
|
|
if(lstLay.Index(csLayer, 0) < 0)
|
|
{
|
|
SetLayerOnOff((const TCHAR *)csLayer, FALSE);
|
|
g_lstCloseLay.Append(tstrnew(csLayer));
|
|
}
|
|
else
|
|
SetLayerOnOff((const TCHAR *)csLayer, TRUE);
|
|
}
|
|
else{
|
|
if(!(lstLay.Index((const TCHAR *)csLayer, 0) < 0))
|
|
SetLayerOnOff((const TCHAR *)csLayer, FALSE);
|
|
}
|
|
}
|
|
|
|
// if(bOpen)//只开选择层,把该层设置为当前层 sr 2012-1-13 取消设置当前层,大多时候用“只开选择层命令”只是为了整体看一下这个层图,而不是在单独这个层上画图。
|
|
// {
|
|
// xg_setvar(_T("CLAYER"), csCurLay);
|
|
// }
|
|
// if(g_pLayerBar) {
|
|
// g_pLayerBar->OnLayerChanged(NULL, NULL);
|
|
// }
|
|
}
|
|
|
|
void OpenSelLayer()
|
|
{
|
|
SelLayer(TRUE);
|
|
}
|
|
|
|
BOOL IsExternalBlock(Entity entBlk)
|
|
{
|
|
if(!entBlk.Is(_T("INSERT")))
|
|
return FALSE;
|
|
BOOL bRet = FALSE;
|
|
TCHAR szBlkName[256];
|
|
entBlk.GetData(2, szBlkName);
|
|
|
|
AcDbBlockTable* pBlockTable = NULL;
|
|
AcDbBlockTableRecord *pRecord = NULL;
|
|
acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead);
|
|
if(Acad::eOk != pBlockTable->getAt(szBlkName, pRecord, AcDb::kForRead))
|
|
return FALSE;
|
|
pBlockTable->close();
|
|
if(pRecord->isFromExternalReference() == true){
|
|
bRet = TRUE;
|
|
}
|
|
if(pRecord)
|
|
pRecord->close();
|
|
return bRet;
|
|
}
|
|
|
|
BOOL HitTestEntity(AcDbEntity *pEntIn, XPoint ptPick, AcGeMatrix3d mat)
|
|
{
|
|
BOOL bRet = FALSE;
|
|
AcDbVoidPtrArray entitySet;
|
|
pEntIn->explode(entitySet);
|
|
int len = entitySet.length();
|
|
for(int i=0;i<len;i++){
|
|
AcDbEntity *pEnt = (AcDbEntity *)entitySet[i];
|
|
AcDbLine *pLine = NULL;
|
|
AcDbSolid *pSolid = NULL;
|
|
AcDbPolyline *pPoly = NULL;
|
|
AcDbArc *pArc = NULL;
|
|
AcDbCircle *pCir = NULL;
|
|
|
|
XCurveSegment seg;
|
|
if(pLine = AcDbLine::cast(pEnt)){
|
|
AcGePoint3d ptStart = pLine->startPoint();
|
|
ptStart = ptStart.transformBy(mat);
|
|
AcGePoint3d ptEnd = pLine->endPoint();
|
|
ptEnd = ptEnd.transformBy(mat);
|
|
XLine line(asDblArray(ptStart), asDblArray(ptEnd), 1);
|
|
if(IsPtOnLine(ptPick, line, 50)){
|
|
ReleaseEntSet(entitySet);
|
|
return TRUE;
|
|
}
|
|
}
|
|
else if(pSolid = AcDbSolid::cast(pEnt)){
|
|
AcGePoint3d pt1, pt2, pt3, pt4;
|
|
XPoly2D poly;
|
|
pSolid->getPointAt(0, pt1);
|
|
pSolid->getPointAt(1, pt2);
|
|
pSolid->getPointAt(2, pt3);
|
|
pSolid->getPointAt(3, pt4);
|
|
poly.AppendNode(pt1);
|
|
poly.AppendNode(pt2);
|
|
poly.AppendNode(pt4);//Solid是1,2,3组成三角形;2,3,4组成三角形,2,3点是共用的
|
|
poly.AppendNode(pt3);
|
|
poly.AppendNode(pt1);
|
|
poly.TransformBy(mat);
|
|
int m = poly.HitTestOnCurve(ptPick);
|
|
if(m != 0){
|
|
ReleaseEntSet(entitySet);
|
|
return TRUE;
|
|
}
|
|
}
|
|
else if(pArc = AcDbArc::cast(pEnt)){
|
|
AcGePoint3d ptIns = pArc->center();
|
|
ptIns = ptIns.transformBy(mat);
|
|
XArc arc(asDblArray(ptIns), pArc->radius(), pArc->startAngle(), pArc->endAngle());
|
|
if(IsPtOnArc(ptPick, arc, 50)){
|
|
ReleaseEntSet(entitySet);
|
|
return TRUE;
|
|
}
|
|
}
|
|
else if(pCir = AcDbCircle::cast(pEnt)){
|
|
AcGePoint3d ptIns = pCir->center();
|
|
ptIns = ptIns.transformBy(mat);
|
|
XCircle cir(asDblArray(ptIns), pCir->radius());
|
|
if(IsPtOnCircle(ptPick, cir, 50)){
|
|
ReleaseEntSet(entitySet);
|
|
return TRUE;
|
|
}
|
|
}
|
|
else if(pPoly = AcDbPolyline::cast(pEnt)){
|
|
XPoly2D poly;
|
|
PolyConvert(*pPoly, poly);
|
|
poly.TransformBy(mat);
|
|
int m = poly.HitTestOnCurve(ptPick);
|
|
if(m != 0){
|
|
ReleaseEntSet(entitySet);
|
|
return TRUE;
|
|
}
|
|
}
|
|
}
|
|
ReleaseEntSet(entitySet);
|
|
return bRet;
|
|
}
|
|
|
|
void CloseLayer(const TCHAR* szLay)
|
|
{
|
|
|
|
CString csLayer = szLay;
|
|
if(csLayer == _T("0") || csLayer == _T("")){
|
|
adsout<< _T("\n0层不能关闭!");
|
|
return;
|
|
}
|
|
SetLayerOnOff(csLayer, FALSE);
|
|
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");
|
|
SetLayerOnOff(csTmp, FALSE);
|
|
}
|
|
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");
|
|
SetLayerOnOff(csTmp, FALSE);
|
|
}
|
|
// if(g_pLayerBar) {
|
|
// g_pLayerBar->OnLayerChanged(NULL, NULL);
|
|
// }
|
|
adsout<< XString(_T("\n已经成功把%s层关闭!"), csLayer);
|
|
}
|
|
|
|
//如果参照的图块内图元图层为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;
|
|
}
|
|
|
|
|
|
|
|
void CloseSelLayer()
|
|
{
|
|
g_ssPickFirst.Free();
|
|
Entity entSel;
|
|
if(SelectEntity(_T("请选择关闭层上的图元或外部参照上的图元<退出>:"), entSel, RBList()) != RTNORM)
|
|
return;
|
|
g_lstCloseLay.Reset();
|
|
|
|
XPushVar<int> vOsMode(_T("OSMODE"), 0);
|
|
XStringList lstLay;
|
|
CString csLayer, csBlkLay;
|
|
|
|
TCHAR szLay[256];
|
|
if(IsExternalBlock(entSel)){//外部参照
|
|
AcDbObjectId objId;
|
|
Acad::ErrorStatus es;
|
|
ads_point ptResult;
|
|
ads_name ent;
|
|
ads_matrix xformres;
|
|
resbuf* refstkres;
|
|
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);
|
|
//如果参照的图块内图元图层为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)
|
|
csLayer = GetExternalBlkLayer(entSel, ptResult, ownID);
|
|
}
|
|
CloseLayer(csLayer);
|
|
g_lstCloseLay.Append(tstrnew(csLayer));
|
|
}
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
}
|
|
else{
|
|
entSel.GetData(8, szLay);
|
|
csLayer = szLay;
|
|
CloseLayer(csLayer);
|
|
CString csPipeTextLay;
|
|
TPipeSys::SysType sys;
|
|
sys = GetPipeSysByLayer(csLayer);
|
|
csPipeTextLay = GetTextLayBySys(sys);
|
|
if(csPipeTextLay != _T("")){ //2012-8-16 关闭上华管线图层,可以自动关闭管线上的标注Dn图层
|
|
CloseLayer(csPipeTextLay);
|
|
g_lstCloseLay.Append(tstrnew(csPipeTextLay));
|
|
}
|
|
|
|
g_lstCloseLay.Append(tstrnew(csLayer));
|
|
|
|
while(SelectEntity(_T("请选择关闭层上的图元或外部参照上的图元<退出>:"), entSel, RBList()) == RTNORM){
|
|
entSel.GetData(8, szLay);
|
|
csLayer = szLay;
|
|
CloseLayer(csLayer);
|
|
|
|
sys = GetPipeSysByLayer(csLayer);
|
|
csPipeTextLay = GetTextLayBySys(sys);
|
|
if(csPipeTextLay != _T("")){
|
|
CloseLayer(csPipeTextLay);
|
|
g_lstCloseLay.Append(tstrnew(csPipeTextLay));
|
|
}
|
|
|
|
g_lstCloseLay.Append(tstrnew(csLayer));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
int GetLayerColorIdx(const TCHAR *szLayer)
|
|
{
|
|
XString fullFile;
|
|
if(FindFile(_T("layerdef.dat"), fullFile)) {
|
|
FILE *fp=fopen(_AS(fullFile), "r");
|
|
if(!fp)
|
|
return -1;
|
|
while(!feof(fp)) {
|
|
char sBuf[256]="";
|
|
TCHAR cName[256]=_T(""), eName[256]=_T(""), sColor[256]=_T("");
|
|
fgets(sBuf, 255, fp);
|
|
if(sBuf[0]) {
|
|
CT_strnth(TString(sBuf), 1, cName);
|
|
CT_strnth(TString(sBuf), 2, eName);
|
|
CT_strnth(TString(sBuf), 3, sColor);
|
|
}
|
|
if(_tcscmp(szLayer, eName) == 0){
|
|
fclose(fp);
|
|
int nColor=_ttoi(sColor);
|
|
return nColor;
|
|
}
|
|
}
|
|
fclose(fp);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void SetLayerColorIdx(const TCHAR *szLayer, int iColor)
|
|
{
|
|
DList<CLayerData> lstLayer;
|
|
XString fullFile;
|
|
if(FindFile(_T("layerdef.dat"), fullFile)) {
|
|
FILE *fp=fopen(_AS(fullFile), "r");
|
|
if(!fp)
|
|
return;
|
|
while(!feof(fp)) {
|
|
char sBuf[256]="";
|
|
TCHAR cName[256]=_T(""), eName[256]=_T(""), sColor[256]=_T(""),sLineType[256]=_T(""),sDes[256]=_T("");
|
|
fgets(sBuf, 255, fp);
|
|
if(sBuf[0]) {
|
|
CT_strnth(TString(sBuf), 1, cName);
|
|
CT_strnth(TString(sBuf), 2, eName);
|
|
CT_strnth(TString(sBuf), 3, sColor);
|
|
CT_strnth(TString(sBuf), 4, sLineType);
|
|
CT_strnth(TString(sBuf), 5, sDes);
|
|
}
|
|
if(cName[0] && eName[0]) {
|
|
int nColor=_ttoi(sColor);
|
|
lstLayer.Append(new CLayerData(eName, cName, sLineType, sDes, nColor));
|
|
}
|
|
}
|
|
fclose(fp);
|
|
}
|
|
int len = lstLayer.Length();
|
|
for(int i=0;i<len;i++){
|
|
if(_tcscmp(lstLayer[i]->m_csEName, szLayer) == 0){
|
|
lstLayer[i]->m_iColor = iColor;
|
|
break;
|
|
}
|
|
}
|
|
|
|
FILE *fp = fopen(_AS(fullFile), "w");
|
|
if(!fp)
|
|
return;
|
|
len = lstLayer.Length();
|
|
for(i=0; i < len; i++){
|
|
CString csColor;
|
|
csColor.Format(_T("%d"), lstLayer[i]->m_iColor);
|
|
CString csTmp = lstLayer[i]->m_csCName + _T(" ") + lstLayer[i]->m_csEName + _T(" ") + csColor + _T(" ")
|
|
+ lstLayer[i]->m_csLinetype + _T(" ") + lstLayer[i]->m_csDes + _T("\n");
|
|
fputs(_AS(csTmp), fp);
|
|
}
|
|
fclose(fp);
|
|
|
|
AcDbObjectId idLayer = GetLayerIdFromString(szLayer);
|
|
if(!idLayer)
|
|
return;
|
|
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
|
if(pLayer) {
|
|
AcCmColor color;
|
|
color.setColorIndex(iColor);
|
|
pLayer->setColor(color);
|
|
}
|
|
else{
|
|
AfxMessageBox(_T("层写保护!"));
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
}
|
|
|
|
void SetLayerEngName(const TCHAR *szChnLayer, const TCHAR *szEngLayer) //2011-10-17 bsl
|
|
{
|
|
DList<CLayerData> lstLayer;
|
|
XString fullFile;
|
|
if(FindFile(_T("layerdef.dat"), fullFile)) {
|
|
FILE *fp=fopen(_AS(fullFile), "r");
|
|
if(!fp)
|
|
return;
|
|
while(!feof(fp)) {
|
|
char sBuf[256]="";
|
|
TCHAR cName[256]=_T(""), eName[256]=_T(""), sColor[256]=_T(""), sLineType[256]=_T(""), sDes[256]=_T("");
|
|
|
|
fgets(sBuf, 255, fp);
|
|
if(sBuf[0]) {
|
|
CT_strnth(TString(sBuf), 1, cName);
|
|
CT_strnth(TString(sBuf), 2, eName);
|
|
CT_strnth(TString(sBuf), 3, sColor);
|
|
CT_strnth(TString(sBuf), 4, sLineType);
|
|
CT_strnth(TString(sBuf), 5, sDes);
|
|
}
|
|
if(cName[0] && eName[0]) {
|
|
int nColor=_ttoi(sColor);
|
|
lstLayer.Append(new CLayerData(eName, cName, sLineType, sDes, nColor));
|
|
}
|
|
}
|
|
fclose(fp);
|
|
}
|
|
int len = lstLayer.Length();
|
|
CString csLayerOld;
|
|
for(int i=0;i<len;i++){
|
|
if(_tcscmp(lstLayer[i]->m_csCName, szChnLayer) == 0){
|
|
csLayerOld = lstLayer[i]->m_csEName;
|
|
lstLayer[i]->m_csEName = szEngLayer;
|
|
break;
|
|
}
|
|
}
|
|
|
|
FILE *fp = fopen(_AS(fullFile), "w");
|
|
if(!fp)
|
|
return;
|
|
len = lstLayer.Length();
|
|
for(i=0; i < len; i++){
|
|
CString csColor;
|
|
csColor.Format(_T("%d"), lstLayer[i]->m_iColor);
|
|
CString csTmp = lstLayer[i]->m_csCName + _T(" ") + lstLayer[i]->m_csEName + _T(" ") + csColor + _T(" ")
|
|
+ lstLayer[i]->m_csLinetype + _T(" ") + lstLayer[i]->m_csDes + _T("\n");
|
|
fputs(_AS(csTmp), fp);
|
|
}
|
|
fclose(fp);
|
|
|
|
AcDbObjectId idLayer = GetLayerIdFromString(csLayerOld);
|
|
if(!idLayer)
|
|
return;
|
|
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
|
if(pLayer) {
|
|
pLayer->setName(szEngLayer);
|
|
}
|
|
else{
|
|
AfxMessageBox(_T("层写保护!"));
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
}
|
|
|
|
void SetLayerEngName2(const TCHAR *szChnLayer, const TCHAR *szEngLayer)
|
|
{
|
|
DList<CLayerData> lstLayer;
|
|
XString fullFile;
|
|
if(FindFile(_T("layerdef.dat"), fullFile)) {
|
|
FILE *fp=fopen(_AS(fullFile), "r");
|
|
if(!fp)
|
|
return;
|
|
while(!feof(fp)) {
|
|
char sBuf[256]="";
|
|
TCHAR cName[256]=_T(""), eName[256]=_T(""), sColor[256]=_T("");
|
|
fgets(sBuf, 255, fp);
|
|
if(sBuf[0]) {
|
|
CT_strnth(TString(sBuf), 1, cName);
|
|
CT_strnth(TString(sBuf), 2, eName);
|
|
CT_strnth(TString(sBuf), 3, sColor);
|
|
}
|
|
if(cName[0] && eName[0]) {
|
|
int nColor=_ttoi(sColor);
|
|
lstLayer.Append(new CLayerData(eName, cName, nColor));
|
|
}
|
|
}
|
|
fclose(fp);
|
|
}
|
|
int len = lstLayer.Length();
|
|
CString csLayerOld;
|
|
for(int i=0;i<len;i++){
|
|
if(_tcscmp(lstLayer[i]->m_csCName, szChnLayer) == 0){
|
|
csLayerOld = lstLayer[i]->m_csEName;
|
|
lstLayer[i]->m_csEName = szEngLayer;
|
|
break;
|
|
}
|
|
}
|
|
|
|
FILE *fp = fopen(_AS(fullFile), "w");
|
|
if(!fp)
|
|
return;
|
|
len = lstLayer.Length();
|
|
for(i=0; i < len; i++){
|
|
CString csColor;
|
|
csColor.Format(_T("%d"), lstLayer[i]->m_iColor);
|
|
CString csTmp = lstLayer[i]->m_csCName + _T(" ") + lstLayer[i]->m_csEName + _T(" ") + csColor + _T("\n");
|
|
fputs(_AS(csTmp), fp);
|
|
}
|
|
fclose(fp);
|
|
|
|
AcDbObjectId idLayer = GetLayerIdFromString(csLayerOld);
|
|
if(!idLayer)
|
|
return;
|
|
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
|
if(pLayer) {
|
|
pLayer->setName(szEngLayer);
|
|
}
|
|
else{
|
|
AfxMessageBox(_T("层写保护!"));
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|