AGX Dynamics  2.37.3.2
PowerLineController.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 
18 
19 #ifndef AGXPOWERLINE_POWER_LINE_CONTROLLER_H
20 #define AGXPOWERLINE_POWER_LINE_CONTROLLER_H
21 
22 
23 #include <agxModel/export.h>
24 #include <agxPowerLine/Unit.h>
25 #include <agxPowerLine/PowerLine.h>
26 
27 #include <agx/Singleton.h>
28 #include <agx/HashTable.h>
29 #include <agx/HashVector.h>
30 
31 #include <functional>
32 
33 
34 namespace agxPowerLine
35 {
36 
43  {
44  public:
49  void addPowerLine(agxPowerLine::PowerLine* powerLine);
50 
56 
60  bool empty() const;
61 
62  virtual void pre(const agx::TimeStamp& time) override;
63  virtual void post(const agx::TimeStamp& time) override;
64 
69 
70  private:
71  virtual ~PowerLinesHandler();
73  };
74 
76 
77 
78 
92  {
93  public:
94  typedef std::function<Connector*()> ConnectorFactory;
95 
96  public:
101  bool addPhysicalDimension(std::string name);
102 
108  void add(agxPowerLine::Connector* connector);
109  void remove(agxPowerLine::Connector* connector);
110 
111 
112  bool getPowerLines(agxSDK::Simulation* simulation, PowerLinePtrVector& powerLines);
113 
122  int getDimensionType(std::string name);
123 
127  std::string getDimensionTypeName(size_t id);
128 
133  agxPowerLine::PhysicalDimension::Type getNumberOfPhysicalDimensions();
134 
140  void setStoredPhysicalDimensionId(int currentId, int previousId);
141 
150  bool hasStoredDimensionsMappings() const;
151 
160  int getStoredPhysicalDimensionId(int currentId);
161 
172  int getCurrentPhysicalDimensionId(int storedId);
173 
178  void clearStoredPhysicalDimensionIds();
179 
180 
181  void registerDefaultConnector(
184  ConnectorFactory connectorCreator);
185 
186  agxPowerLine::Connector* createConnector(
188  agxPowerLine::PhysicalDimension::Type outputType) const;
189 
193  static PowerLineController* instance();
194 
198  static bool isInitialized();
199 
200 
201  private:
203  void registerPowerLine(agxPowerLine::PowerLine* powerLine);
204  void unregisterPowerLine(agxPowerLine::PowerLine* powerLine, agxSDK::Simulation* simulation);
205 
206  protected:
208 
209 
211 
212  virtual ~PowerLineController();
213 
214  friend class PhysicalDimension;
215  void replaceIndexWhenRestoring(std::string name, int index);
216  DimensionNameIdTable::iterator findIndex(int index);
217  virtual void shutdown() override;
218 
219  DimensionNameIdTable m_nameIdTable;
221 
223  SimulationPowerLinesHash m_powerLinesInSimulation;
224 
227  ConnectorFactoryTable m_connectorFactories;
228 
229  private:
230 #ifndef SWIG
231  SINGLETON_CLASSNAME_METHOD()
232 #endif
233  static PowerLineController* s_instance;
234 
235  ConnectorRefSet m_connectors;
236 
237  };
238 }
239 
240 
241 #endif
Links two connections together.
Definition: Connector.h:53
agx::ref_ptr< PowerLinesHandler > PowerLinesHandlerRef
void AGXPHYSICS_EXPORT shutdown()
Shutdown of the AGX Dynamics API will be done when the number of shutdown matches the number of calls...
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a) ...
Definition: SymmetricPair.h:31
Derive from this class to implement a listener for simulation step events.
void addPowerLine(agxPowerLine::PowerLine *powerLine)
Called from the PowerLine&#39;s addNotification, via the PowerLineController, when a PowerLine has been a...
const agxPowerLine::PowerLineRefVector & getPowerLines()
Provides read access to the list of PowerLines that are part of this PowerLinesHandler.
ConnectorFactoryTable m_connectorFactories
A PowerLinesHandler is a collection of PowerLines that are part of the same agxSDK::Simulation.
SimulationPowerLinesHash m_powerLinesInSimulation
agx::HashVector< int, int > m_storeRestoreIdTranslator
Each type of physical dimension handled by the power line has to have a unique name.
agx::SymmetricPair< agxPowerLine::PhysicalDimension::Type > DimTypePair
void removePowerLine(agxPowerLine::PowerLine *powerLine)
Called from the PowerLine&#39;s removeNotification, via the PowerLineController, when a PowerLine has bee...
agx::Real TimeStamp
Definition: TimeStamp.h:26
agxPowerLine contains a collection of connected components that transport power across a system...
Definition: MotorUnit.h:23
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
virtual void post(const agx::TimeStamp &time) override
Called after a step is taken in the simulation Implement this method in the derived class to get call...
agx::HashTable< agxSDK::Simulation *, PowerLinesHandlerRef > SimulationPowerLinesHash
AGXMODEL_EXPORT agxPowerLine::PhysicalDimension::Type getDimensionType(const std::string &dimensionName)
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
AGXBRICK_EXPORT bool isInitialized()
#define AGXMODEL_EXPORT
std::function< Connector *()> ConnectorFactory
virtual void pre(const agx::TimeStamp &time) override
Called before a step is taken in the simulation Implement this method in the derived class to get cal...
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation...
Definition: PowerLine.h:70
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::HashTable< DimTypePair, ConnectorFactory > ConnectorFactoryTable
agx::HashTable< std::string, int > DimensionNameIdTable
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition: Singleton.h:30