几何尺寸与公差论坛------致力于产品几何量公差标准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)
-   -   【转帖】referenced entities (http://www.dimcax.com/hust/showthread.php?t=18389)

yang686526 2009-05-07 12:46 PM

【转帖】referenced entities
 
referenced entities
referenced entities
hello,
i am completely new to opendesignalliance and not a specialist of dxf/dwg data format.
is there is a way to reference an entity and to give it a transformation matrix to have several instance of the same object?
if yes, how can i access to this information with dwgdirect from a oddbentity entity of from the oddbobjectiteratorptr?
thank you a lot in advance for your answer.
guilhem
an entity (or a set of entities) can be put into a block (oddbblocktablerecord). the reference to block (oddbblockreference) can be inserted several times with different transformations representing multiple instances of geometry contained in block.
sergey slezkin
hello sergey,
thank you for your help. in fact i already have the oddbblockreferenceptr,
but i cannot find the way to know it is a reference to a source block...
i am using the code referred in:
in order to get the geometry of each block.
so, i have the simplified code, where the services and the vectorizer are
declared and initialized elsewhere:
code:
void blocktablerecord (oddbblocktablerecordptr btr,
odstaticrxobject<vectorizer> * vectorizer) {
/* iterate on each entity of the block */
for (oddbobjectiteratorptr i = btr->newiterator(); i->done() == false ; i->step()) {
/* get the dwg entity and its owner layer */
oddbentityptr dwg_entity = i->objectid().safeopenobject();
if (dwg_entity->iskindof (odgidrawable::desc())) {
/* draw the dwg entity */
try {
vectorizer->draw (dwg_entity);
}
catch (...) {
log_error ("error when processing layer [%ls]\n", dwg_entity->layer());
}
}
/* if the entity is a block reference, draw its sub blocks */
if (dwg_entity->isa() == oddbblockreference::desc()) {
/* process the children blocks */
this->blocktablerecord (((oddbblockreferenceptr) dwg_entity)
->blocktablerecord().safeopenobject(),
vectorizer);
}
}
}
code:
void openandprocessfile (char * filename) {
oddbdatabaseptr pdb = services.readfile (filename, false, false, oda::ksharedenyno);
if (! pdb.isnull()) {
/* create the rendering context and attach the database */
odstaticrxobject<odgicontextfordbdatabase> context;
context.setdatabase (pdb);
/* get the block table */
oddbblocktableptr table = pdb->getblocktableid().safeopenobject();
/* count the number of blocks */
oddbsymboltableiteratorptr i;
for (i = table->newiterator(); i->done() == false; i->step()) {
/* get the record */
oddbblocktablerecordptr record = i->getrecord();
/* process the record */
processer.blocktablerecord (record, & vectorizer);
}
}
}
i would like to find the way to know that the block is a reference
rather than a true block... i need also to know the source block
in order to make a reference to it with a transformation matrix...
thank you again for your help,
best regards
guilhem
i'm not sure what your task is. if you want to get geometry probably the good place to start from could be odvectorizeex sample.
blocktablerecords are containers holding entities. they are of 2 types: layout blocks (model and paper spaces). each layout has it's block holding entities of the layout. these (layout) blocks are not referenced by any block insertion entity (blockreference).
the blocks of other type (non-layout) can be referenced by blockreference entities storing transformation applied to block contents.
blockreferences can be inserted into layout blocks making referenced blocks visible in layout.
the process can be recursive: layout besides other entities may contain blockreference to some non-layout block which contains references to other blocks.
in order to get geometry of a layout (say model space) you need to process (recurcively because of block reference entities) the contents of the layout block. not the contents of all blocks in table.
sergey slezkin
sergey,
is the odvectorizeex sample allows to get the structure of the drawing in the dwg file (layers and internal blocks)? i have (quickly) test it and it seems that i got the whole geometry without the logical structure...
the sample from where i got my sources seems to be much more simpler than the odvectorizeex sample... but i am absolutely not sure that it meets my requirements...
many thanks for your help
guilhem


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