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

1325 lines
29 KiB
C++

//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, SH Software Co. Ltd.
// = FileName : AecDbBlockInsert.cpp
// = Version : ver2.0
// = Author : zjq
// = CreateDate : 2002-09-09
// = Description: $图块类的定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "AecDbBlockInsert.h"
#include "DList.h"
#include "IdPointPair.h"
#include "XDbObject.h"
#include "XAcGiViewDraw.h"
#include "XConfigBase.h"
#include "XPrivateGlobalFunc.h"
#if ARX > 17
#include "AecDbGrip.h"
#include "AecDbGripDistDim.h"
#endif
#define TCHXD _T("_AEC") //扩展实体数据的应用程序名称
static DList<XIdPointPair> g_lstBlockInsertIds;
ACRX_DXF_DEFINE_MEMBERS(AecDbBlockInsert,AcDbBlockReference, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
1, AEC_DBLK_INSERT,"AEC_KERNAL|缺乏解释器图形看不见, 请下载插件");
const Adesk::UInt8 AecDbBlockInsert::g_nVersion = 4;
AecDbBlockInsert::AecDbBlockInsert()
{
m_nMaskFlag = 0;
}
AecDbBlockInsert::~AecDbBlockInsert()
{
}
Acad::ErrorStatus AecDbBlockInsert::setLayer(AcDbObjectId newVal, Adesk::Boolean doSubents)
{
BOOL bHasId = objectId().isValid();
BOOL bCurDb =(database() == acdbCurDwg());
BOOL bMView = IsMultiView();
BOOL bDisable = FALSE;
BOOL nDrawMode = GetDrawMode();
if (bHasId && bCurDb && bMView )
{
bDisable = TRUE;
}
if (bDisable)
{
return Acad::eOk;
}
return AcDbBlockReference::setLayer(newVal, doSubents);
}
Acad::ErrorStatus AecDbBlockInsert::setLayer(const TCHAR * newVal, Adesk::Boolean doSubents)
{
BOOL bHasId = objectId().isValid();
BOOL bCurDb = (database() == acdbCurDwg());
BOOL bMView = IsMultiView();
BOOL nDrawMode= GetDrawMode();
BOOL bDisable = FALSE;
if (bHasId && bCurDb && bMView )
{
bDisable = TRUE;
}
if (bDisable)
{
return Acad::eOk;
}
return AcDbBlockReference::setLayer(newVal, doSubents);
}
Adesk::UInt32
AecDbBlockInsert::subSetAttributes(AcGiDrawableTraits* pTraits)
{
Adesk::UInt32 nFlag = AcDbBlockReference::subSetAttributes(pTraits);
if (g_nAcadVer < 15.0001)
{
return nFlag;
}
int nDrawMode = GetDrawMode();
int nDraw = 0;
if (nDrawMode == 3 && IsMultiView())
{
nDraw = 3;
}
Adesk::UInt32 nFlagNew = nFlag;
if (g_nAcadVer > 15.0001)
{
nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw;
}
else
{
if (nDraw != 3)
{
nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw;
}
}
return nFlagNew;
}
Adesk::UInt32 AecDbBlockInsert::subViewportDrawLogicalFlags(AcGiViewportDraw * vd)
{
Adesk::UInt32 nRet = AcDbBlockReference::subViewportDrawLogicalFlags(vd);
ASSERT(g_nAcadVer > 15.0001);
Adesk::UInt32 nFlagNew = nRet;
int nDrawMode = GetDrawMode();
int nDraw = 0;
if (nDrawMode == 3 && IsMultiView())
{
nDraw = 3;
}
if (nDraw != 3)
{
nFlagNew |= AcGiDrawable::kDrawableViewIndependentViewportDraw;
}
else
{
nFlagNew |= 256;
}
return nFlagNew;
}
// 基类,不能正常克隆,因此需要重载
AcRxObject *AecDbBlockInsert::clone() const
{
AecDbBlockInsert *pClone = new AecDbBlockInsert;
CopyObject(*this, *pClone);
return pClone;
}
Adesk::Boolean AecDbBlockInsert::subCloneMeForDragging()
{
Adesk::Boolean bClone = AcDbBlockReference::subCloneMeForDragging();
return bClone;
}
// 从DWG读入数据:
Acad::ErrorStatus AecDbBlockInsert::dwgInFields (AcDbDwgFiler* pFiler)
{
// extern BOOL g_bUpdateMViewBlock;
assertWriteEnabled();
Acad::ErrorStatus es = AcDbBlockReference::dwgInFields(pFiler);
if (es != Acad::eOk)
{
return es;
}
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if (nVer > g_nVersion)
{
// 版本太新
return Acad::eMakeMeProxy;
}
pFiler->readItem(&m_nMaskFlag);
if (nVer == 1)
{
m_idBlock2d = _Get2DBlockId();
}
else
{
pFiler->readItem(&m_idBlock2d);
}
if (IsMultiView())
{
g_bUpdateMViewBlock = TRUE;
if (nVer == 2 && database() == acdbCurDwg())
{
m_nMaskFlag |= BIF_T6BETA1;
}
}
if (nVer > 3)
{
es = AEntityBase::DwgInFields(pFiler);
if (es != Acad::eOk)
{
return es;
}
}
return pFiler->filerStatus();
}
Acad::ErrorStatus AecDbBlockInsert::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = AcDbBlockReference::dwgOutFields(pFiler);
if (es != Acad::eOk)
{
return es;
}
if (g_nSaveTArchVer == 5)
{
pFiler->writeItem((Adesk::UInt8)1);
}
else if (g_nSaveTArchVer < 8)//6、7
{
pFiler->writeItem((Adesk::UInt8)3);
}
else
{
pFiler->writeItem(g_nVersion);
}
pFiler->writeItem(m_nMaskFlag);
if (g_nSaveTArchVer == 5)
{//
if (m_idBlock2d.isValid() && IsMultiView())
{
_Set2DBlockId(m_idBlock2d);
}
}
if (g_nSaveTArchVer > 5)
{
pFiler->writeItem(m_idBlock2d);
}
if (g_nSaveTArchVer > 7)
{
es = AEntityBase::DwgOutFields(pFiler);
if (es != Acad::eOk)
{
return es;
}
}
return pFiler->filerStatus();
}
Acad::ErrorStatus AecDbBlockInsert::dxfInFields (AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = AcDbBlockReference::dxfInFields(pFiler);
if (es != Acad::eOk)
{
return es;
}
if (!pFiler->atSubclassData(_T("AecDbBlockInsert")))
{
return Acad::eBadDxfSequence;
}
resbuf rb;
while ((es == Acad::eOk) && ((es = pFiler->readResBuf(&rb)) == Acad::eOk))
{
switch (rb.restype)
{
case 61:
m_nMaskFlag = (Adesk::UInt8)rb.resval.rint;
break;
default:
// 不识别的组抛出,让子类读取
pFiler->pushBackItem();
es = Acad::eEndOfFile;
break;
}
}
if (es != Acad::eEndOfFile)
{
return Acad::eInvalidResBuf;
}
return pFiler->filerStatus();
}
Acad::ErrorStatus AecDbBlockInsert::dxfOutFields(AcDbDxfFiler* pFiler) const
{
Acad::ErrorStatus es;
es = AcDbBlockReference::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass,_T("AecDbBlockInsert"));
assert(es == Acad::eOk);
ASSERT(pFiler->writeUInt16(61, (Adesk::UInt16)m_nMaskFlag) == Acad::eOk);
return es;
}
Adesk::Boolean AecDbBlockInsert::subWorldDraw(AcGiWorldDraw *pWd)
{
assertReadEnabled();
AcGiRegenType rType=pWd->regenType();
if (rType == kAcGiSaveWorldDrawForProxy)
{
return Adesk::kTrue;
}
XAcGiViewDraw dc(pWd,NULL);
if (!OnExplodeOrDraw(dc))
{
return Adesk::kTrue;
}
pWd->subEntityTraits().setSelectionMarker(0); // 解决ACAD2002消隐崩溃的问题
int nDraw = GetDrawMode();
AcDbObjectId idBlock2d = Get2DBlockId();
Adesk::Boolean bRet = Adesk::kTrue;
if ((m_nMaskFlag & BIF_T6BETA1) != 0)
{ //如果块表记录没有渲染材质,就没有必要执行这儿
// AutoCAD 2000不支持多视图图块, 2000i以上才支持
if (!idBlock2d.isValid() || !IsMultiView() ||
nDraw != DRAW_2D || g_nAcadVer < 15.0001)
{ //默认使用三维
AcDbBlockReference::subWorldDraw(pWd);
}
else
{ //完全二维,才使用二维视图,由于遇到包含材质的图块,多视图崩溃
AcGeMatrix3d matTrans = BlockTransform(this);
matTrans(2,3) = 0.0;
OPENOBJ_BEGIN(idBlock2d, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if (pBlock)
{
AcGiSubEntityTraits &traits = pWd->subEntityTraits();
AcDbObjectId idLayer = traits.layerId();
Adesk::UInt16 nColor = traits.color();
AcDbObjectId idLineType = traits.lineTypeId();
#if ARX > 17
AcDbObjectId idMaterial = traits.materialId();
#endif
AcGiGeometry *geom = pWd->rawGeometry();
geom->pushModelTransform(matTrans);
geom->draw(pBlock);
geom->popModelTransform();
traits.setLayer(idLayer);
traits.setColor(nColor);
traits.setLineType(idLineType);
#if ARX > 17
traits.setMaterial(idMaterial);
#endif
}
OPENOBJ_END();
}
}
else
{
if (nDraw == DRAW_3D)
{
bRet = AcDbBlockReference::subWorldDraw(pWd);
}
else if (nDraw == DRAW_2D && idBlock2d.isValid() && IsMultiView())
{
AcGeMatrix3d matTrans = BlockTransform(this);
matTrans(2,3) = 0.0;
OPENOBJ_BEGIN(idBlock2d, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if (pBlock)
{
AcGiSubEntityTraits &traits = pWd->subEntityTraits();
AcDbObjectId idLayer = traits.layerId();
Adesk::UInt16 nColor = traits.color();
AcDbObjectId idLineType = traits.lineTypeId();
#if ARX > 17
AcDbObjectId idMaterial = traits.materialId();
#endif
AcGiGeometry *geom = pWd->rawGeometry();
geom->pushModelTransform(matTrans);
geom->draw(pBlock);
geom->popModelTransform();
traits.setLayer(idLayer);
traits.setColor(nColor);
traits.setLineType(idLineType);
#if ARX > 17
traits.setMaterial(idMaterial);
#endif
}
OPENOBJ_END();
}
else if (!idBlock2d.isValid())
{
bRet = AcDbBlockReference::subWorldDraw(pWd);
}
else
{
bRet = Adesk::kFalse;
}
}
return bRet;
}
void AecDbBlockInsert::subViewportDraw(AcGiViewportDraw* pMode)
{
XAcGiViewDraw dc(NULL,pMode);
if (!OnExplodeOrDraw(dc))
{
return;
}
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();
if (!!ownerId())
{
pMode->subEntityTraits().setSelectionMarker(0);
}
int nDrawMode = GetDrawMode();
AcDbObjectId idBlock2d = Get2DBlockId();
AcDbObjectId idBlock;
if (!idBlock2d)
{
idBlock = blockTableRecord();
}
else
{
if (nDrawMode == 3)
{
if (g_nAcadVer > 15.0001)
{
if (nRegenType == kAcGiRenderCommand || nRegenType == kAcGiHideOrShadeCommand
|| vp.isPerspective() || vtViewDrt != AcGeVector3d(0,0,1))
{ // Draw3d
idBlock = blockTableRecord();
}
else
{
idBlock=idBlock2d;
}
}
else
{
if (nRegenType == kAcGiRenderCommand || vp.isPerspective() || vtViewDrt != AcGeVector3d(0,0,1))
{ // Draw3d
idBlock = blockTableRecord();
}
else
{
idBlock = idBlock2d;
}
}
}
else if (nDrawMode == 1)
{
idBlock = idBlock2d;
}
else if (nDrawMode == 2)
{
idBlock = blockTableRecord();
}
}
if (g_nAcadVer > 15.0001)
{
AcGeMatrix3d matTrans = BlockTransform(this);
if (idBlock == idBlock2d)
{
matTrans(2,3) = 0.0;
}
OPENOBJ_BEGIN(idBlock, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if (pBlock)
{
AcGiSubEntityTraits &traits = pMode->subEntityTraits();
AcDbObjectId idLayer = traits.layerId();
Adesk::UInt16 nColor = traits.color();
AcDbObjectId idLineType = traits.lineTypeId();
#if ARX > 17
AcDbObjectId idMaterial = traits.materialId();
#endif
AcGiGeometry *geom = pMode->rawGeometry();
geom->pushModelTransform(matTrans);
geom->draw(pBlock);
geom->popModelTransform();
traits.setLayer(idLayer);
traits.setColor(nColor);
traits.setLineType(idLineType);
#if ARX > 17
traits.setMaterial(idMaterial);
#endif
}
OPENOBJ_END();
}
}
//AcDbBlockReference的transformBy还没有完全实现镜像操作
//vtNormal!=(0,0,1)时不正确
Acad::ErrorStatus
AecDbBlockInsert::subTransformBy(const AcGeMatrix3d& xform)
{
AcGeVector3d vtNormal = normal();
assertWriteEnabled();
AcGePoint3d origin;
OPENOBJ_BEGIN(blockTableRecord(), AcDb::kForRead, AcDbBlockTableRecord, pBlock);
ASSERT(pBlock);
origin = pBlock->origin();
OPENOBJ_END();
ads_matrix mat;
{
AcGeScale3d scale = scaleFactors();
XPoint ptInsert = position();
double nRotation = rotation();
get_matrix(origin, ptInsert, scale[0], scale[1], scale[2], nRotation, mat);
}
AcGeMatrix3d matTran = AsAcGeMatrix3d(mat);
matTran.preMultBy(xform);
AcGeVector3d vt(1.0, 0.0, 0.0);
vt.transformBy(matTran);
double nRot = ads_angle(XPoint(), XPoint(vt[0],vt[1],vt[2]));
origin.transformBy(matTran);
ads_matrix matRot, matMov;
XPoint(origin).GetMoveMatrix(XPoint(),matMov);
matTran.preMultBy(AsAcGeMatrix3d(matMov));
XPoint().GetRotationMatrix(-nRot, matRot);
matTran.preMultBy(AsAcGeMatrix3d(matRot));
AcGeScale3d scales = AcGeScale3d(matTran(0,0), matTran(1,1), matTran(2,2));
if (fabs(scales[0])<1.0E-6 || fabs(scales[1])<1.0E-6 || fabs(scales[2])<1.0E-6)
{
return Acad::eNotApplicable;
}
setPosition(origin);
setRotation(nRot);
setScaleFactors(scales);
return Acad::eOk;
}
// -----------------------------------------------------------------------
// Overriden functions for edit
// 定义了6个夹点:
// 中心点: 用来移动
// 四个角点: 用来改尺寸
// 边点: 用来改角度
Acad::ErrorStatus AecDbBlockInsert::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
XBlockGeomInfo geom = GetGeomInfo();
gripPoints.append((XPoint &)geom.GetCenter());
gripPoints.append((XPoint &)geom.GetLowLeft());
gripPoints.append((XPoint &)geom.GetLowRight());
gripPoints.append((XPoint &)geom.GetUpRight());
gripPoints.append((XPoint &)geom.GetUpLeft());
return Acad::eOk;
}
//交点捕捉函数
Acad::ErrorStatus
AecDbBlockInsert::subIntersectWith(const AcDbEntity* ent,
AcDb::Intersect intType,
AcGePoint3dArray& points,
INT_PTR thisGsMarker,
INT_PTR otherGsMarker) const
{
if (IsKeyPressed(VK_CONTROL))
{
return AcDbBlockReference::subIntersectWith(ent, intType, points, thisGsMarker, otherGsMarker);
}
return Acad::eNotImplementedYet;
}
// Extend, Trim
Acad::ErrorStatus
AecDbBlockInsert::subIntersectWith(const AcDbEntity* ent,
AcDb::Intersect intType,
const AcGePlane& projPlane,
AcGePoint3dArray& points,
INT_PTR thisGsMarker,
INT_PTR otherGsMarker) const
{
return AcDbBlockReference::subIntersectWith(ent, intType, projPlane, points, thisGsMarker, otherGsMarker);
}
Acad::ErrorStatus AecDbBlockInsert::subGetOsnapPoints(
AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& ptPick,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
int nCount = snapPoints.length();
switch(osnapMode)
{
case AcDb::kOsModeIns:
snapPoints.append(position());
break;
case AcDb::kOsModeCen:
if (IsKeyPressed(VK_CONTROL))
{
AcDbBlockReference::subGetOsnapPoints(osnapMode, gsSelectionMark, ptPick, lastPoint,
viewXform, snapPoints, geomIds);
}
else
{
XBlockGeomInfo geom=GetGeomInfo();
snapPoints.append((XPoint &)geom.GetCenter());
}
break;
case AcDb::kOsModeNode:
{
XBlockGeomInfo geom=GetGeomInfo();
snapPoints.append((XPoint &)geom.GetCenter());
snapPoints.append((XPoint &)geom.GetLowLeft());
snapPoints.append((XPoint &)geom.GetLowRight());
snapPoints.append((XPoint &)geom.GetUpRight());
snapPoints.append((XPoint &)geom.GetUpLeft());
break;
}
case AcDb::kOsModeQuad:
{
XBlockGeomInfo geom=GetGeomInfo();
snapPoints.append((XPoint &)geom.GetLowLeft());
snapPoints.append((XPoint &)geom.GetLowRight());
snapPoints.append((XPoint &)geom.GetUpRight());
snapPoints.append((XPoint &)geom.GetUpLeft());
break;
}
default:
{
if(IsKeyPressed(VK_CONTROL))
{
AcDbBlockReference::subGetOsnapPoints(osnapMode, gsSelectionMark, ptPick, lastPoint,
viewXform, snapPoints, geomIds);
}
else
{
XBlockGeomInfo geom=GetGeomInfo();
AcDbPolyline pline;
geom.GetPolyline(pline);
pline.getOsnapPoints(osnapMode, 0, ptPick, lastPoint, viewXform, snapPoints, geomIds);
}
}
}
int nCount1 = snapPoints.length();
return Acad::eOk;
}
// 取得夹点说明
Acad::ErrorStatus AecDbBlockInsert::GetGripText(int i, CString &cs) const
{
Acad::ErrorStatus es=Acad::eOk;
switch(i)
{
case 0:
cs = (GetCtrlToggle()? _T("移动(Ctrl-中心旋转)") : _T("中心旋转(Ctrl-移动)"));
break;
case 1:
cs = (GetCtrlToggle()? _T("移动(Ctrl-对角拉伸)") : _T("对角拉伸(Ctrl-移动)"));
break;
case 2:
cs = (GetCtrlToggle()? _T("移动(Ctrl-对角拉伸)") : _T("对角拉伸(Ctrl-移动)"));
break;
case 3:
cs = (GetCtrlToggle()? _T("移动(Ctrl-对角拉伸)") : _T("对角拉伸(Ctrl-移动)"));
break;
case 4:
cs = (GetCtrlToggle()? _T("移动(Ctrl-对角拉伸)") : _T("对角拉伸(Ctrl-移动)"));
break;
default:
es = Acad::eInvalidInput;
}
return es;
}
// 功能: 夹点操作
Acad::ErrorStatus AecDbBlockInsert::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset)
{
XBlockGeomInfo geom = GetGeomInfo();
assertWriteEnabled();
BOOL bCtrlPressed = GetCtrlToggle(); //IsKeyPressed(VK_CONTROL);
AcDbObjectId objId = objectId();
XPoint &vtOffset = *(XPoint *)&offset;
XPoint ptFix = geom.m_ptCen;
int idx = 0;
for (int i = 0; i < indices.length(); i++)
{
idx = indices[i];
switch(idx)
{
case 0: // Move Center
if(bCtrlPressed)
{
geom.m_ptCen += vtOffset;
}
else
{
double nRot = ads_angle(XPoint(), vtOffset);
geom.m_nRotation = nRot;
}
break;
case 1: // Move LowLeft
if(bCtrlPressed)
{
geom.m_ptCen += vtOffset;
}
else
{
XPoint ptLowLeft=geom.GetLowLeft();
XPoint ptUpRight=geom.GetUpRight();
ptFix=ptUpRight;
ptLowLeft += vtOffset;
ptLowLeft.z = ptUpRight.z;
XLine ln(ptUpRight, geom.m_nRotation);
XPoint ptPrj;
ptLowLeft.Project(&ln, ptPrj);
geom.m_nSizeX = ads_distance(ptPrj, ptUpRight);
geom.m_nSizeY = ads_distance(ptPrj, ptLowLeft);
Midpoint(ptUpRight, ptLowLeft, geom.m_ptCen);
}
break;
case 2: // Move LowRight
if(bCtrlPressed)
{
geom.m_ptCen += vtOffset;
}
else
{
XPoint ptLowRight=geom.GetLowRight();
XPoint ptUpLeft=geom.GetUpLeft();
ptFix = ptUpLeft;
ptLowRight += vtOffset;
ptLowRight.z = ptUpLeft.z;
XLine ln(ptUpLeft, geom.m_nRotation);
XPoint ptPrj;
ptLowRight.Project(&ln, ptPrj);
geom.m_nSizeX = ads_distance(ptPrj, ptUpLeft);
geom.m_nSizeY = ads_distance(ptPrj, ptLowRight);
Midpoint(ptLowRight, ptUpLeft, geom.m_ptCen);
}
break;
case 3: // Move UpRight
if(bCtrlPressed)
{
geom.m_ptCen += vtOffset;
}
else
{
XPoint ptUpRight=geom.GetUpRight();
XPoint ptLowLeft=geom.GetLowLeft();
ptFix = ptLowLeft;
ptUpRight += vtOffset;
ptUpRight.z = ptLowLeft.z;
XLine ln(ptLowLeft, geom.m_nRotation);
XPoint ptPrj;
ptUpRight.Project(&ln, ptPrj);
geom.m_nSizeX = ads_distance(ptPrj, ptLowLeft);
geom.m_nSizeY = ads_distance(ptPrj, ptUpRight);
Midpoint(ptUpRight, ptLowLeft, geom.m_ptCen);
}
break;
case 4: // Move UpLeft
if(bCtrlPressed)
{
geom.m_ptCen += vtOffset;
}
else
{
XPoint ptUpLeft=geom.GetUpLeft();
XPoint ptLowRight=geom.GetLowRight();
ptFix=ptLowRight;
ptUpLeft += vtOffset;
ptUpLeft.z = ptUpLeft.z;
XLine ln(ptLowRight, geom.m_nRotation);
XPoint ptPrj;
ptUpLeft.Project(&ln, ptPrj);
geom.m_nSizeX = ads_distance(ptPrj, ptLowRight);
geom.m_nSizeY = ads_distance(ptPrj, ptUpLeft);
Midpoint(ptLowRight, ptUpLeft, geom.m_ptCen);
}
break;
default:
break;
}
}
UpdateFrom(geom);
return Acad::eOk;
}
// 功能: 夹点操作
// ACAD漏洞,stretch修改后,仍然被复原
Acad::ErrorStatus AecDbBlockInsert::subMoveStretchPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset)
{
assertWriteEnabled();
if(indices.length())
{
AcGePoint3d ptPos=position();
ptPos += offset;
setPosition(ptPos);
AcGePoint3d ptPos1=position();
AcDbObjectId idThis=objectId();
if(!!idThis)
{
TCHAR szHand[17]=_T("");
AcDbHandle hand=idThis.handle();
hand.getIntoAsciiBuffer(szHand);
setPosition(ptPos1);
//modify by zjq on 100401 调整调用kernal内容的方式
//XString &sCmd=GetCurDocData()->m_sCurCommand;
CString sCmd;
XConfigBase* pBase = GeXConfigBase();
if (pBase != NULL)
{
sCmd = pBase->GetCurrentCommand();
pBase->Close();
}
if(_tcsicmp(sCmd, _T("STRETCH")) == 0)
{
XIdPointPair *p0=g_lstBlockInsertIds.FindNode(&idThis, XIdPointPair::CompareIdForFind);
if(p0)
{
p0->m_pt = ptPos;
}
else
{
g_lstBlockInsertIds.Append(new XIdPointPair(idThis, ptPos));
}
}
}
}
return Acad::eOk;
}
XBlockGeomInfo AecDbBlockInsert::GetGeomInfo() const
{
XBlockGeomInfo geom;
geom.SetFromInsert(this);
return geom;
}
//修改相应的Insert
Acad::ErrorStatus AecDbBlockInsert::UpdateFrom(const XBlockGeomInfo &geom)
{
assertWriteEnabled();
// 用当前选择集是否包含图块来判断, 图块是否曾经被选择过, 十分不可靠
// 取当前选择集是一个十分不可靠的函数
XPoint ptNewBase;
double nNewRot;
AcGeScale3d scale;
if(geom.CalInsertParameters(this, ptNewBase, &nNewRot, &scale[0], &scale[1], &scale[2]) != Acad::eOk)
{
return Acad::eOk;
}
setPosition(ptNewBase);
setRotation(nNewRot);
setScaleFactors(scale);
return Acad::eOk;
}
// 有待改进
Acad::ErrorStatus AecDbBlockInsert::subExplode(AcDbVoidPtrArray& entitySet) const
{
entitySet.append(NewBlockInsert());
return Acad::eOk;
}
Acad::ErrorStatus AecDbBlockInsert::GetExtents2d(XPoint &ptLow, XPoint &ptUp) const
{
AcDbExtents ext;
Acad::ErrorStatus es = getGeomExtents(ext);
ptLow = ext.minPoint();
ptUp = ext.maxPoint();
return es;
}
AcDbBlockReference * AecDbBlockInsert::NewBlockInsert() const
{
int nExpMode = 1;
AcDbObjectId idBlock2d;
if(IsMultiView())
{
idBlock2d = Get2DBlockId();
}
if(idBlock2d.isValid())
{
nExpMode = IsExplode3D(); //0--2D; 1--3D
}
if(nExpMode == 1)
{
idBlock2d = blockTableRecord();
}
AcDbBlockReference *pInsert= new AcDbBlockReference;
pInsert->setPropertiesFrom(this);
pInsert->setBlockTableRecord(idBlock2d);
pInsert->setNormal(normal());
pInsert->setPosition(position());
pInsert->setRotation(rotation());
pInsert->setScaleFactors(scaleFactors());
return pInsert;
}
/* * * * * * * * * * 取 动 态 属 性 显 示 数 据 的 函 数 * * * * * * * * * */
void AecDbBlockInsert::GetTips(DList<ObjInfoUnit> &lstInfo) const
{
XBlockGeomInfo geom = GetGeomInfo();
XString sBlockName = XExport::GetSymbolName(blockTableRecord());
lstInfo.Append(new ObjInfoUnit(_T("对象类型"), _T("$图块")));
lstInfo.Append(new ObjInfoUnit(_T("中心点"), XExport::Point2d2Str(geom.m_ptCen)));
lstInfo.Append(new ObjInfoUnit(_T("转角"), XString(_T("%d"), AS_INT(geom.m_nRotation * 180 / PI))));
lstInfo.Append(new ObjInfoUnit(_T("长度X"), XExport::Dist2Str(geom.m_nSizeX)));
lstInfo.Append(new ObjInfoUnit(_T("宽度Y"), XExport::Dist2Str(geom.m_nSizeY)));
lstInfo.Append(new ObjInfoUnit(_T("高度Z"), XExport::Dist2Str(geom.m_nSizeZ)));
lstInfo.Append(new ObjInfoUnit(_T("图块名称"), sBlockName));
}
void AecDbBlockInsert::SetMaskFlag(Adesk::UInt8 nFlag)
{
assertWriteEnabled();
m_nMaskFlag = nFlag;
}
Adesk::UInt8
AecDbBlockInsert::GetMaskFlag() const
{
return m_nMaskFlag;
}
BOOL AecDbBlockInsert::IsMultiView() const
{
return ((m_nMaskFlag&BIF_MULTIVIEW) != 0);
}
void AecDbBlockInsert::SetMultiView(BOOL bTrue)
{
assertWriteEnabled();
if(bTrue)
{
m_nMaskFlag |= BIF_MULTIVIEW;
}
else
{
m_nMaskFlag &= ~BIF_MULTIVIEW;
}
}
AcDbObjectId AecDbBlockInsert::Get2DBlockId() const
{
assertReadEnabled();
return m_idBlock2d;
}
void AecDbBlockInsert::Set2DBlockId(AcDbObjectId id)
{
assertWriteEnabled();
m_idBlock2d = id;
}
AcDbObjectId AecDbBlockInsert::_Get2DBlockId() const
{
AcDbObjectId idBlock = blockTableRecord();
AcDbObjectId idBlock2d = GetBlock2dFromBlock3d(idBlock);
return idBlock2d;
}
Acad::ErrorStatus AecDbBlockInsert::_Set2DBlockId(AcDbObjectId idBlock2d) const
{
if(!idBlock2d.isValid())
{
return Acad::eInvalidInput;
}
Acad::ErrorStatus es = Acad::eOk;
AcDbObjectId idBlock = blockTableRecord();
OPENOBJ_BEGIN(idBlock, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if(pBlock)
{
AcDbHandle hand=idBlock2d.handle();
TCHAR szHand[256] = _T("");
hand.getIntoAsciiBuffer(szHand);
BOOL bExist = FALSE;
resbuf *pxData = pBlock->xData(TCHXD); // 读扩展数据
if (pxData == NULL)
pxData = pBlock->xData(_T("_TCH"));
if(pxData)
{
resbuf *pNext = pxData->rbnext;
if(pNext && pNext->restype == 1005)
{
if(_tcsicmp(pNext->resval.rstring, szHand) == 0)
{
bExist = TRUE;
}
}
ads_relrb(pxData);
}
if(!bExist)
{
if(pBlock->upgradeOpen() == Acad::eOk)
{
RBList xd = ads_buildlist(1001, TCHXD, 1005, szHand, NULL);
pBlock->setXData(xd);
pBlock->downgradeOpen();
es = Acad::eOk;
}
else
{
es = Acad::eInvalidInput;
}
}
else
{
es = Acad::eInvalidInput;
}
}
else
{
es = Acad::eInvalidInput;
}
OPENOBJ_END();
return es;
}
#if ARX > 17
void AecDbBlockInsert::subGripStatus(const AcDb::GripStat status)
{
assertReadEnabled();
AEntityBase::GripStatus(status);
}
Acad::ErrorStatus AecDbBlockInsert::subGetGripPoints(AcDbGripDataPtrArray& grips,
const double curViewUnitSize,
const int gripSize,
const AcGeVector3d& curViewDir,
const int bitflags) const
{
assertReadEnabled();
return AEntityBase::GetGripPoints(grips,curViewUnitSize,gripSize,curViewDir,bitflags);
}
Acad::ErrorStatus AecDbBlockInsert::subMoveGripPointsAt(const AcDbVoidPtrArray& appData,
const AcGeVector3d& offset,
const int bitflags)
{
assertWriteEnabled();
return AEntityBase::MoveGripPointsAt(appData,offset,bitflags);
}
void AecDbBlockInsert::CreateGrip()
{
AEntityBase::CreateGrip();
for(long i = 1;i<5;i++)
{
GetGrip(i)->AppendDim(new AecDbGripDistDim(AcDbDimData::kDimResultantLength));//X
GetGrip(i)->AppendDim(new AecDbGripDistDim(AcDbDimData::kDimResultantLength));//Y
}
}
Acad::ErrorStatus AecDbBlockInsert::EntityToDim(long iGrip,long iDim,const AcDbEntity*pEnt)
{
AecDbGripDim*pDim = GetGripDim(iGrip,iDim);
if(pDim == NULL)
{
return Acad::eInvalidInput;
}
if(pEnt == NULL)
{
pEnt = this;
}
AecDbBlockInsert *pInsert = AecDbBlockInsert::cast(pEnt);
if(pInsert == NULL)
{
return Acad::eInvalidInput;
}
XBlockGeomInfo info = pInsert->GetGeomInfo();
AecDbGripDistDim *pDistDim = (AecDbGripDistDim*)pDim;
if(iGrip == 2 || iGrip == 4)
{
if(iDim == 0)
{
pDistDim->SetData(pInsert->GetGripPoint((iGrip+2)%4+1),pInsert->GetGripPoint(iGrip),info.GetSizeY()/3);
}
else if(iDim == 1)
{
pDistDim->SetData(pInsert->GetGripPoint(iGrip),pInsert->GetGripPoint(iGrip%4+1),info.GetSizeX()/3);
}
else
{
return Acad::eNotImplementedYet;
}
}
else if(iGrip == 1 || iGrip == 3)
{
if(iDim == 1)
{
pDistDim->SetData(pInsert->GetGripPoint((iGrip+2)%4+1),pInsert->GetGripPoint(iGrip),info.GetSizeX()/3);
}
else if(iDim == 0)
{
pDistDim->SetData(pInsert->GetGripPoint(iGrip),pInsert->GetGripPoint(iGrip%4+1),info.GetSizeY()/3);
}
else
{
return Acad::eNotImplementedYet;
}
}
else
{
return Acad::eNotImplementedYet;
}
return Acad::eOk;
}
Acad::ErrorStatus AecDbBlockInsert::DimToEntity(long iGrip,long iDim,double newValue,const AcGeVector3d& offset)
{
assertWriteEnabled();
if(newValue<1E-9)
{
return Acad::eInvalidInput;
}
XBlockGeomInfo info = GetGeomInfo();
double d;
if(iDim == 0)
{
d=newValue-info.m_nSizeX;
info.m_nSizeX = newValue;
}
else if(iDim == 1)
{
d = newValue-info.m_nSizeY;
info.m_nSizeY = newValue;
}
else
{
return Acad::eNotImplementedYet;
}
if(!GetCtrlToggle())
{
XPoint vt = iDim == 0 ? XPoint(d/2,0) : XPoint(0,d/2);
switch(iGrip)
{
case 1:
vt.Rotate(info.GetRotation()+PI);
break;
case 2:
if(iDim == 0)
{
vt.Rotate(info.GetRotation());
}
else
{
vt.Rotate(info.GetRotation()+PI);
}
break;
case 3:
vt.Rotate(info.GetRotation());
break;
case 4:
if(iDim == 0)
{
vt.Rotate(info.GetRotation()+PI);
}
else
{
vt.Rotate(info.GetRotation());
}
break;
default:
return Acad::eNotImplementedYet;
}
info.m_ptCen += vt;
}
UpdateFrom(info);
return Acad::eOk;
}
#endif
AcDbEntity * AecDbBlockInsert::GetMe()
{
return this;
}
const AcDbEntity * AecDbBlockInsert::GetMe() const
{
return this;
}
int AecDbBlockInsert::GetCtrlToggleIndex()const
{
return 0;
}
bool AecDbBlockInsert::IsModelEntity() const
{
return true;
}
void* AecDbBlockInsert::operator new[](size_t nSize)
{
return 0;
}
void AecDbBlockInsert::operator delete[](void *p)
{
}
void* AecDbBlockInsert::operator new[](size_t nSize, const TCHAR *file, int line)
{
return 0;
}
AcDbObjectId AecDbBlockInsert::GetBlock2dFromBlock3d(AcDbObjectId idBlock) const
{
AcDbObjectId idBlock2d;
OPENOBJ_BEGIN(idBlock, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
if (pBlock)
{
resbuf *pxData = pBlock->xData(TCHXD); // 读扩展数据
if (pxData == NULL)
pxData = pBlock->xData(_T("_TCH"));
if (pxData)
{
resbuf *pNext = pxData->rbnext;
if (pNext && pNext->restype == 1005)
{
AcDbHandle handle(pNext->resval.rstring);
pBlock->database()->getAcDbObjectId(idBlock2d, false, handle);
}
ads_relrb(pxData);
}
}
OPENOBJ_END();
return idBlock2d;
}
void InitBlockInsertIds(BOOL bCmdEnd)
{
if (bCmdEnd)
{
for (int i = 0; i < g_lstBlockInsertIds.Length(); i++)
{
XIdPointPair *p0 = g_lstBlockInsertIds[i];
OPENOBJ_BEGIN(p0->m_id, AcDb::kForWrite, AecDbBlockInsert, pInsert);
if (pInsert)
{
pInsert->setPosition(p0->m_pt);
}
OPENOBJ_END();
}
}
g_lstBlockInsertIds.Reset();
}
void InitDbBlockInsert(BOOL bTrue)
{
if (bTrue)
{
AecDbBlockInsert::rxInit();
acrxBuildClassHierarchy();
}
else
{
deleteAcRxClass(AecDbBlockInsert::desc());
}
}