Panda3D

dxfToEggConverter.cxx

00001 // Filename: dxfToEggConverter.cxx
00002 // Created by:  drose (04May04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "dxfToEggConverter.h"
00016 #include "dxfToEggLayer.h"
00017 #include "eggData.h"
00018 
00019 ////////////////////////////////////////////////////////////////////
00020 //     Function: DXFToEggConverter::Constructor
00021 //       Access: Public
00022 //  Description:
00023 ////////////////////////////////////////////////////////////////////
00024 DXFToEggConverter::
00025 DXFToEggConverter() {
00026 }
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: DXFToEggConverter::Copy Constructor
00030 //       Access: Public
00031 //  Description:
00032 ////////////////////////////////////////////////////////////////////
00033 DXFToEggConverter::
00034 DXFToEggConverter(const DXFToEggConverter &copy) :
00035   SomethingToEggConverter(copy)
00036 {
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: DXFToEggConverter::Destructor
00041 //       Access: Public
00042 //  Description:
00043 ////////////////////////////////////////////////////////////////////
00044 DXFToEggConverter::
00045 ~DXFToEggConverter() {
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: DXFToEggConverter::make_copy
00050 //       Access: Public, Virtual
00051 //  Description: Allocates and returns a new copy of the converter.
00052 ////////////////////////////////////////////////////////////////////
00053 SomethingToEggConverter *DXFToEggConverter::
00054 make_copy() {
00055   return new DXFToEggConverter(*this);
00056 }
00057 
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //     Function: DXFToEggConverter::get_name
00061 //       Access: Public, Virtual
00062 //  Description: Returns the English name of the file type this
00063 //               converter supports.
00064 ////////////////////////////////////////////////////////////////////
00065 string DXFToEggConverter::
00066 get_name() const {
00067   return "DXF";
00068 }
00069 
00070 ////////////////////////////////////////////////////////////////////
00071 //     Function: DXFToEggConverter::get_extension
00072 //       Access: Public, Virtual
00073 //  Description: Returns the common extension of the file type this
00074 //               converter supports.
00075 ////////////////////////////////////////////////////////////////////
00076 string DXFToEggConverter::
00077 get_extension() const {
00078   return "dxf";
00079 }
00080 
00081 ////////////////////////////////////////////////////////////////////
00082 //     Function: DXFToEggConverter::supports_compressed
00083 //       Access: Published, Virtual
00084 //  Description: Returns true if this file type can transparently load
00085 //               compressed files (with a .pz extension), false
00086 //               otherwise.
00087 ////////////////////////////////////////////////////////////////////
00088 bool DXFToEggConverter::
00089 supports_compressed() const {
00090   return true;
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: DXFToEggConverter::convert_file
00095 //       Access: Public, Virtual
00096 //  Description: Handles the reading of the input file and converting
00097 //               it to egg.  Returns true if successful, false
00098 //               otherwise.
00099 ////////////////////////////////////////////////////////////////////
00100 bool DXFToEggConverter::
00101 convert_file(const Filename &filename) {
00102   clear_error();
00103 
00104   if (_egg_data->get_coordinate_system() == CS_default) {
00105     _egg_data->set_coordinate_system(CS_zup_right);
00106   }
00107 
00108   process(filename);
00109   return !had_error();
00110 }
00111 
00112 ////////////////////////////////////////////////////////////////////
00113 //     Function: DXFToEggConverter::new_layer
00114 //       Access: Protected, Virtual
00115 //  Description: 
00116 ////////////////////////////////////////////////////////////////////
00117 DXFLayer *DXFToEggConverter::
00118 new_layer(const string &name) {
00119   return new DXFToEggLayer(name, get_egg_data());
00120 }
00121 
00122 ////////////////////////////////////////////////////////////////////
00123 //     Function: DXFToEggConverter::done_entity
00124 //       Access: Protected, Virtual
00125 //  Description: If the entity is a polygon, creates the corresponding
00126 //               egg polygon.
00127 ////////////////////////////////////////////////////////////////////
00128 void DXFToEggConverter::
00129 done_entity() {
00130   if (_entity == EN_polyline) {
00131     // A Polyline is either an unclosed series of connected line
00132     // segments, or a closed polygon of arbitrary complexity.
00133 
00134     if ((_flags & PF_3d) == 0) {
00135       // it's a 2-d polygon; convert it to 3-d coordinates.
00136       ocs_2_wcs();
00137     }
00138 
00139     if (_flags & PF_closed) {
00140       // it's closed; create a polygon.
00141       nassertv(_layer!=NULL);
00142       ((DXFToEggLayer *)_layer)->add_polygon(this);
00143     } else {
00144       // It's open; create a series of line segments.
00145       nassertv(_layer!=NULL);
00146       ((DXFToEggLayer *)_layer)->add_line(this);
00147     }
00148 
00149   } else if (_entity == EN_3dface) {
00150     // DXF can also represent a polygon as a 3DFace.  This might be
00151     // either a quad or a triangle (if two of the vertices are the
00152     // same).  We'll add the vertices to our list of vertices and then
00153     // define the polygon.
00154     _verts.clear();
00155     _verts.push_back(DXFVertex(_s));
00156     _verts.push_back(DXFVertex(_r));
00157     _verts.push_back(DXFVertex(_q));
00158     _verts.push_back(DXFVertex(_p));
00159     
00160     nassertv(_layer!=NULL);
00161     ((DXFToEggLayer *)_layer)->add_polygon(this);
00162   }
00163 }
00164 
00165 ////////////////////////////////////////////////////////////////////
00166 //     Function: DXFToEggConverter::done_entity
00167 //       Access: Protected, Virtual
00168 //  Description: A hook for user code, if desired.  This function is
00169 //               called when some unexpected error occurs while
00170 //               reading the DXF file.
00171 ////////////////////////////////////////////////////////////////////
00172 void DXFToEggConverter::
00173 error() {
00174   _error = true;
00175 }
 All Classes Functions Variables Enumerations