几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   ObjectARX(C++) (http://www.dimcax.com/hust/forumdisplay.php?f=34)
-   -   【转帖】求救::大家帮我看看红色部分出什么错了 (http://www.dimcax.com/hust/showthread.php?t=7893)

yang686526 2009-04-18 05:31 PM

【转帖】求救::大家帮我看看红色部分出什么错了
 
求救::大家帮我看看红色部分出什么错了
求救::大家帮我看看红色部分出什么错了
以下是我自己编的代码. 其中的红色部分的函数出了什么错 老出来 not open for write的错误
求高手教我改正
#include "stdafx.h"
#include "stdarx.h"
#include "myline.h"
bool b_replace=false;
acgepoint3d get_startpoint,get_endpoint;
void del_replaceline(cmyline mylinex);
acgepoint3d judgement(cmyline cmyline1,cmyline cmyline2);
// this is command 'repline'
void zzh_hfutrepline()
{
// todo: implement the command
acdbdatabase *pcurrentdatabase;
pcurrentdatabase = acdbhostapplicationservices()->workingdatabase();

acdbblocktable *pbt;
pcurrentdatabase->getsymboltable(pbt, acdb::kforread);
acdbblocktablerecord *pbtr;
acdbblocktableiterator *piterator;
pbt->newiterator(piterator);
pbt->close();

acdbline *pline[20], *pline1 = null;
cmyline myline0[20]; //自己定义的直线类,用于存储各个直线的端点
int i=0, count=0;

for (piterator->start();!piterator->done();piterator->step())
{
acdbblocktablerecord *pbtr;
piterator->getrecord(pbtr,acdb::kforwrite,adesk::kfalse);

acdbblocktablerecorditerator *pirterator;
pbtr->newiterator(pirterator); //建立迭代器
pbtr->close();


//完成将直线的端点存储在cmyline中
while(!pirterator->done())
{
acdbentity *pent;
pirterator->getentity(pent,acdb::kforwrite); //打开实体,进行编辑
if (strcmp(pent->isa()->name(),"acdbline") == 0)//若是线形,则继续
{
pline[i]=acdbline::cast(pent);
pent->close();
myline0[i].startpt = pline[i]->startpoint();//将直线的两端点加以保存
myline0[i].endpt = pline[i]->endpoint();
pline[i]->close();
i++;
count++;
}
pirterator->step();
}
delete pirterator;

}
delete piterator;


for ( i=0; i<count; i++)
{
for (int j=i+1; j<count; j++)
{
judgement(myline0[i], myline0[j]);
if (b_replace==true)
{
del_replaceline(myline0[i]);
del_replaceline(myline0[j]);
pbt->getat(acdb_model_space, pbtr,acdb::kforwrite);
pbt->close();

acdbobjectid acdblineid;
pline1=new acdbline(get_startpoint,get_endpoint);//重画一条线代替重复的两条线

pbtr->appendacdbentity(acdblineid, pline1);
pbtr->close();

pline1->setcolorindex(1);
pline1->close();
}
}
}


for (i=0; i<count; i++)
{
pline[i]->close();
}

}
//实现比较两条线是否为重合
//判断最大距离的两点,并返回这两点。以便进行两线的合并。
//
acgepoint3d judgement(cmyline myline1,cmyline myline2)
{
double fslope1, fslope2;//斜率
double sx1, sy1, ex1, ey1;//比较时用到的第一条直线的两个端点坐标变量
double sx2, sy2, ex2, ey2;//第二条直线端点坐标变量

sx1 = myline1.startpt.x;
sy1 = myline1.startpt.y;
ex1 = myline1.endpt.x;
ey1 = myline1.endpt.y;

sx2 = myline2.startpt.x;
sy2 = myline2.startpt.y;
ex2 = myline2.endpt.x;
ey2 = myline2.endpt.y;

fslope1 = (ey1 - sy1) / (ex1 - sx1);
fslope2 = (ey2 - sy2) / (ex2 - sx2);

double max_distance, distance1, distance2, distance3, distance4;

distance1 = (sx1 - ex1) * (sx1 - ex1) + (sy1 - ey1) * (sy1 - ey1);//第一条直线两端点间的距离
distance2 = (sx2 - ex2) * (sx2 - ex2) + (sy2 - ey2) * (sy2 - ey2);//第二条直线两端点间的距离
distance3 = (sx1 - ex2) * (sx1 - ex2) + (sy1 - ey2) * (sy1 - ey2);//第一条直线起点于第二条直线终点间的距离
distance4 = (sx2 - ex1) * (sx2 - ex1) + (sy2 - ey1) * (sy2 - ey1);//第一条直线终点与第二条直线起点间的距离

//判断是否重合有三个条件
//一、是否斜率相等
//二、其中一条线的一端点是否在另一条直线的延长线上
//三、其中一条线的一端点的横坐标是否在另一条直线的两个端点的横坐标之间
if ((fslope1==fslope2)
&&((sy2==(sx2-sx1)*fslope1+sy1)||(ey2==(ex2-sx1)*fslope1+sy1))
&&((sx1<=sx2&&sx2<=ex1)||(sx1<=ex2&&ex2<=ex1)))
{
max_distance = distance1;
if (distance2>max_distance)
max_distance = distance2;
if (distance3>max_distance)
max_distance = distance3;
if (distance4>max_distance)
max_distance = distance4;

if (max_distance==distance1)
{
get_startpoint.x = sx1;
get_startpoint.y = sy1;
get_endpoint.x = ex1;
get_endpoint.y = ey1;

b_replace=true;
return get_endpoint,get_startpoint;
}

else if (max_distance==distance2)
{
get_startpoint.x = sx2;
get_startpoint.y = sy2;
get_endpoint.x = ex2;
get_endpoint.y = ey2;

b_replace=true;
return get_endpoint,get_startpoint;
}

else if (max_distance==distance3)
{
get_startpoint.x = sx1;
get_startpoint.y = sy1;
get_endpoint.x = ex2;
get_endpoint.y = ey2;

b_replace=true;
return get_endpoint,get_startpoint;
}

else if (max_distance==distance4)
{
get_startpoint.x = sx2;
get_startpoint.y = sy2;
get_endpoint.x = ex1;
get_endpoint.y = ey1;

b_replace=true;
return get_endpoint,get_startpoint;
}

else
{
ads_printf("\n error please restart the program !");

}
}

}
void del_replaceline(cmyline mylinex)
{
acdbdatabase *pcurrentdatabase;
pcurrentdatabase = acdbhostapplicationservices()->workingdatabase();

acdbblocktable *pbt;
pcurrentdatabase->getsymboltable(pbt, acdb::kforread);

acdbblocktableiterator *piterator;
pbt->newiterator(piterator);
pbt->close();
for (piterator->start();!piterator->done();piterator->step())
{
acdbblocktablerecord *pbtr;
piterator->getrecord(pbtr,acdb::kforwrite,adesk::kfalse);

acdbblocktablerecorditerator *pirterator;
pbtr->newiterator(pirterator); //建立迭代器
pbtr->close();

while(!pirterator->done())
{
acdbline *pline_del;
acdbentity *pent;
acgepoint3d del_startpt,del_endpt;
pirterator->getentity(pent,acdb::kforwrite); //打开实体,进行编辑
if (strcmp(pent->isa()->name(),"acdbline") == 0)//若是线形,则继续
{
pline_del=acdbline::cast(pent);
pent->close();
del_startpt=pline_del->startpoint();
del_endpt=pline_del->endpoint();

if ((mylinex.startpt.x==del_startpt.x)&&(mylinex.startpt.y==del_startpt.y)
&&(mylinex.endpt.x==del_endpt.x)&&(mylinex.endpt.y==del_endpt.y))
{
pbt->getat(acdb_model_space, pbtr,acdb::kforwrite);
pbt->close();
acdbobjectid acdblineid;
pline_del->erase();

pbtr->appendacdbentity(acdblineid, pline_del);
pbtr->close();
pline_del->close();
}

}
pirterator->step();
}
delete pirterator;

}
delete piterator;

}
问题已经解决 结贴


所有的时间均为北京时间。 现在的时间是 03:39 AM.