uusky 发表于 2005-9-28 14:39:00

[ARX]如何闭合正在画的n边形?(给出源程序)

本帖最后由 作者 于 2005-9-29 10:05:51 编辑 <br /><br /> <P>附上我的测试程序,里面提供了我尺寸标注&nbsp; 求面积&nbsp; 画表格的程序</P>
<P>#include &lt;aced.h&gt;<BR>#include &lt;acedads.h&gt;<BR>#include &lt;dbents.h&gt;<BR>#include &lt;dbsymtb.h&gt;<BR>#include &lt;dbgroup.h&gt;<BR>#include &lt;dbapserv.h&gt;<BR>#include &lt;acestext.h&gt;<BR>#include &lt;migrtion.h&gt;<BR>#include &lt;geassign.h&gt;<BR>#include &lt;math.h&gt;<BR>#include &lt;dbpl.h &gt;</P>
<P>&nbsp;ads_point&nbsp; pt1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcGePoint3d&nbsp; pt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int NodeNumCount; <BR>void&nbsp; area()<BR>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i=0;<BR>&nbsp;acedGetPoint(NULL,"\n请选择起始点:",asDblArray(pt));<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do&nbsp;&nbsp; &nbsp;{<BR>&nbsp;&nbsp;acedGetPoint(asDblArray(pt),"\n拾取下一点:",asDblArray(pt));<BR>&nbsp;&nbsp;AcDbLine *pLine=new AcDbLine(pt,pt);<BR>&nbsp;&nbsp;AcDbBlockTable *pBlkTable2;<BR>&nbsp;&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;-&gt;getSymbolTable(pBlkTable2, AcDb::kForRead);<BR>&nbsp;&nbsp;AcDbBlockTableRecord *pBlockTableRecord;<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;pBlkTable2-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecord,<BR>&nbsp;&nbsp;&nbsp;AcDb::kForWrite);<BR>&nbsp;&nbsp;pBlkTable2-&gt;close();<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;AcDbObjectId lineId=AcDbObjectId::kNull;<BR>&nbsp;&nbsp;pBlockTableRecord-&gt;appendAcDbEntity(lineId, pLine);<BR>&nbsp;&nbsp;pBlockTableRecord-&gt;close();<BR>&nbsp;&nbsp;pLine-&gt;close();<BR>&nbsp;&nbsp;changepoint(pt1,pt);//转换点的类型<BR>&nbsp;&nbsp;changepoint(pt1,pt);//转换点的类型<BR>&nbsp;&nbsp;&nbsp;i++;<BR>&nbsp;&nbsp;&nbsp;NodeNumCount=i;//取得边数<BR>&nbsp;&nbsp; }<BR>&nbsp;while((Equal_Points (pt1, pt1))==0);//起始点=终点时结束循环<BR>}</P>
<P>int Equal_Points (const ads_point p1, const ads_point p2) //判断两点是否为同一点<BR>{<BR>&nbsp;&nbsp;&nbsp; // 指定误差范围<BR>&nbsp;&nbsp;&nbsp; const ads_real Equality_Margin = (ads_real)0.0001; <BR>&nbsp;&nbsp;&nbsp; int c ;<BR>&nbsp;&nbsp;&nbsp; for (c = X ; c &lt;= Z ; c++) <BR>&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (fabs(p1 - p2) &gt; Equality_Margin)<BR>&nbsp;&nbsp;{ return (0) ; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;{<BR>&nbsp;&nbsp;&nbsp;AcDbLine *pLine=new AcDbLine(pt,pt);<BR>&nbsp;&nbsp;&nbsp;AcDbBlockTable *pBlkTable2;<BR>&nbsp;&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;-&gt;getSymbolTable(pBlkTable2, AcDb::kForRead);<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;AcDbBlockTableRecord *pBlockTableRecord;<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;pBlkTable2-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecord,<BR>&nbsp;&nbsp;&nbsp;AcDb::kForWrite);<BR>&nbsp;&nbsp;pBlkTable2-&gt;close();<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;AcDbObjectId lineId=AcDbObjectId::kNull;<BR>&nbsp;&nbsp;pBlockTableRecord-&gt;appendAcDbEntity(lineId, pLine);<BR>&nbsp;&nbsp;pBlockTableRecord-&gt;close();<BR>&nbsp;&nbsp;pLine-&gt;close();<BR>&nbsp;&nbsp;&nbsp; return (1) ;<BR>&nbsp;}<BR>}</P>
<P>void changepoint(ads_point&amp; ads_pt,AcGePoint3d acge_pt)&nbsp; //AcGePoint3d转换成ads_point类型<BR>{ <BR>&nbsp;double x=acge_pt; <BR>&nbsp;double y=acge_pt; <BR>&nbsp;double z=acge_pt;<BR>&nbsp;ads_pt=x; <BR>&nbsp;ads_pt=y; <BR>&nbsp;ads_pt=z; <BR>}</P>
<P>对于如上这段画n边形的程序,有个失误的地方,就是他是以起点=终点来判断n边形画结束的,如果遇到图形线段很多时,如果找不到起点,就会陷入死循环!!</P>
<P>在正常的CAd画图中我们可以用“C”命令来闭合当前正在画的图形,请问这在程序中如何实现,希望有高手指点一下!</P>

uusky 发表于 2005-9-30 19:24:00

斑竹能不能给个意见啊谢谢了

JA_JERRY 发表于 2005-10-2 18:24:00

<P>你可以用AcDbPolyline来画多边形,然后调用setClosed(Adesk::kTrue)实现闭合</P>
页: [1]
查看完整版本: [ARX]如何闭合正在画的n边形?(给出源程序)