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"
|
2017-06-21 11:34:20 +02:00
|
|
|
#include "dxiface.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
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(),
|
2017-06-21 11:34:20 +02:00
|
|
|
m_version(DRW::AC1014),
|
2015-10-02 07:37:31 +02:00
|
|
|
matrix(),
|
2017-06-21 11:34:20 +02:00
|
|
|
input(),
|
2015-10-02 07:37:31 +02:00
|
|
|
varMeasurement(VarMeasurement::Metric),
|
|
|
|
varInsunits(VarInsunits::Centimeters)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-09-07 21:47:02 +02:00
|
|
|
bool VDxfEngine::begin(QPaintDevice *pdev)
|
|
|
|
{
|
|
|
|
Q_UNUSED(pdev)
|
|
|
|
if (size.isValid() == false)
|
|
|
|
{
|
|
|
|
qWarning()<<"VDxfEngine::begin(), size is not valid";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
input = QSharedPointer<dx_iface>(new dx_iface(fileName.toStdString(), varMeasurement, varInsunits));
|
2015-09-07 21:47:02 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-09-07 21:47:02 +02:00
|
|
|
bool VDxfEngine::end()
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
const bool res = input->fileExport(m_version, false);
|
|
|
|
return res;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
// cppcheck-suppress unusedFunction
|
2015-09-07 21:47:02 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-09-07 21:47:02 +02:00
|
|
|
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
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
continue;
|
2016-02-09 16:19:07 +01:00
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
if (m_version > DRW::AC1009)
|
|
|
|
{ // Use lwpolyline
|
|
|
|
DRW_LWPolyline *poly = new DRW_LWPolyline();
|
|
|
|
poly->layer = "0";
|
|
|
|
poly->color = getPenColor();
|
|
|
|
poly->lWeight = DRW_LW_Conv::widthByLayer;
|
|
|
|
poly->lineType = getPenStyle();
|
2017-06-26 12:00:59 +02:00
|
|
|
|
2017-06-23 21:11:25 +02:00
|
|
|
if (polygon.size() > 1 && polygon.first() == polygon.last())
|
|
|
|
{
|
2017-06-26 12:00:59 +02:00
|
|
|
poly->flags |= 0x1; // closed
|
2017-06-23 21:11:25 +02:00
|
|
|
}
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2017-06-26 12:00:59 +02:00
|
|
|
poly->flags |= 0x80; // plinegen
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
for (int i=0; i < polygon.count(); ++i)
|
|
|
|
{
|
|
|
|
poly->addVertex(DRW_Vertex2D(FromPixel(polygon.at(i).x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - polygon.at(i).y(), varInsunits), 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
input->AddEntity(poly);
|
2016-02-09 16:19:07 +01:00
|
|
|
}
|
2017-06-21 11:34:20 +02:00
|
|
|
else
|
|
|
|
{ // Use polyline
|
|
|
|
DRW_Polyline *poly = new DRW_Polyline();
|
|
|
|
poly->layer = "0";
|
|
|
|
poly->color = getPenColor();
|
|
|
|
poly->lWeight = DRW_LW_Conv::widthByLayer;
|
|
|
|
poly->lineType = getPenStyle();
|
2017-06-23 21:11:25 +02:00
|
|
|
if (polygon.size() > 1 && polygon.first() == polygon.last())
|
|
|
|
{
|
2017-06-26 12:00:59 +02:00
|
|
|
poly->flags |= 0x1; // closed
|
2017-06-23 21:11:25 +02:00
|
|
|
}
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2017-06-26 12:00:59 +02:00
|
|
|
poly->flags |= 0x80; // plinegen
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
for (int i=0; i < polygon.count(); ++i)
|
|
|
|
{
|
|
|
|
poly->addVertex(DRW_Vertex(FromPixel(polygon.at(i).x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - polygon.at(i).y(), varInsunits), 0, 0));
|
|
|
|
}
|
2016-02-10 18:32:26 +01:00
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
input->AddEntity(poly);
|
|
|
|
}
|
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());
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
DRW_Line *line = new DRW_Line();
|
|
|
|
line->basePoint = DRW_Coord(FromPixel(p1.x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - p1.y(), varInsunits), 0);
|
|
|
|
line->secPoint = DRW_Coord(FromPixel(p2.x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - p2.y(), varInsunits), 0);
|
|
|
|
line->layer = "0";
|
|
|
|
line->color = getPenColor();
|
|
|
|
line->lWeight = DRW_LW_Conv::widthByLayer;
|
|
|
|
line->lineType = getPenStyle();
|
|
|
|
|
|
|
|
input->AddEntity(line);
|
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
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
if (m_version > DRW::AC1009)
|
|
|
|
{ // Use lwpolyline
|
|
|
|
DRW_LWPolyline *poly = new DRW_LWPolyline();
|
|
|
|
poly->layer = "0";
|
|
|
|
poly->color = getPenColor();
|
|
|
|
poly->lWeight = DRW_LW_Conv::widthByLayer;
|
|
|
|
poly->lineType = getPenStyle();
|
2016-02-10 18:32:26 +01:00
|
|
|
|
2017-06-26 12:00:59 +02:00
|
|
|
if (pointCount > 1 && points[0] == points[pointCount])
|
|
|
|
{
|
|
|
|
poly->flags |= 0x1; // closed
|
|
|
|
}
|
|
|
|
|
|
|
|
poly->flags |= 0x80; // plinegen
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
for (int i = 0; i < pointCount; ++i)
|
|
|
|
{
|
|
|
|
const QPointF p = matrix.map(points[i]);
|
|
|
|
poly->addVertex(DRW_Vertex2D(FromPixel(p.x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - p.y(), varInsunits), 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
input->AddEntity(poly);
|
2016-02-10 18:32:26 +01:00
|
|
|
}
|
2017-06-21 11:34:20 +02:00
|
|
|
else
|
|
|
|
{ // Use polyline
|
|
|
|
DRW_Polyline *poly = new DRW_Polyline();
|
|
|
|
poly->layer = "0";
|
|
|
|
poly->color = getPenColor();
|
|
|
|
poly->lWeight = DRW_LW_Conv::widthByLayer;
|
|
|
|
poly->lineType = getPenStyle();
|
|
|
|
|
2017-06-26 12:00:59 +02:00
|
|
|
if (pointCount > 1 && points[0] == points[pointCount])
|
|
|
|
{
|
|
|
|
poly->flags |= 0x1; // closed
|
|
|
|
}
|
|
|
|
|
|
|
|
poly->flags |= 0x80; // plinegen
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
for (int i = 0; i < pointCount; ++i)
|
|
|
|
{
|
|
|
|
const QPointF p = matrix.map(points[i]);
|
|
|
|
poly->addVertex(DRW_Vertex(FromPixel(p.x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - p.y(), varInsunits), 0, 0));
|
|
|
|
}
|
2016-02-10 18:32:26 +01:00
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
input->AddEntity(poly);
|
|
|
|
}
|
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
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
DRW_Ellipse *ellipse = new DRW_Ellipse();
|
|
|
|
ellipse->basePoint = DRW_Coord(FromPixel(newRect.center().x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - newRect.center().y(), varInsunits), 0);
|
|
|
|
ellipse->secPoint = DRW_Coord(FromPixel(majorX, varInsunits), FromPixel(majorY, varInsunits), 0);
|
|
|
|
ellipse->ratio = ratio;
|
|
|
|
ellipse->staparam = 0;
|
|
|
|
ellipse->endparam = 2*M_PI;
|
|
|
|
|
|
|
|
ellipse->layer = "0";
|
|
|
|
ellipse->color = getPenColor();
|
|
|
|
ellipse->lWeight = DRW_LW_Conv::widthByLayer;
|
|
|
|
ellipse->lineType = getPenStyle();
|
|
|
|
|
|
|
|
input->AddEntity(ellipse);
|
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();
|
2017-06-21 11:34:20 +02:00
|
|
|
|
|
|
|
if (m_version > DRW::AC1009)
|
|
|
|
{ // Use MTEXT
|
|
|
|
DRW_MText *text = new DRW_MText();
|
|
|
|
text->basePoint = DRW_Coord(FromPixel(startPoint.x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - startPoint.y(), varInsunits), 0);
|
|
|
|
text->secPoint = DRW_Coord(FromPixel(startPoint.x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - startPoint.y(), varInsunits), 0);
|
|
|
|
text->height = textSize * matrix.m11();
|
|
|
|
text->text = textItem.text().toStdString();
|
|
|
|
text->style = f.family().toStdString();
|
|
|
|
text->angle = -rotationAngle;
|
|
|
|
|
|
|
|
text->layer = "0";
|
|
|
|
text->color = getPenColor();
|
|
|
|
text->lWeight = DRW_LW_Conv::widthByLayer;
|
|
|
|
text->lineType = getPenStyle();
|
|
|
|
|
|
|
|
input->AddEntity(text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Use TEXT
|
|
|
|
DRW_Text *text = new DRW_Text();
|
|
|
|
text->basePoint = DRW_Coord(FromPixel(startPoint.x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - startPoint.y(), varInsunits), 0);
|
|
|
|
text->secPoint = DRW_Coord(FromPixel(startPoint.x(), varInsunits),
|
|
|
|
FromPixel(getSize().height() - startPoint.y(), varInsunits), 0);
|
|
|
|
text->height = textSize * matrix.m11();
|
|
|
|
text->text = textItem.text().toStdString();
|
|
|
|
text->style = f.family().toStdString();
|
|
|
|
text->angle = -rotationAngle;
|
|
|
|
|
|
|
|
text->layer = "0";
|
|
|
|
text->color = getPenColor();
|
|
|
|
text->lWeight = DRW_LW_Conv::widthByLayer;
|
|
|
|
text->lineType = getPenStyle();
|
|
|
|
|
|
|
|
input->AddEntity(text);
|
|
|
|
}
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPaintEngine::Type VDxfEngine::type() const
|
|
|
|
{
|
|
|
|
return QPaintEngine::User;
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
// cppcheck-suppress unusedFunction
|
2015-09-07 21:47:02 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-09-07 21:47:02 +02:00
|
|
|
QString VDxfEngine::getFileName() const
|
|
|
|
{
|
|
|
|
return fileName;
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-09-07 21:47:02 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
DRW::Version VDxfEngine::GetVersion() const
|
|
|
|
{
|
|
|
|
return m_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::SetVersion(DRW::Version version)
|
|
|
|
{
|
|
|
|
Q_ASSERT(not isActive());
|
|
|
|
m_version = version;
|
|
|
|
}
|
|
|
|
|
2015-09-07 21:47:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
std::string VDxfEngine::getPenStyle()
|
|
|
|
{
|
|
|
|
switch (state->pen().style())
|
|
|
|
{
|
|
|
|
case Qt::DashLine:
|
2017-06-26 12:00:59 +02:00
|
|
|
return "DASHED";
|
2015-09-07 21:47:02 +02:00
|
|
|
case Qt::DotLine:
|
|
|
|
return "DOT";
|
|
|
|
case Qt::DashDotLine:
|
2017-06-23 21:11:25 +02:00
|
|
|
return "DASHDOT2";
|
2015-09-07 21:47:02 +02:00
|
|
|
case Qt::DashDotDotLine:
|
2017-06-23 21:11:25 +02:00
|
|
|
return "DIVIDE2";
|
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)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::black;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::white)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::white;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::darkGray)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::gray;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::gray)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_gray;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::darkMagenta)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::magenta;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::magenta)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_magenta;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::cyan)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_cyan;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::darkCyan)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::cyan;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::blue)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_blue;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::darkBlue)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::blue;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::darkGreen)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::green;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::green)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_green;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::darkRed)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::red;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::red)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_red;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else if(color == Qt::yellow)
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::yellow;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::ColorByLayer;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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
|