AGX Dynamics  2.37.3.2
Unit.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 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 
90  void getConnectedUnits(UnitPtrSetVector& result, agxPowerLine::Side side);
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 
133  void disconnectAll();
134 
135 
136 
137  // Methods called by the rest of the PowerLine/Hydraulics frame work.
138  public:
143  virtual agxPowerLine::DimensionAndSide getConnectableDimension(
145 
149  agxPowerLine::PhysicalDimension* getConnectableInputDimension(
151 
152  agxPowerLine::PhysicalDimension* getConnectableOutputDimension(
154 
163  virtual void getConnectableDimensionTypes(
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 
184  const agxPowerLine::PhysicalDimensionRefVector& getDimensions() const;
186 
187 
194 
195 
200  agxPowerLine::PhysicalDimension* getActiveDimension(size_t index);
201  const agxPowerLine::PhysicalDimension* getActiveDimension(size_t index) const;
202 
207  size_t getNumActiveDimensions() const;
208 
213  agx::String buildDimensionsName() const;
214 
215  /*
216  Functions called by static functions. Do NOT use them.
217  */
218 
219 
220  void addNotification(agxPowerLine::PowerLine* powerLine);
221  void removeNotification(agxPowerLine::PowerLine* powerLine);
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 
327 
329 
331  };
332 
334 }
335 
336 #endif // AGXMODEL_UNIT_H
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
Utility class to hold custom implementations of constraints.
Definition: agxUtil.h:463
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:669
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...
agx::observer_ptr< agx::RigidBody > m_attachBody
Definition: Unit.h:326
PhysicalDimensionRefVector m_dimensions
Definition: Unit.h:324
Pure virtual class.
Definition: Unit.h:72
agxPowerLine::Unit * m_rootUnit
Definition: Unit.h:330
agxPowerLine contains a collection of connected components that transport power across a system...
Definition: MotorUnit.h:23
agx::Vector< Connector * > ConnectorPtrVector
Definition: Connector.h:402
agx::Vector< UnitRef > UnitRefVector
agx::ref_ptr< Unit > UnitRef
agx::Vector< ConnectorRef > ConnectorRefVector
Definition: Connector.h:406
agx::Vector< agx::observer_ptr< Unit > > UnitObsVector
Definition: Unit.h:57
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
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
bool m_ignoreMeForStoreRestoreStream
Definition: Unit.h:328
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
#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
std::pair< agxPowerLine::PhysicalDimension *, agxPowerLine::Side > DimensionAndSide
#define AGXMODEL_EXPORT
AGXCORE_EXPORT Component * root()
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation...
Definition: PowerLine.h:70
agx::SetVector< Unit * > UnitPtrSetVector
Definition: Connector.h:39
agx::Vector< std::pair< agxPowerLine::PhysicalDimension *, agxPowerLine::Side > > DimensionSideVector
Definition: Unit.h:65
agx::HashSet< UnitRef > UnitRefSet
Definition: Unit.h:60
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
agx::SetVector< UnitRef > UnitRefSetVector
Definition: Unit.h:61