- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/dxf/ReaderWriterDXF.cpp
r10329 r13041 1 1 /* dxfReader for OpenSceneGraph Copyright (C) 2005 by GraphArchitecture ( grapharchitecture.com ) 2 2 * Programmed by Paul de Repentigny <pdr@grapharchitecture.com> 3 * 3 * 4 4 * OpenSceneGraph is (C) 2004 Robert Osfield 5 * 5 * 6 6 * This library is provided as-is, without support of any kind. 7 7 * 8 8 * Read DXF docs or OSG docs for any related questions. 9 * 9 * 10 10 * You may contact the author if you have suggestions/corrections/enhancements. 11 11 */ … … 38 38 supportsExtension("dxf","Autodesk DXF format"); 39 39 } 40 40 41 41 virtual const char* className() { return "Autodesk DXF Reader/Writer"; } 42 42 virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*) const; 43 43 44 44 45 virtual WriteResult writeObject(const osg::Object& obj,const std::string& fileName,const Options* options=NULL) const 45 virtual WriteResult writeObject(const osg::Object& obj,const std::string& fileName,const Options* options=NULL) const 46 46 { 47 47 const osg::Node* node = dynamic_cast<const osg::Node*>(&obj); 48 48 if (node) 49 49 return writeNode(*node, fileName, options); 50 else 51 return WriteResult(WriteResult::FILE_NOT_HANDLED); 50 else 51 return WriteResult(WriteResult::FILE_NOT_HANDLED); 52 52 } 53 54 55 virtual WriteResult writeObject(const osg::Object& obj,std::ostream& fout,const Options* options=NULL) const 53 54 55 virtual WriteResult writeObject(const osg::Object& obj,std::ostream& fout,const Options* options=NULL) const 56 56 { 57 57 const osg::Node* node = dynamic_cast<const osg::Node*>(&obj); 58 58 if (node) 59 59 return writeNode(*node, fout, options); 60 else 61 return WriteResult(WriteResult::FILE_NOT_HANDLED); 60 else 61 return WriteResult(WriteResult::FILE_NOT_HANDLED); 62 62 } 63 63 64 virtual WriteResult writeNode(const osg::Node& node,std::ostream& fout,const Options* =NULL) const 65 { 64 virtual WriteResult writeNode(const osg::Node& node,std::ostream& fout,const Options* =NULL) const 65 { 66 66 67 68 DXFWriterNodeVisitor nv(fout); 67 68 DXFWriterNodeVisitor nv(fout); 69 69 70 70 (const_cast<osg::Node*>(&node))->accept(nv); // first pass is to get all node names and types -> layers … … 74 74 nv.writeFooter(); 75 75 } 76 77 return WriteResult(WriteResult::FILE_SAVED); 76 77 return WriteResult(WriteResult::FILE_SAVED); 78 78 } 79 79 80 virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options =NULL) const 81 { 80 virtual WriteResult writeNode(const osg::Node& node,const std::string& fileName,const Options* options =NULL) const 81 { 82 82 if (!acceptsExtension(osgDB::getFileExtension(fileName))) 83 83 return WriteResult(WriteResult::FILE_NOT_HANDLED); 84 84 85 85 osgDB::ofstream f(fileName.c_str()); 86 86 87 87 if (!f.is_open() ) { 88 88 return WriteResult(WriteResult::ERROR_IN_WRITING_FILE); 89 89 } 90 DXFWriterNodeVisitor nv(f); 91 90 DXFWriterNodeVisitor nv(f); 91 92 92 (const_cast<osg::Node*>(&node))->accept(nv); // first pass is to get all node names and types -> layers 93 93 … … 97 97 } 98 98 99 return WriteResult(WriteResult::FILE_SAVED); 99 return WriteResult(WriteResult::FILE_SAVED); 100 100 } 101 101 … … 108 108 109 109 // read file and convert to OSG. 110 osgDB::ReaderWriter::ReadResult 110 osgDB::ReaderWriter::ReadResult 111 111 ReaderWriterdxf::readNode(const std::string& filename, const osgDB::ReaderWriter::Options* options) const 112 112 { … … 120 120 bool improveAccuracyOnly=false; // if true only use the given accuracy if it would improve the curve compared to the previous implementation 121 121 // Thus you can ensure that large curves get rendered better but small ones don't get worse 122 122 123 123 std::string optionsstring=options->getOptionString(); 124 124 125 125 size_t accstart=optionsstring.find("Accuracy("); 126 126 if (accstart>=0) { … … 132 132 if (optionsstring.find("ImproveAccuracyOnly") != std::string::npos) { 133 133 improveAccuracyOnly=true; 134 } 135 // Pull out the initial dxfArc copy from the registry and set accuracy there. 134 } 135 // Pull out the initial dxfArc copy from the registry and set accuracy there. 136 136 // When actual dxfArcs/Circles are created they will inherit these parameters from the exemplar 137 137 dxfEntity::getRegistryEntity("ARC")->setAccuracy(true,maxError,improveAccuracyOnly); 138 dxfEntity::getRegistryEntity("CIRCLE")->setAccuracy(true,maxError,improveAccuracyOnly); 138 dxfEntity::getRegistryEntity("CIRCLE")->setAccuracy(true,maxError,improveAccuracyOnly); 139 139 } // accuracy options exists 140 140 } // options exist
