com.sun.electric.tool.generator.layout
Class LayoutLib

java.lang.Object
  extended by com.sun.electric.tool.generator.layout.LayoutLib

public class LayoutLib
extends java.lang.Object


Nested Class Summary
static class LayoutLib.Corner
           
 
Field Summary
static double DEF_SIZE
          Use the default size.
 
Constructor Summary
LayoutLib()
           
 
Method Summary
static void abutBottom(NodeInst node, double originX, double botY)
          Move a NodeInst so it's bottom edge is at botY.
static void abutBottomTop(java.util.Collection<NodeInst> nodeInsts, double space)
          Abut a list of NodeInsts bottom to top.
static void abutBottomTop(double originX, double botY, java.util.Collection<NodeInst> nodeInsts, double space)
          Abut a list of NodeInsts bottom to top.
static void abutBottomTop(NodeInst bottomNode, double space, NodeInst topNode)
          Abut two NodeInsts bottom to top.
static void abutLeft(NodeInst node, double leftX, double originY)
          Move NodeInst so it's left edge is at leftX and the y-coordinate of it's origin is at originY.
static void abutLeftRight(java.util.Collection<NodeInst> nodeInsts)
          Abut an array of NodeInsts left to right.
static void abutLeftRight(double leftX, double originY, java.util.Collection<NodeInst> nodeInsts)
          Abut an array of NodeInsts left to right.
static void abutLeftRight(NodeInst leftNode, NodeInst rightNode)
          Abut two NodeInsts left to right.
static void alignCorners(NodeInst niFixed, LayoutLib.Corner cnrFixed, NodeInst niMove, LayoutLib.Corner cnrMove, double offsetX, double offsetY)
           
static java.awt.geom.Rectangle2D calculateNodeInst(NodeProto np, double x, double y, double width, double height)
           
static void error(boolean errorHasOccurred, java.lang.String msg)
          Print a message, dump a stack trace, and throw a RuntimeException if errorHasOccurred argument is true.
static java.util.Iterator<ArcInst> getArcInstsOnPortInst(PortInst pi)
          Return a list of ArcInsts attached to PortInst, pi.
static double getArcInstWidth(ArcInst ai)
          Get the width of an ArcInst.
static java.awt.geom.Rectangle2D getBounds(Cell c)
          Get the essential or regular bounds.
static java.awt.geom.Rectangle2D getBounds(Cell cell, Layer.Function function)
          Get the bounding box for the layer in the Cell.
static java.awt.geom.Rectangle2D getBounds(NodeInst node)
          Get the essential or regular bounds.
static double getNodeProtoHeight(NodeProto np)
          Get the default height of a NodeProto.
static double getNodeProtoWidth(NodeProto np)
          Get the default width of a NodeProto.
static java.awt.geom.Point2D getPosition(NodeInst ni)
          Get the position of a NodeInst.
static void modNodeInst(NodeInst ni, double dx, double dy, double dw, double dh, boolean mirrorAboutYAxis, boolean mirrorAboutXAxis, double dAngle)
          Modify the position of a NodeInst.
static ArcInst newArcInst(ArcProto ap, double width, PortInst head, double hX, double hY, PortInst tail, double tX, double tY)
          Create a new ArcInst.
static ArcInst newArcInst(ArcProto ap, double width, PortInst head, PortInst tail)
          Create a new ArcInst.
static Export newExport(Cell cell, java.lang.String name, PortCharacteristic role, ArcProto ap, double w, double x, double y)
          Create an export for a particular layer.
static NodeInst newNodeInst(NodeProto np, double x, double y, double width, double height, double angle, Cell parent)
          Create a new NodeInst.
static NodeInst newNodeInst(NodeProto np, java.awt.geom.Rectangle2D rect, double angle, Cell parent)
           
static Library openLibForRead(java.lang.String libFileName)
          Open a library for reading.
static Library openLibForWrite(java.lang.String libName)
          Open a library for modification.
static java.awt.geom.Rectangle2D roundBounds(java.awt.geom.Rectangle2D r)
           
static double roundCenterX(PortInst pi)
          The center returned by bounds might have a slight amount of rounding error.
static double roundCenterY(PortInst pi)
           
static double widestWireWidth(PortInst port)
          Find the width of the widest wire connected hierarchically to port.
static void writeLibrary(Library lib, int backupScheme)
          Write a library in JELIB format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEF_SIZE

public static final double DEF_SIZE
Use the default size. When a width or height argument has this value the object should be created with its default dimension. Note that -DEF_SIZE is also a legal constant. Negative dimensions specify mirroring for certain methods.

See Also:
Constant Field Values
Constructor Detail

LayoutLib

public LayoutLib()
Method Detail

error

public static void error(boolean errorHasOccurred,
                         java.lang.String msg)
Print a message, dump a stack trace, and throw a RuntimeException if errorHasOccurred argument is true.

Parameters:
errorHasOccurred - indicates a runtime error has been detected
msg - the message to print when an error occurs
Throws:
java.lang.RuntimeException - if errorHasOccurred is true

openLibForRead

public static Library openLibForRead(java.lang.String libFileName)
Open a library for reading. If a library is already open then return it. Otherwise look for the library file named libFileName and open that library.

Parameters:
libFileName - the fully qualified path name of the Library file on disk
Returns:
the open Library or null if it can't be found

openLibForWrite

public static Library openLibForWrite(java.lang.String libName)
Open a library for modification. If a library named libName is already open then return it. Otherwise look for the file named: libFileName and open that library. Finally, if all else fails create a new Library and return it.

Parameters:
libName - the name of the Library file on disk
Returns:
the desired library

writeLibrary

public static void writeLibrary(Library lib,
                                int backupScheme)
Write a library in JELIB format.

Parameters:
lib - the library to be written.

getArcInstWidth

public static double getArcInstWidth(ArcInst ai)
Get the width of an ArcInst. The getArcInstWidth method differs from ArcInst.getLambdaFullWidth() in that it subtracts off the "width offset". Hence, getArcInstWidth returns a width that matches that reported by the GUI.

Parameters:
ai - the ArcInst whose width is reported
Returns:
the width of the ArcInst.

getNodeProtoWidth

public static double getNodeProtoWidth(NodeProto np)
Get the default width of a NodeProto. The getNodeProtoWidth method differs from NodeProto.getDefWidth in that it subtracts off the "width offset". Hence getNodeProtoWidth returns a width that matches that reported by the GUI.

Parameters:
np - the NodeProto we want the width of.
Returns:
the width of the NodeProto.

getNodeProtoHeight

public static double getNodeProtoHeight(NodeProto np)
Get the default height of a NodeProto. The getNodeProtoHeight method differs from NodeProto.getDefHeight in that it subtracts off the "height offset". Hence getNodeProtoHeight returns a height that matches that reported by the GUI.

Parameters:
np - the NodeProto we want the height of
Returns:
the height of the NodeProto

widestWireWidth

public static double widestWireWidth(PortInst port)
Find the width of the widest wire connected hierarchically to port.

Parameters:
port - the PortInst to check for attached wires.
Returns:
the width of the widest wire. This width excludes the "width offset" so it matches the width reported by the GUI. If no wire is attached to port then return DEF_SIZE.

getArcInstsOnPortInst

public static java.util.Iterator<ArcInst> getArcInstsOnPortInst(PortInst pi)
Return a list of ArcInsts attached to PortInst, pi.

Parameters:
pi - PortInst on which to find attached ArcInsts.

roundCenterX

public static double roundCenterX(PortInst pi)
The center returned by bounds might have a slight amount of rounding error. Compensate for this by always rounding coordinates to a 103-4 lambda grid when reading and writing the database.


roundCenterY

public static double roundCenterY(PortInst pi)

calculateNodeInst

public static java.awt.geom.Rectangle2D calculateNodeInst(NodeProto np,
                                                          double x,
                                                          double y,
                                                          double width,
                                                          double height)

newNodeInst

public static NodeInst newNodeInst(NodeProto np,
                                   double x,
                                   double y,
                                   double width,
                                   double height,
                                   double angle,
                                   Cell parent)
Create a new NodeInst. The following geometric transformations are performed upon the NodeProto in order to arrive at the final position of the NodeInst in the coordinate space of the parent:
  1. Scale the NodeProto in x and y so that it has dimensions |width| and |height|. All scaling is performed about the NodeProto's origin, (0, 0).
  2. If width<0 then mirror the preceding result about the y-axis.
  3. If height<0 then mirror the preceding result about the x-axis.
  4. Rotating the preceding result clockwise by angle degrees.
  5. Translate the preceding result by (x, y). Note that the NodeProto's origin always ends up at (x, y) in the coordinate space of the parent.
The newNodeInst method differs from NodeInst.newInstance in the following ways:

Parameters:
np - the NodeProto to instantiate
width - the desired width of the NodeInst
height - the desired height of the NodeInst
x - the desired x-coordinate of the NodeProto's origin in the coordinate space of the parent. If x is negative then the NodeInst mirrors about the y-axis.
y - the desired y-coordinate of the NodeProto's origin in the coordinate space of the parent. If y is negative then the NodeInst mirrors about the x-axis.
angle - the angle, in degrees, of rotation about the NodeProto's origin.
parent - the Cell that will contain the NodeInst.
Returns:
the new NodeInst.

newNodeInst

public static NodeInst newNodeInst(NodeProto np,
                                   java.awt.geom.Rectangle2D rect,
                                   double angle,
                                   Cell parent)

modNodeInst

public static void modNodeInst(NodeInst ni,
                               double dx,
                               double dy,
                               double dw,
                               double dh,
                               boolean mirrorAboutYAxis,
                               boolean mirrorAboutXAxis,
                               double dAngle)
Modify the position of a NodeInst. The size and position of a NodeInst in the coordinate space of its parent cell is determined by 5 parameters: x, y, width, height, and angle, as described in the JavaDoc for newNodeInst. The modNodeInst method modifies those parameters.

The modNodeInst method differs from NodeInst.modifyInstance in the following ways:

Parameters:
ni - the NodeInst to modify
dx - the amount by which to change the x-coordinate of the NodeInst's position
dy - the amount by which to change the y-coordinate of the NodeInst's position
dw - the amount by which to change to absolute value of the NodeInst's width
dh - the amount by which to change to absolute value of the NodeInst's height.
mirrorAboutYAxis - if true then toggle the mirroring of the NodeInst about the y-axis
mirrorAboutXAxis - if true then toggle the mirroring of the NodeInst about the x-axis
dAngle - the amount by which to change the NodeInst's angle

getPosition

public static java.awt.geom.Point2D getPosition(NodeInst ni)
Get the position of a NodeInst. In the coordinate space of the NodeInst's parent, get the x and y-coordinates of the origin of the NodeInst's NodeProto.

Parameters:
ni - the NodeInst we want the position of
Returns:
the x and y-coordinates of the origin of the NodeInst's NodeProto

newArcInst

public static ArcInst newArcInst(ArcProto ap,
                                 double width,
                                 PortInst head,
                                 double hX,
                                 double hY,
                                 PortInst tail,
                                 double tX,
                                 double tY)
Create a new ArcInst. This differs from ArcInst.newInstance in that the "width-offset" is added to the width parameter. The result is an ArcInst that the GUI reports is width wide.

Parameters:
ap - the ArcProto to instantiate
width - the desired width of the ArcInst
head - the head PortInst
hX - the x-coordinate of the head PortInst
hY - the y-coordinate of the head PortInst
tail - the tail PortInst
tX - the x-coordinate of the tail PortInst
tY - the y-coordinate of the tail PortInst
Returns:
the new ArcInst

newArcInst

public static ArcInst newArcInst(ArcProto ap,
                                 double width,
                                 PortInst head,
                                 PortInst tail)
Create a new ArcInst. This differs from ArcInst.newInstance in that the "width-offset" is added to the width parameter. The result is an ArcInst that the GUI reports is width wide.

Connect the new ArcInst to the centers of the PortInsts. If the centers don't share an X or y-coordinate then connect the head and the tail using two ArcInsts. The ArcInst attached to the head is horizontal and the ArcInst attached to the tail is vertical.

Parameters:
ap - the head PortInst
width - the desired width of the ArcInst
head - the head ArcInst
tail - the tail ArcInst
Returns:
the ArcInst connected to the tail.

newExport

public static Export newExport(Cell cell,
                               java.lang.String name,
                               PortCharacteristic role,
                               ArcProto ap,
                               double w,
                               double x,
                               double y)
Create an export for a particular layer.

At the coordinates (x, y) create a NodeInst of a layer-pin for the layer ap. Export that layer-pin's PortInst.

Attach an ArcInst of ArcProto ap to the layer-pin. The ArcInst is useful because Electric uses the widest ArcInst on a PortInst as a hint for the width to use for all future arcs. Because Electric doesn't use the size of layer-pins as width hints, the layer-pin is created in it's default size.

newExport seems very specialized, but it's nearly the only one I use when generating layout.

Parameters:
cell - the Cell to which to add the Export.
name - the name of the Export.
role - the Export's type.
ap - the ArcProto indicating the layer on which to create the Export.
w - width of the ArcInst serving as a hint.
x - the x-coordinate of the layer pin.
y - the y-coordinate of the layer pin.

roundBounds

public static java.awt.geom.Rectangle2D roundBounds(java.awt.geom.Rectangle2D r)

getBounds

public static java.awt.geom.Rectangle2D getBounds(NodeInst node)
Get the essential or regular bounds. If NodeInst node has an Essential Bounds then return it. Otherwise return the regular bounds.

Parameters:
node - the NodeInst.
Returns:
the Rectangle2D representing the bounds.

getBounds

public static java.awt.geom.Rectangle2D getBounds(Cell c)
Get the essential or regular bounds. If Cell c has an Essential Bounds then return it. Otherwise return the regular bounds.

Parameters:
c - the Cell.
Returns:
the Rectangle2D representing the bounds.

abutLeft

public static void abutLeft(NodeInst node,
                            double leftX,
                            double originY)
Move NodeInst so it's left edge is at leftX and the y-coordinate of it's origin is at originY. Don't alter the NodeInst's scale or rotation.

Parameters:
node - the NodeInst
leftX - desired x-coordinate of left edge of node.
originY - desired y-coordinate of node's origin

abutLeftRight

public static void abutLeftRight(double leftX,
                                 double originY,
                                 java.util.Collection<NodeInst> nodeInsts)
Abut an array of NodeInsts left to right. Move the 0th NodeInst so it's left edge is at leftX and it the y-coordinate of its origin is at originY. Abut the remaining nodes left to right. Don't alter any NodeInst's scale or rotation.

Parameters:
leftX - desired x-coordinate of left edge of 0th NodeInst.
originY - desired y-coordinate of all NodeInst origins
nodeInsts - the ArrayList of NodeInsts.

abutLeftRight

public static void abutLeftRight(NodeInst leftNode,
                                 NodeInst rightNode)
Abut two NodeInsts left to right. Move rightNode so its left edge coincides with leftNode's right edge, and the y-coordinate of rightNode's is equal to the y-coordinate of leftNode's origin. Don't move leftNode. Don't alter any node's scale or rotation.

Parameters:
leftNode - the NodeInst that doesn't move.
rightNode - the NodeInst that is moved to butt against leftNode.

abutLeftRight

public static void abutLeftRight(java.util.Collection<NodeInst> nodeInsts)
Abut an array of NodeInsts left to right. Don't move the 0th node. Abut remaining nodes left to right. Don't alter any NodeInst's scale or rotation.

Parameters:
nodeInsts - the ArrayList of NodeInsts

abutBottom

public static void abutBottom(NodeInst node,
                              double originX,
                              double botY)
Move a NodeInst so it's bottom edge is at botY.

Place node's origin at originX. Don't alter node's scale or rotation.

Parameters:
node - the NodeInst to move
originX - desired x-coordinate of NodeInst's origin
botY - desired y-coordinate of bottom edge of NodeInst

abutBottomTop

public static void abutBottomTop(NodeInst bottomNode,
                                 double space,
                                 NodeInst topNode)
Abut two NodeInsts bottom to top. Move topNode so its bottom edge coincides with bottomNode's top edge, and the y-coordinate of topNode's origin is equal to the y-coorinate of bottomNode's origin. Don't move bottomNode. Don't alter any node's scale or rotation.


abutBottomTop

public static void abutBottomTop(double originX,
                                 double botY,
                                 java.util.Collection<NodeInst> nodeInsts,
                                 double space)
Abut a list of NodeInsts bottom to top. Move 0th NodeInst so it's bottom edge is at botY and it's origin has the x-coordinate, originX. Abut remaining nodes bottom to top. Don't alter any NodeInst's scale or rotation.

Parameters:
originX - desired x-coordinate of all NodeInst reference points. Lambda units.
botY - desired y-coordinate of bottom edge of first NodeInst.
nodeInsts - Collection of NodeInsts to abut.

abutBottomTop

public static void abutBottomTop(java.util.Collection<NodeInst> nodeInsts,
                                 double space)
Abut a list of NodeInsts bottom to top. Don't alter position of 0th node. Abut the remaining nodes bottom to top. Don't alter any NodeInst's scale or rotation.

Parameters:
nodeInsts - the list of NodeInsts to abut.

alignCorners

public static void alignCorners(NodeInst niFixed,
                                LayoutLib.Corner cnrFixed,
                                NodeInst niMove,
                                LayoutLib.Corner cnrMove,
                                double offsetX,
                                double offsetY)

getBounds

public static java.awt.geom.Rectangle2D getBounds(Cell cell,
                                                  Layer.Function function)
Get the bounding box for the layer in the Cell. Note this does not include geometry from sub-cells.

Parameters:
cell - the cell to examine
function - the layer's function
Returns:
a bounding box around all instances of the layer in the cell