Changeset 15e197


Ignore:
Timestamp:
Jun 10, 2015, 9:41:07 PM (10 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Command-line arguments are passed to QApplication inside QtUIFactory.

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/QtUIFactory.cpp

    r3054689 r15e197  
    3737#include <string.h>
    3838
     39#include <boost/filesystem/path.hpp>
     40
    3941#include <Qt/qapplication.h>
    4042
     
    4446#include "UIElements/Qt4/QtDialog.hpp"
    4547
     48// boost::python uses placement new which is incompatible with MemDebug.
     49#ifdef HAVE_PYTHON
     50#include "Python/PythonScripting.hpp"
     51#endif
     52
    4653#include "CodePatterns/MemDebug.hpp"
    4754
    48 #include "version.h"
    4955#include "Helpers/defs.hpp"
    5056
    5157using namespace std;
    5258
    53 QtUIFactory::QtUIFactory() :
    54   argc(1)
     59QtUIFactory::QtUIFactory(int _argc, char **_argv) :
     60    argc(1),
     61    argv(new char*[1]),
     62    testlauncher_Interrupted(false),
     63    testlauncher_thread(NULL)
    5564{
    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  }
    6189}
    6290
    6391QtUIFactory::~QtUIFactory()
    6492{
    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;
    68104}
    69105
     
    76112}
    77113
    78 QtUIFactory::description::description() :
    79     UIFactory::factoryDescription("Qt4")
     114QtUIFactory::description::description(int _argc, char **_argv) :
     115    UIFactory::factoryDescription("Qt4"),
     116    argc(_argc),
     117    argv(_argv)
    80118{}
    81119
     
    84122
    85123UIFactory* QtUIFactory::description::makeFactory(){
    86   return new QtUIFactory();
     124  return new QtUIFactory(argc, argv);
    87125}
    88126
     
    91129  return (strncmp(_argument,"--test", 6) == 0);
    92130}
     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}
  • src/UIElements/Qt4/QtUIFactory.hpp

    r3054689 r15e197  
    1717#include "UIElements/UIFactory.hpp"
    1818
     19#include <boost/thread.hpp>
     20#include <string>
     21#include <vector>
     22
    1923class QApplication;
    2024
     
    3034
    3135  struct description : public UIFactory::factoryDescription {
    32     description();
     36    description(int _argc, char **_argv);
    3337    virtual ~description();
    3438
    3539    virtual UIFactory* makeFactory();
    36   };
     40
     41  private:
     42    int argc;
     43    char **argv;
     44 };
    3745  virtual std::string getUIName(){  return "Qt4";  }
    3846
     
    4048
    4149protected:
    42   QtUIFactory();
     50  QtUIFactory(int _argc, char **_argv);
    4351
    4452private:
    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
     58private:
     59  QApplication *app;
     60
    4661  int argc;
    4762  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;
    4969};
    5070
  • src/builder_init.cpp

    r3054689 r15e197  
    150150      ASSERT_DO(Assert::Ask);
    151151      LOG(0, "Setting UI to Qt4.");
    152       UIFactory::registerFactory(new QtUIFactory::description());
     152      UIFactory::registerFactory(new QtUIFactory::description(argc, argv));
    153153      UIFactory::makeUserInterface("Qt4");
    154154    #else
Note: See TracChangeset for help on using the changeset viewer.