AGX Dynamics  2.38.0.2
PowerLine.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
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 #pragma once
17 
18 #include <agxModel/export.h>
19 #include <agxPowerLine/Unit.h>
20 
22 #include <agxStream/Serializable.h>
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 
46 namespace agxPowerLine
47 {
48 
49  class Actuator;
50  class PowerLinesHandler;
52 
56 
61 
66  {
67  public:
68  public:
69 
70  PowerLine();
71 
72  public:
77  int getDimensionType(std::string name);
78 
82  void createConstraintHolder();
83 
87  agxUtil::ConstraintHolder* getConstraintHolder() const;
88 
94  void setAddUnitsOnConnect(agx::Bool addOnConnect);
95  agx::Bool getAddUnitsOnConnect() const;
96 
101  void getRoots(agxPowerLine::UnitPtrPowerLinePtrHashVector& units) const;
102 
103 
104 
114  bool setSource(agxPowerLine::Unit* source);
115  bool setSource(agxPowerLine::SubGraph* source);
116 
120  const agxPowerLine::Unit* getSource() const;
121  agxPowerLine::Unit* getSource();
130  bool add(agxPowerLine::Unit* component);
131  bool add(agxPowerLine::SubGraph* component);
132  bool remove(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 
160  void setSolveType( agx::Constraint::SolveType solveType );
161 
165  agx::Constraint::SolveType getSolveType( ) const;
166 
167 
168  void insertSubGraphRouterTemporary(SubGraph* router);
169 
170  void insertConnectorTemporary( Connector* connector );
171 
172  void collectConstraintsToHolder();
173 
178  bool writeDimensionsGraph(const agx::String& path) const;
179  bool writeDimensionsGraph(const char* path) const;
180 
181 
182  const agxPowerLine::UnitRefSetVector& getUnits() const;
183  const agxPowerLine::ConnectorRefSet& getConnectors() const;
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 {}
198  agxPowerLine::SlotMapper* getSlotMapper();
199 
208  virtual bool store(agxStream::StorageStream& str) const;
209 
219  virtual bool restore(agxStream::StorageStream& str);
220 
222 
223  static bool renderDebug();
224 
231  static agxPowerLine::PowerLine* find(agxSDK::Simulation* simulation, const agx::Name& name);
232 
239  static agxPowerLine::PowerLine* find(agxSDK::Assembly* assembly, const agx::Name& name);
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:
257  bool removeSubGraph(agxPowerLine::SubGraph* component);
258  bool removeUnit(agxPowerLine::Unit* unit);
259  bool removeConnector(agxPowerLine::Connector* connector);
260 
261  bool pointAddConnector(agxPowerLine::Connector* connector);
262  bool pointAddUnit(agxPowerLine::Unit* unit);
263  bool pointReplace( agxPowerLine::Unit* oldUnit, agxPowerLine::Unit* newUnit );
264 
265  bool cacheAdd(agxPowerLine::SubGraph* component);
266  bool cacheRemove(agxPowerLine::SubGraph* component);
267  bool hasCachedOperations() const;
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*));
277  bool traverseDimensions(bool (*callback)(agxPowerLine::PhysicalDimension*));
278  bool traverseConnectors(bool (*callback)(agxPowerLine::Connector*));
279 
280  virtual void initialize();
281 
282  void pre(agx::Real time);
283  void post(agx::Real time);
284 
285  void prepareConstraintDimensions();
286 
287  bool preUpdateGraph();
288 
289  protected:
290  void restorePre46(agxStream::InputArchive& in);
291 
296  void setUnitPowerLine(agxPowerLine::Unit* unit);
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 }
agxPowerLine::PowerLine::m_cachedAdds
agxPowerLine::SubGraphRefVector m_cachedAdds
Definition: PowerLine.h:320
agxPowerLine::PowerLine::m_cacheAddsAndRemoves
bool m_cacheAddsAndRemoves
Definition: PowerLine.h:322
agxPowerLine::UnitPtrPowerLinePtrHashVector
agx::HashVector< agxPowerLine::Unit *, agxPowerLine::PowerLine * > UnitPtrPowerLinePtrHashVector
Definition: PowerLine.h:55
agxPowerLine::PowerLine::m_slotMapper
agxPowerLine::SlotMapperRef m_slotMapper
Definition: PowerLine.h:307
agx::Real
double Real
Definition: Real.h:42
agxPowerLine::PowerLine::removeNotification
virtual void removeNotification(agxSDK::Assembly *) override
Called when this assembly is removed from another assembly.
Definition: PowerLine.h:197
agxPowerLine::PowerLine::m_cachedRemoves
agxPowerLine::SubGraphRefVector m_cachedRemoves
Definition: PowerLine.h:321
agxPowerLine::SubGraph
Definition: SubGraph.h:58
agx::Vector< PowerLineRef >
agxPowerLine::PowerLine::m_solveType
agx::Constraint::SolveType m_solveType
Definition: PowerLine.h:315
Unit.h
agxPowerLine::PowerLine::addNotification
virtual void addNotification(agxSDK::Assembly *) override
Called when this assembly is added to another assembly.
Definition: PowerLine.h:191
export.h
HashVector.h
agxUtil::ConstraintHolder
Utility class to hold custom implementations of constraints.
Definition: agxUtil.h:463
TranslationalDimension.h
agxPowerLine::PowerLineRef
agx::ref_ptr< PowerLine > PowerLineRef
Definition: PowerLine.h:58
Assembly.h
agxStream::StorageStream
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:48
StepEventListener.h
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
AGXSTREAM_DECLARE_SERIALIZABLE
#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
agx::VectorPOD
Vector containing 'raw' data.
Definition: Vector.h:245
agx::observer_ptr< PowerLine >
agxPowerLine::PowerLine::m_tempRouterHashVector
SubGraphRouterBoolHashVector m_tempRouterHashVector
Definition: PowerLine.h:317
agxStream::in
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:399
agxPowerLine::Unit
Pure virtual class.
Definition: Unit.h:71
agxPowerLine::PowerLine::m_tempConnectorHashVector
ConnectorBoolHashVector m_tempConnectorHashVector
Definition: PowerLine.h:318
agxSDK::Assembly
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:67
agxPowerLine::PowerLineObsPtr
agx::observer_ptr< PowerLine > PowerLineObsPtr
Definition: PowerLine.h:57
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agx::SetVector< UnitRef >
agxPowerLine::PowerLine::m_connectors
agxPowerLine::ConnectorRefSet m_connectors
Definition: PowerLine.h:305
agxPowerLine::SubGraphRouterBoolHashVector
agx::HashVector< agxPowerLine::SubGraph *, bool > SubGraphRouterBoolHashVector
Definition: PowerLine.h:54
agxPowerLine::PowerLine
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation.
Definition: PowerLine.h:65
agxPowerLine::PowerLineRefVector
agx::Vector< PowerLineRef > PowerLineRefVector
Definition: PowerLine.h:60
agxPowerLine::PowerLine::m_addOnConnect
bool m_addOnConnect
Definition: PowerLine.h:313
agxPowerLine::PowerLineCollector
PowerLineTraverser that stores the nodes it visits.
Definition: PowerLineTraverser.h:184
agxPowerLine::ConnectorBoolHashVector
agx::HashVector< agxPowerLine::Connector *, bool > ConnectorBoolHashVector
Definition: PowerLine.h:51
agx::Name
Representation of a name string.
Definition: Name.h:32
agxPowerLine::SlotMapper
The SlotMapper is reponsible for mapping one dimensional dimension states to slots in the RigidBodies...
Definition: SlotMapper.h:50
Serializable.h
agxPowerLine::PowerLine::getUnit
Unit * getUnit(const agx::Name &name)
Find and return the first unit with the given name, if any exist.
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:50
RigidBody.h
agxPowerLine
agxPowerLine contains a collection of connected components that transport power across a system.
Definition: MotorUnit.h:23
ElementaryConstraint.h
agxPowerLine::Connector
Links two connections together.
Definition: Connector.h:52
agx::Bool
bool Bool
Definition: Integer.h:40
Singleton.h
agxPowerLine::PowerLine::m_units
agxPowerLine::UnitRefSetVector m_units
Definition: PowerLine.h:304
AGXMODEL_EXPORT
#define AGXMODEL_EXPORT
Definition: agxModel/export.h:42
agxPowerLine::getDimensionType
AGXMODEL_EXPORT agxPowerLine::PhysicalDimension::Type getDimensionType(const std::string &dimensionName)
agx::Constraint::SolveType
SolveType
Specifies in what solvers the constraint will be solved.
Definition: Constraint.h:92
agx::AgXString< std::string >
RotationalDimension.h
agxPowerLine::PowerLine::m_constraintHolder
agxUtil::ConstraintHolderRef m_constraintHolder
Definition: PowerLine.h:311
agx::HashVector< agxPowerLine::Connector *, bool >
StorageStream.h
agxPowerLine::PowerLinePtrVector
agx::VectorPOD< PowerLine * > PowerLinePtrVector
Definition: PowerLine.h:59
agxPowerLine::PowerLine::m_parentBody
agx::observer_ptr< agx::RigidBody > m_parentBody
Definition: PowerLine.h:309
agxSDK::Assembly::removeNotification
virtual void removeNotification(agxSDK::Simulation *)
Called when this assembly is removed from a simulation.
Definition: Assembly.h:657
SlotMapper.h
agxUtil.h
agxSDK::Assembly::addNotification
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:652