AGXDynamics  2.31.1.0
PowerLine.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 
162  void setSolveType( agx::Constraint::SolveType solveType );
163 
167  agx::Constraint::SolveType getSolveType( ) const;
168 
169 
170  void insertSubGraphRouterTemporary(SubGraph* router);
171 
172  void insertConnectorTemporary( Connector* connector );
173 
174  void collectConstraintsToHolder();
175 
180  bool writeDimensionsGraph(const agx::String& path) const;
181  bool writeDimensionsGraph(const char* path) const;
182 
183 
184  const agxPowerLine::UnitRefSetVector& getUnits() const;
185  const agxPowerLine::ConnectorRefSet& getConnectors() const;
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 {}
200  agxPowerLine::SlotMapper* getSlotMapper();
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:
259  bool removeSubGraph(agxPowerLine::SubGraph* component);
260  bool removeUnit(agxPowerLine::Unit* unit);
261  bool removeConnector(agxPowerLine::Connector* connector);
262 
263  bool pointAddConnector(agxPowerLine::Connector* connector);
264  bool pointAddUnit(agxPowerLine::Unit* unit);
265  bool pointReplace( agxPowerLine::Unit* oldUnit, agxPowerLine::Unit* newUnit );
266 
267  bool cacheAdd(agxPowerLine::SubGraph* component);
268  bool cacheRemove(agxPowerLine::SubGraph* component);
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*));
279  bool traverseDimensions(bool (*callback)(agxPowerLine::PhysicalDimension*));
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 
287  void prepareConstraintDimensions();
288 
289  bool preUpdateGraph();
290 
291  protected:
292  void restorePre46(agxStream::InputArchive& in);
293 
298  void setUnitPowerLine(agxPowerLine::Unit* unit);
299 
300 
301 
302  private:
303  bool shouldRenderDebug();
304 
305  protected:
308 
310 
312 
314 
316 
318 
319  SubGraphRouterBoolHashVector m_tempRouterHashVector;
320  ConnectorBoolHashVector m_tempConnectorHashVector;
321 
322  agxPowerLine::SubGraphRefVector m_cachedAdds;
323  agxPowerLine::SubGraphRefVector m_cachedRemoves;
325  };
326 }
327 
328 
329 // AGXMODEL_POWER_LINE_H
330 #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:384
agx::ref_ptr< PowerLine > PowerLineRef
Definition: PowerLine.h:63
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
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:584
agxPowerLine::SlotMapperRef m_slotMapper
Definition: PowerLine.h:309
agxPowerLine::SubGraphRefVector m_cachedRemoves
Definition: PowerLine.h:323
Representation of a name string.
Definition: Name.h:32
agxUtil::ConstraintHolderRef m_constraintHolder
Definition: PowerLine.h:313
agxPowerLine::ConnectorRefSet m_connectors
Definition: PowerLine.h:307
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
Definition: PowerLine.h:65
ConnectorBoolHashVector m_tempConnectorHashVector
Definition: PowerLine.h:320
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:199
agx::Constraint::SolveType m_solveType
Definition: PowerLine.h:317
agx::observer_ptr< agx::RigidBody > m_parentBody
Definition: PowerLine.h:311
virtual void addNotification(agxSDK::Assembly *) override
Called when this assembly is added to another assembly.
Definition: PowerLine.h:193
agxPowerLine::SubGraphRefVector m_cachedAdds
Definition: PowerLine.h:322
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:90
#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:206
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:579
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
#define AGXMODEL_EXPORT
double Real
Definition: Real.h:42
SubGraphRouterBoolHashVector m_tempRouterHashVector
Definition: PowerLine.h:319
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:306
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints, geometries.
Definition: Assembly.h:73