mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-19 04:24:14 +02:00
Number terminals and export wire numbers without building every folio (stage D5)
Terminal numbering builds only the folios holding a terminal. The wire numbers export reads the wires of the folios not built from the project database, and walks a built folio's own wires instead of a DiagramContent, which followed their potentials through folio reports and built the folios at the other end. The wiring list export names a folio from its title block, which a folio not built has; it still builds every folio, writing the whole project out (toXml()). tst_lazyfolios: wire numbers exported as when built, from a .qet and a .qetz, building no folio (fails with DiagramContent: 27 built); terminal numbering builds 7 folios, those with a terminal (fails with diagrams(): 47); the wiring list as when built. ctest 96/96 eager and lazy; 342 corpus projects save the same in all four arms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,11 +19,12 @@
|
||||
#include "qetproject.h"
|
||||
#include "qetapp.h"
|
||||
#include "diagram.h"
|
||||
#include "diagramcontent.h"
|
||||
#include "qetgraphicsitem/conductor.h"
|
||||
#include "qetgraphicsitem/conductortextitem.h"
|
||||
#include "qetgraphicsitem/element.h"
|
||||
#include "qetgraphicsitem/terminal.h"
|
||||
#include "dataBase/projectdatabase.h"
|
||||
#include "properties/elementdata.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
@@ -114,10 +115,30 @@ void ConductorNumExport::fillHash()
|
||||
{
|
||||
//We used this rx to avoid insert num composed only withe white space.
|
||||
QRegularExpression rx("^ *$");
|
||||
for (Diagram *d : m_project->diagrams())
|
||||
auto count = [this](const QString &num) {
|
||||
m_hash.insert(num, m_hash.value(num, 0) + 1);
|
||||
};
|
||||
//The folios not built (QET_LAZY_FOLIOS): their wires from the
|
||||
//project database, by the same rules
|
||||
QList<QUuid> unbuilt;
|
||||
for (Diagram *d : m_project->folios())
|
||||
if (!d->isLoaded()) unbuilt << d->uuid();
|
||||
for (const auto &wire : m_project->dataBase()->wiresOnFolios(unbuilt))
|
||||
{
|
||||
DiagramContent dc(d, false);
|
||||
for (Conductor *c : dc.conductors())
|
||||
if (wire.text.isEmpty() || wire.text.contains(rx)) {
|
||||
continue;
|
||||
}
|
||||
const bool report1 = ElementData::typeFromString(wire.kind1) & ElementData::AllReport;
|
||||
const bool report2 = ElementData::typeFromString(wire.kind2) & ElementData::AllReport;
|
||||
if (!(report1 && report2)) {
|
||||
count(wire.text);
|
||||
}
|
||||
}
|
||||
for (Diagram *d : m_project->builtFolios())
|
||||
{
|
||||
//Its wires only: a DiagramContent would follow their
|
||||
//potentials onto other folios, building those not built
|
||||
for (Conductor *c : d->conductors())
|
||||
{
|
||||
QString num = c->textItem()->toPlainText();
|
||||
if (num.isEmpty() || num.contains(rx)) {
|
||||
|
||||
@@ -1263,6 +1263,32 @@ QList<projectDataBase::FolioSymbol> projectDataBase::symbolsOnFolios(const QList
|
||||
return symbols;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief projectDataBase::wiresOnFolios
|
||||
@return the wires on the folios @p folios, folio by folio in that order,
|
||||
read from the conductor table as it is (see elementTypesOnFolios())
|
||||
*/
|
||||
QList<projectDataBase::FolioWire> projectDataBase::wiresOnFolios(const QList<QUuid> &folios) const
|
||||
{
|
||||
QList<FolioWire> wires;
|
||||
QSqlQuery query(m_data_base);
|
||||
query.prepare(QStringLiteral("SELECT c.text, e1.type, e2.type FROM conductor c "
|
||||
"LEFT JOIN element e1 ON e1.uuid = c.terminal1_element_uuid "
|
||||
"LEFT JOIN element e2 ON e2.uuid = c.terminal2_element_uuid "
|
||||
"WHERE c.diagram_uuid = :folio ORDER BY c.rowid"));
|
||||
for (const QUuid &folio : folios) {
|
||||
query.bindValue(QStringLiteral(":folio"), folio.toString());
|
||||
if (!query.exec()) {
|
||||
continue;
|
||||
}
|
||||
while (query.next()) {
|
||||
wires.append({query.value(0).toString(), query.value(1).toString(),
|
||||
query.value(2).toString()});
|
||||
}
|
||||
}
|
||||
return wires;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief projectDataBase::linkedSymbols
|
||||
@return the symbols @p element is linked to, read from the link table
|
||||
|
||||
@@ -191,6 +191,10 @@ class projectDataBase : public QObject
|
||||
};
|
||||
QList<FolioSymbol> symbolsOnFolios(const QList<QUuid> &folios) const;
|
||||
QList<QUuid> linkedSymbols(const QUuid &element) const;
|
||||
/// A wire placed on a folio: its text and the kinds of the
|
||||
/// symbols at its ends (ElementData::typeToString())
|
||||
struct FolioWire { QString text; QString kind1; QString kind2; };
|
||||
QList<FolioWire> wiresOnFolios(const QList<QUuid> &folios) const;
|
||||
static QVariant sequenceValue(const autonum::sequentialNumbers &sequence);
|
||||
static autonum::sequentialNumbers sequenceFromValue(const QVariant &value);
|
||||
|
||||
|
||||
@@ -13,6 +13,16 @@
|
||||
#include <QSet>
|
||||
#include <algorithm>
|
||||
|
||||
namespace {
|
||||
//The folios holding a terminal, built: a folio not built yet
|
||||
//(QET_LAZY_FOLIOS) holding none is not built for this
|
||||
QList<Diagram *> terminalFolios(QETProject *project)
|
||||
{
|
||||
project->buildFoliosHolding(ElementData::Terminal, false);
|
||||
return project->builtFolios();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalNumberingDialog::TerminalNumberingDialog
|
||||
* Constructor
|
||||
@@ -31,7 +41,7 @@ TerminalNumberingDialog::TerminalNumberingDialog(QWidget *parent, QETProject *pr
|
||||
// Collect all unique terminal strip prefixes from the project
|
||||
if (project) {
|
||||
QSet<QString> prefixes;
|
||||
foreach (Diagram *diagram, project->diagrams()) {
|
||||
foreach (Diagram *diagram, terminalFolios(project)) {
|
||||
foreach (QGraphicsItem *qgi, diagram->items()) {
|
||||
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
|
||||
if (elmt->elementData().m_type == ElementData::Terminal) {
|
||||
@@ -153,7 +163,7 @@ QUndoCommand* TerminalNumberingDialog::getUndoCommand(QETProject *project) const
|
||||
QList<TermInfo> termList;
|
||||
|
||||
// 2. Collect all terminals from all folios in the project
|
||||
foreach (Diagram *diagram, project->diagrams()) {
|
||||
foreach (Diagram *diagram, terminalFolios(project)) {
|
||||
int fIndex = diagram->folioIndex();
|
||||
foreach (QGraphicsItem *qgi, diagram->items()) {
|
||||
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
|
||||
|
||||
@@ -28,8 +28,8 @@ QString WiringListExport::findDiagramFolio(const QDomElement &diagramElem) const
|
||||
// The folio number as the folio shows it ("3/12"). The saved "folio"
|
||||
// attribute is its template ("%id/%total").
|
||||
const int index = diagramElem.attribute("order").toInt();
|
||||
if (m_project && index >= 1 && index <= m_project->diagrams().size()) {
|
||||
return m_project->diagrams().at(index - 1)->border_and_titleblock
|
||||
if (m_project && index >= 1 && index <= m_project->folios().size()) {
|
||||
return m_project->folios().at(index - 1)->border_and_titleblock
|
||||
.titleblockInformation().value("folio").toString();
|
||||
}
|
||||
if (diagramElem.hasAttribute("folio")) return diagramElem.attribute("folio");
|
||||
|
||||
Reference in New Issue
Block a user