Path: blob/main/src/netedit/elements/data/GNEGenericData.cpp
193700 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 GNEGenericData.cpp14/// @author Pablo Alvarez Lopez15/// @date Jan 202016///17// A abstract class for generic datas18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/GNETagPropertiesDatabase.h>22#include <netedit/GNEViewParent.h>23#include <netedit/frames/common/GNESelectorFrame.h>24#include <netedit/frames/data/GNEEdgeDataFrame.h>25#include <utils/gui/div/GLHelper.h>26#include <utils/gui/div/GUIDesigns.h>27#include <utils/gui/div/GUIParameterTableWindow.h>28#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>2930#include "GNEDataInterval.h"31#include "GNEGenericData.h"3233// ===========================================================================34// member method definitions35// ===========================================================================3637GNEGenericData::GNEGenericData(SumoXMLTag tag, GNENet* net) :38GNEAttributeCarrier(tag, net),39GUIGlObject(net->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGLType(), "",40GUIIconSubSys::getIcon(net->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGUIIcon())),41GNEPathElement(GNEPathElement::Options::DATA_ELEMENT),42myDataIntervalParent(nullptr) {43}444546GNEGenericData::GNEGenericData(const SumoXMLTag tag, GNEDataInterval* dataIntervalParent, const Parameterised::Map& parameters) :47GNEAttributeCarrier(tag, dataIntervalParent->getNet(), dataIntervalParent->getFileBucket()),48GUIGlObject(dataIntervalParent->getNet()->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGLType(), dataIntervalParent->getID(),49GUIIconSubSys::getIcon(dataIntervalParent->getNet()->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGUIIcon())),50GNEPathElement(GNEPathElement::Options::DATA_ELEMENT),51Parameterised(parameters),52myDataIntervalParent(dataIntervalParent) {53}545556GNEGenericData::~GNEGenericData() {}575859GNEHierarchicalElement*60GNEGenericData::getHierarchicalElement() {61return this;62}636465GNEMoveElement*66GNEGenericData::getMoveElement() const {67return nullptr;68}697071Parameterised*72GNEGenericData::getParameters() {73return this;74}757677const Parameterised*78GNEGenericData::getParameters() const {79return this;80}818283GUIGlObject*84GNEGenericData::getGUIGlObject() {85return this;86}878889const GUIGlObject*90GNEGenericData::getGUIGlObject() const {91return this;92}939495FileBucket*96GNEGenericData::getFileBucket() const {97if (isTemplate()) {98return nullptr;99} else {100return myDataIntervalParent->getFileBucket();101}102}103104105GNEDataInterval*106GNEGenericData::getDataIntervalParent() const {107return myDataIntervalParent;108}109110111void112GNEGenericData::drawAttribute(const PositionVector& shape) const {113if ((myTagProperty->getTag() == GNE_TAG_EDGEREL_SINGLE) && (shape.length() > 0)) {114// obtain pointer to edge data frame (only for code legibly)115const GNEEdgeDataFrame* edgeDataFrame = myDataIntervalParent->getNet()->getViewParent()->getEdgeDataFrame();116// check if we have to filter generic data117if (edgeDataFrame->shown()) {118// check attribute119if ((edgeDataFrame->getAttributeSelector()->getFilteredAttribute().size() > 0) &&120(getParametersMap().count(edgeDataFrame->getAttributeSelector()->getFilteredAttribute()) > 0)) {121// get value122const std::string value = getParametersMap().at(edgeDataFrame->getAttributeSelector()->getFilteredAttribute());123// calculate center position124const Position centerPosition = shape.positionAtOffset2D(shape.length2D() / 2);125// Add a draw matrix126GLHelper::pushMatrix();127GLHelper::drawText(value, centerPosition, GLO_MAX, 2, RGBColor::BLUE);128// pop draw matrix129GLHelper::popMatrix();130}131}132}133}134135136bool137GNEGenericData::checkDrawFromContour() const {138return false;139}140141142bool143GNEGenericData::checkDrawToContour() const {144return false;145}146147148bool149GNEGenericData::checkDrawRelatedContour() const {150// check opened popup151if (myNet->getViewNet()->getPopup()) {152return myNet->getViewNet()->getPopup()->getGLObject() == this;153}154return false;155}156157158bool159GNEGenericData::checkDrawOverContour() const {160return false;161}162163164bool165GNEGenericData::checkDrawDeleteContour() const {166// get edit modes167const auto& editModes = myNet->getViewNet()->getEditModes();168// check if we're in delete mode169if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_DELETE)) {170return myNet->getViewNet()->checkOverLockedElement(this, mySelected);171} else {172return false;173}174}175176177bool178GNEGenericData::checkDrawDeleteContourSmall() const {179return false;180}181182183bool184GNEGenericData::checkDrawSelectContour() const {185// get edit modes186const auto& editModes = myNet->getViewNet()->getEditModes();187// check if we're in select mode188if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_SELECT)) {189return myNet->getViewNet()->checkOverLockedElement(this, mySelected);190} else {191return false;192}193}194195196bool197GNEGenericData::checkDrawMoveContour() const {198return false;199}200201202bool203GNEGenericData::isGenericDataValid() const {204return true;205}206207208std::string209GNEGenericData::getGenericDataProblem() const {210return "";211}212213214void215GNEGenericData::fixGenericDataProblem() {216throw InvalidArgument(getTagStr() + " cannot fix any problem");217}218219220GUIGLObjectPopupMenu*221GNEGenericData::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {222// create popup223GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);224// build common options225buildPopUpMenuCommonOptions(ret, app, myNet->getViewNet(), myTagProperty->getTag(), mySelected);226// show option to open additional dialog227if (myTagProperty->hasDialog()) {228GUIDesigns::buildFXMenuCommand(ret, (TLF("Open % Dialog", getTagStr())).c_str(), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);229new FXMenuSeparator(ret);230} else {231GUIDesigns::buildFXMenuCommand(ret, (TL("Cursor position in view: ") + toString(getPositionInView().x()) + "," + toString(getPositionInView().y())).c_str(), nullptr, nullptr, 0);232}233return ret;234}235236237GUIParameterTableWindow*238GNEGenericData::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& /* parent */) {239// Create table240GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);241// Iterate over attributes242for (const auto& tagProperty : myTagProperty->getAttributeProperties()) {243// Add attribute and set it dynamic if aren't unique244if (tagProperty->isUnique()) {245ret->mkItem(tagProperty->getAttrStr().c_str(), false, getAttribute(tagProperty->getAttr()));246} else {247ret->mkItem(tagProperty->getAttrStr().c_str(), true, getAttribute(tagProperty->getAttr()));248}249}250// close building251ret->closeBuilding();252return ret;253}254255256void257GNEGenericData::deleteGLObject() {258myNet->deleteGenericData(this, myNet->getUndoList());259}260261262void263GNEGenericData::selectGLObject() {264if (isAttributeCarrierSelected()) {265unselectAttributeCarrier();266} else {267selectAttributeCarrier();268}269// update information label270myNet->getViewParent()->getSelectorFrame()->getSelectionInformation()->updateInformationLabel();271}272273274void275GNEGenericData::updateGLObject() {276updateGeometry();277}278279280Position281GNEGenericData::getAttributePosition(SumoXMLAttr key) const {282return getCommonAttributePosition(key);283}284285286PositionVector287GNEGenericData::getAttributePositionVector(SumoXMLAttr key) const {288return getCommonAttributePositionVector(key);289}290291292bool293GNEGenericData::isPathElementSelected() const {294return mySelected;295}296297// ---------------------------------------------------------------------------298// GNEGenericData - protected methods299// ---------------------------------------------------------------------------300301void302GNEGenericData::drawFilteredAttribute(const GUIVisualizationSettings& s, const PositionVector& laneShape, const std::string& attribute, const GNEDataInterval* dataIntervalParent) const {303if ((myDataIntervalParent == dataIntervalParent) && (getParametersMap().count(attribute) > 0)) {304const Position pos = laneShape.positionAtOffset2D(laneShape.length2D() * 0.5);305const double rot = laneShape.rotationDegreeAtOffset(laneShape.length2D() * 0.5);306// Add a draw matrix for details307GLHelper::pushMatrix();308// draw value309GLHelper::drawText(getParameter(attribute), pos, GLO_MAX - 1, 2, RGBColor::BLACK, s.getTextAngle(rot + 90));310// pop draw matrix311GLHelper::popMatrix();312}313}314315316bool317GNEGenericData::isVisibleInspectDeleteSelect() const {318// get toolbar319const GNEViewNetHelper::IntervalBar& toolBar = myNet->getViewNet()->getIntervalBar();320// declare flag321bool draw = true;322// check filter by generic data type323if ((toolBar.getGenericDataType() != SUMO_TAG_NOTHING) && (toolBar.getGenericDataType() != myTagProperty->getTag())) {324draw = false;325}326// check filter by data set327if (toolBar.getDataSet() && (toolBar.getDataSet() != myDataIntervalParent->getDataSetParent())) {328draw = false;329}330// check filter by begin331if ((toolBar.getBegin() != INVALID_DOUBLE) && (toolBar.getBegin() > myDataIntervalParent->getAttributeDouble(SUMO_ATTR_BEGIN))) {332draw = false;333}334// check filter by end335if ((toolBar.getEnd() != INVALID_DOUBLE) && (toolBar.getEnd() < myDataIntervalParent->getAttributeDouble(SUMO_ATTR_END))) {336draw = false;337}338// check filter by attribute339if ((toolBar.getParameter().size() > 0) && (getParametersMap().count(toolBar.getParameter()) == 0)) {340draw = false;341}342// return flag343return draw;344}345346void347GNEGenericData::replaceFirstParentEdge(const std::string& value) {348auto newEdge = myNet->getAttributeCarriers()->retrieveEdge(value);349GNEHierarchicalElement::updateParent(this, 0, newEdge);350}351352353void354GNEGenericData::replaceLastParentEdge(const std::string& value) {355auto newEdge = myNet->getAttributeCarriers()->retrieveEdge(value);356GNEHierarchicalElement::updateParent(this, (int)getParentEdges().size() - 1, newEdge);357}358359360void361GNEGenericData::replaceParentTAZElement(const int index, const std::string& value) {362std::vector<GNEAdditional*> newTAZs = getParentAdditionals();363auto TAZ = myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TAZ, value);364// continue depending of index and number of TAZs365if (index == 0) {366if (newTAZs.size() == 2) {367if (newTAZs.at(1)->getID() == value) {368newTAZs = {TAZ};369} else {370newTAZs[0] = TAZ;371}372} else if (newTAZs.at(0) != TAZ) {373newTAZs = {TAZ, newTAZs.at(0)};374}375} else if (index == 1) {376if (newTAZs.size() == 2) {377if (newTAZs.at(0)->getID() == value) {378newTAZs = {TAZ};379} else {380newTAZs[1] = TAZ;381}382} else if (newTAZs.at(0) != TAZ) {383newTAZs = {newTAZs.at(0), TAZ};384}385} else {386throw ProcessError(TL("Invalid index"));387}388GNEHierarchicalElement::updateParents(this, newTAZs);389}390391392std::string393GNEGenericData::getPartialID() const {394return getDataIntervalParent()->getDataSetParent()->getID() + "[" +395getDataIntervalParent()->getAttribute(SUMO_ATTR_BEGIN) + "," +396getDataIntervalParent()->getAttribute(SUMO_ATTR_END) + "]:";397}398399/****************************************************************************/400401402