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

yang686526 2009-05-06 04:28 PM

【转帖】iterating modelspace entities
 
iterating modelspace entities
iterating modelspace entities
hi
i am just beginning to learn my way through the dwgdirect interface. i have three questions.
1. what are lightweight polylines stored as in the oddbdatabase?
2. how do i ensure it doesn't convert any polylines to lightweight when it loads the drawing?
3. is it possible to put this code fragment into a switch statement? i don't mind it all. i basically need to know what type of entity it is so that i can process it accordingly. just ineterested if it could be done.
here is the code and thanks in advance.
code:
void cdwgdirectdlg::readentities(oddbobjectid id)
{
oddbblocktablerecordptr pblock = id.safeopenobject(oddb::kforread);
oddbobjectiteratorptr pentiter;
// iterate modelspace entities
for(pentiter = pblock->newiterator(); !pentiter->done(); pentiter->step())
{
// get the entity
oddbentityptr pent = pentiter->entity(oddb::kforread);
// what type of entity is it?
if(pent->iskindof(oddb3dpolyline::desc()))
{
// 3d polyline
oddb3dpolylineptr pentpoly3d = pent;
// process object
}
else if(pent->iskindof(oddb2dpolyline::desc()))
{
// 2d polyline
oddb2dpolylineptr pentpoly2d = pent;
// process object
}
else if(pent->iskindof(oddbline::desc()))
{
// line
oddblineptr pentline = pent;
// process object
}
else if(pent->iskindof(oddbblockreference::desc()))
{
// block (insert)
oddbblockreferenceptr pentblock = pent;
// process object
}
else if(pent->iskindof(oddbtext::desc()))
{
// text
oddbtextptr penttext = pent;
// process object
}
else if(pent->iskindof(oddbpoint::desc()))
{
// point
oddbpointptr pentpoint = pent;
// process object
}
else
{
// object not required
}
}
}
andrew
1. lightweight polylines are represented by oddbpolyline class.
2. plinetype variable is responsible for converting polylines to lightweight polylines:
oddbhostappservises::getplinetype()
oddbhostappservices::setplinetype()
3. switch can't be used in this case. but instead of using "if-else if.." another method is possible (more efficient) - protocol extensions. see readex sample.
sergey slezkin
i think i will stay with the if/else/if ladder if it is an appropriate way of coding.
andrew
quote:
originally posted by sergey slezkin
2. plinetype variable is responsible for converting polylines to lightweight polylines:
oddbhostappservises::getplinetype()
oddbhostappservices::setplinetype()
i can't find these methods in the help file anywhere.
andrew
help file (as many other things in this world) is far from ideal.
look into oddbhostappservices.h (#include "sysvardefs.h") and into sysvardefs.h
sergey slezkin
i was seraching for getplinetype. i didn't realise that it was some different code with get##name or whatever.
i understand about not all things being perfect, but if something is not documented, one doesn't know it is there.
thanks for clarification.
andrew
quote:
originally posted by sergey slezkin
3. switch can't be used in this case. but instead of using "if-else if.." another method is possible (more efficient) - protocol extensions. see readex sample.
what happens if you don't cater for a object in the database?
andrew
sorry, but i don't understand the question.
sergey slezkin
sorry for confusion. you create dispatch classes for line, circle and text. and in code you call the disptach method.
what happens if you get a "point" which you don't have a dispatch class for?
make sense now?
andrew
in odreadex sample a dumper interface is added to oddbentity and some oddbentity's inheritants: line, circle, text.
if a line is quried for dumper interface - it's own dumper is returned. if a point is quried for dumper - oddbentity's dumper is returned.
if no dumper interface was added to oddbentity queryx will return null, assignment operator
dumperptr = ppointptr;
will throw exception.
protocol extension is similar to c++ virtual functions. adding an interface to the base class can be used to process "default" case of "switch" statement.
sergey slezkin


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