00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef DXFFILE_H
00016 #define DXFFILE_H
00017
00018 #include "pandatoolbase.h"
00019
00020 #include "dxfLayer.h"
00021 #include "dxfLayerMap.h"
00022 #include "dxfVertex.h"
00023
00024 #include "luse.h"
00025 #include "filename.h"
00026
00027
00028 static const int DXF_max_line = 256;
00029 static const int DXF_num_colors = 256;
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class DXFFile : public MemoryBase {
00040 public:
00041 DXFFile();
00042 virtual ~DXFFile();
00043
00044 void process(Filename filename);
00045 void process(istream *in, bool owns_in);
00046
00047
00048
00049
00050
00051
00052 virtual void begin_file();
00053 virtual void begin_section();
00054 virtual void done_vertex();
00055 virtual void done_entity();
00056 virtual void end_section();
00057 virtual void end_file();
00058 virtual void error();
00059
00060
00061
00062
00063
00064 virtual DXFLayer *new_layer(const string &name) {
00065 return new DXFLayer(name);
00066 }
00067
00068 enum State {
00069 ST_top,
00070 ST_section,
00071 ST_entity,
00072 ST_verts,
00073 ST_error,
00074 ST_done,
00075 };
00076 enum Section {
00077 SE_unknown,
00078 SE_header,
00079 SE_tables,
00080 SE_blocks,
00081 SE_entities,
00082 SE_objects,
00083 };
00084 enum Entity {
00085 EN_unknown,
00086 EN_3dface,
00087 EN_point,
00088 EN_insert,
00089 EN_vertex,
00090 EN_polyline,
00091 };
00092 enum PolylineFlags {
00093 PF_closed = 0x01,
00094 PF_curve_fit = 0x02,
00095 PF_spline_fit = 0x04,
00096 PF_3d = 0x08,
00097 PF_3d_mesh = 0x10,
00098 PF_closed_n = 0x20,
00099 PF_polyface = 0x40,
00100 PF_continuous_linetype = 0x80,
00101 };
00102
00103
00104
00105
00106 struct Color {
00107 double r, g, b;
00108 };
00109 static Color _colors[DXF_num_colors];
00110
00111
00112
00113 static int find_color(double r, double g, double b);
00114
00115
00116
00117 const Color &get_color() const;
00118
00119
00120
00121
00122
00123
00124 void ocs_2_wcs();
00125
00126
00127
00128
00129 int _flags;
00130 Section _section;
00131 Entity _entity;
00132 LPoint3d _p, _q, _r, _s;
00133 LVector3d _z;
00134 int _color_index;
00135 DXFLayer *_layer;
00136
00137
00138
00139 DXFVertices _verts;
00140
00141
00142 DXFLayerMap _layers;
00143
00144 protected:
00145 State _state;
00146 bool _vertices_follow;
00147 LMatrix4d _ocs2wcs;
00148
00149 istream *_in;
00150 bool _owns_in;
00151
00152 int _code;
00153 string _string;
00154
00155 void compute_ocs();
00156
00157 bool get_group();
00158 void change_state(State new_state);
00159 void change_section(Section new_section);
00160 void change_layer(const string &layer_name);
00161 void change_entity(Entity new_entity);
00162 void reset_entity();
00163
00164 void state_top();
00165 void state_section();
00166 void state_entity();
00167 void state_verts();
00168 };
00169
00170 ostream &operator << (ostream &out, const DXFFile::State &state);
00171 ostream &operator << (ostream &out, const DXFFile::Section §ion);
00172 ostream &operator << (ostream &out, const DXFFile::Entity &entity);
00173
00174 #endif