1. 程式人生 > >arx 自定義實體簡單例項

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[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)) ;
}