Path: blob/main/src/netedit/dialogs/run/GNERunDialog.cpp
193674 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNERunDialog.cpp14/// @author Pablo Alvarez Lopez15/// @date Aug 202516///17// Abstract dialog for running tools18/****************************************************************************/1920#include <netedit/GNEApplicationWindow.h>21#include <netedit/GNEExternalRunner.h>22#include <utils/gui/div/GUIDesigns.h>23#include <utils/gui/events/GUIEvent_Message.h>2425#include "GNERunDialog.h"2627// ===========================================================================28// FOX callback mapping29// ===========================================================================3031FXDEFMAP(GNERunDialog) GNERunDialogMap[] = {32FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_SAVE, GNERunDialog::onCmdSaveLog),33FXMAPFUNC(FXEX::SEL_THREAD_EVENT, ID_LOADTHREAD_EVENT, GNERunDialog::onThreadEvent),34FXMAPFUNC(FXEX::SEL_THREAD, ID_LOADTHREAD_EVENT, GNERunDialog::onThreadEvent)35};3637// Object implementation38FXIMPLEMENT_ABSTRACT(GNERunDialog, GNEDialog, GNERunDialogMap, ARRAYNUMBER(GNERunDialogMap))3940// ============================================-===============================41// member method definitions42// ===========================================================================4344GNERunDialog::GNERunDialog(GNEApplicationWindow* applicationWindow, const std::string& name,45GUIIcon titleIcon, const bool closeIfSucess) :46GNEDialog(applicationWindow, name, titleIcon, DialogType::RUN, GNEDialog::Buttons::RERUN_BACK_OK,47OpenType::MODAL, GNEDialog::ResizeMode::RESIZABLE, 640, 480),48myCloseIfSucess(closeIfSucess) {49// build the thread - io50myThreadEvent.setTarget(this);51myThreadEvent.setSelector(ID_LOADTHREAD_EVENT);52// create header frame53auto headerFrame = new FXHorizontalFrame(myContentFrame, GUIDesignHorizontalFrame);54// adjust padding55headerFrame->setPadLeft(0);56headerFrame->setPadRight(0);57GUIDesigns::buildFXButton(headerFrame, "", "", + TL("Save output"), GUIIconSubSys::getIcon(GUIIcon::SAVE),58this, MID_GNE_BUTTON_SAVE, GUIDesignButtonIcon);59new FXLabel(headerFrame, TL("Console output"), nullptr, GUIDesignLabelThick(JUSTIFY_LEFT));60// create text61auto textFrame = new FXVerticalFrame(myContentFrame, GUIDesignFrameThick);62myText = new FXText(textFrame, 0, 0, (TEXT_READONLY | LAYOUT_FILL_X | LAYOUT_FILL_Y));63// set styled64myText->setHiliteStyles(GUIMessageWindow::getStyles());65myText->setStyled(true);66// update dialog button67updateDialogButtons();68}697071GNERunDialog::~GNERunDialog() {}727374void75GNERunDialog::addEvent(GUIEvent* event, const bool signal) {76// add event to queue77myEvents.push_back(event);78// signal thread event79if (signal) {80myThreadEvent.signal();81}82}838485long86GNERunDialog::onCmdAbort(FXObject*, FXSelector, void*) {87// abort external runner88myApplicationWindow->getExternalRunner()->abort();89// hide dialog90return closeDialogCanceling();91}929394long95GNERunDialog::onCmdRun(FXObject*, FXSelector, void*) {96if (myApplicationWindow->getExternalRunner()->isRunning()) {97// abort external runner98myApplicationWindow->getExternalRunner()->abort();99} else {100// add line and info101std::string line = "--------------------Rerun--------------------\n";102myText->appendStyledText(line.c_str(), (int)line.length(), 1, TRUE);103myText->layout();104myText->update();105myWarning = false;106myError = false;107// update dialog button before running108updateDialogButtons();109// abort external runner110myApplicationWindow->getExternalRunner()->runTool(this);111}112return 1;113}114115116long117GNERunDialog::onCmdSaveLog(FXObject*, FXSelector, void*) {118// create fileDialog119const GNEFileDialog saveLogFileDialog(myApplicationWindow, this,120TL("tool log file"),121SUMOXMLDefinitions::TXTFileExtensions.getStrings(),122GNEFileDialog::OpenMode::SAVE,123GNEFileDialog::ConfigType::NETEDIT);124// check that file is valid125if (saveLogFileDialog.getResult() == GNEDialog::Result::ACCEPT) {126OutputDevice& dev = OutputDevice::getDevice(saveLogFileDialog.getFilename());127dev << myText->getText().text();128dev.close();129}130return 1;131}132133134long135GNERunDialog::onThreadEvent(FXObject*, FXSelector, void*) {136bool toolFinished = false;137while (!myEvents.empty()) {138// get the next event139GUIEvent* e = myEvents.top();140myEvents.pop();141// process142FXint style = -1;143switch (e->getOwnType()) {144case GUIEventType::TOOL_ENDED:145toolFinished = true;146break;147case GUIEventType::MESSAGE_OCCURRED:148style = 1;149break;150case GUIEventType::OUTPUT_OCCURRED:151style = 2;152break;153case GUIEventType::WARNING_OCCURRED:154style = 4;155myWarning = true;156break;157case GUIEventType::ERROR_OCCURRED:158style = 3;159myError = true;160break;161default:162break;163}164if (style >= 0) {165GUIEvent_Message* ec = static_cast<GUIEvent_Message*>(e);166myText->appendStyledText(ec->getMsg().c_str(), (int)ec->getMsg().length(), style, TRUE);167myText->layout();168myText->update();169}170delete e;171}172if (toolFinished) {173// analyze output to update flags174if (myText->getText().find("Warning") != -1) {175myWarning = true;176}177if (myText->getText().find("Error") != -1) {178myError = true;179}180// check if automatically close dialog181if (myCloseIfSucess && !myWarning && !myError) {182return onCmdAccept(nullptr, 0, nullptr);183}184}185updateDialogButtons();186return 1;187}188189190void191GNERunDialog::updateDialogButtons() {192// update buttons193if (myApplicationWindow->getExternalRunner()->isRunning()) {194// update run button195myRunButton->setText(TL("Abort"));196myRunButton->setTipText(TL("Abort running"));197myRunButton->setIcon(GUIIconSubSys::getIcon(GUIIcon::STOP));198// disable buttons199myBackButton->disable();200myAcceptButton->disable();201} else {202// update run button203myRunButton->setText(TL("Rerun"));204myRunButton->setTipText(TL("Rerun tool"));205myRunButton->setIcon(GUIIconSubSys::getIcon(GUIIcon::START));206// enable buttons207myBackButton->enable();208myAcceptButton->enable();209}210// update dialog211GNEDialog::update();212}213214/****************************************************************************/215216217