WorldState.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /* Desc: A world state
18  * Author: Nate Koenig
19  */
20 
21 #ifndef _WORLDSTATE_HH_
22 #define _WORLDSTATE_HH_
23 
24 #include <string>
25 #include <vector>
26 
27 #include <sdf/sdf.hh>
28 
29 #include "gazebo/physics/State.hh"
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
35  namespace physics
36  {
39 
47  {
49  public: WorldState();
50 
55  public: explicit WorldState(const WorldPtr _world);
56 
61  public: explicit WorldState(const sdf::ElementPtr _sdf);
62 
64  public: virtual ~WorldState();
65 
70  public: void Load(const WorldPtr _world);
71 
76  public: virtual void Load(const sdf::ElementPtr _elem);
77 
80  public: void SetWorld(const WorldPtr _world);
81 
86  public: ModelState_M GetModelStates(const boost::regex &_regex) const;
87 
90  public: const ModelState_M &GetModelStates() const;
91 
96  public: unsigned int GetModelStateCount() const;
97 
102  public: ModelState GetModelState(const std::string &_modelName) const;
103 
108  public: bool HasModelState(const std::string &_modelName) const;
109 
114  public: bool IsZero() const;
115 
118  public: void FillSDF(sdf::ElementPtr _sdf);
119 
123  public: virtual void SetWallTime(const common::Time &_time);
124 
127  public: virtual void SetRealTime(const common::Time &_time);
128 
131  public: virtual void SetSimTime(const common::Time &_time);
132 
136  public: virtual void SetIterations(const uint64_t _iterations);
137 
141  public: WorldState &operator=(const WorldState &_state);
142 
146  public: WorldState operator-(const WorldState &_state) const;
147 
151  public: WorldState operator+(const WorldState &_state) const;
152 
157  public: inline friend std::ostream &operator<<(std::ostream &_out,
158  const gazebo::physics::WorldState &_state)
159  {
160  _out << "<state world_name='" << _state.name << "'>"
161  << "<sim_time>" << _state.simTime << "</sim_time>"
162  << "<wall_time>" << _state.wallTime << "</wall_time>"
163  << "<real_time>" << _state.realTime << "</real_time>"
164  << "<iterations>" << _state.iterations << "</iterations>";
165 
166  // List all of the inserted models
167  if (_state.insertions.size() > 0)
168  {
169  _out << "<insertions>";
170  for (std::vector<std::string>::const_iterator iter =
171  _state.insertions.begin();
172  iter != _state.insertions.end(); ++iter)
173  {
174  _out << *iter;
175  }
176  _out << "</insertions>";
177  }
178 
179  // List all of the deleted models
180  if (_state.deletions.size() > 0)
181  {
182  _out << "<deletions>";
183  for (std::vector<std::string>::const_iterator iter =
184  _state.deletions.begin();
185  iter != _state.deletions.end(); ++iter)
186  {
187  _out << "<name>" << (*iter) << "</name>";
188  }
189  _out << "</deletions>";
190  }
191 
192  // List the model states
193  for (ModelState_M::const_iterator iter = _state.modelStates.begin();
194  iter != _state.modelStates.end(); ++iter)
195  {
196  _out << iter->second;
197  }
198 
199  _out << "</state>";
200 
201  return _out;
202  }
203 
205  private: ModelState_M modelStates;
206 
209  private: std::vector<std::string> insertions;
210 
213  private: std::vector<std::string> deletions;
214 
216  private: WorldPtr world;
217  };
219  }
220 }
221 #endif
friend std::ostream & operator<<(std::ostream &_out, const gazebo::physics::WorldState &_state)
Stream insertion operator.
Definition: WorldState.hh:157
#define GZ_PHYSICS_VISIBLE
Definition: system.hh:318
std::string name
Name associated with this State.
Definition: State.hh:130
common::Time realTime
Definition: State.hh:133
State of an entity.
Definition: State.hh:49
std::map< std::string, ModelState > ModelState_M
Definition: PhysicsTypes.hh:204
common::Time wallTime
Times for the state data.
Definition: State.hh:133
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:80
common::Time simTime
Definition: State.hh:133
Store state information of a physics::Model object.
Definition: ModelState.hh:50
uint64_t iterations
The number of simulation iterations when this state was generated.
Definition: State.hh:137
Store state information of a physics::World object.
Definition: WorldState.hh:46
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:39