Package ptolemy.cg.lib.syntactic
Class SyntacticNode
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity
-
- ptolemy.cg.lib.syntactic.SyntacticNode
-
- All Implemented Interfaces:
java.lang.Cloneable
,SyntacticTerm
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class SyntacticNode extends ComponentEntity implements SyntacticTerm
Represent nodes in the context of SyntacticGraphs. Existing and generated elements of models are represented and their ports are represented syntactically as enumerated lists of input and output ports. This enumeration is used for combinatorial composition in syntaxes with unnamed ports.Inheriting classes should use protected methods for constructing representation from existing elements.
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Chris Shaver
- Pt.AcceptedRating:
- red
- Pt.ProposedRating:
- red (shaver)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SyntacticNode.NodeType
Internal enum representing the types of nodes and how they are ordered, compared, and categorized.-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.LinkedList<SyntacticPort>
_inputs
List of references to ports syntactically marked as inputs.protected java.util.LinkedList<SyntacticPort>
_outputs
List of references to ports syntactically marked as outputs.-
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
-
-
Constructor Summary
Constructors Constructor Description SyntacticNode()
Create new instance of SyntacticNode with no connections.SyntacticNode(CompositeEntity container, java.lang.String name)
Construct an entity with the given name contained by the specified entity.SyntacticNode(Workspace workspace)
Create new instance of SyntacticNode with no connections.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
_makeMediatorIcon()
Generate icon for mediator node.protected java.lang.String
_makePermutationIcon(int[] permutation)
Generate icon for permutation node.protected SyntacticPort
_mapInputPort(Port port, int offset)
Get the SyntacticPort corresponding to a channel of a represented input port.protected SyntacticPort
_mapOutputPort(Port port, int offset)
Get the SyntacticPort corresponding to a channel of a represented output port.int
addPorts(Port port, boolean isin)
Add a port node with a directionality.java.lang.String
boundaryCode()
Generate a string signifying the boundary of a node.java.lang.String
description(java.lang.String prefix, java.lang.String suffix)
Print description of Node.java.lang.String
generateCode()
Generate code for node.java.util.List<SyntacticNode>
getConnectedNode(java.util.List<SyntacticPort> ports)
Get a unique list of connected nodes from a given list of ports.SyntacticNode
getConnectedNode(SyntacticPort port)
Get the connected node from a given port.java.util.List<SyntacticNode>
getDownstreamNodes()
Get a list of nodes immediately downstream from outgoing connections.Port
getExteriorPort()
Get the exterior Port syntactically represented by the node.SyntacticPort
getFirstInput()
Get the first input or return null.SyntacticPort
getFirstOutput()
Get the first output or return null.java.lang.String
getIdentifier()
Get string identifier (non-unique) for node.java.util.List<SyntacticPort>
getInputs()
Get the list of ordered inputs.java.lang.String
getLabel()
Get the label of the node.double
getLayoutVerticalSpace()
Get the vertical offset for visually representing node.SyntacticNode.NodeType
getNodeType()
Get the NodeType.int
getOrder()
Get the relative order of the node by types.java.util.List<SyntacticPort>
getOutputs()
Get the list of ordered outputs.Entity
getRepresented()
Get the Entity syntactically represented by the node.java.util.List<SyntacticNode>
getUpstreamNodes()
Get a list of nodes immediately upstream from outgoing connections.boolean
hasCode()
Determine whether or not code should be generated.java.lang.Integer
inputIndex(SyntacticPort port)
Get index represented by the first channel of given port.java.lang.Integer
inputPortIndex(Port port)
Get index represented by the first channel of given port.boolean
isCap()
Determine whether node is a cap.boolean
isExterior()
Determine whether node represents an exterior port.boolean
isFeedback()
Determine whether node represents feedback.boolean
isIdentity()
Determine whether node represents an identity.boolean
isIncoming()
Determine whether node is incoming to the expression.boolean
isInitial()
Determine whether node is initial, having no inputs.boolean
isIsolated()
Determine whether node is isolated from the network.boolean
isMarked()
Get whether the node has been marked.boolean
isMediator()
Determine whether node represents a mediator.boolean
isOutgoing()
Determine whether node is outgoing to the expression.boolean
isPermutation()
Determine whether node is a permutation.boolean
isRepresentative()
Determine whether node represents an Entity or is purely syntactic.boolean
isTerminal()
Determine whether node is terminal, having no outputs.boolean
isVisited()
Get whether the node has been visited.java.lang.Integer
outputIndex(SyntacticPort port)
Get index represented by the first channel of given port.java.lang.Integer
outputPortIndex(Port port)
Get index represented by the first channel of given port.SyntacticRank
rank()
Get the Syntactic rank of the node.void
remark()
Recalculate properties of node.boolean
representEntity(Entity entity)
Represent an Entity and its ports for use in a SyntacticGraph.void
representExteriorPort(Port port)
Represent an exterior port with a purely syntactic Node.void
setCap(boolean direction)
Set node as a initial or terminal node in specified direction, true being out.void
setFeedback(boolean direction)
Set node as a feedback node in specified direction, true being feed out.void
setIdentity()
Set node as an identity.void
setLabel(java.lang.String label)
Set the label used to lexically represent the node.void
setLocation(double x, double y)
Set the location of the node in layout.void
setMarked(boolean b)
Set the marked marker.void
setMediator(boolean direction, int valence)
Set node as a mediator node in specified direction.void
setPermutation(int[] permutation)
Set node as a bijective permutation node with a specified permutation.void
setSyntactic(int inputs, int outputs)
Set node as purely syntactic, not representing any Entity.void
setVisited(boolean b)
Set the visited marker.int
sizeInputs()
Get the number of inputs to the node.int
sizeOutputs()
Get the number of outputs to the node.-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, newPort, propagateExistence, setContainer, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, connectionsChanged, 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, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, 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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getDisplayName, getFullName, getName, getName
-
-
-
-
Field Detail
-
_inputs
protected java.util.LinkedList<SyntacticPort> _inputs
List of references to ports syntactically marked as inputs.
-
_outputs
protected java.util.LinkedList<SyntacticPort> _outputs
List of references to ports syntactically marked as outputs.
-
-
Constructor Detail
-
SyntacticNode
public SyntacticNode()
Create new instance of SyntacticNode with no connections.
-
SyntacticNode
public SyntacticNode(Workspace workspace)
Create new instance of SyntacticNode with no connections.- Parameters:
workspace
- Workspace in which to create the node.
-
SyntacticNode
public SyntacticNode(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct an entity with the given name contained by the specified entity. The container argument must not be null, or a NullPointerException will be thrown. This entity will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version of the workspace. This constructor write-synchronizes on the workspace.- Parameters:
container
- The container entity.name
- The name of the entity.- Throws:
IllegalActionException
- If the entity cannot be contained by the proposed container.NameDuplicationException
- If the name coincides with an entity already in the container.
-
-
Method Detail
-
representEntity
public boolean representEntity(Entity entity) throws IllegalActionException, NameDuplicationException
Represent an Entity and its ports for use in a SyntacticGraph.- Parameters:
entity
- The Entity to be represented with the SyntacticNode- Returns:
- if the representation is total.
- Throws:
IllegalActionException
- If the entity is already represented, if there is a problem getting the width or creating a port or attribute.NameDuplicationException
- If there is a problem creating a port or attribute.
-
addPorts
public int addPorts(Port port, boolean isin) throws IllegalActionException, NameDuplicationException
Add a port node with a directionality. Given port is represented by constructed SyntacticPorts then added to the node in this form. The number of ports added from the given port is the width of the given port. Each channel is represented by a SyntacticPort and pointed back to the given Port.- Parameters:
port
- Port to addisin
- True if input, False if output.- Returns:
- number of SyntacticPorts added (= width).
- Throws:
IllegalActionException
- If thrown while getting the port width, creating a new port, creating a new StringAttribute or setting the expression.NameDuplicationException
- If thrown while creating a new port.
-
representExteriorPort
public void representExteriorPort(Port port) throws IllegalActionException, NameDuplicationException
Represent an exterior port with a purely syntactic Node.- Parameters:
port
- The port to represent on the node.- Throws:
IllegalActionException
- If thrown while creating a new port, creating a new cardinal attribute or setting the cardinal expression.NameDuplicationException
- If thrown while creating a new port or creating a new cardinal attribute.
-
setSyntactic
public void setSyntactic(int inputs, int outputs) throws IllegalActionException, NameDuplicationException
Set node as purely syntactic, not representing any Entity.- Parameters:
inputs
- Number of inputs.outputs
- Number of outputs.- Throws:
IllegalActionException
- If thrown while creating a new port, creating a new cardinal attribute or setting the cardinality.NameDuplicationException
- If thrown while creating a new port or creating a new cardinal attribute.
-
setIdentity
public void setIdentity() throws IllegalActionException, NameDuplicationException
Set node as an identity.- Throws:
IllegalActionException
- If thrown while setting the node as purely syntactic, not representing any Entity.NameDuplicationException
- If thrown while setting the node as purely syntactic, not representing any Entity.
-
setFeedback
public void setFeedback(boolean direction) throws IllegalActionException, NameDuplicationException
Set node as a feedback node in specified direction, true being feed out.- Parameters:
direction
- The direction to make the feedback node.- Throws:
IllegalActionException
- If thrown while setting the node as purely syntactic, not representing any Entity.NameDuplicationException
- If thrown while setting the node as purely syntactic, not representing any Entity.
-
setMediator
public void setMediator(boolean direction, int valence) throws IllegalActionException, NameDuplicationException
Set node as a mediator node in specified direction. The true direction splits, the false merges.- Parameters:
direction
- The direction to make the mediator node.valence
- The amount of endpoints on the opposite side.- Throws:
IllegalActionException
- If thrown while setting the node as purely syntactic, not representing any Entity.NameDuplicationException
- If thrown while setting the node as purely syntactic, not representing any Entity.
-
setCap
public void setCap(boolean direction) throws IllegalActionException, NameDuplicationException
Set node as a initial or terminal node in specified direction, true being out.- Parameters:
direction
- The direction to make the cap node.- Throws:
IllegalActionException
- If thrown while setting the node as purely syntactic, not representing any Entity.NameDuplicationException
- If thrown while setting the node as purely syntactic, not representing any Entity.
-
setPermutation
public void setPermutation(int[] permutation) throws IllegalActionException, NameDuplicationException
Set node as a bijective permutation node with a specified permutation.- Parameters:
permutation
- The permutation to represent as the node.- Throws:
IllegalActionException
- If thrown while setting the node as purely syntactic, not representing any Entity.NameDuplicationException
- If thrown while setting the node as purely syntactic, not representing any Entity.
-
getConnectedNode
public SyntacticNode getConnectedNode(SyntacticPort port)
Get the connected node from a given port. If the graph is not made bijective this gives the first.- Parameters:
port
- The port to look out from.- Returns:
- An immediately connected node.
-
getConnectedNode
public java.util.List<SyntacticNode> getConnectedNode(java.util.List<SyntacticPort> ports)
Get a unique list of connected nodes from a given list of ports.- Parameters:
ports
- The list of ports to look out from.- Returns:
- A set list of immediately connected nodes.
-
getDownstreamNodes
public java.util.List<SyntacticNode> getDownstreamNodes()
Get a list of nodes immediately downstream from outgoing connections.- Returns:
- A list of immediately downstream nodes.
-
getUpstreamNodes
public java.util.List<SyntacticNode> getUpstreamNodes()
Get a list of nodes immediately upstream from outgoing connections.- Returns:
- A list of immediately upstream nodes.
-
remark
public void remark()
Recalculate properties of node.
-
setVisited
public void setVisited(boolean b)
Set the visited marker. This marker is used for algorithms that visit nodes.- Parameters:
b
- State of the visited flag.
-
setMarked
public void setMarked(boolean b)
Set the marked marker. This marker is used for algorithms that traverse nodes.- Parameters:
b
- State of the marked flag.
-
setLabel
public void setLabel(java.lang.String label)
Set the label used to lexically represent the node.- Parameters:
label
- Label to set for node.- See Also:
getLabel()
-
setLocation
public void setLocation(double x, double y) throws IllegalActionException, NameDuplicationException
Set the location of the node in layout.- Parameters:
x
- The x-coordinatey
- The y-coordinate- Throws:
IllegalActionException
- If thrown while creating a new location or setting the coordinates of the location.NameDuplicationException
- If thrown while creating a new location.
-
getLayoutVerticalSpace
public double getLayoutVerticalSpace()
Get the vertical offset for visually representing node.- Returns:
- vertical offset down from baseline.
-
getIdentifier
public java.lang.String getIdentifier()
Get string identifier (non-unique) for node.- Returns:
- identifier string.
-
isVisited
public boolean isVisited()
Get whether the node has been visited.- Returns:
- value of the visited flag.
-
isMarked
public boolean isMarked()
Get whether the node has been marked.- Returns:
- value of the marked flag.
-
outputPortIndex
public java.lang.Integer outputPortIndex(Port port)
Get index represented by the first channel of given port.- Parameters:
port
- The Port represented in the node.- Returns:
- base index object or null if not found.
-
inputPortIndex
public java.lang.Integer inputPortIndex(Port port)
Get index represented by the first channel of given port.- Parameters:
port
- The Port represented in the node.- Returns:
- base index object or null if not found.
-
outputIndex
public java.lang.Integer outputIndex(SyntacticPort port)
Get index represented by the first channel of given port.- Specified by:
outputIndex
in interfaceSyntacticTerm
- Parameters:
port
- The Port represented in the node.- Returns:
- base index object or null if not found.
-
inputIndex
public java.lang.Integer inputIndex(SyntacticPort port)
Get index represented by the first channel of given port.- Specified by:
inputIndex
in interfaceSyntacticTerm
- Parameters:
port
- The Port represented in the node.- Returns:
- base index object or null if not found.
-
getInputs
public java.util.List<SyntacticPort> getInputs()
Get the list of ordered inputs.- Specified by:
getInputs
in interfaceSyntacticTerm
- Returns:
- The list of inputs.
-
getOutputs
public java.util.List<SyntacticPort> getOutputs()
Get the list of ordered outputs.- Specified by:
getOutputs
in interfaceSyntacticTerm
- Returns:
- The list of outputs.
-
sizeInputs
public int sizeInputs()
Get the number of inputs to the node. For input nodes this returns 1 for the input it represents to the downstream node.- Specified by:
sizeInputs
in interfaceSyntacticTerm
- Returns:
- number of inputs.
-
sizeOutputs
public int sizeOutputs()
Get the number of outputs to the node. For output nodes this returns 1 for the output it represents to the upstream node.- Specified by:
sizeOutputs
in interfaceSyntacticTerm
- Returns:
- number of outputs.
-
rank
public SyntacticRank rank()
Get the Syntactic rank of the node.- Specified by:
rank
in interfaceSyntacticTerm
- Returns:
- rank of the node.
-
boundaryCode
public java.lang.String boundaryCode()
Generate a string signifying the boundary of a node. The boundary is the number of inputs and outputs.- Returns:
- string representing boundary of node.
-
getFirstInput
public SyntacticPort getFirstInput()
Get the first input or return null.- Returns:
- first input or null.
-
getFirstOutput
public SyntacticPort getFirstOutput()
Get the first output or return null.- Returns:
- first output or null.
-
getOrder
public int getOrder()
Get the relative order of the node by types. ... which order?- Specified by:
getOrder
in interfaceSyntacticTerm
- Returns:
- the order of the node.
-
isFeedback
public boolean isFeedback()
Determine whether node represents feedback.- Returns:
- Whether node is a feedback node
-
isIdentity
public boolean isIdentity()
Determine whether node represents an identity.- Returns:
- Whether node is identity
-
isExterior
public boolean isExterior()
Determine whether node represents an exterior port.- Returns:
- Whether node is exterior
-
isMediator
public boolean isMediator()
Determine whether node represents a mediator.- Returns:
- Whether node is a mediator
-
isInitial
public boolean isInitial()
Determine whether node is initial, having no inputs.- Returns:
- Whether node is initial
-
isTerminal
public boolean isTerminal()
Determine whether node is terminal, having no outputs.- Returns:
- Whether node is terminal
-
isIsolated
public boolean isIsolated()
Determine whether node is isolated from the network.- Returns:
- Whether node is isolated
-
isCap
public boolean isCap()
Determine whether node is a cap.- Returns:
- Whether node is a cap
-
isPermutation
public boolean isPermutation()
Determine whether node is a permutation.- Returns:
- Whether node is a permutation
-
isIncoming
public boolean isIncoming()
Determine whether node is incoming to the expression.- Returns:
- Whether node is incoming
-
isOutgoing
public boolean isOutgoing()
Determine whether node is outgoing to the expression.- Returns:
- Whether node is outgoing
-
hasCode
public boolean hasCode()
Determine whether or not code should be generated. If false, code should be suppressed such is the case for identity nodes.- Specified by:
hasCode
in interfaceSyntacticTerm
- Returns:
- whether code should be generated.
-
getRepresented
public Entity getRepresented()
Get the Entity syntactically represented by the node.- Returns:
- Represented Entity.
-
getExteriorPort
public Port getExteriorPort()
Get the exterior Port syntactically represented by the node.- Returns:
- Represented Port.
-
getNodeType
public SyntacticNode.NodeType getNodeType()
Get the NodeType.- Returns:
- Represented NodeType.
-
getLabel
public java.lang.String getLabel()
Get the label of the node.- Returns:
- label of the node.
- See Also:
setLabel(java.lang.String)
-
isRepresentative
public boolean isRepresentative()
Determine whether node represents an Entity or is purely syntactic. A purely syntactic node represents a relationship in the Ptolemy network as a SyntacticNode that can be expressed in syntax as an special atomic element rather than as a combinator.- Returns:
- Whether node is a representation.
-
generateCode
public java.lang.String generateCode()
Generate code for node.- Specified by:
generateCode
in interfaceSyntacticTerm
- Returns:
- code representation of node.
-
description
public java.lang.String description(java.lang.String prefix, java.lang.String suffix)
Print description of Node.- Parameters:
prefix
- Line prefix for embedding descriptionsuffix
- Line suffix for embedding description- Returns:
- Description of Node.
-
_mapInputPort
protected SyntacticPort _mapInputPort(Port port, int offset)
Get the SyntacticPort corresponding to a channel of a represented input port.- Parameters:
port
- Port represented.offset
- Offset channel of port, 0 if single port.- Returns:
- corresponding SyntacticPort in node.
-
_mapOutputPort
protected SyntacticPort _mapOutputPort(Port port, int offset)
Get the SyntacticPort corresponding to a channel of a represented output port.- Parameters:
port
- Port represented.offset
- Offset channel of port, 0 if single port.- Returns:
- corresponding SyntacticPort in node.
-
_makePermutationIcon
protected java.lang.String _makePermutationIcon(int[] permutation) throws IllegalActionException, NameDuplicationException
Generate icon for permutation node.- Parameters:
permutation
- Array of permutation values.- Returns:
- svg code for generated icon.
- Throws:
IllegalActionException
- If thrown while creating a new variable with the name "_portSpread".NameDuplicationException
- If thrown while creating a new variable with the name "_portSpread".*sh
-
_makeMediatorIcon
protected java.lang.String _makeMediatorIcon()
Generate icon for mediator node.- Returns:
- svg code for generated icon.
-
-