[f4d063] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[d103d3] | 4 | * Copyright (C) 2010-2011 University of Bonn. All rights reserved.
|
---|
[f4d063] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * builder_init.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Dec 15, 2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
[f4d063] | 21 |
|
---|
[862b6a] | 22 | #include <iomanip>
|
---|
[4e855e] | 23 | #include <iostream>
|
---|
| 24 |
|
---|
[f4d063] | 25 | #include "Actions/ActionHistory.hpp"
|
---|
[949953] | 26 | #include "Actions/ActionExceptions.hpp"
|
---|
| 27 |
|
---|
| 28 | #include "builder_init.hpp"
|
---|
| 29 | #include "cleanUp.hpp"
|
---|
[f4d063] | 30 |
|
---|
[862b6a] | 31 | #include "CodePatterns/Log.hpp"
|
---|
[949953] | 32 |
|
---|
[862b6a] | 33 | #include "Graph/BondGraph.hpp"
|
---|
[949953] | 34 |
|
---|
[862b6a] | 35 | #include "Parser/ChangeTracker.hpp"
|
---|
| 36 | #include "Parser/FormatParserStorage.hpp"
|
---|
[949953] | 37 |
|
---|
| 38 | #include "UIElements/UIFactory.hpp"
|
---|
[862b6a] | 39 | #include "UIElements/CommandLineUI/CommandLineParser.hpp"
|
---|
[949953] | 40 | #include "UIElements/CommandLineUI/CommandLineUIFactory.hpp"
|
---|
[862b6a] | 41 | #ifdef USE_GUI_QT
|
---|
| 42 | #include "UIElements/Qt4/QtUIFactory.hpp"
|
---|
| 43 | #endif
|
---|
| 44 | #include "UIElements/TextUI/TextUIFactory.hpp"
|
---|
[949953] | 45 | #include "UIElements/MainWindow.hpp"
|
---|
[f4d063] | 46 |
|
---|
| 47 | #include "version.h"
|
---|
| 48 |
|
---|
[949953] | 49 | #include "World.hpp"
|
---|
| 50 |
|
---|
[f4d063] | 51 |
|
---|
| 52 | /** Print some initial information output the program.
|
---|
| 53 | *
|
---|
| 54 | */
|
---|
| 55 | void ProgramHeader()
|
---|
| 56 | {
|
---|
| 57 | // print version check and copyright notice
|
---|
| 58 | cout << MOLECUILDERVERSION << endl;
|
---|
| 59 | cout << "MoleCuilder comes with ABSOLUTELY NO WARRANTY; for details type" << endl;
|
---|
| 60 | cout << "`molecuilder --warranty'." << endl;
|
---|
| 61 | cout << "`MoleCuilder - to create and alter molecular systems." << endl;
|
---|
| 62 | cout << "Copyright (C) 2010 University Bonn. All rights reserved." << endl;
|
---|
[ad7270] | 63 | cout << endl;
|
---|
[f4d063] | 64 | }
|
---|
| 65 |
|
---|
| 66 | /** General stuff to intialize before UI.
|
---|
| 67 | *
|
---|
| 68 | */
|
---|
| 69 | void initGeneral()
|
---|
| 70 | {
|
---|
| 71 | // while we are non interactive, we want to abort from asserts
|
---|
| 72 | ASSERT_DO(Assert::Abort);
|
---|
| 73 | ASSERT_HOOK(dumpMemory);
|
---|
| 74 |
|
---|
| 75 | ProgramHeader();
|
---|
| 76 |
|
---|
[ad7270] | 77 | setVerbosity(1);
|
---|
[f4d063] | 78 | // need to init the history before any action is created
|
---|
[ce7fdc] | 79 | MoleCuilder::ActionHistory::init();
|
---|
[f4d063] | 80 |
|
---|
| 81 | // from this moment on, we need to be sure to deeinitialize in the correct order
|
---|
| 82 | // this is handled by the cleanup function
|
---|
| 83 | atexit(cleanUp);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /** Initialize specific UIFactory.
|
---|
| 87 | *
|
---|
| 88 | * @param argc argument count
|
---|
| 89 | * @param argv argument array
|
---|
| 90 | */
|
---|
| 91 | void initUI(int argc, char **argv)
|
---|
| 92 | {
|
---|
| 93 | std::string BondGraphFileName("\n");
|
---|
| 94 | // Parse command line options and if present create respective UI
|
---|
| 95 | // construct bond graph
|
---|
[f71baf] | 96 | if (boost::filesystem::exists(BondGraphFileName)) {
|
---|
| 97 | std::ifstream input(BondGraphFileName.c_str());
|
---|
| 98 | if ((input.good()) && (World::getInstance().getBondGraph()->LoadBondLengthTable(input))) {
|
---|
[47d041] | 99 | LOG(0, "Bond length table loaded successfully.");
|
---|
[f71baf] | 100 | } else {
|
---|
[47d041] | 101 | ELOG(1, "Bond length table loading failed.");
|
---|
[f4d063] | 102 | }
|
---|
[f71baf] | 103 | input.close();
|
---|
[f4d063] | 104 | }
|
---|
| 105 | // handle remaining arguments by CommandLineParser
|
---|
| 106 | if (argc>1) {
|
---|
[47d041] | 107 | LOG(0, "Setting UI to CommandLine.");
|
---|
[f4d063] | 108 | CommandLineParser::getInstance().InitializeCommandArguments();
|
---|
| 109 | CommandLineParser::getInstance().Run(argc,argv);
|
---|
| 110 | UIFactory::registerFactory(new CommandLineUIFactory::description());
|
---|
| 111 | UIFactory::makeUserInterface("CommandLine");
|
---|
| 112 | } else {
|
---|
| 113 | // In the interactive mode, we can leave the user the choice in case of error
|
---|
| 114 | ASSERT_DO(Assert::Ask);
|
---|
| 115 | #ifdef USE_GUI_QT
|
---|
[47d041] | 116 | LOG(0, "Setting UI to Qt4.");
|
---|
[f4d063] | 117 | UIFactory::registerFactory(new QtUIFactory::description());
|
---|
| 118 | UIFactory::makeUserInterface("Qt4");
|
---|
| 119 | #else
|
---|
[47d041] | 120 | LOG(0, "Setting UI to Text.");
|
---|
[f4d063] | 121 | cout << MOLECUILDERVERSION << endl;
|
---|
| 122 | UIFactory::registerFactory(new TextUIFactory::description());
|
---|
| 123 | UIFactory::makeUserInterface("Text");
|
---|
| 124 | #endif
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | /** Create MainWindow and displays.
|
---|
| 129 | * I.e. here all the Actions are parsed and done.
|
---|
| 130 | */
|
---|
| 131 | void doUI()
|
---|
| 132 | {
|
---|
| 133 | MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
|
---|
[e69c87] | 134 | try {
|
---|
| 135 | mainWindow->display();
|
---|
| 136 | } catch(ActionFailureException &e) {
|
---|
| 137 | std::cerr << "Action " << *boost::get_error_info<ActionNameString>(e) << " has failed." << std::endl;
|
---|
| 138 | World::getInstance().setExitFlag(5);
|
---|
| 139 | }
|
---|
[f4d063] | 140 | delete mainWindow;
|
---|
| 141 | }
|
---|
| 142 |
|
---|