168 lines
5.1 KiB
C++
168 lines
5.1 KiB
C++
#include "stdafx.h"
|
|||
|
|
|
||
|
|
extern TARCH_IMPEXP int GetOpenPoly2D(const TCHAR *pMsg, XPoly2D &poly2d, Entity &entRet);
|
||
|
|
// Command: 给墙体增加补丁
|
||
|
|
void AddPatch()
|
||
|
|
{
|
||
|
|
// [2010-3-24 wubo] 修改bug, C004-12: 右键运行墙体造型命令,在命令行输入关键字P无效,直接退出了命令
|
||
|
|
// 这部分代码是为了弥补GetOpenPoly2D函数的缺陷,将这部分代码添加到命令的开始是为了让用户有正常的理解,
|
||
|
|
// 命令一开始便清空PICKFIRST,而不是命令执行的半途中突然实体没有了高亮。
|
||
|
|
// 构造一个空选择集,将其设置为PICKFIRST,亦即清空PICKFIRST
|
||
|
|
ads_name ssPickFirst;
|
||
|
|
if (acedSSAdd(NULL, NULL, ssPickFirst) == RTNORM)
|
||
|
|
{
|
||
|
|
int ret = acedSSSetFirst(ssPickFirst, NULL);
|
||
|
|
ret = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
static bool bConcave=false;//是否内凹
|
||
|
|
TCHAR sKey[1024]=_T("");
|
||
|
|
int nRet;
|
||
|
|
INITGET_BEG(0,_T("T A"))
|
||
|
|
if (!bConcave)
|
||
|
|
nRet=acedGetKword(_T("\n选择 [外凸造型(T)/内凹造型(A)]<外凸造型>:"),sKey);
|
||
|
|
else
|
||
|
|
nRet=acedGetKword(_T("\n选择 [外凸造型(T)/内凹造型(A)]<内凹造型>:"),sKey);
|
||
|
|
INITGET_END()
|
||
|
|
if (nRet==RTCAN)
|
||
|
|
return;
|
||
|
|
if (nRet==RTNORM)
|
||
|
|
{
|
||
|
|
if (sKey[0]==_T('T'))
|
||
|
|
bConcave=false;
|
||
|
|
else if (sKey[0]==_T('A'))
|
||
|
|
bConcave=true;
|
||
|
|
}
|
||
|
|
|
||
|
|
XPoly2D poly;
|
||
|
|
Entity entRet;
|
||
|
|
if (GetOpenPoly2D(_T("\n墙体造型轮廓起点"), poly, entRet)!=RTNORM || !poly)
|
||
|
|
return;
|
||
|
|
|
||
|
|
poly.SetFlag(1);
|
||
|
|
if (!poly || fabs(poly.PathArea())<1.0E-6)
|
||
|
|
return;
|
||
|
|
if (poly.PathArea()>0.0)
|
||
|
|
poly.Reverse(); //确保逆时针
|
||
|
|
|
||
|
|
XPoly2D polyUcs(poly);
|
||
|
|
polyUcs.TransUCS(Groups(0), Groups(1));
|
||
|
|
XPoint ptMin, ptMax;
|
||
|
|
|
||
|
|
//modified by whl on 070608
|
||
|
|
//polyUcs.GetExtend(ptMin, ptMax);
|
||
|
|
poly.GetExtend(ptMin, ptMax);
|
||
|
|
|
||
|
|
XTempZoomWindow vTemp(ptMin, ptMax);
|
||
|
|
|
||
|
|
RBList rbFence=polyUcs.Fence();
|
||
|
|
RBList mask(RTDXF0, _T("TCH_WALL,TCH_CURTAIN_WALL"), NULL);
|
||
|
|
PickSet ss(SS_FREE);
|
||
|
|
//adsout << _T("\n选择墙体!");
|
||
|
|
if (ss.Get(_T("F"), rbFence, NULL, mask)==RTNORM) {
|
||
|
|
TDbWallPatch *pEnt=new TDbWallPatch;
|
||
|
|
pEnt->SetOutlinePoly(poly);
|
||
|
|
pEnt->SetLayerHatch2d(InitLayer(LAY_HATCH, FALSE));
|
||
|
|
if (bConcave)
|
||
|
|
pEnt->SetUsageFlag(TDbWallPatch::kConcave);
|
||
|
|
pEnt->AddToMSpace(Adesk::kFalse);
|
||
|
|
long lCount=ss.Length();
|
||
|
|
for(long i=0L; i<lCount; i++) {
|
||
|
|
Entity ent=ss[i];
|
||
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbWall, pWall);
|
||
|
|
if (pWall) {
|
||
|
|
pEnt->AddPatchId(pWall->objectId());
|
||
|
|
pWall->AddPatchId(pEnt->objectId());
|
||
|
|
//pEnt->SetStyleId(pWall->GetMaterialId());
|
||
|
|
pEnt->SetElevation(pWall->GetElevation());
|
||
|
|
pEnt->SetHeight(pWall->GetHeight());
|
||
|
|
}
|
||
|
|
OPENOBJ_END();
|
||
|
|
}
|
||
|
|
if (!entRet) ;
|
||
|
|
else entRet.Delete();
|
||
|
|
|
||
|
|
pEnt->close();
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
//////////////////////////////////////////////////////////////////////
|
||
|
|
// Command: 刷新补丁
|
||
|
|
void ManualUpdatePatch()
|
||
|
|
{
|
||
|
|
RBList mask1(RTDXF0, _T("TCH_WALL_PATCH"), NULL);
|
||
|
|
Entity ent;
|
||
|
|
if (SelectEntity(_T("\n请选择墙体造型<退出>:"), ent, mask1)!=RTNORM)
|
||
|
|
return;
|
||
|
|
|
||
|
|
RBList mask(RTDXF0, _T("TCH_WALL,TCH_CURTAIN_WALL"), NULL);
|
||
|
|
PickSet ss(SS_FREE);
|
||
|
|
if (SelectEntities(_T("\n选择连接的墙体:"), ss, mask)==RTNORM) {
|
||
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbWallPatch, pPatch);
|
||
|
|
if (!pPatch)
|
||
|
|
return;
|
||
|
|
pPatch->RemoveAllLinkages();
|
||
|
|
|
||
|
|
long lCount=ss.Length();
|
||
|
|
for(long i=0L; i<lCount; i++) {
|
||
|
|
Entity entWall=ss[i];
|
||
|
|
OPENOBJ_BEGIN(entWall, AcDb::kForWrite, TDbWall, pWall);
|
||
|
|
if (pWall) {
|
||
|
|
pPatch->AddPatchId(pWall->objectId());
|
||
|
|
pWall->AddPatchId(pPatch->objectId());
|
||
|
|
}
|
||
|
|
OPENOBJ_END();
|
||
|
|
}
|
||
|
|
OPENOBJ_END();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////////////////////////
|
||
|
|
// Command: 刷新补丁
|
||
|
|
void AutoUpdatePatch()
|
||
|
|
{
|
||
|
|
RBList mask1(RTDXF0, _T("TCH_WALL_PATCH"), NULL);
|
||
|
|
PickSet ssPatches(SS_FREE);
|
||
|
|
|
||
|
|
if (SelectEntities(_T("\n请选择墙体造型:"), ssPatches, mask1)!=RTNORM)
|
||
|
|
return;
|
||
|
|
|
||
|
|
long lCount=ssPatches.Length();
|
||
|
|
for(long i=0L; i<lCount; i++) {
|
||
|
|
Entity entPatch=ssPatches[i];
|
||
|
|
OPENOBJ_BEGIN(entPatch, AcDb::kForWrite, TDbWallPatch, pPatch);
|
||
|
|
if (!pPatch)
|
||
|
|
continue;
|
||
|
|
|
||
|
|
XPoly2D polyOut0(1), polyOut(1);
|
||
|
|
pPatch->GetOutlinePoly(polyOut0);
|
||
|
|
if (!polyOut0)
|
||
|
|
continue;
|
||
|
|
double nFactor=polyOut0.PathArea()>0? -5.0 : 5.0;
|
||
|
|
polyOut0.QuickOffset(nFactor*_DIST_SNAP, polyOut);
|
||
|
|
|
||
|
|
XPoint ptLow, ptUp;
|
||
|
|
polyOut.GetExtend(ptLow, ptUp);
|
||
|
|
ptLow.z=ptUp.z=0;
|
||
|
|
|
||
|
|
pPatch->RemoveAllLinkages();
|
||
|
|
PickSet ssWalls(SS_FREE);
|
||
|
|
if (GetSafeSelection(ssWalls, TRUE, ptLow, ptUp, _T("TCH_WALL,TCH_CURTAIN_WALL"))!=Acad::eOk)
|
||
|
|
continue;
|
||
|
|
|
||
|
|
long lWallCount=ssWalls.Length();
|
||
|
|
for(long idx=0L; idx<lWallCount; idx++) {
|
||
|
|
Entity entWall=ssWalls[idx];
|
||
|
|
OPENOBJ_BEGIN(entWall, AcDb::kForWrite, TDbWall, pWall);
|
||
|
|
if (pWall) {
|
||
|
|
pPatch->AddPatchId(pWall->objectId());
|
||
|
|
pWall->AddPatchId(pPatch->objectId());
|
||
|
|
}
|
||
|
|
OPENOBJ_END();
|
||
|
|
}
|
||
|
|
|
||
|
|
OPENOBJ_END();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|