AGX Dynamics  2.37.2.0
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 
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;
57 
61 
66 
71  {
72  public:
73  public:
74 
75  PowerLine();
76 
77  public:
82  int getDimensionType(std::string name);
83 
87  void createConstraintHolder();
88 
92  agxUtil::ConstraintHolder* getConstraintHolder() const;
93 
99  void setAddUnitsOnConnect(agx::Bool addOnConnect);
100  agx::Bool getAddUnitsOnConnect() const;
101 
106  void getRoots(agxPowerLine::UnitPtrPowerLinePtrHashVector& units) const;
107 
108 
109 
119  bool setSource(agxPowerLine::Unit* source);
120  bool setSource(agxPowerLine::SubGraph* source);
121 
125  const agxPowerLine::Unit* getSource() const;
126  agxPowerLine::Unit* getSource();
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 
158  template <typename T>
159  T* getUnit(const agx::Name& name);
160 
165  void setSolveType( agx::Constraint::SolveType solveType );
166 
170  agx::Constraint::SolveType getSolveType( ) const;
171 
172 
173  void insertSubGraphRouterTemporary(SubGraph* router);
174 
175  void insertConnectorTemporary( Connector* connector );
176 
177  void collectConstraintsToHolder();
178 
183  bool writeDimensionsGraph(const agx::String& path) const;
184  bool writeDimensionsGraph(const char* path) const;
185 
186 
187  const agxPowerLine::UnitRefSetVector& getUnits() const;
188  const agxPowerLine::ConnectorRefSet& getConnectors() const;
189 
190  virtual void addNotification(agxSDK::Simulation* simulation) override;
191  virtual void removeNotification(agxSDK::Simulation* simulation) override;
192 
196  virtual void addNotification(agxSDK::Assembly*) override {}
202  virtual void removeNotification(agxSDK::Assembly*) override {}
203  agxPowerLine::SlotMapper* getSlotMapper();
204 
213  virtual bool store(agxStream::StorageStream& str) const;
214 
224  virtual bool restore(agxStream::StorageStream& str);
225 
227 
228  static bool renderDebug();
229 
236  static agxPowerLine::PowerLine* find(agxSDK::Simulation* simulation, const agx::Name& name);
237 
244  static agxPowerLine::PowerLine* find(agxSDK::Assembly* assembly, const agx::Name& name);
245 
252  static PowerLinePtrVector findAll( const agxSDK::Simulation* simulation, const agx::Name& name );
253 
259  static PowerLinePtrVector findAll( const agxSDK::Simulation* simulation );
260 
261  public:
262  bool removeSubGraph(agxPowerLine::SubGraph* component);
263  bool removeUnit(agxPowerLine::Unit* unit);
264  bool removeConnector(agxPowerLine::Connector* connector);
265 
266  bool pointAddConnector(agxPowerLine::Connector* connector);
267  bool pointAddUnit(agxPowerLine::Unit* unit);
268  bool pointReplace( agxPowerLine::Unit* oldUnit, agxPowerLine::Unit* newUnit );
269 
270  bool cacheAdd(agxPowerLine::SubGraph* component);
271  bool cacheRemove(agxPowerLine::SubGraph* component);
272  bool hasCachedOperations() const;
273  void clearAddRemoveCache(ConnectorPtrVector& addedConnectors, UnitPtrVector& addedUnits);
274 
275  protected:
276 
277  friend class PowerLinesHandler;
278 
279  virtual ~PowerLine();
280 
281  bool traverseUnits(bool (*callback)(agxPowerLine::Unit*));
282  bool traverseDimensions(bool (*callback)(agxPowerLine::PhysicalDimension*));
283  bool traverseConnectors(bool (*callback)(agxPowerLine::Connector*));
284 
285  virtual void initialize();
286 
287  void pre(agx::Real time);
288  void post(agx::Real time);
289 
290  void prepareConstraintDimensions();
291 
292  bool preUpdateGraph();
293 
294  protected:
295  void restorePre46(agxStream::InputArchive& in);
296 
301  void setUnitPowerLine(agxPowerLine::Unit* unit);
302 
303 
304 
305  private:
306  bool shouldRenderDebug();
307 
308  protected:
311 
313 
315 
317 
319 
321 
322  SubGraphRouterBoolHashVector m_tempRouterHashVector;
323  ConnectorBoolHashVector m_tempConnectorHashVector;
324 
328  };
329 
330 
331  template <typename T>
333  {
334  for (auto& unit : m_units)
335  {
336  T* asT = dynamic_cast<T*>(unit.get());
337  if (unit->getName() == name && asT != nullptr)
338  {
339  return asT;
340  }
341  }
342  return nullptr;
343  }
344 }
345 
346 
347 // AGXMODEL_POWER_LINE_H
348 #endif
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
Links two connections together.
Definition: Connector.h:53
PowerLineTraverser that stores the nodes it visits.
Utility class to hold custom implementations of constraints.
Definition: agxUtil.h:463
agx::ref_ptr< PowerLine > PowerLineRef
agx::HashVector< agxPowerLine::Unit *, agxPowerLine::PowerLine * > UnitPtrPowerLinePtrHashVector
Definition: PowerLine.h:60
agx::VectorPOD< PowerLine *> PowerLinePtrVector
Definition: PowerLine.h:64
bool Bool
Definition: Integer.h:48
Unit * getUnit(const agx::Name &name)
Find and return the first unit with the given name, if any exist.
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
A PowerLinesHandler is a collection of PowerLines that are part of the same agxSDK::Simulation.
virtual void removeNotification(agxSDK::Simulation *)
Called when this assembly is removed from a simulation.
Definition: Assembly.h:621
agxPowerLine::SlotMapperRef m_slotMapper
Definition: PowerLine.h:312
agxPowerLine::SubGraphRefVector m_cachedRemoves
Definition: PowerLine.h:326
Representation of a name string.
Definition: Name.h:32
agxPowerLine contains a collection of connected components that transport power across a system...
Definition: MotorUnit.h:23
agxUtil::ConstraintHolderRef m_constraintHolder
Definition: PowerLine.h:316
agxPowerLine::ConnectorRefSet m_connectors
Definition: PowerLine.h:310
agx::HashVector< agxPowerLine::SubGraph *, bool > SubGraphRouterBoolHashVector
Definition: PowerLine.h:59
agx::HashVector< agxPowerLine::Connector *, bool > ConnectorBoolHashVector
Definition: PowerLine.h:56
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
agx::observer_ptr< PowerLine > PowerLineObsPtr
Definition: PowerLine.h:62
agx::Vector< PowerLineRef > PowerLineRefVector
ConnectorBoolHashVector m_tempConnectorHashVector
Definition: PowerLine.h:323
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
virtual void removeNotification(agxSDK::Assembly *) override
Called when this assembly is removed from another assembly.
Definition: PowerLine.h:202
agx::Constraint::SolveType m_solveType
Definition: PowerLine.h:320
agx::observer_ptr< agx::RigidBody > m_parentBody
Definition: PowerLine.h:314
virtual void addNotification(agxSDK::Assembly *) override
Called when this assembly is added to another assembly.
Definition: PowerLine.h:196
agxPowerLine::SubGraphRefVector m_cachedAdds
Definition: PowerLine.h:325
AGXMODEL_EXPORT agxPowerLine::PhysicalDimension::Type getDimensionType(const std::string &dimensionName)
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:48
SolveType
Specifies in what solvers the constraint will be solved.
Definition: Constraint.h:92
#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
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:616
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
#define AGXMODEL_EXPORT
double Real
Definition: Real.h:42
SubGraphRouterBoolHashVector m_tempRouterHashVector
Definition: PowerLine.h:322
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation...
Definition: PowerLine.h:70
agxPowerLine::UnitRefSetVector m_units
Definition: PowerLine.h:309
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints, geometries.
Definition: Assembly.h:66