Seamly2D
Code documentation
dxiface.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** **
3 ** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com **
4 ** **
5 ** This library is free software, licensed under the terms of the GNU **
6 ** General Public License as published by the Free Software Foundation, **
7 ** either version 2 of the License, or (at your option) any later version. **
8 ** You should have received a copy of the GNU General Public License **
9 ** along with this program. If not, see <http://www.gnu.org/licenses/>. **
10 ******************************************************************************/
11 
12 #ifndef DX_IFACE_H
13 #define DX_IFACE_H
14 
15 #include "libdxfrw/drw_interface.h"
16 #include "libdxfrw/libdxfrw.h"
17 #include "dxfdef.h"
18 
19 class QFont;
20 
21 //class to store image data and path from DRW_ImageDef
22 class dx_ifaceImg : public DRW_Image {
23 public:
25  : path()
26  {}
27 
28  explicit dx_ifaceImg(const DRW_Image& p)
29  : DRW_Image(p),
30  path()
31  {}
32 
33  virtual ~dx_ifaceImg() = default;
34  std::string path; //stores the image path
35 };
36 
37 //container class to store entites.
38 class dx_ifaceBlock : public DRW_Block {
39 public:
41  : ent()
42  {}
43 
44  explicit dx_ifaceBlock(const DRW_Block& p)
45  : DRW_Block(p),
46  ent()
47  {}
48 
49  virtual ~dx_ifaceBlock(){
50  for (std::list<DRW_Entity*>::const_iterator it=ent.begin(); it!=ent.end(); ++it)
51  delete *it;
52  }
53  std::list<DRW_Entity*>ent; //stores the entities list
54 };
55 
56 
57 //container class to store full dxf data.
58 class dx_data {
59 public:
61  : headerC(),
62  lineTypes(),
63  layers(),
64  dimStyles(),
65  VPorts(),
66  textStyles(),
67  appIds(),
68  blocks(),
69  images(),
70  mBlock(new dx_ifaceBlock())
71  {}
72 
74  //cleanup,
75  for (std::list<dx_ifaceBlock*>::const_iterator it=blocks.begin(); it!=blocks.end(); ++it)
76  delete *it;
77  delete mBlock;
78  }
79 
80  DRW_Header headerC; //stores a copy of the header vars
81  std::list<DRW_LType>lineTypes; //stores a copy of all line types
82  std::list<DRW_Layer>layers; //stores a copy of all layers
83  std::list<DRW_Dimstyle>dimStyles; //stores a copy of all dimension styles
84  std::list<DRW_Vport>VPorts; //stores a copy of all vports
85  std::list<DRW_Textstyle>textStyles; //stores a copy of all text styles
86  std::list<DRW_AppId>appIds; //stores a copy of all line types
87  std::list<dx_ifaceBlock*>blocks; //stores a copy of all blocks and the entities in it
88  std::list<dx_ifaceImg*>images; //temporary list to find images for link with DRW_ImageDef. Do not delete it!!
89 
90  dx_ifaceBlock* mBlock; //container to store model entities
91 private:
92  Q_DISABLE_COPY(dx_data)
93 
94 };
95 
96 class dx_iface : public DRW_Interface
97 {
98 public:
99  dx_iface(const std::string& file, DRW::Version v, VarMeasurement varMeasurement, VarInsunits varInsunits);
100  virtual ~dx_iface();
101  bool fileExport(bool binary);
102  void writeEntity(DRW_Entity* e);
103 
104 //reimplement virtual DRW_Interface functions
105 //writer part, send all in class dx_data to writer
106  virtual void writeHeader(DRW_Header& data);
107  virtual void writeBlocks();
108  //only send the name, needed by the reader to prepare handles of blocks & blockRecords
109  virtual void writeBlockRecords();
110  //write entities of model space and first paper_space
111  virtual void writeEntities();
112  virtual void writeLTypes();
113  virtual void writeLayers();
114  virtual void writeTextstyles();
115  virtual void writeVports();
116  virtual void writeDimstyles();
117  virtual void writeAppId();
118 
119  void AddEntity(DRW_Entity* e);
120  UTF8STRING AddFont(const QFont &f);
121  void AddBlock(dx_ifaceBlock* block);
122 
123  void AddQtLTypes();
124  void AddDefLayers();
125  void AddAAMALayers();
126  void AddAAMAHeaderData();
127 
128 private:
129  Q_DISABLE_COPY(dx_iface)
130  dxfRW* dxfW; //pointer to writer, needed to send data
131  dx_data cData; // class to store or read data
132  DRW::Version version;
133 
134  void InitHeader(VarMeasurement varMeasurement, VarInsunits varInsunits);
135  void InitTextstyles();
136  void InitAppId();
137 
138  static std::string LocaleToISO();
139 };
140 
141 #endif // DX_IFACE_H
dx_ifaceBlock * mBlock
Definition: dxiface.h:90
std::list< dx_ifaceImg * > images
Definition: dxiface.h:88
DRW_Header headerC
Definition: dxiface.h:80
std::list< DRW_AppId > appIds
Definition: dxiface.h:86
std::list< DRW_Dimstyle > dimStyles
Definition: dxiface.h:83
dx_data()
Definition: dxiface.h:60
~dx_data()
Definition: dxiface.h:73
std::list< DRW_Vport > VPorts
Definition: dxiface.h:84
std::list< dx_ifaceBlock * > blocks
Definition: dxiface.h:87
std::list< DRW_LType > lineTypes
Definition: dxiface.h:81
std::list< DRW_Layer > layers
Definition: dxiface.h:82
std::list< DRW_Textstyle > textStyles
Definition: dxiface.h:85
virtual ~dx_ifaceBlock()
Definition: dxiface.h:49
std::list< DRW_Entity * > ent
Definition: dxiface.h:53
dx_ifaceBlock()
Definition: dxiface.h:40
dx_ifaceBlock(const DRW_Block &p)
Definition: dxiface.h:44
dx_ifaceImg()
Definition: dxiface.h:24
std::string path
Definition: dxiface.h:34
dx_ifaceImg(const DRW_Image &p)
Definition: dxiface.h:28
virtual ~dx_ifaceImg()=default
DRW::Version version
Definition: dxiface.h:132
virtual void writeAppId()
Definition: dxiface.cpp:163
void AddBlock(dx_ifaceBlock *block)
Definition: dxiface.cpp:349
void InitTextstyles()
Definition: dxiface.cpp:294
void InitAppId()
Definition: dxiface.cpp:304
void AddQtLTypes()
Definition: dxiface.cpp:193
virtual void writeVports()
Definition: dxiface.cpp:153
virtual void writeDimstyles()
Definition: dxiface.cpp:158
dx_data cData
Definition: dxiface.h:131
void AddEntity(DRW_Entity *e)
Definition: dxiface.cpp:311
void AddDefLayers()
Definition: dxiface.cpp:285
dxfRW * dxfW
Definition: dxiface.h:130
virtual void writeEntities()
Definition: dxiface.cpp:133
virtual void writeLTypes()
Definition: dxiface.cpp:138
virtual void writeHeader(DRW_Header &data)
Definition: dxiface.cpp:109
virtual void writeLayers()
Definition: dxiface.cpp:143
bool fileExport(bool binary)
Definition: dxiface.cpp:37
void writeEntity(DRW_Entity *e)
Definition: dxiface.cpp:43
UTF8STRING AddFont(const QFont &f)
Definition: dxiface.cpp:316
dx_iface(const std::string &file, DRW::Version v, VarMeasurement varMeasurement, VarInsunits varInsunits)
Definition: dxiface.cpp:22
void AddAAMALayers()
Definition: dxiface.cpp:238
virtual ~dx_iface()
Definition: dxiface.cpp:32
virtual void writeBlockRecords()
Definition: dxiface.cpp:128
void InitHeader(VarMeasurement varMeasurement, VarInsunits varInsunits)
Definition: dxiface.cpp:168
virtual void writeBlocks()
Definition: dxiface.cpp:117
void AddAAMAHeaderData()
Definition: dxiface.cpp:280
virtual void writeTextstyles()
Definition: dxiface.cpp:148
static std::string LocaleToISO()
Definition: dxiface.cpp:354
VarMeasurement
Definition: dxfdef.h:61
VarInsunits
Definition: dxfdef.h:64