Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
dimeEntity Class Referenceabstract

The dimeEntity class is the superclass of all entity classes. More...

#include <dime/entities/Entity.h>

Inheritance diagram for dimeEntity:
dimeRecordHolder dimeBase dimeBlock dimeExtrusionEntity dimeFaceEntity dimeInsert dimeSpline dimeUnknownEntity dimeVertex dimeArc dimeCircle dimeEllipse dimeLine dimeLWPolyline dimePoint dimePolyline dimeText dime3DFace dimeSolid dimeTrace

Public Types

enum  GeometryType { NONE, POLYGONS, LINES, POINTS }
 
- Public Types inherited from dimeBase
enum  {
  dimeBaseType = 1, dimeRecordType, dimeStringRecordType, dimeFloatRecordType,
  dimeDoubleRecordType, dimeInt8RecordType, dimeInt16RecordType, dimeInt32RecordType,
  dimeHexRecordType, dimeRecordHolderType, dimeClassType, dimeUnknownClassType,
  dimeObjectType, dimeUnknownObjectType, dimeEntityType, dimeUnknownEntityType,
  dimePolylineType, dimeVertexType, dimeFaceEntityType, dimeExtrusionEntityType,
  dime3DFaceType, dimeSolidType, dimeTraceType, dimeLineType,
  dimeTextType, dimePointType, dimeBlockType, dimeInsertType,
  dimeCircleType, dimeArcType, dimeLWPolylineType, dimeEllipseType,
  dimeSplineType, dimeSectionType, dimeUnknownSectionType, dimeEntitiesSectionType,
  dimeBlocksSectionType, dimeTablesSectionType, dimeHeaderSectionType, dimeClassesSectionType,
  dimeObjectsSectionType, dimeTableType, dimeTableEntryType, dimeUnknownTableType,
  dimeUCSTableType, dimeLayerTableType, dimeLastTypeTag
}
 

Public Member Functions

 dimeEntity ()
 
virtual ~dimeEntity ()
 
int16 getEntityFlags () const
 
void setEntityFlags (const int16 flags)
 
int16 getColorNumber () const
 
void setColorNumber (const int16 c)
 
virtual void setLayer (const dimeLayer *const layer)
 
virtual const char * getEntityName () const =0
 
const dimeLayergetLayer () const
 
const char * getLayerName () const
 
virtual dimeEntitycopy (dimeModel *const model) const =0
 
virtual bool read (dimeInput *const in)
 
virtual bool write (dimeOutput *const out)
 
virtual bool isOfType (const int thetypeid) const
 
virtual int countRecords () const
 
virtual void print () const
 
bool isDeleted () const
 
void setDeleted (const bool onOff=true)
 
bool isTagged () const
 
void setTagged (const bool onOff=true)
 
virtual bool getRecord (const int groupcode, dimeParam &param, const int index=0) const
 
virtual GeometryType extractGeometry (dimeArray< dimeVec3f > &verts, dimeArray< int > &indices, dimeVec3f &extrusionDir, dxfdouble &thickness)
 
- Public Member Functions inherited from dimeRecordHolder
 dimeRecordHolder (const int separator)
 
virtual ~dimeRecordHolder ()
 
void setRecord (const int groupcode, const dimeParam &value, dimeMemHandler *const memhandler=NULL)
 
void setRecords (const int *const groupcodes, const dimeParam *const params, const int numrecords, dimeMemHandler *const memhandler=NULL)
 
void setIndexedRecord (const int groupcode, const dimeParam &value, const int index, dimeMemHandler *const memhandler=NULL)
 
dimeRecordfindRecord (const int groupcode, const int index=0)
 
int getNumRecordsInRecordHolder (void) const
 
dimeRecordgetRecordInRecordHolder (const int idx) const
 
- Public Member Functions inherited from dimeBase
 dimeBase (void)
 
virtual ~dimeBase ()
 
virtual int typeId () const =0
 
void * operator new (size_t size, dimeMemHandler *memhandler=NULL, const int alignment=4)
 
void operator delete (void *ptr)
 

Static Public Member Functions

static dimeEntitycreateEntity (const char *const name, dimeMemHandler *const memhandler=NULL)
 
static bool readEntities (dimeInput *const file, dimeArray< dimeEntity *> &array, const char *const stopat)
 
static bool copyEntityArray (const dimeEntity *const *const array, const int nument, dimeModel *const model, dimeArray< dimeEntity *> &destarray)
 
static dimeEntity ** copyEntityArray (const dimeEntity *const *const array, int &nument, dimeModel *const model)
 
static void arbitraryAxis (const dimeVec3f &givenaxis, dimeVec3f &newaxis)
 
static void generateUCS (const dimeVec3f &givenaxis, dimeMatrix &m)
 

Protected Member Functions

bool preWrite (dimeOutput *const file)
 
virtual bool traverse (const dimeState *const state, dimeCallback callback, void *userdata)
 
virtual void fixReferences (dimeModel *const model)
 
virtual bool handleRecord (const int groupcode, const dimeParam &param, dimeMemHandler *const memhandler)
 
virtual bool shouldWriteRecord (const int groupcode) const
 
bool copyRecords (dimeEntity *const entity, dimeModel *const model) const
 
- Protected Member Functions inherited from dimeRecordHolder
bool copyRecords (dimeRecordHolder *const rh, dimeMemHandler *const memhandler) const
 

Additional Inherited Members

- Protected Attributes inherited from dimeRecordHolder
dimeRecord ** records
 
int numRecords
 

Detailed Description

The dimeEntity class is the superclass of all entity classes.

If you plan to implement your own entity you should inherit this class. There are some method you need to implement to create an entity, and some steps need to be taken if it's going to work 100% with the rest of the library. I recommend looking at the code for the dimeArc entity when you read this documentation and before you implement your own record. This is a very simple entity. It inherits the dimeExtrusionEntity class. The dimeExtrusionEntity class is used to store extrusion information for an entity, and you should inherit this class if your entity needs all of the following group codes: 39 (thickness), 210, 220, 230 (extrusion direction vector).

The getRecord() method should be implemented to enable records to be queried using the group code of the record. Usually when you implement an entity you store some of the records in class members, and let the dimeRecordHolder class store the records you're not interested in. So, this method should check if the group code parameter matches one of the records stored in one of your class members, and then return the value of that member. If the requested group code isn't store by your class, you should return with a call to your parent's class getRecord() method, usually dimeEntity::getRecord() or dimeExtrusionEntity::getRecord().

The getEntityName() should simply return the DXF name of the entitiy.

The copy() method should make an exact copy of the entity and return this. The dimeModel argument to copy() is the model the copied entity will be a part of. First you should create a new instance of your entitiy. The model'l memory handler should be passed as an argument to new(). Then you should call the copyRecords() method to copy records stored by dimeRecordHolder (dimeEntity inherits dimeRecordHolder). Then you should copy your data members into the new instance. If you inherit the dimeExtrusionEntity you should class copyExtrusionData() before returning.

The write() method should write your entiy using the dimeOutput parameter. Fist your should call the preWrite() method. This will take care of writing the entity name, and handle ugly stuff such as entity handles and ACAD REACTORS data. Then you should write your data members. If you inherit from dimeExtrusionEntity method you should call writeExtrusionData(). The last thing to do before returning is to call dimeEntity::write() to write records not handled by your class.

The typeId() method should be implemented if your entity is not an abstract class. Now you have to edit the include/dime/Base.h, and add a unique type name id for your entity. The typeId() method should simply return this enum value.

The countRecords() method is not critical to implement. It should return the number of records that will be written by your entity. It can be used to create a progress bar while writing a DXF file. It is really only useful for very large DXF files. But you should implement it since it's not too much work.

Implement the extractGeometry() method if you feel like it. This is just a convenience method so you don't have to do this.

The handleRecord() should be implemented to support reading entities from a file, and to let users set records based on group codes. When reading, the handleRecord() method will be called for every record found in the entity. If some group code is not supported by you, you should call the parent's handleRecord() and it will be stored there. If you need to allocate memory to store the data you should check if the dimeMemHandler parameter != NULL and then use it to allocate memory. There is a convenience macro defines in include/dime/Basic.h that copies a string, using the memory handler if != NULL.

Well, that's about it I think. Good luck :) Don't hesitate to contact us (dime-.nosp@m.supp.nosp@m.ort@s.nosp@m.im.n.nosp@m.o) if you have questions about how to create entities.

Constructor & Destructor Documentation

◆ dimeEntity()

dimeEntity::dimeEntity ( )

Constructor.

◆ ~dimeEntity()

dimeEntity::~dimeEntity ( )
virtual

Destructor.

Member Function Documentation

◆ getColorNumber()

int16 dimeEntity::getColorNumber ( ) const
inline

Returns the color number for this entity.

See also
dimeEntity::setColorNumber()

◆ setColorNumber()

void dimeEntity::setColorNumber ( const int16  c)
inline

Sets the color number for this entity. Zero indicates the BYBLOCK (floating) color. 256 indicates BYLAYER. A negative value indicates that the layer is turned off.

◆ setLayer()

void dimeEntity::setLayer ( const dimeLayer *const  layer)
virtual

Sets the layer for this entity. This will change the record with group code 8. If layer equals NULL, the layer will be set to the default layer.

Reimplemented in dimePolyline.

◆ getEntityName()

const char * dimeEntity::getEntityName ( ) const
pure virtual

Must be implemented by subclasses to return the entity name; e.g. POLYLINE, 3DFACE, etc.

Implemented in dimePolyline, dimeSpline, dimeBlock, dimeEllipse, dimeText, dimeVertex, dimeCircle, dimeInsert, dime3DFace, dimeArc, dimeSolid, dimeTrace, dimeLine, dimePoint, dimeLWPolyline, and dimeUnknownEntity.

◆ getLayer()

const dimeLayer * dimeEntity::getLayer ( ) const
inline

Returns the layer of this entity.

◆ getLayerName()

const char * dimeEntity::getLayerName ( ) const

Convenience function which returns the layer name of this entity.

◆ copy()

dimeEntity * dimeEntity::copy ( dimeModel *const  model) const
pure virtual

Must be implemented by subclasses to return a copy of the entity. model is the model the new entity should belong to.

Implemented in dimePolyline, dimeSpline, dimeBlock, dimeText, dimeEllipse, dimeVertex, dimeArc, dimeCircle, dimeInsert, dime3DFace, dimeSolid, dimeTrace, dimeLine, dimePoint, dimeLWPolyline, and dimeUnknownEntity.

◆ read()

bool dimeEntity::read ( dimeInput *const  file)
virtual

Reads an entity from in. Can be overloaded by subclasses, but in most cases this will not be necessary.

See also
dimeEntity::handleRecord().

Reimplemented from dimeRecordHolder.

Reimplemented in dimePolyline, dimeBlock, and dimeInsert.

◆ write()

bool dimeEntity::write ( dimeOutput *const  file)
virtual

◆ isOfType()

bool dimeEntity::isOfType ( const int  thetypeid) const
virtual

Returns true if the object is of type typeid or is inherited from it. Function in base class checks whether thetypeid equals the virtual dimeBase::typeId() value or equals dimeBaseType. Must be implemented by all subclasses that are superclasses of other classes, and should check if thetypeid equals its typeId, and then call its parent's isOfType function. Leaf-classes do not have to implement this method.

Reimplemented from dimeRecordHolder.

Reimplemented in dimeFaceEntity, and dimeExtrusionEntity.

◆ countRecords()

int dimeEntity::countRecords ( ) const
virtual

Returns the number of records in the record holder. Should be overloaded by subclasses which should count their records, and then call the parent's method. This method is used to precalculate the number of records to be written. Very useful when progress information is needed during write().

Reimplemented from dimeRecordHolder.

Reimplemented in dimePolyline, dimeSpline, dimeVertex, dimeBlock, dime3DFace, dimeEllipse, dimeText, dimeFaceEntity, dimeArc, dimeInsert, dimeCircle, dimeLine, dimePoint, dimeSolid, dimeTrace, dimeExtrusionEntity, dimeLWPolyline, and dimeUnknownEntity.

◆ isDeleted()

bool dimeEntity::isDeleted ( ) const

Returns if this entity is marked as deleted or not.

See also
dimeEntity::setDeleted().

◆ setDeleted()

void dimeEntity::setDeleted ( const bool  onOff = true)

Sets the deleted state of this entity to onOff.

See also
dimeEntity::isDeleted().

◆ isTagged()

bool dimeEntity::isTagged ( ) const

Useful for developers (at least for me :-).

See also
dimeEntity::setTagged()

◆ setTagged()

void dimeEntity::setTagged ( const bool  onOff = true)

Useful for developers.

See also
dimeEntity::isTagged()

◆ getRecord()

bool dimeEntity::getRecord ( const int  groupcode,
dimeParam param,
const int  index = 0 
) const
virtual

Will return the value of the record with group code groupcode. false is returned if the record could not be found. Subclasses should overload this method if one or several records are stored in the class. If the groupcode queried is not stored internally, the subclass should call its parent's method.

Reimplemented from dimeRecordHolder.

Reimplemented in dimePolyline, dimeSpline, dimeBlock, dimeEllipse, dimeText, dimeVertex, dimeCircle, dimeInsert, dime3DFace, dimeArc, dimeSolid, dimeTrace, dimeLine, dimePoint, dimeFaceEntity, dimeLWPolyline, and dimeExtrusionEntity.

◆ extractGeometry()

dimeEntity::GeometryType dimeEntity::extractGeometry ( dimeArray< dimeVec3f > &  verts,
dimeArray< int > &  indices,
dimeVec3f extrusionDir,
dxfdouble &  thickness 
)
virtual

A special convenience function, included for your pleasure. Enables the user to ignore the type of entity, and just call this method when extracting geometry. Very useful for 3D viewers that need DXF support. Check out the dxf2vrml directory for an example on how to convert a DXF file to VRML.

Should be overloaded by all subclasses that have geometry, default function returns no geometry. Don't forget to transform vertices by the current transformation matrix if used in a callback from dimeEntity::traverse().

If there are coordinates, but no indices, this means running indices for the entire vertex array.

Different faces and/or line segments are separated by a -1 in the indices array, just as in VRML files.

If thickness != 0.0, the data should, before transformation, be extruded by that length along the extrusion direction. Hence, a point becomes a line, a line becomes a quad, and a polygon becomes an object with a volume.

If thickness == 0.0 and extrusionDir != (0,0,1) all the vertices should be transformed by a matrix that can be created using dimeEntity::generateUCS(). If you are using dimeModel::traverseEntities() to extract the geometry, simply right-multiply the UCS matrix with the matrix found in dimeState to get the correct transformation.

Reimplemented in dimePolyline, dimeText, dimeArc, dimeCircle, dimeFaceEntity, dimeLine, dimePoint, and dimeLWPolyline.

◆ preWrite()

bool dimeEntity::preWrite ( dimeOutput *const  file)
protected

Writes the group code 0, layer name, and some other stuff.

◆ traverse()

bool dimeEntity::traverse ( const dimeState *const  state,
dimeCallback  callback,
void *  userdata 
)
protectedvirtual

The traversal function used when dimeModel::traverseEntities() is called. Most entities use this default method, but some entities (INSERT, BUILD) will need to overload it.

Reimplemented in dimePolyline, dimeBlock, and dimeInsert.

◆ fixReferences()

void dimeEntity::fixReferences ( dimeModel *const  model)
protectedvirtual

Used to find all forward references.

See also
dimeEntitiesSection::fixReferences().

Reimplemented in dimeBlock, and dimeInsert.

◆ handleRecord()

bool dimeEntity::handleRecord ( const int  groupcode,
const dimeParam param,
dimeMemHandler *const  memhandler 
)
protectedvirtual

Must be overloaded by entities that directly supports a record type. During dimeRecordHolder::read(), dimeRecordHolder::setRecord and dimeRecordHolder::setRecords, this function is called for every record found, and it is up to the subclass if the record should be stored internally, or if a generic record should be created and stored in this superclass. A subclass should return true when it will handle the record, false otherwise. Default function does nothing, and returns false.

For entities, records with group codes 8 (layer name) and 62 (color number) are automatically handled by the dimeEntity class.

See also
dimeRecordHolder::read()
dimeRecordHolder::setRecord()

Reimplemented from dimeRecordHolder.

Reimplemented in dimePolyline, dimeSpline, dimeVertex, dimeText, dimeBlock, dimeInsert, dime3DFace, dimeEllipse, dimeFaceEntity, dimeArc, dimeLWPolyline, dimeCircle, dimeLine, dimePoint, dimeSolid, dimeTrace, and dimeExtrusionEntity.

◆ shouldWriteRecord()

bool dimeEntity::shouldWriteRecord ( const int  groupcode) const
protectedvirtual

Can be overloaded by subclasses that want the record holder to store a record, but handles writing themselves. Default method returns true for all group codes.

Reimplemented from dimeRecordHolder.

◆ createEntity()

dimeEntity * dimeEntity::createEntity ( const char *const  name,
dimeMemHandler *const  memhandler = NULL 
)
static

Static function which creates an entity based on its name.

◆ readEntities()

bool dimeEntity::readEntities ( dimeInput *const  file,
dimeArray< dimeEntity *> &  array,
const char *const  stopat 
)
static

Static function that reads all entities until an entity of type stopat is found. Returns true if all entities were read OK. When reading stops, the group code 0 and the entity name (stopat) will already have been read.

◆ copyEntityArray() [1/2]

bool dimeEntity::copyEntityArray ( const dimeEntity *const *const  array,
const int  nument,
dimeModel *const  model,
dimeArray< dimeEntity *> &  destarray 
)
static

Static function which copies all non-deleted entites from array of length nument into destarray.

◆ copyEntityArray() [2/2]

dimeEntity ** dimeEntity::copyEntityArray ( const dimeEntity *const *const  array,
int &  nument,
dimeModel *const  model 
)
static

Static function which copies all non-deleted entites from array of length nument into a new array. Will return the number of copied entities in nument. This function returns NULL either when out of memory, or if there was no non-deleted entities.

◆ arbitraryAxis()

void dimeEntity::arbitraryAxis ( const dimeVec3f givenaxis,
dimeVec3f newaxis 
)
static

Will return an "arbitrary" axis, based on givenaxis. Based on code from DXF Parser R10, from Autodesk Inc. Is used to find the x-axis bases on the given z-axis.

See also
dimeEntity::generateUCS()

◆ generateUCS()

void dimeEntity::generateUCS ( const dimeVec3f givenaxis,
dimeMatrix m 
)
static

Will generate a coordinate system, based on givenaxis, which will be the z-axis in the new coordinate system.

See also
dimeEntity::arbitraryAxis()

◆ copyRecords()

bool dimeEntity::copyRecords ( dimeEntity *const  entity,
dimeModel *const  model 
) const
protected

Copies the common and unclassified records.


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