Eclipse SUMO - Simulation of Urban MObility
Node.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // Representation of electric circuit nodes, i.e. wire junctions and connection points.
22 /****************************************************************************/
23 #include <string>
24 #include <algorithm>
25 #include "Node.h"
26 #include "Element.h"
27 
28 using namespace std;
29 
30 // A constructor, same functionality as "init" functions
31 Node::Node(string name, int id) {
32  isground = false;
33  this->name = name; // unique property, each object has distinctive and unique name
34  this->id = id; // a sequential ID number, might be useful when making the equation
35  this->num_matrixRow = -1;
36  this->num_matrixCol = -1;
37  this->voltage = 0;
38  this->elements = new vector<Element*>(0);
39  isremovable = false;
40 }
41 
42 // connects an element to the node
43 void Node::addElement(Element* element) {
44  elements->push_back(element);
45 }
46 
47 void Node::eraseElement(Element* element) {
48  elements->erase(std::remove(elements->begin(), elements->end(), element), elements->end());
49 }
50 
51 // getters and setters
52 double Node::getVoltage() {
53  return this->voltage;
54 }
55 
56 void Node::setVoltage(double volt) {
57  this->voltage = volt;
58 }
59 
61  return (int) elements->size();
62 }
63 
64 string& Node::getName() {
65  return this->name;
66 }
67 
69  return this->isground;
70 }
71 
72 void Node::setGround(bool newIsGround) {
73  this->isground = newIsGround;
74 }
75 
76 int Node::getId() {
77  return this->id;
78 }
79 
80 void Node::setId(int newId) {
81  this->id = newId;
82 }
83 
84 void Node::setNumMatrixRow(int num) {
85  this->num_matrixRow = num;
86 }
87 
89  return this->num_matrixRow;
90 }
91 
92 void Node::setNumMatrixCol(int num) {
93  this->num_matrixCol = num;
94 }
95 
97  return this->num_matrixCol;
98 }
99 
100 vector<Element*>* Node::getElements() {
101  return elements;
102 }
103 
104 void Node::setRemovability(bool newIsRemovable) {
105  this->isremovable = newIsRemovable;
106 }
107 
109  for (Element* it : *this->getElements()) {
110  if (it != element) {
111  return it;
112  }
113  }
114  return nullptr;
115 }
void setVoltage(double volt)
Definition: Node.cpp:56
std::vector< Element * > * getElements()
Definition: Node.cpp:100
void setGround(bool isground)
Definition: Node.cpp:72
void setNumMatrixCol(int num)
Definition: Node.cpp:92
int getId()
Definition: Node.cpp:76
std::string & getName()
Definition: Node.cpp:64
int getNumMatrixCol()
Definition: Node.cpp:96
Node(std::string name, int id)
Definition: Node.cpp:31
Element * getAnOtherElement(Element *element)
Definition: Node.cpp:108
bool isGround()
Definition: Node.cpp:68
void addElement(Element *element)
Definition: Node.cpp:43
void eraseElement(Element *element)
Definition: Node.cpp:47
int getNumOfElements()
Definition: Node.cpp:60
double getVoltage()
Definition: Node.cpp:52
void setNumMatrixRow(int num)
Definition: Node.cpp:84
void setId(int id)
Definition: Node.cpp:80
void setRemovability(bool isremovable)
Definition: Node.cpp:104
int getNumMatrixRow()
Definition: Node.cpp:88