ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
dl_dxf.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
3 **
4 ** This file is part of the dxflib project.
5 **
6 ** This file is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
10 **
11 ** Licensees holding valid dxflib Professional Edition licenses may use
12 ** this file in accordance with the dxflib Commercial License
13 ** Agreement provided with the Software.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** See http://www.ribbonsoft.com for further details.
19 **
20 ** Contact info@ribbonsoft.com if any conditions of this licensing are
21 ** not clear to you.
22 **
23 **********************************************************************/
24 
25 #include "dl_dxf.h"
26 
27 #include <algorithm>
28 #include <cassert>
29 #include <cmath>
30 #include <cstdio>
31 #include <string>
32 
33 #include "dl_attributes.h"
34 #include "dl_codes.h"
35 #include "dl_creationadapter.h"
36 #include "dl_writer_ascii.h"
37 #include "iostream"
38 
43  version = DL_VERSION_2000;
44 
45  vertices = NULL;
46  maxVertices = 0;
47  vertexIndex = 0;
48 
49  knots = NULL;
50  maxKnots = 0;
51  knotIndex = 0;
52 
53  weights = NULL;
54  weightIndex = 0;
55 
56  controlPoints = NULL;
57  maxControlPoints = 0;
58  controlPointIndex = 0;
59 
60  fitPoints = NULL;
61  maxFitPoints = 0;
62  fitPointIndex = 0;
63 
64  leaderVertices = NULL;
65  maxLeaderVertices = 0;
66  leaderVertexIndex = 0;
67 }
68 
73  if (vertices != NULL) {
74  delete[] vertices;
75  }
76  if (knots != NULL) {
77  delete[] knots;
78  }
79  if (controlPoints != NULL) {
80  delete[] controlPoints;
81  }
82  if (fitPoints != NULL) {
83  delete[] fitPoints;
84  }
85  if (weights != NULL) {
86  delete[] weights;
87  }
88  if (leaderVertices != NULL) {
89  delete[] leaderVertices;
90  }
91 }
92 
105 bool DL_Dxf::in(const std::string& file,
106  DL_CreationInterface* creationInterface) {
107  FILE* fp;
108  firstCall = true;
109  currentObjectType = DL_UNKNOWN;
110 
111  fp = fopen(file.c_str(), "rt");
112  if (fp) {
113  std::locale oldLocale =
114  std::locale::global(std::locale("C")); // use dot in numbers
115  while (readDxfGroups(fp, creationInterface)) {
116  }
117  std::locale::global(oldLocale);
118  fclose(fp);
119  return true;
120  }
121 
122  return false;
123 }
124 
135 bool DL_Dxf::in(std::stringstream& stream,
136  DL_CreationInterface* creationInterface) {
137  if (stream.good()) {
138  firstCall = true;
139  currentObjectType = DL_UNKNOWN;
140  while (readDxfGroups(stream, creationInterface)) {
141  }
142  return true;
143  }
144  return false;
145 }
146 
169 bool DL_Dxf::readDxfGroups(FILE* fp, DL_CreationInterface* creationInterface) {
170  static int line = 1;
171 
172  // Read one group of the DXF file and strip the lines:
173  if (DL_Dxf::getStrippedLine(groupCodeTmp, DL_DXF_MAXLINE, fp) &&
174  DL_Dxf::getStrippedLine(groupValue, DL_DXF_MAXLINE, fp, false)) {
175  groupCode = (unsigned int)toInt(groupCodeTmp);
176 
177  creationInterface->processCodeValuePair(groupCode, groupValue);
178  line += 2;
179  processDXFGroup(creationInterface, groupCode, groupValue);
180  }
181 
182  return !feof(fp);
183 }
184 
188 bool DL_Dxf::readDxfGroups(std::stringstream& stream,
189  DL_CreationInterface* creationInterface) {
190  static int line = 1;
191 
192  // Read one group of the DXF file and chop the lines:
193  if (DL_Dxf::getStrippedLine(groupCodeTmp, DL_DXF_MAXLINE, stream) &&
194  DL_Dxf::getStrippedLine(groupValue, DL_DXF_MAXLINE, stream, false)) {
195  groupCode = (unsigned int)toInt(groupCodeTmp);
196 
197  line += 2;
198  processDXFGroup(creationInterface, groupCode, groupValue);
199  }
200  return !stream.eof();
201 }
202 
220 bool DL_Dxf::getStrippedLine(std::string& s,
221  unsigned int size,
222  FILE* fp,
223  bool stripSpace) {
224  if (!feof(fp)) {
225  // The whole line in the file. Includes space for NULL.
226  char* wholeLine = new char[size];
227  // Only the useful part of the line
228  char* line;
229 
230  line = fgets(wholeLine, size, fp);
231 
232  if (line != NULL && line[0] != '\0') { // Evaluates to fgets() retval
233  // line == wholeLine at this point.
234  // Both guaranteed to be NULL terminated.
235 
236  // Strip leading whitespace and trailing CR/LF.
237  stripWhiteSpace(&line, stripSpace);
238 
239  s = line;
240  assert(size > s.length());
241  }
242 
243  delete[] wholeLine; // Done with wholeLine
244 
245  return true;
246  } else {
247  s = "";
248  return false;
249  }
250 }
251 
255 bool DL_Dxf::getStrippedLine(std::string& s,
256  unsigned int size,
257  std::stringstream& stream,
258  bool stripSpace) {
259  if (!stream.eof()) {
260  // Only the useful part of the line
261  char* line = new char[size + 1];
262  char* oriLine = line;
263  stream.getline(line, size);
264  stripWhiteSpace(&line, stripSpace);
265  s = line;
266  assert(size > s.length());
267  delete[] oriLine;
268  return true;
269  } else {
270  s[0] = '\0';
271  return false;
272  }
273 }
274 
285 bool DL_Dxf::stripWhiteSpace(char** s, bool stripSpace) {
286  // last non-NULL char:
287  int lastChar = static_cast<int>(strlen(*s)) - 1;
288 
289  // Is last character CR or LF?
290  while ((lastChar >= 0) &&
291  (((*s)[lastChar] == 10) || ((*s)[lastChar] == 13) ||
292  (stripSpace &&
293  ((*s)[lastChar] == ' ' || ((*s)[lastChar] == '\t'))))) {
294  (*s)[lastChar] = '\0';
295  lastChar--;
296  }
297 
298  // Skip whitespace, excluding \n, at beginning of line
299  if (stripSpace) {
300  while ((*s)[0] == ' ' || (*s)[0] == '\t') {
301  ++(*s);
302  }
303  }
304 
305  return ((*s) ? true : false);
306 }
307 
321  int groupCode,
322  const std::string& groupValue) {
323  // printf("%d\n", groupCode);
324  // printf("%s\n", groupValue.c_str());
325 
326  // Init values on first call
327  if (firstCall) {
328  settingValue[0] = '\0';
329  firstCall = false;
330  }
331 
332  // Indicates comment or dxflib version:
333  if (groupCode == 999) {
334  if (!groupValue.empty()) {
335  if (groupValue.substr(0, 6) == "dxflib") {
336  libVersion = getLibVersion(groupValue.substr(7));
337  }
338 
339  addComment(creationInterface, groupValue);
340  }
341  }
342 
343  // Indicates start of new entity or variable:
344  else if (groupCode == 0 || groupCode == 9) {
345  // If new entity is encountered, the last one is complete.
346  // Prepare default attributes for next entity:
347  std::string layer = getStringValue(8, "0");
348 
349  int width;
350  // Compatibility with qcad1:
351  if (hasValue(39) && !hasValue(370)) {
352  width = getIntValue(39, -1);
353  }
354  // since autocad 2002:
355  else if (hasValue(370)) {
356  width = getIntValue(370, -1);
357  }
358  // default to BYLAYER:
359  else {
360  width = -1;
361  }
362 
363  int color;
364  color = getIntValue(62, 256);
365  int color24;
366  color24 = getIntValue(420, -1);
367  int handle;
368  handle = getInt16Value(5, -1);
369 
370  std::string linetype = getStringValue(6, "BYLAYER");
371 
372  attrib = DL_Attributes(layer, // layer
373  color, // color
374  color24, // 24 bit color
375  width, // width
376  linetype, // linetype
377  handle); // handle
378  attrib.setInPaperSpace((bool)getIntValue(67, 0));
379  attrib.setLinetypeScale(getRealValue(48, 1.0));
380  creationInterface->setAttributes(attrib);
381 
382  int elevationGroupCode = 30;
383  if (currentObjectType == DL_ENTITY_LWPOLYLINE) {
384  // see lwpolyline group codes reference
385  elevationGroupCode = 38;
386  } else {
387  // see polyline group codes reference
388  elevationGroupCode = 30;
389  }
390 
391  creationInterface->setExtrusion(
392  getRealValue(210, 0.0), getRealValue(220, 0.0),
393  getRealValue(230, 1.0), getRealValue(elevationGroupCode, 0.0));
394 
395  // Add the previously parsed entity via creationInterface
396  switch (currentObjectType) {
397  case DL_SETTING:
398  addSetting(creationInterface);
399  break;
400 
401  case DL_LAYER:
402  addLayer(creationInterface);
403  break;
404 
405  case DL_LINETYPE:
406  addLinetype(creationInterface);
407  break;
408 
409  case DL_BLOCK:
410  addBlock(creationInterface);
411  break;
412 
413  case DL_ENDBLK:
414  endBlock(creationInterface);
415  break;
416 
417  case DL_STYLE:
418  addTextStyle(creationInterface);
419  break;
420 
421  case DL_ENTITY_POINT:
422  addPoint(creationInterface);
423  break;
424 
425  case DL_ENTITY_LINE:
426  addLine(creationInterface);
427  break;
428 
429  case DL_ENTITY_XLINE:
430  addXLine(creationInterface);
431  break;
432 
433  case DL_ENTITY_RAY:
434  addRay(creationInterface);
435  break;
436 
437  case DL_ENTITY_POLYLINE:
439  addPolyline(creationInterface);
440  break;
441 
442  case DL_ENTITY_VERTEX:
443  addVertex(creationInterface);
444  break;
445 
446  case DL_ENTITY_SPLINE:
447  addSpline(creationInterface);
448  break;
449 
450  case DL_ENTITY_ARC:
451  addArc(creationInterface);
452  break;
453 
454  case DL_ENTITY_CIRCLE:
455  addCircle(creationInterface);
456  break;
457 
458  case DL_ENTITY_ELLIPSE:
459  addEllipse(creationInterface);
460  break;
461 
462  case DL_ENTITY_INSERT:
463  addInsert(creationInterface);
464  break;
465 
466  case DL_ENTITY_MTEXT:
467  addMText(creationInterface);
468  break;
469 
470  case DL_ENTITY_TEXT:
471  addText(creationInterface);
472  break;
473 
475  addArcAlignedText(creationInterface);
476  break;
477 
478  case DL_ENTITY_ATTRIB:
479  addAttribute(creationInterface);
480  break;
481 
482  case DL_ENTITY_DIMENSION: {
483  int type = (getIntValue(70, 0) & 0x07);
484 
485  switch (type) {
486  case 0:
487  addDimLinear(creationInterface);
488  break;
489 
490  case 1:
491  addDimAligned(creationInterface);
492  break;
493 
494  case 2:
495  addDimAngular(creationInterface);
496  break;
497 
498  case 3:
499  addDimDiametric(creationInterface);
500  break;
501 
502  case 4:
503  addDimRadial(creationInterface);
504  break;
505 
506  case 5:
507  addDimAngular3P(creationInterface);
508  break;
509 
510  case 6:
511  addDimOrdinate(creationInterface);
512  break;
513 
514  default:
515  break;
516  }
517  } break;
518 
519  case DL_ENTITY_LEADER:
520  addLeader(creationInterface);
521  break;
522 
523  case DL_ENTITY_HATCH:
524  // addHatch(creationInterface);
525  handleHatchData(creationInterface);
526  break;
527 
528  case DL_ENTITY_IMAGE:
529  addImage(creationInterface);
530  break;
531 
532  case DL_ENTITY_IMAGEDEF:
533  addImageDef(creationInterface);
534  break;
535 
536  case DL_ENTITY_TRACE:
537  addTrace(creationInterface);
538  break;
539 
540  case DL_ENTITY_3DFACE:
541  add3dFace(creationInterface);
542  break;
543 
544  case DL_ENTITY_SOLID:
545  addSolid(creationInterface);
546  break;
547 
548  case DL_ENTITY_SEQEND:
549  endSequence(creationInterface);
550  break;
551 
552  default:
553  break;
554  }
555 
556  creationInterface->endSection();
557 
558  // reset all values (they are not persistent and only this
559  // way we can set defaults for omitted values)
560  // for (int i=0; i<DL_DXF_MAXGROUPCODE; ++i) {
561  // values[i][0] = '\0';
562  // }
563  values.clear();
564  settingValue[0] = '\0';
565  settingKey = "";
566  firstHatchLoop = true;
567  // firstHatchEdge = true;
568  hatchEdge = DL_HatchEdgeData();
569  // xRecordHandle = "";
570  xRecordValues = false;
571 
572  // Last DXF entity or setting has been handled
573  // Now determine what the next entity or setting type is
574 
575  int prevEntity = currentObjectType;
576 
577  // Read DXF variable:
578  if (groupValue[0] == '$') {
579  currentObjectType = DL_SETTING;
580  settingKey = groupValue;
581  }
582 
583  // Read Layers:
584  else if (groupValue == "LAYER") {
585  currentObjectType = DL_LAYER;
586  }
587 
588  // Read Linetypes:
589  else if (groupValue == "LTYPE") {
590  currentObjectType = DL_LINETYPE;
591  }
592 
593  // Read Blocks:
594  else if (groupValue == "BLOCK") {
595  currentObjectType = DL_BLOCK;
596  } else if (groupValue == "ENDBLK") {
597  currentObjectType = DL_ENDBLK;
598  }
599 
600  // Read text styles:
601  else if (groupValue == "STYLE") {
602  currentObjectType = DL_STYLE;
603  }
604 
605  // Read entities:
606  else if (groupValue == "POINT") {
607  currentObjectType = DL_ENTITY_POINT;
608  } else if (groupValue == "LINE") {
609  currentObjectType = DL_ENTITY_LINE;
610  } else if (groupValue == "XLINE") {
611  currentObjectType = DL_ENTITY_XLINE;
612  } else if (groupValue == "RAY") {
613  currentObjectType = DL_ENTITY_RAY;
614  } else if (groupValue == "POLYLINE") {
615  currentObjectType = DL_ENTITY_POLYLINE;
616  } else if (groupValue == "LWPOLYLINE") {
617  currentObjectType = DL_ENTITY_LWPOLYLINE;
618  } else if (groupValue == "VERTEX") {
619  currentObjectType = DL_ENTITY_VERTEX;
620  } else if (groupValue == "SPLINE") {
621  currentObjectType = DL_ENTITY_SPLINE;
622  } else if (groupValue == "ARC") {
623  currentObjectType = DL_ENTITY_ARC;
624  } else if (groupValue == "ELLIPSE") {
625  currentObjectType = DL_ENTITY_ELLIPSE;
626  } else if (groupValue == "CIRCLE") {
627  currentObjectType = DL_ENTITY_CIRCLE;
628  } else if (groupValue == "INSERT") {
629  currentObjectType = DL_ENTITY_INSERT;
630  } else if (groupValue == "TEXT") {
631  currentObjectType = DL_ENTITY_TEXT;
632  } else if (groupValue == "MTEXT") {
633  currentObjectType = DL_ENTITY_MTEXT;
634  } else if (groupValue == "ARCALIGNEDTEXT") {
635  currentObjectType = DL_ENTITY_ARCALIGNEDTEXT;
636  } else if (groupValue == "ATTRIB") {
637  currentObjectType = DL_ENTITY_ATTRIB;
638  } else if (groupValue == "DIMENSION") {
639  currentObjectType = DL_ENTITY_DIMENSION;
640  } else if (groupValue == "LEADER") {
641  currentObjectType = DL_ENTITY_LEADER;
642  } else if (groupValue == "HATCH") {
643  currentObjectType = DL_ENTITY_HATCH;
644  } else if (groupValue == "IMAGE") {
645  currentObjectType = DL_ENTITY_IMAGE;
646  } else if (groupValue == "IMAGEDEF") {
647  currentObjectType = DL_ENTITY_IMAGEDEF;
648  } else if (groupValue == "TRACE") {
649  currentObjectType = DL_ENTITY_TRACE;
650  } else if (groupValue == "SOLID") {
651  currentObjectType = DL_ENTITY_SOLID;
652  } else if (groupValue == "3DFACE") {
653  currentObjectType = DL_ENTITY_3DFACE;
654  } else if (groupValue == "SEQEND") {
655  currentObjectType = DL_ENTITY_SEQEND;
656  } else if (groupValue == "XRECORD") {
657  currentObjectType = DL_XRECORD;
658  } else if (groupValue == "DICTIONARY") {
659  currentObjectType = DL_DICTIONARY;
660  } else {
661  currentObjectType = DL_UNKNOWN;
662  }
663 
664  // end of old style POLYLINE entity
665  if (prevEntity == DL_ENTITY_VERTEX &&
666  currentObjectType != DL_ENTITY_VERTEX) {
667  endEntity(creationInterface);
668  }
669 
670  // TODO: end of SPLINE entity
671  // if (prevEntity==DL_ENTITY_CONTROLPOINT &&
672  // currentEntity!=DL_ENTITY_CONTROLPOINT) {
673  // endEntity(creationInterface);
674  //}
675 
676  return true;
677 
678  } else {
679  // Group code does not indicate start of new entity or setting,
680  // so this group must be continuation of data for the current
681  // one.
682  if (groupCode < DL_DXF_MAXGROUPCODE) {
683  bool handled = false;
684 
685  switch (currentObjectType) {
686  case DL_ENTITY_MTEXT:
687  handled = handleMTextData(creationInterface);
688  break;
689 
691  handled = handleLWPolylineData(creationInterface);
692  break;
693 
694  case DL_ENTITY_SPLINE:
695  handled = handleSplineData(creationInterface);
696  break;
697 
698  case DL_ENTITY_LEADER:
699  handled = handleLeaderData(creationInterface);
700  break;
701 
702  case DL_ENTITY_HATCH:
703  handled = handleHatchData(creationInterface);
704  break;
705 
706  case DL_XRECORD:
707  handled = handleXRecordData(creationInterface);
708  break;
709 
710  case DL_DICTIONARY:
711  handled = handleDictionaryData(creationInterface);
712  break;
713 
714  case DL_LINETYPE:
715  handled = handleLinetypeData(creationInterface);
716  break;
717 
718  default:
719  break;
720  }
721 
722  // Always try to handle XData, unless we're in an XData record:
723  if (currentObjectType != DL_XRECORD) {
724  handled = handleXData(creationInterface);
725  }
726 
727  if (!handled) {
728  // Normal group / value pair:
729  values[groupCode] = groupValue;
730  }
731  }
732 
733  return false;
734  }
735  return false;
736 }
737 
741 void DL_Dxf::addComment(DL_CreationInterface* creationInterface,
742  const std::string& comment) {
743  creationInterface->addComment(comment);
744 }
745 
746 void DL_Dxf::addDictionary(DL_CreationInterface* creationInterface) {
747  creationInterface->addDictionary(DL_DictionaryData(getStringValue(5, "")));
748 }
749 
751  creationInterface->addDictionaryEntry(DL_DictionaryEntryData(
752  getStringValue(3, ""), getStringValue(350, "")));
753 }
754 
758 void DL_Dxf::addSetting(DL_CreationInterface* creationInterface) {
759  int c = -1;
760  std::map<int, std::string>::iterator it = values.begin();
761  if (it != values.end()) {
762  c = it->first;
763  }
764  // for (int i=0; i<=380; ++i) {
765  // if (values[i][0]!='\0') {
766  // c = i;
767  // break;
768  // }
769  // }
770 
771  // string
772  if (c >= 0 && c <= 9) {
773  creationInterface->setVariableString(settingKey, values[c], c);
774 #ifdef DL_COMPAT
775  // backwards compatibility:
776  creationInterface->setVariableString(settingKey.c_str(),
777  values[c].c_str(), c);
778 #endif
779  }
780  // vector
781  else if (c >= 10 && c <= 39) {
782  if (c == 10) {
783  creationInterface->setVariableVector(
784  settingKey, getRealValue(c, 0.0), getRealValue(c + 10, 0.0),
785  getRealValue(c + 20, 0.0), c);
786  }
787  }
788  // double
789  else if (c >= 40 && c <= 59) {
790  creationInterface->setVariableDouble(settingKey, getRealValue(c, 0.0),
791  c);
792  }
793  // int
794  else if (c >= 60 && c <= 99) {
795  creationInterface->setVariableInt(settingKey, getIntValue(c, 0), c);
796  }
797  // misc
798  else if (c >= 0) {
799  creationInterface->setVariableString(settingKey, getStringValue(c, ""),
800  c);
801  }
802 }
803 
807 void DL_Dxf::addLayer(DL_CreationInterface* creationInterface) {
808  // correct some invalid attributes for layers:
809  attrib = creationInterface->getAttributes();
810  if (attrib.getColor() == 256 || attrib.getColor() == 0) {
811  attrib.setColor(7);
812  }
813  if (attrib.getWidth() < 0) {
814  attrib.setWidth(1);
815  }
816 
817  std::string linetype = attrib.getLinetype();
818  std::transform(linetype.begin(), linetype.end(), linetype.begin(),
819  ::toupper);
820  if (linetype == "BYLAYER" || linetype == "BYBLOCK") {
821  attrib.setLinetype("CONTINUOUS");
822  }
823 
824  // add layer
825  std::string name = getStringValue(2, "");
826  if (name.length() == 0) {
827  return;
828  }
829 
830  creationInterface->addLayer(DL_LayerData(name, getIntValue(70, 0)));
831 }
832 
836 void DL_Dxf::addLinetype(DL_CreationInterface* creationInterface) {
837  std::string name = getStringValue(2, "");
838  if (name.length() == 0) {
839  return;
840  }
841  int numDashes = getIntValue(73, 0);
842  // double dashes[numDashes];
843 
844  DL_LinetypeData d(
845  // name:
846  name,
847  // description:
848  getStringValue(3, ""),
849  // flags
850  getIntValue(70, 0),
851  // number of dashes:
852  numDashes,
853  // pattern length:
854  getRealValue(40, 0.0)
855  // pattern:
856  // dashes
857  );
858 
859  if (name != "By Layer" && name != "By Block" && name != "BYLAYER" &&
860  name != "BYBLOCK") {
861  creationInterface->addLinetype(d);
862  }
863 }
864 
869  if (groupCode == 49) {
870  creationInterface->addLinetypeDash(toReal(groupValue));
871  return true;
872  }
873 
874  return false;
875 }
876 
880 void DL_Dxf::addBlock(DL_CreationInterface* creationInterface) {
881  std::string name = getStringValue(2, "");
882  if (name.length() == 0) {
883  return;
884  }
885 
886  DL_BlockData d(
887  // Name:
888  name,
889  // flags:
890  getIntValue(70, 0),
891  // base point:
892  getRealValue(10, 0.0), getRealValue(20, 0.0),
893  getRealValue(30, 0.0));
894 
895  creationInterface->addBlock(d);
896 }
897 
901 void DL_Dxf::endBlock(DL_CreationInterface* creationInterface) {
902  creationInterface->endBlock();
903 }
904 
905 void DL_Dxf::addTextStyle(DL_CreationInterface* creationInterface) {
906  std::string name = getStringValue(2, "");
907  if (name.length() == 0) {
908  return;
909  }
910 
911  DL_StyleData d(
912  // name:
913  name,
914  // flags
915  getIntValue(70, 0),
916  // fixed text heigth:
917  getRealValue(40, 0.0),
918  // width factor:
919  getRealValue(41, 0.0),
920  // oblique angle:
921  getRealValue(50, 0.0),
922  // text generation flags:
923  getIntValue(71, 0),
924  // last height used:
925  getRealValue(42, 0.0),
926  // primart font file:
927  getStringValue(3, ""),
928  // big font file:
929  getStringValue(4, ""));
930  creationInterface->addTextStyle(d);
931 }
932 
936 void DL_Dxf::addPoint(DL_CreationInterface* creationInterface) {
937  DL_PointData d(getRealValue(10, 0.0), getRealValue(20, 0.0),
938  getRealValue(30, 0.0));
939  creationInterface->addPoint(d);
940 }
941 
945 void DL_Dxf::addLine(DL_CreationInterface* creationInterface) {
946  DL_LineData d(getRealValue(10, 0.0), getRealValue(20, 0.0),
947  getRealValue(30, 0.0), getRealValue(11, 0.0),
948  getRealValue(21, 0.0), getRealValue(31, 0.0));
949 
950  creationInterface->addLine(d);
951 }
952 
956 void DL_Dxf::addXLine(DL_CreationInterface* creationInterface) {
957  DL_XLineData d(getRealValue(10, 0.0), getRealValue(20, 0.0),
958  getRealValue(30, 0.0), getRealValue(11, 0.0),
959  getRealValue(21, 0.0), getRealValue(31, 0.0));
960 
961  creationInterface->addXLine(d);
962 }
963 
967 void DL_Dxf::addRay(DL_CreationInterface* creationInterface) {
968  DL_RayData d(getRealValue(10, 0.0), getRealValue(20, 0.0),
969  getRealValue(30, 0.0), getRealValue(11, 0.0),
970  getRealValue(21, 0.0), getRealValue(31, 0.0));
971 
972  creationInterface->addRay(d);
973 }
974 
979 void DL_Dxf::addPolyline(DL_CreationInterface* creationInterface) {
980  DL_PolylineData pd(maxVertices, getIntValue(71, 0), getIntValue(72, 0),
981  getIntValue(70, 0), getRealValue(38, 0));
982  creationInterface->addPolyline(pd);
983 
984  maxVertices = std::min(maxVertices, vertexIndex + 1);
985 
986  if (currentObjectType == DL_ENTITY_LWPOLYLINE) {
987  for (int i = 0; i < maxVertices; i++) {
988  DL_VertexData d(vertices[i * 4], vertices[i * 4 + 1],
989  vertices[i * 4 + 2], vertices[i * 4 + 3]);
990 
991  creationInterface->addVertex(d);
992  }
993  creationInterface->endEntity();
994  }
995 }
996 
1001 void DL_Dxf::addVertex(DL_CreationInterface* creationInterface) {
1002  // vertex defines a face of the mesh if its vertex flags group has the
1003  // 128 bit set but not the 64 bit. 10, 20, 30 are irrelevant and set to
1004  // 0 in this case
1005  if ((getIntValue(70, 0) & 128) && !(getIntValue(70, 0) & 64)) {
1006  return;
1007  }
1008 
1009  DL_VertexData d(getRealValue(10, 0.0), getRealValue(20, 0.0),
1010  getRealValue(30, 0.0), getRealValue(42, 0.0));
1011 
1012  creationInterface->addVertex(d);
1013 }
1014 
1018 void DL_Dxf::addSpline(DL_CreationInterface* creationInterface) {
1019  DL_SplineData sd(getIntValue(71, 3), maxKnots, maxControlPoints,
1020  maxFitPoints, getIntValue(70, 4));
1021 
1022  sd.tangentStartX = getRealValue(12, 0.0);
1023  sd.tangentStartY = getRealValue(22, 0.0);
1024  sd.tangentStartZ = getRealValue(32, 0.0);
1025  sd.tangentEndX = getRealValue(13, 0.0);
1026  sd.tangentEndY = getRealValue(23, 0.0);
1027  sd.tangentEndZ = getRealValue(33, 0.0);
1028 
1029  creationInterface->addSpline(sd);
1030 
1031  int i;
1032  for (i = 0; i < maxControlPoints; i++) {
1033  DL_ControlPointData d(controlPoints[i * 3], controlPoints[i * 3 + 1],
1034  controlPoints[i * 3 + 2], weights[i]);
1035 
1036  creationInterface->addControlPoint(d);
1037  }
1038  for (i = 0; i < maxFitPoints; i++) {
1039  DL_FitPointData d(fitPoints[i * 3], fitPoints[i * 3 + 1],
1040  fitPoints[i * 3 + 2]);
1041 
1042  creationInterface->addFitPoint(d);
1043  }
1044  for (i = 0; i < maxKnots; i++) {
1045  DL_KnotData k(knots[i]);
1046 
1047  creationInterface->addKnot(k);
1048  }
1049  creationInterface->endEntity();
1050 }
1051 
1055 void DL_Dxf::addArc(DL_CreationInterface* creationInterface) {
1056  DL_ArcData d(getRealValue(10, 0.0), getRealValue(20, 0.0),
1057  getRealValue(30, 0.0), getRealValue(40, 0.0),
1058  getRealValue(50, 0.0), getRealValue(51, 0.0));
1059 
1060  creationInterface->addArc(d);
1061 }
1062 
1066 void DL_Dxf::addCircle(DL_CreationInterface* creationInterface) {
1067  DL_CircleData d(getRealValue(10, 0.0), getRealValue(20, 0.0),
1068  getRealValue(30, 0.0), getRealValue(40, 0.0));
1069 
1070  creationInterface->addCircle(d);
1071 }
1072 
1077 void DL_Dxf::addEllipse(DL_CreationInterface* creationInterface) {
1078  DL_EllipseData d(getRealValue(10, 0.0), getRealValue(20, 0.0),
1079  getRealValue(30, 0.0), getRealValue(11, 0.0),
1080  getRealValue(21, 0.0), getRealValue(31, 0.0),
1081  getRealValue(40, 1.0), getRealValue(41, 0.0),
1082  getRealValue(42, 2 * M_PI));
1083 
1084  creationInterface->addEllipse(d);
1085 }
1086 
1090 void DL_Dxf::addInsert(DL_CreationInterface* creationInterface) {
1091  // printf("addInsert\n");
1092  // printf("code 50: %s\n", values[50]);
1093  // printf("code 50 length: %d\n", strlen(values[50]));
1094  // printf("code 50:\n");
1095  // getRealValue(50, 0.0);
1096 
1097  std::string name = getStringValue(2, "");
1098  if (name.length() == 0) {
1099  return;
1100  }
1101 
1102  DL_InsertData d(
1103  name,
1104  // insertion point
1105  getRealValue(10, 0.0), getRealValue(20, 0.0), getRealValue(30, 0.0),
1106  // scale:
1107  getRealValue(41, 1.0), getRealValue(42, 1.0), getRealValue(43, 1.0),
1108  // angle (deg):
1109  getRealValue(50, 0.0),
1110  // cols / rows:
1111  getIntValue(70, 1), getIntValue(71, 1),
1112  // spacing:
1113  getRealValue(44, 0.0), getRealValue(45, 0.0));
1114 
1115  creationInterface->addInsert(d);
1116 }
1117 
1124 void DL_Dxf::addTrace(DL_CreationInterface* creationInterface) {
1125  DL_TraceData td;
1126 
1127  for (int k = 0; k < 4; k++) {
1128  td.x[k] = getRealValue(10 + k, 0.0);
1129  td.y[k] = getRealValue(20 + k, 0.0);
1130  td.z[k] = getRealValue(30 + k, 0.0);
1131  }
1132  creationInterface->addTrace(td);
1133 }
1134 
1138 void DL_Dxf::add3dFace(DL_CreationInterface* creationInterface) {
1139  DL_3dFaceData td;
1140 
1141  for (int k = 0; k < 4; k++) {
1142  td.x[k] = getRealValue(10 + k, 0.0);
1143  td.y[k] = getRealValue(20 + k, 0.0);
1144  td.z[k] = getRealValue(30 + k, 0.0);
1145  }
1146  creationInterface->add3dFace(td);
1147 }
1148 
1155 void DL_Dxf::addSolid(DL_CreationInterface* creationInterface) {
1156  DL_SolidData sd;
1157 
1158  for (int k = 0; k < 4; k++) {
1159  sd.x[k] = getRealValue(10 + k, 0.0);
1160  sd.y[k] = getRealValue(20 + k, 0.0);
1161  sd.z[k] = getRealValue(30 + k, 0.0);
1162  }
1163  creationInterface->addSolid(sd);
1164 }
1165 
1169 void DL_Dxf::addMText(DL_CreationInterface* creationInterface) {
1170  double angle = 0.0;
1171 
1172  if (hasValue(50)) {
1173  if (libVersion <= 0x02000200) {
1174  // wrong but compatible with dxflib <=2.0.2.0 (angle stored in rad):
1175  angle = getRealValue(50, 0.0);
1176  } else {
1177  angle = (getRealValue(50, 0.0) * 2 * M_PI) / 360.0;
1178  }
1179  } else if (hasValue(11) && hasValue(21)) {
1180  double x = getRealValue(11, 0.0);
1181  double y = getRealValue(21, 0.0);
1182 
1183  if (fabs(x) < 1.0e-6) {
1184  if (y > 0.0) {
1185  angle = M_PI / 2.0;
1186  } else {
1187  angle = M_PI / 2.0 * 3.0;
1188  }
1189  } else {
1190  angle = atan(y / x);
1191  }
1192  }
1193 
1194  DL_MTextData d(
1195  // insertion point
1196  getRealValue(10, 0.0), getRealValue(20, 0.0), getRealValue(30, 0.0),
1197  // X direction vector
1198  getRealValue(11, 0.0), getRealValue(21, 0.0), getRealValue(31, 0.0),
1199  // height
1200  getRealValue(40, 2.5),
1201  // width
1202  getRealValue(41, 0.0),
1203  // attachment point
1204  getIntValue(71, 1),
1205  // drawing direction
1206  getIntValue(72, 1),
1207  // line spacing style
1208  getIntValue(73, 1),
1209  // line spacing factor
1210  getRealValue(44, 1.0),
1211  // text
1212  getStringValue(1, ""),
1213  // style
1214  getStringValue(7, ""),
1215  // angle
1216  angle);
1217  creationInterface->addMText(d);
1218 }
1219 
1224  if (groupCode == 105) {
1225  return false;
1226  }
1227 
1228  if (groupCode == 5) {
1229  creationInterface->addXRecord(groupValue);
1230  return true;
1231  }
1232 
1233  if (groupCode == 280) {
1234  xRecordValues = true;
1235  return true;
1236  }
1237 
1238  if (!xRecordValues) {
1239  return false;
1240  }
1241 
1242  // string:
1243  if (groupCode <= 9 || groupCode == 100 || groupCode == 102 ||
1244  groupCode == 105 || (groupCode >= 300 && groupCode <= 369) ||
1245  (groupCode >= 1000 && groupCode <= 1009)) {
1246  creationInterface->addXRecordString(groupCode, groupValue);
1247  return true;
1248  }
1249 
1250  // int:
1251  else if ((groupCode >= 60 && groupCode <= 99) ||
1252  (groupCode >= 160 && groupCode <= 179) ||
1253  (groupCode >= 270 && groupCode <= 289)) {
1254  creationInterface->addXRecordInt(groupCode, toInt(groupValue));
1255  return true;
1256  }
1257 
1258  // bool:
1259  else if (groupCode >= 290 && groupCode <= 299) {
1260  creationInterface->addXRecordBool(groupCode, toBool(groupValue));
1261  return true;
1262  }
1263 
1264  // double:
1265  else if ((groupCode >= 10 && groupCode <= 59) ||
1266  (groupCode >= 110 && groupCode <= 149) ||
1267  (groupCode >= 210 && groupCode <= 239)) {
1268  creationInterface->addXRecordReal(groupCode, toReal(groupValue));
1269  return true;
1270  }
1271 
1272  return false;
1273 }
1274 
1279  if (groupCode == 3) {
1280  return true;
1281  }
1282 
1283  if (groupCode == 5) {
1284  creationInterface->addDictionary(DL_DictionaryData(groupValue));
1285  return true;
1286  }
1287 
1288  if (groupCode == 350) {
1289  creationInterface->addDictionaryEntry(
1290  DL_DictionaryEntryData(getStringValue(3, ""), groupValue));
1291  return true;
1292  }
1293  return false;
1294 }
1295 
1299 bool DL_Dxf::handleXData(DL_CreationInterface* creationInterface) {
1300  if (groupCode == 1001) {
1301  creationInterface->addXDataApp(groupValue);
1302  return true;
1303  } else if (groupCode >= 1000 && groupCode <= 1009) {
1304  creationInterface->addXDataString(groupCode, groupValue);
1305  return true;
1306  } else if (groupCode >= 1010 && groupCode <= 1059) {
1307  creationInterface->addXDataReal(groupCode, toReal(groupValue));
1308  return true;
1309  } else if (groupCode >= 1060 && groupCode <= 1070) {
1310  creationInterface->addXDataInt(groupCode, toInt(groupValue));
1311  return true;
1312  } else if (groupCode == 1071) {
1313  creationInterface->addXDataInt(groupCode, toInt(groupValue));
1314  return true;
1315  }
1316 
1317  return false;
1318 }
1319 
1324  // Special handling of text chunks for MTEXT entities:
1325  if (groupCode == 3) {
1326  creationInterface->addMTextChunk(groupValue);
1327  return true;
1328  }
1329 
1330  return false;
1331 }
1332 
1337  // Allocate LWPolyline vertices (group code 90):
1338  if (groupCode == 90) {
1339  maxVertices = toInt(groupValue);
1340  if (maxVertices > 0) {
1341  if (vertices != NULL) {
1342  delete[] vertices;
1343  }
1344  vertices = new double[4 * maxVertices];
1345  for (int i = 0; i < maxVertices; ++i) {
1346  vertices[i * 4] = 0.0;
1347  vertices[i * 4 + 1] = 0.0;
1348  vertices[i * 4 + 2] = 0.0;
1349  vertices[i * 4 + 3] = 0.0;
1350  }
1351  }
1352  vertexIndex = -1;
1353  return true;
1354  }
1355 
1356  // Process LWPolylines vertices (group codes 10/20/30/42):
1357  else if (groupCode == 10 || groupCode == 20 || groupCode == 30 ||
1358  groupCode == 42) {
1359  if (vertexIndex < maxVertices - 1 && groupCode == 10) {
1360  vertexIndex++;
1361  }
1362 
1363  if (groupCode <= 30) {
1364  if (vertexIndex >= 0 && vertexIndex < maxVertices) {
1365  vertices[4 * vertexIndex + (groupCode / 10 - 1)] =
1366  toReal(groupValue);
1367  }
1368  } else if (groupCode == 42 && vertexIndex < maxVertices) {
1369  vertices[4 * vertexIndex + 3] = toReal(groupValue);
1370  }
1371  return true;
1372  }
1373  return false;
1374 }
1375 
1379 bool DL_Dxf::handleSplineData(DL_CreationInterface* /*creationInterface*/) {
1380  // Allocate Spline knots (group code 72):
1381  if (groupCode == 72) {
1382  maxKnots = toInt(groupValue);
1383  if (maxKnots > 0) {
1384  if (knots != NULL) {
1385  delete[] knots;
1386  }
1387  knots = new double[maxKnots];
1388  for (int i = 0; i < maxKnots; ++i) {
1389  knots[i] = 0.0;
1390  }
1391  }
1392  knotIndex = -1;
1393  return true;
1394  }
1395 
1396  // Allocate Spline control points / weights (group code 73):
1397  else if (groupCode == 73) {
1398  maxControlPoints = toInt(groupValue);
1399  if (maxControlPoints > 0) {
1400  if (controlPoints != NULL) {
1401  delete[] controlPoints;
1402  }
1403  if (weights != NULL) {
1404  delete[] weights;
1405  }
1406  controlPoints = new double[3 * maxControlPoints];
1407  weights = new double[maxControlPoints];
1408  for (int i = 0; i < maxControlPoints; ++i) {
1409  controlPoints[i * 3] = 0.0;
1410  controlPoints[i * 3 + 1] = 0.0;
1411  controlPoints[i * 3 + 2] = 0.0;
1412  weights[i] = 1.0;
1413  }
1414  }
1415  controlPointIndex = -1;
1416  weightIndex = -1;
1417  return true;
1418  }
1419 
1420  // Allocate Spline fit points (group code 74):
1421  else if (groupCode == 74) {
1422  maxFitPoints = toInt(groupValue);
1423  if (maxFitPoints > 0) {
1424  if (fitPoints != NULL) {
1425  delete[] fitPoints;
1426  }
1427  fitPoints = new double[3 * maxFitPoints];
1428  for (int i = 0; i < maxFitPoints; ++i) {
1429  fitPoints[i * 3] = 0.0;
1430  fitPoints[i * 3 + 1] = 0.0;
1431  fitPoints[i * 3 + 2] = 0.0;
1432  }
1433  }
1434  fitPointIndex = -1;
1435  return true;
1436  }
1437 
1438  // Process spline knot vertices (group code 40):
1439  else if (groupCode == 40) {
1440  if (knotIndex < maxKnots - 1) {
1441  knotIndex++;
1442  knots[knotIndex] = toReal(groupValue);
1443  }
1444  return true;
1445  }
1446 
1447  // Process spline control points (group codes 10/20/30):
1448  else if (groupCode == 10 || groupCode == 20 || groupCode == 30) {
1449  if (controlPointIndex < maxControlPoints - 1 && groupCode == 10) {
1450  controlPointIndex++;
1451  }
1452 
1453  if (controlPointIndex >= 0 && controlPointIndex < maxControlPoints) {
1454  controlPoints[3 * controlPointIndex + (groupCode / 10 - 1)] =
1455  toReal(groupValue);
1456  }
1457  return true;
1458  }
1459 
1460  // Process spline fit points (group codes 11/21/31):
1461  else if (groupCode == 11 || groupCode == 21 || groupCode == 31) {
1462  if (fitPointIndex < maxFitPoints - 1 && groupCode == 11) {
1463  fitPointIndex++;
1464  }
1465 
1466  if (fitPointIndex >= 0 && fitPointIndex < maxFitPoints) {
1467  fitPoints[3 * fitPointIndex + ((groupCode - 1) / 10 - 1)] =
1468  toReal(groupValue);
1469  }
1470  return true;
1471  }
1472 
1473  // Process spline weights (group code 41)
1474  else if (groupCode == 41) {
1475  if (weightIndex < maxControlPoints - 1) {
1476  weightIndex++;
1477  }
1478 
1479  if (weightIndex >= 0 && weightIndex < maxControlPoints) {
1480  weights[weightIndex] = toReal(groupValue);
1481  }
1482  return true;
1483  }
1484  return false;
1485 }
1486 
1490 bool DL_Dxf::handleLeaderData(DL_CreationInterface* /*creationInterface*/) {
1491  // Allocate Leader vertices (group code 76):
1492  if (groupCode == 76) {
1493  maxLeaderVertices = toInt(groupValue);
1494  if (maxLeaderVertices > 0) {
1495  if (leaderVertices != NULL) {
1496  delete[] leaderVertices;
1497  }
1498  leaderVertices = new double[3 * maxLeaderVertices];
1499  for (int i = 0; i < maxLeaderVertices; ++i) {
1500  leaderVertices[i * 3] = 0.0;
1501  leaderVertices[i * 3 + 1] = 0.0;
1502  leaderVertices[i * 3 + 2] = 0.0;
1503  }
1504  }
1505  leaderVertexIndex = -1;
1506  return true;
1507  }
1508 
1509  // Process Leader vertices (group codes 10/20/30):
1510  else if (groupCode == 10 || groupCode == 20 || groupCode == 30) {
1511  if (leaderVertexIndex < maxLeaderVertices - 1 && groupCode == 10) {
1512  leaderVertexIndex++;
1513  }
1514 
1515  if (groupCode <= 30) {
1516  if (leaderVertexIndex >= 0 &&
1517  leaderVertexIndex < maxLeaderVertices) {
1518  leaderVertices[3 * leaderVertexIndex + (groupCode / 10 - 1)] =
1519  toReal(groupValue);
1520  }
1521  }
1522  return true;
1523  }
1524 
1525  return false;
1526 }
1527 
1531 void DL_Dxf::addText(DL_CreationInterface* creationInterface) {
1532  DL_TextData d(
1533  // insertion point
1534  getRealValue(10, 0.0), getRealValue(20, 0.0), getRealValue(30, 0.0),
1535  // alignment point
1538  // height
1539  getRealValue(40, 2.5),
1540  // x scale
1541  getRealValue(41, 1.0),
1542  // generation flags
1543  getIntValue(71, 0),
1544  // h just
1545  getIntValue(72, 0),
1546  // v just
1547  getIntValue(73, 0),
1548  // text
1549  getStringValue(1, ""),
1550  // style
1551  getStringValue(7, ""),
1552  // angle
1553  (getRealValue(50, 0.0) * 2 * M_PI) / 360.0);
1554 
1555  creationInterface->addText(d);
1556 }
1557 
1564  d.text = getStringValue(1, "");
1565  d.font = getStringValue(2, "");
1566  d.style = getStringValue(7, "");
1567  d.cx = getRealValue(10, 0.0);
1568  d.cy = getRealValue(20, 0.0);
1569  d.cz = getRealValue(30, 0.0);
1570  d.radius = getRealValue(40, 0.0);
1571  d.xScaleFactor = getRealValue(41, 0.0);
1572  d.height = getRealValue(42, 0.0);
1573  d.spacing = getRealValue(43, 0.0);
1574  d.offset = getRealValue(44, 0.0);
1575  d.rightOffset = getRealValue(45, 0.0);
1576  d.leftOffset = getRealValue(46, 0.0);
1577  d.startAngle = getRealValue(50, 0.0);
1578  d.endAngle = getRealValue(51, 0.0);
1580  d.direction = getIntValue(71, 0);
1581  d.alignment = getIntValue(72, 0);
1582  d.side = getIntValue(73, 0);
1583  d.bold = getIntValue(74, 0);
1584  d.italic = getIntValue(75, 0);
1585  d.underline = getIntValue(76, 0);
1586  d.characerSet = getIntValue(77, 0);
1587  d.pitch = getIntValue(78, 0);
1588  d.shxFont = getIntValue(79, 0);
1589  d.wizard = getIntValue(280, 0);
1590  d.arcHandle = getIntValue(330, 0);
1591 
1592  creationInterface->addArcAlignedText(d);
1593 }
1594 
1599 void DL_Dxf::addAttribute(DL_CreationInterface* creationInterface) {
1600  DL_AttributeData d(
1601  // insertion point
1602  getRealValue(10, 0.0), getRealValue(20, 0.0), getRealValue(30, 0.0),
1603  // alignment point
1604  getRealValue(11, 0.0), getRealValue(21, 0.0), getRealValue(31, 0.0),
1605  // height
1606  getRealValue(40, 2.5),
1607  // x scale
1608  getRealValue(41, 1.0),
1609  // generation flags
1610  getIntValue(71, 0),
1611  // h just
1612  getIntValue(72, 0),
1613  // v just
1614  getIntValue(74, 0),
1615  // tag
1616  getStringValue(2, ""),
1617  // text
1618  getStringValue(1, ""),
1619  // style
1620  getStringValue(7, ""),
1621  // angle
1622  (getRealValue(50, 0.0) * 2 * M_PI) / 360.0);
1623 
1624  creationInterface->addAttribute(d);
1625 }
1626 
1631  // generic dimension data:
1632  return DL_DimensionData(
1633  // def point
1634  getRealValue(10, 0.0), getRealValue(20, 0.0), getRealValue(30, 0.0),
1635  // text middle point
1636  getRealValue(11, 0.0), getRealValue(21, 0.0), getRealValue(31, 0.0),
1637  // type
1638  getIntValue(70, 0),
1639  // attachment point
1640  getIntValue(71, 5),
1641  // line sp. style
1642  getIntValue(72, 1),
1643  // line sp. factor
1644  getRealValue(41, 1.0),
1645  // text
1646  getStringValue(1, ""),
1647  // style
1648  getStringValue(3, ""),
1649  // angle
1650  getRealValue(53, 0.0));
1651 }
1652 
1657 void DL_Dxf::addDimLinear(DL_CreationInterface* creationInterface) {
1659 
1660  // horizontal / vertical / rotated dimension:
1661  DL_DimLinearData dl(
1662  // definition point 1
1663  getRealValue(13, 0.0), getRealValue(23, 0.0), getRealValue(33, 0.0),
1664  // definition point 2
1665  getRealValue(14, 0.0), getRealValue(24, 0.0), getRealValue(34, 0.0),
1666  // angle
1667  getRealValue(50, 0.0),
1668  // oblique
1669  getRealValue(52, 0.0));
1670  creationInterface->addDimLinear(d, dl);
1671 }
1672 
1679 
1680  // aligned dimension:
1681  DL_DimAlignedData da(
1682  // extension point 1
1683  getRealValue(13, 0.0), getRealValue(23, 0.0), getRealValue(33, 0.0),
1684  // extension point 2
1685  getRealValue(14, 0.0), getRealValue(24, 0.0),
1686  getRealValue(34, 0.0));
1687  creationInterface->addDimAlign(d, da);
1688 }
1689 
1694 void DL_Dxf::addDimRadial(DL_CreationInterface* creationInterface) {
1696 
1697  DL_DimRadialData dr(
1698  // definition point
1699  getRealValue(15, 0.0), getRealValue(25, 0.0), getRealValue(35, 0.0),
1700  // leader length:
1701  getRealValue(40, 0.0));
1702  creationInterface->addDimRadial(d, dr);
1703 }
1704 
1711 
1712  // diametric dimension:
1714  // definition point
1715  getRealValue(15, 0.0), getRealValue(25, 0.0), getRealValue(35, 0.0),
1716  // leader length:
1717  getRealValue(40, 0.0));
1718  creationInterface->addDimDiametric(d, dr);
1719 }
1720 
1727 
1728  // angular dimension:
1729  DL_DimAngularData da(
1730  // definition point 1
1731  getRealValue(13, 0.0), getRealValue(23, 0.0), getRealValue(33, 0.0),
1732  // definition point 2
1733  getRealValue(14, 0.0), getRealValue(24, 0.0), getRealValue(34, 0.0),
1734  // definition point 3
1735  getRealValue(15, 0.0), getRealValue(25, 0.0), getRealValue(35, 0.0),
1736  // definition point 4
1737  getRealValue(16, 0.0), getRealValue(26, 0.0),
1738  getRealValue(36, 0.0));
1739  creationInterface->addDimAngular(d, da);
1740 }
1741 
1748 
1749  // angular dimension (3P):
1751  // definition point 1
1752  getRealValue(13, 0.0), getRealValue(23, 0.0), getRealValue(33, 0.0),
1753  // definition point 2
1754  getRealValue(14, 0.0), getRealValue(24, 0.0), getRealValue(34, 0.0),
1755  // definition point 3
1756  getRealValue(15, 0.0), getRealValue(25, 0.0),
1757  getRealValue(35, 0.0));
1758  creationInterface->addDimAngular3P(d, da);
1759 }
1760 
1767 
1768  // ordinate dimension:
1769  DL_DimOrdinateData dl(
1770  // definition point 1
1771  getRealValue(13, 0.0), getRealValue(23, 0.0), getRealValue(33, 0.0),
1772  // definition point 2
1773  getRealValue(14, 0.0), getRealValue(24, 0.0), getRealValue(34, 0.0),
1774  (getIntValue(70, 0) & 64) == 64 // true: X-type, false: Y-type
1775  );
1776  creationInterface->addDimOrdinate(d, dl);
1777 }
1778 
1782 void DL_Dxf::addLeader(DL_CreationInterface* creationInterface) {
1783  // leader (arrow)
1784  DL_LeaderData le(
1785  // arrow head flag
1786  getIntValue(71, 1),
1787  // leader path type
1788  getIntValue(72, 0),
1789  // Leader creation flag
1790  getIntValue(73, 3),
1791  // Hookline direction flag
1792  getIntValue(74, 1),
1793  // Hookline flag
1794  getIntValue(75, 0),
1795  // Text annotation height
1796  getRealValue(40, 1.0),
1797  // Text annotation width
1798  getRealValue(41, 1.0),
1799  // Number of vertices in leader
1800  getIntValue(76, 0));
1801  creationInterface->addLeader(le);
1802 
1803  for (int i = 0; i < maxLeaderVertices; i++) {
1804  DL_LeaderVertexData d(leaderVertices[i * 3], leaderVertices[i * 3 + 1],
1805  leaderVertices[i * 3 + 2]);
1806 
1807  creationInterface->addLeaderVertex(d);
1808  }
1809  creationInterface->endEntity();
1810 }
1811 
1815 void DL_Dxf::addHatch(DL_CreationInterface* creationInterface) {
1816  DL_HatchData hd(getIntValue(91, 1), getIntValue(70, 0),
1817  getRealValue(41, 1.0), getRealValue(52, 0.0),
1818  getStringValue(2, ""));
1819 
1820  creationInterface->addHatch(hd);
1821 
1822  for (unsigned int i = 0; i < hatchEdges.size(); i++) {
1823  creationInterface->addHatchLoop(
1824  DL_HatchLoopData(static_cast<int>(hatchEdges[i].size())));
1825  for (unsigned int k = 0; k < hatchEdges[i].size(); k++) {
1826  creationInterface->addHatchEdge(DL_HatchEdgeData(hatchEdges[i][k]));
1827  }
1828  }
1829 
1830  creationInterface->endEntity();
1831 }
1832 
1834  addHatchEdge();
1835  hatchEdges.push_back(std::vector<DL_HatchEdgeData>());
1836 }
1837 
1839  if (hatchEdge.defined) {
1840  if (hatchEdges.size() > 0) {
1841  hatchEdges.back().push_back(hatchEdge);
1842  }
1843  hatchEdge = DL_HatchEdgeData();
1844  }
1845 }
1846 
1851  // New polyline loop, group code 92
1852  // or new loop with individual edges, group code 93
1853  if (groupCode == 92 || groupCode == 93) {
1854  if (firstHatchLoop) {
1855  hatchEdges.clear();
1856  firstHatchLoop = false;
1857  }
1858  if (groupCode == 92 && (toInt(groupValue) & 2) == 2) {
1859  addHatchLoop();
1860  }
1861  if (groupCode == 93) {
1862  addHatchLoop();
1863  }
1864  return true;
1865  }
1866 
1867  // New hatch edge or new section / entity: add last hatch edge:
1868  if (groupCode == 72 || groupCode == 0 || groupCode == 78 ||
1869  groupCode == 98) {
1870  // polyline boundaries use code 72 for bulge flag:
1871  if (groupCode != 72 || (getIntValue(92, 0) & 2) == 0) {
1872  addHatchEdge();
1873  }
1874 
1875  if (groupCode == 0 /*|| groupCode==78*/) {
1876  addHatch(creationInterface);
1877  } else {
1878  hatchEdge.type = toInt(groupValue);
1879  }
1880  return true;
1881  }
1882 
1883  // polyline boundary:
1884  if ((getIntValue(92, 0) & 2) == 2) {
1885  switch (groupCode) {
1886  case 10:
1887  hatchEdge.type = 0;
1888  hatchEdge.vertices.push_back(std::vector<double>());
1889  hatchEdge.vertices.back().push_back(toReal(groupValue));
1890  return true;
1891  case 20:
1892  if (!hatchEdge.vertices.empty()) {
1893  hatchEdge.vertices.back().push_back(toReal(groupValue));
1894  hatchEdge.defined = true;
1895  }
1896  return true;
1897  case 42:
1898  if (!hatchEdge.vertices.empty()) {
1899  hatchEdge.vertices.back().push_back(toReal(groupValue));
1900  hatchEdge.defined = true;
1901  }
1902  return true;
1903  }
1904  } else {
1905  // Line edge:
1906  if (hatchEdge.type == 1) {
1907  switch (groupCode) {
1908  case 10:
1909  hatchEdge.x1 = toReal(groupValue);
1910  return true;
1911  case 20:
1912  hatchEdge.y1 = toReal(groupValue);
1913  return true;
1914  case 11:
1915  hatchEdge.x2 = toReal(groupValue);
1916  return true;
1917  case 21:
1918  hatchEdge.y2 = toReal(groupValue);
1919  hatchEdge.defined = true;
1920  return true;
1921  }
1922  }
1923 
1924  // Arc edge:
1925  if (hatchEdge.type == 2) {
1926  switch (groupCode) {
1927  case 10:
1928  hatchEdge.cx = toReal(groupValue);
1929  return true;
1930  case 20:
1931  hatchEdge.cy = toReal(groupValue);
1932  return true;
1933  case 40:
1934  hatchEdge.radius = toReal(groupValue);
1935  return true;
1936  case 50:
1937  hatchEdge.angle1 = toReal(groupValue) / 360.0 * 2 * M_PI;
1938  return true;
1939  case 51:
1940  hatchEdge.angle2 = toReal(groupValue) / 360.0 * 2 * M_PI;
1941  return true;
1942  case 73:
1943  hatchEdge.ccw = (bool)toInt(groupValue);
1944  hatchEdge.defined = true;
1945  return true;
1946  }
1947  }
1948 
1949  // Ellipse arc edge:
1950  if (hatchEdge.type == 3) {
1951  switch (groupCode) {
1952  case 10:
1953  hatchEdge.cx = toReal(groupValue);
1954  return true;
1955  case 20:
1956  hatchEdge.cy = toReal(groupValue);
1957  return true;
1958  case 11:
1959  hatchEdge.mx = toReal(groupValue);
1960  return true;
1961  case 21:
1962  hatchEdge.my = toReal(groupValue);
1963  return true;
1964  case 40:
1965  hatchEdge.ratio = toReal(groupValue);
1966  return true;
1967  case 50:
1968  hatchEdge.angle1 = toReal(groupValue) / 360.0 * 2 * M_PI;
1969  return true;
1970  case 51:
1971  hatchEdge.angle2 = toReal(groupValue) / 360.0 * 2 * M_PI;
1972  return true;
1973  case 73:
1974  hatchEdge.ccw = (bool)toInt(groupValue);
1975  hatchEdge.defined = true;
1976  return true;
1977  }
1978  }
1979 
1980  // Spline edge:
1981  if (hatchEdge.type == 4) {
1982  switch (groupCode) {
1983  case 94:
1984  hatchEdge.degree = toInt(groupValue);
1985  return true;
1986  case 73:
1987  hatchEdge.rational = toBool(groupValue);
1988  return true;
1989  case 74:
1990  hatchEdge.periodic = toBool(groupValue);
1991  return true;
1992  case 95:
1993  hatchEdge.nKnots = toInt(groupValue);
1994  return true;
1995  case 96:
1996  hatchEdge.nControl = toInt(groupValue);
1997  return true;
1998  case 97:
1999  hatchEdge.nFit = toInt(groupValue);
2000  return true;
2001  case 40:
2002  if (hatchEdge.knots.size() < hatchEdge.nKnots) {
2003  hatchEdge.knots.push_back(toReal(groupValue));
2004  }
2005  return true;
2006  case 10:
2007  if (hatchEdge.controlPoints.size() < hatchEdge.nControl) {
2008  std::vector<double> v;
2009  v.push_back(toReal(groupValue));
2010  hatchEdge.controlPoints.push_back(v);
2011  }
2012  return true;
2013  case 20:
2014  if (!hatchEdge.controlPoints.empty() &&
2015  hatchEdge.controlPoints.back().size() == 1) {
2016  hatchEdge.controlPoints.back().push_back(
2017  toReal(groupValue));
2018  }
2019  hatchEdge.defined = true;
2020  return true;
2021  case 42:
2022  if (hatchEdge.weights.size() < hatchEdge.nControl) {
2023  hatchEdge.weights.push_back(toReal(groupValue));
2024  }
2025  return true;
2026  case 11:
2027  if (hatchEdge.fitPoints.size() < hatchEdge.nFit) {
2028  std::vector<double> v;
2029  v.push_back(toReal(groupValue));
2030  hatchEdge.fitPoints.push_back(v);
2031  }
2032  return true;
2033  case 21:
2034  if (!hatchEdge.fitPoints.empty() &&
2035  hatchEdge.fitPoints.back().size() == 1) {
2036  hatchEdge.fitPoints.back().push_back(
2037  toReal(groupValue));
2038  }
2039  hatchEdge.defined = true;
2040  return true;
2041  case 12:
2042  hatchEdge.startTangentX = toReal(groupValue);
2043  return true;
2044  case 22:
2045  hatchEdge.startTangentY = toReal(groupValue);
2046  return true;
2047  case 13:
2048  hatchEdge.endTangentX = toReal(groupValue);
2049  return true;
2050  case 23:
2051  hatchEdge.endTangentY = toReal(groupValue);
2052  return true;
2053  }
2054  }
2055  }
2056 
2057  return false;
2058 }
2059 
2063 void DL_Dxf::addImage(DL_CreationInterface* creationInterface) {
2064  DL_ImageData id( // pass ref insead of name we don't have yet
2065  getStringValue(340, ""),
2066  // ins point:
2067  getRealValue(10, 0.0), getRealValue(20, 0.0), getRealValue(30, 0.0),
2068  // u vector:
2069  getRealValue(11, 1.0), getRealValue(21, 0.0), getRealValue(31, 0.0),
2070  // v vector:
2071  getRealValue(12, 0.0), getRealValue(22, 1.0), getRealValue(32, 0.0),
2072  // image size (pixel):
2073  getIntValue(13, 1), getIntValue(23, 1),
2074  // brightness, contrast, fade
2075  getIntValue(281, 50), getIntValue(282, 50), getIntValue(283, 0));
2076 
2077  creationInterface->addImage(id);
2078  creationInterface->endEntity();
2079  currentObjectType = DL_UNKNOWN;
2080 }
2081 
2086 void DL_Dxf::addImageDef(DL_CreationInterface* creationInterface) {
2087  DL_ImageDefData id( // handle
2088  getStringValue(5, ""), getStringValue(1, ""));
2089 
2090  creationInterface->linkImage(id);
2091  creationInterface->endEntity();
2092  currentObjectType = DL_UNKNOWN;
2093 }
2094 
2098 void DL_Dxf::endEntity(DL_CreationInterface* creationInterface) {
2099  creationInterface->endEntity();
2100 }
2101 
2105 void DL_Dxf::endSequence(DL_CreationInterface* creationInterface) {
2106  creationInterface->endSequence();
2107 }
2108 
2113 // int DL_Dxf::stringToInt(const char* s, bool* ok) {
2114 // if (ok!=NULL) {
2115 // // check string:
2116 // *ok = true;
2117 // int i=0;
2118 // bool dot = false;
2119 // do {
2120 // if (s[i]=='\0') {
2121 // break;
2122 // } else if (s[i]=='.') {
2123 // if (dot==true) {
2124 // //std::cerr << "two dots\n";
2125 // *ok = false;
2126 // } else {
2127 // dot = true;
2128 // }
2129 // } else if (s[i]<'0' || s[i]>'9') {
2130 // //std::cerr << "NaN: '" << s[i] << "'\n";
2131 // *ok = false;
2132 // }
2133 // i++;
2134 // } while(s[i]!='\0' && *ok==true);
2135 // }
2136 
2137 // return atoi(s);
2138 //}
2139 
2150  char* f = new char[strlen(file) + 1];
2151  strcpy(f, file);
2152  this->version = version;
2153 
2154  DL_WriterA* dw = new DL_WriterA(f, version);
2155  if (dw->openFailed()) {
2156  delete dw;
2157  delete[] f;
2158  return NULL;
2159  } else {
2160  delete[] f;
2161  return dw;
2162  }
2163 }
2164 
2170  dw.comment("dxflib " DL_VERSION);
2171  dw.sectionHeader();
2172 
2173  dw.dxfString(9, "$ACADVER");
2174  switch (version) {
2175  case DL_Codes::AC1009:
2176  dw.dxfString(1, "AC1009");
2177  break;
2178  case DL_Codes::AC1012:
2179  dw.dxfString(1, "AC1012");
2180  break;
2181  case DL_Codes::AC1014:
2182  dw.dxfString(1, "AC1014");
2183  break;
2184  case DL_Codes::AC1015:
2185  dw.dxfString(1, "AC1015");
2186  break;
2187  case DL_Codes::AC1009_MIN:
2188  // minimalistic DXF version is unidentified in file:
2189  break;
2190  }
2191 
2192  // Newer version require that (otherwise a*cad crashes..)
2193  if (version == DL_VERSION_2000) {
2194  dw.dxfString(9, "$HANDSEED");
2195  dw.dxfHex(5, 0xFFFF);
2196  }
2197 
2198  // commented out: more variables can be added after that by caller:
2199  // dw.sectionEnd();
2200 }
2201 
2210  const DL_PointData& data,
2211  const DL_Attributes& attrib) {
2212  dw.entity("POINT");
2213  if (version == DL_VERSION_2000) {
2214  dw.dxfString(100, "AcDbEntity");
2215  }
2216  dw.entityAttributes(attrib);
2217  if (version == DL_VERSION_2000) {
2218  dw.dxfString(100, "AcDbPoint");
2219  }
2220  dw.coord(DL_POINT_COORD_CODE, data.x, data.y, data.z);
2221 }
2222 
2231  const DL_LineData& data,
2232  const DL_Attributes& attrib) {
2233  dw.entity("LINE");
2234  if (version == DL_VERSION_2000) {
2235  dw.dxfString(100, "AcDbEntity");
2236  }
2237  dw.entityAttributes(attrib);
2238  if (version == DL_VERSION_2000) {
2239  dw.dxfString(100, "AcDbLine");
2240  }
2241  dw.coord(DL_LINE_START_CODE, data.x1, data.y1, data.z1);
2242  dw.coord(DL_LINE_END_CODE, data.x2, data.y2, data.z2);
2243 }
2244 
2253  const DL_XLineData& data,
2254  const DL_Attributes& attrib) {
2255  dw.entity("XLINE");
2256  if (version == DL_VERSION_2000) {
2257  dw.dxfString(100, "AcDbEntity");
2258  }
2259  dw.entityAttributes(attrib);
2260  if (version == DL_VERSION_2000) {
2261  dw.dxfString(100, "AcDbLine");
2262  }
2263  dw.coord(DL_LINE_START_CODE, data.bx, data.by, data.bz);
2264  dw.coord(DL_LINE_END_CODE, data.dx, data.dy, data.dz);
2265 }
2266 
2275  const DL_RayData& data,
2276  const DL_Attributes& attrib) {
2277  dw.entity("RAY");
2278  if (version == DL_VERSION_2000) {
2279  dw.dxfString(100, "AcDbEntity");
2280  }
2281  dw.entityAttributes(attrib);
2282  if (version == DL_VERSION_2000) {
2283  dw.dxfString(100, "AcDbLine");
2284  }
2285  dw.coord(DL_LINE_START_CODE, data.bx, data.by, data.bz);
2286  dw.coord(DL_LINE_END_CODE, data.dx, data.dy, data.dz);
2287 }
2288 
2298  const DL_PolylineData& data,
2299  const DL_Attributes& attrib) {
2300  if (version == DL_VERSION_2000) {
2301  dw.entity("LWPOLYLINE");
2302  dw.dxfString(100, "AcDbEntity");
2303  dw.entityAttributes(attrib);
2304  dw.dxfString(100, "AcDbPolyline");
2305  dw.dxfInt(90, (int)data.number);
2306  dw.dxfInt(70, data.flags);
2307  } else {
2308  dw.entity("POLYLINE");
2309  dw.entityAttributes(attrib);
2310  polylineLayer = attrib.getLayer();
2311  dw.dxfInt(66, 1);
2312  dw.dxfInt(70, data.flags);
2313  dw.coord(DL_VERTEX_COORD_CODE, 0.0, 0.0, 0.0);
2314  }
2315 }
2316 
2325  if (version == DL_VERSION_2000) {
2326  dw.dxfReal(10, data.x);
2327  dw.dxfReal(20, data.y);
2328  dw.dxfReal(30, data.z);
2329  if (fabs(data.bulge) > 1.0e-10) {
2330  dw.dxfReal(42, data.bulge);
2331  }
2332  } else {
2333  dw.entity("VERTEX");
2334  // dw.entityAttributes(attrib);
2335  dw.dxfString(8, polylineLayer);
2336  dw.coord(DL_VERTEX_COORD_CODE, data.x, data.y, data.z);
2337  if (fabs(data.bulge) > 1.0e-10) {
2338  dw.dxfReal(42, data.bulge);
2339  }
2340  }
2341 }
2342 
2347  if (version == DL_VERSION_2000) {
2348  } else {
2349  dw.entity("SEQEND");
2350  }
2351 }
2352 
2362  const DL_SplineData& data,
2363  const DL_Attributes& attrib) {
2364  dw.entity("SPLINE");
2365  if (version == DL_VERSION_2000) {
2366  dw.dxfString(100, "AcDbEntity");
2367  }
2368  dw.entityAttributes(attrib);
2369  if (version == DL_VERSION_2000) {
2370  dw.dxfString(100, "AcDbSpline");
2371  }
2372  dw.dxfInt(70, data.flags);
2373  dw.dxfInt(71, data.degree);
2374  dw.dxfInt(72, data.nKnots); // number of knots
2375  dw.dxfInt(73, data.nControl); // number of control points
2376  dw.dxfInt(74, data.nFit); // number of fit points
2377 }
2378 
2387  const DL_ControlPointData& data) {
2388  dw.dxfReal(10, data.x);
2389  dw.dxfReal(20, data.y);
2390  dw.dxfReal(30, data.z);
2391 }
2392 
2401  dw.dxfReal(11, data.x);
2402  dw.dxfReal(21, data.y);
2403  dw.dxfReal(31, data.z);
2404 }
2405 
2414  dw.dxfReal(40, data.k);
2415 }
2416 
2425  const DL_CircleData& data,
2426  const DL_Attributes& attrib) {
2427  dw.entity("CIRCLE");
2428  if (version == DL_VERSION_2000) {
2429  dw.dxfString(100, "AcDbEntity");
2430  }
2431  dw.entityAttributes(attrib);
2432  if (version == DL_VERSION_2000) {
2433  dw.dxfString(100, "AcDbCircle");
2434  }
2435  dw.coord(10, data.cx, data.cy, data.cz);
2436  dw.dxfReal(40, data.radius);
2437 }
2438 
2447  const DL_ArcData& data,
2448  const DL_Attributes& attrib) {
2449  dw.entity("ARC");
2450  if (version == DL_VERSION_2000) {
2451  dw.dxfString(100, "AcDbEntity");
2452  }
2453  dw.entityAttributes(attrib);
2454  if (version == DL_VERSION_2000) {
2455  dw.dxfString(100, "AcDbCircle");
2456  }
2457  dw.coord(10, data.cx, data.cy, data.cz);
2458  dw.dxfReal(40, data.radius);
2459  if (version == DL_VERSION_2000) {
2460  dw.dxfString(100, "AcDbArc");
2461  }
2462  dw.dxfReal(50, data.angle1);
2463  dw.dxfReal(51, data.angle2);
2464 }
2465 
2474  const DL_EllipseData& data,
2475  const DL_Attributes& attrib) {
2476  if (version > DL_VERSION_R12) {
2477  dw.entity("ELLIPSE");
2478  if (version == DL_VERSION_2000) {
2479  dw.dxfString(100, "AcDbEntity");
2480  }
2481  dw.entityAttributes(attrib);
2482  if (version == DL_VERSION_2000) {
2483  dw.dxfString(100, "AcDbEllipse");
2484  }
2485  dw.coord(10, data.cx, data.cy, data.cz);
2486  dw.coord(11, data.mx, data.my, data.mz);
2487  dw.dxfReal(40, data.ratio);
2488  dw.dxfReal(41, data.angle1);
2489  dw.dxfReal(42, data.angle2);
2490  }
2491 }
2492 
2501  const DL_SolidData& data,
2502  const DL_Attributes& attrib) {
2503  dw.entity("SOLID");
2504  if (version == DL_VERSION_2000) {
2505  dw.dxfString(100, "AcDbEntity");
2506  }
2507  dw.entityAttributes(attrib);
2508  if (version == DL_VERSION_2000) {
2509  dw.dxfString(100, "AcDbTrace");
2510  }
2511  dw.coord(10, data.x[0], data.y[0], data.z[0]);
2512  dw.coord(11, data.x[1], data.y[1], data.z[1]);
2513  dw.coord(12, data.x[2], data.y[2], data.z[2]);
2514  dw.coord(13, data.x[3], data.y[3], data.z[3]);
2515  dw.dxfReal(39, data.thickness);
2516 }
2517 
2526  const DL_TraceData& data,
2527  const DL_Attributes& attrib) {
2528  dw.entity("TRACE");
2529  if (version == DL_VERSION_2000) {
2530  dw.dxfString(100, "AcDbEntity");
2531  }
2532  dw.entityAttributes(attrib);
2533  if (version == DL_VERSION_2000) {
2534  dw.dxfString(100, "AcDbTrace");
2535  }
2536  dw.coord(10, data.x[0], data.y[0], data.z[0]);
2537  dw.coord(11, data.x[1], data.y[1], data.z[1]);
2538  dw.coord(12, data.x[2], data.y[2], data.z[2]);
2539  dw.coord(13, data.x[3], data.y[3], data.z[3]);
2540  dw.dxfReal(39, data.thickness);
2541 }
2542 
2551  const DL_3dFaceData& data,
2552  const DL_Attributes& attrib) {
2553  dw.entity("3DFACE");
2554  if (version == DL_VERSION_2000) {
2555  dw.dxfString(100, "AcDbEntity");
2556  }
2557  dw.entityAttributes(attrib);
2558  if (version == DL_VERSION_2000) {
2559  dw.dxfString(100, "AcDbFace");
2560  }
2561  dw.coord(10, data.x[0], data.y[0], data.z[0]);
2562  dw.coord(11, data.x[1], data.y[1], data.z[1]);
2563  dw.coord(12, data.x[2], data.y[2], data.z[2]);
2564  dw.coord(13, data.x[3], data.y[3], data.z[3]);
2565 }
2566 
2575  const DL_InsertData& data,
2576  const DL_Attributes& attrib) {
2577  if (data.name.empty()) {
2578  std::cerr << "DL_Dxf::writeInsert: "
2579  << "Block name must not be empty\n";
2580  return;
2581  }
2582 
2583  dw.entity("INSERT");
2584  if (version == DL_VERSION_2000) {
2585  dw.dxfString(100, "AcDbEntity");
2586  }
2587  dw.entityAttributes(attrib);
2588  if (version == DL_VERSION_2000) {
2589  if (data.cols != 1 || data.rows != 1) {
2590  dw.dxfString(100, "AcDbMInsertBlock");
2591  } else {
2592  dw.dxfString(100, "AcDbBlockReference");
2593  }
2594  }
2595  dw.dxfString(2, data.name);
2596  dw.dxfReal(10, data.ipx);
2597  dw.dxfReal(20, data.ipy);
2598  dw.dxfReal(30, data.ipz);
2599  if (data.sx != 1.0 || data.sy != 1.0) {
2600  dw.dxfReal(41, data.sx);
2601  dw.dxfReal(42, data.sy);
2602  dw.dxfReal(43, 1.0);
2603  }
2604  if (data.angle != 0.0) {
2605  dw.dxfReal(50, data.angle);
2606  }
2607  if (data.cols != 1 || data.rows != 1) {
2608  dw.dxfInt(70, data.cols);
2609  dw.dxfInt(71, data.rows);
2610  }
2611  if (data.colSp != 0.0 || data.rowSp != 0.0) {
2612  dw.dxfReal(44, data.colSp);
2613  dw.dxfReal(45, data.rowSp);
2614  }
2615 }
2616 
2625  const DL_MTextData& data,
2626  const DL_Attributes& attrib) {
2627  dw.entity("MTEXT");
2628  if (version == DL_VERSION_2000) {
2629  dw.dxfString(100, "AcDbEntity");
2630  }
2631  dw.entityAttributes(attrib);
2632  if (version == DL_VERSION_2000) {
2633  dw.dxfString(100, "AcDbMText");
2634  }
2635  dw.dxfReal(10, data.ipx);
2636  dw.dxfReal(20, data.ipy);
2637  dw.dxfReal(30, data.ipz);
2638  dw.dxfReal(40, data.height);
2639  dw.dxfReal(41, data.width);
2640 
2641  dw.dxfInt(71, data.attachmentPoint);
2642  dw.dxfInt(72, data.drawingDirection);
2643 
2644  // Creare text chunks of 250 characters each:
2645  int length = static_cast<int>(data.text.length());
2646  char chunk[251];
2647  int i;
2648  for (i = 250; i < length; i += 250) {
2649  strncpy(chunk, &data.text.c_str()[i - 250], 250);
2650  chunk[250] = '\0';
2651  dw.dxfString(3, chunk);
2652  }
2653  strncpy(chunk, &data.text.c_str()[i - 250], 250);
2654  chunk[250] = '\0';
2655  dw.dxfString(1, chunk);
2656 
2657  dw.dxfString(7, data.style);
2658 
2659  // since dxflib 2.0.2.1: degrees not rad (error in autodesk dxf doc)
2660  dw.dxfReal(50, data.angle / (2.0 * M_PI) * 360.0);
2661 
2662  dw.dxfInt(73, data.lineSpacingStyle);
2663  dw.dxfReal(44, data.lineSpacingFactor);
2664 }
2665 
2674  const DL_TextData& data,
2675  const DL_Attributes& attrib) {
2676  dw.entity("TEXT");
2677  if (version == DL_VERSION_2000) {
2678  dw.dxfString(100, "AcDbEntity");
2679  }
2680  dw.entityAttributes(attrib);
2681  if (version == DL_VERSION_2000) {
2682  dw.dxfString(100, "AcDbText");
2683  }
2684  dw.dxfReal(10, data.ipx);
2685  dw.dxfReal(20, data.ipy);
2686  dw.dxfReal(30, data.ipz);
2687  dw.dxfReal(40, data.height);
2688  dw.dxfString(1, data.text);
2689  dw.dxfReal(50, data.angle / (2 * M_PI) * 360.0);
2690  dw.dxfReal(41, data.xScaleFactor);
2691  dw.dxfString(7, data.style);
2692 
2693  dw.dxfInt(71, data.textGenerationFlags);
2694  dw.dxfInt(72, data.hJustification);
2695 
2696  dw.dxfReal(11, data.apx);
2697  dw.dxfReal(21, data.apy);
2698  dw.dxfReal(31, data.apz);
2699 
2700  if (version == DL_VERSION_2000) {
2701  // required twice for some reason:
2702  dw.dxfString(100, "AcDbText");
2703  }
2704 
2705  dw.dxfInt(73, data.vJustification);
2706 }
2707 
2709  const DL_AttributeData& data,
2710  const DL_Attributes& attrib) {
2711  dw.entity("ATTRIB");
2712  if (version == DL_VERSION_2000) {
2713  dw.dxfString(100, "AcDbEntity");
2714  }
2715  dw.entityAttributes(attrib);
2716  if (version == DL_VERSION_2000) {
2717  dw.dxfString(100, "AcDbText");
2718  }
2719  dw.dxfReal(10, data.ipx);
2720  dw.dxfReal(20, data.ipy);
2721  dw.dxfReal(30, data.ipz);
2722  dw.dxfReal(40, data.height);
2723  dw.dxfString(1, data.text);
2724  dw.dxfReal(50, data.angle / (2 * M_PI) * 360.0);
2725  dw.dxfReal(41, data.xScaleFactor);
2726  dw.dxfString(7, data.style);
2727 
2728  dw.dxfInt(71, data.textGenerationFlags);
2729  dw.dxfInt(72, data.hJustification);
2730 
2731  dw.dxfReal(11, data.apx);
2732  dw.dxfReal(21, data.apy);
2733  dw.dxfReal(31, data.apz);
2734 
2735  if (version == DL_VERSION_2000) {
2736  dw.dxfString(100, "AcDbAttribute");
2737  }
2738 
2739  dw.dxfString(2, data.tag);
2740  dw.dxfInt(74, data.vJustification);
2741 }
2742 
2744  const DL_DimensionData& data) {
2745  if (version == DL_VERSION_2000) {
2746  dw.dxfString(1001, "ACAD");
2747  dw.dxfString(1000, "DSTYLE");
2748  dw.dxfString(1002, "{");
2749  dw.dxfInt(1070, 144);
2750  dw.dxfReal(1040, data.linearFactor);
2751  dw.dxfInt(1070, 40);
2752  dw.dxfReal(1040, data.dimScale);
2753  dw.dxfString(1002, "}");
2754  }
2755 }
2756 
2766  const DL_DimensionData& data,
2767  const DL_DimAlignedData& edata,
2768  const DL_Attributes& attrib) {
2769  dw.entity("DIMENSION");
2770 
2771  if (version == DL_VERSION_2000) {
2772  dw.dxfString(100, "AcDbEntity");
2773  }
2774  dw.entityAttributes(attrib);
2775  if (version == DL_VERSION_2000) {
2776  dw.dxfString(100, "AcDbDimension");
2777  }
2778 
2779  dw.dxfReal(10, data.dpx);
2780  dw.dxfReal(20, data.dpy);
2781  dw.dxfReal(30, data.dpz);
2782 
2783  dw.dxfReal(11, data.mpx);
2784  dw.dxfReal(21, data.mpy);
2785  dw.dxfReal(31, 0.0);
2786 
2787  dw.dxfInt(70, data.type);
2788  if (version > DL_VERSION_R12) {
2789  dw.dxfInt(71, data.attachmentPoint);
2790  dw.dxfInt(72, data.lineSpacingStyle); // opt
2791  dw.dxfReal(41, data.lineSpacingFactor); // opt
2792  }
2793 
2794  dw.dxfReal(42, data.angle);
2795 
2796  dw.dxfString(1, data.text); // opt
2797  // dw.dxfString(3, data.style);
2798  dw.dxfString(3, "Standard");
2799 
2800  if (version == DL_VERSION_2000) {
2801  dw.dxfString(100, "AcDbAlignedDimension");
2802  }
2803 
2804  dw.dxfReal(13, edata.epx1);
2805  dw.dxfReal(23, edata.epy1);
2806  dw.dxfReal(33, 0.0);
2807 
2808  dw.dxfReal(14, edata.epx2);
2809  dw.dxfReal(24, edata.epy2);
2810  dw.dxfReal(34, 0.0);
2811 
2813 }
2814 
2824  const DL_DimensionData& data,
2825  const DL_DimLinearData& edata,
2826  const DL_Attributes& attrib) {
2827  dw.entity("DIMENSION");
2828 
2829  if (version == DL_VERSION_2000) {
2830  dw.dxfString(100, "AcDbEntity");
2831  }
2832  dw.entityAttributes(attrib);
2833  if (version == DL_VERSION_2000) {
2834  dw.dxfString(100, "AcDbDimension");
2835  }
2836 
2837  dw.dxfReal(10, data.dpx);
2838  dw.dxfReal(20, data.dpy);
2839  dw.dxfReal(30, data.dpz);
2840 
2841  dw.dxfReal(11, data.mpx);
2842  dw.dxfReal(21, data.mpy);
2843  dw.dxfReal(31, 0.0);
2844 
2845  dw.dxfInt(70, data.type);
2846  if (version > DL_VERSION_R12) {
2847  dw.dxfInt(71, data.attachmentPoint);
2848  dw.dxfInt(72, data.lineSpacingStyle); // opt
2849  dw.dxfReal(41, data.lineSpacingFactor); // opt
2850  }
2851 
2852  dw.dxfReal(42, data.angle);
2853 
2854  dw.dxfString(1, data.text); // opt
2855  // dw.dxfString(3, data.style);
2856  dw.dxfString(3, "Standard");
2857 
2858  if (version == DL_VERSION_2000) {
2859  dw.dxfString(100, "AcDbAlignedDimension");
2860  }
2861 
2862  dw.dxfReal(13, edata.dpx1);
2863  dw.dxfReal(23, edata.dpy1);
2864  dw.dxfReal(33, 0.0);
2865 
2866  dw.dxfReal(14, edata.dpx2);
2867  dw.dxfReal(24, edata.dpy2);
2868  dw.dxfReal(34, 0.0);
2869 
2870  dw.dxfReal(50, edata.angle / (2.0 * M_PI) * 360.0);
2871 
2872  if (version == DL_VERSION_2000) {
2873  dw.dxfString(100, "AcDbRotatedDimension");
2874  }
2875 
2877 }
2878 
2888  const DL_DimensionData& data,
2889  const DL_DimRadialData& edata,
2890  const DL_Attributes& attrib) {
2891  dw.entity("DIMENSION");
2892 
2893  if (version == DL_VERSION_2000) {
2894  dw.dxfString(100, "AcDbEntity");
2895  }
2896  dw.entityAttributes(attrib);
2897  if (version == DL_VERSION_2000) {
2898  dw.dxfString(100, "AcDbDimension");
2899  }
2900 
2901  dw.dxfReal(10, data.dpx);
2902  dw.dxfReal(20, data.dpy);
2903  dw.dxfReal(30, data.dpz);
2904 
2905  dw.dxfReal(11, data.mpx);
2906  dw.dxfReal(21, data.mpy);
2907  dw.dxfReal(31, 0.0);
2908 
2909  dw.dxfInt(70, data.type);
2910  if (version > DL_VERSION_R12) {
2911  dw.dxfInt(71, data.attachmentPoint);
2912  dw.dxfInt(72, data.lineSpacingStyle); // opt
2913  dw.dxfReal(41, data.lineSpacingFactor); // opt
2914  }
2915 
2916  dw.dxfReal(42, data.angle);
2917 
2918  dw.dxfString(1, data.text); // opt
2919  // dw.dxfString(3, data.style);
2920  dw.dxfString(3, "Standard");
2921 
2922  if (version == DL_VERSION_2000) {
2923  dw.dxfString(100, "AcDbRadialDimension");
2924  }
2925 
2926  dw.dxfReal(15, edata.dpx);
2927  dw.dxfReal(25, edata.dpy);
2928  dw.dxfReal(35, 0.0);
2929 
2930  dw.dxfReal(40, edata.leader);
2931 
2933 }
2934 
2944  const DL_DimensionData& data,
2945  const DL_DimDiametricData& edata,
2946  const DL_Attributes& attrib) {
2947  dw.entity("DIMENSION");
2948 
2949  if (version == DL_VERSION_2000) {
2950  dw.dxfString(100, "AcDbEntity");
2951  }
2952  dw.entityAttributes(attrib);
2953  if (version == DL_VERSION_2000) {
2954  dw.dxfString(100, "AcDbDimension");
2955  }
2956 
2957  dw.dxfReal(10, data.dpx);
2958  dw.dxfReal(20, data.dpy);
2959  dw.dxfReal(30, data.dpz);
2960 
2961  dw.dxfReal(11, data.mpx);
2962  dw.dxfReal(21, data.mpy);
2963  dw.dxfReal(31, 0.0);
2964 
2965  dw.dxfInt(70, data.type);
2966  if (version > DL_VERSION_R12) {
2967  dw.dxfInt(71, data.attachmentPoint);
2968  dw.dxfInt(72, data.lineSpacingStyle); // opt
2969  dw.dxfReal(41, data.lineSpacingFactor); // opt
2970  }
2971 
2972  dw.dxfReal(42, data.angle);
2973 
2974  dw.dxfString(1, data.text); // opt
2975  // dw.dxfString(3, data.style);
2976  dw.dxfString(3, "Standard");
2977 
2978  if (version == DL_VERSION_2000) {
2979  dw.dxfString(100, "AcDbDiametricDimension");
2980  }
2981 
2982  dw.dxfReal(15, edata.dpx);
2983  dw.dxfReal(25, edata.dpy);
2984  dw.dxfReal(35, 0.0);
2985 
2986  dw.dxfReal(40, edata.leader);
2987 
2989 }
2990 
3000  const DL_DimensionData& data,
3001  const DL_DimAngularData& edata,
3002  const DL_Attributes& attrib) {
3003  dw.entity("DIMENSION");
3004 
3005  if (version == DL_VERSION_2000) {
3006  dw.dxfString(100, "AcDbEntity");
3007  }
3008  dw.entityAttributes(attrib);
3009  if (version == DL_VERSION_2000) {
3010  dw.dxfString(100, "AcDbDimension");
3011  }
3012 
3013  dw.dxfReal(10, data.dpx);
3014  dw.dxfReal(20, data.dpy);
3015  dw.dxfReal(30, data.dpz);
3016 
3017  dw.dxfReal(11, data.mpx);
3018  dw.dxfReal(21, data.mpy);
3019  dw.dxfReal(31, 0.0);
3020 
3021  dw.dxfInt(70, data.type);
3022  if (version > DL_VERSION_R12) {
3023  dw.dxfInt(71, data.attachmentPoint);
3024  dw.dxfInt(72, data.lineSpacingStyle); // opt
3025  dw.dxfReal(41, data.lineSpacingFactor); // opt
3026  }
3027 
3028  dw.dxfReal(42, data.angle);
3029 
3030  dw.dxfString(1, data.text); // opt
3031  // dw.dxfString(3, data.style);
3032  dw.dxfString(3, "Standard");
3033 
3034  if (version == DL_VERSION_2000) {
3035  dw.dxfString(100, "AcDb2LineAngularDimension");
3036  }
3037 
3038  dw.dxfReal(13, edata.dpx1);
3039  dw.dxfReal(23, edata.dpy1);
3040  dw.dxfReal(33, 0.0);
3041 
3042  dw.dxfReal(14, edata.dpx2);
3043  dw.dxfReal(24, edata.dpy2);
3044  dw.dxfReal(34, 0.0);
3045 
3046  dw.dxfReal(15, edata.dpx3);
3047  dw.dxfReal(25, edata.dpy3);
3048  dw.dxfReal(35, 0.0);
3049 
3050  dw.dxfReal(16, edata.dpx4);
3051  dw.dxfReal(26, edata.dpy4);
3052  dw.dxfReal(36, 0.0);
3053 }
3054 
3064  const DL_DimensionData& data,
3065  const DL_DimAngular3PData& edata,
3066  const DL_Attributes& attrib) {
3067  dw.entity("DIMENSION");
3068 
3069  if (version == DL_VERSION_2000) {
3070  dw.dxfString(100, "AcDbEntity");
3071  }
3072  dw.entityAttributes(attrib);
3073  if (version == DL_VERSION_2000) {
3074  dw.dxfString(100, "AcDbDimension");
3075  }
3076 
3077  dw.dxfReal(10, data.dpx);
3078  dw.dxfReal(20, data.dpy);
3079  dw.dxfReal(30, data.dpz);
3080 
3081  dw.dxfReal(11, data.mpx);
3082  dw.dxfReal(21, data.mpy);
3083  dw.dxfReal(31, 0.0);
3084 
3085  dw.dxfInt(70, data.type);
3086  if (version > DL_VERSION_R12) {
3087  dw.dxfInt(71, data.attachmentPoint);
3088  dw.dxfInt(72, data.lineSpacingStyle); // opt
3089  dw.dxfReal(41, data.lineSpacingFactor); // opt
3090  }
3091 
3092  dw.dxfReal(42, data.angle);
3093 
3094  dw.dxfString(1, data.text); // opt
3095  // dw.dxfString(3, data.style);
3096  dw.dxfString(3, "Standard");
3097 
3098  if (version == DL_VERSION_2000) {
3099  dw.dxfString(100, "AcDb3PointAngularDimension");
3100  }
3101 
3102  dw.dxfReal(13, edata.dpx1);
3103  dw.dxfReal(23, edata.dpy1);
3104  dw.dxfReal(33, 0.0);
3105 
3106  dw.dxfReal(14, edata.dpx2);
3107  dw.dxfReal(24, edata.dpy2);
3108  dw.dxfReal(34, 0.0);
3109 
3110  dw.dxfReal(15, edata.dpx3);
3111  dw.dxfReal(25, edata.dpy3);
3112  dw.dxfReal(35, 0.0);
3113 }
3114 
3124  const DL_DimensionData& data,
3125  const DL_DimOrdinateData& edata,
3126  const DL_Attributes& attrib) {
3127  dw.entity("DIMENSION");
3128 
3129  if (version == DL_VERSION_2000) {
3130  dw.dxfString(100, "AcDbEntity");
3131  }
3132  dw.entityAttributes(attrib);
3133  if (version == DL_VERSION_2000) {
3134  dw.dxfString(100, "AcDbDimension");
3135  }
3136 
3137  dw.dxfReal(10, data.dpx);
3138  dw.dxfReal(20, data.dpy);
3139  dw.dxfReal(30, data.dpz);
3140 
3141  dw.dxfReal(11, data.mpx);
3142  dw.dxfReal(21, data.mpy);
3143  dw.dxfReal(31, 0.0);
3144 
3145  int type = data.type;
3146  if (edata.xtype) {
3147  type |= 0x40;
3148  }
3149 
3150  dw.dxfInt(70, type);
3151  if (version > DL_VERSION_R12) {
3152  dw.dxfInt(71, data.attachmentPoint);
3153  dw.dxfInt(72, data.lineSpacingStyle); // opt
3154  dw.dxfReal(41, data.lineSpacingFactor); // opt
3155  }
3156 
3157  dw.dxfString(1, data.text); // opt
3158  // dw.dxfString(3, data.style);
3159  dw.dxfString(3, "Standard");
3160 
3161  if (version == DL_VERSION_2000) {
3162  dw.dxfString(100, "AcDbOrdinateDimension");
3163  }
3164 
3165  dw.dxfReal(13, edata.dpx1);
3166  dw.dxfReal(23, edata.dpy1);
3167  dw.dxfReal(33, 0.0);
3168 
3169  dw.dxfReal(14, edata.dpx2);
3170  dw.dxfReal(24, edata.dpy2);
3171  dw.dxfReal(34, 0.0);
3172 }
3173 
3183  const DL_LeaderData& data,
3184  const DL_Attributes& attrib) {
3185  if (version > DL_VERSION_R12) {
3186  dw.entity("LEADER");
3187  if (version == DL_VERSION_2000) {
3188  dw.dxfString(100, "AcDbEntity");
3189  }
3190  dw.entityAttributes(attrib);
3191  if (version == DL_VERSION_2000) {
3192  dw.dxfString(100, "AcDbLeader");
3193  }
3194  dw.dxfString(3, "Standard");
3195  dw.dxfInt(71, data.arrowHeadFlag);
3196  dw.dxfInt(72, data.leaderPathType);
3197  dw.dxfInt(73, data.leaderCreationFlag);
3198  dw.dxfInt(74, data.hooklineDirectionFlag);
3199  dw.dxfInt(75, data.hooklineFlag);
3200  dw.dxfReal(40, data.textAnnotationHeight);
3201  dw.dxfReal(41, data.textAnnotationWidth);
3202  dw.dxfInt(76, data.number);
3203  }
3204 }
3205 
3213  const DL_LeaderVertexData& data) {
3214  if (version > DL_VERSION_R12) {
3215  dw.dxfReal(10, data.x);
3216  dw.dxfReal(20, data.y);
3217  }
3218 }
3219 
3230  const DL_HatchData& data,
3231  const DL_Attributes& attrib) {
3232  dw.entity("HATCH");
3233  if (version == DL_VERSION_2000) {
3234  dw.dxfString(100, "AcDbEntity");
3235  }
3236  dw.entityAttributes(attrib);
3237  if (version == DL_VERSION_2000) {
3238  dw.dxfString(100, "AcDbHatch");
3239  }
3240  dw.dxfReal(10, 0.0); // elevation
3241  dw.dxfReal(20, 0.0);
3242  dw.dxfReal(30, 0.0);
3243  dw.dxfReal(210, 0.0); // extrusion dir.
3244  dw.dxfReal(220, 0.0);
3245  dw.dxfReal(230, 1.0);
3246  if (data.solid == false) {
3247  dw.dxfString(2, data.pattern);
3248  } else {
3249  dw.dxfString(2, "SOLID");
3250  }
3251  dw.dxfInt(70, (int)data.solid);
3252  dw.dxfInt(71, 0); // non-associative
3253  dw.dxfInt(91, data.numLoops);
3254 }
3255 
3264  const DL_HatchData& data,
3265  const DL_Attributes& /*attrib*/) {
3266  dw.dxfInt(75, 0); // odd parity
3267  dw.dxfInt(76, 1); // pattern type
3268  if (data.solid == false) {
3269  dw.dxfReal(52, data.angle);
3270  dw.dxfReal(41, data.scale);
3271  dw.dxfInt(77, 0); // not double
3272  // dw.dxfInt(78, 0);
3273  dw.dxfInt(78, 1);
3274  dw.dxfReal(53, 45.0);
3275  dw.dxfReal(43, 0.0);
3276  dw.dxfReal(44, 0.0);
3277  dw.dxfReal(45, -0.0883883476483184);
3278  dw.dxfReal(46, 0.0883883476483185);
3279  dw.dxfInt(79, 0);
3280  }
3281  dw.dxfInt(98, 0);
3282 
3283  if (version == DL_VERSION_2000) {
3284  dw.dxfString(1001, "ACAD");
3285  dw.dxfReal(1010, data.originX);
3286  dw.dxfReal(1020, data.originY);
3287  dw.dxfInt(1030, 0);
3288  }
3289 }
3290 
3300  dw.dxfInt(92, 1);
3301  dw.dxfInt(93, data.numEdges);
3302  // dw.dxfInt(97, 0);
3303 }
3304 
3313  dw.dxfInt(97, 0);
3314 }
3315 
3324  if (data.type < 1 || data.type > 4) {
3325  printf("WARNING: unsupported hatch edge type: %d", data.type);
3326  }
3327 
3328  dw.dxfInt(72, data.type);
3329 
3330  switch (data.type) {
3331  // line:
3332  case 1:
3333  dw.dxfReal(10, data.x1);
3334  dw.dxfReal(20, data.y1);
3335  dw.dxfReal(11, data.x2);
3336  dw.dxfReal(21, data.y2);
3337  break;
3338 
3339  // arc:
3340  case 2:
3341  dw.dxfReal(10, data.cx);
3342  dw.dxfReal(20, data.cy);
3343  dw.dxfReal(40, data.radius);
3344  dw.dxfReal(50, data.angle1 / (2 * M_PI) * 360.0);
3345  dw.dxfReal(51, data.angle2 / (2 * M_PI) * 360.0);
3346  dw.dxfInt(73, (int)(data.ccw));
3347  break;
3348 
3349  // ellipse arc:
3350  case 3:
3351  dw.dxfReal(10, data.cx);
3352  dw.dxfReal(20, data.cy);
3353  dw.dxfReal(11, data.mx);
3354  dw.dxfReal(21, data.my);
3355  dw.dxfReal(40, data.ratio);
3356  dw.dxfReal(50, data.angle1 / (2 * M_PI) * 360.0);
3357  dw.dxfReal(51, data.angle2 / (2 * M_PI) * 360.0);
3358  dw.dxfInt(73, (int)(data.ccw));
3359  break;
3360 
3361  // spline:
3362  case 4:
3363  dw.dxfInt(94, data.degree);
3364  dw.dxfBool(73, data.rational);
3365  dw.dxfBool(74, data.periodic);
3366  dw.dxfInt(95, data.nKnots);
3367  dw.dxfInt(96, data.nControl);
3368  for (unsigned int i = 0; i < data.knots.size(); i++) {
3369  dw.dxfReal(40, data.knots[i]);
3370  }
3371  for (unsigned int i = 0; i < data.controlPoints.size(); i++) {
3372  dw.dxfReal(10, data.controlPoints[i][0]);
3373  dw.dxfReal(20, data.controlPoints[i][1]);
3374  }
3375  for (unsigned int i = 0; i < data.weights.size(); i++) {
3376  dw.dxfReal(42, data.weights[i]);
3377  }
3378  if (data.nFit > 0) {
3379  dw.dxfInt(97, data.nFit);
3380  for (unsigned int i = 0; i < data.fitPoints.size(); i++) {
3381  dw.dxfReal(11, data.fitPoints[i][0]);
3382  dw.dxfReal(21, data.fitPoints[i][1]);
3383  }
3384  }
3385  if (fabs(data.startTangentX) > 1.0e-4 ||
3386  fabs(data.startTangentY) > 1.0e-4) {
3387  dw.dxfReal(12, data.startTangentX);
3388  dw.dxfReal(22, data.startTangentY);
3389  }
3390  if (fabs(data.endTangentX) > 1.0e-4 ||
3391  fabs(data.endTangentY) > 1.0e-4) {
3392  dw.dxfReal(13, data.endTangentX);
3393  dw.dxfReal(23, data.endTangentY);
3394  }
3395  break;
3396 
3397  default:
3398  break;
3399  }
3400 }
3401 
3408  const DL_ImageData& data,
3409  const DL_Attributes& attrib) {
3410  /*if (data.file.empty()) {
3411  std::cerr << "DL_Dxf::writeImage: "
3412  << "Image file must not be empty\n";
3413  return;
3414 }*/
3415 
3416  dw.entity("IMAGE");
3417 
3418  if (version == DL_VERSION_2000) {
3419  dw.dxfString(100, "AcDbEntity");
3420  }
3421  dw.entityAttributes(attrib);
3422  if (version == DL_VERSION_2000) {
3423  dw.dxfString(100, "AcDbRasterImage");
3424  dw.dxfInt(90, 0);
3425  }
3426  // insertion point
3427  dw.dxfReal(10, data.ipx);
3428  dw.dxfReal(20, data.ipy);
3429  dw.dxfReal(30, data.ipz);
3430 
3431  // vector along bottom side (1 pixel long)
3432  dw.dxfReal(11, data.ux);
3433  dw.dxfReal(21, data.uy);
3434  dw.dxfReal(31, data.uz);
3435 
3436  // vector along left side (1 pixel long)
3437  dw.dxfReal(12, data.vx);
3438  dw.dxfReal(22, data.vy);
3439  dw.dxfReal(32, data.vz);
3440 
3441  // image size in pixel
3442  dw.dxfReal(13, data.width);
3443  dw.dxfReal(23, data.height);
3444 
3445  // handle of IMAGEDEF object
3446  int handle = dw.incHandle();
3447  dw.dxfHex(340, handle);
3448 
3449  // flags
3450  dw.dxfInt(70, 15);
3451 
3452  // clipping:
3453  dw.dxfInt(280, 0);
3454 
3455  // brightness, contrast, fade
3456  dw.dxfInt(281, data.brightness);
3457  dw.dxfInt(282, data.contrast);
3458  dw.dxfInt(283, data.fade);
3459 
3460  return handle;
3461 }
3462 
3467  int handle,
3468  const DL_ImageData& data) {
3469  /*if (data.file.empty()) {
3470  std::cerr << "DL_Dxf::writeImage: "
3471  << "Image file must not be empty\n";
3472  return;
3473 }*/
3474 
3475  dw.dxfString(0, "IMAGEDEF");
3476  if (version == DL_VERSION_2000) {
3477  dw.dxfHex(5, handle);
3478  }
3479 
3480  if (version == DL_VERSION_2000) {
3481  dw.dxfString(100, "AcDbRasterImageDef");
3482  dw.dxfInt(90, 0);
3483  }
3484  // file name:
3485  dw.dxfString(1, data.ref);
3486 
3487  // image size in pixel
3488  dw.dxfReal(10, data.width);
3489  dw.dxfReal(20, data.height);
3490 
3491  dw.dxfReal(11, 1.0);
3492  dw.dxfReal(21, 1.0);
3493 
3494  // loaded:
3495  dw.dxfInt(280, 1);
3496  // units:
3497  dw.dxfInt(281, 0);
3498 }
3499 
3509  const DL_LayerData& data,
3510  const DL_Attributes& attrib) {
3511  if (data.name.empty()) {
3512  std::cerr << "DL_Dxf::writeLayer: "
3513  << "Layer name must not be empty\n";
3514  return;
3515  }
3516 
3517  int color = attrib.getColor();
3518  if (color >= 256) {
3519  std::cerr << "Layer color cannot be " << color << ". Changed to 7.\n";
3520  color = 7;
3521  }
3522  if (data.off) {
3523  // negative color value means layer is off:
3524  color = -color;
3525  }
3526 
3527  if (data.name == "0") {
3528  dw.tableLayerEntry(0x10);
3529  } else {
3530  dw.tableLayerEntry();
3531  }
3532 
3533  dw.dxfString(2, data.name);
3534  dw.dxfInt(70, data.flags);
3535  dw.dxfInt(62, color);
3536  if (version >= DL_VERSION_2000 && attrib.getColor24() != -1) {
3537  dw.dxfInt(420, attrib.getColor24());
3538  }
3539 
3540  dw.dxfString(6,
3541  (attrib.getLinetype().length() == 0 ? std::string("CONTINUOUS")
3542  : attrib.getLinetype()));
3543 
3544  if (version >= DL_VERSION_2000) {
3545  // layer defpoints cannot be plotted
3546  std::string lstr = data.name;
3547  std::transform(lstr.begin(), lstr.end(), lstr.begin(), tolower);
3548  if (lstr == "defpoints") {
3549  dw.dxfInt(290, 0);
3550  }
3551  }
3552  if (version >= DL_VERSION_2000 && attrib.getWidth() != -1) {
3553  dw.dxfInt(370, attrib.getWidth());
3554  }
3555  if (version >= DL_VERSION_2000) {
3556  dw.dxfHex(390, 0xF);
3557  }
3558 }
3559 
3565  std::string nameUpper = data.name;
3566  std::transform(nameUpper.begin(), nameUpper.end(), nameUpper.begin(),
3567  ::toupper);
3568 
3569  if (data.name.empty()) {
3570  std::cerr << "DL_Dxf::writeLinetype: "
3571  << "Line type name must not be empty\n";
3572  return;
3573  }
3574 
3575  // ignore BYLAYER, BYBLOCK for R12
3576  if (version < DL_VERSION_2000) {
3577  if (nameUpper == "BYBLOCK" || nameUpper == "BYLAYER") {
3578  return;
3579  }
3580  }
3581 
3582  // write id (not for R12)
3583  if (nameUpper == "BYBLOCK") {
3584  dw.tableLinetypeEntry(0x14);
3585  } else if (nameUpper == "BYLAYER") {
3586  dw.tableLinetypeEntry(0x15);
3587  } else if (nameUpper == "CONTINUOUS") {
3588  dw.tableLinetypeEntry(0x16);
3589  } else {
3590  dw.tableLinetypeEntry();
3591  }
3592 
3593  dw.dxfString(2, data.name);
3594  dw.dxfInt(70, data.flags);
3595 
3596  if (nameUpper == "BYBLOCK") {
3597  dw.dxfString(3, "");
3598  dw.dxfInt(72, 65);
3599  dw.dxfInt(73, 0);
3600  dw.dxfReal(40, 0.0);
3601  } else if (nameUpper == "BYLAYER") {
3602  dw.dxfString(3, "");
3603  dw.dxfInt(72, 65);
3604  dw.dxfInt(73, 0);
3605  dw.dxfReal(40, 0.0);
3606  } else if (nameUpper == "CONTINUOUS") {
3607  dw.dxfString(3, "Solid line");
3608  dw.dxfInt(72, 65);
3609  dw.dxfInt(73, 0);
3610  dw.dxfReal(40, 0.0);
3611  } else {
3612  dw.dxfString(3, data.description);
3613  dw.dxfInt(72, 65);
3614  dw.dxfInt(73, data.numberOfDashes);
3615  dw.dxfReal(40, data.patternLength);
3616  for (int i = 0; i < data.numberOfDashes; i++) {
3617  dw.dxfReal(49, data.pattern[i]);
3618  if (version >= DL_VERSION_R13) {
3619  dw.dxfInt(74, 0);
3620  }
3621  }
3622  }
3623 }
3624 
3630 void DL_Dxf::writeAppid(DL_WriterA& dw, const std::string& name) {
3631  if (name.empty()) {
3632  std::cerr << "DL_Dxf::writeAppid: "
3633  << "Application name must not be empty\n";
3634  return;
3635  }
3636 
3637  std::string n = name;
3638  std::transform(n.begin(), n.end(), n.begin(), ::toupper);
3639 
3640  if (n == "ACAD") {
3641  dw.tableAppidEntry(0x12);
3642  } else {
3643  dw.tableAppidEntry();
3644  }
3645  dw.dxfString(2, name);
3646  dw.dxfInt(70, 0);
3647 }
3648 
3653  if (data.name.empty()) {
3654  std::cerr << "DL_Dxf::writeBlock: "
3655  << "Block name must not be empty\n";
3656  return;
3657  }
3658 
3659  std::string n = data.name;
3660  std::transform(n.begin(), n.end(), n.begin(), ::toupper);
3661 
3662  if (n == "*PAPER_SPACE") {
3663  dw.sectionBlockEntry(0x1C);
3664  } else if (n == "*MODEL_SPACE") {
3665  dw.sectionBlockEntry(0x20);
3666  } else if (n == "*PAPER_SPACE0") {
3667  dw.sectionBlockEntry(0x24);
3668  } else {
3669  dw.sectionBlockEntry();
3670  }
3671  dw.dxfString(2, data.name);
3672  dw.dxfInt(70, 0);
3673  dw.coord(10, data.bpx, data.bpy, data.bpz);
3674  dw.dxfString(3, data.name);
3675  dw.dxfString(1, "");
3676 }
3677 
3683 void DL_Dxf::writeEndBlock(DL_WriterA& dw, const std::string& name) {
3684  std::string n = name;
3685  std::transform(n.begin(), n.end(), n.begin(), ::toupper);
3686 
3687  if (n == "*PAPER_SPACE") {
3688  dw.sectionBlockEntryEnd(0x1D);
3689  } else if (n == "*MODEL_SPACE") {
3690  dw.sectionBlockEntryEnd(0x21);
3691  } else if (n == "*PAPER_SPACE0") {
3692  dw.sectionBlockEntryEnd(0x25);
3693  } else {
3694  dw.sectionBlockEntryEnd();
3695  }
3696 }
3697 
3704  dw.dxfString(0, "TABLE");
3705  dw.dxfString(2, "VPORT");
3706  if (version == DL_VERSION_2000) {
3707  dw.dxfHex(5, 0x8);
3708  }
3709  // dw.dxfHex(330, 0);
3710  if (version == DL_VERSION_2000) {
3711  dw.dxfString(100, "AcDbSymbolTable");
3712  }
3713  dw.dxfInt(70, 1);
3714  dw.dxfString(0, "VPORT");
3715  // dw.dxfHex(5, 0x2F);
3716  if (version == DL_VERSION_2000) {
3717  dw.handle();
3718  }
3719  // dw.dxfHex(330, 8);
3720  if (version == DL_VERSION_2000) {
3721  dw.dxfString(100, "AcDbSymbolTableRecord");
3722  dw.dxfString(100, "AcDbViewportTableRecord");
3723  }
3724  dw.dxfString(2, "*Active");
3725  dw.dxfInt(70, 0);
3726  dw.dxfReal(10, 0.0);
3727  dw.dxfReal(20, 0.0);
3728  dw.dxfReal(11, 1.0);
3729  dw.dxfReal(21, 1.0);
3730  dw.dxfReal(12, 286.3055555555555);
3731  dw.dxfReal(22, 148.5);
3732  dw.dxfReal(13, 0.0);
3733  dw.dxfReal(23, 0.0);
3734  dw.dxfReal(14, 10.0);
3735  dw.dxfReal(24, 10.0);
3736  dw.dxfReal(15, 10.0);
3737  dw.dxfReal(25, 10.0);
3738  dw.dxfReal(16, 0.0);
3739  dw.dxfReal(26, 0.0);
3740  dw.dxfReal(36, 1.0);
3741  dw.dxfReal(17, 0.0);
3742  dw.dxfReal(27, 0.0);
3743  dw.dxfReal(37, 0.0);
3744  dw.dxfReal(40, 297.0);
3745  dw.dxfReal(41, 1.92798353909465);
3746  dw.dxfReal(42, 50.0);
3747  dw.dxfReal(43, 0.0);
3748  dw.dxfReal(44, 0.0);
3749  dw.dxfReal(50, 0.0);
3750  dw.dxfReal(51, 0.0);
3751  dw.dxfInt(71, 0);
3752  dw.dxfInt(72, 100);
3753  dw.dxfInt(73, 1);
3754  dw.dxfInt(74, 3);
3755  dw.dxfInt(75, 1);
3756  dw.dxfInt(76, 1);
3757  dw.dxfInt(77, 0);
3758  dw.dxfInt(78, 0);
3759 
3760  if (version == DL_VERSION_2000) {
3761  dw.dxfInt(281, 0);
3762  dw.dxfInt(65, 1);
3763  dw.dxfReal(110, 0.0);
3764  dw.dxfReal(120, 0.0);
3765  dw.dxfReal(130, 0.0);
3766  dw.dxfReal(111, 1.0);
3767  dw.dxfReal(121, 0.0);
3768  dw.dxfReal(131, 0.0);
3769  dw.dxfReal(112, 0.0);
3770  dw.dxfReal(122, 1.0);
3771  dw.dxfReal(132, 0.0);
3772  dw.dxfInt(79, 0);
3773  dw.dxfReal(146, 0.0);
3774  }
3775  dw.dxfString(0, "ENDTAB");
3776 }
3777 
3781 void DL_Dxf::writeStyle(DL_WriterA& dw, const DL_StyleData& style) {
3782  // dw.dxfString( 0, "TABLE");
3783  // dw.dxfString( 2, "STYLE");
3784  // if (version==DL_VERSION_2000) {
3785  // dw.dxfHex(5, 3);
3786  // }
3787  // dw.dxfHex(330, 0);
3788  // if (version==DL_VERSION_2000) {
3789  // dw.dxfString(100, "AcDbSymbolTable");
3790  // }
3791  // dw.dxfInt( 70, 1);
3792  dw.dxfString(0, "STYLE");
3793  if (version == DL_VERSION_2000) {
3794  if (style.name == "Standard") {
3795  // dw.dxfHex(5, 0x11);
3796  styleHandleStd = dw.handle();
3797  } else {
3798  dw.handle();
3799  }
3800  }
3801  // dw.dxfHex(330, 3);
3802  if (version == DL_VERSION_2000) {
3803  dw.dxfString(100, "AcDbSymbolTableRecord");
3804  dw.dxfString(100, "AcDbTextStyleTableRecord");
3805  }
3806  dw.dxfString(2, style.name);
3807  dw.dxfInt(70, style.flags);
3808  dw.dxfReal(40, style.fixedTextHeight);
3809  dw.dxfReal(41, style.widthFactor);
3810  dw.dxfReal(50, style.obliqueAngle);
3811  dw.dxfInt(71, style.textGenerationFlags);
3812  dw.dxfReal(42, style.lastHeightUsed);
3813  if (version == DL_VERSION_2000) {
3814  dw.dxfString(3, "");
3815  dw.dxfString(4, "");
3816  dw.dxfString(1001, "ACAD");
3817  // dw.dxfString(1000, style.name);
3818  dw.dxfString(1000, style.primaryFontFile);
3819  int xFlags = 0;
3820  if (style.bold) {
3821  xFlags = xFlags | 0x2000000;
3822  }
3823  if (style.italic) {
3824  xFlags = xFlags | 0x1000000;
3825  }
3826  dw.dxfInt(1071, xFlags);
3827  } else {
3828  dw.dxfString(3, style.primaryFontFile);
3829  dw.dxfString(4, style.bigFontFile);
3830  }
3831  // dw.dxfString( 0, "ENDTAB");
3832 }
3833 
3840  dw.dxfString(0, "TABLE");
3841  dw.dxfString(2, "VIEW");
3842  if (version == DL_VERSION_2000) {
3843  dw.dxfHex(5, 6);
3844  }
3845  // dw.dxfHex(330, 0);
3846  if (version == DL_VERSION_2000) {
3847  dw.dxfString(100, "AcDbSymbolTable");
3848  }
3849  dw.dxfInt(70, 0);
3850  dw.dxfString(0, "ENDTAB");
3851 }
3852 
3859  dw.dxfString(0, "TABLE");
3860  dw.dxfString(2, "UCS");
3861  if (version == DL_VERSION_2000) {
3862  dw.dxfHex(5, 7);
3863  }
3864  // dw.dxfHex(330, 0);
3865  if (version == DL_VERSION_2000) {
3866  dw.dxfString(100, "AcDbSymbolTable");
3867  }
3868  dw.dxfInt(70, 0);
3869  dw.dxfString(0, "ENDTAB");
3870 }
3871 
3878  double dimasz,
3879  double dimexe,
3880  double dimexo,
3881  double dimgap,
3882  double dimtxt) {
3883  dw.dxfString(0, "TABLE");
3884  dw.dxfString(2, "DIMSTYLE");
3885  if (version == DL_VERSION_2000) {
3886  dw.dxfHex(5, 0xA);
3887  dw.dxfString(100, "AcDbSymbolTable");
3888  }
3889  dw.dxfInt(70, 1);
3890  if (version == DL_VERSION_2000) {
3891  dw.dxfString(100, "AcDbDimStyleTable");
3892  dw.dxfInt(71, 0);
3893  }
3894 
3895  dw.dxfString(0, "DIMSTYLE");
3896  if (version == DL_VERSION_2000) {
3897  dw.dxfHex(105, 0x27);
3898  }
3899  // dw.handle(105);
3900  // dw.dxfHex(330, 0xA);
3901  if (version == DL_VERSION_2000) {
3902  dw.dxfString(100, "AcDbSymbolTableRecord");
3903  dw.dxfString(100, "AcDbDimStyleTableRecord");
3904  }
3905  dw.dxfString(2, "Standard");
3906  if (version == DL_VERSION_R12) {
3907  dw.dxfString(3, "");
3908  dw.dxfString(4, "");
3909  dw.dxfString(5, "");
3910  dw.dxfString(6, "");
3911  dw.dxfString(7, "");
3912  dw.dxfReal(40, 1.0);
3913  }
3914 
3915  dw.dxfReal(41, dimasz);
3916  dw.dxfReal(42, dimexo);
3917  dw.dxfReal(43, 3.75);
3918  dw.dxfReal(44, dimexe);
3919  if (version == DL_VERSION_R12) {
3920  dw.dxfReal(45, 0.0);
3921  dw.dxfReal(46, 0.0);
3922  dw.dxfReal(47, 0.0);
3923  dw.dxfReal(48, 0.0);
3924  }
3925  dw.dxfInt(70, 0);
3926  if (version == DL_VERSION_R12) {
3927  dw.dxfInt(71, 0);
3928  dw.dxfInt(72, 0);
3929  }
3930  dw.dxfInt(73, 0);
3931  dw.dxfInt(74, 0);
3932  if (version == DL_VERSION_R12) {
3933  dw.dxfInt(75, 0);
3934  dw.dxfInt(76, 0);
3935  }
3936  dw.dxfInt(77, 1);
3937  dw.dxfInt(78, 8);
3938  dw.dxfReal(140, dimtxt);
3939  dw.dxfReal(141, 2.5);
3940  if (version == DL_VERSION_R12) {
3941  dw.dxfReal(142, 0.0);
3942  }
3943  dw.dxfReal(143, 0.03937007874016);
3944  if (version == DL_VERSION_R12) {
3945  dw.dxfReal(144, 1.0);
3946  dw.dxfReal(145, 0.0);
3947  dw.dxfReal(146, 1.0);
3948  }
3949  dw.dxfReal(147, dimgap);
3950  if (version == DL_VERSION_R12) {
3951  dw.dxfInt(170, 0);
3952  }
3953  dw.dxfInt(171, 3);
3954  dw.dxfInt(172, 1);
3955  if (version == DL_VERSION_R12) {
3956  dw.dxfInt(173, 0);
3957  dw.dxfInt(174, 0);
3958  dw.dxfInt(175, 0);
3959  dw.dxfInt(176, 0);
3960  dw.dxfInt(177, 0);
3961  dw.dxfInt(178, 0);
3962  }
3963  if (version == DL_VERSION_2000) {
3964  dw.dxfInt(271, 2);
3965  dw.dxfInt(272, 2);
3966  dw.dxfInt(274, 3);
3967  dw.dxfInt(278, 44);
3968  dw.dxfInt(283, 0);
3969  dw.dxfInt(284, 8);
3970  dw.dxfHex(340, styleHandleStd);
3971  // dw.dxfHex(340, 0x11);
3972  }
3973  // * /
3974  dw.dxfString(0, "ENDTAB");
3975 }
3976 
3983  dw.dxfString(0, "TABLE");
3984  dw.dxfString(2, "BLOCK_RECORD");
3985  if (version == DL_VERSION_2000) {
3986  dw.dxfHex(5, 1);
3987  }
3988  // dw.dxfHex(330, 0);
3989  if (version == DL_VERSION_2000) {
3990  dw.dxfString(100, "AcDbSymbolTable");
3991  }
3992  dw.dxfInt(70, 1);
3993 
3994  dw.dxfString(0, "BLOCK_RECORD");
3995  if (version == DL_VERSION_2000) {
3996  dw.dxfHex(5, 0x1F);
3997  }
3998  // int msh = dw.handle();
3999  // dw.setModelSpaceHandle(msh);
4000  // dw.dxfHex(330, 1);
4001  if (version == DL_VERSION_2000) {
4002  dw.dxfString(100, "AcDbSymbolTableRecord");
4003  dw.dxfString(100, "AcDbBlockTableRecord");
4004  }
4005  dw.dxfString(2, "*Model_Space");
4006  dw.dxfHex(340, 0x22);
4007 
4008  dw.dxfString(0, "BLOCK_RECORD");
4009  if (version == DL_VERSION_2000) {
4010  dw.dxfHex(5, 0x1B);
4011  }
4012  // int psh = dw.handle();
4013  // dw.setPaperSpaceHandle(psh);
4014  // dw.dxfHex(330, 1);
4015  if (version == DL_VERSION_2000) {
4016  dw.dxfString(100, "AcDbSymbolTableRecord");
4017  dw.dxfString(100, "AcDbBlockTableRecord");
4018  }
4019  dw.dxfString(2, "*Paper_Space");
4020  dw.dxfHex(340, 0x1E);
4021 
4022  dw.dxfString(0, "BLOCK_RECORD");
4023  if (version == DL_VERSION_2000) {
4024  dw.dxfHex(5, 0x23);
4025  }
4026  // int ps0h = dw.handle();
4027  // dw.setPaperSpace0Handle(ps0h);
4028  // dw.dxfHex(330, 1);
4029  if (version == DL_VERSION_2000) {
4030  dw.dxfString(100, "AcDbSymbolTableRecord");
4031  dw.dxfString(100, "AcDbBlockTableRecord");
4032  }
4033  dw.dxfString(2, "*Paper_Space0");
4034  dw.dxfHex(340, 0x26);
4035 
4036  // dw.dxfString( 0, "ENDTAB");
4037 }
4038 
4042 void DL_Dxf::writeBlockRecord(DL_WriterA& dw, const std::string& name) {
4043  dw.dxfString(0, "BLOCK_RECORD");
4044  if (version == DL_VERSION_2000) {
4045  dw.handle();
4046  }
4047  // dw->dxfHex(330, 1);
4048  if (version == DL_VERSION_2000) {
4049  dw.dxfString(100, "AcDbSymbolTableRecord");
4050  dw.dxfString(100, "AcDbBlockTableRecord");
4051  }
4052  dw.dxfString(2, name);
4053  dw.dxfHex(340, 0);
4054 }
4055 
4062  const std::string& appDictionaryName) {
4063  dw.dxfString(0, "SECTION");
4064  dw.dxfString(2, "OBJECTS");
4065 
4066  dw.dxfString(0, "DICTIONARY");
4067  dw.dxfHex(5, 0xC);
4068  dw.dxfString(100, "AcDbDictionary");
4069  dw.dxfInt(280, 0);
4070  dw.dxfInt(281, 1);
4071  dw.dxfString(3, "ACAD_GROUP");
4072  dw.dxfHex(350, 0xD);
4073  dw.dxfString(3, "ACAD_LAYOUT");
4074  dw.dxfHex(350, 0x1A);
4075  dw.dxfString(3, "ACAD_MLINESTYLE");
4076  dw.dxfHex(350, 0x17);
4077  dw.dxfString(3, "ACAD_PLOTSETTINGS");
4078  dw.dxfHex(350, 0x19);
4079  dw.dxfString(3, "ACAD_PLOTSTYLENAME");
4080  dw.dxfHex(350, 0xE);
4081  dw.dxfString(3, "AcDbVariableDictionary");
4082  int acDbVariableDictionaryHandle = dw.handle(350);
4083  // int acDbVariableDictionaryHandle = dw.getNextHandle();
4084  // dw.dxfHex(350, acDbVariableDictionaryHandle);
4085  // dw.incHandle();
4086 
4087  if (appDictionaryName.length() != 0) {
4088  dw.dxfString(3, appDictionaryName);
4089  appDictionaryHandle = dw.handle(350);
4090  // appDictionaryHandle = dw.getNextHandle();
4091  // dw.dxfHex(350, appDictionaryHandle);
4092  // dw.incHandle();
4093  }
4094 
4095  dw.dxfString(0, "DICTIONARY");
4096  dw.dxfHex(5, 0xD);
4097  // dw.handle(); // D
4098  // dw.dxfHex(330, 0xC);
4099  dw.dxfString(100, "AcDbDictionary");
4100  dw.dxfInt(280, 0);
4101  dw.dxfInt(281, 1);
4102 
4103  dw.dxfString(0, "ACDBDICTIONARYWDFLT");
4104  dw.dxfHex(5, 0xE);
4105  // dicId4 = dw.handle(); // E
4106  // dw.dxfHex(330, 0xC); // C
4107  dw.dxfString(100, "AcDbDictionary");
4108  dw.dxfInt(281, 1);
4109  dw.dxfString(3, "Normal");
4110  dw.dxfHex(350, 0xF);
4111  // dw.dxfHex(350, dw.getNextHandle()+5); // F
4112  dw.dxfString(100, "AcDbDictionaryWithDefault");
4113  dw.dxfHex(340, 0xF);
4114  // dw.dxfHex(340, dw.getNextHandle()+5); // F
4115 
4116  dw.dxfString(0, "ACDBPLACEHOLDER");
4117  dw.dxfHex(5, 0xF);
4118  // dw.handle(); // F
4119  // dw.dxfHex(330, dicId4); // E
4120 
4121  dw.dxfString(0, "DICTIONARY");
4122  // dicId3 = dw.handle(); // 17
4123  dw.dxfHex(5, 0x17);
4124  // dw.dxfHex(330, 0xC); // C
4125  dw.dxfString(100, "AcDbDictionary");
4126  dw.dxfInt(280, 0);
4127  dw.dxfInt(281, 1);
4128  dw.dxfString(3, "Standard");
4129  dw.dxfHex(350, 0x18);
4130  // dw.dxfHex(350, dw.getNextHandle()+5); // 18
4131 
4132  dw.dxfString(0, "MLINESTYLE");
4133  dw.dxfHex(5, 0x18);
4134  // dw.handle(); // 18
4135  // dw.dxfHex(330, dicId3); // 17
4136  dw.dxfString(100, "AcDbMlineStyle");
4137  dw.dxfString(2, "STANDARD");
4138  dw.dxfInt(70, 0);
4139  dw.dxfString(3, "");
4140  dw.dxfInt(62, 256);
4141  dw.dxfReal(51, 90.0);
4142  dw.dxfReal(52, 90.0);
4143  dw.dxfInt(71, 2);
4144  dw.dxfReal(49, 0.5);
4145  dw.dxfInt(62, 256);
4146  dw.dxfString(6, "BYLAYER");
4147  dw.dxfReal(49, -0.5);
4148  dw.dxfInt(62, 256);
4149  dw.dxfString(6, "BYLAYER");
4150 
4151  dw.dxfString(0, "DICTIONARY");
4152  dw.dxfHex(5, 0x19);
4153  // dw.handle(); // 17
4154  // dw.dxfHex(330, 0xC); // C
4155  dw.dxfString(100, "AcDbDictionary");
4156  dw.dxfInt(280, 0);
4157  dw.dxfInt(281, 1);
4158 
4159  dw.dxfString(0, "DICTIONARY");
4160  // dicId2 = dw.handle(); // 1A
4161  dw.dxfHex(5, 0x1A);
4162  // dw.dxfHex(330, 0xC);
4163  dw.dxfString(100, "AcDbDictionary");
4164  dw.dxfInt(281, 1);
4165  dw.dxfString(3, "Layout1");
4166  dw.dxfHex(350, 0x1E);
4167  // dw.dxfHex(350, dw.getNextHandle()+2); // 1E
4168  dw.dxfString(3, "Layout2");
4169  dw.dxfHex(350, 0x26);
4170  // dw.dxfHex(350, dw.getNextHandle()+4); // 26
4171  dw.dxfString(3, "Model");
4172  dw.dxfHex(350, 0x22);
4173  // dw.dxfHex(350, dw.getNextHandle()+5); // 22
4174 
4175  dw.dxfString(0, "LAYOUT");
4176  dw.dxfHex(5, 0x1E);
4177  // dw.handle(); // 1E
4178  // dw.dxfHex(330, dicId2); // 1A
4179  dw.dxfString(100, "AcDbPlotSettings");
4180  dw.dxfString(1, "");
4181  dw.dxfString(2, "none_device");
4182  dw.dxfString(4, "");
4183  dw.dxfString(6, "");
4184  dw.dxfReal(40, 0.0);
4185  dw.dxfReal(41, 0.0);
4186  dw.dxfReal(42, 0.0);
4187  dw.dxfReal(43, 0.0);
4188  dw.dxfReal(44, 0.0);
4189  dw.dxfReal(45, 0.0);
4190  dw.dxfReal(46, 0.0);
4191  dw.dxfReal(47, 0.0);
4192  dw.dxfReal(48, 0.0);
4193  dw.dxfReal(49, 0.0);
4194  dw.dxfReal(140, 0.0);
4195  dw.dxfReal(141, 0.0);
4196  dw.dxfReal(142, 1.0);
4197  dw.dxfReal(143, 1.0);
4198  dw.dxfInt(70, 688);
4199  dw.dxfInt(72, 0);
4200  dw.dxfInt(73, 0);
4201  dw.dxfInt(74, 5);
4202  dw.dxfString(7, "");
4203  dw.dxfInt(75, 16);
4204  dw.dxfReal(147, 1.0);
4205  dw.dxfReal(148, 0.0);
4206  dw.dxfReal(149, 0.0);
4207  dw.dxfString(100, "AcDbLayout");
4208  dw.dxfString(1, "Layout1");
4209  dw.dxfInt(70, 1);
4210  dw.dxfInt(71, 1);
4211  dw.dxfReal(10, 0.0);
4212  dw.dxfReal(20, 0.0);
4213  dw.dxfReal(11, 420.0);
4214  dw.dxfReal(21, 297.0);
4215  dw.dxfReal(12, 0.0);
4216  dw.dxfReal(22, 0.0);
4217  dw.dxfReal(32, 0.0);
4218  dw.dxfReal(14, 1.000000000000000E+20);
4219  dw.dxfReal(24, 1.000000000000000E+20);
4220  dw.dxfReal(34, 1.000000000000000E+20);
4221  dw.dxfReal(15, -1.000000000000000E+20);
4222  dw.dxfReal(25, -1.000000000000000E+20);
4223  dw.dxfReal(35, -1.000000000000000E+20);
4224  dw.dxfReal(146, 0.0);
4225  dw.dxfReal(13, 0.0);
4226  dw.dxfReal(23, 0.0);
4227  dw.dxfReal(33, 0.0);
4228  dw.dxfReal(16, 1.0);
4229  dw.dxfReal(26, 0.0);
4230  dw.dxfReal(36, 0.0);
4231  dw.dxfReal(17, 0.0);
4232  dw.dxfReal(27, 1.0);
4233  dw.dxfReal(37, 0.0);
4234  dw.dxfInt(76, 0);
4235  // dw.dxfHex(330, dw.getPaperSpaceHandle()); // 1B
4236  dw.dxfHex(330, 0x1B);
4237 
4238  dw.dxfString(0, "LAYOUT");
4239  dw.dxfHex(5, 0x22);
4240  // dw.handle(); // 22
4241  // dw.dxfHex(330, dicId2); // 1A
4242  dw.dxfString(100, "AcDbPlotSettings");
4243  dw.dxfString(1, "");
4244  dw.dxfString(2, "none_device");
4245  dw.dxfString(4, "");
4246  dw.dxfString(6, "");
4247  dw.dxfReal(40, 0.0);
4248  dw.dxfReal(41, 0.0);
4249  dw.dxfReal(42, 0.0);
4250  dw.dxfReal(43, 0.0);
4251  dw.dxfReal(44, 0.0);
4252  dw.dxfReal(45, 0.0);
4253  dw.dxfReal(46, 0.0);
4254  dw.dxfReal(47, 0.0);
4255  dw.dxfReal(48, 0.0);
4256  dw.dxfReal(49, 0.0);
4257  dw.dxfReal(140, 0.0);
4258  dw.dxfReal(141, 0.0);
4259  dw.dxfReal(142, 1.0);
4260  dw.dxfReal(143, 1.0);
4261  dw.dxfInt(70, 1712);
4262  dw.dxfInt(72, 0);
4263  dw.dxfInt(73, 0);
4264  dw.dxfInt(74, 0);
4265  dw.dxfString(7, "");
4266  dw.dxfInt(75, 0);
4267  dw.dxfReal(147, 1.0);
4268  dw.dxfReal(148, 0.0);
4269  dw.dxfReal(149, 0.0);
4270  dw.dxfString(100, "AcDbLayout");
4271  dw.dxfString(1, "Model");
4272  dw.dxfInt(70, 1);
4273  dw.dxfInt(71, 0);
4274  dw.dxfReal(10, 0.0);
4275  dw.dxfReal(20, 0.0);
4276  dw.dxfReal(11, 12.0);
4277  dw.dxfReal(21, 9.0);
4278  dw.dxfReal(12, 0.0);
4279  dw.dxfReal(22, 0.0);
4280  dw.dxfReal(32, 0.0);
4281  dw.dxfReal(14, 0.0);
4282  dw.dxfReal(24, 0.0);
4283  dw.dxfReal(34, 0.0);
4284  dw.dxfReal(15, 0.0);
4285  dw.dxfReal(25, 0.0);
4286  dw.dxfReal(35, 0.0);
4287  dw.dxfReal(146, 0.0);
4288  dw.dxfReal(13, 0.0);
4289  dw.dxfReal(23, 0.0);
4290  dw.dxfReal(33, 0.0);
4291  dw.dxfReal(16, 1.0);
4292  dw.dxfReal(26, 0.0);
4293  dw.dxfReal(36, 0.0);
4294  dw.dxfReal(17, 0.0);
4295  dw.dxfReal(27, 1.0);
4296  dw.dxfReal(37, 0.0);
4297  dw.dxfInt(76, 0);
4298  // dw.dxfHex(330, dw.getModelSpaceHandle()); // 1F
4299  dw.dxfHex(330, 0x1F);
4300 
4301  dw.dxfString(0, "LAYOUT");
4302  // dw.handle(); // 26
4303  dw.dxfHex(5, 0x26);
4304  // dw.dxfHex(330, dicId2); // 1A
4305  dw.dxfString(100, "AcDbPlotSettings");
4306  dw.dxfString(1, "");
4307  dw.dxfString(2, "none_device");
4308  dw.dxfString(4, "");
4309  dw.dxfString(6, "");
4310  dw.dxfReal(40, 0.0);
4311  dw.dxfReal(41, 0.0);
4312  dw.dxfReal(42, 0.0);
4313  dw.dxfReal(43, 0.0);
4314  dw.dxfReal(44, 0.0);
4315  dw.dxfReal(45, 0.0);
4316  dw.dxfReal(46, 0.0);
4317  dw.dxfReal(47, 0.0);
4318  dw.dxfReal(48, 0.0);
4319  dw.dxfReal(49, 0.0);
4320  dw.dxfReal(140, 0.0);
4321  dw.dxfReal(141, 0.0);
4322  dw.dxfReal(142, 1.0);
4323  dw.dxfReal(143, 1.0);
4324  dw.dxfInt(70, 688);
4325  dw.dxfInt(72, 0);
4326  dw.dxfInt(73, 0);
4327  dw.dxfInt(74, 5);
4328  dw.dxfString(7, "");
4329  dw.dxfInt(75, 16);
4330  dw.dxfReal(147, 1.0);
4331  dw.dxfReal(148, 0.0);
4332  dw.dxfReal(149, 0.0);
4333  dw.dxfString(100, "AcDbLayout");
4334  dw.dxfString(1, "Layout2");
4335  dw.dxfInt(70, 1);
4336  dw.dxfInt(71, 2);
4337  dw.dxfReal(10, 0.0);
4338  dw.dxfReal(20, 0.0);
4339  dw.dxfReal(11, 12.0);
4340  dw.dxfReal(21, 9.0);
4341  dw.dxfReal(12, 0.0);
4342  dw.dxfReal(22, 0.0);
4343  dw.dxfReal(32, 0.0);
4344  dw.dxfReal(14, 0.0);
4345  dw.dxfReal(24, 0.0);
4346  dw.dxfReal(34, 0.0);
4347  dw.dxfReal(15, 0.0);
4348  dw.dxfReal(25, 0.0);
4349  dw.dxfReal(35, 0.0);
4350  dw.dxfReal(146, 0.0);
4351  dw.dxfReal(13, 0.0);
4352  dw.dxfReal(23, 0.0);
4353  dw.dxfReal(33, 0.0);
4354  dw.dxfReal(16, 1.0);
4355  dw.dxfReal(26, 0.0);
4356  dw.dxfReal(36, 0.0);
4357  dw.dxfReal(17, 0.0);
4358  dw.dxfReal(27, 1.0);
4359  dw.dxfReal(37, 0.0);
4360  dw.dxfInt(76, 0);
4361  // dw.dxfHex(330, dw.getPaperSpace0Handle()); // 23
4362  dw.dxfHex(330, 0x23);
4363 
4364  dw.dxfString(0, "DICTIONARY");
4365  // dw.dxfHex(5, 0x2C);
4366  // dicId5 =
4367  dw.dxfHex(5, acDbVariableDictionaryHandle);
4368  // dw.handle(); // 2C
4369  // dw.dxfHex(330, 0xC); // C
4370  dw.dxfString(100, "AcDbDictionary");
4371  dw.dxfInt(281, 1);
4372  dw.dxfString(3, "DIMASSOC");
4373  // dw.dxfHex(350, 0x2F);
4374  dw.dxfHex(350, dw.getNextHandle() + 1); // 2E
4375  dw.dxfString(3, "HIDETEXT");
4376  // dw.dxfHex(350, 0x2E);
4377  dw.dxfHex(350, dw.getNextHandle()); // 2D
4378 
4379  dw.dxfString(0, "DICTIONARYVAR");
4380  // dw.dxfHex(5, 0x2E);
4381  dw.handle(); // 2E
4382  // dw.dxfHex(330, dicId5); // 2C
4383  dw.dxfString(100, "DictionaryVariables");
4384  dw.dxfInt(280, 0);
4385  dw.dxfInt(1, 2);
4386 
4387  dw.dxfString(0, "DICTIONARYVAR");
4388  // dw.dxfHex(5, 0x2D);
4389  dw.handle(); // 2D
4390  // dw.dxfHex(330, dicId5); // 2C
4391  dw.dxfString(100, "DictionaryVariables");
4392  dw.dxfInt(280, 0);
4393  dw.dxfInt(1, 1);
4394 }
4395 
4397  dw.dxfString(0, "DICTIONARY");
4398  // dw.handle();
4399  dw.dxfHex(5, appDictionaryHandle);
4400  dw.dxfString(100, "AcDbDictionary");
4401  dw.dxfInt(281, 1);
4402 }
4403 
4404 int DL_Dxf::writeDictionaryEntry(DL_WriterA& dw, const std::string& name) {
4405  dw.dxfString(3, name);
4406  int handle = dw.getNextHandle();
4407  dw.dxfHex(350, handle);
4408  dw.incHandle();
4409  return handle;
4410 }
4411 
4412 void DL_Dxf::writeXRecord(DL_WriterA& dw, int handle, int value) {
4413  dw.dxfString(0, "XRECORD");
4414  dw.dxfHex(5, handle);
4415  dw.dxfHex(330, appDictionaryHandle);
4416  dw.dxfString(100, "AcDbXrecord");
4417  dw.dxfInt(280, 1);
4418  dw.dxfInt(90, value);
4419 }
4420 
4421 void DL_Dxf::writeXRecord(DL_WriterA& dw, int handle, double value) {
4422  dw.dxfString(0, "XRECORD");
4423  dw.dxfHex(5, handle);
4424  dw.dxfHex(330, appDictionaryHandle);
4425  dw.dxfString(100, "AcDbXrecord");
4426  dw.dxfInt(280, 1);
4427  dw.dxfReal(40, value);
4428 }
4429 
4430 void DL_Dxf::writeXRecord(DL_WriterA& dw, int handle, bool value) {
4431  dw.dxfString(0, "XRECORD");
4432  dw.dxfHex(5, handle);
4433  dw.dxfHex(330, appDictionaryHandle);
4434  dw.dxfString(100, "AcDbXrecord");
4435  dw.dxfInt(280, 1);
4436  dw.dxfBool(290, value);
4437 }
4438 
4440  int handle,
4441  const std::string& value) {
4442  dw.dxfString(0, "XRECORD");
4443  dw.dxfHex(5, handle);
4444  dw.dxfHex(330, appDictionaryHandle);
4445  dw.dxfString(100, "AcDbXrecord");
4446  dw.dxfInt(280, 1);
4447  dw.dxfString(1000, value);
4448 }
4449 
4455 void DL_Dxf::writeObjectsEnd(DL_WriterA& dw) { dw.dxfString(0, "ENDSEC"); }
4456 
4460 void DL_Dxf::writeComment(DL_WriterA& dw, const std::string& comment) {
4461  dw.dxfString(999, comment);
4462 }
4463 
4468  if (version >= DL_VERSION_2000) {
4469  return true;
4470  } else if (version == DL_VERSION_R12) {
4471  // these are all the variables recognized by dxf r12:
4472  if (!strcmp(var, "$ACADVER")) {
4473  return true;
4474  }
4475  if (!strcmp(var, "$ACADVER")) {
4476  return true;
4477  }
4478  if (!strcmp(var, "$ANGBASE")) {
4479  return true;
4480  }
4481  if (!strcmp(var, "$ANGDIR")) {
4482  return true;
4483  }
4484  if (!strcmp(var, "$ATTDIA")) {
4485  return true;
4486  }
4487  if (!strcmp(var, "$ATTMODE")) {
4488  return true;
4489  }
4490  if (!strcmp(var, "$ATTREQ")) {
4491  return true;
4492  }
4493  if (!strcmp(var, "$AUNITS")) {
4494  return true;
4495  }
4496  if (!strcmp(var, "$AUPREC")) {
4497  return true;
4498  }
4499  if (!strcmp(var, "$AXISMODE")) {
4500  return true;
4501  }
4502  if (!strcmp(var, "$AXISUNIT")) {
4503  return true;
4504  }
4505  if (!strcmp(var, "$BLIPMODE")) {
4506  return true;
4507  }
4508  if (!strcmp(var, "$CECOLOR")) {
4509  return true;
4510  }
4511  if (!strcmp(var, "$CELTYPE")) {
4512  return true;
4513  }
4514  if (!strcmp(var, "$CHAMFERA")) {
4515  return true;
4516  }
4517  if (!strcmp(var, "$CHAMFERB")) {
4518  return true;
4519  }
4520  if (!strcmp(var, "$CLAYER")) {
4521  return true;
4522  }
4523  if (!strcmp(var, "$COORDS")) {
4524  return true;
4525  }
4526  if (!strcmp(var, "$DIMALT")) {
4527  return true;
4528  }
4529  if (!strcmp(var, "$DIMALTD")) {
4530  return true;
4531  }
4532  if (!strcmp(var, "$DIMALTF")) {
4533  return true;
4534  }
4535  if (!strcmp(var, "$DIMAPOST")) {
4536  return true;
4537  }
4538  if (!strcmp(var, "$DIMASO")) {
4539  return true;
4540  }
4541  if (!strcmp(var, "$DIMASZ")) {
4542  return true;
4543  }
4544  if (!strcmp(var, "$DIMBLK")) {
4545  return true;
4546  }
4547  if (!strcmp(var, "$DIMBLK1")) {
4548  return true;
4549  }
4550  if (!strcmp(var, "$DIMBLK2")) {
4551  return true;
4552  }
4553  if (!strcmp(var, "$DIMCEN")) {
4554  return true;
4555  }
4556  if (!strcmp(var, "$DIMCLRD")) {
4557  return true;
4558  }
4559  if (!strcmp(var, "$DIMCLRE")) {
4560  return true;
4561  }
4562  if (!strcmp(var, "$DIMCLRT")) {
4563  return true;
4564  }
4565  if (!strcmp(var, "$DIMDLE")) {
4566  return true;
4567  }
4568  if (!strcmp(var, "$DIMDLI")) {
4569  return true;
4570  }
4571  if (!strcmp(var, "$DIMEXE")) {
4572  return true;
4573  }
4574  if (!strcmp(var, "$DIMEXO")) {
4575  return true;
4576  }
4577  if (!strcmp(var, "$DIMGAP")) {
4578  return true;
4579  }
4580  if (!strcmp(var, "$DIMLFAC")) {
4581  return true;
4582  }
4583  if (!strcmp(var, "$DIMLIM")) {
4584  return true;
4585  }
4586  if (!strcmp(var, "$DIMPOST")) {
4587  return true;
4588  }
4589  if (!strcmp(var, "$DIMRND")) {
4590  return true;
4591  }
4592  if (!strcmp(var, "$DIMSAH")) {
4593  return true;
4594  }
4595  if (!strcmp(var, "$DIMSCALE")) {
4596  return true;
4597  }
4598  if (!strcmp(var, "$DIMSE1")) {
4599  return true;
4600  }
4601  if (!strcmp(var, "$DIMSE2")) {
4602  return true;
4603  }
4604  if (!strcmp(var, "$DIMSHO")) {
4605  return true;
4606  }
4607  if (!strcmp(var, "$DIMSOXD")) {
4608  return true;
4609  }
4610  if (!strcmp(var, "$DIMSTYLE")) {
4611  return true;
4612  }
4613  if (!strcmp(var, "$DIMTAD")) {
4614  return true;
4615  }
4616  if (!strcmp(var, "$DIMTFAC")) {
4617  return true;
4618  }
4619  if (!strcmp(var, "$DIMTIH")) {
4620  return true;
4621  }
4622  if (!strcmp(var, "$DIMTIX")) {
4623  return true;
4624  }
4625  if (!strcmp(var, "$DIMTM")) {
4626  return true;
4627  }
4628  if (!strcmp(var, "$DIMTOFL")) {
4629  return true;
4630  }
4631  if (!strcmp(var, "$DIMTOH")) {
4632  return true;
4633  }
4634  if (!strcmp(var, "$DIMTOL")) {
4635  return true;
4636  }
4637  if (!strcmp(var, "$DIMTP")) {
4638  return true;
4639  }
4640  if (!strcmp(var, "$DIMTSZ")) {
4641  return true;
4642  }
4643  if (!strcmp(var, "$DIMTVP")) {
4644  return true;
4645  }
4646  if (!strcmp(var, "$DIMTXT")) {
4647  return true;
4648  }
4649  if (!strcmp(var, "$DIMZIN")) {
4650  return true;
4651  }
4652  if (!strcmp(var, "$DWGCODEPAGE")) {
4653  return true;
4654  }
4655  if (!strcmp(var, "$DRAGMODE")) {
4656  return true;
4657  }
4658  if (!strcmp(var, "$ELEVATION")) {
4659  return true;
4660  }
4661  if (!strcmp(var, "$EXTMAX")) {
4662  return true;
4663  }
4664  if (!strcmp(var, "$EXTMIN")) {
4665  return true;
4666  }
4667  if (!strcmp(var, "$FILLETRAD")) {
4668  return true;
4669  }
4670  if (!strcmp(var, "$FILLMODE")) {
4671  return true;
4672  }
4673  if (!strcmp(var, "$HANDLING")) {
4674  return true;
4675  }
4676  if (!strcmp(var, "$HANDSEED")) {
4677  return true;
4678  }
4679  if (!strcmp(var, "$INSBASE")) {
4680  return true;
4681  }
4682  if (!strcmp(var, "$LIMCHECK")) {
4683  return true;
4684  }
4685  if (!strcmp(var, "$LIMMAX")) {
4686  return true;
4687  }
4688  if (!strcmp(var, "$LIMMIN")) {
4689  return true;
4690  }
4691  if (!strcmp(var, "$LTSCALE")) {
4692  return true;
4693  }
4694  if (!strcmp(var, "$LUNITS")) {
4695  return true;
4696  }
4697  if (!strcmp(var, "$LUPREC")) {
4698  return true;
4699  }
4700  if (!strcmp(var, "$MAXACTVP")) {
4701  return true;
4702  }
4703  if (!strcmp(var, "$MENU")) {
4704  return true;
4705  }
4706  if (!strcmp(var, "$MIRRTEXT")) {
4707  return true;
4708  }
4709  if (!strcmp(var, "$ORTHOMODE")) {
4710  return true;
4711  }
4712  if (!strcmp(var, "$OSMODE")) {
4713  return true;
4714  }
4715  if (!strcmp(var, "$PDMODE")) {
4716  return true;
4717  }
4718  if (!strcmp(var, "$PDSIZE")) {
4719  return true;
4720  }
4721  if (!strcmp(var, "$PELEVATION")) {
4722  return true;
4723  }
4724  if (!strcmp(var, "$PEXTMAX")) {
4725  return true;
4726  }
4727  if (!strcmp(var, "$PEXTMIN")) {
4728  return true;
4729  }
4730  if (!strcmp(var, "$PLIMCHECK")) {
4731  return true;
4732  }
4733  if (!strcmp(var, "$PLIMMAX")) {
4734  return true;
4735  }
4736  if (!strcmp(var, "$PLIMMIN")) {
4737  return true;
4738  }
4739  if (!strcmp(var, "$PLINEGEN")) {
4740  return true;
4741  }
4742  if (!strcmp(var, "$PLINEWID")) {
4743  return true;
4744  }
4745  if (!strcmp(var, "$PSLTSCALE")) {
4746  return true;
4747  }
4748  if (!strcmp(var, "$PUCSNAME")) {
4749  return true;
4750  }
4751  if (!strcmp(var, "$PUCSORG")) {
4752  return true;
4753  }
4754  if (!strcmp(var, "$PUCSXDIR")) {
4755  return true;
4756  }
4757  if (!strcmp(var, "$PUCSYDIR")) {
4758  return true;
4759  }
4760  if (!strcmp(var, "$QTEXTMODE")) {
4761  return true;
4762  }
4763  if (!strcmp(var, "$REGENMODE")) {
4764  return true;
4765  }
4766  if (!strcmp(var, "$SHADEDGE")) {
4767  return true;
4768  }
4769  if (!strcmp(var, "$SHADEDIF")) {
4770  return true;
4771  }
4772  if (!strcmp(var, "$SKETCHINC")) {
4773  return true;
4774  }
4775  if (!strcmp(var, "$SKPOLY")) {
4776  return true;
4777  }
4778  if (!strcmp(var, "$SPLFRAME")) {
4779  return true;
4780  }
4781  if (!strcmp(var, "$SPLINESEGS")) {
4782  return true;
4783  }
4784  if (!strcmp(var, "$SPLINETYPE")) {
4785  return true;
4786  }
4787  if (!strcmp(var, "$SURFTAB1")) {
4788  return true;
4789  }
4790  if (!strcmp(var, "$SURFTAB2")) {
4791  return true;
4792  }
4793  if (!strcmp(var, "$SURFTYPE")) {
4794  return true;
4795  }
4796  if (!strcmp(var, "$SURFU")) {
4797  return true;
4798  }
4799  if (!strcmp(var, "$SURFV")) {
4800  return true;
4801  }
4802  if (!strcmp(var, "$TDCREATE")) {
4803  return true;
4804  }
4805  if (!strcmp(var, "$TDINDWG")) {
4806  return true;
4807  }
4808  if (!strcmp(var, "$TDUPDATE")) {
4809  return true;
4810  }
4811  if (!strcmp(var, "$TDUSRTIMER")) {
4812  return true;
4813  }
4814  if (!strcmp(var, "$TEXTSIZE")) {
4815  return true;
4816  }
4817  if (!strcmp(var, "$TEXTSTYLE")) {
4818  return true;
4819  }
4820  if (!strcmp(var, "$THICKNESS")) {
4821  return true;
4822  }
4823  if (!strcmp(var, "$TILEMODE")) {
4824  return true;
4825  }
4826  if (!strcmp(var, "$TRACEWID")) {
4827  return true;
4828  }
4829  if (!strcmp(var, "$UCSNAME")) {
4830  return true;
4831  }
4832  if (!strcmp(var, "$UCSORG")) {
4833  return true;
4834  }
4835  if (!strcmp(var, "$UCSXDIR")) {
4836  return true;
4837  }
4838  if (!strcmp(var, "$UCSYDIR")) {
4839  return true;
4840  }
4841  if (!strcmp(var, "$UNITMODE")) {
4842  return true;
4843  }
4844  if (!strcmp(var, "$USERI1")) {
4845  return true;
4846  }
4847  if (!strcmp(var, "$USERR1")) {
4848  return true;
4849  }
4850  if (!strcmp(var, "$USRTIMER")) {
4851  return true;
4852  }
4853  if (!strcmp(var, "$VISRETAIN")) {
4854  return true;
4855  }
4856  if (!strcmp(var, "$WORLDVIEW")) {
4857  return true;
4858  }
4859  if (!strcmp(var, "$FASTZOOM")) {
4860  return true;
4861  }
4862  if (!strcmp(var, "$GRIDMODE")) {
4863  return true;
4864  }
4865  if (!strcmp(var, "$GRIDUNIT")) {
4866  return true;
4867  }
4868  if (!strcmp(var, "$SNAPANG")) {
4869  return true;
4870  }
4871  if (!strcmp(var, "$SNAPBASE")) {
4872  return true;
4873  }
4874  if (!strcmp(var, "$SNAPISOPAIR")) {
4875  return true;
4876  }
4877  if (!strcmp(var, "$SNAPMODE")) {
4878  return true;
4879  }
4880  if (!strcmp(var, "$SNAPSTYLE")) {
4881  return true;
4882  }
4883  if (!strcmp(var, "$SNAPUNIT")) {
4884  return true;
4885  }
4886  if (!strcmp(var, "$VIEWCTR")) {
4887  return true;
4888  }
4889  if (!strcmp(var, "$VIEWDIR")) {
4890  return true;
4891  }
4892  if (!strcmp(var, "$VIEWSIZE")) {
4893  return true;
4894  }
4895  return false;
4896  }
4897 
4898  return false;
4899 }
4900 
4905 int DL_Dxf::getLibVersion(const std::string& str) {
4906  int d[4];
4907  int idx = 0;
4908  // char v[4][5];
4909  std::string v[4];
4910  int ret = 0;
4911 
4912  for (unsigned int i = 0; i < str.length() && idx < 3; ++i) {
4913  if (str[i] == '.') {
4914  d[idx] = i;
4915  idx++;
4916  }
4917  }
4918 
4919  if (idx >= 2) {
4920  d[3] = static_cast<int>(str.length());
4921 
4922  v[0] = str.substr(0, d[0]);
4923  v[1] = str.substr(d[0] + 1, d[1] - d[0] - 1);
4924  v[2] = str.substr(d[1] + 1, d[2] - d[1] - 1);
4925  if (idx >= 3) {
4926  v[3] = str.substr(d[2] + 1, d[3] - d[2] - 1);
4927  } else {
4928  v[3] = "0";
4929  }
4930 
4931  ret = (atoi(v[0].c_str()) << (3 * 8)) +
4932  (atoi(v[1].c_str()) << (2 * 8)) +
4933  (atoi(v[2].c_str()) << (1 * 8)) + (atoi(v[3].c_str()) << (0 * 8));
4934 
4935  return ret;
4936  } else {
4937  std::cerr << "DL_Dxf::getLibVersion: invalid version number: " << str
4938  << "\n";
4939  return 0;
4940  }
4941 }
4942 
4947 // double DL_Dxf::toReal(const char* value, double def) {
4948 // if (value!=NULL && value[0] != '\0') {
4949 // printf("toReal: not empty: %s\n", value);
4950 // printf("toReal: val: %f\n", atof(value));
4951 // printf("toReal: 0: %d\n", value[0]);
4952 // printf("toReal: 1: %d\n", value[1]);
4953 // printf("toReal: 2: %d\n", value[2]);
4954 // double ret;
4955 // if (strchr(value, ',') != NULL) {
4956 // char* tmp = new char[strlen(value)+1];
4957 // strcpy(tmp, value);
4958 // DL_WriterA::strReplace(tmp, ',', '.');
4959 // ret = atof(tmp);
4960 // delete[] tmp;
4961 // }
4962 // else {
4963 // ret = atof(value);
4964 // }
4965 // return ret;
4966 // } else {
4967 // return def;
4968 // }
4969 // }
4970 
4975  char* buf1;
4976  char* buf2;
4977  char* buf3;
4978  char* buf4;
4979  char* buf5;
4980  char* buf6;
4981 
4982  buf1 = new char[10];
4983  buf2 = new char[10];
4984  buf3 = new char[10];
4985  buf4 = new char[10];
4986  buf5 = new char[10];
4987  buf6 = new char[10];
4988 
4989  strcpy(buf1, " 10\n");
4990  strcpy(buf2, "10");
4991  strcpy(buf3, "10\n");
4992  strcpy(buf4, " 10 \n");
4993  strcpy(buf5, " 10 \r");
4994  strcpy(buf6, "\t10 \n");
4995 
4996  std::cout << "1 buf1: '" << buf1 << "'\n";
4997  stripWhiteSpace(&buf1);
4998  std::cout << "2 buf1: '" << buf1 << "'\n";
4999  // assert(!strcmp(buf1, "10"));
5000 
5001  std::cout << "1 buf2: '" << buf2 << "'\n";
5002  stripWhiteSpace(&buf2);
5003  std::cout << "2 buf2: '" << buf2 << "'\n";
5004 
5005  std::cout << "1 buf3: '" << buf3 << "'\n";
5006  stripWhiteSpace(&buf3);
5007  std::cout << "2 buf3: '" << buf3 << "'\n";
5008 
5009  std::cout << "1 buf4: '" << buf4 << "'\n";
5010  stripWhiteSpace(&buf4);
5011  std::cout << "2 buf4: '" << buf4 << "'\n";
5012 
5013  std::cout << "1 buf5: '" << buf5 << "'\n";
5014  stripWhiteSpace(&buf5);
5015  std::cout << "2 buf5: '" << buf5 << "'\n";
5016 
5017  std::cout << "1 buf6: '" << buf6 << "'\n";
5018  stripWhiteSpace(&buf6);
5019  std::cout << "2 buf6: '" << buf6 << "'\n";
5020 }
constexpr double M_PI
Pi.
Definition: CVConst.h:19
int width
int size
std::string version
std::string name
char type
math::float4 color
#define NULL
std::string getLinetype() const
void setLinetype(const std::string &linetype)
int getColor() const
int getWidth() const
void setInPaperSpace(bool on)
std::string getLayer() const
void setLinetypeScale(double linetypeScale)
void setWidth(int width)
int getColor24() const
void setColor(int color)
@ AC1012
Definition: dl_codes.h:98
@ AC1014
Definition: dl_codes.h:99
@ AC1009_MIN
Definition: dl_codes.h:96
@ AC1015
Definition: dl_codes.h:100
@ AC1009
Definition: dl_codes.h:97
virtual void addBlock(const DL_BlockData &data)=0
virtual void addHatchEdge(const DL_HatchEdgeData &data)=0
virtual void addDimAngular3P(const DL_DimensionData &data, const DL_DimAngular3PData &edata)=0
virtual void addEllipse(const DL_EllipseData &data)=0
virtual void add3dFace(const DL_3dFaceData &data)=0
virtual void addSolid(const DL_SolidData &data)=0
virtual void addVertex(const DL_VertexData &data)=0
virtual void addInsert(const DL_InsertData &data)=0
virtual void addDimRadial(const DL_DimensionData &data, const DL_DimRadialData &edata)=0
virtual void addDimAlign(const DL_DimensionData &data, const DL_DimAlignedData &edata)=0
void setAttributes(const DL_Attributes &attrib)
virtual void addDictionary(const DL_DictionaryData &data)=0
virtual void addComment(const std::string &comment)=0
virtual void addXDataString(int code, const std::string &value)=0
virtual void addXRecord(const std::string &handle)=0
virtual void addPoint(const DL_PointData &data)=0
virtual void setVariableVector(const std::string &key, double v1, double v2, double v3, int code)=0
virtual void addDimAngular(const DL_DimensionData &data, const DL_DimAngularData &edata)=0
virtual void linkImage(const DL_ImageDefData &data)=0
virtual void addArcAlignedText(const DL_ArcAlignedTextData &data)=0
virtual void addLinetype(const DL_LinetypeData &data)=0
virtual void addArc(const DL_ArcData &data)=0
virtual void addFitPoint(const DL_FitPointData &data)=0
virtual void addXRecordReal(int code, double value)=0
virtual void addText(const DL_TextData &data)=0
virtual void addDimOrdinate(const DL_DimensionData &data, const DL_DimOrdinateData &edata)=0
virtual void addRay(const DL_RayData &data)=0
virtual void addLeaderVertex(const DL_LeaderVertexData &data)=0
DL_Attributes getAttributes()
virtual void addMTextChunk(const std::string &text)=0
virtual void addLine(const DL_LineData &data)=0
virtual void endSection()=0
virtual void addXRecordString(int code, const std::string &value)=0
virtual void addAttribute(const DL_AttributeData &data)=0
virtual void addTextStyle(const DL_StyleData &data)=0
virtual void endSequence()=0
virtual void addDictionaryEntry(const DL_DictionaryEntryData &data)=0
virtual void addTrace(const DL_TraceData &data)=0
virtual void addHatchLoop(const DL_HatchLoopData &data)=0
virtual void addDimLinear(const DL_DimensionData &data, const DL_DimLinearData &edata)=0
virtual void addImage(const DL_ImageData &data)=0
virtual void addDimDiametric(const DL_DimensionData &data, const DL_DimDiametricData &edata)=0
virtual void addLayer(const DL_LayerData &data)=0
virtual void processCodeValuePair(unsigned int groupCode, const std::string &groupValue)=0
void setExtrusion(double dx, double dy, double dz, double elevation)
virtual void endBlock()=0
virtual void addXDataApp(const std::string &appId)=0
virtual void addMText(const DL_MTextData &data)=0
virtual void addXRecordInt(int code, int value)=0
virtual void setVariableString(const std::string &key, const std::string &value, int code)=0
virtual void addXDataInt(int code, int value)=0
virtual void addHatch(const DL_HatchData &data)=0
virtual void addLinetypeDash(double length)=0
virtual void setVariableDouble(const std::string &key, double value, int code)=0
virtual void addXRecordBool(int code, bool value)=0
virtual void addXDataReal(int code, double value)=0
virtual void addLeader(const DL_LeaderData &data)=0
virtual void addCircle(const DL_CircleData &data)=0
virtual void addSpline(const DL_SplineData &data)=0
virtual void endEntity()=0
virtual void addControlPoint(const DL_ControlPointData &data)=0
virtual void addXLine(const DL_XLineData &data)=0
virtual void setVariableInt(const std::string &key, int value, int code)=0
virtual void addKnot(const DL_KnotData &data)=0
virtual void addPolyline(const DL_PolylineData &data)=0
void addDictionary(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:746
double toReal(const std::string &str)
Definition: dl_dxf.h:443
void addComment(DL_CreationInterface *creationInterface, const std::string &comment)
Definition: dl_dxf.cpp:741
void writeXLine(DL_WriterA &dw, const DL_XLineData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2252
void writeView(DL_WriterA &dw)
Definition: dl_dxf.cpp:3839
void writeDimAligned(DL_WriterA &dw, const DL_DimensionData &data, const DL_DimAlignedData &edata, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2765
void addMText(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1169
void writeObjects(DL_WriterA &dw, const std::string &appDictionaryName="")
Definition: dl_dxf.cpp:4061
void addDictionaryEntry(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:750
void writeTrace(DL_WriterA &dw, const DL_TraceData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2525
void addPolyline(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:979
void writeArc(DL_WriterA &dw, const DL_ArcData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2446
void addSpline(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1018
bool handleDictionaryData(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1278
void write3dFace(DL_WriterA &dw, const DL_3dFaceData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2550
void writeImageDef(DL_WriterA &dw, int handle, const DL_ImageData &data)
Definition: dl_dxf.cpp:3466
void writeLeaderVertex(DL_WriterA &dw, const DL_LeaderVertexData &data)
Definition: dl_dxf.cpp:3212
void writeHatchEdge(DL_WriterA &dw, const DL_HatchEdgeData &data)
Definition: dl_dxf.cpp:3323
void endBlock(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:901
bool handleHatchData(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1850
void writeStyle(DL_WriterA &dw, const DL_StyleData &style)
Definition: dl_dxf.cpp:3781
void addLinetype(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:836
DL_Dxf()
Definition: dl_dxf.cpp:42
void writeObjectsEnd(DL_WriterA &dw)
Definition: dl_dxf.cpp:4455
void addEllipse(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1077
void writePolyline(DL_WriterA &dw, const DL_PolylineData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2297
void writeFitPoint(DL_WriterA &dw, const DL_FitPointData &data)
Definition: dl_dxf.cpp:2400
bool handleSplineData(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1379
void writeDimStyle(DL_WriterA &dw, double dimasz, double dimexe, double dimexo, double dimgap, double dimtxt)
Definition: dl_dxf.cpp:3877
void addBlock(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:880
void endSequence(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:2105
void addHatchEdge()
Definition: dl_dxf.cpp:1838
void writeRay(DL_WriterA &dw, const DL_RayData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2274
void writeVPort(DL_WriterA &dw)
Definition: dl_dxf.cpp:3703
void writeAttribute(DL_WriterA &dw, const DL_AttributeData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2708
void writeDimRadial(DL_WriterA &dw, const DL_DimensionData &data, const DL_DimRadialData &edata, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2887
void writePoint(DL_WriterA &dw, const DL_PointData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2209
void addArc(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1055
void writeDimDiametric(DL_WriterA &dw, const DL_DimensionData &data, const DL_DimDiametricData &edata, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2943
void addSetting(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:758
void writeCircle(DL_WriterA &dw, const DL_CircleData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2424
bool handleLWPolylineData(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1336
void addVertex(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1001
void addDimOrdinate(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1765
~DL_Dxf()
Definition: dl_dxf.cpp:72
void addHatchLoop()
Definition: dl_dxf.cpp:1833
int writeImage(DL_WriterA &dw, const DL_ImageData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:3407
void writeHeader(DL_WriterA &dw)
Writes a DXF header to the file currently opened by the given DXF writer object.
Definition: dl_dxf.cpp:2169
void addLeader(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1782
void writeText(DL_WriterA &dw, const DL_TextData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2673
void writeSpline(DL_WriterA &dw, const DL_SplineData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2361
bool handleXData(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1299
bool handleXRecordData(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1223
bool readDxfGroups(FILE *fp, DL_CreationInterface *creationInterface)
Reads a group couplet from a DXF file. Calls another function to process it.
Definition: dl_dxf.cpp:169
void writeEndBlock(DL_WriterA &dw, const std::string &name)
Definition: dl_dxf.cpp:3683
void addXLine(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:956
void addTextStyle(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:905
void addLine(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:945
bool handleMTextData(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1323
void writeVertex(DL_WriterA &dw, const DL_VertexData &data)
Definition: dl_dxf.cpp:2324
void addHatch(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1815
int toInt(const std::string &str)
Definition: dl_dxf.h:407
static bool getStrippedLine(std::string &s, unsigned int size, FILE *stream, bool stripSpace=true)
Reads line from file & strips whitespace at start and newline at end.
Definition: dl_dxf.cpp:220
void writeSolid(DL_WriterA &dw, const DL_SolidData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2500
void writeLayer(DL_WriterA &dw, const DL_LayerData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:3508
void writeDimOrdinate(DL_WriterA &dw, const DL_DimensionData &data, const DL_DimOrdinateData &edata, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:3123
int getInt16Value(int code, int def)
Definition: dl_dxf.h:412
void addDimAligned(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1677
void addSolid(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1155
void addTrace(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1124
void addRay(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:967
void writeAppDictionary(DL_WriterA &dw)
Definition: dl_dxf.cpp:4396
void writeBlock(DL_WriterA &dw, const DL_BlockData &data)
Definition: dl_dxf.cpp:3652
void writeAppid(DL_WriterA &dw, const std::string &name)
Definition: dl_dxf.cpp:3630
void addImageDef(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:2086
DL_DimensionData getDimData()
Definition: dl_dxf.cpp:1630
void addDimDiametric(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1709
void addDimRadial(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1694
void writeControlPoint(DL_WriterA &dw, const DL_ControlPointData &data)
Definition: dl_dxf.cpp:2386
void writeLeader(DL_WriterA &dw, const DL_LeaderData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:3182
void writeHatchLoop1(DL_WriterA &dw, const DL_HatchLoopData &data)
Definition: dl_dxf.cpp:3299
void addLayer(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:807
void addDimAngular(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1725
void writeUcs(DL_WriterA &dw)
Definition: dl_dxf.cpp:3858
void endEntity(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:2098
void addImage(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:2063
void writeXRecord(DL_WriterA &dw, int handle, int value)
Definition: dl_dxf.cpp:4412
void addCircle(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1066
bool hasValue(int code)
Definition: dl_dxf.h:398
static bool stripWhiteSpace(char **s, bool stripSpaces=true)
Strips leading whitespace and trailing Carriage Return (CR) and Line Feed (LF) from NULL terminated s...
Definition: dl_dxf.cpp:285
bool handleLeaderData(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1490
static bool checkVariable(const char *var, DL_Codes::version version)
Definition: dl_dxf.cpp:4467
int getIntValue(int code, int def)
Definition: dl_dxf.h:400
void addPoint(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:936
double getRealValue(int code, double def)
Definition: dl_dxf.h:436
void writeDimLinear(DL_WriterA &dw, const DL_DimensionData &data, const DL_DimLinearData &edata, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2823
static void test()
Definition: dl_dxf.cpp:4974
void writeEllipse(DL_WriterA &dw, const DL_EllipseData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2473
void writeHatch2(DL_WriterA &dw, const DL_HatchData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:3263
void writeLinetype(DL_WriterA &dw, const DL_LinetypeData &data)
Definition: dl_dxf.cpp:3564
void writeHatch1(DL_WriterA &dw, const DL_HatchData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:3229
void writeLine(DL_WriterA &dw, const DL_LineData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2230
int getLibVersion(const std::string &str)
Definition: dl_dxf.cpp:4905
void writeDimStyleOverrides(DL_WriterA &dw, const DL_DimensionData &data)
Definition: dl_dxf.cpp:2743
bool processDXFGroup(DL_CreationInterface *creationInterface, int groupCode, const std::string &groupValue)
Definition: dl_dxf.cpp:320
void addDimAngular3P(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1746
void writeDimAngular3P(DL_WriterA &dw, const DL_DimensionData &data, const DL_DimAngular3PData &edata, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:3063
void addText(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1531
void writePolylineEnd(DL_WriterA &dw)
Definition: dl_dxf.cpp:2346
void addDimLinear(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1657
void writeDimAngular(DL_WriterA &dw, const DL_DimensionData &data, const DL_DimAngularData &edata, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2999
void writeInsert(DL_WriterA &dw, const DL_InsertData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2574
void writeHatchLoop2(DL_WriterA &dw, const DL_HatchLoopData &data)
Definition: dl_dxf.cpp:3312
bool toBool(const std::string &str)
Definition: dl_dxf.h:424
bool handleLinetypeData(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:868
void writeBlockRecord(DL_WriterA &dw)
Definition: dl_dxf.cpp:3982
int writeDictionaryEntry(DL_WriterA &dw, const std::string &name)
Definition: dl_dxf.cpp:4404
bool in(const std::string &file, DL_CreationInterface *creationInterface)
Reads the given file and calls the appropriate functions in the given creation interface for every en...
Definition: dl_dxf.cpp:105
DL_WriterA * out(const char *file, DL_Codes::version version=DL_Codes::AC1015)
Opens the given file for writing and returns a pointer to the dxf writer. This pointer needs to be pa...
Definition: dl_dxf.cpp:2149
void writeKnot(DL_WriterA &dw, const DL_KnotData &data)
Definition: dl_dxf.cpp:2413
void add3dFace(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1138
void addInsert(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1090
void writeMText(DL_WriterA &dw, const DL_MTextData &data, const DL_Attributes &attrib)
Definition: dl_dxf.cpp:2624
void writeComment(DL_WriterA &dw, const std::string &comment)
Definition: dl_dxf.cpp:4460
std::string getStringValue(int code, const std::string &def)
Definition: dl_dxf.h:429
void addArcAlignedText(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1562
void addAttribute(DL_CreationInterface *creationInterface)
Definition: dl_dxf.cpp:1599
void dxfReal(int gc, double value) const
void dxfInt(int gc, int value) const
void dxfString(int gc, const char *value) const
bool openFailed() const
void dxfHex(int gc, int value) const
void tableLinetypeEntry(unsigned long int h=0) const
Definition: dl_writer.h:375
unsigned long getNextHandle() const
Definition: dl_writer.h:496
void comment(const char *text) const
Definition: dl_writer.h:282
void entity(const char *entTypeName) const
Definition: dl_writer.h:294
void sectionBlockEntry(unsigned long int h=0) const
Definition: dl_writer.h:419
unsigned long incHandle() const
Definition: dl_writer.h:501
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
unsigned long handle(int gc=5) const
Definition: dl_writer.h:487
virtual void dxfBool(int gc, bool value) const
Definition: dl_writer.h:552
void tableAppidEntry(unsigned long int h=0) const
Definition: dl_writer.h:397
void sectionHeader() const
Definition: dl_writer.h:93
void coord(int gc, double x, double y, double z=0) const
Definition: dl_writer.h:468
void entityAttributes(const DL_Attributes &attrib) const
Definition: dl_writer.h:315
#define DL_POINT_COORD_CODE
Definition: dl_codes.h:414
#define DL_VERSION_R12
Definition: dl_codes.h:367
#define DL_DXF_MAXLINE
Definition: dl_codes.h:57
#define DL_LINE_END_CODE
Definition: dl_codes.h:436
#define DL_LINE_START_CODE
Definition: dl_codes.h:435
#define DL_DXF_MAXGROUPCODE
Definition: dl_codes.h:58
#define DL_VERTEX_COORD_CODE
Definition: dl_codes.h:502
#define DL_VERSION_2000
Definition: dl_codes.h:374
#define DL_VERSION_R13
Definition: dl_codes.h:369
#define DL_ENTITY_LEADER
Definition: dl_dxf.h:88
#define DL_ENTITY_ELLIPSE
Definition: dl_dxf.h:83
#define DL_UNKNOWN
Definition: dl_dxf.h:66
#define DL_ENTITY_3DFACE
Definition: dl_dxf.h:95
#define DL_ENTITY_RAY
Definition: dl_dxf.h:97
#define DL_ENTITY_HATCH
Definition: dl_dxf.h:89
#define DL_NANDOUBLE
Definition: dl_dxf.h:53
#define DL_ENTITY_SPLINE
Definition: dl_dxf.h:78
#define DL_ENTITY_ARCALIGNEDTEXT
Definition: dl_dxf.h:98
#define DL_ENTITY_DIMENSION
Definition: dl_dxf.h:87
#define DL_SETTING
Definition: dl_dxf.h:72
#define DL_ENTITY_ARC
Definition: dl_dxf.h:81
#define DL_ENTITY_POINT
Definition: dl_dxf.h:73
#define DL_BLOCK
Definition: dl_dxf.h:68
#define DL_ENTITY_LINE
Definition: dl_dxf.h:74
#define DL_ENTITY_VERTEX
Definition: dl_dxf.h:77
#define DL_ENTITY_INSERT
Definition: dl_dxf.h:84
#define DL_ENTITY_ATTRIB
Definition: dl_dxf.h:90
#define DL_ENTITY_CIRCLE
Definition: dl_dxf.h:82
#define DL_STYLE
Definition: dl_dxf.h:71
#define DL_LAYER
Definition: dl_dxf.h:67
#define DL_DICTIONARY
Definition: dl_dxf.h:101
#define DL_LINETYPE
Definition: dl_dxf.h:70
#define DL_ENTITY_SEQEND
Definition: dl_dxf.h:99
#define DL_ENTITY_MTEXT
Definition: dl_dxf.h:86
#define DL_ENDBLK
Definition: dl_dxf.h:69
#define DL_ENTITY_TEXT
Definition: dl_dxf.h:85
#define DL_ENTITY_IMAGE
Definition: dl_dxf.h:91
#define DL_XRECORD
Definition: dl_dxf.h:100
#define DL_ENTITY_XLINE
Definition: dl_dxf.h:96
#define DL_ENTITY_SOLID
Definition: dl_dxf.h:94
#define DL_ENTITY_POLYLINE
Definition: dl_dxf.h:75
#define DL_ENTITY_IMAGEDEF
Definition: dl_dxf.h:92
#define DL_ENTITY_LWPOLYLINE
Definition: dl_dxf.h:76
#define DL_VERSION
Definition: dl_dxf.h:59
#define DL_ENTITY_TRACE
Definition: dl_dxf.h:93
GraphType data
Definition: graph_cut.cc:138
normal_z y
normal_z x
unsigned int nKnots
Definition: dl_entities.h:1669
std::vector< double > knots
Definition: dl_entities.h:1676
std::vector< std::vector< double > > controlPoints
Definition: dl_entities.h:1675
std::vector< std::vector< double > > vertices
Definition: dl_entities.h:1687
unsigned int nControl
Definition: dl_entities.h:1671
unsigned int nFit
Definition: dl_entities.h:1673
std::vector< double > weights
Definition: dl_entities.h:1677
unsigned int degree
Definition: dl_entities.h:1665
std::vector< std::vector< double > > fitPoints
Definition: dl_entities.h:1678
double tangentEndY
Definition: dl_entities.h:525
double tangentEndZ
Definition: dl_entities.h:526
double tangentStartY
Definition: dl_entities.h:522
double tangentEndX
Definition: dl_entities.h:524
double tangentStartZ
Definition: dl_entities.h:523
double tangentStartX
Definition: dl_entities.h:521
std::string primaryFontFile
Definition: dl_entities.h:174
std::string bigFontFile
Definition: dl_entities.h:176
double widthFactor
Definition: dl_entities.h:166
int textGenerationFlags
Definition: dl_entities.h:170
double lastHeightUsed
Definition: dl_entities.h:172
double obliqueAngle
Definition: dl_entities.h:168
std::string name
Definition: dl_entities.h:160
double fixedTextHeight
Definition: dl_entities.h:164
double x[4]
Definition: dl_entities.h:476
double z[4]
Definition: dl_entities.h:478
double y[4]
Definition: dl_entities.h:477