ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
dl_writer.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
3 ** Copyright (C) 2001 Robert J. Campbell Jr.
4 **
5 ** This file is part of the dxflib project.
6 **
7 ** This file is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
11 **
12 ** Licensees holding valid dxflib Professional Edition licenses may use
13 ** this file in accordance with the dxflib Commercial License
14 ** Agreement provided with the Software.
15 **
16 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 **
19 ** See http://www.ribbonsoft.com for further details.
20 **
21 ** Contact info@ribbonsoft.com if any conditions of this licensing are
22 ** not clear to you.
23 **
24 **********************************************************************/
25 
26 #ifndef DL_WRITER_H
27 #define DL_WRITER_H
28 
29 #include "dl_global.h"
30 
31 #ifndef _WIN32
32 #include <strings.h>
33 #endif
34 
35 #if _MSC_VER > 1000
36 #pragma once
37 #endif // _MSC_VER > 1000
38 
39 #include <algorithm>
40 #include <iostream>
41 
42 #include "dl_attributes.h"
43 #include "dl_codes.h"
44 
56 public:
60  DL_Writer(DL_Codes::version version) : m_handle(0x30) {
61  this->version = version;
62  modelSpaceHandle = 0;
63  paperSpaceHandle = 0;
64  paperSpace0Handle = 0;
65  }
66 
67  virtual ~DL_Writer() {};
68 
78  void section(const char* name) const {
79  dxfString(0, "SECTION");
80  dxfString(2, name);
81  }
82 
93  void sectionHeader() const { section("HEADER"); }
94 
105  void sectionTables() const { section("TABLES"); }
106 
117  void sectionBlocks() const { section("BLOCKS"); }
118 
129  void sectionEntities() const { section("ENTITIES"); }
130 
141  void sectionClasses() const { section("CLASSES"); }
142 
153  void sectionObjects() const { section("OBJECTS"); }
154 
163  void sectionEnd() const { dxfString(0, "ENDSEC"); }
164 
177  void table(const char* name, int num, int h = 0) const {
178  dxfString(0, "TABLE");
179  dxfString(2, name);
180  if (version >= DL_VERSION_2000) {
181  if (h == 0) {
182  handle();
183  } else {
184  dxfHex(5, h);
185  }
186  dxfString(100, "AcDbSymbolTable");
187  }
188  dxfInt(70, num);
189  }
190 
204  void tableLayers(int num) const { table("LAYER", num, 2); }
205 
219  void tableLinetypes(int num) const {
220  // linetypeHandle = 5;
221  table("LTYPE", num, 5);
222  }
223 
237  void tableAppid(int num) const { table("APPID", num, 9); }
238 
252  void tableStyle(int num) const { table("STYLE", num, 3); }
253 
262  void tableEnd() const { dxfString(0, "ENDTAB"); }
263 
272  void dxfEOF() const { dxfString(0, "EOF"); }
273 
282  void comment(const char* text) const { dxfString(999, text); }
283 
294  void entity(const char* entTypeName) const {
295  dxfString(0, entTypeName);
296  if (version >= DL_VERSION_2000) {
297  handle();
298  }
299  }
300 
315  void entityAttributes(const DL_Attributes& attrib) const {
316  // layer name:
317  dxfString(8, attrib.getLayer());
318 
319  // R12 doesn't accept BYLAYER values. The value has to be missing
320  // in that case.
321  if (version >= DL_VERSION_2000 || attrib.getColor() != 256) {
322  dxfInt(62, attrib.getColor());
323  }
324  if (version >= DL_VERSION_2000 && attrib.getColor24() != -1) {
325  dxfInt(420, attrib.getColor24());
326  }
327  if (version >= DL_VERSION_2000) {
328  dxfInt(370, attrib.getWidth());
329  }
330  if (version >= DL_VERSION_2000) {
331  dxfReal(48, attrib.getLinetypeScale());
332  }
333  std::string linetype = attrib.getLinetype();
334  std::transform(linetype.begin(), linetype.end(), linetype.begin(),
335  ::toupper);
336  if (version >= DL_VERSION_2000 || linetype == "BYLAYER") {
337  dxfString(6, attrib.getLinetype());
338  }
339  }
340 
344  void subClass(const char* sub) const { dxfString(100, sub); }
345 
354  void tableLayerEntry(unsigned long int h = 0) const {
355  dxfString(0, "LAYER");
356  if (version >= DL_VERSION_2000) {
357  if (h == 0) {
358  handle();
359  } else {
360  dxfHex(5, h);
361  }
362  dxfString(100, "AcDbSymbolTableRecord");
363  dxfString(100, "AcDbLayerTableRecord");
364  }
365  }
366 
375  void tableLinetypeEntry(unsigned long int h = 0) const {
376  dxfString(0, "LTYPE");
377  if (version >= DL_VERSION_2000) {
378  if (h == 0) {
379  handle();
380  } else {
381  dxfHex(5, h);
382  }
383  // dxfHex(330, 0x5);
384  dxfString(100, "AcDbSymbolTableRecord");
385  dxfString(100, "AcDbLinetypeTableRecord");
386  }
387  }
388 
397  void tableAppidEntry(unsigned long int h = 0) const {
398  dxfString(0, "APPID");
399  if (version >= DL_VERSION_2000) {
400  if (h == 0) {
401  handle();
402  } else {
403  dxfHex(5, h);
404  }
405  // dxfHex(330, 0x9);
406  dxfString(100, "AcDbSymbolTableRecord");
407  dxfString(100, "AcDbRegAppTableRecord");
408  }
409  }
410 
419  void sectionBlockEntry(unsigned long int h = 0) const {
420  dxfString(0, "BLOCK");
421  if (version >= DL_VERSION_2000) {
422  if (h == 0) {
423  handle();
424  } else {
425  dxfHex(5, h);
426  }
427  // dxfHex(330, blockHandle);
428  dxfString(100, "AcDbEntity");
429  if (h == 0x1C) {
430  dxfInt(67, 1);
431  }
432  dxfString(8, "0"); // TODO: Layer for block
433  dxfString(100, "AcDbBlockBegin");
434  }
435  }
436 
445  void sectionBlockEntryEnd(unsigned long int h = 0) const {
446  dxfString(0, "ENDBLK");
447  if (version >= DL_VERSION_2000) {
448  if (h == 0) {
449  handle();
450  } else {
451  dxfHex(5, h);
452  }
453  // dxfHex(330, blockHandle);
454  dxfString(100, "AcDbEntity");
455  if (h == 0x1D) {
456  dxfInt(67, 1);
457  }
458  dxfString(8, "0"); // TODO: Layer for block
459  dxfString(100, "AcDbBlockEnd");
460  }
461  }
462 
463  void color(int col = 256) const { dxfInt(62, col); }
464  void linetype(const char* lt) const { dxfString(6, lt); }
465  void linetypeScale(double scale) const { dxfReal(48, scale); }
466  void lineWeight(int lw) const { dxfInt(370, lw); }
467 
468  void coord(int gc, double x, double y, double z = 0) const {
469  dxfReal(gc, x);
470  dxfReal(gc + 10, y);
471  dxfReal(gc + 20, z);
472  }
473 
474  void coordTriplet(int gc, const double* value) const {
475  if (value) {
476  dxfReal(gc, *value++);
477  dxfReal(gc + 10, *value++);
478  dxfReal(gc + 20, *value++);
479  }
480  }
481 
482  void resetHandle() const { m_handle = 1; }
483 
487  unsigned long handle(int gc = 5) const {
488  // handle has to be hex
489  dxfHex(gc, m_handle);
490  return m_handle++;
491  }
492 
496  unsigned long getNextHandle() const { return m_handle; }
497 
501  unsigned long incHandle() const { return m_handle++; }
502 
507  void setModelSpaceHandle(unsigned long h) { modelSpaceHandle = h; }
508 
509  unsigned long getModelSpaceHandle() { return modelSpaceHandle; }
510 
515  void setPaperSpaceHandle(unsigned long h) { paperSpaceHandle = h; }
516 
517  unsigned long getPaperSpaceHandle() { return paperSpaceHandle; }
518 
523  void setPaperSpace0Handle(unsigned long h) { paperSpace0Handle = h; }
524 
525  unsigned long getPaperSpace0Handle() { return paperSpace0Handle; }
526 
534  virtual void dxfReal(int gc, double value) const = 0;
535 
543  virtual void dxfInt(int gc, int value) const = 0;
544 
552  virtual void dxfBool(int gc, bool value) const { dxfInt(gc, (int)value); }
553 
561  virtual void dxfHex(int gc, int value) const = 0;
562 
570  virtual void dxfString(int gc, const char* value) const = 0;
571 
579  virtual void dxfString(int gc, const std::string& value) const = 0;
580 
581 protected:
582  mutable unsigned long m_handle;
583  mutable unsigned long modelSpaceHandle;
584  mutable unsigned long paperSpaceHandle;
585  mutable unsigned long paperSpace0Handle;
586 
591 
592 private:
593 };
594 
595 #endif
std::string version
std::string name
std::string getLinetype() const
int getColor() const
int getWidth() const
std::string getLayer() const
int getColor24() const
double getLinetypeScale() const
unsigned long m_handle
Definition: dl_writer.h:582
void lineWeight(int lw) const
Definition: dl_writer.h:466
virtual void dxfInt(int gc, int value) const =0
virtual void dxfString(int gc, const char *value) const =0
void dxfEOF() const
Definition: dl_writer.h:272
void sectionTables() const
Definition: dl_writer.h:105
void setPaperSpace0Handle(unsigned long h)
Definition: dl_writer.h:523
void tableEnd() const
Definition: dl_writer.h:262
void setModelSpaceHandle(unsigned long h)
Definition: dl_writer.h:507
unsigned long getPaperSpace0Handle()
Definition: dl_writer.h:525
void sectionClasses() const
Definition: dl_writer.h:141
virtual void dxfReal(int gc, double value) const =0
unsigned long paperSpaceHandle
Definition: dl_writer.h:584
void coordTriplet(int gc, const double *value) const
Definition: dl_writer.h:474
unsigned long getPaperSpaceHandle()
Definition: dl_writer.h:517
void tableLinetypeEntry(unsigned long int h=0) const
Definition: dl_writer.h:375
virtual ~DL_Writer()
Definition: dl_writer.h:67
void sectionObjects() const
Definition: dl_writer.h:153
unsigned long getNextHandle() const
Definition: dl_writer.h:496
void section(const char *name) const
Definition: dl_writer.h:78
virtual void dxfString(int gc, const std::string &value) const =0
void comment(const char *text) const
Definition: dl_writer.h:282
void tableLinetypes(int num) const
Definition: dl_writer.h:219
void tableStyle(int num) const
Definition: dl_writer.h:252
void entity(const char *entTypeName) const
Definition: dl_writer.h:294
void tableLayers(int num) const
Definition: dl_writer.h:204
void sectionBlockEntry(unsigned long int h=0) const
Definition: dl_writer.h:419
void sectionEnd() const
Definition: dl_writer.h:163
unsigned long paperSpace0Handle
Definition: dl_writer.h:585
unsigned long incHandle() const
Definition: dl_writer.h:501
void resetHandle() const
Definition: dl_writer.h:482
void sectionBlockEntryEnd(unsigned long int h=0) const
Definition: dl_writer.h:445
void tableLayerEntry(unsigned long int h=0) const
Definition: dl_writer.h:354
void subClass(const char *sub) const
Definition: dl_writer.h:344
unsigned long handle(int gc=5) const
Definition: dl_writer.h:487
virtual void dxfHex(int gc, int value) const =0
virtual void dxfBool(int gc, bool value) const
Definition: dl_writer.h:552
void sectionBlocks() const
Definition: dl_writer.h:117
void table(const char *name, int num, int h=0) const
Definition: dl_writer.h:177
unsigned long getModelSpaceHandle()
Definition: dl_writer.h:509
void linetypeScale(double scale) const
Definition: dl_writer.h:465
DL_Writer(DL_Codes::version version)
Definition: dl_writer.h:60
void linetype(const char *lt) const
Definition: dl_writer.h:464
void tableAppid(int num) const
Definition: dl_writer.h:237
void tableAppidEntry(unsigned long int h=0) const
Definition: dl_writer.h:397
void color(int col=256) const
Definition: dl_writer.h:463
void sectionHeader() const
Definition: dl_writer.h:93
void setPaperSpaceHandle(unsigned long h)
Definition: dl_writer.h:515
void coord(int gc, double x, double y, double z=0) const
Definition: dl_writer.h:468
void sectionEntities() const
Definition: dl_writer.h:129
void entityAttributes(const DL_Attributes &attrib) const
Definition: dl_writer.h:315
unsigned long modelSpaceHandle
Definition: dl_writer.h:583
DL_Codes::version version
Definition: dl_writer.h:590
#define DL_VERSION_2000
Definition: dl_codes.h:374
#define DXFLIB_EXPORT
Definition: dl_global.h:12
normal_z y
normal_z x
normal_z z