2015-09-07 21:47:02 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vdxfengine.cpp
|
|
|
|
** @author Valentina Zhuravska <zhuravska19(at)gmail.com>
|
|
|
|
** @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
|
|
|
|
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vdxfengine.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QColor>
|
2015-09-07 21:47:02 +02:00
|
|
|
#include <QDateTime>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QFlag>
|
|
|
|
#include <QFlags>
|
|
|
|
#include <QFont>
|
|
|
|
#include <QLineF>
|
|
|
|
#include <QList>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QPaintEngineState>
|
|
|
|
#include <QPainterPath>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPolygonF>
|
|
|
|
#include <QTextItem>
|
|
|
|
#include <Qt>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
|
|
|
#include "../vmisc/def.h"
|
|
|
|
#include "../vmisc/diagnostic.h"
|
2016-08-16 18:57:32 +02:00
|
|
|
#include "../vmisc/vmath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "dxflib/dl_attributes.h"
|
|
|
|
#include "dxflib/dl_codes.h"
|
|
|
|
#include "dxflib/dl_dxf.h"
|
|
|
|
#include "dxflib/dl_entities.h"
|
|
|
|
#include "dxflib/dl_writer_ascii.h"
|
|
|
|
|
2015-09-07 21:47:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
static inline QPaintEngine::PaintEngineFeatures svgEngineFeatures()
|
|
|
|
{
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wsign-conversion")
|
|
|
|
QT_WARNING_DISABLE_INTEL(68)
|
2015-09-07 21:47:02 +02:00
|
|
|
|
|
|
|
return QPaintEngine::PaintEngineFeatures(
|
|
|
|
QPaintEngine::AllFeatures
|
|
|
|
& ~QPaintEngine::PatternBrush
|
|
|
|
& ~QPaintEngine::PerspectiveTransform
|
|
|
|
& ~QPaintEngine::ConicalGradientFill
|
|
|
|
& ~QPaintEngine::PorterDuff);
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VDxfEngine::VDxfEngine()
|
|
|
|
:QPaintEngine(svgEngineFeatures()),
|
2015-10-02 07:37:31 +02:00
|
|
|
size(),
|
|
|
|
resolution(static_cast<int>(PrintDPI)),
|
|
|
|
fileName(),
|
|
|
|
matrix(),
|
|
|
|
dxf(nullptr),
|
|
|
|
dw(nullptr),
|
|
|
|
varMeasurement(VarMeasurement::Metric),
|
|
|
|
varInsunits(VarInsunits::Centimeters)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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);
|
|
|
|
|
2016-02-09 16:19:07 +01:00
|
|
|
if (dw==nullptr)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
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<int>(varMeasurement));
|
|
|
|
|
|
|
|
dw->dxfString(9, "$INSUNITS");
|
|
|
|
dw->dxfInt(70, static_cast<int>(varInsunits));
|
|
|
|
|
2016-03-27 18:00:08 +02:00
|
|
|
dw->dxfString(9, "$DIMSCALE");
|
|
|
|
dw->dxfReal(40, 1.0);
|
|
|
|
|
|
|
|
// Official documentation says that initial value is 1.0, however LibreCAD has trouble if not set this value
|
|
|
|
// explicitly.
|
|
|
|
dw->dxfString(9, "$DIMLFAC");
|
|
|
|
dw->dxfReal(40, 1.0);
|
|
|
|
|
2015-09-07 21:47:02 +02:00
|
|
|
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);
|
2016-02-09 16:19:07 +01:00
|
|
|
|
|
|
|
dw->tableLinetypes(25);
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("BYBLOCK", "BYBLOCK", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("BYLAYER", "BYLAYER", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("CONTINUOUS", "Continuous", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("ACAD_ISO02W100", "ACAD_ISO02W100", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("ACAD_ISO03W100", "ACAD_ISO03W100", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("ACAD_ISO04W100", "ACAD_ISO04W100", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("ACAD_ISO05W100", "ACAD_ISO05W100", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("BORDER", "BORDER", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("BORDER2", "BORDER2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("BORDERX2", "BORDERX2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("CENTER", "CENTER", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("CENTER2", "CENTER2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("CENTERX2", "CENTERX2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DASHDOT", "DASHDOT", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DASHDOT2", "DASHDOT2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DASHDOTX2", "DASHDOTX2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DASHED", "DASHED", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DASHED2", "DASHED2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DASHEDX2", "DASHEDX2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DIVIDE", "DIVIDE", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DIVIDE2", "DIVIDE2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DIVIDEX2", "DIVIDEX2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DOT", "DOT", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DOT2", "DOT2", 0, 0, 0.0));
|
|
|
|
dxf->writeLinetype(*dw, DL_LinetypeData("DOTX2", "DOTX2", 0, 0, 0.0));
|
2015-09-07 21:47:02 +02:00
|
|
|
dw->tableEnd();
|
2016-02-09 16:19:07 +01:00
|
|
|
|
2015-09-07 21:47:02 +02:00
|
|
|
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
|
2016-02-09 16:19:07 +01:00
|
|
|
|
|
|
|
dw->tableEnd();
|
|
|
|
|
|
|
|
dw->tableStyle(1);
|
|
|
|
DL_StyleData style("Standard", 0, 0.0, 1.0, 0.0, 0, 2.5, "txt", "");
|
|
|
|
style.bold = false;
|
|
|
|
style.italic = false;
|
|
|
|
dxf->writeStyle(*dw, style);
|
|
|
|
dw->tableEnd();
|
|
|
|
|
|
|
|
dxf->writeView(*dw);
|
|
|
|
dxf->writeUcs(*dw);
|
|
|
|
dw->tableAppid(1);
|
|
|
|
dw->tableAppidEntry(0x12);
|
|
|
|
dw->dxfString(2, "ACAD");
|
|
|
|
dw->dxfInt(70, 0);
|
|
|
|
dw->tableEnd();
|
|
|
|
|
|
|
|
dxf->writeDimStyle(*dw, 1, 1, 1, 1, 1);
|
|
|
|
|
|
|
|
dxf->writeBlockRecord(*dw);
|
|
|
|
dxf->writeBlockRecord(*dw, "layout");
|
2015-09-07 21:47:02 +02:00
|
|
|
dw->tableEnd();
|
2016-02-09 16:19:07 +01:00
|
|
|
|
|
|
|
dw->sectionEnd();
|
|
|
|
|
|
|
|
dw->sectionBlocks();
|
|
|
|
dxf->writeBlock(*dw, DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
|
|
|
|
dxf->writeEndBlock(*dw, "*Model_Space");
|
|
|
|
dxf->writeBlock(*dw, DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0));
|
|
|
|
dxf->writeEndBlock(*dw, "*Paper_Space");
|
|
|
|
dxf->writeBlock(*dw, DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0));
|
|
|
|
dxf->writeEndBlock(*dw, "*Paper_Space0");
|
|
|
|
|
|
|
|
dxf->writeBlock(*dw, DL_BlockData("layout", 0, 0.0, 0.0, 0.0));
|
|
|
|
// ...
|
|
|
|
// write block entities e.g. with dxf->writeLine(), ..
|
|
|
|
// ...
|
|
|
|
dxf->writeEndBlock(*dw, "layout");
|
|
|
|
|
2015-09-07 21:47:02 +02:00
|
|
|
dw->sectionEnd();
|
|
|
|
|
|
|
|
dw->sectionEntities();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VDxfEngine::end()
|
|
|
|
{
|
|
|
|
dw->sectionEnd();
|
2016-02-09 16:19:07 +01:00
|
|
|
dxf->writeObjects(*dw);
|
|
|
|
dxf->writeObjectsEnd(*dw);
|
2015-09-07 21:47:02 +02:00
|
|
|
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)
|
|
|
|
{
|
2016-02-09 16:19:07 +01:00
|
|
|
const QList<QPolygonF> subpaths = path.toSubpathPolygons(matrix);
|
2015-09-07 21:47:02 +02:00
|
|
|
|
2016-02-09 16:19:07 +01:00
|
|
|
for (int j=0; j < subpaths.size(); ++j)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2016-02-09 16:19:07 +01:00
|
|
|
const QPolygonF polygon = subpaths.at(j);
|
2016-02-10 18:32:26 +01:00
|
|
|
if (polygon.isEmpty())
|
2016-02-09 16:19:07 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-10 18:32:26 +01:00
|
|
|
dxf->writePolyline(*dw,
|
|
|
|
DL_PolylineData(polygon.size(), 0, 0, 0),
|
|
|
|
DL_Attributes("0", getPenColor(), -1, getPenStyle(), 1.0));
|
|
|
|
|
|
|
|
for (int i=0; i < polygon.count(); ++i)
|
2016-02-09 16:19:07 +01:00
|
|
|
{
|
2016-03-27 18:35:55 +02:00
|
|
|
dxf->writeVertex(*dw,
|
|
|
|
DL_VertexData(FromPixel(polygon.at(i).x(), varInsunits),
|
2016-03-27 18:00:08 +02:00
|
|
|
FromPixel(getSize().height() - polygon.at(i).y(), varInsunits), 0, 0));
|
2016-02-09 16:19:07 +01:00
|
|
|
}
|
2016-02-10 18:32:26 +01:00
|
|
|
|
|
|
|
dxf->writePolylineEnd(*dw);
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::drawLines(const QLineF * lines, int lineCount)
|
|
|
|
{
|
2016-02-10 18:32:26 +01:00
|
|
|
for (int i = 0; i < lineCount; ++i)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2016-03-27 18:00:08 +02:00
|
|
|
const QPointF p1 = matrix.map(lines[i].p1());
|
|
|
|
const QPointF p2 = matrix.map(lines[i].p2());
|
|
|
|
|
|
|
|
dxf->writeLine(*dw,
|
|
|
|
DL_LineData(FromPixel(p1.x(), varInsunits), // start point
|
|
|
|
FromPixel(getSize().height() - p1.y(), varInsunits),
|
|
|
|
FromPixel(0.0, varInsunits),
|
|
|
|
FromPixel(p2.x(), varInsunits), // end point
|
|
|
|
FromPixel(getSize().height() - p2.y(), varInsunits),
|
|
|
|
FromPixel(0.0, varInsunits)),
|
|
|
|
DL_Attributes("0", getPenColor(), -1, getPenStyle(), 1.0));
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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)
|
|
|
|
|
2016-02-10 18:32:26 +01:00
|
|
|
if (pointCount <= 0)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2016-02-10 18:32:26 +01:00
|
|
|
return;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2016-02-10 18:32:26 +01:00
|
|
|
|
|
|
|
dxf->writePolyline(*dw,
|
|
|
|
DL_PolylineData(pointCount, 0, 0, 0),
|
|
|
|
DL_Attributes("0", getPenColor(), -1, getPenStyle(), 1.0));
|
|
|
|
|
|
|
|
for (int i = 0; i < pointCount; ++i)
|
|
|
|
{
|
2016-03-27 18:00:08 +02:00
|
|
|
const QPointF p = matrix.map(points[i]);
|
2016-03-27 18:35:55 +02:00
|
|
|
dxf->writeVertex(*dw,
|
|
|
|
DL_VertexData(FromPixel(p.x(), varInsunits),
|
2016-03-27 18:00:08 +02:00
|
|
|
FromPixel(getSize().height() - p.y(), varInsunits), 0, 0));
|
2016-02-10 18:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dxf->writePolylineEnd(*dw);
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::drawPolygon(const QPoint *points, int pointCount, QPaintEngine::PolygonDrawMode mode)
|
|
|
|
{
|
|
|
|
QPaintEngine::drawPolygon(points, pointCount, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::drawEllipse(const QRectF & rect)
|
|
|
|
{
|
2016-03-27 18:00:08 +02:00
|
|
|
const QRectF newRect = matrix.mapRect(rect);
|
|
|
|
const double rotationAngle = atan(matrix.m12()/matrix.m11());
|
2015-09-07 21:47:02 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2016-03-27 18:00:08 +02:00
|
|
|
|
|
|
|
dxf->writeEllipse(*dw,
|
|
|
|
DL_EllipseData(FromPixel(newRect.center().x(), varInsunits), // center X
|
|
|
|
FromPixel(getSize().height() - newRect.center().y(), varInsunits), // center Y
|
|
|
|
FromPixel(0, varInsunits), // center Z
|
|
|
|
FromPixel(majorX, varInsunits),
|
|
|
|
FromPixel(majorY, varInsunits),
|
|
|
|
FromPixel(0, varInsunits),
|
2016-03-27 18:35:55 +02:00
|
|
|
FromPixel(ratio, varInsunits),
|
2016-03-27 18:00:08 +02:00
|
|
|
0, 6.28 // startangle and endangle of ellipse in rad
|
|
|
|
),
|
|
|
|
DL_Attributes("0", getPenColor(), -1, getPenStyle(), 1.0));
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::drawEllipse(const QRect & rect)
|
|
|
|
{
|
|
|
|
QPaintEngine::drawEllipse(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::drawTextItem(const QPointF & p, const QTextItem & textItem)
|
|
|
|
{
|
2016-03-27 18:00:08 +02:00
|
|
|
const QPointF startPoint = matrix.map(p);
|
|
|
|
const double rotationAngle = atan(matrix.m12()/matrix.m11());
|
2015-09-07 21:47:02 +02:00
|
|
|
|
2015-10-28 15:22:36 +01:00
|
|
|
const QFont f = textItem.font();
|
2016-03-27 18:00:08 +02:00
|
|
|
const int textSize = f.pixelSize() == -1 ? f.pointSize() : f.pixelSize();
|
|
|
|
dxf->writeText(*dw,
|
|
|
|
DL_TextData(FromPixel(startPoint.x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - startPoint.y(), varInsunits),
|
|
|
|
FromPixel(0, varInsunits),
|
|
|
|
FromPixel(startPoint.x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - startPoint.y(), varInsunits),
|
|
|
|
FromPixel(0, varInsunits),
|
|
|
|
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
|
|
|
|
f.family().toUtf8().constData(), // font
|
|
|
|
-rotationAngle
|
|
|
|
),
|
|
|
|
DL_Attributes("0", getPenColor(), -1, getPenStyle(), 1.0));
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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)
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT(not isActive());
|
2015-09-07 21:47:02 +02:00
|
|
|
size = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-27 18:00:08 +02:00
|
|
|
double VDxfEngine::getResolution() const
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
return resolution;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-27 18:00:08 +02:00
|
|
|
void VDxfEngine::setResolution(double value)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT(not isActive());
|
2015-09-07 21:47:02 +02:00
|
|
|
resolution = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VDxfEngine::getFileName() const
|
|
|
|
{
|
|
|
|
return fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::setFileName(const QString &value)
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT(not isActive());
|
2015-09-07 21:47:02 +02:00
|
|
|
fileName = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
std::string VDxfEngine::getPenStyle()
|
|
|
|
{
|
|
|
|
switch (state->pen().style())
|
|
|
|
{
|
|
|
|
case Qt::DashLine:
|
|
|
|
return "DASHED";
|
|
|
|
case Qt::DotLine:
|
|
|
|
return "DOT";
|
|
|
|
case Qt::DashDotLine:
|
|
|
|
return "DASHDOT";
|
|
|
|
case Qt::DashDotDotLine:
|
|
|
|
return "DIVIDE";
|
2016-12-21 20:35:07 +01:00
|
|
|
case Qt::SolidLine:
|
2015-09-07 21:47:02 +02:00
|
|
|
default:
|
|
|
|
return "BYLAYER";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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)
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT(not isActive());
|
2015-09-07 21:47:02 +02:00
|
|
|
varMeasurement = var;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::setInsunits(const VarInsunits &var)
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT(not isActive());
|
2015-09-07 21:47:02 +02:00
|
|
|
varInsunits = var;
|
|
|
|
}
|
2016-03-27 18:00:08 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wswitch-default")
|
2016-03-27 18:00:08 +02:00
|
|
|
|
|
|
|
double VDxfEngine::FromPixel(double pix, const VarInsunits &unit) const
|
|
|
|
{
|
|
|
|
switch (unit)
|
|
|
|
{
|
|
|
|
case VarInsunits::Millimeters:
|
|
|
|
return pix / resolution * 25.4;
|
|
|
|
case VarInsunits::Centimeters:
|
|
|
|
return pix / resolution * 25.4 / 10.0;
|
|
|
|
case VarInsunits::Inches:
|
|
|
|
return pix / resolution;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|