Fawkes API Fawkes Development Version
navgraph_node.cpp
1
2/***************************************************************************
3 * navgraph_node.cpp - Topological graph node
4 *
5 * Created: Fri Sep 21 16:11:20 2012
6 * Copyright 2012 Tim Niemueller [www.niemueller.de]
7 ****************************************************************************/
8
9/* This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version. A runtime exception applies to
13 * this software (see LICENSE.GPL_WRE file mentioned below for details).
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
21 */
22
23#include <navgraph/navgraph_node.h>
24
25namespace fawkes {
26
27/** @class NavGraphNode <navgraph/navgraph_node.h>
28 * Topological graph node.
29 * @author Tim Niemueller
30 */
31
32/** Constructor for invalid node. */
33NavGraphNode::NavGraphNode() : unconnected_(false)
34{
35}
36
37/** Constructor.
38 * @param name name of the node
39 * @param x x coordinate in global frame of node
40 * @param y y coordinate in global frame of node
41 * @param properties properties for the new node
42 */
43NavGraphNode::NavGraphNode(const std::string & name,
44 float x,
45 float y,
46 std::map<std::string, std::string> properties)
47: unconnected_(false)
48{
49 name_ = name;
50 x_ = x;
51 y_ = y;
52 properties_ = properties;
53}
54
55/** Constructor.
56 * @param name name of the node
57 * @param x x coordinate in global frame of node
58 * @param y y coordinate in global frame of node
59 */
60NavGraphNode::NavGraphNode(const std::string &name, float x, float y) : unconnected_(false)
61{
62 name_ = name;
63 x_ = x;
64 y_ = y;
65}
66
67/** Set X position.
68 * @param x X coordinate in global frame for node.
69 */
70void
72{
73 x_ = x;
74}
75
76/** Set Y position.
77 * @param y Y coordinate in global frame for node.
78 */
79void
81{
82 y_ = y;
83}
84
85/** Set name of node.
86 * @param name new name for node
87 */
88void
89NavGraphNode::set_name(const std::string &name)
90{
91 name_ = name;
92}
93
94/** Set unconnected state of the node.
95 * A node must be marked as unconnected explicitly or otherwise it is an
96 * error that the graph will report as an error. On other hand, unconnected
97 * nodes may not have any connection. By default nodes are expected to
98 * have at least one connection (behaving as though this function had been
99 * called with "false").
100 * @param unconnected true to make this node a unconnected node,
101 * false otherwise
102 */
103void
105{
106 unconnected_ = unconnected;
107}
108
109/** Get specified property as string.
110 * @param prop property key
111 * @return property value as string
112 */
113std::string
114NavGraphNode::property(const std::string &prop) const
115{
116 std::map<std::string, std::string>::const_iterator p;
117 if ((p = properties_.find(prop)) != properties_.end()) {
118 return p->second;
119 } else {
120 return "";
121 }
122}
123
124/** Overwrite properties with given ones.
125 * @param properties map of properties to set
126 */
127void
128NavGraphNode::set_properties(const std::map<std::string, std::string> &properties)
129{
130 properties_ = properties;
131}
132
133/** Set property.
134 * @param property property key
135 * @param value property value
136 */
137void
138NavGraphNode::set_property(const std::string &property, const std::string &value)
139{
140 properties_[property] = value;
141}
142
143/** Set property.
144 * @param property property key
145 * @param value property value
146 */
147void
148NavGraphNode::set_property(const std::string &property, float value)
149{
150 properties_[property] = StringConversions::to_string(value);
151}
152
153/** Set property.
154 * @param property property key
155 * @param value property value
156 */
157void
158NavGraphNode::set_property(const std::string &property, int value)
159{
160 properties_[property] = StringConversions::to_string(value);
161}
162
163/** Set property.
164 * @param property property key
165 * @param value property value
166 */
167void
168NavGraphNode::set_property(const std::string &property, bool value)
169{
170 properties_[property] = value ? "true" : "false";
171}
172
173/** Set directly reachable nodes of node.
174 * @param reachable_nodes vector of directly reachable nodes
175 */
176void
177NavGraphNode::set_reachable_nodes(std::vector<std::string> reachable_nodes)
178{
179 reachable_nodes_ = reachable_nodes;
180}
181
182} // end of namespace fawkes
float x() const
Get X coordinate in global frame.
Definition: navgraph_node.h:58
void set_x(float x)
Set X position.
std::string property(const std::string &prop) const
Get specified property as string.
void set_property(const std::string &property, const std::string &value)
Set property.
void set_name(const std::string &name)
Set name of node.
const std::map< std::string, std::string > & properties() const
Get all properties.
bool unconnected() const
Check if this node shall be unconnected.
Definition: navgraph_node.h:74
const std::string & name() const
Get name of node.
Definition: navgraph_node.h:50
NavGraphNode()
Constructor for invalid node.
void set_reachable_nodes(std::vector< std::string > reachable_nodes)
Set directly reachable nodes of node.
float y() const
Get Y coordinate in global frame.
Definition: navgraph_node.h:66
void set_properties(const std::map< std::string, std::string > &properties)
Overwrite properties with given ones.
void set_unconnected(bool unconnected)
Set unconnected state of the node.
void set_y(float y)
Set Y position.
const std::vector< std::string > & reachable_nodes() const
Get reachable nodes.
static std::string to_string(unsigned int i)
Convert unsigned int value to a string.
Fawkes library namespace.