2017-07-16 20:10:48 +02:00
|
|
|
/************************************************************************
|
2015-09-07 21:47:02 +02:00
|
|
|
**
|
|
|
|
** @file vdxfengine.cpp
|
|
|
|
** @author Valentina Zhuravska <zhuravska19(at)gmail.com>
|
|
|
|
** @date 12 8, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-09-07 21:47:02 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-09-07 21:47:02 +02:00
|
|
|
**
|
|
|
|
** 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>
|
2018-07-16 19:00:42 +02:00
|
|
|
#include <QTextCodec>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QTextItem>
|
|
|
|
#include <Qt>
|
|
|
|
#include <QtDebug>
|
2022-10-07 15:04:07 +02:00
|
|
|
#include <QtMath>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include "../vmisc/def.h"
|
2022-08-22 10:34:02 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vmisc/diagnostic.h"
|
2022-08-22 10:34:02 +02:00
|
|
|
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
|
2017-06-21 11:34:20 +02:00
|
|
|
#include "dxiface.h"
|
2017-07-16 20:10:48 +02:00
|
|
|
#include "../vlayout/vlayoutpiece.h"
|
2022-10-28 15:16:02 +02:00
|
|
|
#include "../vlayout/vlayoutpoint.h"
|
2019-07-22 16:06:30 +02:00
|
|
|
#include "../vgeometry/vgeometrydef.h"
|
2022-10-28 15:16:02 +02:00
|
|
|
#include "../vgeometry/vlayoutplacelabel.h"
|
2017-07-16 20:10:48 +02:00
|
|
|
|
|
|
|
static const qreal AAMATextHeight = 2.5;
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2020-03-15 12:35:31 +01:00
|
|
|
namespace
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer0, (UTF8STRING("0"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer1, (UTF8STRING("1"))) // NOLINT
|
2022-10-28 15:16:02 +02:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer2, (UTF8STRING("2"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer3, (UTF8STRING("3"))) // NOLINT
|
2022-10-07 15:04:07 +02:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer4, (UTF8STRING("4"))) // NOLINT
|
|
|
|
//Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer5, (UTF8STRING("5"))) // NOLINT
|
|
|
|
//Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer6, (UTF8STRING("6"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer7, (UTF8STRING("7"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer8, (UTF8STRING("8"))) // NOLINT
|
|
|
|
//Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer9, (UTF8STRING("9"))) // NOLINT
|
|
|
|
//Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer10, (UTF8STRING("10"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer11, (UTF8STRING("11"))) // NOLINT
|
|
|
|
//Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer12, (UTF8STRING("12"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer13, (UTF8STRING("13"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer14, (UTF8STRING("14"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer15, (UTF8STRING("15"))) // NOLINT
|
|
|
|
//Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer19, (UTF8STRING("19"))) // NOLINT
|
|
|
|
//Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer26, (UTF8STRING("26"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer80, (UTF8STRING("80"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer81, (UTF8STRING("81"))) // NOLINT
|
|
|
|
//Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer82, (UTF8STRING("82"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer83, (UTF8STRING("83"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer84, (UTF8STRING("84"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer85, (UTF8STRING("85"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer86, (UTF8STRING("86"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer87, (UTF8STRING("87"))) // NOLINT
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
auto PieceOutline(const VLayoutPiece &detail) -> QVector<VLayoutPoint>
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
QVector<VLayoutPoint> outline;
|
2020-03-15 12:35:31 +01:00
|
|
|
if (detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn())
|
|
|
|
{
|
|
|
|
outline = detail.GetMappedSeamAllowancePoints();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
outline = detail.GetMappedContourPoints();
|
|
|
|
}
|
|
|
|
return outline;
|
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
} // namespace
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2015-09-07 21:47:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
static inline auto svgEngineFeatures() -> QPaintEngine::PaintEngineFeatures
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
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
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
return {QPaintEngine::AllFeatures
|
2015-09-07 21:47:02 +02:00
|
|
|
& ~QPaintEngine::PatternBrush
|
|
|
|
& ~QPaintEngine::PerspectiveTransform
|
|
|
|
& ~QPaintEngine::ConicalGradientFill
|
2022-10-07 15:04:07 +02:00
|
|
|
& ~QPaintEngine::PorterDuff};
|
2015-09-07 21:47:02 +02:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VDxfEngine::VDxfEngine()
|
|
|
|
:QPaintEngine(svgEngineFeatures()),
|
2022-10-07 15:04:07 +02:00
|
|
|
m_textBuffer(new DRW_Text())
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-29 17:56:52 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VDxfEngine::~VDxfEngine()
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
delete m_textBuffer;
|
2017-06-29 17:56:52 +02:00
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::begin(QPaintDevice *pdev) -> bool
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(pdev)
|
2017-07-16 20:10:48 +02:00
|
|
|
|
|
|
|
if (isActive())
|
|
|
|
{
|
|
|
|
qWarning("VDxfEngine::begin(), the engine was alredy activated");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
if (not m_size.isValid())
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
qWarning()<<"VDxfEngine::begin(), size is not valid";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input = QSharedPointer<dx_iface>(new dx_iface(GetFileNameForLocale(), m_version, m_varMeasurement,
|
|
|
|
m_varInsunits));
|
|
|
|
m_input->AddQtLTypes();
|
|
|
|
m_input->AddDefLayers();
|
2015-09-07 21:47:02 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::end() -> bool
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
return m_input->fileExport(m_binary);
|
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)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
m_matrix = state.transform(); // Save new matrix for moving paths
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-09-07 21:47:02 +02:00
|
|
|
void VDxfEngine::drawPath(const QPainterPath &path)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
const QList<QPolygonF> subpaths = path.toSubpathPolygons(m_matrix);
|
2015-09-07 21:47:02 +02:00
|
|
|
|
2022-01-29 13:57:21 +01:00
|
|
|
for (const auto& polygon : subpaths)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
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
|
2022-01-29 13:57:21 +01:00
|
|
|
auto *poly = new DRW_LWPolyline();
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->layer = *layer0;
|
|
|
|
poly->color = GetPenColor();
|
2017-06-21 11:34:20 +02:00
|
|
|
poly->lWeight = DRW_LW_Conv::widthByLayer;
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->lineType = GetPenStyle();
|
2017-06-26 12:00:59 +02:00
|
|
|
|
2022-01-29 13:57:21 +01:00
|
|
|
if (polygon.size() > 1 && ConstFirst<QPointF>(polygon) == ConstLast<QPointF>(polygon))
|
2017-06-23 21:11:25 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->flags |= 0x1; // closed NOLINT(hicpp-signed-bitwise)
|
2017-06-23 21:11:25 +02:00
|
|
|
}
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->flags |= 0x80; // plinegen NOLINT(hicpp-signed-bitwise)
|
2017-06-26 12:00:59 +02:00
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto p : polygon)
|
2017-06-21 11:34:20 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->addVertex(DRW_Vertex2D(FromPixel(p.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - p.y(), m_varInsunits), 0));
|
2017-06-21 11:34:20 +02:00
|
|
|
}
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddEntity(poly);
|
2016-02-09 16:19:07 +01:00
|
|
|
}
|
2017-06-21 11:34:20 +02:00
|
|
|
else
|
|
|
|
{ // Use polyline
|
2022-01-29 13:57:21 +01:00
|
|
|
auto *poly = new DRW_Polyline();
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->layer = *layer0;
|
|
|
|
poly->color = GetPenColor();
|
2017-06-21 11:34:20 +02:00
|
|
|
poly->lWeight = DRW_LW_Conv::widthByLayer;
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->lineType = GetPenStyle();
|
2022-01-29 13:57:21 +01:00
|
|
|
if (polygon.size() > 1 && ConstFirst<QPointF>(polygon) == ConstLast<QPointF>(polygon))
|
2017-06-23 21:11:25 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->flags |= 0x1; // closed NOLINT(hicpp-signed-bitwise)
|
2017-06-23 21:11:25 +02:00
|
|
|
}
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->flags |= 0x80; // plinegen NOLINT(hicpp-signed-bitwise)
|
2017-06-26 12:00:59 +02:00
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto p : polygon)
|
2017-06-21 11:34:20 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->addVertex(DRW_Vertex(FromPixel(p.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - p.y(), m_varInsunits), 0, 0));
|
2017-06-21 11:34:20 +02:00
|
|
|
}
|
2016-02-10 18:32:26 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddEntity(poly);
|
2017-06-21 11:34:20 +02:00
|
|
|
}
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
void VDxfEngine::drawLines(const QLineF *lines, int lineCount)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2016-02-10 18:32:26 +01:00
|
|
|
for (int i = 0; i < lineCount; ++i)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
const QPointF p1 = m_matrix.map(lines[i].p1()); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
|
|
|
const QPointF p2 = m_matrix.map(lines[i].p2()); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
|
|
|
|
|
|
|
auto *line = new DRW_Line();
|
|
|
|
line->basePoint = DRW_Coord(FromPixel(p1.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - p1.y(), m_varInsunits), 0);
|
|
|
|
line->secPoint = DRW_Coord(FromPixel(p2.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - p2.y(), m_varInsunits), 0);
|
|
|
|
line->layer = *layer0;
|
|
|
|
line->color = GetPenColor();
|
2017-06-21 11:34:20 +02:00
|
|
|
line->lWeight = DRW_LW_Conv::widthByLayer;
|
2022-10-07 15:04:07 +02:00
|
|
|
line->lineType = GetPenStyle();
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_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
|
2022-10-07 15:04:07 +02:00
|
|
|
auto *poly = new DRW_LWPolyline();
|
|
|
|
poly->layer = *layer0;
|
|
|
|
poly->color = GetPenColor();
|
2017-06-21 11:34:20 +02:00
|
|
|
poly->lWeight = DRW_LW_Conv::widthByLayer;
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->lineType = GetPenStyle();
|
2016-02-10 18:32:26 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
if (pointCount > 1 && points[0] == points[pointCount]) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
2017-06-26 12:00:59 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->flags |= 0x1; // closed NOLINT(hicpp-signed-bitwise)
|
2017-06-26 12:00:59 +02:00
|
|
|
}
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->flags |= 0x80; // plinegen NOLINT(hicpp-signed-bitwise)
|
2017-06-26 12:00:59 +02:00
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
for (int i = 0; i < pointCount; ++i)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
const QPointF p = m_matrix.map(points[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
|
|
|
poly->addVertex(DRW_Vertex2D(FromPixel(p.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - p.y(), m_varInsunits), 0));
|
2017-06-21 11:34:20 +02:00
|
|
|
}
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddEntity(poly);
|
2016-02-10 18:32:26 +01:00
|
|
|
}
|
2017-06-21 11:34:20 +02:00
|
|
|
else
|
|
|
|
{ // Use polyline
|
2022-10-07 15:04:07 +02:00
|
|
|
auto *poly = new DRW_Polyline();
|
|
|
|
poly->layer = *layer0;
|
|
|
|
poly->color = GetPenColor();
|
2017-06-21 11:34:20 +02:00
|
|
|
poly->lWeight = DRW_LW_Conv::widthByLayer;
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->lineType = GetPenStyle();
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
if (pointCount > 1 && points[0] == points[pointCount]) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
2017-06-26 12:00:59 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->flags |= 0x1; // closed NOLINT(hicpp-signed-bitwise)
|
2017-06-26 12:00:59 +02:00
|
|
|
}
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->flags |= 0x80; // plinegen NOLINT(hicpp-signed-bitwise)
|
2017-06-26 12:00:59 +02:00
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
for (int i = 0; i < pointCount; ++i)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
const QPointF p = m_matrix.map(points[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
|
|
|
poly->addVertex(DRW_Vertex(FromPixel(p.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - p.y(), m_varInsunits), 0, 0));
|
2017-06-21 11:34:20 +02:00
|
|
|
}
|
2016-02-10 18:32:26 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddEntity(poly);
|
2017-06-21 11:34:20 +02:00
|
|
|
}
|
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)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
const QRectF newRect = m_matrix.mapRect(rect);
|
|
|
|
const double rotationAngle = atan(m_matrix.m12()/m_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())
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
majorX = (rect.top() - rect.center().y())*sin(rotationAngle)*m_matrix.m11()/cos(rotationAngle);
|
2015-09-07 21:47:02 +02:00
|
|
|
// major axis * sin(rotation angle) * x-scale-factor
|
2022-10-07 15:04:07 +02:00
|
|
|
majorY = (rect.top() - rect.center().y())*m_matrix.m22();
|
2015-09-07 21:47:02 +02:00
|
|
|
// major axis * cos(rotation angle) * y-scale-factor, where y-scale-factor = matrix.m22()/cos(rotationAngle)
|
|
|
|
ratio = rect.width()/rect.height();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
majorX = (rect.right() - rect.center().x())*m_matrix.m11();
|
2015-09-07 21:47:02 +02:00
|
|
|
// major axis * cos(rotation angle) * x-scale-factor, where y-scale-factor = matrix.m22()/cos(rotationAngle)
|
2022-10-07 15:04:07 +02:00
|
|
|
majorY = (rect.right() - rect.center().x())*sin(rotationAngle)*m_matrix.m22()/cos(rotationAngle);
|
2015-09-07 21:47:02 +02:00
|
|
|
// major axis * sin(rotation angle) * y-scale-factor
|
|
|
|
ratio = rect.height()/rect.width();
|
|
|
|
}
|
2016-03-27 18:00:08 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
auto *ellipse = new DRW_Ellipse();
|
|
|
|
ellipse->basePoint = DRW_Coord(FromPixel(newRect.center().x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - newRect.center().y(), m_varInsunits), 0);
|
|
|
|
ellipse->secPoint = DRW_Coord(FromPixel(majorX, m_varInsunits), FromPixel(majorY, m_varInsunits), 0);
|
2017-06-21 11:34:20 +02:00
|
|
|
ellipse->ratio = ratio;
|
|
|
|
ellipse->staparam = 0;
|
|
|
|
ellipse->endparam = 2*M_PI;
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
ellipse->layer = *layer0;
|
|
|
|
ellipse->color = GetPenColor();
|
2017-06-21 11:34:20 +02:00
|
|
|
ellipse->lWeight = DRW_LW_Conv::widthByLayer;
|
2022-10-07 15:04:07 +02:00
|
|
|
ellipse->lineType = GetPenStyle();
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_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)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
if (m_textBuffer->text.empty())
|
2017-06-29 17:56:52 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
const QPointF startPoint = m_matrix.map(p);
|
|
|
|
const double rotationAngle = qRadiansToDegrees(qAtan2(m_matrix.m12(), m_matrix.m11()));
|
2015-09-07 21:47:02 +02:00
|
|
|
|
2017-06-29 17:56:52 +02:00
|
|
|
const QFont f = textItem.font();
|
2022-10-07 15:04:07 +02:00
|
|
|
const UTF8STRING fontStyle = m_input->AddFont(f);
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_textBuffer->basePoint = DRW_Coord(FromPixel(startPoint.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - startPoint.y(), m_varInsunits), 0);
|
|
|
|
m_textBuffer->secPoint = DRW_Coord(FromPixel(startPoint.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - startPoint.y(), m_varInsunits), 0);
|
|
|
|
m_textBuffer->height = FromPixel(QFontMetrics(f).height(), m_varInsunits);
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_textBuffer->style = fontStyle;
|
|
|
|
m_textBuffer->angle = -rotationAngle;
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_textBuffer->layer = *layer0;
|
|
|
|
m_textBuffer->color = GetPenColor();
|
|
|
|
m_textBuffer->lWeight = DRW_LW_Conv::widthByLayer;
|
|
|
|
m_textBuffer->lineType = GetPenStyle();
|
2017-06-29 17:56:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding
|
|
|
|
* special placholder. */
|
|
|
|
QString t = textItem.text();
|
|
|
|
const bool foundEndOfString = t.contains(endStringPlaceholder);
|
|
|
|
|
|
|
|
if (foundEndOfString)
|
|
|
|
{
|
2018-03-14 15:01:24 +01:00
|
|
|
t.replace(endStringPlaceholder, QString());
|
2017-06-21 11:34:20 +02:00
|
|
|
}
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_textBuffer->text += t.toStdString();
|
2017-06-21 11:34:20 +02:00
|
|
|
|
2017-06-29 17:56:52 +02:00
|
|
|
if (foundEndOfString)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddEntity(m_textBuffer);
|
|
|
|
m_textBuffer = new DRW_Text();
|
2017-06-21 11:34:20 +02:00
|
|
|
}
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
2017-06-29 17:56:52 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::type() const -> QPaintEngine::Type
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::GetSize() const -> QSize
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
return m_size;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
void VDxfEngine::SetSize(const QSize &value)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT(not isActive());
|
2022-10-07 15:04:07 +02:00
|
|
|
m_size = value;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::GetResolution() const -> double
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
return m_resolution;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +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());
|
2022-10-07 15:04:07 +02:00
|
|
|
m_resolution = value;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::GetFileName() const -> QString
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
return m_fileName;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
void VDxfEngine::SetFileName(const QString &value)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT(not isActive());
|
2022-10-07 15:04:07 +02:00
|
|
|
m_fileName = value;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
2017-06-21 11:34:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::GetVersion() const -> DRW::Version
|
2017-06-21 11:34:20 +02:00
|
|
|
{
|
|
|
|
return m_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::SetVersion(DRW::Version version)
|
|
|
|
{
|
|
|
|
Q_ASSERT(not isActive());
|
|
|
|
m_version = version;
|
|
|
|
}
|
|
|
|
|
2017-06-26 16:28:41 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::SetBinaryFormat(bool binary)
|
|
|
|
{
|
|
|
|
m_binary = binary;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::IsBinaryFormat() const -> bool
|
2017-06-26 16:28:41 +02:00
|
|
|
{
|
|
|
|
return m_binary;
|
|
|
|
}
|
|
|
|
|
2015-09-07 21:47:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::GetPenStyle() -> std::string
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::GetPenColor() -> int
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::white)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::white;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::darkGray)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::gray;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::gray)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_gray;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::darkMagenta)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::magenta;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::magenta)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_magenta;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::cyan)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_cyan;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::darkCyan)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::cyan;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::blue)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_blue;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::darkBlue)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::blue;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::darkGreen)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::green;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::green)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_green;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::darkRed)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::red;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::red)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::l_red;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
if(color == Qt::yellow)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2017-06-21 11:34:20 +02:00
|
|
|
return DRW::yellow;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
return DRW::ColorByLayer;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
void VDxfEngine::SetMeasurement(const VarMeasurement &var)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT(not isActive());
|
2022-10-07 15:04:07 +02:00
|
|
|
m_varMeasurement = var;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
void VDxfEngine::SetInsunits(const VarInsunits &var)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_ASSERT(not isActive());
|
2022-10-07 15:04:07 +02:00
|
|
|
m_varInsunits = var;
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
2016-03-27 18:00:08 +02:00
|
|
|
|
2020-03-21 17:15:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::GetXScale() const -> qreal
|
2020-03-21 17:15:29 +01:00
|
|
|
{
|
|
|
|
return m_xscale;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::SetXScale(const qreal &xscale)
|
|
|
|
{
|
|
|
|
m_xscale = xscale;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::GetYScale() const -> qreal
|
2020-03-21 17:15:29 +01:00
|
|
|
{
|
|
|
|
return m_yscale;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::SetYScale(const qreal &yscale)
|
|
|
|
{
|
|
|
|
m_yscale = yscale;
|
|
|
|
}
|
|
|
|
|
2021-04-28 19:06:24 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::ErrorString() const -> QString
|
2021-04-28 19:06:24 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
return QString::fromStdString(m_input->ErrorString());
|
2021-04-28 19:06:24 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::FromPixel(double pix, const VarInsunits &unit) const -> double
|
2016-03-27 18:00:08 +02:00
|
|
|
{
|
|
|
|
switch (unit)
|
|
|
|
{
|
|
|
|
case VarInsunits::Millimeters:
|
2022-10-07 15:04:07 +02:00
|
|
|
return pix / m_resolution * 25.4;
|
2016-03-27 18:00:08 +02:00
|
|
|
case VarInsunits::Centimeters:
|
2022-10-07 15:04:07 +02:00
|
|
|
return pix / m_resolution * 25.4 / 10.0;
|
2016-03-27 18:00:08 +02:00
|
|
|
case VarInsunits::Inches:
|
2022-10-07 15:04:07 +02:00
|
|
|
return pix / m_resolution;
|
2016-03-27 18:00:08 +02:00
|
|
|
}
|
2017-07-16 20:10:48 +02:00
|
|
|
return pix;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::ToPixel(double val, const VarInsunits &unit) const -> double
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
switch (unit)
|
|
|
|
{
|
|
|
|
case VarInsunits::Millimeters:
|
2022-10-07 15:04:07 +02:00
|
|
|
return (val / 25.4) * m_resolution;
|
2017-07-16 20:10:48 +02:00
|
|
|
case VarInsunits::Centimeters:
|
2022-10-07 15:04:07 +02:00
|
|
|
return ((val * 10.0) / 25.4) * m_resolution;
|
2017-07-16 20:10:48 +02:00
|
|
|
case VarInsunits::Inches:
|
2022-10-07 15:04:07 +02:00
|
|
|
return val * m_resolution;
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
return val;
|
2016-03-27 18:00:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2017-07-16 20:10:48 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::ExportToAAMA(const QVector<VLayoutPiece> &details) -> bool
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
if (not m_size.isValid())
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
qWarning()<<"VDxfEngine::begin(), size is not valid";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
m_input = QSharedPointer<dx_iface>::create(GetFileNameForLocale(), m_version, m_varMeasurement, m_varInsunits);
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddAAMAHeaderData();
|
2017-07-17 16:19:49 +02:00
|
|
|
if (m_version > DRW::AC1009)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddDefLayers();
|
2017-07-17 16:19:49 +02:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddAAMALayers();
|
2017-07-16 20:10:48 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
ExportStyleSystemText(m_input, details);
|
2017-07-16 20:10:48 +02:00
|
|
|
|
2020-03-21 17:15:29 +01:00
|
|
|
for(auto detail : details)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
auto detailBlock = QSharedPointer<dx_ifaceBlock>::create();
|
2017-07-17 16:43:10 +02:00
|
|
|
|
|
|
|
QString blockName = detail.GetName();
|
|
|
|
if (m_version <= DRW::AC1009)
|
|
|
|
{
|
|
|
|
blockName.replace(' ', '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
detailBlock->name = blockName.toStdString();
|
2022-10-07 15:04:07 +02:00
|
|
|
detailBlock->layer = *layer1;
|
2017-07-16 20:10:48 +02:00
|
|
|
|
2020-03-21 17:15:29 +01:00
|
|
|
detail.Scale(m_xscale, m_yscale);
|
|
|
|
|
2017-07-16 20:10:48 +02:00
|
|
|
ExportAAMAOutline(detailBlock, detail);
|
|
|
|
ExportAAMADraw(detailBlock, detail);
|
|
|
|
ExportAAMAIntcut(detailBlock, detail);
|
|
|
|
ExportAAMANotch(detailBlock, detail);
|
|
|
|
ExportAAMAGrainline(detailBlock, detail);
|
2020-03-15 12:35:31 +01:00
|
|
|
ExportPieceText(detailBlock, detail);
|
2017-10-15 11:25:20 +02:00
|
|
|
ExportAAMADrill(detailBlock, detail);
|
2017-07-16 20:10:48 +02:00
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
m_input->AddBlock(detailBlock.get());
|
2017-07-16 20:10:48 +02:00
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
QScopedPointer<DRW_Insert> insert(new DRW_Insert());
|
2017-07-17 16:43:10 +02:00
|
|
|
insert->name = blockName.toStdString();
|
2022-10-07 15:04:07 +02:00
|
|
|
insert->layer = *layer1;
|
2017-07-16 20:10:48 +02:00
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
m_input->AddEntity(insert.take());
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
return m_input->fileExport(m_binary);
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportAAMAOutline(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
QVector<VLayoutPoint> points = PieceOutline(detail);
|
|
|
|
|
|
|
|
if (DRW_Entity *e = AAMAPolygon(points, *layer1, true))
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
ExportTurnPoints(detailBlock, points);
|
|
|
|
ExportCurvePoints(detailBlock, points);
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportAAMADraw(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2021-04-19 16:28:25 +02:00
|
|
|
if (detail.IsSeamAllowance() && not detail.IsHideMainPath() && not detail.IsSeamAllowanceBuiltIn())
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
QVector<VLayoutPoint> points = detail.GetMappedContourPoints();
|
2022-10-07 15:04:07 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(detail.GetMappedContourPoints(), *layer8, true))
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
ExportTurnPoints(detailBlock, points);
|
|
|
|
ExportCurvePoints(detailBlock, points);
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
const QVector<QVector<VLayoutPoint>> drawIntLine = detail.MappedInternalPathsForCut(false);
|
|
|
|
for(const auto &intLine : drawIntLine)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(intLine, *layer8, false))
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
ExportTurnPoints(detailBlock, intLine);
|
|
|
|
ExportCurvePoints(detailBlock, intLine);
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
const QVector<VLayoutPlaceLabel> labels = detail.GetPlaceLabels();
|
2022-10-07 15:04:07 +02:00
|
|
|
for(const auto &label : labels)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
if (label.Type() != PlaceLabelType::Doubletree && label.Type() != PlaceLabelType::Button
|
|
|
|
&& label.Type() != PlaceLabelType::Circle)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
PlaceLabelImg shape = detail.MapPlaceLabelShape(VAbstractPiece::PlaceLabelShape(label));
|
|
|
|
for(const auto &points : shape)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(points, *layer8, false))
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
ExportTurnPoints(detailBlock, points);
|
|
|
|
ExportCurvePoints(detailBlock, points);
|
2017-10-15 11:25:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportAAMAIntcut(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
QVector<QVector<VLayoutPoint>> drawIntCut = detail.MappedInternalPathsForCut(true);
|
2018-04-03 10:15:58 +02:00
|
|
|
for(auto &intCut : drawIntCut)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(intCut, *layer11, false))
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
2022-10-28 15:16:02 +02:00
|
|
|
|
|
|
|
ExportTurnPoints(detailBlock, intCut);
|
|
|
|
ExportCurvePoints(detailBlock, intCut);
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportAAMANotch(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
if (detail.IsSeamAllowance())
|
|
|
|
{
|
2021-05-27 18:52:37 +02:00
|
|
|
const QVector<VLayoutPassmark> passmarks = detail.GetMappedPassmarks();
|
2022-10-07 15:04:07 +02:00
|
|
|
for(const auto &passmark : passmarks)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
for (const auto &line : passmark.lines)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
if (DRW_Entity *e = AAMALine(line, *layer4))
|
2019-05-27 13:57:36 +02:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportAAMAGrainline(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2021-05-27 18:52:37 +02:00
|
|
|
const QVector<QPointF> grainline = detail.GetMappedGrainline();
|
2017-07-16 20:10:48 +02:00
|
|
|
if (grainline.count() > 1)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
if (DRW_Entity *e = AAMALine(QLineF(ConstFirst(grainline), ConstLast(grainline)), *layer7))
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportPieceText(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
const QStringList list = detail.GetPieceText();
|
|
|
|
const QPointF startPos = detail.GetPieceTextPosition();
|
|
|
|
|
|
|
|
for (int i = 0; i < list.size(); ++i)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
QPointF pos(startPos.x(), startPos.y() - ToPixel(AAMATextHeight * m_yscale, m_varInsunits)*(list.size() - i-1));
|
|
|
|
detailBlock->ent.push_back(AAMAText(pos, list.at(i), *layer1));
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-03-15 12:35:31 +01:00
|
|
|
void VDxfEngine::ExportStyleSystemText(const QSharedPointer<dx_iface> &input, const QVector<VLayoutPiece> &details)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
for(const auto &detail : details)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
const QStringList strings = detail.GetPatternText();
|
2017-07-16 20:10:48 +02:00
|
|
|
if (not strings.isEmpty())
|
|
|
|
{
|
|
|
|
for (int j = 0; j < strings.size(); ++j)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
QPointF pos(0, GetSize().height() -
|
|
|
|
ToPixel(AAMATextHeight * m_yscale, m_varInsunits)*(strings.size() - j-1));
|
|
|
|
input->AddEntity(AAMAText(pos, strings.at(j), *layer1));
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportAAMADrill(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
const QVector<VLayoutPlaceLabel> labels = detail.GetPlaceLabels();
|
2017-10-15 11:25:20 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
for(const auto &label : labels)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
if (label.Type() == PlaceLabelType::Doubletree || label.Type() == PlaceLabelType::Button
|
|
|
|
|| label.Type() == PlaceLabelType::Circle)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
const QPointF center = detail.GetMatrix().map(label.Center());
|
|
|
|
detailBlock->ent.push_back(AAMAPoint(center, *layer13));
|
2017-10-15 11:25:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-15 12:35:31 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::ExportToASTM(const QVector<VLayoutPiece> &details) -> bool
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
if (not m_size.isValid())
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
qWarning()<<"VDxfEngine::begin(), size is not valid";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input = QSharedPointer<dx_iface>(new dx_iface(GetFileNameForLocale(), m_version, m_varMeasurement,
|
|
|
|
m_varInsunits));
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddAAMAHeaderData();
|
2020-03-15 12:35:31 +01:00
|
|
|
if (m_version > DRW::AC1009)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddDefLayers();
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
m_input->AddASTMLayers();
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
ExportStyleSystemText(m_input, details);
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2020-03-21 17:15:29 +01:00
|
|
|
for(auto detail : details)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
auto detailBlock = QSharedPointer<dx_ifaceBlock>::create();
|
2020-03-15 12:35:31 +01:00
|
|
|
|
|
|
|
QString blockName = detail.GetName();
|
|
|
|
if (m_version <= DRW::AC1009)
|
|
|
|
{
|
|
|
|
blockName.replace(' ', '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
detailBlock->name = blockName.toStdString();
|
2022-10-07 15:04:07 +02:00
|
|
|
detailBlock->layer = *layer1;
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2020-03-21 17:15:29 +01:00
|
|
|
detail.Scale(m_xscale, m_yscale);
|
|
|
|
|
2020-03-15 12:35:31 +01:00
|
|
|
ExportASTMPieceBoundary(detailBlock, detail);
|
|
|
|
ExportASTMSewLine(detailBlock, detail);
|
|
|
|
ExportASTMInternalLine(detailBlock, detail);
|
|
|
|
ExportASTMInternalCutout(detailBlock, detail);
|
|
|
|
ExportASTMNotch(detailBlock, detail);
|
|
|
|
ExportAAMAGrainline(detailBlock, detail);
|
|
|
|
ExportPieceText(detailBlock, detail);
|
|
|
|
ExportASTMDrill(detailBlock, detail);
|
|
|
|
ExportASTMAnnotationText(detailBlock, detail);
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
m_input->AddBlock(detailBlock.get());
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
QScopedPointer<DRW_Insert> insert(new DRW_Insert());
|
2020-03-15 12:35:31 +01:00
|
|
|
insert->name = blockName.toStdString();
|
2022-10-07 15:04:07 +02:00
|
|
|
insert->layer = *layer1;
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
m_input->AddEntity(insert.take());
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
return m_input->fileExport(m_binary);
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportASTMPieceBoundary(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
QVector<VLayoutPoint> pieceBoundary = PieceOutline(detail);
|
2020-03-15 12:35:31 +01:00
|
|
|
|
|
|
|
// Piece boundary
|
2022-10-28 15:16:02 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(pieceBoundary, *layer1, true))
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
ExportTurnPoints(detailBlock, pieceBoundary);
|
|
|
|
ExportCurvePoints(detailBlock, pieceBoundary);
|
|
|
|
|
2020-03-15 12:35:31 +01:00
|
|
|
// Piece boundary quality validation curves
|
2022-10-28 15:16:02 +02:00
|
|
|
if (DRW_Entity *q = AAMAPolygon(pieceBoundary, *layer84, true))
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportASTMSewLine(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2021-04-19 16:28:25 +02:00
|
|
|
if (detail.IsSeamAllowance() && not detail.IsHideMainPath() && not detail.IsSeamAllowanceBuiltIn())
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
QVector<VLayoutPoint> sewLine = detail.GetMappedContourPoints();
|
2020-03-15 12:35:31 +01:00
|
|
|
|
|
|
|
// Sew lines
|
2022-10-07 15:04:07 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(sewLine, *layer14, true))
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
ExportTurnPoints(detailBlock, sewLine);
|
|
|
|
ExportCurvePoints(detailBlock, sewLine);
|
|
|
|
|
2020-03-15 12:35:31 +01:00
|
|
|
// Sew lines quality validation curves
|
2022-10-07 15:04:07 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(sewLine, *layer87, true))
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportASTMInternalLine(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
const QVector<QVector<VLayoutPoint>> drawIntLine = detail.MappedInternalPathsForCut(false);
|
|
|
|
for(const auto &intLine : drawIntLine)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
// Internal line
|
2022-10-28 15:16:02 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(intLine, *layer8, false))
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
ExportTurnPoints(detailBlock, intLine);
|
|
|
|
ExportCurvePoints(detailBlock, intLine);
|
|
|
|
|
2020-03-15 12:35:31 +01:00
|
|
|
// Internal lines quality validation curves
|
2022-10-28 15:16:02 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(intLine, *layer85, false))
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
const QVector<VLayoutPlaceLabel> labels = detail.GetPlaceLabels();
|
2022-10-07 15:04:07 +02:00
|
|
|
for(const auto &label : labels)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
if (label.Type() != PlaceLabelType::Doubletree && label.Type() != PlaceLabelType::Button
|
|
|
|
&& label.Type() != PlaceLabelType::Circle)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
PlaceLabelImg shape = detail.MapPlaceLabelShape(VAbstractPiece::PlaceLabelShape(label));
|
|
|
|
for(const auto &p : shape)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
// Internal line (placelabel)
|
2022-10-07 15:04:07 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(p, *layer8, false))
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
ExportTurnPoints(detailBlock, p);
|
|
|
|
ExportCurvePoints(detailBlock, p);
|
|
|
|
|
2020-03-15 12:35:31 +01:00
|
|
|
// Internal lines quality validation curves
|
2022-10-07 15:04:07 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(p, *layer85, false))
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportASTMInternalCutout(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
QVector<QVector<VLayoutPoint>> drawIntCut = detail.MappedInternalPathsForCut(true);
|
2020-03-15 12:35:31 +01:00
|
|
|
for(auto &intCut : drawIntCut)
|
|
|
|
{
|
|
|
|
// Internal cutout
|
2022-10-07 15:04:07 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(intCut, *layer11, false))
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
ExportTurnPoints(detailBlock, intCut);
|
|
|
|
ExportCurvePoints(detailBlock, intCut);
|
|
|
|
|
2020-03-15 12:35:31 +01:00
|
|
|
// Internal cutouts quality validation curves
|
2022-10-07 15:04:07 +02:00
|
|
|
if (DRW_Entity *e = AAMAPolygon(intCut, *layer86, false))
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportASTMAnnotationText(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
QString name = detail.GetName();
|
|
|
|
QPointF textPos = detail.VLayoutPiece::DetailBoundingRect().center();
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
QPointF pos(textPos.x(), textPos.y() - ToPixel(AAMATextHeight, m_varInsunits));
|
|
|
|
detailBlock->ent.push_back(AAMAText(pos, name, *layer15));
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportASTMDrill(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
const QVector<VLayoutPlaceLabel> labels = detail.GetPlaceLabels();
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
for(const auto &label : labels)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
if (label.Type() == PlaceLabelType::Doubletree || label.Type() == PlaceLabelType::Button
|
|
|
|
|| label.Type() == PlaceLabelType::Circle)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-28 15:16:02 +02:00
|
|
|
const QPointF center = detail.GetMatrix().map(label.Center());
|
|
|
|
detailBlock->ent.push_back(AAMAPoint(center, *layer13));
|
2020-03-15 12:35:31 +01:00
|
|
|
|
|
|
|
// TODO. Investigate drill category
|
|
|
|
// QPointF pos(center.x(), center.y() - ToPixel(AAMATextHeight, varInsunits));
|
2022-10-07 15:04:07 +02:00
|
|
|
// detailBlock->ent.push_back(AAMAText(pos, category, *layer13));
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportASTMNotch(const QSharedPointer<dx_ifaceBlock> &detailBlock, const VLayoutPiece &detail)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
if (detail.IsSeamAllowance())
|
|
|
|
{
|
2021-05-27 18:52:37 +02:00
|
|
|
const QVector<VLayoutPassmark> passmarks = detail.GetMappedPassmarks();
|
2022-10-07 15:04:07 +02:00
|
|
|
for(const auto &passmark : passmarks)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
auto *notch = new DRW_ASTMNotch();
|
2020-03-15 12:35:31 +01:00
|
|
|
const QPointF center = passmark.baseLine.p1();
|
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
notch->basePoint = DRW_Coord(FromPixel(center.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - center.y(), m_varInsunits),
|
|
|
|
FromPixel(passmark.baseLine.length(), m_varInsunits));
|
2020-03-15 12:35:31 +01:00
|
|
|
|
|
|
|
notch->angle = passmark.baseLine.angle();
|
|
|
|
|
|
|
|
if (passmark.type == PassmarkLineType::OneLine || passmark.type == PassmarkLineType::TwoLines
|
|
|
|
|| passmark.type == PassmarkLineType::ThreeLines)
|
|
|
|
{ // Slit notch
|
2022-10-07 15:04:07 +02:00
|
|
|
notch->layer = *layer4;
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
|
|
|
else if (passmark.type == PassmarkLineType::VMark || passmark.type == PassmarkLineType::VMark2)
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
QLineF boundaryLine(ConstFirst(passmark.lines).p2(), ConstLast(passmark.lines).p2());
|
2022-10-07 15:04:07 +02:00
|
|
|
notch->thickness = FromPixel(boundaryLine.length(), m_varInsunits); // width
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
notch->layer = *layer4;
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
|
|
|
else if (passmark.type == PassmarkLineType::TMark)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
qreal width = FromPixel(ConstLast(passmark.lines).length(), m_varInsunits);
|
|
|
|
notch->thickness = FromPixel(width, m_varInsunits);
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
notch->layer = *layer80;
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
|
|
|
else if (passmark.type == PassmarkLineType::BoxMark)
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
QPointF start = ConstFirst(passmark.lines).p1();
|
|
|
|
QPointF end = ConstLast(passmark.lines).p2();
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
notch->layer = *layer81;
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
notch->thickness = FromPixel(QLineF(start, end).length(), m_varInsunits);
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
|
|
|
else if (passmark.type == PassmarkLineType::UMark)
|
|
|
|
{
|
2022-01-29 09:59:02 +01:00
|
|
|
QPointF start = ConstFirst(passmark.lines).p1();
|
|
|
|
QPointF end = ConstLast(passmark.lines).p2();
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
notch->thickness = FromPixel(QLineF(start, end).length(), m_varInsunits);
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
notch->layer = *layer83;
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
detailBlock->ent.push_back(notch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-16 20:10:48 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
void VDxfEngine::ExportTurnPoints(const QSharedPointer<dx_ifaceBlock> &detailBlock,
|
|
|
|
const QVector<VLayoutPoint> &points) const
|
|
|
|
{
|
|
|
|
for(const auto &p : qAsConst(points))
|
|
|
|
{
|
|
|
|
if (p.TurnPoint())
|
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(AAMAPoint(p, *layer2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::ExportCurvePoints(const QSharedPointer<dx_ifaceBlock> &detailBlock,
|
|
|
|
const QVector<VLayoutPoint> &points) const
|
|
|
|
{
|
|
|
|
for(const auto &p : qAsConst(points))
|
|
|
|
{
|
|
|
|
if (p.CurvePoint() && not p.TurnPoint())
|
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(AAMAPoint(p, *layer3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VDxfEngine::AAMAPolygon(const QVector<VLayoutPoint> &polygon, const UTF8STRING &layer,
|
|
|
|
bool forceClosed) -> DRW_Entity *
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
if (polygon.isEmpty())
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_version > DRW::AC1009)
|
|
|
|
{ // Use lwpolyline
|
|
|
|
return CreateAAMAPolygon<DRW_LWPolyline, DRW_Vertex2D>(polygon, layer, forceClosed);
|
|
|
|
}
|
2022-10-07 15:04:07 +02:00
|
|
|
|
|
|
|
// Use polyline
|
|
|
|
return CreateAAMAPolygon<DRW_Polyline, DRW_Vertex>(polygon, layer, forceClosed);
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::AAMALine(const QLineF &line, const UTF8STRING &layer) -> DRW_Entity *
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
auto *lineEnt = new DRW_Line();
|
|
|
|
lineEnt->basePoint = DRW_Coord(FromPixel(line.p1().x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - line.p1().y(), m_varInsunits), 0);
|
|
|
|
lineEnt->secPoint = DRW_Coord(FromPixel(line.p2().x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - line.p2().y(), m_varInsunits), 0);
|
|
|
|
lineEnt->layer = layer;
|
2017-07-16 20:10:48 +02:00
|
|
|
|
|
|
|
return lineEnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::AAMAText(const QPointF &pos, const QString &text, const UTF8STRING &layer) -> DRW_Entity *
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
auto *textLine = new DRW_Text();
|
2017-07-16 20:10:48 +02:00
|
|
|
|
2022-10-07 15:04:07 +02:00
|
|
|
textLine->basePoint = DRW_Coord(FromPixel(pos.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - pos.y(), m_varInsunits), 0);
|
|
|
|
textLine->secPoint = DRW_Coord(FromPixel(pos.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - pos.y(), m_varInsunits), 0);
|
2017-07-16 20:10:48 +02:00
|
|
|
textLine->height = AAMATextHeight;
|
2022-10-07 15:04:07 +02:00
|
|
|
textLine->layer = layer;
|
2017-07-16 20:10:48 +02:00
|
|
|
textLine->text = text.toStdString();
|
|
|
|
|
|
|
|
return textLine;
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto VDxfEngine::AAMAPoint(const QPointF &pos, const UTF8STRING &layer) const -> DRW_Point *
|
|
|
|
{
|
|
|
|
auto *point = new DRW_Point();
|
|
|
|
point->basePoint = DRW_Coord(FromPixel(pos.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - pos.y(), m_varInsunits), 0);
|
|
|
|
point->layer = layer;
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
2018-07-16 19:00:42 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::FromUnicodeToCodec(const QString &str, QTextCodec *codec) -> std::string
|
2018-07-16 19:00:42 +02:00
|
|
|
{
|
2019-04-05 14:42:22 +02:00
|
|
|
return codec->fromUnicode(str).toStdString();
|
2018-07-16 19:00:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-07 15:04:07 +02:00
|
|
|
auto VDxfEngine::GetFileNameForLocale() const -> std::string
|
2018-07-16 19:00:42 +02:00
|
|
|
{
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
return VDxfEngine::FromUnicodeToCodec(fileName, QTextCodec::codecForLocale());
|
|
|
|
#else
|
2022-10-07 15:04:07 +02:00
|
|
|
return m_fileName.toStdString();
|
2018-07-16 19:00:42 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-07-16 20:10:48 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-10-28 15:16:02 +02:00
|
|
|
template<class P, class V, class C>
|
|
|
|
auto VDxfEngine::CreateAAMAPolygon(const QVector<C> &polygon, const UTF8STRING &layer,
|
|
|
|
bool forceClosed) -> P *
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
auto *poly = new P();
|
|
|
|
poly->layer = layer;
|
2017-07-16 20:10:48 +02:00
|
|
|
|
|
|
|
if (forceClosed)
|
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->flags |= 0x1; // closed NOLINT(hicpp-signed-bitwise)
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-29 13:57:21 +01:00
|
|
|
if (polygon.size() > 1 && ConstFirst<QPointF>(polygon) == ConstLast<QPointF>(polygon))
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->flags |= 0x1; // closed NOLINT(hicpp-signed-bitwise)
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
for (const auto &p : polygon)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
poly->addVertex(V(FromPixel(p.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - p.y(), m_varInsunits)));
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return poly;
|
|
|
|
}
|