Panda3D
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes

DXFFile Class Reference

A generic DXF-reading class. More...

#include "dxfFile.h"

Inheritance diagram for DXFFile:
MemoryBase DXFPoints DXFToEggConverter

List of all members.

Classes

struct  Color

Public Types

enum  Entity {
  EN_unknown, EN_3dface, EN_point, EN_insert,
  EN_vertex, EN_polyline
}
enum  PolylineFlags {
  PF_closed = 0x01, PF_curve_fit = 0x02, PF_spline_fit = 0x04, PF_3d = 0x08,
  PF_3d_mesh = 0x10, PF_closed_n = 0x20, PF_polyface = 0x40, PF_continuous_linetype = 0x80
}
enum  Section {
  SE_unknown, SE_header, SE_tables, SE_blocks,
  SE_entities, SE_objects
}
enum  State {
  ST_top, ST_section, ST_entity, ST_verts,
  ST_error, ST_done
}

Public Member Functions

virtual void begin_file ()
 A hook for user code, if desired.
virtual void begin_section ()
 A hook for user code, if desired.
virtual void done_entity ()
 This is the primary hook for user code.
virtual void done_vertex ()
 A hook for user code, if desired.
virtual void end_file ()
 A hook for user code, if desired.
virtual void end_section ()
 A hook for user code, if desired.
virtual void error ()
 A hook for user code, if desired.
const Colorget_color () const
 This is a convenience function to return the r,g,b color of the current entity (at the time of done_entity()).
virtual DXFLayernew_layer (const string &name)
void ocs_2_wcs ()
 Assuming the current entity is a planar-based entity, for instance, a 2-d polygon (as opposed to a 3-d polygon), this converts the coordinates from the funny planar coordinate system to the world coordinates.
void process (Filename filename)
 Opens the indicated filename and reads it as a DXF file.
void process (istream *in, bool owns_in)
 Reads the indicated stream as a DXF file.

Static Public Member Functions

static int find_color (double r, double g, double b)
 Returns the index of the closest matching AutoCAD color to the indicated r, g, b.

Public Attributes

int _color_index
Entity _entity
int _flags
DXFLayer_layer
DXFLayerMap _layers
LPoint3d _p
LPoint3d _q
LPoint3d _r
LPoint3d _s
Section _section
DXFVertices _verts
LVector3d _z

Static Public Attributes

static Color _colors [DXF_num_colors]

Protected Member Functions

void change_entity (Entity new_entity)
void change_layer (const string &layer_name)
 Given a newly read layer name, sets the _layer pointer to point to the associate layer.
void change_section (Section new_section)
void change_state (State new_state)
 Called as new nodes are read to update the internal state correctly.
void compute_ocs ()
 Computes the matrix used to convert from the planar coordinate system to world coordinates.
bool get_group ()
 Reads the next code, string pair from the DXF file.
void reset_entity ()
 Resets the current entity to its initial, default state prior to reading a new entity.
void state_entity ()
 Does the DXF processing when we are reading an entity.
void state_section ()
 Does the DXF processing when we are within some section.
void state_top ()
 Does the DXF processing when we are at the top of the file, outside of any section.
void state_verts ()
 Does the DXF processing when we are reading the list of vertices that might follow an entity.

Protected Attributes

int _code
istream * _in
LMatrix4d _ocs2wcs
bool _owns_in
State _state
string _string
bool _vertices_follow

Detailed Description

A generic DXF-reading class.

This class can read a DXF file but doesn't actually do anything with the data; it's intended to be inherited from and the appropriate functions overridden (particularly DoneEntity()).

Definition at line 39 of file dxfFile.h.


Member Function Documentation

void DXFFile::begin_file ( ) [virtual]

A hook for user code, if desired.

This function is called whenever processing begins on the DXF file.

Definition at line 380 of file dxfFile.cxx.

Referenced by process().

void DXFFile::begin_section ( ) [virtual]

A hook for user code, if desired.

This function is called whenever a new section in the DXF file is encountered.

Definition at line 392 of file dxfFile.cxx.

void DXFFile::change_layer ( const string &  layer_name) [protected]

Given a newly read layer name, sets the _layer pointer to point to the associate layer.

If the layer name has not been encountered before, creates a new layer definition.

Definition at line 675 of file dxfFile.cxx.

References DXFLayerMap::get_layer().

Referenced by state_entity(), state_section(), and state_verts().

void DXFFile::change_state ( State  new_state) [protected]

Called as new nodes are read to update the internal state correctly.

Definition at line 621 of file dxfFile.cxx.

References done_entity(), done_vertex(), end_file(), end_section(), and reset_entity().

Referenced by get_group(), state_section(), and state_top().

void DXFFile::compute_ocs ( ) [protected]

Computes the matrix used to convert from the planar coordinate system to world coordinates.

Definition at line 544 of file dxfFile.cxx.

References LMatrix4d::invert_from(), and LVecBase3d::normalize().

Referenced by ocs_2_wcs().

void DXFFile::done_entity ( ) [virtual]

This is the primary hook for user code.

This function is called when an entity is read from the DXF file. This may be something like a polygon, point, or a polygon mesh: any geometry. It is up to the user code to override this function and do something interesting with each piece of geometry that is read.

Reimplemented in DXFToEggConverter, and DXFPoints.

Definition at line 426 of file dxfFile.cxx.

Referenced by change_state().

void DXFFile::done_vertex ( ) [virtual]

A hook for user code, if desired.

This function is called whenever a vertex is read from the DXF file. This function has the default behavior of adding the vertex to the _verts list, so that when done_entity() is called later, it will have the complete list of vertices available to it.

Definition at line 407 of file dxfFile.cxx.

Referenced by change_state().

void DXFFile::end_file ( ) [virtual]

A hook for user code, if desired.

This function is called when the DXF processing is complete.

Definition at line 448 of file dxfFile.cxx.

Referenced by change_state().

void DXFFile::end_section ( ) [virtual]

A hook for user code, if desired.

This function is called as each section in the DXF file is finished.

Definition at line 437 of file dxfFile.cxx.

Referenced by change_state().

void DXFFile::error ( ) [virtual]

A hook for user code, if desired.

This function is called when some unexpected error occurs while reading the DXF file.

Reimplemented in DXFToEggConverter.

Definition at line 460 of file dxfFile.cxx.

int DXFFile::find_color ( double  r,
double  g,
double  b 
) [static]

Returns the index of the closest matching AutoCAD color to the indicated r, g, b.

Definition at line 473 of file dxfFile.cxx.

const DXFFile::Color & DXFFile::get_color ( ) const

This is a convenience function to return the r,g,b color of the current entity (at the time of done_entity()).

It's based on the _color_index value that was read from the DXF file.

Definition at line 499 of file dxfFile.cxx.

Referenced by DXFToEggLayer::add_line(), and DXFToEggLayer::add_polygon().

bool DXFFile::get_group ( ) [protected]

Reads the next code, string pair from the DXF file.

This is the basic unit of data in a DXF file.

Definition at line 580 of file dxfFile.cxx.

References change_state().

Referenced by process(), and state_top().

void DXFFile::ocs_2_wcs ( )

Assuming the current entity is a planar-based entity, for instance, a 2-d polygon (as opposed to a 3-d polygon), this converts the coordinates from the funny planar coordinate system to the world coordinates.

It converts the _p value of the entity, as well as all vertices in the _verts list.

Definition at line 518 of file dxfFile.cxx.

References compute_ocs().

Referenced by DXFPoints::done_entity(), and DXFToEggConverter::done_entity().

void DXFFile::process ( istream *  in,
bool  owns_in 
)

Reads the indicated stream as a DXF file.

If owns_in is true, then the istream will be deleted via vfs->close_read_file() when the DXFFile object destructs.

Definition at line 335 of file dxfFile.cxx.

References begin_file(), VirtualFileSystem::close_read_file(), VirtualFileSystem::get_global_ptr(), get_group(), state_entity(), state_section(), state_top(), and state_verts().

void DXFFile::process ( Filename  filename)

Opens the indicated filename and reads it as a DXF file.

Definition at line 314 of file dxfFile.cxx.

References VirtualFileSystem::get_global_ptr(), VirtualFileSystem::open_read_file(), and Filename::set_text().

Referenced by DXFToEggConverter::convert_file().

void DXFFile::reset_entity ( ) [protected]

Resets the current entity to its initial, default state prior to reading a new entity.

Definition at line 710 of file dxfFile.cxx.

Referenced by change_state().

void DXFFile::state_entity ( ) [protected]

Does the DXF processing when we are reading an entity.

Definition at line 822 of file dxfFile.cxx.

References change_layer(), and state_section().

Referenced by process().

void DXFFile::state_section ( ) [protected]

Does the DXF processing when we are within some section.

Definition at line 775 of file dxfFile.cxx.

References change_layer(), and change_state().

Referenced by process(), state_entity(), and state_verts().

void DXFFile::state_top ( ) [protected]

Does the DXF processing when we are at the top of the file, outside of any section.

Definition at line 730 of file dxfFile.cxx.

References change_state(), and get_group().

Referenced by process().

void DXFFile::state_verts ( ) [protected]

Does the DXF processing when we are reading the list of vertices that might follow an entity.

Definition at line 919 of file dxfFile.cxx.

References change_layer(), and state_section().

Referenced by process().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations