214 lines
6.7 KiB
C++
214 lines
6.7 KiB
C++
#include "stdafx.h"
|
|
|
|
//#include <arxtools.h>
|
|
//#include <DbObject.h>
|
|
//#include <dbwall.h>
|
|
|
|
|
|
#include "tapi.h"
|
|
#include "Resource.h"
|
|
//#include "ChangeLayerDlg.h"
|
|
#include "twtdef.h"
|
|
|
|
#if (ADS>16)
|
|
#include "dblstate.h"
|
|
#endif
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//如果参照的图块内图元图层为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 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);
|
|
}
|
|
|
|
adsout<< XString(_T("\n已经成功把%s层关闭!"), csLayer);
|
|
}
|
|
|
|
|
|
XStringList g_lstCloseLay;
|
|
|
|
void CloseSelLayer1()
|
|
{
|
|
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));
|
|
}
|
|
}
|
|
}
|