[ARX]
<P>本人刚在学习ObjectARX,出现如下问题望各位看看:<BR>1:在AcDbEntity派生类中定义了getGripPoints()函数,但在CAD中看不到夹点,<BR>是何原因(下附原程序).<BR>2:在worldDraw()函数中采用AcDbText *pText=new AcDbText()与<BR>mode->geometry().text()定义实体有何区别.<BR>类定义:<BR>class DLLIMPEXP dingteClass : public AcDbCurve<BR>{<BR>public:</P><P> ACRX_DECLARE_MEMBERS(dingteClass);</P>
<P> // Constructor / Destructor<BR> dingteClass();<BR> virtual ~dingteClass();</P>
<P> //{{AFX_ARX_METHODS(dingteClass)<BR> virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* pFiler) const;<BR> virtual Acad::ErrorStatus dxfInFields(AcDbDxfFiler* pFiler);<BR> virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;<BR> virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler);<BR> virtual Acad::ErrorStatus getStartPoint(AcGePoint3d& x0) const;<BR> virtual Acad::ErrorStatus getEndPoint(AcGePoint3d& x0) const;<BR> virtual Acad::ErrorStatus getGripPoints(AcGePoint3dArray& gripPoints,<BR> AcDbIntArray& osnapModes,<BR> AcDbIntArray& geomIds) const;<BR> virtual Acad::ErrorStatus moveGripPointsAt(const AcDbIntArray& indices,<BR> const AcGeVector3d& offset);<BR> <BR> virtual Acad::ErrorStatus transformBy(const AcGeMatrix3d& xform); <BR> virtual Adesk::Boolean worldDraw(AcGiWorldDraw* mode);<BR> //}}AFX_ARX_METHODS</P>
<P><BR> //{{AFX_ARX_DATA_ACCESS(dingteClass)<BR> Acad::ErrorStatus setEntPoint(const AcGePoint3d entPoint);<BR> Acad::ErrorStatus entPoint(AcGePoint3d& entPoint);<BR> Acad::ErrorStatus setStartPoint(const AcGePoint3d startPoint);<BR> Acad::ErrorStatus startPoint(AcGePoint3d& startPoint);<BR> //}}AFX_ARX_DATA_ACCESS</P>
<P><BR>private:<BR> //{{AFX_ARX_DATA(dingteClass)<BR> AcGePoint3d m_entPoint;<BR> AcGePoint3d m_startPoint;<BR> //}}AFX_ARX_DATA</P>
<P><BR>private:</P>
<P> void *operator new[](unsigned nSize) { return 0; }<BR> void operator delete[](void *p) {};<BR> void *operator new[](unsigned nSize, const char *file, int line) { return 0; }</P>
<P>};<BR>类实现:<BR>Adesk::Boolean dingteClass::worldDraw(AcGiWorldDraw* mode)<BR>{<BR> assertReadEnabled();<BR> // TODO: implement this function.<BR> //AcGePoint3d startPoint,entPoint;<BR> //this->startPoint(startPoint);<BR> //this->entPoint(entPoint);<BR> //AcGeVector3d normal(0.0, 0.0, 1.0);<BR> //AcGeVector3d direction=m_startPoint-m_entPoint;<BR> //mode->geometry().text(m_startPoint,normal,direction,5,0.8,0,"toolTe");</P>
<P> //AcGePoint3d *pVerts=new AcGePoint3d;<BR> //pVerts=m_startPoint;<BR> //pVerts=m_entPoint;<BR> //mode->geometry().polyline(2,pVerts);</P>
<P> AcDbText *pText=new AcDbText();<BR> pText->setTextString("Hello");<BR> pText->setPosition(m_startPoint);<BR> pText->setHeight(5.0);<BR> pText->worldDraw(mode);</P>
<P> AcDbLine *line;<BR> line=new AcDbLine(m_startPoint,m_entPoint);<BR> line->worldDraw(mode);</P>
<P> return AcDbEntity::worldDraw(mode);<BR>}</P>
<P>Acad::ErrorStatus dingteClass::startPoint(AcGePoint3d& startPoint)<BR>{<BR> assertReadEnabled();<BR> startPoint = m_startPoint;<BR> return Acad::eOk;<BR>}</P>
<P>Acad::ErrorStatus dingteClass::setStartPoint(const AcGePoint3d startPoint)<BR>{<BR> assertWriteEnabled();<BR> m_startPoint = startPoint;<BR> return Acad::eOk;<BR>}</P>
<P>Acad::ErrorStatus dingteClass::entPoint(AcGePoint3d& entPoint)<BR>{<BR> assertReadEnabled();<BR> entPoint = m_entPoint;<BR> return Acad::eOk;<BR>}</P>
<P>Acad::ErrorStatus dingteClass::setEntPoint(const AcGePoint3d entPoint)<BR>{<BR> assertWriteEnabled();<BR> m_entPoint = entPoint;<BR> return Acad::eOk;<BR>}</P>
<P><BR>Acad::ErrorStatus dingteClass::transformBy(const AcGeMatrix3d& xform)<BR>{<BR> assertWriteEnabled();<BR> // TODO: implement this function.<BR> m_startPoint.transformBy(xform);<BR> m_entPoint.transformBy(xform);</P>
<P> return AcDbEntity::transformBy(xform);<BR>}</P>
<P><BR>Acad::ErrorStatus dingteClass::moveGripPointsAt(const AcDbIntArray& indices,<BR> const AcGeVector3d& offset)<BR>{<BR> assertWriteEnabled();<BR> // TODO: implement this function.</P>
<P> dingteClass* te=new dingteClass();<BR> AcGePoint3d entPoint,startPoint;<BR> te->getEndPoint(entPoint);<BR> te->getStartPoint(startPoint);<BR> startPoint +=offset;<BR> entPoint +=offset;<BR> te->setEntPoint(entPoint);<BR> te->setStartPoint(startPoint);<BR> return AcDbEntity::moveGripPointsAt(indices, offset);<BR>}</P>
<P>Acad::ErrorStatus dingteClass::getGripPoints(AcGePoint3dArray& gripPoints,<BR> AcDbIntArray& osnapModes,<BR> AcDbIntArray& geomIds) const<BR>{<BR> assertReadEnabled();<BR> // TODO: implement this function.<BR> AcGePoint3d entPoint,startPoint;<BR> AcGeVector3d normal(0.0, 0.0, 1.0); <BR> startPoint=m_startPoint;<BR> entPoint=m_entPoint;<BR> acdbEcs2Wcs(asDblArray(startPoint),<BR> asDblArray(startPoint),asDblArray(normal),Adesk::kFalse);<BR> acdbEcs2Wcs(asDblArray(entPoint),<BR> asDblArray(entPoint),asDblArray(normal),Adesk::kFalse);<BR> gripPoints.append(startPoint);<BR> gripPoints.append(entPoint);<BR> </P>
<P> return AcDbEntity::getGripPoints(gripPoints, osnapModes, geomIds);<BR>}</P>
<P>Acad::ErrorStatus dingteClass::getEndPoint(AcGePoint3d& x0) const<BR>{<BR> assertReadEnabled();<BR> // TODO: implement this function.</P>
<P> x0=m_entPoint;<BR> return AcDbCurve::getEndPoint(x0);<BR>}</P>
<P>Acad::ErrorStatus dingteClass::getStartPoint(AcGePoint3d& x0) const<BR>{<BR> assertReadEnabled();<BR> // TODO: implement this function.<BR> x0=m_startPoint;</P>
<P> return AcDbCurve::getStartPoint(x0);<BR>}</P>
<P>Acad::ErrorStatus dingteClass::dwgInFields(AcDbDwgFiler* pFiler)<BR>{<BR> assertWriteEnabled();<BR> Acad::ErrorStatus es;</P>
<P> // Call dwgInFields from AcDbCurve<BR> if ((es = AcDbCurve::dwgInFields(pFiler)) != Acad::eOk) {<BR> return es;<BR> }</P>
<P> // Read version number.<BR> Adesk::UInt16 version;<BR> pFiler->readItem(&version);<BR> if (version > VERSION_DINGTECLASS)<BR> return Acad::eMakeMeProxy;</P>
<P> // Read the data members.<BR> switch (version)<BR> {<BR> case (1):<BR> pFiler->readItem(&m_startPoint);<BR> pFiler->readItem(&m_entPoint);<BR> // TODO: here you can file datamembers not<BR> // created by the ObjectARX Add-In.</P>
<P> break;<BR> }</P>
<P><BR> return pFiler->filerStatus();<BR>}</P>
<P>Acad::ErrorStatus dingteClass::dwgOutFields(AcDbDwgFiler* pFiler) const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es;</P>
<P> // Call dwgOutFields from AcDbCurve<BR> if ((es = AcDbCurve::dwgOutFields(pFiler)) != Acad::eOk) {<BR> return es;<BR> }</P>
<P> // Write version number.<BR> pFiler->writeItem((Adesk::UInt16) VERSION_DINGTECLASS);</P>
<P> // Write the data members.<BR> pFiler->writeItem(m_startPoint);<BR> pFiler->writeItem(m_entPoint);<BR> // TODO: here you can file datamembers not<BR> // created by the ObjectARX Add-In.</P>
<P><BR> return pFiler->filerStatus();<BR>}</P>
<P>Acad::ErrorStatus dingteClass::dxfInFields(AcDbDxfFiler* pFiler)<BR>{<BR> assertWriteEnabled();<BR> struct resbuf rb;</P>
<P> if ((AcDbCurve::dxfInFields(pFiler) != Acad::eOk) ||<BR> !pFiler->atSubclassData("dingteClass"))<BR> return pFiler->filerStatus();</P>
<P> // Read version number.<BR> pFiler->readItem(&rb);<BR> if (rb.restype != AcDb::kDxfInt16) {<BR> pFiler->pushBackItem();<BR> pFiler->setError(Acad::eInvalidDxfCode,<BR> "nError: expected object version group code %d",<BR> AcDb::kDxfInt16);<BR> return pFiler->filerStatus();<BR> } else {<BR> Adesk::UInt16 version = rb.resval.rint;<BR> if (version > VERSION_DINGTECLASS)<BR> return Acad::eMakeMeProxy;<BR> }</P>
<P> pFiler->readItem(&rb);<BR> if (rb.restype == AcDb::kDxfXCoord) {<BR> m_startPoint = asPnt3d(rb.resval.rpoint);<BR> } else {<BR> pFiler->pushBackItem();<BR> pFiler->setError(Acad::eInvalidDxfCode,<BR> "nError: expected group code %d",<BR> AcDb::kDxfXCoord);<BR> return pFiler->filerStatus();<BR> }</P>
<P> pFiler->readItem(&rb);<BR> if (rb.restype == AcDb::kDxfXCoord + 1) {<BR> m_entPoint = asPnt3d(rb.resval.rpoint);<BR> } else {<BR> pFiler->pushBackItem();<BR> pFiler->setError(Acad::eInvalidDxfCode,<BR> "nError: expected group code %d",<BR> AcDb::kDxfXCoord + 1);<BR> return pFiler->filerStatus();<BR> }</P>
<P> // TODO: here you can file datamembers not<BR> // created by the ObjectARX Add-In.</P>
<P> return pFiler->filerStatus();<BR>}</P>
<P>Acad::ErrorStatus dingteClass::dxfOutFields(AcDbDxfFiler* pFiler) const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es;</P>
<P> if ((es = AcDbCurve::dxfOutFields(pFiler)) != Acad::eOk)<BR> return es;</P>
<P> // Write subclass marker.<BR> pFiler->writeItem(AcDb::kDxfSubclass, "dingteClass");</P>
<P> // Write version number.<BR> pFiler->writeItem(AcDb::kDxfInt16, (Adesk::UInt16) VERSION_DINGTECLASS);</P>
<P> pFiler->writeItem(AcDb::kDxfXCoord, m_startPoint);<BR> pFiler->writeItem(AcDb::kDxfXCoord + 1, m_entPoint);</P>
<P> // TODO: here you can file datamembers not<BR> // created by the ObjectARX Add-In.</P>
<P> return es;<BR>}</P>
页:
[1]