QElectroTech  0.70
nomenclature.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include <QtDebug>
19 
20 #include "nomenclature.h"
21 #include "elementprovider.h"
22 #include "assignvariables.h"
23 
24 #define PR(x) qDebug() << #x " = " << x;
25 
30 nomenclature::nomenclature(QETProject *project, QWidget *parent):
31  m_project(project)
32 {
33  m_parent = parent;
34  //get list of schema present in project
35  m_list_diagram = m_project -> diagrams();
36 }
37 
42 }
43 
49 {
50  // SAVE IN FILE
51  QString name = QObject::tr("nomenclature_") + QString(m_project -> title());
52  if (!name.endsWith(".csv")) {
53  name += ".csv";
54  }
55  QString filename = QFileDialog::getSaveFileName(this->m_parent, QObject::tr("Enregister sous... "), name, QObject::tr("Fichiers csv (*.csv)"));
56  QFile file(filename);
57  if( !filename.isEmpty() ) {
58  if(QFile::exists ( filename )){
59  // if file already exist -> delete it
60  if(!QFile::remove ( filename ) ){
62  QObject::tr("Impossible de remplacer le fichier!\n\n")+
63  "Destination : "+filename+"\n");
64  return false;
65  }
66  }
67  if (file.open(QIODevice::WriteOnly | QIODevice::Text)){
68  QTextStream stream(&file);
69  stream << getNomenclature() << endl;
70  }
71  else return false;
72  }
73  else return false;
74 
75  return true;
76 }
77 
84 {
85  //Process...
86  QString data = QObject::tr("NOMENCLATURE : ") + m_project -> title() + "\n\n";
87  data += QObject::tr("A001") +";" //:Don't translate this text! //ID for folio position in project
88  ""+ QObject::tr("B001") +";" //:Don't translate this text! //ID for folio title
89  ""+ QObject::tr("C001") +";" //:Don't translate this text! //ID for folio number
90  ""+ QObject::tr("D001") +";" //:Don't translate this text! //ID for qet designation
91  ""+ QObject::tr("E001") +";" //:Don't translate this text! //ID for position of element on the folio
92  ""+ QObject::tr("F001") +";" //:Don't translate this text! //ID for label of element
93  ""+ QObject::tr("F002") +";" //:Don't translate this text! //ID for label formula of element
94  ""+ QObject::tr("G001") +";" //:Don't translate this text! //ID for order number
95  ""+ QObject::tr("H001") +";" //:Don't translate this text! //ID for article description
96  ""+ QObject::tr("H002") +";" //:Don't translate this text! //ID for plant
97  ""+ QObject::tr("I001") +";" //:Don't translate this text! //ID for comment
98  ""+ QObject::tr("J001") +";" //:Don't translate this text! //ID for manufacturer
99  ""+ QObject::tr("K001") +";" //:Don't translate this text! //ID for article number
100  ""+ QObject::tr("L001") +";" //:Don't translate this text! //ID for quantity
101  ""+ QObject::tr("L002") +";" //:Don't translate this text! //ID for unity
102  ""+ QObject::tr("L003") +";" //:Don't translate this text! //ID for supplier
103  ""+ QObject::tr("M001") +";" //:Don't translate this text! //ID for auxiliary field 1
104  ""+ QObject::tr("M002") +";" //:Don't translate this text! //ID for auxiliary field 2
105  ""+ QObject::tr("N001")+";" //:Don't translate this text! //ID for internal number
106  ""+ QObject::tr("O001")+";" //:Don't translate this text! //ID for location
107  ""+ QObject::tr("P001") +"\n"; //:Don't translate this text! //ID for function
108  data += QObject::tr("Position du folio") +";"
109  ""+ QObject::tr("Titre de folio") +";"
110  ""+ QObject::tr("Numéro de folio") +";"
111  ""+ QObject::tr("Désignation qet") +";"
112  ""+ QObject::tr("Position") +";"
113  ""+ QObject::tr("Label") +";"
114  ""+ QObject::tr("Formule du label") +";"
115  ""+ QObject::tr("Désignation") +";"
116  ""+ QObject::tr("Description") +";"
117  ""+ QObject::tr("Installation") +";"
118  ""+ QObject::tr("Commentaire") +";"
119  ""+ QObject::tr("Fabricant") +";"
120  ""+ QObject::tr("Numéro de commande") +";"
121  ""+ QObject::tr("Fournisseur") +";"
122  ""+ QObject::tr("Quantité") +";"
123  ""+ QObject::tr("Unité") +";"
124  ""+ QObject::tr("Bloc auxiliaire 1") +";"
125  ""+ QObject::tr("Bloc auxiliaire 2") +";"
126  ""+ QObject::tr("Numéro interne") +";"
127  ""+ QObject::tr("Localisation") +";"
128  ""+ QObject::tr("Fonction") +"\n";
129 
130 
131  if(m_list_diagram.isEmpty()) return data;
132 
133  foreach (Diagram *d, m_list_diagram) {
134  //Get only simple, master and unlinked slave element.
135  ElementProvider ep(d);
136  QSettings settings;
137  QList <Element *> list_elements;
138 
139  if (settings.value("nomenclature/terminal-exportlist", true).toBool()){
140  list_elements << ep.find(Element::Simple | Element::Master | Element::Terminale);
141 
142  }else{
143 
144  list_elements << ep.find(Element::Simple | Element::Master);
145 
146  }
147 
148  list_elements << ep.freeElement(Element::Slave);
149 
150  foreach (Element *elmt, list_elements) {
151  data += getElementInfo(elmt);
152  }
153  }
154 
155  return data;
156 }
157 
164  QString info;
165 
166  Diagram *diagram = elmt -> diagram();
167  DiagramContext elmt_info = elmt -> elementInformations();
168  autonum::sequentialNumbers empty_seq;
169 
170  info += QString::number(diagram -> folioIndex()+1) + ";";
171  info += diagram -> title() + ";";
172  info += autonum::AssignVariables::formulaToLabel(diagram->border_and_titleblock.folio(), empty_seq, diagram) + ";";
173  info += elmt -> name() + ";";
174  info += elmt-> diagram()-> convertPosition(elmt -> scenePos()).toString() + ";";
175  info += autonum::AssignVariables::formulaToLabel(elmt_info["label"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
176  info += autonum::AssignVariables::formulaToLabel(elmt_info["formula"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
177  info += autonum::AssignVariables::formulaToLabel(elmt_info["designation"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
178  info += autonum::AssignVariables::formulaToLabel(elmt_info["description"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
179  info += autonum::AssignVariables::formulaToLabel(elmt_info["plant"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
180  info += autonum::AssignVariables::formulaToLabel(elmt_info["comment"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
181  info += autonum::AssignVariables::formulaToLabel(elmt_info["manufacturer"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
182  info += autonum::AssignVariables::formulaToLabel(elmt_info["manufacturer-reference"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
183  info += autonum::AssignVariables::formulaToLabel(elmt_info["supplier"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
184  info += autonum::AssignVariables::formulaToLabel(elmt_info["quantity"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
185  info += autonum::AssignVariables::formulaToLabel(elmt_info["unity"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
186  info += autonum::AssignVariables::formulaToLabel(elmt_info["auxiliary1"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
187  info += autonum::AssignVariables::formulaToLabel(elmt_info["auxiliary2"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
188  info += autonum::AssignVariables::formulaToLabel(elmt_info["machine-manufacturer-reference"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
189  info += autonum::AssignVariables::formulaToLabel(elmt_info["location"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + ";";
190  info += autonum::AssignVariables::formulaToLabel(elmt_info["function"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + "\n";
191 
192  return info;
193 }
QList< Element * > find(const int filter) const
ElementProvider::find Search and return the asked element corresponding with the given filter...
QList< Diagram * > m_list_diagram
Definition: nomenclature.h:40
static QString formulaToLabel(QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt=nullptr)
AssignVariables::formulaToLabel Return the with variable assigned (ready to be displayed) ...
QWidget * m_parent
Definition: nomenclature.h:41
bool saveToCSVFile()
QETProject * m_project
Definition: nomenclature.h:39
QString getNomenclature()
nomenclature::getNomenclature Create and formated a nomenclature to csv file.
Diagram * diagram() const
QetGraphicsItem::diagram return the diagram of this item.
autonum::sequentialNumbers & rSequenceStruct()
Definition: element.h:96
nomenclature(QETProject *project, QWidget *parent=nullptr)
QIcon tr
Definition: qeticons.cpp:204
QString folio() const
QList< Element * > freeElement(const int filter) const
ElementProvider::FreeElement Search and return the asked element corresponding with the given filter ...
virtual ~nomenclature()
QString getElementInfo(Element *elmt)
nomenclature::getElementInfo
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
Definition: diagram.h:74
QMessageBox::StandardButton critical(QWidget *, const QString &, const QString &, QMessageBox::StandardButtons=QMessageBox::Ok, QMessageBox::StandardButton=QMessageBox::NoButton)