AGX Dynamics  2.35.0.1
Unit.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 having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 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_UNIT_H
18 #define AGXPOWERLINE_UNIT_H
19 
20 #include <agxModel/export.h>
23 #include <agxPowerLine/Connector.h>
24 #include <agxPowerLine/SubGraph.h>
25 
27 #include <agxStream/Serializable.h>
28 
29 #include <agxUtil/agxUtil.h>
30 
31 #include <agx/RigidBody.h>
33 
34 
35 namespace agxPowerLine
36 {
37  /************************************************************************/
38  /*
39  The agxPowerLine::PowerLine implementation is the base for energy transportation
40  in a 1D physical system.
41 
42  The energy is stored in units connected by connectors. Each unit can have a set of both
43  in and out connections, representing different physical dimensions.
44 
45  The physical dimensions can either be dynamically solved or be represented as
46  a kinematic calculator that uses a lookup table to calculate its current state
47  given the surrounding units. It could affect the power produced in its dynamically
48  solved parent, or the state of gradient for that parent.(For example a look up table
49  working as a gear box for a drive train will affect the torque and RPM of the
50  incoming shaft. Since it has no shaft of its own it will convert the parent shaft )
51  */
52  /************************************************************************/
53  class Unit;
54  class Traverser;
63 
64 
66 
67 
73  {
74  public:
78  Unit();
79 
83  virtual bool isValid() const;
84 
88  virtual bool isConnected(agxPowerLine::Unit* otherUnit) const;
89 
91 
97  void attach(agx::RigidBody* body);
98 
104  virtual bool connect(agxPowerLine::Connector* connector);
105 
113  virtual bool connect(
114  agxPowerLine::Side mySide,
115  agxPowerLine::Side connectorSide,
116  agxPowerLine::Connector* connector);
117 
122  virtual bool connect(agxPowerLine::Unit* otherUnit);
123 
124  virtual bool connect(
125  agxPowerLine::Side mySide,
126  agxPowerLine::Side otherSide,
127  agxPowerLine::Unit* other);
128 
129 
130 
131  virtual bool disconnect(agxPowerLine::Unit* unit);
132 
134 
135 
136 
137  // Methods called by the rest of the PowerLine/Hydraulics frame work.
138  public:
145 
151 
154 
165 
166 
170  virtual size_t getNumConnectableDimensions(Side side) const;
171 
172 
177  void getOwnConnectedUnits(UnitPtrSetVector& unitSet, bool startFromCleanUnitSet = true) const;
178  void getOwnConnectedUnits(UnitPtrSetVector& unitSet, agxPowerLine::Side side, bool startFromCleanUnitSet = true) const;
179 
186 
187 
194 
195 
202 
207  size_t getNumActiveDimensions() const;
208 
214 
215  /*
216  Functions called by static functions. Do NOT use them.
217  */
218 
219 
222 
229  virtual bool addNotification(agxSDK::Simulation* simulation) override;
230  virtual bool removeNotification(agxUtil::ConstraintHolder* constraintHolder, agxSDK::Simulation* simulation) override;
232 
233 
234  agxPowerLine::PowerLine* getPowerLine() const;
235 
237  bool hasConnector( const Connector* connector ) const;
238 
239 
242  size_t getNumConnections() const;
243 
253  size_t getConnectors(const agxPowerLine::Unit* unit, agxPowerLine::ConnectorPtrVector& result);
254  size_t getInputConnectors(const agxPowerLine::Unit* unit, agxPowerLine::ConnectorPtrVector& result);
255  size_t getOutputConnectors(const agxPowerLine::Unit* unit, agxPowerLine::ConnectorPtrVector& result);
256 
257  size_t getConnectors(agxPowerLine::ConnectorPtrVector& result) const;
258  size_t getInputConnectors(agxPowerLine::ConnectorPtrVector& result) const;
259  size_t getOutputConnectors(agxPowerLine::ConnectorPtrVector& result) const;
260 
261 
262  Connector* getFirstInputConnector(const agxPowerLine::Unit* unit) const;
263  Connector* getFirstOutputConnector(const agxPowerLine::Unit* unit) const;
264 
265  agxPowerLine::Side getSide(const Connector* connector) const;
266 
267 
268  bool getIgnoreForStoreRestoreStream() const;
269 
270 
271  virtual bool postStore(agxStream::StorageStream& str) const;
272 
273  virtual bool postRestore(agxStream::StorageStream& str);
274 
278  virtual bool store(agxStream::StorageStream& str) const override;
279 
283  virtual bool restore(agxStream::StorageStream& str) override;
284 
285  void spreadRootToGraph();
286 
287  agxPowerLine::Unit* getRoot() const;
288 
289  void setRoot(agxPowerLine::Unit* root);
290 
291  virtual bool vetoConnect(agxPowerLine::Connector* connector) const;
292 
294  virtual void store(agxStream::OutputArchive& out) const override;
295  virtual void restore(agxStream::InputArchive& in) override;
296 
297  protected:
298  virtual ~Unit();
299 
303  friend class Traverser;
304  friend class GraphTraverser;
305  friend class PowerLine;
306  friend class Actuator;
307  friend class Connector;
308 
312  virtual bool hasValidInputConnection() const;
313 
317  void setPowerLine(PowerLine* powerLine);
318 
319  bool activateDimension( PhysicalDimension* dimension );
320 
321  void restorePre46(agxStream::InputArchive& in);
322 
323  protected:
325 
326  agx::observer_ptr<agx::RigidBody> m_attachBody;
327 
328  bool m_ignoreMeForStoreRestoreStream;
329 
330  agxPowerLine::Unit* m_rootUnit;
331  };
332 
333  typedef agx::ref_ptr< Unit > UnitRef;
334 }
335 
336 #endif // AGXMODEL_UNIT_H
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:221
#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
Pure virtual class.
Definition: Unit.h:73
virtual bool connect(agxPowerLine::Side mySide, agxPowerLine::Side connectorSide, agxPowerLine::Connector *connector)
Connect the unit to a connector, specifying the side of each.
const agxPowerLine::PhysicalDimensionRefVector & getDimensions() const
virtual size_t getNumConnectableDimensions(Side side) const
virtual bool disconnect(agxPowerLine::Unit *unit)
virtual bool connect(agxPowerLine::Unit *otherUnit)
Connect the unit to another unit.
agxPowerLine::PhysicalDimension * getConnectableOutputDimension(agxPowerLine::PhysicalDimension::Type type)
agxPowerLine::PhysicalDimensionRefVector & getDimensions()
void addNotification(agxPowerLine::PowerLine *powerLine)
void removeNotification(agxPowerLine::PowerLine *powerLine)
void getOwnConnectedUnits(UnitPtrSetVector &unitSet, bool startFromCleanUnitSet=true) const
Constructs the set of Units connected to this Unit's own dimensions.
void getConnectedUnits(UnitPtrSetVector &result, agxPowerLine::Side side)
agxPowerLine::PhysicalDimension * getDimension(agxPowerLine::PhysicalDimension::Type type)
agx::String buildDimensionsName() const
agxPowerLine::PhysicalDimension * getActiveDimension(size_t index)
Unit()
Constructor.
size_t getNumActiveDimensions() const
The number of non-null PhysicalDimension in this Unit, not including internal Units.
void attach(agx::RigidBody *body)
Define which body in the simulation this Unit is attached to.
virtual void getConnectableDimensionTypes(agxPowerLine::PhysicalDimension::TypeVector &types, agxPowerLine::Side side) const
agxPowerLine::PhysicalDimension * getConnectableInputDimension(agxPowerLine::PhysicalDimension::Type type)
const agxPowerLine::PhysicalDimension * getActiveDimension(size_t index) const
const agxPowerLine::PhysicalDimension * getDimension(agxPowerLine::PhysicalDimension::Type type) const
virtual bool isValid() const
virtual agxPowerLine::DimensionAndSide getConnectableDimension(agxPowerLine::PhysicalDimension::Type type, agxPowerLine::Side side)
virtual bool isConnected(agxPowerLine::Unit *otherUnit) const
virtual bool connect(agxPowerLine::Side mySide, agxPowerLine::Side otherSide, agxPowerLine::Unit *other)
virtual bool connect(agxPowerLine::Connector *connector)
Connect the unit to a connector.
void getOwnConnectedUnits(UnitPtrSetVector &unitSet, agxPowerLine::Side side, bool startFromCleanUnitSet=true) const
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: agx/HashSet.h:666
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxPowerLine contains a collection of connected components that transport power across a system.
Definition: MotorUnit.h:24
agx::SetVector< Unit * > UnitPtrSetVector
Definition: Connector.h:39
agx::Vector< UnitRef > UnitRefVector
agx::Vector< std::pair< agxPowerLine::PhysicalDimension *, agxPowerLine::Side > > DimensionSideVector
Definition: Unit.h:65
agx::HashSet< UnitRef > UnitRefSet
Definition: Unit.h:60
std::pair< agxPowerLine::PhysicalDimension *, agxPowerLine::Side > DimensionAndSide
agx::Vector< ConnectorRef > ConnectorRefVector
Definition: Connector.h:406
agx::ref_ptr< Unit > UnitRef
agx::Vector< Connector * > ConnectorPtrVector
Definition: Connector.h:402
agx::SetVector< UnitRef > UnitRefSetVector
Definition: Unit.h:61
agx::Vector< agx::observer_ptr< Unit > > UnitObsVector
Definition: Unit.h:57
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
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
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
The agxUtil namespace contain classes and methods for utility functionality.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
AGXCORE_EXPORT Component * root()