// LayerManBar.cpp: implementation of the CLayerManBar class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" //#include //#include //#include #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:"), ss, RBList()) != RTNORM) return; long length = ss.Length(); XStringList lstExist, lstLock; for(long j=0;jgetLayerTable(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;i16) 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:"); // else // csPrompt = _T("请选择关闭层上的图元 <退出>:"); // if(SelectEntities(csPrompt, ss, RBList()) != RTNORM) // return; // long length = ss.Length(); // XStringList lstLay; // for(long j=0;j14.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 lstAttachment; pPipe->GetAttachments(lstAttachment); int leng = lstAttachment.Length(); for(int m=0;mlayer(); 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=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 0){ TCHAR szYes[256]; int ret = ads_getstring(0, _T("\n执行【锁非选层】后,锁定了若干图层,是否全部打开?(N继续执行):"), szYes); if(_tcsicmp(szYes, _T("N")) != 0){ //mod liaoy 170801 //for(int i=0;i=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=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;jgetLayerTable(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;i16) //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:"), 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;jsetLayer(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:"); 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;jOnLayerChanged(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;istartPoint(); 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 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 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;im_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 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;im_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 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;im_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(); }