source: src/UIElements/Qt4/QtUIFactory.cpp@ 704d59

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 704d59 was c13b91, checked in by Frederik Heber <heber@…>, 10 years ago

Gui is returning error code of 5 (in test mode) if (last) action failed.

  • this allows to take over return code checks in testsuite.
  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * QtUIFactory.cpp
25 *
26 * Created on: Jan 14, 2010
27 * Author: crueger
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <cassert>
36#include <iostream>
37#include <fstream>
38#include <string.h>
39
40#include <boost/filesystem/path.hpp>
41
42#include <Qt/qapplication.h>
43
44
45#include "UIElements/Qt4/QtUIFactory.hpp"
46#include "UIElements/Qt4/QtMainWindow.hpp"
47#include "UIElements/Qt4/QtDialog.hpp"
48
49// boost::python uses placement new which is incompatible with MemDebug.
50#ifdef HAVE_PYTHON
51#include "Python/PythonScripting.hpp"
52#endif
53
54#include "CodePatterns/MemDebug.hpp"
55
56#include "Helpers/defs.hpp"
57
58using namespace std;
59
60QtUIFactory::QtUIFactory(int _argc, char **_argv) :
61 argc(1),
62 argv(new char*[1]),
63 testlauncher_Interrupted(false),
64 testlauncher_thread(NULL)
65{
66
67 // check whether we are in test mode
68 if ((_argc > 1) && (isTestMode(_argv[1]))) {
69#ifdef HAVE_BOOST_THREAD_HPP
70 std::vector<std::string> scripts;
71 scripts.reserve(_argc-1);
72 for (int i=2;i<_argc;++i)
73 scripts.push_back(std::string(_argv[i]));
74
75 // check for line-by-line execution
76 const bool SingleLineStepping = (strncmp(&_argv[1][6], "single", 6) == 0);
77
78 // prepare an extra thread
79 std::cout << "TESTLAUNCHER: Preparing " << std::endl;
80 testlauncher_thread = new boost::thread(
81 boost::bind(&QtUIFactory::testrun, this, scripts, SingleLineStepping));
82#else
83 std::cerr << "Boost::thread support missing! Cannot launch test scripts.\n";
84#endif
85 // use fake commands to not pass test stuff
86 const int length = strlen(_argv[0]);
87 argv[0] = new char[length];
88 strncpy(_argv[0],_argv[0], length);
89 app = new QApplication(argc,argv);
90 } else {
91 app = new QApplication(_argc,_argv);
92 }
93}
94
95QtUIFactory::~QtUIFactory()
96{
97 if (testlauncher_thread != NULL) {
98 // notify testlauncher_thread thread that we wish to terminate
99 testlauncher_thread->interrupt();
100 // wait till it ends
101 testlauncher_thread->join();
102 // and remove
103 delete testlauncher_thread;
104 }
105 // free fake command line argument arrays
106 delete[] argv[0];
107 delete[] argv;
108}
109
110Dialog* QtUIFactory::makeDialog(const std::string &_title) {
111 return new QtDialog(_title);
112}
113
114MainWindow* QtUIFactory::makeMainWindow() {
115 return new QtMainWindow(app);
116}
117
118QtUIFactory::description::description(int _argc, char **_argv) :
119 UIFactory::factoryDescription("Qt4"),
120 argc(_argc),
121 argv(_argv)
122{}
123
124QtUIFactory::description::~description()
125{}
126
127UIFactory* QtUIFactory::description::makeFactory(){
128 return new QtUIFactory(argc, argv);
129}
130
131bool QtUIFactory::isTestMode(const char *_argument)
132{
133 return (strncmp(_argument,"--test", 6) == 0);
134}
135
136void QtUIFactory::testrun(const std::vector<std::string> _scripts, const bool _singleLineStepping) const
137{
138 std::cout << "TESTLAUNCHER: Waiting for GUI to set up" << std::endl;
139 testlauncher_sleep(boost::posix_time::seconds(3));
140
141 std::vector<std::string>::const_iterator scriptiter = _scripts.begin();
142 do {
143 // then launch script
144 std::cout << "TESTLAUNCHER: Launching script " << *scriptiter
145 << (_singleLineStepping ? " line by line." : ".") <<std::endl;
146#ifdef HAVE_PYTHON
147 if (_singleLineStepping) {
148 boost::filesystem::path scriptfilename(*scriptiter);
149 ASSERT( boost::filesystem::exists(scriptfilename),
150 "QtUIFactory::testrun() - given testmode script file "
151 +toString(scriptfilename.string())+" does not exist.");
152 std::ifstream scriptfile(scriptfilename.string().c_str());
153 std::string scriptfile_line;
154 const std::string testmode("testmode, line nr.");
155 unsigned int line_nr = 0;
156 while(std::getline(scriptfile, scriptfile_line)) {
157 std::string scriptname = testmode+toString(++line_nr);
158 executePythonScript(scriptfile_line, scriptname);
159 }
160 } else {
161 executePythonScriptFile(*scriptiter);
162 }
163#else
164 std::cerr << "Python support not compiled in, cannot execute gui test scripts.\n";
165#endif
166 ++scriptiter;
167
168 std::cout << "TESTLAUNCHER: Sleeping after script" << std::endl;
169 testlauncher_sleep(boost::posix_time::seconds(1.5));
170
171 } while ((scriptiter != _scripts.end()) && (!testlauncher_Interrupted));
172
173 // send quit signal
174 std::cout << "TESTLAUNCHER: Quitting" << std::endl;
175 app->quit(); // exit flag here is not relevant, end of main() sets the return code
176}
177
178void QtUIFactory::testlauncher_sleep(const boost::posix_time::time_duration& _period) const
179{
180 try {
181 // first sleep for four seconds
182#if BOOST_VERSION < 105000
183 testlauncher_thread->sleep(boost::get_system_time() + _period);
184#else
185 boost::this_thread::sleep_for(boost::chrono::seconds(4));
186#endif
187 } catch(boost::thread_interrupted &e) {
188 LOG(2, "INFO: testlauncher thread has received stop signal.");
189 }
190}
Note: See TracBrowser for help on using the repository browser.