mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-14 17:44:13 +02:00
5c4fa8fadf
Every project now opens without building its folios; a folio is built when it is shown or something needs its items (QETProject::lazyFolios()). QET_LAZY_FOLIOS is gone; QET_EAGER_FOLIOS=1 builds every folio on opening, as before, for comparisons and troubleshooting. Comments that named the old variable now say "lazy folios"; the tests switch modes with the new one. The first save of a .qet as .qetz still builds every folio: a .qet does not say which program wrote it, so its folios are written again rather than copied. A .qetz opens and saves without building. ctest 96/96 by default and with QET_EAGER_FOLIOS=1; 342 corpus projects save the same in all four arms and export the same. In the GUI (qet-gui-dialog): a 136-folio .qetz opens with no folio built, shows folios 1 to 4, saves building none, the save = the original but the time spent in it; a .qet opens lazily, saves as a .qetz beside it after the notice, the .qet unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
165 lines
4.7 KiB
C++
165 lines
4.7 KiB
C++
/*
|
|
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 "conductornumexport.h"
|
|
#include "qetproject.h"
|
|
#include "qetapp.h"
|
|
#include "diagram.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>
|
|
|
|
/**
|
|
@brief ConductorNumExport::ConductorNumExport
|
|
@param project : the project to export the conductors num
|
|
@param parent : parent widget
|
|
*/
|
|
ConductorNumExport::ConductorNumExport(QETProject *project, QWidget *parent) :
|
|
m_project(project),
|
|
m_parent_widget(parent)
|
|
{
|
|
fillHash();
|
|
}
|
|
|
|
/**
|
|
@brief ConductorNumExport::toCsv
|
|
Export the num of conductors into a csv file.
|
|
@return true if suceesfully exported.
|
|
*/
|
|
bool ConductorNumExport::toCsv()
|
|
{
|
|
//save in csv file in same directory as project by default
|
|
QString dir = m_project->currentDir();
|
|
if (dir.isEmpty()) dir = QETApp::documentDir();
|
|
QString name = dir % "/" % QObject::tr("number_of_wiring_") % m_project->title() % ".csv";
|
|
// if(!name.endsWith(".csv")) {
|
|
// name += ".csv";
|
|
// }
|
|
|
|
QString filename = QFileDialog::getSaveFileName(m_parent_widget, QObject::tr("Save As... "), name, QObject::tr("Files csv (*.csv)"));
|
|
QFile file(filename);
|
|
if(!filename.isEmpty())
|
|
{
|
|
if(QFile::exists(filename))
|
|
{
|
|
// if file already exist -> delete it
|
|
if(!QFile::remove(filename))
|
|
{
|
|
QMessageBox::critical(m_parent_widget, QObject::tr("Error"),
|
|
QObject::tr("Unable to replace the file!\n\n") %
|
|
"Destination : " % filename % "\n");
|
|
return false;
|
|
}
|
|
}
|
|
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
{
|
|
QTextStream stream(&file);
|
|
|
|
stream << wiresNum() << &Qt::endl(stream);
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
@brief ConductorNumExport::wiresNum
|
|
@return the wire num formatted in csv
|
|
*/
|
|
QString ConductorNumExport::wiresNum() const
|
|
{
|
|
QString csv;
|
|
|
|
QStringList list = m_hash.keys();
|
|
list.sort();
|
|
for (QString key : list)
|
|
{
|
|
for (int i=0; i<m_hash.value(key) ; ++i) {
|
|
csv.append(key % "\n");
|
|
}
|
|
}
|
|
|
|
return csv;
|
|
}
|
|
|
|
/**
|
|
@brief ConductorNumExport::fillHash
|
|
make/fill of m_hash
|
|
*/
|
|
void ConductorNumExport::fillHash()
|
|
{
|
|
//We used this rx to avoid insert num composed only withe white space.
|
|
QRegularExpression rx("^ *$");
|
|
auto count = [this](const QString &num) {
|
|
m_hash.insert(num, m_hash.value(num, 0) + 1);
|
|
};
|
|
//The folios not built (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))
|
|
{
|
|
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)) {
|
|
continue;
|
|
}
|
|
|
|
//We must define if the connected terminals are folio reports, if
|
|
//both are the case we don't add the num to the hash because
|
|
//neither terminal represents a real terminal. Otherwise the
|
|
//conductor counts once, regardless of how many of its two ends
|
|
//are real -- counting per terminal instead of per conductor
|
|
//doubled every ordinary two-real-terminal conductor's tally.
|
|
bool terminal1_is_report = c->terminal1->parentElement()->linkType() & Element::AllReport;
|
|
bool terminal2_is_report = c->terminal2->parentElement()->linkType() & Element::AllReport;
|
|
if (!(terminal1_is_report && terminal2_is_report))
|
|
{
|
|
int value = m_hash.value(num, 0);
|
|
++value;
|
|
m_hash.insert(num, value);
|
|
}
|
|
}
|
|
}
|
|
}
|