| http://www.coin3d.org/ http://www.kongsberg.com/kogt/

Public Member Functions | Static Public Member Functions | List of all members
dimeModel Class Reference

The dimeModel class organizes a model. More...

`#include <dime/Model.h>`

## Public Member Functions

| dimeModel (const bool usememhandler=false)
| ~dimeModel ()
dimeModel * | copy () const
bool | init ()
bool | read (dimeInput *const in)
bool | write (dimeOutput *const out)
int | countRecords () const
bool | traverseEntities (dimeCallback callback, void *userdata=NULL, bool traverseBlocksSection=false, bool explodeInserts=true, bool traversePolylineVertices=false)
const char * | addReference (const char *const name, void *id)
void * | findReference (const char *const name) const
const char * | findRefStringPtr (const char *const name) const
void | removeReference (const char *const name)
class dimeMemHandler * | getMemHandler ()
int | getNumLayers () const
const class dimeLayer * | getLayer (const int idx) const
const class dimeLayer * | getLayer (const char *const layername) const
const class dimeLayer * | addLayer (const char *const layername, const int16 colnum=7, const int16 flags=0)
const char * | getDxfVersion () const
const char * | addBlock (const char *const blockname, dimeBlock *const block)
class dimeBlock * | findBlock (const char *const blockname)
class dimeSection * | findSection (const char *const sectionname)
const class dimeSection * | findSection (const char *const sectionname) const
int | getNumSections () const
class dimeSection * | getSection (const int idx)
void | insertSection (dimeSection *const section, const int idx=-1)
void | removeSection (const int idx)
void | registerHandle (const int handle)
void | registerHandle (const char *const handle)
int | getUniqueHandle ()
const char * | getUniqueHandle (char *buf, const int bufsize)
void | addEntity (dimeEntity *entity)

## Static Public Member Functions

static const char * | getVersionString ()
static void | getVersion (int &major, int &minor)

## Detailed Description

The dimeModel class organizes a model.

The constructor accepts a boolean value which specifies whether or not a memory handler should be used. The special purpose memory handler used in Coin can be used if you're just going to read a file and write the file, and not do too much dynamic work on the model. The memory handler yields very fast allocation/deallocation, and has virtually no overhead when allocating. This is important if you have large files with millions of records. The disadvantage is that memory will not be freed until the model is destructed, so if you modify your model, e.g. remove or replace an entity, the memory for the now unused entity will not be freed until the model is destructed. Then all used memory will be freed at once.

Also, if you plan to implement your own entities, it takes a bit of extra care to support the memory handler. In short, you should always check if a memory allocator should be used before allocating memory, since the destructor for entities will never be called when a memory handler is used. See the documentation in dimeEntity for more information about how to create your own entities and how to support the memory handler.

## Constructor & Destructor Documentation

## ◆ dimeModel()

dimeModel::dimeModel | ( | const bool | usememhandler = `false` | ) |

Constructor. If usememhandler is TRUE, the dimeMemHandler will be used to allocate entities and records.

References init().

Referenced by copy().

## ◆ ~dimeModel()

dimeModel::~dimeModel | ( |  | ) |

Destructor.

References dimeArray< T >::count().

## Member Function Documentation

## ◆ addBlock()

const char * dimeModel::addBlock | ( | const char *const | blockname,
|  | dimeBlock *const | block
| ) |  |

Use this to add a block to the model. Make sure you also add it in the BLOCKS section.

References dimeDict::enter().

Referenced by dimeBlock::copy(), and dimeBlock::read().

## ◆ addEntity()

void dimeModel::addEntity | ( | dimeEntity * | entity | ) |

Convenience function

References findSection(), and dimeEntitiesSection::insertEntity().

## ◆ addLayer()

const dimeLayer * dimeModel::addLayer | ( | const char *const | name,
|  | const int16 | colnum = `7`,
|  | const int16 | flags = `0`
| ) |  |

Adds a layer to the list of layers. If the layer allready exists, a pointer to the existing layer will be returned.

References dimeArray< T >::count(), dimeDict::enter(), and dimeDict::find().

Referenced by dimeEntity::copyRecords(), dimeLayerTable::dimeLayerTable(), dimeEntity::read(), and dimeLayerTable::registerLayer().

## ◆ addReference()

const char * dimeModel::addReference | ( | const char *const | name,
|  | void * | id
| ) |  |

Adds a reference in this model's dictionary. Used by BLOCK and INSERT entities to resolve references, but can also be used for other purposes.

References dimeDict::enter().

Referenced by dimeInsert::copy(), and dimeInsert::read().

## ◆ copy()

dimeModel * dimeModel::copy | ( |  | ) | const

Returns a copy of the model.

References dimeArray< T >::count(), dimeModel(), findSection(), dimeBlocksSection::fixReferences(), dimeEntitiesSection::fixReferences(), and init().

Referenced by dimeBlocksSection::~dimeBlocksSection(), dimeClassesSection::~dimeClassesSection(), and dimeObjectsSection::~dimeObjectsSection().

## ◆ countRecords()

int dimeModel::countRecords | ( |  | ) | const

Counts the number of records in the file. Useful if you need progress information while writing the file to disk.

See also
  dimeOutput::setCallback()

References dimeArray< T >::count().

## ◆ findBlock()

dimeBlock * dimeModel::findBlock | ( | const char *const | blockname | ) |

Returns a pointer to the block with name blockname, or NULL if no block with that name exists.

References dimeDict::find().

## ◆ findReference()

void * dimeModel::findReference | ( | const char *const | name | ) | const

Finds a reference from the dictionary.

References dimeDict::find().

Referenced by dimeInsert::copy(), dimeInsert::fixReferences(), and dimeInsert::read().

## ◆ findRefStringPtr()

const char * dimeModel::findRefStringPtr | ( | const char *const | name | ) | const

Finds a pointer to a string in the dictionary.

References dimeDict::find().

Referenced by dimeInsert::copy(), and dimeInsert::read().

## ◆ findSection() [1/2]

dimeSection * dimeModel::findSection | ( | const char *const | sectionname | ) |

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References dimeArray< T >::count().

Referenced by addEntity(), copy(), dxfConverter::findHeaderVariables(), getDxfVersion(), read(), traverseEntities(), and write().

## ◆ findSection() [2/2]

const dimeSection * dimeModel::findSection | ( | const char *const | sectionname | ) | const

Finds the section with section sectionname. Currently (directly) supported sections are HEADER, CLASSES, TABLES, BLOCKS, ENTITIES and OBJECTS.

References dimeArray< T >::count().

## ◆ getDxfVersion()

const char * dimeModel::getDxfVersion | ( |  | ) | const

Returns the AutoCAD drawing database version number. This function return NULL if no version number is found in the file. Currently (directly) supported versions are: r10, r11/r12, r13 and r14.

References findSection(), and dimeHeaderSection::getVariable().

## ◆ getLayer() [1/2]

const dimeLayer * dimeModel::getLayer | ( | const int | idx | ) | const

Returns the layer at index idx.

See also
  dimeModel::getNumLayers()

References dimeArray< T >::count().

## ◆ getLayer() [2/2]

const dimeLayer * dimeModel::getLayer | ( | const char *const | layername | ) | const

Returns the layer with name layername. Returns NULL if no layer by that name is found.

References dimeDict::find().

## ◆ getMemHandler()

dimeMemHandler * dimeModel::getMemHandler | ( |  | ) |

Returns a pointer to the memory handler used for this model.

Referenced by dimeLWPolyline::copy(), dimeUnknownEntity::copy(), dimeUnknownClass::copy(), dimeLine::copy(), dimePoint::copy(), dimeSolid::copy(), dimeTrace::copy(), dime3DFace::copy(), dimeCircle::copy(), dimeInsert::copy(), dimeArc::copy(), dimeVertex::copy(), dimeEllipse::copy(), dimeBlock::copy(), dimeText::copy(), dimeSpline::copy(), dimePolyline::copy(), dimeEntity::copyEntityArray(), dimeTableEntry::copyRecords(), dimeObject::copyRecords(), dimeClass::copyRecords(), dimeEntity::copyRecords(), dimeLayerTable::dimeLayerTable(), dimeUCSTable::dimeUCSTable(), dimeInput::getMemHandler(), dimeHeaderSection::setVariable(), write(), dimeBlocksSection::~dimeBlocksSection(), dimeClassesSection::~dimeClassesSection(), dimeEntitiesSection::~dimeEntitiesSection(), dimeObjectsSection::~dimeObjectsSection(), dimeTable::~dimeTable(), dimeTablesSection::~dimeTablesSection(), dimeUnknownObject::~dimeUnknownObject(), dimeUnknownSection::~dimeUnknownSection(), and dimeUnknownTable::~dimeUnknownTable().

## ◆ getNumLayers()

int dimeModel::getNumLayers | ( |  | ) | const

Returns the number of layers in the model. A default layer will always be created. It is called "Default DIME layer", and it has layer id number 0. All other layers are assigned running numbers from 1.

See also
  dimeLayer::getLayerNum()
  dimeModel::getLayer()

References dimeArray< T >::count().

## ◆ getNumSections()

int dimeModel::getNumSections | ( |  | ) | const

Returns the number of sections in the model.

See also
  dimeModel::getSection()

References dimeArray< T >::count().

## ◆ getSection()

dimeSection * dimeModel::getSection | ( | const int | idx | ) |

Returns the section at index idx.

See also
  dimeModel::getNumSections()

References dimeArray< T >::count().

## ◆ getVersionString()

const char * dimeModel::getVersionString | ( |  | ) |

static

This method returns a string saying which version of DIME is used.j

## ◆ init()

bool dimeModel::init | ( |  | ) |

Should be called before you start working with the model. Will be called by read() so if you're reading a model from a file you will not have to worry about this.

The method cleans up the old data structures and creates new data structures for the new model.

References dimeArray< T >::setCount().

Referenced by copy(), dimeModel(), and read().

## ◆ insertSection()

void dimeModel::insertSection | ( | dimeSection *const | section,
|  | const int | idx = `-1`
| ) |  |

Inserts a new section to the list of sections. The argument idx, specifies the target position of the new section in the list of sections. If idx is negative, the section will be placed at the end of the list.

Sections shold never be allocated on the stack. Use the new/delete operators to create/destroy section instances.

References dimeArray< T >::count().

## ◆ read()

bool dimeModel::read | ( | dimeInput *const | in | ) |

Reads the model file into the internal structures.

References dimeRecord::createRecord(), dimeSection::createSection(), findSection(), dimeBlocksSection::fixReferences(), dimeEntitiesSection::fixReferences(), dimeInput::getFilePosition(), dimeInput::getMemHandler(), init(), dimeInput::readGroupCode(), and dimeInput::readString().

## ◆ registerHandle() [1/2]

void dimeModel::registerHandle | ( | const int | handle | ) |

Newer DXF files has stupid handles (groupcode 5) for all entities, tables etc. I can't undestand they have no real purpose, but all handles must be unique when the file is loaded back into AutoCAD...

Referenced by dimeInput::readString(), dimeInput::readStringNoSkip(), and registerHandle().

## ◆ registerHandle() [2/2]

void dimeModel::registerHandle | ( | const char *const | handle | ) |

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References registerHandle().

## ◆ removeReference()

void dimeModel::removeReference | ( | const char *const | name | ) |

Removes a reference from the dictionary.

References dimeDict::remove().

## ◆ removeSection()

void dimeModel::removeSection | ( | const int | idx | ) |

Removes a section from the list of sections.

References dimeArray< T >::count(), and dimeArray< T >::removeElem().

## ◆ traverseEntities()

bool dimeModel::traverseEntities | ( | dimeCallback | callback,
|  | void * | userdata = `NULL`,
|  | bool | traverseBlocksSection = `false`,
|  | bool | explodeInserts = `true`,
|  | bool | traversePolylineVertices = `false`
| ) |  |

Traverses all entities in the model.

References findSection(), dimeBlocksSection::getBlock(), dimeEntitiesSection::getEntity(), dimeBlocksSection::getNumBlocks(), dimeEntitiesSection::getNumEntities(), dimeBlock::traverse(), and dimeEntity::traverse().

Referenced by dxfConverter::doConvert().

## ◆ write()

bool dimeModel::write | ( | dimeOutput *const | out | ) |

Writes the model to file. Currently only DXF files are supported, but hopefullt DWG will be supported soon.

References dimeArray< T >::count(), findSection(), getMemHandler(), dimeHeaderSection::getVariable(), dimeHeaderSection::setVariable(), dimeOutput::writeGroupCode(), dimeOutput::writeHeader(), and dimeOutput::writeString().

Referenced by dimeClassesSection::~dimeClassesSection(), and dimeObjectsSection::~dimeObjectsSection().

The documentation for this class was generated from the following files:

- Model.h
- Model.cpp

Copyright © by Kongsberg Oil & Gas Technologies. All rights reserved.