Files
envi-code/SourceCode/Code2026/tg_shs/shs_geLib/TEntityBase.cpp
T
2026-09-28 15:28:50 +08:00

2516 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 : TEntityBase.cpp
// = Version : ver2.0
// = Author : xlc
// = CreateDate : 2002-09-09
// = Description: 上华基本对象基础类的定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TEntityBase.h"
#include "TSubText.h"
#include "TPushMemVar.h"
#include "TGGiExplodeDraw.h"
#include "TDbBlockInsert.h"
#include "TDbEntity.h"
#include "TDbCurveEntity.h"
#include "TGGiWorldViewportDraw.h"
#include "TConfigBase.h"
#include "TAcDbBlockTableRecordZone.h"
#include "TchPrivateGlobalFunc.h"
#include "TchGlobalCurveFunc.h"
#include "TGGeCurveInline.h"
#if ADS>15
#include "TDbGrip.h"
#include "TDbGripDim.h"
#endif
extern BOOL GetDocLicenser();
extern CMapPtrToPtr g_mapDbToModelRecZone;;
void GetTrueTextExtent(const AcDbEntity*pEnt,TGGePoly2D &polyExt)
{
AcDbEntity *pText=AcDbEntity::cast(pEnt->clone());
AcDbExtents ext;
TADSGePoint3d ptLoc;
double rot=0;
//modify by xlc on 100304 调整调用TDbText的方式
/*
if(pText->isKindOf(TDbText::desc()))
{
TDbText*pText1=TDbText::cast(pText);
rot=pText1->GetRotation()+pText1->GetLayoutRotation();
pText1->SetRotation(0);
pText1->SetLayoutRotation(0);
ptLoc=pText1->GetLocation();
}
else if(pText->isKindOf(TDbMText::desc()))
{
TDbMText*pText1=TDbMText::cast(pText);
rot=pText1->GetRotation()+pText1->GetLayoutRotation();
pText1->SetRotation(0);
pText1->SetLayoutRotation(0);
ptLoc=pText1->GetLocation();
}*/
if(_tcsicmp(pText->isA()->name(),_T("TDbText")) == 0
||_tcsicmp(pText->isA()->name(),_T("TDbMText")) == 0)
{
TDbEntity* pText1 = TDbEntity::cast(pText);
rot=pText1->TBaseGetRotation()+pText1->GetLayoutRotation();
pText1->TBaseSetRotation(0);
pText1->SetLayoutRotation(0);
ptLoc=pText1->TBaseGetLocation();
}
else if(pText->isKindOf(AcDbText::desc()))
{
AcDbText*pText1=AcDbText::cast(pText);
rot=pText1->rotation();
pText1->setRotation(0);
ptLoc=pText1->position();
}
else
{
AcDbMText*pText1=AcDbMText::cast(pText);
rot=pText1->rotation();
pText1->setRotation(0);
ptLoc=pText1->location();
}
pText->getGeomExtents(ext);
delete pText;
TADSGePoint3d pt1=ext.minPoint(),pt3=ext.maxPoint();
TADSGePoint3d pt2(pt3.x,pt1.y),pt4(pt1.x,pt3.y);
polyExt.AppendNode(pt1);
polyExt.AppendNode(pt2);
polyExt.AppendNode(pt3);
polyExt.AppendNode(pt4);
ads_matrix mat;
ptLoc.GetRotationMatrix(rot,mat);
polyExt.TransUCS(mat);
}
// 2-TArch5;3-TArch6 ; 4- TArch7 ;5- TArch8; wlw 6-T20
const Adesk::UInt8 TEntityBase::g_nVersion = 6;
TEntityBase::TEntityBase()
{
extern double g_nDefaultScale;
m_nQuickMarker = 0;
m_nLayoutRotation = 0.0;
m_nPaperScale = g_nDefaultScale;
TConfigBase* pBase = GetGlobalConfigBase();
if (pBase != NULL)
{
m_nPaperScale = pBase->DocGetPScale();
pBase->Close();
}
m_lstClipId.Reset();
m_lstClippedId.Reset();
}
Acad::ErrorStatus TEntityBase::ExplodeOrDraw2d(TGGiExplodeDrawBase &dc) const
{
return Acad::eOk;
}
Acad::ErrorStatus TEntityBase::ExplodeOrDraw3d(TGGiExplodeDrawBase &dc) const
{
return Acad::eOk;
}
TEntityBase::ExplodeOrDrawType TEntityBase::GetExplodeOrDrawType() const
{
return m_eExplodeOrDrawType;
}
bool TEntityBase::IsClipOut()const
{
return false;
}
bool TEntityBase::IsMeClip()const
{
return false;
}
Acad::ErrorStatus TEntityBase::GetClipBoundary(TGGePoly2D& poly)const
{
AcGeVector3d vt;
return GetPathPoly(poly,vt);
}
void TEntityBase::UnionScale(double nScale)
{
}
int TEntityBase::GetFirstVersion()const
{
return 5;
}
bool TEntityBase::IsModelEntity() const
{
return false;
}
BOOL TEntityBase::IsValid() const
{
return TRUE;
}
const TCHAR* TEntityBase::GetDefaultLayer() const
{
return NULL;
}
void TEntityBase::GetTips(TDPtrList<TObjInfoUnit> &lstInfo) const
{
}
AcDbObjectId TEntityBase::GetOwnerId() const
{
return AcDbObjectId::kNull;
}
int TEntityBase::ConvertText(TConvertTextPtr ptr, void *pData)
{
return RTNONE;
}
void TEntityBase::SetSubText(long i,CString sText)
{
}
void TEntityBase::ResetTextPos()
{
}
Acad::ErrorStatus TEntityBase::GetPathPoly(TGGePoly2D &poly,AcGeVector3d&vt)const
{
return Acad::eNotImplementedYet;
}
Acad::ErrorStatus TEntityBase::SetPathPoly(const TGGePoly2D &poly,const AcGeVector3d&vt)
{
return Acad::eNotImplementedYet;
}
Acad::ErrorStatus TEntityBase::GetBindPath(TGGePoly2D &poly,AcGeVector3d&vt)const
{
return GetPathPoly(poly,vt);
}
int TEntityBase::GetCtrlToggleIndex()const
{
return -1;
}
Acad::ErrorStatus TEntityBase::GetGripText(int i, CString &cs) const
{
return Acad::eNotImplemented;
}
void TEntityBase::Close()
{
if (GetMe() != NULL)
{
GetMe()->close();
}
}
BOOL TEntityBase::IsLayoutRotated() const
{
return (fabs(m_nLayoutRotation) > _angSnap);
}
const TEntityFields & TEntityBase::GetFields()const
{
return m_allFields;
}
TEntityFields& TEntityBase::Fields()
{
return m_allFields;
}
// 返回发现的位置,同时posStart往前移动(以便继续找下一个使用),
TTextPosition
TEntityBase::FindSubText(const TCHAR *sSubText, TTextPosition &posStart, TTextRange *pRange) const
{
TTextPosition pos;
return pos;
}
// 返回下一次查找的开始位置
TTextPosition
TEntityBase::ReplaceSubText(const TTextPosition &posRep, const TCHAR *sRepText, TTextRange *pRange)
{
TTextPosition pos;
return pos;
}
void TEntityBase::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
{
AcDbEntity *pTrgEntity = GetMe();
if (!pTrgEntity)
{
return;
}
// 颜色
if (gMatchFlag & AcDbMatchProperties::kColorFlag)
{
pTrgEntity->setColorIndex(pSrcEntity->colorIndex());
}
//图层
if (pTrgEntity->database() == NULL
|| pSrcEntity->database() == NULL
|| pTrgEntity->database() == pSrcEntity->database()) //add by W on 060317
{
if (gMatchFlag & AcDbMatchProperties::kLayerFlag)
{
pTrgEntity->setLayer(pSrcEntity->layerId());
}
// 线型
if (gMatchFlag & AcDbMatchProperties::kLtypeFlag)
{
pTrgEntity->setLinetype(pSrcEntity->linetypeId());
}
#if ADS > 16
// 材质
if (gMatchFlag & AcDbMatchProperties::kMaterialFlag)
{
pTrgEntity->setMaterial(pSrcEntity->materialId());
}
#endif
}
// 线型比例
if (gMatchFlag & AcDbMatchProperties::kLtscaleFlag)
{
pTrgEntity->setLinetypeScale(pSrcEntity->linetypeScale());
}
// 可见性. 总是被复制
pTrgEntity->setVisibility(pSrcEntity->visibility());
const TDbEntity *pSrc1 = TDbEntity::cast(pSrcEntity);
const TDbCurveEntity *pSrc2 = TDbCurveEntity::cast(pSrcEntity);
const TEntityBase *pBaseSrc(NULL);
if (pSrc1)
{
m_nPaperScale = pSrc1->m_nPaperScale;
m_nLayoutRotation = pSrc1->m_nLayoutRotation;
pBaseSrc = (TEntityBase*)pSrc1;
}
else if (pSrc2)
{
m_nPaperScale = pSrc2->m_nPaperScale;
m_nLayoutRotation = pSrc2->m_nLayoutRotation;
pBaseSrc = (TEntityBase*)pSrc2;
}
//wlw add 131224 xdata的复制
if (pBaseSrc && pSrcEntity->desc() == pTrgEntity->desc())
{
m_XDataMap = *(pBaseSrc->GetSpecialtyDataReadOnly());
}
}
INT_PTR TEntityBase::GetQuickMarker() const
{
return m_nQuickMarker;
}
TEntityBase::DrawType TEntityBase::GetDrawType() const
{
return k2Dand3D;
}
// 虚函数
AecObjectEditMethod TEntityBase::GetEditMethod() const
{
return NULL;
}
void TEntityBase::SetPScale(double scale)
{
AcDbEntity *pEnt = GetMe();
if (pEnt)
{
pEnt->assertWriteEnabled();
}
m_nPaperScale = scale;
}
// 取模型比例, 在绘图状态下, 速度要快得多
double TEntityBase::GetPScale() const
{
return m_nPaperScale;
}
double TEntityBase::GetLayoutRotation() const
{
return m_nLayoutRotation;
}
void TEntityBase::SetLayoutRotation(double nRot)
{
AcDbEntity *pEnt = GetMe();
if (pEnt)
{
pEnt->assertWriteEnabled();
}
m_nLayoutRotation = AngleRangeTo2PI(nRot);
}
BOOL TEntityBase::IsSolidFill() const
{
BOOL bSolidFill = FALSE; //如果不是布图方式, 则取全局填充模式
TConfigBase* pBase = GetGlobalConfigBase();
if (pBase != NULL)
{
bSolidFill = pBase->DocGetIsSolidFill();
pBase->Close();
}
return bSolidFill;
}
BOOL TEntityBase::IsBoldLine() const
{
BOOL bBoldLine = FALSE; //如果不是布图方式, 则取全局填充模式
TConfigBase* pBase = GetGlobalConfigBase();
if (pBase != NULL)
{
bBoldLine = pBase->DocGetIsLineWeight();
pBase->Close();
}
return bBoldLine;
}
Acad::ErrorStatus TEntityBase::DownGradeSave(int nDrawMode, AcDbVoidPtrArray &entSet, BOOL *bErase)
{
Acad::ErrorStatus es = Acad::eOk;
if (g_nSaveTArchVer >= GetFirstVersion())
{
if (bErase)
{
*bErase = FALSE;
}
}
else
{
TGGiExplodeDraw dc(entSet);
if (!OnExplodeOrDraw(dc))
{
return es;
}
dc.SetPropertiesFrom(GetMe());
if (nDrawMode == DRAW_2D)
{
es = ExplodeOrDraw2d(dc);
}
else
{
es = ExplodeOrDraw3d(dc);
}
if (bErase)
{
*bErase = TRUE;
}
}
return es;
}
// 从模型中取粗线宽度并换算成为模型空间尺寸
double TEntityBase::GetModelThick() const
{
double nThick = 0.0;
TConfigBase* pBase = GetGlobalConfigBase();
if (pBase != NULL)
{
nThick = pBase->DocGetIsLineWeight() ? pBase->DocGetHighBold() : 0.0;
pBase->Close();
}
return nThick * GetPScale();
}
// 取绘图模式
inline int TEntityBase::GetDrawMode() const
{
BOOL nDrawMode = 3;
TConfigBase* pBase = GetGlobalConfigBase();
if (pBase != NULL)
{
nDrawMode = pBase->DocGetDrawMode();
pBase->Close();
}
return nDrawMode;
}
inline TConfigBase* TEntityBase::GetConfigBase()
{
TConfigBase* pBase = NULL;
pBase = GetGlobalConfigBase();
return pBase;
}
// 只有SetAttributes包含
Adesk::UInt32 TEntityBase::ViewportDrawLogicalFlags(AcGiViewportDraw * vd, Adesk::UInt32 nFlag)
{
ASSERT(g_nAcadVer > 15.0001);
Adesk::UInt32 nFlagNew = nFlag;
int nDrawMode = GetDrawMode();
DrawType nDrawType = GetDrawType();
int nDraw = GetDispMethod(nDrawMode, nDrawType);
if (nDraw != 3)
{
nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw;
}
else
{
nFlagNew |= 256;
}
return nFlagNew;
}
Adesk::UInt32 TEntityBase::SetAttributes(AcGiDrawableTraits * traits, Adesk::UInt32 nFlag)
{
if (g_nAcadVer < 15.0001)
{
return nFlag;
}
// sg delete 120507,下面的修改暂时去掉,会引来设备专业的对象显示有问题
//根据图层的关闭确定drawable的控制 2011-10-10 lfy 修改
//---------------------------------------------------------->
//ads_name ent;
//acdbGetAdsName(ent,GetMe()->layerId());
//resbuf* pRb = acdbEntGet(ent);
//resbuf* pTemp = pRb;
//while (pTemp != NULL)
//{
// if (pTemp->restype == 62)
// {
// if (pTemp->resval.rint < 0)
// {
// nFlag |= AcGiDrawable::kDrawableIsInvisible;
// }
// }
// pTemp = pTemp->rbnext;
//}
//acutRelRb(pRb);
//<-----------------------------------------------------------
int nDrawMode = GetDrawMode();
DrawType nDrawType = GetDrawType();
int nDraw = GetDispMethod(nDrawMode, nDrawType);
Adesk::UInt32 nFlagNew = nFlag;
if (g_nAcadVer> 15.0001)
{
nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw;
}
else
{
if (nDraw != 3)
{
nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw;
}
}
return nFlagNew;
}
//默认都可以被TDbSymbCut裁剪
bool TEntityBase::IsClipMe(const TEntityBase* pEnt)const
{
if (!IsModelEntity()) //add by W on 070524
{
return false;
}
if (pEnt == NULL)
{
return true;
}
//if (pEnt->GetMe()->isKindOf(TDbSymbCut::desc()))
if (_tcsicmp(pEnt->GetMe()->isA()->name(),_T("TDbSymbCut")) == 0)
{
return true;
}
return false;
}
bool TEntityBase::OnExplodeOrDraw(TGGiDrawStreamBase& dc)const
{
for (long i = 0; i < m_lstClipId.Length(); i++)
{
const AcDbObjectId &id = m_lstClipId[i];
if (id.isNull() || !id.isValid())
{
continue;
}
AcDbEntity *pEnt = NULL;
acdbOpenObject(pEnt,id,AcDb::kForRead);
if (pEnt != NULL)
{
TEntityBase* pEntBase = TEntityBase::Cast(pEnt);
if (pEntBase != NULL)
{
TGGePoly2D poly;
if (pEntBase->GetClipBoundary(poly) == Acad::eOk)
{
poly.SetElevation(0);
//if (pEntBase->GetMe()->isKindOf(TDbSymbCut::desc()))
if (_tcsicmp(pEntBase->GetMe()->isA()->name(),_T("TDbSymbCut")) == 0)
{
//TDbSymbCut* pCut = TDbSymbCut::cast(pEntBase->GetMe());
TDbEntity* pCut = TDbEntity::cast(pEntBase->GetMe());
dc.PushClip(poly,pCut->GetClipType());
}
else
{
dc.PushClip(poly,TGGiClipBoundary::kClipIn);
}
}
}
pEnt->close();
}
}
return true;
}
// 功能: 相当于worldDraw
Adesk::Boolean TEntityBase::WorldDraw(AcGiWorldDraw *pWd)
{
m_eExplodeOrDrawType = kWroldDraw;
if (!GetDocLicenser())
{
return Adesk::kTrue;
}
int nDrawMode = GetDrawMode();
DrawType nDrawType = GetDrawType();
AcGiRegenType nRegenType = pWd->regenType();
if (nRegenType == kAcGiSaveWorldDrawForProxy && !g_bSaveProxyGraph) // 代理时不保存
{
return Adesk::kTrue;
}
int nDraw = GetDispMethod(nDrawMode, nDrawType);
TGGiWorldViewportDraw dc(pWd, NULL);
// 设属性,解决打印出现崩溃 --wyg20090801
dc.SetLayer(_T("0"));
dc.SetColor(256);
if (!OnExplodeOrDraw(dc))
{
return Adesk::kTrue;
}
if (nRegenType == kAcGiSaveWorldDrawForProxy
|| nRegenType == kAcGiSaveWorldDrawForR12)
{
if (!!GetOwnerId())
{
pWd->subEntityTraits().setSelectionMarker(0);
dc.SetColorLayer(GetMe()->colorIndex(), GetMe()->layerId());
#if ADS > 16
dc.SetMaterial(GetMe()->materialId());
#endif
}
if ((nDrawMode & DRAW_2D) && (nDrawType != k3DOnly))
{
ExplodeOrDraw2d(dc);
}
else if ((nDrawMode & DRAW_3D) && (nDrawType != k2DOnly))
{
ExplodeOrDraw3d(dc);
}
return Adesk::kTrue;
}
if (g_nAcadVer < 15.0001)
{ //为什么ACAD2002以上的版本总是调用ViewportDraw
if (nDraw == 1 )
{
ExplodeOrDraw2d(dc);
return Adesk::kTrue;
}
else if (nDraw == 2)
{
ExplodeOrDraw3d(dc);
return Adesk::kTrue;
}
else if (nDraw == 3)
{
return Adesk::kFalse; // ViewportDraw
}
}
return Adesk::kFalse;
}
// 为了支持依赖于视窗的显示, 相当于viewportDraw
void TEntityBase::ViewportDraw(AcGiViewportDraw* pMode)
{
m_eExplodeOrDrawType = kViewportDraw;
AcGiRegenType nRegenType = pMode->regenType();
AcGiViewport &vp = pMode->viewport();
AcGePoint3d ptCamera, ptTarget;
vp.getCameraTarget(ptTarget);
vp.getCameraLocation(ptCamera);
AcGeVector3d vtViewDrt = ptCamera-ptTarget;
AcGeVector3d vtViewDir1= vp.viewDir();
AcGeVector3d vtCamera;
vp.getCameraUpVector(vtCamera);
vtViewDrt.normalize();
TGGiWorldViewportDraw dc(NULL, pMode);
// 设属性,解决打印出现崩溃 --wyg20090801
dc.SetLayer(_T("0"));
dc.SetColor(256);
if (!OnExplodeOrDraw(dc))
{
return;
}
if (!!GetOwnerId())
{
pMode->subEntityTraits().setSelectionMarker(0);
dc.SetColorLayer(GetMe()->colorIndex(), GetMe()->layerId());
#if ADS > 16
dc.SetMaterial(GetMe()->materialId());
#endif
}
int nDrawMode = GetDrawMode();
DrawType nDrawType = GetDrawType();
int nDraw = GetDispMethod(nDrawMode, nDrawType);
if (nDraw == 3)
{
if (g_nAcadVer > 15.0001)
{
if (nRegenType == kAcGiRenderCommand
|| nRegenType == kAcGiHideOrShadeCommand
|| vp.isPerspective()
|| vtViewDrt != AcGeVector3d(0,0,1))
{
ExplodeOrDraw3d(dc);
}
else
{
ExplodeOrDraw2d(dc);
}
}
else
{
if (nRegenType == kAcGiRenderCommand
|| vp.isPerspective()
|| vtViewDrt != AcGeVector3d(0,0,1))
{
ExplodeOrDraw3d(dc);
}
else
{
ExplodeOrDraw2d(dc);
}
}
}
else if (nDraw == 1)
{
ExplodeOrDraw2d(dc);
}
else if (nDraw == 2)
{
ExplodeOrDraw3d(dc);
}
}
Acad::ErrorStatus
TEntityBase::Explode(AcDbVoidPtrArray& entitySet) const
{
ExplodeOrDrawType& eExplodeType = (ExplodeOrDrawType&)m_eExplodeOrDrawType;
eExplodeType = kExplode;
//加密语句
if (TchGeLib::g_nProtectCode == 0)
{
return Acad::eCannotExplodeEntity;
}
int expMode = GetExplodeMode();
Acad::ErrorStatus es = Acad::eCannotExplodeEntity;
TGGiExplodeDraw dc(entitySet);
if (!OnExplodeOrDraw(dc))
{
return Acad::eCannotExplodeEntity;
}
dc.SetPropertiesFrom(GetMe());
if (expMode == 1)
{
es = ExplodeOrDraw2d(dc);
}
else if (expMode == 2)
{
es = ExplodeOrDraw3d(dc);
}
return es;
}
int TEntityBase::GetExplodeMode() const
{
int nDrawMode = GetDrawMode();
DrawType nDrawType = GetDrawType();
int nDraw = GetDispMethod(nDrawMode, nDrawType);
if (nDraw == 1)
{
nDraw = DRAW_2D;
}
else if (nDraw == 2)
{
nDraw = DRAW_3D;
}
else if (nDraw == 3)
{
TADSGePoint3d viewDir;
TGGetVar(_T("VIEWDIR"), &viewDir);
viewDir = Ucs2Wcs(viewDir, TRUE);
if (fabs(viewDir.x) > 1.0E-6 || fabs(viewDir.y) > 1.0E-6)
{
nDraw = DRAW_3D;
}
else
{
nDraw = DRAW_2D;
}
}
return nDraw;
}
BOOL &TEntityBase::GetCtrlToggle()const
{
int id = GetCtrlToggleIndex();
if (id < 0 || id >= 100)
{
return g_bCtrlToggle;
}
return g_bCtrlToggle1[id];
}
void TEntityBase::ToggleCtrl()
{
int id = GetCtrlToggleIndex();
if (id < 0 || id >= 100)
{
g_bCtrlToggle = !g_bCtrlToggle;
}
else
{
g_bCtrlToggle1[id] = !g_bCtrlToggle1[id];
}
}
void TEntityBase::ListInfo() const
{
TDPtrList<TObjInfoUnit> lstInfo;
const AcDbEntity *pEnt = GetMe();
ASSERT(pEnt);
AcRxClass *pRT = pEnt->isA();
lstInfo.Append(new TObjInfoUnit(_T("DXF名称"), pRT->dxfName()));
AcDbHandle handle;
pEnt->getAcDbHandle(handle);
TCHAR szHandle[32] = _T("");
handle.getIntoAsciiBuffer(szHandle);
lstInfo.Append(new TObjInfoUnit(_T("对象句柄"), szHandle));
TCHAR *szLayer = pEnt->layer();
ASSERT(szLayer);
lstInfo.Append(new TObjInfoUnit(_T("图层"), szLayer));
delete [] szLayer;
TCString sColorDesc;
int nColor = pEnt->colorIndex();
switch (nColor)
{
case 0:
sColorDesc=_T("随块");
break;
case 1:
sColorDesc=_T("红色(1)");
break;
case 2:
sColorDesc=_T("黄色(2)");
break;
case 3:
sColorDesc=_T("绿色(3)");
break;
case 4:
sColorDesc=_T("青色(4)");
break;
case 5:
sColorDesc=_T("蓝色(5)");
break;
case 6:
sColorDesc=_T("粉红(6)");
break;
case 7:
sColorDesc=_T("白色(7)");
break;
case 256:
sColorDesc=_T("随层");
break;
default:
sColorDesc<<nColor;
break;
}
lstInfo.Append(new TObjInfoUnit(_T("颜色"), sColorDesc));
lstInfo.Append(new TObjInfoUnit(_T("比例"), TCString(_T("%.0f"), m_nPaperScale)));
GetTips(lstInfo);
int nSep = 30;
for (int i = 0; i < lstInfo.Length(); i++)
{
TCString sContent(256);
memset(sContent, 0, 255*sizeof(TCHAR));
TObjInfoUnit *pObjUnit = lstInfo[i];
TCString sLabel(256), sValue(256);
sLabel << pObjUnit->m_sLabel;
if (_tcslen(pObjUnit->m_sValue) < 200)
{
sValue << pObjUnit->m_sValue;
}
else
{
sValue << _T("...");
}
sLabel[nSep-1] = 0;
int nLen = _tcslen(sLabel);
#ifndef _UNICODE
int nPos = nSep - nLen;
memset(sContent, ' ', (nPos + 1) * sizeof(char));
#else
int nPos = (nSep - nLen) / 2;
wmemset(sContent, _T(' '), (nPos + 1) * sizeof(wchar_t));
#endif
sContent << sLabel << _T(": ") << sValue;
TchGeLib::adsout << _T("\n") << sContent;
}
}
//禁止ACGI和图块生成
Acad::ErrorStatus TEntityBase::SimpleExplode(AcDbVoidPtrArray& entSet) const
{
BOOL bMakeBlock = g_bMakeBlock;
BOOL bAcis = g_bEnableAcis;
g_bMakeBlock = FALSE;
g_bEnableAcis= FALSE;
TPushMemVar<BOOL> vTemp(TGGiExplodeDraw::m_bFullExplode, TRUE);
TPushMemVar<BOOL> vTemp1(g_bOsnapExpl, TRUE);
Acad::ErrorStatus es = Explode(entSet);
g_bEnableAcis = bAcis;
g_bMakeBlock = bMakeBlock;
return es;
}
Acad::ErrorStatus TEntityBase::GetExtents2d(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const
{
TAcDbBlockTableRecordZone* pZone = NULL;
g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone);
if (pZone != NULL && !pZone->isActive())
{
pZone = NULL;
}
AcDbExtents ext;
if (pZone != NULL)
{
if ( pZone->getGeomExtents(GetMe()->objectId(),ext))
{
ptLow = ext.minPoint();
ptUp = ext.maxPoint();
ptLow.z = ptUp.z = 0.0;
return Acad::eOk;
}
}
//如果是楼梯,则取夹点集算范围加速 lfy 2010-6-12
CString sText = GetMe()->isA()->name();
if (sText.Find(_T("Stair")) != -1)
{
AcDbIntArray arModes,arGeIds;
AcGePoint3dArray arPts;
GetMe()->getGripPoints(arPts,arModes,arGeIds);
for (int i = 0;i < arPts.length();i++)
{
if (i == 0)
{
ptLow = arPts.at(i);
ptUp = arPts.at(i);
}
else
{
ptLow = Min(ptLow, TADSGePoint3d(arPts.at(i)));
ptUp = Max(ptUp, TADSGePoint3d(arPts.at(i)));
}
}
if (pZone != NULL)
{
//add by xlc on 100619 有时会id为空,此时包围盒大小有误
AcDbObjectId id = GetMe()->objectId();
if (!id.isNull())
{
ext.set(ptLow,ptUp);
pZone->setGeomExtents(id,ext);
}
}
ptLow.z = ptUp.z = 0.0;
return Acad::eOk;
}
BOOL bInit = FALSE;
AcDbVoidPtrArray entSet;
TGGiExplodeDraw dc(entSet);
BOOL bMakeBlock = g_bMakeBlock;
BOOL bAcis = g_bEnableAcis;
g_bMakeBlock = FALSE;
g_bEnableAcis= FALSE;
Acad::ErrorStatus es;
{
TPushMemVar<BOOL> vTemp(g_bGetExtents, TRUE);
es = ExplodeOrDraw2d(dc);
}
g_bMakeBlock = bMakeBlock;
g_bEnableAcis= bAcis;
int len = entSet.length();
for (int i = 0; i < len; i++)
{
AcDbEntity *pEnt = (AcDbEntity *)entSet[i];
AcDbExtents ext;
if (pEnt->getGeomExtents(ext) == Acad::eOk)
{
AcGePoint3d ptMax = ext.maxPoint(), ptMin = ext.minPoint();
if (bInit)
{
ptLow = Min(ptLow, TADSGePoint3d(ptMin));
ptUp = Max(ptUp, TADSGePoint3d(ptMax));
}
else
{
ptLow = ptMin;
ptUp = ptMax;
bInit = TRUE;
}
}
}
if (pZone != NULL)
{
//add by xlc on 100619 有时会id为空,此时包围盒大小有误
AcDbObjectId id = GetMe()->objectId();
if (!id.isNull())
{
ext.set(ptLow,ptUp);
pZone->setGeomExtents(id,ext);
}
}
ReleaseEntSet(entSet);
ptLow.z = ptUp.z = 0.0;
return es;
}
Acad::ErrorStatus TEntityBase::GetExtents(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const
{
TAcDbBlockTableRecordZone* pZone = NULL;
g_mapDbToModelRecZone.Lookup((void*)acdbCurDwg(),(void*&)pZone);
if (pZone != NULL && !pZone->isActive())
{
pZone = NULL;
}
AcDbExtents ext;
if (pZone != NULL)
{
if ( pZone->getGeomExtents(GetMe()->objectId(),ext))
{
ptLow = ext.minPoint();
ptUp = ext.maxPoint();
ptLow.z = ptUp.z = 0.0;
return Acad::eOk;
}
}
//如果是楼梯,则取夹点集算范围加速 lfy 2010-6-12
CString sText = GetMe()->isA()->name();
if (sText.Find(_T("Stair")) != -1)
{
AcDbIntArray arModes,arGeIds;
AcGePoint3dArray arPts;
GetMe()->getGripPoints(arPts,arModes,arGeIds);
for (int i = 0;i < arPts.length();i++)
{
if (i == 0)
{
ptLow = arPts.at(i);
ptUp = arPts.at(i);
}
else
{
ptLow = Min(ptLow, TADSGePoint3d(arPts.at(i)));
ptUp = Max(ptUp, TADSGePoint3d(arPts.at(i)));
}
}
if (pZone != NULL)
{
//add by xlc on 100619 有时会id为空,此时包围盒大小有误
AcDbObjectId id = GetMe()->objectId();
if (!id.isNull())
{
ext.set(ptLow,ptUp);
pZone->setGeomExtents(id,ext);
}
}
ptLow.z = ptUp.z = 0.0;
return Acad::eOk;
}
BOOL bInit = FALSE;
AcDbVoidPtrArray entSet;
Acad::ErrorStatus es;
{
TPushMemVar<BOOL> vTemp(g_bGetExtents, TRUE);
es = SimpleExplode(entSet);
}
int len = entSet.length();
for (int i = 0; i < len; i++)
{
AcDbEntity *pEnt = (AcDbEntity *)entSet[i];
AcDbExtents ext;
if (pEnt->getGeomExtents(ext) == Acad::eOk)
{
AcGePoint3d ptMax = ext.maxPoint(), ptMin = ext.minPoint();
if (bInit)
{
ptLow = Min(ptLow, TADSGePoint3d(ptMin));
ptUp = Max(ptUp, TADSGePoint3d(ptMax));
}
else
{
ptLow = ptMin;
ptUp = ptMax;
bInit = TRUE;
}
}
}
ReleaseEntSet(entSet);
if (pZone != NULL)
{
//add by xlc on 100619 有时会id为空,此时包围盒大小有误
AcDbObjectId id = GetMe()->objectId();
if (!id.isNull())
{
ext.set(ptLow,ptUp);
pZone->setGeomExtents(id,ext);
}
}
return es;
}
Acad::ErrorStatus TEntityBase::GetExtents(TADSGePoint3d &ptCen, double *nX, double *nY, double *nZ) const
{
TADSGePoint3d ptLow, ptUp;
Acad::ErrorStatus es = GetExtents(ptLow, ptUp);
if (es != Acad::eOk)
{
return es;
}
ptCen = ptLow + ptUp;
ptCen.Scale(0.5);
if (nX)
{
*nX = ptUp.x - ptLow.x;
}
if (nY)
{
*nY = ptUp.y - ptLow.y;
}
if (nZ)
{
*nZ = ptUp.z - ptLow.z;
}
return es;
}
// 功能: 定义特征捕捉点
// 状态: 有待完成
Acad::ErrorStatus TEntityBase::GetOsnapPoints(
AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& ptPick,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
AcDbVoidPtrArray entSet;
INT_PTR nMarker = m_nQuickMarker;
((TEntityBase *)this)->m_nQuickMarker = gsSelectionMark;
Acad::ErrorStatus es;
es = SimpleExplode(entSet);
((TEntityBase *)this)->m_nQuickMarker = nMarker;
if (es == Acad::eOk)
{
int len = entSet.length();
for (int i = 0; i < len; i++)
{
AcDbEntity *pEnt=(AcDbEntity *)entSet[i];
if (pEnt->isKindOf(AcDbText::desc()))
{
if (osnapMode == AcDb::kOsModeIns)
{
snapPoints.append(AcDbText::cast(pEnt)->position());
}
else
{
continue;
}
}
es = pEnt->getOsnapPoints(osnapMode, 0, ptPick, lastPoint, viewXform,
snapPoints, geomIds);
}
es = Acad::eOk;
}
ReleaseEntSet(entSet);
return es;
}
// 功能: 定义特征捕捉点
// 状态: 有待完成insertionMat
Acad::ErrorStatus TEntityBase::GetOsnapPoints(
AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& ptPick,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds,
const AcGeMatrix3d& insertionMat) const
{
Acad::ErrorStatus es = GetMe()->getOsnapPoints(osnapMode,gsSelectionMark,ptPick,
lastPoint,viewXform,snapPoints,geomIds);
return es;
}
bool TEntityBase::IsIntersectWith(const AcDbEntity*pEntity,bool bFrame)const
{
if (bFrame)
{
TEntityBase* pEntBase = TEntityBase::Cast(pEntity);
if (pEntBase != NULL)
{
TADSGePoint3d ptLow1,ptUp1,ptLow,ptUp;
if (GetExtents2d(ptLow,ptUp) != Acad::eOk
|| pEntBase->GetExtents2d(ptLow1,ptUp1) != Acad::eOk)
{
return false;
}
if (ptLow1.x > ptUp.x ||
ptLow1.y > ptUp.y ||
ptUp1.x < ptLow.x ||
ptUp1.y < ptLow.y)
{
return false;
}
return true;
}
}
AcDbVoidPtrArray entSet;
if (GetMe()->explode(entSet) == Acad::eOk)
{
int len = entSet.length();
TEntityBase *pEntBase = TEntityBase::Cast(pEntity);
if (pEntBase != NULL)
{
for (int i = 0; i < len; i++)
{
AcDbEntity *pEnt = (AcDbEntity *)entSet[i];
if (pEntBase->IsIntersectWith(pEnt))
{
ReleaseEntSet(entSet);
return true;
}
}
}
else
{
AcGePoint3dArray pts;
for (int i = 0; i < len; i++)
{
AcDbEntity *pEnt = (AcDbEntity *)entSet[i];
if ((GetMe()->intersectWith(pEntity,AcDb::kOnBothOperands,AcGePlane(AcGePoint3d::kOrigin,AcGeVector3d::kZAxis),pts) == Acad::eOk
&& !pts.isEmpty()))
{
ReleaseEntSet(entSet);
return true;
}
}
}
ReleaseEntSet(entSet);
}
return false;
}
Acad::ErrorStatus TEntityBase::IntersectWith(const AcDbEntity* ent,
AcDb::Intersect intType,
AcGePoint3dArray& points,
INT_PTR thisGsMarker,
INT_PTR otherGsMarker) const
{
int expMode = GetExplodeMode();
if (expMode == 2)
{
return Acad::eNotImplementedYet;
}
AcDbVoidPtrArray entSet;
INT_PTR nMarker = m_nQuickMarker;
((TEntityBase *)this)->m_nQuickMarker = thisGsMarker;
Acad::ErrorStatus es;
es = SimpleExplode(entSet);
((TEntityBase *)this)->m_nQuickMarker = nMarker;
if (es == Acad::eOk)
{
es = Acad::eNotApplicable;
int len = entSet.length();
for(int i = 0; i < len; i++)
{
AcDbEntity *pEnt = (AcDbEntity *)entSet[i];
if (pEnt->isKindOf(AcDbText::desc()))
{
continue;
}
if (pEnt->intersectWith(ent, intType, points, 0, otherGsMarker) == Acad::eOk)
{
es = Acad::eOk;
}
}
}
ReleaseEntSet(entSet);
return es;
}
Acad::ErrorStatus TEntityBase::IntersectWith(const AcDbEntity* ent,
AcDb::Intersect intType,
const AcGePlane& projPlane,
AcGePoint3dArray& points,
INT_PTR thisGsMarker,
INT_PTR otherGsMarker) const
{
int expMode = GetExplodeMode();
if (expMode == 2)
{
return Acad::eNotImplementedYet;
}
AcDbVoidPtrArray entSet;
INT_PTR nMarker = m_nQuickMarker;
((TEntityBase *)this)->m_nQuickMarker = thisGsMarker;
Acad::ErrorStatus es;
es = SimpleExplode(entSet);
((TEntityBase *)this)->m_nQuickMarker = nMarker;
if (es == Acad::eOk)
{
es = Acad::eNotApplicable;
int len = entSet.length();
for (int i = 0; i < len; i++)
{
AcDbEntity *pEnt = (AcDbEntity *)entSet[i];
if (pEnt->isKindOf(AcDbText::desc()))
{
continue;
}
if (pEnt->intersectWith(ent, intType, projPlane, points, 0, otherGsMarker) == Acad::eOk)
{
es = Acad::eOk;
}
}
}
ReleaseEntSet(entSet);
return es;
}
//基于布局的转角
double TEntityBase::Layout2Wcs(double nAngLay) const
{
return AngleRangeTo2PI(nAngLay + m_nLayoutRotation);
}
//基于布局的转角
double TEntityBase::Wcs2Layout(double nAngWcs) const
{
return AngleRangeTo2PI(nAngWcs - m_nLayoutRotation);
}
//在布局时正常观察的WCS角度
double TEntityBase::NormalViewAngle(double nAngWcs) const
{
double nAng1 = TchPrivate::ChangeAngleTo1_4(Wcs2Layout(nAngWcs));
nAng1 = AngleRangeTo2PI(m_nLayoutRotation + nAng1);
return nAng1;
}
//在位编辑支持
long TEntityBase::GetSubTextNum()const
{
TPushMemVar<BOOL> vTemp(g_bExplodeSubText,TRUE);
AcDbVoidPtrArray allEnt;
TGGiExplodeDraw dc(allEnt);
ExplodeOrDraw2d(dc);
long count = 0;
for (long i = 0; i < allEnt.length(); i++)
{
AcDbEntity* pEnt = (AcDbEntity*)allEnt[i];
if (pEnt->isKindOf(AcDbText::desc())
|| pEnt->isKindOf(AcDbMText::desc())
// || pEnt->isKindOf(TDbText::desc())
// || pEnt->isKindOf(TDbMText::desc()))
||(_tcsicmp(pEnt->isA()->name(),_T("TDbText")) == 0)
||(_tcsicmp(pEnt->isA()->name(),_T("TDbMText")) == 0))
{
count++;
}
}
ReleaseEntSet(allEnt);
return count;
}
long TEntityBase::GetNextSubTextIndex(long i, bool bVert, bool bPre)const
{
long num = GetSubTextNum();
if (bPre)
{
return i = (i - 1 + num) % num;
}
else
{
return i = (i + 1 ) % num;
}
}
TSubText* TEntityBase::GetSubText(long iText)const
{
TPushMemVar<BOOL> vTemp(g_bExplodeSubText,TRUE);
TSubText* pSubText = NULL;
AcDbVoidPtrArray allEnt;
TGGiExplodeDraw dc(allEnt);
dc.SetPropertiesFrom(GetMe()); //add by W on 060404
ExplodeOrDraw2d(dc);
long count = 0;
for (long i = 0; i < allEnt.length(); i++)
{
AcDbEntity* pEnt = (AcDbEntity*)allEnt[i];
if (pEnt->isKindOf(AcDbText::desc())
|| pEnt->isKindOf(AcDbMText::desc())
// || pEnt->isKindOf(TDbText::desc())
// || pEnt->isKindOf(TDbMText::desc()))
||(_tcsicmp(pEnt->isA()->name(),_T("TDbText")) == 0)
||(_tcsicmp(pEnt->isA()->name(),_T("TDbMText")) == 0))
{
if (count == iText)
{
allEnt[i] = NULL;
pSubText = new TSubText(GetMe()->objectId(),pEnt,iText);
break;
}
count++;
}
}
ReleaseEntSet(allEnt);
return pSubText;
}
TSubText* TEntityBase::HitTestText(TADSGePoint3d pt)const
{
TPushMemVar<BOOL> vTemp(g_bExplodeSubText,TRUE);
TSubText* pSubText = NULL;
AcDbVoidPtrArray allEnt;
TGGiExplodeDraw dc(allEnt);
dc.SetPropertiesFrom(GetMe()); //add by W on 060404
ExplodeOrDraw2d(dc);
long count = 0;
for (long i = 0;i < allEnt.length(); i++)
{
AcDbEntity* pEnt = (AcDbEntity*)allEnt[i];
if (pEnt->isKindOf(AcDbText::desc())
|| pEnt->isKindOf(AcDbMText::desc())
//|| pEnt->isKindOf(TDbText::desc())
//|| pEnt->isKindOf(TDbMText::desc()))
|| _tcsicmp(pEnt->isA()->name(), _T("TDbText")) == 0
|| _tcsicmp(pEnt->isA()->name(), _T("TDbMText")) == 0)
{
AcDbExtents ext;
pEnt->getGeomExtents(ext);
TADSGePoint3d ptMin = ext.minPoint();
TADSGePoint3d ptMax = ext.maxPoint();
if (pt.x >= ptMin.x
&& pt.x <= ptMax.x
&& pt.y >= ptMin.y
&& pt.y <= ptMax.y)
{
allEnt[i] = NULL;
TGGePoly2D polyExt;
GetTrueTextExtent(pEnt,polyExt);
polyExt.SetElevation(0);
pt.z = 0;
if ((pt & polyExt) != PR_OUTSIDE)
{
pSubText = new TSubText(GetMe()->objectId(),pEnt,count);
break;
}
}
count++;
}
}
ReleaseEntSet(allEnt);
return pSubText;
}
//在位编辑支持end
Acad::ErrorStatus TEntityBase::DwgInFields(AcDbDwgFiler* pFiler)
{
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if (nVer > g_nVersion)
{
return Acad::eMakeMeProxy;
}
if (nVer > 1)
{
pFiler->readItem(&m_nPaperScale);
}
if (nVer > 2)
{
pFiler->readItem(&m_nLayoutRotation);
}
m_lstClipId.Reset();
m_lstClippedId.Reset();
if (nVer > 3)
{
Adesk::UInt8 nFlag = 0;
pFiler->readItem(&nFlag);
if ((nFlag & 0x01) != 0)
{
Adesk::UInt8 nCount = 0;
pFiler->readItem(&nCount);
for (Adesk::UInt8 n = 0; n < nCount; n++)
{
AcDbSoftPointerId id;
pFiler->readItem(&id);
m_lstClipId.Append(new AcDbSoftPointerId(id));
}
}
if ((nFlag & 0x02) != 0)
{
Adesk::UInt8 nCount = 0;
pFiler->readItem(&nCount);
for (Adesk::UInt8 n = 0; n < nCount; n++)
{
AcDbSoftPointerId id;
pFiler->readItem(&id);
m_lstClippedId.Append(new AcDbSoftPointerId(id));
}
}
}
if (nVer > 4)
{
m_allFields.DwgIn(pFiler);
}
if (nVer > 5)
m_XDataMap.dwgInFields(pFiler);
return pFiler->filerStatus();
}
Acad::ErrorStatus TEntityBase::DwgOutFields(AcDbDwgFiler* pFiler) const
{
if (false)
//if (!g_szArxContext && g_nUseHours > 300.0)
{
pFiler->writeItem(g_nVersion);
}
else
{
if (g_nSaveTArchVer == 5)
{
pFiler->writeItem((Adesk::UInt8)2);
}
else if (g_nSaveTArchVer == 6)
{
pFiler->writeItem((Adesk::UInt8)3);
}
else if (g_nSaveTArchVer == 7)
{
pFiler->writeItem((Adesk::UInt8)4);
}
else if (g_nSaveTArchVer == 8)
{
pFiler->writeItem((Adesk::UInt8)5);
}
else if (g_nSaveTArchVer == 9)
{
pFiler->writeItem((Adesk::UInt8)5);
}
else
{
pFiler->writeItem(g_nVersion);
}
}
pFiler->writeItem(m_nPaperScale);
if (g_nSaveTArchVer > 5)
{
pFiler->writeItem(m_nLayoutRotation);
}
if (g_nSaveTArchVer > 6)
{
Adesk::UInt8 nFlag = 0;
if (IsClipMe())
{
nFlag |= 0x01;
}
if (IsMeClip())
{
nFlag |= 0x02;
}
pFiler->writeItem(nFlag);
if ((nFlag & 0x01) != 0)
{
Adesk::UInt8 nCount = (Adesk::UInt8)m_lstClipId.Length();
pFiler->writeItem(nCount);
for(long i = 0; i < nCount; i++)
{
const AcDbSoftPointerId &id = m_lstClipId[i];
// modify by xlc on 100827 解决块参照在位编辑时删除对象后参照丢失无法保存的问题
if(id.isErased())
{
pFiler->writeItem(AcDbSoftPointerId(AcDbObjectId::kNull));
}
else
{
pFiler->writeItem(id);
}
}
}
if ((nFlag & 0x02) != 0)
{
Adesk::UInt8 nCount = (Adesk::UInt8)m_lstClippedId.Length();
pFiler->writeItem(nCount);
for (long i = 0; i < nCount; i++)
{
const AcDbSoftPointerId &id = m_lstClippedId[i];
// modify by xlc on 100827 解决块参照在位编辑时删除对象后参照丢失无法保存的问题
if(id.isErased())
{
pFiler->writeItem(AcDbSoftPointerId(AcDbObjectId::kNull));
}
else
{
pFiler->writeItem(id);
}
}
}
}
if (g_nSaveTArchVer > 7)
{
m_allFields.DwgOut(pFiler);
}
if (g_nSaveTArchVer > 9)
m_XDataMap.dwgOutFields(pFiler);
return pFiler->filerStatus();
}
Acad::ErrorStatus TEntityBase::DxfInFields (AcDbDxfFiler* pFiler)
{
resbuf rb;
Acad::ErrorStatus es = Acad::eOk;
while ((es == Acad::eOk)
&& ((es = pFiler->readResBuf(&rb)) == Acad::eOk))
{
switch (rb.restype)
{
case 46:
m_nLayoutRotation = rb.resval.rreal;
break;
case 47:
m_nPaperScale = rb.resval.rreal;
break;
case 68:
break;
default:
// 不能识别的组,释放从子类读取
pFiler->pushBackItem();
es = Acad::eEndOfFile;
break;
}
}
// es必须返回eEndOfFile ,否则会出错,应立即返回
if (es != Acad::eEndOfFile)
{
return Acad::eInvalidResBuf;
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TEntityBase::DxfOutFields(AcDbDxfFiler* pFiler) const
{
pFiler->writeItem(46, GetLayoutRotation());
pFiler->writeItem(47, GetPScale());
pFiler->writeInt16(68, (Adesk::Int16)GetDrawType());
return pFiler->filerStatus();
}
TEntityBase* TEntityBase::Cast(const AcDbObject*pEnt0)
{
TDbEntity *pEnt = TDbEntity::cast(pEnt0);
if (pEnt != NULL)
{
return pEnt;
}
else
{
TDbCurveEntity*pEnt1 = TDbCurveEntity::cast(pEnt0);
if (pEnt1 != NULL)
{
return pEnt1;
}
else
{
return TDbBlockInsert::cast(pEnt0);
}
}
return NULL;
}
void TEntityBase::RemoveClipId(const AcDbObjectId&id)
{
GetMe()->assertWriteEnabled();
m_lstClipId.FindAndDel(&id,CompareObjectId);
}
void TEntityBase::RemoveClippedId(const AcDbObjectId&id)
{
GetMe()->assertWriteEnabled();
m_lstClippedId.FindAndDel(&id,CompareObjectId);
}
void TEntityBase::AppendClipId(const AcDbObjectId&id)
{
GetMe()->assertWriteEnabled();
if (!m_lstClipId.FindNode(&id, CompareObjectId))
{
m_lstClipId.Append(new AcDbSoftPointerId(id));
}
}
void TEntityBase::AppendClippedId(const AcDbObjectId&id)
{
GetMe()->assertWriteEnabled();
if (!m_lstClippedId.FindNode(&id, CompareObjectId))
{
m_lstClippedId.Append(new AcDbSoftPointerId(id));
}
}
void TEntityBase::ResetClippedShip()
{
GetMe()->assertWriteEnabled();
for (long i = 0; i < m_lstClippedId.Length(); i++)
{
const AcDbObjectId &id = *m_lstClippedId[i];
if (id.isNull() || !id.isValid())
{
continue;
}
AcDbEntity *pEnt = NULL;
acdbOpenObject(pEnt,id,AcDb::kForWrite);
if (pEnt != NULL)
{
TEntityBase *pEntBase = TEntityBase::Cast(pEnt);
if (pEntBase != NULL)
{
pEntBase->RemoveClipId(GetMe()->objectId());
}
pEnt->close();
}
}
m_lstClippedId.Reset();
}
void TEntityBase::ResetClipShip()
{
GetMe()->assertWriteEnabled();
for (long i = 0; i < m_lstClipId.Length(); i++)
{
const AcDbObjectId& id = *m_lstClipId[i];
if (id.isNull() || !id.isValid())
{
continue;
}
AcDbEntity *pEnt = NULL;
acdbOpenObject(pEnt,id,AcDb::kForWrite);
if (pEnt != NULL)
{
TEntityBase *pEntBase = TEntityBase::Cast(pEnt);
if (pEntBase != NULL)
{
pEntBase->RemoveClippedId(GetMe()->objectId());
}
pEnt->close();
}
}
m_lstClipId.Reset();
}
//更新主动裁剪关系
void TEntityBase::ValidateClipShip(LPVOID pResver,LPVOID pResver2)
{
Acad::ErrorStatus es = GetMe()->upgradeOpen();
//add by xlc on 100618 上华图块在位编辑时es返回eOnLockedLayer
if (!(es == Acad::eOk || es == Acad::eWasOpenForWrite ))
{
return;
}
GetMe()->assertWriteEnabled();
ResetClippedShip();
TADSGePoint3d ptMid,ptLow,ptUp;
if (GetExtents2d(ptLow,ptUp) != Acad::eOk)
{
return;
}
AcDbObjectIdArray* pArray = NULL;
AcDbObjectIdArray idArray;
if (pResver != NULL)
{
typedef std::map<LONG_PTR,PVOID>::iterator IT;
std::map<LONG_PTR,PVOID>* pmap = (std::map<LONG_PTR,PVOID>*)pResver;
IT it = pmap->find(GetMe()->blockId().asOldId());
if (it != pmap->end())
{
pArray = (AcDbObjectIdArray* )(*it).second;
idArray.append(*pArray);
}
else
{
pArray = new AcDbObjectIdArray;
GetVisibleEnts(*pArray,GetMe()->blockId(),true,pResver2);//AcDb::kVisible
std::pair<LONG_PTR,PVOID> pairT;
pairT.first = GetMe()->blockId().asOldId();
pairT.second = (PVOID)pArray;
pmap->insert(pairT);
}
}
else
{
GetVisibleEnts(idArray,GetMe()->blockId(),true,pResver2);
pArray = &idArray;
}
AcDb::Visibility vs;
for (long i = 0; i < pArray->length(); i++)
{
AcDbEntity *pEntity = NULL;
acdbOpenObject(pEntity,pArray->at(i),AcDb::kForRead);
if (pEntity == NULL)
{
continue;
}
vs = pEntity->visibility();
TEntityBase* pEntBase = TEntityBase::Cast(pEntity);
if (pEntBase == NULL)
{
pArray->removeAt(i);
i-= 1;
pEntity->close();
continue;
}
if ( !pEntBase->IsClipMe(this))
{
pEntity->close();
continue;
}
TADSGePoint3d ptLow1,ptUp1;
if (pEntBase->GetExtents2d(ptLow1,ptUp1) != Acad::eOk)
{
pEntity->close();
continue;
}
if (ptLow1.x > ptUp.x
|| ptLow1.y > ptUp.y
|| ptUp1.x < ptLow.x
|| ptUp1.y < ptLow.y)
{
pEntity->close();
continue;
}
if (pEntity->upgradeOpen() == Acad::eOk)
{
//Acad::ErrorStatus es = GetMe()->upgradeOpen();
//GetMe()->assertWriteEnabled();
//ResetClippedShip();
AppendClippedId(pEntity->objectId());
if (es == Acad::eOk)
{
GetMe()->downgradeOpen();
}
pEntBase->AppendClipId(GetMe()->objectId());
}
pEntity->close();
}
}
//更新被裁剪关系
void TEntityBase::ValidateClippedShip(LPVOID pResver,LPVOID pResver2)
{
Acad::ErrorStatus es = GetMe()->upgradeOpen();
//add by xlc on 100618 上华图块在位编辑时es返回eOnLockedLayer
if (!(es == Acad::eOk || es == Acad::eWasOpenForWrite ))
{
return;
}
GetMe()->assertWriteEnabled();
ResetClipShip();
TADSGePoint3d ptMid,ptLow,ptUp;
if (GetExtents2d(ptLow,ptUp) != Acad::eOk)
{
return;
}
AcDbObjectIdArray* pArray = NULL;
AcDbObjectIdArray idArray;
if (pResver != NULL)
{
typedef std::map<LONG_PTR,PVOID>::iterator IT;
std::map<LONG_PTR,PVOID>* pmap = (std::map<LONG_PTR,PVOID>*)pResver;
IT it = pmap->find(GetMe()->blockId().asOldId());
if (it != pmap->end())
{
pArray = (AcDbObjectIdArray* )(*it).second;
}
else
{
pArray = new AcDbObjectIdArray;
GetVisibleEnts(*pArray,GetMe()->blockId(),true,pResver2);
std::pair<LONG_PTR,PVOID> pairT;
pairT.first = GetMe()->blockId().asOldId();
pairT.second = (PVOID)pArray;
pmap->insert(pairT);
}
}
else
{
GetVisibleEnts(idArray,GetMe()->blockId(),true,pResver2);//AcDb::kVisible
pArray = &idArray;
}
for (long i = 0; i < pArray->length(); i++)
{
AcDbEntity *pEntity = NULL;
acdbOpenObject(pEntity,pArray->at(i),AcDb::kForRead);
if (pEntity == NULL)
{
continue;
}
TEntityBase* pEntBase = TEntityBase::Cast(pEntity);
if (pEntBase == NULL)
{
pArray->removeAt(i);
i-= 1;
pEntity->close();
continue;
}
if (!IsClipMe(pEntBase))
{
pEntity->close();
continue;
}
TADSGePoint3d ptLow1,ptUp1;
if (pEntBase->GetExtents2d(ptLow1,ptUp1) != Acad::eOk)
{
pEntity->close();
continue;
}
if (ptLow1.x > ptUp.x
|| ptLow1.y > ptUp.y
|| ptUp1.x < ptLow.x
|| ptUp1.y < ptLow.y)
{
pEntity->close();
continue;
}
if (pEntity->upgradeOpen() == Acad::eOk)
{
//Acad::ErrorStatus es = GetMe()->upgradeOpen();
//GetMe()->assertWriteEnabled();
//ResetClipShip();
pEntBase->AppendClippedId(GetMe()->objectId());
if (es == Acad::eOk)
{
GetMe()->downgradeOpen();
}
AppendClipId(pEntity->objectId());
}
pEntity->close();
}
}
#if ADS > 15
//动态输入夹点支持
long TEntityBase::GetGripNum()const
{
return m_allGrip.GetLength();
}
TDbGrip* TEntityBase::GetGrip(long i)const
{
return m_allGrip.GetAt(i);
}
TDbGripDim* TEntityBase::GetGripDim(long iGrip,long iDim)
{
return GetGrip(iGrip)->GetDim(iDim);
}
void TEntityBase::ClearGrip()
{
m_allGrip.Clear();
}
//更新夹点参数和关联动态标注
void TEntityBase::UpdateDim(long iGrip,const AcDbEntity *pEnt)
{
if (!m_allGrip.IsValidIndex(iGrip))
{
return;
}
TDbGrip *pGrip = m_allGrip[iGrip];
for (long iDim = 0; iDim < pGrip->GetDimNum(); iDim++)
{
EntityToDim(iGrip,iDim,pEnt);
}
pGrip->UpdateDimEnt();
}
const TCHAR* TEntityBase::GripToolTip(AcDbGripData* pThis)
{
if (pThis == NULL)
{
return NULL;
}
TDbGrip* pGrip = (TDbGrip*)pThis->appData();
if (pGrip == NULL)
{
return NULL;
}
return pGrip->ToolTip();
}
bool TEntityBase::GripWorldDraw(AcDbGripData* pThis,
AcGiWorldDraw* pWd,
const AcDbObjectId& entId,
AcDbGripOperations::DrawType type,
AcGePoint3d* imageGripPoint,
double dGripSize)
{
if (pThis == NULL)
{
return false;
}
TDbGrip* pGrip = (TDbGrip*)pThis->appData();
if (pGrip == NULL)
{
return false;
}
return pGrip->WorldDraw(pWd,type,dGripSize);
}
void TEntityBase::GripViewportDraw(AcDbGripData* pThis,
AcGiViewportDraw* pVd,
const AcDbObjectId& entId,
AcDbGripOperations::DrawType type,
AcGePoint3d* imageGripPoint,
int dGripSize)
{
if (pThis == NULL)
{
return;
}
TDbGrip* pGrip = (TDbGrip*)pThis->appData();
if (pGrip == NULL)
{
return;
}
pGrip->ViewportDraw(pVd,type,dGripSize);
}
void TEntityBase::GripHoverDimension(AcDbGripData* pThis,
const AcDbObjectId& entId,
double dimScale,
AcDbDimDataPtrArray& dimData)
{
if (pThis == NULL)
{
return;
}
TDbGrip* pGrip = (TDbGrip*)pThis->appData();
if (pGrip == NULL)
{
return;
}
pGrip->GetHoverDimension(entId,dimScale,dimData);
}
void TEntityBase::GripHotDimension(AcDbGripData* pThis,
const AcDbObjectId& entId,
double dimScale,
AcDbDimDataPtrArray& dimData)
{
if (pThis == NULL)
{
return;
}
TDbGrip* pGrip = (TDbGrip*)pThis->appData();
if (pGrip == NULL)
{
return;
}
pGrip->GetHotDimension(entId,dimScale,dimData);
}
AcGeVector3d TEntityBase::DimDataSetValue(AcDbDimData* pThis,
AcDbEntity* pEnt,
double newValue,
const AcGeVector3d& offset)
{
AcGeVector3d offset1(0,0,0);
if (pThis == NULL && pEnt == NULL)
{
return offset1;
}
TEntityBase* pGripEntity = TEntityBase::Cast(pEnt);
if (pGripEntity != NULL)
{
TDbGripDim* pGripDim = (TDbGripDim*)pThis->appData();
if (pGripDim != NULL)
{
const TDbGrip* pGrip = pGripDim->Grip();
if (pGrip != NULL)
{
long iGrip = pGrip->Index();
long iDim = pGripDim->Index();
AcGePoint3d ptGripOld = pGripEntity->GetGripPoint(iGrip);
if (pEnt->objectId().isValid()) //add by W on 071009
{
pEnt->assertWriteEnabled();
}
if (pGripEntity->DimToEntity(iGrip,iDim,newValue,offset) == Acad::eOk)
{
if (pGripDim->CanLock())
{
pGripDim->Lock(newValue);
}
offset1 = pGripEntity->GetGripPoint(iGrip) - ptGripOld;
}
}
}
}
return offset1;
}
void TEntityBase::GripStatus(const AcDb::GripStat status)
{
if (status == AcDb::kGripsDone)
{
ClearGrip();
}
}
void TEntityBase::CreateGrip()
{
AcGePoint3dArray gripPoints;
AcDbIntArray osnapModes,geomIds;
if (GetMe()->getGripPoints(gripPoints,osnapModes,geomIds) == Acad::eOk)
{
m_allGrip.SetLength(gripPoints.length());
for (long i = 0; i < gripPoints.length(); i++)
{
m_allGrip[i] = new TDbGrip(this,gripPoints[i]);
m_allGrip[i]->SetIndex(i);
}
}
}
Acad::ErrorStatus TEntityBase::EntityToDim(long iGrip,long iDim,const AcDbEntity*pEnt)
{
return Acad::eNotImplementedYet;
}
Acad::ErrorStatus TEntityBase::DimToEntity(long iGrip,long iDim,double newValue,const AcGeVector3d& offset)
{
return Acad::eNotImplementedYet;
}
AcGePoint3d TEntityBase::GetGripPoint(long iGrip)const
{
AcGePoint3dArray points;
AcDbIntArray osnapModes,geomIds;
GetMe()->getGripPoints(points,osnapModes,geomIds);
return points[iGrip];
}
Acad::ErrorStatus TEntityBase::GetGripPoints(AcDbGripDataPtrArray& grips,
const double curViewUnitSize,
const int gripSize,
const AcGeVector3d& curViewDir,
const int bitflags) const
{
TEntityBase* pThis = (TEntityBase*)this;
//创建夹点(包括夹点参数)
pThis->ClearGrip(); //安全操作
pThis->CreateGrip();
//由夹点创建AcDbGripData
for (long i = 0; i < m_allGrip.GetLength(); i++)
{
grips.append(m_allGrip.GetAt(i)->CreateGripData());
}
return Acad::eOk;
}
Acad::ErrorStatus TEntityBase::MoveGripPointsAt(const AcDbVoidPtrArray& appData,
const AcGeVector3d& offset,
const int bitflags)
{
if (appData.isEmpty())
{
return Acad::eInvalidInput;
}
TDbGrip* pGrip=(TDbGrip*)appData[0];
TEntityBase *pOwner=pGrip->Owner();
if (pOwner == NULL)
{
return Acad::eInvalidInput;
}
AcDbIntArray indice;
for (long i = 0; i < appData.length(); i++)
{
indice.append(((TDbGrip*)appData[i])->Index());
}
Acad::ErrorStatus es = GetMe()->moveGripPointsAt(indice,offset);
//模拟锁定
for (i = 0; i < pGrip->GetDimNum(); i++)
{
TDbGripDim *pDim = pGrip->GetDim(i);
if (pDim->IsLocked())
{
DimToEntity(pGrip->Index(), i, pDim->GetLockValue(), AcGeVector3d(0,0,0));
}
}
if (es == Acad::eOk)
{
for (i = 0; i < indice.length(); i++)
{
pOwner->UpdateDim(indice[i],GetMe());
}
}
return es;
}
#endif // ADS > 15
bool TEntityBase::UnifyElevation(double dElevation)
{
return true;
}
bool TEntityBase::GetStandardFaceBody(AcDbVoidPtrArray& arFacePtrs) const
{
return false;
}
bool TEntityBase::GetSafeProtectedSpace(AcDbVoidPtrArray& arFacePtrs) const
{
return false;
}
bool TEntityBase::GetSection(const AcDbFace &face, const AcGeVector3d& vtPlaneSecDir, std::vector<TObjSectionRecord> &sectionRecord, AcDbVoidPtrArray& arFillPtrs) const
{
return false;
}
CString TEntityBase::GetXml(const AcGeMatrix3d& mat) const
{
// sr modify 120801
const AcDbEntity *pEnt = GetMe();
if (pEnt)
{
CString strLayerName, strLineType;
TCHAR *chlayer = pEnt->layer();
strLayerName = chlayer;
delete [] chlayer;
TCHAR *szLinetype = pEnt->linetype();
strLineType = szLinetype;
delete [] szLinetype;
CString strXML = _T("");
strXML += _T("<LAYER name=\"图层名\" comment=\"当前对象的图层\">");
strXML += strLayerName + _T("</LAYER>\n");
strXML += _T("<LINETYPE name=\"线型\" comment=\"当前对象的线型名\">");
strXML += strLineType + _T("</LINETYPE>\n");
return strXML;
}
return _T("");
}
//t20
TDbXDataMap* TEntityBase::GetSpecialtyData()
{
return NULL;
}
TDbXDataMap* TEntityBase::GetSpecialtyDataReadOnly() const
{
return NULL;
}
BOOL TEntityBase::SetAt(LPCTSTR pszKey,TXData& XData)
{
return FALSE;
}
BOOL TEntityBase::GetAt(LPCTSTR pszKey,TXData& XData) const
{
return FALSE;
}
CString TEntityBase::Tg2PKPM(const AcGeMatrix3d& mat) const { return _T(""); }
CString TEntityBase::Tg2PDMS(const AcGeMatrix3d& mat) const { return _T(""); }