arx 自定义实体简单实例
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 = s;
m采用ptStart = s;
m采用ptStart = s;
m采用ptEnd = e;
m采用ptEnd = e;
m采用ptEnd = e;
}
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;
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;
Verts=m采用ptStart;
Verts=m采用ptEnd;
mode->geometry().polyline(2,Verts);
return (AcDbEntity::subWorldDraw (mode)) ;
}
页:
[1]