AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
Link.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or
9having been advised so by Algoryx Simulation AB for a time limited evaluation,
10or having purchased a valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agxWire/ILinkNode.h>
21
22#define LINK_V2_SERIALIZATION_VERSION agx::UInt16( 37 )
23
24namespace agxSDK
25{
26 class SimulationProxy;
27}
28
29namespace agxWire
30{
31 class Winch;
32
34
41 {
42 public:
46
47 public:
53 {
54 WIRE_BEGIN = 0,
55 WIRE_END = 1,
57 INVALID_CONNECTION = 0xFF
59 };
60
64 enum class WinchState
65 {
66 PULLED_IN,
68 INSIDE,
71 OVERLAPPING,
73 NONE
74 };
75
76 public:
84 static agxWire::Wire* getWire( const agxWire::ConnectingNode* connectingNode,
85 agx::Bool findClosestIfLinkConnections = false );
86
90 static agxWire::Link* getLink( const agxWire::ConnectingNode* connectingNode );
91
96
101
113 const agx::Vec3& relativeTranslate1,
114 agxWire::Link* link,
115 agxWire::Wire* wire2,
116 const agx::Vec3& relativeTranslate2 );
117
118 public:
123
128
139
147
156 agx::Bool attach( agxWire::Wire* wire, const agx::Vec3& relativeTranslate, agxWire::Link::ConnectionType type );
157
164
171
179
184
191
198
203 template< typename T >
204 T* getAlgorithm() const;
205
209 void transform();
210
215
220
225
230
235
240
244 template<typename Pred>
246
250 template<typename Pred>
252
257
262
275
283
285 public:
289 void initialize( agxSDK::SimulationProxy* simulationProxy );
290
296 void setEnable( agx::Bool enable, agxSDK::SimulationProxy* simulationProxy );
297
301 void onRemoveNotification( agxWire::Wire* wire, agxWire::ConnectingNode* connectingNode );
302
304
306
307 protected:
311 enum State
312 {
313 NONE = 0,
314 INITIALIZED = 1 << 0,
315 ENABLE_TOGGLED = 1 << 1
316 };
317
319
320 protected:
325
329 virtual ~Link();
330
335
340
345
350
355
360
361 protected:
362 friend class LinkController;
363
368 virtual agx::Bool executeUpdate( const agxSDK::SimulationProxy* simulationProxy );
369
373 virtual void update( agxWire::WireParallelCallbacksHandler::CallbackTypes type, agxSDK::SimulationProxy* simulationProxy );
374
375 protected:
382
383 private:
384 ConnectionsContainer m_connections;
385 };
386
391 class AGXPHYSICS_EXPORT Link::Algorithm : public agx::Referenced, public agxStream::Serializable
392 {
393 public:
400 virtual void onLinkEnable(agx::Bool enable, agxWire::Link* link, agxSDK::SimulationProxy* simulationProxy);
401
407 virtual void preCollide(agxWire::Link* link, agxSDK::SimulationProxy* simulationProxy);
408
414 virtual void pre(agxWire::Link* link, agxSDK::SimulationProxy* simulationProxy);
415
421 virtual void post(agxWire::Link* link, agxSDK::SimulationProxy* simulationProxy);
422
428
434
439
444
449
455
461
465 template< typename T >
466 T* find() const;
467
471 template< typename T >
472 const T* as() const;
473
477 template< typename T >
478 T* as();
479
481 public:
485 virtual void store( agxStream::OutputArchive& out ) const override;
486
490 virtual void restore( agxStream::InputArchive& in ) override;
491
493
495
496 protected:
500 Algorithm();
501
502 private:
503 enum State { IDLE = 0, UPDATING_CHILDREN = (1<<0) };
504
505 private:
506 typedef agx::Vector< agxWire::Link::AlgorithmRef > ChildrenContainer;
507
508 private:
509 ChildrenContainer m_children;
510 ChildrenContainer m_removedChildren;
511 Link::Algorithm* m_parent;
512 agx::Int32 m_state;
513 };
514
516
517 inline void Link::Algorithm::onLinkEnable(agx::Bool /*enable*/, agxWire::Link* /*link*/, agxSDK::SimulationProxy* /*simulationProxy*/) {}
518
519 inline void Link::Algorithm::preCollide(agxWire::Link* /*link*/, agxSDK::SimulationProxy* /*simulationProxy*/) {}
520
521 inline void Link::Algorithm::pre(agxWire::Link* /*link*/, agxSDK::SimulationProxy* /*simulationProxy*/) {}
522
523 inline void Link::Algorithm::post(agxWire::Link* /*link*/, agxSDK::SimulationProxy* /*simulationProxy*/) {}
524
525 template<typename T>
526 T* Link::getAlgorithm() const
527 {
528 T* algorithm = nullptr;
529 for ( agx::UInt i = 0, numAlgorithms = m_algorithms.size(); algorithm == nullptr && i < numAlgorithms; ++i )
530 algorithm = m_algorithms[ i ]->find<T>();
531
532 return algorithm;
533 }
534
536
537 template<typename Pred>
538 Link::ConnectionsContainer Link::getConnectingNodes( Pred pred ) const
539 {
541 ret.reserve( m_connections.size() );
542 for ( agx::UInt i = 0, numConnections = m_connections.size(); i < numConnections; ++i )
543 if ( pred( m_connections[ i ] ) )
544 ret.push_back( m_connections[ i ] );
545 return ret;
546 }
547
548 template<typename Pred>
550 {
551 for ( agx::UInt i = 0, numConnections = m_connections.size(); i < numConnections; ++i )
552 if ( pred( m_connections[ i ] ) )
553 return m_connections[ i ];
554 return nullptr;
555 }
556
557 template<typename T>
558 T* Link::Algorithm::find() const
559 {
560 T* algorithm = const_cast<Link::Algorithm*>( this )->as<T>();
561 for ( agx::UInt i = 0; algorithm == nullptr && i < m_children.size(); ++i )
562 algorithm = m_children[ i ]->find<T>();
563
564 return algorithm;
565 }
566
567 template<typename T>
568 const T* Link::Algorithm::as() const
569 {
570 return dynamic_cast<const T*>( this );
571 }
572
573 template<typename T>
574 T* Link::Algorithm::as()
575 {
576 return dynamic_cast<T*>( this );
577 }
578}
579
580
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#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 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
#define AGXPHYSICS_EXPORT
Interface class used by internal objects running in parallel.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Connecting nodes contains two nodes, one at center of mass and the other at the user defined position...
Object holding parameters, such as bend and twist stiffness, related to wire to link connections.
Definition: ILinkNode.h:36
Interface class for nodes connected to links.
Definition: ILinkNode.h:29
Winch object which works like agxWire::WireWinchController but enables the features of having stored,...
Definition: Winch.h:31
Interface and placeholder of controllers/helpers for wires.
Definition: Wire.h:62
The base class for a constraint.
Definition: Constraint.h:89
size_t size() const
Definition: Container.h:134
Base class providing referencing counted objects.
Definition: Referenced.h:120
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:49
size_t find(const T2 &element) const
Find the index to a matching element, return size() if not found.
Definition: agx/Vector.h:856
void reserve(size_t size)
Reserve capacity in the vector.
Definition: agx/Vector.h:583
void push_back(const T2 &value)
Definition: agx/Vector.h:715
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
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...
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:39
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
int32_t Int32
Definition: Integer.h:37
bool Bool
Definition: Integer.h:40
uint64_t UInt
Definition: Integer.h:27