Hopsan
Port Class Reference
Inheritance diagram for Port:
BiDirectionalSignalPort MultiPort PowerPort ReadPort SystemPort WritePort PowerMultiPort ReadMultiPort

Public Types

enum  RequireConnectionEnumT { Required , NotRequired }
 This enum specifies the RequiredConnection enums.
 

Public Member Functions

 Port (const HString &rNodeType, const HString &rPortName, Component *pParentComponent, Port *pParentPort=0)
 Port base class constructor.
 
virtual ~Port ()
 Destructor.
 
double readNode (const size_t idx) const
 Reads a value from the connected node.
 
virtual double readNode (const size_t idx, const size_t subPortIdx) const
 Reads a value from the connected node.
 
void writeNode (const size_t idx, const double value)
 Writes a value to the connected node.
 
virtual void writeNode (const size_t idx, const double value, const size_t subPortIdx)
 Writes a value to the connected node.
 
virtual double readNodeSafe (const size_t idx, const size_t subPortIdx=0) const
 Reads a value from the connected node.
 
virtual void writeNodeSafe (const size_t idx, const double value, const size_t subPortIdx=0)
 Writes a value to the connected node.
 
virtual NodegetNodePtr (const size_t subPortIdx=0)
 Returns a pointer to the connected node or 0 if no node exist.
 
virtual const NodegetNodePtr (const size_t subPortIdx=0) const
 Returns the node pointer in the port.
 
virtual double * getNodeDataPtr (const size_t idx, const size_t subPortIdx=0) const
 Get a ptr to the data variable in the node.
 
virtual std::vector< double > * getDataVectorPtr (const size_t subPortIdx=0)
 
virtual size_t getNumDataVariables () const
 Returns the number of data variables in the node.
 
virtual const std::vector< NodeDataDescription > * getNodeDataDescriptions (const size_t subPortIdx=0) const
 Get all node data descriptions.
 
virtual const NodeDataDescriptiongetNodeDataDescription (const size_t dataid, const size_t subPortIdx=0) const
 Get a specific node data description.
 
virtual int getNodeDataIdFromName (const HString &rName, const size_t subPortIdx=0)
 Ask the node for the dataId for a particular data name such as (Pressure)
 
virtual void setSignalNodeQuantityOrUnit (const HString &rQuantityOrUnit)
 A help function that makes it possible to overwrite the unit or quantity of scalar signal node variables.
 
virtual void setSignalNodeQuantityModifyable (bool tf)
 
virtual HString getSignalNodeQuantity () const
 
virtual bool getSignalNodeQuantityModifyable () const
 
const HStringgetVariableAlias (const size_t id) const
 Get the alias name for a specific node variable id.
 
int getVariableIdByAlias (const HString &rAlias) const
 Get the variable id for a specific alias name.
 
virtual bool haveLogData (const size_t subPortIdx=0)
 Check if log data exist in the ports node.
 
virtual std::vector< double > * getLogTimeVectorPtr (const size_t subPortIdx=0)
 
virtual std::vector< std::vector< double > > * getLogDataVectorPtr (size_t subPortIdx=0)
 
virtual const std::vector< std::vector< double > > * getLogDataVectorPtr (size_t subPortIdx=0) const
 
virtual void setEnableLogging (const bool enableLog)
 
bool isLoggingEnabled () const
 
virtual bool isConnected () const
 Check if the port is currently connected.
 
virtual bool isConnectedTo (Port *pOtherPort)
 Check if this port is connected to other port.
 
bool isConnectionRequired ()
 Check if the port MUST be connected.
 
virtual std::vector< Port * > getConnectedPorts (const int subPortIdx=-1) const
 Get a vector of pointers to all other ports connected connected to this one.
 
size_t getNumConnectedPorts (const int subPortIdx=-1)
 Returns the number of ports connected to this port.
 
virtual size_t getNumPorts ()
 
bool isInterfacePort () const
 
virtual bool isMultiPort () const
 Convenience function to check if port is multiport.
 
const HStringgetNodeType () const
 Returns the type of node that can be connected to this port.
 
virtual PortTypesEnumT getPortType () const
 Get the port type.
 
virtual PortTypesEnumT getExternalPortType ()
 Get the External port type (virtual, should be overloaded in systemports only)
 
virtual PortTypesEnumT getInternalPortType ()
 Get the Internal port type (virtual, should be overloaded in systemports only)
 
virtual SortHintEnumT getSortHint () const
 
virtual void setSortHint (SortHintEnumT hint)
 
virtual SortHintEnumT getInternalSortHint ()
 
PortgetParentPort () const
 
ComponentgetComponent () const
 Returns the parent component.
 
const HStringgetName () const
 Get the port name.
 
const HStringgetComponentName () const
 Get the name of the component that the port is attached to.
 
const HStringgetDescription () const
 Get port description.
 
void setDescription (const HString &rDescription)
 Set port description.
 
virtual double getStartValue (const size_t idx, const size_t subPortIdx=0)
 Get the actual start value of the port.
 
virtual void loadStartValues ()
 Load start values by copying the start values from the port to the node.
 
virtual void loadStartValuesFromSimulation ()
 Load start values to the start value container from the node (last values from simulation)
 
std::vector< double > & getNodeDataVector ()
 Returns a reference to the Node data in the port.
 
const std::vector< double > & getNodeDataVector () const
 Returns a reference to the Node data in the port.
 
virtual std::vector< double > & getNodeDataVector (const size_t subPortIdx)
 Returns a reference to the Node data in the port.
 
virtual const std::vector< double > & getNodeDataVector (const size_t subPortIdx) const
 Returns a reference to the Node data in the port.
 

Protected Member Functions

virtual void setDefaultStartValue (const size_t idx, const double value, const size_t subPortIdx=0)
 Set the an actual start value of the port.
 
virtual void disableStartValue (const size_t idx)
 Disables start value for specified data type.
 
virtual NodegetStartNodePtr ()
 Get a pointer to the start node.
 
virtual void setNode (Node *pNode)
 Set the node that the port is connected to.
 
virtual PortaddSubPort ()
 Adds a subport to a multiport.
 
virtual void removeSubPort (Port *pPort)
 Removes a subport from multiport.
 
void registerStartValueParameters ()
 This function registers the startvalue parameters from the start node.
 
void unRegisterStartValueParameters ()
 Unregisters all startvalue parameters from the start node.
 
void addConnectedPort (Port *pPort, const size_t subPortIdx=0)
 Adds a pointer to an other connected port to a port.
 
void eraseConnectedPort (Port *pPort, const size_t subPortIdx=0)
 Removes a pointer to an other connected port from a port.
 
void createStartNode (const HString &rNodeType)
 Creates a start node in the port.
 
void eraseStartNode ()
 Removes the start node in the port and unregisters all start value parameters.
 
void setVariableAlias (const HString &rAlias, const size_t id)
 

Protected Attributes

HString mNodeType
 
SortHintEnumT mSortHint
 
ComponentmpComponent
 
PortmpParentPort
 
bool mEnableLogging
 
std::vector< Port * > mConnectedPorts
 

Friends

class Component
 
class ComponentSystem
 
class ConnectionAssistant
 
class AliasHandler
 
class MultiPort
 

Member Function Documentation

◆ addConnectedPort()

void addConnectedPort ( Port * pPort,
const size_t subPortIdx = 0 )
protected

Adds a pointer to an other connected port to a port.

Parameters
[in]pPortA pointer to the other port
[in]subPortIdxIgnored for non multi ports

◆ addSubPort()

Port * addSubPort ( )
protectedvirtual

Adds a subport to a multiport.

Reimplemented in PowerMultiPort, and ReadMultiPort.

◆ createStartNode()

void createStartNode ( const HString & rNodeType)
protected

Creates a start node in the port.

Parameters
[in]rNodeTypeThe type of node to create (Such as NodeHydraulic)

<

◆ disableStartValue()

void disableStartValue ( const size_t idx)
protectedvirtual

Disables start value for specified data type.

Parameters
idxData index of start value to be disabled

◆ eraseConnectedPort()

void eraseConnectedPort ( Port * pPort,
const size_t subPortIdx = 0 )
protected

Removes a pointer to an other connected port from a port.

Parameters
[in]pPortThe pointer to the other port to be removed
[in]subPortIdxIgnored for non multi ports

◆ getConnectedPorts()

std::vector< Port * > getConnectedPorts ( const int subPortIdx = -1) const
virtual

Get a vector of pointers to all other ports connected connected to this one.

Parameters
[in]subPortIdxIgnored for non multi ports
Returns
A vector with the connected port pointers

Reimplemented in MultiPort.

◆ getDataVectorPtr()

vector< double > * getDataVectorPtr ( const size_t subPortIdx = 0)
virtual
Parameters
[in]subPortIdxIgnored on non multi ports

Reimplemented in MultiPort.

◆ getDescription()

const HString & getDescription ( ) const

Get port description.

Returns
Port description

◆ getExternalPortType()

PortTypesEnumT getExternalPortType ( )
virtual

Get the External port type (virtual, should be overloaded in systemports only)

Reimplemented in SystemPort.

◆ getInternalPortType()

PortTypesEnumT getInternalPortType ( )
virtual

Get the Internal port type (virtual, should be overloaded in systemports only)

Reimplemented in SystemPort.

◆ getLogDataVectorPtr()

vector< vector< double > > * getLogDataVectorPtr ( size_t subPortIdx = 0)
virtual
Parameters
[in]subPortIdxIgnored on non multi ports

Reimplemented in MultiPort.

◆ getLogTimeVectorPtr()

vector< double > * getLogTimeVectorPtr ( const size_t subPortIdx = 0)
virtual
Parameters
[in]subPortIdxIgnored on non multi ports

Reimplemented in MultiPort.

◆ getNodeDataDescription()

const NodeDataDescription * getNodeDataDescription ( const size_t dataid,
const size_t subPortIdx = 0 ) const
virtual

Get a specific node data description.

Parameters
[in]dataidThe node data id (Such as NodeHydraulic::Pressure)
[in]subPortIdxIgnored on non multi ports
Returns
A const pointer to the node data description, or 0 if no node exist

Reimplemented in MultiPort.

◆ getNodeDataDescriptions()

const std::vector< NodeDataDescription > * getNodeDataDescriptions ( const size_t subPortIdx = 0) const
virtual

Get all node data descriptions.

Parameters
[in]subPortIdxIgnored on non multi ports
Returns
A const pointer to the internal node vector with node data descriptions

Reimplemented in MultiPort.

◆ getNodeDataIdFromName()

int getNodeDataIdFromName ( const HString & rName,
const size_t subPortIdx = 0 )
virtual

Ask the node for the dataId for a particular data name such as (Pressure)

This is a wrapper function for the actual Node function,

Parameters
[in]rNameThe name of the variable (Such as Pressure)
[in]subPortIdxIgnored on non multi ports
Returns
The node data id (positive integer) if the variable name is found else returns -1 to indicate failure

Reimplemented in MultiPort.

◆ getNodeDataPtr()

double * getNodeDataPtr ( const size_t idx,
const size_t subPortIdx = 0 ) const
virtual

Get a ptr to the data variable in the node.

Parameters
[in]idxThe id of the data variable to return ptr to
[in]subPortIdxIgnored for non multi ports
Returns
Pointer to data variable or 0 if idx was not found

Reimplemented in MultiPort.

◆ getNodeDataVector() [1/4]

std::vector< double > & getNodeDataVector ( )
inline

Returns a reference to the Node data in the port.

Returns
A reference to the node data vector

◆ getNodeDataVector() [2/4]

const std::vector< double > & getNodeDataVector ( ) const
inline

Returns a reference to the Node data in the port.

Returns
A reference to the node data vector

◆ getNodeDataVector() [3/4]

virtual std::vector< double > & getNodeDataVector ( const size_t subPortIdx)
inlinevirtual

Returns a reference to the Node data in the port.

Parameters
[in]subPortIdxThe index of a multiport subport to access
Returns
A reference to the node data vector

Reimplemented in MultiPort.

◆ getNodeDataVector() [4/4]

virtual const std::vector< double > & getNodeDataVector ( const size_t subPortIdx) const
inlinevirtual

Returns a reference to the Node data in the port.

Parameters
[in]subPortIdxThe index of a multiport subport to access
Returns
A reference to the node data vector

Reimplemented in MultiPort.

◆ getNodePtr() [1/2]

Node * getNodePtr ( const size_t subPortIdx = 0)
virtual

Returns a pointer to the connected node or 0 if no node exist.

Parameters
[in]subPortIdxIgnored on non multi ports

Reimplemented in MultiPort.

◆ getNodePtr() [2/2]

const Node * getNodePtr ( const size_t subPortIdx = 0) const
virtual

Returns the node pointer in the port.

Parameters
[in]subPortIdxIgnored for non multi ports
Returns
The node pointer in this port

Reimplemented in MultiPort.

◆ getNumConnectedPorts()

size_t getNumConnectedPorts ( const int subPortIdx = -1)

Returns the number of ports connected to this port.

Parameters
[in]subPortIdxThe index of the subPort to check. Ignored on non multi ports
Returns
The number of connected ports

◆ getNumDataVariables()

size_t getNumDataVariables ( ) const
virtual

Returns the number of data variables in the node.

Returns
The number of data variables in the node

◆ getPortType()

PortTypesEnumT getPortType ( ) const
virtual

◆ getStartNodePtr()

Node * getStartNodePtr ( )
protectedvirtual

Get a pointer to the start node.

Returns
StartNode ptr or 0 if no startnode

◆ getStartValue()

double getStartValue ( const size_t idx,
const size_t subPortIdx = 0 )
virtual

Get the actual start value of the port.

Parameters
[in]idxis the index of the start value e.g. NodeHydraulic::Pressure
[in]subPortIdxIgnored on non multi ports
Returns
the start value

Reimplemented in MultiPort.

◆ getVariableAlias()

const HString & getVariableAlias ( const size_t id) const

Get the alias name for a specific node variable id.

Parameters
[in]idThe node data id of the requested variable (Ex: NodeHydraulic::Pressure)
Returns
The alias name or empty string if no alias name exist for requested variable

◆ getVariableIdByAlias()

int getVariableIdByAlias ( const HString & rAlias) const

Get the variable id for a specific alias name.

Parameters
[in]rAliasThe alias name to search for
Returns
The variable id (integer value) (Ex:: NodeHydarulic::Pressure) or -1 if not found

◆ haveLogData()

bool haveLogData ( const size_t subPortIdx = 0)
virtual

Check if log data exist in the ports node.

Parameters
[in]subPortIdxIgnored on non multi ports
Returns
True or False

Reimplemented in MultiPort.

◆ isConnected()

bool isConnected ( ) const
virtual

Check if the port is currently connected.

Returns True or False

Reimplemented in MultiPort.

◆ isConnectedTo()

bool isConnectedTo ( Port * pOtherPort)
virtual

Check if this port is connected to other port.

Reimplemented in MultiPort.

◆ isMultiPort()

bool isMultiPort ( ) const
virtual

Convenience function to check if port is multiport.

Reimplemented in MultiPort.

◆ loadStartValues()

void loadStartValues ( )
virtual

Load start values by copying the start values from the port to the node.

Reimplemented in MultiPort, and ReadPort.

◆ loadStartValuesFromSimulation()

void loadStartValuesFromSimulation ( )
virtual

Load start values to the start value container from the node (last values from simulation)

Reimplemented in MultiPort.

◆ removeSubPort()

void removeSubPort ( Port * pPort)
protectedvirtual

Removes a subport from multiport.

Reimplemented in MultiPort.

◆ setDefaultStartValue()

void setDefaultStartValue ( const size_t idx,
const double value,
const size_t subPortIdx = 0 )
protectedvirtual

Set the an actual start value of the port.

Parameters
[in]idxis the index of the start value e.g. NodeHydraulic::Pressure
[in]valueis the start value that should be written
[in]subPortIdxIgnored on non multi ports

◆ setDescription()

void setDescription ( const HString & rDescription)

Set port description.

Parameters
[in]rDescriptionThe new description

◆ setNode()

void setNode ( Node * pNode)
protectedvirtual

Set the node that the port is connected to.

Parameters
[in]pNodeA pointer to the Node

Reimplemented in MultiPort.

◆ setSignalNodeQuantityModifyable()

void setSignalNodeQuantityModifyable ( bool tf)
virtual

◆ setSignalNodeQuantityOrUnit()

void setSignalNodeQuantityOrUnit ( const HString & rQuantityOrUnit)
virtual

A help function that makes it possible to overwrite the unit or quantity of scalar signal node variables.

◆ setVariableAlias()

void setVariableAlias ( const HString & rAlias,
const size_t id )
protected
Note
This one should be called by system, do not call this manually (that will create a mess)