coldmoon 发表于 2007-5-1 16:04:00

求救::大家帮我看看红色部分出什么错了

<p>以下是我自己编的代码. 其中的红色部分的函数出了什么错 老出来 not open for write的错误</p><p>求高手教我改正</p><p><br/>#include "StdAfx.h"<br/>#include "StdArx.h"</p><p>#include "myline.h"</p><p></p><p>bool b_Replace=FALSE;<br/>AcGePoint3d get_startpoint,get_endpoint;</p><p>void Del_Replaceline(Cmyline mylinex);<br/>AcGePoint3d Judgement(Cmyline Cmyline1,Cmyline Cmyline2);</p><p>// This is command 'REPLINE'<br/>void zzh_hfutrepline()<br/>{<br/>&nbsp;// TODO: Implement the command<br/>&nbsp;AcDbDatabase *pCurrentDatabase;<br/>&nbsp;pCurrentDatabase = acdbHostApplicationServices()-&gt;workingDatabase();<br/>&nbsp;<br/>&nbsp;&nbsp;&nbsp; AcDbBlockTable *pBT;<br/>&nbsp;pCurrentDatabase-&gt;getSymbolTable(pBT, AcDb::kForRead);</p><p>&nbsp;AcDbBlockTableRecord *pBTR;<br/>&nbsp;AcDbBlockTableIterator *pIterator;<br/>&nbsp;pBT-&gt;newIterator(pIterator);<br/>&nbsp;pBT-&gt;close();<br/>&nbsp;<br/>&nbsp;AcDbLine *pLine, *pLine1 = NULL; <br/>&nbsp;Cmyline myline0;&nbsp; //自己定义的直线类,用于存储各个直线的端点<br/>&nbsp;int i=0, Count=0;<br/>&nbsp;<br/>&nbsp;for (pIterator-&gt;start();!pIterator-&gt;done();pIterator-&gt;step())<br/>&nbsp;{<br/>&nbsp;&nbsp;AcDbBlockTableRecord *pBTR;<br/>&nbsp;&nbsp;pIterator-&gt;getRecord(pBTR,AcDb::kForWrite,Adesk::kFalse);<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;AcDbBlockTableRecordIterator *pIrterator;<br/>&nbsp;&nbsp;pBTR-&gt;newIterator(pIrterator);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //建立迭代器&nbsp;&nbsp;<br/>&nbsp;&nbsp;pBTR-&gt;close();<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //完成将直线的端点存储在Cmyline中<br/>&nbsp;&nbsp;while(!pIrterator-&gt;done())<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;AcDbEntity *pEnt;<br/>&nbsp;&nbsp;&nbsp;pIrterator-&gt;getEntity(pEnt,AcDb::kForWrite); //打开实体,进行编辑<br/>&nbsp;&nbsp;&nbsp;if (strcmp(pEnt-&gt;isA()-&gt;name(),"AcDbLine") == 0)//若是线形,则继续<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;pLine=AcDbLine::cast(pEnt);<br/>&nbsp;&nbsp;&nbsp;&nbsp;pEnt-&gt;close();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;myline0.startpt = pLine-&gt;startPoint();//将直线的两端点加以保存<br/>&nbsp;&nbsp;&nbsp;&nbsp;myline0.endpt = pLine-&gt;endPoint();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;pLine-&gt;close();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;i++;<br/>&nbsp;&nbsp;&nbsp;&nbsp;Count++;<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;pIrterator-&gt;step();<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;delete pIrterator;<br/>&nbsp;<br/>&nbsp;}<br/>&nbsp;delete pIterator;<br/>&nbsp;&nbsp;<br/>&nbsp;<br/>&nbsp;for ( i=0; i&lt;Count; i++)<br/>&nbsp;{<br/>&nbsp;&nbsp;for (int j=i+1; j&lt;Count; j++)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;Judgement(myline0, myline0);</p><p>&nbsp;&nbsp;&nbsp;if (b_Replace==TRUE)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#f76809">Del_Replaceline(myline0);<br/>&nbsp;&nbsp;&nbsp;&nbsp;Del_Replaceline(myline0);</font></p><p>&nbsp;&nbsp;&nbsp;&nbsp;pBT-&gt;getAt(ACDB_MODEL_SPACE, pBTR,AcDb::kForWrite);<br/>&nbsp;&nbsp;&nbsp;&nbsp;pBT-&gt;close();<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;AcDbObjectId acdbLineId;<br/>&nbsp;&nbsp;&nbsp;&nbsp;pLine1=new AcDbLine(get_startpoint,get_endpoint);//重画一条线代替重复的两条线<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;pBTR-&gt;appendAcDbEntity(acdbLineId, pLine1);<br/>&nbsp;&nbsp;&nbsp;&nbsp;pBTR-&gt;close();<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;pLine1-&gt;setColorIndex(1);<br/>&nbsp;&nbsp;&nbsp;&nbsp;pLine1-&gt;close();<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;}<br/>&nbsp;}</p><p>&nbsp;<br/>&nbsp;<br/>&nbsp;for (i=0; i&lt;Count; i++)<br/>&nbsp;{<br/>&nbsp;&nbsp;pLine-&gt;close();<br/>&nbsp;}<br/>&nbsp;&nbsp; <br/>}</p><p><br/>//实现比较两条线是否为重合<br/>//判断最大距离的两点,并返回这两点。以便进行两线的合并。<br/>// <br/>AcGePoint3d Judgement(Cmyline myline1,Cmyline myline2)<br/>{<br/>&nbsp;double fslope1, fslope2;//斜率<br/>&nbsp;double Sx1, Sy1, Ex1, Ey1;//比较时用到的第一条直线的两个端点坐标变量<br/>&nbsp;double Sx2, Sy2, Ex2, Ey2;//第二条直线端点坐标变量<br/>&nbsp;<br/>&nbsp;Sx1 = myline1.startpt.x;<br/>&nbsp;Sy1 = myline1.startpt.y;<br/>&nbsp;Ex1 = myline1.endpt.x;<br/>&nbsp;Ey1 = myline1.endpt.y;<br/>&nbsp;<br/>&nbsp;Sx2 = myline2.startpt.x;<br/>&nbsp;Sy2 = myline2.startpt.y;<br/>&nbsp;Ex2 = myline2.endpt.x;<br/>&nbsp;Ey2 = myline2.endpt.y;<br/>&nbsp;<br/>&nbsp;fslope1 = (Ey1 - Sy1) / (Ex1 - Sx1);<br/>&nbsp;fslope2 = (Ey2 - Sy2) / (Ex2 - Sx2);<br/>&nbsp;<br/>&nbsp;double Max_distance, distance1, distance2, distance3, distance4;<br/>&nbsp;<br/>&nbsp;distance1 = (Sx1 - Ex1) * (Sx1 - Ex1) + (Sy1 - Ey1) * (Sy1 - Ey1);//第一条直线两端点间的距离<br/>&nbsp;distance2 = (Sx2 - Ex2) * (Sx2 - Ex2) + (Sy2 - Ey2) * (Sy2 - Ey2);//第二条直线两端点间的距离<br/>&nbsp;distance3 = (Sx1 - Ex2) * (Sx1 - Ex2) + (Sy1 - Ey2) * (Sy1 - Ey2);//第一条直线起点于第二条直线终点间的距离<br/>&nbsp;distance4 = (Sx2 - Ex1) * (Sx2 - Ex1) + (Sy2 - Ey1) * (Sy2 - Ey1);//第一条直线终点与第二条直线起点间的距离<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;//判断是否重合有三个条件<br/>&nbsp;//一、是否斜率相等<br/>&nbsp;//二、其中一条线的一端点是否在另一条直线的延长线上<br/>&nbsp;//三、其中一条线的一端点的横坐标是否在另一条直线的两个端点的横坐标之间<br/>&nbsp;if ((fslope1==fslope2)<br/>&nbsp;&nbsp;&amp;&amp;((Sy2==(Sx2-Sx1)*fslope1+Sy1)||(Ey2==(Ex2-Sx1)*fslope1+Sy1))<br/>&nbsp;&nbsp;&amp;&amp;((Sx1&lt;=Sx2&amp;&amp;Sx2&lt;=Ex1)||(Sx1&lt;=Ex2&amp;&amp;Ex2&lt;=Ex1)))<br/>&nbsp;{<br/>&nbsp;&nbsp;Max_distance = distance1;<br/>&nbsp;&nbsp;if (distance2&gt;Max_distance)<br/>&nbsp;&nbsp;&nbsp;Max_distance = distance2;<br/>&nbsp;&nbsp;if (distance3&gt;Max_distance)<br/>&nbsp;&nbsp;&nbsp;Max_distance = distance3;<br/>&nbsp;&nbsp;if (distance4&gt;Max_distance)<br/>&nbsp;&nbsp;&nbsp;Max_distance = distance4;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;if (Max_distance==distance1)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;get_startpoint.x = Sx1;<br/>&nbsp;&nbsp;&nbsp;get_startpoint.y = Sy1;<br/>&nbsp;&nbsp;&nbsp;get_endpoint.x = Ex1;<br/>&nbsp;&nbsp;&nbsp;get_endpoint.y = Ey1;<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;b_Replace=TRUE;<br/>&nbsp;&nbsp;&nbsp;return get_endpoint,get_startpoint;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;else if (Max_distance==distance2)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;get_startpoint.x = Sx2;<br/>&nbsp;&nbsp;&nbsp;get_startpoint.y = Sy2;<br/>&nbsp;&nbsp;&nbsp;get_endpoint.x = Ex2;<br/>&nbsp;&nbsp;&nbsp;get_endpoint.y = Ey2;<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;b_Replace=TRUE;<br/>&nbsp;&nbsp;&nbsp;return get_endpoint,get_startpoint;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;else if (Max_distance==distance3)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;get_startpoint.x = Sx1;<br/>&nbsp;&nbsp;&nbsp;get_startpoint.y = Sy1;<br/>&nbsp;&nbsp;&nbsp;get_endpoint.x = Ex2;<br/>&nbsp;&nbsp;&nbsp;get_endpoint.y = Ey2;<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;b_Replace=TRUE;<br/>&nbsp;&nbsp;&nbsp;return get_endpoint,get_startpoint;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;else if (Max_distance==distance4)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;get_startpoint.x = Sx2;<br/>&nbsp;&nbsp;&nbsp;get_startpoint.y = Sy2;<br/>&nbsp;&nbsp;&nbsp;get_endpoint.x = Ex1;<br/>&nbsp;&nbsp;&nbsp;get_endpoint.y = Ey1;<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;b_Replace=TRUE;<br/>&nbsp;&nbsp;&nbsp;return get_endpoint,get_startpoint;<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;else<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;ads_printf("\n error please restart the program !");<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;}<br/>&nbsp;}<br/>&nbsp;&nbsp;<br/>}</p><p></p><p><font color="#f73809">void Del_Replaceline(Cmyline mylinex)<br/>{<br/>&nbsp;AcDbDatabase *pCurrentDatabase;<br/>&nbsp;pCurrentDatabase = acdbHostApplicationServices()-&gt;workingDatabase();<br/>&nbsp;<br/>&nbsp;&nbsp;&nbsp; AcDbBlockTable *pBT;<br/>&nbsp;pCurrentDatabase-&gt;getSymbolTable(pBT, AcDb::kForRead);<br/>&nbsp;</font></p><p><font color="#f73809">&nbsp;AcDbBlockTableIterator *pIterator;<br/>&nbsp;pBT-&gt;newIterator(pIterator);<br/>&nbsp;pBT-&gt;close();<br/>&nbsp;for (pIterator-&gt;start();!pIterator-&gt;done();pIterator-&gt;step())<br/>&nbsp;{<br/>&nbsp;&nbsp;AcDbBlockTableRecord *pBTR;<br/>&nbsp;&nbsp;pIterator-&gt;getRecord(pBTR,AcDb::kForWrite,Adesk::kFalse);<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;AcDbBlockTableRecordIterator *pIrterator;<br/>&nbsp;&nbsp;pBTR-&gt;newIterator(pIrterator);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //建立迭代器&nbsp;&nbsp;<br/>&nbsp;&nbsp;pBTR-&gt;close();<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;while(!pIrterator-&gt;done())<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;AcDbLine *pline_Del;<br/>&nbsp;&nbsp;&nbsp;AcDbEntity *pEnt;<br/>&nbsp;&nbsp;&nbsp;AcGePoint3d Del_Startpt,Del_Endpt;<br/>&nbsp;&nbsp;&nbsp;pIrterator-&gt;getEntity(pEnt,AcDb::kForWrite); //打开实体,进行编辑<br/>&nbsp;&nbsp;&nbsp;if (strcmp(pEnt-&gt;isA()-&gt;name(),"AcDbLine") == 0)//若是线形,则继续<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;pline_Del=AcDbLine::cast(pEnt);<br/>&nbsp;&nbsp;&nbsp;&nbsp;pEnt-&gt;close();</font></p><p><font color="#f73809">&nbsp;&nbsp;&nbsp;&nbsp;Del_Startpt=pline_Del-&gt;startPoint();<br/>&nbsp;&nbsp;&nbsp;&nbsp;Del_Endpt=pline_Del-&gt;endPoint();<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;if ((mylinex.startpt.x==Del_Startpt.x)&amp;&amp;(mylinex.startpt.y==Del_Startpt.y)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&amp;(mylinex.endpt.x==Del_Endpt.x)&amp;&amp;(mylinex.endpt.y==Del_Endpt.y))<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pBT-&gt;getAt(ACDB_MODEL_SPACE, pBTR,AcDb::kForWrite);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBT-&gt;close();</font></p><p><font color="#f73809">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AcDbObjectId acdbLineId;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pline_Del-&gt;erase();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBTR-&gt;appendAcDbEntity(acdbLineId, pline_Del);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;pBTR-&gt;close();</font></p><p><font color="#f73809">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pline_Del-&gt;close();<br/>&nbsp;&nbsp;&nbsp;&nbsp;}</font></p><p><font color="#f73809">&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;pIrterator-&gt;step();<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;delete pIrterator;&nbsp;<br/>&nbsp;&nbsp;<br/>&nbsp;}<br/>&nbsp;delete pIterator;<br/>&nbsp;&nbsp;<br/>}</font><br/></p>

coldmoon 发表于 2007-5-2 12:55:00

<p>问题已经解决 结贴</p>
页: [1]
查看完整版本: 求救::大家帮我看看红色部分出什么错了