2023-06-21 09:24:51 +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 Valentina project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
|
|
|
** <https://gitlab.com/smart-pattern/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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
2015-09-07 21:47:02 +02:00
|
|
|
|
|
|
|
#include "vdxfengine.h"
|
2023-05-02 16:38:30 +02:00
|
|
|
#include <QLineF>
|
2023-05-02 16:38:02 +02:00
|
|
|
|
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 <QtDebug>
|
2022-10-07 15:04:07 +02:00
|
|
|
#include <QtMath>
|
2023-04-07 15:12:07 +02:00
|
|
|
#include <memory>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2023-02-11 15:14:15 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
#include "../vmisc/vtextcodec.h"
|
|
|
|
#else
|
|
|
|
#include <QTextCodec>
|
|
|
|
#endif
|
|
|
|
|
2019-07-22 16:06:30 +02:00
|
|
|
#include "../vgeometry/vgeometrydef.h"
|
2022-10-28 15:16:02 +02:00
|
|
|
#include "../vgeometry/vlayoutplacelabel.h"
|
2023-05-08 16:50:22 +02:00
|
|
|
#include "../vlayout/vlayoutpiece.h"
|
|
|
|
#include "../vlayout/vlayoutpoint.h"
|
2023-06-21 09:24:51 +02:00
|
|
|
#include "../vmisc/def.h"
|
2023-05-08 16:50:22 +02:00
|
|
|
#include "dxiface.h"
|
2017-07-16 20:10:48 +02:00
|
|
|
|
2023-10-13 14:26:19 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
|
|
|
#include "../vmisc/compatibility.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace Qt::Literals::StringLiterals;
|
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
const qreal AAMATextHeight = 2.5;
|
|
|
|
|
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wunused-member-function")
|
|
|
|
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer0, (UTF8STRING("0"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer1, (UTF8STRING("1"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer2, (UTF8STRING("2"))) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const UTF8STRING, layer3, (UTF8STRING("3"))) // NOLINT
|
|
|
|
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
|
|
|
|
|
|
|
|
QT_WARNING_POP
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto PieceOutline(const VLayoutPiece &detail) -> QVector<VLayoutPoint>
|
|
|
|
{
|
|
|
|
if (detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn())
|
|
|
|
{
|
2023-07-07 11:16:49 +02:00
|
|
|
return detail.GetMappedSeamAllowancePoints();
|
2023-06-21 09:24:51 +02:00
|
|
|
}
|
2023-07-07 11:16:49 +02:00
|
|
|
return detail.GetMappedContourPoints();
|
2023-06-21 09:24:51 +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
|
|
|
{
|
2023-06-21 09:24:51 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wsign-conversion")
|
|
|
|
QT_WARNING_DISABLE_INTEL(68)
|
2015-09-07 21:47:02 +02:00
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
return {QPaintEngine::AllFeatures & ~QPaintEngine::PatternBrush & ~QPaintEngine::PerspectiveTransform &
|
|
|
|
~QPaintEngine::ConicalGradientFill & ~QPaintEngine::PorterDuff};
|
2015-09-07 21:47:02 +02:00
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
QT_WARNING_POP
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VDxfEngine::VDxfEngine()
|
2023-06-21 09:24:51 +02:00
|
|
|
: QPaintEngine(svgEngineFeatures()),
|
|
|
|
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
|
|
|
{
|
2023-06-21 09:24:51 +02:00
|
|
|
qWarning() << "VDxfEngine::begin(), size is not valid";
|
2015-09-07 21:47:02 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
m_input =
|
|
|
|
QSharedPointer<dx_iface>(new dx_iface(GetFileNameForLocale(), m_version, m_varMeasurement, m_varInsunits));
|
2023-04-01 14:03:34 +02:00
|
|
|
m_input->AddDefHeaderData();
|
2022-10-07 15:04:07 +02:00
|
|
|
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
|
|
|
|
2023-06-21 09:24:51 +02: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
|
|
|
|
2023-08-12 11:03:28 +02:00
|
|
|
if (polygon.size() > 1 && polygon.constFirst() == polygon.constLast())
|
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();
|
2023-08-12 11:03:28 +02:00
|
|
|
if (polygon.size() > 1 && polygon.constFirst() == polygon.constLast())
|
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();
|
2023-06-21 09:24:51 +02:00
|
|
|
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);
|
2022-10-07 15:04:07 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-21 09:24:51 +02:00
|
|
|
void VDxfEngine::drawLines(const QLine *lines, int lineCount)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2023-06-21 09:24:51 +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)
|
2023-06-21 09:24:51 +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-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
|
|
|
|
2023-06-21 09:24:51 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-21 09:24:51 +02:00
|
|
|
void VDxfEngine::drawEllipse(const QRectF &rect)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2022-10-07 15:04:07 +02:00
|
|
|
const QRectF newRect = m_matrix.mapRect(rect);
|
2023-06-21 09:24:51 +02:00
|
|
|
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
|
2023-06-21 09:24:51 +02:00
|
|
|
double ratio; // ratio of minor axis to major axis
|
|
|
|
if (rect.width() <= rect.height())
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
2023-06-21 09:24:51 +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
|
2023-06-21 09:24:51 +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)
|
2023-06-21 09:24:51 +02:00
|
|
|
ratio = rect.width() / rect.height();
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-21 09:24:51 +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)
|
2023-06-21 09:24:51 +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
|
2023-06-21 09:24:51 +02:00
|
|
|
ratio = rect.height() / rect.width();
|
2015-09-07 21:47:02 +02:00
|
|
|
}
|
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;
|
2023-06-21 09:24:51 +02:00
|
|
|
ellipse->endparam = 2 * M_PI;
|
2017-06-21 11:34:20 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-21 09:24:51 +02:00
|
|
|
void VDxfEngine::drawEllipse(const QRect &rect)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
|
|
|
QPaintEngine::drawEllipse(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-21 09:24:51 +02:00
|
|
|
void VDxfEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
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),
|
2023-06-21 09:24:51 +02:00
|
|
|
FromPixel(GetSize().height() - startPoint.y(), m_varInsunits), 0);
|
2022-10-07 15:04:07 +02:00
|
|
|
m_textBuffer->secPoint = DRW_Coord(FromPixel(startPoint.x(), m_varInsunits),
|
2023-06-21 09:24:51 +02:00
|
|
|
FromPixel(GetSize().height() - startPoint.y(), m_varInsunits), 0);
|
2022-10-07 15:04:07 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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
|
|
|
}
|
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
}
|
|
|
|
|
2023-06-21 09:24:51 +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();
|
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
if (color == Qt::black)
|
2015-09-07 21:47:02 +02:00
|
|
|
{
|
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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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
|
|
|
|
2023-06-21 09:24:51 +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)
|
|
|
|
{
|
2023-07-10 18:23:41 +02:00
|
|
|
Q_ASSERT(not isActive());
|
2020-03-21 17:15:29 +01:00
|
|
|
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)
|
|
|
|
{
|
2023-07-10 18:23:41 +02:00
|
|
|
Q_ASSERT(not isActive());
|
2020-03-21 17:15:29 +01:00
|
|
|
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
|
|
|
{
|
2023-06-21 09:24:51 +02:00
|
|
|
qWarning() << "VDxfEngine::begin(), size is not valid";
|
2017-07-16 20:10:48 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-28 15:16:02 +02:00
|
|
|
m_input = QSharedPointer<dx_iface>::create(GetFileNameForLocale(), m_version, m_varMeasurement, m_varInsunits);
|
2023-04-01 14:03:34 +02:00
|
|
|
m_input->AddXSpaceBlock(false);
|
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
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
for (auto detail : details)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2023-03-30 16:20:16 +02:00
|
|
|
// Use custom deleter function to lose ownership after adding the block
|
|
|
|
bool deleteBlock = true;
|
2023-06-21 09:24:51 +02:00
|
|
|
auto NoOpDeleter = [&deleteBlock](dx_ifaceBlock *block)
|
2023-03-30 16:20:16 +02:00
|
|
|
{
|
|
|
|
if (deleteBlock)
|
|
|
|
{
|
|
|
|
delete block;
|
|
|
|
}
|
|
|
|
};
|
2022-10-28 15:16:02 +02:00
|
|
|
|
2023-03-30 16:20:16 +02:00
|
|
|
auto detailBlock = QSharedPointer<dx_ifaceBlock>(new dx_ifaceBlock, NoOpDeleter);
|
2017-07-17 16:43:10 +02:00
|
|
|
|
|
|
|
QString blockName = detail.GetName();
|
|
|
|
if (m_version <= DRW::AC1009)
|
|
|
|
{
|
2023-10-13 14:26:19 +02:00
|
|
|
blockName.replace(' '_L1, '_'_L1);
|
2017-07-17 16:43:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
detailBlock->name = blockName.toStdString();
|
2023-04-01 14:03:34 +02:00
|
|
|
detailBlock->flags = 64;
|
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-11-10 11:05:06 +01:00
|
|
|
m_input->AddBlock(detailBlock.data());
|
2017-07-16 20:10:48 +02:00
|
|
|
|
2023-04-03 12:44:20 +02:00
|
|
|
std::unique_ptr<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
|
|
|
|
2023-04-03 12:44:20 +02:00
|
|
|
m_input->AddEntity(insert.release());
|
2023-03-30 16:20:16 +02:00
|
|
|
|
|
|
|
deleteBlock = false; // lose ownership
|
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-11-04 16:16:50 +01:00
|
|
|
const UTF8STRING &layer = not detail.IsSewLineOnDrawing() ? *layer14 : *layer8;
|
|
|
|
|
|
|
|
if (DRW_Entity *e = AAMAPolygon(points, layer, 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);
|
2023-06-21 09:24:51 +02:00
|
|
|
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();
|
2023-06-21 09:24:51 +02:00
|
|
|
for (const auto &label : labels)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2023-06-21 09:24:51 +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));
|
2023-06-21 09:24:51 +02:00
|
|
|
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);
|
2023-06-21 09:24:51 +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();
|
2023-06-21 09:24:51 +02:00
|
|
|
for (const auto &passmark : passmarks)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2023-04-06 17:21:24 +02:00
|
|
|
std::unique_ptr<DRW_ASTMNotch> notch(new DRW_ASTMNotch());
|
|
|
|
const QPointF center = passmark.baseLine.p1();
|
|
|
|
|
|
|
|
notch->basePoint = DRW_Coord(FromPixel(center.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - center.y(), m_varInsunits),
|
|
|
|
FromPixel(passmark.baseLine.length(), m_varInsunits));
|
|
|
|
notch->angle = passmark.baseLine.angle();
|
|
|
|
notch->layer = *layer4;
|
|
|
|
|
|
|
|
detailBlock->ent.push_back(notch.release());
|
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
|
|
|
{
|
2023-05-02 16:38:02 +02:00
|
|
|
const QLineF grainlineMainLine = detail.GetMappedGrainlineMainLine();
|
|
|
|
if (not grainlineMainLine.isNull())
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2023-05-02 16:38:02 +02:00
|
|
|
if (DRW_Entity *e = AAMALine(grainlineMainLine, *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)
|
|
|
|
{
|
2023-02-09 16:23:11 +01:00
|
|
|
const qreal height = ToPixel(AAMATextHeight * m_yscale, m_varInsunits);
|
2023-06-21 09:24:51 +02:00
|
|
|
QPointF pos(startPos.x(), startPos.y() - height * (static_cast<int>(list.size()) - i - 1));
|
2022-10-07 15:04:07 +02:00
|
|
|
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
|
|
|
{
|
2023-06-21 09:24:51 +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)
|
|
|
|
{
|
2023-02-09 16:23:11 +01:00
|
|
|
const qreal height = ToPixel(AAMATextHeight * m_yscale, m_varInsunits);
|
2023-06-21 09:24:51 +02:00
|
|
|
QPointF pos(0, GetSize().height() - height * (static_cast<int>(strings.size()) - j - 1));
|
2022-10-07 15:04:07 +02:00
|
|
|
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
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
for (const auto &label : labels)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2023-06-21 09:24:51 +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
|
|
|
{
|
2023-06-21 09:24:51 +02:00
|
|
|
qWarning() << "VDxfEngine::begin(), size is not valid";
|
2020-03-15 12:35:31 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
m_input =
|
|
|
|
QSharedPointer<dx_iface>(new dx_iface(GetFileNameForLocale(), m_version, m_varMeasurement, m_varInsunits));
|
2023-04-01 14:03:34 +02:00
|
|
|
m_input->AddXSpaceBlock(false);
|
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
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
for (auto detail : details)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2023-03-30 16:20:16 +02:00
|
|
|
// Use custom deleter function to lose ownership after adding the block
|
|
|
|
bool deleteBlock = true;
|
2023-06-21 09:24:51 +02:00
|
|
|
auto NoOpDeleter = [&deleteBlock](dx_ifaceBlock *block)
|
2023-03-30 16:20:16 +02:00
|
|
|
{
|
|
|
|
if (deleteBlock)
|
|
|
|
{
|
|
|
|
delete block;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
auto detailBlock = QSharedPointer<dx_ifaceBlock>(new dx_ifaceBlock, NoOpDeleter);
|
2020-03-15 12:35:31 +01:00
|
|
|
|
|
|
|
QString blockName = detail.GetName();
|
|
|
|
if (m_version <= DRW::AC1009)
|
|
|
|
{
|
2023-10-13 14:26:19 +02:00
|
|
|
blockName.replace(' '_L1, '_'_L1);
|
2020-03-15 12:35:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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-11-10 11:05:06 +01:00
|
|
|
m_input->AddBlock(detailBlock.data());
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2023-04-03 12:44:20 +02:00
|
|
|
std::unique_ptr<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
|
|
|
|
2023-04-03 12:44:20 +02:00
|
|
|
m_input->AddEntity(insert.release());
|
2023-03-30 16:20:16 +02:00
|
|
|
|
|
|
|
deleteBlock = false; // lose ownership
|
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);
|
2023-06-21 09:24:51 +02:00
|
|
|
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();
|
2023-06-21 09:24:51 +02:00
|
|
|
for (const auto &label : labels)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2023-06-21 09:24:51 +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));
|
2023-06-21 09:24:51 +02:00
|
|
|
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);
|
2023-06-21 09:24:51 +02:00
|
|
|
for (auto &intCut : drawIntCut)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
2023-06-21 09:24:51 +02:00
|
|
|
for (const auto &label : labels)
|
2020-03-15 12:35:31 +01:00
|
|
|
{
|
2023-06-21 09:24:51 +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());
|
2023-04-06 17:21:24 +02:00
|
|
|
QLineF diameter = detail.GetMatrix().map(QLineF(label.Box().bottomLeft(), label.Box().topRight()));
|
|
|
|
|
|
|
|
std::unique_ptr<DRW_Point> point(new DRW_Point());
|
|
|
|
point->basePoint = DRW_Coord(FromPixel(center.x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - center.y(), m_varInsunits),
|
|
|
|
FromPixel(diameter.length(), m_varInsunits));
|
|
|
|
point->layer = *layer13;
|
|
|
|
detailBlock->ent.push_back(point.release());
|
2020-03-15 12:35:31 +01:00
|
|
|
|
|
|
|
// TODO. Investigate drill category
|
2023-06-21 09:24:51 +02:00
|
|
|
// QPointF pos(center.x(), center.y() - ToPixel(AAMATextHeight, m_varInsunits));
|
|
|
|
// 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();
|
2023-06-21 09:24:51 +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();
|
|
|
|
|
2023-05-08 16:50:22 +02:00
|
|
|
switch (passmark.type)
|
|
|
|
{
|
|
|
|
case PassmarkLineType::OneLine:
|
|
|
|
case PassmarkLineType::TwoLines:
|
|
|
|
case PassmarkLineType::ThreeLines:
|
|
|
|
// Slit notch
|
|
|
|
notch->layer = *layer4;
|
|
|
|
break;
|
2023-05-06 19:01:15 +02:00
|
|
|
case PassmarkLineType::ExternalVMark:
|
|
|
|
case PassmarkLineType::InternalVMark:
|
2023-05-08 16:50:22 +02:00
|
|
|
{ // V-Notch
|
2023-08-12 11:03:28 +02:00
|
|
|
QLineF boundaryLine(passmark.lines.constFirst().p1(), passmark.lines.constLast().p2());
|
2023-05-08 16:50:22 +02:00
|
|
|
notch->thickness = FromPixel(boundaryLine.length(), m_varInsunits); // width
|
|
|
|
notch->layer = *layer4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PassmarkLineType::TMark:
|
|
|
|
// T-Notch
|
2023-08-12 11:03:28 +02:00
|
|
|
notch->thickness = FromPixel(passmark.lines.constLast().length(), m_varInsunits); // width
|
2023-05-08 16:50:22 +02:00
|
|
|
notch->layer = *layer80;
|
|
|
|
break;
|
|
|
|
case PassmarkLineType::BoxMark:
|
|
|
|
{ // Castle Notch
|
2023-08-12 11:03:28 +02:00
|
|
|
QPointF start = passmark.lines.constFirst().p1();
|
|
|
|
QPointF end = passmark.lines.constLast().p2();
|
2023-05-08 16:50:22 +02:00
|
|
|
|
|
|
|
notch->layer = *layer81;
|
|
|
|
notch->thickness = FromPixel(QLineF(start, end).length(), m_varInsunits); // width
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PassmarkLineType::UMark:
|
|
|
|
{ // U-Notch
|
2023-08-12 11:03:28 +02:00
|
|
|
QPointF start = passmark.lines.constFirst().p1();
|
|
|
|
QPointF end = passmark.lines.constLast().p2();
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2023-05-08 16:50:22 +02:00
|
|
|
notch->thickness = FromPixel(QLineF(start, end).length(), m_varInsunits); // width
|
2020-03-15 12:35:31 +01:00
|
|
|
|
2023-05-08 16:50:22 +02:00
|
|
|
notch->layer = *layer83;
|
|
|
|
break;
|
|
|
|
}
|
2023-05-06 19:01:15 +02:00
|
|
|
case PassmarkLineType::CheckMark:
|
|
|
|
{ // Check Notch
|
2023-08-12 11:03:28 +02:00
|
|
|
const QLineF &line1 = passmark.lines.constFirst();
|
|
|
|
const QLineF &line2 = passmark.lines.constLast();
|
2023-05-06 19:01:15 +02:00
|
|
|
|
|
|
|
qreal width = QLineF(line1.p1(), line2.p2()).length();
|
|
|
|
|
|
|
|
if (not passmark.isClockwiseOpening)
|
|
|
|
{ // a counter clockwise opening
|
|
|
|
width *= -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
notch->thickness = FromPixel(width, m_varInsunits); // width
|
|
|
|
notch->layer = *layer82;
|
|
|
|
break;
|
|
|
|
}
|
2023-05-08 16:50:22 +02:00
|
|
|
case PassmarkLineType::LAST_ONE_DO_NOT_USE:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
break;
|
2023-05-09 17:59:57 +02:00
|
|
|
default:
|
|
|
|
break;
|
2023-05-08 16:50:22 +02:00
|
|
|
};
|
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
|
|
|
|
{
|
2023-06-21 09:24:51 +02:00
|
|
|
for (const auto &p : qAsConst(points))
|
2022-10-28 15:16:02 +02:00
|
|
|
{
|
|
|
|
if (p.TurnPoint())
|
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(AAMAPoint(p, *layer2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VDxfEngine::ExportCurvePoints(const QSharedPointer<dx_ifaceBlock> &detailBlock,
|
|
|
|
const QVector<VLayoutPoint> &points) const
|
|
|
|
{
|
2023-06-21 09:24:51 +02:00
|
|
|
for (const auto &p : qAsConst(points))
|
2022-10-28 15:16:02 +02:00
|
|
|
{
|
|
|
|
if (p.CurvePoint() && not p.TurnPoint())
|
|
|
|
{
|
|
|
|
detailBlock->ent.push_back(AAMAPoint(p, *layer3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-21 09:24:51 +02:00
|
|
|
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);
|
2023-06-21 09:24:51 +02:00
|
|
|
lineEnt->secPoint = DRW_Coord(FromPixel(line.p2().x(), m_varInsunits),
|
|
|
|
FromPixel(GetSize().height() - line.p2().y(), m_varInsunits), 0);
|
2022-10-07 15:04:07 +02:00
|
|
|
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
|
|
|
|
2023-06-21 09:24:51 +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();
|
2023-06-21 09:24:51 +02:00
|
|
|
point->basePoint =
|
|
|
|
DRW_Coord(FromPixel(pos.x(), m_varInsunits), FromPixel(GetSize().height() - pos.y(), m_varInsunits), 0);
|
2022-10-28 15:16:02 +02:00
|
|
|
point->layer = layer;
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
2018-07-16 19:00:42 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-02-11 15:14:15 +01:00
|
|
|
auto VDxfEngine::FromUnicodeToCodec(const QString &str, VTextCodec *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)
|
2023-02-28 09:14:14 +01:00
|
|
|
return VDxfEngine::FromUnicodeToCodec(m_fileName, VTextCodec::codecForName("System"));
|
2018-07-16 19:00:42 +02:00
|
|
|
#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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-06-21 09:24:51 +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
|
|
|
|
{
|
2023-08-12 11:03:28 +02:00
|
|
|
if (polygon.size() > 1 && polygon.constFirst() == polygon.constLast())
|
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
|
|
|
{
|
2023-06-21 09:24:51 +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;
|
|
|
|
}
|