AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
PowerLine.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
9having been advised so by Algoryx Simulation AB for a time limited evaluation,
10or having purchased a valid 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#pragma once
17
18#include <agxModel/export.h>
19#include <agxPowerLine/Unit.h>
20
24
25#include <agxUtil/agxUtil.h>
26
27#include <agx/RigidBody.h>
28#include <agx/Singleton.h>
30
34
35#include <agxSDK/Assembly.h>
36
37
38#include <agx/HashVector.h>
39
40
41
42
43#define POWER_LINE_DEBUG 0
44
45
46namespace agxPowerLine
47{
48
49 class Actuator;
50 class PowerLinesHandler;
51 class PowerLineCollector;
52
56
61
66 {
67 public:
68 public:
69
71
72 public:
77 int getDimensionType(std::string name);
78
83
88
94 void setAddUnitsOnConnect(agx::Bool addOnConnect);
96
102
103
104
116
130 bool add(agxPowerLine::Unit* component);
131 bool add(agxPowerLine::SubGraph* component);
133
134 size_t getNumUnits() const;
135 size_t getNumConnectors() const;
136
143 Unit* getUnit(const agx::Name& name);
144
151 const Unit* getUnit(const agx::Name& name) const;
152
153 template <typename T>
154 T* getUnit(const agx::Name& name);
155
161
166
167
169
171
173
178 bool writeDimensionsGraph(const agx::String& path) const;
179 bool writeDimensionsGraph(const char* path) const;
180
181
184
185 virtual void addNotification(agxSDK::Simulation* simulation) override;
186 virtual void removeNotification(agxSDK::Simulation* simulation) override;
187
191 virtual void addNotification(agxSDK::Assembly*) override {}
197 virtual void removeNotification(agxSDK::Assembly*) override {}
199
208 virtual bool store(agxStream::StorageStream& str) const;
209
220
222
223 static bool renderDebug();
224
231 static agxPowerLine::PowerLine* find(agxSDK::Simulation* simulation, const agx::Name& name);
232
240
247 static PowerLinePtrVector findAll( const agxSDK::Simulation* simulation, const agx::Name& name );
248
254 static PowerLinePtrVector findAll( const agxSDK::Simulation* simulation );
255
256 public:
260
264
268 void clearAddRemoveCache(ConnectorPtrVector& addedConnectors, UnitPtrVector& addedUnits);
269
270 protected:
271
272 friend class PowerLinesHandler;
273
274 virtual ~PowerLine();
275
276 bool traverseUnits(bool (*callback)(agxPowerLine::Unit*));
279
280 virtual void initialize();
281
282 void pre(agx::Real time);
283 void post(agx::Real time);
284
286
288
289 protected:
291
297
298
299
300 private:
301 bool shouldRenderDebug();
302
303 protected:
306
308
310
312
314
316
319
323 };
324
325
326 template <typename T>
328 {
329 for (auto& unit : m_units)
330 {
331 T* asT = dynamic_cast<T*>(unit.get());
332 if (unit->getName() == name && asT != nullptr)
333 {
334 return asT;
335 }
336 }
337 return nullptr;
338 }
339}
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
#define AGXMODEL_EXPORT
Links two connections together.
Definition: Connector.h:53
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation.
Definition: PowerLine.h:66
agx::Constraint::SolveType getSolveType() const
void setUnitPowerLine(agxPowerLine::Unit *unit)
Set the given Unit's PowerLine to this.
void clearAddRemoveCache(ConnectorPtrVector &addedConnectors, UnitPtrVector &addedUnits)
void post(agx::Real time)
static agxPowerLine::PowerLine * find(agxSDK::Simulation *simulation, const agx::Name &name)
Search the given simulation for a power line with the given name.
const Unit * getUnit(const agx::Name &name) const
Find and return the first unit with the given name, if any exist.
void pre(agx::Real time)
static PowerLinePtrVector findAll(const agxSDK::Simulation *simulation)
Finds all powerlines in the given simulation.
virtual void addNotification(agxSDK::Assembly *) override
Called when this assembly is added to another assembly.
Definition: PowerLine.h:191
void getRoots(agxPowerLine::UnitPtrPowerLinePtrHashVector &units) const
Get pointers to all roots, each connected to a sub graph.
agxPowerLine::Unit * getSource()
static PowerLinePtrVector findAll(const agxSDK::Simulation *simulation, const agx::Name &name)
Find all powerlines with given name.
ConnectorBoolHashVector m_tempConnectorHashVector
Definition: PowerLine.h:318
Unit * getUnit(const agx::Name &name)
Find and return the first unit with the given name, if any exist.
void createConstraintHolder()
Creates a constraint holder for all elementary constraints between the physical dimensions.
virtual void initialize()
bool removeConnector(agxPowerLine::Connector *connector)
bool traverseDimensions(bool(*callback)(agxPowerLine::PhysicalDimension *))
void restorePre46(agxStream::InputArchive &in)
agx::Bool getAddUnitsOnConnect() const
agxPowerLine::SlotMapper * getSlotMapper()
agxPowerLine::SubGraphRefVector m_cachedRemoves
Definition: PowerLine.h:321
const agxPowerLine::ConnectorRefSet & getConnectors() const
bool add(agxPowerLine::Unit *component)
bool writeDimensionsGraph(const char *path) const
bool remove(agxPowerLine::SubGraph *component)
virtual void addNotification(agxSDK::Simulation *simulation) override
Called when this assembly is added to a simulation (given that it not already is in the simulation).
void setAddUnitsOnConnect(agx::Bool addOnConnect)
Decide if: when units added to this powerLine are to be connected to units not belonging to any power...
SubGraphRouterBoolHashVector m_tempRouterHashVector
Definition: PowerLine.h:317
int getDimensionType(std::string name)
bool cacheRemove(agxPowerLine::SubGraph *component)
bool writeDimensionsGraph(const agx::String &path) const
Write the current graph state of the powerline to a .dot file (path)
agx::observer_ptr< agx::RigidBody > m_parentBody
Definition: PowerLine.h:309
size_t getNumConnectors() const
virtual void removeNotification(agxSDK::Assembly *) override
Called when this assembly is removed from another assembly.
Definition: PowerLine.h:197
bool setSource(agxPowerLine::Unit *source)
Set the unit the traverser shall start traversing from.
void insertConnectorTemporary(Connector *connector)
agxPowerLine::SlotMapperRef m_slotMapper
Definition: PowerLine.h:307
void setSolveType(agx::Constraint::SolveType solveType)
Set the current solve type DIRECT_AND_ITERATIVE is used by default.
virtual bool restore(agxStream::StorageStream &str)
Restores internal data from stream.
bool traverseConnectors(bool(*callback)(agxPowerLine::Connector *))
const agxPowerLine::UnitRefSetVector & getUnits() const
bool removeSubGraph(agxPowerLine::SubGraph *component)
virtual bool store(agxStream::StorageStream &str) const
Stores internal data for this PowerLine into stream.
size_t getNumUnits() const
virtual void removeNotification(agxSDK::Simulation *simulation) override
Called when this assembly is removed from a simulation.
void insertSubGraphRouterTemporary(SubGraph *router)
agx::Constraint::SolveType m_solveType
Definition: PowerLine.h:315
bool removeUnit(agxPowerLine::Unit *unit)
const agxPowerLine::Unit * getSource() const
agxPowerLine::UnitRefSetVector m_units
Definition: PowerLine.h:304
agxUtil::ConstraintHolderRef m_constraintHolder
Definition: PowerLine.h:311
static bool renderDebug()
agxPowerLine::SubGraphRefVector m_cachedAdds
Definition: PowerLine.h:320
bool traverseUnits(bool(*callback)(agxPowerLine::Unit *))
bool hasCachedOperations() const
agxUtil::ConstraintHolder * getConstraintHolder() const
bool setSource(agxPowerLine::SubGraph *source)
bool add(agxPowerLine::SubGraph *component)
bool pointAddConnector(agxPowerLine::Connector *connector)
static agxPowerLine::PowerLine * find(agxSDK::Assembly *assembly, const agx::Name &name)
Search the given assembly for a power line with the given name.
bool pointAddUnit(agxPowerLine::Unit *unit)
agxPowerLine::ConnectorRefSet m_connectors
Definition: PowerLine.h:305
bool pointReplace(agxPowerLine::Unit *oldUnit, agxPowerLine::Unit *newUnit)
bool cacheAdd(agxPowerLine::SubGraph *component)
A PowerLinesHandler is a collection of PowerLines that are part of the same agxSDK::Simulation.
The SlotMapper is reponsible for mapping one dimensional dimension states to slots in the RigidBodies...
Definition: SlotMapper.h:51
Pure virtual class.
Definition: Unit.h:72
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:70
virtual void removeNotification(agxSDK::Simulation *)
Called when this assembly is removed from a simulation.
Definition: Assembly.h:778
virtual void addNotification(agxSDK::Simulation *)
Called when this assembly is added to a simulation (given that it not already is in the simulation).
Definition: Assembly.h:773
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:49
Utility class to hold custom implementations of constraints.
Definition: agxUtil.h:523
SolveType
Specifies in what solvers the constraint will be solved.
Definition: Constraint.h:93
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:41
Representation of a name string.
Definition: Name.h:33
Vector containing 'raw' data.
Definition: agx/Vector.h:246
agxPowerLine contains a collection of connected components that transport power across a system.
Definition: MotorUnit.h:24
agx::Vector< PowerLineRef > PowerLineRefVector
Definition: PowerLine.h:60
agx::HashVector< agxPowerLine::Connector *, bool > ConnectorBoolHashVector
Definition: PowerLine.h:53
agx::observer_ptr< PowerLine > PowerLineObsPtr
Definition: PowerLine.h:57
agx::HashVector< agxPowerLine::Unit *, agxPowerLine::PowerLine * > UnitPtrPowerLinePtrHashVector
Definition: PowerLine.h:55
agx::HashVector< agxPowerLine::SubGraph *, bool > SubGraphRouterBoolHashVector
Definition: PowerLine.h:54
agx::VectorPOD< PowerLine * > PowerLinePtrVector
Definition: PowerLine.h:59
agx::ref_ptr< PowerLine > PowerLineRef
Definition: PowerLine.h:58
bool Bool
Definition: Integer.h:40
double Real
Definition: Real.h:41