AGX Dynamics  2.37.2.0
System.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 agxPlot
32 {
33  class Output;
35 
37  {
38  public:
39  System();
40 
41 
49  agxPlot::Window* getOrCreateWindow(const agx::String& windowId = "");
50 
60  void setTimeStep(agx::Real timeStep);
61 
66  bool shouldUpdate() const;
67 
73  void add(agxPlot::Output* output);
74 
81  void remove(agxPlot::Output* output);
82 
86  void generateData();
87 
91  void refresh();
92 
100  bool addDataSeries(agxPlot::DataSeries* dataSeries);
101 
102 
106  agxPlot::DataSeries* getDataSeries(agx::UInt id) const;
107 
109  const OutputRefVector& getOutputs() const;
110 
114  bool hasAnyWindow() const;
115 
124  void getDescription(agxJson::Value& root, bool includeData) const;
130  void setFromDescription(const agxJson::Value& root);
131 
136  void save() const;
141  void load();
142 
147  void closeOutputs();
148 
152  void clearDataSeries();
153 
157  void disableWindows();
158 
160  OutputAddedEvent outputAdded;
161 
163  static void disableAllPlotting();
164  static bool plottingDisabled();
165 
166  public:
167  /***************************************/
168  /* HELPER FUNCTIONS FOR CREATING PLOTS */
169  /***************************************/
170  protected:
171  ~System();
172  private:
173  void updatedRepresentation();
179  void add(Window* window);
180 
181  bool hasData() const;
182 
183  void simulationTickCallback(agx::Clock *clock);
184 
186 
187  private:
188  friend class agxSDK::Simulation;
189  void setSimulation(agxSDK::Simulation* simulation);
190 
191  private:
192  agxPlot::DataSeriesRefVector m_dataSeries;
193  agx::Clock::TickEvent::CallbackType m_simulationTickCallback;
194  WindowRefVector m_windows;
196  OutputRefVector m_outputs;
197  OutputThreadRef m_outputThread;
198  bool m_loadingJournal;
199 
200  bool m_updatedRepresentation;
201  agx::Real m_plotTimeStep;
202  agx::Real m_lastPlotTime;
203 
204  agx::Event::CallbackType m_windowRepresentationChangedCallback;
205  private:
206  friend class OutputThread;
207  agx::Mutex m_outputMutex;
208  };
210 
211 
213 
215  {
216  public:
217  OutputThread(System *system, agx::Real frequency = 30);
218 
219  void setFrequency(agx::Real frequency);
220  agx::Real getFrequency() const;
221 
222  protected:
223  virtual ~OutputThread();
224 
225  private:
226  virtual void run();
227 
228  void start();
229  void stop();
230  void updateOutputs();
231 
232  private:
233  System *m_system;
234  bool m_running;
235  agx::Block m_startBlock;
236  agx::Timer m_timer;
237  agx::Real m_frequency;
238  };
239 }
240 
241 #endif
Basic wrapper class aroud std::thread.
Definition: Thread.h:82
Namespace contains functionality related to plotting.
Generalized callback, using std::function.
Definition: Callback.h:53
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:74
Block synchronization primitive.
Base class providing referencing counted objects.
Definition: Referenced.h:119
uint32_t UInt
Definition: Integer.h:34
Templated callback with one argument.
Definition: Callback.h:100
agx::Event1< agxPlot::Output * > OutputAddedEvent
Definition: System.h:159
OutputAddedEvent outputAdded
Definition: System.h:160
std::mutex Mutex
Definition: Referenced.h:99
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
Clock class keeps representation of virtual/simulated time.
Definition: Clock.h:37
double Real
Definition: Real.h:42
AGXCORE_EXPORT Component * root()