source: src/UIElements/Qt4/QtUIFactory.cpp@ 15e197

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 15e197 was 15e197, checked in by Frederik Heber <heber@…>, 10 years ago

Command-line arguments are passed to QApplication inside QtUIFactory.

  • Property mode set to 100644
File size: 4.7 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 <string.h>
38
39#include <boost/filesystem/path.hpp>
40
41#include <Qt/qapplication.h>
42
43
44#include "UIElements/Qt4/QtUIFactory.hpp"
45#include "UIElements/Qt4/QtMainWindow.hpp"
46#include "UIElements/Qt4/QtDialog.hpp"
47
48// boost::python uses placement new which is incompatible with MemDebug.
49#ifdef HAVE_PYTHON
50#include "Python/PythonScripting.hpp"
51#endif
52
53#include "CodePatterns/MemDebug.hpp"
54
55#include "Helpers/defs.hpp"
56
57using namespace std;
58
59QtUIFactory::QtUIFactory(int _argc, char **_argv) :
60 argc(1),
61 argv(new char*[1]),
62 testlauncher_Interrupted(false),
63 testlauncher_thread(NULL)
64{
65
66 // check whether we are in test mode
67 if ((_argc > 1) && (isTestMode(_argv[1]))) {
68#ifdef HAVE_BOOST_THREAD_HPP
69 std::vector<std::string> scripts;
70 scripts.reserve(_argc-1);
71 for (int i=2;i<_argc;++i)
72 scripts.push_back(std::string(_argv[i]));
73
74 // prepare an extra thread
75 std::cout << "TESTLAUNCHER: Preparing " << std::endl;
76 testlauncher_thread = new boost::thread(
77 boost::bind(&QtUIFactory::testrun, this, scripts));
78#else
79 std::cerr << "Boost::thread support missing! Cannot launch test scripts.\n";
80#endif
81 // use fake commands to not pass test stuff
82 const int length = strlen(_argv[0]);
83 argv[0] = new char[length];
84 strncpy(_argv[0],_argv[0], length);
85 app = new QApplication(argc,argv);
86 } else {
87 app = new QApplication(_argc,_argv);
88 }
89}
90
91QtUIFactory::~QtUIFactory()
92{
93 if (testlauncher_thread != NULL) {
94 // notify testlauncher_thread thread that we wish to terminate
95 testlauncher_thread->interrupt();
96 // wait till it ends
97 testlauncher_thread->join();
98 // and remove
99 delete testlauncher_thread;
100 }
101 // free fake command line argument arrays
102 delete[] argv[0];
103 delete[] argv;
104}
105
106Dialog* QtUIFactory::makeDialog(const std::string &_title) {
107 return new QtDialog(_title);
108}
109
110MainWindow* QtUIFactory::makeMainWindow() {
111 return new QtMainWindow(app);
112}
113
114QtUIFactory::description::description(int _argc, char **_argv) :
115 UIFactory::factoryDescription("Qt4"),
116 argc(_argc),
117 argv(_argv)
118{}
119
120QtUIFactory::description::~description()
121{}
122
123UIFactory* QtUIFactory::description::makeFactory(){
124 return new QtUIFactory(argc, argv);
125}
126
127bool QtUIFactory::isTestMode(const char *_argument)
128{
129 return (strncmp(_argument,"--test", 6) == 0);
130}
131
132void QtUIFactory::testrun(const std::vector<std::string> _scripts) const
133{
134 std::cout << "TESTLAUNCHER: Waiting for GUI to set up" << std::endl;
135 testlauncher_sleep(boost::posix_time::seconds(3));
136
137 std::vector<std::string>::const_iterator scriptiter = _scripts.begin();
138 do {
139 // then launch script
140 std::cout << "TESTLAUNCHER: Launching script " << *scriptiter << std::endl;
141 boost::filesystem::path scriptfilename(*scriptiter);
142 ASSERT( boost::filesystem::exists(scriptfilename),
143 "QtUIFactory::testrun() - given testmode script file "
144 +toString(scriptfilename.string())+" does not exist.");
145 executePythonScriptFile(scriptfilename);
146 ++scriptiter;
147
148 std::cout << "TESTLAUNCHER: Sleeping after script" << std::endl;
149 testlauncher_sleep(boost::posix_time::seconds(1.5));
150
151 } while ((scriptiter != _scripts.end()) && (!testlauncher_Interrupted));
152
153 // send quit signal
154 std::cout << "TESTLAUNCHER: Quitting" << std::endl;
155 app->quit();
156}
157
158void QtUIFactory::testlauncher_sleep(const boost::posix_time::time_duration& _period) const
159{
160 try {
161 // first sleep for four seconds
162#if BOOST_VERSION < 105000
163 testlauncher_thread->sleep(boost::get_system_time() + _period);
164#else
165 boost::this_thread::sleep_for(boost::chrono::seconds(4));
166#endif
167 } catch(boost::thread_interrupted &e) {
168 LOG(2, "INFO: testlauncher thread has received stop signal.");
169 }
170}
Note: See TracBrowser for help on using the repository browser.