AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
System.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXPLOT_SYSTEM_H
18 #define AGXPLOT_SYSTEM_H
19 
20 #include <agxPlot/Window.h>
21 #include <agxPlot/Output.h>
22 #include <agxPlot/Queue.h>
23 #include <agxPlot/DataSeries.h>
24 
25 #include <agx/Thread.h>
27 #include <agx/Timer.h>
28 
29 #include <agxSDK/Simulation.h>
30 
31 namespace agxSDK
32 {
33  class Simulation;
34 }
35 
36 namespace agxPlot
37 {
38  class Output;
40 
42  {
43  public:
44  System();
45 
46 
54  agxPlot::Window* getOrCreateWindow(const agx::String& windowId = "");
55 
65  void setTimeStep(agx::Real timeStep);
66 
71  bool shouldUpdate() const;
72 
78  void add(agxPlot::Output* output);
79 
86  void remove(agxPlot::Output* output);
87 
91  void generateData();
92 
96  void refresh();
97 
105  bool addDataSeries(agxPlot::DataSeries* dataSeries);
106 
107 
111  agxPlot::DataSeries* getDataSeries(agx::UInt id) const;
112 
114  const OutputRefVector& getOutputs() const;
115 
119  bool hasAnyWindow() const;
120 
129  void getDescription(agxJson::Value& root, bool includeData) const;
135  void setFromDescription(const agxJson::Value& root);
136 
141  void save() const;
146  void load();
147 
152  void closeOutputs();
153 
157  void clearDataSeries();
158 
162  void disableWindows();
163 
166 
168  static void disableAllPlotting();
169  static bool plottingDisabled();
170 
171  public:
172  /***************************************/
173  /* HELPER FUNCTIONS FOR CREATING PLOTS */
174  /***************************************/
175  protected:
176  ~System();
177  private:
178  void updatedRepresentation();
184  void add(Window* window);
185 
186  bool hasData() const;
187 
188  void simulationTickCallback(agx::Clock *clock);
189 
191 
192  private:
193  friend class agxSDK::Simulation;
194  void setSimulation(agxSDK::Simulation* simulation);
195 
196  private:
197  agxPlot::DataSeriesRefVector m_dataSeries;
198  agx::Clock::TickEvent::CallbackType m_simulationTickCallback;
199  WindowRefVector m_windows;
201  OutputRefVector m_outputs;
202  OutputThreadRef m_outputThread;
203  bool m_loadingJournal;
204 
205  bool m_updatedRepresentation;
206  agx::Real m_plotTimeStep;
207  agx::Real m_lastPlotTime;
208 
209  agx::Event::CallbackType m_windowRepresentationChangedCallback;
210  private:
211  friend class OutputThread;
212  agx::Mutex m_outputMutex;
213  };
215 
216 
218 
220  {
221  public:
222  OutputThread(System *system, agx::Real frequency = 30);
223 
224  void setFrequency(agx::Real frequency);
225  agx::Real getFrequency() const;
226 
227  protected:
228  virtual ~OutputThread();
229 
230  private:
231  virtual void run();
232 
233  void start();
234  void stop();
235  void updateOutputs();
236 
237  private:
238  System *m_system;
239  bool m_running;
240  agx::Block m_startBlock;
241  agx::Timer m_timer;
242  agx::Real m_frequency;
243  };
244 }
245 
246 #endif
Basic wrapper class aroud std::thread.
Definition: Thread.h:81
OutputThread(System *system, agx::Real frequency=30)
void setFrequency(agx::Real frequency)
Generalized callback, using std::function.
Definition: Callback.h:53
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:73
Block synchronization primitive.
Base class providing referencing counted objects.
Definition: Referenced.h:113
uint32_t UInt
Definition: Integer.h:34
Templated callback with one argument.
Definition: Callback.h:100
agx::Real getFrequency() const
agx::Event1< agxPlot::Output * > OutputAddedEvent
Definition: System.h:164
OutputAddedEvent outputAdded
Definition: System.h:165
std::mutex Mutex
Definition: Referenced.h:93
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
Clock class keeps representation of virtual/simulated time.
Definition: Clock.h:37
double Real
Definition: Real.h:42
AGXCORE_EXPORT Component * root()