洪华 发表于 2006-3-20 23:21:00

[ARX]

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