FXint GUILoadThread::run() { GUINet* net = 0; int simStartTime = 0; int simEndTime = 0; std::vector<std::string> guiSettingsFiles; bool osgView = false; OptionsCont& oc = OptionsCont::getOptions(); // register message callbacks MsgHandler::getMessageInstance()->addRetriever(myMessageRetriever); MsgHandler::getErrorInstance()->addRetriever(myErrorRetriever); MsgHandler::getWarningInstance()->addRetriever(myWarningRetriever); // try to load the given configuration if (!initOptions()) { // the options are not valid but maybe we want to quit GUIGlobals::gQuitOnEnd = oc.getBool("quit-on-end"); submitEndAndCleanup(net, simStartTime, simEndTime); return 0; } // within gui-based applications, nothing is reported to the console MsgHandler::getMessageInstance()->removeRetriever(&OutputDevice::getDevice("stdout")); MsgHandler::getWarningInstance()->removeRetriever(&OutputDevice::getDevice("stderr")); MsgHandler::getErrorInstance()->removeRetriever(&OutputDevice::getDevice("stderr")); // do this once again to get parsed options MsgHandler::initOutputOptions(); XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net")); GUIGlobals::gRunAfterLoad = oc.getBool("start"); GUIGlobals::gQuitOnEnd = oc.getBool("quit-on-end"); if (!MSFrame::checkOptions()) { MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); submitEndAndCleanup(net, simStartTime, simEndTime); return 0; } // initialise global settings RandHelper::initRandGlobal(); RandHelper::initRandGlobal(&MSVehicleControl::myVehicleParamsRNG); MSFrame::setMSGlobals(oc); GUITexturesHelper::allowTextures(!oc.getBool("disable-textures")); MSVehicleControl* vehControl = 0; #ifdef HAVE_INTERNAL GUIVisualizationSettings::UseMesoSim = MSGlobals::gUseMesoSim; if (MSGlobals::gUseMesoSim) { vehControl = new GUIMEVehicleControl(); } else #endif vehControl = new GUIVehicleControl(); GUIEdgeControlBuilder* eb = 0; try { net = new GUINet( vehControl, new GUIEventControl(), new GUIEventControl(), new GUIEventControl()); eb = new GUIEdgeControlBuilder(); GUIDetectorBuilder db(*net); NLJunctionControlBuilder jb(*net, db); GUITriggerBuilder tb; NLHandler handler("", *net, db, tb, *eb, jb); tb.setHandler(&handler); NLBuilder builder(oc, *net, *eb, jb, db, handler); MsgHandler::getErrorInstance()->clear(); MsgHandler::getWarningInstance()->clear(); MsgHandler::getMessageInstance()->clear(); if (!builder.build()) { throw ProcessError(); } else { net->initGUIStructures(); simStartTime = string2time(oc.getString("begin")); simEndTime = string2time(oc.getString("end")); guiSettingsFiles = oc.getStringVector("gui-settings-file"); #ifdef HAVE_INTERNAL osgView = oc.getBool("osg-view"); #endif } } catch (ProcessError& e) { if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) { WRITE_ERROR(e.what()); } MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); delete net; net = 0; #ifndef _DEBUG } catch (std::exception& e) { WRITE_ERROR(e.what()); delete net; net = 0; #endif } if (net == 0) { MSNet::clearAll(); } delete eb; submitEndAndCleanup(net, simStartTime, simEndTime, guiSettingsFiles, osgView); return 0; }
FXint GUILoadThread::run() { GUINet *net = 0; int simStartTime = 0; int simEndTime = 0; // remove old options OptionsCont &oc = OptionsCont::getOptions(); oc.clear(); // within gui-based applications, nothing is reported to the console MsgHandler::getErrorInstance()->report2cout(false); MsgHandler::getErrorInstance()->report2cerr(false); MsgHandler::getWarningInstance()->report2cout(false); MsgHandler::getWarningInstance()->report2cerr(false); MsgHandler::getMessageInstance()->report2cout(false); MsgHandler::getMessageInstance()->report2cerr(false); // register message callbacks MsgHandler::getMessageInstance()->addRetriever(myMessageRetriever); MsgHandler::getErrorInstance()->addRetriever(myErrorRetriever); MsgHandler::getWarningInstance()->addRetriever(myWarningRetriever); // try to load the given configuration if (!initOptions()) { // the options are not valid submitEndAndCleanup(net, simStartTime, simEndTime); return 0; } MsgHandler::initOutputOptions(true); if (!MSFrame::checkOptions()) { // the options are not valid MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); submitEndAndCleanup(net, simStartTime, simEndTime); return 0; } RandHelper::initRandGlobal(); // try to load MSFrame::setMSGlobals(oc); net = new GUINet(new GUIVehicleControl(), new GUIEventControl(), new GUIEventControl(), new GUIEventControl()); GUIEdgeControlBuilder *eb = new GUIEdgeControlBuilder(GUIGlObjectStorage::gIDStorage); NLJunctionControlBuilder jb(*net, oc); GUIDetectorBuilder db(*net); GUIGeomShapeBuilder sb(*net, GUIGlObjectStorage::gIDStorage); GUITriggerBuilder tb; NLHandler handler("", *net, db, tb, *eb, jb, sb); tb.setHandler(&handler); NLBuilder builder(oc, *net, *eb, jb, db, handler); try { MsgHandler::getErrorInstance()->clear(); MsgHandler::getWarningInstance()->clear(); MsgHandler::getMessageInstance()->clear(); if (!builder.build()) { throw ProcessError(); } else { net->initGUIStructures(); simStartTime = string2time(oc.getString("begin")); simEndTime = string2time(oc.getString("end")); } } catch (ProcessError &e) { if (std::string(e.what())!=std::string("Process Error") && std::string(e.what())!=std::string("")) { MsgHandler::getErrorInstance()->inform(e.what()); } MsgHandler::getErrorInstance()->inform("Quitting (on error).", false); delete net; net = 0; #ifndef _DEBUG } catch (std::exception &e) { MsgHandler::getErrorInstance()->inform(e.what()); delete net; net = 0; #endif } if (net==0) { MSNet::clearAll(); } delete eb; submitEndAndCleanup(net, simStartTime, simEndTime); return 0; }
FXint GNELoadThread::run() { // register message callbacks MsgHandler::getMessageInstance()->addRetriever(myMessageRetriever); MsgHandler::getErrorInstance()->addRetriever(myErrorRetriever); MsgHandler::getWarningInstance()->addRetriever(myWarningRetriever); GNENet* net = 0; // try to load the given configuration OptionsCont& oc = OptionsCont::getOptions(); oc.clear(); if (!initOptions()) { submitEndAndCleanup(net); return 0; } MsgHandler::initOutputOptions(); if (!(NIFrame::checkOptions() && NBFrame::checkOptions() && NWFrame::checkOptions())) { // options are not valid WRITE_ERROR("Invalid Options. Nothing loaded"); submitEndAndCleanup(net); return 0; } MsgHandler::getErrorInstance()->clear(); MsgHandler::getWarningInstance()->clear(); MsgHandler::getMessageInstance()->clear(); RandHelper::initRandGlobal(); if (!GeoConvHelper::init(oc)) { WRITE_ERROR("Could not build projection!"); submitEndAndCleanup(net); return 0; } XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net")); // this netbuilder instance becomes the responsibility of the GNENet NBNetBuilder* netBuilder = new NBNetBuilder(); netBuilder->applyOptions(oc); if (myNewNet) { // create new network net = new GNENet(netBuilder); } else { NILoader nl(*netBuilder); try { nl.load(oc); if (!myLoadNet) { WRITE_MESSAGE("Performing initial computation ...\n"); // perform one-time processing (i.e. edge removal) netBuilder->compute(oc); // @todo remove one-time processing options! } else { // make coordinate conversion usable before first netBuilder->compute() GeoConvHelper::computeFinal(); } if (oc.getBool("ignore-errors")) { MsgHandler::getErrorInstance()->clear(); } // check whether any errors occured if (MsgHandler::getErrorInstance()->wasInformed()) { throw ProcessError(); } else { net = new GNENet(netBuilder); } } catch (ProcessError& e) { if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) { WRITE_ERROR(e.what()); } WRITE_ERROR("Failed to build network."); delete net; delete netBuilder; net = 0; } catch (std::exception& e) { WRITE_ERROR(e.what()); #ifdef _DEBUG throw; #endif delete net; delete netBuilder; net = 0; } } // only a single setting file is supported submitEndAndCleanup(net, oc.getString("gui-settings-file"), oc.getBool("registry-viewport")); return 0; }