| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 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 | |
|---|
| 23 | using namespace std; |
|---|
| 24 | |
|---|
| 25 | bool |
|---|
| 26 | dxfFile::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 | |
|---|
| 42 | return false; |
|---|
| 43 | } else { |
|---|
| 44 | return false; |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | osg::Group* |
|---|
| 49 | dxfFile::dxf2osg() |
|---|
| 50 | { |
|---|
| 51 | if (!_entities) return NULL; |
|---|
| 52 | if (!_tables) { |
|---|
| 53 | _tables = new dxfTables; |
|---|
| 54 | } |
|---|
| 55 | osg::ref_ptr<dxfLayerTable> layerTable = _tables->getOrCreateLayerTable(); |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | _scene = new scene(layerTable.get()); |
|---|
| 60 | _entities->drawScene(_scene.get()); |
|---|
| 61 | osg::Group* g = _scene->scene2osg(); |
|---|
| 62 | return g; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | dxfBlock* |
|---|
| 66 | dxfFile::findBlock(std::string name) |
|---|
| 67 | { |
|---|
| 68 | if (_blocks.get()) |
|---|
| 69 | return _blocks->findBlock(name); |
|---|
| 70 | return NULL; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | VariableList |
|---|
| 77 | dxfFile::getVariable(std::string var) |
|---|
| 78 | { |
|---|
| 79 | return _header->getVariable(var); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | short |
|---|
| 84 | dxfFile::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 | |
|---|
| 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 | |
|---|
| 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 | } |
|---|