Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYCreateElementDialog.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
21 #include <qlayout.h>
22 #include <qmessagebox.h>
23 #include <qlabel.h>
24 #include <qpushbutton.h>
25 #include <qlistwidget.h>
26 
27 #include "Tympan/core/exceptions.h"
28 #include "Tympan/core/logging.h"
32 #include "TYCreateElementDialog.h"
33 
34 #define TR(id) OLocalizator::getString("TYCreateElementDialog", (id))
35 
36 #ifdef _DEBUG
38  #if WITH_NMPB
39 static const int nbMainElts = 60;
40  #else
41 static const int nbMainElts = 59;
42  #endif
43 
45 static char const* _listMainElement[] = {"TYAcousticBox",
46  "TYAcousticCircle",
47  "TYAcousticCylinder",
48  "TYAcousticLine",
49  "TYAcousticPolygon", /*01*/
50  "TYAcousticRectangleNode",
51  "TYAcousticRectangle",
52  "TYAcousticSemiCircle",
53  "TYAcousticSemiCylinder",
54  "TYAcousticSurfaceNode", /*02*/
55  "TYAcousticSurface",
56  "TYBoucheSurface",
57  "TYChemineeSurface",
58  "TYAcousticVolumeNode",
59  "TYAcousticVolume", /*03*/
60  "TYAltimetrie",
61  "TYAttenuateur",
62  "TYBatiment",
63  "TYBox", /*04*/
64  "TYCalcul",
65  "TYCourbeNiveau",
66  "TYCoursEau",
67  "TYDalle",
68  "TYDirectivity", /*05*/
69  "TYElement",
70  "TYEtage",
71  "TYInfrastructure",
72  "TYLinearMaillage",
73  "TYMachine", /*06*/
74  "TYMaillage",
75  "TYMateriauConstruction",
76  "TYMurElement",
77  "TYMur",
78  "TYParoi", /*07*/
79  "TYPlanEau",
80  "TYPointCalcul",
81  "TYPointControl",
82  "TYPoint",
83  "TYPolygon", /*08*/
84  "TYProjet",
85  "TYRectangle",
86  "TYRectangularMaillage",
87  "TYRepere",
88  "TYReseauTransport", /*09*/
89  "TYResultat",
90  #if WITH_NMPB
91  "TYRoute",
92  #endif
93  "TYSegment",
94  "TYSiteNode",
95  "TYSol", /*10*/
96  "TYSourceLineic",
97  "TYSourcePonctuelle",
98  "TYSourceBafflee",
99  "TYSourceCheminee",
100  "TYSourceSurfacic", /*11*/
101  "TYSource",
102  "TYSpectre",
103  "TYTerrain",
104  "TYTopographie",
105  "TYTrafic", /*12*/
106  "TYVegetation"};
107 #else // _DEBUG
109 static const int nbMainElts = 13;
110 
112 static char const* _listMainElement[] = {"TYProjet", "TYSiteNode",
113  "TYBatiment", "TYMachine",
114  "TYSpectre", /*1*/
115  "TYAttenuateur", "TYMateriauConstruction",
116  "TYSol", "TYParoi", /*2*/
117  "TYVegetation", "TYSourcePonctuelle",
118  "TYSourceBafflee", "TYSourceCheminee"};
119 #endif // _DEBUG
120 
121 TYCreateElementDialog::TYCreateElementDialog(QWidget* parent, const char* name, Qt::WindowFlags f)
122  : QDialog(parent, f)
123 {
124  setObjectName(name);
125  setWindowTitle(TR("id_caption"));
126 
127  // Layout
128  QGridLayout* pLayout = new QGridLayout();
129  setLayout(pLayout);
130 
131  _pElementChoiceListBox = new QListWidget(this);
132  _pElementChoiceListBox->setSelectionMode(QAbstractItemView::SingleSelection);
133  pLayout->addWidget(_pElementChoiceListBox, 0, 0);
134 
135  // On rempli la liste
136  for (int i = 0; i < nbMainElts; i++)
137  {
138  _pElementChoiceListBox->insertItem(
139  i, new QListWidgetItem(OLocalizator::getString("DisplayName", _listMainElement[i])));
140  }
141 
142  QBoxLayout* pBtnLayout = new QHBoxLayout();
143  pLayout->addLayout(pBtnLayout, 1, 0);
144 
145  pBtnLayout->addStretch(1);
146 
147  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), this);
148  pButtonOK->setDefault(true);
149  QObject::connect(pButtonOK, &QPushButton::clicked, this, &TYCreateElementDialog::accept);
150  pBtnLayout->addWidget(pButtonOK);
151 
152  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), this);
153  pButtonCancel->setShortcut(Qt::Key_Escape);
154  QObject::connect(pButtonCancel, &QPushButton::clicked, this, &TYCreateElementDialog::reject);
155  pBtnLayout->addWidget(pButtonCancel);
156 
157  TYPreferenceManager::loadGeometryFromPreferences(metaObject()->className(), this);
158 }
159 
161 {
162  TYPreferenceManager::saveGeometryToPreferences(metaObject()->className(), this);
163 }
164 
166 {
167  LPTYElement pElt;
168  try
169  {
170  pElt = dynamic_cast<TYElement*>(TYElement::findAndClone(eltType.toLatin1()));
171  }
172  catch (tympan::invalid_data&)
173  {
174  pElt = nullptr;
175  }
176 
177  if (pElt != nullptr)
178  {
179  TYOpenElementDialog* pOpenDlg = new TYOpenElementDialog(this);
180  pOpenDlg->openElement(pElt);
181  }
182 }
183 
185 {
186  if (r == Accepted)
187  {
188  createElement(_listMainElement[_pElementChoiceListBox->currentRow()]);
189  }
190 
191  QDialog::done(r);
192 }
#define TR(id)
Boite de dialogue pour la creation d'un nouvel element metier. L'element cree peut etre sauvegarde en...
Boite de dialogue pour le chargement d'un element metier (fichier header)
const char * name
static QString getString(const QString &classname, const QString &stringId)
static OPrototype * findAndClone(const char *className)
Definition: TYElement.cpp:37
virtual void done(int r)
Ce slot est appele lorsqu'on valide un choix de la boite de dialogue.
virtual ~TYCreateElementDialog()
Destructeur.
TYCreateElementDialog(QWidget *parent=0, const char *name=0, Qt::WindowFlags f=QFlag(0))
Constructeur par defaut.
void createElement(QString eltType)
Gere la creation d'un nouvel element au sein de l'application.
QListWidget * _pElementChoiceListBox
Boite de dialogue pour le chargement d'un element metier. L'element peut etre ouvert dans un modeleur...
void openElement(LPTYElement pElt)
Utilities to handle exceptions and to pretty-print value.
The base exception class for errors due to invalid data.
Definition: exceptions.h:60