/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-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 GNEChange.h14/// @author Jakob Erdmann15/// @date Mar 201116///17// The reification of a netedit editing operation (see command pattern)18// inherits from FXCommand and is used to for undo/redo19/****************************************************************************/20#pragma once21#include <config.h>2223#include <netbuild/NBEdge.h>24#include <netbuild/NBNode.h>25#include <netedit/GNEViewNet.h>26#include <netedit/elements/GNEHierarchicalStructureParents.h>27#include <netedit/elements/additional/GNETAZSourceSink.h>28#include <netedit/elements/data/GNEGenericData.h>29#include <netedit/elements/demand/GNEDemandElement.h>30#include <netedit/elements/network/GNEEdge.h>31#include <netedit/elements/network/GNEJunction.h>32#include <netedit/elements/network/GNELane.h>33#include <utils/foxtools/fxheader.h>34#include <utils/geom/PositionVector.h>35#include <utils/xml/SUMOXMLDefinitions.h>3637// ===========================================================================38// class declarations39// ===========================================================================40class GNEHierarchicalElement;41class GNEAttributeCarrier;42class GNEDataSet;43class GNEDataInterval;44class GNEMeanData;45class GNENet;46class GNEViewNet;4748// ===========================================================================49// class definitions50// ===========================================================================51/**52* @class GNEChange53* @brief the function-object for an editing operation (abstract base)54*/55class GNEChange : public FXObject {56FXDECLARE_ABSTRACT(GNEChange)5758public:59/// @name friend class60friend class GNEChangeGroup;61friend class GNEUndoList;6263/**@brief Constructor64* @param[in] supermode related with this change65* @param[in] forward The direction of this change66* @param[in] selectedElement flag to mark if element is selected67*/68GNEChange(Supermode supermode, bool forward, const bool selectedElement);6970/**@brief Constructor71* @param[in] supermode related with this change72* @param[in] element hierarchical element73* @param[in] forward The direction of this change74* @param[in] selectedElement flag to mark if element is selected75*/76GNEChange(Supermode supermode, GNEHierarchicalElement* element, bool forward, const bool selectedElement);7778/// @brief Destructor79~GNEChange();8081/// @brief undo action/operation82virtual void undo() = 0;8384/// @brief redo action/operation85virtual void redo() = 0;8687/// @brief return undoName88virtual std::string undoName() const = 0;8990/// @brief return redoName91virtual std::string redoName() const = 0;9293/// @brief Return the size of the command group94virtual int size() const;9596/// @brief get supermode97Supermode getSupermode() const;9899/**100* @brief Return TRUE if this command can be merged with previous undo101* commands. This is useful to combine e.g. multiple consecutive102* single-character text changes into a single block change.103* The default implementation returns FALSE.104*/105bool canMerge() const;106107/**108* @brief Called by the undo system to try and merge the new incoming command109* with this command; should return TRUE if merging was possible.110* The default implementation returns FALSE.111*/112bool mergeWith(GNEChange* command);113114protected:115/// @brief FOX need this116GNEChange();117118/// @brief add given element in parents and children119template<typename T>120void addElementInParentsAndChildren(T* element) {121// add element in children122for (const auto& junction : myParents.get<GNEJunction*>()) {123GNEHierarchicalElement::insertChild(junction, element);124}125for (const auto& edge : myParents.get<GNEEdge*>()) {126GNEHierarchicalElement::insertChild(edge, element);127}128for (const auto& lane : myParents.get<GNELane*>()) {129GNEHierarchicalElement::insertChild(lane, element);130}131for (const auto& additional : myParents.get<GNEAdditional*>()) {132GNEHierarchicalElement::insertChild(additional, element);133}134for (const auto& sourceSink : myParents.get<GNETAZSourceSink*>()) {135GNEHierarchicalElement::insertChild(sourceSink, element);136}137for (const auto& demandElement : myParents.get<GNEDemandElement*>()) {138GNEHierarchicalElement::insertChild(demandElement, element);139}140for (const auto& genericData : myParents.get<GNEGenericData*>()) {141GNEHierarchicalElement::insertChild(genericData, element);142}143}144145/// @brief remove given element from parents and children146template<typename T>147void removeElementFromParentsAndChildren(T* element) {148// Remove element from parents149for (const auto& junction : myParents.get<GNEJunction*>()) {150GNEHierarchicalElement::removeChild(junction, element);151}152for (const auto& edge : myParents.get<GNEEdge*>()) {153GNEHierarchicalElement::removeChild(edge, element);154}155for (const auto& lane : myParents.get<GNELane*>()) {156GNEHierarchicalElement::removeChild(lane, element);157}158for (const auto& additional : myParents.get<GNEAdditional*>()) {159GNEHierarchicalElement::removeChild(additional, element);160}161for (const auto& sourceSink : myParents.get<GNETAZSourceSink*>()) {162GNEHierarchicalElement::removeChild(sourceSink, element);163}164for (const auto& demandElement : myParents.get<GNEDemandElement*>()) {165GNEHierarchicalElement::removeChild(demandElement, element);166}167for (const auto& genericData : myParents.get<GNEGenericData*>()) {168GNEHierarchicalElement::removeChild(genericData, element);169}170}171172/// @brief supermode related with this change173const Supermode mySupermode;174175/// @brief Hierarchical container with parents176const GNEHierarchicalStructureParents myParents;177178/// @brief we group antagonistic commands (create junction/delete junction) and keep them apart by this flag179bool myForward;180181/// @brief flag for check if element is selected182const bool mySelectedElement;183184private:185// @brief next GNEChange (can be access by GNEChangeGroup and GNEUndoList)186GNEChange* next;187188/// @brief Invalidated copy constructor.189GNEChange(const GNEChange&) = delete;190191/// @brief Invalidated assignment operator.192GNEChange& operator=(const GNEChange&) = delete;193};194195196