mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-14 09:14:14 +02:00
Fix DXF export of circles, arcs and the title block at the right (#1339)
Circles and arcs: drawArcEllipse() split each curve into quarters and fitted a circular ARC through a point half way between the curve and its chord, so every circle came out as a flattened diamond. A circle or an arc of one is now one exact CIRCLE or ARC. R10 has no ELLIPSE entity, so a true ellipse is a polyline through the curve, one point every 5 degrees. The export also used a different scale on each axis, which made round things oval; it now uses one, the largest that fits the sheet. Title block at the right: the DXF laid the horizontal template out in the narrow vertical strip, squashing it into the top corner. It is now laid out horizontally and turned a quarter, as draw() turns the painter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -462,6 +462,17 @@ target_link_libraries(tst_dxfwrappedtext PRIVATE Qt::Test)
|
||||
target_compile_definitions(tst_dxfwrappedtext PRIVATE
|
||||
"QET_TEST_BINARY_PATH=\"$<TARGET_FILE:qelectrotech>\"")
|
||||
|
||||
# --export-dxf on a folio with its title block at the right (issue #1339):
|
||||
# a circle and an arc stay one CIRCLE and one ARC, the title block is turned.
|
||||
add_executable(
|
||||
tst_dxfcurves
|
||||
tst_dxfcurves.cpp)
|
||||
add_test(NAME tst_dxfcurves COMMAND tst_dxfcurves)
|
||||
add_dependencies(tst_dxfcurves qelectrotech)
|
||||
target_link_libraries(tst_dxfcurves PRIVATE Qt::Test)
|
||||
target_compile_definitions(tst_dxfcurves PRIVATE
|
||||
"QET_TEST_BINARY_PATH=\"$<TARGET_FILE:qelectrotech>\"")
|
||||
|
||||
# --export-pdf puts an A3 folio on an A3 page whichever way it is turned:
|
||||
# QPageSize matches standard sheets upright only, so a wide folio is matched
|
||||
# upright and turned. fixtures/pdf_page_a3.qet has one folio each way.
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<project title="DXF curves and title block" uuid="{6c1a7d2e-9b54-4d2f-8f68-3f0d0f0a7b10}" version="0.200.1">
|
||||
<properties>
|
||||
<property name="saveddate" show="1">10/2/26</property>
|
||||
<property name="saveddate-eu" show="1">02-10-2026</property>
|
||||
<property name="saveddate-us" show="1">2026-10-02</property>
|
||||
<property name="savedfilename" show="1">dxf_curves</property>
|
||||
<property name="savedtime" show="1">18:39</property>
|
||||
</properties>
|
||||
<usage enabled="true" time_spent="0"/>
|
||||
<newdiagrams>
|
||||
<border cols="17" colsize="60" displaycols="true" displayrows="true" rows="8" rowsize="80"/>
|
||||
<inset author="" auto_page_num="" date="null" displayAt="bottom" filename="" folio="" indexrev="" locmach="" plant="" title="" version=""/>
|
||||
<conductors bicolor="false" bus="" cable="" color2="#000000" condsize="1" conductor_color="" conductor_section="" dash-size="1" displaytext="1" formula="" function="" horizontal-alignment="AlignBottom" horizrotatetext="0" num="_" numsize="7" onetextperfolio="0" tension_protocol="" text_color="#000000" type="multi" vertical-alignment="AlignRight" vertirotatetext="270"/>
|
||||
<report label="%f-%l%c"/>
|
||||
<xrefs>
|
||||
<xref delayprefix="" displayhas="cross" master_label="%f-%l%c" offset="0" powerprefix="" showallconfiguredslaves="false" showpowerctc="true" showterminalname="true" slave_label="(%f-%l%c)" slave_offset="0" snapto="label" switchprefix="" type="coil" xrefpos="AlignBottom"/>
|
||||
<xref delayprefix="" displayhas="cross" master_label="%f-%l%c" offset="0" powerprefix="" showallconfiguredslaves="false" showpowerctc="true" showterminalname="true" slave_label="(%f-%l%c)" slave_offset="0" snapto="label" switchprefix="" type="commutator" xrefpos="AlignBottom"/>
|
||||
<xref delayprefix="" displayhas="cross" master_label="%f-%l%c" offset="0" powerprefix="" showallconfiguredslaves="false" showpowerctc="true" showterminalname="true" slave_label="(%f-%l%c)" slave_offset="0" snapto="label" switchprefix="" type="plc" xrefpos="AlignBottom"/>
|
||||
<xref delayprefix="" displayhas="cross" master_label="%f-%l%c" offset="0" powerprefix="" showallconfiguredslaves="false" showpowerctc="true" showterminalname="true" slave_label="(%f-%l%c)" slave_offset="0" snapto="label" switchprefix="" type="protection" xrefpos="AlignBottom"/>
|
||||
</xrefs>
|
||||
<conductors_autonums auto_break_conductors="false" current_autonum="" freeze_new_conductors="false"/>
|
||||
<folio_autonums/>
|
||||
<element_autonums current_autonum="" freeze_new_elements="false"/>
|
||||
<guides/>
|
||||
</newdiagrams>
|
||||
<diagram author="" auto_page_num="" cols="17" colsize="60" date="null" displayAt="right" displaycols="true" displayrows="true" filename="" folio="" freezeNewConductor="false" freezeNewElement="false" height="660" indexrev="" locmach="" order="1" plant="" rows="8" rowsize="80" title="" uuid="{6c1a7d2e-9b54-4d2f-8f68-3f0d0f0a7a01}" version="0.200.1-dev">
|
||||
<defaultconductor bicolor="false" bus="" cable="" color2="#000000" condsize="1" conductor_color="" conductor_section="" dash-size="1" displaytext="1" formula="" function="" horizontal-alignment="AlignBottom" horizrotatetext="0" num="_" numsize="7" onetextperfolio="0" tension_protocol="" text_color="#000000" type="multi" vertical-alignment="AlignRight" vertirotatetext="270"/>
|
||||
<elements>
|
||||
<element freezeLabel="false" is_movable="1" orientation="0" prefix="" type="embed://import/curves.elmt" uuid="{6c1a7d2e-9b54-4d2f-8f68-3f0d0f0a7a02}" x="300" y="300" z="10">
|
||||
<terminals/>
|
||||
<inputs/>
|
||||
<dynamic_texts/>
|
||||
<texts_groups/>
|
||||
</element>
|
||||
</elements>
|
||||
</diagram>
|
||||
<collection>
|
||||
<category name="import">
|
||||
<names>
|
||||
<name lang="en">Imported elements</name>
|
||||
</names>
|
||||
<element name="curves.elmt">
|
||||
<definition height="80" hotspot_x="10" hotspot_y="10" link_type="simple" type="element" version="0.100.0" width="120">
|
||||
<uuid uuid="{6c1a7d2e-9b54-4d2f-8f68-3f0d0f0a7a05}"/>
|
||||
<names>
|
||||
<name lang="en">Circle and arc</name>
|
||||
</names>
|
||||
<description>
|
||||
<ellipse antialias="true" style="line-style:normal;line-weight:normal;filling:none;color:black" x="0" y="0" width="20" height="20"/>
|
||||
<arc antialias="true" style="line-style:normal;line-weight:normal;filling:none;color:black" x="40" y="0" width="20" height="20" start="30" angle="120"/>
|
||||
</description>
|
||||
</definition>
|
||||
</element>
|
||||
</category>
|
||||
</collection>
|
||||
</project>
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
Copyright 2006-2026 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech 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 QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <QtTest>
|
||||
#include <QProcess>
|
||||
#include <QTemporaryDir>
|
||||
|
||||
/**
|
||||
--export-dxf on a folio whose title block is at the right (issue #1339):
|
||||
a symbol's circle is one CIRCLE and its arc one ARC with the symbol's own
|
||||
angles, which needs the same scale on both axes; the title block is
|
||||
turned a quarter, as it is on screen.
|
||||
*/
|
||||
class tst_dxfcurves : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/// The entities on @a layer, each as its group codes and values.
|
||||
static QList<QMultiHash<int, QString>> entities(const QStringList &values,
|
||||
const QString &type,
|
||||
const QString &layer)
|
||||
{
|
||||
QList<QMultiHash<int, QString>> found;
|
||||
for (int i = 0 ; i + 1 < values.size() ; i += 2)
|
||||
{
|
||||
if (values.at(i).trimmed() != QLatin1String("0")
|
||||
|| values.at(i + 1).trimmed() != type)
|
||||
continue;
|
||||
QMultiHash<int, QString> entity;
|
||||
for (int j = i + 2 ; j + 1 < values.size()
|
||||
&& values.at(j).trimmed() != QLatin1String("0") ; j += 2)
|
||||
entity.insert(values.at(j).trimmed().toInt(), values.at(j + 1).trimmed());
|
||||
if (entity.value(8) == layer)
|
||||
found << entity;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void curvesAndTitleBlock()
|
||||
{
|
||||
const QString project = QFINDTESTDATA("fixtures/dxf_curves.qet");
|
||||
QVERIFY2(!project.isEmpty(), "fixture project not found");
|
||||
QTemporaryDir dir;
|
||||
QVERIFY(dir.isValid());
|
||||
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
env.insert(QStringLiteral("QT_QPA_PLATFORM"), QStringLiteral("offscreen"));
|
||||
QProcess proc;
|
||||
proc.setProcessEnvironment(env);
|
||||
proc.start(QStringLiteral(QET_TEST_BINARY_PATH), {QStringLiteral("--export-dxf"), project, dir.path()});
|
||||
QVERIFY2(proc.waitForFinished(60000), "--export-dxf timed out");
|
||||
QCOMPARE(proc.exitCode(), 0);
|
||||
|
||||
QFile file(dir.filePath(QStringLiteral("01_diagram.dxf")));
|
||||
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text));
|
||||
const QStringList values = QString::fromUtf8(file.readAll()).split(QLatin1Char('\n'));
|
||||
const QString symbols = QStringLiteral("QET_SYMBOLS");
|
||||
|
||||
//The 20 px circle: one CIRCLE, nothing approximated
|
||||
const auto circles = entities(values, QStringLiteral("CIRCLE"), symbols);
|
||||
QCOMPARE(circles.size(), 1);
|
||||
QVERIFY(entities(values, QStringLiteral("POLYLINE"), symbols).isEmpty());
|
||||
|
||||
//The arc from 30 to 150 degrees, same radius as the circle
|
||||
const auto arcs = entities(values, QStringLiteral("ARC"), symbols);
|
||||
QCOMPARE(arcs.size(), 1);
|
||||
QCOMPARE(arcs.first().value(50).toDouble(), 30.0);
|
||||
QCOMPARE(arcs.first().value(51).toDouble(), 150.0);
|
||||
QCOMPARE(arcs.first().value(40).toDouble(), circles.first().value(40).toDouble());
|
||||
|
||||
//Every title block text turned a quarter, as drawn on screen
|
||||
const auto texts = entities(values, QStringLiteral("TEXT"), QStringLiteral("QET_TITLEBLOCK"));
|
||||
QVERIFY(!texts.isEmpty());
|
||||
for (const auto &text : texts)
|
||||
QCOMPARE(text.value(50).toDouble(), 90.0);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_dxfcurves)
|
||||
#include "tst_dxfcurves.moc"
|
||||
Reference in New Issue
Block a user