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

1121 lines
30 KiB
C++

#include "stdafx.h"
ACRX_DXF_DEFINE_MEMBERS(ATSRect, ATSCurveEntity, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
1, ATS_RECT, "ATS_RECT图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
IMPLEMENT_TENTBASE(TDbRect);
const Adesk::UInt8 TDbRect::g_nVersion = 2;
TDbRect::TDbRect()
:m_nRotation(0.0), m_nSizeX(0.0), m_nSizeY(0.0), m_nSizeZ(0.0),
m_nRectFlag(0),m_vtNormal(0,0,1)
{
m_baseFlag=kCenter;
}
// 提供对格式刷的支持
void TDbRect::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
{
assertWriteEnabled();
TDbCurveEntity::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
TDbRect *pSrc=TDbRect::cast(pSrcEntity);
if(pSrc) {
m_nRectFlag = pSrc->m_nRectFlag; //标志
m_nSizeX=pSrc->m_nSizeX;
m_nSizeY=pSrc->m_nSizeY;
m_nSizeZ=pSrc->m_nSizeZ;
m_baseFlag=pSrc->m_baseFlag;
}
}
BOOL TDbRect::IsValid() const
{
BOOL bValid=TDbCurveEntity::IsValid();
if(!bValid)
return bValid;
if(m_nSizeX<_DIST_SNAP || m_nSizeY<_DIST_SNAP)
return FALSE;
return TRUE;
}
/*
Acad::ErrorStatus
TDbRect::getClassID(CLSID* pClsid) const
{
return Acad::eOk;
}
*/
// 取得四个角点
XPoint TDbRect::GetLowLeft() const
{
//modified by fxj 090427
double nAng=0.0;
if(m_nSizeX>=_DIST_SNAP)
nAng = atan(m_nSizeY/m_nSizeX);
else if(m_nSizeY>=_DIST_SNAP)
nAng=PI/2.0;
else
return m_ptCen;
double nLen = sqrt(m_nSizeY*m_nSizeY + m_nSizeX*m_nSizeX);
XPoint ptLowLeft;
ads_polar(m_ptCen, m_nRotation+PI+nAng, nLen/2.0, ptLowLeft);
return ptLowLeft;
}
XPoint TDbRect::GetLowRight() const
{
//modified by fxj 090427
double nAng=0.0;
if(m_nSizeX>=_DIST_SNAP)
nAng = atan(m_nSizeY/m_nSizeX);
else if(m_nSizeY>=_DIST_SNAP)
nAng=PI/2.0;
else
return m_ptCen;
double nLen = sqrt(m_nSizeY*m_nSizeY + m_nSizeX*m_nSizeX);
XPoint ptLowRight;
ads_polar(m_ptCen, m_nRotation-nAng, nLen/2.0, ptLowRight);
return ptLowRight;
}
XPoint TDbRect::GetUpRight() const
{
//modified by fxj 090427
double nAng=0.0;
if(m_nSizeX>=_DIST_SNAP)
nAng = atan(m_nSizeY/m_nSizeX);
else if(m_nSizeY>=_DIST_SNAP)
nAng=PI/2.0;
else
return m_ptCen;
double nLen = sqrt(m_nSizeY*m_nSizeY + m_nSizeX*m_nSizeX);
XPoint ptUpRight;
ads_polar(m_ptCen, m_nRotation+nAng, nLen/2.0, ptUpRight);
return ptUpRight;
}
XPoint TDbRect::GetUpLeft() const
{
//modified by fxj 090427
double nAng=0.0;
if(m_nSizeX>=_DIST_SNAP)
nAng = atan(m_nSizeY/m_nSizeX);
else if(m_nSizeY>=_DIST_SNAP)
nAng=PI/2.0;
else
return m_ptCen;
double nLen = sqrt(m_nSizeY*m_nSizeY + m_nSizeX*m_nSizeX);
XPoint ptUpLeft;
ads_polar(m_ptCen, m_nRotation+PI-nAng, nLen/2.0, ptUpLeft);
return ptUpLeft;
}
void TDbRect::GetPolyline(AcDbPolyline &pline) const
{
pline.reset(Adesk::kFalse, 0);
pline.setElevation(0.0);
pline.setNormal(m_vtNormal);
pline.addVertexAt(0, GetLowLeft().AsAcGePoint2d());
pline.addVertexAt(1, GetLowRight().AsAcGePoint2d());
pline.addVertexAt(2, GetUpRight().AsAcGePoint2d());
pline.addVertexAt(3, GetUpLeft().AsAcGePoint2d());
pline.setThickness(m_nSizeZ);
pline.setClosed(Adesk::kTrue);
}
Acad::ErrorStatus
TDbRect::subGetClassID(CLSID* pClsid) const
{
return Acad::eOk;
}
// 从DWG读入数据:
Acad::ErrorStatus TDbRect::dwgInFields (AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = TDbCurveEntity::dwgInFields(pFiler);
if(es != Acad::eOk) return es;
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if(nVer>g_nVersion) {// Version is too new
return Acad::eMakeMeProxy;
}
pFiler->readItem(&m_nRectFlag);
pFiler->readItem(&(AcGePoint3d &)m_ptCen); //底面中心
pFiler->readItem(&m_nRotation);
pFiler->readItem(&m_nSizeX);
pFiler->readItem(&m_nSizeY);
pFiler->readItem(&m_nSizeZ);
pFiler->readItem(&(AcGeVector3d &)m_vtNormal);
if(nVer>1) {
Adesk::UInt8 flag;
pFiler->readItem(&flag);
m_baseFlag=(BasePosition)flag;
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbRect::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = TDbCurveEntity::dwgOutFields(pFiler);
if(es != Acad::eOk) return es;
pFiler->writeItem(g_nVersion);
pFiler->writeItem(m_nRectFlag);
pFiler->writeItem((AcGePoint3d &)m_ptCen); //底面中心
pFiler->writeItem(m_nRotation);
pFiler->writeItem(m_nSizeX);
pFiler->writeItem(m_nSizeY);
pFiler->writeItem(m_nSizeZ);
pFiler->writeItem((AcGeVector3d &)m_vtNormal);
pFiler->writeItem((Adesk::UInt8)m_baseFlag);
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbRect::dxfInFields (AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = TDbCurveEntity::dxfInFields(pFiler);
if(es!=Acad::eOk)
return es;
if (!pFiler->atSubclassData(_T("TDbRect"))) {
return Acad::eBadDxfSequence;
}
int fieldsFlags=0;
resbuf rb;
int n1;
double r1=0.0, r2=0.0, r3=0.0;
XPoint pt;
while ((es == Acad::eOk)
&& ((es = pFiler->readResBuf(&rb)) == Acad::eOk)) {
switch (rb.restype) {
case 40:
r1=rb.resval.rreal;
fieldsFlags |= 0x01;
break;
case 41:
r2=rb.resval.rreal;
fieldsFlags |= 0x02;
break;
case 42:
r3=rb.resval.rreal;
fieldsFlags |= 0x04;
break;
case AcDb::kDxfInt16:
n1=rb.resval.rint;
fieldsFlags |= 0x08;
break;
case 10:
pt=rb.resval.rpoint;
fieldsFlags |= 0x10;
break;
case 210:
m_vtNormal=rb.resval.rpoint;
break;
case 50:
m_nRotation=rb.resval.rreal;
break;
//fall through intentional
default:
// An unrecognized group. Push it back so that
// the subclass can read it again.
pFiler->pushBackItem();
es = Acad::eEndOfFile;
break;
}
}
// At this point the es variable must contain eEndOfFile
// - either from readResBuf() or from pushback. If not,
// it indicates that an error happened and we should
// return immediately.
//
if (es != Acad::eEndOfFile)
return Acad::eInvalidResBuf;
if(!(fieldsFlags&0x10)) {
pFiler->setError(_T("\nMissing DXF group code: 10"));
return Acad::eMissingDxfField;
}
if(!(fieldsFlags&0x01) || !(fieldsFlags&0x02) || r1<_DIST_SNAP || r2<_DIST_SNAP) {
pFiler->setError(_T("\nError DXF group code: 40, 41"));
return Acad::eMissingDxfField;
}
m_ptCen=pt;
m_nSizeX=r1;
m_nSizeY=r2;
if(fieldsFlags&0x04)
m_nSizeZ=r3;
if(fieldsFlags&0x08)
m_nRectFlag=n1;
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbRect::dxfOutFields(AcDbDxfFiler* pFiler) const
{
Acad::ErrorStatus es;
es = TDbCurveEntity::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbRect"));
assert(es == Acad::eOk);
pFiler->writeDouble(40, m_nSizeX);
pFiler->writeDouble(41, m_nSizeY);
pFiler->writeDouble(42, m_nSizeZ);
pFiler->writePoint3d(10, m_ptCen);
pFiler->writeDouble(50, m_nRotation);
pFiler->writeInt16(AcDb::kDxfInt16, m_nRectFlag);
pFiler->writeVector3d(210, m_vtNormal);
return es;
}
Acad::ErrorStatus
TDbRect::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
TDbCurveEntity::subTransformBy(xform);
XPoint ptLowLeft=GetLowLeft();
XPoint ptLowRight=GetLowRight();
XPoint ptUpLeft=GetUpLeft();
ptUpLeft.z=m_ptCen.z + m_nSizeZ;
XPoint ptCen=Ecs2Wcs(m_ptCen, m_vtNormal);
ptLowLeft=Ecs2Wcs(ptLowLeft, m_vtNormal);
ptLowRight=Ecs2Wcs(ptLowRight, m_vtNormal);
ptUpLeft=Ecs2Wcs(ptUpLeft, m_vtNormal);
((AcGePoint3d &)ptCen).transformBy(xform);
((AcGePoint3d &)ptLowLeft).transformBy(xform);
((AcGePoint3d &)ptLowRight).transformBy(xform);
((AcGePoint3d &)ptUpLeft).transformBy(xform);
((AcGeVector3d &)m_vtNormal).transformBy(xform);
ptLowLeft=Wcs2Ecs(ptLowLeft, m_vtNormal);
ptLowRight=Wcs2Ecs(ptLowRight, m_vtNormal);
ptUpLeft=Wcs2Ecs(ptUpLeft, m_vtNormal);
m_ptCen = Wcs2Ecs(ptCen, m_vtNormal);
m_nRotation=ads_angle(ptLowLeft, ptLowRight);
m_nSizeX=ptLowLeft.Distance2d(ptLowRight);
m_nSizeY=ptLowLeft.Distance2d(ptUpLeft);
m_nSizeZ=fabs(ptUpLeft.z - m_ptCen.z);
return Acad::eOk;
}
// -----------------------------------------------------------------------
// Overriden functions for edit
// 定义了6个夹点:
// 中心点: 用来移动
// 四个角点: 用来改尺寸
// 边点: 用来改角度
Acad::ErrorStatus TDbRect::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
XPoint ptCen=Ecs2Wcs(GetCenter(), m_vtNormal);
XPoint ptLowLeft=Ecs2Wcs(GetLowLeft(), m_vtNormal);
XPoint ptLowRight=Ecs2Wcs(GetLowRight(), m_vtNormal);
XPoint ptUpRight=Ecs2Wcs(GetUpRight(), m_vtNormal);
XPoint ptUpLeft=Ecs2Wcs(GetUpLeft(), m_vtNormal);
gripPoints.append(ptCen);
gripPoints.append(ptLowLeft);
gripPoints.append(ptLowRight);
gripPoints.append(ptUpRight);
gripPoints.append(ptUpLeft);
return Acad::eOk;
}
Acad::ErrorStatus
TDbRect::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
{
assertReadEnabled();
XPoint ptCen=Ecs2Wcs(GetCenter(), m_vtNormal);
XPoint ptLowLeft=Ecs2Wcs(GetLowLeft(), m_vtNormal);
XPoint ptLowRight=Ecs2Wcs(GetLowRight(), m_vtNormal);
XPoint ptUpRight=Ecs2Wcs(GetUpRight(), m_vtNormal);
XPoint ptUpLeft=Ecs2Wcs(GetUpLeft(), m_vtNormal);
stretchPoints.append(ptCen);
/*
gripPoints.append(ptLowLeft);
gripPoints.append(ptLowRight);
gripPoints.append(ptUpRight);
gripPoints.append(ptUpLeft);
*/
return Acad::eOk;
}
Acad::ErrorStatus TDbRect::subGetOsnapPoints(
AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& ptPick,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
Acad::ErrorStatus es=Acad::eOk;
//int nCount=snapPoints.length();
//int expMode=GetExplodeMode();
XPoint ptCen=Ecs2Wcs(GetCenter(), m_vtNormal);
XPoint ptLowLeft=Ecs2Wcs(GetLowLeft(), m_vtNormal);
XPoint ptLowRight=Ecs2Wcs(GetLowRight(), m_vtNormal);
XPoint ptUpRight=Ecs2Wcs(GetUpRight(), m_vtNormal);
XPoint ptUpLeft=Ecs2Wcs(GetUpLeft(), m_vtNormal);
if(!IsExplode3D()) {
ptCen.z=0;
ptLowLeft.z=0;
ptLowRight.z=0;
ptUpLeft.z=0;
}
switch(osnapMode) {
case AcDb::kOsModeIns:
case AcDb::kOsModeCen:
snapPoints.append(ptCen);
break;
case AcDb::kOsModeNode:
snapPoints.append(ptCen);
snapPoints.append(ptLowLeft);
snapPoints.append(ptLowRight);
snapPoints.append(ptUpRight);
snapPoints.append(ptUpLeft);
break;
case AcDb::kOsModeQuad:
snapPoints.append(ptLowLeft);
snapPoints.append(ptLowRight);
snapPoints.append(ptUpRight);
snapPoints.append(ptUpLeft);
break;
default:
es=TDbCurveEntity::subGetOsnapPoints(osnapMode,
gsSelectionMark,
ptPick,
lastPoint,
viewXform,
snapPoints,
geomIds);
}
return es;
}
Acad::ErrorStatus TDbRect::GetPathPoly(XPoly2D& polyPath,AcGeVector3d&normal)const
{
assertReadEnabled();
polyPath.AppendNode(GetLowLeft());
polyPath.AppendNode(GetLowRight());
polyPath.AppendNode(GetUpRight());
polyPath.AppendNode(GetUpLeft());
normal=m_vtNormal.AsAcGeVector3d();
return Acad::eOk;
}
// 绘制二维
Acad::ErrorStatus
TDbRect::ExplodeOrDraw2d(XExplodeDraw &dc) const
{
//add by fxj 090427
if(m_nSizeX>=_DIST_SNAP && m_nSizeY>=_DIST_SNAP)
;
else
return Acad::eOk;
XPoint ptLowLeft=Ecs2Wcs(GetLowLeft(), m_vtNormal);
XPoint ptLowRight=Ecs2Wcs(GetLowRight(), m_vtNormal);
XPoint ptUpRight=Ecs2Wcs(GetUpRight(), m_vtNormal);
XPoint ptUpLeft=Ecs2Wcs(GetUpLeft(), m_vtNormal);
ptLowLeft.z=ptLowRight.z=ptUpRight.z=ptUpLeft.z=0;
XPoly2D poly2d(1);
poly2d.AppendNode(ptLowLeft);
poly2d.AppendNode(ptLowRight);
poly2d.AppendNode(ptUpRight);
poly2d.AppendNode(ptUpLeft);
dc << poly2d;
if(m_nRectFlag==RF_DIA45)
dc << XLine(ptLowLeft, ptUpRight);
else if(m_nRectFlag==RF_DIA135)
dc << XLine(ptUpLeft, ptLowRight);
else if(m_nRectFlag==RF_CROSSING)
dc << XLine(ptLowLeft, ptUpRight) << XLine(ptUpLeft, ptLowRight);
return Acad::eOk;
}
Acad::ErrorStatus
TDbRect::ExplodeOrDraw3d(XExplodeDraw &dc) const
{
//add by fxj 090427
if(m_nSizeZ>=_DIST_SNAP)
;
else
return Acad::eOk;
if(m_nSizeX>=_DIST_SNAP && m_nSizeY>=_DIST_SNAP)
;
else
return Acad::eOk;
XPoint ptLowLeft=Ecs2Wcs(GetLowLeft(), m_vtNormal);
XPoint ptLowRight=Ecs2Wcs(GetLowRight(), m_vtNormal);
XPoint ptUpRight=Ecs2Wcs(GetUpRight(), m_vtNormal);
XPoint ptUpLeft=Ecs2Wcs(GetUpLeft(), m_vtNormal);
XPoly2D poly2d(1);
poly2d.AppendNode(ptLowLeft);
poly2d.AppendNode(ptLowRight);
poly2d.AppendNode(ptUpRight);
poly2d.AppendNode(ptUpLeft);
XVector3D vt=m_vtNormal;
vt.Normalize();
vt *= m_nSizeZ;
dc.DrawBody(poly2d, vt);
return Acad::eOk;
}
// 取得夹点说明
Acad::ErrorStatus TDbRect::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 TDbRect::subMoveGripPointsAt(
const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
XPoint &vtOffset=*(XPoint *)&offset;
BOOL bCtrlPressed=GetCtrlToggle();
if(bCtrlPressed) {
XPoint ptCen=Ecs2Wcs(GetCenter(), m_vtNormal);
ptCen += vtOffset;
m_ptCen = Wcs2Ecs(ptCen, m_vtNormal);
return Acad::eOk;
}
XVector3D vtEcs=Wcs2Ecs(vtOffset, m_vtNormal, TRUE);
int idx=0;
for (int i = 0; i < indices.length(); i++) {
idx = indices[i];
switch(idx) {
case 0: // Move Center
{
double nRot=ads_angle(XPoint(), Wcs2Ecs(vtOffset, m_vtNormal, TRUE));
m_nRotation = nRot;
}
break; // stretch begin point
case 1: // Move LowLeft
{
XPoint ptLowLeft=Ecs2Wcs(GetLowLeft(), m_vtNormal);
XPoint ptUpRight=GetUpRight();
ptLowLeft += vtOffset;
ptLowLeft = Wcs2Ecs(ptLowLeft, m_vtNormal);
ptLowLeft.z = ptUpRight.z;
XLine ln(ptUpRight, m_nRotation);
XPoint ptPrj;
ptLowLeft.Project(&ln, ptPrj);
m_nSizeX = ptPrj.Distance2d(ptUpRight);
m_nSizeY = ptPrj.Distance2d(ptLowLeft);
Midpoint(ptUpRight, ptLowLeft, m_ptCen);
}
break;
case 2: // Move LowRight
{
XPoint ptLowRight=GetLowRight();
XPoint ptUpLeft=GetUpLeft();
ptLowRight += vtEcs;
ptLowRight.z = ptUpLeft.z;
XLine ln(ptUpLeft, m_nRotation);
XPoint ptPrj;
ptLowRight.Project(&ln, ptPrj);
m_nSizeX = ptPrj.Distance2d(ptUpLeft);
m_nSizeY = ptPrj.Distance2d(ptLowRight);
Midpoint(ptLowRight, ptUpLeft, m_ptCen);
}
break;
case 3: // Move UpRight
{
XPoint ptUpRight=GetUpRight();
XPoint ptLowLeft=GetLowLeft();
ptUpRight += vtEcs;
ptUpRight.z = ptLowLeft.z;
XLine ln(ptLowLeft, m_nRotation);
XPoint ptPrj;
ptUpRight.Project(&ln, ptPrj);
m_nSizeX = ptPrj.Distance2d(ptLowLeft);
m_nSizeY = ptPrj.Distance2d(ptUpRight);
Midpoint(ptUpRight, ptLowLeft, m_ptCen);
}
break;
case 4: // Move UpLeft
{
XPoint ptUpLeft=GetUpLeft();
XPoint ptLowRight=GetLowRight();
ptUpLeft += vtEcs;
ptUpLeft.z = ptUpLeft.z;
XLine ln(ptLowRight, m_nRotation);
XPoint ptPrj;
ptUpLeft.Project(&ln, ptPrj);
m_nSizeX = ptPrj.Distance2d(ptLowRight);
m_nSizeY = ptPrj.Distance2d(ptUpLeft);
Midpoint(ptLowRight, ptUpLeft, m_ptCen);
}
break;
default:
break;
}
}
return Acad::eOk;
}
#if ADS>15
void TDbRect::CreateGrip()
{
TEntityBase::CreateGrip();
for(long i=1;i<5;i++)
{
GetGrip(i)->AppendDim(new TDbGripDistDim(AcDbDimData::kDimResultantLength));//X
GetGrip(i)->AppendDim(new TDbGripDistDim(AcDbDimData::kDimResultantLength));//Y
}
}
Acad::ErrorStatus TDbRect::EntityToDim(long iGrip,long iDim,const AcDbEntity*pEnt)
{
TDbGripDim*pDim=GetGripDim(iGrip,iDim);
if(pDim==NULL)
return Acad::eInvalidInput;
if(pEnt==NULL)
pEnt=this;
TDbRect *pInsert=TDbRect::cast(pEnt);
if(pInsert==NULL)
return Acad::eInvalidInput;
TDbGripDistDim *pDistDim=(TDbGripDistDim*)pDim;
if(iGrip==2||iGrip==4)
{
if(iDim==0)
pDistDim->SetData(pInsert->GetGripPoint((iGrip+2)%4+1),pInsert->GetGripPoint(iGrip),pInsert->GetSizeY()/3);
else if(iDim==1)
pDistDim->SetData(pInsert->GetGripPoint(iGrip),pInsert->GetGripPoint(iGrip%4+1),pInsert->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),pInsert->GetSizeX()/3);
else if(iDim==0)
pDistDim->SetData(pInsert->GetGripPoint(iGrip),pInsert->GetGripPoint(iGrip%4+1),pInsert->GetSizeY()/3);
else
return Acad::eNotImplementedYet;
}
else
return Acad::eNotImplementedYet;
return Acad::eOk;
}
Acad::ErrorStatus TDbRect::DimToEntity(long iGrip,long iDim,double newValue,const AcGeVector3d& offset)
{
assertWriteEnabled();
if(newValue<1E-9)
return Acad::eInvalidInput;
double d;
if(iDim==0)
{
d=newValue-m_nSizeX;
m_nSizeX=newValue;
}
else if(iDim==1)
{
d=newValue-m_nSizeY;
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(GetRotation()+PI);
break;
case 2:
if(iDim==0)
vt.Rotate(GetRotation());
else
vt.Rotate(GetRotation()+PI);
break;
case 3:
vt.Rotate(GetRotation());
break;
case 4:
if(iDim==0)
vt.Rotate(GetRotation()+PI);
else
vt.Rotate(GetRotation());
break;
default:
return Acad::eNotImplementedYet;
}
m_ptCen+=vt;
}
return Acad::eOk;
}
#endif
// 功能: 夹点操作
Acad::ErrorStatus TDbRect::subMoveStretchPointsAt(
const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
if(indices.length()) {
XPoint &vtOffset=*(XPoint *)&offset;
XVector3D vtEcs=Wcs2Ecs(vtOffset, m_vtNormal, TRUE);
m_ptCen += vtEcs;
}
return Acad::eOk;
}
void TDbRect::GetTips(DList<TObjInfoUnit> &lstInfo) const
{
lstInfo.Append(new TObjInfoUnit(_T("对象类型"), _T("上华矩形")));
lstInfo.Append(new TObjInfoUnit(_T("中心点"), Point2d2Str(m_ptCen)));
lstInfo.Append(new TObjInfoUnit(_T("转角"), XString(_T("%d"), AS_INT(m_nRotation*180/PI))));
lstInfo.Append(new TObjInfoUnit(_T("长度X"), Dist2Str(m_nSizeX)));
lstInfo.Append(new TObjInfoUnit(_T("宽度Y"), Dist2Str(m_nSizeY)));
lstInfo.Append(new TObjInfoUnit(_T("高度Z"), Dist2Str(m_nSizeZ)));
}
BOOL TDbRect::SetPolyline(const AcDbPolyline &pline)
{
assertWriteEnabled();
XPoly2D poly2d;
PolyConvert(pline, poly2d);
if(poly2d.TotalSegments()==4) {
XVector3D vtNorm=pline.normal();
SetNormal(vtNorm);
SetRotation(ads_angle(*poly2d[0], *poly2d[1]));
XPoint ptCen;
poly2d.Center(ptCen);
SetCenter(ptCen);
SetSizeX(ads_distance(*poly2d[0], *poly2d[1]));
SetSizeY(ads_distance(*poly2d[2], *poly2d[1]));
SetSizeZ(pline.thickness());
return TRUE;
}
return FALSE;
}
//////////////////////////////////////////////////////////////////////
Acad::ErrorStatus
TDbRect::getPlane(AcGePlane& plane, AcDb::Planarity& flag) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getPlane(plane, flag);
}
Adesk::Boolean TDbRect::isPlanar() const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.isPlanar();
}
Adesk::Boolean TDbRect::isClosed() const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.isClosed();
}
Adesk::Boolean TDbRect::isPeriodic() const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.isPeriodic();
}
Acad::ErrorStatus TDbRect::getStartPoint(AcGePoint3d& ptStart) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getStartPoint(ptStart);
}
Acad::ErrorStatus TDbRect::getEndPoint(AcGePoint3d& ptEnd) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getEndPoint(ptEnd);
}
Acad::ErrorStatus TDbRect::extend(
Adesk::Boolean extendStart,
const AcGePoint3d& toPoint)
{
assertWriteEnabled();
AcDbPolyline pline;
GetPolyline(pline);
return pline.extend(extendStart, toPoint);
}
Acad::ErrorStatus TDbRect::extend(double newParam)
{
assertWriteEnabled();
AcDbPolyline pline;
GetPolyline(pline);
return pline.extend(newParam);
}
Acad::ErrorStatus TDbRect::getClosestPointTo(
const AcGePoint3d& givenPnt,
const AcGeVector3d& normal,
AcGePoint3d& pointOnCurve,
Adesk::Boolean extend ) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getClosestPointTo(givenPnt, normal, pointOnCurve, extend);
}
Acad::ErrorStatus TDbRect::getClosestPointTo(
const AcGePoint3d& givenPnt,
AcGePoint3d& pointOnCurve,
Adesk::Boolean extend ) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getClosestPointTo(givenPnt, pointOnCurve, extend);
}
Acad::ErrorStatus TDbRect::getDistAtParam(
double param,
double& dist) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getDistAtParam(param, dist);
}
Acad::ErrorStatus TDbRect::getDistAtPoint(
const AcGePoint3d& point,
double& distance) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getDistAtPoint(point, distance);
}
Acad::ErrorStatus TDbRect::getStartParam(double& startParam) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getStartParam(startParam);
}
Acad::ErrorStatus TDbRect::getEndParam(double& endParam) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getEndParam(endParam);
}
Acad::ErrorStatus TDbRect::getParamAtPoint(
const AcGePoint3d& point,
double& param) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getParamAtPoint(point, param);
}
Acad::ErrorStatus TDbRect::getParamAtDist(
double dist,
double& param) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getParamAtDist(dist, param);
}
Acad::ErrorStatus TDbRect::getPointAtDist(
double dist,
AcGePoint3d& point) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getPointAtDist(dist, point);
}
Acad::ErrorStatus TDbRect::getPointAtParam(double param, AcGePoint3d &point) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getPointAtParam(param, point);
}
#if (ADS>14)
Acad::ErrorStatus TDbRect::getOffsetCurvesGivenPlaneNormal(
const AcGeVector3d& normal,
double offsetDist,
AcDbVoidPtrArray& offsetCurves) const
{
AcDbVoidPtrArray entSet;
AcDbPolyline pline;
GetPolyline(pline);
Acad::ErrorStatus es=pline.getOffsetCurvesGivenPlaneNormal(normal, offsetDist, entSet);
if(es==Acad::eOk) {
int nCount=entSet.length();
for(int n=0; n<nCount; n++) {
AcDbEntity *pEnt=(AcDbEntity *)entSet[n];
if(pEnt->isKindOf(AcDbPolyline::desc())) {
AcDbPolyline *pCurve=AcDbPolyline::cast(pEnt);
TDbRect *pRect=new TDbRect;
pRect->setPropertiesFrom(this);
if(pRect->SetPolyline(*pCurve))
offsetCurves.append(pRect);
else
delete pRect;
}
}
}
ReleaseEntSet(entSet);
return es;
}
#endif
Acad::ErrorStatus TDbRect::getOffsetCurves(
double offsetDist,
AcDbVoidPtrArray& offsetCurves) const
{
if(offsetDist*2+m_nSizeX<_DIST_SNAP ||
offsetDist*2+m_nSizeY<_DIST_SNAP)
return Acad::eInvalidInput;
TDbRect *pClone=(TDbRect *)clone();
pClone->m_nSizeX += 2*offsetDist;
pClone->m_nSizeY += 2*offsetDist;
offsetCurves.append(pClone);
return Acad::eOk;
}
Acad::ErrorStatus TDbRect::getOrthoProjectedCurve(
const AcGePlane& projPlane,
AcDbCurve*& projCurve) const
{
AcDbPolyline pline;
GetPolyline(pline);
AcDbCurve *pCurve=NULL;
Acad::ErrorStatus es=pline.getOrthoProjectedCurve(projPlane, pCurve);
if(es==Acad::eOk) {
AcDbPolyline *pPolyline=AcDbPolyline::cast(pCurve);
if(pPolyline) {
TDbRect *pClone=(TDbRect *)clone();
if(pClone->SetPolyline(*pPolyline))
projCurve=pClone;
else {
delete pClone;
es=Acad::eInvalidInput;
}
} else
es=Acad::eInvalidInput;
}
if(pCurve) delete pCurve;
return es;
}
Acad::ErrorStatus TDbRect::getProjectedCurve(
const AcGePlane& projPlane,
const AcGeVector3d& projDir,
AcDbCurve*& projCurve) const
{
AcDbPolyline pline;
GetPolyline(pline);
AcDbCurve *pCurve=NULL;
Acad::ErrorStatus es=pline.getProjectedCurve(projPlane, projDir, pCurve);
if(es==Acad::eOk) {
AcDbPolyline *pPolyline=AcDbPolyline::cast(pCurve);
if(pPolyline) {
TDbRect *pClone=(TDbRect *)clone();
if(pClone->SetPolyline(*pPolyline))
projCurve=pClone;
else {
delete pClone;
es=Acad::eInvalidInput;
}
} else
es=Acad::eInvalidInput;
}
if(pCurve) delete pCurve;
return es;
}
Acad::ErrorStatus TDbRect::getFirstDeriv(
double param,
AcGeVector3d& firstDeriv) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getFirstDeriv(param, firstDeriv);
}
Acad::ErrorStatus TDbRect::getFirstDeriv(
const AcGePoint3d& point,
AcGeVector3d& firstDeriv) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getFirstDeriv(point, firstDeriv);
}
Acad::ErrorStatus TDbRect::getSecondDeriv(
double param,
AcGeVector3d& secDeriv) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getSecondDeriv(param, secDeriv);
}
Acad::ErrorStatus TDbRect::getSecondDeriv(
const AcGePoint3d& point,
AcGeVector3d& secDeriv) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getSecondDeriv(point, secDeriv);
}
Acad::ErrorStatus TDbRect::getSpline(AcDbSpline*& spline) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getSpline(spline);
}
Acad::ErrorStatus TDbRect::getSplitCurves(
const AcGeDoubleArray& params,
AcDbVoidPtrArray& curveSegments) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getSplitCurves(params, curveSegments);
}
Acad::ErrorStatus TDbRect::getSplitCurves(
const AcGePoint3dArray& points,
AcDbVoidPtrArray& curveSegments) const
{
AcDbPolyline pline;
GetPolyline(pline);
return pline.getSplitCurves(points, curveSegments);
}
void InitDbRect(BOOL bTrue)
{
if(bTrue) {
TDbRect::rxInit();
acrxBuildClassHierarchy();
TDbRect::InitMatchProtocol(TRUE);
} else {
TDbRect::InitMatchProtocol(FALSE);
deleteAcRxClass(TDbRect::desc());
}
}
void CreateRectangle()
{
XPoint pt1, pt2;
if(XGetPoint(NULL, _T("\n第一个角点"), pt1)==RTNORM &&
ads_getcorner(pt1, _T("\n第二个角点<退出>:"), pt2)==RTNORM) {
XVector3D vt=Ucs2Wcs(XVector3D(0,0,1), TRUE);
XRectAngle box(pt1, pt2);
XPoint ptCen;
Midpoint(pt1, pt2, ptCen);
TDbRect *pRect=new TDbRect;
pRect->SetNormal(vt);
pRect->SetCenter(Ucs2Ecs(ptCen, vt));
pRect->SetSizeX(box.Width());
pRect->SetSizeY(box.Height());
pRect->SetRotation(Ucs2Wcs(0.0));
pRect->AddToCSpace(Adesk::kTrue);
}
}