Class UnitsConverter

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class UnitsConverter
    extends Transformer
    An actor that outputs a scaled and offset version of the input based on a unit conversion factor specified in the unitSystem ontology. Produce an output token on each firing with a value that transforms the input value according to the conversion required between the specified input and output unit measurements. The unit measurements are taken from the unitSystem Ontology and an OntologySolver for the unitSystem ontology must be present in the model. For data types where multiplication is not commutative (such as matrices), whether the factor is multiplied on the left is controlled by the scaleOnLeft parameter. Setting the parameter to true means that the factor is multiplied on the left, and the input on the right. Otherwise, the factor is multiplied on the right.
    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Charles Shelton
    Pt.AcceptedRating:
    Red (cshelton)
    Pt.ProposedRating:
    Red (cshelton)
    • Field Detail

      • dimensionConcept

        public StringAttribute dimensionConcept
        The name of the dimension from which both units are derived.
      • conversionLabel

        public StringAttribute conversionLabel
        The conversion label string that will be displayed on the actor icon. It is of the form "inputUnits -> outputUnits" For example, if the actor converts kilometers to miles, its icon label would be: "km -> mi" This label will change when the user changes the unit conversion.
      • inputUnitConcept

        public StringAttribute inputUnitConcept
        The input unit measurement for the actor. This specifies the units in which the input value is received. It will be a Concept in the unitSystem Ontology.
      • outputUnitConcept

        public StringAttribute outputUnitConcept
        The output unit measurement for the actor. This specifies the units to which the output value is transformed. It will be a Concept in the unitSystem Ontology.
      • scaleOnLeft

        public Parameter scaleOnLeft
        Multiply on the left. This parameter controls whether the units transformation factor is multiplied on the left. The default value is a boolean token of value true. Setting is to false will multiply the factor on the right.
      • unitSystemOntologySolver

        public Parameter unitSystemOntologySolver
        The unitSystem ontology solver in the model that contains the unitSystem ontology.
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        Update the conversionLabel attribute value when either the inputUnitConcept or the outputUnitConcept attributes change. For any other attribute change call the superclass method.
        Overrides:
        attributeChanged in class NamedObj
        Parameters:
        attribute - The attribute that has changed.
        Throws:
        IllegalActionException - Thrown if there is a problem setting the expression of the conversionLabel attribute.
      • getUnitConcept

        public UnitConcept getUnitConcept​(boolean fromInput)
                                   throws IllegalActionException
        Return the UnitInformation Concept in the unitSystem ontology for the specified string attribute which represents the unit specification for the either the actor's input or output port.
        Parameters:
        fromInput - true if we want the concept specified by the inputUnitConcept and false if we want the concept specified by the outputUnitConcept.
        Returns:
        The UnitInformation concept associated with this unit concept name.
        Throws:
        IllegalActionException - Thrown if the ontology solver has not been specified, the unit name cannot be found in the unitSystem ontology, or the attribute passed in is not one of the actor's inputUnitConcept or outputUnitConcept attributes.
      • getUnitOntologySolver

        public OntologySolver getUnitOntologySolver()
                                             throws IllegalActionException
        Return the unitSystem ontology solver specified by the actor's unitSystemOntologySolver parameter.
        Returns:
        The unitSystem ontology solver, or null if it is not specified.
        Throws:
        IllegalActionException - Thrown if there is a problem getting the ontology solver object from the parameter.