AGX Dynamics  2.38.0.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 #pragma once
18 
19 
20 #include <agxModel/export.h>
21 #include <agxPowerLine/Unit.h>
22 #include <agxPowerLine/PowerLine.h>
23 
24 #include <agx/Singleton.h>
25 #include <agx/HashTable.h>
26 #include <agx/HashVector.h>
27 
28 #include <functional>
29 
30 
31 namespace agxPowerLine
32 {
33 
40  {
41  public:
46  void addPowerLine(agxPowerLine::PowerLine* powerLine);
47 
53 
57  bool empty() const;
58 
59  virtual void pre(const agx::TimeStamp& time) override;
60  virtual void post(const agx::TimeStamp& time) override;
61 
66 
67  private:
68  virtual ~PowerLinesHandler();
70  };
71 
73 
74 
75 
89  {
90  public:
91  typedef std::function<Connector*()> ConnectorFactory;
92 
93  public:
98  bool addPhysicalDimension(std::string name);
99 
105  void add(agxPowerLine::Connector* connector);
106  void remove(agxPowerLine::Connector* connector);
107 
108 
109  bool getPowerLines(agxSDK::Simulation* simulation, PowerLinePtrVector& powerLines);
110 
119  int getDimensionType(std::string name);
120 
124  std::string getDimensionTypeName(size_t id);
125 
130  agxPowerLine::PhysicalDimension::Type getNumberOfPhysicalDimensions();
131 
137  void setStoredPhysicalDimensionId(int currentId, int previousId);
138 
147  bool hasStoredDimensionsMappings() const;
148 
157  int getStoredPhysicalDimensionId(int currentId);
158 
169  int getCurrentPhysicalDimensionId(int storedId);
170 
175  void clearStoredPhysicalDimensionIds();
176 
177 
178  void registerDefaultConnector(
181  ConnectorFactory connectorCreator);
182 
183  agxPowerLine::Connector* createConnector(
185  agxPowerLine::PhysicalDimension::Type outputType) const;
186 
190  static PowerLineController* instance();
191 
195  static bool isInitialized();
196 
197 
198  private:
200  void registerPowerLine(agxPowerLine::PowerLine* powerLine);
201  void unregisterPowerLine(agxPowerLine::PowerLine* powerLine, agxSDK::Simulation* simulation);
202 
203  protected:
205 
206 
208 
209  virtual ~PowerLineController();
210 
211  friend class PhysicalDimension;
212  void replaceIndexWhenRestoring(std::string name, int index);
213  DimensionNameIdTable::iterator findIndex(int index);
214  virtual void shutdown() override;
215 
218 
221 
225 
226  private:
227 #ifndef SWIG
228  SINGLETON_CLASSNAME_METHOD()
229 #endif
230  static PowerLineController* s_instance;
231 
232  ConnectorRefSet m_connectors;
233 
234  };
235 }
agxPowerLine::PowerLineController::DimensionNameIdTable
agx::HashTable< std::string, int > DimensionNameIdTable
Definition: PowerLineController.h:204
agx::SymmetricPair
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:31
PowerLine.h
agxSDK::StepEventListener
Derive from this class to implement a listener for simulation step events.
Definition: StepEventListener.h:37
agxPowerLine::PowerLinesHandlerRef
agx::ref_ptr< PowerLinesHandler > PowerLinesHandlerRef
Definition: PowerLineController.h:72
agx::Vector< PowerLineRef >
Unit.h
agxPowerLine::PowerLineController::m_storeRestoreIdTranslator
agx::HashVector< int, int > m_storeRestoreIdTranslator
Definition: PowerLineController.h:217
agxPowerLine::PowerLineController::m_connectorFactories
ConnectorFactoryTable m_connectorFactories
Definition: PowerLineController.h:224
export.h
HashTable.h
agxPowerLine::PowerLineController::DimTypePair
agx::SymmetricPair< agxPowerLine::PhysicalDimension::Type > DimTypePair
Definition: PowerLineController.h:222
HashVector.h
agxPowerLine::PowerLineController::m_powerLinesInSimulation
SimulationPowerLinesHash m_powerLinesInSimulation
Definition: PowerLineController.h:220
agxPowerLine::PowerLinesHandler::addPowerLine
void addPowerLine(agxPowerLine::PowerLine *powerLine)
Called from the PowerLine's addNotification, via the PowerLineController, when a PowerLine has been a...
agxPowerLine::PhysicalDimension
Pure virtual class.
Definition: PhysicalDimension.h:92
agxPowerLine::PowerLinesHandler
A PowerLinesHandler is a collection of PowerLines that are part of the same agxSDK::Simulation.
Definition: PowerLineController.h:39
agx::VectorPOD
Vector containing 'raw' data.
Definition: Vector.h:245
agxPowerLine::PhysicalDimension::Type
int Type
Definition: PhysicalDimension.h:95
agxPowerLine::PowerLineController::m_nameIdTable
DimensionNameIdTable m_nameIdTable
Definition: PowerLineController.h:216
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agx::isInitialized
bool AGXPHYSICS_EXPORT isInitialized()
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agx::shutdown
void AGXPHYSICS_EXPORT shutdown()
Shutdown of the AGX Dynamics API will be done when the number of shutdown matches the number of calls...
agx::SetVector< ConnectorRef >
agx::Singleton
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition: Singleton.h:30
agxPowerLine::PowerLinesHandler::post
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...
agxPowerLine::PowerLinesHandler::removePowerLine
void removePowerLine(agxPowerLine::PowerLine *powerLine)
Called from the PowerLine's removeNotification, via the PowerLineController, when a PowerLine has bee...
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashTable.h:926
agxPowerLine::PowerLine
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation.
Definition: PowerLine.h:65
agxPowerLine::PowerLineController::SimulationPowerLinesHash
agx::HashTable< agxSDK::Simulation *, PowerLinesHandlerRef > SimulationPowerLinesHash
Definition: PowerLineController.h:219
agxPowerLine::PowerLinesHandler::getPowerLines
const agxPowerLine::PowerLineRefVector & getPowerLines()
Provides read access to the list of PowerLines that are part of this PowerLinesHandler.
agxPowerLine
agxPowerLine contains a collection of connected components that transport power across a system.
Definition: MotorUnit.h:23
agxPowerLine::Connector
Links two connections together.
Definition: Connector.h:52
agx::TimeStamp
agx::Real TimeStamp
Definition: TimeStamp.h:26
Singleton.h
agxPowerLine::PowerLineController::ConnectorFactory
std::function< Connector *()> ConnectorFactory
Definition: PowerLineController.h:91
agxPowerLine::PowerLineController
Each type of physical dimension handled by the power line has to have a unique name.
Definition: PowerLineController.h:88
AGXMODEL_EXPORT
#define AGXMODEL_EXPORT
Definition: agxModel/export.h:42
agxPowerLine::getDimensionType
AGXMODEL_EXPORT agxPowerLine::PhysicalDimension::Type getDimensionType(const std::string &dimensionName)
agxPowerLine::PowerLineController::ConnectorFactoryTable
agx::HashTable< DimTypePair, ConnectorFactory > ConnectorFactoryTable
Definition: PowerLineController.h:223
agx::HashVector< int, int >
agxPowerLine::PowerLinesHandler::pre
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...
agxPowerLine::PowerLinesHandler::empty
bool empty() const