simulink

edu.tum.cs.simulink.util
Class SimulinkUtils

java.lang.Object
  extended by edu.tum.cs.simulink.util.SimulinkUtils

public class SimulinkUtils
extends java.lang.Object

Collection of utility methods for Simulink models.

Version:
$Rev: 26277 $
Author:
deissenb, $Author: juergens $
Rating:
GREEN Hash: 0D8577FED291C7F4F560DB259060F6F4

Constructor Summary
SimulinkUtils()
           
 
Method Summary
static java.util.Set<SimulinkBlock> calculateParentSet(java.util.Collection<SimulinkBlock> blocks)
          Calculate the set of all parent blocks up to the model for the given blocks.
static void copyParameters(ParameterizedElement source, ParameterizedElement target)
          Copy parameters from one parameterized element to another.
static int countLines(SimulinkBlock block)
          Recursively count lines.
static int countStates(IStateflowNodeContainer<?> node)
          Recursively count Stateflow states.
static int countStates(StateflowMachine stateflowMachine)
          Count states of all charts of the machine.
static int countSubBlocks(SimulinkBlock block)
          Recursively count sub blocks.
static java.util.Map<java.lang.String,SimulinkBlock> createIdToNodeMap(SimulinkBlock block)
          Create map that maps from id to block.
static java.lang.String createSimulinkId(java.lang.Iterable<java.lang.String> names)
          Create Simulink id from a iteration of names.
static java.lang.String escape(java.lang.String string)
          Replaces forward slashes by double forward slashes.
static StateflowBlock getBlock(IStateflowElement<?> element)
          Get the Stateflow block a Stateflow element belongs to.
static StateflowChart getChart(IStateflowElement<?> element)
          Get the Stateflow chart a Stateflow element belongs to.
static java.lang.String getFQStateName(StateflowState state)
          Get full qualified state name.
static int[] getIntParameterArray(java.lang.String parameter)
          Get Simulink array parameter as array.
static SimulinkBlock getStateflowInport(SimulinkInPort inPort)
          Obtain in port.
static SimulinkBlock getStateflowOutport(SimulinkOutPort outPort)
          Obtain out port block that is below the a Stateflow block and describes the output of a Stateflow chart.
static java.lang.String getStateName(StateflowState state)
          Get name of a Stateflow state as defined in the Stateflow manual.
static java.lang.String[] getStringParameterArray(java.lang.String parameter)
          Get Simulink array parameter as array.
static boolean isTargetlinkBlock(SimulinkBlock node)
          Checks if a block is a target link block.
static java.util.List<SimulinkBlock> listBlocksDepthFirst(SimulinkBlock block)
          Returns all recursively reachable subblocks of the given block.
static java.util.List<java.lang.String> splitSimulinkId(java.lang.String string)
          Split full qualified identifier.
static
<X extends java.lang.Exception>
void
visitDepthFirst(SimulinkBlock block,  visitor)
          Visit blocks in a depth first manner.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimulinkUtils

public SimulinkUtils()
Method Detail

copyParameters

public static void copyParameters(ParameterizedElement source,
                                  ParameterizedElement target)
Copy parameters from one parameterized element to another.


createIdToNodeMap

public static java.util.Map<java.lang.String,SimulinkBlock> createIdToNodeMap(SimulinkBlock block)
Create map that maps from id to block.


escape

public static java.lang.String escape(java.lang.String string)
Replaces forward slashes by double forward slashes.


getIntParameterArray

public static int[] getIntParameterArray(java.lang.String parameter)
Get Simulink array parameter as array. This raises a NumberFormatException if the elements of the array are not integers.


getStringParameterArray

public static java.lang.String[] getStringParameterArray(java.lang.String parameter)
Get Simulink array parameter as array.


isTargetlinkBlock

public static boolean isTargetlinkBlock(SimulinkBlock node)
Checks if a block is a target link block.


splitSimulinkId

public static java.util.List<java.lang.String> splitSimulinkId(java.lang.String string)
Split full qualified identifier.


createSimulinkId

public static java.lang.String createSimulinkId(java.lang.Iterable<java.lang.String> names)
Create Simulink id from a iteration of names. This takes care of proper escaping.

Throws:
PreconditionException - if one of names starts or ends with a slash

visitDepthFirst

public static <X extends java.lang.Exception> void visitDepthFirst(SimulinkBlock block,
                                                                    visitor)
                            throws X extends java.lang.Exception
Visit blocks in a depth first manner.

Type Parameters:
X - Type of exception thrown by the visitor.
Parameters:
block - block to start with
visitor - the visitor
Throws:
X - exception thrown by the visitor.
X extends java.lang.Exception

listBlocksDepthFirst

public static java.util.List<SimulinkBlock> listBlocksDepthFirst(SimulinkBlock block)
Returns all recursively reachable subblocks of the given block.


calculateParentSet

public static java.util.Set<SimulinkBlock> calculateParentSet(java.util.Collection<SimulinkBlock> blocks)
Calculate the set of all parent blocks up to the model for the given blocks.


countSubBlocks

public static int countSubBlocks(SimulinkBlock block)
Recursively count sub blocks.


countLines

public static int countLines(SimulinkBlock block)
Recursively count lines.


countStates

public static int countStates(IStateflowNodeContainer<?> node)
Recursively count Stateflow states.


countStates

public static int countStates(StateflowMachine stateflowMachine)
Count states of all charts of the machine.


getChart

public static StateflowChart getChart(IStateflowElement<?> element)
Get the Stateflow chart a Stateflow element belongs to.

Returns:
the Stateflow chart or null if the element is unconnected or not associated with a chart, e.g. StateflowTarget.

getBlock

public static StateflowBlock getBlock(IStateflowElement<?> element)
Get the Stateflow block a Stateflow element belongs to.

Returns:
the Stateflow block or null if the element is unconnected or not associated with a chart, e.g. StateflowTarget.

getStateName

public static java.lang.String getStateName(StateflowState state)
Get name of a Stateflow state as defined in the Stateflow manual. As Stateflow awkwardly stores the names as part of the label, this is put in a utility methods and not directly at class StateflowState.


getFQStateName

public static java.lang.String getFQStateName(StateflowState state)
Get full qualified state name. This is deliberately not part of class StateflowState as names of Stateflow derives names from the state labels.


getStateflowOutport

public static SimulinkBlock getStateflowOutport(SimulinkOutPort outPort)
Obtain out port block that is below the a Stateflow block and describes the output of a Stateflow chart. What Simulink displays like an atomic Stateflow chart is internally represented as a Simulink sub system that itself contains multiple blocks. The sub system itself has a normal inport/outport which has only a number (as (almost) all ports of Simulink sub systems do). However the sub system contains a block of type Inport/Outport (quite confusing...) and this is the one the carries the name of the Stateflow output. Note that this is related to a past CR described at . The code is the following:
  • iterate over all child blocks of the sub system that represents the Stateflow chart
  • pick the one that is of type Inport/Outport and that has the same port index as the inport/outport of the sub system (the index defines the mapping between the Inport/Ouport block and the actual inport/outport)


getStateflowInport

public static SimulinkBlock getStateflowInport(SimulinkInPort inPort)
Obtain in port. See getStateflowOutport(SimulinkOutPort) for details.


simulink

simulink - 2.7