Refactoring.

This commit is contained in:
Roman Telezhynskyi 2022-10-07 16:04:07 +03:00
parent 2eaecc747c
commit 576e3bbbf2
5 changed files with 457 additions and 422 deletions

File diff suppressed because it is too large Load Diff

View File

@ -55,70 +55,74 @@ class VDxfEngine final : public QPaintEngine
friend class VDxfPaintDevice;
public:
VDxfEngine();
virtual ~VDxfEngine();
~VDxfEngine() override;
virtual bool begin(QPaintDevice *pdev) override;
virtual bool end() override;
virtual void updateState(const QPaintEngineState &state) override;
virtual void drawPath(const QPainterPath &path) override;
virtual void drawLines(const QLineF * lines, int lineCount) override;
virtual void drawLines(const QLine * lines, int lineCount) override;
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override;
virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) override;
virtual void drawEllipse(const QRectF & rect) override;
virtual void drawEllipse(const QRect & rect) override;
virtual void drawTextItem(const QPointF & p, const QTextItem & textItem) override;
virtual Type type() const override;
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override;
auto type() const -> Type override;
QSize getSize() const;
void setSize(const QSize &value);
auto begin(QPaintDevice *pdev) -> bool override;
auto end() -> bool override;
double getResolution() const;
void setResolution(double value);
void updateState(const QPaintEngineState &state) override;
QString getFileName() const;
void setFileName(const QString &value);
void drawPath(const QPainterPath &path) override;
void drawLines(const QLineF * lines, int lineCount) override;
void drawLines(const QLine * lines, int lineCount) override;
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override;
void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) override;
void drawEllipse(const QRectF & rect) override;
void drawEllipse(const QRect & rect) override;
void drawTextItem(const QPointF & p, const QTextItem & textItem) override;
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override;
DRW::Version GetVersion() const;
void SetVersion(DRW::Version version);
auto GetSize() const -> QSize;
void SetSize(const QSize &value);
auto GetResolution() const -> double;
void SetResolution(double value);
auto GetFileName() const -> QString;
void SetFileName(const QString &value);
auto GetVersion() const -> DRW::Version;
void SetVersion(DRW::Version version);
void SetBinaryFormat(bool binary);
bool IsBinaryFormat() const;
auto IsBinaryFormat() const -> bool;
std::string getPenStyle();
int getPenColor();
auto GetPenStyle() -> std::string;
auto GetPenColor() -> int;
void setMeasurement(const VarMeasurement &var);
void setInsunits(const VarInsunits &var);
void SetMeasurement(const VarMeasurement &var);
void SetInsunits(const VarInsunits &var);
qreal GetXScale() const;
void SetXScale(const qreal &xscale);
auto GetXScale() const -> qreal;
void SetXScale(const qreal &xscale);
qreal GetYScale() const;
void SetYScale(const qreal &yscale);
auto GetYScale() const -> qreal;
void SetYScale(const qreal &yscale);
QString ErrorString() const;
auto ErrorString() const -> QString;
private:
Q_DISABLE_COPY_MOVE(VDxfEngine) // NOLINT
QSize size;
double resolution;
QString fileName;
DRW::Version m_version;
bool m_binary;
QTransform matrix;
QSharedPointer<dx_iface> input;
VarMeasurement varMeasurement;
VarInsunits varInsunits;
DRW_Text *textBuffer;
QSize m_size{};
double m_resolution{static_cast<int>(PrintDPI)};
QString m_fileName{};
DRW::Version m_version{DRW::AC1014};
bool m_binary{false};
QTransform m_matrix{};
QSharedPointer<dx_iface> m_input{};
VarMeasurement m_varMeasurement{VarMeasurement::Metric};
VarInsunits m_varInsunits{VarInsunits::Millimeters};
DRW_Text *m_textBuffer{nullptr};
qreal m_xscale{1};
qreal m_yscale{1};
Q_REQUIRED_RESULT double FromPixel(double pix, const VarInsunits &unit) const;
Q_REQUIRED_RESULT double ToPixel(double val, const VarInsunits &unit) const;
Q_REQUIRED_RESULT auto FromPixel(double pix, const VarInsunits &unit) const -> double;
Q_REQUIRED_RESULT auto ToPixel(double val, const VarInsunits &unit) const -> double;
bool ExportToAAMA(const QVector<VLayoutPiece> &details);
auto ExportToAAMA(const QVector<VLayoutPiece> &details) -> bool;
void ExportAAMAOutline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail);
void ExportAAMADraw(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail);
void ExportAAMAIntcut(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail);
@ -128,7 +132,7 @@ private:
void ExportStyleSystemText(const QSharedPointer<dx_iface> &input, const QVector<VLayoutPiece> &details);
void ExportAAMADrill(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail);
bool ExportToASTM(const QVector<VLayoutPiece> &details);
auto ExportToASTM(const QVector<VLayoutPiece> &details) -> bool;
void ExportASTMPieceBoundary(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail);
void ExportASTMSewLine(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail);
void ExportASTMInternalLine(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail);
@ -137,15 +141,17 @@ private:
void ExportASTMDrill(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail);
void ExportASTMNotch(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail);
Q_REQUIRED_RESULT DRW_Entity *AAMAPolygon(const QVector<QPointF> &polygon, const QString &layer, bool forceClosed);
Q_REQUIRED_RESULT DRW_Entity *AAMALine(const QLineF &line, const QString &layer);
Q_REQUIRED_RESULT DRW_Entity *AAMAText(const QPointF &pos, const QString &text, const QString &layer);
Q_REQUIRED_RESULT auto AAMAPolygon(const QVector<QPointF> &polygon, const UTF8STRING &layer,
bool forceClosed) -> DRW_Entity *;
Q_REQUIRED_RESULT auto AAMALine(const QLineF &line, const UTF8STRING &layer) -> DRW_Entity *;
Q_REQUIRED_RESULT auto AAMAText(const QPointF &pos, const QString &text, const UTF8STRING &layer) -> DRW_Entity *;
template<class P, class V>
Q_REQUIRED_RESULT P *CreateAAMAPolygon(const QVector<QPointF> &polygon, const QString &layer, bool forceClosed);
Q_REQUIRED_RESULT auto CreateAAMAPolygon(const QVector<QPointF> &polygon, const UTF8STRING &layer,
bool forceClosed) -> P *;
static std::string FromUnicodeToCodec(const QString &str, QTextCodec *codec);
std::string getFileNameForLocale() const;
static auto FromUnicodeToCodec(const QString &str, QTextCodec *codec) -> std::string;
auto GetFileNameForLocale() const -> std::string;
};
#endif // VDXFENGINE_H

View File

@ -35,213 +35,212 @@
//---------------------------------------------------------------------------------------------------------------------
VDxfPaintDevice::VDxfPaintDevice()
:QPaintDevice(), engine(new VDxfEngine()), fileName()
{
}
:m_engine(new VDxfEngine())
{}
//---------------------------------------------------------------------------------------------------------------------
VDxfPaintDevice::~VDxfPaintDevice()
{
delete engine;
delete m_engine;
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
QPaintEngine *VDxfPaintDevice::paintEngine() const
auto VDxfPaintDevice::paintEngine() const -> QPaintEngine *
{
return engine;
return m_engine;
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
QString VDxfPaintDevice::getFileName() const
auto VDxfPaintDevice::GetFileName() const -> QString
{
return fileName;
return m_fileName;
}
//---------------------------------------------------------------------------------------------------------------------
void VDxfPaintDevice::setFileName(const QString &value)
void VDxfPaintDevice::SetFileName(const QString &value)
{
if (engine->isActive())
if (m_engine->isActive())
{
qWarning("VDxfPaintDevice::setFileName(), cannot set file name while Dxf is being generated");
return;
}
fileName = value;
engine->setFileName(fileName);
m_fileName = value;
m_engine->SetFileName(m_fileName);
}
//---------------------------------------------------------------------------------------------------------------------
QSize VDxfPaintDevice::getSize()
auto VDxfPaintDevice::GetSize() -> QSize
{
return engine->getSize();
return m_engine->GetSize();
}
//---------------------------------------------------------------------------------------------------------------------
void VDxfPaintDevice::setSize(const QSize &size)
void VDxfPaintDevice::SetSize(const QSize &size)
{
if (engine->isActive())
if (m_engine->isActive())
{
qWarning("VDxfPaintDevice::setSize(), cannot set size while Dxf is being generated");
return;
}
engine->setSize(size);
m_engine->SetSize(size);
}
//---------------------------------------------------------------------------------------------------------------------
double VDxfPaintDevice::getResolution() const
auto VDxfPaintDevice::GetResolution() const -> double
{
return engine->getResolution();
return m_engine->GetResolution();
}
//---------------------------------------------------------------------------------------------------------------------
void VDxfPaintDevice::setResolution(double dpi)
void VDxfPaintDevice::SetResolution(double dpi)
{
if (engine->isActive())
if (m_engine->isActive())
{
qWarning("VDxfPaintDevice::setResolution(), cannot set dpi while Dxf is being generated");
return;
}
engine->setResolution(dpi);
m_engine->SetResolution(dpi);
}
//---------------------------------------------------------------------------------------------------------------------
DRW::Version VDxfPaintDevice::GetVersion() const
auto VDxfPaintDevice::GetVersion() const -> DRW::Version
{
return engine->GetVersion();
return m_engine->GetVersion();
}
//---------------------------------------------------------------------------------------------------------------------
void VDxfPaintDevice::SetVersion(DRW::Version version)
{
if (engine->isActive())
if (m_engine->isActive())
{
qWarning("VDxfPaintDevice::SetVersion(), cannot set version while Dxf is being generated");
return;
}
engine->SetVersion(version);
m_engine->SetVersion(version);
}
//---------------------------------------------------------------------------------------------------------------------
void VDxfPaintDevice::SetBinaryFormat(bool binary)
{
if (engine->isActive())
if (m_engine->isActive())
{
qWarning("VDxfPaintDevice::SetBinaryFormat(), cannot set binary format while Dxf is being generated");
return;
}
engine->SetBinaryFormat(binary);
m_engine->SetBinaryFormat(binary);
}
//---------------------------------------------------------------------------------------------------------------------
bool VDxfPaintDevice::IsBinaryFromat() const
auto VDxfPaintDevice::IsBinaryFromat() const -> bool
{
return engine->IsBinaryFormat();
return m_engine->IsBinaryFormat();
}
//---------------------------------------------------------------------------------------------------------------------
void VDxfPaintDevice::setMeasurement(const VarMeasurement &var)
void VDxfPaintDevice::SetMeasurement(const VarMeasurement &var)
{
if (engine->isActive())
if (m_engine->isActive())
{
qWarning("VDxfPaintDevice::setMeasurement(), cannot set measurements while Dxf is being generated");
return;
}
engine->setMeasurement(var);
m_engine->SetMeasurement(var);
}
//---------------------------------------------------------------------------------------------------------------------
void VDxfPaintDevice::setInsunits(const VarInsunits &var)
void VDxfPaintDevice::SetInsunits(const VarInsunits &var)
{
if (engine->isActive())
if (m_engine->isActive())
{
qWarning("VDxfPaintDevice::setInsunits(), cannot set units while Dxf is being generated");
return;
}
engine->setInsunits(var);
m_engine->SetInsunits(var);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VDxfPaintDevice::GetXScale() const
auto VDxfPaintDevice::GetXScale() const -> qreal
{
return engine->GetYScale();
return m_engine->GetYScale();
}
//---------------------------------------------------------------------------------------------------------------------
void VDxfPaintDevice::SetXScale(const qreal &xscale)
{
if (engine->isActive())
if (m_engine->isActive())
{
qWarning("VDxfPaintDevice::SetXScale(), cannot set x scale while Dxf is being generated");
return;
}
engine->SetXScale(xscale);
m_engine->SetXScale(xscale);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VDxfPaintDevice::GetYScale() const
auto VDxfPaintDevice::GetYScale() const -> qreal
{
return engine->GetXScale();
return m_engine->GetXScale();
}
//---------------------------------------------------------------------------------------------------------------------
void VDxfPaintDevice::SetYScale(const qreal &yscale)
{
if (engine->isActive())
if (m_engine->isActive())
{
qWarning("VDxfPaintDevice::SetYScale(), cannot set y scale while Dxf is being generated");
return;
}
engine->SetYScale(yscale);
m_engine->SetYScale(yscale);
}
//---------------------------------------------------------------------------------------------------------------------
bool VDxfPaintDevice::ExportToAAMA(const QVector<VLayoutPiece> &details) const
auto VDxfPaintDevice::ExportToAAMA(const QVector<VLayoutPiece> &details) const -> bool
{
engine->setActive(true);
const bool res = engine->ExportToAAMA(details);
engine->setActive(false);
m_engine->setActive(true);
const bool res = m_engine->ExportToAAMA(details);
m_engine->setActive(false);
return res;
}
//---------------------------------------------------------------------------------------------------------------------
bool VDxfPaintDevice::ExportToASTM(const QVector<VLayoutPiece> &details) const
auto VDxfPaintDevice::ExportToASTM(const QVector<VLayoutPiece> &details) const -> bool
{
engine->setActive(true);
const bool res = engine->ExportToASTM(details);
engine->setActive(false);
m_engine->setActive(true);
const bool res = m_engine->ExportToASTM(details);
m_engine->setActive(false);
return res;
}
//---------------------------------------------------------------------------------------------------------------------
QString VDxfPaintDevice::ErrorString() const
auto VDxfPaintDevice::ErrorString() const -> QString
{
return engine->ErrorString();
return m_engine->ErrorString();
}
//---------------------------------------------------------------------------------------------------------------------
int VDxfPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const
auto VDxfPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const -> int
{
switch (metric)
{
case QPaintDevice::PdmDepth:
return 32;
case QPaintDevice::PdmWidth:
return engine->getSize().width();
return m_engine->GetSize().width();
case QPaintDevice::PdmHeight:
return engine->getSize().height();
return m_engine->GetSize().height();
case QPaintDevice::PdmHeightMM:
return qRound(engine->getSize().height() * 25.4 / engine->getResolution());
return qRound(m_engine->GetSize().height() * 25.4 / m_engine->GetResolution());
case QPaintDevice::PdmWidthMM:
return qRound(engine->getSize().width() * 25.4 / engine->getResolution());
return qRound(m_engine->GetSize().width() * 25.4 / m_engine->GetResolution());
case QPaintDevice::PdmNumColors:
return static_cast<int>(0xffffffff);
case QPaintDevice::PdmPhysicalDpiX:
case QPaintDevice::PdmPhysicalDpiY:
case QPaintDevice::PdmDpiX:
case QPaintDevice::PdmDpiY:
return static_cast<int>(engine->getResolution());
return static_cast<int>(m_engine->GetResolution());
case QPaintDevice::PdmDevicePixelRatio:
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
case QPaintDevice::PdmDevicePixelRatioScaled:

View File

@ -45,45 +45,46 @@ class VDxfPaintDevice : public QPaintDevice
{
public:
VDxfPaintDevice();
virtual ~VDxfPaintDevice() override;
virtual QPaintEngine *paintEngine() const override;
~VDxfPaintDevice() override;
QString getFileName() const;
void setFileName(const QString &value);
auto paintEngine() const -> QPaintEngine * override;
QSize getSize();
void setSize(const QSize &size);
auto GetFileName() const -> QString;
void SetFileName(const QString &value);
double getResolution() const;
void setResolution(double dpi);
auto GetSize() -> QSize;
void SetSize(const QSize &size);
DRW::Version GetVersion() const;
void SetVersion(DRW::Version version);
auto GetResolution() const -> double;
void SetResolution(double dpi);
auto GetVersion() const -> DRW::Version;
void SetVersion(DRW::Version version);
void SetBinaryFormat(bool binary);
bool IsBinaryFromat() const;
auto IsBinaryFromat() const -> bool;
void setMeasurement(const VarMeasurement &var);
void setInsunits(const VarInsunits &var);
void SetMeasurement(const VarMeasurement &var);
void SetInsunits(const VarInsunits &var);
qreal GetXScale() const;
void SetXScale(const qreal &xscale);
auto GetXScale() const -> qreal;
void SetXScale(const qreal &xscale);
qreal GetYScale() const;
void SetYScale(const qreal &yscale);
auto GetYScale() const -> qreal;
void SetYScale(const qreal &yscale);
bool ExportToAAMA(const QVector<VLayoutPiece> &details) const;
bool ExportToASTM(const QVector<VLayoutPiece> &details) const;
auto ExportToAAMA(const QVector<VLayoutPiece> &details) const -> bool;
auto ExportToASTM(const QVector<VLayoutPiece> &details) const -> bool;
QString ErrorString() const;
auto ErrorString() const -> QString;
protected:
virtual int metric(PaintDeviceMetric metric) const override;
auto metric(PaintDeviceMetric metric) const -> int override;
private:
// cppcheck-suppress unknownMacro
Q_DISABLE_COPY_MOVE(VDxfPaintDevice) // NOLINT
VDxfEngine *engine;
QString fileName;
VDxfEngine *m_engine;
QString m_fileName{};
};
#endif // VDXFPAINTDEVICE_H

View File

@ -251,12 +251,12 @@ void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList<QGraphi
PrepareTextForDXF(endStringPlaceholder, details);
VDxfPaintDevice generator;
generator.setFileName(m_fileName);
generator.setSize(QSize(qFloor(m_imageRect.width() * m_xScale), qFloor(m_imageRect.height() * m_yScale)));
generator.setResolution(PrintDPI);
generator.SetFileName(m_fileName);
generator.SetSize(QSize(qFloor(m_imageRect.width() * m_xScale), qFloor(m_imageRect.height() * m_yScale)));
generator.SetResolution(PrintDPI);
generator.SetVersion(static_cast<DRW::Version>(m_dxfVersion));
generator.SetBinaryFormat(m_binaryDxfFormat);
generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
generator.SetInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
QPainter painter;
if (painter.begin(&generator))
@ -277,12 +277,12 @@ void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList<QGraphi
void VLayoutExporter::ExportToAAMADXF(const QVector<VLayoutPiece> &details) const
{
VDxfPaintDevice generator;
generator.setFileName(m_fileName);
generator.setSize(QSize(qCeil(m_imageRect.width() * m_xScale), qCeil(m_imageRect.height() * m_yScale)));
generator.setResolution(PrintDPI);
generator.SetFileName(m_fileName);
generator.SetSize(QSize(qCeil(m_imageRect.width() * m_xScale), qCeil(m_imageRect.height() * m_yScale)));
generator.SetResolution(PrintDPI);
generator.SetVersion(static_cast<DRW::Version>(m_dxfVersion));
generator.SetBinaryFormat(m_binaryDxfFormat);
generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
generator.SetInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
generator.SetXScale(m_xScale);
generator.SetYScale(m_yScale);
if (not generator.ExportToAAMA(details))
@ -296,12 +296,12 @@ void VLayoutExporter::ExportToAAMADXF(const QVector<VLayoutPiece> &details) cons
void VLayoutExporter::ExportToASTMDXF(const QVector<VLayoutPiece> &details) const
{
VDxfPaintDevice generator;
generator.setFileName(m_fileName);
generator.setSize(QSize(qCeil(m_imageRect.width() * m_xScale), qCeil(m_imageRect.height() * m_yScale)));
generator.setResolution(PrintDPI);
generator.SetFileName(m_fileName);
generator.SetSize(QSize(qCeil(m_imageRect.width() * m_xScale), qCeil(m_imageRect.height() * m_yScale)));
generator.SetResolution(PrintDPI);
generator.SetVersion(static_cast<DRW::Version>(m_dxfVersion));
generator.SetBinaryFormat(m_binaryDxfFormat);
generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
generator.SetInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
generator.SetXScale(m_xScale);
generator.SetYScale(m_yScale);
if (not generator.ExportToASTM(details))