WorldState.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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"
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace physics
37  {
40 
48  {
50  public: WorldState();
51 
56  public: explicit WorldState(const WorldPtr _world);
57 
62  public: explicit WorldState(const sdf::ElementPtr _sdf);
63 
65  public: virtual ~WorldState();
66 
71  public: void Load(const WorldPtr _world);
72 
77  public: virtual void Load(const sdf::ElementPtr _elem);
78 
81  public: void SetWorld(const WorldPtr _world);
82 
87  public: ModelState_M GetModelStates(const boost::regex &_regex) const;
88 
91  public: const ModelState_M &GetModelStates() const;
92 
95  public: const LightState_M &LightStates() const;
96 
101  public: unsigned int GetModelStateCount() const;
102 
107  public: unsigned int LightStateCount() const;
108 
113  public: ModelState GetModelState(const std::string &_modelName) const;
114 
119  public: LightState GetLightState(const std::string &_lightName) const;
120 
125  public: bool HasModelState(const std::string &_modelName) const;
126 
131  public: bool HasLightState(const std::string &_lightName) const;
132 
136  public: const std::vector<std::string> &Insertions() const;
137 
142  public: void SetInsertions(const std::vector<std::string> &_insertions);
143 
147  public: const std::vector<std::string> &Deletions() const;
148 
152  public: void SetDeletions(const std::vector<std::string> &_deletions);
153 
158  public: bool IsZero() const;
159 
162  public: void FillSDF(sdf::ElementPtr _sdf);
163 
167  public: virtual void SetWallTime(const common::Time &_time);
168 
171  public: virtual void SetRealTime(const common::Time &_time);
172 
175  public: virtual void SetSimTime(const common::Time &_time);
176 
180  public: virtual void SetIterations(const uint64_t _iterations);
181 
185  public: WorldState &operator=(const WorldState &_state);
186 
190  public: WorldState operator-(const WorldState &_state) const;
191 
195  public: WorldState operator+(const WorldState &_state) const;
196 
201  public: inline friend std::ostream &operator<<(std::ostream &_out,
202  const gazebo::physics::WorldState &_state)
203  {
204  _out << "<state world_name='" << _state.name << "'>"
205  << "<sim_time>" << _state.simTime << "</sim_time>"
206  << "<wall_time>" << _state.wallTime << "</wall_time>"
207  << "<real_time>" << _state.realTime << "</real_time>"
208  << "<iterations>" << _state.iterations << "</iterations>";
209 
210  // List all of the inserted models
211  if (_state.insertions.size() > 0)
212  {
213  _out << "<insertions>";
214  for (std::vector<std::string>::const_iterator iter =
215  _state.insertions.begin();
216  iter != _state.insertions.end(); ++iter)
217  {
218  _out << *iter;
219  }
220  _out << "</insertions>";
221  }
222 
223  // List all of the deleted models
224  if (_state.deletions.size() > 0)
225  {
226  _out << "<deletions>";
227  for (std::vector<std::string>::const_iterator iter =
228  _state.deletions.begin();
229  iter != _state.deletions.end(); ++iter)
230  {
231  _out << "<name>" << (*iter) << "</name>";
232  }
233  _out << "</deletions>";
234  }
235 
236  // List the model states
237  for (const auto &model : _state.modelStates)
238  {
239  _out << model.second;
240  }
241 
242  // List the light states
243  for (const auto &light : _state.lightStates)
244  {
245  _out << light.second;
246  }
247 
248  _out << "</state>";
249 
250  return _out;
251  }
252 
254  private: ModelState_M modelStates;
255 
257  private: LightState_M lightStates;
258 
261  private: std::vector<std::string> insertions;
262 
265  private: std::vector<std::string> deletions;
266 
268  private: WorldPtr world;
269  };
271  }
272 }
273 #endif
friend std::ostream & operator<<(std::ostream &_out, const gazebo::physics::WorldState &_state)
Stream insertion operator.
Definition: WorldState.hh:201
#define GZ_PHYSICS_VISIBLE
Definition: system.hh:259
std::string name
Name associated with this State.
Definition: State.hh:130
std::map< std::string, LightState > LightState_M
Definition: PhysicsTypes.hh:228
common::Time realTime
Definition: State.hh:133
State of an entity.
Definition: State.hh:49
Store state information of a Light object.
Definition: LightState.hh:37
std::map< std::string, ModelState > ModelState_M
Definition: PhysicsTypes.hh:224
common::Time wallTime
Times for the state data.
Definition: State.hh:133
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:84
common::Time simTime
Definition: State.hh:133
Store state information of a physics::Model object.
Definition: ModelState.hh:48
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:47
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44