几何尺寸与公差论坛------致力于产品几何量公差标准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)
-   -   【转帖】objectarx&dummies教程(七)——containers (http://www.dimcax.com/hust/showthread.php?t=6312)

yang686526 2009-04-16 10:35 AM

【转帖】objectarx&dummies教程(七)——containers
 
objectarx&dummies教程(七)——containers
objectarx&dummies教程(七)——containers
class 7 - containers
hello,
on this class i will present the concepts and features of objectarx container objects. we have talked a little bit about them before but now we will go into further details.
introduction
the container object purpose is to store and manage objects of the same type or class. there are two types of containers: symbol tables and dictionaries. each type of container has some specific functionalities that were designed to allow easy and efficient access methods.
symbol tables
this type of container is designed to store the so called records. each symbol table object store its records using an unique entry name. through this entry you can obtain the record pointer and read or write information. the container may also receive new entries or even has entries removed (in case they are not used by other objects).
to walk through an object container entries you will need to use a proper iterator which will allow you to get entries and access its objects. autocad has some symbol tables to store layers, linetypes, text styles and other objects. as these containers work almost the same way, there is a common base class for each of symbol tables, its records and the proper iterators.
the symbol table class tree is as follows:
acdbsymboltable
acdbabstractviewtable
acdbviewporttable
acdbviewtable
acdbblocktable
acdbdimstyletable
acdblayertable
acdblinetypetable
acdbregapptable
acdbtextstyletable
acdbucstable
acdbsymboltablerecord
acdbabstractviewtablerecord
acdbviewporttablerecord
acdbviewtablerecord
acdbblocktablerecord
acdbdimstyletablerecord
acdblayertablerecord
acdblinetypetablerecord
acdbregapptable
acdbtextstyletable
acdbucstable
acdbsymboltableiterator
acdbabstractviewtableiterator
acdbviewporttableiterator
acdbviewtableiterator
acdbblocktableiterator
acdbdimstyletableiterator
acdblayertableiterator
acdblinetypetableiterator
acdbregapptableiterator
acdbtextstyletableiterator
acdbucstableiterator
so, to create a layer, for instance, you will need to:
open current database;
open acdblayertable (for write);
create an acdblayertablerecord (using new operator);
configure the acdblayertablerecord;
add it to acdblayertable which is its proper container;
close the record;
close the container.
void createlayer() {
acdblayertable *playertbl = null;
acdbhostapplicationservices()->workingdatabase()
->getsymboltable(playertbl, acdb::kforwrite);
if (!playertbl->has("mylayer")) {
acdblayertablerecord *playertblrcd = new acdblayertablerecord;
playertblrcd->setname("mylayer");
accmcolor color;
color.setcolorindex(1); // red
playertblrcd->setcolor(color);
playertbl->add(playertblrcd);
playertblrcd->close();
} else acutprintf("\nlayer already exists");
playertbl->close();
}
to list all existing layers:
open current database;
open acdblayertable (for read);
create an acdblayertableiterator;
perform a loop through container entries;
get the key name for each entry;
close the container.
void iteratelayers() {
acdblayertable* playertbl = null;
acdbhostapplicationservices()->workingdatabase()
->getsymboltable(playertbl, acdb::kforread);
acdblayertableiterator* playeriterator;
playertbl->newiterator(playeriterator);
acdblayertablerecord* playertblrcd;
char *plname;
for (; !playeriterator->done(); playeriterator->step()) {
playeriterator->getrecord(playertblrcd, acdb::kforread);
playertblrcd->getname(plname);
playertblrcd->close();
acutprintf("\nlayer name: %s",plname);
acutdelstring(plname);
}
delete playeriterator;
playertbl->close();
}
dictionaries
this type of container is designed to store generic acdbobject derived class objects. this container is very useful because we can also store our custom objects inside it. the dictionary structure is much like a tree structure where we have nodes and entries. inside the same node, entries can not repeat its name because they need to be unique inside the same level. these are the so called key entries and each key entry will map to an acdbobject pointer which can be retrieved directly or through an interator (acdbdictionaryiterator).
to store an object we need to create an entry using the setat() method passing also the object pointer which we already have instantiated with the new operator. after add this object we need to close() it. acdbdictionary container will return the given acdbobjectid for each entry.
this container is also used by some autocad features like groups and multiline styles. we will cover more about dictionaries on the custom objects chapter.


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