Seamly2D
Code documentation
vdxfengine.cpp
Go to the documentation of this file.
1  /************************************************************************
2  **
3  ** @file vdxfengine.cpp
4  ** @author Valentina Zhuravska <zhuravska19(at)gmail.com>
5  ** @date 12 8, 2015
6  **
7  ** @brief
8  ** @copyright
9  ** This source code is part of the Valentine project, a pattern making
10  ** program, whose allow create and modeling patterns of clothing.
11  ** Copyright (C) 2013-2015 Seamly2D project
12  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
13  **
14  ** Seamly2D is free software: you can redistribute it and/or modify
15  ** it under the terms of the GNU General Public License as published by
16  ** the Free Software Foundation, either version 3 of the License, or
17  ** (at your option) any later version.
18  **
19  ** Seamly2D is distributed in the hope that it will be useful,
20  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  ** GNU General Public License for more details.
23  **
24  ** You should have received a copy of the GNU General Public License
25  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #include "vdxfengine.h"
30 
31 #include <QByteArray>
32 #include <QColor>
33 #include <QDateTime>
34 #include <QFlag>
35 #include <QFlags>
36 #include <QFont>
37 #include <QLineF>
38 #include <QList>
39 #include <QMessageLogger>
40 #include <QPaintEngineState>
41 #include <QPainterPath>
42 #include <QPen>
43 #include <QPolygonF>
44 #include <QTextItem>
45 #include <Qt>
46 #include <QtDebug>
47 
48 #include "../vmisc/def.h"
49 #include "../vmisc/diagnostic.h"
50 #include "../vmisc/vmath.h"
51 #include "dxiface.h"
52 #include "../vlayout/vlayoutpiece.h"
53 
54 static const qreal AAMATextHeight = 2.5;
55 
56 //---------------------------------------------------------------------------------------------------------------------
57 static inline QPaintEngine::PaintEngineFeatures svgEngineFeatures()
58 {
59 QT_WARNING_PUSH
60 QT_WARNING_DISABLE_CLANG("-Wsign-conversion")
61 QT_WARNING_DISABLE_INTEL(68)
62 
63  return QPaintEngine::PaintEngineFeatures(
64  QPaintEngine::AllFeatures
65  & ~QPaintEngine::PatternBrush
66  & ~QPaintEngine::PerspectiveTransform
67  & ~QPaintEngine::ConicalGradientFill
68  & ~QPaintEngine::PorterDuff);
69 
71 }
72 
73 //---------------------------------------------------------------------------------------------------------------------
75  : QPaintEngine(svgEngineFeatures())
76  , size()
77  , resolution(static_cast<int>(PrintDPI))
78  , fileName()
79  , m_version(DRW::AC1014)
80  , m_binary(false)
81  , transform()
82  , input()
83  , varMeasurement(VarMeasurement::Metric)
84  , varInsunits(VarInsunits::Millimeters)
85  , textBuffer(new DRW_Text())
86 {
87 }
88 
89 //---------------------------------------------------------------------------------------------------------------------
91 {
92  delete textBuffer;
93 }
94 
95 //---------------------------------------------------------------------------------------------------------------------
96 bool VDxfEngine::begin(QPaintDevice *pdev)
97 {
98  Q_UNUSED(pdev)
99 
100  if (isActive())
101  {
102  qWarning("VDxfEngine::begin(), the engine was alredy activated");
103  return false;
104  }
105 
106  if (size.isValid() == false)
107  {
108  qWarning()<<"VDxfEngine::begin(), size is not valid";
109  return false;
110  }
111 
113  input->AddQtLTypes();
114  input->AddDefLayers();
115  return true;
116 }
117 
118 //---------------------------------------------------------------------------------------------------------------------
120 {
121  const bool res = input->fileExport(m_binary);
122  return res;
123 }
124 
125 //---------------------------------------------------------------------------------------------------------------------
126 // cppcheck-suppress unusedFunction
127 void VDxfEngine::updateState(const QPaintEngineState &state)
128 {
129  QPaintEngine::DirtyFlags flags = state.state();
130 
131  // always stream full gstate, which is not required, but...
132  flags |= QPaintEngine::AllDirty;
133 
134 
135  if (flags & QPaintEngine::DirtyTransform)
136  {
137  transform = state.transform(); // Save new transformation for moving paths
138  }
139 }
140 
141 //---------------------------------------------------------------------------------------------------------------------
142 void VDxfEngine::drawPath(const QPainterPath &path)
143 {
144  const QList<QPolygonF> subpaths = path.toSubpathPolygons(transform);
145 
146  for (int j=0; j < subpaths.size(); ++j)
147  {
148  const QPolygonF polygon = subpaths.at(j);
149  if (polygon.isEmpty())
150  {
151  continue;
152  }
153 
154  if (m_version > DRW::AC1009)
155  { // Use lwpolyline
156  DRW_LWPolyline *poly = new DRW_LWPolyline();
157  poly->layer = "0";
158  poly->color = getPenColor();
159  poly->lWeight = DRW_LW_Conv::widthByLayer;
160  poly->lineType = getPenStyle();
161 
162  if (polygon.size() > 1 && polygon.first() == polygon.last())
163  {
164  poly->flags |= 0x1; // closed
165  }
166 
167  poly->flags |= 0x80; // plinegen
168 
169  for (int i=0; i < polygon.count(); ++i)
170  {
171  poly->addVertex(DRW_Vertex2D(FromPixel(polygon.at(i).x(), varInsunits),
172  FromPixel(getSize().height() - polygon.at(i).y(), varInsunits), 0));
173  }
174 
175  input->AddEntity(poly);
176  }
177  else
178  { // Use polyline
179  DRW_Polyline *poly = new DRW_Polyline();
180  poly->layer = "0";
181  poly->color = getPenColor();
182  poly->lWeight = DRW_LW_Conv::widthByLayer;
183  poly->lineType = getPenStyle();
184  if (polygon.size() > 1 && polygon.first() == polygon.last())
185  {
186  poly->flags |= 0x1; // closed
187  }
188 
189  poly->flags |= 0x80; // plinegen
190 
191  for (int i=0; i < polygon.count(); ++i)
192  {
193  poly->addVertex(DRW_Vertex(FromPixel(polygon.at(i).x(), varInsunits),
194  FromPixel(getSize().height() - polygon.at(i).y(), varInsunits), 0, 0));
195  }
196 
197  input->AddEntity(poly);
198  }
199  }
200 }
201 
202 //---------------------------------------------------------------------------------------------------------------------
203 void VDxfEngine::drawLines(const QLineF * lines, int lineCount)
204 {
205  for (int i = 0; i < lineCount; ++i)
206  {
207  const QPointF p1 = transform.map(lines[i].p1());
208  const QPointF p2 = transform.map(lines[i].p2());
209 
210  DRW_Line *line = new DRW_Line();
211  line->basePoint = DRW_Coord(FromPixel(p1.x(), varInsunits),
212  FromPixel(getSize().height() - p1.y(), varInsunits), 0);
213  line->secPoint = DRW_Coord(FromPixel(p2.x(), varInsunits),
214  FromPixel(getSize().height() - p2.y(), varInsunits), 0);
215  line->layer = "0";
216  line->color = getPenColor();
217  line->lWeight = DRW_LW_Conv::widthByLayer;
218  line->lineType = getPenStyle();
219 
220  input->AddEntity(line);
221  }
222 }
223 
224 //---------------------------------------------------------------------------------------------------------------------
225 void VDxfEngine::drawLines(const QLine * lines, int lineCount)
226 {
227  QPaintEngine::drawLines(lines, lineCount);
228 }
229 
230 //---------------------------------------------------------------------------------------------------------------------
231 void VDxfEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
232 {
233  Q_UNUSED(mode)
234 
235  if (pointCount <= 0)
236  {
237  return;
238  }
239 
240  if (m_version > DRW::AC1009)
241  { // Use lwpolyline
242  DRW_LWPolyline *poly = new DRW_LWPolyline();
243  poly->layer = "0";
244  poly->color = getPenColor();
245  poly->lWeight = DRW_LW_Conv::widthByLayer;
246  poly->lineType = getPenStyle();
247 
248  if (pointCount > 1 && points[0] == points[pointCount])
249  {
250  poly->flags |= 0x1; // closed
251  }
252 
253  poly->flags |= 0x80; // plinegen
254 
255  for (int i = 0; i < pointCount; ++i)
256  {
257  const QPointF p = transform.map(points[i]);
258  poly->addVertex(DRW_Vertex2D(FromPixel(p.x(), varInsunits),
259  FromPixel(getSize().height() - p.y(), varInsunits), 0));
260  }
261 
262  input->AddEntity(poly);
263  }
264  else
265  { // Use polyline
266  DRW_Polyline *poly = new DRW_Polyline();
267  poly->layer = "0";
268  poly->color = getPenColor();
269  poly->lWeight = DRW_LW_Conv::widthByLayer;
270  poly->lineType = getPenStyle();
271 
272  if (pointCount > 1 && points[0] == points[pointCount])
273  {
274  poly->flags |= 0x1; // closed
275  }
276 
277  poly->flags |= 0x80; // plinegen
278 
279  for (int i = 0; i < pointCount; ++i)
280  {
281  const QPointF p = transform.map(points[i]);
282  poly->addVertex(DRW_Vertex(FromPixel(p.x(), varInsunits),
283  FromPixel(getSize().height() - p.y(), varInsunits), 0, 0));
284  }
285 
286  input->AddEntity(poly);
287  }
288 }
289 
290 //---------------------------------------------------------------------------------------------------------------------
291 void VDxfEngine::drawPolygon(const QPoint *points, int pointCount, QPaintEngine::PolygonDrawMode mode)
292 {
293  QPaintEngine::drawPolygon(points, pointCount, mode);
294 }
295 
296 //---------------------------------------------------------------------------------------------------------------------
297 void VDxfEngine::drawEllipse(const QRectF & rect)
298 {
299  const QRectF newRect = transform.mapRect(rect);
300  const double rotationAngle = atan(transform.m12()/transform.m11());
301 
302  double majorX, majorY; // distanse between center and endpoint of the major axis
303  double ratio; // ratio of minor axis to major axis
304  if(rect.width()<= rect.height())
305  {
306  majorX = (rect.top() - rect.center().y())*sin(rotationAngle)*transform.m11()/cos(rotationAngle);
307  // major axis * sin(rotation angle) * x-scale-factor
308  majorY = (rect.top() - rect.center().y())*transform.m22();
309  // major axis * cos(rotation angle) * y-scale-factor, where y-scale-factor = transform.m22()/cos(rotationAngle)
310  ratio = rect.width()/rect.height();
311  }
312  else
313  {
314  majorX = (rect.right() - rect.center().x())*transform.m11();
315  // major axis * cos(rotation angle) * x-scale-factor, where y-scale-factor = transform.m22()/cos(rotationAngle)
316  majorY = (rect.right() - rect.center().x())*sin(rotationAngle)*transform.m22()/cos(rotationAngle);
317  // major axis * sin(rotation angle) * y-scale-factor
318  ratio = rect.height()/rect.width();
319  }
320 
321  DRW_Ellipse *ellipse = new DRW_Ellipse();
322  ellipse->basePoint = DRW_Coord(FromPixel(newRect.center().x(), varInsunits),
323  FromPixel(getSize().height() - newRect.center().y(), varInsunits), 0);
324  ellipse->secPoint = DRW_Coord(FromPixel(majorX, varInsunits), FromPixel(majorY, varInsunits), 0);
325  ellipse->ratio = ratio;
326  ellipse->staparam = 0;
327  ellipse->endparam = 2*M_PI;
328 
329  ellipse->layer = "0";
330  ellipse->color = getPenColor();
331  ellipse->lWeight = DRW_LW_Conv::widthByLayer;
332  ellipse->lineType = getPenStyle();
333 
334  input->AddEntity(ellipse);
335 }
336 
337 //---------------------------------------------------------------------------------------------------------------------
338 void VDxfEngine::drawEllipse(const QRect & rect)
339 {
340  QPaintEngine::drawEllipse(rect);
341 }
342 
343 //---------------------------------------------------------------------------------------------------------------------
344 void VDxfEngine::drawTextItem(const QPointF & p, const QTextItem & textItem)
345 {
346  if (textBuffer->text.size() == 0)
347  {
348  const QPointF startPoint = transform.map(p);
349  const double rotationAngle = qRadiansToDegrees(qAtan2(transform.m12(), transform.m11()));
350 
351  const QFont f = textItem.font();
352  const UTF8STRING fontStyle = input->AddFont(f);
353 
354  textBuffer->basePoint = DRW_Coord(FromPixel(startPoint.x(), varInsunits),
355  FromPixel(getSize().height() - startPoint.y(), varInsunits), 0);
356  textBuffer->secPoint = DRW_Coord(FromPixel(startPoint.x(), varInsunits),
357  FromPixel(getSize().height() - startPoint.y(), varInsunits), 0);
358  textBuffer->height = FromPixel(QFontMetrics(f).height(), varInsunits);
359 
360  textBuffer->style = fontStyle;
361  textBuffer->angle = -rotationAngle;
362 
363  textBuffer->layer = "0";
364  textBuffer->color = getPenColor();
365  textBuffer->lWeight = DRW_LW_Conv::widthByLayer;
366  textBuffer->lineType = getPenStyle();
367  }
368 
369  /* Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding
370  * special placholder. */
371  QString t = textItem.text();
372  const bool foundEndOfString = t.contains(endStringPlaceholder);
373 
374  if (foundEndOfString)
375  {
376  t.replace(endStringPlaceholder, "");
377  }
378 
379  textBuffer->text += t.toStdString();
380 
381  if (foundEndOfString)
382  {
383  input->AddEntity(textBuffer);
384  textBuffer = new DRW_Text();
385  }
386 }
387 
388 //---------------------------------------------------------------------------------------------------------------------
389 QPaintEngine::Type VDxfEngine::type() const
390 {
391  return QPaintEngine::User;
392 }
393 
394 //---------------------------------------------------------------------------------------------------------------------
395 // cppcheck-suppress unusedFunction
396 void VDxfEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
397 {
398  Q_UNUSED(r)
399  Q_UNUSED(pm)
400  Q_UNUSED(sr)
401 }
402 
403  //---------------------------------------------------------------------------------------------------------------------
404 QSize VDxfEngine::getSize() const
405 {
406  return size;
407 }
408 
409  //---------------------------------------------------------------------------------------------------------------------
410 void VDxfEngine::setSize(const QSize &value)
411 {
412  Q_ASSERT(not isActive());
413  size = value;
414 }
415 
416  //---------------------------------------------------------------------------------------------------------------------
418 {
419  return resolution;
420 }
421 
422 //---------------------------------------------------------------------------------------------------------------------
423 void VDxfEngine::setResolution(double value)
424 {
425  Q_ASSERT(not isActive());
426  resolution = value;
427 }
428 
429 //---------------------------------------------------------------------------------------------------------------------
430 QString VDxfEngine::getFileName() const
431 {
432  return fileName;
433 }
434 
435 //---------------------------------------------------------------------------------------------------------------------
436 void VDxfEngine::setFileName(const QString &value)
437 {
438  Q_ASSERT(not isActive());
439  fileName = value;
440 }
441 
442 //---------------------------------------------------------------------------------------------------------------------
443 DRW::Version VDxfEngine::GetVersion() const
444 {
445  return m_version;
446 }
447 
448 //---------------------------------------------------------------------------------------------------------------------
449 void VDxfEngine::SetVersion(DRW::Version version)
450 {
451  Q_ASSERT(not isActive());
452  m_version = version;
453 }
454 
455 //---------------------------------------------------------------------------------------------------------------------
457 {
458  m_binary = binary;
459 }
460 
461 //---------------------------------------------------------------------------------------------------------------------
463 {
464  return m_binary;
465 }
466 
467 //---------------------------------------------------------------------------------------------------------------------
469 {
470  switch (state->pen().style())
471  {
472  case Qt::DashLine:
473  return "DASHED";
474  case Qt::DotLine:
475  return "DOT";
476  case Qt::DashDotLine:
477  return "DASHDOT2";
478  case Qt::DashDotDotLine:
479  return "DIVIDE2";
480  case Qt::SolidLine:
481  default:
482  return "BYLAYER";
483  }
484 }
485 
486 //---------------------------------------------------------------------------------------------------------------------
488 {
489  QColor color = state->pen().color();
490 
491  if(color == Qt::black)
492  {
493  return DRW::black;
494  }
495  else if(color == Qt::white)
496  {
497  return DRW::white;
498  }
499  else if(color == Qt::darkGray)
500  {
501  return DRW::gray;
502  }
503  else if(color == Qt::gray)
504  {
505  return DRW::l_gray;
506  }
507  else if(color == Qt::darkMagenta)
508  {
509  return DRW::magenta;
510  }
511  else if(color == Qt::magenta)
512  {
513  return DRW::l_magenta;
514  }
515  else if(color == Qt::cyan)
516  {
517  return DRW::l_cyan;
518  }
519  else if(color == Qt::darkCyan)
520  {
521  return DRW::cyan;
522  }
523  else if(color == Qt::blue)
524  {
525  return DRW::l_blue;
526  }
527  else if(color == Qt::darkBlue)
528  {
529  return DRW::blue;
530  }
531  else if(color == Qt::darkGreen)
532  {
533  return DRW::green;
534  }
535  else if(color == Qt::green)
536  {
537  return DRW::l_green;
538  }
539  else if(color == Qt::darkRed)
540  {
541  return DRW::red;
542  }
543  else if(color == Qt::red)
544  {
545  return DRW::l_red;
546  }
547  else if(color == Qt::yellow)
548  {
549  return DRW::yellow;
550  }
551  else
552  {
553  return DRW::ColorByLayer;
554  }
555 }
556 
557 //---------------------------------------------------------------------------------------------------------------------
559 {
560  Q_ASSERT(not isActive());
561  varMeasurement = var;
562 }
563 
564 //---------------------------------------------------------------------------------------------------------------------
566 {
567  Q_ASSERT(not isActive());
568  varInsunits = var;
569 }
570 
571 //---------------------------------------------------------------------------------------------------------------------
572 QT_WARNING_PUSH
573 QT_WARNING_DISABLE_GCC("-Wswitch-default")
574 
575 double VDxfEngine::FromPixel(double pix, const VarInsunits &unit) const
576 {
577  switch (unit)
578  {
580  return pix / resolution * 25.4;
582  return pix / resolution * 25.4 / 10.0;
583  case VarInsunits::Inches:
584  return pix / resolution;
585  }
586  return pix;
587 }
588 
589 //---------------------------------------------------------------------------------------------------------------------
590 double VDxfEngine::ToPixel(double val, const VarInsunits &unit) const
591 {
592  switch (unit)
593  {
595  return (val / 25.4) * resolution;
597  return ((val * 10.0) / 25.4) * resolution;
598  case VarInsunits::Inches:
599  return val * resolution;
600  }
601  return val;
602 }
603 
605 
606 //---------------------------------------------------------------------------------------------------------------------
608 {
609  if (size.isValid() == false)
610  {
611  qWarning()<<"VDxfEngine::begin(), size is not valid";
612  return false;
613  }
614 
616  input->AddAAMAHeaderData();
617  if (m_version > DRW::AC1009)
618  {
619  input->AddDefLayers();
620  }
621  input->AddAAMALayers();
622 
623  ExportAAMAGlobalText(input, details);
624 
625  for(int i = 0; i < details.size(); ++i)
626  {
627  const VLayoutPiece &detail = details.at(i);
628 
629  dx_ifaceBlock *detailBlock = new dx_ifaceBlock();
630 
631  QString blockName = detail.GetName();
632  if (m_version <= DRW::AC1009)
633  {
634  blockName.replace(' ', '_');
635  }
636 
637  detailBlock->name = blockName.toStdString();
638  detailBlock->layer = "1";
639 
640  ExportAAMAOutline(detailBlock, detail);
641  ExportAAMADraw(detailBlock, detail);
642  ExportAAMAIntcut(detailBlock, detail);
643  ExportAAMANotch(detailBlock, detail);
644  ExportAAMAGrainline(detailBlock, detail);
645  ExportAAMAText(detailBlock, detail);
646 
647  input->AddBlock(detailBlock);
648 
649  DRW_Insert *insert = new DRW_Insert();
650  insert->name = blockName.toStdString();
651  insert->layer = "1";
652 
653  input->AddEntity(insert);
654  }
655 
656  return input->fileExport(m_binary);
657 }
658 
659 //---------------------------------------------------------------------------------------------------------------------
661 {
662  QVector<QPointF> outline;
663  if (piece.IsSeamAllowance() && not piece.IsSeamAllowanceBuiltIn())
664  {
665  outline = piece.GetSeamAllowancePoints();
666  }
667  else
668  {
669  outline = piece.getContourPoints();
670  }
671 
672  DRW_Entity *e = AAMAPolygon(outline, "1", true);
673  if (e)
674  {
675  detailBlock->ent.push_back(e);
676  }
677 }
678 
679 //---------------------------------------------------------------------------------------------------------------------
680 void VDxfEngine::ExportAAMADraw(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
681 {
682  if (not detail.isHideSeamLine())
683  {
684  QVector<QPointF> poly = detail.getContourPoints();
685  DRW_Entity *e = AAMAPolygon(poly, "8", true);
686  if (e)
687  {
688  detailBlock->ent.push_back(e);
689  }
690  }
691 }
692 
693 //---------------------------------------------------------------------------------------------------------------------
694 void VDxfEngine::ExportAAMAIntcut(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
695 {
696  QVector<QVector<QPointF>> drawIntCut = detail.InternalPathsForCut(false);
697  for(int j = 0; j < drawIntCut.size(); ++j)
698  {
699  DRW_Entity *e = AAMAPolygon(drawIntCut.at(j), "8", false);
700  if (e)
701  {
702  detailBlock->ent.push_back(e);
703  }
704  }
705 
706  drawIntCut = detail.InternalPathsForCut(true);
707  for(int j = 0; j < drawIntCut.size(); ++j)
708  {
709  DRW_Entity *e = AAMAPolygon(drawIntCut.at(j), "11", false);
710  if (e)
711  {
712  detailBlock->ent.push_back(e);
713  }
714  }
715 }
716 
717 //---------------------------------------------------------------------------------------------------------------------
718 void VDxfEngine::ExportAAMANotch(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
719 {
720  if (detail.IsSeamAllowance())
721  {
722  QVector<QLineF> notches = detail.getNotches();
723  for(int i = 0; i < notches.size(); ++i)
724  {
725  DRW_Entity *e = AAMALine(notches.at(i), "4");
726  if (e)
727  {
728  detailBlock->ent.push_back(e);
729  }
730  }
731  }
732 }
733 
734 //---------------------------------------------------------------------------------------------------------------------
736 {
737  const QVector<QPointF> grainline = detail.getGrainline();
738  if (grainline.count() > 1)
739  {
740  DRW_Entity *e = AAMALine(QLineF(grainline.first(), grainline.last()), "7");
741  if (e)
742  {
743  detailBlock->ent.push_back(e);
744  }
745  }
746 }
747 
748 //---------------------------------------------------------------------------------------------------------------------
749 void VDxfEngine::ExportAAMAText(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
750 {
751  const QStringList list = detail.GetPieceText();
752  const QPointF startPos = detail.GetPieceTextPosition();
753 
754  for (int i = 0; i < list.size(); ++i)
755  {
756  QPointF pos(startPos.x(), startPos.y() - ToPixel(AAMATextHeight, varInsunits)*(list.size() - i-1));
757  detailBlock->ent.push_back(AAMAText(pos, list.at(i), "1"));
758  }
759 }
760 
761 //---------------------------------------------------------------------------------------------------------------------
763 {
764  for(int i = 0; i < details.size(); ++i)
765  {
766  const QStringList strings = details.at(i).GetPatternText();
767  if (not strings.isEmpty())
768  {
769  for (int j = 0; j < strings.size(); ++j)
770  {
771  QPointF pos(0, getSize().height() - ToPixel(AAMATextHeight, varInsunits)*(strings.size() - j-1));
772  input->AddEntity(AAMAText(pos, strings.at(j), "1"));
773  }
774  return;
775  }
776  }
777 }
778 
779 //---------------------------------------------------------------------------------------------------------------------
780 DRW_Entity *VDxfEngine::AAMAPolygon(const QVector<QPointF> &polygon, const QString &layer, bool forceClosed)
781 {
782  if (polygon.isEmpty())
783  {
784  return nullptr;
785  }
786 
787  if (m_version > DRW::AC1009)
788  { // Use lwpolyline
789  return CreateAAMAPolygon<DRW_LWPolyline, DRW_Vertex2D>(polygon, layer, forceClosed);
790  }
791  else
792  { // Use polyline
793  return CreateAAMAPolygon<DRW_Polyline, DRW_Vertex>(polygon, layer, forceClosed);
794  }
795 }
796 
797 //---------------------------------------------------------------------------------------------------------------------
798 DRW_Entity *VDxfEngine::AAMALine(const QLineF &line, const QString &layer)
799 {
800  DRW_Line *lineEnt = new DRW_Line();
801  lineEnt->basePoint = DRW_Coord(FromPixel(line.p1().x(), varInsunits),
802  FromPixel(getSize().height() - line.p1().y(), varInsunits), 0);
803  lineEnt->secPoint = DRW_Coord(FromPixel(line.p2().x(), varInsunits),
804  FromPixel(getSize().height() - line.p2().y(), varInsunits), 0);
805  lineEnt->layer = layer.toStdString();
806 
807  return lineEnt;
808 }
809 
810 //---------------------------------------------------------------------------------------------------------------------
811 DRW_Entity *VDxfEngine::AAMAText(const QPointF &pos, const QString &text, const QString &layer)
812 {
813  DRW_Text *textLine = new DRW_Text();
814 
815  textLine->basePoint = DRW_Coord(FromPixel(pos.x(), varInsunits),
816  FromPixel(getSize().height() - pos.y(), varInsunits), 0);
817  textLine->secPoint = DRW_Coord(FromPixel(pos.x(), varInsunits),
818  FromPixel(getSize().height() - pos.y(), varInsunits), 0);
819  textLine->height = AAMATextHeight;
820  textLine->layer = layer.toStdString();
821  textLine->text = text.toStdString();
822 
823  return textLine;
824 }
825 
826 //---------------------------------------------------------------------------------------------------------------------
827 template<class P, class V>
828 P *VDxfEngine::CreateAAMAPolygon(const QVector<QPointF> &polygon, const QString &layer, bool forceClosed)
829 {
830  P *poly = new P();
831  poly->layer = layer.toStdString();
832 
833  if (forceClosed)
834  {
835  poly->flags |= 0x1; // closed
836  }
837  else
838  {
839  if (polygon.size() > 1 && polygon.first() == polygon.last())
840  {
841  poly->flags |= 0x1; // closed
842  }
843  }
844 
845  for (int i=0; i < polygon.count(); ++i)
846  {
847  poly->addVertex(V(FromPixel(polygon.at(i).x(), varInsunits),
848  FromPixel(getSize().height() - polygon.at(i).y(), varInsunits)));
849  }
850 
851  return poly;
852 }
bool IsSeamAllowanceBuiltIn() const
bool IsSeamAllowance() const
bool isHideSeamLine() const
QString GetName() const
double resolution
Definition: vdxfengine.h:98
void setMeasurement(const VarMeasurement &var)
Definition: vdxfengine.cpp:558
virtual bool begin(QPaintDevice *pdev) Q_DECL_OVERRIDE
Definition: vdxfengine.cpp:96
QSharedPointer< dx_iface > input
Definition: vdxfengine.h:103
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) Q_DECL_OVERRIDE
Definition: vdxfengine.cpp:396
virtual void drawLines(const QLineF *lines, int lineCount) Q_DECL_OVERRIDE
Definition: vdxfengine.cpp:203
double getResolution() const
Definition: vdxfengine.cpp:417
std::string getPenStyle()
Definition: vdxfengine.cpp:468
int getPenColor()
Definition: vdxfengine.cpp:487
QString getFileName() const
Definition: vdxfengine.cpp:430
QString fileName
Definition: vdxfengine.h:99
void ExportAAMAOutline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
Definition: vdxfengine.cpp:660
bool m_binary
Definition: vdxfengine.h:101
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem) Q_DECL_OVERRIDE
Definition: vdxfengine.cpp:344
Q_REQUIRED_RESULT DRW_Entity * AAMAText(const QPointF &pos, const QString &text, const QString &layer)
Definition: vdxfengine.cpp:811
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) Q_DECL_OVERRIDE
Definition: vdxfengine.cpp:231
void ExportAAMAIntcut(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
Definition: vdxfengine.cpp:694
DRW::Version m_version
Definition: vdxfengine.h:100
virtual void drawEllipse(const QRectF &rect) Q_DECL_OVERRIDE
Definition: vdxfengine.cpp:297
void ExportAAMAGlobalText(const QSharedPointer< dx_iface > &input, const QVector< VLayoutPiece > &details)
Definition: vdxfengine.cpp:762
Q_REQUIRED_RESULT double FromPixel(double pix, const VarInsunits &unit) const
Definition: vdxfengine.cpp:575
bool ExportToAAMA(const QVector< VLayoutPiece > &details)
Definition: vdxfengine.cpp:607
bool IsBinaryFormat() const
Definition: vdxfengine.cpp:462
void SetBinaryFormat(bool binary)
Definition: vdxfengine.cpp:456
VarMeasurement varMeasurement
Definition: vdxfengine.h:104
void setSize(const QSize &value)
Definition: vdxfengine.cpp:410
QSize size
Definition: vdxfengine.h:97
virtual bool end() Q_DECL_OVERRIDE
Definition: vdxfengine.cpp:119
void ExportAAMAGrainline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
Definition: vdxfengine.cpp:735
QSize getSize() const
Definition: vdxfengine.cpp:404
QTransform transform
Definition: vdxfengine.h:102
DRW_Text * textBuffer
Definition: vdxfengine.h:106
void ExportAAMANotch(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
Definition: vdxfengine.cpp:718
Q_REQUIRED_RESULT DRW_Entity * AAMAPolygon(const QVector< QPointF > &polygon, const QString &layer, bool forceClosed)
Definition: vdxfengine.cpp:780
virtual ~VDxfEngine()
Definition: vdxfengine.cpp:90
DRW::Version GetVersion() const
Definition: vdxfengine.cpp:443
void setResolution(double value)
Definition: vdxfengine.cpp:423
void ExportAAMADraw(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
Definition: vdxfengine.cpp:680
virtual void drawPath(const QPainterPath &path) Q_DECL_OVERRIDE
Definition: vdxfengine.cpp:142
Q_REQUIRED_RESULT double ToPixel(double val, const VarInsunits &unit) const
Definition: vdxfengine.cpp:590
Q_REQUIRED_RESULT P * CreateAAMAPolygon(const QVector< QPointF > &polygon, const QString &layer, bool forceClosed)
virtual void updateState(const QPaintEngineState &state) Q_DECL_OVERRIDE
Definition: vdxfengine.cpp:127
void ExportAAMAText(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
Definition: vdxfengine.cpp:749
void setInsunits(const VarInsunits &var)
Definition: vdxfengine.cpp:565
void SetVersion(DRW::Version version)
Definition: vdxfengine.cpp:449
void setFileName(const QString &value)
Definition: vdxfengine.cpp:436
virtual Type type() const Q_DECL_OVERRIDE
Definition: vdxfengine.cpp:389
VarInsunits varInsunits
Definition: vdxfengine.h:105
Q_REQUIRED_RESULT DRW_Entity * AAMALine(const QLineF &line, const QString &layer)
Definition: vdxfengine.cpp:798
QStringList GetPieceText() const
QVector< QPointF > getContourPoints() const
QVector< QLineF > getNotches() const
QVector< QVector< QPointF > > InternalPathsForCut(bool cut) const
QVector< QPointF > GetSeamAllowancePoints() const
QPointF GetPieceTextPosition() const
QVector< QPointF > getGrainline() const
std::list< DRW_Entity * > ent
Definition: dxiface.h:53
const qreal PrintDPI
Definition: def.cpp:228
double FromPixel(double pix, const Unit &unit)
Definition: def.cpp:250
const QString endStringPlaceholder
Definition: dxfdef.cpp:56
VarMeasurement
Definition: dxfdef.h:61
VarInsunits
Definition: dxfdef.h:64
static const qreal AAMATextHeight
Definition: vdxfengine.cpp:54
static QPaintEngine::PaintEngineFeatures svgEngineFeatures()
Definition: vdxfengine.cpp:57