From 80b0f38f0d80392ca3a61b723337ffd5fd328228 Mon Sep 17 00:00:00 2001 From: val177 Date: Mon, 7 Sep 2015 22:47:02 +0300 Subject: [PATCH] Added dxf export --HG-- branch : feature --- .../valentina/dialogs/dialogsavelayout.cpp | 1 + src/app/valentina/mainwindowsnogui.cpp | 23 +- src/app/valentina/mainwindowsnogui.h | 1 + src/libs/vdxf/dxfdef.h | 37 ++ src/libs/vdxf/vdxf.pri | 9 +- src/libs/vdxf/vdxfengine.cpp | 467 ++++++++++++++++++ src/libs/vdxf/vdxfengine.h | 87 ++++ src/libs/vdxf/vdxfpaintdevice.cpp | 146 ++++++ src/libs/vdxf/vdxfpaintdevice.h | 65 +++ 9 files changed, 833 insertions(+), 3 deletions(-) create mode 100644 src/libs/vdxf/dxfdef.h create mode 100644 src/libs/vdxf/vdxfengine.cpp create mode 100644 src/libs/vdxf/vdxfengine.h create mode 100644 src/libs/vdxf/vdxfpaintdevice.cpp create mode 100644 src/libs/vdxf/vdxfpaintdevice.h diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 2a67a2463..db1522b94 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -50,6 +50,7 @@ const std::vector DialogSaveLayout::availFormats = { VFrmWithTest(tr("Wavefront OBJ (*.obj)"), ".obj"), VFrmWithTest(tr("PS files (*.ps)"), ".ps", 1), //fixme: use 1 to have exe once tested on 1st run, or any other value to test always as original do VFrmWithTest(tr("EPS files (*.eps)"), ".eps", 1), + VFrmWithTest(tr("DXF files (*.dxf)"), ".dxf"), }; diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 4ebb7bcca..7c30007ce 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -30,6 +30,7 @@ #include "core/vapplication.h" #include "../vpatterndb/vcontainer.h" #include "../vobj/vobjpaintdevice.h" +#include "../vdxf/vdxfpaintdevice.h" #include "dialogs/dialoglayoutsettings.h" #include "../vlayout/vlayoutgenerator.h" @@ -209,7 +210,7 @@ void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) scenes[i]->setBackgroundBrush( *brush ); shadows[i]->setVisible(false); paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), 0.1, Qt::NoPen)); - const QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj"; + const QStringList suffix = QStringList() << "svg" << "png" << "pdf" << "eps" << "ps" << "obj" << "dxf"; switch (suffix.indexOf(suf)) { case 0: //svg @@ -234,6 +235,9 @@ void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) ObjFile(name, i); paper->setVisible(true); break; + case 6: //dxf + DxfFile(name, i); + break; default: qDebug() << "Can't recognize file suffix." << Q_FUNC_INFO; break; @@ -675,6 +679,23 @@ void MainWindowsNoGUI::ObjFile(const QString &name, int i) const } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::DxfFile(const QString &name, int i) const +{ + QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); + if (paper) + { + VDxfPaintDevice generator; + generator.setFileName(name); + generator.setSize(paper->rect().size().toSize()); + generator.setResolution(static_cast(PrintDPI)); + QPainter painter; + painter.begin(&generator); + scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); + painter.end(); + } +} + //--------------------------------------------------------------------------------------------------------------------- QVector MainWindowsNoGUI::AllSheets() { diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index d555154a2..0a96d6563 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -112,6 +112,7 @@ private: void PsFile(const QString &name, int i)const; void PdfToPs(const QStringList ¶ms)const; void ObjFile(const QString &name, int i)const; + void DxfFile(const QString &name, int i)const; QVector AllSheets(); diff --git a/src/libs/vdxf/dxfdef.h b/src/libs/vdxf/dxfdef.h new file mode 100644 index 000000000..b92073651 --- /dev/null +++ b/src/libs/vdxf/dxfdef.h @@ -0,0 +1,37 @@ +/************************************************************************ + ** + ** @file def.h + ** @author Roman Telezhynskyi + ** @date 31 8, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef DXFDEF_H +#define DXFDEF_H + +enum class VarMeasurement : unsigned char { English=0, Metric=1 }; + +//Default drawing units for AutoCAD DesignCenter blocks: +enum class VarInsunits : unsigned char { Inches=1, Millimeters=4, Centimeters=5 }; + +#endif // DXFDEF_H diff --git a/src/libs/vdxf/vdxf.pri b/src/libs/vdxf/vdxf.pri index 95340e6e4..a92d4303a 100644 --- a/src/libs/vdxf/vdxf.pri +++ b/src/libs/vdxf/vdxf.pri @@ -4,7 +4,9 @@ SOURCES += \ $$PWD/stable.cpp \ $$PWD/dxflib/dl_dxf.cpp \ - $$PWD/dxflib/dl_writer_ascii.cpp + $$PWD/dxflib/dl_writer_ascii.cpp \ + $$PWD/vdxfengine.cpp \ + $$PWD/vdxfpaintdevice.cpp HEADERS += \ $$PWD/stable.h \ @@ -18,4 +20,7 @@ HEADERS += \ $$PWD/dxflib/dl_extrusion.h \ $$PWD/dxflib/dl_global.h \ $$PWD/dxflib/dl_writer.h \ - $$PWD/dxflib/dl_writer_ascii.h + $$PWD/dxflib/dl_writer_ascii.h \ + $$PWD/vdxfengine.h \ + $$PWD/vdxfpaintdevice.h \ + $$PWD/dxfdef.h diff --git a/src/libs/vdxf/vdxfengine.cpp b/src/libs/vdxf/vdxfengine.cpp new file mode 100644 index 000000000..23624c555 --- /dev/null +++ b/src/libs/vdxf/vdxfengine.cpp @@ -0,0 +1,467 @@ +/************************************************************************ + ** + ** @file vdxfengine.cpp + ** @author Valentina Zhuravska + ** @date 12 8, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vdxfengine.h" +#include +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +static inline QPaintEngine::PaintEngineFeatures svgEngineFeatures() +{ +#ifdef Q_CC_CLANG +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wsign-conversion" +#endif + + return QPaintEngine::PaintEngineFeatures( + QPaintEngine::AllFeatures + & ~QPaintEngine::PatternBrush + & ~QPaintEngine::PerspectiveTransform + & ~QPaintEngine::ConicalGradientFill + & ~QPaintEngine::PorterDuff); + +#ifdef Q_CC_CLANG +#pragma clang diagnostic pop +#endif +} + +//--------------------------------------------------------------------------------------------------------------------- +VDxfEngine::VDxfEngine() + :QPaintEngine(svgEngineFeatures()), + size(), resolution(PrintDPI), matrix(), varMeasurement(VarMeasurement::Metric), + varInsunits(VarInsunits::Centimeters) +{ +} + + //--------------------------------------------------------------------------------------------------------------------- +VDxfEngine::~VDxfEngine() +{ +} + + //--------------------------------------------------------------------------------------------------------------------- +bool VDxfEngine::begin(QPaintDevice *pdev) +{ + Q_UNUSED(pdev) + if (size.isValid() == false) + { + qWarning()<<"VDxfEngine::begin(), size is not valid"; + return false; + } + + dxf = new DL_Dxf(); + DL_Codes::version exportVersion = DL_Codes::AC1015; + QByteArray fileNameArray = getFileName().toLocal8Bit(); + dw = dxf->out(fileNameArray.data(), exportVersion); + + if (dw==NULL) + { + qWarning("VDxfEngine::begin(), can't open file"); + return false; + } + + dxf->writeHeader(*dw); + + dxf->writeComment(*dw, "Valentina DXF File"); + + dw->dxfString(9, "$ANGDIR"); // 1 = Clockwise angles, 0 = Counterclockwise + dw->dxfInt(70, 0); // Qt use counterclockwise + + dw->dxfString(9, "$MEASUREMENT"); // Sets drawing units: 0 = English; 1 = Metric + dw->dxfInt(70, static_cast(varMeasurement)); + + dw->dxfString(9, "$INSUNITS"); + dw->dxfInt(70, static_cast(varInsunits)); + + QString dateTime = QDateTime::currentDateTime().toString("yyyyMMdd.HHmmsszzz"); + dateTime.chop(1);// we need hundredths of a second + dw->dxfString(9, "$TDCREATE"); + dw->dxfString(40, dateTime.toUtf8().constData()); + + dw->sectionEnd(); + + dw->sectionTables(); + dxf->writeVPort(*dw); + dw->tableEnd(); + int numberOfLayers = 1; + dw->tableLayers(numberOfLayers); + + dxf->writeLayer(*dw, + DL_LayerData("0", 0), + DL_Attributes( + std::string(""), // leave empty + DL_Codes::black, // default color + 100, // default width + "CONTINUOUS", // default line style + 1.0)); // default line type scale + dw->tableEnd(); + dw->sectionEnd(); + + dw->sectionEntities(); + return true; +} + + //--------------------------------------------------------------------------------------------------------------------- +bool VDxfEngine::end() +{ + dw->sectionEnd(); + dw->dxfEOF(); + dw->close(); + delete dw; + delete dxf; + return true; +} + + //--------------------------------------------------------------------------------------------------------------------- + // cppcheck-suppress unusedFunction +void VDxfEngine::updateState(const QPaintEngineState &state) +{ + QPaintEngine::DirtyFlags flags = state.state(); + + // always stream full gstate, which is not required, but... + flags |= QPaintEngine::AllDirty; + + + if (flags & QPaintEngine::DirtyTransform) + { + matrix = state.matrix(); // Save new matrix for moving paths + } +} + + //--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::drawPath(const QPainterPath &path) +{ + QPolygonF polygon = path.toFillPolygon(matrix); + if (polygon.size() < 3) + { + return; + } + + for (int i=1; i < polygon.count(); i++) + { + dxf->writeLine( + *dw, + DL_LineData(polygon.at(i-1).x(), // start point + getSize().height() - polygon.at(i-1).y(), + 0.0, + polygon.at(i).x(), // end point + getSize().height() - polygon.at(i).y(), + 0.0), + DL_Attributes("0", getPenColor(), state->pen().width(), getPenStyle(), 1.0)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::drawLines(const QLineF * lines, int lineCount) +{ + for (int i = 0; i < lineCount; i++) + { + QPointF p1 = matrix.map(lines[i].p1()); + QPointF p2 = matrix.map(lines[i].p2()); + + dxf->writeLine( + *dw, + DL_LineData(p1.x(), // start point + getSize().height() - p1.y(), + 0.0, + p2.x(), // end point + getSize().height() - p2.y(), + 0.0), + DL_Attributes("0", getPenColor(), state->pen().width(), getPenStyle(), 1.0)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::drawLines(const QLine * lines, int lineCount) +{ + QPaintEngine::drawLines(lines, lineCount); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) +{ + Q_UNUSED(mode) + + for (int i = 1; i < pointCount; i++) + { + QPointF p1 = matrix.map(points[i-1]); + QPointF p2 = matrix.map(points[i]); + + dxf->writeLine( + *dw, + DL_LineData(p1.x(), // start point + getSize().height() - p1.y(), + 0.0, + p2.x(), // end point + getSize().height() - p2.y(), + 0.0), + DL_Attributes("0", getPenColor(), state->pen().width(), getPenStyle(), 1.0)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::drawPolygon(const QPoint *points, int pointCount, QPaintEngine::PolygonDrawMode mode) +{ + QPaintEngine::drawPolygon(points, pointCount, mode); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::drawEllipse(const QRectF & rect) +{ + QRectF newRect = matrix.mapRect(rect); + double rotationAngle = atan(matrix.m12()/matrix.m11()); + + double majorX, majorY; // distanse between center and endpoint of the major axis + double ratio; // ratio of minor axis to major axis + if(rect.width()<= rect.height()) + { + majorX = (rect.top() - rect.center().y())*sin(rotationAngle)*matrix.m11()/cos(rotationAngle); + // major axis * sin(rotation angle) * x-scale-factor + majorY = (rect.top() - rect.center().y())*matrix.m22(); + // major axis * cos(rotation angle) * y-scale-factor, where y-scale-factor = matrix.m22()/cos(rotationAngle) + ratio = rect.width()/rect.height(); + } + else + { + majorX = (rect.right() - rect.center().x())*matrix.m11(); + // major axis * cos(rotation angle) * x-scale-factor, where y-scale-factor = matrix.m22()/cos(rotationAngle) + majorY = (rect.right() - rect.center().x())*sin(rotationAngle)*matrix.m22()/cos(rotationAngle); + // major axis * sin(rotation angle) * y-scale-factor + ratio = rect.height()/rect.width(); + } + dxf->writeEllipse( + *dw, + DL_EllipseData(newRect.center().x(), // center X + getSize().height() - newRect.center().y(), // center Y + 0, // center Z + majorX, + majorY, + 0, + ratio, + 0,6.28 // startangle and endangle of ellipse in rad + ), + DL_Attributes("0", getPenColor(), state->pen().width(), getPenStyle(), 1.0)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::drawEllipse(const QRect & rect) +{ + QPaintEngine::drawEllipse(rect); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::drawTextItem(const QPointF & p, const QTextItem & textItem) +{ + QPointF startPoint = matrix.map(p); + double rotationAngle = atan(matrix.m12()/matrix.m11()); + + int textSize = textItem.font().pixelSize() == -1 ? textItem.font().pointSize() : textItem.font().pixelSize(); + dxf->writeText( + *dw, + DL_TextData(startPoint.x(), + getSize().height() - startPoint.y(), + 0, + startPoint.x(), + getSize().height() - startPoint.y(), + 0, + textSize * matrix.m11(), + 1, // relative X scale factor + 0, // flag (0 = default, 2 = Backwards, 4 = Upside down) + 0, // Horizontal justification (0 = Left (default), 1 = Center, 2 = Right,) + 0, // Vertical justification (0 = Baseline (default), 1 = Bottom, 2 = Middle, 3= Top) + textItem.text().toUtf8().constData(), // text data + textItem.font().family().toUtf8().constData(), // font + -rotationAngle + ), + DL_Attributes("0", getPenColor(), state->pen().width(), getPenStyle(), 1.0)); +} + + //--------------------------------------------------------------------------------------------------------------------- +QPaintEngine::Type VDxfEngine::type() const +{ + return QPaintEngine::User; +} + + //--------------------------------------------------------------------------------------------------------------------- + // cppcheck-suppress unusedFunction +void VDxfEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) +{ + Q_UNUSED(r) + Q_UNUSED(pm) + Q_UNUSED(sr) +} + + //--------------------------------------------------------------------------------------------------------------------- +QSize VDxfEngine::getSize() const +{ + return size; +} + + //--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::setSize(const QSize &value) +{ + Q_ASSERT(!isActive()); + size = value; +} + + //--------------------------------------------------------------------------------------------------------------------- +int VDxfEngine::getResolution() const +{ + return resolution; +} + + //--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::setResolution(int value) +{ + Q_ASSERT(!isActive()); + resolution = value; +} + + //--------------------------------------------------------------------------------------------------------------------- +QString VDxfEngine::getFileName() const +{ + return fileName; +} + + //--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::setFileName(const QString &value) +{ + Q_ASSERT(!isActive()); + fileName = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +std::string VDxfEngine::getPenStyle() +{ + switch (state->pen().style()) + { + case Qt::SolidLine: + return "BYLAYER"; + break; + case Qt::DashLine: + return "DASHED"; + break; + case Qt::DotLine: + return "DOT"; + break; + case Qt::DashDotLine: + return "DASHDOT"; + break; + case Qt::DashDotDotLine: + return "DIVIDE"; + break; + default: + return "BYLAYER"; + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int VDxfEngine::getPenColor() +{ + QColor color = state->pen().color(); + + if(color == Qt::black) + { + return DL_Codes::black; + } + else if(color == Qt::white) + { + return DL_Codes::white; + } + else if(color == Qt::darkGray) + { + return DL_Codes::gray; + } + else if(color == Qt::gray) + { + return DL_Codes::l_gray; + } + else if(color == Qt::darkMagenta) + { + return DL_Codes::magenta; + } + else if(color == Qt::magenta) + { + return DL_Codes::l_magenta; + } + else if(color == Qt::cyan) + { + return DL_Codes::l_cyan; + } + else if(color == Qt::darkCyan) + { + return DL_Codes::cyan; + } + else if(color == Qt::blue) + { + return DL_Codes::l_blue; + } + else if(color == Qt::darkBlue) + { + return DL_Codes::blue; + } + else if(color == Qt::darkGreen) + { + return DL_Codes::green; + } + else if(color == Qt::green) + { + return DL_Codes::l_green; + } + else if(color == Qt::darkRed) + { + return DL_Codes::red; + } + else if(color == Qt::red) + { + return DL_Codes::l_red; + } + else if(color == Qt::yellow) + { + return DL_Codes::yellow; + } + else + { + return DL_Codes::bylayer; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::setMeasurement(const VarMeasurement &var) +{ + Q_ASSERT(!isActive()); + varMeasurement = var; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::setInsunits(const VarInsunits &var) +{ + Q_ASSERT(!isActive()); + varInsunits = var; +} diff --git a/src/libs/vdxf/vdxfengine.h b/src/libs/vdxf/vdxfengine.h new file mode 100644 index 000000000..217fb044d --- /dev/null +++ b/src/libs/vdxf/vdxfengine.h @@ -0,0 +1,87 @@ +/************************************************************************ + ** + ** @file vdxfengine.h + ** @author Valentina Zhuravska + ** @date 12 8, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VDXFENGINE_H +#define VDXFENGINE_H + +#include +#include "dxflib/dl_dxf.h" +#include "../vmisc/def.h" +#include "dxfdef.h" + +class QTextStream; + +class VDxfEngine : public QPaintEngine +{ +public: + VDxfEngine(); + virtual ~VDxfEngine() Q_DECL_OVERRIDE; + + virtual bool begin(QPaintDevice *pdev) Q_DECL_OVERRIDE; + virtual bool end() Q_DECL_OVERRIDE; + virtual void updateState(const QPaintEngineState &state) Q_DECL_OVERRIDE; + virtual void drawPath(const QPainterPath &path) Q_DECL_OVERRIDE; + virtual void drawLines(const QLineF * lines, int lineCount) Q_DECL_OVERRIDE; + virtual void drawLines(const QLine * lines, int lineCount) Q_DECL_OVERRIDE; + virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) Q_DECL_OVERRIDE; + virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) Q_DECL_OVERRIDE; + virtual void drawEllipse(const QRectF & rect) Q_DECL_OVERRIDE; + virtual void drawEllipse(const QRect & rect) Q_DECL_OVERRIDE; + virtual void drawTextItem(const QPointF & p, const QTextItem & textItem) Q_DECL_OVERRIDE; + virtual Type type() const Q_DECL_OVERRIDE; + virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) Q_DECL_OVERRIDE; + + QSize getSize() const; + void setSize(const QSize &value); + + int getResolution() const; + void setResolution(int value); + + QString getFileName() const; + void setFileName(const QString &value); + + std::string getPenStyle(); + int getPenColor(); + + void setMeasurement(const VarMeasurement &var); + void setInsunits(const VarInsunits &var); + +private: + Q_DISABLE_COPY(VDxfEngine) + QSize size; + int resolution; + QString fileName; + QMatrix matrix; + DL_Dxf* dxf; + DL_WriterA* dw; + VarMeasurement varMeasurement; + VarInsunits varInsunits; + +}; + +#endif // VDXFENGINE_H diff --git a/src/libs/vdxf/vdxfpaintdevice.cpp b/src/libs/vdxf/vdxfpaintdevice.cpp new file mode 100644 index 000000000..c9a583451 --- /dev/null +++ b/src/libs/vdxf/vdxfpaintdevice.cpp @@ -0,0 +1,146 @@ +/************************************************************************ + ** + ** @file vdxfpaintdevice.cpp + ** @author Valentina Zhuravska + ** @date 12 812, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vdxfpaintdevice.h" +#include "vdxfengine.h" + +#include + + //--------------------------------------------------------------------------------------------------------------------- +VDxfPaintDevice::VDxfPaintDevice() + :QPaintDevice(), engine(new VDxfEngine()), fileName() +{ +} + + //--------------------------------------------------------------------------------------------------------------------- +VDxfPaintDevice::~VDxfPaintDevice() +{ + delete engine; +} + + //--------------------------------------------------------------------------------------------------------------------- + // cppcheck-suppress unusedFunction +QPaintEngine *VDxfPaintDevice::paintEngine() const +{ + return engine; +} + + //--------------------------------------------------------------------------------------------------------------------- + // cppcheck-suppress unusedFunction +QString VDxfPaintDevice::getFileName() const +{ + return fileName; +} + + //--------------------------------------------------------------------------------------------------------------------- +void VDxfPaintDevice::setFileName(const QString &value) +{ + if (engine->isActive()) + { + qWarning("VDxfPaintDevice::setFileName(), cannot set file name while Dxf is being generated"); + return; + } + + fileName = value; + engine->setFileName(fileName); +} + + //--------------------------------------------------------------------------------------------------------------------- +QSize VDxfPaintDevice::getSize() +{ + return engine->getSize(); +} + + //--------------------------------------------------------------------------------------------------------------------- +void VDxfPaintDevice::setSize(const QSize &size) +{ + if (engine->isActive()) + { + qWarning("VDxfPaintDevice::setSize(), cannot set size while Dxf is being generated"); + return; + } + engine->setSize(size); +} + + //--------------------------------------------------------------------------------------------------------------------- +int VDxfPaintDevice::getResolution() const +{ + return engine->getResolution(); +} + + //--------------------------------------------------------------------------------------------------------------------- +void VDxfPaintDevice::setResolution(int dpi) +{ + engine->setResolution(dpi); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfPaintDevice::setMeasurement(const VarMeasurement &var) +{ + engine->setMeasurement(var); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfPaintDevice::setInsunits(const VarInsunits &var) +{ + engine->setInsunits(var); +} + + //--------------------------------------------------------------------------------------------------------------------- +int VDxfPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const +{ + switch (metric) + { + case QPaintDevice::PdmDepth: + return 32; + case QPaintDevice::PdmWidth: + return engine->getSize().width(); + case QPaintDevice::PdmHeight: + return engine->getSize().height(); + case QPaintDevice::PdmDpiX: + return engine->getResolution(); + case QPaintDevice::PdmDpiY: + return engine->getResolution(); + case QPaintDevice::PdmHeightMM: + return qRound(engine->getSize().height() * 25.4 / engine->getResolution()); + case QPaintDevice::PdmWidthMM: + return qRound(engine->getSize().width() * 25.4 / engine->getResolution()); + case QPaintDevice::PdmNumColors: + return static_cast(0xffffffff); + case QPaintDevice::PdmPhysicalDpiX: + return engine->getResolution(); + case QPaintDevice::PdmPhysicalDpiY: + return engine->getResolution(); + case QPaintDevice::PdmDevicePixelRatio: + return 1; + default: + qWarning("VDxfPaintDevice::metric(), unhandled metric %d\n", metric); + break; + } + return 0; +} diff --git a/src/libs/vdxf/vdxfpaintdevice.h b/src/libs/vdxf/vdxfpaintdevice.h new file mode 100644 index 000000000..a69a35541 --- /dev/null +++ b/src/libs/vdxf/vdxfpaintdevice.h @@ -0,0 +1,65 @@ +/************************************************************************ + ** + ** @file vdxfpaintdevice.h + ** @author Valentina Zhuravska + ** @date 12 812, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VDXFPAINTDEVICE_H +#define VDXFPAINTDEVICE_H + +#include +#include +#include "dxfdef.h" + +class VDxfEngine; + +class VDxfPaintDevice : public QPaintDevice +{ +public: + VDxfPaintDevice(); + virtual ~VDxfPaintDevice() Q_DECL_OVERRIDE; + virtual QPaintEngine *paintEngine() const Q_DECL_OVERRIDE; + + QString getFileName() const; + void setFileName(const QString &value); + + QSize getSize(); + void setSize(const QSize &size); + + int getResolution() const; + void setResolution(int dpi); + + void setMeasurement(const VarMeasurement &var); + void setInsunits(const VarInsunits &var); + +protected: + virtual int metric(PaintDeviceMetric metric) const Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(VDxfPaintDevice) + VDxfEngine *engine; + QString fileName; +}; + +#endif // VDXFPAINTDEVICE_H