dime
0.9.1
Portable DXF file library
|
The dimeEntity class is the superclass of all entity classes. More...
#include <dime/entities/Entity.h>
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 () |
virtual dimeEntity * | copy (dimeModel *const model) const =0 |
virtual int | countRecords () const |
virtual GeometryType | extractGeometry (dimeArray< dimeVec3f > &verts, dimeArray< int > &indices, dimeVec3f &extrusionDir, dxfdouble &thickness) |
int16 | getColorNumber () const |
int16 | getEntityFlags () const |
virtual const char * | getEntityName () const =0 |
const dimeLayer * | getLayer () const |
const char * | getLayerName () const |
virtual bool | getRecord (const int groupcode, dimeParam ¶m, const int index=0) const |
bool | isDeleted () const |
virtual bool | isOfType (const int thetypeid) const |
bool | isTagged () const |
virtual void | print () const |
virtual bool | read (dimeInput *const in) |
void | setColorNumber (const int16 c) |
void | setDeleted (const bool onOff=true) |
void | setEntityFlags (const int16 flags) |
virtual void | setLayer (const dimeLayer *const layer) |
void | setTagged (const bool onOff=true) |
virtual bool | write (dimeOutput *const out) |
Public Member Functions inherited from dimeRecordHolder | |
dimeRecordHolder (const int separator) | |
virtual | ~dimeRecordHolder () |
dimeRecord * | findRecord (const int groupcode, const int index=0) |
int | getNumRecordsInRecordHolder (void) const |
dimeRecord * | getRecordInRecordHolder (const int idx) const |
void | setIndexedRecord (const int groupcode, const dimeParam &value, const int index, dimeMemHandler *const memhandler=NULL) |
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) |
Public Member Functions inherited from dimeBase | |
dimeBase (void) | |
virtual | ~dimeBase () |
void | operator delete (void *ptr) |
void * | operator new (size_t size, dimeMemHandler *memhandler=NULL, const int alignment=4) |
virtual int | typeId () const =0 |
Static Public Member Functions | |
static void | arbitraryAxis (const dimeVec3f &givenaxis, dimeVec3f &newaxis) |
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 dimeEntity * | createEntity (const char *const name, dimeMemHandler *const memhandler=NULL) |
static void | generateUCS (const dimeVec3f &givenaxis, dimeMatrix &m) |
static bool | readEntities (dimeInput *const file, dimeArray< dimeEntity * > &array, const char *const stopat) |
Protected Member Functions | |
bool | copyRecords (dimeEntity *const entity, dimeModel *const model) const |
virtual void | fixReferences (dimeModel *const model) |
virtual bool | handleRecord (const int groupcode, const dimeParam ¶m, dimeMemHandler *const memhandler) |
bool | preWrite (dimeOutput *const file) |
virtual bool | shouldWriteRecord (const int groupcode) const |
virtual bool | traverse (const dimeState *const state, dimeCallback callback, void *userdata) |
Protected Member Functions inherited from dimeRecordHolder | |
bool | copyRecords (dimeRecordHolder *const rh, dimeMemHandler *const memhandler) const |
Additional Inherited Members | |
Protected Attributes inherited from dimeRecordHolder | |
int | numRecords |
dimeRecord ** | records |
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 methods 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 stored 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 entity.
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 entity. The model's 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 entity using the dimeOutput parameter. Fist you 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 defined in include/dime/Basic.h that copies a string, using the memory handler if set.
Well, that's about it I think. Good luck :) Don't hesitate to contact us (coin-.nosp@m.supp.nosp@m.ort@c.nosp@m.oin3.nosp@m.d.org) if you have questions about how to create entities.
dimeEntity::dimeEntity | ( | ) |
Constructor.
|
virtual |
Destructor.
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.
|
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 dime3DFace, dimeArc, dimeBlock, dimeCircle, dimeEllipse, dimeInsert, dimeLine, dimeLWPolyline, dimePoint, dimePolyline, dimeSolid, dimeSpline, dimeText, dimeTrace, dimeUnknownEntity, and dimeVertex.
|
static |
Static function which copies all non-deleted entities from array of length nument into destarray.
|
static |
Static function which copies all non-deleted entities 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.
|
protected |
Copies the common and unclassified records.
|
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 dime3DFace, dimeArc, dimeBlock, dimeCircle, dimeEllipse, dimeExtrusionEntity, dimeFaceEntity, dimeInsert, dimeLine, dimeLWPolyline, dimePoint, dimePolyline, dimeSolid, dimeSpline, dimeText, dimeTrace, dimeUnknownEntity, and dimeVertex.
|
static |
Static function which creates an entity based on its name.
|
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 dimeArc, dimeCircle, dimeFaceEntity, dimeLine, dimeLWPolyline, dimePoint, dimePolyline, and dimeText.
|
protectedvirtual |
Used to find all forward references.
Reimplemented in dimeBlock, and dimeInsert.
|
static |
Will generate a coordinate system, based on givenaxis, which will be the Z-axis in the new coordinate system.
|
inline |
Returns the color number for this entity.
|
pure virtual |
Must be implemented by subclasses to return the entity name, e.g. POLYLINE, 3DFACE, etc.
Implemented in dime3DFace, dimeArc, dimeBlock, dimeCircle, dimeEllipse, dimeInsert, dimeLine, dimeLWPolyline, dimePoint, dimePolyline, dimeSolid, dimeSpline, dimeText, dimeTrace, dimeUnknownEntity, and dimeVertex.
|
inline |
Returns the layer of this entity.
const char * dimeEntity::getLayerName | ( | ) | const |
Convenience function which returns the layer name of this entity.
|
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 group code queried is not stored internally, the subclass should call its parent's method.
Reimplemented from dimeRecordHolder.
Reimplemented in dimeLWPolyline, dimeSpline, dime3DFace, dimeArc, dimeBlock, dimeCircle, dimeEllipse, dimeExtrusionEntity, dimeFaceEntity, dimeInsert, dimeLine, dimePoint, dimePolyline, dimeSolid, dimeText, dimeTrace, and dimeVertex.
|
protectedvirtual |
Must be overloaded by entities that directly support 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.
Reimplemented from dimeRecordHolder.
Reimplemented in dime3DFace, dimeArc, dimeBlock, dimeCircle, dimeEllipse, dimeExtrusionEntity, dimeFaceEntity, dimeInsert, dimeLine, dimeLWPolyline, dimePoint, dimePolyline, dimeSolid, dimeSpline, dimeText, dimeTrace, and dimeVertex.
bool dimeEntity::isDeleted | ( | ) | const |
Returns if this entity is marked as deleted or not.
|
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.
bool dimeEntity::isTagged | ( | ) | const |
Useful for developers (at least for me :-).
|
protected |
Writes the group code 0, layer name, and some other stuff.
|
virtual |
Reads an entity from in. Can be overloaded by subclasses, but in most cases this will not be necessary.
Reimplemented from dimeRecordHolder.
Reimplemented in dimeBlock, dimeInsert, and dimePolyline.
|
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.
|
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.
void dimeEntity::setDeleted | ( | const bool | onOff = true | ) |
Sets the deleted state of this entity to onOff.
|
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.
void dimeEntity::setTagged | ( | const bool | onOff = true | ) |
Useful for developers.
|
protectedvirtual |
Can be overloaded by subclasses that want the record holder to store a record, but handle writing themselves. Default method returns true for all group codes.
Reimplemented from dimeRecordHolder.
|
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 dimeBlock, dimeInsert, and dimePolyline.
|
virtual |
Will write the records to file.
Reimplemented from dimeRecordHolder.
Reimplemented in dime3DFace, dimeArc, dimeBlock, dimeCircle, dimeEllipse, dimeInsert, dimeLine, dimeLWPolyline, dimePoint, dimePolyline, dimeSolid, dimeSpline, dimeText, dimeTrace, dimeUnknownEntity, and dimeVertex.