Package ptolemy.domains.ontologies.lib
Class UnitsConverter
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- ptolemy.actor.lib.Transformer
-
- ptolemy.domains.ontologies.lib.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 unitSystemOntology
and anOntologySolver
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)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description StringAttribute
conversionLabel
The conversion label string that will be displayed on the actor icon.StringAttribute
dimensionConcept
The name of the dimension from which both units are derived.StringAttribute
inputUnitConcept
The input unit measurement for the actor.StringAttribute
outputUnitConcept
The output unit measurement for the actor.Parameter
scaleOnLeft
Multiply on the left.Parameter
unitSystemOntologySolver
The unitSystem ontology solver in the model that contains the unitSystem ontology.-
Fields inherited from class ptolemy.actor.lib.Transformer
input, output
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description UnitsConverter(CompositeEntity container, java.lang.String name)
Construct an actor with the given container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeChanged(Attribute attribute)
Update the conversionLabel attribute value when either the inputUnitConcept or the outputUnitConcept attributes change.void
fire()
Transform the input value from its original units measurement to the output units measurement.UnitConcept
getUnitConcept(boolean fromInput)
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.OntologySolver
getUnitOntologySolver()
Return the unitSystem ontology solver specified by the actor's unitSystemOntologySolver parameter.void
preinitialize()
Preinitialize the actor by setting the unit system ontology concepts for the input and output ports.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
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
-
outputUnitConcept
public StringAttribute outputUnitConcept
-
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.
-
-
Constructor Detail
-
UnitsConverter
public UnitsConverter(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct an actor with the given container and name.- Parameters:
container
- The container.name
- The name of this actor.- Throws:
IllegalActionException
- If the actor cannot be contained by the proposed container.NameDuplicationException
- If the container already has an actor with this name.
-
-
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 classNamedObj
- Parameters:
attribute
- The attribute that has changed.- Throws:
IllegalActionException
- Thrown if there is a problem setting the expression of the conversionLabel attribute.
-
fire
public void fire() throws IllegalActionException
Transform the input value from its original units measurement to the output units measurement. If there is no input, then produce no output.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If there is no director.
-
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.
-
preinitialize
public void preinitialize() throws IllegalActionException
Preinitialize the actor by setting the unit system ontology concepts for the input and output ports.- Specified by:
preinitialize
in interfaceInitializable
- Overrides:
preinitialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- Thrown if the input or output unit concepts are incorrectly specified.
-
-