AGX Dynamics  2.38.0.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 #pragma once
18 
19 #include <agxModel/export.h>
22 #include <agxPowerLine/Connector.h>
23 #include <agxPowerLine/SubGraph.h>
24 
26 #include <agxStream/Serializable.h>
27 
28 #include <agxUtil/agxUtil.h>
29 
30 #include <agx/RigidBody.h>
32 
33 
34 namespace agxPowerLine
35 {
36  /************************************************************************/
37  /*
38  The agxPowerLine::PowerLine implementation is the base for energy transportation
39  in a 1D physical system.
40 
41  The energy is stored in units connected by connectors. Each unit can have a set of both
42  in and out connections, representing different physical dimensions.
43 
44  The physical dimensions can either be dynamically solved or be represented as
45  a kinematic calculator that uses a lookup table to calculate its current state
46  given the surrounding units. It could affect the power produced in its dynamically
47  solved parent, or the state of gradient for that parent.(For example a look up table
48  working as a gear box for a drive train will affect the torque and RPM of the
49  incoming shaft. Since it has no shaft of its own it will convert the parent shaft )
50  */
51  /************************************************************************/
52  class Unit;
53  class Traverser;
62 
63 
65 
66 
72  {
73  public:
77  Unit();
78 
82  virtual bool isValid() const;
83 
87  virtual bool isConnected(agxPowerLine::Unit* otherUnit) const;
88 
89  void getConnectedUnits(UnitPtrSetVector& result, agxPowerLine::Side side);
90 
96  void attach(agx::RigidBody* body);
97 
103  virtual bool connect(agxPowerLine::Connector* connector);
104 
112  virtual bool connect(
113  agxPowerLine::Side mySide,
114  agxPowerLine::Side connectorSide,
115  agxPowerLine::Connector* connector);
116 
121  virtual bool connect(agxPowerLine::Unit* otherUnit);
122 
123  virtual bool connect(
124  agxPowerLine::Side mySide,
125  agxPowerLine::Side otherSide,
126  agxPowerLine::Unit* other);
127 
128 
129 
130  virtual bool disconnect(agxPowerLine::Unit* unit);
131 
132  void disconnectAll();
133 
134 
135 
136  // Methods called by the rest of the PowerLine/Hydraulics frame work.
137  public:
142  virtual agxPowerLine::DimensionAndSide getConnectableDimension(
144 
148  agxPowerLine::PhysicalDimension* getConnectableInputDimension(
150 
151  agxPowerLine::PhysicalDimension* getConnectableOutputDimension(
153 
162  virtual void getConnectableDimensionTypes(
164 
165 
169  virtual size_t getNumConnectableDimensions(Side side) const;
170 
171 
176  void getOwnConnectedUnits(UnitPtrSetVector& unitSet, bool startFromCleanUnitSet = true) const;
177  void getOwnConnectedUnits(UnitPtrSetVector& unitSet, agxPowerLine::Side side, bool startFromCleanUnitSet = true) const;
178 
183  const agxPowerLine::PhysicalDimensionRefVector& getDimensions() const;
185 
186 
193 
194 
199  agxPowerLine::PhysicalDimension* getActiveDimension(size_t index);
200  const agxPowerLine::PhysicalDimension* getActiveDimension(size_t index) const;
201 
206  size_t getNumActiveDimensions() const;
207 
212  agx::String buildDimensionsName() const;
213 
214  /*
215  Functions called by static functions. Do NOT use them.
216  */
217 
218 
219  void addNotification(agxPowerLine::PowerLine* powerLine);
220  void removeNotification(agxPowerLine::PowerLine* powerLine);
221 
228  virtual bool addNotification(agxSDK::Simulation* simulation) override;
229  virtual bool removeNotification(agxUtil::ConstraintHolder* constraintHolder, agxSDK::Simulation* simulation) override;
231 
232 
233  agxPowerLine::PowerLine* getPowerLine() const;
234 
236  bool hasConnector( const Connector* connector ) const;
237 
238 
241  size_t getNumConnections() const;
242 
252  size_t getConnectors(const agxPowerLine::Unit* unit, agxPowerLine::ConnectorPtrVector& result);
253  size_t getInputConnectors(const agxPowerLine::Unit* unit, agxPowerLine::ConnectorPtrVector& result);
254  size_t getOutputConnectors(const agxPowerLine::Unit* unit, agxPowerLine::ConnectorPtrVector& result);
255 
256  size_t getConnectors(agxPowerLine::ConnectorPtrVector& result) const;
257  size_t getInputConnectors(agxPowerLine::ConnectorPtrVector& result) const;
258  size_t getOutputConnectors(agxPowerLine::ConnectorPtrVector& result) const;
259 
260 
261  Connector* getFirstInputConnector(const agxPowerLine::Unit* unit) const;
262  Connector* getFirstOutputConnector(const agxPowerLine::Unit* unit) const;
263 
264  agxPowerLine::Side getSide(const Connector* connector) const;
265 
266 
267  bool getIgnoreForStoreRestoreStream() const;
268 
269 
270  virtual bool postStore(agxStream::StorageStream& str) const;
271 
272  virtual bool postRestore(agxStream::StorageStream& str);
273 
277  virtual bool store(agxStream::StorageStream& str) const override;
278 
282  virtual bool restore(agxStream::StorageStream& str) override;
283 
284  void spreadRootToGraph();
285 
286  agxPowerLine::Unit* getRoot() const;
287 
288  void setRoot(agxPowerLine::Unit* root);
289 
290  virtual bool vetoConnect(agxPowerLine::Connector* connector) const;
291 
293  virtual void store(agxStream::OutputArchive& out) const override;
294  virtual void restore(agxStream::InputArchive& in) override;
295 
296  protected:
297  virtual ~Unit();
298 
302  friend class Traverser;
303  friend class GraphTraverser;
304  friend class PowerLine;
305  friend class Actuator;
306  friend class Connector;
307 
311  virtual bool hasValidInputConnection() const;
312 
316  void setPowerLine(PowerLine* powerLine);
317 
318  bool activateDimension( PhysicalDimension* dimension );
319 
320  void restorePre46(agxStream::InputArchive& in);
321 
322  protected:
324 
326 
328 
330  };
331 
333 }
agxPowerLine::Actuator
Definition: Actuator.h:46
agxPowerLine::Side
Side
Definition: Sides.h:28
agxPowerLine::SubGraph
Definition: SubGraph.h:58
agx::Vector< UnitRef >
agxStream::out
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.
Definition: OutputArchive.h:412
agxPowerLine::Unit::m_rootUnit
agxPowerLine::Unit * m_rootUnit
Definition: Unit.h:329
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
export.h
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
PowerLineUtils.h
agxUtil::ConstraintHolder
Utility class to hold custom implementations of constraints.
Definition: agxUtil.h:463
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxStream::StorageStream
Abstract base class for storing/restoring a line/drums with version control.
Definition: StorageStream.h:48
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE
#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
StepEventListener.h
agxPowerLine::PhysicalDimension
Pure virtual class.
Definition: PhysicalDimension.h:92
agxPowerLine::PhysicalDimension::Type
int Type
Definition: PhysicalDimension.h:95
agx::observer_ptr< agx::RigidBody >
agxPowerLine::UnitPtrSetVector
agx::SetVector< Unit * > UnitPtrSetVector
Definition: Connector.h:38
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
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::UnitRef
agx::ref_ptr< Unit > UnitRef
Definition: Connector.h:45
agxPowerLine::UnitRefVector
agx::Vector< UnitRef > UnitRefVector
Definition: Connector.h:46
agxPowerLine::PowerLine
PowerLine is the base class for a system of power transfer integrated into the rigid body simulation.
Definition: PowerLine.h:65
agxPowerLine::Unit::m_dimensions
PhysicalDimensionRefVector m_dimensions
Definition: Unit.h:323
Connector.h
agxPowerLine::ConnectorRefVector
agx::Vector< ConnectorRef > ConnectorRefVector
Definition: Connector.h:405
agxStream::OutputArchive
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
Serializable.h
agx::HashSet
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:669
agx::root
AGXCORE_EXPORT Component * root()
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:50
RigidBody.h
agxPowerLine::UnitObsVector
agx::Vector< agx::observer_ptr< Unit > > UnitObsVector
Definition: Unit.h:56
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
agxPowerLine::UnitRefSet
agx::HashSet< UnitRef > UnitRefSet
Definition: Unit.h:59
SubGraph.h
AGXMODEL_EXPORT
#define AGXMODEL_EXPORT
Definition: agxModel/export.h:42
agxPowerLine::Unit::m_ignoreMeForStoreRestoreStream
bool m_ignoreMeForStoreRestoreStream
Definition: Unit.h:327
agx::AgXString< std::string >
agxPowerLine::UnitRefSetVector
agx::SetVector< UnitRef > UnitRefSetVector
Definition: Unit.h:60
agxPowerLine::ConnectorPtrVector
agx::Vector< Connector * > ConnectorPtrVector
Definition: Connector.h:401
agxPowerLine::Unit::m_attachBody
agx::observer_ptr< agx::RigidBody > m_attachBody
Definition: Unit.h:325
agxPowerLine::DimensionSideVector
agx::Vector< std::pair< agxPowerLine::PhysicalDimension *, agxPowerLine::Side > > DimensionSideVector
Definition: Unit.h:64
agxPowerLine::DimensionAndSide
std::pair< agxPowerLine::PhysicalDimension *, agxPowerLine::Side > DimensionAndSide
Definition: PhysicalDimension.h:77
agxUtil.h
PhysicalDimension.h