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

Revision 4801, 3.4 kB (checked in by robert, 8 years ago)

Replaced tabs with spaces.

  • 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 == 2 && _isNewSection) {
95        _isNewSection = false;
96//        std::cout << "Reading section " << s << std::endl;
97        if (s =="HEADER") {
98            _header = new dxfHeader;
99            _current = _header.get();
100        } else if (s =="TABLES") {
101            _tables = new dxfTables;
102            _current = _tables.get();
103        } else if (s =="BLOCKS") {
104            _blocks = new dxfBlocks;
105            _current = _blocks.get();
106        } else if (s =="ENTITIES") {
107            _entities = new dxfEntities;
108            _current = _entities.get();
109        } else {
110            _current = _unknown.get();
111        }
112    } else if (_isNewSection) {
113        // problem. a 0/SECTION should be followed by a 2/SECTION_NAME
114        std::cout << "No groupcode for changing section " << cv._groupCode << " value: " << s << std::endl;
115        return -1;
116    } else if (_current.get()) {
117        _current->assign(this, cv);
118    }
119    return 1;
120}
Note: See TracBrowser for help on using the browser.