netspyboy 发表于 2010-6-21 11:27:00

直线、圆弧如何转换成多义线

<p>如题<font face="Verdana">直线(<font face="Verdana">AcDbLine</font>)<font face="Verdana">圆弧</font>(<font face="Verdana">AcDbArc</font>)如何转换成多义线(<font face="Verdana">AcDbPolyline</font>)?</font></p>
<p>我想给直线添加宽度,故转换为多义线(<font face="Verdana">pline-&gt;setLineWeight()不是我的答案</font>)</p>
<p>我想用多义线的<font face="Verdana">pPolyline-&gt;setWidthsAt(i,PL_Width,PL_Width);</font></p>
<p>跪求转换方法,</p>

rongyifei 发表于 2010-6-21 20:41:00

<p><font face="Verdana">AcDbObjectId PostToMS(AcDbEntity *pEnt)<br/>{<br/>&nbsp;AcDbBlockTable *pBlkTbl;<br/>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getBlockTable(pBlkTbl,<br/>&nbsp;&nbsp;AcDb::kForRead);<br/>&nbsp;AcDbBlockTableRecord *pMS;<br/>&nbsp;pBlkTbl-&gt;getAt(ACDB_MODEL_SPACE,pMS,AcDb::kForWrite);<br/>&nbsp;pBlkTbl-&gt;close();<br/>&nbsp;AcDbObjectId EntID;<br/>&nbsp;pMS-&gt;appendAcDbEntity(EntID,pEnt);<br/>&nbsp;pMS-&gt;close();<br/>&nbsp;return EntID;<br/>}</font></p>
<p>&nbsp;</p>
<p><font face="Verdana">static void ROYMyTest_test1(void)<br/>&nbsp;{<br/>&nbsp;&nbsp;// Add your code for command ROYMyTest._test1 here<br/>&nbsp;&nbsp;ads_point pt;<br/>&nbsp;&nbsp;ads_name ename;<br/>&nbsp;&nbsp;AcDbObjectId EntID;<br/>&nbsp;&nbsp;AcDbEntity *pEnt=NULL;<br/>&nbsp;&nbsp;if (acedEntSel(_T("\nSelect a line or arc:"),ename,pt)!=RTNORM<br/>&nbsp;&nbsp;&nbsp;|| acdbGetObjectId(EntID,ename)!=Acad::eOk<br/>&nbsp;&nbsp;&nbsp;|| acdbOpenAcDbEntity(pEnt,EntID,AcDb::kForRead)!=Acad::eOk)<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;if (!(pEnt-&gt;isKindOf(AcDbLine::desc()) || pEnt-&gt;isKindOf(AcDbArc::desc())))<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;pEnt-&gt;close();<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;AcDbLine *pLine;<br/>&nbsp;&nbsp;AcDbArc *pArc;<br/>&nbsp;&nbsp;AcGePoint3d ptStart,ptEnd;<br/>&nbsp;&nbsp;double dBugle,startAngle,endAngle,dAngle;<br/>&nbsp;&nbsp;if (pEnt-&gt;isKindOf(AcDbLine::desc()))<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;pLine=AcDbLine::cast(pEnt);<br/>&nbsp;&nbsp;&nbsp;if (pLine!=NULL)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;ptStart=pLine-&gt;startPoint();<br/>&nbsp;&nbsp;&nbsp;&nbsp;ptEnd=pLine-&gt;endPoint();<br/>&nbsp;&nbsp;&nbsp;&nbsp;dBugle=0;<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;else<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;pArc=AcDbArc::cast(pEnt);<br/>&nbsp;&nbsp;&nbsp;if (pArc!=NULL)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;pArc-&gt;getStartPoint(ptStart);<br/>&nbsp;&nbsp;&nbsp;&nbsp;pArc-&gt;getEndPoint(ptEnd);<br/>&nbsp;&nbsp;&nbsp;&nbsp;startAngle=pArc-&gt;startAngle();<br/>&nbsp;&nbsp;&nbsp;&nbsp;endAngle=pArc-&gt;endAngle();<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (endAngle&lt;startAngle)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endAngle+=8*atan(1.0);<br/>&nbsp;&nbsp;&nbsp;&nbsp;dAngle=endAngle-startAngle;<br/>&nbsp;&nbsp;&nbsp;&nbsp;dBugle=tan(dAngle/4);<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;if (pEnt-&gt;upgradeOpen()!=Acad::eOk)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;pEnt-&gt;close();<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;pEnt-&gt;erase();<br/>&nbsp;&nbsp;pEnt-&gt;close();</font></p>
<p><font face="Verdana">&nbsp;&nbsp;AcDbPolyline *pPLine;<br/>&nbsp;&nbsp;pPLine=new AcDbPolyline(2);<br/>&nbsp;&nbsp;pPLine-&gt;addVertexAt(0,asPnt2d(asDblArray(ptStart)),dBugle);<br/>&nbsp;&nbsp;pPLine-&gt;addVertexAt(1,asPnt2d(asDblArray(ptEnd)));<br/>&nbsp;&nbsp;PostToMS((AcDbEntity*)pPLine);<br/>&nbsp;&nbsp;pPLine-&gt;close();<br/>&nbsp;}</font></p>

rongyifei 发表于 2010-6-21 20:42:00

<p>以上代码仅供参考!</p>

netspyboy 发表于 2010-6-22 16:46:00

<p>首先感谢
<table style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all" class="bbslist100 tableborder" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="BORDER-BOTTOM: #e4e7ec 1px="1px"solid; BACKGROUND: #fafdff" class="infoleft leftcolor" valign="center"><img alt="帅哥哟,离线,有人找我吗?" src="http://bbs.mjtd.com/Skins/Default/ofMale.gif"/>
<div><span style="FILTER: glow(color='#A6BA98',strength='2'); WIDTH: 105px"><font color="#61b713" face="Verdana"><b>rongyifei</b></font></div></span></td></tr></tbody></table></p>无私的把代码分享出来

netspyboy 发表于 2010-6-22 16:51:00

<p>困惑我很久以致我自己的代码不能成功转换的就是少了:endAngle+=8*atan(1.0)这句,导致dBugle不对。</p>
<p>非常感谢。</p>
页: [1]
查看完整版本: 直线、圆弧如何转换成多义线