Files
envi-code/SourceCode/Code2026/tg_shs/shs_kernal/TDbWallPatch.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

2233 lines
51 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TDbWallPatch.cpp
// = Version : ver2.0
// = Author : xlc
// = CreateDate : 2002-09-09
// = Description: 墙体造型类的定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TDbWallPatch.h"
#include "TDbWall.h"
#include "TDbColumn.h"
#include "Symdef.h"
#include "TSearchRegionFromCurve.h"
#include "TGGeRegion.h"
#include "DbConfig.h"
#include "TDPtrList.h"
#include "TPushMemVar.h"
#include "wall_xdata_key.h"
// ver:1-TArch5;2-TArch6;3-TArch7;4-TArch8
const Adesk::UInt8 TDbWallPatch::g_nVersion = 4;
ACRX_DXF_DEFINE_MEMBERS(ATSWallPatch, ATSEntity, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
1, ATS_WALL_PATCH, "ATS_WALL_PATCH,图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
IMPLEMENT_TENTBASE(TDbWallPatch);
extern double g_nInsulateThick;
//TDbWallPatch::TDbWallPatch(): TGGiCurveStream(), m_nUsageFlag(kUnknown), m_nElevation(0.0), m_nHeight(0.0),m_nFlag(0),m_nInsulateThick(80)
TDbWallPatch::TDbWallPatch(): TGGiCurveStream(), m_nUsageFlag(kUnknown), m_nElevation(0.0), m_nHeight(0.0),m_nFlag(0),m_nInsulateThick((int)g_nInsulateThick)
{
}
Acad::ErrorStatus TDbWallPatch::subGetClassID(CLSID* pClsid) const
{
return Acad::eOk;
}
BOOL TDbWallPatch::IsValid() const
{
BOOL bRet = TDbEntity::IsValid();
if (!bRet)
{
return bRet;
}
bRet = (m_polyOutline.Length() > 1 && m_polyOutline.IsClosed() &&
m_nHeight > -1.0E-6);
return bRet;
}
Acad::ErrorStatus TDbWallPatch::SetPathPoly(const TGGePoly2D &polyPath,const AcGeVector3d&normal)
{
assertWriteEnabled();
m_polyOutline = polyPath;
if (m_polyOutline.PathArea() > 0)
{
m_polyOutline.Reverse();
}
return Acad::eOk;
}
Acad::ErrorStatus TDbWallPatch::GetPathPoly(TGGePoly2D &polyPath,AcGeVector3d&normal) const
{
assertReadEnabled();
polyPath = m_polyOutline;
normal = AcGeVector3d::kZAxis;
return Acad::eOk;
}
// 提供对格式刷的支持
void TDbWallPatch::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
{
assertWriteEnabled();
TDbEntity::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
TDbWallPatch *pSrc = TDbWallPatch::cast(pSrcEntity);
if (pSrc)
{
m_nUsageFlag = pSrc->m_nUsageFlag;
m_nFlag = pSrc->m_nFlag;
m_nInsulateThick = pSrc->m_nInsulateThick;
if (database() == NULL
|| pSrcEntity->database() == NULL
|| database() == pSrcEntity->database()) //add by W on 060317
{
m_idLayerHatch2d = pSrc->m_idLayerHatch2d;
m_idLayerInsulate = pSrc->m_idLayerInsulate;
}
}
}
// 从DWG读入数据:
// 注意: 有待加入版本控制
Acad::ErrorStatus TDbWallPatch::dwgInFields (AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = TDbEntity::dwgInFields(pFiler);
if (es != Acad::eOk)
{
return es;
}
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if (nVer > g_nVersion)
{
return Acad::eMakeMeProxy;
}
m_lstCurves.Reset();
ReadCurveList(pFiler, m_lstCurves);
pFiler->readItem(&m_nElevation);
m_polyOutline.Reset();
ReadPoly2D(pFiler, m_polyOutline);
pFiler->readItem(&m_nHeight);
m_lstIdsForPatch.Reset();
Adesk::UInt8 nPatchCount = 0; // max 255
pFiler->readItem(&nPatchCount);
for (Adesk::UInt8 n = 0; n < nPatchCount; n++)
{
AcDbSoftPointerId id;
pFiler->readItem(&id);
m_lstIdsForPatch.Append(new AcDbSoftPointerId(id));
}
Adesk::UInt8 nUsage;
pFiler->readItem(&nUsage);
m_nUsageFlag = (UsageFlag)nUsage;
if (nVer > 1)
{
pFiler->readItem(&m_idLayerHatch2d);
}
else
{
if (database() == acdbCurDwg())
{
m_idLayerHatch2d = InitLayer(LAY_HATCH, FALSE);
}
else
{
m_idLayerHatch2d = GetLayerIdFromString(LAY_HATCH, database());
}
}
m_lstNeighbourId.Reset();
if (nVer > 2) //TArch7
{
Adesk::UInt8 nCount = 0; // max 255
pFiler->readItem(&nCount);
for (Adesk::UInt8 n = 0; n < nCount; n++)
{
AcDbSoftPointerId id;
pFiler->readItem(&id);
m_lstNeighbourId.Append(new AcDbSoftPointerId(id));
}
Adesk::UInt8 nStyle;
pFiler->readItem(&nStyle);
m_nStyle = (TWallPatchStyle)nStyle;
}
if (nVer > 3) //TArch8
{
pFiler->readItem(&m_nFlag);
pFiler->readItem(&m_nInsulateThick);
pFiler->readItem(&m_idLayerInsulate);
}
return pFiler->filerStatus();
}
// 写出数据到dwg:
Acad::ErrorStatus TDbWallPatch::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = TDbEntity::dwgOutFields(pFiler);
if (es != Acad::eOk)
{
return es;
}
if (g_nSaveTArchVer == 5)
{
pFiler->writeItem((Adesk::UInt8)1);
}
else if (g_nSaveTArchVer == 6)
{
pFiler->writeItem((Adesk::UInt8)2);
}
else if (g_nSaveTArchVer == 7)
{
pFiler->writeItem((Adesk::UInt8)3);
}
else
{
pFiler->writeItem(g_nVersion);
}
TchPrivate::WriteCurveList(pFiler, m_lstCurves);
pFiler->writeItem(m_nElevation);
WritePoly2D(pFiler, m_polyOutline);
pFiler->writeItem(m_nHeight);
Adesk::UInt8 nPatchCount = (Adesk::UInt8)m_lstIdsForPatch.Length(); // max 255
pFiler->writeItem(nPatchCount);
for (Adesk::UInt8 n = 0; n < nPatchCount; n++)
{
const AcDbSoftPointerId &id = m_lstIdsForPatch[(int)n];
pFiler->writeItem(id);
}
pFiler->writeItem((Adesk::UInt8)m_nUsageFlag);
if (g_nSaveTArchVer > 5)
{
pFiler->writeItem(m_idLayerHatch2d);
}
if (g_nSaveTArchVer > 6)
{
Adesk::UInt8 nCount = (Adesk::UInt8)m_lstNeighbourId.Length();
pFiler->writeItem(nCount);
for (long i = 0; i < m_lstNeighbourId.Length(); i++)
{
const AcDbSoftPointerId &id = m_lstNeighbourId[i];
pFiler->writeItem(id);
}
pFiler->writeItem((Adesk::UInt8)m_nStyle);
}
if (g_nSaveTArchVer > 7) //TArch8
{
pFiler->writeItem(m_nFlag);
pFiler->writeItem(m_nInsulateThick);
pFiler->writeItem(m_idLayerInsulate);
}
return es;
}
Acad::ErrorStatus TDbWallPatch::dxfInFields (AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = TDbEntity::dxfInFields(pFiler);
if (es != Acad::eOk)
{
return es;
}
if (!pFiler->atSubclassData(_T("TDbWallPatch")))
{
return Acad::eBadDxfSequence;
}
double r1, r2, r3;
TCString sHatchLayer;
TADSGePoint3d pt;
Adesk::UInt32 fieldsFlags = 0;
resbuf rb;
TDPtrList<AcDbSoftPointerId> lstIds;
AcDbObjectId id;
TDPtrList<TADSGePoint3d> pts;
TDPtrList<double> bulges;
while ((es == Acad::eOk)
&& ((es = pFiler->readResBuf(&rb)) == Acad::eOk))
{
switch (rb.restype)
{
case AcDb::kDxfReal:
r1 = rb.resval.rreal;
fieldsFlags |= 0x01;
break;
case AcDb::kDxfReal + 1:
fieldsFlags |= 0x02;
r2 = rb.resval.rreal;
break;
case AcDb::kDxfSoftPointerId:
fieldsFlags |= 0x04;
acdbGetObjectId(id, rb.resval.rlname);
lstIds.Append(new AcDbSoftPointerId(id));
break;
case AcDb::kDxfXCoord:
pt = rb.resval.rpoint;
pts.Append(new TADSGePoint3d(pt));
break;
case AcDb::kDxfAngle:
r3 = rb.resval.rreal;
bulges.Append(new double(r3));
break;
case 411:
sHatchLayer = rb.resval.rstring;
fieldsFlags |= 0x08;
free(rb.resval.rstring);
break;
default:
pFiler->pushBackItem();
es = Acad::eEndOfFile;
break;
}
}
if (es != Acad::eEndOfFile)
{
return Acad::eInvalidResBuf;
}
if (!(fieldsFlags & 0x04))
{
pFiler->setError(Acad::eMissingDxfField,
_T("\nMissing DXF group code: %d"), AcDb::kDxfSoftPointerId);
return Acad::eMissingDxfField;
}
if (pts.Length() < 2 || pts.Length() != bulges.Length())
{
pFiler->setError(Acad::eMissingDxfField,
_T("\nError DXF group code: 10, 50"));
return Acad::eMissingDxfField;
}
if (fieldsFlags & 0x01)
{
m_nHeight = r1;
}
if (fieldsFlags & 0x02)
{
m_nElevation = r2;
}
m_lstIdsForPatch.Reset();
lstIds.SetDelFlag(FALSE);
for (int i = 0; i < lstIds.Length(); i++)
{
m_lstIdsForPatch.Append(lstIds[i]);
}
m_polyOutline.Reset();
for (i = 0; i < pts.Length(); i++)
{
m_polyOutline.AppendNode(*pts[i], *bulges[i]);
}
if (fieldsFlags & 0x08)
{
m_idLayerHatch2d = GetLayerIdFromString(sHatchLayer, database());
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbWallPatch::dxfOutFields(AcDbDxfFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = TDbEntity::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbWallPatch"));
assert(es == Acad::eOk);
pFiler->writeDouble(AcDb::kDxfReal, m_nHeight);
pFiler->writeDouble(AcDb::kDxfReal + 1, m_nElevation);
for (int i = 0; i < m_lstIdsForPatch.Length(); i++)
{
const AcDbSoftPointerId &id = m_lstIdsForPatch[i];
pFiler->writeItem(AcDb::kDxfSoftPointerId,id);
}
for (i = 0; i < m_polyOutline.Length(); i++)
{
pFiler->writePoint2d(AcDb::kDxfXCoord, m_polyOutline[i].AsAcGePoint2d());
pFiler->writeDouble(AcDb::kDxfAngle, m_polyOutline.GetBulge(i));
}
pFiler->writeString(411, (const TCHAR*)LayerId2String(m_idLayerHatch2d));
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbWallPatch::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
TchExport2::GetGripPoints(m_polyOutline,gripPoints);
return Acad::eOk;
}
Acad::ErrorStatus TDbWallPatch::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
{
assertReadEnabled();
AcDbPolyline pline;
PolyConvert(m_polyOutline, pline);
return pline.getStretchPoints(stretchPoints);
}
Acad::ErrorStatus TDbWallPatch::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
TDbEntity::subTransformBy(xform);
//modified by W on 070413
//ads_matrix mat;
//memcpy(mat, &xform, sizeof(ads_matrix));
//for (int i = 0; i<m_polyOutline.Length(); i++) {
// TADSGePoint3d &pt = *m_polyOutline[i];
// pt.z = m_nElevation;
// pt.TransformBy(mat);
// //以第一个顶点的z坐标为基准
// if (i == 0) {
// m_nElevation = pt.z;
// }
// pt.z=0.0; // 2D Only
//}
//for (i=0; i<m_lstCurves.Length(); i++) {
// TGGeCurveSegment *pCurve=m_lstCurves[i];
// // 圆弧的变换不能使用下列方法
// pCurve->startPoint.TransformBy(mat);
// pCurve->endPoint.TransformBy(mat);
//}
if (m_polyOutline.Length() < 1)
{
return Acad::eOk;
}
m_polyOutline.SetElevation(m_nElevation);
m_polyOutline.TransformBy(xform);
m_nElevation = m_polyOutline[0]->z;
m_polyOutline.SetElevation(0);
if (m_polyOutline.PathArea() > 0)
{
m_polyOutline.Reverse();
}
return Acad::eOk;
}
// 功能: 夹点操作
Acad::ErrorStatus TDbWallPatch::subMoveGripPointsAt(
const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
Acad::ErrorStatus es = TchExport2::MoveGripPointsAt(m_polyOutline, indices, offset);
m_polyOutline.SetElevation(0.0);
return es;
}
// 功能: 夹点操作
Acad::ErrorStatus TDbWallPatch::subMoveStretchPointsAt(
const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
AcDbPolyline pline;
PolyConvert(m_polyOutline, pline);
Acad::ErrorStatus es = pline.moveGripPointsAt(indices, offset);
PolyConvert(pline, m_polyOutline);
m_polyOutline.SetElevation(0.0);
return es;
}
// 取得夹点说明
Acad::ErrorStatus TDbWallPatch::GetGripText(int i, CString &cs) const
{
assertReadEnabled();
TchExport2::GetGripText(m_polyOutline,i,cs);
return Acad::eOk;
}
#if ADS > 15
void TDbWallPatch::CreateGrip()
{
TDbEntity::CreateGrip();
TchExport2::CreateGrip(this,m_polyOutline,0);
}
Acad::ErrorStatus TDbWallPatch::EntityToDim(long iGrip,long iDim,const AcDbEntity*pEnt)
{
TEntityBase *pCurve = TDbWallPatch::cast(pEnt);
if (pCurve == NULL)
{
pCurve = this;
}
TGGePoly2D polyPath;
AcGeVector3d normal;
pCurve->GetPathPoly(polyPath,normal);
return ::EntityToDim(this,polyPath,iGrip,iDim,0);
}
Acad::ErrorStatus TDbWallPatch::DimToEntity(long iGrip,long iDim,double newValue,const AcGeVector3d& offset)
{
assertWriteEnabled();
TDbWallPatch curve;
curve.CopyPropertiesFrom(this,0);
Acad::ErrorStatus es = ::DimToEntity(this,m_polyOutline,iGrip,iDim,newValue,offset,0);
if (es == Acad::eOk&&!IsValid())
{
CopyPropertiesFrom(&curve,0);
return Acad::eInvalidInput;
}
return es;
}
#endif
// 如果其他构件优先(强)于本构件, 则用它们的外轮廓, 如果相等用内轮廓
void TDbWallPatch::GetInPatchObjectOutline(TDPtrList<TGGePoly2D> &lstClipPolies) const
{
double nThick = DocGetIsLineWeight() ? GetLineWeight(FALSE) : 0.0;
for (int i = 0; i < m_lstIdsForPatch.Length(); i++)
{
OPENOBJ_BEGIN(m_lstIdsForPatch[i], AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
TGGePoly2D polyOut(1);
pWall->GetOutlinePoly(m_nElevation, polyOut); //一定是逆时针
TGGePoly2D polyIn(1);
if (polyOut.QuickOffset(-nThick, polyIn) == RTNORM)
{
lstClipPolies.Append(new TGGePoly2D(polyIn));
}
}
OPENOBJ_END();
}
return;
}
void TDbWallPatch::ClipOutlineByPatchWalls(TDPtrList<TGGeCurveSegment> &lstResult, TDPtrList<TGGeCurveSegment> &lstResultIn) const
{
TDPtrList<TGGeCurveSegment> lstCurves, lstCurves1, *pSource = NULL, *pDest = NULL;
TDPtrList<TGGeCurveSegment> lstCurvesIn, lstCurves1In, *pSourceIn = NULL, *pDestIn = NULL;
double nThick = DocGetIsLineWeight() ? GetLineWeight(FALSE) : 0.0;
TGGePoly2D polyOut(1), polyIn(1);
GetOutlinePoly(polyOut);
ASSERT(polyOut.Length() != 0);
polyOut.QuickOffset(-nThick, polyIn);
ExplodePoly2D(polyOut, lstCurves);
if (!lstCurves)
{
return;
}
BOOL bThickMode = (IsBoldLine() && nThick > _DIST_SNAP);
if (bThickMode)
{
ExplodePoly2D(polyIn, lstCurvesIn);
}
pSource = &lstCurves;
pSourceIn = &lstCurvesIn;
pDest = &lstCurves1;
pDestIn = &lstCurves1In;
AcDbObjectId idOwner = ownerId();
if (!!idOwner)
{ //不是拖动状态
//找接于柱子的墙
for (int i = 0; i < m_lstIdsForPatch.Length(); i++)
{
OPENOBJ_BEGIN(m_lstIdsForPatch[i], AcDb::kForRead, TDbWall, pWall);
if (!pWall)
{
continue;
}
TGGePoly2D polyWall(1);
pWall->GetOutlinePoly(0.0, polyWall);
polyWall.SetElevation(GetElevation());
pDest->Reset();
TDPtrList<TGGeCurveSegment> lstTemp, lstEdge;
PolyClip(*pSource, polyWall, lstTemp, *pDest, lstEdge);
if (!pDest->Length()) //裁剩下空
{
return;
}
TchPrivate::Exchange(pSource, pDest);
if (bThickMode)
{
TGGePoly2D polyClip(1);
TGGeCurveSegment cvLeftIn, cvRightIn; //粗线内侧
pWall->GetThickLineSideCurve(cvLeftIn, cvRightIn);
polyClip.AppendNode(cvLeftIn.GetStartPoint());
polyClip.AppendNode(pWall->GetStartPoint());
polyClip.AppendNode(cvRightIn.GetStartPoint(), cvRightIn.GetBulge());
polyClip.AppendNode(cvRightIn.GetEndPoint());
polyClip.AppendNode(pWall->GetEndPoint());
polyClip.AppendNode(cvLeftIn.GetEndPoint(), -cvLeftIn.GetBulge());
polyClip.SetElevation(GetElevation());
pDestIn->Reset();
PolyClip(*pSourceIn, polyClip, lstTemp, *pDestIn, lstEdge);
TchPrivate::Exchange(pSourceIn, pDestIn);
pDestIn->Reset();
}
OPENOBJ_END();
}
}
for (int n = 0; n < pSource->Length(); n++)
{
lstResult.Append(new TGGeCurveSegment(*(*pSource)[n]));
}
if (bThickMode)
{
for (n = 0; n < pSourceIn->Length(); n++)
{
lstResultIn.Append(new TGGeCurveSegment(*(*pSourceIn)[n]));
}
}
}
static int GetExternalBoundary(const TDPtrList<TGGeCurveSegment> &lstCurves, TGGePoly2D &poly2d, BOOL bHasArc)
{
TDPtrList<TGGeCurveSegment> lstShadeCurves, lstShadeArcs;
for (int i = 0; i < lstCurves.Length(); i++)
{
TGGeCurveSegment *seg = new TGGeCurveSegment(lstCurves[i]);
seg->SetElevation(0.0);
if (bHasArc && !seg->Is(CURVE_LINE))
{
lstShadeArcs.Append(seg);
}
else
{
lstShadeCurves.Append(seg);
}
}
if (bHasArc)
{ //怎么没有考虑弧的重叠呢?
TdRemoveDupCurves(lstShadeCurves, FALSE, FALSE);
lstShadeArcs.SetDelFlag(FALSE);
for (int n = 0; n < lstShadeArcs.Length(); n++)
{
lstShadeCurves.Append(lstShadeArcs[n]);
}
IntersectCurves(lstShadeCurves, _DIST_SNAP);
}
else
{
TdRemoveDupCurves(lstShadeCurves, FALSE, TRUE);
}
for (i = lstShadeCurves.Length() - 1; i >= 0; i--)
{
TGGeCurveSegment *pSeg = lstShadeCurves[i];
if (pSeg->GetLength() < _DIST_SNAP)
{
lstShadeCurves.Remove();
}
}
TSearchRegionFromCurve aSearch;
try
{
aSearch.InitStart(lstShadeCurves);
}
catch(...)
{
adsout << _T("\n发生例外情况!");
return RTERROR;
}
TGGeRegion *pExt = aSearch.SearchRegions();
if (pExt)
{
poly2d.Reset();
pExt->CenterPoly2D(poly2d);
poly2d.Compress();
return RTNORM;
}
return RTERROR;
}
// Modify on 2002/4/26 by Z, 对调填充和绘制边界的顺序,以利于图面美观
Acad::ErrorStatus TDbWallPatch::ExplodeOrDraw2d(TGGiExplodeDrawBase &dc) const
{
Acad::ErrorStatus es = Acad::eOk;
AcDbObjectId idMe = objectId();
if (!idMe)
{
dc << m_polyOutline;
return es;
}
double nThick = DocGetIsLineWeight() ? GetLineWeight(FALSE) : 0.0;
BOOL bInsulate = HasInsulate();
//得到所有邻接墙、柱的外轮廓
TDPtrList<TGGePoly2D> lstWallOut,lstWallOutInsulate;
TDualPtrList<AcDbObjectId> lstColu;
for (int i = 0; i<m_lstIdsForPatch.Length(); i++)
{
OPENOBJ_BEGIN(m_lstIdsForPatch[i], AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
TGGePoly2D polyOut(1);
pWall->GetOutlinePoly(0, polyOut);
lstWallOut.Append(new TGGePoly2D(polyOut));
//保温层裁剪需要考虑到墙的保温
pWall->GetOutlinePoly(0, polyOut,1);
lstWallOutInsulate.Append(new TGGePoly2D(polyOut));
if (lstColu.Find(pWall->GetStartColumnId()) == NOT_FOUND)
{
OPENOBJ_BEGIN(pWall->GetStartColumnId(),AcDb::kForRead,TDbColumn,pColu)
if (pColu)
{
TGGePoly2D polyOut = pColu->GetOutlinePoly();
// del by xlc on 110406 绘制填充时不需要保温,解决有保温的情况下填充豁口问题
//if (bInsulate)
//{
// GetOffsetPoly2D(pColu->m_polyOutline,polyOut,pColu->m_nInsulateThick);
//}
polyOut.SetElevation(0);
lstWallOut.Append(new TGGePoly2D(polyOut));
dc.PushClip(polyOut);
}
OPENOBJ_END()
lstColu.AddTail(pWall->GetStartColumnId());
}
if (lstColu.Find(pWall->GetEndColumnId()) == NOT_FOUND)
{
OPENOBJ_BEGIN(pWall->GetEndColumnId(),AcDb::kForRead,TDbColumn,pColu)
if (pColu)
{
TGGePoly2D polyOut = pColu->GetOutlinePoly();
// del by xlc on 110406 绘制填充时不需要保温,解决有保温的情况下填充豁口问题
//if (bInsulate)
//{
// GetOffsetPoly2D(pColu->m_polyOutline,polyOut,pColu->m_nInsulateThick);
//}
polyOut.SetElevation(0);
lstWallOut.Append(new TGGePoly2D(polyOut));
dc.PushClip(polyOut);
}
OPENOBJ_END()
lstColu.AddTail(pWall->GetEndColumnId());
}
}
OPENOBJ_END();
}
//计算大融合体外轮廓
TDPtrList<TGGePoly2D> lstMyPoly,lstUnion;
TGGePoly2D *pNewPoly = new TGGePoly2D(m_polyOutline);
pNewPoly->SetElevation(0);
lstMyPoly.Append(pNewPoly);
Union(lstMyPoly,lstWallOut,lstUnion);
TGGePoly2D polyUnion(m_polyOutline);
if (lstUnion.Length() == 1)
{
polyUnion = *lstUnion[0];
}
else //add by W on 080923,解决union出错问题
{
TDPtrList<TGGeCurveSegment> lstCurve;
ExplodePoly2D(m_polyOutline,lstCurve);
for (long i = 0; i < lstWallOut.Length(); i++)
{
ExplodePoly2D(*lstWallOut[i],lstCurve);
}
TGGePoly2D polyTemp(1);
if (GetExternalBoundary(lstCurve,polyTemp,TRUE) == RTNORM)
{
polyUnion = polyTemp;
}
}
//wlw修改100629
TGGePoly2D polyInsulate;
TGGePoly2D polyUnionInsulate(m_polyOutline);
bool bzoom = true;
if (GetUsageFlag() == kConcave)
{
bzoom = false;
}
if (bInsulate)
{
//计算大融合体外轮廓
lstMyPoly.Reset();
lstUnion.Reset();
if (lstWallOut.Length() > 0)
{
lstWallOut.Remove(0);
}
lstWallOutInsulate << lstWallOut;
GetOffsetPoly2D(m_polyOutline, polyInsulate, m_nInsulateThick,bzoom);
polyInsulate.SetElevation(0);
lstMyPoly.Append(new TGGePoly2D(polyInsulate));
Union(lstMyPoly,lstWallOutInsulate,lstUnion);
if (lstUnion.Length() == 1)
{
polyUnionInsulate = *lstUnion[0];
}
else
{
TDPtrList<TGGeCurveSegment> lstCurve;
ExplodePoly2D(polyInsulate,lstCurve);
for (long i = 0; i < lstWallOutInsulate.Length(); i++)
{
ExplodePoly2D(*lstWallOutInsulate[i],lstCurve);
}
TGGePoly2D polyTemp(1);
if (GetExternalBoundary(lstCurve,polyTemp,TRUE) == RTNORM)
{
polyUnionInsulate = polyTemp;
}
}
}
if (GetUsageFlag() != kConcave)
{
if (!g_bOsnapExpl)
{
//绘制填充
const TCHAR *pszHatch = NULL;
if ((pszHatch = GetHatchPattern()) != NULL)
{
//绘制内部填充
AcDbObjectId idOldLay = dc.GetLayerId();
int nColorOld = dc.GetColor();
dc.SetColorLayer(GetHatchColor(),m_idLayerHatch2d);
if (_tcsicmp(pszHatch, _T("SOLID")) == 0)
{
dc<<TGGeSolid(m_polyOutline);
}
else
{
dc<<TGGeHatch(m_polyOutline, pszHatch, GetPScale());
}
dc.SetLayer(idOldLay);
dc.SetColor(nColorOld);
}
//绘制加粗边界
if (nThick > _DIST_SNAP)
{
bool bFree = true;
//add by W on 061225
extern AcDbObjectId g_idPubWall; //墙柱加粗的图层,为上华3服务
AcDbObjectId idOldLayer = dc.GetLayerId();
dc.SetLayer(g_idPubWall);
if (m_lstIdsForPatch.Length() > 0)
{
TGGePoly2D polyUnionHatch = polyUnion;
TGGePoly2D polyTemp(1);
double nOffset = -nThick;
if (polyUnionHatch.QuickOffset(nOffset, polyTemp) == RTNORM)
{
polyUnionHatch = polyTemp;
}
TDPtrList<TGGePoly2D> lstResultPolies;
if (TchSubExport::Subtract(m_polyOutline,polyUnionHatch,lstResultPolies) == RTNORM
&& lstResultPolies.Length() > 0)
{
bFree = false;
for (int i = 0; i < lstResultPolies.Length(); i++)
{
dc << TGGeSolid(*lstResultPolies[i]);
}
}
}
if (bFree) //独立造型。
{
TDPtrList<TGGeCurveSegment> lstSegs, lstSegsIn;
ClipOutlineByPatchWalls(lstSegs, lstSegsIn);
if (lstSegsIn.Length() > 0 && lstSegs.Length() == lstSegsIn.Length())
{
for (int n = 0; n < lstSegs.Length(); n++)
{
dc << TGGeSolidCurve(*lstSegs[n], *lstSegsIn[n]);
}
}
}
dc.SetLayer(idOldLayer);
}
}
//绘制边界细线
TDPtrList<TGGeCurveSegment> lstSegs0,lstSegs,temp;
ExplodePoly2D(m_polyOutline,lstSegs0);
PolyClip(lstSegs0,polyUnion,temp,lstSegs);
for (int n = 0; n < lstSegs.Length(); n++)
{
dc << *lstSegs[n];
}
// 输出其他曲线
for (int i = 0; i < m_lstCurves.Length(); i++)
{
dc << m_lstCurves[i];
}
}
else //内凹造型
{
//绘制加粗边界
if (!g_bOsnapExpl && nThick > _DIST_SNAP)
{
TGGePoly2D polyTemp(1);
if (m_polyOutline.QuickOffset(nThick, polyTemp) == RTNORM)
{
TDPtrList<TGGePoly2D> lstResultPolies,lstPolySub,buf;
TchSubExport::Intersect(polyUnion,polyTemp,buf);
lstPolySub.Append(new TGGePoly2D(m_polyOutline));
Subtract(buf,lstPolySub,lstResultPolies);
for (i = 0; i < lstResultPolies.Length(); i++)
{
TGGePoly2D &poly = *lstResultPolies[i];
if (!g_bOsnapExpl)
{
dc << TGGeSolid(poly);
}
}
}
}
//绘制边界细线
TDPtrList<TGGeCurveSegment> lstSegs0,lstSegs,lstOut,lstEdge;
ExplodePoly2D(m_polyOutline,lstSegs0);
PolyClip(lstSegs0,polyUnion,lstSegs,lstOut,lstEdge);
if (lstSegs.Length() < 1)
{
dc << m_polyOutline;
}
else
{
for (int n = 0; n < lstSegs.Length(); n++)
{
dc << *lstSegs[n];
}
}
}
//wlw修改100629绘制保温
if (bInsulate && m_nInsulateThick > 1.E-5)
{
// add by xlc on 110519 解决阳台遮挡保温层的问题
long iClipCount = 0; //阳台裁剪边界数
for (long i = 0; i < m_lstClippedId.Length(); i++)
{
const AcDbObjectId &id = m_lstClippedId[i];
if (id.isNull() || !id.isValid())
{
continue;
}
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbBalcony, pBalcony);
if (pBalcony)
{
if(pBalcony->IsBalconyClipInsu())
{
TGGePoly2D polyBal = pBalcony->GetOutline(),polyIn;
if( pBalcony->GetPolyIn(polyIn))
{
polyIn.SetFlag(0);
polyIn.Reverse();
for (int j = 0; j < polyIn.Length(); j++)
{
polyBal.AppendNode(*polyIn[j], polyIn.GetBulge(j));
}
dc.PushClip(polyBal);
iClipCount++;
}
}
}
OPENOBJ_END();
}
DrawInsulateLine(polyInsulate,polyUnionInsulate,bzoom,dc);
// add by xlc on 110519 解决阳台遮挡保温层的问题
while (iClipCount > 0)
{
dc.PopClip();
iClipCount--;
}
}
return es;
}
Acad::ErrorStatus TDbWallPatch::ExplodeOrDraw3d(TGGiExplodeDrawBase &dc) const
{
extern GEOAPI BOOL g_bExplodeMesh;
if (m_nHeight < _DIST_SNAP || GetUsageFlag() == TDbWallPatch::kConcave) //高度为0的不绘制
{
return Acad::eOk;
}
double nElev = GetElevation();
TGGePoly2D polyOut(m_polyOutline);
polyOut.SetElevation(nElev);
double nHeight = m_nHeight;
BOOL bVisBot = HasBottom(), bVisTop = HasTop();
if (!DocGetLevelLine()
&& TchGeLib::g_bExplodeMesh
&& (!bVisBot || !bVisTop))
{
TGGePoly2D polyBot;
polyOut.Disperse1(polyBot, _AS_SYS_UNIT(g_nCirDeviation));
int nColumn = polyBot.Length() + 1;
int nRow = 2;
TADSGePoint3d *ptArray = new TADSGePoint3d[nColumn * nRow];
for (int m = 0; m < nRow; m++)
{
for (int n = 0; n < nColumn; n++)
{
int nBase = m * nColumn;
int idx = n;
if (n == nColumn - 1)
{
idx = 0;
}
ptArray[nBase + n] = *polyBot[idx];
if (m)
{
ptArray[nBase + n].z += nHeight;
}
}
}
AcGiEdgeData edgeData;
Adesk::UInt8 *edgeVis = new Adesk::UInt8[(nColumn - 1) * nRow + nColumn * (nRow - 1)];
for (m = 0; m < (nColumn - 1) * nRow; m++)
{
if (m < nColumn - 1)
{
edgeVis[m] = bVisBot;
}
else
{
edgeVis[m] = bVisTop;
}
}
for (int n = 0; n < nColumn; n++)
{
int idx = n;
if (n == nColumn - 1)
{
idx = 0;
}
edgeVis[m + n] = 1;
}
edgeData.setVisibility(edgeVis);
dc.DrawMesh(nRow, nColumn, (AcGePoint3d *)ptArray, &edgeData);
delete [] ptArray;
delete [] edgeVis;
if (bVisBot)
{
dc.DrawShell(polyBot);
}
if (bVisTop)
{
polyBot.SetElevation(nElev + nHeight);
dc.DrawShell(polyBot);
}
}
else
{
dc.DrawBody(polyOut, TVector3D(0,0,nHeight));
}
return Acad::eOk;
}
const TCHAR *TDbWallPatch::GetDefaultLayer() const
{
const TCHAR *szLay = LAY_WALL;
if (m_lstIdsForPatch.Length() > 0)
{
const AcDbObjectId id = m_lstIdsForPatch[0];
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
szLay = pWall->GetDefaultLayer();
}
OPENOBJ_END();
}
return szLay;
}
void TDbWallPatch::UpdateAssocWallGraphics() const
{
int nLen = m_lstIdsForPatch.Length();
for (int i = 0; i < nLen; i++)
{
OPENOBJ_BEGIN(m_lstIdsForPatch[i], AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
pWall->draw();
}
OPENOBJ_END();
}
}
BOOL TDbWallPatch::HasTop() const
{
int nLen = m_lstIdsForPatch.Length();
BOOL bHasTop = TRUE;
if (nLen > 0)
{
AcDbObjectId idWall = m_lstIdsForPatch[0];
OPENOBJ_BEGIN(idWall, AcDb::kForRead, TDbWall, pWall);
if (pWall && !pWall->HasTop())
{
if (fabs(GetElevation() + GetHeight() -
pWall->GetElevation() - pWall->GetHeight()) < _DIST_SNAP)
{
bHasTop = FALSE;
}
}
OPENOBJ_END();
}
else
{
bHasTop = (fabs(GetElevation() + GetHeight() - DocGetLHeight()) > _DIST_SNAP);
}
return bHasTop;
}
BOOL TDbWallPatch::HasBottom() const
{
int nLen = m_lstIdsForPatch.Length();
BOOL bHasBot = TRUE;
if (nLen > 0)
{
AcDbObjectId idWall = m_lstIdsForPatch[0];
OPENOBJ_BEGIN(idWall, AcDb::kForRead, TDbWall, pWall);
if (pWall && !pWall->HasBottom())
{
if (fabs(GetElevation() - pWall->GetElevation()) < _DIST_SNAP)
{
bHasBot = FALSE;
}
}
OPENOBJ_END();
}
else
{
bHasBot = (fabs(GetElevation()) > _DIST_SNAP);
}
return bHasBot;
}
void TDbWallPatch::GetTips(TDPtrList<TObjInfoUnit> &lstInfo) const
{
const TCHAR *pszUsage = _T("墙体造型");
lstInfo.Append(new TObjInfoUnit(_T("对象类型"), pszUsage));
lstInfo.Append(new TObjInfoUnit(_T("高度"), TchExport::Dist2Str(m_nHeight)));
lstInfo.Append(new TObjInfoUnit(_T("底标高"), TchExport::Dist2Str(GetElevation())));
double nArea = m_polyOutline.Area();
lstInfo.Append(new TObjInfoUnit(_T("底面积"), TCString(_T("%.2f"), _AS_SQMETER(nArea))));
lstInfo.Append(new TObjInfoUnit(_T("体积"), TCString(_T("%.3f"), _AS_SQMETER(nArea) * _AS_METER(m_nHeight))));
}
Acad::ErrorStatus TDbWallPatch::AddPatchId(const AcDbObjectId &id)
{
if (!id || m_lstIdsForPatch.FindNode(&id, CompareObjectId))
{
return Acad::eInvalidInput;
}
m_lstIdsForPatch.Append(new AcDbSoftPointerId(id));
return Acad::eOk;
}
Acad::ErrorStatus TDbWallPatch::RemovePatchId(const AcDbObjectId &id)
{
if (!id || m_lstIdsForPatch.FindNode(&id, CompareObjectId))
{
return Acad::eInvalidInput;
}
m_lstIdsForPatch.Remove();
return Acad::eOk;
}
BOOL TDbWallPatch::IsConcrete() const
{
if (!m_lstIdsForPatch)
{
return FALSE;
}
const AcDbObjectId id = m_lstIdsForPatch[0];
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWall, pWall);
if (pWall && pWall->GetStyle() == TWallData::kConcrete)
{
return TRUE;
}
OPENOBJ_END();
return FALSE;
}
const TCHAR *TDbWallPatch::GetHatchPattern() const
{
if (!m_lstIdsForPatch)
{
return NULL;
}
if (m_lstIdsForPatch.Length() > 0)
{
const AcDbObjectId id = m_lstIdsForPatch[0];
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
return pWall->GetHatchPattern();
}
OPENOBJ_END();
}
return NULL;
}
Adesk::UInt16 TDbWallPatch::GetHatchColor() const
{
Adesk::UInt16 color = 256;
if (m_lstIdsForPatch.Length() > 0)
{
const AcDbObjectId id = m_lstIdsForPatch[0];
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
color = pWall->GetHatchColor();
}
OPENOBJ_END();
}
return color;
}
//取线粗,不管加粗开关是否开启
double TDbWallPatch::GetLineWeight(BOOL bAsPaperUnit) const
{
double nWeight = 0.0;
if (m_lstIdsForPatch.Length() > 0)
{
const AcDbObjectId id = m_lstIdsForPatch[0];
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
nWeight = pWall->GetLineWeight(TRUE);
}
OPENOBJ_END();
}
if (!bAsPaperUnit)
{
nWeight *= GetPScale();
}
return nWeight;
}
const TCHAR * TDbWallPatch::Descriptor()
{
return _T("TDbWallPatch");
}
const TCHAR * TDbWallPatch::Desc()
{
return Descriptor();
}
Acad::ErrorStatus TDbWallPatch::subClose()
{
Acad::ErrorStatus es = TDbEntity::subClose();
if (es == Acad::eOk && isModified() && database() == acdbCurDwg())
{
static BOOL g_bWallPatchSubClose = FALSE;
if (!g_bWallPatchSubClose) //防止与TDbWall::subClose的递归调用
{
TPushMemVar<BOOL> vTemp(g_bWallPatchSubClose,TRUE);
//通知附件, 墙体已经发生变化
for (int i = 0; i < m_lstIdsForPatch.Length(); i++)
{
OPENOBJ_BEGIN(*m_lstIdsForPatch[i], AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
if (!pWall->isModified())
{
if (pWall->upgradeOpen() == Acad::eOk)
{
pWall->recordGraphicsModified(Adesk::kTrue);
}
}
}
OPENOBJ_END();
}
}
}
return es;
}
Acad::ErrorStatus TDbWallPatch::subErase(Adesk::Boolean bErasing)
{
extern BOOL SkipSubErase(const TCHAR *szCmd);
Acad::ErrorStatus es = TDbEntity::subErase(bErasing);
TCString &cmdStr = GetCurDocData()->m_sCurCommand;
if (TchPrivate::SkipSubErase(cmdStr))
{
return es;
}
if (es == Acad::eOk && bErasing == Adesk::kTrue && database() == acdbCurDwg())
{
//通知墙体, 解除对附件的连接
for (int i = 0; i < m_lstIdsForPatch.Length(); i++)
{
OPENOBJ_BEGIN(*m_lstIdsForPatch[i], AcDb::kForWrite, TDbWall, pWall);
if (pWall)
{
pWall->assertWriteEnabled();
pWall->RemovePatchId(objectId());
}
OPENOBJ_END();
}
}
return es;
}
// 移除同墙体的连接关系(双向)
void TDbWallPatch::RemoveAllLinkages()
{
assertWriteEnabled();
//通知墙体, 解除对附件的连接
for (int i = 0; i < m_lstIdsForPatch.Length(); i++)
{
OPENOBJ_BEGIN(*m_lstIdsForPatch[i], AcDb::kForWrite, TDbWall, pWall);
if (pWall)
{
pWall->assertWriteEnabled();
pWall->RemovePatchId(objectId());
}
OPENOBJ_END();
}
m_lstIdsForPatch.Reset();
}
Acad::ErrorStatus
TDbWallPatch::subWblockClone(AcRxObject* pOwner,
AcDbObject*& pClonedObject,
AcDbIdMapping& idMap,
Adesk::Boolean isPrimary) const
{
Acad::ErrorStatus es = TDbEntity::subWblockClone(pOwner, pClonedObject, idMap, isPrimary);
return es;
}
BOOL TDbWallPatch::OnlyPatchMe(AcDbObjectId idWall) const
{
return (m_lstIdsForPatch.Length() == 1 && m_lstIdsForPatch[0] == idWall);
}
bool TDbWallPatch::IsModelEntity() const
{
return true;
}
bool TDbWallPatch::IsMeClip()const
{
return true;
}
AcDbEntity* TDbWallPatch::GetMyEntity()const
{
return (AcDbEntity*)this;
}
int TDbWallPatch::GetMaterialIndex()const
{
return GetStyle();
}
TDbWallPatch::Usage TDbWallPatch::GetUsage()const
{
return kPatch;
}
const TDPtrList<AcDbSoftPointerId> & TDbWallPatch::GetPatchIds() const
{
return m_lstIdsForPatch;
}
TDbWallPatch::UsageFlag TDbWallPatch::GetUsageFlag() const
{
return m_nUsageFlag;
}
void TDbWallPatch::SetUsageFlag(UsageFlag nUsage)
{
m_nUsageFlag = nUsage;
}
//用于OPM的属性, 形状被修改后需调用UpdateAssocWallGraphics();
double TDbWallPatch::GetElevation() const
{
return m_nElevation; //底标高
}
void TDbWallPatch::SetElevation(double nElev)
{
assertWriteEnabled();
m_nElevation = nElev;
}
void TDbWallPatch::GetOutlinePoly(TGGePoly2D &poly, bool bInsulate) const
{
if (HasInsulate())
{
if (bInsulate)
{
bool bzoom = true;
if (GetUsageFlag() == kConcave)
{
bzoom = false;
}
GetOffsetPoly2D(m_polyOutline,poly,m_nInsulateThick,bzoom);
}
else
{
poly = m_polyOutline;
}
}
else
{
poly = m_polyOutline;
}
}
void TDbWallPatch::SetOutlinePoly(const TGGePoly2D &poly)
{
assertWriteEnabled();
m_polyOutline = poly;
if (m_polyOutline.PathArea() > 0)
{
m_polyOutline.Reverse(); //确保按逆时针方向
}
}
double TDbWallPatch::GetHeight() const
{
return m_nHeight; //高度, 如果为0则不显示三维
}
void TDbWallPatch::SetHeight(double h)
{
assertWriteEnabled();
m_nHeight = h;
}
AcDbObjectId TDbWallPatch::GetLayerHatch2d() const
{
return m_idLayerHatch2d;
}
void TDbWallPatch::SetLayerHatch2d(AcDbObjectId id)
{
assertWriteEnabled();
m_idLayerHatch2d = id;
}
void TDbWallPatch::SetStyle(TWallPatchStyle style)
{
assertWriteEnabled();
m_nStyle = style;
}
TDbWallPatch::TWallPatchStyle TDbWallPatch::GetStyle() const
{
assertReadEnabled();
return m_nStyle;
}
AcDbObjectId TDbWallPatch::GetLayerInsulateId() const
{
return m_idLayerInsulate;
}
void TDbWallPatch::SetLayerInsulateId(AcDbObjectId id)
{
assertWriteEnabled();
m_idLayerInsulate = id;
}
double TDbWallPatch::GetInsulateThick() const
{
return m_nInsulateThick;
}
void TDbWallPatch::SetInsulateThick(double dThick)
{
assertWriteEnabled();
m_nInsulateThick = dThick;
}
BOOL TDbWallPatch::HasInsulate() const
{
return ((m_nFlag & WF_PATCH_INSULATE) != 0);
}
void TDbWallPatch::SetInsulate(BOOL bTrue)
{
if (bTrue)
{
m_nFlag |= WF_PATCH_INSULATE;
}
else
{
m_nFlag &= ~WF_PATCH_INSULATE;
}
}
int TDbWallPatch::GetWallFlag() const
{
return m_nFlag;
}
void TDbWallPatch::SetWallFlag(int nFlag)
{
m_nFlag = nFlag;
}
// 通用的函数, 要移到其他模块
Acad::ErrorStatus TDbWallPatch::ReadCurve(AcDbDwgFiler *pFiler, TGGeCurveSegment &seg)
{
TADSGePoint3d ptStart,ptEnd;
pFiler->readItem(&(AcGePoint3d &)ptStart);
pFiler->readItem(&(AcGePoint3d &)ptEnd);
seg.SetStartPoint(ptStart);
seg.SetEndPoint(ptEnd);
double bulge = 0;
pFiler->readItem(&bulge);
seg.SetBulge(bulge);
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbWallPatch::ReadCurveList(AcDbDwgFiler *pFiler, TDPtrList<TGGeCurveSegment> &lstSegs)
{
Adesk::UInt16 nCount = 0;
pFiler->readItem(&nCount);
for (Adesk::UInt16 i = 0U; i<nCount; i++)
{
TGGeCurveSegment *seg = new TGGeCurveSegment;
ReadCurve(pFiler, *seg);
lstSegs.Append(seg);
}
return pFiler->filerStatus();
}
void TDbWallPatch::GetInsulateExLine(TDPtrList<TGGeCurveSegment> &lstSegs) const
{
// 对于内凹式造型添加保温线保证造型保温与墙保温不断开
lstSegs.Reset();
TGGeCurveSegment segl,segr;
TGGeCurveSegment segIs,segTmp;
ads_point pt1,pt2;
AcGePoint3dArray arptIns,arptInsInsulate;
TADSGePoint3d ptInter;
TGGePoly2D polyPath(1),polyPathIs(1);
double dThick = DocGetIsLineWeight() ? GetLineWeight(FALSE) : 0.0;
AcGeVector3d vt;
for (int i = 0; i< m_lstIdsForPatch.Length(); i++)
{
OPENOBJ_BEGIN(m_lstIdsForPatch[i], AcDb::kForRead, TDbWall, pWall);
if (pWall == NULL)
{
continue;
}
// 绘制保温线
TDPtrList<TGGeCurveSegment> lstInsulateCurves;
for (int nSide = 0; nSide < 2; nSide++)
{
pWall->GetSideCurve(segl,segr,0.0,TRUE);
// 取得墙保温线分别于造型和造型保温求交,得到交线
if (pWall->IsInsulateOnSide(nSide))
{
segIs = nSide ? segr : segl;
segIs.SetLineFlag(LS_INFINITE);
GetOutlinePoly(polyPathIs);
GetOutlinePoly(polyPath,0);
polyPath.SetElevation(GetElevation());
polyPathIs.SetElevation(GetElevation());
for (int j = 0; j < polyPath.Length(); j++)
{
polyPath.Nth(j,segTmp);
segTmp.SetLineFlag(LS_FINITE);
if (segIs.Intersection(segTmp,pt1,pt2))
{
ptInter = pt1;
arptIns.append(ptInter);
//对弧线来说,有两个交点
if (segTmp.GetBulge() > 0)
{
ptInter = pt2;
arptIns.append(ptInter);
break;
}
}
}
for (j = 0; j < polyPathIs.Length(); j++)
{
polyPathIs.Nth(j,segTmp);
segTmp.SetLineFlag(LS_FINITE);
if (segIs.Intersection(segTmp,pt1,pt2))
{
ptInter = pt1;
arptInsInsulate.append(ptInter);
//对弧线来说,有两个交点
if (segTmp.GetBulge() > 0)
{
ptInter = pt2;
arptInsInsulate.append(ptInter);
break;
}
}
}
//如果交点多于2个点,暂时不处理。处理方法可将点数组按照墙线方向序列化,取第一个和最后一个wlw
if (arptInsInsulate.length() == 2 && arptIns.length() == 2)
{
segTmp.SetBulge(0.0);
segTmp.SetStartPoint(arptIns[0]);
segTmp.SetEndPoint(arptInsInsulate[0]);
if (arptIns[0].distanceTo(arptInsInsulate[0]) > arptIns[0].distanceTo(arptInsInsulate[1]))
{
segTmp.SetEndPoint(arptInsInsulate[1]);
}
if (dThick > 0.01)
{//补加粗的豁口
vt = segTmp.StartPoint() - segTmp.EndPoint();
vt.normalize();
segTmp.StartPoint() += vt * dThick;
}
lstSegs.Append(new TGGeCurveSegment(segTmp));
segTmp.SetStartPoint(arptIns[1]);
segTmp.SetEndPoint(arptInsInsulate[1]);
if (arptIns[1].distanceTo(arptInsInsulate[1]) > arptIns[1].distanceTo(arptInsInsulate[0]))
{
segTmp.SetEndPoint(arptInsInsulate[1]);
}
if (dThick > 0.01)
{//补加粗的豁口
vt = segTmp.StartPoint() - segTmp.EndPoint();
vt.normalize();
segTmp.StartPoint() += vt * dThick;
}
lstSegs.Append(new TGGeCurveSegment(segTmp));
}
}
}
OPENOBJ_END();
}
}
void TDbWallPatch::DrawInsulateLine(const TGGePoly2D& polyInsulate,TGGePoly2D& polyUnionInsulate, bool bzoom, TGGiExplodeDrawBase &dc) const
{
TDPtrList<TGGeCurveSegment> lstSegsTmp,lstSegsOut,lstSegsIn;
ExplodePoly2D(polyInsulate,lstSegsTmp);
PolyClip(lstSegsTmp,polyUnionInsulate,lstSegsIn,lstSegsOut);
AcDbObjectId idOldLay = dc.GetLayerId();
int nColorOld = dc.GetColor();
dc.SetColorLayer(colorIndex(), m_idLayerInsulate);
int n = 0,nSide=0;
int nSaveFlag = 0;
m_XDataMap.GetAt(_T("DownGradeSaveFlag"), nSaveFlag);
// 外凸
if (bzoom)
{
BOOL bFullExplode = FALSE;
if (_tcscmp(dc.Desc(), TGGiWorldViewportDraw::Descriptor()) == 0)
{
bFullExplode = TRUE;
}
if (_tcscmp(dc.Desc(), TGGiExplodeDraw::Descriptor()) == 0)
{
bFullExplode = ((TGGiExplodeDraw &)dc).m_bFullExplode;
}
BOOL bIsWallHatch = FALSE;
CString sPattern;
Adesk::UInt16 nColor(256);
const AcDbObjectId id = m_lstIdsForPatch[0];
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWall, pWall);
AcDbObjectId idLineBlock;
TDbPolyPathArray linepat;
TGGePoly2D poly2d;
TADSGePoint3d ptOnln;
TGGeCurveSegment seg;
if (pWall)
{//wlw add 140220 增加保温花线
pWall->GetSpecialtyDataReadOnly()->GetAt(idKEY_WALL_WARM_HATCH_PATTERN_ID, idLineBlock);
pWall->GetSpecialtyDataReadOnly()->GetAt(bKEY_WALL_WARM_HATCH_OP, bIsWallHatch);
pWall->GetSpecialtyDataReadOnly()->GetAt(nKEY_WALL_WARM_HATCH_COLOR, (int&)nColor);
if (pWall->GetUsageFlag() == TWallData::kParapet)
{
bIsWallHatch = FALSE;
}
if (bIsWallHatch && bFullExplode && !g_bOsnapExpl)
{
linepat.SetUnitId(idLineBlock);
for (n = 0; n < lstSegsOut.Length(); n++)
{
seg = *lstSegsOut[n];
nSide = pWall->OnWhichSide(lstSegsOut[n]->MidPoint());
if (pWall->IsInsulateOnSide(nSide))
{
for (int j = 0; j < m_polyOutline.Length(); j++)
{
TADSGePoint3d pt = m_polyOutline[j];
lstSegsOut[n]->ProjectToMe(pt,ptOnln);
//为了避免墙相交时图案重叠
if (fabs(m_nInsulateThick - ptOnln.Distance2d(pt)) < 1 && ((ptOnln & seg) == PR_INSIDE))
{
if (lstSegsOut[n]->StartPoint().Distance2d(ptOnln) < lstSegsOut[n]->EndPoint().Distance2d(ptOnln))
{
seg.SetStartPoint(ptOnln);
}
else
{
seg.SetEndPoint(ptOnln);
}
}
}
poly2d.Reset();
seg.AsPoly2D(poly2d);
linepat.SetBaseType(1);//0,左,1,右,2,中
linepat.SetUnitHeight(m_nInsulateThick);
linepat.SetPathPoly(poly2d,AcGeVector3d::kZAxis);
linepat.SetRatio(1);
if (nSaveFlag == 1)
{
linepat.setLayer(dc.GetLayerId());
linepat.setColorIndex(dc.GetColor());
dc.DrawEntity(linepat);
}
else
{
BOOL bWallLinepatClipOld = g_bWallLinepatClip;
if (_tcscmp(dc.Desc(), TGGiWorldViewportDraw::Descriptor())==0)
{
g_bWallLinepatClip = TRUE;
}
linepat.ExplodeOrDraw2d(dc);
g_bWallLinepatClip = bWallLinepatClipOld;
}
}
}
}
}
OPENOBJ_END();
for (n = 0; n < lstSegsOut.Length(); n++)
{
dc << *lstSegsOut[n];
}
}
//内凹
else
{
if (lstSegsIn.Length() < 1)
{
dc << polyInsulate;
}
else
{
for (n = 0; n < lstSegsIn.Length(); n++)
{
dc << *lstSegsIn[n];
}
//添加两根连接小线
GetInsulateExLine(lstSegsOut);
for (n = 0; n < lstSegsOut.Length(); n++)
{
dc << *lstSegsOut[n];
}
}
}
dc.SetLayer(idOldLay);
dc.SetColor(nColorOld);
}
// sg add 101115,支持统一标高
bool TDbWallPatch::UnifyElevation(double dElevation)
{
assertWriteEnabled();
SetElevation(dElevation);
return true;
}
// sg add 101118,支持导出XML
CString TDbWallPatch::GetXml(const AcGeMatrix3d& mat) const
{
TXmlTree xmlTree;
POSITION posRoot = xmlTree.Insert(_T("ATS_WALL_PATCH"), NULL, NULL);
{
xmlTree.SetAttribute(posRoot, _T("name"), _T("墙体造型"));
xmlTree.SetAttribute(posRoot, _T("comment"), _T("上华对象名称"));
}
CString strText;
POSITION posItem1 = xmlTree.Insert(_T("Object_ID"), posRoot, NULL);
{
xmlTree.SetAttribute(posItem1, _T("name"), _T("对象编号"));
xmlTree.SetAttribute(posItem1, _T("comment"), _T("当前对象的句柄"));
strText.Format(_T("%ld"), objectId());
xmlTree.SetItemText(posItem1, strText);
}
POSITION posItem2 = xmlTree.Insert(_T("Link_WALL"), posRoot, posItem1);
{
xmlTree.SetAttribute(posItem2, _T("name"), _T("连接墙体"));
POSITION posItemLinkID = NULL;
for (int i = 0; i < m_lstIdsForPatch.Length(); i++)
{
posItemLinkID = xmlTree.Insert(_T("Link_ID"), posItem2, posItemLinkID);
xmlTree.SetAttribute(posItemLinkID, _T("name"), _T("墙体句柄"));
strText.Format(_T("%ld"), m_lstIdsForPatch[i]);
xmlTree.SetItemText(posItemLinkID, strText);
}
}
POSITION posItem3 = xmlTree.Insert(_T("Property"), posRoot, posItem2);
{
xmlTree.SetAttribute(posItem3, _T("name"), _T("外凸特性"));
xmlTree.SetAttribute(posItem3, _T("comment"), _T("外凸为1,内凹为0"));
strText.Format(_T("%d"), m_nUsageFlag != kConcave);
xmlTree.SetItemText(posItem3, strText);
}
POSITION posItem4 = xmlTree.Insert(_T("Baseline"), posRoot, posItem3);
{
xmlTree.SetAttribute(posItem4, _T("name"), _T("基线参数"));
POSITION posItemPoint = NULL;
TADSGePoint3d ptNode;
for (int i = 0; i < m_polyOutline.Length(); i++)
{
ptNode = m_polyOutline[i];
strText.Format(_T("Point_%d"), i + 1);
posItemPoint = xmlTree.Insert(strText, posItem4, posItemPoint);
{
strText.Format(_T("第%d点"), i + 1);
xmlTree.SetAttribute(posItemPoint, _T("name"), strText);
strText.Format(_T("%f,%f,%f"), ptNode.x, ptNode.y, ptNode.z);
xmlTree.SetItemText(posItemPoint, strText);
}
strText.Format(_T("Ang_%d"), i + 1);
posItemPoint = xmlTree.Insert(strText, posItem4, posItemPoint);
{
strText.Format(_T("圆心角%d"), i + 1);
xmlTree.SetAttribute(posItemPoint, _T("name"), strText);
strText.Format(_T("%f"), m_polyOutline.GetBulge(i));
xmlTree.SetItemText(posItemPoint, strText);
}
}
}
POSITION posItem5 = xmlTree.Insert(_T("Height"), posRoot, posItem4);
{
xmlTree.SetAttribute(posItem5, _T("name"), _T("墙体造型高度参数"));
POSITION posItemHeight = NULL;
posItemHeight = xmlTree.Insert(_T("Net_Height"), posItem5, posItemHeight);
{
xmlTree.SetAttribute(posItemHeight, _T("name"), _T("墙体造型高"));
xmlTree.SetAttribute(posItemHeight, _T("comment"), _T("从墙体造型底起算的墙体造型净高"));
strText.Format(_T("%f"), GetHeight());
xmlTree.SetItemText(posItemHeight, strText);
}
posItemHeight = xmlTree.Insert(_T("Bottom_Height"), posItem5, posItemHeight);
{
xmlTree.SetAttribute(posItemHeight, _T("name"), _T("墙体造型底高"));
xmlTree.SetAttribute(posItemHeight, _T("comment"), _T("从零标高到墙体造型底的相对高度"));
strText.Format(_T("%f"), GetElevation());
xmlTree.SetItemText(posItemHeight, strText);
}
}
CString strBase = TEntityBase::GetXml(mat);
CString strXml = xmlTree.GetXml();
int nIndex = strXml.Find(_T("<Object_ID"));
strXml.Insert(nIndex, strBase);
return strXml;
}
//add by xlc on 110408 抽取保温线
Acad::ErrorStatus TDbWallPatch::DownGradeSave(int nDrawMode, AcDbVoidPtrArray &entSet, BOOL *bErase)
{
// sg delete 110907,为了保证图纸导出后的门窗显示正确,恢复到和8.5B2版本一致
if (g_nSaveTArchVer < 10)
{
TGGiExplodeDraw dcSrc(entSet);
dcSrc.m_bFullExplode = TRUE;
AcDbVoidPtrArray arpents;
dcSrc.SetPropertiesFrom(GetMe());
if (nDrawMode == DRAW_2D)
{//导出T9时需要T20的保温和填充 wlw add 140219
int nFlag = 1;
m_XDataMap.SetAt(_T("DownGradeSaveFlag"), nFlag);
ExplodeOrDraw2d(dcSrc);
nFlag = 0;
m_XDataMap.SetAt(_T("DownGradeSaveFlag"), nFlag);
for (int i = 0; i < entSet.length(); i++)
{
AcDbEntity *pent = (AcDbEntity*)entSet[i];
if ( (pent->isKindOf(TDbPolyPathArray::desc())) )
{
arpents.append(entSet[i]);
}
/*导出低版本不支持,否则与全局填充重叠
else if (pent->isKindOf(AcDbHatch::desc()))
{
BOOL bIsWallHatch = FALSE;
OPENOBJ_BEGIN(*m_lstIdsForPatch[0], AcDb::kForRead, TDbWall, pWall);
pWall->GetSpecialtyDataReadOnly()->GetAt(bKET_WALL_HATCH_OP, bIsWallHatch);
OPENOBJ_END()
if (bIsWallHatch)
{//只有是自定义的hatch才导出
if (pent->layerId() == m_idLayerHatch2d)
{
arpents.append(entSet[i]);
}
}
}
*/
}
entSet = (arpents);
}
}
return TDbEntity::DownGradeSave(nDrawMode, entSet, bErase);
/*
Acad::ErrorStatus es = Acad::eOk;
if (nDrawMode == DRAW_3D)
{
if (bErase)
{
*bErase = FALSE;
}
return es;
}
if (g_nSaveTArchVer <= 8) //TArch8之前版本
{
if (GetInsulateThick() < 1.e-5 || !HasInsulate()) //无保温
{
if (bErase)
{
*bErase = FALSE;
}
}
else
{
TDbWallPatch *pNewSet=NULL;
{
XPushMemVar<int> vTemp(g_nSaveTArchVer,_TCH_VERSION);
pNewSet=(TDbWallPatch*)clone();
}
pNewSet->SetInsulate(FALSE);
for (int n = 0; n < m_lstIdsForPatch.Length(); n++)
{
pNewSet->AddPatchId(*m_lstIdsForPatch[n]);
}
entSet.append(pNewSet);
TGGiExplodeDraw dc(entSet);
BOOL bInsulate = HasInsulate();
//得到所有邻接墙、柱的外轮廓
TDPtrList<TGGePoly2D> lstWallOut,lstWallOutInsulate;
TDualPtrList<AcDbObjectId> lstColu;
for (int i = 0; i<m_lstIdsForPatch.Length(); i++)
{
OPENOBJ_BEGIN(*m_lstIdsForPatch[i], AcDb::kForRead, TDbWall, pWall);
if (pWall)
{
TGGePoly2D polyOut(1);
pWall->GetOutlinePoly(0, polyOut);
lstWallOut.Append(new TGGePoly2D(polyOut));
//保温层裁剪需要考虑到墙的保温
pWall->GetOutlinePoly(0, polyOut,1);
lstWallOutInsulate.Append(new TGGePoly2D(polyOut));
if (lstColu.Find(pWall->GetStartColumnId()) == NOT_FOUND)
{
OPENOBJ_BEGIN(pWall->GetStartColumnId(),AcDb::kForRead,TDbColumn,pColu)
if (pColu)
{
TGGePoly2D polyOut = pColu->GetOutlinePoly();
polyOut.SetElevation(0);
lstWallOut.Append(new TGGePoly2D(polyOut));
dc.PushClip(polyOut);
}
OPENOBJ_END()
lstColu.AddTail(pWall->GetStartColumnId());
}
if (lstColu.Find(pWall->GetEndColumnId()) == NOT_FOUND)
{
OPENOBJ_BEGIN(pWall->GetEndColumnId(),AcDb::kForRead,TDbColumn,pColu)
if (pColu)
{
TGGePoly2D polyOut = pColu->GetOutlinePoly();
polyOut.SetElevation(0);
lstWallOut.Append(new TGGePoly2D(polyOut));
dc.PushClip(polyOut);
}
OPENOBJ_END()
lstColu.AddTail(pWall->GetEndColumnId());
}
}
OPENOBJ_END();
}
//计算大融合体外轮廓
TDPtrList<TGGePoly2D> lstMyPoly,lstUnion;
TGGePoly2D polyInsulate;
TGGePoly2D polyUnionInsulate(m_polyOutline);
bool bzoom = true;
if (GetUsageFlag() == kConcave)
{
bzoom = false;
}
if (bInsulate)
{
//计算大融合体外轮廓
lstMyPoly.Reset();
lstUnion.Reset();
if (lstWallOut.Length() > 0)
{
lstWallOut.Remove(0);
}
lstWallOutInsulate << lstWallOut;
GetOffsetPoly2D(m_polyOutline, polyInsulate, m_nInsulateThick,bzoom);
polyInsulate.SetElevation(0);
lstMyPoly.Append(new TGGePoly2D(polyInsulate));
Union(lstMyPoly,lstWallOutInsulate,lstUnion);
if (lstUnion.Length() == 1)
{
polyUnionInsulate = *lstUnion[0];
}
else
{
TDPtrList<TGGeCurveSegment> lstCurve;
ExplodePoly2D(polyInsulate,lstCurve);
for (long i = 0; i < lstWallOutInsulate.Length(); i++)
{
ExplodePoly2D(*lstWallOutInsulate[i],lstCurve);
}
TGGePoly2D polyTemp(1);
if (GetExternalBoundary(lstCurve,polyTemp,TRUE) == RTNORM)
{
polyUnionInsulate = polyTemp;
}
}
}
DrawInsulateLine(polyInsulate,polyUnionInsulate,bzoom,dc);
if (bErase)
{
*bErase = TRUE;
}
}
}
else
{
if (bErase)
{
*bErase = FALSE;
}
}
return es;
*/
}