dxfrenderer.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dxfrenderer.h
  3. // Purpose: DXF reader and renderer
  4. // Author: Sandro Sigala
  5. // Modified by:
  6. // Created: 2005-11-10
  7. // Copyright: (c) Sandro Sigala
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _DXFRENDERER_H_
  11. #define _DXFRENDERER_H_
  12. struct DXFVector
  13. {
  14. DXFVector() { x = y = z = 0.0f; }
  15. DXFVector(float _x, float _y, float _z) { x = _x; y = _y; z = _z; }
  16. float x, y, z;
  17. };
  18. struct DXFEntity
  19. {
  20. enum Type { Line, Face } type;
  21. int colour;
  22. };
  23. struct DXFLine: public DXFEntity
  24. {
  25. DXFLine() { type = Line; }
  26. DXFVector v0;
  27. DXFVector v1;
  28. };
  29. struct DXFFace: public DXFEntity
  30. {
  31. DXFFace() { type = Face; }
  32. void CalculateNormal();
  33. DXFVector v0;
  34. DXFVector v1;
  35. DXFVector v2;
  36. DXFVector v3;
  37. DXFVector n; // normal
  38. };
  39. struct DXFLayer
  40. {
  41. DXFLayer() { colour = -1; }
  42. wxString name;
  43. int colour;
  44. };
  45. WX_DECLARE_LIST(DXFEntity, DXFEntityList);
  46. WX_DECLARE_LIST(DXFLayer, DXFLayerList);
  47. class DXFRenderer
  48. {
  49. public:
  50. DXFRenderer();
  51. ~DXFRenderer();
  52. void Clear();
  53. bool Load(wxInputStream& stream);
  54. bool IsOk() const { return m_loaded; }
  55. void Render() const;
  56. private:
  57. bool ParseHeader(wxInputStream& stream);
  58. bool ParseTables(wxInputStream& stream);
  59. bool ParseEntities(wxInputStream& stream);
  60. int GetLayerColour(const wxString& layer) const;
  61. void NormalizeEntities();
  62. bool m_loaded;
  63. DXFLayerList m_layers;
  64. DXFEntityList m_entities;
  65. };
  66. #endif // !_DXFRENDERER_H_