root/OpenSceneGraph/trunk/src/osgPlugins/dxf/dxfFile.cpp @ 11112

Revision 11112, 3.4 kB (checked in by robert, 5 years ago)

From Simon Buckley, "Attached is a small change to the file src\osgPlugins\dxf\dxfFile.cpp that allows the dxf reader to skip comments in a dxf file. I found with the existing version and a test file I had that the loader failed when comments were present. I made a very minor change to allow "999" comment codes to be skipped rather than causing load failure."

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* dxfReader for OpenSceneGraph  Copyright (C) 2005 by GraphArchitecture ( grapharchitecture.com )
2 * Programmed by Paul de Repentigny <pdr@grapharchitecture.com>
3 *
4 * OpenSceneGraph is (C) 2004 Robert Osfield
5 *
6 * This library is provided as-is, without support of any kind.
7 *
8 * Read DXF docs or OSG docs for any related questions.
9 *
10 * You may contact the author if you have suggestions/corrections/enhancements.
11 */
12
13#include "dxfFile.h"
14#include "dxfReader.h"
15#include "dxfBlock.h"
16#include "dxfEntity.h"
17#include "dxfDataTypes.h"
18#include "scene.h"
19#include "codeValue.h"
20
21#include <osg/Group>
22
23using namespace std;
24
25bool   
26dxfFile::parseFile()
27{
28    if (_fileName == "") return false;
29    _reader = new dxfReader;
30   
31    if (_reader->openFile(_fileName)) {
32        codeValue cv;
33        while(_reader->nextGroupCode(cv)) {
34            short result = assign(cv);
35            if (result < 0)
36                return false;
37            else if (result == 0) {
38                return true;
39            }
40        }
41        // we did not reach 0 EOF
42        return false;
43    } else {
44        return false;
45    }
46}
47
48osg::Group*
49dxfFile::dxf2osg()
50{
51    if (!_entities) return NULL;
52    if (!_tables) { // a dxfTable is needed to create undefined layers
53        _tables = new dxfTables;
54    }
55    osg::ref_ptr<dxfLayerTable> layerTable = _tables->getOrCreateLayerTable();
56    // to do: should be more general and pass a pointer to ourselves
57    // which in turn should be able to feed any information
58    // the scene might need
59    _scene = new scene(layerTable.get());
60    _entities->drawScene(_scene.get());
61    osg::Group* g = _scene->scene2osg();
62    return g;
63}
64
65dxfBlock*   
66dxfFile::findBlock(std::string name)
67{
68    if (_blocks.get())
69        return _blocks->findBlock(name);
70    return NULL;
71}
72
73/// not used. if you want to know what a header variable
74/// contains, call this. pass the complete variable name
75/// including "$", for example: "$EXTMAX"
76VariableList
77dxfFile::getVariable(std::string var)
78{
79    return _header->getVariable(var);
80}
81
82/// parse the dxf sections
83short 
84dxfFile::assign(codeValue& cv)
85{
86    std::string s = cv._string;
87    if (cv._groupCode == 0 && s == std::string("ENDSEC")) {
88        _isNewSection = false;
89        _current = _unknown.get();
90    } else if (cv._groupCode == 0 && s == std::string("SECTION")) {
91        _isNewSection = true;
92    } else if (cv._groupCode == 0 && s == std::string("EOF")) {
93        return 0;
94    } else if (cv._groupCode == 999) {    // skip comments
95    } else if (cv._groupCode == 2 && _isNewSection) {
96        _isNewSection = false;
97//        std::cout << "Reading section " << s << std::endl;
98        if (s =="HEADER") {
99            _header = new dxfHeader;
100            _current = _header.get();
101        } else if (s =="TABLES") {
102            _tables = new dxfTables;
103            _current = _tables.get();
104        } else if (s =="BLOCKS") {
105            _blocks = new dxfBlocks;
106            _current = _blocks.get();
107        } else if (s =="ENTITIES") {
108            _entities = new dxfEntities;
109            _current = _entities.get();
110        } else {
111            _current = _unknown.get();
112        }
113    } else if (_isNewSection) {
114        // problem. a 0/SECTION should be followed by a 2/SECTION_NAME
115        std::cout << "No groupcode for changing section " << cv._groupCode << " value: " << s << std::endl;
116        return -1;
117    } else if (_current.get()) {
118        _current->assign(this, cv);
119    }
120    return 1;
121}
Note: See TracBrowser for help on using the browser.