36 { 0.65, 0.325, 0.325 },
42 { 0.15, 0.075, 0.075 },
46 { 0.65, 0.4063, 0.325 },
48 { 0.5, 0.3125, 0.25 },
50 { 0.3, 0.1875, 0.15 },
52 { 0.15, 0.0938, 0.075 },
56 { 0.65, 0.4875, 0.325 },
62 { 0.15, 0.1125, 0.075 },
66 { 0.65, 0.5688, 0.325 },
68 { 0.5, 0.4375, 0.25 },
70 { 0.3, 0.2625, 0.15 },
72 { 0.15, 0.1313, 0.075 },
76 { 0.65, 0.65, 0.325 },
82 { 0.15, 0.15, 0.075 },
86 { 0.5688, 0.65, 0.325 },
88 { 0.4375, 0.5, 0.25 },
90 { 0.2625, 0.3, 0.15 },
92 { 0.1313, 0.15, 0.075 },
96 { 0.4875, 0.65, 0.325 },
100 { 0.225, 0.3, 0.15 },
102 { 0.1125, 0.15, 0.075 },
106 { 0.4063, 0.65, 0.325 },
108 { 0.3125, 0.5, 0.25 },
110 { 0.1875, 0.3, 0.15 },
112 { 0.0938, 0.15, 0.075 },
116 { 0.325, 0.65, 0.325 },
122 { 0.075, 0.15, 0.075 },
126 { 0.325, 0.65, 0.4063 },
128 { 0.25, 0.5, 0.3125 },
130 { 0.15, 0.3, 0.1875 },
132 { 0.075, 0.15, 0.0938 },
136 { 0.325, 0.65, 0.4875 },
138 { 0.25, 0.5, 0.375 },
140 { 0.15, 0.3, 0.225 },
142 { 0.075, 0.15, 0.1125 },
146 { 0.325, 0.65, 0.5688 },
148 { 0.25, 0.5, 0.4375 },
150 { 0.15, 0.3, 0.2625 },
152 { 0.075, 0.15, 0.1313 },
156 { 0.325, 0.65, 0.65 },
162 { 0.075, 0.15, 0.15 },
166 { 0.325, 0.5688, 0.65 },
168 { 0.25, 0.4375, 0.5 },
170 { 0.15, 0.2625, 0.3 },
172 { 0.075, 0.1313, 0.15 },
176 { 0.325, 0.4875, 0.65 },
178 { 0.25, 0.375, 0.5 },
180 { 0.15, 0.225, 0.3 },
182 { 0.075, 0.1125, 0.15 },
186 { 0.325, 0.4063, 0.65 },
188 { 0.25, 0.3125, 0.5 },
190 { 0.15, 0.1875, 0.3 },
192 { 0.075, 0.0938, 0.15 },
196 { 0.325, 0.325, 0.65 },
202 { 0.075, 0.075, 0.15 },
206 { 0.4063, 0.325, 0.65 },
208 { 0.3125, 0.25, 0.5 },
210 { 0.1875, 0.15, 0.3 },
212 { 0.0938, 0.075, 0.15 },
216 { 0.4875, 0.325, 0.65 },
218 { 0.375, 0.25, 0.5 },
220 { 0.225, 0.15, 0.3 },
222 { 0.1125, 0.075, 0.15 },
226 { 0.5688, 0.325, 0.65 },
228 { 0.4375, 0.25, 0.5 },
230 { 0.2625, 0.15, 0.3 },
232 { 0.1313, 0.075, 0.15 },
236 { 0.65, 0.325, 0.65 },
242 { 0.15, 0.075, 0.15 },
246 { 0.65, 0.325, 0.5688 },
248 { 0.5, 0.25, 0.4375 },
250 { 0.3, 0.15, 0.2625 },
252 { 0.15, 0.075, 0.1313 },
256 { 0.65, 0.325, 0.4875 },
258 { 0.5, 0.25, 0.375 },
260 { 0.3, 0.15, 0.225 },
262 { 0.15, 0.075, 0.1125 },
266 { 0.65, 0.325, 0.4063 },
268 { 0.5, 0.25, 0.3125 },
270 { 0.3, 0.15, 0.1875 },
272 { 0.15, 0.075, 0.0938 },
273 { 0.33, 0.33, 0.33 },
274 { 0.464, 0.464, 0.464 },
275 { 0.598, 0.598, 0.598 },
276 { 0.732, 0.732, 0.732 },
277 { 0.866, 0.866, 0.866 },
338 while (_state != ST_done && _state != ST_error) {
445 double best_diff = 4.0;
448 for (
int i = 0; i < 255; i++) {
449 double diff = ((r - _colors[i].r) * (r - _colors[i].r) +
450 (g - _colors[i].g) * (g - _colors[i].g) +
451 (b - _colors[i].b) * (b - _colors[i].b));
452 if (diff < best_diff) {
468 if (_color_index >= 0 && _color_index <= 255) {
469 return _colors[_color_index];
494 DXFVertices::iterator vi;
495 for (vi = _verts.begin(); vi != _verts.end(); ++vi) {
496 (*vi)._p = (*vi)._p * _ocs2wcs;
515 if (fabs(_z[0]) < 1.0/64.0 && fabs(_z[1]) < 1.0/64.0) {
516 x = cross(LVector3d(0.0, 1.0, 0.0), _z);
518 x = cross(LVector3d(0.0, 0.0, 1.0), _z);
526 ocs( x[0], x[1], x[2], 0,
528 _z[0], _z[1], _z[2], 0,
531 _ocs2wcs.invert_from(ocs);
545 change_state(ST_error);
551 while (in && in.peek() !=
'\n') {
555 while (in && isspace(in.peek()) && in.peek() !=
'\n') {
559 std::getline(in, _string);
563 change_state(ST_error);
568 }
while (_code == 999);
578 change_state(State new_state) {
579 if (_state == ST_verts) {
581 _p.set(0.0, 0.0, 0.0);
582 _q.set(0.0, 0.0, 0.0);
583 _r.set(0.0, 0.0, 0.0);
584 _s.set(0.0, 0.0, 0.0);
586 if ((_state == ST_entity || _state == ST_verts) &&
587 new_state != ST_verts) {
613 change_section(Section new_section) {
614 change_state(ST_section);
615 _section = new_section;
626 change_layer(
const string &layer_name) {
627 if (_layer ==
nullptr || _layer->get_name() != layer_name) {
628 _layer = _layers.
get_layer(layer_name,
this);
637 change_entity(Entity new_entity) {
638 if (new_entity == EN_vertex && _vertices_follow) {
641 change_state(ST_verts);
645 change_state(ST_entity);
646 _entity = new_entity;
657 _p.set(0.0, 0.0, 0.0);
658 _q.set(0.0, 0.0, 0.0);
659 _r.set(0.0, 0.0, 0.0);
660 _s.set(0.0, 0.0, 0.0);
661 _z.set(0.0, 0.0, 1.0);
662 _vertices_follow =
false;
665 _verts.erase(_verts.begin(), _verts.end());
676 nout <<
"Group code 0 not found at top level; found code " << _code
678 change_state(ST_error);
680 if (_string ==
"SECTION") {
683 nout <<
"Group code 0 not immediately followed by code 2; found code " 684 << _code <<
" instead.\n";
686 if (_string ==
"HEADER") {
687 change_section(SE_header);
688 }
else if (_string ==
"TABLES") {
689 change_section(SE_tables);
690 }
else if (_string ==
"BLOCKS") {
691 change_section(SE_blocks);
692 }
else if (_string ==
"ENTITIES") {
693 change_section(SE_entities);
694 }
else if (_string ==
"OBJECTS") {
695 change_section(SE_objects);
697 change_section(SE_unknown);
701 }
else if (_string ==
"EOF") {
702 change_state(ST_done);
704 nout <<
"Unexpected section at top level: '" << _string <<
"'\n";
705 change_state(ST_error);
721 if (_string ==
"ENDSEC") {
722 change_state(ST_top);
724 if (_section == SE_entities) {
725 if (_string ==
"3DFACE") {
726 change_entity(EN_3dface);
727 }
else if (_string ==
"POINT") {
728 change_entity(EN_point);
729 }
else if (_string ==
"INSERT") {
730 change_entity(EN_insert);
731 }
else if (_string ==
"VERTEX") {
732 change_entity(EN_vertex);
733 }
else if (_string ==
"POLYLINE") {
734 change_entity(EN_polyline);
736 change_entity(EN_unknown);
743 change_layer(_string);
769 change_layer(_string);
864 change_layer(_string);
885 ostream &operator << (ostream &out,
const DXFFile::State &state) {
887 case DXFFile::ST_top:
888 return out <<
"ST_top";
889 case DXFFile::ST_section:
890 return out <<
"ST_section";
891 case DXFFile::ST_entity:
892 return out <<
"ST_entity";
893 case DXFFile::ST_verts:
894 return out <<
"ST_verts";
895 case DXFFile::ST_error:
896 return out <<
"ST_error";
897 case DXFFile::ST_done:
898 return out <<
"ST_done";
900 return out <<
"Unknown state";
903 ostream &operator << (ostream &out,
const DXFFile::Section §ion) {
905 case DXFFile::SE_unknown:
906 return out <<
"SE_unknown";
907 case DXFFile::SE_header:
908 return out <<
"SE_header";
909 case DXFFile::SE_tables:
910 return out <<
"SE_tables";
911 case DXFFile::SE_blocks:
912 return out <<
"SE_blocks";
913 case DXFFile::SE_entities:
914 return out <<
"SE_entities";
915 case DXFFile::SE_objects:
916 return out <<
"SE_objects";
918 return out <<
"Unknown section";
921 ostream &operator << (ostream &out,
const DXFFile::Entity &entity) {
923 case DXFFile::EN_unknown:
924 return out <<
"EN_unknown";
925 case DXFFile::EN_3dface:
926 return out <<
"EN_3dface";
927 case DXFFile::EN_point:
928 return out <<
"EN_point";
929 case DXFFile::EN_insert:
930 return out <<
"EN_insert";
931 case DXFFile::EN_vertex:
932 return out <<
"EN_vertex";
933 case DXFFile::EN_polyline:
934 return out <<
"EN_polyline";
936 return out <<
"Unknown entity";
int string_to_int(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
double string_to_double(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
virtual void end_file()
A hook for user code, if desired.
A hierarchy of directories and files that appears to be one continuous file system,...
std::istream * open_read_file(const Filename &filename, bool auto_unwrap) const
Convenience function; returns a newly allocated istream if the file exists and can be read,...
virtual void begin_section()
A hook for user code, if desired.
void set_text()
Indicates that the filename represents a text file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void close_read_file(std::istream *stream)
Closes a file opened by a previous call to open_read_file().
virtual void error()
A hook for user code, if desired.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
virtual void begin_file()
A hook for user code, if desired.
virtual void done_entity()
This is the primary hook for user code.
DXFLayer * get_layer(const std::string &name, DXFFile *dxffile)
Looks up the layer name in the map, and returns a pointer to the associated DXFLayer.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
virtual void end_section()
A hook for user code, if desired.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Stored within DXFFile, this is the basic Vertex data of a DXF file.
void ocs_2_wcs()
Assuming the current entity is a planar-based entity, for instance, a 2-d polygon (as opposed to a 3-...
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.
virtual void done_vertex()
A hook for user code, if desired.
void process(Filename filename)
Opens the indicated filename and reads it as a DXF file.
const Color & get_color() const
This is a convenience function to return the r,g,b color of the current entity (at the time of done_e...
string trim_right(const string &str)
Returns a new string representing the contents of the given string with the trailing whitespace remov...