hades.signals
Class Signal

java.lang.Object
  extended byhades.signals.Signal
All Implemented Interfaces:
ColorSource, ContextToolTip, java.io.Serializable, Simulatable
Direct Known Subclasses:
ImageSignal, IntegerSignal, SignalInteger, SignalStdLogic1164, SignalStdLogicVector, StringSignal

public class Signal
extends java.lang.Object
implements Simulatable, ColorSource, ContextToolTip, java.io.Serializable

Signal - the base class for all hades simulation signals. All SimObjects are connected via subclasses of Signal, e.g. 'hades.signal.Std_logic_1164'. This class is _not_ used to draw the Signal. Both senders and receivers of this signals are kept in arrays (instead of lists or vectors), because we want fastest read-access. Insertion and deletions of senders/receivers are rare events.

A Signal is expected to belong to some Design, to allow for hierarchical netlist.

See Also:
Serialized Form

Field Summary
protected static boolean debug
           
protected  Design design
           
protected  int[] DFS
           
protected  java.lang.Object[] driverValues
           
protected  java.util.Vector[] EA
           
protected  boolean glowMode
           
protected  boolean[] isRoot
           
protected  Label label
           
protected  double lastChangeTime
           
protected  java.lang.Object lastValue
           
protected  java.lang.String name
           
protected  java.util.Hashtable portPositionTable
           
protected  Waveform probe
           
protected  ProbeSymbol probeSymbol
           
protected  Port[] receivers
           
protected  WireSegment[] segments
           
protected  Port[] senders
           
protected  SimKernel simulator
           
protected  SolderDot[] solderDots
           
protected  java.util.StringTokenizer st
           
protected  java.awt.Point[] VA
           
protected  java.lang.Object value
           
protected  java.util.Hashtable vertexTable
           
protected  java.util.Hashtable VI
           
protected  boolean visible
           
protected  boolean[] visited
           
 
Constructor Summary
Signal()
          create an (abstract) Signal
Signal(java.lang.String name)
          create an (abstract) Signal called 'name'
Signal(java.lang.String name, Port[] senders, Port[] receivers)
          create an (abstract) Signal called 'name' with given senders and receivers
 
Method Summary
 boolean addReceiver(Port p)
          add a new receiver to this Signal
 void addSegment(WireSegment ws)
          add a new segment to this Signal.
 boolean addSender(Port p)
          add a new sender to this Signal
 void addSolderDot(SolderDot sd)
           
 void buildEdgeVectors()
           
 void buildVertexArrays()
          construct an array VA[i] to reference signal vertices via an index
 boolean canConnect(Port port)
          check whether this Signal can be connected to Port port.
 boolean canMerge(Signal signal)
           
 void connect(Port p)
          connect this Signal to Port p.
 int countSegments()
           
 int countSendersAndReceivers()
           
 int countSubgraphs()
           
protected  void createLabel()
           
 void createPortPositionTable()
          build the portPositionTable for this Signal.
 void createVertexTable()
          create and initialize a Hashtable to represent all vertices of the Signal graph.
 void dbg(java.lang.String s)
           
 boolean deleteReceiver(Port p)
          delete a receiver from this Signal
 void deleteSegment(WireSegment ws)
           
 boolean deleteSender(Port p)
          delete a sender from this Signal
 void deleteSingularSegments()
           
 void DFS()
          create a depth-first-search numbering of the Signal graph in the array DFS[]; A negative index indicates the start of a new connected component of the Signal graph.
 void disconnect(Port p)
           
 void disconnectAll()
           
 void elaborate(java.lang.Object arg)
          elaborate(): called at the start of the simulation to initialize this signal.
 void evaluate(java.lang.Object arg)
          evaluate().
 java.awt.Color getColor()
          get the color to be used for drawing the WireSegments and SolderDots for this Signal during animation.
static boolean getDebug()
           
 Design getDesign()
           
 java.lang.Object[] getDriverValues()
           
 java.lang.String getFullName()
           
 boolean getGlowMode()
           
 Label getLabel()
           
 double getLastChangeTime()
           
 java.lang.String getName()
           
 java.lang.Object getPreviousValue()
           
 Waveform getProbe()
           
 ProbeSymbol getProbeSymbol()
           
 Port[] getReceivers()
           
 FigObject[] getSegments()
           
 Port[] getSenders()
           
 SimKernel getSimulator()
           
 FigObject[] getSolderDots()
           
 java.lang.String getToolTip(java.awt.Point position, long millis)
          construct a (short) tool tip message for a Signal.
 java.lang.Object getValue()
           
 java.util.Hashtable getVertexTable()
          return the vertexTable for this Signal, which may be null.
 boolean getVisible()
           
 void handleGlowMode()
          do whatever is necessary to update our graphical representation when the glow mode state changed.
 boolean hasEvent()
           
 boolean hasProbe()
           
 boolean isConnected(Port port)
           
 boolean isPortPosition(java.awt.Point p)
           
 boolean isStable(double dt)
           
 boolean isVertex(java.awt.Point p)
           
 boolean isVisible()
           
 void merge(Signal victim)
          merge this Signal with Signal victim: we add all senders, receivers, and wire segments from victim to our own data structares.
 void message(java.lang.String msg)
          message(): print or display an information message
protected  void moveLabelTo(java.awt.Point p)
           
 int numberOfDrivers()
           
 void parseName()
           
protected  void parsePorts()
          phase 1: parse the 'ports' part of this Signal.
protected  void parseSegments()
          phase 2 parse the segments, if visible
protected  void parseSolderDots()
          phase 3: parse the solder dots, if visible
 void printDFS()
           
 void printGraph()
           
 void printPortPositionTable()
           
 void printSegments()
           
 void printVertexTable()
          print the contents of the vertexTable.
 void propagateConnectivityChanges()
          this method is called from the connect() and disconnect() methods to inform all senders/receivers of this Signal of any interactive changes made to the Signal connectivity status.
 void readFromString(java.lang.String line, Design design)
           
 void rebuildSolderDots()
          an utility method to rebuild the array with all SolderDots on this Signal.
 void removeProbe()
           
 java.lang.String renameAfterDriver()
          rename this signal after the component and port driving the signal, and return the resulting name, too.
static void setDebug(boolean d)
           
 void setDesign(Design d)
           
 void setGlowMode(boolean b)
           
 void setName(java.lang.String _name)
           
 void setProbe(Waveform w)
           
 void setProbeSymbol(ProbeSymbol ps)
           
 void setSimulator(SimKernel simulator)
           
 void setTrafo(FigTrafo2D trafo)
          set a new transformation for the graphical display of this Signals segments and solder dots.
 void setValue(java.lang.Object o)
           
 void setValue(java.lang.String s)
           
 void setVisible(boolean v)
           
 void showInternalWireSegments(boolean visible)
          show (or hide) the 'internal' WireSegments of this Signal, that is, all WireSegments that are not directly connected to SimObject Port.
 Signal[] splitIntoSubgraphs()
          split a Signal into its connected subgraphs, and return an Array with references to these subgraph Signals.
 void tearDown()
          clear all references held by this signal.
 java.lang.String toString()
          toString() - the usual info method
 java.lang.String toStringVerbose()
           
 java.lang.String toStringVerboseOld()
           
 void write(java.io.PrintWriter ps)
           
 void writeAsResource(java.io.PrintWriter ps)
          writeAsResource(): write a Signal to a text-file.
protected  void writePorts(java.io.PrintWriter ps)
          number of ports, instance-names of connected components with port names.
protected  void writeSegments(java.io.PrintWriter ps)
          write the number of segments, then the segment coordinates for the graphical representation of this Signal
 void writeSolderDots(java.io.PrintWriter ps)
          write the number and position of all SolderDots for the graphical representation of this Signal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

simulator

protected SimKernel simulator

receivers

protected Port[] receivers

senders

protected Port[] senders

driverValues

protected java.lang.Object[] driverValues

design

protected Design design

name

protected java.lang.String name

value

protected java.lang.Object value

lastValue

protected java.lang.Object lastValue

lastChangeTime

protected double lastChangeTime

visible

protected boolean visible

segments

protected WireSegment[] segments

solderDots

protected SolderDot[] solderDots

glowMode

protected boolean glowMode

label

protected Label label

probeSymbol

protected ProbeSymbol probeSymbol

probe

protected Waveform probe

st

protected java.util.StringTokenizer st

debug

protected static boolean debug

vertexTable

protected java.util.Hashtable vertexTable

portPositionTable

protected java.util.Hashtable portPositionTable

VI

protected java.util.Hashtable VI

VA

protected java.awt.Point[] VA

EA

protected java.util.Vector[] EA

visited

protected boolean[] visited

isRoot

protected boolean[] isRoot

DFS

protected int[] DFS
Constructor Detail

Signal

public Signal()
create an (abstract) Signal


Signal

public Signal(java.lang.String name)
create an (abstract) Signal called 'name'


Signal

public Signal(java.lang.String name,
              Port[] senders,
              Port[] receivers)
create an (abstract) Signal called 'name' with given senders and receivers

Method Detail

getDesign

public Design getDesign()

setDesign

public void setDesign(Design d)

getDebug

public static boolean getDebug()

setDebug

public static void setDebug(boolean d)

getSimulator

public SimKernel getSimulator()

setSimulator

public void setSimulator(SimKernel simulator)

getReceivers

public Port[] getReceivers()

getSenders

public Port[] getSenders()

getDriverValues

public java.lang.Object[] getDriverValues()

countSendersAndReceivers

public int countSendersAndReceivers()

numberOfDrivers

public int numberOfDrivers()

hasProbe

public boolean hasProbe()

getProbe

public Waveform getProbe()

setProbe

public void setProbe(Waveform w)

removeProbe

public void removeProbe()

setProbeSymbol

public void setProbeSymbol(ProbeSymbol ps)

getProbeSymbol

public ProbeSymbol getProbeSymbol()

getColor

public java.awt.Color getColor()
get the color to be used for drawing the WireSegments and SolderDots for this Signal during animation. This method is required to implement the ColorSource interface. In this class, we always return Color.blue, but subclasses should override this method as needed.

Specified by:
getColor in interface ColorSource

getVisible

public boolean getVisible()

isVisible

public boolean isVisible()

setVisible

public void setVisible(boolean v)

getLabel

public Label getLabel()

createLabel

protected void createLabel()

moveLabelTo

protected void moveLabelTo(java.awt.Point p)

getSegments

public FigObject[] getSegments()

countSegments

public int countSegments()

getSolderDots

public FigObject[] getSolderDots()

addSegment

public void addSegment(WireSegment ws)
add a new segment to this Signal. Override this method in subclasses as needed to specify signal-specific segment attributes, e.g.
   
     public void addSegment( WireSegment ws ) {
       super.addSegment( ws );
       ws.getAttributes().lineWidth = 160;
     }
     


printSegments

public void printSegments()

deleteSegment

public void deleteSegment(WireSegment ws)

addSolderDot

public void addSolderDot(SolderDot sd)

setTrafo

public void setTrafo(FigTrafo2D trafo)
set a new transformation for the graphical display of this Signals segments and solder dots.


getValue

public java.lang.Object getValue()

setValue

public void setValue(java.lang.Object o)

setValue

public void setValue(java.lang.String s)

getPreviousValue

public java.lang.Object getPreviousValue()

getLastChangeTime

public double getLastChangeTime()

isStable

public boolean isStable(double dt)

hasEvent

public boolean hasEvent()

setName

public void setName(java.lang.String _name)

getName

public java.lang.String getName()

getFullName

public java.lang.String getFullName()

renameAfterDriver

public java.lang.String renameAfterDriver()
rename this signal after the component and port driving the signal, and return the resulting name, too. For example, a signal driven by a flipflop named "DFF3" will be renamed to "DFF3.Q", which might be a (much) more useful name than the default name (like "n_137") created by the Hades editor. For signals with multiple drivers, we use a randomly chosen driver.

Note that this method does not check whether the resulting name is unique in its Design. We assume that the component names in the Design are unique too, as well as the component port names...

As a special exception, we check whether the driving component is a hades.models.io.Ipin. If so, we rename the signal to the same name as the Ipin (without the ".Y").

If the signal has no driver, this method does not modify the signal name.


setGlowMode

public void setGlowMode(boolean b)

getGlowMode

public boolean getGlowMode()

handleGlowMode

public void handleGlowMode()
do whatever is necessary to update our graphical representation when the glow mode state changed. Base class Signal does nothing here.


canConnect

public boolean canConnect(Port port)
check whether this Signal can be connected to Port port. This is impossible, if either port is already connected to another signal, or if there is a type or value (e.g. bus width) mismatch between this Signal's type and the type expected by the port.


canMerge

public boolean canMerge(Signal signal)

isConnected

public boolean isConnected(Port port)

connect

public void connect(Port p)
connect this Signal to Port p. This will automatically add P as a sender or receiver, depending on the I/O-type of Port p.


disconnect

public void disconnect(Port p)

disconnectAll

public void disconnectAll()

propagateConnectivityChanges

public void propagateConnectivityChanges()
this method is called from the connect() and disconnect() methods to inform all senders/receivers of this Signal of any interactive changes made to the Signal connectivity status. This method should be overridded by subclasses as necessary to maintain a consistent state between the Signal itself and the connected SimObjects.

For example, we want to propagate the current Signal value to a newly added receiver port, in order to avoid additional simulation restarts.

Note that this method should not generate additional SimEvents during simulation startup.


addSender

public boolean addSender(Port p)
add a new sender to this Signal


deleteSender

public boolean deleteSender(Port p)
delete a sender from this Signal


addReceiver

public boolean addReceiver(Port p)
add a new receiver to this Signal


deleteReceiver

public boolean deleteReceiver(Port p)
delete a receiver from this Signal


elaborate

public void elaborate(java.lang.Object arg)
elaborate(): called at the start of the simulation to initialize this signal.

Specified by:
elaborate in interface Simulatable
Parameters:
arg - an arbitrary argument

evaluate

public void evaluate(java.lang.Object arg)
evaluate(). The base class 'hades.signals.Signal' just ignores this method. Subclasses should implement the required behavior.

Specified by:
evaluate in interface Simulatable
Parameters:
arg - An object with the new value for this signal.

message

public void message(java.lang.String msg)
Description copied from interface: Simulatable
message(): print or display an information message

Specified by:
message in interface Simulatable

write

public void write(java.io.PrintWriter ps)

toString

public java.lang.String toString()
toString() - the usual info method


toStringVerboseOld

public java.lang.String toStringVerboseOld()

toStringVerbose

public java.lang.String toStringVerbose()

getToolTip

public java.lang.String getToolTip(java.awt.Point position,
                                   long millis)
construct a (short) tool tip message for a Signal. This method should be overridden as needed.

Specified by:
getToolTip in interface ContextToolTip

tearDown

public void tearDown()
clear all references held by this signal. Unfortunately, this method seems to be required to help the garbage collector to clean up all the (circular) references between signal, port, simobjects, simulator, and GUI fast enough. Note that the signal cannot be used after this method has been called. Should be overridden by subclasses as needed.


writeAsResource

public void writeAsResource(java.io.PrintWriter ps)
writeAsResource(): write a Signal to a text-file. This method uses the following data format, where all values are concatenated on one single line seperated by blanks:
     classname
     signalname 
     n_ports [instancename portname]**n_ports
     n_segments [n_points [xi yi]**n_points ]**n_segments
     n_solders [xi yi]**n_solders
    
The following example describes a Signal of type "SignalStdLogic1164" with name "n2", two connections to port "Y" on instance "i6" and port "A" on instance "i7". The signal has only one wire-segment which runs from point (27600, 15600) to point (30000 15600) and zero solder dots: "hades.signals.SignalStdLogic1164 n2 2 i6 Y i7 A 1 2 27600 15600 30000 1560 0 0 "


writePorts

protected void writePorts(java.io.PrintWriter ps)
                   throws java.lang.Exception
number of ports, instance-names of connected components with port names. There is only one subtlety: We don't want to include bidirectional ports doubly, so we include them only with the senders.

Throws:
java.lang.Exception

writeSegments

protected void writeSegments(java.io.PrintWriter ps)
                      throws java.lang.Exception
write the number of segments, then the segment coordinates for the graphical representation of this Signal

Throws:
java.lang.Exception

writeSolderDots

public void writeSolderDots(java.io.PrintWriter ps)
                     throws java.lang.Exception
write the number and position of all SolderDots for the graphical representation of this Signal

Throws:
java.lang.Exception

readFromString

public void readFromString(java.lang.String line,
                           Design design)

parseName

public void parseName()

parsePorts

protected void parsePorts()
phase 1: parse the 'ports' part of this Signal.


parseSegments

protected void parseSegments()
phase 2 parse the segments, if visible


parseSolderDots

protected void parseSolderDots()
phase 3: parse the solder dots, if visible


getVertexTable

public java.util.Hashtable getVertexTable()
return the vertexTable for this Signal, which may be null. The vertexTable maps vertices (Point positions) to multiplicity, the number of wire-segments (edges) outgoing from the vertex.


createVertexTable

public void createVertexTable()
create and initialize a Hashtable to represent all vertices of the Signal graph. The Hashtable contains pairs of (Point,int) data, where Point is a WireSegment end point, and the integer specifies the multiplicity (number of connected WireSegments) at this point.

Note that it is trivial to rebuild the SolderDot array from the vertexTable.


deleteSingularSegments

public void deleteSingularSegments()

printVertexTable

public void printVertexTable()
print the contents of the vertexTable. This method will initialize the vertexTable, if necessary;


isVertex

public boolean isVertex(java.awt.Point p)

createPortPositionTable

public void createPortPositionTable()
build the portPositionTable for this Signal.

This method retrieves the positions of all Ports this Signal is connected to, and enters them to the portPositionTable.

Currently, the portPositionTable is only used to rebuild the SolderDots on a Signal, because we want a SolderDot on all vertices with more than three edges, but also on port vertices with two edges.


isPortPosition

public boolean isPortPosition(java.awt.Point p)

printPortPositionTable

public void printPortPositionTable()

buildVertexArrays

public void buildVertexArrays()
construct an array VA[i] to reference signal vertices via an index


buildEdgeVectors

public void buildEdgeVectors()

DFS

public void DFS()
create a depth-first-search numbering of the Signal graph in the array DFS[]; A negative index indicates the start of a new connected component of the Signal graph.

See Sedgewick, algorithms in c++, Addison-Wesley for a description of the algorithm.


printDFS

public void printDFS()

printGraph

public void printGraph()

countSubgraphs

public int countSubgraphs()

splitIntoSubgraphs

public Signal[] splitIntoSubgraphs()
split a Signal into its connected subgraphs, and return an Array with references to these subgraph Signals. This method should probably be called after a WireSegment was deleted.

Note that this method does not reconstruct the Editor's objectList. Also note that this method expects that the Signal connectivity graph has already been constructed, e.g. by calling DFS().

Also note that we can safely assume that the Signal in question is visible. This is because splitIntoSubgraphs is only called in reaction to user-interaction on the editor canvas, which implies that the "this" signal is currently visible. This in turn means that we call setVisible() on all splitter signals, which fixes an important editor GUI bug.


dbg

public void dbg(java.lang.String s)

rebuildSolderDots

public void rebuildSolderDots()
an utility method to rebuild the array with all SolderDots on this Signal. A SolderDot is added to all Signal vertices with multiplicity larger than 2 (that is, when more than 2 WireSegments end at this vertex) or the multiplicity is 2 for a Port vertex.

Note that you will have to rebuild the editor's object list before the changes to this Signal will be visible. Typically, you might use something like the following code:

      signal.rebuildSolderDots();
      editor.deleteFromObjectList( signal );
      editor.insertIntoObjectList( signal );
      editor.doRedraw();
    


merge

public void merge(Signal victim)
merge this Signal with Signal victim: we add all senders, receivers, and wire segments from victim to our own data structares. Finally, we rebuild the vertex array and the solder dots.


showInternalWireSegments

public void showInternalWireSegments(boolean visible)
show (or hide) the 'internal' WireSegments of this Signal, that is, all WireSegments that are not directly connected to SimObject Port. This method is used for better visualization in big circuit schematics, e.g. to selectively hide some control signals while still displaying the control signals 'ends' and all of the datapath signals.