AGX Dynamics  2.38.0.2
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 #pragma once
18 
19 #include <agxPlot/Window.h>
20 #include <agxPlot/Output.h>
21 #include <agxPlot/Queue.h>
22 #include <agxPlot/DataSeries.h>
23 
24 #include <agx/Thread.h>
26 #include <agx/Timer.h>
27 
28 #include <agxSDK/Simulation.h>
29 
30 namespace agxPlot
31 {
32  class Output;
34 
39  {
40  public:
41  System();
42 
43 
51  agxPlot::Window* getOrCreateWindow(const agx::String& windowId = "");
52 
62  void setTimeStep(agx::Real timeStep);
63 
68  bool shouldUpdate() const;
69 
75  void add(agxPlot::Output* output);
76 
83  void remove(agxPlot::Output* output);
84 
88  void generateData();
89 
93  void refresh();
94 
102  bool addDataSeries(agxPlot::DataSeries* dataSeries);
103 
104 
108  agxPlot::DataSeries* getDataSeries(agx::UInt id) const;
109 
111  const OutputRefVector& getOutputs() const;
112 
116  bool hasAnyWindow() const;
117 
126  void getDescription(agxJson::Value& root, bool includeData) const;
132  void setFromDescription(const agxJson::Value& root);
133 
138  void save() const;
143  void load();
144 
149  void closeOutputs();
150 
154  void clearDataSeries();
155 
159  void disableWindows();
160 
163 
165  static void disableAllPlotting();
166  static bool plottingDisabled();
167 
168  public:
169  /***************************************/
170  /* HELPER FUNCTIONS FOR CREATING PLOTS */
171  /***************************************/
172  protected:
173  ~System();
174  private:
175  void updatedRepresentation();
181  void add(Window* window);
182 
183  bool hasData() const;
184 
185  void simulationTickCallback(agx::Clock *clock);
186 
188 
189  private:
190  friend class agxSDK::Simulation;
191  void setSimulation(agxSDK::Simulation* simulation);
192 
193  private:
194  agxPlot::DataSeriesRefVector m_dataSeries;
195  agx::Clock::TickEvent::CallbackType m_simulationTickCallback;
196  WindowRefVector m_windows;
198  OutputRefVector m_outputs;
199  OutputThreadRef m_outputThread;
200  bool m_loadingJournal;
201 
202  bool m_updatedRepresentation;
203  agx::Real m_plotTimeStep;
204  agx::Real m_lastPlotTime;
205 
206  agx::Event::CallbackType m_windowRepresentationChangedCallback;
207  private:
208  friend class OutputThread;
209  agx::Mutex m_outputMutex;
210  };
212 
213 
215 
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 }
agx::UInt
uint64_t UInt
Definition: Integer.h:27
agx::BasicThread
Basic wrapper class aroud std::thread.
Definition: Thread.h:82
agx::Real
double Real
Definition: Real.h:42
agx::Vector< OutputRef >
agxPlot
Namespace contains functionality related to plotting.
Simulation.h
agxPlot::System::OutputThread
Definition: System.h:219
agxPlot::System::OutputThread::~OutputThread
virtual ~OutputThread()
agx::EventT< Callback >::CallbackType
Callback CallbackType
Definition: Event.h:37
DataSeries.h
agx::observer_ptr< agxSDK::Simulation >
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agx::Block
Block synchronization primitive.
Definition: ThreadSynchronization.h:96
Window.h
agxPlot::System::OutputThread::OutputThread
OutputThread(System *system, agx::Real frequency=30)
agx::ref_ptr< OutputThread >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agxPlot::System::OutputThread::setFrequency
void setFrequency(agx::Real frequency)
Timer.h
agxPlot::System::OutputAddedEvent
agx::Event1< agxPlot::Output * > OutputAddedEvent
Definition: System.h:161
agx::Mutex
std::mutex Mutex
Definition: Referenced.h:99
Thread.h
Queue.h
agxPlot::System
System that manages the plotting system.
Definition: System.h:38
Output.h
agxPlot::Window
Definition: Window.h:28
agx::root
AGXCORE_EXPORT Component * root()
agx::Callback1
Templated callback with one argument.
Definition: Callback.h:100
agxPlot::System::outputAdded
OutputAddedEvent outputAdded
Definition: System.h:162
agx::Event1< agxPlot::Output * >
agxPlot::DataSeries
Class that encapsulates data to be plotted, including methods for accessing the data,...
Definition: DataSeries.h:44
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agx::Timer
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
Definition: Timer.h:74
agx::AgXString< std::string >
agx::Clock
Clock class keeps representation of virtual/simulated time.
Definition: Clock.h:37
ThreadSynchronization.h
agxPlot::Output
THis class wraps the description of data that should be plotted.
Definition: Output.h:34
agxPlot::System::OutputThread::getFrequency
agx::Real getFrequency() const