blackriver 发表于 2006-7-8 11:00:00

ARX自定义捕捉(AcDbCustomOsnapInfo)中的两个问题

<P>ARX自定义捕捉(AcDbCustomOsnapInfo)中的两个问题</P>
<P>1. 如果同时捕捉一条直线的中点与最近点,例子如下,但在捕捉中点的时候非常不易,总是受最近点的影响. 猜想可以pickPoint与中点之间的显</P>
<P>示距离小于一定像素时,只追加中点,而不再追加最近点,但又不能计算它们之间的显示距离(像素值)</P>
<P>Acad::ErrorStatus<BR>AsdkThirdOsnapCurveInfo::getOsnapInfo(<BR>&nbsp;AcDbEntity*&nbsp;&nbsp;&nbsp;&nbsp;pickedObject,<BR>&nbsp;int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gsSelectionMark,<BR>&nbsp;const AcGePoint3d&amp;&nbsp;&nbsp;pickPoint,<BR>&nbsp;const AcGePoint3d&amp;&nbsp;&nbsp;lastPoint,<BR>&nbsp;const AcGeMatrix3d&amp;&nbsp;&nbsp;viewXform,<BR>&nbsp;AcArray&lt;AcGePoint3d&gt;&amp;&nbsp;snapPoints,<BR>&nbsp;AcArray&lt;int&gt;&amp;&nbsp;&nbsp;&nbsp;geomIdsForPts,<BR>&nbsp;AcArray&lt;AcGeCurve3d*&gt;&amp;&nbsp;snapCurves,<BR>&nbsp;AcArray&lt;int&gt;&amp;&nbsp;&nbsp;&nbsp;geomIdsForLines)<BR>{<BR>&nbsp;if(pickedObject-&gt;isKindOf(AcDbLine::desc()))<BR>&nbsp;{<BR>&nbsp;&nbsp;AcDbLine *pLine=AcDbLine::cast(pickedObject);<BR>&nbsp;&nbsp;double startParam, endParam;<BR>&nbsp;&nbsp;Acad::ErrorStatus es=pLine-&gt;getStartParam( startParam);<BR>&nbsp;&nbsp;es=pLine-&gt;getEndParam( endParam );</P>
<P>&nbsp;&nbsp;AcGePoint3d pt;<BR>&nbsp;&nbsp;es=pLine-&gt;getPointAtParam( 0.5*(startParam + endParam), pt );<BR>&nbsp;&nbsp;snapPoints.append(pt);</P>
<P>&nbsp;&nbsp;pLine-&gt;getClosestPointTo(pickPoint, pt);<BR>&nbsp;&nbsp;snapPoints.append(pt);<BR>&nbsp;}<BR>&nbsp;return Acad::eOk;<BR>}</P>
<P>2. 怎样捕捉圆(圆弧的圆心)?问题是:鼠标移到圆弧上时,并没有显示圆心符号. 如果加上以下一段:<BR>&nbsp;&nbsp;AcGeLine3d *pLine1=new AcGeLine3d(pt, pt+AcGeVector3d(1, 0, 0));<BR>&nbsp;&nbsp;snapCurves.append(pLine1);<BR>&nbsp;能显示圆心符号,并能进行X方向的对象追踪,但鼠标移到圆心位置时,圆心符号即消失.</P>
<P><BR>AsdkThirdOsnapCurveInfo::getOsnapInfo(<BR>&nbsp;AcDbEntity*&nbsp;&nbsp;&nbsp;&nbsp;pickedObject,<BR>&nbsp;int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gsSelectionMark,<BR>&nbsp;const AcGePoint3d&amp;&nbsp;&nbsp;pickPoint,<BR>&nbsp;const AcGePoint3d&amp;&nbsp;&nbsp;lastPoint,<BR>&nbsp;const AcGeMatrix3d&amp;&nbsp;&nbsp;viewXform,<BR>&nbsp;AcArray&lt;AcGePoint3d&gt;&amp;&nbsp;snapPoints,<BR>&nbsp;AcArray&lt;int&gt;&amp;&nbsp;&nbsp;&nbsp;geomIdsForPts,<BR>&nbsp;AcArray&lt;AcGeCurve3d*&gt;&amp;&nbsp;snapCurves,<BR>&nbsp;AcArray&lt;int&gt;&amp;&nbsp;&nbsp;&nbsp;geomIdsForLines)<BR>{<BR>&nbsp;if(pickedObject-&gt;isKindOf(AcDbArc::desc()))<BR>&nbsp;{<BR>&nbsp;&nbsp;AcDbArc *pArc=AcDbArc::cast(pickedObject);<BR>&nbsp;&nbsp;AcGePoint3d pt;<BR>&nbsp;&nbsp;pArc-&gt;getStartPoint(pt);<BR>&nbsp;&nbsp;snapPoints.append(pt);<BR>&nbsp;&nbsp;pArc-&gt;getEndPoint(pt);<BR>&nbsp;&nbsp;snapPoints.append(pt);</P>
<P>&nbsp;&nbsp;pt=pArc-&gt;center();<BR>&nbsp;&nbsp;snapPoints.append(pt);<BR>&nbsp;&nbsp;//AcGeLine3d *pLine1=new AcGeLine3d(pt, pt+AcGeVector3d(1, 0, 0));<BR>&nbsp;&nbsp;//snapCurves.append(pLine1);<BR>&nbsp;&nbsp;//AcGeLine3d *pLine2=new AcGeLine3d(pt, pt+AcGeVector3d(0, 1, 0));<BR>&nbsp;&nbsp;//snapCurves.append(pLine2);<BR>&nbsp;&nbsp;//AcGeCircArc3d *pCircle=new AcGeCircArc3d(pt, AcGeVector3d(0, 0, 1), 1);<BR>&nbsp;&nbsp;//snapCurves.append(pCircle);</P>
<P>&nbsp;&nbsp;pArc-&gt;getClosestPointTo(pickPoint, pt);<BR>&nbsp;&nbsp;snapPoints.append(pt);</P>
<P>&nbsp;&nbsp;geomIdsForPts.append(pArc-&gt;id().asOldId());<BR>&nbsp;&nbsp;geomIdsForPts.append(pArc-&gt;id().asOldId());</P>
<P>&nbsp;&nbsp;return Acad::eOk;<BR>&nbsp;}<BR>&nbsp;return Acad::eOk;<BR>}</P>
<P>高手快来帮一把啊,这两个问题搞得我很郁闷.<BR></P>
页: [1]
查看完整版本: ARX自定义捕捉(AcDbCustomOsnapInfo)中的两个问题