diff --git a/SourceCode/Code2026/AecRxBase/AecDbCurveBase.cpp b/SourceCode/Code2026/AecRxBase/AecDbCurveBase.cpp index 9042794..0c433e8 100644 --- a/SourceCode/Code2026/AecRxBase/AecDbCurveBase.cpp +++ b/SourceCode/Code2026/AecRxBase/AecDbCurveBase.cpp @@ -1,3250 +1,1205 @@ -#include "stdafx.h" -#include -#include "AecDbCurveBase.h" -#include "AcGiViewDraw.h" -#include "AcGiExplodeDraw.h" -#include "simpleproperty.h" -#include "dbobjptr.h" -#include "AecDbObjXDataMap.h" -#include "AecDbEntityBase.h" -#include "dbgrip.h" -#include "AecGripCback.h" -#include "GrPolyhedronGeometry.h" - -using namespace GrPolyhedronGeometry; - -static const Adesk::UInt16 kRed = 1; - -BOOL ReadModelXData(LPCTSTR pszKey, AecDbObjXDataMap& xDataMap, AcDbDatabase* pDb); -BOOL WriteModelXData(LPCTSTR pszKey, AecDbObjXDataMap& xDataMap, AcDbDatabase* pDb); -extern CString IDCreate(); - -const Adesk::UInt16 kColorByLayer = 256; - -#ifndef _ttof -#define _ttof(pszVal) _tcstod((pszVal), NULL) -#endif - -ACRX_NO_CONS_DEFINE_MEMBERS(AecDbCurveBase, AcDbCurve); - -namespace -{ - void FreeBuffer(int n, AcDbVoidPtrArray& arEntPtrs) - { - AcDbEntity* pEnt = NULL; - while (arEntPtrs.length() > n) - { - pEnt = (AcDbEntity*)arEntPtrs.last(); - pEnt->erase(); - pEnt->close(); - DELETE_PTR(pEnt); - arEntPtrs.removeLast(); - } - } - -} - -AecDbCurveBase::AecDbCurveBase(void) -{ - m_eExplodeOrDrawType = kWroldDraw; - m_nDrawDimCur = -1; -} - -AecDbCurveBase::~AecDbCurveBase(void) -{ - FreeBuffer(0, m_ar2DDrableBufPtrs_); - FreeBuffer(0, m_ar3DDrableBufPtrs_); -} - -static void ReleaseEntSet(AcDbVoidPtrArray &entSet) -{ - while(!entSet.isEmpty()) - { - AcDbEntity *pEnt = AcDbEntity::cast((AcDbEntity *)entSet[0]); - if (pEnt != NULL) - { - DELETE_PTR(pEnt); - } - entSet.removeAt(0); - } -} - -Adesk::UInt32 AecDbCurveBase::subViewportDrawLogicalFlags(AcGiViewportDraw * vd) -{ - Adesk::UInt32 nRet = AcDbCurve::subViewportDrawLogicalFlags(vd); - - Adesk::UInt32 nFlagNew = nRet; - int nDrawMode = GetDrawMode(); - DrawModeType nDrawType = k2Dand3D; - int nDraw = GetDrawDimOnType(nDrawMode, nDrawType); - - if (nDraw != 3) - { - nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw; - } - else - { - nFlagNew |= kDrawableRegenDraw;//256 - } - return nFlagNew; -} - -Adesk::UInt32 AecDbCurveBase::subSetAttributes(AcGiDrawableTraits * traits) -{ - Adesk::UInt32 nRet = AcDbCurve::subSetAttributes(traits); - int nDrawMode = GetDrawMode(); - DrawModeType nDrawType = k2Dand3D; - int nDraw = GetDrawDimOnType(nDrawMode, nDrawType); - - Adesk::UInt32 nFlagNew = nRet; - nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw; - - return nFlagNew; -} - -Adesk::Boolean AecDbCurveBase::subWorldDraw(AcGiWorldDraw *pWd) -{ - assertReadEnabled(); - - m_eExplodeOrDrawType = kWroldDraw; - AcGiViewDraw dc(pWd, NULL); - dc.SetDrawRaw(this); - - //1.如果是保存代理图形 - AcGiRegenType nRegenType = pWd->regenType(); - if (nRegenType == kAcGiSaveWorldDrawForProxy) - { - ads_point pt; - struct resbuf rb; - acedGetVar(_T("VIEWDIR"),&rb); - ads_point_set(rb.resval.rpoint,pt); - - ads_point viewDir; - acdbUcs2Wcs(pt,viewDir,false); - - if (fabs(viewDir[X]) > 1.0e-6 || fabs(viewDir[Y]) > 1.0e-6) - { - Draw3d(dc); - m_nDrawDimCur = 3; - } - else - { - Draw2d(dc); - m_nDrawDimCur = 2; - } - return Adesk::kTrue; - } - - //设属性 - dc.SetLayer(_T("0")); - dc.SetColor(256); - - //如果图层关闭 - AcDbLayerTableRecordPointer pLayer; - if ( Acad::eOk == pLayer.open(layerId(), AcDb::kForRead) ) - { - if ( pLayer->isOff() ) - { - return Adesk::kTrue; - } - } - - int nDrawMode = GetDrawMode(); - DrawModeType nDrawType = k2Dand3D; - int nDraw = GetDrawDimOnType(nDrawMode, nDrawType); - - if (nRegenType == kAcGiSaveWorldDrawForProxy - || nRegenType == kAcGiSaveWorldDrawForR12) - { - if (!!ownerId()) - { - pWd->subEntityTraits().setSelectionMarker(0); - dc.SetColor(colorIndex()); - dc.SetLayer(layerId()); - } - - if ((nDrawMode & DRAW_2D) && (nDrawType != k3DOnly)) - { - Draw2d(dc); - m_nDrawDimCur = 2; - } - else if ((nDrawMode & DRAW_3D) && (nDrawType != k2DOnly)) - { - Draw3d(dc); - m_nDrawDimCur = 3; - } - return Adesk::kTrue; - } - return Adesk::kFalse; -} - -void AecDbCurveBase::subViewportDraw(AcGiViewportDraw* pMode) -{ - assertReadEnabled(); - - 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(); - AcGiViewDraw dc(NULL, pMode); - dc.SetDrawRaw(this); - - // 设属性 - dc.SetLayer(_T("0")); - dc.SetColor(256); - - //如果图层关闭 - AcDbLayerTableRecordPointer pLayer; - if ( Acad::eOk == pLayer.open(layerId(), AcDb::kForRead) ) - { - if ( pLayer->isOff() ) - { - return ; - } - } - - if (!!ownerId()) - { - pMode->subEntityTraits().setSelectionMarker(0); - dc.SetColor(colorIndex()); - dc.SetLayer(layerId()); - } - - int nDrawMode = GetDrawMode(); - DrawModeType nDrawType = k2Dand3D; - int nDraw = GetDrawDimOnType(nDrawMode, nDrawType); - - if (nDraw == 3) - { - if ( nRegenType == kAcGiRenderCommand - || nRegenType == kAcGiHideOrShadeCommand - || vp.isPerspective() - || vtViewDrt != AcGeVector3d(0,0,1)) - { - Draw3d(dc); - m_nDrawDimCur = 3; - } - else - { - Draw2d(dc); - m_nDrawDimCur = 2; - } - } - else if (nDraw == 1) - { - Draw2d(dc); - m_nDrawDimCur = 2; - } - else if (nDraw == 2) - { - Draw3d(dc); - m_nDrawDimCur = 3; - } -} - -//保存代理实体图元 -void AecDbCurveBase::saveAs(AcGiWorldDraw *pWd,AcDb::SaveType saveType) -{ - AecDbObjXDataMap xDataMap; - ReadModelXData(EW_EARTHWORMINIT, xDataMap, NULL); - int nSaveToProxy(0); - xDataMap.GetAt(_T("SaveToProxy"), nSaveToProxy); - if (nSaveToProxy == 0) // 不保存代理图形 - return; - - AcGiRegenType rtype = pWd->regenType(); - if (rtype == kAcGiSaveWorldDrawForProxy) - { - subWorldDraw(pWd); - } - else - { - AcDbCurve::saveAs(pWd, saveType); - } -} - -Acad::ErrorStatus AecDbCurveBase::subExplode(AcDbVoidPtrArray& entitySet) const -{ - ExplodeOrDrawType& eExplodeType = (ExplodeOrDrawType&)m_eExplodeOrDrawType; - eExplodeType = kExplode; - - int expMode = GetExplodeMode(); - if (expMode == 1) - { - GetDraw2dables(0,entitySet); - } - else if (expMode == 2) - { - GetDraw3dables(entitySet); - } - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::subGetGeomExtents(AcDbExtents& extents) const -{ - AcGePoint3d ptLow, ptUp; - - AcDbVoidPtrArray entSet; - - int expMode = GetExplodeMode(); - if (expMode == 1) - { - entSet.append(Get2DBuffer()); - } - else if (expMode == 2) - { - entSet.append(Get3DBuffer()); - } - - BOOL bInit = TRUE; - AcGePoint3d ptMax,ptMin; - AcDbExtents ext,extT; - - int len = entSet.length(); - for (int i = 0; i < len; i++) - { - AcDbEntity *pEnt = (AcDbEntity *)entSet[i]; - - if (pEnt->getGeomExtents(extT) == Acad::eOk) - { - ext.addExt(extT); - } - } - ptLow = ext.minPoint(); - ptUp = ext.maxPoint(); - - extents.set(ptLow, ptUp); - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::subGet3dGeomExtents(AcDbExtents &extents) const -{ - AcDbVoidPtrArray entSet; - if (!Has3DBuffer()) - { - AcGiViewDraw dc(NULL, NULL); - Draw3d(dc); - } - entSet.append(Get3DBuffer()); - - if (entSet.isEmpty()) - return Acad::eNullExtents; - - BOOL bInit = TRUE; - AcGePoint3d ptMax, ptMin; - AcDbExtents ext, extT; - - int len = entSet.length(); - for (int i = 0; i < len; i++) - { - AcDbEntity *pEnt = (AcDbEntity *)entSet[i]; - - if (pEnt->getGeomExtents(extT) == Acad::eOk) - { - ext.addExt(extT); - } - } - - AcGePoint3d ptLow, ptUp; - ptLow = ext.minPoint(); - ptUp = ext.maxPoint(); - extents.set(ptLow, ptUp); - - return Acad::eOk; -} - -void AecDbCurveBase::subList() const -{ - AcDbCurve::subList(); -} - -Acad::ErrorStatus AecDbCurveBase::setColorIndex(Adesk::UInt16 color,Adesk::Boolean doSubents/* = true*/) -{ - assertWriteEnabled(); - AecDbObjXDataMap* pMap = GetSpecialtyData(); - if (pMap != NULL) - { - int nCr = 0; - if (pMap->GetAt(_T("COLOR"),nCr)) - { - pMap->SetAt(_T("COLOR"),color); - } - } - return AcDbCurve::setColorIndex(color,doSubents); -} - -Acad::ErrorStatus AecDbCurveBase::subIntersectWith(const AcDbEntity* ent, - AcDb::Intersect intType, - AcGePoint3dArray& points, - INT_PTR thisGsMarker, - INT_PTR otherGsMarker) const -{ - assertReadEnabled(); - - Acad::ErrorStatus es; - AcDbCurve* pNaCrv = GetNativeCurve(); - if (pNaCrv != NULL) - { - //放开后很慢 - es = pNaCrv->intersectWith(ent,intType,points,thisGsMarker,otherGsMarker); - } - - //EXTEND 仅仅需要 m_pBaseCurve 求交 - struct resbuf rb; - acedGetVar(_T("CMDNAMES"),&rb); - if (_tcscmp(rb.resval.rstring,_T("EXTEND")) != 0) - { - int expMode = GetExplodeMode(); - if (expMode == 2) - { - return Acad::eNotImplementedYet; - } - - const AcDbVoidPtrArray& entSet = Get2DBuffer(); - es = Acad::eNotApplicable; - - int len = entSet.length(); - for(int i = 0; i < len; i++) - { - AcDbEntity *pEnt = (AcDbEntity *)entSet[i]; - if (pEnt != NULL && Acad::eOk == pEnt->intersectWith(ent, intType, points, 0, otherGsMarker) ) - { - es = Acad::eOk; - } - } - } - return es; -} - -Acad::ErrorStatus AecDbCurveBase::subIntersectWith(const AcDbEntity* ent, - AcDb::Intersect intType, - const AcGePlane& projPlane, - AcGePoint3dArray& points, - INT_PTR thisGsMarker, - INT_PTR otherGsMarker) const -{ - assertReadEnabled(); - - Acad::ErrorStatus es; - AcDbCurve* pNaCrv = GetNativeCurve(); - if (pNaCrv != NULL) - { - //放开后很慢 - es = pNaCrv->intersectWith(ent,intType,points,thisGsMarker,otherGsMarker); - } - - int expMode = GetExplodeMode(); - if (expMode == 2) - { - return Acad::eNotImplementedYet; - } - - //EXTEND 仅仅需要 m_pBaseCurve 求交 - struct resbuf rb; - acedGetVar(_T("CMDNAMES"),&rb); - if (_tcscmp(rb.resval.rstring,_T("EXTEND")) != 0) - { - const AcDbVoidPtrArray& entSet = Get2DBuffer(); - es = Acad::eNotApplicable; - - int len = entSet.length(); - for (int i = 0; i < len; i++) - { - AcDbEntity *pEnt = (AcDbEntity *)entSet[i]; - if (pEnt != NULL && Acad::eOk == pEnt->intersectWith(ent, intType, projPlane, points, 0, otherGsMarker) ) - { - es = Acad::eOk; - } - } - } - return es; -} - -Acad::ErrorStatus AecDbCurveBase::subSetPropertiesFrom( const AcDbEntity* pEntity, Adesk::Boolean doSubents/* = Adesk::kTrue*/) -{ - assertWriteEnabled(); - Acad::ErrorStatus es = AcDbCurve::setPropertiesFrom(pEntity, doSubents); - - // 颜色 - { - setColorIndex(pEntity->colorIndex()); - } - - //图层 - if (database() == NULL || - database() == pEntity->database()) - { - { - setLayer(layerId()); - } - - // 线型 - { - setLinetype(pEntity->linetypeId()); - } - -#if ARX > 16 - // 材质 - { - setMaterial(pEntity->materialId()); - } -#endif - } - - // 线型比例 - { - setLinetypeScale(pEntity->linetypeScale()); - } - - // 可见性. 总是被复制 - setVisibility(pEntity->visibility()); - - return es; -} - -#if (ARX > 15) -Acad::ErrorStatus AecDbCurveBase::subGetOsnapPoints( AcDb::OsnapMode osnapMode, - INT_PTR gsSelectionMark, - const AcGePoint3d& ptPick, - const AcGePoint3d& lastPoint, - const AcGeMatrix3d& viewXform, - AcGePoint3dArray& snapPoints, - AcDbIntArray& geomIds) const -{ - assertReadEnabled(); - - AcDbVoidPtrArray entSet; - int expMode = GetExplodeMode(); - if (expMode == 1) - { - entSet.append(Get2DBuffer()); - } - else if (expMode == 2) - { - entSet.append(Get3DBuffer()); - } - - Acad::ErrorStatus es = Acad::eOk; - 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; - } - return es; -} - -Acad::ErrorStatus AecDbCurveBase::subGetOsnapPoints( AcDb::OsnapMode osnapMode, - INT_PTR gsSelectionMark, - const AcGePoint3d& ptPick, - const AcGePoint3d& lastPoint, - const AcGeMatrix3d& viewXform, - AcGePoint3dArray& snapPoints, - AcDbIntArray& geomIds, - const AcGeMatrix3d& insersionMat) const -{ - assertReadEnabled(); - return getOsnapPoints(osnapMode,gsSelectionMark,ptPick,lastPoint,viewXform,snapPoints,geomIds); -} -#endif - -#if ARX>15 -void AecDbCurveBase::subGripStatus(const AcDb::GripStat status) -{ - -} - -Acad::ErrorStatus AecDbCurveBase::subGetGripPoints ( AcDbGripDataPtrArray& grips, - const double curViewUnitSize, - const int gripSize, - const AcGeVector3d& curViewDir, - const int bitflags) const -{ - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::subMoveGripPointsAt(const AcDbVoidPtrArray& appData,const AcGeVector3d& offset,const int bitflags) -{ - return Acad::eOk; -} -#endif - -Acad::ErrorStatus AecDbCurveBase::subGetGripPoints (AcGePoint3dArray& gripPoints,AcDbIntArray& osnapModes,AcDbIntArray& geomIds) const -{ - assertReadEnabled(); - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::subMoveGripPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset) -{ - assertWriteEnabled(); - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::subGetStretchPoints(AcGePoint3dArray& stretchPoints) const -{ - assertReadEnabled(); - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::subMoveStretchPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset) -{ - assertWriteEnabled(); - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::subTransformBy(const AcGeMatrix3d& xform) -{ - assertWriteEnabled(); - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::subGetTransformedCopy(const AcGeMatrix3d& xform,AcDbEntity*& pEnt) const -{ - assertReadEnabled(); - AcDbEntity *pCloned = (AcDbEntity *)clone(); - pCloned->setLayer(layerId());// - ((AecDbCurveBase*)pCloned)->m_nDrawDimCur = m_nDrawDimCur; - - Acad::ErrorStatus es = pCloned->transformBy(xform); - if(es == Acad::eOk) - pEnt = pCloned; - else - DELETE_PTR(pCloned); - return es; -} - -Acad::ErrorStatus AecDbCurveBase::subDeepClone( AcDbObject* pOwner, - AcDbObject*& pClonedObject, - AcDbIdMapping& idMap, - Adesk::Boolean isPrimary) const -{ - // You should always pass back pClonedObject == NULL - // if, for any reason, you do not actually clone it - // during this call. The caller should pass it in - // as NULL, but to be safe, we set it here as well. - // - pClonedObject = NULL; - - // If this object is in the idMap and is already - // cloned, then return. - // - bool isPrim = false; - if (isPrimary) - isPrim = true; - AcDbIdPair idPair(objectId(), (AcDbObjectId)NULL, - false, isPrim); - if (idMap.compute(idPair) && (idPair.value() != NULL)) - return Acad::eOk; - - // Create the clone - // - AecDbCurveBase *pClone = (AecDbCurveBase*)isA()->create(); - if (pClone != NULL) - pClonedObject = pClone; // set the return value - else - return Acad::eOutOfMemory; - - AcDbDeepCloneFiler filer; - dwgOut(&filer); - - filer.seek(0L, AcDb::kSeekFromStart); - pClone->dwgIn(&filer); - pClone->NewGUID(); - pClone->setLayer(layerId()); - - bool bOwnerXlated = false; - if (isPrimary) - { - AcDbBlockTableRecord *pBTR = - AcDbBlockTableRecord::cast(pOwner); - if (pBTR != NULL) - { - pBTR->appendAcDbEntity(pClone); - bOwnerXlated = true; - } - else - { - pOwner->database()->addAcDbObject(pClone); - } - } else { - pOwner->database()->addAcDbObject(pClone); - pClone->setOwnerId(pOwner->objectId()); - bOwnerXlated = true; - } - - // This must be called for all newly created objects - // in deepClone. It is turned off by endDeepClone() - // after it has translated the references to their - // new values. - // - pClone->setAcDbObjectIdsInFlux(); - pClone->disableUndoRecording(true); - - // Add the new information to the idMap. We can use - // the idPair started above. - // - idPair.setValue(pClonedObject->objectId()); - idPair.setIsCloned(Adesk::kTrue); - idPair.setIsOwnerXlated(bOwnerXlated); - idMap.assign(idPair); - - // Using the filer list created above, find and clone - // any owned objects. - // - - AcDbObjectId id; - while (filer.getNextOwnedObject(id)) { - - AcDbObject *pSubObject; - AcDbObject *pClonedSubObject; - - // Some object's references may be set to NULL, - // so don't try to clone them. - // - if (id == NULL) - continue; - - // Open the object and clone it. Note that we now - // set "isPrimary" to kFalse here because the object - // is being cloned, not as part of the primary set, - // but because it is owned by something in the - // primary set. - // - acdbOpenAcDbObject(pSubObject, id, AcDb::kForRead); - pClonedSubObject = NULL; - pSubObject->deepClone(pClonedObject, - pClonedSubObject, - idMap, Adesk::kFalse); - - // If this is a kDcInsert context, the objects - // may be "cheapCloned". In this case, they are - // "moved" instead of cloned. The result is that - // pSubObject and pClonedSubObject will point to - // the same object. So, we only want to close - // pSubObject if it really is a different object - // than its clone. - // - if (pSubObject != pClonedSubObject) - pSubObject->close(); - - // The pSubObject may either already have been - // cloned, or for some reason has chosen not to be - // cloned. In that case, the returned pointer will - // be NULL. Otherwise, since we have no immediate - // use for it now, we can close the clone. - // - if (pClonedSubObject != NULL) - pClonedSubObject->close(); - } - - //xdataMap 复制 - //到mep中找建立新的关系 - AecDbObjXDataMap* pXDataMapCloned = pClone->GetSpecialtyData(); - AecDbObjXDataMap* pXDataMap = (AecDbObjXDataMap*)GetSpecialtyData(); - - if (pXDataMapCloned != NULL) pXDataMapCloned->CopyFrom(pXDataMap); - if (pXDataMap != NULL && pXDataMapCloned != NULL) - { - //发送提资需要相同的ID - Adesk::Int16 nVal = acdbCurDwg()->useri4(); - if (nVal != KEY_NOPROTECT) - { - int nVt = 0; - CString sID = IDCreate(); - if (pXDataMapCloned->HasKey(KEY_NO, nVt)) - { - pXDataMapCloned->SetAt(KEY_NO, sID); - } - } - - AecDbObjXDataMap::It it = pXDataMap->Begin(); - AecDbObjXDataMap::It end = pXDataMap->End(); - - CString sKey; - CStringArray arHandKeys; - - AecXData cVal; - memset(&cVal,0,sizeof(AecXData)); - - AcDbObjectId idSrc,idCloned; - for (; it != end; ) - { - if (!pXDataMap->GetNext(it, sKey, cVal)) break; - if (cVal.nVt == AecXData::kTypeSoftId || cVal.nVt == AecXData::kTypeHardId)//soft,hard - { - idSrc.setFromOldId(cVal.nVal); - - AcDbObject *pSubObject; - AcDbObject *pClonedSubObject; - - // Some object's references may be set to NULL, - // so don't try to clone them. - // - if (idSrc == NULL) - continue; - - AcDbIdPair idPair2(idSrc, (AcDbObjectId)NULL, - false, isPrim); - if (idMap.compute(idPair2) && (idPair2.value() != NULL)) - { - if (pXDataMapCloned != NULL) - { - pXDataMapCloned->RemoveAt(sKey); - pXDataMapCloned->SetAt(sKey,idPair2.value(),cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); - } - continue; - } - - // Open the object and clone it. Note that we now - // set "isPrimary" to kFalse here because the object - // is being cloned, not as part of the primary set, - // but because it is owned by something in the - // primary set. - // - pSubObject = NULL; - acdbOpenAcDbObject(pSubObject, idSrc, AcDb::kForRead); - pClonedSubObject = NULL; - - if (pSubObject != NULL) - { - //只考虑上华AEC的实体 - LPCTSTR pszDxf = pSubObject->isA()->dxfName(); - if (_tcsstr(pszDxf,_T("AEC_'")) != NULL) - { - pSubObject->deepClone(pClonedObject, - pClonedSubObject, - idMap, Adesk::kFalse); - } - else - { - pSubObject->close(); - pSubObject = NULL; - } - } - - // If this is a kDcInsert context, the objects - // may be "cheapCloned". In this case, they are - // "moved" instead of cloned. The result is that - // pSubObject and pClonedSubObject will point to - // the same object. So, we only want to close - // pSubObject if it really is a different object - // than its clone. - // - if (pSubObject != pClonedSubObject) - pSubObject->close(); - - // The pSubObject may either already have been - // cloned, or for some reason has chosen not to be - // cloned. In that case, the returned pointer will - // be NULL. Otherwise, since we have no immediate - // use for it now, we can close the clone. - // - if (pClonedSubObject != NULL) - idCloned = pClonedSubObject->objectId(); - - if (pClonedSubObject != NULL) - pClonedSubObject->close(); - - if (pXDataMapCloned != NULL) - { - if (idCloned.isValid()) - { - pXDataMapCloned->RemoveAt(sKey); - pXDataMapCloned->SetAt(sKey, idCloned, cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); - } - else - { - - } - } - } - else if (sKey.Find(_T("$H")) != -1 && cVal.nVt == AecXData::kTypeString)//可能的实体句柄 - { - arHandKeys.Add(sKey); - } - } - - //2022-05-04 需要测试 - CString sHand; - AcDbHandle hd; - for(int n = 0;n < arHandKeys.GetSize();n++) - { - sKey = arHandKeys.GetAt(n); - sHand = sKey; - sHand.TrimRight(_T("$H")); - - AcDbHandle handle(sHand); - - AcDbObjectId idSrc; - if ( Acad::eOk == acdbCurDwg()->getAcDbObjectId(idSrc,false,handle) ) - { - AcDbObject *pSubObject; - AcDbObject *pClonedSubObject; - - // Some object's references may be set to NULL, - // so don't try to clone them. - // - if (idSrc == NULL) - continue; - - AcDbIdPair idPair2(idSrc, (AcDbObjectId)NULL, - false, isPrim); - if (idMap.compute(idPair2) && (idPair2.value() != NULL)) - { - CString sKeyNew; - //sKey.Format(_T("%s$H"),szHand); - - if (pXDataMapCloned != NULL) - { - TCHAR szHand[19]; - memset(szHand,0,sizeof(szHand) ); - idPair2.value().handle().getIntoAsciiBuffer(szHand); - sKeyNew.Format(_T("%s$H"),szHand); - - pXDataMapCloned->RemoveAt(sKey); - pXDataMapCloned->SetAt(sKeyNew,szHand); - } - continue; - } - - // Open the object and clone it. Note that we now - // set "isPrimary" to kFalse here because the object - // is being cloned, not as part of the primary set, - // but because it is owned by something in the - // primary set. - // - pSubObject = NULL; - acdbOpenAcDbObject(pSubObject, idSrc, AcDb::kForRead); - pClonedSubObject = NULL; - - if (pSubObject != NULL) - { - //只考虑上华AEC的实体 - LPCTSTR pszDxf = pSubObject->isA()->dxfName(); - if (_tcsstr(pszDxf,_T("AEC_'")) != NULL) - { - pSubObject->deepClone(pClonedObject, - pClonedSubObject, - idMap, Adesk::kFalse); - } - else - { - pSubObject->close(); - pSubObject = NULL; - } - } - - // If this is a kDcInsert context, the objects - // may be "cheapCloned". In this case, they are - // "moved" instead of cloned. The result is that - // pSubObject and pClonedSubObject will point to - // the same object. So, we only want to close - // pSubObject if it really is a different object - // than its clone. - // - if (pSubObject != pClonedSubObject) - pSubObject->close(); - - // The pSubObject may either already have been - // cloned, or for some reason has chosen not to be - // cloned. In that case, the returned pointer will - // be NULL. Otherwise, since we have no immediate - // use for it now, we can close the clone. - // - if (pClonedSubObject != NULL) - idCloned = pClonedSubObject->objectId(); - - if (pClonedSubObject != NULL) - pClonedSubObject->close(); - - if (pXDataMapCloned != NULL) - { - CString sKeyNew; - TCHAR szHand[19]; - memset(szHand,0,sizeof(szHand) ); - - idCloned.handle().getIntoAsciiBuffer(szHand); - sKeyNew.Format(_T("%s$H"),szHand); - - pXDataMapCloned->RemoveAt(sKey); - pXDataMapCloned->SetAt(sKeyNew,szHand); - } - } - } - } - - // Leave pClonedObject open for the caller - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::subWblockClone(AcRxObject* pOwner, - AcDbObject*& pClonedObject, - AcDbIdMapping& idMap, - Adesk::Boolean isPrimary) const -{ - // You should always pass back pClonedObject == NULL - // if, for any reason, you do not actually clone it - // during this call. The caller should pass it in - // as NULL, but to be safe, we set it here as well. - // - pClonedObject = NULL; - - // If this is a fast wblock operation then no cloning - // should take place, so we simply call the base class's - // wblockClone() and return whatever it returns. - // - // For fast wblock, the source and destination databases - // are the same, so we can use that as the test to see - // if a fast wblock is in progress. - // - AcDbDatabase *pDest, *pOrig; - idMap.destDb(pDest); - idMap.origDb(pOrig); - if (pDest == pOrig) - return AcDbCurve::subWblockClone(pOwner, pClonedObject, - idMap, isPrimary); - - // If this is an Xref bind operation and this AsdkPoly - // entity is in Paper Space, then we don't want to - // clone because Xref bind doesn't support cloning - // entities in Paper Space. So we simply return - // Acad::eOk - // - AcDbObjectId pspace; - AcDbBlockTable *pTable; - database()->getSymbolTable(pTable, AcDb::kForRead); - pTable->getAt(ACDB_PAPER_SPACE, pspace); - pTable->close(); - - if ( idMap.deepCloneContext() == AcDb::kDcXrefBind - && ownerId() == pspace) - return Acad::eOk; - - // If this object is in the idMap and is already - // cloned, then return. - // - bool isPrim = false; - if (isPrimary) - isPrim = true; - - AcDbIdPair idPair(objectId(), (AcDbObjectId)NULL, - false, isPrim); - if (idMap.compute(idPair) && (idPair.value() != NULL)) - return Acad::eOk; - - // The owner object can be either an AcDbObject, or an - // AcDbDatabase. AcDbDatabase is used if the caller is - // not the owner of the object being cloned (because it - // is being cloned as part of an AcDbHardPointerId - // reference). In this case, the correct ownership - // will be set during reference translation. So, if - // the owner is an AcDbDatabase, then pOwn will be left - // NULL here, and is used as a "flag" later. - // - - AcDbObject *pOwn = AcDbObject::cast(pOwner); - AcDbDatabase *pDb = AcDbDatabase::cast(pOwner); - if (pDb == NULL) - pDb = pOwn->database(); - - // STEP 1: - // Create the clone - // - AecDbCurveBase *pClone = (AecDbCurveBase*)isA()->create(); - if (pClone != NULL) - pClonedObject = pClone; // set the return value - else - return Acad::eOutOfMemory; - - // STEP 2: - // If the owner is an AcDbBlockTableRecord, go ahead - // and append the clone. If not, but we know who the - // owner is, set the clone's ownerId to it. Otherwise, - // we set the clone's ownerId to our own ownerId (in - // other words, the original owner Id). This Id will - // then be used later, in reference translation, as - // a key to finding who the new owner should be. This - // means that the original owner must also be cloned at - // some point during the wblock operation. - // EndDeepClone's reference translation aborts if the - // owner is not found in the idMap. - // - // The most common situation where this happens is - // AcDbEntity references to Symbol Table Records, such - // as the Layer an Entity is on. This is when you will - // have to pass in the destination database as the owner - // of the Layer Table Record. Since all Symbol Tables - // are always cloned in Wblock, you do not need to make - // sure that Symbol Table Record owners are cloned. - // - // However, if the owner is one of your own classes, - // then it is up to you to make sure that it gets - // cloned. This is probably easiest to do at the end - // of this function. Otherwise you may have problems - // with recursion when the owner, in turn, attempts - // to clone this object as one of its subObjects. - // - AcDbBlockTableRecord *pBTR = NULL; - if (pOwn != NULL) - pBTR = AcDbBlockTableRecord::cast(pOwn); - if (pBTR != NULL && isPrimary) { - pBTR->appendAcDbEntity(pClone); - } else { - pDb->addAcDbObject(pClonedObject); - } - - // STEP 3: - // The AcDbWblockCloneFiler makes a list of - // AcDbHardOwnershipIds and AcDbHardPointerIds. These - // are the references which must be cloned during a - // Wblock operation. - // - AcDbWblockCloneFiler filer; - dwgOut(&filer); - - // STEP 4: - // Rewind the filer and read the data into the clone. - // - filer.seek(0L, AcDb::kSeekFromStart); - pClone->dwgIn(&filer); - pClone->NewGUID(); - - idMap.assign(AcDbIdPair(objectId(), pClonedObject->objectId(), Adesk::kTrue, - isPrim, (Adesk::Boolean)(pOwn != NULL) )); - - pClonedObject->setOwnerId((pOwn != NULL) ? - pOwn->objectId() : ownerId()); - - // STEP 5: - // This must be called for all newly created objects - // in wblockClone. It is turned off by endDeepClone() - // after it has translated the references to their - // new values. - // - pClone->setAcDbObjectIdsInFlux(); - - // STEP 6: - // Add the new information to the idMap. We can use - // the idPair started above. We must also let the - // idMap entry know whether the clone's owner is - // correct, or needs to be translated later. - // - - // STEP 7: - // Using the filer list created above, find and clone - // any hard references. - // - - AcDbObjectId id; - while (filer.getNextHardObject(id)) - { - AcDbObject *pSubObject; - AcDbObject *pClonedSubObject; - - // Some object's references may be set to NULL, - // so don't try to clone them. - // - if (id == NULL) - continue; - - // If the referenced object is from a different - // database, such as an xref, do not clone it. - // - acdbOpenAcDbObject(pSubObject, id, AcDb::kForRead); - if (pSubObject->database() != database()) { - pSubObject->close(); - continue; - } - - // We can find out if this is an AcDbHardPointerId - // verses an AcDbHardOwnershipId, by seeing if we - // are the owner of the pSubObject. If we are not, - // then we cannot pass our clone in as the owner - // for the pSubObject's clone. In that case, we - // pass in our clone's database (the destination - // database). - // - // Note that we now set "isPrimary" to kFalse here - // because the object is being cloned, not as part - // of the primary set, but because it is owned by - // something in the primary set. - // - pClonedSubObject = NULL; - if (pSubObject->ownerId() == objectId()) { - pSubObject->wblockClone(pClone, - pClonedSubObject, - idMap, Adesk::kFalse); - } else { - pSubObject->wblockClone(pClone->database(), - pClonedSubObject, - idMap, Adesk::kFalse); - } - pSubObject->close(); - - // The pSubObject may either already have been - // cloned, or for some reason has chosen not to be - // cloned. In that case, the returned pointer will - // be NULL. Otherwise, since we have no immediate - // use for it now, we can close the clone. - // - if (pClonedSubObject != NULL) - pClonedSubObject->close(); - } - - //xdataMap 复制 - //到mep中找建立新的关系 - AecDbObjXDataMap* pXDataMapCloned = pClone->GetSpecialtyData(); - AecDbObjXDataMap* pXDataMap = (AecDbObjXDataMap*)GetSpecialtyData(); - - if (pXDataMap != NULL && pXDataMapCloned != NULL) - { - //发送提资需要相同的ID - Adesk::Int16 nVal = acdbCurDwg()->useri4(); - if (nVal != KEY_NOPROTECT) - { - int nVt = 0; - CString sID = IDCreate(); - if (pXDataMapCloned->HasKey(KEY_NO, nVt)) - { - pXDataMapCloned->SetAt(KEY_NO, sID); - } - } - - AecDbObjXDataMap::It it = pXDataMap->Begin(); - AecDbObjXDataMap::It end = pXDataMap->End(); - - CString sKey; - CStringArray arHandKeys; - - AecXData cVal; - memset(&cVal,0,sizeof(AecXData)); - - AcDbObjectId idSrc,idCloned; - for (; it != end;) - { - if (!pXDataMap->GetNext(it, sKey, cVal)) break; - if (cVal.nVt == AecXData::kTypeSoftId || cVal.nVt == AecXData::kTypeHardId)//soft,hard - { - idSrc.setFromOldId(cVal.nVal); - - AcDbObject *pSubObject; - AcDbObject *pClonedSubObject; - - // Some object's references may be set to NULL, - // so don't try to clone them. - // - if (idSrc == NULL) - continue; - - AcDbIdPair idPair2(idSrc, (AcDbObjectId)NULL, - false, isPrim); - if (idMap.compute(idPair2) && (idPair2.value() != NULL)) - { - if (pXDataMapCloned != NULL) - { - pXDataMapCloned->SetAt(sKey,idPair2.value(),cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); - } - continue; - } - - // Open the object and clone it. Note that we now - // set "isPrimary" to kFalse here because the object - // is being cloned, not as part of the primary set, - // but because it is owned by something in the - // primary set. - // - acdbOpenAcDbObject(pSubObject, idSrc, AcDb::kForRead); - pClonedSubObject = NULL; - - if (pSubObject->ownerId() == objectId()) { - pSubObject->wblockClone(pClone, - pClonedSubObject, - idMap, Adesk::kFalse); - } else { - pSubObject->wblockClone(pClone->database(), - pClonedSubObject, - idMap, Adesk::kFalse); - } - - // If this is a kDcInsert context, the objects - // may be "cheapCloned". In this case, they are - // "moved" instead of cloned. The result is that - // pSubObject and pClonedSubObject will point to - // the same object. So, we only want to close - // pSubObject if it really is a different object - // than its clone. - // - if (pSubObject != pClonedSubObject) - pSubObject->close(); - - // The pSubObject may either already have been - // cloned, or for some reason has chosen not to be - // cloned. In that case, the returned pointer will - // be NULL. Otherwise, since we have no immediate - // use for it now, we can close the clone. - // - idCloned = pClonedSubObject->objectId(); - - if (pClonedSubObject != NULL) - pClonedSubObject->close(); - - if (pXDataMapCloned != NULL) - { - pXDataMapCloned->RemoveAt(sKey); - pXDataMapCloned->SetAt(sKey,idCloned,cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); - } - } - else if (sKey.Find(_T("$H")) != -1 && cVal.nVt == AecXData::kTypeString)//可能的实体句柄 - { - arHandKeys.Add(sKey); - } - } - } - return Acad::eOk; -} - -Adesk::Boolean AecDbCurveBase::isClosed() const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Adesk::Boolean bRet = pCurve->isClosed(); - return bRet; - } - else - { - return AcDbCurve::isClosed(); - } -} - -Adesk::Boolean AecDbCurveBase::isPeriodic() const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Adesk::Boolean bRet = pCurve->isPeriodic(); - return bRet; - } - else - { - return AcDbCurve::isPeriodic(); - } -} - -Acad::ErrorStatus AecDbCurveBase::getStartParam(double&pa) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getStartParam(pa); - return bRet; - } - else - { - return AcDbCurve::getStartParam(pa); - } -} - -Acad::ErrorStatus AecDbCurveBase::getEndParam (double&pa) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getEndParam(pa); - return bRet; - } - else - { - return AcDbCurve::getEndParam(pa); - } -} - -Acad::ErrorStatus AecDbCurveBase::getStartPoint(AcGePoint3d&pt) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getStartPoint(pt); - return bRet; - } - else - { - return AcDbCurve::getStartPoint(pt); - } -} - -Acad::ErrorStatus AecDbCurveBase::getEndPoint (AcGePoint3d&pt) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getEndPoint(pt); - return bRet; - } - else - { - return AcDbCurve::getEndPoint(pt); - } -} - -Acad::ErrorStatus AecDbCurveBase::getPointAtParam(double pa, AcGePoint3d&pt) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getPointAtParam(pa,pt); - return bRet; - } - else - { - return AcDbCurve::getPointAtParam(pa,pt); - } -} - -Acad::ErrorStatus AecDbCurveBase::getParamAtPoint(const AcGePoint3d& pt, double&pa)const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getParamAtPoint(pt,pa); - return bRet; - } - else - { - return AcDbCurve::getParamAtPoint(pt,pa); - } -} - -Acad::ErrorStatus AecDbCurveBase::getDistAtParam (double param, double& dist) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getDistAtParam(param,dist); - return bRet; - } - else - { - return AcDbCurve::getDistAtParam(param,dist); - } -} - -Acad::ErrorStatus AecDbCurveBase::getParamAtDist (double dist, double& param) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getParamAtDist(dist,param); - return bRet; - } - else - { - return AcDbCurve::getParamAtDist(dist,param); - } -} - -Acad::ErrorStatus AecDbCurveBase::getDistAtPoint (const AcGePoint3d&pt, double&dist)const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getDistAtPoint(pt,dist); - return bRet; - } - else - { - return AcDbCurve::getDistAtPoint(pt,dist); - } -} - -Acad::ErrorStatus AecDbCurveBase::getPointAtDist (double dist, AcGePoint3d&pt) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getPointAtDist(dist,pt); - return bRet; - } - else - { - return AcDbCurve::getPointAtDist(dist,pt); - } -} - -Acad::ErrorStatus AecDbCurveBase::getFirstDeriv (double param,AcGeVector3d& firstDeriv) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getFirstDeriv(param,firstDeriv); - return bRet; - } - else - { - return AcDbCurve::getFirstDeriv(param,firstDeriv); - } -} - -Acad::ErrorStatus AecDbCurveBase::getFirstDeriv (const AcGePoint3d&pt,AcGeVector3d& firstDeriv) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getFirstDeriv(pt,firstDeriv); - return bRet; - } - else - { - return AcDbCurve::getFirstDeriv(pt,firstDeriv); - } -} - -Acad::ErrorStatus AecDbCurveBase::getSecondDeriv (double param,AcGeVector3d& secDeriv) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getSecondDeriv(param,secDeriv); - return bRet; - } - else - { - return AcDbCurve::getSecondDeriv(param,secDeriv); - } -} - -Acad::ErrorStatus AecDbCurveBase::getSecondDeriv (const AcGePoint3d&pt,AcGeVector3d& secDeriv) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getSecondDeriv(pt,secDeriv); - return bRet; - } - else - { - return AcDbCurve::getSecondDeriv(pt,secDeriv); - } -} - -Acad::ErrorStatus AecDbCurveBase::getClosestPointTo(const AcGePoint3d& givenPnt, - AcGePoint3d& pointOnCurve, - Adesk::Boolean extend) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getClosestPointTo(givenPnt,pointOnCurve,extend); - return bRet; - } - else - { - return AcDbCurve::getClosestPointTo(givenPnt,pointOnCurve,extend); - } -} - -Acad::ErrorStatus AecDbCurveBase::getClosestPointTo(const AcGePoint3d& givenPnt, - const AcGeVector3d& direction, - AcGePoint3d& pointOnCurve, - Adesk::Boolean extend) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getClosestPointTo(givenPnt,direction,pointOnCurve,extend); - return bRet; - } - else - { - return AcDbCurve::getClosestPointTo(givenPnt,direction,pointOnCurve,extend); - } -} - -Acad::ErrorStatus AecDbCurveBase::getOrthoProjectedCurve(const AcGePlane& plane, - AcDbCurve*& projCrv) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - AcDbCurve* pCurve1 = NULL; - Acad::ErrorStatus bRet = pCurve->getOrthoProjectedCurve(plane,pCurve1); - if (bRet == Acad::eOk) - { - AecDbCurveBase* pCurveEnt = (AecDbCurveBase*)clone(); - bRet = pCurveEnt->SetBaseCurve(pCurve1); - projCrv = pCurveEnt; - - DELETE_PTR(pCurve1); - } - return bRet; - } - else - { - return AcDbCurve::getOrthoProjectedCurve(plane,projCrv); - } -} - -Acad::ErrorStatus AecDbCurveBase::getProjectedCurve(const AcGePlane& plane, - const AcGeVector3d& projDir, - AcDbCurve*& projCrv) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - AcDbCurve* pCurve1 = NULL; - Acad::ErrorStatus bRet = pCurve->getProjectedCurve(plane,projDir,pCurve1); - if (bRet == Acad::eOk) - { - AecDbCurveBase* pCurveEnt = (AecDbCurveBase*)clone(); - bRet = pCurveEnt->SetBaseCurve(pCurve1); - projCrv = pCurveEnt; - - DELETE_PTR(pCurve1); - } - return bRet; - } - else - { - return AcDbCurve::getProjectedCurve(plane,projDir,projCrv); - } -} - -Acad::ErrorStatus AecDbCurveBase::getOffsetCurves(double offsetDist, - AcDbVoidPtrArray& offsetCurves) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - AcDbVoidPtrArray offsetCurves0; - Acad::ErrorStatus bRet = pCurve->getOffsetCurves(offsetDist,offsetCurves0); - if (bRet == Acad::eOk) - { - for (long i = 0; i < offsetCurves0.length(); i++) - { - AecDbCurveBase*pCurveEnt = (AecDbCurveBase*)clone(); - pCurveEnt->SetBaseCurve((AcDbCurve*)offsetCurves0[i]); - offsetCurves.append(pCurveEnt); - } - - ReleaseEntSet(offsetCurves0); - } - return bRet; - } - else - { - return AcDbCurve::getOffsetCurves(offsetDist,offsetCurves); - } -} - -Acad::ErrorStatus AecDbCurveBase::getOffsetCurvesGivenPlaneNormal( - const AcGeVector3d& normal, - double offsetDist, - AcDbVoidPtrArray& offsetCurves) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - AcDbVoidPtrArray offsetCurves0; - Acad::ErrorStatus bRet = pCurve->getOffsetCurvesGivenPlaneNormal(normal,offsetDist,offsetCurves0); - if (bRet == Acad::eOk) - { - for (long i = 0; i < offsetCurves0.length(); i++) - { - AecDbCurveBase*pCurveEnt = (AecDbCurveBase*)clone(); - pCurveEnt->SetBaseCurve((AcDbCurve*)offsetCurves0[i]); - offsetCurves.append(pCurveEnt); - } - - ReleaseEntSet(offsetCurves0); - } - return bRet; - } - else - return AcDbCurve::getOffsetCurvesGivenPlaneNormal(normal,offsetDist,offsetCurves); -} - -Acad::ErrorStatus AecDbCurveBase::getSpline(AcDbSpline*& spline) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getSpline(spline); - return bRet; - } - else - { - return AcDbCurve::getSpline(spline); - } -} - -Acad::ErrorStatus AecDbCurveBase::getSplitCurves (const AcGeDoubleArray& params, - AcDbVoidPtrArray& curveSegments) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - AcDbVoidPtrArray curveSegments0; - Acad::ErrorStatus bRet = pCurve->getSplitCurves(params,curveSegments0); - if (bRet == Acad::eOk) - { - for (long i = 0; i < curveSegments0.length(); i++) - { - AecDbCurveBase*pCurveEnt = (AecDbCurveBase*)clone(); - AecDbObjXDataMap* pXDataMap = pCurveEnt->GetSpecialtyData(); - if (pXDataMap != NULL) - { - CString sNo; - if (pXDataMap->GetAt(KEY_NO,sNo)) - { - sNo = IDCreate(); - pXDataMap->SetAt(KEY_NO,sNo); - } - } - pCurveEnt->SetBaseCurve((AcDbCurve*)curveSegments0[i]); - curveSegments.append(pCurveEnt); - } - - ReleaseEntSet(curveSegments0); - } - return bRet; - } - else - { - return AcDbCurve::getSplitCurves(params,curveSegments); - } -} - -Acad::ErrorStatus AecDbCurveBase::getSplitCurves (const AcGePoint3dArray& points, - AcDbVoidPtrArray& curveSegments) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - AcDbVoidPtrArray curveSegments0; - Acad::ErrorStatus bRet = pCurve->getSplitCurves(points,curveSegments0); - if (bRet == Acad::eOk) - { - for (long i = 0; i < curveSegments0.length(); i++) - { - AecDbCurveBase*pCurveEnt = (AecDbCurveBase*)clone(); - AecDbObjXDataMap* pXDataMap = pCurveEnt->GetSpecialtyData(); - if (pXDataMap != NULL) - { - CString sNo; - if (pXDataMap->GetAt(KEY_NO,sNo)) - { - sNo = IDCreate(); - pXDataMap->SetAt(KEY_NO,sNo); - } - } - pCurveEnt->SetBaseCurve((AcDbCurve*)curveSegments0[i]); - curveSegments.append(pCurveEnt); - } - - ReleaseEntSet(curveSegments0); - } - return bRet; - } - else - { - return AcDbCurve::getSplitCurves(points,curveSegments); - } -} - -Acad::ErrorStatus AecDbCurveBase::extend(double newParam) -{ - AssertWriteEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->extend(newParam); - if (bRet == Acad::eOk) - { - //bRet = SetBaseCurve(pCurve); - } - return bRet; - } - else - { - return AcDbCurve::extend(newParam); - } -} - -static AcDbArc* FormatArc(const AcGePoint3d& ptGe1,const AcGePoint3d& ptGe2,const AcGePoint3d& ptGe3) -{ - AcDbArc* pArcThis = NULL; - AcGeCircArc3d cirArc3d; - cirArc3d.set(ptGe1,ptGe2,ptGe3);//可能逆弧 - - AcGeVector3d vtNorm = cirArc3d.normal(); - if (vtNorm.isParallelTo(AcGeVector3d::kZAxis)) - { - if (!vtNorm.isCodirectionalTo(AcGeVector3d::kZAxis)) - { - vtNorm.negate();//相反 - } - } - AcDbCircle cir; - cir.setCenter(cirArc3d.center()); - cir.setRadius(cirArc3d.radius()); - cir.setNormal(vtNorm); - - AcGePoint3dArray arPts; - arPts.append(ptGe1); - arPts.append(ptGe3); - - AcDbVoidPtrArray arCurPtrs; - cir.getSplitCurves(arPts,arCurPtrs); - - double dPara = 0.0; - AcDbCurve* pCurve = NULL; - for (int j = 0;j < arCurPtrs.length();j++) - { - pCurve = (AcDbCurve*)arCurPtrs.at(j); - if (pCurve != NULL) - { - if (Acad::eOk == pCurve->getParamAtPoint(ptGe2,dPara))//中点在圆弧上 - { - AcDbArc* pArc = AcDbArc::cast(pCurve); - if (pArc != NULL) - { - pArcThis = pArc; - arCurPtrs.removeAt(j); - break; - } - } - } - } - FreeBuffer(0,arCurPtrs); - return pArcThis; -} - -static AcGePoint3d GetArcMidPoint(AcDbArc* pArc) -{ - double dSta = 0.0,dEnd = 0.0; - pArc->getStartParam(dSta); - pArc->getEndParam(dEnd); - - AcGePoint3d ptMid; - pArc->getPointAtParam((dSta + dEnd) / 2.0,ptMid); - - return ptMid; -} - -Acad::ErrorStatus AecDbCurveBase::extend(Adesk::Boolean extendStart, - const AcGePoint3d& toPoint) -{ - AssertWriteEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - AcGePoint3d ptS,ptE; - pCurve->getStartPoint(ptS); - pCurve->getEndPoint(ptE); - - if (toPoint.distanceTo(ptS) < toPoint.distanceTo(ptE)) - extendStart = Adesk::kTrue; - else - extendStart = Adesk::kFalse; - - Acad::ErrorStatus bRet = pCurve->extend(extendStart,toPoint); - if (bRet == Acad::eOk) - { - //延长到外部一点 - //GetNativeCurve - //bRet = SetBaseCurve(pCurve); - } - else - { - //内部,缩短到内部一点 - AcDbLine* pLn = AcDbLine::cast(pCurve); - if (pLn != NULL) - { - if (extendStart) - { - pLn->setStartPoint(toPoint); - } - else - { - pLn->setEndPoint(toPoint); - } - bRet = Acad::eOk; - } - - AcDbArc* pArc = AcDbArc::cast(pCurve); - if (pArc != NULL) - { - if (extendStart)//开始缩短 - { - AcGePoint3d ptE,ptM; - pArc->getEndPoint(ptE); - ptM = GetArcMidPoint(pArc); - - AcDbArc* pArc2 = FormatArc(toPoint,ptM,ptE); - if (pArc2 != NULL) - { - pArc->setStartAngle(pArc2->startAngle()); - pArc->setEndAngle(pArc2->endAngle()); - delete pArc2; - } - } - else//末尾缩短 - { - AcGePoint3d ptE,ptM; - pArc->getStartPoint(ptE); - ptM = GetArcMidPoint(pArc); - - AcDbArc* pArc2 = FormatArc(ptE,ptM,toPoint); - if (pArc2 != NULL) - { - pArc->setStartAngle(pArc2->startAngle()); - pArc->setEndAngle(pArc2->endAngle()); - delete pArc2; - } - } - bRet = Acad::eOk; - } - } - return bRet; - } - else - { - return AcDbCurve::extend(extendStart,toPoint); - } -} - -Acad::ErrorStatus AecDbCurveBase::getArea(double&area) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getArea(area); - return bRet; - } - else - { - return AcDbCurve::getArea(area); - } -} - -Adesk::Boolean AecDbCurveBase::isPlanar() const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Adesk::Boolean bRet = pCurve->isPlanar(); - return bRet; - } - else - { - return AcDbCurve::isPlanar(); - } -} - -Acad::ErrorStatus AecDbCurveBase::getPlane(AcGePlane&plane, AcDb::Planarity&pr) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - Acad::ErrorStatus bRet = pCurve->getPlane(plane,pr); - return bRet; - } - else - { - return AcDbCurve::getPlane(plane,pr); - } -} - -void AecDbCurveBase::getEcs(AcGeMatrix3d& retVal) const -{ - assertReadEnabled(); - - AcDbCurve* pCurve = GetNativeCurve(); - if (pCurve != NULL) - { - pCurve->getEcs(retVal); - } - else - { - AcDbCurve::getEcs(retVal); - } -} - -Acad::ErrorStatus AecDbCurveBase::SetBaseCurve(const AcDbCurve* pDbCurve) -{ - return Acad::eNotImplementedYet; -} - -AcDbCurve* AecDbCurveBase::GetBaseCurve(bool bOrthoProjectToXY) const -{ - return NULL; -} - -AcDbCurve* AecDbCurveBase::GetNativeCurve() const -{ - return NULL; -} - -//AEC派生 -int AecDbCurveBase::GetDrawMode() -{ - int nDrawMode = 3; - //从命名字典中取,默认3 - - return nDrawMode; -} - -void AecDbCurveBase::SetDrawMode(int nMode) -{ - //写入命名字典 -} - -//某些实体只有2D -int AecDbCurveBase::GetDrawDimOnType(int nDrawMode, int nDrawType) const -{ - int nDraw = 0; //0--NONE; 1--2D; 2--3D; 3--2D&3D; - if (nDrawMode == DRAW_2D && (nDrawType == k2DOnly || nDrawType == k2Dand3D)) - { - nDraw = 1; - } - else if (nDrawMode == DRAW_3D && (nDrawType == k3DOnly || nDrawType == k2Dand3D)) - { - nDraw = 2; - } - else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == k2Dand3D) - { - nDraw = 3;//转到viewportdraw - } - else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == k2DOnly) - { - nDraw = 1; - } - else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == k3DOnly) - { - nDraw = 2; - } - return nDraw; -} - -void AecDbCurveBase::BackupColorIndex(AcDbEntity* pEnt) -{ - if (pEnt != NULL) - { - struct resbuf* pXData = NULL; - pXData = pEnt->xData(_T("COLOR_BK")); - if (pXData == NULL) - { - struct resbuf* pTemp = acutNewRb(AcDb::kDxfRegAppName); - acutNewString(_T("COLOR_BK"),pTemp->resval.rstring); - pXData = pTemp; - - struct resbuf* pTempNext = NULL; - pTempNext = acutNewRb(AcDb::kDxfXdInteger32); - pTempNext->resval.rlong = pEnt->colorIndex(); - pTemp->rbnext = pTempNext; - pTempNext->rbnext = NULL; - - acdbRegApp(_T("COLOR_BK")); - pEnt->setXData(pXData); - acutRelRb(pXData); - } - } -} - -int AecDbCurveBase::SetBackupColorIndex(AcDbEntity* pEnt) -{ - int nColor = kColorByLayer; - if (pEnt != NULL) - { - resbuf* pXData = NULL; - pXData = pEnt->xData(_T("COLOR_BK")); - if (pXData != NULL) - { - struct resbuf* pTempNext = pXData->rbnext; - if (pTempNext != NULL) - { - if (pTempNext->restype == AcDb::kDxfXdInteger32) - { - nColor = pTempNext->resval.rint; - pEnt->setColorIndex(nColor); - // 存在清空 - struct resbuf* pTmp = acutNewRb(AcDb::kDxfRegAppName); - pEnt->setXData(pTmp); - acutRelRb(pXData); - acutRelRb(pTmp); - } - } - } - } - return nColor; -} - -int AecDbCurveBase::GetExplodeMode() const -{ - int nDrawMode = GetDrawMode(); - DrawModeType nDrawType = k2Dand3D; - int nDraw = GetDrawDimOnType(nDrawMode, nDrawType); - - if (nDraw == 1) - { - nDraw = DRAW_2D; - } - else if (nDraw == 2) - { - nDraw = DRAW_3D; - } - else if (nDraw == 3) - { - ads_point pt; - struct resbuf rb; - acedGetVar(_T("VIEWDIR"),&rb); - ads_point_set(rb.resval.rpoint,pt); - - ads_point viewDir; - acdbUcs2Wcs(pt,viewDir,false); - - if (fabs(viewDir[X]) > 1.0e-6 || fabs(viewDir[Y]) > 1.0e-6) - { - nDraw = DRAW_3D; - } - else - { - nDraw = DRAW_2D; - } - } - return nDraw; -} - -Acad::ErrorStatus AecDbCurveBase::dwgInFields (AcDbDwgFiler* pFiler) -{ - assertWriteEnabled () ; - - //----- Read parent class information first. - Acad::ErrorStatus es = AcDbCurve::dwgInFields (pFiler) ; - if ( es != Acad::eOk ) - return (es) ; - - return (pFiler->filerStatus ()) ; -} - -Acad::ErrorStatus AecDbCurveBase::dwgOutFields(AcDbDwgFiler* pFiler) const -{ - assertReadEnabled () ; - //----- Save parent class information first. - Acad::ErrorStatus es = AcDbCurve::dwgOutFields (pFiler) ; - if ( es != Acad::eOk ) - return (es) ; - - return (pFiler->filerStatus ()) ; -} - -Acad::ErrorStatus AecDbCurveBase::dxfInFields (AcDbDxfFiler* pFiler) -{ - assertWriteEnabled () ; - - //----- Read parent class information first. - Acad::ErrorStatus es = AcDbCurve::dxfInFields (pFiler) ; - if ( es != Acad::eOk ) - return (es) ; - - return (pFiler->filerStatus ()) ; -} - -Acad::ErrorStatus AecDbCurveBase::dxfOutFields(AcDbDxfFiler* pFiler) const -{ - assertReadEnabled () ; - //----- Save parent class information first. - Acad::ErrorStatus es = AcDbCurve::dxfOutFields (pFiler) ; - if ( es != Acad::eOk ) - return (es) ; - - return (pFiler->filerStatus ()) ; -} - -Acad::ErrorStatus AecDbCurveBase::Draw2d(AcGiDraw &dc) const -{ - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::Draw3d(AcGiDraw &dc) const -{ - return Acad::eOk; -} - -void AecDbCurveBase::AssertWriteEnabled(Adesk::Boolean autoUndo /*= true*/, Adesk::Boolean recordModified /*= true*/) -{ - FreeBuffer(0, m_ar2DDrableBufPtrs_); - FreeBuffer(0, m_ar3DDrableBufPtrs_); - - m_ar3DDrableBufPtrs_.removeAll(); - m_ar2DDrableBufPtrs_.removeAll(); - - assertWriteEnabled(autoUndo,recordModified); -} - -bool AecDbCurveBase::GetPositionGrip(int nIndex, AecGripData *&pGrip) const -{ - return NULL; -} - -extern double PixelToWcs(int nPixel); -bool AecDbCurveBase::SubAddHitEditGrip(AcDbGripDataPtrArray &grips) const -{ - assertReadEnabled(); - - AecGripData *pGrip = NULL; - GetPositionGrip(grips.length() - 1, pGrip); - - if (pGrip != NULL) - { - AcGePoint3d ptHit = pGrip->ptGrip; - ptHit += AcGeVector3d::kXAxis * PixelToWcs(30); - - AecGripData *pGrip2 = new AecGripData; - memset(pGrip2, 0, sizeof(AecGripData)); - - pGrip2->nIndex = grips.length(); - pGrip2->ePos = eHitEdit; - pGrip2->nColor = kRed; - pGrip2->ptGrip = ptHit; - _tcscpy(pGrip2->szTip, _T("点击修改")); - _tcscpy(pGrip2->szID, _T("HITEDIT_2023")); - pGrip2->pOwner = (AcDbEntity *)this; - pGrip2->idHost = this->objectId(); - AcDbGripData* pGripData = new AcDbGripData; - pGripData->setGripPoint(ptHit); - pGripData->setAppData((void *)pGrip2); - pGripData->setWorldDraw(AecGripCback::WorldDrawfunc); - pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc); - grips.append(pGripData); - - return true; - } - - return false; -} - -//不得导出,需要数据,增加特定的获取函数 -extern AecDbObjXDataMap g_mapGlobalData; -bool AecDbCurveBase::HitOnGripEdit(const AcDbVoidPtrArray &gripAppData) -{ - AecGripData *pAppData = NULL; - AcDbIntArray arIndex; - - if (gripAppData.isEmpty()) - { - return Acad::eOk; - } - - pAppData = (AecGripData *)gripAppData.first(); - if (pAppData->ePos == eHitEdit) - { - //命令名 DBL_DXFNAME - TCHAR szCmd[65]; - _tcscpy(szCmd, _T("DBL_")); - _tcscat(szCmd, this->isA()->dxfName()); - - //判断命令是否存在 - AcEdCommand *pCmd = acedRegCmds->lookupLocalCmd(szCmd); - if (pCmd != NULL) - { - //发送ID 到 USERI; - AcDbObjectId id = pAppData->idHost; - - g_mapGlobalData.SetAt(szCmd, id); - - acedPostCommand(_T("\x03")); - - _tcscat(szCmd, _T(" ")); - acedPostCommand(szCmd); - } - else - { - acutPrintf(_T("\nLocalCmd %s does not exist!"), szCmd); - } - return true; - } - return false; -} - -bool AecDbCurveBase::Draw3DBuffers(AcGiDraw &dc)const -{ - if (m_ar3DDrableBufPtrs_.isEmpty()) return false; - AcDbEntity *pEnt = NULL; - for (int i = 0; i < m_ar3DDrableBufPtrs_.length(); ++i) - { - pEnt = (AcDbEntity *)m_ar3DDrableBufPtrs_[i]; - dc.DrawEntity(*pEnt); - } - return true; -} - -bool AecDbCurveBase::Draw2DBuffers(AcGiDraw &dc)const -{ - if (m_ar2DDrableBufPtrs_.isEmpty()) - { - return false; - } - AcDbEntity *pEnt = NULL; - for (int i = 0; i < m_ar2DDrableBufPtrs_.length(); ++i) - { - pEnt = (AcDbEntity *)m_ar2DDrableBufPtrs_[i]; - pEnt->setLayer(dc.GetLayerId()); - pEnt->setColorIndex(colorIndex()); - dc.DrawEntity(*pEnt); - } - return true; -} - -const AcDbVoidPtrArray& AecDbCurveBase::Get3DBuffer() const -{ - //剖切隐藏 - BoolSubtractHide(); - - return m_ar3DDrableBufPtrs_; -} - -const AcDbVoidPtrArray& AecDbCurveBase::Get2DBuffer() const -{ - return m_ar2DDrableBufPtrs_; -} - -bool AecDbCurveBase::Has3DBuffer() const -{ - return !m_ar3DDrableBufPtrs_.isEmpty(); -} - -bool AecDbCurveBase::Has2DBuffer() const -{ - return !m_ar2DDrableBufPtrs_.isEmpty(); -} - -void AecDbCurveBase::Add3DBuffer(AcDbEntity *pEnt) const -{ - if (pEnt) m_ar3DDrableBufPtrs_.append(pEnt); -} - -void AecDbCurveBase::Add3DBuffer(const AcDbVoidPtrArray &arr) const -{ - m_ar3DDrableBufPtrs_.append(arr); -} - -void AecDbCurveBase::Add2DBuffer(AcDbEntity *pEnt) const -{ - if (pEnt) m_ar2DDrableBufPtrs_.append(pEnt); -} - -void AecDbCurveBase::Add2DBuffer(const AcDbVoidPtrArray &arr) const -{ - m_ar2DDrableBufPtrs_.append(arr); -} - -bool AecDbCurveBase::IsIn2DBuffer(AcDbEntity* pEnt) const -{ - assertReadEnabled(); - if (-1 == m_ar2DDrableBufPtrs_.find(pEnt)) - return false; - return true; -} - -bool AecDbCurveBase::IsIn3DBuffer(AcDbEntity* pEnt) const -{ - assertReadEnabled(); - if (-1 == m_ar3DDrableBufPtrs_.find(pEnt)) - return false; - return true; -} - -void AecDbCurveBase::Clean3DBuffer() const -{ - FreeBuffer(0, m_ar3DDrableBufPtrs_); - m_ar3DDrableBufPtrs_.removeAll(); -} - -void AecDbCurveBase::Clean2DBuffer() const -{ - FreeBuffer(0, m_ar2DDrableBufPtrs_); - m_ar2DDrableBufPtrs_.removeAll(); -} - -void AecDbCurveBase::Clean3DBufferNoDel() const -{ - m_ar3DDrableBufPtrs_.removeAll(); -} - -void AecDbCurveBase::Clean2DBufferNoDel() const -{ - m_ar2DDrableBufPtrs_.removeAll(); -} - -int AecDbCurveBase::GetDrawDimCur() const -{ - return m_nDrawDimCur; -} - -//获取二维视图显示的图形 -int AecDbCurveBase::GetDraw2dables(Adesk::UInt16 nDrawStyle, AcDbVoidPtrArray& arEntPtrs) const -{ - assertReadEnabled(); - - AcDbEntity* pEnt = NULL,*pEntT = NULL; - const AcDbVoidPtrArray &ar2D = Get2DBuffer(); - for (int i = 0;i < ar2D.length();i++) - { - pEnt = (AcDbEntity*)ar2D.at(i); - pEntT = (AcDbEntity*)pEnt->clone(); - - pEntT->setLayer(layerId()); - arEntPtrs.append(pEntT); - } - return arEntPtrs.length(); -} - -//获取三维显示图形 -int AecDbCurveBase::GetDraw3dables(AcDbVoidPtrArray& arEntPtrs,bool bWriteBimInfo) const -{ - assertReadEnabled(); - - const AecDbObjXDataMap* pXDataMap = GetSpecialtyData(); - if (pXDataMap != NULL) - { - AcDbEntity* pEnt = NULL,*pEntClone = NULL; - if (!Has3DBuffer()) - { - AcGiViewDraw dc(NULL, NULL); - Draw3d(dc); - } - const AcDbVoidPtrArray &ar3D = Get3DBuffer(); - for (int i = 0;i < ar3D.length();i++) - { - pEnt = (AcDbEntity*)ar3D.at(i); - pEntClone = (AcDbEntity*)pEnt->clone(); - - int nColor = 0; - if ( pXDataMap->GetAt(_T("COLOR"),nColor) ) - { - pEntClone->setColorIndex(nColor); - } - else - { - pEntClone->setColorIndex(colorIndex()); - } - pEntClone->setLayer(layerId()); - - if (bWriteBimInfo) - { - pXDataMap->Write(pEntClone,_T("BIMDATA")); - } - arEntPtrs.append(pEntClone); - } - } - return arEntPtrs.length(); -} - -void AecDbCurveBase::UpdateDrableSpecData(LPCTSTR pszApp,LPCTSTR pszKey,CString& sVal) -{ - assertWriteEnabled(); - - AecDbObjXDataMap xDataMap; - AcDbEntity* pEnt = NULL,*pEntT = NULL; - const AcDbVoidPtrArray &ar2D = Get2DBuffer(); - for (int i = 0;i < ar2D.length();i++) - { - pEnt = (AcDbEntity*)ar2D.at(i); - - if (xDataMap.Read(pEnt,pszApp)) - { - xDataMap.RemoveAt(pszKey); - xDataMap.SetAt(pszKey,sVal); - xDataMap.Write(pEnt,pszApp); - } - } - - const AcDbVoidPtrArray &ar3D = Get3DBuffer(); - for (int i = 0;i < ar3D.length();i++) - { - pEnt = (AcDbEntity*)ar3D.at(i); - if (xDataMap.Read(pEnt,pszApp)) - { - xDataMap.RemoveAt(pszKey); - xDataMap.SetAt(pszKey,sVal); - xDataMap.Write(pEnt,pszApp); - } - } -} - -bool AecDbCurveBase::GetBimInfoTip(CString& sInfoTip) const -{ - return false; -} - -bool AecDbCurveBase::GetProperties(SimpleProperty::PropertySetByIndex &porpertys) const -{ - assertReadEnabled(); - CString sLayer(_T("0")); - TCHAR *pLayer = layer(); - if (pLayer) - { - sLayer = pLayer; - acutDelString(pLayer); - } - SimpleProperty::makeAndInsert(porpertys, _T("图层"), sLayer, false); - const AecDbObjXDataMap *pData = GetSpecialtyData(); - CString sys; - if (pData->GetAt(PIPE_SYS, sys)) - SimpleProperty::makeAndInsert(porpertys, _T("分系统"), sys, false); - - return TRUE; -} - -bool AecDbCurveBase::SetProperties(SimpleProperty::PropertySetByName &properties) -{ - AssertWriteEnabled(); - using namespace SimpleProperty; - CString sVal(_T("")); - if (properties.findAndSet(_T("图层"), sVal)) - { - setLayer(sVal); - } - if (properties.findAndSet(_T("分系统"), sVal)) - { - AecDbObjXDataMap *pData = GetSpecialtyData(AcDb::kForWrite); - if (pData) - pData->SetAt(PIPE_SYS, sVal); - } - return true; -} - -bool AecDbCurveBase::SendUserData(struct resbuf *pRb) -{ - return false; -} - -Acad::ErrorStatus AecDbCurveBase::ReCreateDraw2d() -{ - assertWriteEnabled(); - Clean2DBuffer(); - return Acad::eOk; -} - -Acad::ErrorStatus AecDbCurveBase::ReCreateDraw3d() -{ - assertWriteEnabled(); - Clean3DBuffer(); - return Acad::eOk; -} - -int AecDbCurveBase::GetSectionDraw(const AcGePoint3d& ptFr,const AcGePoint3d& ptTo,const AcGeVector3d& vtViewDir,const AcGeVector3d& vtTo, AcDbVoidPtrArray& arRegionPtrs) const -{ - return 0; -} - -bool AecDbCurveBase::GetSectionHatchPattern(CString& sPattern) const -{ - assertReadEnabled(); - - CString sMat; - - if (GetSpecialtyData()->GetAt(KEY_SECTION_HATCH, sMat)) - { - sPattern = sMat; - if (sMat == HATCH_NO_NEED) - return false; - - if (sMat != HATCH_DEFAULT) - return true; - } - - if ( GetSpecialtyData()->GetAt(KEY_MATERIAL,sMat)) - { - //以后从外部配置文件中获取 - //钢筋混凝土 - //石材 - //砖墙 - //填充墙体 - //轻质隔墙 - //玻璃幕墙 - - sPattern = _T("AR-CONC"); - if (sMat.CompareNoCase(_T("钢筋混凝土")) == 0) - { - sPattern = _T("钢筋混凝土"); - } - else if(sMat.CompareNoCase(_T("石材")) == 0) - { - sPattern = _T("天然石材"); - } - else if(sMat.CompareNoCase(_T("砖墙")) == 0) - { - sPattern = _T("普通砖"); - } - else if(sMat.CompareNoCase(_T("填充墙体")) == 0) - { - sPattern = _T("钢筋混凝土"); - } - else if(sMat.CompareNoCase(_T("轻质隔墙")) == 0) - { - sPattern = _T("混凝土"); - } - else if(sMat.CompareNoCase(_T("玻璃幕墙")) == 0) - { - sPattern = _T("玻璃砖墙"); - } - } - return true; -} - -double AecDbCurveBase::GetVolume(bool bIsBody/* = false*/) const -{ - assertReadEnabled(); - - if (!Has3DBuffer()) - { - AcGiViewDraw dc(NULL,NULL); - Draw3d(dc); - } - - double dVol = 0.0,dVolAll = 0.0,momInertia[3],prodInertia[3],prinMoments[3],radiiGyration[3]; - AcGePoint3d ptCen; - AcGeVector3d prinAxes[3]; - AcDbExtents extents; - - AcDbVoidPtrArray arEntPtrs; - GetDraw3dables(arEntPtrs); - - AcDbEntity* pEnt = NULL; - for (int i = 0;i < arEntPtrs.length();i++) - { - pEnt = (AcDbEntity*)arEntPtrs.at(i); - - AcDb3dSolid* pSolid = AcDb3dSolid::cast(pEnt); - if (pSolid != NULL) - { - pSolid->getMassProp(dVol,ptCen,momInertia,prodInertia,prinMoments,prinAxes,radiiGyration,extents); - dVolAll += dVol; - } - } - return dVolAll; -} - -int AecDbCurveBase::ComparedTo(AecDbCurveBase* pCurOther) const -{ - return -1;//不做比较 -} - -double AecDbCurveBase::GetArea() const -{ - assertReadEnabled(); - - if (!Has3DBuffer()) - { - AcGiViewDraw dc(NULL,NULL); - Draw3d(dc); - } - - double dArea = 0.0,dAreaAll = 0.0; - AcDbVoidPtrArray arEntPtrs; - GetDraw3dables(arEntPtrs); - - AcDbEntity* pEnt = NULL; - for (int i = 0;i < arEntPtrs.length();i++) - { - pEnt = (AcDbEntity*)arEntPtrs.at(i); - - AcDb3dSolid* pSolid = AcDb3dSolid::cast(pEnt); - if (pSolid != NULL) - { - pSolid->getArea(dArea); - dAreaAll += fabs(dArea); - } - - AcDbRegion* pReg = AcDbRegion::cast(pEnt); - if (pReg != NULL) - { - pReg->getArea(dArea); - dAreaAll += fabs(dArea); - } - } - return dAreaAll; -} - -void AecDbCurveBase::Add3DBoolSubtract(AcDb3dSolid* pSolidBlackHole) -{ - assertWriteEnabled(); - - const AcDbVoidPtrArray& ar3D_ = Get3DBuffer(); - AcDbVoidPtrArray ar3D; - ar3D.append(ar3D_); - - AcDbEntity* pEnt = NULL; - AcDb3dSolid* pSolid = NULL; - AcDb3dSolid* pSolidCln = NULL; - AcDb3dSolid* pSolidNotGet = NULL; - Acad::ErrorStatus es; - - Adesk::Boolean bSlidInterface = Adesk::kFalse; - double dArea1 = 0.0,dArea2 = 0.0; - - for (int i = 0;i < ar3D.length();i++) - { - pEnt = (AcDbEntity*)ar3D.at(i); - - pSolid = AcDb3dSolid::cast(pEnt); - if (pSolid != NULL) - { - pSolidCln = (AcDb3dSolid*)pSolidBlackHole->clone(); - - //有交集才处理 - if ( Acad::eOk == pSolid->checkInterference( pSolidCln,Adesk::kFalse,bSlidInterface,pSolidNotGet)) - { - pSolid->getArea(dArea1); - - es = pSolid->booleanOper(AcDb::kBoolSubtract,pSolidCln); - - pSolid->getArea(dArea2); - - if ( es == Acad::eOk) - { - pSolid->recordGraphicsModified(Adesk::kTrue); - - if ( fabs(dArea1 - dArea2) < 1.e-3)//没有变化,被包含 - { - ar3D.removeAt(i); - i -= 1; - m_ar3DDrableBufPtrs_.removeAt(i); - } - } - else if ( es == Acad::eGeneralModelingFailure ) - { - ar3D.removeAt(i); - i -= 1; - m_ar3DDrableBufPtrs_.removeAt(i); - } - //delete pSolidCln; - } - } - } -} - -void AecDbCurveBase::Remove3DBoolSubtract() -{ - assertWriteEnabled(); - - //清除3D,重建 - Clean3DBuffer(); -} - -void AecDbCurveBase::AddBlackHole(AcDbObjectId& idHole) -{ - AssertWriteEnabled(); - - AecDbObjXDataMap* pXdataMap = GetSpecialtyData(AcDb::kForWrite); - if (pXdataMap != NULL) - { - TCHAR szHand[19]; - memset(szHand,0,sizeof(szHand) ); - idHole.handle().getIntoAsciiBuffer(szHand); - - CString sKey; - sKey.Format(_T("%s_%s"),KEY_HOLE,szHand); - pXdataMap->SetAt(sKey,idHole.handle()); - } -} - -void AecDbCurveBase::RemoveBlackHole(AcDbObjectId& idHole) -{ - AssertWriteEnabled(); - AecDbObjXDataMap* pXdataMap = GetSpecialtyData(AcDb::kForWrite); - if (pXdataMap != NULL) - { - TCHAR szHand[19]; - memset(szHand,0,sizeof(szHand) ); - idHole.handle().getIntoAsciiBuffer(szHand); - - CString sKey; - sKey.Format(_T("%s_%s"),KEY_HOLE,szHand); - pXdataMap->RemoveAt(sKey); - } -} - -void AecDbCurveBase::DrawBlackHole(AcDbEntity* pSolidEnt) const -{ - AcDb3dSolid* pSolidAll = AcDb3dSolid::cast(pSolidEnt); - if (pSolidAll == NULL) - return; - - const AecDbObjXDataMap* pCXDataMap = GetSpecialtyData(); - if (pCXDataMap != NULL) - { - AecDbObjXDataMap* pXDataMap = (AecDbObjXDataMap*)pCXDataMap; - AecDbObjXDataMap::It it = pXDataMap->Begin(); - AecDbObjXDataMap::It end = pXDataMap->End(); - - CString sKey; - - AecXData cVal; - memset(&cVal,0,sizeof(AecXData)); - - AcDbEntity* pEnt = NULL; - AcDbHandle hd; - AcDbObjectId idHole; - - for (; it != end; ) - { - if (!pXDataMap->GetNext(it, sKey, cVal)) - break; - - if (sKey.Find(KEY_HOLE) != -1) - { - pXDataMap->GetAt(sKey,hd); - if ( Acad::eOk == acdbCurDwg()->getAcDbObjectId(idHole,false,hd) ) - { - if ( Acad::eOk == acdbOpenAcDbEntity(pEnt,idHole,AcDb::kForRead)) - { - AecDbEntityBase* pBlackHole = AecDbEntityBase::cast(pEnt); - if (pBlackHole != NULL) - { - AcDb3dSolid* pSolidBlackHold = pBlackHole->GetBlackHole(); - if (pSolidBlackHold != NULL) - { - pSolidAll->booleanOper(AcDb::kBoolSubtract,pSolidBlackHold); - } - } - pEnt->close(); - } - } - } - } - } -} - -AcDb3dSolid* AecDbCurveBase::GetBlackHole() const -{ - return NULL; -} - -void AecDbCurveBase::SplitStrintToArray(LPCTSTR pszDescr, CStringArray & arInfo, TCHAR tcSpace) -{ - if (pszDescr == NULL) return; - - CString sDescr = pszDescr; - int nLen = sDescr.GetLength(); - int i = 0; - CString sText = _T(""); - TCHAR tchar = _T('\0'); - - for (i = 0; i < nLen; i++) - { - tchar = sDescr.GetAt(i); - if (tchar == tcSpace) - { - if (!sText.IsEmpty()) - arInfo.Add(sText); - sText = _T(""); - } - else - { - sText += tchar; - } - - if (i == nLen - 1 && !sText.IsEmpty()) - { - arInfo.Add(sText); - } - } -} - -AcDbPolyline * AecDbCurveBase::StringToPolyline(LPCTSTR pszPoint2ds) -{ - CString sPlane,sTemp; - CString sAll = pszPoint2ds; - int nPos = sAll.Find(_T("plane=")); - if (nPos != -1) - { - sPlane = sAll.Mid(nPos); - sTemp = sAll.Mid(0,nPos); - sAll = sTemp; - } - - CStringArray arXYs; - SplitStrintToArray(sAll, arXYs, _T(',')); - - double dEl = 0.0; - AcGeVector3d vtNorm = AcGeVector3d::kZAxis; - - CString sLast; - if (arXYs.GetSize() > 0) - { - sLast = arXYs.GetAt(arXYs.GetSize() - 1); - if (sLast.Find(_T('[')) != -1) - { - sLast.TrimLeft(_T('[')); - sLast.TrimRight(_T(']')); - } - - CStringArray arVals; - SplitStrintToArray(sLast, arVals, _T(';')); - - if (arVals.GetSize() >= 4) - { - dEl = _ttof(arVals.GetAt(0)); - vtNorm.set(_ttof(arVals.GetAt(1)), _ttof(arVals.GetAt(2)), _ttof(arVals.GetAt(3))); - } - } - - CString sX, sYB, sBulge, sY; - double dBulge = 0.0; - int nFind = -1; - AcGePoint2d pt; - AcDbPolyline pl; - - AcDbPolyline* pPl = new AcDbPolyline; - - if (!sPlane.IsEmpty()) - { - sPlane.TrimLeft(_T("plane=")); - sPlane.TrimLeft(_T('(')); - sPlane.TrimRight(_T(')')); - - CStringArray arVals; - SplitStrintToArray(sPlane,arVals,_T(',')); - - if (arVals.GetSize() >= 4) - { - vtNorm.set(_ttof(arVals.GetAt(0)),_ttof(arVals.GetAt(1)),_ttof(arVals.GetAt(2))); - dEl = _ttof(arVals.GetAt(3)); - - pPl->setNormal(vtNorm); - pPl->setElevation(dEl); - } - } - else - { - pPl->setNormal(vtNorm); - pPl->setElevation(dEl); - } - - for (int i = 0; i < arXYs.GetSize() / 2; i++) - { - sX = arXYs.GetAt(2 * i); - sYB = arXYs.GetAt(2 * i + 1); - sY = sYB; - dBulge = 0.0; - - nFind = sYB.Find(_T('@')); - if (nFind != -1) - { - sBulge = sYB.Mid(nFind + 1); - dBulge = _ttof(sBulge); - sY = sYB.Mid(0, nFind); - } - - pt.set(_ttof(sX), _ttof(sY)); - pPl->addVertexAt(i, pt, dBulge); - } - return pPl; -} - -static AcGePoint3d MidPoint(AcGePoint3d& pt1, AcGePoint3d& pt2) -{ - return AcGePoint3d((pt1.x + pt2.x) / 2.0, - (pt1.y + pt2.y) / 2.0, - (pt1.z + pt2.z) / 2.0); -} - -//剖切隐藏 -void AecDbCurveBase::BoolSubtractHide() const -{ - if (m_ar3DDrableBufPtrs_.isEmpty()) - return; - - const AecDbObjXDataMap* pXDataMap = GetSpecialtyData(); - if (pXDataMap != NULL) - { - CString sPl; - double dBomEl = 0.0,dH = 0.0; - - if ( pXDataMap->GetAt(KEY_BOOLSPL,sPl) && - pXDataMap->GetAt(KEY_BOOLBOM,dBomEl) && - pXDataMap->GetAt(KEY_BOOLH,dH) ) - { - AcDbPolyline* pPl = StringToPolyline(sPl); - if (pPl != NULL) - { - AcGePoint3d ptFr,ptTo; - pPl->getPointAt(0,ptFr); - - //简单取内一心 - if (pPl->numVerts() > 2) - { - AcGePoint3d pt2; - pPl->getPointAt(2,pt2); - ptFr = MidPoint(ptFr,pt2); - } - - AcDbLine ln; - ptFr.z = dBomEl; - ptTo = ptFr; - ptTo.z = dH; - ln.setStartPoint(ptFr); - ln.setEndPoint(ptTo); - - AcDbRegion* pRegion = NULL; - AcDbVoidPtrArray arCur,arReg; - arCur.append(pPl); - - Acad::ErrorStatus es; - if (Acad::eOk == ( es = AcDbRegion::createFromCurves(arCur,arReg) ) ) - { - if (!arReg.isEmpty()) - { - pRegion = (AcDbRegion*)arReg.first(); - - AcDb3dSolid* pSoldSub = new AcDb3dSolid; - if ( Acad::eOk == (es = pSoldSub->extrudeAlongPath(pRegion,&ln) ) ) - { - AcDb3dSolid* pSolid = NULL; - AcDbEntity* pEnt = NULL; - for (int i = 0;i < m_ar3DDrableBufPtrs_.length();i++) - { - pEnt = (AcDbEntity*)m_ar3DDrableBufPtrs_.at(i); - pSolid = AcDb3dSolid::cast(pEnt); - if (pSolid != NULL) - { - AcDb3dSolid* pSolidSubCln = (AcDb3dSolid*)pSoldSub->clone(); - CopyObject(*pSoldSub,*pSolidSubCln); - - if ( Acad::eOk != (es = pSolid->booleanOper(AcDb::kBoolSubtract,pSolidSubCln) ) ) - { - delete pSolidSubCln; - } - } - } - } - delete pSoldSub; - delete pRegion; - } - } - delete pPl; - } - } - } -} - -typedef AcArray AcDbEntityArray; -void AecDbCurveBase::PreprocessForHlr(const AcGePoint3d &ptPlnO - , const AcGeVector3d &vtPlnN - , AcArray &ar) const -{ - assertReadEnabled(); - return; -} - -void AecDbCurveBase::ProcessHlrResult(const AcDbEntityArray &ar - , const std::map &preAr - , AcDbEntityArray &output) const -{ - assertReadEnabled(); - AcDbObjectId idLy(layerId()), idLt(linetypeId()); - int clr(colorIndex()); - - const AecDbObjXDataMap *pXData = GetSpecialtyData(); - - for (int i(0); i < ar.length(); ++i) - { - AcDbEntity *pEnt((AcDbEntity *)ar[i]->clone()); - if (pEnt) - { - if (pXData) - pXData->Write(pEnt, BIMDATA_APP); - pEnt->setLayer(idLy); - pEnt->setLinetype(idLt); - pEnt->setColorIndex(clr); - output.append(pEnt); - } - } -} - -SHJson::WValue& AecDbCurveBase::ToJson(bool bExprotGeo) const -{ - using namespace SHJson; - assertReadEnabled(); - WValue &v(m_json); - v.SetObject(); - - addMember(v, _T("__class__"), isA()->name()); - addMember(v, _T("__self__"), objectId().asOldId()); - addMember(v, _T("__owner__"), 0); - - const AecDbObjXDataMap *pXMap = GetSpecialtyData(); - if (pXMap) - { - addMember(v, _T("__xdata__"), pXMap->ToJson()); - } - - CString sVertices, sIndices; - __int64 dwRgb = 0; - - struct resbuf rb; - acedGetVar(_T("useri5"), &rb); - if (rb.resval.rint == 30)//3D导出 - { - WValue node; - node.SetObject(); - - WValue body; - body.SetArray(); - - AcDbEntity *pE = NULL; - for (int i = 0; i < Get3DBuffer().length(); i++) - { - node.SetNull(); - - pE = (AcDbEntity *)Get3DBuffer().at(i); - AcDb3dSolid *p3d = AcDb3dSolid::cast(pE); - if (p3d != NULL) - { - dwRgb = RGB(p3d->color().red(), p3d->color().green(), p3d->color().blue()); - - if (PolyhedronGeometry(p3d, sVertices, sIndices)) - { - addMember(node, _T("RGB"), dwRgb); - addMember(node, _T("vertices"), sVertices); - addMember(node, _T("indices"), sIndices); - pushBack(body, node); - } - } - - AcDbSubDMesh *pSubMesh = AcDbSubDMesh::cast(pE); - if (pSubMesh != NULL) - { - dwRgb = RGB(pSubMesh->color().red(), pSubMesh->color().green(), pSubMesh->color().blue()); - if (PolyhedronGeometry(pSubMesh, sVertices, sIndices)) - { - addMember(node, _T("RGB"), dwRgb); - addMember(node, _T("vertices"), sVertices); - addMember(node, _T("indices"), sIndices); - pushBack(body, node); - } - } - } - - if (!body.Empty()) - addMember(v, _T("__body__"), body); - } - - return v; -} - -bool AecDbCurveBase::ByJson(const SHJson::WValue &v) -{ - using namespace SHJson; - AssertWriteEnabled(); - AecDbObjXDataMap *pXMap = GetSpecialtyData(AcDb::kForWrite); - if (pXMap) - { - MCIt it = v.FindMember(_T("__xdata__")); - if (it != v.MemberEnd()) - return pXMap->ByJson(it->value); - } - return true; -} - -Acad::ErrorStatus AecDbCurveBase::setTransparency(const AcCmTransparency &trans, Adesk::Boolean doSubents) -{ - AssertWriteEnabled(); - return AcDbEntity::setTransparency(trans, doSubents); -} - -CString AecDbCurveBase::getUniqueName() const -{ - return _T(""); -} \ No newline at end of file +#include "stdafx.h" +#include +#include "AecDbCurveBase.h" +#include "AcGiViewDraw.h" +#include "AcGiExplodeDraw.h" +#include "simpleproperty.h" +#include "dbobjptr.h" +#include "AecDbObjXDataMap.h" +#include "AecDbEntityBase.h" +#include "dbgrip.h" +#include "AecGripCback.h" + +extern CString IDCreate(); + +ACRX_NO_CONS_DEFINE_MEMBERS(AecDbCurveBase, AcDbCurve); + +AecDbCurveBase::AecDbCurveBase(void) : AecDbEntityCommon() +{ +} + +AecDbCurveBase::~AecDbCurveBase(void) { } + +Adesk::UInt32 AecDbCurveBase::subViewportDrawLogicalFlags(AcGiViewportDraw * vd) +{ + // 基类实现是 protected,只能在这里取;后续计算交给 Common。 + return AecDbEntityCommon::base_ViewportDrawLogicalFlags( + AcDbCurve::subViewportDrawLogicalFlags(vd)); +} + +Adesk::UInt32 AecDbCurveBase::subSetAttributes(AcGiDrawableTraits * traits) +{ + // 基类实现是 protected,只能在这里取;后续计算交给 Common。 + return AecDbEntityCommon::base_SetAttributes( + AcDbCurve::subSetAttributes(traits)); +} + +Adesk::Boolean AecDbCurveBase::subWorldDraw(AcGiWorldDraw *pWd) +{ + // 具体实现与另一条根共用 AecDbEntityCommon::base_WorldDraw, + // 这里只保留 AcGiDrawable 虚函数这一侧的入口。 + return AecDbEntityCommon::base_WorldDraw(pWd); +} + +void AecDbCurveBase::subViewportDraw(AcGiViewportDraw* pMode) +{ + // 具体实现与另一条根共用 AecDbEntityCommon::base_ViewportDraw, + // 这里只保留 AcGiDrawable 虚函数这一侧的入口。 + AecDbEntityCommon::base_ViewportDraw(pMode); +} + +//保存代理实体图元 +void AecDbCurveBase::saveAs(AcGiWorldDraw *pWd,AcDb::SaveType saveType) +{ + // 具体实现与另一条根共用 AecDbEntityCommon::base_SaveAs, + // 这里只保留 AcGiDrawable 虚函数这一侧的入口。 + AecDbEntityCommon::base_SaveAs(pWd, saveType); +} + +Adesk::Boolean AecDbCurveBase::CallWorldDraw(AcGiWorldDraw *pWd) +{ + // 虚拟调用,回到最派生类的 subWorldDraw + return subWorldDraw(pWd); +} + +Acad::ErrorStatus AecDbCurveBase::subExplode(AcDbVoidPtrArray& entitySet) const +{ + // 具体实现与另一条根共用 AecDbEntityCommon::base_Explode, + // 这里只保留虚函数这一侧的入口。 + return AecDbEntityCommon::base_Explode(entitySet); +} + +Acad::ErrorStatus AecDbCurveBase::subGetGeomExtents(AcDbExtents& extents) const +{ + // 具体实现与另一条根共用 AecDbEntityCommon::base_GetGeomExtents, + // 这里只保留 AcDbEntity 虚函数这一侧的入口。 + return AecDbEntityCommon::base_GetGeomExtents(extents); +} + + +void AecDbCurveBase::subList() const +{ + AcDbCurve::subList(); +} + +Acad::ErrorStatus AecDbCurveBase::setColorIndex(Adesk::UInt16 color,Adesk::Boolean doSubents/* = true*/) +{ + assertWriteEnabled(); + AecDbObjXDataMap* pMap = GetSpecialtyData(); + if (pMap != NULL) + { + int nCr = 0; + if (pMap->GetAt(_T("COLOR"),nCr)) + { + pMap->SetAt(_T("COLOR"),color); + } + } + return AcDbCurve::setColorIndex(color,doSubents); +} + +Acad::ErrorStatus AecDbCurveBase::subIntersectWith(const AcDbEntity* ent, + AcDb::Intersect intType, + AcGePoint3dArray& points, + INT_PTR thisGsMarker, + INT_PTR otherGsMarker) const +{ + assertReadEnabled(); + + Acad::ErrorStatus es; + AcDbCurve* pNaCrv = GetNativeCurve(); + if (pNaCrv != NULL) + { + //放开后很慢 + es = pNaCrv->intersectWith(ent,intType,points,thisGsMarker,otherGsMarker); + } + + //EXTEND 仅仅需要 m_pBaseCurve 求交 + struct resbuf rb; + acedGetVar(_T("CMDNAMES"),&rb); + if (_tcscmp(rb.resval.rstring,_T("EXTEND")) != 0) + { + int expMode = GetExplodeMode(); + if (expMode == 2) + { + return Acad::eNotImplementedYet; + } + + const AcDbVoidPtrArray& entSet = Get2DBuffer(); + es = Acad::eNotApplicable; + + int len = entSet.length(); + for(int i = 0; i < len; i++) + { + AcDbEntity *pEnt = (AcDbEntity *)entSet[i]; + if (pEnt != NULL && Acad::eOk == pEnt->intersectWith(ent, intType, points, 0, otherGsMarker) ) + { + es = Acad::eOk; + } + } + } + return es; +} + +Acad::ErrorStatus AecDbCurveBase::subIntersectWith(const AcDbEntity* ent, + AcDb::Intersect intType, + const AcGePlane& projPlane, + AcGePoint3dArray& points, + INT_PTR thisGsMarker, + INT_PTR otherGsMarker) const +{ + assertReadEnabled(); + + Acad::ErrorStatus es; + AcDbCurve* pNaCrv = GetNativeCurve(); + if (pNaCrv != NULL) + { + //放开后很慢 + es = pNaCrv->intersectWith(ent,intType,points,thisGsMarker,otherGsMarker); + } + + int expMode = GetExplodeMode(); + if (expMode == 2) + { + return Acad::eNotImplementedYet; + } + + //EXTEND 仅仅需要 m_pBaseCurve 求交 + struct resbuf rb; + acedGetVar(_T("CMDNAMES"),&rb); + if (_tcscmp(rb.resval.rstring,_T("EXTEND")) != 0) + { + const AcDbVoidPtrArray& entSet = Get2DBuffer(); + es = Acad::eNotApplicable; + + int len = entSet.length(); + for (int i = 0; i < len; i++) + { + AcDbEntity *pEnt = (AcDbEntity *)entSet[i]; + if (pEnt != NULL && Acad::eOk == pEnt->intersectWith(ent, intType, projPlane, points, 0, otherGsMarker) ) + { + es = Acad::eOk; + } + } + } + return es; +} + +Acad::ErrorStatus AecDbCurveBase::subSetPropertiesFrom( const AcDbEntity* pEntity, Adesk::Boolean doSubents/* = Adesk::kTrue*/) +{ + assertWriteEnabled(); + Acad::ErrorStatus es = AcDbCurve::setPropertiesFrom(pEntity, doSubents); + + // 颜色 + { + setColorIndex(pEntity->colorIndex()); + } + + //图层 + if (database() == NULL || + database() == pEntity->database()) + { + { + setLayer(layerId()); + } + + // 线型 + { + setLinetype(pEntity->linetypeId()); + } + +#if ARX > 16 + // 材质 + { + setMaterial(pEntity->materialId()); + } +#endif + } + + // 线型比例 + { + setLinetypeScale(pEntity->linetypeScale()); + } + + // 可见性. 总是被复制 + setVisibility(pEntity->visibility()); + + return es; +} + +#if (ARX > 15) +Acad::ErrorStatus AecDbCurveBase::subGetOsnapPoints( AcDb::OsnapMode osnapMode, + INT_PTR gsSelectionMark, + const AcGePoint3d& ptPick, + const AcGePoint3d& lastPoint, + const AcGeMatrix3d& viewXform, + AcGePoint3dArray& snapPoints, + AcDbIntArray& geomIds) const +{ + return AecDbEntityCommon::base_GetOsnapPoints(osnapMode, gsSelectionMark, ptPick, + lastPoint, viewXform, snapPoints, geomIds); +} + +Acad::ErrorStatus AecDbCurveBase::subGetOsnapPoints( AcDb::OsnapMode osnapMode, + INT_PTR gsSelectionMark, + const AcGePoint3d& ptPick, + const AcGePoint3d& lastPoint, + const AcGeMatrix3d& viewXform, + AcGePoint3dArray& snapPoints, + AcDbIntArray& geomIds, + const AcGeMatrix3d& insersionMat) const +{ + assertReadEnabled(); + return getOsnapPoints(osnapMode,gsSelectionMark,ptPick,lastPoint,viewXform,snapPoints,geomIds); +} +#endif + +#if ARX>15 +void AecDbCurveBase::subGripStatus(const AcDb::GripStat status) +{ + +} + +Acad::ErrorStatus AecDbCurveBase::subGetGripPoints ( AcDbGripDataPtrArray& grips, + const double curViewUnitSize, + const int gripSize, + const AcGeVector3d& curViewDir, + const int bitflags) const +{ + return Acad::eOk; +} + +Acad::ErrorStatus AecDbCurveBase::subMoveGripPointsAt(const AcDbVoidPtrArray& appData,const AcGeVector3d& offset,const int bitflags) +{ + return Acad::eOk; +} +#endif + +Acad::ErrorStatus AecDbCurveBase::subGetGripPoints (AcGePoint3dArray& gripPoints,AcDbIntArray& osnapModes,AcDbIntArray& geomIds) const +{ + assertReadEnabled(); + return Acad::eOk; +} + +Acad::ErrorStatus AecDbCurveBase::subMoveGripPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset) +{ + assertWriteEnabled(); + return Acad::eOk; +} + +Acad::ErrorStatus AecDbCurveBase::subGetStretchPoints(AcGePoint3dArray& stretchPoints) const +{ + assertReadEnabled(); + return Acad::eOk; +} + +Acad::ErrorStatus AecDbCurveBase::subMoveStretchPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset) +{ + assertWriteEnabled(); + return Acad::eOk; +} + +Acad::ErrorStatus AecDbCurveBase::subTransformBy(const AcGeMatrix3d& xform) +{ + assertWriteEnabled(); + return Acad::eOk; +} + +Acad::ErrorStatus AecDbCurveBase::subGetTransformedCopy(const AcGeMatrix3d& xform,AcDbEntity*& pEnt) const +{ + assertReadEnabled(); + AcDbEntity *pCloned = (AcDbEntity *)clone(); + pCloned->setLayer(layerId());// + ((AecDbCurveBase*)pCloned)->m_nDrawDimCur = m_nDrawDimCur; + + Acad::ErrorStatus es = pCloned->transformBy(xform); + if(es == Acad::eOk) + pEnt = pCloned; + else + DELETE_PTR(pCloned); + return es; +} + +Acad::ErrorStatus AecDbCurveBase::subDeepClone( AcDbObject* pOwner, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary) const +{ + // 具体实现与 AecDbEntityBase 共用 AecDbEntityCommon::base_DeepClone, + // 这里只保留 AcDbObject 虚函数这一侧的入口。 + return AecDbEntityCommon::base_DeepClone(pOwner, pClonedObject, idMap, isPrimary); +} + +Acad::ErrorStatus AecDbCurveBase::subWblockClone(AcRxObject* pOwner, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary) const +{ + return AecDbEntityCommon::base_WblockClone(pOwner, pClonedObject, idMap, isPrimary); +} + +Acad::ErrorStatus AecDbCurveBase::CallAcDbWblockClone(AcRxObject* pOwner, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary) const +{ + return AcDbCurve::subWblockClone(pOwner, pClonedObject, idMap, isPrimary); +} + +Adesk::Boolean AecDbCurveBase::isClosed() const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Adesk::Boolean bRet = pCurve->isClosed(); + return bRet; + } + else + { + return AcDbCurve::isClosed(); + } +} + +Adesk::Boolean AecDbCurveBase::isPeriodic() const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Adesk::Boolean bRet = pCurve->isPeriodic(); + return bRet; + } + else + { + return AcDbCurve::isPeriodic(); + } +} + +Acad::ErrorStatus AecDbCurveBase::getStartParam(double&pa) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getStartParam(pa); + return bRet; + } + else + { + return AcDbCurve::getStartParam(pa); + } +} + +Acad::ErrorStatus AecDbCurveBase::getEndParam (double&pa) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getEndParam(pa); + return bRet; + } + else + { + return AcDbCurve::getEndParam(pa); + } +} + +Acad::ErrorStatus AecDbCurveBase::getStartPoint(AcGePoint3d&pt) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getStartPoint(pt); + return bRet; + } + else + { + return AcDbCurve::getStartPoint(pt); + } +} + +Acad::ErrorStatus AecDbCurveBase::getEndPoint (AcGePoint3d&pt) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getEndPoint(pt); + return bRet; + } + else + { + return AcDbCurve::getEndPoint(pt); + } +} + +Acad::ErrorStatus AecDbCurveBase::getPointAtParam(double pa, AcGePoint3d&pt) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getPointAtParam(pa,pt); + return bRet; + } + else + { + return AcDbCurve::getPointAtParam(pa,pt); + } +} + +Acad::ErrorStatus AecDbCurveBase::getParamAtPoint(const AcGePoint3d& pt, double&pa)const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getParamAtPoint(pt,pa); + return bRet; + } + else + { + return AcDbCurve::getParamAtPoint(pt,pa); + } +} + +Acad::ErrorStatus AecDbCurveBase::getDistAtParam (double param, double& dist) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getDistAtParam(param,dist); + return bRet; + } + else + { + return AcDbCurve::getDistAtParam(param,dist); + } +} + +Acad::ErrorStatus AecDbCurveBase::getParamAtDist (double dist, double& param) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getParamAtDist(dist,param); + return bRet; + } + else + { + return AcDbCurve::getParamAtDist(dist,param); + } +} + +Acad::ErrorStatus AecDbCurveBase::getDistAtPoint (const AcGePoint3d&pt, double&dist)const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getDistAtPoint(pt,dist); + return bRet; + } + else + { + return AcDbCurve::getDistAtPoint(pt,dist); + } +} + +Acad::ErrorStatus AecDbCurveBase::getPointAtDist (double dist, AcGePoint3d&pt) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getPointAtDist(dist,pt); + return bRet; + } + else + { + return AcDbCurve::getPointAtDist(dist,pt); + } +} + +Acad::ErrorStatus AecDbCurveBase::getFirstDeriv (double param,AcGeVector3d& firstDeriv) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getFirstDeriv(param,firstDeriv); + return bRet; + } + else + { + return AcDbCurve::getFirstDeriv(param,firstDeriv); + } +} + +Acad::ErrorStatus AecDbCurveBase::getFirstDeriv (const AcGePoint3d&pt,AcGeVector3d& firstDeriv) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getFirstDeriv(pt,firstDeriv); + return bRet; + } + else + { + return AcDbCurve::getFirstDeriv(pt,firstDeriv); + } +} + +Acad::ErrorStatus AecDbCurveBase::getSecondDeriv (double param,AcGeVector3d& secDeriv) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getSecondDeriv(param,secDeriv); + return bRet; + } + else + { + return AcDbCurve::getSecondDeriv(param,secDeriv); + } +} + +Acad::ErrorStatus AecDbCurveBase::getSecondDeriv (const AcGePoint3d&pt,AcGeVector3d& secDeriv) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getSecondDeriv(pt,secDeriv); + return bRet; + } + else + { + return AcDbCurve::getSecondDeriv(pt,secDeriv); + } +} + +Acad::ErrorStatus AecDbCurveBase::getClosestPointTo(const AcGePoint3d& givenPnt, + AcGePoint3d& pointOnCurve, + Adesk::Boolean extend) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getClosestPointTo(givenPnt,pointOnCurve,extend); + return bRet; + } + else + { + return AcDbCurve::getClosestPointTo(givenPnt,pointOnCurve,extend); + } +} + +Acad::ErrorStatus AecDbCurveBase::getClosestPointTo(const AcGePoint3d& givenPnt, + const AcGeVector3d& direction, + AcGePoint3d& pointOnCurve, + Adesk::Boolean extend) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getClosestPointTo(givenPnt,direction,pointOnCurve,extend); + return bRet; + } + else + { + return AcDbCurve::getClosestPointTo(givenPnt,direction,pointOnCurve,extend); + } +} + +Acad::ErrorStatus AecDbCurveBase::getOrthoProjectedCurve(const AcGePlane& plane, + AcDbCurve*& projCrv) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + AcDbCurve* pCurve1 = NULL; + Acad::ErrorStatus bRet = pCurve->getOrthoProjectedCurve(plane,pCurve1); + if (bRet == Acad::eOk) + { + AecDbCurveBase* pCurveEnt = (AecDbCurveBase*)clone(); + bRet = pCurveEnt->SetBaseCurve(pCurve1); + projCrv = pCurveEnt; + + DELETE_PTR(pCurve1); + } + return bRet; + } + else + { + return AcDbCurve::getOrthoProjectedCurve(plane,projCrv); + } +} + +Acad::ErrorStatus AecDbCurveBase::getProjectedCurve(const AcGePlane& plane, + const AcGeVector3d& projDir, + AcDbCurve*& projCrv) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + AcDbCurve* pCurve1 = NULL; + Acad::ErrorStatus bRet = pCurve->getProjectedCurve(plane,projDir,pCurve1); + if (bRet == Acad::eOk) + { + AecDbCurveBase* pCurveEnt = (AecDbCurveBase*)clone(); + bRet = pCurveEnt->SetBaseCurve(pCurve1); + projCrv = pCurveEnt; + + DELETE_PTR(pCurve1); + } + return bRet; + } + else + { + return AcDbCurve::getProjectedCurve(plane,projDir,projCrv); + } +} + +Acad::ErrorStatus AecDbCurveBase::getOffsetCurves(double offsetDist, + AcDbVoidPtrArray& offsetCurves) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + AcDbVoidPtrArray offsetCurves0; + Acad::ErrorStatus bRet = pCurve->getOffsetCurves(offsetDist,offsetCurves0); + if (bRet == Acad::eOk) + { + for (long i = 0; i < offsetCurves0.length(); i++) + { + AecDbCurveBase*pCurveEnt = (AecDbCurveBase*)clone(); + pCurveEnt->SetBaseCurve((AcDbCurve*)offsetCurves0[i]); + offsetCurves.append(pCurveEnt); + } + + deleteArrayVoidPtrs(offsetCurves0); + } + return bRet; + } + else + { + return AcDbCurve::getOffsetCurves(offsetDist,offsetCurves); + } +} + +Acad::ErrorStatus AecDbCurveBase::getOffsetCurvesGivenPlaneNormal( + const AcGeVector3d& normal, + double offsetDist, + AcDbVoidPtrArray& offsetCurves) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + AcDbVoidPtrArray offsetCurves0; + Acad::ErrorStatus bRet = pCurve->getOffsetCurvesGivenPlaneNormal(normal,offsetDist,offsetCurves0); + if (bRet == Acad::eOk) + { + for (long i = 0; i < offsetCurves0.length(); i++) + { + AecDbCurveBase*pCurveEnt = (AecDbCurveBase*)clone(); + pCurveEnt->SetBaseCurve((AcDbCurve*)offsetCurves0[i]); + offsetCurves.append(pCurveEnt); + } + + deleteArrayVoidPtrs(offsetCurves0); + } + return bRet; + } + else + return AcDbCurve::getOffsetCurvesGivenPlaneNormal(normal,offsetDist,offsetCurves); +} + +Acad::ErrorStatus AecDbCurveBase::getSpline(AcDbSpline*& spline) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getSpline(spline); + return bRet; + } + else + { + return AcDbCurve::getSpline(spline); + } +} + +Acad::ErrorStatus AecDbCurveBase::getSplitCurves (const AcGeDoubleArray& params, + AcDbVoidPtrArray& curveSegments) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + AcDbVoidPtrArray curveSegments0; + Acad::ErrorStatus bRet = pCurve->getSplitCurves(params,curveSegments0); + if (bRet == Acad::eOk) + { + for (long i = 0; i < curveSegments0.length(); i++) + { + AecDbCurveBase*pCurveEnt = (AecDbCurveBase*)clone(); + AecDbObjXDataMap* pXDataMap = pCurveEnt->GetSpecialtyData(); + if (pXDataMap != NULL) + { + CString sNo; + if (pXDataMap->GetAt(KEY_NO,sNo)) + { + sNo = IDCreate(); + pXDataMap->SetAt(KEY_NO,sNo); + } + } + pCurveEnt->SetBaseCurve((AcDbCurve*)curveSegments0[i]); + curveSegments.append(pCurveEnt); + } + + deleteArrayVoidPtrs(curveSegments0); + } + return bRet; + } + else + { + return AcDbCurve::getSplitCurves(params,curveSegments); + } +} + +Acad::ErrorStatus AecDbCurveBase::getSplitCurves (const AcGePoint3dArray& points, + AcDbVoidPtrArray& curveSegments) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + AcDbVoidPtrArray curveSegments0; + Acad::ErrorStatus bRet = pCurve->getSplitCurves(points,curveSegments0); + if (bRet == Acad::eOk) + { + for (long i = 0; i < curveSegments0.length(); i++) + { + AecDbCurveBase*pCurveEnt = (AecDbCurveBase*)clone(); + AecDbObjXDataMap* pXDataMap = pCurveEnt->GetSpecialtyData(); + if (pXDataMap != NULL) + { + CString sNo; + if (pXDataMap->GetAt(KEY_NO,sNo)) + { + sNo = IDCreate(); + pXDataMap->SetAt(KEY_NO,sNo); + } + } + pCurveEnt->SetBaseCurve((AcDbCurve*)curveSegments0[i]); + curveSegments.append(pCurveEnt); + } + + deleteArrayVoidPtrs(curveSegments0); + } + return bRet; + } + else + { + return AcDbCurve::getSplitCurves(points,curveSegments); + } +} + +Acad::ErrorStatus AecDbCurveBase::extend(double newParam) +{ + AssertWriteEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->extend(newParam); + if (bRet == Acad::eOk) + { + //bRet = SetBaseCurve(pCurve); + } + return bRet; + } + else + { + return AcDbCurve::extend(newParam); + } +} + +static AcDbArc* FormatArc(const AcGePoint3d& ptGe1,const AcGePoint3d& ptGe2,const AcGePoint3d& ptGe3) +{ + AcDbArc* pArcThis = NULL; + AcGeCircArc3d cirArc3d; + cirArc3d.set(ptGe1,ptGe2,ptGe3);//可能逆弧 + + AcGeVector3d vtNorm = cirArc3d.normal(); + if (vtNorm.isParallelTo(AcGeVector3d::kZAxis)) + { + if (!vtNorm.isCodirectionalTo(AcGeVector3d::kZAxis)) + { + vtNorm.negate();//相反 + } + } + AcDbCircle cir; + cir.setCenter(cirArc3d.center()); + cir.setRadius(cirArc3d.radius()); + cir.setNormal(vtNorm); + + AcGePoint3dArray arPts; + arPts.append(ptGe1); + arPts.append(ptGe3); + + AcDbVoidPtrArray arCurPtrs; + cir.getSplitCurves(arPts,arCurPtrs); + + double dPara = 0.0; + AcDbCurve* pCurve = NULL; + for (int j = 0;j < arCurPtrs.length();j++) + { + pCurve = (AcDbCurve*)arCurPtrs.at(j); + if (pCurve != NULL) + { + if (Acad::eOk == pCurve->getParamAtPoint(ptGe2,dPara))//中点在圆弧上 + { + AcDbArc* pArc = AcDbArc::cast(pCurve); + if (pArc != NULL) + { + pArcThis = pArc; + arCurPtrs.removeAt(j); + break; + } + } + } + } + deleteArrayVoidPtrs(arCurPtrs); + return pArcThis; +} + +static AcGePoint3d GetArcMidPoint(AcDbArc* pArc) +{ + double dSta = 0.0,dEnd = 0.0; + pArc->getStartParam(dSta); + pArc->getEndParam(dEnd); + + AcGePoint3d ptMid; + pArc->getPointAtParam((dSta + dEnd) / 2.0,ptMid); + + return ptMid; +} + +Acad::ErrorStatus AecDbCurveBase::extend(Adesk::Boolean extendStart, + const AcGePoint3d& toPoint) +{ + AssertWriteEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + AcGePoint3d ptS,ptE; + pCurve->getStartPoint(ptS); + pCurve->getEndPoint(ptE); + + if (toPoint.distanceTo(ptS) < toPoint.distanceTo(ptE)) + extendStart = Adesk::kTrue; + else + extendStart = Adesk::kFalse; + + Acad::ErrorStatus bRet = pCurve->extend(extendStart,toPoint); + if (bRet == Acad::eOk) + { + //延长到外部一点 + //GetNativeCurve + //bRet = SetBaseCurve(pCurve); + } + else + { + //内部,缩短到内部一点 + AcDbLine* pLn = AcDbLine::cast(pCurve); + if (pLn != NULL) + { + if (extendStart) + { + pLn->setStartPoint(toPoint); + } + else + { + pLn->setEndPoint(toPoint); + } + bRet = Acad::eOk; + } + + AcDbArc* pArc = AcDbArc::cast(pCurve); + if (pArc != NULL) + { + if (extendStart)//开始缩短 + { + AcGePoint3d ptE,ptM; + pArc->getEndPoint(ptE); + ptM = GetArcMidPoint(pArc); + + AcDbArc* pArc2 = FormatArc(toPoint,ptM,ptE); + if (pArc2 != NULL) + { + pArc->setStartAngle(pArc2->startAngle()); + pArc->setEndAngle(pArc2->endAngle()); + delete pArc2; + } + } + else//末尾缩短 + { + AcGePoint3d ptE,ptM; + pArc->getStartPoint(ptE); + ptM = GetArcMidPoint(pArc); + + AcDbArc* pArc2 = FormatArc(ptE,ptM,toPoint); + if (pArc2 != NULL) + { + pArc->setStartAngle(pArc2->startAngle()); + pArc->setEndAngle(pArc2->endAngle()); + delete pArc2; + } + } + bRet = Acad::eOk; + } + } + return bRet; + } + else + { + return AcDbCurve::extend(extendStart,toPoint); + } +} + +Acad::ErrorStatus AecDbCurveBase::getArea(double&area) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getArea(area); + return bRet; + } + else + { + return AcDbCurve::getArea(area); + } +} + +Adesk::Boolean AecDbCurveBase::isPlanar() const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Adesk::Boolean bRet = pCurve->isPlanar(); + return bRet; + } + else + { + return AcDbCurve::isPlanar(); + } +} + +Acad::ErrorStatus AecDbCurveBase::getPlane(AcGePlane&plane, AcDb::Planarity&pr) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + Acad::ErrorStatus bRet = pCurve->getPlane(plane,pr); + return bRet; + } + else + { + return AcDbCurve::getPlane(plane,pr); + } +} + +void AecDbCurveBase::getEcs(AcGeMatrix3d& retVal) const +{ + assertReadEnabled(); + + AcDbCurve* pCurve = GetNativeCurve(); + if (pCurve != NULL) + { + pCurve->getEcs(retVal); + } + else + { + AcDbCurve::getEcs(retVal); + } +} + +Acad::ErrorStatus AecDbCurveBase::SetBaseCurve(const AcDbCurve* pDbCurve) +{ + return Acad::eNotImplementedYet; +} + +AcDbCurve* AecDbCurveBase::GetBaseCurve(bool bOrthoProjectToXY) const +{ + return NULL; +} + +AcDbCurve* AecDbCurveBase::GetNativeCurve() const +{ + return NULL; +} + +Acad::ErrorStatus AecDbCurveBase::dwgInFields (AcDbDwgFiler* pFiler) +{ + assertWriteEnabled () ; + + //----- Read parent class information first. + Acad::ErrorStatus es = AcDbCurve::dwgInFields (pFiler) ; + if ( es != Acad::eOk ) + return (es) ; + + return (pFiler->filerStatus ()) ; +} + +Acad::ErrorStatus AecDbCurveBase::dwgOutFields(AcDbDwgFiler* pFiler) const +{ + assertReadEnabled () ; + //----- Save parent class information first. + Acad::ErrorStatus es = AcDbCurve::dwgOutFields (pFiler) ; + if ( es != Acad::eOk ) + return (es) ; + + return (pFiler->filerStatus ()) ; +} + +Acad::ErrorStatus AecDbCurveBase::dxfInFields (AcDbDxfFiler* pFiler) +{ + assertWriteEnabled () ; + + //----- Read parent class information first. + Acad::ErrorStatus es = AcDbCurve::dxfInFields (pFiler) ; + if ( es != Acad::eOk ) + return (es) ; + + return (pFiler->filerStatus ()) ; +} + +Acad::ErrorStatus AecDbCurveBase::dxfOutFields(AcDbDxfFiler* pFiler) const +{ + assertReadEnabled () ; + //----- Save parent class information first. + Acad::ErrorStatus es = AcDbCurve::dxfOutFields (pFiler) ; + if ( es != Acad::eOk ) + return (es) ; + + return (pFiler->filerStatus ()) ; +} + +bool AecDbCurveBase::Draw2DBuffers(AcGiDraw &dc)const +{ + if (m_ar2DDrableBufPtrs_.isEmpty()) + { + return false; + } + AcDbEntity *pEnt = NULL; + for (int i = 0; i < m_ar2DDrableBufPtrs_.length(); ++i) + { + pEnt = (AcDbEntity *)m_ar2DDrableBufPtrs_[i]; + pEnt->setLayer(dc.GetLayerId()); + pEnt->setColorIndex(colorIndex()); + dc.DrawEntity(*pEnt); + } + return true; +} + +int AecDbCurveBase::ComparedTo(AecDbCurveBase* pCurOther) const +{ + return -1;//不做比较 +} + +double AecDbCurveBase::GetArea() const +{ + assertReadEnabled(); + + if (!Has3DBuffer()) + { + AcGiViewDraw dc(NULL,NULL); + Draw3d(dc); + } + + double dArea = 0.0,dAreaAll = 0.0; + AcDbVoidPtrArray arEntPtrs; + GetDraw3dables(arEntPtrs); + + AcDbEntity* pEnt = NULL; + for (int i = 0;i < arEntPtrs.length();i++) + { + pEnt = (AcDbEntity*)arEntPtrs.at(i); + + AcDb3dSolid* pSolid = AcDb3dSolid::cast(pEnt); + if (pSolid != NULL) + { + pSolid->getArea(dArea); + dAreaAll += fabs(dArea); + } + + AcDbRegion* pReg = AcDbRegion::cast(pEnt); + if (pReg != NULL) + { + pReg->getArea(dArea); + dAreaAll += fabs(dArea); + } + } + return dAreaAll; +} + +static AcGePoint3d MidPoint(AcGePoint3d& pt1, AcGePoint3d& pt2) +{ + return AcGePoint3d((pt1.x + pt2.x) / 2.0, + (pt1.y + pt2.y) / 2.0, + (pt1.z + pt2.z) / 2.0); +} + +typedef AcArray AcDbEntityArray; +Acad::ErrorStatus AecDbCurveBase::setTransparency(const AcCmTransparency &trans, Adesk::Boolean doSubents) +{ + AssertWriteEnabled(); + return AcDbEntity::setTransparency(trans, doSubents); +} + \ No newline at end of file diff --git a/SourceCode/Code2026/AecRxBase/AecDbEntityBase.cpp b/SourceCode/Code2026/AecRxBase/AecDbEntityBase.cpp index 4193989..b79d2d7 100644 --- a/SourceCode/Code2026/AecRxBase/AecDbEntityBase.cpp +++ b/SourceCode/Code2026/AecRxBase/AecDbEntityBase.cpp @@ -7,354 +7,70 @@ #include "AecDbObjXDataMap.h" #include "AecGripCback.h" -#include "GrPolyhedronGeometry.h" - -using namespace GrPolyhedronGeometry; - -BOOL ReadModelXData(LPCTSTR pszKey, AecDbObjXDataMap& xDataMap, AcDbDatabase* pDb); -BOOL WriteModelXData(LPCTSTR pszKey, AecDbObjXDataMap& xDataMap, AcDbDatabase* pDb); -extern CString IDCreate(); - -const Adesk::UInt16 kColorByLayer = 256; -static const Adesk::UInt16 kRed = 1; - -#ifndef _ttof -#define _ttof(pszVal) _tcstod((pszVal), NULL) -#endif - -namespace -{ - void FreeBuffer(int n, AcDbVoidPtrArray& arEntPtrs) - { - AcDbEntity* pEnt = NULL; - while (arEntPtrs.length() > n) - { - pEnt = (AcDbEntity*)arEntPtrs.last(); - pEnt->erase(); - pEnt->close(); - DELETE_PTR(pEnt); - arEntPtrs.removeLast(); - } - } -} - ACRX_NO_CONS_DEFINE_MEMBERS(AecDbEntityBase, AcDbEntity); -AecDbEntityBase::AecDbEntityBase(void) +AecDbEntityBase::AecDbEntityBase(void): AecDbEntityCommon() { - m_eExplodeOrDrawType = kWroldDraw; - m_nDrawDimCur = -1; } -AecDbEntityBase::~AecDbEntityBase(void) -{ - FreeBuffer(0, m_ar2DDrableBufPtrs_); - FreeBuffer(0, m_ar3DDrableBufPtrs_); -} - -static void ReleaseEntSet(AcDbVoidPtrArray &entSet) -{ - while(!entSet.isEmpty()) - { - AcDbEntity *pEnt = AcDbEntity::cast((AcDbEntity *)entSet[0]); - if (pEnt != NULL) - { - DELETE_PTR(pEnt); - } - entSet.removeAt(0); - } -} +AecDbEntityBase::~AecDbEntityBase(void) { } Adesk::UInt32 AecDbEntityBase::subViewportDrawLogicalFlags(AcGiViewportDraw * vd) { - Adesk::UInt32 nRet = AcDbEntity::subViewportDrawLogicalFlags(vd); - - Adesk::UInt32 nFlagNew = nRet; - int nDrawMode = AecDbEntityBase::GetDrawMode(); - int nDraw = GetDrawDimOnType(nDrawMode, k2Dand3D); - - if (nDraw != 3) - { - nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw; - } - else - { - nFlagNew |= AcGiDrawable::kDrawableRegenDraw;//256; - } - return nFlagNew; + // 基类实现是 protected,只能在这里取;后续计算交给 Common。 + return AecDbEntityCommon::base_ViewportDrawLogicalFlags( + AcDbEntity::subViewportDrawLogicalFlags(vd)); } Adesk::UInt32 AecDbEntityBase::subSetAttributes(AcGiDrawableTraits * traits) { - Adesk::UInt32 nRet = AcDbEntity::subSetAttributes(traits); - int nDrawMode = AecDbEntityBase::GetDrawMode(); - int nDraw = GetDrawDimOnType(nDrawMode, k2Dand3D); - - Adesk::UInt32 nFlagNew = nRet; - nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw; - - return nFlagNew; + // 基类实现是 protected,只能在这里取;后续计算交给 Common。 + return AecDbEntityCommon::base_SetAttributes( + AcDbEntity::subSetAttributes(traits)); } Adesk::Boolean AecDbEntityBase::subWorldDraw(AcGiWorldDraw *pWd) { - assertReadEnabled(); - - m_eExplodeOrDrawType = kWroldDraw; - AcGiViewDraw dc(pWd, NULL); - dc.SetDrawRaw(this); - - //1.如果是保存代理图形 - AcGiRegenType nRegenType = pWd->regenType(); - if (nRegenType == kAcGiSaveWorldDrawForProxy) - { - ads_point pt; - struct resbuf rb; - acedGetVar(_T("VIEWDIR"),&rb); - ads_point_set(rb.resval.rpoint,pt); - - ads_point viewDir; - acdbUcs2Wcs(pt,viewDir,false); - - if (fabs(viewDir[X]) > 1.0e-6 || fabs(viewDir[Y]) > 1.0e-6) - { - Draw3d(dc); - m_nDrawDimCur = 3; - } - else - { - Draw2d(dc); - m_nDrawDimCur = 2; - } - return Adesk::kTrue; - } - - //设属性 - dc.SetLayer(_T("0")); - dc.SetColor(256); - - //如果图层关闭 - AcDbLayerTableRecordPointer pLayer; - if ( Acad::eOk == pLayer.open(layerId(), AcDb::kForRead) ) - { - if ( pLayer->isOff() ) - { - return Adesk::kTrue; - } - } - - int nDrawType = k2Dand3D; - int nDrawMode = AecDbEntityBase::GetDrawMode(); - int nDraw = GetDrawDimOnType(nDrawMode, k2Dand3D); - - if (nRegenType == kAcGiSaveWorldDrawForProxy - || nRegenType == kAcGiSaveWorldDrawForR12) - { - if (!!ownerId()) - { - pWd->subEntityTraits().setSelectionMarker(0); - dc.SetColor(colorIndex()); - dc.SetLayer(layerId()); - } - - if ((nDrawMode & DRAW_2D) && (nDrawType != k3DOnly)) - { - Draw2d(dc); - m_nDrawDimCur = 2; - } - else if ((nDrawMode & DRAW_3D) && (nDrawType != k2DOnly)) - { - Draw3d(dc); - m_nDrawDimCur = 3; - } - return Adesk::kTrue; - } - return Adesk::kFalse; + // 具体实现与另一条根共用 AecDbEntityCommon::base_WorldDraw, + // 这里只保留 AcGiDrawable 虚函数这一侧的入口。 + return AecDbEntityCommon::base_WorldDraw(pWd); } void AecDbEntityBase::subViewportDraw(AcGiViewportDraw* pMode) { - assertReadEnabled(); - 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(); - AcGiViewDraw dc(NULL, pMode); - dc.SetDrawRaw(this); - - // 设属性 - dc.SetLayer(_T("0")); - dc.SetColor(256); - - //如果图层关闭 - AcDbLayerTableRecordPointer pLayer; - if ( Acad::eOk == pLayer.open(layerId(), AcDb::kForRead) ) - { - if ( pLayer->isOff() ) - { - return; - } - } - - if (!!ownerId()) - { - pMode->subEntityTraits().setSelectionMarker(0); - dc.SetColor(colorIndex()); - dc.SetLayer(layerId()); - } - - int nDrawMode = AecDbEntityBase::GetDrawMode(); - int nDraw = GetDrawDimOnType(nDrawMode, k2Dand3D); - - if (nDraw == 3) - { - if ( nRegenType == kAcGiRenderCommand - || nRegenType == kAcGiHideOrShadeCommand - || vp.isPerspective() - || vtViewDrt != AcGeVector3d(0,0,1)) - { - Draw3d(dc); - m_nDrawDimCur = 3; - } - else - { - Draw2d(dc); - m_nDrawDimCur = 2; - } - } - else if (nDraw == 1) - { - Draw2d(dc); - m_nDrawDimCur = 2; - } - else if (nDraw == 2) - { - Draw3d(dc); - m_nDrawDimCur = 3; - } + // 具体实现与另一条根共用 AecDbEntityCommon::base_ViewportDraw, + // 这里只保留 AcGiDrawable 虚函数这一侧的入口。 + AecDbEntityCommon::base_ViewportDraw(pMode); } //保存代理实体图元 void AecDbEntityBase::saveAs(AcGiWorldDraw *pWd,AcDb::SaveType saveType) { - AecDbObjXDataMap xDataMap; - ReadModelXData(EW_EARTHWORMINIT, xDataMap, NULL); - int nSaveToProxy(0); - xDataMap.GetAt(_T("SaveToProxy"), nSaveToProxy); - if (nSaveToProxy == 0) // 不保存代理图形 - return; + // 具体实现与另一条根共用 AecDbEntityCommon::base_SaveAs, + // 这里只保留 AcGiDrawable 虚函数这一侧的入口。 + AecDbEntityCommon::base_SaveAs(pWd, saveType); +} - AcGiRegenType rtype = pWd->regenType(); - if (rtype == kAcGiSaveWorldDrawForProxy) - { - subWorldDraw(pWd); - } - else - { - AcDbEntity::saveAs(pWd, saveType); - } +Adesk::Boolean AecDbEntityBase::CallWorldDraw(AcGiWorldDraw *pWd) +{ + // 虚拟调用,回到最派生类的 subWorldDraw + return subWorldDraw(pWd); } Acad::ErrorStatus AecDbEntityBase::subExplode(AcDbVoidPtrArray& entitySet) const { - ExplodeOrDrawType& eExplodeType = (ExplodeOrDrawType&)m_eExplodeOrDrawType; - eExplodeType = kExplode; - - int expMode = GetExplodeMode(); - if (expMode == 1) - { - GetDraw2dables(0,entitySet); - } - else if (expMode == 2) - { - GetDraw3dables(entitySet); - } - return Acad::eOk; + // 具体实现与另一条根共用 AecDbEntityCommon::base_Explode, + // 这里只保留虚函数这一侧的入口。 + return AecDbEntityCommon::base_Explode(entitySet); } Acad::ErrorStatus AecDbEntityBase::subGetGeomExtents(AcDbExtents& extents) const { - AcGePoint3d ptLow, ptUp; - - AcDbVoidPtrArray entSet; - int expMode = GetExplodeMode(); - if (expMode == 1) - { - entSet.append(Get2DBuffer()); - } - else if (expMode == 2) - { - entSet.append(Get3DBuffer()); - } - - BOOL bInit = TRUE; - AcGePoint3d ptMax,ptMin; - AcDbExtents ext,extT; - - int len = entSet.length(); - for (int i = 0; i < len; i++) - { - AcDbEntity *pEnt = (AcDbEntity *)entSet[i]; - - if (pEnt->getGeomExtents(extT) == Acad::eOk) - { - ext.addExt(extT); - } - } - ptLow = ext.minPoint(); - ptUp = ext.maxPoint(); - extents.set(ptLow, ptUp); - - return Acad::eOk; + // 具体实现与另一条根共用 AecDbEntityCommon::base_GetGeomExtents, + // 这里只保留 AcDbEntity 虚函数这一侧的入口。 + return AecDbEntityCommon::base_GetGeomExtents(extents); } -Acad::ErrorStatus AecDbEntityBase::subGet3dGeomExtents(AcDbExtents &extents) const -{ - AcDbVoidPtrArray entSet; - if (!Has3DBuffer()) - { - AcGiViewDraw dc(NULL, NULL); - Draw3d(dc); - } - entSet.append(Get3DBuffer()); - - if (entSet.isEmpty()) - return Acad::eNullExtents; - - BOOL bInit = TRUE; - AcGePoint3d ptMax, ptMin; - AcDbExtents ext, extT; - - int len = entSet.length(); - for (int i = 0; i < len; i++) - { - AcDbEntity *pEnt = (AcDbEntity *)entSet[i]; - - if (pEnt->getGeomExtents(extT) == Acad::eOk) - { - ext.addExt(extT); - } - } - - AcGePoint3d ptLow, ptUp; - ptLow = ext.minPoint(); - ptUp = ext.maxPoint(); - extents.set(ptLow, ptUp); - - return Acad::eOk; -} void AecDbEntityBase::subList() const { @@ -465,52 +181,16 @@ Acad::ErrorStatus AecDbEntityBase::subSetPropertiesFrom( const AcDbEntity* pEnti } #if (ARX > 15) -Acad::ErrorStatus AecDbEntityBase::subGetOsnapPoints( AcDb::OsnapMode osnapMode, - INT_PTR gsSelectionMark, - const AcGePoint3d& ptPick, - const AcGePoint3d& lastPoint, - const AcGeMatrix3d& viewXform, - AcGePoint3dArray& snapPoints, +Acad::ErrorStatus AecDbEntityBase::subGetOsnapPoints( AcDb::OsnapMode osnapMode, + INT_PTR gsSelectionMark, + const AcGePoint3d& ptPick, + const AcGePoint3d& lastPoint, + const AcGeMatrix3d& viewXform, + AcGePoint3dArray& snapPoints, AcDbIntArray& geomIds) const { - assertReadEnabled(); - - AcDbVoidPtrArray entSet; - int expMode = GetExplodeMode(); - if (expMode == 1) - { - entSet.append(Get2DBuffer()); - } - else if (expMode == 2) - { - entSet.append(Get3DBuffer()); - } - - Acad::ErrorStatus es = Acad::eOk; - 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; - } - return Acad::eOk; + return AecDbEntityCommon::base_GetOsnapPoints(osnapMode, gsSelectionMark, ptPick, + lastPoint, viewXform, snapPoints, geomIds); } Acad::ErrorStatus AecDbEntityBase::subGetOsnapPoints( AcDb::OsnapMode osnapMode, @@ -600,363 +280,7 @@ Acad::ErrorStatus AecDbEntityBase::subDeepClone( AcDbObject* pOwner, AcDbIdMapping& idMap, Adesk::Boolean isPrimary) const { - // You should always pass back pClonedObject == NULL - // if, for any reason, you do not actually clone it - // during this call. The caller should pass it in - // as NULL, but to be safe, we set it here as well. - // - pClonedObject = NULL; - - // If this object is in the idMap and is already - // cloned, then return. - // - bool isPrim = false; - if (isPrimary) - isPrim = true; - AcDbIdPair idPair(objectId(), (AcDbObjectId)NULL, - false, isPrim); - if (idMap.compute(idPair) && (idPair.value() != NULL)) - return Acad::eOk; - - // Create the clone - // - AecDbEntityBase *pClone = (AecDbEntityBase*)isA()->create(); - if (pClone != NULL) - pClonedObject = pClone; // set the return value - else - return Acad::eOutOfMemory; - - AcDbDeepCloneFiler filer; - dwgOut(&filer); - - filer.seek(0L, AcDb::kSeekFromStart); - pClone->dwgIn(&filer); - pClone->NewGUID(); - pClone->setLayer(layerId()); - - bool bOwnerXlated = false; - if (isPrimary) - { - AcDbBlockTableRecord *pBTR = - AcDbBlockTableRecord::cast(pOwner); - if (pBTR != NULL) - { - pBTR->appendAcDbEntity(pClone); - bOwnerXlated = true; - } - else - { - pOwner->database()->addAcDbObject(pClone); - } - } else { - pOwner->database()->addAcDbObject(pClone); - pClone->setOwnerId(pOwner->objectId()); - bOwnerXlated = true; - } - - // This must be called for all newly created objects - // in deepClone. It is turned off by endDeepClone() - // after it has translated the references to their - // new values. - // - pClone->setAcDbObjectIdsInFlux(); - pClone->disableUndoRecording(true); - - - // Add the new information to the idMap. We can use - // the idPair started above. - // - idPair.setValue(pClonedObject->objectId()); - idPair.setIsCloned(Adesk::kTrue); - idPair.setIsOwnerXlated(bOwnerXlated); - idMap.assign(idPair); - - // Using the filer list created above, find and clone - // any owned objects. - // - AcDbObjectId id; - while (filer.getNextOwnedObject(id)) { - - AcDbObject *pSubObject; - AcDbObject *pClonedSubObject; - - // Some object's references may be set to NULL, - // so don't try to clone them. - // - if (id == NULL) - continue; - - // Open the object and clone it. Note that we now - // set "isPrimary" to kFalse here because the object - // is being cloned, not as part of the primary set, - // but because it is owned by something in the - // primary set. - // - acdbOpenAcDbObject(pSubObject, id, AcDb::kForRead); - pClonedSubObject = NULL; - pSubObject->deepClone(pClonedObject, - pClonedSubObject, - idMap, Adesk::kFalse); - - // If this is a kDcInsert context, the objects - // may be "cheapCloned". In this case, they are - // "moved" instead of cloned. The result is that - // pSubObject and pClonedSubObject will point to - // the same object. So, we only want to close - // pSubObject if it really is a different object - // than its clone. - // - if (pSubObject != pClonedSubObject) - pSubObject->close(); - - // The pSubObject may either already have been - // cloned, or for some reason has chosen not to be - // cloned. In that case, the returned pointer will - // be NULL. Otherwise, since we have no immediate - // use for it now, we can close the clone. - // - if (pClonedSubObject != NULL) - pClonedSubObject->close(); - } - - //xdataMap 复制 - //到mep中找建立新的关系 - AecDbObjXDataMap* pXDataMapCloned = pClone->GetSpecialtyData(); - AecDbObjXDataMap* pXDataMap = (AecDbObjXDataMap*)GetSpecialtyData(); - - if (pXDataMapCloned != NULL) pXDataMapCloned->CopyFrom(pXDataMap); - if (pXDataMap != NULL && pXDataMapCloned != NULL) - { - //发送提资需要相同的ID - Adesk::Int16 nVal = acdbCurDwg()->useri4(); - if (nVal != KEY_NOPROTECT) - { - int nVt = 0; - CString sID = IDCreate(); - if (pXDataMapCloned->HasKey(KEY_NO, nVt)) - { - pXDataMapCloned->SetAt(KEY_NO, sID); - } - } - - AecDbObjXDataMap::It it = pXDataMap->Begin(); - AecDbObjXDataMap::It end = pXDataMap->End(); - - CString sKey; - CStringArray arHandKeys; - - AecXData cVal; - memset(&cVal,0,sizeof(AecXData)); - - AcDbObjectId idSrc,idCloned; - for (; it != end; ) - { - if (!pXDataMap->GetNext(it, sKey, cVal)) break; - if (cVal.nVt == AecXData::kTypeSoftId || cVal.nVt == AecXData::kTypeHardId)//soft,hard - { - idSrc.setFromOldId(cVal.nVal); - - AcDbObject *pSubObject; - AcDbObject *pClonedSubObject; - - // Some object's references may be set to NULL, - // so don't try to clone them. - // - if (idSrc == NULL) - continue; - - AcDbIdPair idPair2(idSrc, (AcDbObjectId)NULL, - false, isPrim); - if (idMap.compute(idPair2) && (idPair2.value() != NULL)) - { - if (pXDataMapCloned != NULL) - { - pXDataMapCloned->RemoveAt(sKey); - pXDataMapCloned->SetAt(sKey, idPair2.value(), cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); - } - continue; - } - - // Open the object and clone it. Note that we now - // set "isPrimary" to kFalse here because the object - // is being cloned, not as part of the primary set, - // but because it is owned by something in the - // primary set. - // - pSubObject = NULL; - acdbOpenAcDbObject(pSubObject, idSrc, AcDb::kForRead); - pClonedSubObject = NULL; - - if (pSubObject != NULL) - { - //只考虑上华AEC的实体 - LPCTSTR pszDxf = pSubObject->isA()->dxfName(); - if (_tcsstr(pszDxf, _T("AEC_'")) != NULL) - { - pSubObject->deepClone(pClonedObject, - pClonedSubObject, - idMap, Adesk::kFalse); - } - else - { - pSubObject->close(); - pSubObject = NULL; - } - } - - // If this is a kDcInsert context, the objects - // may be "cheapCloned". In this case, they are - // "moved" instead of cloned. The result is that - // pSubObject and pClonedSubObject will point to - // the same object. So, we only want to close - // pSubObject if it really is a different object - // than its clone. - // - if (pSubObject != pClonedSubObject) - pSubObject->close(); - - // The pSubObject may either already have been - // cloned, or for some reason has chosen not to be - // cloned. In that case, the returned pointer will - // be NULL. Otherwise, since we have no immediate - // use for it now, we can close the clone. - // - if (pClonedSubObject != NULL) - idCloned = pClonedSubObject->objectId(); - - if (pClonedSubObject != NULL) - pClonedSubObject->close(); - - if (pXDataMapCloned != NULL) - { - if (idCloned.isValid()) - { - pXDataMapCloned->RemoveAt(sKey); - pXDataMapCloned->SetAt(sKey, idCloned, cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); - } - else - { - - } - } - } - else if (sKey.Find(_T("$H")) != -1 && cVal.nVt == AecXData::kTypeString)//可能的实体句柄 - { - arHandKeys.Add(sKey); - } - } - - //2022-05-04 需要测试 - CString sHand; - AcDbHandle hd; - for (int n = 0; n < arHandKeys.GetSize(); n++) - { - sKey = arHandKeys.GetAt(n); - sHand = sKey; - sHand.TrimRight(_T("$H")); - - AcDbHandle handle(sHand); - - AcDbObjectId idSrc; - if (Acad::eOk == acdbCurDwg()->getAcDbObjectId(idSrc, false, handle)) - { - AcDbObject *pSubObject; - AcDbObject *pClonedSubObject; - - // Some object's references may be set to NULL, - // so don't try to clone them. - // - if (idSrc == NULL) - continue; - - AcDbIdPair idPair2(idSrc, (AcDbObjectId)NULL, - false, isPrim); - if (idMap.compute(idPair2) && (idPair2.value() != NULL)) - { - CString sKeyNew; - //sKey.Format(_T("%s$H"),szHand); - - if (pXDataMapCloned != NULL) - { - TCHAR szHand[19]; - memset(szHand, 0, sizeof(szHand)); - idPair2.value().handle().getIntoAsciiBuffer(szHand); - sKeyNew.Format(_T("%s$H"), szHand); - - pXDataMapCloned->RemoveAt(sKey); - pXDataMapCloned->SetAt(sKeyNew, szHand); - } - continue; - } - - // Open the object and clone it. Note that we now - // set "isPrimary" to kFalse here because the object - // is being cloned, not as part of the primary set, - // but because it is owned by something in the - // primary set. - // - pSubObject = NULL; - acdbOpenAcDbObject(pSubObject, idSrc, AcDb::kForRead); - pClonedSubObject = NULL; - - if (pSubObject != NULL) - { - //只考虑上华AEC的实体 - LPCTSTR pszDxf = pSubObject->isA()->dxfName(); - if (_tcsstr(pszDxf, _T("AEC_'")) != NULL) - { - pSubObject->deepClone(pClonedObject, - pClonedSubObject, - idMap, Adesk::kFalse); - } - else - { - pSubObject->close(); - pSubObject = NULL; - } - } - - // If this is a kDcInsert context, the objects - // may be "cheapCloned". In this case, they are - // "moved" instead of cloned. The result is that - // pSubObject and pClonedSubObject will point to - // the same object. So, we only want to close - // pSubObject if it really is a different object - // than its clone. - // - if (pSubObject != pClonedSubObject) - pSubObject->close(); - - // The pSubObject may either already have been - // cloned, or for some reason has chosen not to be - // cloned. In that case, the returned pointer will - // be NULL. Otherwise, since we have no immediate - // use for it now, we can close the clone. - // - if (pClonedSubObject != NULL) - idCloned = pClonedSubObject->objectId(); - - if (pClonedSubObject != NULL) - pClonedSubObject->close(); - - if (pXDataMapCloned != NULL) - { - CString sKeyNew; - TCHAR szHand[19]; - memset(szHand, 0, sizeof(szHand)); - - idCloned.handle().getIntoAsciiBuffer(szHand); - sKeyNew.Format(_T("%s$H"), szHand); - - pXDataMapCloned->RemoveAt(sKey); - pXDataMapCloned->SetAt(sKeyNew, szHand); - } - } - } - } - - // Leave pClonedObject open for the caller - return Acad::eOk; + return AecDbEntityCommon::base_DeepClone(pOwner, pClonedObject, idMap, isPrimary); } Acad::ErrorStatus AecDbEntityBase::subWblockClone(AcRxObject* pOwner, @@ -964,457 +288,15 @@ Acad::ErrorStatus AecDbEntityBase::subWblockClone(AcRxObject* pOwner, AcDbIdMapping& idMap, Adesk::Boolean isPrimary) const { - // You should always pass back pClonedObject == NULL - // if, for any reason, you do not actually clone it - // during this call. The caller should pass it in - // as NULL, but to be safe, we set it here as well. - // - pClonedObject = NULL; - - // If this is a fast wblock operation then no cloning - // should take place, so we simply call the base class's - // wblockClone() and return whatever it returns. - // - // For fast wblock, the source and destination databases - // are the same, so we can use that as the test to see - // if a fast wblock is in progress. - // - AcDbDatabase *pDest, *pOrig; - idMap.destDb(pDest); - idMap.origDb(pOrig); - if (pDest == pOrig) - return AcDbEntity::subWblockClone(pOwner, pClonedObject, - idMap, isPrimary); - - // If this is an Xref bind operation and this AsdkPoly - // entity is in Paper Space, then we don't want to - // clone because Xref bind doesn't support cloning - // entities in Paper Space. So we simply return - // Acad::eOk - // - AcDbObjectId pspace; - AcDbBlockTable *pTable; - database()->getSymbolTable(pTable, AcDb::kForRead); - pTable->getAt(ACDB_PAPER_SPACE, pspace); - pTable->close(); - - if (idMap.deepCloneContext() == AcDb::kDcXrefBind - && ownerId() == pspace) - return Acad::eOk; - - // If this object is in the idMap and is already - // cloned, then return. - // - bool isPrim = false; - if (isPrimary) - isPrim = true; - - AcDbIdPair idPair(objectId(), (AcDbObjectId)NULL, - false, isPrim); - if (idMap.compute(idPair) && (idPair.value() != NULL)) - return Acad::eOk; - - // The owner object can be either an AcDbObject, or an - // AcDbDatabase. AcDbDatabase is used if the caller is - // not the owner of the object being cloned (because it - // is being cloned as part of an AcDbHardPointerId - // reference). In this case, the correct ownership - // will be set during reference translation. So, if - // the owner is an AcDbDatabase, then pOwn will be left - // NULL here, and is used as a "flag" later. - // - - AcDbObject *pOwn = AcDbObject::cast(pOwner); - AcDbDatabase *pDb = AcDbDatabase::cast(pOwner); - if (pDb == NULL) - pDb = pOwn->database(); - - // STEP 1: - // Create the clone - // - AecDbEntityBase *pClone = (AecDbEntityBase *)isA()->create(); - if (pClone != NULL) - pClonedObject = pClone; // set the return value - else - return Acad::eOutOfMemory; - - // STEP 2: - // If the owner is an AcDbBlockTableRecord, go ahead - // and append the clone. If not, but we know who the - // owner is, set the clone's ownerId to it. Otherwise, - // we set the clone's ownerId to our own ownerId (in - // other words, the original owner Id). This Id will - // then be used later, in reference translation, as - // a key to finding who the new owner should be. This - // means that the original owner must also be cloned at - // some point during the wblock operation. - // EndDeepClone's reference translation aborts if the - // owner is not found in the idMap. - // - // The most common situation where this happens is - // AcDbEntity references to Symbol Table Records, such - // as the Layer an Entity is on. This is when you will - // have to pass in the destination database as the owner - // of the Layer Table Record. Since all Symbol Tables - // are always cloned in Wblock, you do not need to make - // sure that Symbol Table Record owners are cloned. - // - // However, if the owner is one of your own classes, - // then it is up to you to make sure that it gets - // cloned. This is probably easiest to do at the end - // of this function. Otherwise you may have problems - // with recursion when the owner, in turn, attempts - // to clone this object as one of its subObjects. - // - AcDbBlockTableRecord *pBTR = NULL; - if (pOwn != NULL) - pBTR = AcDbBlockTableRecord::cast(pOwn); - if (pBTR != NULL && isPrimary) { - pBTR->appendAcDbEntity(pClone); - } - else { - pDb->addAcDbObject(pClonedObject); - } - - // STEP 3: - // The AcDbWblockCloneFiler makes a list of - // AcDbHardOwnershipIds and AcDbHardPointerIds. These - // are the references which must be cloned during a - // Wblock operation. - // - AcDbWblockCloneFiler filer; - dwgOut(&filer); - - // STEP 4: - // Rewind the filer and read the data into the clone. - // - filer.seek(0L, AcDb::kSeekFromStart); - pClone->dwgIn(&filer); - pClone->NewGUID(); - - idMap.assign(AcDbIdPair(objectId(), pClonedObject->objectId(), Adesk::kTrue, - isPrim, (Adesk::Boolean)(pOwn != NULL))); - - pClonedObject->setOwnerId((pOwn != NULL) ? - pOwn->objectId() : ownerId()); - - // STEP 5: - // This must be called for all newly created objects - // in wblockClone. It is turned off by endDeepClone() - // after it has translated the references to their - // new values. - // - pClone->setAcDbObjectIdsInFlux(); - - // STEP 6: - // Add the new information to the idMap. We can use - // the idPair started above. We must also let the - // idMap entry know whether the clone's owner is - // correct, or needs to be translated later. - // - - // STEP 7: - // Using the filer list created above, find and clone - // any hard references. - // - - AcDbObjectId id; - while (filer.getNextHardObject(id)) - { - AcDbObject *pSubObject; - AcDbObject *pClonedSubObject; - - // Some object's references may be set to NULL, - // so don't try to clone them. - // - if (id == NULL) - continue; - - // If the referenced object is from a different - // database, such as an xref, do not clone it. - // - acdbOpenAcDbObject(pSubObject, id, AcDb::kForRead); - if (pSubObject->database() != database()) { - pSubObject->close(); - continue; - } - - // We can find out if this is an AcDbHardPointerId - // verses an AcDbHardOwnershipId, by seeing if we - // are the owner of the pSubObject. If we are not, - // then we cannot pass our clone in as the owner - // for the pSubObject's clone. In that case, we - // pass in our clone's database (the destination - // database). - // - // Note that we now set "isPrimary" to kFalse here - // because the object is being cloned, not as part - // of the primary set, but because it is owned by - // something in the primary set. - // - pClonedSubObject = NULL; - if (pSubObject->ownerId() == objectId()) { - pSubObject->wblockClone(pClone, - pClonedSubObject, - idMap, Adesk::kFalse); - } - else { - pSubObject->wblockClone(pClone->database(), - pClonedSubObject, - idMap, Adesk::kFalse); - } - pSubObject->close(); - - // The pSubObject may either already have been - // cloned, or for some reason has chosen not to be - // cloned. In that case, the returned pointer will - // be NULL. Otherwise, since we have no immediate - // use for it now, we can close the clone. - // - if (pClonedSubObject != NULL) - pClonedSubObject->close(); - } - - //xdataMap 复制 - //到mep中找建立新的关系 - AecDbObjXDataMap *pXDataMapCloned = pClone->GetSpecialtyData(); - AecDbObjXDataMap *pXDataMap = (AecDbObjXDataMap *)GetSpecialtyData(); - - if (pXDataMap != NULL && pXDataMapCloned != NULL) - { - //发送提资需要相同的ID - Adesk::Int16 nVal = acdbCurDwg()->useri4(); - if (nVal != KEY_NOPROTECT) - { - int nVt = 0; - CString sID = IDCreate(); - if (pXDataMapCloned->HasKey(KEY_NO, nVt)) - { - pXDataMapCloned->SetAt(KEY_NO, sID); - } - } - - AecDbObjXDataMap::It it = pXDataMap->Begin(); - AecDbObjXDataMap::It end = pXDataMap->End(); - - CString sKey; - CStringArray arHandKeys; - - AecXData cVal; - memset(&cVal, 0, sizeof(AecXData)); - - AcDbObjectId idSrc, idCloned; - for (; it != end;) - { - if (!pXDataMap->GetNext(it, sKey, cVal)) break; - if (cVal.nVt == AecXData::kTypeSoftId || cVal.nVt == AecXData::kTypeHardId)//soft,hard - { - idSrc.setFromOldId(cVal.nVal); - - AcDbObject *pSubObject; - AcDbObject *pClonedSubObject; - - // Some object's references may be set to NULL, - // so don't try to clone them. - // - if (idSrc == NULL) - continue; - - AcDbIdPair idPair2(idSrc, (AcDbObjectId)NULL, - false, isPrim); - if (idMap.compute(idPair2) && (idPair2.value() != NULL)) - { - if (pXDataMapCloned != NULL) - { - pXDataMapCloned->SetAt(sKey, idPair2.value(), cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); - } - continue; - } - - // Open the object and clone it. Note that we now - // set "isPrimary" to kFalse here because the object - // is being cloned, not as part of the primary set, - // but because it is owned by something in the - // primary set. - // - acdbOpenAcDbObject(pSubObject, idSrc, AcDb::kForRead); - pClonedSubObject = NULL; - - if (pSubObject->ownerId() == objectId()) { - pSubObject->wblockClone(pClone, - pClonedSubObject, - idMap, Adesk::kFalse); - } - else { - pSubObject->wblockClone(pClone->database(), - pClonedSubObject, - idMap, Adesk::kFalse); - } - - // If this is a kDcInsert context, the objects - // may be "cheapCloned". In this case, they are - // "moved" instead of cloned. The result is that - // pSubObject and pClonedSubObject will point to - // the same object. So, we only want to close - // pSubObject if it really is a different object - // than its clone. - // - if (pSubObject != pClonedSubObject) - pSubObject->close(); - - // The pSubObject may either already have been - // cloned, or for some reason has chosen not to be - // cloned. In that case, the returned pointer will - // be NULL. Otherwise, since we have no immediate - // use for it now, we can close the clone. - // - idCloned = pClonedSubObject->objectId(); - - if (pClonedSubObject != NULL) - pClonedSubObject->close(); - - if (pXDataMapCloned != NULL) - { - pXDataMapCloned->RemoveAt(sKey); - pXDataMapCloned->SetAt(sKey, idCloned, cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); - } - } - else if (sKey.Find(_T("$H")) != -1 && cVal.nVt == AecXData::kTypeString)//可能的实体句柄 - { - arHandKeys.Add(sKey); - } - } - } - return Acad::eOk; + return AecDbEntityCommon::base_WblockClone(pOwner, pClonedObject, idMap, isPrimary); } -//AEC派生 -int AecDbEntityBase::GetDrawMode() +Acad::ErrorStatus AecDbEntityBase::CallAcDbWblockClone(AcRxObject* pOwner, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary) const { - int nDrawMode = 3; - //从命名字典中取,默认3 - - return nDrawMode; -} - -void AecDbEntityBase::SetDrawMode(int nMode) -{ - //写入命名字典 -} - -//某些实体只有2D -int AecDbEntityBase::GetDrawDimOnType(int nDrawMode, int nDrawType) const -{ - int nDraw = 0; //0--NONE; 1--2D; 2--3D; 3--2D&3D; - if (nDrawMode == DRAW_2D && (nDrawType == k2DOnly || nDrawType == k2Dand3D)) - { - nDraw = 1; - } - else if (nDrawMode == DRAW_3D && (nDrawType == k3DOnly || nDrawType == k2Dand3D)) - { - nDraw = 2; - } - else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == k2Dand3D) - { - nDraw = 3;//转到viewportdraw - } - else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == k2DOnly) - { - nDraw = 1; - } - else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == k3DOnly) - { - nDraw = 2; - } - return nDraw; -} - -void AecDbEntityBase::BackupColorIndex(AcDbEntity* pEnt) -{ - if (pEnt != NULL) - { - struct resbuf* pXData = NULL; - pXData = pEnt->xData(_T("COLOR_BK")); - if (pXData == NULL) - { - struct resbuf* pTemp = acutNewRb(AcDb::kDxfRegAppName); - acutNewString(_T("COLOR_BK"),pTemp->resval.rstring); - pXData = pTemp; - - struct resbuf* pTempNext = NULL; - pTempNext = acutNewRb(AcDb::kDxfXdInteger32); - pTempNext->resval.rlong = pEnt->colorIndex(); - pTemp->rbnext = pTempNext; - pTempNext->rbnext = NULL; - - acdbRegApp(_T("COLOR_BK")); - pEnt->setXData(pXData); - acutRelRb(pXData); - } - } -} - -int AecDbEntityBase::SetBackupColorIndex(AcDbEntity* pEnt) -{ - int nColor = kColorByLayer; - if (pEnt != NULL) - { - resbuf* pXData = NULL; - pXData = pEnt->xData(_T("COLOR_BK")); - if (pXData != NULL) - { - struct resbuf* pTempNext = pXData->rbnext; - if (pTempNext != NULL) - { - if (pTempNext->restype == AcDb::kDxfXdInteger32) - { - nColor = pTempNext->resval.rint; - - // 存在清空 - struct resbuf* pTmp = acutNewRb(AcDb::kDxfRegAppName); - pEnt->setXData(pTmp); - acutRelRb(pXData); - acutRelRb(pTmp); - } - } - } - } - return nColor; -} - -int AecDbEntityBase::GetExplodeMode() const -{ - int nDrawMode = AecDbEntityBase::GetDrawMode(); - int nDraw = GetDrawDimOnType(nDrawMode, k2Dand3D); - - if (nDraw == 1) - { - nDraw = DRAW_2D; - } - else if (nDraw == 2) - { - nDraw = DRAW_3D; - } - else if (nDraw == 3) - { - ads_point pt; - struct resbuf rb; - acedGetVar(_T("VIEWDIR"),&rb); - ads_point_set(rb.resval.rpoint,pt); - - ads_point viewDir; - acdbUcs2Wcs(pt,viewDir,false); - - if (fabs(viewDir[X]) > 1.0e-6 || fabs(viewDir[Y]) > 1.0e-6) - { - nDraw = DRAW_3D; - } - else - { - nDraw = DRAW_2D; - } - } - return nDraw; + return AcDbEntity::subWblockClone(pOwner, pClonedObject, idMap, isPrimary); } Acad::ErrorStatus AecDbEntityBase::dwgInFields (AcDbDwgFiler* pFiler) @@ -1463,471 +345,6 @@ Acad::ErrorStatus AecDbEntityBase::dxfOutFields(AcDbDxfFiler* pFiler) const return (pFiler->filerStatus ()) ; } -Acad::ErrorStatus AecDbEntityBase::Draw2d(AcGiDraw &dc) const -{ - return Acad::eOk; -} - -Acad::ErrorStatus AecDbEntityBase::Draw3d(AcGiDraw &dc) const -{ - return Acad::eOk; -} - -void AecDbEntityBase::AssertWriteEnabled(Adesk::Boolean autoUndo /*= true*/, Adesk::Boolean recordModified /*= true*/) -{ - FreeBuffer(0, m_ar2DDrableBufPtrs_); - FreeBuffer(0, m_ar3DDrableBufPtrs_); - - m_ar3DDrableBufPtrs_.removeAll(); - m_ar2DDrableBufPtrs_.removeAll(); - - assertWriteEnabled(autoUndo,recordModified); -} - -bool AecDbEntityBase::GetPositionGrip(int nIndex, AecGripData *&pGrip) const -{ - return NULL; -} - -extern double PixelToWcs(int nPixel); -bool AecDbEntityBase::SubAddHitEditGrip(AcDbGripDataPtrArray &grips) const -{ - assertReadEnabled(); - - AecGripData *pGrip = NULL; - GetPositionGrip(grips.length() - 1, pGrip); - - if (pGrip != NULL) - { - AcGePoint3d ptHit = pGrip->ptGrip; - ptHit += AcGeVector3d::kXAxis * PixelToWcs(30); - - AecGripData *pGrip2 = new AecGripData; - memset(pGrip2, 0, sizeof(AecGripData)); - - pGrip2->nIndex = grips.length(); - pGrip2->ePos = eHitEdit; - pGrip2->nColor = kRed; - pGrip2->ptGrip = ptHit; - _tcscpy(pGrip2->szTip, _T("点击修改")); - _tcscpy(pGrip2->szID, _T("HITEDIT_2023")); - pGrip2->pOwner = (AcDbEntity *)this; - pGrip2->idHost = this->objectId(); - AcDbGripData *pGripData = new AcDbGripData; - pGripData->setGripPoint(ptHit); - pGripData->setAppData((void *)pGrip2); - pGripData->setWorldDraw(AecGripCback::WorldDrawfunc); - pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc); - grips.append(pGripData); - - return true; - } - - return false; -} - -//不得导出,需要数据,增加特定的获取函数 -extern AecDbObjXDataMap g_mapGlobalData; -bool AecDbEntityBase::HitOnGripEdit(const AcDbVoidPtrArray &gripAppData) -{ - AecGripData *pAppData = NULL; - AcDbIntArray arIndex; - - if (gripAppData.isEmpty()) - { - return Acad::eOk; - } - - pAppData = (AecGripData *)gripAppData.first(); - if (pAppData->ePos == eHitEdit) - { - //命令名 DBL_DXFNAME - TCHAR szCmd[65]; - _tcscpy(szCmd, _T("DBL_")); - _tcscat(szCmd, this->isA()->dxfName()); - - //判断命令是否存在 - AcEdCommand *pCmd = acedRegCmds->lookupLocalCmd(szCmd); - if (pCmd != NULL) - { - //发送ID 到 USERI; - AcDbObjectId id = pAppData->idHost; - - g_mapGlobalData.SetAt(szCmd, id); - - acedPostCommand(_T("\x03")); - - _tcscat(szCmd, _T(" ")); - acedPostCommand(szCmd); - } - else - { - acutPrintf(_T("\nLocalCmd %s does not exist!"), szCmd); - } - return true; - } - return false; -} - -bool AecDbEntityBase::Draw3DBuffers(AcGiDraw &dc)const -{ - if (m_ar3DDrableBufPtrs_.isEmpty()) return false; - for (int i = 0; i < m_ar3DDrableBufPtrs_.length(); ++i) - { - AcDbEntity *pEnt((AcDbEntity*)m_ar3DDrableBufPtrs_[i]); - dc.DrawEntity(*pEnt); - } - return true; -} - -bool AecDbEntityBase::Draw2DBuffers(AcGiDraw &dc)const -{ - if (m_ar2DDrableBufPtrs_.isEmpty()) - return false; - - for (int i = 0; i < m_ar2DDrableBufPtrs_.length(); ++i) - { - dc.DrawEntity(*(AcDbEntity*)m_ar2DDrableBufPtrs_[i]); - } - return true; -} - -const AcDbVoidPtrArray& AecDbEntityBase::Get3DBuffer() const -{ - BoolSubtractHide(); - return m_ar3DDrableBufPtrs_; -} - -const AcDbVoidPtrArray& AecDbEntityBase::Get2DBuffer() const -{ - return m_ar2DDrableBufPtrs_; -} - -bool AecDbEntityBase::Has3DBuffer() const -{ - return !m_ar3DDrableBufPtrs_.isEmpty(); -} - -bool AecDbEntityBase::Has2DBuffer() const -{ - return !m_ar2DDrableBufPtrs_.isEmpty(); -} - -void AecDbEntityBase::Add3DBuffer(AcDbEntity *pEnt) const -{ - if (pEnt && m_ar3DDrableBufPtrs_.find(pEnt) == -1) - m_ar3DDrableBufPtrs_.append(pEnt); -} - -void AecDbEntityBase::Add3DBuffer(const AcDbVoidPtrArray &arr) const -{ - for (int i = 0; i < arr.length(); ++i) - Add3DBuffer((AcDbEntity*)arr[i]); -} - -void AecDbEntityBase::Add2DBuffer(const AcDbVoidPtrArray &arr) const -{ - for (int i = 0; i < arr.length(); ++i) - Add2DBuffer((AcDbEntity*)arr[i]); -} - -void AecDbEntityBase::Add2DBuffer(AcDbEntity *pEnt) const -{ - if (pEnt && m_ar2DDrableBufPtrs_.find(pEnt) == -1) - m_ar2DDrableBufPtrs_.append(pEnt); -} - -bool AecDbEntityBase::IsIn2DBuffer(AcDbEntity* pEnt) const -{ - assertReadEnabled(); - if (-1 == m_ar2DDrableBufPtrs_.find(pEnt)) - return false; - return true; -} - -bool AecDbEntityBase::IsIn3DBuffer(AcDbEntity* pEnt) const -{ - assertReadEnabled(); - if (-1 == m_ar3DDrableBufPtrs_.find(pEnt)) - return false; - return true; -} - -void AecDbEntityBase::Clean3DBuffer() const -{ - FreeBuffer(0, m_ar3DDrableBufPtrs_); - m_ar3DDrableBufPtrs_.removeAll(); -} - -void AecDbEntityBase::Clean2DBuffer() const -{ - FreeBuffer(0, m_ar2DDrableBufPtrs_); - m_ar2DDrableBufPtrs_.removeAll(); -} - -void AecDbEntityBase::Clean3DBufferNoDel() const -{ - m_ar3DDrableBufPtrs_.removeAll(); -} - -void AecDbEntityBase::Clean2DBufferNoDel() const -{ - m_ar2DDrableBufPtrs_.removeAll(); -} - -int AecDbEntityBase::GetDrawDimCur() const -{ - return m_nDrawDimCur; -} - -//获取二维视图显示的图形 -int AecDbEntityBase::GetDraw2dables(Adesk::UInt16 nDrawStyle, AcDbVoidPtrArray& arEntPtrs) const -{ - assertReadEnabled(); - - AcDbEntity* pEnt = NULL,*pEntT = NULL; - const AcDbVoidPtrArray &ar2D = Get2DBuffer(); - for (int i = 0;i < ar2D.length();i++) - { - pEnt = (AcDbEntity*)ar2D.at(i); - pEntT = (AcDbEntity*)pEnt->clone(); - - pEntT->setLayer(layerId()); - arEntPtrs.append(pEntT); - } - return arEntPtrs.length(); -} - -void AecDbEntityBase::UpdateDrableSpecData(LPCTSTR pszApp,LPCTSTR pszKey,CString& sVal) -{ - assertWriteEnabled(); - - AecDbObjXDataMap xDataMap; - AcDbEntity* pEnt = NULL,*pEntT = NULL; - const AcDbVoidPtrArray &ar2D = Get2DBuffer(); - for (int i = 0;i < ar2D.length();i++) - { - pEnt = (AcDbEntity*)ar2D.at(i); - - if (xDataMap.Read(pEnt,pszApp)) - { - xDataMap.RemoveAt(pszKey); - xDataMap.SetAt(pszKey,sVal); - xDataMap.Write(pEnt,pszApp); - } - } - - const AcDbVoidPtrArray &ar3D = Get3DBuffer(); - for (int i = 0;i < ar3D.length();i++) - { - pEnt = (AcDbEntity*)ar3D.at(i); - if (xDataMap.Read(pEnt,pszApp)) - { - xDataMap.RemoveAt(pszKey); - xDataMap.SetAt(pszKey,sVal); - xDataMap.Write(pEnt,pszApp); - } - } -} - -bool AecDbEntityBase::GetBimInfoTip(CString& sInfoTip) const -{ - return false; -} - -bool AecDbEntityBase::GetProperties(SimpleProperty::PropertySetByIndex &porpertys) const -{ - assertReadEnabled(); - CString sLayer(_T("0")); - TCHAR *pLayer = layer(); - if (pLayer) - { - sLayer = pLayer; - acutDelString(pLayer); - } - - SimpleProperty::makeAndInsert(porpertys, _T("图层"), sLayer, false); - const AecDbObjXDataMap *pData = GetSpecialtyData(); - CString sys; - if (pData->GetAt(PIPE_SYS, sys)) - SimpleProperty::makeAndInsert(porpertys, _T("分系统"), sys, false); - return true; -} - -bool AecDbEntityBase::SetProperties(SimpleProperty::PropertySetByName & properties) -{ - AssertWriteEnabled(); - using namespace SimpleProperty; - CString sVal(_T("")); - if (properties.findAndSet(_T("图层"), sVal)) - { - setLayer(sVal); - } - if (properties.findAndSet(_T("分系统"), sVal)) - { - AecDbObjXDataMap *pData = GetSpecialtyData(AcDb::kForWrite); - if (pData) - pData->SetAt(PIPE_SYS, sVal); - } - return true; -} - -bool AecDbEntityBase::SendUserData(struct resbuf *pRb) -{ - return false; -} - -//获取三维显示图形 -int AecDbEntityBase::GetDraw3dables(AcDbVoidPtrArray& arEntPtrs,bool bWriteBimInfo) const -{ - assertReadEnabled(); - - const AecDbObjXDataMap* pXDataMap = GetSpecialtyData(); - if (pXDataMap != NULL) - { - AcDbEntity* pEnt = NULL,*pEntClone = NULL; - - if (!Has3DBuffer()) - { - AcGiViewDraw dc(NULL, NULL); - Draw3d(dc); - } - - const AcDbVoidPtrArray &ar3D = Get3DBuffer(); - for (int i = 0;i < ar3D.length();i++) - { - pEnt = (AcDbEntity*)ar3D.at(i); - pEntClone = (AcDbEntity*)pEnt->clone(); - - int nColor = 0; - if ( pXDataMap->GetAt(_T("COLOR"),nColor) ) - { - pEntClone->setColorIndex(nColor); - } - else - { - pEntClone->setColorIndex(colorIndex()); - } - pEntClone->setLayer(layerId()); - if (bWriteBimInfo) - { - pXDataMap->Write(pEntClone,_T("BIMDATA")); - } - arEntPtrs.append(pEntClone); - } - } - return arEntPtrs.length(); -} - -int AecDbEntityBase::GetSectionDraw(const AcGePoint3d& ptFr,const AcGePoint3d& ptTo,const AcGeVector3d& vtViewDir,const AcGeVector3d& vtTo, AcDbVoidPtrArray& arRegionPtrs) const -{ - return 0; -} - -bool AecDbEntityBase::GetSectionHatchPattern(CString& sPattern) const -{ - assertReadEnabled(); - - CString sMat; - if (GetSpecialtyData()->GetAt(KEY_SECTION_HATCH, sMat)) - { - sPattern = sMat; - if (sMat == HATCH_NO_NEED) - return false; - - if (sMat != HATCH_DEFAULT) - return true; - } - if ( GetSpecialtyData()->GetAt(KEY_MATERIAL,sMat)) - { - //以后从外部配置文件中获取 - //钢筋混凝土 - //石材 - //砖墙 - //填充墙体 - //轻质隔墙 - //玻璃幕墙 - - sPattern = _T("AR-CONC");//默认 - if (sMat.CompareNoCase(_T("钢筋混凝土")) == 0) - { - sPattern = _T("钢筋混凝土"); - } - else if(sMat.CompareNoCase(_T("混凝土")) == 0) - { - sPattern = _T("混凝土"); - } - else if(sMat.CompareNoCase(_T("石材")) == 0) - { - sPattern = _T("天然石材"); - } - else if(sMat.CompareNoCase(_T("砖墙")) == 0) - { - sPattern = _T("普通砖"); - } - else if(sMat.CompareNoCase(_T("填充墙体")) == 0) - { - sPattern = _T("钢筋混凝土"); - } - else if(sMat.CompareNoCase(_T("轻质隔墙")) == 0) - { - sPattern = _T("混凝土"); - } - else if(sMat.CompareNoCase(_T("玻璃幕墙")) == 0) - { - sPattern = _T("玻璃砖墙"); - } - } - return true; -} - -Acad::ErrorStatus AecDbEntityBase::ReCreateDraw2d() -{ - assertWriteEnabled(); - Clean2DBuffer(); - return Acad::eOk; -} - -Acad::ErrorStatus AecDbEntityBase::ReCreateDraw3d() -{ - assertWriteEnabled(); - Clean3DBuffer(); - return Acad::eOk; -} - -double AecDbEntityBase::GetVolume(bool bIsBody/* = false*/) const -{ - assertReadEnabled(); - - if (!Has3DBuffer()) - { - AcGiViewDraw dc(NULL,NULL); - Draw3d(dc); - } - - double dVol = 0.0,dVolAll = 0.0,momInertia[3],prodInertia[3],prinMoments[3],radiiGyration[3]; - AcGePoint3d ptCen; - AcGeVector3d prinAxes[3]; - AcDbExtents extents; - - AcDbVoidPtrArray arEntPtrs; - GetDraw3dables(arEntPtrs); - - AcDbEntity* pEnt = NULL; - for (int i = 0;i < arEntPtrs.length();i++) - { - pEnt = (AcDbEntity*)arEntPtrs.at(i); - - AcDb3dSolid* pSolid = AcDb3dSolid::cast(pEnt); - if (pSolid != NULL) - { - pSolid->getMassProp(dVol,ptCen,momInertia,prodInertia,prinMoments,prinAxes,radiiGyration,extents); - dVolAll += dVol; - } - } - return dVolAll; -} - int AecDbEntityBase::ComparedTo(AecDbEntityBase* pEntOther) const { return -1; @@ -1962,497 +379,10 @@ double AecDbEntityBase::GetArea() const return dAreaAll; } -void AecDbEntityBase::Add3DBoolSubtract(AcDb3dSolid* pSolidBlackHole) -{ - assertWriteEnabled(); - const AcDbVoidPtrArray& ar3D_ = Get3DBuffer(); - AcDbVoidPtrArray ar3D; - ar3D.append(ar3D_); - - AcDbEntity* pEnt = NULL; - AcDb3dSolid* pSolid = NULL; - AcDb3dSolid* pSolidCln = NULL; - AcDb3dSolid* pSolidNotGet = NULL; - Acad::ErrorStatus es; - - Adesk::Boolean bSlidInterface = Adesk::kFalse; - double dArea1 = 0.0,dArea2 = 0.0; - - for (int i = 0;i < ar3D.length();i++) - { - pEnt = (AcDbEntity*)ar3D.at(i); - - pSolid = AcDb3dSolid::cast(pEnt); - if (pSolid != NULL) - { - pSolidCln = (AcDb3dSolid*)pSolidBlackHole->clone(); - - //有交集才处理 - if ( Acad::eOk == pSolid->checkInterference( pSolidCln,Adesk::kFalse,bSlidInterface,pSolidNotGet)) - { - pSolid->getArea(dArea1); - - es = pSolid->booleanOper(AcDb::kBoolSubtract,pSolidCln); - - pSolid->getArea(dArea2); - - if ( es == Acad::eOk) - { - pSolid->recordGraphicsModified(Adesk::kTrue); - - if ( fabs(dArea1 - dArea2) < 1.e-3)//没有变化,被包含 - { - ar3D.removeAt(i); - i -= 1; - m_ar3DDrableBufPtrs_.removeAt(i); - } - } - else if ( es == Acad::eGeneralModelingFailure ) - { - ar3D.removeAt(i); - i -= 1; - m_ar3DDrableBufPtrs_.removeAt(i); - } - //delete pSolidCln; - } - } - } -} - -void AecDbEntityBase::Remove3DBoolSubtract() -{ - assertWriteEnabled(); - - //清除3D,重建 - Clean3DBuffer(); -} - -void AecDbEntityBase::AddBlackHole(AcDbObjectId& idHole) -{ - AssertWriteEnabled(); - - AecDbObjXDataMap* pXdataMap = GetSpecialtyData(AcDb::kForWrite); - if (pXdataMap != NULL) - { - TCHAR szHand[19]; - memset(szHand,0,sizeof(szHand) ); - idHole.handle().getIntoAsciiBuffer(szHand); - - CString sKey; - sKey.Format(_T("%s_%s"),KEY_HOLE,szHand); - pXdataMap->SetAt(sKey,idHole.handle()); - } -} - -void AecDbEntityBase::RemoveBlackHole(AcDbObjectId& idHole) -{ - AssertWriteEnabled(); - - AecDbObjXDataMap* pXdataMap = GetSpecialtyData(AcDb::kForWrite); - if (pXdataMap != NULL) - { - TCHAR szHand[19]; - memset(szHand,0,sizeof(szHand) ); - idHole.handle().getIntoAsciiBuffer(szHand); - - CString sKey; - sKey.Format(_T("%s_%s"),KEY_HOLE,szHand); - pXdataMap->RemoveAt(sKey); - } -} - -void AecDbEntityBase::DrawBlackHole(AcDbEntity* pSolidEnt) const -{ - AcDb3dSolid* pSolidAll = AcDb3dSolid::cast(pSolidEnt); - if (pSolidAll == NULL) - return; - - const AecDbObjXDataMap* pCXDataMap = GetSpecialtyData(); - if (pCXDataMap != NULL) - { - AecDbObjXDataMap* pXDataMap = (AecDbObjXDataMap*)pCXDataMap; - AecDbObjXDataMap::It it = pXDataMap->Begin(); - AecDbObjXDataMap::It end = pXDataMap->End(); - - CString sKey; - - AecXData cVal; - memset(&cVal,0,sizeof(AecXData)); - - AcDbEntity* pEnt = NULL; - AcDbHandle hd; - AcDbObjectId idHole; - - for (; it != end; ) - { - if (!pXDataMap->GetNext(it, sKey, cVal)) - break; - - if (sKey.Find(KEY_HOLE) != -1) - { - pXDataMap->GetAt(sKey,hd); - if ( Acad::eOk == acdbCurDwg()->getAcDbObjectId(idHole,false,hd) ) - { - if ( Acad::eOk == acdbOpenAcDbEntity(pEnt,idHole,AcDb::kForRead)) - { - AecDbEntityBase* pBlackHole = AecDbEntityBase::cast(pEnt); - if (pBlackHole != NULL) - { - AcDb3dSolid* pSolidBlackHold = pBlackHole->GetBlackHole(); - if (pSolidBlackHold != NULL) - { - pSolidAll->booleanOper(AcDb::kBoolSubtract,pSolidBlackHold); - } - } - pEnt->close(); - } - } - } - } - } -} - -AcDb3dSolid* AecDbEntityBase::GetBlackHole() const -{ - return NULL; -} - -void AecDbEntityBase::SplitStrintToArray(LPCTSTR pszDescr, CStringArray & arInfo, TCHAR tcSpace) -{ - if (pszDescr == NULL) return; - - CString sDescr = pszDescr; - int nLen = sDescr.GetLength(); - int i = 0; - CString sText = _T(""); - TCHAR tchar = _T('\0'); - - for (i = 0; i < nLen; i++) - { - tchar = sDescr.GetAt(i); - if (tchar == tcSpace) - { - if (!sText.IsEmpty()) - arInfo.Add(sText); - sText = _T(""); - } - else - { - sText += tchar; - } - - if (i == nLen - 1 && !sText.IsEmpty()) - { - arInfo.Add(sText); - } - } -} - -AcDbPolyline * AecDbEntityBase::StringToPolyline(LPCTSTR pszPoint2ds) -{ - CString sPlane,sTemp; - CString sAll = pszPoint2ds; - int nPos = sAll.Find(_T("plane=")); - if (nPos != -1) - { - sPlane = sAll.Mid(nPos); - sTemp = sAll.Mid(0,nPos); - sAll = sTemp; - } - - CStringArray arXYs; - SplitStrintToArray(sAll, arXYs, _T(',')); - - double dEl = 0.0; - AcGeVector3d vtNorm = AcGeVector3d::kZAxis; - - CString sLast; - if (arXYs.GetSize() > 0) - { - sLast = arXYs.GetAt(arXYs.GetSize() - 1); - if (sLast.Find(_T('[')) != -1) - { - sLast.TrimLeft(_T('[')); - sLast.TrimRight(_T(']')); - } - - CStringArray arVals; - SplitStrintToArray(sLast, arVals, _T(';')); - - if (arVals.GetSize() >= 4) - { - dEl = _ttof(arVals.GetAt(0)); - vtNorm.set(_ttof(arVals.GetAt(1)), _ttof(arVals.GetAt(2)), _ttof(arVals.GetAt(3))); - } - } - - CString sX, sYB, sBulge, sY; - double dBulge = 0.0; - int nFind = -1; - AcGePoint2d pt; - AcDbPolyline pl; - - AcDbPolyline* pPl = new AcDbPolyline; - - if (!sPlane.IsEmpty()) - { - sPlane.TrimLeft(_T("plane=")); - sPlane.TrimLeft(_T('(')); - sPlane.TrimRight(_T(')')); - - CStringArray arVals; - SplitStrintToArray(sPlane,arVals,_T(',')); - - if (arVals.GetSize() >= 4) - { - vtNorm.set(_ttof(arVals.GetAt(0)),_ttof(arVals.GetAt(1)),_ttof(arVals.GetAt(2))); - dEl = _ttof(arVals.GetAt(3)); - - pPl->setNormal(vtNorm); - pPl->setElevation(dEl); - } - } - else - { - pPl->setNormal(vtNorm); - pPl->setElevation(dEl); - } - - for (int i = 0; i < arXYs.GetSize() / 2; i++) - { - sX = arXYs.GetAt(2 * i); - sYB = arXYs.GetAt(2 * i + 1); - sY = sYB; - dBulge = 0.0; - - nFind = sYB.Find(_T('@')); - if (nFind != -1) - { - sBulge = sYB.Mid(nFind + 1); - dBulge = _ttof(sBulge); - sY = sYB.Mid(0, nFind); - } - - pt.set(_ttof(sX), _ttof(sY)); - pPl->addVertexAt(i, pt, dBulge); - } - return pPl; -} - -static AcGePoint3d MidPoint(AcGePoint3d& pt1, AcGePoint3d& pt2) -{ - return AcGePoint3d((pt1.x + pt2.x) / 2.0, - (pt1.y + pt2.y) / 2.0, - (pt1.z + pt2.z) / 2.0); -} - -//剖切隐藏 -void AecDbEntityBase::BoolSubtractHide() const -{ - if (m_ar3DDrableBufPtrs_.isEmpty()) - return; - - const AecDbObjXDataMap* pXDataMap = GetSpecialtyData(); - if (pXDataMap != NULL) - { - CString sPl; - double dBomEl = 0.0,dH = 0.0; - - if ( pXDataMap->GetAt(KEY_BOOLSPL,sPl) && - pXDataMap->GetAt(KEY_BOOLBOM,dBomEl) && - pXDataMap->GetAt(KEY_BOOLH,dH) ) - { - AcDbPolyline* pPl = StringToPolyline(sPl); - if (pPl != NULL) - { - AcGePoint3d ptFr,ptTo; - pPl->getPointAt(0,ptFr); - - //简单取内一心 - if (pPl->numVerts() > 2) - { - AcGePoint3d pt2; - pPl->getPointAt(2,pt2); - ptFr = MidPoint(ptFr,pt2); - } - - AcDbLine ln; - ptFr.z = dBomEl; - ptTo = ptFr; - ptTo.z = dH; - ln.setStartPoint(ptFr); - ln.setEndPoint(ptTo); - - AcDbRegion* pRegion = NULL; - AcDbVoidPtrArray arCur,arReg; - arCur.append(pPl); - - Acad::ErrorStatus es; - if (Acad::eOk == ( es = AcDbRegion::createFromCurves(arCur,arReg) ) ) - { - if (!arReg.isEmpty()) - { - pRegion = (AcDbRegion*)arReg.first(); - - AcDb3dSolid* pSoldSub = new AcDb3dSolid; - if ( Acad::eOk == (es = pSoldSub->extrudeAlongPath(pRegion,&ln) ) ) - { - AcDb3dSolid* pSolid = NULL; - AcDbEntity* pEnt = NULL; - for (int i = 0;i < m_ar3DDrableBufPtrs_.length();i++) - { - pEnt = (AcDbEntity*)m_ar3DDrableBufPtrs_.at(i); - pSolid = AcDb3dSolid::cast(pEnt); - if (pSolid != NULL) - { - AcDb3dSolid* pSolidSubCln = (AcDb3dSolid*)pSoldSub->clone(); - CopyObject(*pSoldSub,*pSolidSubCln); - - if ( Acad::eOk != (es = pSolid->booleanOper(AcDb::kBoolSubtract,pSolidSubCln) ) ) - { - delete pSolidSubCln; - } - } - } - } - delete pSoldSub; - delete pRegion; - } - } - delete pPl; - } - } - } -} - -SHJson::WValue& AecDbEntityBase::ToJson(bool bExprotGeo) const -{ - assertReadEnabled(); - using namespace SHJson; - WValue &v(m_json); - v.SetObject(); - addMember(v, _T("__class__"), isA()->name()); - addMember(v, _T("__self__"), objectId().asOldId()); - addMember(v, _T("__owner__"), 0); - - const AecDbObjXDataMap *pXMap = GetSpecialtyData(); - if (pXMap) - { - addMember(v, _T("__xdata__"), pXMap->ToJson()); - } - - CString sVertices, sIndices; - __int64 dwRgb = 0; - - struct resbuf rb; - acedGetVar(_T("useri5"), &rb); - if (rb.resval.rint == 30)//3D导出 - { - WValue node; - node.SetObject(); - - WValue body; - body.SetArray(); - - AcDbEntity *pE = NULL; - for (int i = 0; i < Get3DBuffer().length(); i++) - { - node.SetNull(); - - pE = (AcDbEntity *)Get3DBuffer().at(i); - AcDb3dSolid *p3d = AcDb3dSolid::cast(pE); - if (p3d != NULL) - { - dwRgb = RGB(p3d->color().red(), p3d->color().green(), p3d->color().blue()); - - if (PolyhedronGeometry(p3d, sVertices, sIndices)) - { - addMember(node, _T("RGB"), dwRgb); - addMember(node, _T("vertices"), sVertices); - addMember(node, _T("indices"), sIndices); - pushBack(body, node); - } - } - - AcDbSubDMesh *pSubMesh = AcDbSubDMesh::cast(pE); - if (pSubMesh != NULL) - { - dwRgb = RGB(pSubMesh->color().red(), pSubMesh->color().green(), pSubMesh->color().blue()); - if (PolyhedronGeometry(pSubMesh, sVertices, sIndices)) - { - addMember(node, _T("RGB"), dwRgb); - addMember(node, _T("vertices"), sVertices); - addMember(node, _T("indices"), sIndices); - pushBack(body, node); - } - } - } - - if (!body.Empty()) - addMember(v, _T("__body__"), body); - } - - return v; -} - -bool AecDbEntityBase::ByJson(const SHJson::WValue &v) -{ - using namespace SHJson; - AssertWriteEnabled(); - AecDbObjXDataMap *pXMap = GetSpecialtyData(AcDb::kForWrite); - if (pXMap) - { - MCIt it = v.FindMember(_T("__xdata__")); - if (it != v.MemberEnd()) - return pXMap->ByJson(it->value); - } - return true; -} Acad::ErrorStatus AecDbEntityBase::setTransparency(const AcCmTransparency &trans, Adesk::Boolean doSubents) { AssertWriteEnabled(); return AcDbEntity::setTransparency(trans, doSubents); } - -CString AecDbEntityBase::getUniqueName() const -{ - return _T(""); -} - - -typedef AcArray AcDbEntityArray; -void AecDbEntityBase::PreprocessForHlr(const AcGePoint3d &ptPlnO - , const AcGeVector3d &vtPlnN - , AcDbEntityArray &ar) const -{ - assertReadEnabled(); - return; -} - -void AecDbEntityBase::ProcessHlrResult(const AcDbEntityArray &ar - , const std::map &preAr - , AcDbEntityArray &output) const -{ - assertReadEnabled(); - AcDbObjectId idLy(layerId()), idLt(linetypeId()); - int clr(colorIndex()); - - const AecDbObjXDataMap *pXData = GetSpecialtyData(); - - for (int i(0); i < ar.length(); ++i) - { - AcDbEntity *pEnt((AcDbEntity*)ar[i]->clone()); - if (pEnt) - { - if (pXData) - pXData->Write(pEnt, BIMDATA_APP); - pEnt->setLayer(idLy); - pEnt->setLinetype(idLt); - pEnt->setColorIndex(clr); - output.append(pEnt); - } - } -} - diff --git a/SourceCode/Code2026/AecRxBase/AecDbEntityCommon.cpp b/SourceCode/Code2026/AecRxBase/AecDbEntityCommon.cpp new file mode 100644 index 0000000..37ad00b --- /dev/null +++ b/SourceCode/Code2026/AecRxBase/AecDbEntityCommon.cpp @@ -0,0 +1,1938 @@ +#include "stdafx.h" +#include "AecDbEntityCommon.h" +#include "AecDbObjXDataMap.h" +#include "AcGiViewDraw.h" +#include "dbobjptr.h" +#include "simpleproperty.h" +#include "AecGripCback.h" + +BOOL ReadModelXData(LPCTSTR pszKey, AecDbObjXDataMap& xDataMap, AcDbDatabase* pDb); + +const Adesk::UInt16 kColorByLayer = 256; +static const Adesk::UInt16 kRed = 1; + +namespace +{ + void FreeBuffer(int n, AcDbVoidPtrArray& arEntPtrs) + { + AcDbEntity* pEnt = NULL; + while (arEntPtrs.length() > n) + { + pEnt = (AcDbEntity*)arEntPtrs.last(); + pEnt->erase(); + pEnt->close(); + DELETE_PTR(pEnt); + arEntPtrs.removeLast(); + } + } + + AcGePoint3d MidPoint(AcGePoint3d &pt1, AcGePoint3d &pt2) + { + return AcGePoint3d((pt1.x + pt2.x) / 2.0, + (pt1.y + pt2.y) / 2.0, + (pt1.z + pt2.z) / 2.0); + } + + CString IDCreate() + { + CString sID = _T(""); + + GUID Guid; + static TCHAR szGuid[39]; + RPC_WSTR pszGuid = NULL; + + UuidCreate(&Guid); + + if (RPC_S_OK != UuidToString(&Guid, &pszGuid)) + { + return _T(""); + } + + lstrcpyn(szGuid, (TCHAR *)pszGuid, sizeof(szGuid)); + RpcStringFree(&pszGuid); + + szGuid[38] = _T('\0'); + sID = szGuid; + sID.MakeUpper(); + return sID; + } + +} + +void AecDbEntityCommon::AssertWriteEnabled(Adesk::Boolean autoUndo, Adesk::Boolean recordModified) +{ + FreeBuffer(0, m_ar2DDrableBufPtrs_); + FreeBuffer(0, m_ar3DDrableBufPtrs_); + + m_ar3DDrableBufPtrs_.removeAll(); + m_ar2DDrableBufPtrs_.removeAll(); + + GetMe()->assertWriteEnabled(autoUndo, recordModified); +} + +AecDbEntityCommon::AecDbEntityCommon(void) +{ + m_eExplodeOrDrawType = kWroldDraw; + m_nDrawDimCur = -1; +} + +AecDbEntityCommon::~AecDbEntityCommon(void) +{ + FreeBuffer(0, m_ar2DDrableBufPtrs_); + FreeBuffer(0, m_ar3DDrableBufPtrs_); +} + +Acad::ErrorStatus AecDbEntityCommon::Draw2d(AcGiDraw & dc) const { return Acad::eOk; } + +Acad::ErrorStatus AecDbEntityCommon::Draw3d(AcGiDraw & dc) const { return Acad::eOk; } + +bool AecDbEntityCommon::Draw2DBuffers(AcGiDraw & dc) const +{ + if (m_ar2DDrableBufPtrs_.isEmpty()) + return false; + + for (int i = 0; i < m_ar2DDrableBufPtrs_.length(); ++i) + dc.DrawEntity(*(AcDbEntity *)m_ar2DDrableBufPtrs_[i]); + + return true; +} + +const AcDbVoidPtrArray& AecDbEntityCommon::Get2DBuffer() const { return m_ar2DDrableBufPtrs_; } + +bool AecDbEntityCommon::Has2DBuffer() const { return !m_ar2DDrableBufPtrs_.isEmpty(); } + +void AecDbEntityCommon::Add2DBuffer(AcDbEntity * pEnt) const +{ + if (pEnt && m_ar2DDrableBufPtrs_.find(pEnt) == -1) + m_ar2DDrableBufPtrs_.append(pEnt); +} + +void AecDbEntityCommon::Add2DBuffer(const AcDbVoidPtrArray & arr) const +{ + for (int i = 0; i < arr.length(); ++i) + Add2DBuffer((AcDbEntity *)arr[i]); +} + +bool AecDbEntityCommon::IsIn2DBuffer(AcDbEntity *pEnt) const +{ + if (-1 == m_ar2DDrableBufPtrs_.find(pEnt)) + return false; + return true; +} + +void AecDbEntityCommon::Clean2DBuffer()const +{ + FreeBuffer(0, m_ar2DDrableBufPtrs_); + m_ar2DDrableBufPtrs_.removeAll(); +} + +void AecDbEntityCommon::Clean2DBufferNoDel()const { m_ar2DDrableBufPtrs_.removeAll(); } + +bool AecDbEntityCommon::Draw3DBuffers(AcGiDraw &dc) const +{ + if (m_ar3DDrableBufPtrs_.isEmpty()) + return false; + + for (int i = 0; i < m_ar3DDrableBufPtrs_.length(); ++i) + dc.DrawEntity(*(AcDbEntity *)m_ar3DDrableBufPtrs_[i]); + + return true; +} + +const AcDbVoidPtrArray& AecDbEntityCommon::Get3DBuffer() const { return m_ar3DDrableBufPtrs_; } + +bool AecDbEntityCommon::Has3DBuffer() const { return !m_ar3DDrableBufPtrs_.isEmpty(); } + +void AecDbEntityCommon::Add3DBuffer(AcDbEntity * pEnt) const +{ + if (pEnt && m_ar3DDrableBufPtrs_.find(pEnt) == -1) + m_ar3DDrableBufPtrs_.append(pEnt); +} + +void AecDbEntityCommon::Add3DBuffer(const AcDbVoidPtrArray & arr) const +{ + for (int i = 0; i < arr.length(); ++i) + Add3DBuffer((AcDbEntity *)arr[i]); +} + +bool AecDbEntityCommon::IsIn3DBuffer(AcDbEntity *pEnt) const +{ + if (-1 == m_ar3DDrableBufPtrs_.find(pEnt)) + return false; + return true; +} + +void AecDbEntityCommon::Clean3DBuffer()const +{ + FreeBuffer(0, m_ar3DDrableBufPtrs_); + m_ar3DDrableBufPtrs_.removeAll(); +} + +void AecDbEntityCommon::Clean3DBufferNoDel()const { m_ar3DDrableBufPtrs_.removeAll(); } + +Acad::ErrorStatus AecDbEntityCommon::ReCreateDraw2d() +{ + GetMe()->assertWriteEnabled(); + Clean2DBuffer(); + return Acad::eOk; +} + +Acad::ErrorStatus AecDbEntityCommon::ReCreateDraw3d() +{ + GetMe()->assertWriteEnabled(); + Clean3DBuffer(); + return Acad::eOk; +} + + +int AecDbEntityCommon::GetDrawDimCur() const { return m_nDrawDimCur; } + +CString AecDbEntityCommon::getUniqueName() const { return _T(""); } + +int AecDbEntityCommon::GetExplodeMode() const +{ + + int nDrawMode = GetDrawMode(); + DrawModeType nDrawType = k2Dand3D; + int nDraw = GetDrawDimOnType(nDrawMode, nDrawType); + + if (nDraw == 1) + { + nDraw = DRAW_2D; + } + else if (nDraw == 2) + { + nDraw = DRAW_3D; + } + else if (nDraw == 3) + { + ads_point pt; + struct resbuf rb; + acedGetVar(_T("VIEWDIR"), &rb); + ads_point_set(rb.resval.rpoint, pt); + + ads_point viewDir; + acdbUcs2Wcs(pt, viewDir, false); + + if (fabs(viewDir[X]) > 1.0e-6 || fabs(viewDir[Y]) > 1.0e-6) + { + nDraw = DRAW_3D; + } + else + { + nDraw = DRAW_2D; + } + } + return nDraw; +} + +int AecDbEntityCommon::GetDrawMode() +{ + int nDrawMode = 3; + //从命名字典中取,默认3 + + return nDrawMode; +} + +void AecDbEntityCommon::SetDrawMode(int nMode) +{ + //写入命名字典 +} + +void AecDbEntityCommon::BackupColorIndex(AcDbEntity* pEnt) +{ + if (pEnt != NULL) + { + struct resbuf* pXData = NULL; + pXData = pEnt->xData(_T("COLOR_BK")); + if (pXData == NULL) + { + struct resbuf* pTemp = acutNewRb(AcDb::kDxfRegAppName); + acutNewString(_T("COLOR_BK"),pTemp->resval.rstring); + pXData = pTemp; + + struct resbuf* pTempNext = NULL; + pTempNext = acutNewRb(AcDb::kDxfXdInteger32); + pTempNext->resval.rlong = pEnt->colorIndex(); + pTemp->rbnext = pTempNext; + pTempNext->rbnext = NULL; + + acdbRegApp(_T("COLOR_BK")); + pEnt->setXData(pXData); + acutRelRb(pXData); + } + } +} + +int AecDbEntityCommon::SetBackupColorIndex(AcDbEntity* pEnt) +{ + int nColor = kColorByLayer; + if (pEnt != NULL) + { + resbuf* pXData = NULL; + pXData = pEnt->xData(_T("COLOR_BK")); + if (pXData != NULL) + { + struct resbuf* pTempNext = pXData->rbnext; + if (pTempNext != NULL) + { + if (pTempNext->restype == AcDb::kDxfXdInteger32) + { + nColor = pTempNext->resval.rint; + pEnt->setColorIndex(nColor); + // 存在清空 + struct resbuf* pTmp = acutNewRb(AcDb::kDxfRegAppName); + pEnt->setXData(pTmp); + acutRelRb(pXData); + acutRelRb(pTmp); + } + } + } + } + return nColor; +} + +int AecDbEntityCommon::GetDrawDimOnType(int nDrawMode, int nDrawType) const +{ + int nDraw = 0; //0--NONE; 1--2D; 2--3D; 3--2D&3D; + if (nDrawMode == DRAW_2D && (nDrawType == k2DOnly || nDrawType == k2Dand3D)) + { + nDraw = 1; + } + else if (nDrawMode == DRAW_3D && (nDrawType == k3DOnly || nDrawType == k2Dand3D)) + { + nDraw = 2; + } + else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == k2Dand3D) + { + nDraw = 3;//转到viewportdraw + } + else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == k2DOnly) + { + nDraw = 1; + } + else if (nDrawMode == (DRAW_2D | DRAW_3D) && nDrawType == k3DOnly) + { + nDraw = 2; + } + return nDraw; + +} + +typedef AcArray AcDbEntityArray; +void AecDbEntityCommon::PreprocessForHlr(const AcGePoint3d &ptPlnO + , const AcGeVector3d &vtPlnN + , AcDbEntityArray &ar) const +{ + GetMe()->assertReadEnabled(); + return; +} + +void AecDbEntityCommon::ProcessHlrResult(const AcDbEntityArray &ar + , const std::map &preAr + , AcDbEntityArray &output) const +{ + GetMe()->assertReadEnabled(); + AcDbObjectId idLy(GetMe()->layerId()), idLt(GetMe()->linetypeId()); + int clr(GetMe()->colorIndex()); + + const AecDbObjXDataMap *pXData = GetSpecialtyData(); + + for (int i(0); i < ar.length(); ++i) + { + AcDbEntity *pEnt((AcDbEntity*)ar[i]->clone()); + if (pEnt) + { + if (pXData) + pXData->Write(pEnt, BIMDATA_APP); + pEnt->setLayer(idLy); + pEnt->setLinetype(idLt); + pEnt->setColorIndex(clr); + output.append(pEnt); + } + } +} + +bool AecDbEntityCommon::GetBimInfoTip(CString& sInfoTip) const +{ + return false; +} + +bool AecDbEntityCommon::GetProperties(SimpleProperty::PropertySetByIndex &porpertys) const +{ + GetMe()->assertReadEnabled(); + CString sLayer(_T("0")); + TCHAR *pLayer = GetMe()->layer(); + if (pLayer) + { + sLayer = pLayer; + acutDelString(pLayer); + } + + SimpleProperty::makeAndInsert(porpertys, _T("图层"), sLayer, false); + const AecDbObjXDataMap *pData = GetSpecialtyData(); + CString sys; + if (pData->GetAt(PIPE_SYS, sys)) + SimpleProperty::makeAndInsert(porpertys, _T("分系统"), sys, false); + return true; +} + +bool AecDbEntityCommon::SetProperties(SimpleProperty::PropertySetByName & properties) +{ + AssertWriteEnabled(); + using namespace SimpleProperty; + CString sVal(_T("")); + if (properties.findAndSet(_T("图层"), sVal)) + { + GetMe()->setLayer(sVal); + } + if (properties.findAndSet(_T("分系统"), sVal)) + { + AecDbObjXDataMap *pData = GetSpecialtyData(AcDb::kForWrite); + if (pData) + pData->SetAt(PIPE_SYS, sVal); + } + return true; +} + +double AecDbEntityCommon::GetVolume(bool bIsBody) const +{ + GetMe()->assertReadEnabled(); + + if (!Has3DBuffer()) + { + AcGiViewDraw dc(NULL, NULL); + Draw3d(dc); + } + + double dVol = 0.0, dVolAll = 0.0, momInertia[3], prodInertia[3], prinMoments[3], radiiGyration[3]; + AcGePoint3d ptCen; + AcGeVector3d prinAxes[3]; + AcDbExtents extents; + + AcDbVoidPtrArray arEntPtrs; + GetDraw3dables(arEntPtrs); + + AcDbEntity *pEnt = NULL; + for (int i = 0; i < arEntPtrs.length(); i++) + { + pEnt = (AcDbEntity *)arEntPtrs.at(i); + + AcDb3dSolid *pSolid = AcDb3dSolid::cast(pEnt); + if (pSolid != NULL) + { + pSolid->getMassProp(dVol, ptCen, momInertia, prodInertia, prinMoments, prinAxes, radiiGyration, extents); + dVolAll += dVol; + } + } + return dVolAll; +} + +int AecDbEntityCommon::GetDraw2dables(Adesk::UInt16 nDrawStyle, AcDbVoidPtrArray &arEntPtrs) const +{ + GetMe()->assertReadEnabled(); + + AcDbEntity* pEnt = NULL,*pEntT = NULL; + const AcDbVoidPtrArray &ar2D = Get2DBuffer(); + for (int i = 0;i < ar2D.length();i++) + { + pEnt = (AcDbEntity*)ar2D.at(i); + pEntT = (AcDbEntity*)pEnt->clone(); + + pEntT->setLayer(GetMe()->layerId()); + arEntPtrs.append(pEntT); + } + return arEntPtrs.length(); +} + +int AecDbEntityCommon::GetDraw3dables(AcDbVoidPtrArray& arEntPtrs,bool bWriteBimInfo) const +{ + GetMe()->assertReadEnabled(); + + const AecDbObjXDataMap* pXDataMap = GetSpecialtyData(); + if (pXDataMap != NULL) + { + AcDbEntity* pEnt = NULL,*pEntClone = NULL; + + if (!Has3DBuffer()) + { + AcGiViewDraw dc(NULL, NULL); + Draw3d(dc); + } + + const AcDbVoidPtrArray &ar3D = Get3DBuffer(); + for (int i = 0;i < ar3D.length();i++) + { + pEnt = (AcDbEntity*)ar3D.at(i); + pEntClone = (AcDbEntity*)pEnt->clone(); + + int nColor = 0; + if ( pXDataMap->GetAt(_T("COLOR"),nColor) ) + { + pEntClone->setColorIndex(nColor); + } + else + { + pEntClone->setColorIndex(GetMe()->colorIndex()); + } + pEntClone->setLayer(GetMe()->layerId()); + if (bWriteBimInfo) + { + pXDataMap->Write(pEntClone,_T("BIMDATA")); + } + arEntPtrs.append(pEntClone); + } + } + return arEntPtrs.length(); +} + +SHJson::WValue& AecDbEntityCommon::ToJson(bool bExprotGeo) const +{ + GetMe()->assertReadEnabled(); + using namespace SHJson; + WValue &v(m_json); + v.SetObject(); + addMember(v, _T("__class__"), GetMe()->isA()->name()); + addMember(v, _T("__self__"), GetMe()->objectId().asOldId()); + addMember(v, _T("__owner__"), 0); + + const AecDbObjXDataMap *pXMap = GetSpecialtyData(); + if (pXMap) + { + addMember(v, _T("__xdata__"), pXMap->ToJson()); + } + + return v; +} + +bool AecDbEntityCommon::ByJson(const SHJson::WValue &v) +{ + using namespace SHJson; + AssertWriteEnabled(); + AecDbObjXDataMap *pXMap = GetSpecialtyData(AcDb::kForWrite); + if (pXMap) + { + MCIt it = v.FindMember(_T("__xdata__")); + if (it != v.MemberEnd()) + return pXMap->ByJson(it->value); + } + return true; +} + +bool AecDbEntityCommon::GetSectionHatchPattern(CString& sPattern) const +{ + GetMe()->assertReadEnabled(); + + CString sMat; + if (GetSpecialtyData()->GetAt(KEY_SECTION_HATCH, sMat)) + { + sPattern = sMat; + if (sMat == HATCH_NO_NEED) + return false; + + if (sMat != HATCH_DEFAULT) + return true; + } + if ( GetSpecialtyData()->GetAt(KEY_MATERIAL,sMat)) + { + //以后从外部配置文件中获取 + //钢筋混凝土 + //石材 + //砖墙 + //填充墙体 + //轻质隔墙 + //玻璃幕墙 + + sPattern = _T("AR-CONC");//默认 + if (sMat.CompareNoCase(_T("钢筋混凝土")) == 0) + { + sPattern = _T("钢筋混凝土"); + } + else if(sMat.CompareNoCase(_T("混凝土")) == 0) + { + sPattern = _T("混凝土"); + } + else if(sMat.CompareNoCase(_T("石材")) == 0) + { + sPattern = _T("天然石材"); + } + else if(sMat.CompareNoCase(_T("砖墙")) == 0) + { + sPattern = _T("普通砖"); + } + else if(sMat.CompareNoCase(_T("填充墙体")) == 0) + { + sPattern = _T("钢筋混凝土"); + } + else if(sMat.CompareNoCase(_T("轻质隔墙")) == 0) + { + sPattern = _T("混凝土"); + } + else if(sMat.CompareNoCase(_T("玻璃幕墙")) == 0) + { + sPattern = _T("玻璃砖墙"); + } + } + return true; +} + +void AecDbEntityCommon::BoolSubtractHide() const +{ +} + +Acad::ErrorStatus AecDbEntityCommon::subGet3dGeomExtents(AcDbExtents &extents) const +{ + AcDbVoidPtrArray entSet; + if (!Has3DBuffer()) + { + AcGiViewDraw dc(NULL, NULL); + Draw3d(dc); + } + entSet.append(Get3DBuffer()); + + if (entSet.isEmpty()) + return Acad::eNullExtents; + + BOOL bInit = TRUE; + AcGePoint3d ptMax, ptMin; + AcDbExtents ext, extT; + + int len = entSet.length(); + for (int i = 0; i < len; i++) + { + AcDbEntity *pEnt = (AcDbEntity *)entSet[i]; + + if (pEnt->getGeomExtents(extT) == Acad::eOk) + { + ext.addExt(extT); + } + } + + AcGePoint3d ptLow, ptUp; + ptLow = ext.minPoint(); + ptUp = ext.maxPoint(); + extents.set(ptLow, ptUp); + + return Acad::eOk; +} + +void AecDbEntityCommon::Add3DBoolSubtract(AcDb3dSolid* pSolidBlackHole) +{ + GetMe()->assertWriteEnabled(); + + const AcDbVoidPtrArray& ar3D_ = Get3DBuffer(); + AcDbVoidPtrArray ar3D; + ar3D.append(ar3D_); + + AcDbEntity* pEnt = NULL; + AcDb3dSolid* pSolid = NULL; + AcDb3dSolid* pSolidCln = NULL; + AcDb3dSolid* pSolidNotGet = NULL; + Acad::ErrorStatus es; + + Adesk::Boolean bSlidInterface = Adesk::kFalse; + double dArea1 = 0.0,dArea2 = 0.0; + + for (int i = 0;i < ar3D.length();i++) + { + pEnt = (AcDbEntity*)ar3D.at(i); + + pSolid = AcDb3dSolid::cast(pEnt); + if (pSolid != NULL) + { + pSolidCln = (AcDb3dSolid*)pSolidBlackHole->clone(); + + //有交集才处理 + if ( Acad::eOk == pSolid->checkInterference( pSolidCln,Adesk::kFalse,bSlidInterface,pSolidNotGet)) + { + pSolid->getArea(dArea1); + + es = pSolid->booleanOper(AcDb::kBoolSubtract,pSolidCln); + + pSolid->getArea(dArea2); + + if ( es == Acad::eOk) + { + pSolid->recordGraphicsModified(Adesk::kTrue); + + if ( fabs(dArea1 - dArea2) < 1.e-3)//没有变化,被包含 + { + ar3D.removeAt(i); + m_ar3DDrableBufPtrs_.removeAt(i); + i -= 1; + } + } + else if ( es == Acad::eGeneralModelingFailure ) + { + ar3D.removeAt(i); + m_ar3DDrableBufPtrs_.removeAt(i); + i -= 1; + } + //delete pSolidCln; + } + } + } +} + +void AecDbEntityCommon::Remove3DBoolSubtract() +{ + GetMe()->assertWriteEnabled(); + + //清除3D,重建 + Clean3DBuffer(); +} + +void AecDbEntityCommon::AddBlackHole(AcDbObjectId& idHole) +{ + AssertWriteEnabled(); + + AecDbObjXDataMap* pXdataMap = GetSpecialtyData(AcDb::kForWrite); + if (pXdataMap != NULL) + { + TCHAR szHand[19]; + memset(szHand,0,sizeof(szHand) ); + idHole.handle().getIntoAsciiBuffer(szHand); + + CString sKey; + sKey.Format(_T("%s_%s"),KEY_HOLE,szHand); + pXdataMap->SetAt(sKey,idHole.handle()); + } +} + +void AecDbEntityCommon::RemoveBlackHole(AcDbObjectId& idHole) +{ + AssertWriteEnabled(); + + AecDbObjXDataMap* pXdataMap = GetSpecialtyData(AcDb::kForWrite); + if (pXdataMap != NULL) + { + TCHAR szHand[19]; + memset(szHand,0,sizeof(szHand) ); + idHole.handle().getIntoAsciiBuffer(szHand); + + CString sKey; + sKey.Format(_T("%s_%s"),KEY_HOLE,szHand); + pXdataMap->RemoveAt(sKey); + } +} + +void AecDbEntityCommon::DrawBlackHole(AcDbEntity* pSolidEnt) const +{ + AcDb3dSolid* pSolidAll = AcDb3dSolid::cast(pSolidEnt); + if (pSolidAll == NULL) + return; + + const AecDbObjXDataMap* pCXDataMap = GetSpecialtyData(); + if (pCXDataMap != NULL) + { + AecDbObjXDataMap* pXDataMap = (AecDbObjXDataMap*)pCXDataMap; + AecDbObjXDataMap::It it = pXDataMap->Begin(); + AecDbObjXDataMap::It end = pXDataMap->End(); + + CString sKey; + + AecXData cVal; + memset(&cVal,0,sizeof(AecXData)); + + AcDbEntity* pEnt = NULL; + AcDbHandle hd; + AcDbObjectId idHole; + + for (; it != end; ) + { + if (!pXDataMap->GetNext(it, sKey, cVal)) + break; + + if (sKey.Find(KEY_HOLE) != -1) + { + pXDataMap->GetAt(sKey,hd); + if ( Acad::eOk == acdbCurDwg()->getAcDbObjectId(idHole,false,hd) ) + { + if ( Acad::eOk == acdbOpenAcDbEntity(pEnt,idHole,AcDb::kForRead)) + { + if (IsThisMe(pEnt)) + { + AecDbEntityCommon *pBlackHole = dynamic_cast(pEnt); + if (pBlackHole != NULL) + { + AcDb3dSolid *pSolidBlackHold = pBlackHole->GetBlackHole(); + if (pSolidBlackHold != NULL) + { + pSolidAll->booleanOper(AcDb::kBoolSubtract, pSolidBlackHold); + } + } + } + pEnt->close(); + } + } + } + } + } +} + +void AecDbEntityCommon::UpdateDrableSpecData(LPCTSTR pszApp,LPCTSTR pszKey,CString& sVal) +{ + GetMe()->assertWriteEnabled(); + + AecDbObjXDataMap xDataMap; + AcDbEntity* pEnt = NULL,*pEntT = NULL; + const AcDbVoidPtrArray &ar2D = Get2DBuffer(); + for (int i = 0;i < ar2D.length();i++) + { + pEnt = (AcDbEntity*)ar2D.at(i); + + if (xDataMap.Read(pEnt,pszApp)) + { + xDataMap.RemoveAt(pszKey); + xDataMap.SetAt(pszKey,sVal); + xDataMap.Write(pEnt,pszApp); + } + } + + const AcDbVoidPtrArray &ar3D = Get3DBuffer(); + for (int i = 0;i < ar3D.length();i++) + { + pEnt = (AcDbEntity*)ar3D.at(i); + if (xDataMap.Read(pEnt,pszApp)) + { + xDataMap.RemoveAt(pszKey); + xDataMap.SetAt(pszKey,sVal); + xDataMap.Write(pEnt,pszApp); + } + } +} + +extern double PixelToWcs(int nPixel); +bool AecDbEntityCommon::SubAddHitEditGrip(AcDbGripDataPtrArray &grips) const +{ + GetMe()->assertReadEnabled(); + + AecGripData *pGrip = NULL; + GetPositionGrip(grips.length() - 1, pGrip); + + if (pGrip != NULL) + { + AcGePoint3d ptHit = pGrip->ptGrip; + ptHit += AcGeVector3d::kXAxis * PixelToWcs(30); + + AecGripData *pGrip2 = new AecGripData; + memset(pGrip2, 0, sizeof(AecGripData)); + + pGrip2->nIndex = grips.length(); + pGrip2->ePos = eHitEdit; + pGrip2->nColor = kRed; + pGrip2->ptGrip = ptHit; + _tcscpy(pGrip2->szTip, _T("点击修改")); + _tcscpy(pGrip2->szID, _T("HITEDIT_2023")); + pGrip2->pOwner = (AcDbEntity *)GetMe(); + pGrip2->idHost = GetMe()->objectId(); + AcDbGripData *pGripData = new AcDbGripData; + pGripData->setGripPoint(ptHit); + pGripData->setAppData((void *)pGrip2); + pGripData->setWorldDraw(AecGripCback::WorldDrawfunc); + pGripData->setToolTipFunc(AecGripCback::GripToolTipFunc); + grips.append(pGripData); + + return true; + } + + return false; +} + +//不得导出,需要数据,增加特定的获取函数 +extern AecDbObjXDataMap g_mapGlobalData; +bool AecDbEntityCommon::HitOnGripEdit(const AcDbVoidPtrArray &gripAppData) +{ + AecGripData *pAppData = NULL; + AcDbIntArray arIndex; + + if (gripAppData.isEmpty()) + { + return Acad::eOk; + } + + pAppData = (AecGripData *)gripAppData.first(); + if (pAppData->ePos == eHitEdit) + { + //命令名 DBL_DXFNAME + TCHAR szCmd[65]; + _tcscpy(szCmd, _T("DBL_")); + _tcscat(szCmd, GetMe()->isA()->dxfName()); + + //判断命令是否存在 + AcEdCommand *pCmd = acedRegCmds->lookupLocalCmd(szCmd); + if (pCmd != NULL) + { + //发送ID 到 USERI; + AcDbObjectId id = pAppData->idHost; + + g_mapGlobalData.SetAt(szCmd, id); + + acedPostCommand(_T("\x03")); + + _tcscat(szCmd, _T(" ")); + acedPostCommand(szCmd); + } + else + { + acutPrintf(_T("\nLocalCmd %s does not exist!"), szCmd); + } + return true; + } + return false; +} + +//按分隔符拆字符串。来源:AecDbEntityBase.cpp / AecDbCurveBase.cpp(两族逐字相同) +void AecDbEntityCommon::SplitStrintToArray(LPCTSTR pszDescr, CStringArray & arInfo, TCHAR tcSpace) +{ + if (pszDescr == NULL) return; + + CString sDescr = pszDescr; + int nLen = sDescr.GetLength(); + int i = 0; + CString sText = _T(""); + TCHAR tchar = _T('\0'); + + for (i = 0; i < nLen; i++) + { + tchar = sDescr.GetAt(i); + if (tchar == tcSpace) + { + if (!sText.IsEmpty()) + arInfo.Add(sText); + sText = _T(""); + } + else + { + sText += tchar; + } + + if (i == nLen - 1 && !sText.IsEmpty()) + { + arInfo.Add(sText); + } + } +} + +// 世界绘制:原 AecDbEntityBase::subWorldDraw / AecDbCurveBase::subWorldDraw 逐行一致。 +// subWorldDraw 是 AcGiDrawable 的虚函数,本类不在 AcDb 继承链上,只能由两个根各自转发。 +Adesk::Boolean AecDbEntityCommon::base_WorldDraw(AcGiWorldDraw *pWd) +{ + GetMe()->assertReadEnabled(); + + m_eExplodeOrDrawType = kWroldDraw; + AcGiViewDraw dc(pWd, NULL); + dc.SetDrawRaw(GetMe()); + + //1.如果是保存代理图形 + AcGiRegenType nRegenType = pWd->regenType(); + if (nRegenType == kAcGiSaveWorldDrawForProxy) + { + ads_point pt; + struct resbuf rb; + acedGetVar(_T("VIEWDIR"),&rb); + ads_point_set(rb.resval.rpoint,pt); + + ads_point viewDir; + acdbUcs2Wcs(pt,viewDir,false); + + if (fabs(viewDir[X]) > 1.0e-6 || fabs(viewDir[Y]) > 1.0e-6) + { + Draw3d(dc); + m_nDrawDimCur = 3; + } + else + { + Draw2d(dc); + m_nDrawDimCur = 2; + } + return Adesk::kTrue; + } + + //设属性 + dc.SetLayer(_T("0")); + dc.SetColor(256); + + //如果图层关闭 + AcDbLayerTableRecordPointer pLayer; + if ( Acad::eOk == pLayer.open(GetMe()->layerId(), AcDb::kForRead) ) + { + if ( pLayer->isOff() ) + { + return Adesk::kTrue; + } + } + + int nDrawMode = GetDrawMode(); + DrawModeType nDrawType = k2Dand3D; + int nDraw = GetDrawDimOnType(nDrawMode, nDrawType); + + if (nRegenType == kAcGiSaveWorldDrawForProxy + || nRegenType == kAcGiSaveWorldDrawForR12) + { + if (!!GetMe()->ownerId()) + { + pWd->subEntityTraits().setSelectionMarker(0); + dc.SetColor(GetMe()->colorIndex()); + dc.SetLayer(GetMe()->layerId()); + } + + if ((nDrawMode & DRAW_2D) && (nDrawType != k3DOnly)) + { + Draw2d(dc); + m_nDrawDimCur = 2; + } + else if ((nDrawMode & DRAW_3D) && (nDrawType != k2DOnly)) + { + Draw3d(dc); + m_nDrawDimCur = 3; + } + return Adesk::kTrue; + } + return Adesk::kFalse; +} + +// 视口绘制:原 AecDbEntityBase::subViewportDraw / AecDbCurveBase::subViewportDraw 逐行一致。 +// 同样是 AcGiDrawable 的虚函数,只能由两个根各自转发。 +void AecDbEntityCommon::base_ViewportDraw(AcGiViewportDraw* pMode) +{ + GetMe()->assertReadEnabled(); + 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(); + AcGiViewDraw dc(NULL, pMode); + dc.SetDrawRaw(GetMe()); + + // 设属性 + dc.SetLayer(_T("0")); + dc.SetColor(256); + + //如果图层关闭 + AcDbLayerTableRecordPointer pLayer; + if ( Acad::eOk == pLayer.open(GetMe()->layerId(), AcDb::kForRead) ) + { + if ( pLayer->isOff() ) + { + return; + } + } + + if (!!GetMe()->ownerId()) + { + pMode->subEntityTraits().setSelectionMarker(0); + dc.SetColor(GetMe()->colorIndex()); + dc.SetLayer(GetMe()->layerId()); + } + + int nDrawMode = GetDrawMode(); + DrawModeType nDrawType = k2Dand3D; + int nDraw = GetDrawDimOnType(nDrawMode, nDrawType); + + if (nDraw == 3) + { + if ( nRegenType == kAcGiRenderCommand + || nRegenType == kAcGiHideOrShadeCommand + || vp.isPerspective() + || vtViewDrt != AcGeVector3d(0,0,1)) + { + Draw3d(dc); + m_nDrawDimCur = 3; + } + else + { + Draw2d(dc); + m_nDrawDimCur = 2; + } + } + else if (nDraw == 1) + { + Draw2d(dc); + m_nDrawDimCur = 2; + } + else if (nDraw == 2) + { + Draw3d(dc); + m_nDrawDimCur = 3; + } +} + +// 保存代理实体图元:原两个根的 saveAs 逐行一致。 +void AecDbEntityCommon::base_SaveAs(AcGiWorldDraw *pWd, AcDb::SaveType saveType) +{ + AecDbObjXDataMap xDataMap; + ReadModelXData(EW_EARTHWORMINIT, xDataMap, NULL); + int nSaveToProxy(0); + xDataMap.GetAt(_T("SaveToProxy"), nSaveToProxy); + if (nSaveToProxy == 0) // 不保存代理图形 + return; + + AcGiRegenType rtype = pWd->regenType(); + if (rtype == kAcGiSaveWorldDrawForProxy) + { + // 走实体自己的 subWorldDraw(子类可能重写),不是 Common 的 base_WorldDraw + CallWorldDraw(pWd); + } + else + { + GetMe()->AcDbEntity::saveAs(pWd, saveType); + } +} + +// 视口绘制标志:原两个根的 subViewportDrawLogicalFlags 逐行一致。 +// nBaseFlags 由两个根用 AcDbEntity::subViewportDrawLogicalFlags(vd) 取到后传入—— +// 该接口在 AcGiDrawable / AcDbObject 里是 protected,本类不在继承链上取不到。 +Adesk::UInt32 AecDbEntityCommon::base_ViewportDrawLogicalFlags(Adesk::UInt32 nBaseFlags) +{ + Adesk::UInt32 nFlagNew = nBaseFlags; + int nDrawMode = GetDrawMode(); + DrawModeType nDrawType = k2Dand3D; + int nDraw = GetDrawDimOnType(nDrawMode, nDrawType); + + if (nDraw != 3) + { + nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw; + } + else + { + nFlagNew |= AcGiDrawable::kDrawableRegenDraw; + } + return nFlagNew; +} + +// 绘制属性:原两个根的 subSetAttributes 逐行一致,同样是 protected,base 结果由根传入。 +Adesk::UInt32 AecDbEntityCommon::base_SetAttributes(Adesk::UInt32 nBaseFlags) +{ + int nDrawMode = GetDrawMode(); + DrawModeType nDrawType = k2Dand3D; + int nDraw = GetDrawDimOnType(nDrawMode, nDrawType); + + Adesk::UInt32 nFlagNew = nBaseFlags; + nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw; + + return nFlagNew; +} + +// 炸开:原两个根的 subExplode 逐行一致。 +Acad::ErrorStatus AecDbEntityCommon::base_Explode(AcDbVoidPtrArray& entitySet) const +{ + ExplodeOrDrawType& eExplodeType = (ExplodeOrDrawType&)m_eExplodeOrDrawType; + eExplodeType = kExplode; + + int expMode = GetExplodeMode(); + if (expMode == 1) + { + GetDraw2dables(0,entitySet); + } + else if (expMode == 2) + { + GetDraw3dables(entitySet); + } + return Acad::eOk; +} + +// 几何范围:原 AecDbEntityBase::subGetGeomExtents / AecDbCurveBase::subGetGeomExtents 逐行一致。 +Acad::ErrorStatus AecDbEntityCommon::base_GetGeomExtents(AcDbExtents& extents) const +{ + AcGePoint3d ptLow, ptUp; + + AcDbVoidPtrArray entSet; + int expMode = GetExplodeMode(); + if (expMode == 1) + { + entSet.append(Get2DBuffer()); + } + else if (expMode == 2) + { + entSet.append(Get3DBuffer()); + } + + BOOL bInit = TRUE; + AcGePoint3d ptMax,ptMin; + AcDbExtents ext,extT; + + int len = entSet.length(); + for (int i = 0; i < len; i++) + { + AcDbEntity *pEnt = (AcDbEntity *)entSet[i]; + + if (pEnt->getGeomExtents(extT) == Acad::eOk) + { + ext.addExt(extT); + } + } + ptLow = ext.minPoint(); + ptUp = ext.maxPoint(); + extents.set(ptLow, ptUp); + + return Acad::eOk; +} + +// 对象捕捉点:原两个根的 subGetOsnapPoints(第一个重载)逐行一致。 +Acad::ErrorStatus AecDbEntityCommon::base_GetOsnapPoints( AcDb::OsnapMode osnapMode, + INT_PTR gsSelectionMark, + const AcGePoint3d& ptPick, + const AcGePoint3d& lastPoint, + const AcGeMatrix3d& viewXform, + AcGePoint3dArray& snapPoints, + AcDbIntArray& geomIds) const +{ + GetMe()->assertReadEnabled(); + + AcDbVoidPtrArray entSet; + int expMode = GetExplodeMode(); + if (expMode == 1) + { + entSet.append(Get2DBuffer()); + } + else if (expMode == 2) + { + entSet.append(Get3DBuffer()); + } + + Acad::ErrorStatus es = Acad::eOk; + 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; + } + return Acad::eOk; +} + +Acad::ErrorStatus AecDbEntityCommon::base_DeepClone( AcDbObject* pOwner, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary) const +{ + // You should always pass back pClonedObject == NULL + // if, for any reason, you do not actually clone it + // during this call. The caller should pass it in + // as NULL, but to be safe, we set it here as well. + // + pClonedObject = NULL; + + // If this object is in the idMap and is already + // cloned, then return. + // + bool isPrim = false; + if (isPrimary) + isPrim = true; + AcDbIdPair idPair(GetMe()->objectId(), (AcDbObjectId)NULL, + false, isPrim); + if (idMap.compute(idPair) && (idPair.value() != NULL)) + return Acad::eOk; + + // Create the clone + // + AcDbEntity *pClone = (AcDbEntity*)GetMe()->isA()->create(); + AecDbEntityCommon *pCloneCommon = dynamic_cast(pClone); + if (pClone != NULL && pCloneCommon != NULL) + pClonedObject = pClone; // set the return value + else + return Acad::eOutOfMemory; + + AcDbDeepCloneFiler filer; + GetMe()->dwgOut(&filer); + + filer.seek(0L, AcDb::kSeekFromStart); + pClone->dwgIn(&filer); + pCloneCommon->NewGUID(); + pClone->setLayer(GetMe()->layerId()); + + bool bOwnerXlated = false; + if (isPrimary) + { + AcDbBlockTableRecord *pBTR = + AcDbBlockTableRecord::cast(pOwner); + if (pBTR != NULL) + { + pBTR->appendAcDbEntity(pClone); + bOwnerXlated = true; + } + else + { + pOwner->database()->addAcDbObject(pClone); + } + } else { + pOwner->database()->addAcDbObject(pClone); + pClone->setOwnerId(pOwner->objectId()); + bOwnerXlated = true; + } + + // This must be called for all newly created objects + // in deepClone. It is turned off by endDeepClone() + // after it has translated the references to their + // new values. + // + pClone->setAcDbObjectIdsInFlux(); + pClone->disableUndoRecording(true); + + + // Add the new information to the idMap. We can use + // the idPair started above. + // + idPair.setValue(pClonedObject->objectId()); + idPair.setIsCloned(Adesk::kTrue); + idPair.setIsOwnerXlated(bOwnerXlated); + idMap.assign(idPair); + + // Using the filer list created above, find and clone + // any owned objects. + // + AcDbObjectId id; + while (filer.getNextOwnedObject(id)) { + + AcDbObject *pSubObject(NULL); + AcDbObject *pClonedSubObject(NULL); + + // Some object's references may be set to NULL, + // so don't try to clone them. + // + if (id == NULL) + continue; + + // Open the object and clone it. Note that we now + // set "isPrimary" to kFalse here because the object + // is being cloned, not as part of the primary set, + // but because it is owned by something in the + // primary set. + // + acdbOpenAcDbObject(pSubObject, id, AcDb::kForRead); + if (pSubObject == NULL) + continue; + pClonedSubObject = NULL; + pSubObject->deepClone(pClonedObject, + pClonedSubObject, + idMap, Adesk::kFalse); + + // If this is a kDcInsert context, the objects + // may be "cheapCloned". In this case, they are + // "moved" instead of cloned. The result is that + // pSubObject and pClonedSubObject will point to + // the same object. So, we only want to close + // pSubObject if it really is a different object + // than its clone. + // + if (pSubObject != pClonedSubObject) + pSubObject->close(); + + // The pSubObject may either already have been + // cloned, or for some reason has chosen not to be + // cloned. In that case, the returned pointer will + // be NULL. Otherwise, since we have no immediate + // use for it now, we can close the clone. + // + if (pClonedSubObject != NULL) + pClonedSubObject->close(); + } + + //xdataMap 复制 + //到mep中找建立新的关系 + AecDbObjXDataMap* pXDataMapCloned = pCloneCommon->GetSpecialtyData(); + AecDbObjXDataMap* pXDataMap = (AecDbObjXDataMap*)GetSpecialtyData(); + + if (pXDataMap != NULL && pXDataMapCloned != NULL) + { + pXDataMapCloned->CopyFrom(pXDataMap); + //发送提资需要相同的ID + Adesk::Int16 nVal = acdbCurDwg()->useri4(); + if (nVal != KEY_NOPROTECT) + { + int nVt = 0; + CString sID = IDCreate(); + if (pXDataMapCloned->HasKey(KEY_NO, nVt)) + { + pXDataMapCloned->SetAt(KEY_NO, sID); + } + } + + AecDbObjXDataMap::It it = pXDataMap->Begin(); + AecDbObjXDataMap::It end = pXDataMap->End(); + + CString sKey; + CStringArray arHandKeys; + + AecXData cVal; + memset(&cVal,0,sizeof(AecXData)); + + AcDbObjectId idSrc,idCloned; + for (; it != end; ) + { + if (!pXDataMap->GetNext(it, sKey, cVal)) break; + if (cVal.nVt == AecXData::kTypeSoftId || cVal.nVt == AecXData::kTypeHardId)//soft,hard + { + idSrc.setFromOldId(cVal.nVal); + + AcDbObject *pSubObject; + AcDbObject *pClonedSubObject; + + // Some object's references may be set to NULL, + // so don't try to clone them. + // + if (idSrc == NULL) + continue; + + AcDbIdPair idPair2(idSrc, (AcDbObjectId)NULL, + false, isPrim); + if (idMap.compute(idPair2) && (idPair2.value() != NULL)) + { + if (pXDataMapCloned != NULL) + { + pXDataMapCloned->RemoveAt(sKey); + pXDataMapCloned->SetAt(sKey, idPair2.value(), cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); + } + continue; + } + + // Open the object and clone it. Note that we now + // set "isPrimary" to kFalse here because the object + // is being cloned, not as part of the primary set, + // but because it is owned by something in the + // primary set. + // + pSubObject = NULL; + acdbOpenAcDbObject(pSubObject, idSrc, AcDb::kForRead); + pClonedSubObject = NULL; + + if (pSubObject != NULL) + { + //只考虑上华AEC的实体 + LPCTSTR pszDxf = pSubObject->isA()->dxfName(); + if (_tcsstr(pszDxf, _T("AEC_'")) != NULL) + { + pSubObject->deepClone(pClonedObject, + pClonedSubObject, + idMap, Adesk::kFalse); + } + else + { + pSubObject->close(); + pSubObject = NULL; + } + } + + // If this is a kDcInsert context, the objects + // may be "cheapCloned". In this case, they are + // "moved" instead of cloned. The result is that + // pSubObject and pClonedSubObject will point to + // the same object. So, we only want to close + // pSubObject if it really is a different object + // than its clone. + // + if (pSubObject != NULL && pSubObject != pClonedSubObject) + pSubObject->close(); + + // The pSubObject may either already have been + // cloned, or for some reason has chosen not to be + // cloned. In that case, the returned pointer will + // be NULL. Otherwise, since we have no immediate + // use for it now, we can close the clone. + // + if (pClonedSubObject != NULL) + idCloned = pClonedSubObject->objectId(); + + if (pClonedSubObject != NULL) + pClonedSubObject->close(); + + if (pXDataMapCloned != NULL && idCloned.isValid()) + { + pXDataMapCloned->RemoveAt(sKey); + pXDataMapCloned->SetAt(sKey, idCloned, cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); + } + idCloned = AcDbObjectId::kNull; + } + else if (sKey.Find(_T("$H")) != -1 && cVal.nVt == AecXData::kTypeString)//可能的实体句柄 + { + arHandKeys.Add(sKey); + } + } + + //2022-05-04 需要测试 + CString sHand; + AcDbHandle hd; + for (int n = 0; n < arHandKeys.GetSize(); n++) + { + sKey = arHandKeys.GetAt(n); + sHand = sKey; + sHand.TrimRight(_T("$H")); + + AcDbHandle handle(sHand); + + AcDbObjectId idSrc; + if (Acad::eOk == acdbCurDwg()->getAcDbObjectId(idSrc, false, handle)) + { + AcDbObject *pSubObject; + AcDbObject *pClonedSubObject; + + // Some object's references may be set to NULL, + // so don't try to clone them. + // + if (idSrc == NULL) + continue; + + AcDbIdPair idPair2(idSrc, (AcDbObjectId)NULL, + false, isPrim); + if (idMap.compute(idPair2) && (idPair2.value() != NULL)) + { + CString sKeyNew; + //sKey.Format(_T("%s$H"),szHand); + + if (pXDataMapCloned != NULL) + { + TCHAR szHand[19]; + memset(szHand, 0, sizeof(szHand)); + idPair2.value().handle().getIntoAsciiBuffer(szHand); + sKeyNew.Format(_T("%s$H"), szHand); + + pXDataMapCloned->RemoveAt(sKey); + pXDataMapCloned->SetAt(sKeyNew, szHand); + } + continue; + } + + // Open the object and clone it. Note that we now + // set "isPrimary" to kFalse here because the object + // is being cloned, not as part of the primary set, + // but because it is owned by something in the + // primary set. + // + pSubObject = NULL; + acdbOpenAcDbObject(pSubObject, idSrc, AcDb::kForRead); + pClonedSubObject = NULL; + + if (pSubObject != NULL) + { + //只考虑上华AEC的实体 + LPCTSTR pszDxf = pSubObject->isA()->dxfName(); + if (_tcsstr(pszDxf, _T("AEC_'")) != NULL) + { + pSubObject->deepClone(pClonedObject, + pClonedSubObject, + idMap, Adesk::kFalse); + } + else + { + pSubObject->close(); + pSubObject = NULL; + } + } + + // If this is a kDcInsert context, the objects + // may be "cheapCloned". In this case, they are + // "moved" instead of cloned. The result is that + // pSubObject and pClonedSubObject will point to + // the same object. So, we only want to close + // pSubObject if it really is a different object + // than its clone. + // + if (pSubObject != pClonedSubObject) + pSubObject->close(); + + // The pSubObject may either already have been + // cloned, or for some reason has chosen not to be + // cloned. In that case, the returned pointer will + // be NULL. Otherwise, since we have no immediate + // use for it now, we can close the clone. + // + if (pClonedSubObject != NULL) + idCloned = pClonedSubObject->objectId(); + + if (pClonedSubObject != NULL) + pClonedSubObject->close(); + + if (pXDataMapCloned != NULL && idCloned.isValid()) + { + CString sKeyNew; + TCHAR szHand[19]; + memset(szHand, 0, sizeof(szHand)); + + idCloned.handle().getIntoAsciiBuffer(szHand); + sKeyNew.Format(_T("%s$H"), szHand); + + pXDataMapCloned->RemoveAt(sKey); + pXDataMapCloned->SetAt(sKeyNew, szHand); + } + idCloned = AcDbObjectId::kNull; + } + } + } + + // Leave pClonedObject open for the caller + return Acad::eOk; +} + +Acad::ErrorStatus AecDbEntityCommon::base_WblockClone(AcRxObject* pOwner, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary) const +{ + // You should always pass back pClonedObject == NULL + // if, for any reason, you do not actually clone it + // during this call. The caller should pass it in + // as NULL, but to be safe, we set it here as well. + // + pClonedObject = NULL; + + // fast wblock(源库与目标库相同)不做任何克隆,交回 AcDb 一侧。 + AcDbDatabase *pDest, *pOrig; + idMap.destDb(pDest); + idMap.origDb(pOrig); + if (pDest == pOrig) + return CallAcDbWblockClone(pOwner, pClonedObject, idMap, isPrimary); + + // If this is an Xref bind operation and this AsdkPoly + // entity is in Paper Space, then we don't want to + // clone because Xref bind doesn't support cloning + // entities in Paper Space. So we simply return + // Acad::eOk + // + AcDbObjectId pspace; + AcDbBlockTable *pTable(NULL); + GetMe()->database()->getSymbolTable(pTable, AcDb::kForRead); + if (pTable == NULL) + return Acad::eOk; + pTable->getAt(ACDB_PAPER_SPACE, pspace); + pTable->close(); + + if (idMap.deepCloneContext() == AcDb::kDcXrefBind + && GetMe()->ownerId() == pspace) + return Acad::eOk; + + // If this object is in the idMap and is already + // cloned, then return. + // + bool isPrim = false; + if (isPrimary) + isPrim = true; + + AcDbIdPair idPair(GetMe()->objectId(), (AcDbObjectId)NULL, + false, isPrim); + if (idMap.compute(idPair) && (idPair.value() != NULL)) + return Acad::eOk; + + // The owner object can be either an AcDbObject, or an + // AcDbDatabase. AcDbDatabase is used if the caller is + // not the owner of the object being cloned (because it + // is being cloned as part of an AcDbHardPointerId + // reference). In this case, the correct ownership + // will be set during reference translation. So, if + // the owner is an AcDbDatabase, then pOwn will be left + // NULL here, and is used as a "flag" later. + // + + AcDbObject *pOwn = AcDbObject::cast(pOwner); + AcDbDatabase *pDb = AcDbDatabase::cast(pOwner); + if (pDb == NULL) + pDb = pOwn->database(); + + // STEP 1: + // Create the clone + // + AcDbEntity *pClone = (AcDbEntity*)GetMe()->isA()->create(); + AecDbEntityCommon *pCloneCommon(NULL); + if (pClone) + { + pCloneCommon = dynamic_cast(pClone); + if (pCloneCommon != NULL) + pClonedObject = pClone; // set the return value + else + { + DELETE_PTR(pClone); + return Acad::eOutOfMemory; + } + } + else + return Acad::eOutOfMemory; + + + // STEP 2: + // If the owner is an AcDbBlockTableRecord, go ahead + // and append the clone. If not, but we know who the + // owner is, set the clone's ownerId to it. Otherwise, + // we set the clone's ownerId to our own ownerId (in + // other words, the original owner Id). This Id will + // then be used later, in reference translation, as + // a key to finding who the new owner should be. This + // means that the original owner must also be cloned at + // some point during the wblock operation. + // EndDeepClone's reference translation aborts if the + // owner is not found in the idMap. + // + // The most common situation where this happens is + // AcDbEntity references to Symbol Table Records, such + // as the Layer an Entity is on. This is when you will + // have to pass in the destination database as the owner + // of the Layer Table Record. Since all Symbol Tables + // are always cloned in Wblock, you do not need to make + // sure that Symbol Table Record owners are cloned. + // + // However, if the owner is one of your own classes, + // then it is up to you to make sure that it gets + // cloned. This is probably easiest to do at the end + // of this function. Otherwise you may have problems + // with recursion when the owner, in turn, attempts + // to clone this object as one of its subObjects. + // + AcDbBlockTableRecord *pBTR = NULL; + if (pOwn != NULL) + pBTR = AcDbBlockTableRecord::cast(pOwn); + if (pBTR != NULL && isPrimary) { + pBTR->appendAcDbEntity(pClone); + } + else { + pDb->addAcDbObject(pClonedObject); + } + + // STEP 3: + // The AcDbWblockCloneFiler makes a list of + // AcDbHardOwnershipIds and AcDbHardPointerIds. These + // are the references which must be cloned during a + // Wblock operation. + // + AcDbWblockCloneFiler filer; + GetMe()->dwgOut(&filer); + + // STEP 4: + // Rewind the filer and read the data into the clone. + // + filer.seek(0L, AcDb::kSeekFromStart); + pClone->dwgIn(&filer); + pCloneCommon->NewGUID(); + + idMap.assign(AcDbIdPair(GetMe()->objectId(), pClonedObject->objectId(), Adesk::kTrue, + isPrim, (Adesk::Boolean)(pOwn != NULL))); + + pClonedObject->setOwnerId((pOwn != NULL) ? + pOwn->objectId() : GetMe()->ownerId()); + + // STEP 5: + // This must be called for all newly created objects + // in wblockClone. It is turned off by endDeepClone() + // after it has translated the references to their + // new values. + // + pClone->setAcDbObjectIdsInFlux(); + + // STEP 6: + // Add the new information to the idMap. We can use + // the idPair started above. We must also let the + // idMap entry know whether the clone's owner is + // correct, or needs to be translated later. + // + + // STEP 7: + // Using the filer list created above, find and clone + // any hard references. + // + + AcDbObjectId id; + while (filer.getNextHardObject(id)) + { + AcDbObject *pSubObject(NULL); + AcDbObject *pClonedSubObject(NULL); + + // Some object's references may be set to NULL, + // so don't try to clone them. + // + if (id == NULL) + continue; + + // If the referenced object is from a different + // database, such as an xref, do not clone it. + // + acdbOpenAcDbObject(pSubObject, id, AcDb::kForRead); + if (pSubObject == NULL) + continue; + if (pSubObject->database() != GetMe()->database()) { + pSubObject->close(); + continue; + } + + // We can find out if this is an AcDbHardPointerId + // verses an AcDbHardOwnershipId, by seeing if we + // are the owner of the pSubObject. If we are not, + // then we cannot pass our clone in as the owner + // for the pSubObject's clone. In that case, we + // pass in our clone's database (the destination + // database). + // + // Note that we now set "isPrimary" to kFalse here + // because the object is being cloned, not as part + // of the primary set, but because it is owned by + // something in the primary set. + // + pClonedSubObject = NULL; + if (pSubObject->ownerId() == GetMe()->objectId()) { + pSubObject->wblockClone(pClone, + pClonedSubObject, + idMap, Adesk::kFalse); + } + else { + pSubObject->wblockClone(pClone->database(), + pClonedSubObject, + idMap, Adesk::kFalse); + } + pSubObject->close(); + + // The pSubObject may either already have been + // cloned, or for some reason has chosen not to be + // cloned. In that case, the returned pointer will + // be NULL. Otherwise, since we have no immediate + // use for it now, we can close the clone. + // + if (pClonedSubObject != NULL) + pClonedSubObject->close(); + } + + //xdataMap 复制 + //到mep中找建立新的关系 + + AecDbObjXDataMap *pXDataMapCloned = pCloneCommon->GetSpecialtyData(); + + + AecDbObjXDataMap *pXDataMap = (AecDbObjXDataMap *)GetSpecialtyData(); + + if (pXDataMap != NULL && pXDataMapCloned != NULL) + { + //发送提资需要相同的ID + Adesk::Int16 nVal = acdbCurDwg()->useri4(); + if (nVal != KEY_NOPROTECT) + { + int nVt = 0; + CString sID = IDCreate(); + if (pXDataMapCloned->HasKey(KEY_NO, nVt)) + { + pXDataMapCloned->SetAt(KEY_NO, sID); + } + } + + AecDbObjXDataMap::It it = pXDataMap->Begin(); + AecDbObjXDataMap::It end = pXDataMap->End(); + + CString sKey; + CStringArray arHandKeys; + + AecXData cVal; + memset(&cVal, 0, sizeof(AecXData)); + + AcDbObjectId idSrc, idCloned; + for (; it != end;) + { + if (!pXDataMap->GetNext(it, sKey, cVal)) break; + if (cVal.nVt == AecXData::kTypeSoftId || cVal.nVt == AecXData::kTypeHardId)//soft,hard + { + idSrc.setFromOldId(cVal.nVal); + + AcDbObject *pSubObject; + AcDbObject *pClonedSubObject; + + // Some object's references may be set to NULL, + // so don't try to clone them. + // + if (idSrc == NULL) + continue; + + AcDbIdPair idPair2(idSrc, (AcDbObjectId)NULL, + false, isPrim); + if (idMap.compute(idPair2) && (idPair2.value() != NULL)) + { + if (pXDataMapCloned != NULL) + { + pXDataMapCloned->SetAt(sKey, idPair2.value(), cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); + } + continue; + } + + // Open the object and clone it. Note that we now + // set "isPrimary" to kFalse here because the object + // is being cloned, not as part of the primary set, + // but because it is owned by something in the + // primary set. + // + acdbOpenAcDbObject(pSubObject, idSrc, AcDb::kForRead); + if (pSubObject == NULL) + continue; + pClonedSubObject = NULL; + + if (pSubObject->ownerId() == GetMe()->objectId()) { + pSubObject->wblockClone(pClone, + pClonedSubObject, + idMap, Adesk::kFalse); + } + else { + pSubObject->wblockClone(pClone->database(), + pClonedSubObject, + idMap, Adesk::kFalse); + } + + // If this is a kDcInsert context, the objects + // may be "cheapCloned". In this case, they are + // "moved" instead of cloned. The result is that + // pSubObject and pClonedSubObject will point to + // the same object. So, we only want to close + // pSubObject if it really is a different object + // than its clone. + // + if (pSubObject != NULL && pSubObject != pClonedSubObject) + pSubObject->close(); + + // The pSubObject may either already have been + // cloned, or for some reason has chosen not to be + // cloned. In that case, the returned pointer will + // be NULL. Otherwise, since we have no immediate + // use for it now, we can close the clone. + // + if (pClonedSubObject != NULL) + idCloned = pClonedSubObject->objectId(); + + if (pClonedSubObject != NULL) + pClonedSubObject->close(); + + if (pXDataMapCloned != NULL && idCloned.isValid()) + { + pXDataMapCloned->RemoveAt(sKey); + pXDataMapCloned->SetAt(sKey, idCloned, cVal.nVt == AecXData::kTypeSoftId ? TRUE : FALSE); + } + idCloned = AcDbObjectId::kNull; + } + else if (sKey.Find(_T("$H")) != -1 && cVal.nVt == AecXData::kTypeString)//可能的实体句柄 + { + arHandKeys.Add(sKey); + } + } + } + return Acad::eOk; +} + + + diff --git a/SourceCode/Code2026/AecRxBase/cmakelists.txt b/SourceCode/Code2026/AecRxBase/cmakelists.txt index 0583c3e..5a6f965 100644 --- a/SourceCode/Code2026/AecRxBase/cmakelists.txt +++ b/SourceCode/Code2026/AecRxBase/cmakelists.txt @@ -9,6 +9,7 @@ set(SOURCES "AecBaseDoubleClickEdit.cpp" "AecDbCurveBase.cpp" "AecDbEntityBase.cpp" + "AecDbEntityCommon.cpp" "AecDbObjXDataMap.cpp" "AecGiSubEntityTraits.cpp" "AecGripCback.cpp" diff --git a/SourceCode/Code2026/inc/AecDbCurveBase.h b/SourceCode/Code2026/inc/AecDbCurveBase.h index be0e91e..b30a26a 100644 --- a/SourceCode/Code2026/inc/AecDbCurveBase.h +++ b/SourceCode/Code2026/inc/AecDbCurveBase.h @@ -4,6 +4,7 @@ #include "AecSubDef.h" #include "shJson.h" #include "EarThwormDef.h" +#include "AecDbEntityCommon.h" #pragma warning(disable: 4275 4251) @@ -21,71 +22,15 @@ class AecDbObjXDataMap; class AcGiViewDraw; class AcGiExplodeDraw; -namespace SimpleProperty { struct PropertySetByIndex; struct PropertySetByName; } -class AECDLLIMPEXP AecDbCurveBase : public AcDbCurve +class AECDLLIMPEXP AecDbCurveBase : public AcDbCurve, public AecDbEntityCommon { public: - template - BOOL GetAt(LPCTSTR pszKey, T &va) const - { - const AecDbObjXDataMap *pMap(GetSpecialtyData()); - if (!pMap) return FALSE; - return pMap->GetAt(pszKey, va); - } - - template - BOOL GetAt(LPCTSTR pszKey, T1 va1, T2 va2) const - { - const AecDbObjXDataMap *pMap(GetSpecialtyData()); - if (!pMap) return FALSE; - return pMap->GetAt(pszKey, va1, va2); - } - - template - BOOL GetAt(LPCTSTR pszKey, TCHAR (&va)[N]) const - { - const AecDbObjXDataMap *pMap(GetSpecialtyData()); - if (!pMap) return FALSE; - CString s; - if (pMap->GetAt(pszKey, s) == FALSE) return FALSE; - - _tcsncpy_s(va, N, s, N - 1); - - return TRUE; - } - - template - BOOL GetAt(LPCTSTR pszKey, LPTSTR va) const - { - const AecDbObjXDataMap *pMap(GetSpecialtyData()); - if (!pMap) return FALSE; - CString s; - if (pMap->GetAt(pszKey, s) == FALSE) return FALSE; - - _tcsncpy_s(va, N, s, N - 1); - - return TRUE; - } - - template - BOOL SetAt(LPCTSTR pszKey, T va) - { - AecDbObjXDataMap *pMap(GetSpecialtyData(AcDb::kForWrite)); - if (!pMap) return FALSE; - return pMap->SetAt(pszKey, va); - } - - template - BOOL SetAt(LPCTSTR pszKey, T1 va1, T2 va2) - { - AecDbObjXDataMap *pMap(GetSpecialtyData(AcDb::kForWrite)); - if (!pMap) return FALSE; - return pMap->SetAt(pszKey, va1, va2); - } + ACRX_DECLARE_MEMBERS(AecDbCurveBase); public: - - ACRX_DECLARE_MEMBERS(AecDbCurveBase); + virtual AcDbEntity *GetMe() { return this; } + virtual const AcDbEntity *GetMe() const { return this; } + virtual bool IsThisMe(const AcDbEntity *pEnt) const { return AecDbCurveBase::cast(pEnt) != NULL; } protected: AecDbCurveBase(void); @@ -113,17 +58,17 @@ public: virtual Acad::ErrorStatus setColorIndex(Adesk::UInt16 color,Adesk::Boolean doSubents = true); virtual Acad::ErrorStatus subIntersectWith( const AcDbEntity* ent, - AcDb::Intersect intType, - AcGePoint3dArray& points, - INT_PTR thisGsMarker, - INT_PTR otherGsMarker) const; + AcDb::Intersect intType, + AcGePoint3dArray& points, + INT_PTR thisGsMarker, + INT_PTR otherGsMarker) const; virtual Acad::ErrorStatus subIntersectWith( const AcDbEntity* ent, - AcDb::Intersect intType, - const AcGePlane& projPlane, - AcGePoint3dArray& points, - INT_PTR thisGsMarker, - INT_PTR otherGsMarker) const; + AcDb::Intersect intType, + const AcGePlane& projPlane, + AcGePoint3dArray& points, + INT_PTR thisGsMarker, + INT_PTR otherGsMarker) const; virtual Acad::ErrorStatus subSetPropertiesFrom( const AcDbEntity* pEntity, Adesk::Boolean doSubents = Adesk::kTrue); @@ -230,88 +175,26 @@ public: AcDbIdMapping& idMap, Adesk::Boolean isPrimary = Adesk::kTrue) const; +protected: + virtual Acad::ErrorStatus CallAcDbWblockClone(AcRxObject* pOwnerObject, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary) const; + + // 桥:回到具体实体自己的 subWorldDraw(子类可能重写,saveAs 的代理分支要用)。 + // subWorldDraw 在 AcGiDrawable 里是 protected,本类取不到,由两个根转调。 + virtual Adesk::Boolean CallWorldDraw(AcGiWorldDraw* pWd); + +public: virtual Acad::ErrorStatus setTransparency(const AcCmTransparency &trans, Adesk::Boolean doSubents = true); public: - //获取当前显示模式 - int GetDrawDimCur() const; - - //专业数据 和绘制设置 - virtual AecDbObjXDataMap* GetSpecialtyData(AcDb::OpenMode bMode = AcDb::kForWrite) = 0; - virtual const AecDbObjXDataMap* GetSpecialtyData() const = 0; - - //获取二维视图显示的图形 - virtual int GetDraw2dables(Adesk::UInt16 nDrawStyle, AcDbVoidPtrArray& arEntPtrs) const; - - //获取三维显示图形 - virtual int GetDraw3dables(AcDbVoidPtrArray& arEntPtrs,bool bWriteBimInfo = false ) const; - - //剖切提取 - virtual int GetSectionDraw(const AcGePoint3d& ptFr,const AcGePoint3d& ptTo,const AcGeVector3d& vtViewDir,const AcGeVector3d& vtTo, AcDbVoidPtrArray& arRegionPtrs) const; - - //剖切填充根据材质获取样式 - bool GetSectionHatchPattern(CString& sPattern) const; - - Acad::ErrorStatus ReCreateDraw2d(); - Acad::ErrorStatus ReCreateDraw3d(); - - virtual double GetVolume(bool bIsBody = false) const; - virtual int ComparedTo(AecDbCurveBase* pCurOther) const; - virtual void SetActive(bool bActive){}; - virtual bool IsActive() const{return false;} - virtual void NewGUID() {}; - - // 导出json - virtual SHJson::WValue& ToJson(bool bExprotGeo = true) const; - // 通过json创建 - virtual bool ByJson(const SHJson::WValue &v); - - // 得到实体唯一得名字,revit 通过这个字符串来判断是否有同样得实体 - // 如果有,则在revit中可以生成一个族来替代这些同样得实体,以加快速度 - virtual CString getUniqueName() const; - double GetArea() const; - void Add3DBoolSubtract(AcDb3dSolid* pSolidBlackHole); - void Remove3DBoolSubtract(); - - virtual AcDb3dSolid* GetBlackHole() const; - void AddBlackHole(AcDbObjectId& idHole); - void RemoveBlackHole(AcDbObjectId& idHole); - void DrawBlackHole(AcDbEntity* pSolidEnt) const; - - void UpdateDrableSpecData(LPCTSTR pszApp,LPCTSTR pszKey,CString& sVal); - - virtual bool GetBimInfoTip(CString& sInfoTip) const; - - // 为方便用户查询实体的属性,可以重载此函数,目前,此函数使用在“实体快速选择”功能上 - virtual bool GetProperties(SimpleProperty::PropertySetByIndex &porpertys) const; - virtual bool SetProperties(SimpleProperty::PropertySetByName &porpertys); - - //用户级别的数据调用消息 - virtual bool SendUserData(struct resbuf *pRb); - -protected: - - //动态绘制状态记录值 - ExplodeOrDrawType m_eExplodeOrDrawType; - - //控制全局的所有实体的显示模式 - static int GetDrawMode(); - static void SetDrawMode(int nMode); - static void BackupColorIndex(AcDbEntity* pEnt); - static int SetBackupColorIndex(AcDbEntity* pEnt); - - //获取炸碎2D/3d模式 - int GetExplodeMode() const; - - //获取显示维度 0--NONE; 1--2D; 2--3D; 3--2D&3D - int GetDrawDimOnType(int nDrawMode, int nDrawType) const; - protected: virtual Acad::ErrorStatus SetBaseCurve(const AcDbCurve* pDbCurve); @@ -319,91 +202,7 @@ protected: //返回原生Curve,不可以删除 virtual AcDbCurve* GetNativeCurve() const; - //以下需要 AEC 派生 - virtual Acad::ErrorStatus Draw2d(AcGiDraw &dc) const; - - virtual Acad::ErrorStatus Draw3d(AcGiDraw &dc) const; - - short m_nDrawDimCur; - -protected: - //清理图元的特定writeenable - virtual void AssertWriteEnabled(Adesk::Boolean autoUndo = true, Adesk::Boolean recordModified = true); - - //2023-6-26 增加单击夹点发送命令DBL_DXF - virtual bool GetPositionGrip(int nIndex, AecGripData*& pGrip) const; - bool SubAddHitEditGrip(AcDbGripDataPtrArray &grips) const; - bool HitOnGripEdit(const AcDbVoidPtrArray &gripAppData); - public: - bool Draw3DBuffers(AcGiDraw &dc)const; - bool Draw2DBuffers(AcGiDraw &dc)const; - - const AcDbVoidPtrArray& Get3DBuffer()const; - const AcDbVoidPtrArray& Get2DBuffer()const; - - bool Has3DBuffer()const; - bool Has2DBuffer()const; - - void Add3DBuffer(AcDbEntity *pEnt)const; - void Add2DBuffer(AcDbEntity *pEnt)const; - - bool IsIn2DBuffer(AcDbEntity* pEnt) const; - bool IsIn3DBuffer(AcDbEntity* pEnt) const; - - void Add3DBuffer(const AcDbVoidPtrArray &arr)const; - void Add2DBuffer(const AcDbVoidPtrArray &arr)const; - - void Clean3DBuffer()const; - void Clean2DBuffer()const; - - void Clean3DBufferNoDel()const; - void Clean2DBufferNoDel()const; - - void BoolSubtractHide() const; - - Acad::ErrorStatus subGet3dGeomExtents(AcDbExtents &extents) const; - - /* - hlr计算,会默认调用实体的 Draw3d 函数,得到绘制的结果。 - 但是,对与有些实体,并不够用,还需要补充一些 - 比如:管线的中心线和梯度符号等等 - */ - virtual void PreprocessForHlr(const AcGePoint3d &ptPlnO - , const AcGeVector3d &vtPlnN - , AcArray &ar) const; - /* - 此函数只修改 ar内的实体的 图层、线型、颜色, 但线宽不处理 - 如有其他要求,重载 - - ar 是 hlr 通过调用实体的Draw3d函数得到的结果 - - preAr 中的 first(AcDbEntity*) 来自于 “PreprocessForHlr” 函数得到的实体指针 - preAr 中的 second 来自于 first 经过 hlr 计算之后的结果 - 基类不处理 preAr -*/ - virtual void ProcessHlrResult(const AcArray &ar - , const std::map> &preAr - , AcArray &output) const; -public: - template static BOOL CopyObject(const K &src, K &dest) - { - AcDbDeepCloneFiler filer; - BOOL bRet = FALSE; - if (src.dwgOutFields(&filer) == Acad::eOk) - { - filer.seek(0L, AcDb::kSeekFromStart); - bRet = (dest.dwgInFields(&filer) == Acad::eOk); - } - return bRet; - } - - static void SplitStrintToArray(LPCTSTR pszDescr, CStringArray & arInfo, TCHAR tcSpace); - static AcDbPolyline* StringToPolyline(LPCTSTR pszPoint2ds); - -private: - // 以下为绘制缓存部分,分为2D和3D两部分 - mutable AcDbVoidPtrArray m_ar2DDrableBufPtrs_;//临时缓存 俯视图 - mutable AcDbVoidPtrArray m_ar3DDrableBufPtrs_;//临时缓存 - mutable SHJson::WValue m_json; + // 曲线族特有:绘制时按宿主图层/颜色设置缓存实体(Common 里声明为 virtual) + virtual bool Draw2DBuffers(AcGiDraw &dc)const; }; diff --git a/SourceCode/Code2026/inc/AecDbEntityBase.h b/SourceCode/Code2026/inc/AecDbEntityBase.h index 2f200a1..622abfa 100644 --- a/SourceCode/Code2026/inc/AecDbEntityBase.h +++ b/SourceCode/Code2026/inc/AecDbEntityBase.h @@ -4,6 +4,7 @@ #include "AecSubDef.h" #include "shJson.h" #include "EarThwormDef.h" +#include "AecDbEntityCommon.h" #if ARX > 25 #include "AecDbObjXDataMap.h" @@ -24,70 +25,16 @@ class AcGiViewDraw; class AcGiExplodeDraw; namespace SimpleProperty { struct PropertySetByIndex; struct PropertySetByName; } -class AECDLLIMPEXP AecDbEntityBase : public AcDbEntity +class AECDLLIMPEXP AecDbEntityBase : public AcDbEntity, public AecDbEntityCommon { public: - template - BOOL GetAt(LPCTSTR pszKey, T &va) const - { - const AecDbObjXDataMap *pMap(GetSpecialtyData()); - if (!pMap) return FALSE; - return pMap->GetAt(pszKey, va); - } - - template - BOOL GetAt(LPCTSTR pszKey, T1 va1, T2 va2) const - { - const AecDbObjXDataMap *pMap(GetSpecialtyData()); - if (!pMap) return FALSE; - return pMap->GetAt(pszKey, va1, va2); - } - - template - BOOL GetAt(LPCTSTR pszKey, TCHAR(&va)[N]) const - { - const AecDbObjXDataMap *pMap(GetSpecialtyData()); - if (!pMap) return FALSE; - CString s; - if (pMap->GetAt(pszKey, s) == FALSE) return FALSE; - - _tcsncpy_s(va, N, s, N - 1); - - return TRUE; - } - - template - BOOL GetAt(LPCTSTR pszKey, LPTSTR va) const - { - const AecDbObjXDataMap *pMap(GetSpecialtyData()); - if (!pMap) return FALSE; - CString s; - if (pMap->GetAt(pszKey, s) == FALSE) return FALSE; - - _tcsncpy_s(va, N, s, N - 1); - - return TRUE; - } - - template - BOOL SetAt(LPCTSTR pszKey, T va) - { - AecDbObjXDataMap *pMap(GetSpecialtyData(AcDb::kForWrite)); - if (!pMap) return FALSE; - return pMap->SetAt(pszKey, va); - } - - template - BOOL SetAt(LPCTSTR pszKey, T1 va1, T2 va2) - { - AecDbObjXDataMap *pMap(GetSpecialtyData(AcDb::kForWrite)); - if (!pMap) return FALSE; - return pMap->SetAt(pszKey, va1, va2); - } -public: - ACRX_DECLARE_MEMBERS(AecDbEntityBase); +public: + virtual AcDbEntity *GetMe() { return this; } + virtual const AcDbEntity *GetMe() const { return this; } + virtual bool IsThisMe(const AcDbEntity *pEnt) const { return AecDbEntityBase::cast(pEnt) != NULL; } + protected: AecDbEntityBase(void); virtual ~AecDbEntityBase(void); @@ -119,7 +66,8 @@ public: INT_PTR thisGsMarker, INT_PTR otherGsMarker) const; - virtual Acad::ErrorStatus subSetPropertiesFrom( const AcDbEntity* pEntity, Adesk::Boolean doSubents = Adesk::kTrue); + virtual Acad::ErrorStatus subSetPropertiesFrom( const AcDbEntity* pEntity + , Adesk::Boolean doSubents = Adesk::kTrue); #if (ARX > 15) virtual Acad::ErrorStatus subGetOsnapPoints( AcDb::OsnapMode osnapMode, @@ -181,177 +129,23 @@ public: AcDbIdMapping& idMap, Adesk::Boolean isPrimary = Adesk::kTrue) const; +protected: + virtual Acad::ErrorStatus CallAcDbWblockClone(AcRxObject* pOwnerObject, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary) const; + + // 桥:回到具体实体自己的 subWorldDraw(子类可能重写,saveAs 的代理分支要用)。 + // subWorldDraw 在 AcGiDrawable 里是 protected,本类取不到,由两个根转调。 + virtual Adesk::Boolean CallWorldDraw(AcGiWorldDraw* pWd); + +public: virtual Acad::ErrorStatus setTransparency(const AcCmTransparency &trans, Adesk::Boolean doSubents = true); public: - //获取当前显示模式 - int GetDrawDimCur() const; - - //专业数据 和绘制设置 - virtual AecDbObjXDataMap* GetSpecialtyData(AcDb::OpenMode bMode = AcDb::kForWrite) = 0; - virtual const AecDbObjXDataMap* GetSpecialtyData() const = 0; - - //获取二维视图显示的图形 - virtual int GetDraw2dables(Adesk::UInt16 nDrawStyle, AcDbVoidPtrArray& arEntPtrs) const; - - //获取三维显示图形 - virtual int GetDraw3dables(AcDbVoidPtrArray& arEntPtrs,bool bWriteBimInfo = false ) const; - - //剖切提取 - virtual int GetSectionDraw(const AcGePoint3d& ptFr,const AcGePoint3d& ptTo,const AcGeVector3d& vtViewDir,const AcGeVector3d& vtTo, AcDbVoidPtrArray& arRegionPtrs) const; - - bool GetSectionHatchPattern(CString& sPattern) const; - - Acad::ErrorStatus ReCreateDraw2d(); - Acad::ErrorStatus ReCreateDraw3d(); - //获取体积 - virtual double GetVolume(bool bIsBody = false) const; - virtual int ComparedTo(AecDbEntityBase* pEntOther) const; - virtual void SetActive(bool bActive){}; - virtual bool IsActive() const{return false;} - virtual void NewGUID() {} - - // 导出json - virtual SHJson::WValue& ToJson(bool bExprotGeo = true) const; - // 通过json创建 - virtual bool ByJson(const SHJson::WValue &v); - - // 得到实体唯一得名字,revit 通过这个字符串来判断是否有同样得实体 - // 如果有,则在revit中可以生成一个族来替代这些同样得实体,以加快速度 - virtual CString getUniqueName() const; - - double GetArea() const; - - //... - void Add3DBoolSubtract(AcDb3dSolid* pSolidBlackHole); - void Remove3DBoolSubtract(); - - virtual AcDb3dSolid* GetBlackHole() const; - void AddBlackHole(AcDbObjectId& idHole); - void RemoveBlackHole(AcDbObjectId& idHole); - void DrawBlackHole(AcDbEntity* pSolidEnt) const; - - void UpdateDrableSpecData(LPCTSTR pszApp,LPCTSTR pszKey,CString& sVal); - - virtual bool GetBimInfoTip(CString& sInfoTip) const; - - // 为方便用户查询实体的属性,可以重载此函数,目前,此函数使用在“实体快速选择”功能上 - virtual bool GetProperties(SimpleProperty::PropertySetByIndex &porpertys) const; - virtual bool SetProperties(SimpleProperty::PropertySetByName &porpertys); - - //用户级别的数据调用消息 - virtual bool SendUserData(struct resbuf *pRb); - -protected: - - //动态绘制状态记录值 - ExplodeOrDrawType m_eExplodeOrDrawType; - - //控制全局的所有实体的显示模式 - static int GetDrawMode(); - static void SetDrawMode(int nMode); - static void BackupColorIndex(AcDbEntity* pEnt); - static int SetBackupColorIndex(AcDbEntity* pEnt); - - //获取炸碎2D/3d模式 - int GetExplodeMode() const; - - //获取显示维度 0--NONE; 1--2D; 2--3D; 3--2D&3D - int GetDrawDimOnType(int nDrawMode, int nDrawType) const; - -protected: - - //以下需要 AEC 派生 - virtual Acad::ErrorStatus Draw2d(AcGiDraw &dc) const; - - virtual Acad::ErrorStatus Draw3d(AcGiDraw &dc) const; - - short m_nDrawDimCur; - -protected: - //清理图元的特定writeenable - virtual void AssertWriteEnabled(Adesk::Boolean autoUndo = true, Adesk::Boolean recordModified = true); - - //2023-6-26 增加单击夹点发送命令DBL_DXF - virtual bool GetPositionGrip(int nIndex, AecGripData *&pGrip) const; - bool SubAddHitEditGrip(AcDbGripDataPtrArray &grips) const; - bool HitOnGripEdit(const AcDbVoidPtrArray &gripAppData); - -public: - bool Draw3DBuffers(AcGiDraw &dc)const; - bool Draw2DBuffers(AcGiDraw &dc)const; - - const AcDbVoidPtrArray& Get3DBuffer()const; - const AcDbVoidPtrArray& Get2DBuffer()const; - - bool Has3DBuffer()const; - bool Has2DBuffer()const; - - void Add3DBuffer(AcDbEntity *pEnt)const; - void Add2DBuffer(AcDbEntity *pEnt)const; - - bool IsIn2DBuffer(AcDbEntity* pEnt) const; - bool IsIn3DBuffer(AcDbEntity* pEnt) const; - - void Add3DBuffer(const AcDbVoidPtrArray &arr)const; - void Add2DBuffer(const AcDbVoidPtrArray &arr)const; - - void Clean3DBuffer()const; - void Clean2DBuffer()const; - - void Clean3DBufferNoDel()const; - void Clean2DBufferNoDel()const; - - void BoolSubtractHide() const; - - Acad::ErrorStatus subGet3dGeomExtents(AcDbExtents &extents) const; - - /* - hlr计算,会默认调用实体的 Draw3d 函数,得到绘制的结果。 - 但是,对与有些实体,并不够用,还需要补充一些 - 比如:管线的中心线和梯度符号等等 - */ - virtual void PreprocessForHlr( const AcGePoint3d &ptPlnO - , const AcGeVector3d &vtPlnN - , AcArray &ar) const; - - /* - 此函数只修改 ar内的实体的 图层、线型、颜色, 但线宽不处理 - 如有其他要求,重载 - - ar 是 hlr 通过调用实体的Draw3d函数得到的结果 - - preAr 中的 first(AcDbEntity*) 来自于 “PreprocessForHlr” 函数得到的实体指针 - preAr 中的 second 来自于 first 经过 hlr 计算之后的结果 - 基类不处理 preAr - */ - virtual void ProcessHlrResult(const AcArray &ar - , const std::map> &preAr - , AcArray &output ) const; - -public: - template static BOOL CopyObject(const K &src, K &dest) - { - AcDbDeepCloneFiler filer; - BOOL bRet = FALSE; - if (src.dwgOutFields(&filer) == Acad::eOk) - { - filer.seek(0L, 0); - bRet = (dest.dwgInFields(&filer) == Acad::eOk); - } - return bRet; - } - - static void SplitStrintToArray(LPCTSTR pszDescr, CStringArray & arInfo, TCHAR tcSpace); - static AcDbPolyline* StringToPolyline(LPCTSTR pszPoint2ds); - -private: - // 以下为绘制缓存部分,分为2D和3D两部分 - mutable AcDbVoidPtrArray m_ar2DDrableBufPtrs_;//临时缓存 俯视图 - mutable AcDbVoidPtrArray m_ar3DDrableBufPtrs_;//临时缓存 - mutable SHJson::WValue m_json; + virtual double GetArea() const; }; diff --git a/SourceCode/Code2026/inc/AecDbEntityCommon.h b/SourceCode/Code2026/inc/AecDbEntityCommon.h new file mode 100644 index 0000000..d1dc904 --- /dev/null +++ b/SourceCode/Code2026/inc/AecDbEntityCommon.h @@ -0,0 +1,342 @@ +#pragma once +// ============================================================================ +// AecDbEntityCommon.h +// +// 自定义实体的公共基类。 +// +// AecDbEntityBase : public AcDbEntity +// AecDbCurveBase : public AcDbCurve +// +// 两者是两条平行的根(AcDb 类不能虚继承),历史上是两份逐行复制的实现。 +// 本类不继承任何 AcDb / ARX 类,只承载两条根中 AcDbEntity 虚函数那一层, +// 以及它们必须的依赖(显示缓存、显示模式、写使能、静态工具)。 +// +// 约定: +// 1. 需要 AcDb 基类的实现时,直接 GetMe()->AcDbEntity::xxx(...) 限定调用, +// 不为「AcDbEntity:: 还是 AcDbCurve::」另立钩子。 +// AcDbCurve 没有重写这些接口(dwgInFields / subList / saveAs / setTransparency / +// setColorIndex / subWblockClone … 都在 AcDbEntity),两者是同一个实现。 +// 2. 两族行为有差异的函数,本类给默认实现并声明为 virtual, +// 由有差异的那一族 override。不用 bool 开关参数,也不合并行为。 +// 3. 需要回到 AcDb 一侧操作时走 GetMe()。 +// ============================================================================ + +#include "dbmain.h" +#include "AcGiDraw.h" +#include "AecSubDef.h" +#include "shJson.h" +#include "EarThwormDef.h" + +#pragma warning(disable: 4275 4251) + +// 与 AecDbEntityBase.h 相同的导出规则:AecRxBase 内部导出,其它模块导入。 +// 用独立宏名,避免与 AECDLLIMPEXP 的定义顺序互相影响。 +#ifdef AECRXBASE_EXPORT +#define AECCOMMON_DLLIMPEXP __declspec(dllexport) +#else +#define AECCOMMON_DLLIMPEXP __declspec(dllimport) +#endif + +class AecDbObjXDataMap; +class AcGiViewDraw; +class AcGiExplodeDraw; +namespace SimpleProperty { struct PropertySetByIndex; struct PropertySetByName; } + +#ifndef _ttof +#define _ttof(pszVal) _tcstod((pszVal), NULL) +#endif + + +class AECCOMMON_DLLIMPEXP AecDbEntityCommon +{ +public: + AecDbEntityCommon(void); + virtual ~AecDbEntityCommon(void); + +protected: + // 世界绘制:原 AecDbEntityBase::subWorldDraw / AecDbCurveBase::subWorldDraw + // 逐行一致。subWorldDraw 是 AcGiDrawable 的虚函数,本类不在 AcDb 继承链上, + // 只能由两个根各自留一行转发。 + virtual Adesk::Boolean base_WorldDraw(AcGiWorldDraw* pWd); + + // 视口绘制:原两个根的 subViewportDraw 逐行一致,同样只能由两个根转发。 + virtual void base_ViewportDraw(AcGiViewportDraw* pMode); + + // 视口绘制标志 / 绘制属性:原两个根逐行一致。 + // 这两个接口在 AcDb 一侧是 protected,本类取不到,由两个根先调基类、 + // 把基类结果作为 nBaseFlags 传进来,这里只负责叠加自己的标志位。 + virtual Adesk::UInt32 base_ViewportDrawLogicalFlags(Adesk::UInt32 nBaseFlags); + virtual Adesk::UInt32 base_SetAttributes(Adesk::UInt32 nBaseFlags); + + // 炸开:原两个根的 subExplode 逐行一致。 + virtual Acad::ErrorStatus base_Explode(AcDbVoidPtrArray& entitySet) const; + + // 保存代理实体图元:原两个根的 saveAs 逐行一致。 + // 代理分支要回到具体实体自己的 subWorldDraw(子类可能重写),走 CallWorldDraw。 + virtual void base_SaveAs(AcGiWorldDraw* pWd, AcDb::SaveType saveType); + + // 几何范围:原两个根的 subGetGeomExtents 逐行一致。 + virtual Acad::ErrorStatus base_GetGeomExtents(AcDbExtents& extents) const; + + // 对象捕捉点(第一个重载):原两个根逐行一致。 + virtual Acad::ErrorStatus base_GetOsnapPoints(AcDb::OsnapMode osnapMode, + INT_PTR gsSelectionMark, + const AcGePoint3d& ptPick, + const AcGePoint3d& lastPoint, + const AcGeMatrix3d& viewXform, + AcGePoint3dArray& snapPoints, + AcDbIntArray& geomIds) const; + + virtual Acad::ErrorStatus base_DeepClone( AcDbObject* pOwnerObject, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary = Adesk::kTrue) const; + + virtual Acad::ErrorStatus base_WblockClone( AcRxObject* pOwnerObject, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary = Adesk::kTrue) const; + + // 桥:转调 AcDb 一侧原生的 subWblockClone(fast wblock 时用它交回基类)。 + // subWblockClone 在 AcDbObject 里是 protected,本类不在继承链上, + // 只能由两个根各自转调,限定 AcDbEntity:: / AcDbCurve::。 + virtual Acad::ErrorStatus CallAcDbWblockClone(AcRxObject* pOwnerObject, + AcDbObject*& pClonedObject, + AcDbIdMapping& idMap, + Adesk::Boolean isPrimary) const = 0; + + // 桥:回到具体实体自己的 subWorldDraw(子类可能重写,saveAs 的代理分支要用)。 + // subWorldDraw 在 AcGiDrawable 里是 protected,本类不在继承链上取不到。 + virtual Adesk::Boolean CallWorldDraw(AcGiWorldDraw* pWd) = 0; + + // ------------------------------------------------------------------ + // 桥:由 AecDbEntityBase / AecDbCurveBase 实现 + // ------------------------------------------------------------------ +public: + // 回到 AcDb 一侧。两个根的 AcDb 根都是第一个基类,实现为 return this; + virtual AcDbEntity* GetMe() = 0; + virtual const AcDbEntity* GetMe() const = 0; + virtual bool IsThisMe(const AcDbEntity *pEnt) const = 0; + + // 专业数据容器(两个根原本就是纯虚接口) + virtual AecDbObjXDataMap* GetSpecialtyData(AcDb::OpenMode bMode = AcDb::kForWrite) = 0; + virtual const AecDbObjXDataMap* GetSpecialtyData() const = 0; + + //获取当前显示模式 + int GetDrawDimCur() const; + + + // 得到实体唯一得名字,revit 通过这个字符串来判断是否有同样得实体 + // 如果有,则在revit中可以生成一个族来替代这些同样得实体,以加快速度 + virtual CString getUniqueName() const; + + virtual void NewGUID() {} + + virtual double GetArea() const {return .0;} + + virtual void PreprocessForHlr( const AcGePoint3d &ptPlnO + , const AcGeVector3d &vtPlnN + , AcArray &ar) const; + + /* + 此函数只修改 ar内的实体的 图层、线型、颜色, 但线宽不处理 + 如有其他要求,重载 + + ar 是 hlr 通过调用实体的Draw3d函数得到的结果 + + preAr 中的 first(AcDbEntity*) 来自于 “PreprocessForHlr” 函数得到的实体指针 + preAr 中的 second 来自于 first 经过 hlr 计算之后的结果 + 基类不处理 preAr + */ + virtual void ProcessHlrResult(const AcArray &ar + , const std::map> &preAr + , AcArray &output ) const; + + virtual bool GetBimInfoTip(CString& sInfoTip) const; + + // 为方便用户查询实体的属性,可以重载此函数,目前,此函数使用在“实体快速选择”功能上 + virtual bool GetProperties(SimpleProperty::PropertySetByIndex &porpertys) const; + virtual bool SetProperties(SimpleProperty::PropertySetByName &porpertys); + + // 导出json + virtual SHJson::WValue& ToJson(bool bExprotGeo = true) const; + // 通过json创建 + virtual bool ByJson(const SHJson::WValue &v); + + + //获取体积 + virtual double GetVolume(bool bIsBody = false) const; + + virtual void SetActive(bool bActive) {}; + + virtual bool IsActive() const { return false; } + +protected: + // 子类真正实现的绘制入口(两个根的默认实现都是 return eOk) + virtual Acad::ErrorStatus Draw2d(AcGiDraw& dc) const; + virtual Acad::ErrorStatus Draw3d(AcGiDraw& dc) const; + + virtual void AssertWriteEnabled(Adesk::Boolean autoUndo = true, Adesk::Boolean recordModified = true); + +protected: + static int GetDrawMode(); + static void SetDrawMode(int nMode); + static void BackupColorIndex(AcDbEntity* pEnt); + static int SetBackupColorIndex(AcDbEntity* pEnt); + + //获取炸碎2D/3d模式 + int GetExplodeMode() const; + + //获取显示维度 0--NONE; 1--2D; 2--3D; 3--2D&3D + int GetDrawDimOnType(int nDrawMode, int nDrawType) const; + + //2023-6-26 增加单击夹点发送命令DBL_DXF + virtual bool GetPositionGrip(int nIndex, AecGripData *&pGrip) const { return NULL; } + bool SubAddHitEditGrip(AcDbGripDataPtrArray &grips) const; + bool HitOnGripEdit(const AcDbVoidPtrArray &gripAppData); + +public: + // 2d 缓存操作 + virtual bool Draw2DBuffers(AcGiDraw &dc) const; + const AcDbVoidPtrArray& Get2DBuffer()const; + bool Has2DBuffer()const; + void Add2DBuffer(AcDbEntity *pEnt)const; + void Add2DBuffer(const AcDbVoidPtrArray &arr)const; + bool IsIn2DBuffer(AcDbEntity* pEnt) const; + void Clean2DBuffer()const; + void Clean2DBufferNoDel()const; + + // 3d 缓存操作 + bool Draw3DBuffers(AcGiDraw &dc) const; + const AcDbVoidPtrArray &Get3DBuffer()const; + bool Has3DBuffer()const; + void Add3DBuffer(AcDbEntity *pEnt)const; + void Add3DBuffer(const AcDbVoidPtrArray &arr)const; + bool IsIn3DBuffer(AcDbEntity *pEnt) const; + void Clean3DBuffer()const; + void Clean3DBufferNoDel()const; + + Acad::ErrorStatus ReCreateDraw2d(); + Acad::ErrorStatus ReCreateDraw3d(); + + //获取二维视图显示的图形 + virtual int GetDraw2dables(Adesk::UInt16 nDrawStyle, AcDbVoidPtrArray &arEntPtrs) const; + + //获取三维显示图形 + virtual int GetDraw3dables(AcDbVoidPtrArray &arEntPtrs, bool bWriteBimInfo = false) const; + + + //用户级别的数据调用消息 + virtual bool SendUserData(struct resbuf *pRb) { return false; } + + virtual int GetSectionDraw(const AcGePoint3d &ptFr + , const AcGePoint3d &ptTo + , const AcGeVector3d &vtViewDir + , const AcGeVector3d &vtTo + , AcDbVoidPtrArray &arRegionPtrs) const { return 0; } + + virtual AcDb3dSolid *GetBlackHole() const { return NULL; } + + //剖切提取 + bool GetSectionHatchPattern(CString& sPattern) const; + + void BoolSubtractHide() const; + Acad::ErrorStatus subGet3dGeomExtents(AcDbExtents &extents) const; + + void Add3DBoolSubtract(AcDb3dSolid* pSolidBlackHole); + void Remove3DBoolSubtract(); + void AddBlackHole(AcDbObjectId& idHole); + void RemoveBlackHole(AcDbObjectId& idHole); + void DrawBlackHole(AcDbEntity* pSolidEnt) const; + + void UpdateDrableSpecData(LPCTSTR pszApp,LPCTSTR pszKey,CString& sVal); + + //按分隔符拆字符串(CoreLibrary / PipelineCmd 等多处按 AecDbEntityBase:: 限定调用) + static void SplitStrintToArray(LPCTSTR pszDescr, CStringArray & arInfo, TCHAR tcSpace); + +protected: + // 绘制函数被调用的方式(WorldDraw / ViewportDraw / Explode) + // mutable:subExplode 是 const 函数,原实现靠 const_cast 写入 + mutable ExplodeOrDrawType m_eExplodeOrDrawType; + + // 最近一次实际绘制的是 2D / 3D(-1 表示尚未绘制) + short m_nDrawDimCur; + + // 2D / 3D 显示缓存 + mutable AcDbVoidPtrArray m_ar2DDrableBufPtrs_;//临时缓存 俯视图 + mutable AcDbVoidPtrArray m_ar3DDrableBufPtrs_;//临时缓存 + +private: + mutable SHJson::WValue m_json; + +public: + template + BOOL GetAt(LPCTSTR pszKey, T &va) const + { + const AecDbObjXDataMap *pMap(GetSpecialtyData()); + if (!pMap) return FALSE; + return pMap->GetAt(pszKey, va); + } + + template + BOOL GetAt(LPCTSTR pszKey, T1 va1, T2 va2) const + { + const AecDbObjXDataMap *pMap(GetSpecialtyData()); + if (!pMap) return FALSE; + return pMap->GetAt(pszKey, va1, va2); + } + + template + BOOL GetAt(LPCTSTR pszKey, TCHAR(&va)[N]) const + { + const AecDbObjXDataMap *pMap(GetSpecialtyData()); + if (!pMap) return FALSE; + CString s; + if (pMap->GetAt(pszKey, s) == FALSE) return FALSE; + + _tcsncpy_s(va, N, s, N - 1); + + return TRUE; + } + + template + BOOL GetAt(LPCTSTR pszKey, LPTSTR va) const + { + const AecDbObjXDataMap *pMap(GetSpecialtyData()); + if (!pMap) return FALSE; + CString s; + if (pMap->GetAt(pszKey, s) == FALSE) return FALSE; + + _tcsncpy_s(va, N, s, N - 1); + + return TRUE; + } + + template + BOOL SetAt(LPCTSTR pszKey, T va) + { + AecDbObjXDataMap *pMap(GetSpecialtyData(AcDb::kForWrite)); + if (!pMap) return FALSE; + return pMap->SetAt(pszKey, va); + } + + template + BOOL SetAt(LPCTSTR pszKey, T1 va1, T2 va2) + { + AecDbObjXDataMap *pMap(GetSpecialtyData(AcDb::kForWrite)); + if (!pMap) return FALSE; + return pMap->SetAt(pszKey, va1, va2); + } + + template static BOOL CopyObject(const K &src, K &dest) + { + AcDbDeepCloneFiler filer; + BOOL bRet = FALSE; + if (src.dwgOutFields(&filer) == Acad::eOk) + { + filer.seek(0L, 0); + bRet = (dest.dwgInFields(&filer) == Acad::eOk); + } + return bRet; + } +};