AGX Dynamics  2.35.0.1
PowerLine.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
9 having been advised so by Algoryx Simulation AB for a time limited evaluation,
10 or having purchased a 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 AGXPOWERLINE_POWER_LINE_H
18 #define AGXPOWERLINE_POWER_LINE_H
19 
20 
21 
22 
23 #include <agxModel/export.h>
24 #include <agxPowerLine/Unit.h>
25 
27 #include <agxStream/Serializable.h>
29 
30 #include <agxUtil/agxUtil.h>
31 
32 #include <agx/RigidBody.h>
33 #include <agx/Singleton.h>
35 
39 
40 #include <agxSDK/Assembly.h>
41 
42 
43 #include <agx/HashVector.h>
44 
45 
46 
47 
48 #define POWER_LINE_DEBUG 0
49 
50 
51 namespace agxPowerLine
52 {
53 
54  class Actuator;
55  class PowerLinesHandler;
56  class PowerLineCollector;
57 
61 
66 
71  {
72  public:
73  public:
74 
76 
77  public:
82  int getDimensionType(std::string name);
83 
88 
93 
99  void setAddUnitsOnConnect(agx::Bool addOnConnect);
101 
107 
108 
109 
121 
135  bool add(agxPowerLine::Unit* component);
136  bool add(agxPowerLine::SubGraph* component);
137  bool remove(agxPowerLine::SubGraph* component);
138 
139  size_t getNumUnits() const;
140  size_t getNumConnectors() const;
141 
148  Unit* getUnit(const agx::Name& name);
149 
156  const Unit* getUnit(const agx::Name& name) const;
157 
163 
168 
169 
171 
173 
175 
180  bool writeDimensionsGraph(const agx::String& path) const;
181  bool writeDimensionsGraph(const char* path) const;
182 
183 
186 
187  virtual void addNotification(agxSDK::Simulation* simulation) override;
188  virtual void removeNotification(agxSDK::Simulation* simulation) override;
189 
193  virtual void addNotification(agxSDK::Assembly*) override {}
199  virtual void removeNotification(agxSDK::Assembly*) override {}
201 
210  virtual bool store(agxStream::StorageStream& str) const;
211 
221  virtual bool restore(agxStream::StorageStream& str);
222 
224 
225  static bool renderDebug();
226 
233  static agxPowerLine::PowerLine* find(agxSDK::Simulation* simulation, const agx::Name& name);
234 
241  static agxPowerLine::PowerLine* find(agxSDK::Assembly* assembly, const agx::Name& name);
242 
249  static PowerLinePtrVector findAll( const agxSDK::Simulation* simulation, const agx::Name& name );
250 
256  static PowerLinePtrVector findAll( const agxSDK::Simulation* simulation );
257 
258  public:
262 
266 
269  bool hasCachedOperations() const;
270  void clearAddRemoveCache(ConnectorPtrVector& addedConnectors, UnitPtrVector& addedUnits);
271 
272  protected:
273 
274  friend class PowerLinesHandler;
275 
276  virtual ~PowerLine();
277 
278  bool traverseUnits(bool (*callback)(agxPowerLine::Unit*));
280  bool traverseConnectors(bool (*callback)(agxPowerLine::Connector*));
281 
282  virtual void initialize();
283 
284  void pre(agx::Real time);
285  void post(agx::Real time);
286 
288 
290 
291  protected:
293 
299 
300 
301 
302  private:
303  bool shouldRenderDebug();
304 
305  protected:
308 
310 
312 
314 
316 
318 
321 
325  };
326 }
327 
328 
329 // AGXMODEL_POWER_LINE_H
330 #endif
#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:54
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation.
Definition: PowerLine.h:71
const Unit * getUnit(const agx::Name &name) const
Find and return the first unit with the given name, if any exist.
agx::Constraint::SolveType getSolveType() const
void setUnitPowerLine(agxPowerLine::Unit *unit)
Set the given Unit's PowerLine to this.
void clearAddRemoveCache(ConnectorPtrVector &addedConnectors, UnitPtrVector &addedUnits)
const agxPowerLine::Unit * getSource() const
void post(agx::Real time)
void pre(agx::Real time)
const agxPowerLine::ConnectorRefSet & getConnectors() const
agxPowerLine::SlotMapper * getSlotMapper()
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:193
void getRoots(agxPowerLine::UnitPtrPowerLinePtrHashVector &units) const
Get pointers to all roots, each connected to a sub graph.
const agxPowerLine::UnitRefSetVector & getUnits() const
static PowerLinePtrVector findAll(const agxSDK::Simulation *simulation, const agx::Name &name)
Find all powerlines with given name.
ConnectorBoolHashVector m_tempConnectorHashVector
Definition: PowerLine.h:320
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::SubGraphRefVector m_cachedRemoves
Definition: PowerLine.h:323
bool add(agxPowerLine::Unit *component)
bool writeDimensionsGraph(const char *path) const
agxUtil::ConstraintHolder * getConstraintHolder() 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:319
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)
static agxPowerLine::PowerLine * find(agxSDK::Simulation *simulation, const agx::Name &name)
Search the given simulation for a power line with the given name.
agx::observer_ptr< agx::RigidBody > m_parentBody
Definition: PowerLine.h:311
agxPowerLine::Unit * getSource()
size_t getNumConnectors() const
virtual void removeNotification(agxSDK::Assembly *) override
Called when this assembly is removed from another assembly.
Definition: PowerLine.h:199
bool setSource(agxPowerLine::Unit *source)
Set the unit the traverser shall start traversing from.
void insertConnectorTemporary(Connector *connector)
Unit * getUnit(const agx::Name &name)
Find and return the first unit with the given name, if any exist.
agxPowerLine::SlotMapperRef m_slotMapper
Definition: PowerLine.h:309
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 *))
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:317
bool removeUnit(agxPowerLine::Unit *unit)
agxPowerLine::UnitRefSetVector m_units
Definition: PowerLine.h:306
static agxPowerLine::PowerLine * find(agxSDK::Assembly *assembly, const agx::Name &name)
Search the given assembly for a power line with the given name.
agxUtil::ConstraintHolderRef m_constraintHolder
Definition: PowerLine.h:313
static bool renderDebug()
agxPowerLine::SubGraphRefVector m_cachedAdds
Definition: PowerLine.h:322
bool traverseUnits(bool(*callback)(agxPowerLine::Unit *))
bool hasCachedOperations() const
bool setSource(agxPowerLine::SubGraph *source)
bool add(agxPowerLine::SubGraph *component)
bool pointAddConnector(agxPowerLine::Connector *connector)
bool pointAddUnit(agxPowerLine::Unit *unit)
agxPowerLine::ConnectorRefSet m_connectors
Definition: PowerLine.h:307
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:52
Pure virtual class.
Definition: Unit.h:73
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:67
virtual void removeNotification(agxSDK::Simulation *)
Called when this assembly is removed from a simulation.
Definition: Assembly.h:618
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:613
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:52
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:464
SolveType
Specifies in what solvers the constraint will be solved.
Definition: Constraint.h:93
Representation of a name string.
Definition: Name.h:33
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::Vector< PowerLineRef > PowerLineRefVector
agx::HashVector< agxPowerLine::Connector *, bool > ConnectorBoolHashVector
Definition: PowerLine.h:56
agx::observer_ptr< PowerLine > PowerLineObsPtr
Definition: PowerLine.h:62
agx::HashVector< agxPowerLine::Unit *, agxPowerLine::PowerLine * > UnitPtrPowerLinePtrHashVector
Definition: PowerLine.h:60
agx::HashVector< agxPowerLine::SubGraph *, bool > SubGraphRouterBoolHashVector
Definition: PowerLine.h:59
agx::VectorPOD< PowerLine * > PowerLinePtrVector
Definition: PowerLine.h:64
agx::ref_ptr< PowerLine > PowerLineRef
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
bool Bool
Definition: Integer.h:48
double Real
Definition: Real.h:42