Code_TYMPAN  4.4.0
Industrial site acoustic simulation
main.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 <qmessagebox.h>
22 #include <QDir>
23 
24 #include "Tympan/core/logging.h"
26 #include "TYApplication.h"
27 
28 static QtMessageHandler old_handler;
29 
30 static void MyQTMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message)
31 {
32  if (old_handler != NULL)
33  {
34  old_handler(type, context, message);
35  }
36 
37  switch (type)
38  {
39  case QtInfoMsg:
40  break;
41  case QtDebugMsg:
42  break;
43  case QtWarningMsg:
44  break;
45  case QtCriticalMsg:
46  case QtFatalMsg:
47  int selected = 0;
48 
49  selected = QMessageBox::critical(NULL, "Attention !", message, "Debug", "Continue", "Quit");
50 
51  if (selected == 0)
52  {
53  // Debug
54 #if defined(WIN32)
55  _CrtDbgBreak();
56 #endif
57  }
58  else if (selected == 1)
59  {
60  // Continue
61  }
62  else if (selected == 2)
63  {
64  // Quit
65  exit(1);
66  }
67  break;
68  }
69 }
70 
71 static int tyMain(int argc, char** argv)
72 {
73  bool success = false;
74 
75  old_handler = qInstallMessageHandler(MyQTMessageHandler);
76 
77  TYApplication tyApp(argc, argv);
78  if (tyApp.init())
79  {
80  // Lance la boucle principal
81  success = tyApp.run();
82 
83  // Termine correctement l'appli
84  tyApp.close();
85  }
86  OMessageManager::get()->debug("Counters : TYElements created %u, deleted %u and ID generated %u",
89  qInstallMessageHandler(old_handler);
90 
91  // return code
92  int ret = 0;
93  success ? ret = 0 : ret = 1;
94 
95  return ret;
96 }
97 
98 bool setenv(const char* pVarEnvName, QString& pVarEnvValue, bool pForceUpdate)
99 {
100  bool ret = true;
101  QString currentVarEnvValue = QString::fromLocal8Bit(qgetenv(pVarEnvName));
102  if (currentVarEnvValue != "" && !pForceUpdate)
103  {
104  OMessageManager::get()->info("Environment variable %s already set to : '%s'.\n", pVarEnvName,
105  currentVarEnvValue.toUtf8().data());
106  pVarEnvValue = currentVarEnvValue;
107  }
108  else
109  {
110  OMessageManager::get()->info("Trying to set environment variable %s to : '%s'.\n", pVarEnvName,
111  pVarEnvValue.toUtf8().data());
112  ret = qputenv(pVarEnvName, pVarEnvValue.toUtf8());
113  }
114  return ret;
115 }
116 
117 bool setenv()
118 {
119  bool ret = true;
120  const QChar SEP = QDir::listSeparator();
121 #ifdef _DEBUG
122  const char* PLUGINS = "/pluginsd";
123  const char* CYTHON = "/cython_d";
124 #else
125  const char* PLUGINS = "/plugins";
126  const char* CYTHON = "/cython";
127 #endif
128 
129  const QString TYMPAN_INSTALL_DIR = QDir::currentPath();
130  OMessageManager::get()->info("TYMPAN_INSTALL_DIR is '%s'.\n", TYMPAN_INSTALL_DIR.toUtf8().data());
131 
132  ret |= qputenv("PYTHONIOENCODING", "UTF8");
133 
134  QString TYMPAN_INSTALL_PATH = QString(TYMPAN_INSTALL_DIR);
135  ret |= setenv("TYMPAN_INSTALL_PATH", TYMPAN_INSTALL_PATH, false);
136 
137  QString PYTHONTYMPAN = TYMPAN_INSTALL_DIR + QString("/Python310");
138  ret |= setenv("PYTHONTYMPAN", PYTHONTYMPAN, false);
139 
140  QString TYMPAN_SOLVERDIR = TYMPAN_INSTALL_DIR + QString(PLUGINS);
141  ret |= setenv("TYMPAN_SOLVERDIR", TYMPAN_SOLVERDIR, false);
142 
143  QString CGAL_BINDINGS_PATH = TYMPAN_INSTALL_DIR + CYTHON + QString("/CGAL");
144  ret |= setenv("CGAL_BINDINGS_PATH", CGAL_BINDINGS_PATH, false);
145 
146  QString TYMPAN_PYTHON_INTERP = PYTHONTYMPAN + QString("/python.exe");
147  ret |= setenv("TYMPAN_PYTHON_INTERP", TYMPAN_PYTHON_INTERP, false);
148 
149  QString PYTHONPATH = TYMPAN_INSTALL_DIR + CYTHON + SEP + PYTHONTYMPAN + SEP + PYTHONTYMPAN + "/DLLs" +
150  SEP + PYTHONTYMPAN + "/Lib" + SEP + PYTHONTYMPAN + "/Lib/site-packages" + SEP +
151  TYMPAN_INSTALL_DIR;
152 
153  ret |= setenv("PYTHONPATH", PYTHONPATH, false);
154 
155  QString PATH = TYMPAN_INSTALL_DIR + SEP + PYTHONTYMPAN + SEP + PYTHONTYMPAN + "/DLLs" + SEP +
156  PYTHONTYMPAN + "/Lib" + SEP + PYTHONTYMPAN + "/Scripts";
157  ret |= setenv("PATH", PATH, true);
158 
159  QString LD_LIBRARY_PATH = TYMPAN_INSTALL_DIR + "/lib" + SEP + TYMPAN_INSTALL_DIR + CYTHON + SEP +
160  TYMPAN_INSTALL_DIR + CYTHON + QString("/CGAL");
161  ret |= setenv("LD_LIBRARY_PATH", LD_LIBRARY_PATH, false);
162 
163  ret |= setenv("PYTHONLEGACYWINDOWSSTDIO", QString("1"), false);
164 
165  return ret;
166 }
167 
168 int main(int argc, char** argv)
169 {
170  int ret = 0;
171  bool ret_setenv = true;
172  ret_setenv = setenv();
173  if (!ret_setenv)
174  {
175  OMessageManager::get()->info("Unable to set environment variables, closing application.");
176  return ret;
177  }
178  // Register TY* classes before starting the application
180  // Appel le main de Tympan
181  ret = tyMain(argc, argv);
182  return ret;
183 }
pour l'application Tympan (fichier header)
const char * SEP
virtual void debug(const char *message,...)
Definition: logging.cpp:151
static OMessageManager * get()
Definition: logging.cpp:108
virtual void info(const char *message,...)
Definition: logging.cpp:143
Classe principale pour l'application Tympan.
Definition: TYApplication.h:46
static uint64 getConstructorCount()
Definition: TYElement.cpp:634
static uint64 getIdGenerationCount()
Definition: TYElement.cpp:643
static uint64 getDestructorCount()
Definition: TYElement.cpp:638
int main(int argc, char **argv)
Definition: main.cpp:168
bool setenv(const char *pVarEnvName, QString &pVarEnvValue, bool pForceUpdate)
Definition: main.cpp:98
void init_registry()