几何尺寸与公差论坛------致力于产品几何量公差标准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)
-   DirectDWG (http://www.dimcax.com/hust/forumdisplay.php?f=89)
-   -   【转帖】problems with entity transformation (http://www.dimcax.com/hust/showthread.php?t=18222)

yang686526 2009-05-06 11:53 PM

【转帖】problems with entity transformation
 
problems with entity transformation
problems with entity transformation
hello, i'm having problems with tranformations. i loop through modelspace for blockrefs and for each blockref i want to dump all of its block's entity data. the problem is that the resulting polylines have invalid points for their vertices and i don't know why. so it would be great if someone could analyze my code here to see if something is wrong. i have an example drawing to show that my code doesn't work and i can send it if nothing is terribly wrong with this code. by the way 'odamfcapp' draws my problem drawing correctly so i really think that my code is the problem!
here is the code :
------------------
void dwgdumpblocks()
{
oddbblocktablerecordptr pblockms = pdb->getmodelspaceid().safeopenobject(oddb::kforwrite) ;
oddbobjectiteratorptr pentiterms = pblockms->newiterator();
//loop the modelspace for blockrefs
for(pentiterms->start(); !pentiterms->done(); pentiterms->step())
{
oddbentityptr pentms = pentiterms->objectid().safeopenobject(oddb::kforwrite);
if(pentms->iskindof(oddbblockreference::desc()))
{
oddbblockreferenceptr blkref = pentms;
oddbblocktablerecordptr pblock = blkref->blocktablerecord().safeopenobject(oddb::kforwrite );
odgematrix3d matr = blkref->blocktransform(); //read the transform. matr.
//dump data
split_and_dump_blkrefs(pblock,matr);
}
}
void split_and_dump_blkrefs(oddbblocktablerecordptr pblock, odgematrix3d blk_matr)
{
oddbobjectiteratorptr pentiter = pblock->newiterator();
for(pentiter->start(); !pentiter->done(); pentiter->step())
{
oddbentityptr pent = entiter->objectid().safeopenobject(oddb::kforwrite);
oddbentityptr ptrent;
//i know that this next code mail fail if used non-uniform scaling
if(pent->gettransformedcopy(blk_matr,ptrent) != eok)
continue;
if(ptrent->iskindof(oddbpolyline::descr())
{
oddbpolylineptr ppoly = ptrent;
for(unsigned int i=0; i<ppoly->numverts(); i++)
{
odgepoint3d pt;
ppoly->getpointat(i,pt);
//points here are not correct
printf("x:%.1f, %.1f\n",pt.x,pt.y);
}
}
}
}
i don't know if the gettransformedcopy() call fails or most propably i'm doing something wrong here. autocad says that vertice coordinate are different than my code shows. i'm using v.1.12 library.
-juhani
1. as you correctly noticed gettransformedcopy() for oddbpolyline do not work for non-uniform scale.
2. your code does not take into account block's base point (if block's base point is different from (0,0,0) you'll get offset points.
3. autocad shows coordinates in current ucs (user coordinate system) which may be different from wcs (world coordinate system).
sergey slezkin
still having problems...
thanks for your reply to my question, sergey.
how should i take into account the origin of the block in my code. when i get the matrix with call
odgematrix3d matr = blkref->blocktransform(); i can see that the matrix entry points have the correct coordinates of the block's origin but when i call the later gettransformedcopy() for a polyline entity the resulting points are wrong. i'm sorry that i don't understand but should i make an other transformation with the block origin or what? anyway how can get the ucs coordinates if that is my problem?


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