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