AGXDynamics  2.35.0.3
System.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
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
agx::BasicThread
Basic wrapper class aroud std::thread.
Definition: Thread.h:81
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:214
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:126
agxPlot::System::OutputThread::setFrequency
void setFrequency(agx::Real frequency)
Timer.h
agxPlot::System::OutputAddedEvent
agx::Event1< agxPlot::Output * > OutputAddedEvent
Definition: System.h:159
agx::Mutex
std::mutex Mutex
Definition: Referenced.h:93
Thread.h
Queue.h
agxPlot::System
Definition: System.h:36
Output.h
agxPlot::Window
Definition: Window.h:29
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:160
agx::Event1< agxPlot::Output * >
agxPlot::DataSeries
Definition: DataSeries.h:40
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agx::UInt
uint32_t UInt
Definition: Integer.h:34
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
Definition: Output.h:32
agxPlot::System::OutputThread::getFrequency
agx::Real getFrequency() const