# Node.py -- Pamhyr # Copyright (C) 2023-2024 INRAE # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -*- coding: utf-8 -*- from Model.Tools.PamhyrDB import PamhyrID from Model.Network.Point import Point class Node(PamhyrID): def __init__(self, id: int, name: str, x: float = 0.0, y: float = 0.0, status=None): super(Node, self).__init__(id) self._status = status if name == "": self._name = f"Node #{self.pamhyr_id}" else: self._name = name self.pos = Point(x, y) def __getitem__(self, key): ret = None if key == "name": ret = self._name elif key == "id": ret = self.pamhyr_id elif key == "pos": ret = f"({self.pos.x},{self.pos.y})" return ret def __setitem__(self, key, value): if key == "name": self._name = value elif key == "id": self.pamhyr_id = value self._status.modified() @property def name(self): return self._name @property def x(self): return self.pos.x @property def y(self): return self.pos.y def setPos(self, x, y): self.pos.x = x self.pos.y = y self._status.modified()