AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
PowerLineController.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19
20#include <agxModel/export.h>
21#include <agxPowerLine/Unit.h>
23
24#include <agx/Singleton.h>
25#include <agx/HashTable.h>
26#include <agx/HashVector.h>
27
28#include <functional>
29
30
31namespace agxPowerLine
32{
33
40 {
41 public:
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);
107
108
110
119 int getDimensionType(std::string name);
120
124 std::string getDimensionTypeName(size_t id);
125
131
137 void setStoredPhysicalDimensionId(int currentId, int previousId);
138
148
158
170
176
177
181 ConnectorFactory connectorCreator);
182
186
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
210
211 friend class PhysicalDimension;
212 void replaceIndexWhenRestoring(std::string name, 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}
#define AGXMODEL_EXPORT
Links two connections together.
Definition: Connector.h:53
Each type of physical dimension handled by the power line has to have a unique name.
void clearStoredPhysicalDimensionIds()
Clear the stored-to-current type ID mappings so that future PowerLine restores doesn't accidentally u...
void setStoredPhysicalDimensionId(int currentId, int previousId)
Used while preparing power line for being restored.
agx::HashVector< int, int > m_storeRestoreIdTranslator
DimensionNameIdTable::iterator findIndex(int index)
int getDimensionType(std::string name)
agx::HashTable< DimTypePair, ConnectorFactory > ConnectorFactoryTable
int getStoredPhysicalDimensionId(int currentId)
Usable during restore of power line to map between indices in PhysicalDimension::m_dimensions.
bool getPowerLines(agxSDK::Simulation *simulation, PowerLinePtrVector &powerLines)
agx::HashTable< agxSDK::Simulation *, PowerLinesHandlerRef > SimulationPowerLinesHash
bool addPhysicalDimension(std::string name)
Add a named physical dimension.
std::function< Connector *()> ConnectorFactory
static PowerLineController * instance()
agxPowerLine::Connector * createConnector(agxPowerLine::PhysicalDimension::Type inputType, agxPowerLine::PhysicalDimension::Type outputType) const
agxPowerLine::PhysicalDimension::Type getNumberOfPhysicalDimensions()
agx::HashTable< std::string, int > DimensionNameIdTable
void replaceIndexWhenRestoring(std::string name, int index)
agx::SymmetricPair< agxPowerLine::PhysicalDimension::Type > DimTypePair
bool hasStoredDimensionsMappings() const
Return true if mappings for stored dimensions IDs has been configured.
virtual void shutdown() override
Implement this method to cleanup your Singleton class.
int getCurrentPhysicalDimensionId(int storedId)
Converts a stored PhysicalDimension type ID to the corresponding ID for the current PowerLineControll...
SimulationPowerLinesHash m_powerLinesInSimulation
std::string getDimensionTypeName(size_t id)
void registerDefaultConnector(agxPowerLine::PhysicalDimension::Type inputType, agxPowerLine::PhysicalDimension::Type outputType, ConnectorFactory connectorCreator)
void remove(agxPowerLine::Connector *connector)
void add(agxPowerLine::Connector *connector)
The PowerLineController is in charge of keeping reference pointers to connectors that are created but...
ConnectorFactoryTable m_connectorFactories
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation.
Definition: PowerLine.h:66
A PowerLinesHandler is a collection of PowerLines that are part of the same agxSDK::Simulation.
void addPowerLine(agxPowerLine::PowerLine *powerLine)
Called from the PowerLine's addNotification, via the PowerLineController, when a PowerLine has been a...
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...
const agxPowerLine::PowerLineRefVector & getPowerLines()
Provides read access to the list of PowerLines that are part of this PowerLinesHandler.
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...
void removePowerLine(agxPowerLine::PowerLine *powerLine)
Called from the PowerLine's removeNotification, via the PowerLineController, when a PowerLine has bee...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Derive from this class to implement a listener for simulation step events.
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:41
Inheritance with partial specialization due to bug with ref_ptr containers.
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
Definition: Singleton.h:31
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:32
Vector containing 'raw' data.
Definition: agx/Vector.h:246
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
agxPowerLine contains a collection of connected components that transport power across a system.
Definition: MotorUnit.h:24
agx::ref_ptr< PowerLinesHandler > PowerLinesHandlerRef
agx::Real TimeStamp
Definition: TimeStamp.h:26