ElementIDMap is a template for classes which store a mapping from some "foreign" object ID to DGN Element Ids (64 bit unsigned integers). More...
#include <ElementIdMap.h>
Public Member Functions | |
ElementIdMap (_ForeignIdIO const &io) | |
T_AUInt64 | GetId (_ForeignId const &foreignId) |
Return elementId for supplied foreignId. More... | |
StatusInt | Store (DataExternalizer &sink) const |
Store map. More... | |
StatusInt | Load (DataInternalizer &source) |
Load map. More... | |
BeFileName | GetMapFileName (WStringCR baseName) |
StatusInt | Load (WStringCR baseFileName) |
Load map. More... | |
StatusInt | Store (WStringCR baseFileName) |
Store map. More... | |
ElementIDMap is a template for classes which store a mapping from some "foreign" object ID to DGN Element Ids (64 bit unsigned integers).
By utilizing this mapping an application which generates DGN elements from its objects with its own ID system can insure that the elements always recieve consistent ElementIDs. This is important as element IDs are used by MicrStation to store named groups, item sets, clash detection sets, associative dimension targets etc.
In order for the element map to be useful, it must be persistent. The default implementation stores and reads the map to a file with the same name but with the extension ".dgnIdMap".... a Rhino file "test.3dm" would use a mapping file, "test.3dm.dgnIdMap".
Example file creation code: StatusInt LoadFile (...) { m_fileObj->SetHighestID (0x80000000); // Insure that all non-mapped IDs are above mapped/. m_idMap.Load (GetFileName()); // Load ID Map. for (...) { ObjectID foreignObjectId. // From current object. EditElemHandle editElemHandle; ElementId elementId = m_idMap->GetId (foreignObjectId); ... GenerateElement (editElemHandle, object, elementId); TxnElementAddOptions txnOptions (false // Do not call Asynchs. false, // Do not save in ID true); // Override IDs (with those from map). ITxnManager::GetCurrentTxn().AddElement (editElemHandle, txnOptions); } m_idMap->Store (GetFileName()); // Save ID map. }
Note: that in the example we set the initially set the highest element ID to reserve low IDs for those in the map. All elements generated without the explicitly mapped IDs will be sequentially numbered beginning with this value (0x80000000).
Example ElementIdMap definition. The code below demonstrates the creation of a class for a map from a foreign ID: "ON_UUID" with a compare function, "ON_UuidCompare". as this is a fixed size key, the default IO class, "FixedSizeForeignIdIO" is used. struct ON_UuidLess { bool operator () (ON_UUID const& id1, ON_UUID const& id2) { return ON_UuidCompare (&id1, &id2) < 0; } }; typedef ElementIdMap <ON_UUID, ON_UuidLess> T_UuidToElementIdMap; struct ON_UuidToElementIdMap : T_UuidToElementIdMap { FixedSizeForeignIdIO<ON_UUID> idIo; ON_UuidToElementIdMap () : T_UuidToElementIdMap (idIo) { } };
+===============+===============+===============+===============+===============+======*/
ElementIdMap | ( | _ForeignIdIO const & | io | ) |
T_AUInt64 GetId | ( | _ForeignId const & | foreignId | ) |
Return elementId for supplied foreignId.
If the foreignId is not currently mapped then one is generated by incrementing m_highestId.
[in] | foreignId | Foreign object Id (templated). |
BeFileName GetMapFileName | ( | WStringCR | baseName | ) |
StatusInt Load | ( | DataInternalizer & | source | ) |
StatusInt Store | ( | DataExternalizer & | sink | ) | const |
Store map.
[in] | baseFileName | file name |
References BeAssert, Bentley::ERROR, fwrite, NULL, and Bentley::SUCCESS.