Path: blob/main/src/utils/foxtools/MFXGroupBoxModule.cpp
169678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2006-2025 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 MFXGroupBoxModule.cpp14/// @author Pablo Alvarez Lopez15/// @date Dec 202116///17//18/****************************************************************************/1920/* =========================================================================21* included modules22* ======================================================================= */23#include <config.h>2425#include <utils/gui/div/GUIDesigns.h>26#include <utils/gui/images/GUIIconSubSys.h>27#include <utils/gui/windows/GUIAppEnum.h>28#include <netedit/frames/GNEFrame.h>29#include <netedit/GNEViewNet.h>30#include <netedit/GNEViewParent.h>31#include <netedit/GNEApplicationWindow.h>32#include <netedit/frames/GNETLSTable.h>3334#include "MFXGroupBoxModule.h"35#include "MFXButtonTooltip.h"363738// ===========================================================================39// FOX callback mapping40// ===========================================================================4142FXDEFMAP(MFXGroupBoxModule) MFXGroupBoxModuleMap[] = {43FXMAPFUNC(SEL_PAINT, 0, MFXGroupBoxModule::onPaint),44FXMAPFUNC(SEL_COMMAND, MID_GROUPBOXMODULE_COLLAPSE, MFXGroupBoxModule::onCmdCollapseButton),45FXMAPFUNC(SEL_COMMAND, MID_GROUPBOXMODULE_EXTEND, MFXGroupBoxModule::onCmdExtendButton),46FXMAPFUNC(SEL_COMMAND, MID_GROUPBOXMODULE_RESETWIDTH, MFXGroupBoxModule::onCmdResetButton),47FXMAPFUNC(SEL_COMMAND, MID_GROUPBOXMODULE_SAVE, MFXGroupBoxModule::onCmdSaveButton),48FXMAPFUNC(SEL_COMMAND, MID_GROUPBOXMODULE_LOAD, MFXGroupBoxModule::onCmdLoadButton),49FXMAPFUNC(SEL_UPDATE, MID_GROUPBOXMODULE_RESETWIDTH, MFXGroupBoxModule::onUpdResetButton),50};5152// Object implementation53FXIMPLEMENT(MFXGroupBoxModule, FXVerticalFrame, MFXGroupBoxModuleMap, ARRAYNUMBER(MFXGroupBoxModuleMap))5455// ===========================================================================56// method definitions57// ===========================================================================5859MFXGroupBoxModule::MFXGroupBoxModule(GNEFrame* frame, const std::string& text, const int options) :60FXVerticalFrame(frame->getContentFrame(), GUIDesignGroupBoxModule),61myOptions(options),62myFrameParent(frame),63myCollapsed(false) {64// build button and labels65FXHorizontalFrame* headerFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);66if (myOptions & Options::COLLAPSIBLE) {67myCollapseButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::COLLAPSE), this, MID_GROUPBOXMODULE_COLLAPSE, GUIDesignButtonMFXGroupBoxModule);68}69if (myOptions & Options::EXTENSIBLE) {70myExtendButton = new MFXButtonTooltip(headerFrame,71frame->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),72TL("Expand"), nullptr, this, MID_GROUPBOXMODULE_EXTEND, GUIDesignButtonMFXGroupBoxModuleExtend);73myExtendButton->setTipText(TL("Expand frame to show all contents"));74myResetWidthButton = new MFXButtonTooltip(headerFrame,75frame->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),76"", GUIIconSubSys::getIcon(GUIIcon::RESET), this, MID_GROUPBOXMODULE_RESETWIDTH, GUIDesignButtonMFXGroupBoxModule);77myResetWidthButton->setTipText(TL("Shrink frame to default width"));78}79if (myOptions & Options::SAVE) {80mySaveButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::SAVE), this, MID_GROUPBOXMODULE_SAVE, GUIDesignButtonMFXGroupBoxModule);81}82if (myOptions & Options::LOAD) {83myLoadButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::OPEN_NET), this, MID_GROUPBOXMODULE_LOAD, GUIDesignButtonMFXGroupBoxModule);84}85myLabel = new FXLabel(headerFrame, text.c_str(), nullptr, GUIDesignLabelMFXGroupBoxModule);86// build collapsable frame87myCollapsableFrame = new FXVerticalFrame(this, GUIDesignCollapsableFrame);88}899091MFXGroupBoxModule::MFXGroupBoxModule(FXVerticalFrame* contentFrame, const std::string& text, const int options) :92FXVerticalFrame(contentFrame, GUIDesignGroupBoxModuleExtendY),93myOptions(options),94myCollapsed(false) {95// build button and labels96FXHorizontalFrame* headerFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);97if (myOptions & Options::COLLAPSIBLE) {98myCollapseButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::COLLAPSE), this, MID_GROUPBOXMODULE_COLLAPSE, GUIDesignButtonMFXGroupBoxModule);99}100if (myOptions & Options::EXTENSIBLE) {101throw ProcessError("This MFXGroupBoxModule doesn't support Extensible flag");102}103if (myOptions & Options::SAVE) {104mySaveButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::SAVE), this, MID_GROUPBOXMODULE_SAVE, GUIDesignButtonMFXGroupBoxModule);105}106if (myOptions & Options::LOAD) {107myLoadButton = GUIDesigns::buildFXButton(headerFrame, "", "", "", GUIIconSubSys::getIcon(GUIIcon::OPEN_NET), this, MID_GROUPBOXMODULE_LOAD, GUIDesignButtonMFXGroupBoxModule);108}109myLabel = new FXLabel(headerFrame, text.c_str(), nullptr, GUIDesignLabelMFXGroupBoxModule);110// build collapsable frame111myCollapsableFrame = new FXVerticalFrame(this, GUIDesignCollapsableFrame);112}113114115MFXGroupBoxModule::~MFXGroupBoxModule() {}116117118void119MFXGroupBoxModule::setText(const std::string& text) {120myLabel->setText(text.c_str());121}122123124FXVerticalFrame*125MFXGroupBoxModule::getCollapsableFrame() {126return myCollapsableFrame;127}128129130long131MFXGroupBoxModule::onPaint(FXObject*, FXSelector, void* ptr) {132FXEvent* event = (FXEvent*)ptr;133FXDCWindow dc(this, event);134// Paint background135dc.setForeground(backColor);136dc.fillRectangle(event->rect.x, event->rect.y, event->rect.w, event->rect.h);137// draw groove rectangle138drawGrooveRectangle(dc, 0, 15, width, height - 15);139return 1;140}141142143long144MFXGroupBoxModule::onCmdCollapseButton(FXObject*, FXSelector, void*) {145if (myCollapsed) {146myCollapsed = false;147myCollapseButton->setIcon(GUIIconSubSys::getIcon(GUIIcon::COLLAPSE));148myCollapsableFrame->show();149} else {150myCollapsed = true;151myCollapseButton->setIcon(GUIIconSubSys::getIcon(GUIIcon::UNCOLLAPSE));152myCollapsableFrame->hide();153}154recalc();155return 1;156}157158159long160MFXGroupBoxModule::onCmdExtendButton(FXObject*, FXSelector, void*) {161if (myFrameParent) {162int maximumWidth = -1;163// iterate over all collapsableFrame childrens164for (auto child = myCollapsableFrame->getFirst(); child != nullptr; child = child->getNext()) {165// currently only for GNETLSTables166const auto TLSTable = dynamic_cast<GNETLSTable*>(child);167if (TLSTable) {168// get scrollbar width169const int scrollBarWidth = TLSTable->getTLSPhasesParent()->getTLSEditorParent()->getScrollBarWidth();170if ((TLSTable->getWidth() + scrollBarWidth) > maximumWidth) {171maximumWidth = (TLSTable->getWidth() + scrollBarWidth);172}173}174}175// set frame ara width176if (maximumWidth != -1) {177// add extra padding (30, constant, 15 left, 15 right)178myFrameParent->getViewNet()->getViewParent()->setFrameAreaWidth(maximumWidth + 30);179}180}181return 1;182}183184185long186MFXGroupBoxModule::onCmdResetButton(FXObject*, FXSelector, void*) {187if (myFrameParent) {188myFrameParent->getViewNet()->getViewParent()->setFrameAreaWidth(220);189}190return 1;191}192193194long195MFXGroupBoxModule::onUpdResetButton(FXObject* sender, FXSelector, void*) {196if (myFrameParent) {197if (myFrameParent->getViewNet()->getViewParent()->getFrameAreaWidth() == 220) {198sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);199} else {200sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);201}202}203return 1;204}205206207long208MFXGroupBoxModule::onCmdSaveButton(FXObject*, FXSelector, void*) {209return saveContents();210}211212213long214MFXGroupBoxModule::onCmdLoadButton(FXObject*, FXSelector, void*) {215return loadContents();216}217218219MFXGroupBoxModule::MFXGroupBoxModule() :220myOptions(Options::NOTHING),221myCollapsed(false) {222}223224225bool226MFXGroupBoxModule::saveContents() const {227// nothing to do228return false;229}230231232bool233MFXGroupBoxModule::loadContents() const {234// nothing to do235return false;236}237238239void240MFXGroupBoxModule::toggleSaveButton(const bool value) {241if (mySaveButton) {242if (value) {243mySaveButton->enable();244} else {245mySaveButton->disable();246}247}248}249250251