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 #ifndef DXF_TABLE 14 #define DXF_TABLE 1 15 16 #include <string> 17 #include <map> 18 19 #include <osg/Referenced> 20 #include <osg/ref_ptr> 21 22 class dxfFile; 23 class codeValue; 24 25 // special case: the layer table 26 27 class dxfTable : public osg::Referenced 28 { 29 public: dxfTable()30 dxfTable() {} ~dxfTable()31 virtual ~dxfTable() {} assign(dxfFile *,codeValue &)32 virtual void assign(dxfFile* , codeValue& ) { } 33 }; 34 35 36 class dxfLayer : public osg::Referenced 37 { 38 public: _name(name)39 dxfLayer(std::string name = "0") : _name(name), _color(7), _frozen(false) {} ~dxfLayer()40 virtual ~dxfLayer() {} 41 virtual void assign(dxfFile* dxf, codeValue& cv); getName()42 virtual const std::string& getName() const { return _name; } getColor()43 virtual const unsigned short& getColor() const { return _color; } setName(const std::string & name)44 virtual void setName(const std::string& name) { _name = name; } getFrozen()45 const bool& getFrozen() const { return _frozen; } 46 protected: 47 std::string _name; 48 unsigned short _color; 49 bool _frozen; 50 }; 51 52 class dxfLayerTable : public dxfTable 53 { 54 public: dxfLayerTable()55 dxfLayerTable() {} ~dxfLayerTable()56 virtual ~dxfLayerTable() {} 57 virtual void assign(dxfFile* dxf, codeValue& cv); 58 findOrCreateLayer(std::string name)59 dxfLayer* findOrCreateLayer(std::string name) 60 { 61 if (name == "") name = "0"; // nowhere it is said "" is invalid, but... 62 dxfLayer* layer = _layers[name].get(); 63 if (!layer) { 64 layer = new dxfLayer; 65 _layers[name] = layer; 66 } 67 return layer; 68 } 69 70 protected: 71 std::map<std::string, osg::ref_ptr<dxfLayer> > _layers; 72 osg::ref_ptr<dxfLayer> _currentLayer; 73 }; 74 75 #endif 76