高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】losing objects when writing dwg file
losing objects when writing dwg file
losing objects when writing dwg file
using dwgdirect 2.5.2, windows xp, visual studio 2005.
i am writing a program that performs coordinate system transformations on the coordinates in dwg files. the basic logic for transforming the objects in the file is:
code:
// load the file
// blkiter is a block table iterator
// open the block and iterate through its contained entities
oddbblocktablerecordptr pblock = blkiter->getrecordid().safeopenobject();
oddbobjectiteratorptr pentiter;
for (pentiter = pblock->newiterator(); !pentiter->done(); pentiter->step())
{
oddbentityptr pentity = pentiter->entity(oddb::kforwrite);
// retrieve the protocol extension and transform the entity
odsmartptr<bautocadloader> pentloader = pentity;
pentloader->transform(pentity, pacadtransform);
}
// write the file.in most cases, this works fine, but i have run into a file where i get a very strange result (the file is attached). when i write the output file, the model space block only contains the first object from the input file. the new coordinates in the object are correct, but there is only one object.
the attached file appears to be an autocad 2000 file. if i load it into autocad 2004 and save it as an autocad 2004 file, then the transformation works fine (i.e., the output contains all objects). if i save it as an autocad 2000 file, then the transformation fails (output contains 1 object).
i have tried having my program write the file as both autocad 2004 and autocad 2000, and the resulting file still has only 1 model space object.
this file can be loaded and displayed in the odamfcapp program, and we can load it into our own viewer program. there appears to be a problem with modifying the file contents in place, then writing the file out.
does anyone have any insight into this issue?
thanks.
bob
can it be reproduced by just calling transformby() with some matrix, w/o your protocol extension?
vladimir
i'm using coordinate conversion libraries that convert points based on coordinate system definitions. i don't have a good way to get a matrix that represents that transformation.
also, i tried re-ran my test using dwgdirect 2.6.1, and the problem is still there.
i ran the following test on your file:
code:
oddbblocktableptr bt = pdbcmdctx->database()->getblocktableid().safeopenobject();
for (oddbsymboltableiteratorptr i1 = bt->newiterator(); !i1->done(); i1->step())
{
oddbblocktablerecordptr pblock = i1->getrecordid().safeopenobject();
oddbobjectiteratorptr pentiter;
for (pentiter = pblock->newiterator(); !pentiter->done(); pentiter->step())
{
oddbentityptr pentity = pentiter->entity(oddb::kforwrite);
pentity->transformby(odgematrix3d::translation(odgevector3d(1.0, 0.0, 0.0)));
}
}after the test, all the entities are present in saved drawing. there is something in your transformation code.
try to close entity smart pointer and reopen it, to make sure it was not e.g. erased during transformation.
vladimir
the file contains many oddbpoint objects. the protocol extension for oddbpoints looks like this:
code:
void transform(oddbentity* pentity, const bautocadcoordtransformptr& pct) const
{
oddbpointptr pdwgpoint = pentity;
// perform the coordinate transformation
pdwgpoint->setposition(pct->transformacadpoint(pdwgpoint->position()));
}and the transformacadpoint method looks like this:
code:
odgepoint3d transformacadpoint(const odgepoint3d& acadpt)
{
bpoint ptin(acadpt.x, acadpt.y, acadpt.z);
bpoint ptout = convertsourcetotarget(ptin);
return odgepoint3d(ptout.x, ptout.y, ptout.z);
}it is pretty simple, and i don't think the entity pointer is being erased. there are no exceptions being thrown. the strange thing is that my code works every file i've tried it with except for the one that i attached, which leads me to believe that there is something odd about that file. i've tried auditing it in autocad, but no errors were reported, and if i save the file from autocad in autocad 2004 format, it gets handled properly.
one other thing i forgot to mention is that i am using a page controller. after each group of 200 objects, i make a call to oddbpageobjects(). i have traced through those calls, and they seem to be ok. the write() calls seem to be returning 'true'. my page controller implementation is very similar to the sample provided in the toolkit.
actually, in current version, paging is not very useful, because, while saving, all the objects willl be loaded back, and if paging is called while saving - invalid file may be produced. (there was a bug found recently, that breaks paging while saving)
try to turn off paging - will your test be working correctly then?
vladimir
i turned off paging and that seemed to fix the problem.
when do you expect the paging bug to be fixed?
the bug (5237) is fixed. the fix is available for fonding members from svn. binary maintenance release is planned for autumn.
the bug effects saving r13,14,15 dwg files.
sergey slezkin
|