1 /************************************************************************ 2 ** 3 ** @file vdxfengine.h 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 Valentina project, a pattern making 10 ** program, whose allow create and modeling patterns of clothing. 11 ** Copyright (C) 2013-2015 Valentina project 12 ** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved. 13 ** 14 ** Valentina 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 ** Valentina 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 Valentina. If not, see <http://www.gnu.org/licenses/>. 26 ** 27 *************************************************************************/ 28 29 #ifndef VDXFENGINE_H 30 #define VDXFENGINE_H 31 32 #include <qcompilerdetection.h> 33 #include <QMatrix> 34 #include <QPaintEngine> 35 #include <QPointF> 36 #include <QRectF> 37 #include <QSize> 38 #include <QString> 39 #include <QtGlobal> 40 #include <string> 41 42 #include "../vmisc/def.h" 43 #include "dxfdef.h" 44 #include "libdxfrw/drw_base.h" 45 46 class QTextStream; 47 class dx_iface; 48 class DRW_Text; 49 class VLayoutPiece; 50 class DRW_Entity; 51 class dx_ifaceBlock; 52 53 class VDxfEngine : public QPaintEngine 54 { 55 friend class VDxfPaintDevice; 56 public: 57 VDxfEngine(); 58 virtual ~VDxfEngine(); 59 60 virtual bool begin(QPaintDevice *pdev) override; 61 virtual bool end() override; 62 virtual void updateState(const QPaintEngineState &state) override; 63 virtual void drawPath(const QPainterPath &path) override; 64 virtual void drawLines(const QLineF * lines, int lineCount) override; 65 virtual void drawLines(const QLine * lines, int lineCount) override; 66 virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override; 67 virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) override; 68 virtual void drawEllipse(const QRectF & rect) override; 69 virtual void drawEllipse(const QRect & rect) override; 70 virtual void drawTextItem(const QPointF & p, const QTextItem & textItem) override; 71 virtual Type type() const override; 72 virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override; 73 74 QSize getSize() const; 75 void setSize(const QSize &value); 76 77 double getResolution() const; 78 void setResolution(double value); 79 80 QString getFileName() const; 81 void setFileName(const QString &value); 82 83 DRW::Version GetVersion() const; 84 void SetVersion(DRW::Version version); 85 86 void SetBinaryFormat(bool binary); 87 bool IsBinaryFormat() const; 88 89 std::string getPenStyle(); 90 int getPenColor(); 91 92 void setMeasurement(const VarMeasurement &var); 93 void setInsunits(const VarInsunits &var); 94 95 qreal GetXScale() const; 96 void SetXScale(const qreal &xscale); 97 98 qreal GetYScale() const; 99 void SetYScale(const qreal &yscale); 100 101 QString ErrorString() const; 102 103 private: 104 Q_DISABLE_COPY(VDxfEngine) 105 QSize size; 106 double resolution; 107 QString fileName; 108 DRW::Version m_version; 109 bool m_binary; 110 QTransform matrix; 111 QSharedPointer<dx_iface> input; 112 VarMeasurement varMeasurement; 113 VarInsunits varInsunits; 114 DRW_Text *textBuffer; 115 qreal m_xscale{1}; 116 qreal m_yscale{1}; 117 118 Q_REQUIRED_RESULT double FromPixel(double pix, const VarInsunits &unit) const; 119 Q_REQUIRED_RESULT double ToPixel(double val, const VarInsunits &unit) const; 120 121 bool ExportToAAMA(const QVector<VLayoutPiece> &details); 122 void ExportAAMAOutline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 123 void ExportAAMADraw(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 124 void ExportAAMAIntcut(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 125 void ExportAAMANotch(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 126 void ExportAAMAGrainline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 127 void ExportPieceText(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 128 void ExportStyleSystemText(const QSharedPointer<dx_iface> &input, const QVector<VLayoutPiece> &details); 129 void ExportAAMADrill(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 130 131 bool ExportToASTM(const QVector<VLayoutPiece> &details); 132 void ExportASTMPieceBoundary(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 133 void ExportASTMSewLine(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 134 void ExportASTMInternalLine(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 135 void ExportASTMInternalCutout(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 136 void ExportASTMAnnotationText(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 137 void ExportASTMDrill(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 138 void ExportASTMNotch(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail); 139 140 Q_REQUIRED_RESULT DRW_Entity *AAMAPolygon(const QVector<QPointF> &polygon, const QString &layer, bool forceClosed); 141 Q_REQUIRED_RESULT DRW_Entity *AAMALine(const QLineF &line, const QString &layer); 142 Q_REQUIRED_RESULT DRW_Entity *AAMAText(const QPointF &pos, const QString &text, const QString &layer); 143 144 template<class P, class V> 145 Q_REQUIRED_RESULT P *CreateAAMAPolygon(const QVector<QPointF> &polygon, const QString &layer, bool forceClosed); 146 147 static std::string FromUnicodeToCodec(const QString &str, QTextCodec *codec); 148 std::string getFileNameForLocale() const; 149 }; 150 151 #endif // VDXFENGINE_H 152