Panda3D
dxfToEggConverter.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file dxfToEggConverter.cxx
10  * @author drose
11  * @date 2004-05-04
12  */
13 
14 #include "dxfToEggConverter.h"
15 #include "dxfToEggLayer.h"
16 #include "eggData.h"
17 
18 /**
19  *
20  */
21 DXFToEggConverter::
22 DXFToEggConverter() {
23 }
24 
25 /**
26  *
27  */
28 DXFToEggConverter::
29 DXFToEggConverter(const DXFToEggConverter &copy) :
31 {
32 }
33 
34 /**
35  *
36  */
37 DXFToEggConverter::
38 ~DXFToEggConverter() {
39 }
40 
41 /**
42  * Allocates and returns a new copy of the converter.
43  */
46  return new DXFToEggConverter(*this);
47 }
48 
49 
50 /**
51  * Returns the English name of the file type this converter supports.
52  */
53 std::string DXFToEggConverter::
54 get_name() const {
55  return "DXF";
56 }
57 
58 /**
59  * Returns the common extension of the file type this converter supports.
60  */
61 std::string DXFToEggConverter::
62 get_extension() const {
63  return "dxf";
64 }
65 
66 /**
67  * Returns true if this file type can transparently load compressed files
68  * (with a .pz extension), false otherwise.
69  */
72  return true;
73 }
74 
75 /**
76  * Handles the reading of the input file and converting it to egg. Returns
77  * true if successful, false otherwise.
78  */
80 convert_file(const Filename &filename) {
81  clear_error();
82 
83  if (_egg_data->get_coordinate_system() == CS_default) {
84  _egg_data->set_coordinate_system(CS_zup_right);
85  }
86 
87  process(filename);
88  return !had_error();
89 }
90 
91 /**
92  *
93  */
94 DXFLayer *DXFToEggConverter::
95 new_layer(const std::string &name) {
96  return new DXFToEggLayer(name, get_egg_data());
97 }
98 
99 /**
100  * If the entity is a polygon, creates the corresponding egg polygon.
101  */
102 void DXFToEggConverter::
103 done_entity() {
104  if (_entity == EN_polyline) {
105  // A Polyline is either an unclosed series of connected line segments, or
106  // a closed polygon of arbitrary complexity.
107 
108  if ((_flags & PF_3d) == 0) {
109  // it's a 2-d polygon; convert it to 3-d coordinates.
110  ocs_2_wcs();
111  }
112 
113  if (_flags & PF_closed) {
114  // it's closed; create a polygon.
115  nassertv(_layer!=nullptr);
116  ((DXFToEggLayer *)_layer)->add_polygon(this);
117  } else {
118  // It's open; create a series of line segments.
119  nassertv(_layer!=nullptr);
120  ((DXFToEggLayer *)_layer)->add_line(this);
121  }
122 
123  } else if (_entity == EN_3dface) {
124  // DXF can also represent a polygon as a 3DFace. This might be either a
125  // quad or a triangle (if two of the vertices are the same). We'll add
126  // the vertices to our list of vertices and then define the polygon.
127  _verts.clear();
128  _verts.push_back(DXFVertex(_s));
129  _verts.push_back(DXFVertex(_r));
130  _verts.push_back(DXFVertex(_q));
131  _verts.push_back(DXFVertex(_p));
132 
133  nassertv(_layer!=nullptr);
134  ((DXFToEggLayer *)_layer)->add_polygon(this);
135  }
136 }
137 
138 /**
139  * A hook for user code, if desired. This function is called when some
140  * unexpected error occurs while reading the DXF file.
141  */
142 void DXFToEggConverter::
143 error() {
144  _error = true;
145 }
This represents a "layer" as read from the DXF file.
Definition: dxfLayer.h:28
bool had_error() const
Returns true if an error was detected during the conversion process (unless _allow_errors is true),...
virtual std::string get_extension() const
Returns the common extension of the file type this converter supports.
EggData * get_egg_data()
Returns the EggData structure.
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz extension),...
virtual std::string get_name() const
Returns the English name of the file type this converter supports.
The specialization of DXFLayer used by DXFToEggConverter.
Definition: dxfToEggLayer.h:35
void clear_error()
Resets the error flag to the no-error state.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool convert_file(const Filename &filename)
Handles the reading of the input file and converting it to egg.
virtual SomethingToEggConverter * make_copy()
Allocates and returns a new copy of the converter.
Stored within DXFFile, this is the basic Vertex data of a DXF file.
Definition: dxfVertex.h:27
void ocs_2_wcs()
Assuming the current entity is a planar-based entity, for instance, a 2-d polygon (as opposed to a 3-...
Definition: dxfFile.cxx:482
void process(Filename filename)
Opens the indicated filename and reads it as a DXF file.
Definition: dxfFile.cxx:310
This is a base class for a family of converter classes that manage a conversion from some file type t...
This class supervises the construction of an EggData structure from a DXF file.