//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : AEntityBase.cpp // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: $基本对象基础类的定义 // = Maintainers: // //-----------------------------------------------------------------------------+ #include "StdAfx.h" #include "AEntityBase.h" #include "SubText.h" #include "XPushMemVar.h" #include "XExplodeStream.h" #include "AecDbBlockInsert.h" #include "AecEntity.h" #include "AecCurveEntity.h" #include "XAcGiViewDraw.h" #include "XConfigBase.h" #include "XBlockTableRecordZone.h" #include "XPrivateGlobalFunc.h" #include "XGlobalCurveFunc.h" #include "XCurveInline.h" #include "dbmatch.h" #include "dbobjptr.h" #if ARX > 17 #include "AecDbGrip.h" #include "AecDbGripDim.h" #endif extern CMapPtrToPtr g_mapDbToModelRecZone;; void GetTrueTextExtent(const AcDbEntity*pEnt,XPoly2D &polyExt) { AcDbEntity *pText=AcDbEntity::cast(pEnt->clone()); AcDbExtents ext; XPoint ptLoc; double rot=0; //modify by zjq on 100304 调整调用AecDbText的方式 /* if(pText->isKindOf(AecDbText::desc())) { AecDbText*pText1=AecDbText::cast(pText); rot=pText1->GetRotation()+pText1->GetLayoutRotation(); pText1->SetRotation(0); pText1->SetLayoutRotation(0); ptLoc=pText1->GetLocation(); } else if(pText->isKindOf(AecDbMText::desc())) { AecDbMText*pText1=AecDbMText::cast(pText); rot=pText1->GetRotation()+pText1->GetLayoutRotation(); pText1->SetRotation(0); pText1->SetLayoutRotation(0); ptLoc=pText1->GetLocation(); }*/ if(_tcsicmp(pText->isA()->name(),_T("AecDbText")) == 0 || _tcsicmp(pText->isA()->name(),_T("AecDbMText")) == 0 || _tcsicmp(pText->isA()->name(),_T("AecDbMTextNew")) == 0 ) { AecEntity* pText1 = AecEntity::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; XPoint pt1=ext.minPoint(),pt3=ext.maxPoint(); XPoint 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 const Adesk::UInt8 AEntityBase::g_nVersion = 5; AEntityBase::AEntityBase() { m_nQuickMarker = 0; m_nLayoutRotation = 0.0; m_nPaperScale = 1;//DocGetPScale(); //也许由于不能访问全局设置导致出错 XConfigBase* pBase = GetGlobalConfigBase(); if (pBase != NULL) { m_nPaperScale = pBase->DocGetPScale(); pBase->Close(); } m_lstClipId.Reset(); m_lstClippedId.Reset(); } Acad::ErrorStatus AEntityBase::ExplodeOrDraw2d(XExplodeDraw &dc) const { return Acad::eOk; } Acad::ErrorStatus AEntityBase::ExplodeOrDraw3d(XExplodeDraw &dc) const { return Acad::eOk; } bool AEntityBase::GetStandardFaceBody(AcDbVoidPtrArray& arFacePtrs) const { return false; } bool AEntityBase::GetSafeProtectedSpace(AcDbVoidPtrArray& arFacePtrs)const { return false; } bool AEntityBase::GetSection(const AcDbFace &face, const AcGeVector3d &vtPlaneSecDir, std::vector §ionRecord, AcDbVoidPtrArray& arFillPtrs)const { return false; } CString AEntityBase::GetXml()const { return _T(""); } AEntityBase::ExplodeOrDrawType AEntityBase::GetExplodeOrDrawType() const { return m_eExplodeOrDrawType; } bool AEntityBase::IsClipOut()const { return false; } bool AEntityBase::IsMeClip()const { return false; } Acad::ErrorStatus AEntityBase::GetClipBoundary(XPoly2D& poly)const { AcGeVector3d v; return GetPathPoly(poly,v); } void AEntityBase::UnionScale(double nScale) { } int AEntityBase::GetFirstVersion()const { return 5; } bool AEntityBase::IsModelEntity() const { return false; } BOOL AEntityBase::IsValid() const { return TRUE; } const TCHAR* AEntityBase::GetDefaultLayer() const { return NULL; } void AEntityBase::GetTips(DList &lstInfo) const { } AcDbObjectId AEntityBase::GetOwnerId() const { return AcDbObjectId::kNull; } int AEntityBase::ConvertText(TConvertTextPtr ptr, void *pData) { return RTNONE; } void AEntityBase::SetSubText(long i,CString sText) { } void AEntityBase::ResetTextPos() { } Acad::ErrorStatus AEntityBase::GetPathPoly(XPoly2D &poly,AcGeVector3d&vt)const { return Acad::eNotImplementedYet; } Acad::ErrorStatus AEntityBase::SetPathPoly(const XPoly2D &poly,const AcGeVector3d&vt) { return Acad::eNotImplementedYet; } Acad::ErrorStatus AEntityBase::GetBindPath(XPoly2D &poly,AcGeVector3d&vt)const { return GetPathPoly(poly,vt); } int AEntityBase::GetCtrlToggleIndex()const { return -1; } Acad::ErrorStatus AEntityBase::GetGripText(int i, CString &cs) const { return Acad::eNotImplemented; } void AEntityBase::Close() { if (GetMe() != NULL) { GetMe()->close(); } } BOOL AEntityBase::IsLayoutRotated() const { return (fabs(m_nLayoutRotation) > _angSnap); } const EntityFields & AEntityBase::GetFields()const { return m_allFields; } EntityFields& AEntityBase::Fields() { return m_allFields; } // 返回发现的位置,同时posStart往前移动(以便继续找下一个使用), TextPosition AEntityBase::FindSubText(const TCHAR *sSubText, TextPosition &posStart, TextRange *pRange) const { TextPosition pos; return pos; } // 返回下一次查找的开始位置 TextPosition AEntityBase::ReplaceSubText(const TextPosition &posRep, const TCHAR *sRepText, TextRange *pRange) { TextPosition pos; return pos; } void AEntityBase::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 on 060317 { if (gMatchFlag & AcDbMatchProperties::kLayerFlag) { pTrgEntity->setLayer(pSrcEntity->layerId()); } // 线型 if (gMatchFlag & AcDbMatchProperties::kLtypeFlag) { pTrgEntity->setLinetype(pSrcEntity->linetypeId()); } #if ARX > 17 // 材质 if (gMatchFlag & AcDbMatchProperties::kMaterialFlag) { pTrgEntity->setMaterial(pSrcEntity->materialId()); } #endif } // 线型比例 if (gMatchFlag & AcDbMatchProperties::kLtscaleFlag) { pTrgEntity->setLinetypeScale(pSrcEntity->linetypeScale()); } // 可见性. 总是被复制 pTrgEntity->setVisibility(pSrcEntity->visibility()); const AecEntity *pSrc1 = AecEntity::cast(pSrcEntity); const AecCurveEntity *pSrc2 = AecCurveEntity::cast(pSrcEntity); if (pSrc1) { m_nPaperScale = pSrc1->m_nPaperScale; m_nLayoutRotation = pSrc1->m_nLayoutRotation; } else if (pSrc2) { m_nPaperScale = pSrc2->m_nPaperScale; m_nLayoutRotation = pSrc2->m_nLayoutRotation; } } INT_PTR AEntityBase::GetQuickMarker() const { return m_nQuickMarker; } AEntityBase::DrawType AEntityBase::GetDrawType() const { return k2Dand3D; } // 虚函数 AecObjectEditMethod AEntityBase::GetEditMethod() const { return NULL; } void AEntityBase::SetPScale(double scale) { AcDbEntity *pEnt = GetMe(); if (pEnt) { pEnt->assertWriteEnabled(); } m_nPaperScale = scale; } // 取模型比例, 在绘图状态下, 速度要快得多 double AEntityBase::GetPScale() const { return m_nPaperScale; } double AEntityBase::GetLayoutRotation() const { return m_nLayoutRotation; } void AEntityBase::SetLayoutRotation(double nRot) { AcDbEntity *pEnt = GetMe(); if (pEnt) { pEnt->assertWriteEnabled(); } m_nLayoutRotation = CT_std_angle(nRot); } BOOL AEntityBase::IsSolidFill() const { BOOL bSolidFill = FALSE; //如果不是布图方式, 则取全局填充模式 XConfigBase* pBase = GetGlobalConfigBase(); if (pBase != NULL) { bSolidFill = pBase->DocGetIsSolidFill(); pBase->Close(); } return bSolidFill; } BOOL AEntityBase::IsBoldLine() const { BOOL bBoldLine = FALSE; //如果不是布图方式, 则取全局填充模式 XConfigBase* pBase = GetGlobalConfigBase(); if (pBase != NULL) { bBoldLine = pBase->DocGetIsLineWeight(); pBase->Close(); } return bBoldLine; } Acad::ErrorStatus AEntityBase::DownGradeSave(int nDrawMode, AcDbVoidPtrArray &entSet, BOOL *bErase) { Acad::ErrorStatus es = Acad::eOk; if (g_nSaveTArchVer >= GetFirstVersion()) { if (bErase) { *bErase = FALSE; } } else { XExplodeStream 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 AEntityBase::GetModelThick() const { double nThick = 0.0; XConfigBase* pBase = GetGlobalConfigBase(); if (pBase != NULL) { nThick = pBase->DocGetIsLineWeight() ? pBase->DocGetHighBold() : 0.0; pBase->Close(); } return nThick * GetPScale(); } // 取绘图模式 inline int AEntityBase::GetDrawMode() const { BOOL nDrawMode = 3; XConfigBase* pBase = GetGlobalConfigBase(); if (pBase != NULL) { nDrawMode = pBase->DocGetDrawMode(); pBase->Close(); } return nDrawMode; } XConfigBase* AEntityBase::GeXConfigBase() { XConfigBase* pBase = NULL; pBase = GetGlobalConfigBase(); return pBase; } // 只有SetAttributes包含 Adesk::UInt32 AEntityBase::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 AEntityBase::SetAttributes(AcGiDrawableTraits * traits, Adesk::UInt32 nFlag) { if (g_nAcadVer < 15.0001) { return nFlag; } 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; } //默认都可以被AecDbSymbCut裁剪 bool AEntityBase::IsClipMe(const AEntityBase* pEnt)const { if (!IsModelEntity()) //add by W on 070524 { return false; } if (pEnt == NULL) { return true; } //if (pEnt->GetMe()->isKindOf(AecDbSymbCut::desc())) if (_tcsicmp(pEnt->GetMe()->isA()->name(),_T("TDbSymbCut")) == 0) { return true; } return false; } bool AEntityBase::OnExplodeOrDraw(XDcStream& 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) { AEntityBase* pEntBase = AEntityBase::Cast(pEnt); if (pEntBase != NULL) { XPoly2D poly; if (pEntBase->GetClipBoundary(poly) == Acad::eOk) { poly.SetElevation(0); //if (pEntBase->GetMe()->isKindOf(AecDbSymbCut::desc())) if (_tcsicmp(pEntBase->GetMe()->isA()->name(),_T("TDbSymbCut")) == 0) { //AecDbSymbCut* pCut = AecDbSymbCut::cast(pEntBase->GetMe()); AecEntity* pCut = AecEntity::cast(pEntBase->GetMe()); if (pCut != NULL) dc.PushClip(poly,pCut->GetClipType()); } else { dc.PushClip(poly,XDcClip::kClipIn); } } } pEnt->close(); } } return true; } // 功能: 相当于worldDraw Adesk::Boolean AEntityBase::WorldDraw(AcGiWorldDraw *pWd) { m_eExplodeOrDrawType = kWroldDraw; int nDrawMode = GetDrawMode(); DrawType nDrawType = GetDrawType(); XAcGiViewDraw dc(pWd, NULL); // AcDbEntity* pMe = GetMe(); // if (dc.IsPlotGeneration()) // { // } AcGiRegenType nRegenType = pWd->regenType(); if (nRegenType == kAcGiSaveWorldDrawForProxy) // 代理时不保存 { XPoint viewDir; xg_getvar(_T("VIEWDIR"), &viewDir); viewDir = Ucs2Wcs(viewDir, TRUE); if (fabs(viewDir.x) > 1.0E-6 || fabs(viewDir.y) > 1.0E-6) { ExplodeOrDraw3d(dc); } else { ExplodeOrDraw2d(dc); } return Adesk::kTrue; } int nDraw = GetDispMethod(nDrawMode, nDrawType); // 设属性,解决打印出现崩溃 --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 ARX > 17 // 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; } // 功能: 相当于worldDraw //Adesk::Boolean AEntityBase::WorldDraw(AcGiWorldDraw *pWd) //{ // m_eExplodeOrDrawType = kWroldDraw; // // int nDrawMode = GetDrawMode(); // AEntityBase::DrawType nDrawType = GetDrawType(); // // XAcGiViewDraw dc(pWd, NULL); // AcGiRegenType nRegenType = pWd->regenType(); // // if (nRegenType == kAcGiSaveWorldDrawForProxy && !g_bSaveProxyGraph) // 代理时不保存 // { // if (!!GetOwnerId()) // { // pWd->subEntityTraits().setSelectionMarker(0); // dc.SetColorLayer(GetMe()->colorIndex(), GetMe()->layerId()); //#if ARX > 17 // dc.SetMaterial(GetMe()->materialId()); //#endif // } // // 取当前视口 // XPoint viewDir; // xg_getvar(_T("VIEWDIR"), &viewDir); // viewDir = Ucs2Wcs(viewDir, TRUE); // // if (fabs(viewDir.x) > 1.0E-6 || fabs(viewDir.y) > 1.0E-6) // { // ExplodeOrDraw3d(dc); // } // else // { // ExplodeOrDraw2d(dc); // } // return Adesk::kTrue; // } // return Adesk::kTrue; //} // 为了支持依赖于视窗的显示, 相当于viewportDraw void AEntityBase::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(); XAcGiViewDraw dc(NULL, pMode); // 设属性,解决打印出现崩溃 --wyg20090801 dc.SetLayer(_T("0")); dc.SetColor(256); //如果图层关闭 AcDbLayerTableRecordPointer pLayer(GetMe()->layerId(), AcDb::kForRead); if (pLayer.openStatus() == Acad::eOk && pLayer->isOff() ) { return; } if (!OnExplodeOrDraw(dc)) { return; } if (!!GetOwnerId()) { dc.SetLayer(GetMe()->layerId()); pMode->subEntityTraits().setSelectionMarker(0); dc.SetColorLayer(GetMe()->colorIndex(), GetMe()->layerId()); #if ARX > 17 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 AEntityBase::Explode(AcDbVoidPtrArray& entitySet) const { ExplodeOrDrawType& eExplodeType = (ExplodeOrDrawType&)m_eExplodeOrDrawType; eExplodeType = kExplode; int expMode = GetExplodeMode(); Acad::ErrorStatus es = Acad::eCannotExplodeEntity; XExplodeStream 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 AEntityBase::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) { XPoint viewDir; xg_getvar(_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 &AEntityBase::GetCtrlToggle()const { int id = GetCtrlToggleIndex(); if (id < 0 || id >= 100) { return g_bCtrlToggle; } return g_bCtrlToggle1[id]; } void AEntityBase::ToggleCtrl() { int id = GetCtrlToggleIndex(); if (id < 0 || id >= 100) { g_bCtrlToggle = !g_bCtrlToggle; } else { g_bCtrlToggle1[id] = !g_bCtrlToggle1[id]; } } void AEntityBase::ListInfo() const { DList lstInfo; const AcDbEntity *pEnt = GetMe(); ASSERT(pEnt); AcRxClass *pRT = pEnt->isA(); lstInfo.Append(new ObjInfoUnit(_T("DXF名称"), pRT->dxfName())); AcDbHandle handle; pEnt->getAcDbHandle(handle); TCHAR szHandle[32] = _T(""); handle.getIntoAsciiBuffer(szHandle); lstInfo.Append(new ObjInfoUnit(_T("对象句柄"), szHandle)); TCHAR *szLayer = pEnt->layer(); ASSERT(szLayer); lstInfo.Append(new ObjInfoUnit(_T("图层"), szLayer)); delete [] szLayer; XString 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<m_sLabel; if (_tcslen(pObjUnit->m_sValue) < 200) { sValue << pObjUnit->m_sValue; } else { sValue << _T("..."); } sLabel[nSep-1] = 0; INT_PTR nLen = _tcslen(sLabel); #ifndef _UNICODE int nPos = nSep - nLen; memset(sContent, ' ', (nPos + 1) * sizeof(char)); #else INT_PTR nPos = (nSep - nLen) / 2; wmemset(sContent, _T(' '), (nPos + 1) * sizeof(wchar_t)); #endif sContent << sLabel << _T(": ") << sValue; XGeLib::adsout << _T("\n") << sContent; } } //禁止ACGI和图块生成 Acad::ErrorStatus AEntityBase::SimpleExplode(AcDbVoidPtrArray& entSet) const { BOOL bMakeBlock = g_bMakeBlock; BOOL bAcis = g_bEnableAcis; g_bMakeBlock = FALSE; g_bEnableAcis= FALSE; XPushMemVar vTemp(XExplodeStream::m_bFullExplode, TRUE); XPushMemVar vTemp1(g_bOsnapExpl, TRUE); Acad::ErrorStatus es = Explode(entSet); g_bEnableAcis = bAcis; g_bMakeBlock = bMakeBlock; return es; } Acad::ErrorStatus AEntityBase::GetExtents2d(XPoint &ptLow, XPoint &ptUp) const { XBlockTableRecordZone* 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; } } //如果是楼梯,则取夹点集算范围加速 zjq 2009-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, XPoint(arPts.at(i))); ptUp = Max(ptUp, XPoint(arPts.at(i))); } } if (pZone != NULL) { //add by zjq 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; XExplodeStream dc(entSet); BOOL bMakeBlock = g_bMakeBlock; BOOL bAcis = g_bEnableAcis; g_bMakeBlock = FALSE; g_bEnableAcis= FALSE; Acad::ErrorStatus es; { XPushMemVar 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, XPoint(ptMin)); ptUp = Max(ptUp, XPoint(ptMax)); } else { ptLow = ptMin; ptUp = ptMax; bInit = TRUE; } } } if (pZone != NULL) { //add by zjq 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 AEntityBase::GetExtents(XPoint &ptLow, XPoint &ptUp) const { XBlockTableRecordZone* 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; } } //如果是楼梯,则取夹点集算范围加速 zjq 2009-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, XPoint(arPts.at(i))); ptUp = Max(ptUp, XPoint(arPts.at(i))); } } if (pZone != NULL) { //add by zjq 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; { XPushMemVar 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, XPoint(ptMin)); ptUp = Max(ptUp, XPoint(ptMax)); } else { ptLow = ptMin; ptUp = ptMax; bInit = TRUE; } } } ReleaseEntSet(entSet); if (pZone != NULL) { //add by zjq on 100619 有时会id为空,此时包围盒大小有误 AcDbObjectId id = GetMe()->objectId(); if (!id.isNull()) { ext.set(ptLow,ptUp); pZone->setGeomExtents(id,ext); } } return es; } Acad::ErrorStatus AEntityBase::GetExtents(XPoint &ptCen, double *nX, double *nY, double *nZ) const { XPoint 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 AEntityBase::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; ((AEntityBase *)this)->m_nQuickMarker = gsSelectionMark; Acad::ErrorStatus es; es = SimpleExplode(entSet); ((AEntityBase *)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 AEntityBase::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 AEntityBase::IsIntersectWith(const AcDbEntity*pEntity,bool bFrame)const { if (bFrame) { AEntityBase* pEntBase = AEntityBase::Cast(pEntity); if (pEntBase != NULL) { XPoint 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(); AEntityBase *pEntBase = AEntityBase::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 AEntityBase::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; ((AEntityBase *)this)->m_nQuickMarker = thisGsMarker; Acad::ErrorStatus es; es = SimpleExplode(entSet); ((AEntityBase *)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 AEntityBase::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; ((AEntityBase *)this)->m_nQuickMarker = thisGsMarker; Acad::ErrorStatus es; es = SimpleExplode(entSet); ((AEntityBase *)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 AEntityBase::Layout2Wcs(double nAngLay) const { return CT_std_angle(nAngLay + m_nLayoutRotation); } //基于布局的转角 double AEntityBase::Wcs2Layout(double nAngWcs) const { return CT_std_angle(nAngWcs - m_nLayoutRotation); } //在布局时正常观察的WCS角度 double AEntityBase::NormalViewAngle(double nAngWcs) const { double nAng1 = XPrivate::xg_angle(Wcs2Layout(nAngWcs)); nAng1 = CT_std_angle(m_nLayoutRotation + nAng1); return nAng1; } //在位编辑支持 long AEntityBase::GetSubTextNum()const { XPushMemVar vTemp(g_bExplodeSubText,TRUE); AcDbVoidPtrArray allEnt; XExplodeStream 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(AecDbText::desc()) // || pEnt->isKindOf(AecDbMText::desc())) ||(_tcsicmp(pEnt->isA()->name(),_T("AecDbText")) == 0) ||(_tcsicmp(pEnt->isA()->name(),_T("AecDbMText")) == 0) ||_tcsicmp(pEnt->isA()->name(),_T("AecDbMTextNew")) == 0) { count++; } } ReleaseEntSet(allEnt); return count; } long AEntityBase::GetNexSubTextIndex(long i, bool bVert, bool bPre)const { long num = GetSubTextNum(); if (bPre) { return i = (i - 1 + num) % num; } else { return i = (i + 1 ) % num; } } SubText* AEntityBase::GetSubText(long iText)const { XPushMemVar vTemp(g_bExplodeSubText,TRUE); SubText* pSubText = NULL; AcDbVoidPtrArray allEnt; XExplodeStream 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(AecDbText::desc()) // || pEnt->isKindOf(AecDbMText::desc())) ||(_tcsicmp(pEnt->isA()->name(),_T("AecDbText")) == 0) ||(_tcsicmp(pEnt->isA()->name(),_T("AecDbMText")) == 0) ||_tcsicmp(pEnt->isA()->name(),_T("AecDbMTextNew")) == 0) { if (count == iText) { allEnt[i] = NULL; pSubText = new SubText(GetMe()->objectId(),pEnt,iText); break; } count++; } } ReleaseEntSet(allEnt); return pSubText; } SubText* AEntityBase::HitTestText(XPoint pt)const { XPushMemVar vTemp(g_bExplodeSubText,TRUE); SubText* pSubText = NULL; AcDbVoidPtrArray allEnt; XExplodeStream 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(AecDbText::desc()) //|| pEnt->isKindOf(AecDbMText::desc())) || _tcsicmp(pEnt->isA()->name(), _T("AecDbText")) == 0 || _tcsicmp(pEnt->isA()->name(), _T("AecDbMText")) == 0 ||_tcsicmp(pEnt->isA()->name(),_T("AecDbMTextNew")) == 0) { AcDbExtents ext; pEnt->getGeomExtents(ext); XPoint ptMin = ext.minPoint(); XPoint ptMax = ext.maxPoint(); if (pt.x >= ptMin.x && pt.x <= ptMax.x && pt.y >= ptMin.y && pt.y <= ptMax.y) { allEnt[i] = NULL; XPoly2D polyExt; GetTrueTextExtent(pEnt,polyExt); polyExt.SetElevation(0); pt.z = 0; if ((pt & polyExt) != PR_OUTSIDE) { pSubText = new SubText(GetMe()->objectId(),pEnt,count); break; } } count++; } } ReleaseEntSet(allEnt); return pSubText; } //在位编辑支持end Acad::ErrorStatus AEntityBase::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); } return pFiler->filerStatus(); } Acad::ErrorStatus AEntityBase::DwgOutFields(AcDbDwgFiler* pFiler) const { 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 { 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 zjq 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 zjq on 100827 解决块参照在位编辑时删除对象后参照丢失无法保存的问题 if(id.isErased()) { pFiler->writeItem(AcDbSoftPointerId(AcDbObjectId::kNull)); } else { pFiler->writeItem(id); } } } } if (g_nSaveTArchVer > 7) { m_allFields.DwgOut(pFiler); } return pFiler->filerStatus(); } Acad::ErrorStatus AEntityBase::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 AEntityBase::DxfOutFields(AcDbDxfFiler* pFiler) const { pFiler->writeItem(46, GetLayoutRotation()); pFiler->writeItem(47, GetPScale()); pFiler->writeInt16(68, (Adesk::Int16)GetDrawType()); return pFiler->filerStatus(); } AEntityBase* AEntityBase::Cast(const AcDbObject*pEnt0) { AecEntity *pEnt = AecEntity::cast(pEnt0); if (pEnt != NULL) { return pEnt; } else { AecCurveEntity*pEnt1 = AecCurveEntity::cast(pEnt0); if (pEnt1 != NULL) { return pEnt1; } else { return AecDbBlockInsert::cast(pEnt0); } } return NULL; } void AEntityBase::RemoveClipId(const AcDbObjectId&id) { GetMe()->assertWriteEnabled(); m_lstClipId.FindAndDel(&id,CompareObjectId); } void AEntityBase::RemoveClippedId(const AcDbObjectId&id) { GetMe()->assertWriteEnabled(); m_lstClippedId.FindAndDel(&id,CompareObjectId); } void AEntityBase::AppendClipId(const AcDbObjectId&id) { GetMe()->assertWriteEnabled(); if (!m_lstClipId.FindNode(&id, CompareObjectId)) { m_lstClipId.Append(new AcDbSoftPointerId(id)); } } void AEntityBase::AppendClippedId(const AcDbObjectId&id) { GetMe()->assertWriteEnabled(); if (!m_lstClippedId.FindNode(&id, CompareObjectId)) { m_lstClippedId.Append(new AcDbSoftPointerId(id)); } } void AEntityBase::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) { AEntityBase *pEntBase = AEntityBase::Cast(pEnt); if (pEntBase != NULL) { pEntBase->RemoveClipId(GetMe()->objectId()); } pEnt->close(); } } m_lstClippedId.Reset(); } void AEntityBase::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) { AEntityBase *pEntBase = AEntityBase::Cast(pEnt); if (pEntBase != NULL) { pEntBase->RemoveClippedId(GetMe()->objectId()); } pEnt->close(); } } m_lstClipId.Reset(); } //更新主动裁剪关系 void AEntityBase::ValidateClipShip(LPVOID pResver,LPVOID pResver2) { Acad::ErrorStatus es = GetMe()->upgradeOpen(); //add by zjq on 100618 $图块在位编辑时es返回eOnLockedLayer if (!(es == Acad::eOk || es == Acad::eWasOpenForWrite )) { return; } GetMe()->assertWriteEnabled(); ResetClippedShip(); XPoint ptMid,ptLow,ptUp; if (GetExtents2d(ptLow,ptUp) != Acad::eOk) { return; } AcDbObjectIdArray* pArray = NULL; AcDbObjectIdArray idArray; if (pResver != NULL) { typedef std::map::iterator IT; std::map* pmap = (std::map*)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 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(); AEntityBase* pEntBase = AEntityBase::Cast(pEntity); if (pEntBase == NULL) { pArray->removeAt(i); i-= 1; pEntity->close(); continue; } if ( !pEntBase->IsClipMe(this)) { pEntity->close(); continue; } XPoint 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 AEntityBase::ValidateClippedShip(LPVOID pResver,LPVOID pResver2) { Acad::ErrorStatus es = GetMe()->upgradeOpen(); //add by zjq on 100618 $图块在位编辑时es返回eOnLockedLayer if (!(es == Acad::eOk || es == Acad::eWasOpenForWrite )) { return; } GetMe()->assertWriteEnabled(); ResetClipShip(); XPoint ptMid,ptLow,ptUp; if (GetExtents2d(ptLow,ptUp) != Acad::eOk) { return; } AcDbObjectIdArray* pArray = NULL; AcDbObjectIdArray idArray; if (pResver != NULL) { typedef std::map::iterator IT; std::map* pmap = (std::map*)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 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; } AEntityBase* pEntBase = AEntityBase::Cast(pEntity); if (pEntBase == NULL) { pArray->removeAt(i); i-= 1; pEntity->close(); continue; } if (!IsClipMe(pEntBase)) { pEntity->close(); continue; } XPoint 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 ARX > 17 //动态输入夹点支持 long AEntityBase::GetGripNum()const { return m_allGrip.GetLength(); } AecDbGrip* AEntityBase::GetGrip(long i)const { return m_allGrip.GetAt(i); } AecDbGripDim* AEntityBase::GetGripDim(long iGrip,long iDim) { return GetGrip(iGrip)->GetDim(iDim); } void AEntityBase::ClearGrip() { m_allGrip.Clear(); } //更新夹点参数和关联动态标注 void AEntityBase::UpdateDim(long iGrip,const AcDbEntity *pEnt) { if (!m_allGrip.IsValidIndex(iGrip)) { return; } AecDbGrip *pGrip = m_allGrip[iGrip]; for (long iDim = 0; iDim < pGrip->GetDimNum(); iDim++) { EntityToDim(iGrip,iDim,pEnt); } pGrip->UpdateDimEnt(); } const TCHAR* AEntityBase::GripToolTip(AcDbGripData* pThis) { if (pThis == NULL) { return NULL; } AecDbGrip* pGrip = (AecDbGrip*)pThis->appData(); if (pGrip == NULL) { return NULL; } return pGrip->ToolTip(); } bool AEntityBase::GripWorldDraw(AcDbGripData* pThis, AcGiWorldDraw* pWd, const AcDbObjectId& entId, AcDbGripOperations::DrawType type, AcGePoint3d* imageGripPoint, double dGripSize) { if (pThis == NULL) { return false; } AecDbGrip* pGrip = (AecDbGrip*)pThis->appData(); if (pGrip == NULL) { return false; } return pGrip->WorldDraw(pWd,type,dGripSize); } void AEntityBase::GripViewportDraw(AcDbGripData* pThis, AcGiViewportDraw* pVd, const AcDbObjectId& entId, AcDbGripOperations::DrawType type, AcGePoint3d* imageGripPoint, int dGripSize) { if (pThis == NULL) { return; } AecDbGrip* pGrip = (AecDbGrip*)pThis->appData(); if (pGrip == NULL) { return; } pGrip->ViewportDraw(pVd,type,dGripSize); } void AEntityBase::GripHoverDimension(AcDbGripData* pThis, const AcDbObjectId& entId, double dimScale, AcDbDimDataPtrArray& dimData) { if (pThis == NULL) { return; } AecDbGrip* pGrip = (AecDbGrip*)pThis->appData(); if (pGrip == NULL) { return; } pGrip->GetHoverDimension(entId,dimScale,dimData); } void AEntityBase::GripHotDimension(AcDbGripData* pThis, const AcDbObjectId& entId, double dimScale, AcDbDimDataPtrArray& dimData) { if (pThis == NULL) { return; } AecDbGrip* pGrip = (AecDbGrip*)pThis->appData(); if (pGrip == NULL) { return; } pGrip->GetHotDimension(entId,dimScale,dimData); } AcGeVector3d AEntityBase::DimDataSetValue(AcDbDimData* pThis, AcDbEntity* pEnt, double newValue, const AcGeVector3d& offset) { AcGeVector3d offset1(0,0,0); if (pThis == NULL && pEnt == NULL) { return offset1; } AEntityBase* pGripEntity = AEntityBase::Cast(pEnt); if (pGripEntity != NULL) { AecDbGripDim* pGripDim = (AecDbGripDim*)pThis->appData(); if (pGripDim != NULL) { const AecDbGrip* 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 AEntityBase::GripStatus(const AcDb::GripStat status) { if (status == AcDb::kGripsDone) { ClearGrip(); } } void AEntityBase::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 AecDbGrip(this,gripPoints[i]); m_allGrip[i]->SetIndex(i); } } } Acad::ErrorStatus AEntityBase::EntityToDim(long iGrip,long iDim,const AcDbEntity*pEnt) { return Acad::eNotImplementedYet; } Acad::ErrorStatus AEntityBase::DimToEntity(long iGrip,long iDim,double newValue,const AcGeVector3d& offset) { return Acad::eNotImplementedYet; } AcGePoint3d AEntityBase::GetGripPoint(long iGrip)const { AcGePoint3dArray points; AcDbIntArray osnapModes,geomIds; GetMe()->getGripPoints(points,osnapModes,geomIds); return points[iGrip]; } Acad::ErrorStatus AEntityBase::GetGripPoints(AcDbGripDataPtrArray& grips, const double curViewUnitSize, const int gripSize, const AcGeVector3d& curViewDir, const int bitflags) const { AEntityBase* pThis = (AEntityBase*)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 AEntityBase::MoveGripPointsAt(const AcDbVoidPtrArray& appData, const AcGeVector3d& offset, const int bitflags) { if (appData.isEmpty()) { return Acad::eInvalidInput; } AecDbGrip* pGrip=(AecDbGrip*)appData[0]; AEntityBase *pOwner=pGrip->Owner(); if (pOwner == NULL) { return Acad::eInvalidInput; } AcDbIntArray indice; for (long i = 0; i < appData.length(); i++) { indice.append(((AecDbGrip*)appData[i])->Index()); } Acad::ErrorStatus es = GetMe()->moveGripPointsAt(indice,offset); //模拟锁定 for (int i = 0; i < pGrip->GetDimNum(); i++) { AecDbGripDim *pDim = pGrip->GetDim(i); if (pDim->IsLocked()) { DimToEntity(pGrip->Index(), i, pDim->GetLockValue(), AcGeVector3d(0,0,0)); } } if (es == Acad::eOk) { for (int i = 0; i < indice.length(); i++) { pOwner->UpdateDim(indice[i],GetMe()); } } return es; } #endif // ADS > 15 bool AEntityBase::UnifyElevation(double dElevation) { return true; } /* // 由系统的显示模式和构件的显示类型确定显示方式 0--NONE; 1--2D; 2--3D; 3--2D&3D; int AEntityBase::GetDispMethod(int nDrawMode, int nDrawType) const { return nDrawMode; int nDraw = 0; //0--NONE; 1--2D; 2--3D; 3--2D&3D; if (nDrawMode == DRAW_2D && (nDrawType == AEntityBase::k2DOnly || nDrawType == AEntityBase::k2Dand3D)) { nDraw = 1; } else if (nDrawMode == DRAW_3D && (nDrawType == AEntityBase::k3DOnly || nDrawType == AEntityBase::k2Dand3D)) { nDraw = 2; } else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == AEntityBase::k2Dand3D) { nDraw=3; } else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == AEntityBase::k2DOnly) { nDraw = 1; } else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == AEntityBase::k3DOnly) { nDraw = 2; } return nDraw; } */