天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 82|回复: 0

arx 自定义实体简单实例

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
class DLLIMPEXP MyLineEx : public AcDbEntity {


public:
ACRX_DECLARE_MEMBERS(MyLineEx) ;


protected:
static Adesk::UInt32 kCurrentVersionNumber ;


private:
AcGePoint3d m_ptStart;
AcGePoint3d m_ptEnd;


public:
MyLineEx () ;
MyLineEx (const AcGePoint3d& s,const AcGePoint3d& e);


virtual ~MyLineEx () ;
//----- AcDbObject protocols
//- Dwg Filing protocol


////保存,复制
virtual Acad::ErrorStatus dwgOutFields (AcDbDwgFiler *pFiler) const ;
virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler *pFiler) ;


//----- AcDbEntity protocols
//- Graphics protocol
protected:

////显示的时候调用
virtual Adesk::Boolean subWorldDraw (AcGiWorldDraw *mode) ;
////暂时不知道
virtual Adesk::UInt32 subSetAttributes (AcGiDrawableTraits *traits) ;


////单击时候触发,显示夹点
virtual Acad::ErrorStatus subGetGripPoints(
    AcGePoint3dArray& gripPoints,
    AcDbIntArray&  osnapModes,
    AcDbIntArray&  geomIds) const;


////移动时候触发
virtual Acad::ErrorStatus subMoveGripPointsAt(const AcDbIntArray& indices,
                                                     const AcGeVector3d& offset);


////捕捉的时候
virtual Acad::ErrorStatus subGetOsnapPoints(
                                    AcDb::OsnapMode     osnapMode,
                                    Adesk::GsMarker     gsSelectionMark,
                                    const AcGePoint3d&  pickPoint,
                                    const AcGePoint3d&  lastPoint,
                                    const AcGeMatrix3d& viewXform,
                                    AcGePoint3dArray&   snapPoints,
                                    AcDbIntArray &   geomIds) const;


////移动,旋转
virtual Acad::ErrorStatus   subTransformBy(const AcGeMatrix3d& xform);


////暂时不知道
virtual Acad::ErrorStatus   subGetTransformedCopy(const AcGeMatrix3d& xform,
                                                   AcDbEntity*& pEnt) const;
} ;
//===========================================================================

MyLineEx::MyLineEx () : AcDbEntity () {
}


MyLineEx::MyLineEx(const AcGePoint3d& s,const AcGePoint3d& e)
{
m_ptStart[X] = s[X];
m_ptStart[Y] = s[Y];
m_ptStart[Z] = s[Z];


m_ptEnd[X] = e[X];
m_ptEnd[Y] = e[Y];
m_ptEnd[Z] = e[Z];
}


MyLineEx::~MyLineEx () {
}


////单击实体的时候用到,添加夹点
Acad::ErrorStatus MyLineEx::subGetGripPoints(
    AcGePoint3dArray& gripPoints,
    AcDbIntArray&  osnapModes,
AcDbIntArray&  geomIds) const
{

//acedInitGet(RSG_NOZERO + RSG_NONULL+RSG_NONEG,_T(""));
assertReadEnabled();
// TODO: implement this function.
AcGeVector3d vecLine = m_ptEnd - m_ptStart;
acutPrintf(_T("\nsubGetGripPoints"));
gripPoints.append(m_ptStart);
gripPoints.append(m_ptEnd);
gripPoints.append(m_ptStart + vecLine / 2.0);
gripPoints.append(m_ptStart + vecLine / 3.0);



return Acad::eOk;
}


////拖动夹点的时候用到,indices为夹点数组的下标数组
Acad::ErrorStatus MyLineEx::subMoveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
// TODO: implement this function.
assertReadEnabled();


int len = indices.length();
for(int i = 0;i < len; i++)
{
int k = indices[i];


switch(k)
{
case 0:
m_ptStart += offset;
break;
case 1:
m_ptEnd += offset;
break;
case 2:
case 3:
m_ptStart += offset;
m_ptEnd += offset;
break;
default:break;
}
}



return Acad::eOk;
}


////捕捉的时候调用,添加捕捉点(交点不是这个函数)
Acad::ErrorStatus MyLineEx::subGetOsnapPoints(
                                    AcDb::OsnapMode     osnapMode,
                                    Adesk::GsMarker     gsSelectionMark,
                                    const AcGePoint3d&  pickPoint,
                                    const AcGePoint3d&  lastPoint,
                                    const AcGeMatrix3d& viewXform,
                                    AcGePoint3dArray&   snapPoints,
                                    AcDbIntArray &   geomIds) const
{
//assertWriteEnabled();
// TODO: implement this function.
assertReadEnabled();
// TODO: implement this function.
snapPoints.append(m_ptStart);
snapPoints.append(m_ptEnd);
snapPoints.append(m_ptStart + (m_ptEnd - m_ptStart) / 2);
snapPoints.append(m_ptStart + (m_ptEnd - m_ptStart) / 3);
//snapPoints.append(m_ptStart + (m_ptEnd - m_ptStart) / 4);


/*return Acad::eOk;*/
return Acad::eOk;/*AcDbEntity::getOsnapPoints(osnapMode, gsSelectionMark, pickPoint, lastPoint, viewXform, snapPoints, geomIds);*/
}


////实现移动,旋转等变换
Acad::ErrorStatus   MyLineEx::subTransformBy(const AcGeMatrix3d& xform)
{
assertReadEnabled();
assertWriteEnabled();


m_ptStart.transformBy(xform);
m_ptEnd.transformBy(xform);
//m_center.transformBy(mat);
return Acad::eOk;
}


Acad::ErrorStatus MyLineEx::subGetTransformedCopy(const AcGeMatrix3d& xform,AcDbEntity*& pEnt) const
{
assertReadEnabled();


//AcGePoint3d ptS = m_ptStart;
//AcGePoint3d ptE = m_ptEnd;
//
//ptS.transformBy(xform);
//ptE.transformBy(xform);


//AcDbLine* ent = new AcDbLine(m_ptStart,m_ptEnd);
//assert(ent != NULL);
//ent->setPropertiesFrom(this);
//pEnt = ent;


acutPrintf(_T("\naaa"));
//m_ptStart.transformBy(xform);
//m_ptEnd.transformBy(xform);
return Acad::eOk;
}




//-----------------------------------------------------------------------------
//----- AcDbObject protocols
//- Dwg Filing protocol
Acad::ErrorStatus MyLineEx::dwgOutFields (AcDbDwgFiler *pFiler) const {
assertReadEnabled () ;
//----- Save parent class information first.
Acad::ErrorStatus es =AcDbEntity::dwgOutFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//----- Object version number needs to be saved first
if ( (es =pFiler->writeUInt32 (MyLineEx::kCurrentVersionNumber)) != Acad::eOk )
return (es) ;
//----- Output params
//.....
////这两句加上才能复制
pFiler->writePoint3d(m_ptStart);
pFiler->writePoint3d(m_ptEnd);


return (pFiler->filerStatus ()) ;
}


Acad::ErrorStatus MyLineEx::dwgInFields (AcDbDwgFiler *pFiler) {
assertWriteEnabled () ;
//----- Read parent class information first.
Acad::ErrorStatus es =AcDbEntity::dwgInFields (pFiler) ;
if ( es != Acad::eOk )
return (es) ;
//----- Object version number needs to be read first
Adesk::UInt32 version =0 ;
if ( (es =pFiler->readUInt32 (&version)) != Acad::eOk )
return (es) ;
if ( version > MyLineEx::kCurrentVersionNumber )
return (Acad::eMakeMeProxy) ;
//- Uncomment the 2 following lines if your current object implementation cannot
//- support previous version of that object.
//if ( version < MyLineEx::kCurrentVersionNumber )
// return (Acad::eMakeMeProxy) ;
//----- Read params
//.....
////这两句加上,才能复制
pFiler->readPoint3d(&m_ptStart);
pFiler->readPoint3d(&m_ptEnd);






return (pFiler->filerStatus ()) ;
}

//-----------------------------------------------------------------------------
//----- AcDbEntity protocols
Adesk::Boolean MyLineEx::subWorldDraw (AcGiWorldDraw *mode) {
assertReadEnabled () ;


//获取虚线线型ID
mode->subEntityTraits().setColor(150);


AcGePoint3d Verts[2];
Verts[0]=m_ptStart;
Verts[1]=m_ptEnd;
mode->geometry().polyline(2,Verts);


return (AcDbEntity::subWorldDraw (mode)) ;
}

 

 

 

 

arx 自定义实体简单实例
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 09:25 , Processed in 0.167346 second(s), 28 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表