2013-03-17 20:24:48 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 The QElectroTech Team
|
2013-03-17 20:24:48 +00:00
|
|
|
This file is part of QElectroTech.
|
2015-09-15 08:20:39 +00:00
|
|
|
|
2013-03-17 20:24:48 +00:00
|
|
|
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.
|
2015-09-15 08:20:39 +00:00
|
|
|
|
2013-03-17 20:24:48 +00:00
|
|
|
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.
|
2015-09-15 08:20:39 +00:00
|
|
|
|
2013-03-17 20:24:48 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <QtDebug>
|
|
|
|
|
|
|
|
#include "nomenclature.h"
|
2014-10-05 13:35:01 +00:00
|
|
|
#include "elementprovider.h"
|
2016-11-09 16:06:04 +00:00
|
|
|
#include "assignvariables.h"
|
2017-01-19 12:43:40 +00:00
|
|
|
|
2013-03-17 20:24:48 +00:00
|
|
|
#define PR(x) qDebug() << #x " = " << x;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructor
|
2015-09-15 08:20:39 +00:00
|
|
|
@param an project (QETProject) of QET file
|
2013-03-17 20:24:48 +00:00
|
|
|
*/
|
|
|
|
nomenclature::nomenclature(QETProject *project, QWidget *parent):
|
|
|
|
m_project(project)
|
|
|
|
{
|
|
|
|
m_parent = parent;
|
2014-10-05 13:35:01 +00:00
|
|
|
//get list of schema present in project
|
|
|
|
m_list_diagram = m_project -> diagrams();
|
2013-03-17 20:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor
|
|
|
|
*/
|
|
|
|
nomenclature::~nomenclature() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Save to csv file
|
|
|
|
@param true if success
|
|
|
|
*/
|
2015-09-15 08:20:39 +00:00
|
|
|
bool nomenclature::saveToCSVFile()
|
|
|
|
{
|
2013-03-17 20:24:48 +00:00
|
|
|
// SAVE IN FILE
|
2015-09-15 08:20:39 +00:00
|
|
|
QString name = QObject::tr("nomenclature_") + QString(m_project -> title());
|
2014-10-05 13:35:01 +00:00
|
|
|
if (!name.endsWith(".csv")) {
|
|
|
|
name += ".csv";
|
|
|
|
}
|
2015-09-15 08:20:39 +00:00
|
|
|
QString filename = QFileDialog::getSaveFileName(this->m_parent, QObject::tr("Enregister sous... "), name, QObject::tr("Fichiers csv (*.csv)"));
|
2013-03-17 20:24:48 +00:00
|
|
|
QFile file(filename);
|
|
|
|
if( !filename.isEmpty() ) {
|
|
|
|
if(QFile::exists ( filename )){
|
|
|
|
// if file already exist -> delete it
|
|
|
|
if(!QFile::remove ( filename ) ){
|
2015-09-15 08:20:39 +00:00
|
|
|
QMessageBox::critical(this->m_parent, QObject::tr("Erreur"),
|
|
|
|
QObject::tr("Impossible de remplacer le fichier!\n\n")+
|
2013-03-17 20:24:48 +00:00
|
|
|
"Destination: "+filename+"\n");
|
|
|
|
return false;
|
2015-09-15 08:20:39 +00:00
|
|
|
}
|
2013-03-17 20:24:48 +00:00
|
|
|
}
|
|
|
|
if (file.open(QIODevice::WriteOnly | QIODevice::Text)){
|
|
|
|
QTextStream stream(&file);
|
2014-10-05 13:35:01 +00:00
|
|
|
stream << getNomenclature() << endl;
|
2013-03-17 20:24:48 +00:00
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
else return false;
|
2015-09-15 08:20:39 +00:00
|
|
|
|
2013-03-17 20:24:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-10-05 13:35:01 +00:00
|
|
|
* @brief nomenclature::getNomenclature
|
|
|
|
* Create and formated a nomenclature to csv file.
|
|
|
|
* @return The QString of nomenclature
|
|
|
|
*/
|
2015-09-15 08:20:39 +00:00
|
|
|
QString nomenclature::getNomenclature()
|
|
|
|
{
|
2014-10-05 13:35:01 +00:00
|
|
|
//Process...
|
2015-09-15 08:20:39 +00:00
|
|
|
QString data = QObject::tr("NOMENCLATURE : ") + m_project -> title() + "\n\n";
|
|
|
|
data += QObject::tr("N° de folio") +";"
|
|
|
|
""+ QObject::tr("Titre de folio") +";"
|
2016-05-18 05:39:42 +00:00
|
|
|
""+ QObject::tr("Label de folio") +";"
|
2015-09-15 08:20:39 +00:00
|
|
|
""+ QObject::tr("Désignation qet") +";"
|
|
|
|
""+ QObject::tr("Position") +";"
|
|
|
|
""+ QObject::tr("Label") +";"
|
|
|
|
""+ QObject::tr("Désignation") +";"
|
2017-10-02 16:59:53 +00:00
|
|
|
""+ QObject::tr("Description") +";"
|
2015-09-15 08:20:39 +00:00
|
|
|
""+ QObject::tr("Commentaire") +";"
|
|
|
|
""+ QObject::tr("Fabricant") +";"
|
|
|
|
""+ QObject::tr("Reference") +";"
|
2015-09-29 09:20:38 +00:00
|
|
|
""+ QObject::tr("Bloc auxiliaire 1") +";"
|
|
|
|
""+ QObject::tr("Bloc auxiliaire 2") +";"
|
2015-09-15 08:20:39 +00:00
|
|
|
""+ QObject::tr("Machine-reference") +";"
|
|
|
|
""+ QObject::tr("Localisation") +";"
|
|
|
|
""+ QObject::tr("Fonction") +"\n";
|
2015-04-02 15:48:04 +00:00
|
|
|
|
2014-10-05 13:35:01 +00:00
|
|
|
|
|
|
|
if(m_list_diagram.isEmpty()) return data;
|
2014-10-04 14:16:35 +00:00
|
|
|
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Diagram *d, m_list_diagram) {
|
2016-11-09 16:06:04 +00:00
|
|
|
//Get only simple, master and unlinked slave element.
|
|
|
|
ElementProvider ep(d);
|
|
|
|
QSettings settings;
|
|
|
|
QList <Element *> list_elements;
|
|
|
|
|
|
|
|
if (settings.value("nomenclature/terminal-exportlist", true).toBool()){
|
|
|
|
list_elements << ep.find(Element::Simple | Element::Master | Element::Terminale);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
list_elements << ep.find(Element::Simple | Element::Master);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
list_elements << ep.freeElement(Element::Slave);
|
|
|
|
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Element *elmt, list_elements) {
|
2014-10-05 13:35:01 +00:00
|
|
|
data += getElementInfo(elmt);
|
|
|
|
}
|
2013-03-17 20:24:48 +00:00
|
|
|
}
|
2014-10-05 13:35:01 +00:00
|
|
|
|
|
|
|
return data;
|
2013-03-17 20:24:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-05 13:35:01 +00:00
|
|
|
/**
|
|
|
|
* @brief nomenclature::getElementInfo
|
|
|
|
* @param elmt : the element to getinfo
|
|
|
|
* @return : QString with information about element formated to csv file
|
|
|
|
*/
|
2016-05-25 14:49:33 +00:00
|
|
|
QString nomenclature::getElementInfo(Element *elmt) {
|
2014-10-05 13:35:01 +00:00
|
|
|
QString info;
|
|
|
|
|
|
|
|
Diagram *diagram = elmt -> diagram();
|
|
|
|
DiagramContext elmt_info = elmt -> elementInformations();
|
2017-01-19 12:43:40 +00:00
|
|
|
autonum::sequentialNumbers empty_seq;
|
2014-10-05 13:35:01 +00:00
|
|
|
|
|
|
|
info += QString::number(diagram -> folioIndex()+1) + ";";
|
|
|
|
info += diagram -> title() + ";";
|
2017-01-19 12:43:40 +00:00
|
|
|
info += autonum::AssignVariables::formulaToLabel(diagram->border_and_titleblock.folio(), empty_seq, diagram) + ";";
|
2014-10-05 13:35:01 +00:00
|
|
|
info += elmt -> name() + ";";
|
2015-06-10 19:31:26 +00:00
|
|
|
info += elmt-> diagram()-> convertPosition(elmt -> scenePos()).toString() + ";";
|
2016-11-09 16:06:04 +00:00
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["label"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["designation"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
2017-10-02 16:59:53 +00:00
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["description"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
2016-11-09 16:06:04 +00:00
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["comment"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["manufacturer"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["manufacturer-reference"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["auxiliary1"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["auxiliary2"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["machine-manufacturer-reference"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["location"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
|
|
|
|
info += autonum::AssignVariables::formulaToLabel(elmt_info["function"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + "\n";
|
|
|
|
|
2014-10-05 13:35:01 +00:00
|
|
|
return info;
|
|
|
|
}
|