Changeset 15e197
- Timestamp:
- Jun 10, 2015, 9:41:07 PM (10 years ago)
- Branches:
- 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
- Children:
- 0f0407
- Parents:
- 3054689
- git-author:
- Frederik Heber <heber@…> (05/13/15 18:20:52)
- git-committer:
- Frederik Heber <heber@…> (06/10/15 21:41:07)
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Qt4/QtUIFactory.cpp
r3054689 r15e197 37 37 #include <string.h> 38 38 39 #include <boost/filesystem/path.hpp> 40 39 41 #include <Qt/qapplication.h> 40 42 … … 44 46 #include "UIElements/Qt4/QtDialog.hpp" 45 47 48 // boost::python uses placement new which is incompatible with MemDebug. 49 #ifdef HAVE_PYTHON 50 #include "Python/PythonScripting.hpp" 51 #endif 52 46 53 #include "CodePatterns/MemDebug.hpp" 47 54 48 #include "version.h"49 55 #include "Helpers/defs.hpp" 50 56 51 57 using namespace std; 52 58 53 QtUIFactory::QtUIFactory() : 54 argc(1) 59 QtUIFactory::QtUIFactory(int _argc, char **_argv) : 60 argc(1), 61 argv(new char*[1]), 62 testlauncher_Interrupted(false), 63 testlauncher_thread(NULL) 55 64 { 56 // For now we just fake the command line parameters to make QT happy 57 argv = new char*[1]; 58 argv[0] = new char[256]; 59 strcpy(argv[0],MOLECUILDERVERSION); 60 app = new QApplication(argc,argv); 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 } 61 89 } 62 90 63 91 QtUIFactory::~QtUIFactory() 64 92 { 65 //delete app; 66 delete [] argv[0]; 67 delete [] argv; 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; 68 104 } 69 105 … … 76 112 } 77 113 78 QtUIFactory::description::description() : 79 UIFactory::factoryDescription("Qt4") 114 QtUIFactory::description::description(int _argc, char **_argv) : 115 UIFactory::factoryDescription("Qt4"), 116 argc(_argc), 117 argv(_argv) 80 118 {} 81 119 … … 84 122 85 123 UIFactory* QtUIFactory::description::makeFactory(){ 86 return new QtUIFactory( );124 return new QtUIFactory(argc, argv); 87 125 } 88 126 … … 91 129 return (strncmp(_argument,"--test", 6) == 0); 92 130 } 131 132 void 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 158 void 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 } -
src/UIElements/Qt4/QtUIFactory.hpp
r3054689 r15e197 17 17 #include "UIElements/UIFactory.hpp" 18 18 19 #include <boost/thread.hpp> 20 #include <string> 21 #include <vector> 22 19 23 class QApplication; 20 24 … … 30 34 31 35 struct description : public UIFactory::factoryDescription { 32 description( );36 description(int _argc, char **_argv); 33 37 virtual ~description(); 34 38 35 39 virtual UIFactory* makeFactory(); 36 }; 40 41 private: 42 int argc; 43 char **argv; 44 }; 37 45 virtual std::string getUIName(){ return "Qt4"; } 38 46 … … 40 48 41 49 protected: 42 QtUIFactory( );50 QtUIFactory(int _argc, char **_argv); 43 51 44 52 private: 45 // faked command line arguments 53 54 void testrun(const std::vector<std::string> _scripts) const; 55 56 void testlauncher_sleep(const boost::posix_time::time_duration& _period) const; 57 58 private: 59 QApplication *app; 60 46 61 int argc; 47 62 char **argv; 48 QApplication *app; 63 64 //!> internal flag to tell testlauncher_thread to stop 65 mutable bool testlauncher_Interrupted; 66 67 //!> internal thread to call Actions 68 boost::thread *testlauncher_thread; 49 69 }; 50 70 -
src/builder_init.cpp
r3054689 r15e197 150 150 ASSERT_DO(Assert::Ask); 151 151 LOG(0, "Setting UI to Qt4."); 152 UIFactory::registerFactory(new QtUIFactory::description( ));152 UIFactory::registerFactory(new QtUIFactory::description(argc, argv)); 153 153 UIFactory::makeUserInterface("Qt4"); 154 154 #else
Note:
See TracChangeset
for help on using the changeset viewer.