de.fhstralsund.vinets.geometry
Class NetElementGeometry

java.lang.Object
  extended by de.fhstralsund.vinets.geometry.NetElementGeometry
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class NetElementGeometry
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Models the geometric aspects of a NetElement as positon and size. These values are manipulated usually by layout algorithms.

The values apply to a virtual coordinate system with coordinates ranging from 0 to MAX_X and MAX_Y for x- and y-values, respectively. Accordingly, all changes of the geometry are guaranteed to meet these constraints.

Coordinates are considered as equal if they differ by EPS or less.

Usually, the top level graph in the VinetS editor has width and height equal to MAX_X and MAX_Y, respectively. Any other NetElement has coordinates in the local graph space of its host and thus smaller values (since it is contained geometrically in the host.) But, if a Block has an inner Graph, its own inner graph space (which is used as coordinate system for the contained NetElements) has again dimension MAX_X times MAX_Y.

All methods that set coordinates guarantee that the values of all corners are always on the rectangular grid defined by the host of this NetElement if grid snapping is on for the host.

See Also:
Serialized Form

Field Summary
static double EPS
          The precision.
static double MAX_X
          The maximum x-coordinate.
static double MAX_Y
          The maximum y-coordinate.
protected  double x
          The x-coordinate of the left upper corner of the bounding box of this NetElement in the relative coordinate system of its host.
protected  double y
          The y-coordinate of the left upper corner of the bounding box of this NetElement in the relative coordinate system of its host.
 
Constructor Summary
NetElementGeometry(NetElement owner)
          Constructs a new NetElementGeometry at position (0,0) with width and height being 0 as well.
NetElementGeometry(NetElement owner, boolean ignored)
          Convenience constructor that constructs a new NetElementGeometry at position (0,0) with width=MAX_X and height=MAX_Y.
NetElementGeometry(NetElement owner, double x, double y)
          Constructs a new NetElementGeometry at the given position in the relative coordinate system of the host of this NetElement with width and height being 0.
NetElementGeometry(NetElement owner, double x, double y, double width, double height)
          Constructs a new NetElementGeometry at the given position and size in the relative coordinate system of the host of this NetElement.
NetElementGeometry(NetElement owner, java.awt.geom.Point2D origin)
          Constructs a new NetElementGeometry at the given position in the relative coordinate system of the host of this NetElement with width and height being 0.
NetElementGeometry(NetElement owner, java.awt.geom.Point2D origin, java.awt.geom.Dimension2D size)
          Constructs a new NetElementGeometry at the given position and size in the relative coordinate system of the host of this NetElement.
 
Method Summary
 java.lang.Object clone()
          Creates and returns a copy of this NetElementGeometry.
static boolean equals(double one, double two)
          Compares two double values for equality upto EPS.
 boolean equals(java.lang.Object obj)
          Indicates whether some other Object is equal to this NetElementGeometry.
 double getGlobalHeight()
          Returns the height of this NetElementGeometry in the global coordinate system of the host of its owner.
 java.awt.geom.Point2D getGlobalPosition()
          Returns the position of this NetElementGeometry in the global coordinate system of the host of its owner (that is, the graph space coordinates for an inner block).
 java.awt.geom.Dimension2D getGlobalSize()
          Returns the size of this NetElementGeometry in the global coordinate system of the host of its owner.
 double getGlobalWidth()
          Returns the width of this NetElementGeometry in the global coordinate system of the host of its owner.
 double getGlobalX()
          Returns the x-coordinate of this NetElementGeometry in the global coordinate system of the host of its owner.
 double getGlobalY()
          Returns the y-coordinate of this NetElementGeometry in the global coordinate system of the host of its owner.
 double getHeight()
          Returns the height in y-direction.
 NetElement getOwner()
          Getter for property owner.
 java.awt.geom.Point2D getPosition()
          Returns the coordinates.
 java.awt.geom.Dimension2D getSize()
          Returns the size.
 java.awt.geom.AffineTransform getToGlobalTransform()
          The returned transform matrix can be used to transform the local coordinates of any point contained in this NetElementGeometry into the coordinates system of the host of its owner.
 java.awt.geom.AffineTransform getToLocalTransform()
          The returned transform matrix can be used to transform global graph coordinates into local coordinates of the owner of this geometry.
 double getWidth()
          Returns the width in x-direction.
 double getX()
          Returns the x-coordinate of the left upper corner.
 double getXGrid()
          Getter for property xGrid.
 double getY()
          Returns the y-coordinate of the left upper corner.
 double getYGrid()
          Getter for property yGrid.
 int hashCode()
          Returns a hash code value for this NetElementGeometry.
 boolean isGridSnappingOn()
          Getter for property gridSnappingOn.
 void setGridSnappingOn(boolean gridSnappingOn)
          Setter for property gridSnappingOn.
 void setHeight(double value)
          Sets the height.
 void setOwner(NetElement el)
          Restricted setter for property owner.
 void setPosition(java.awt.geom.Point2D pos)
          Sets the position.
 void setSize(java.awt.geom.Dimension2D size)
          Sets the size.
 void setSize(double width, double height)
          Sets the size.
 void setWidth(double value)
          Sets the width.
 void setX(double value)
          Sets the x-coordinate.
 void setXGrid(double xGrid)
          Setter for property xGrid.
 void setY(double value)
          Sets the y-coordinate.
 void setYGrid(double yGrid)
          Setter for property yGrid.
 java.lang.String toString()
          Returns a String representation of the NetElementGeometry.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EPS

public static final double EPS
The precision.

See Also:
Constant Field Values

MAX_X

public static final double MAX_X
The maximum x-coordinate.

See Also:
Constant Field Values

MAX_Y

public static final double MAX_Y
The maximum y-coordinate.

See Also:
Constant Field Values

x

protected double x
The x-coordinate of the left upper corner of the bounding box of this NetElement in the relative coordinate system of its host. x should always be between 0 and MAX_X.


y

protected double y
The y-coordinate of the left upper corner of the bounding box of this NetElement in the relative coordinate system of its host. y should always be between 0 and MAX_Y.

Constructor Detail

NetElementGeometry

public NetElementGeometry(NetElement owner,
                          double x,
                          double y)
Constructs a new NetElementGeometry at the given position in the relative coordinate system of the host of this NetElement with width and height being 0.

Parameters:
owner - the NetElement to which this geometry belongs.
x - the x-coordinate of the left upper corner.
y - the y-coordinate of the left upper corner.

NetElementGeometry

public NetElementGeometry(NetElement owner,
                          double x,
                          double y,
                          double width,
                          double height)
Constructs a new NetElementGeometry at the given position and size in the relative coordinate system of the host of this NetElement.

Parameters:
owner - the NetElement to which this geometry belongs.
x - the x-coordinate of the left upper corner.
y - the y-coordinate of the left upper corner.
width - the width of the bounding box in x-direction.
height - the height of the bounding box in y-direction.

NetElementGeometry

public NetElementGeometry(NetElement owner)
Constructs a new NetElementGeometry at position (0,0) with width and height being 0 as well.

Parameters:
owner - the NetElement to which this geometry belongs.

NetElementGeometry

public NetElementGeometry(NetElement owner,
                          boolean ignored)
Convenience constructor that constructs a new NetElementGeometry at position (0,0) with width=MAX_X and height=MAX_Y. Usually, used for the top level graph.

Parameters:
owner - the NetElement to which this geometry belongs.
ignored - dummy to identify this special constructor.

NetElementGeometry

public NetElementGeometry(NetElement owner,
                          java.awt.geom.Point2D origin)
Constructs a new NetElementGeometry at the given position in the relative coordinate system of the host of this NetElement with width and height being 0.

Parameters:
owner - the NetElement to which this geometry belongs.
origin - the coordinates of the left upper corner.

NetElementGeometry

public NetElementGeometry(NetElement owner,
                          java.awt.geom.Point2D origin,
                          java.awt.geom.Dimension2D size)
Constructs a new NetElementGeometry at the given position and size in the relative coordinate system of the host of this NetElement.

Parameters:
owner - the NetElement to which this geometry belongs.
origin - the coordinates of the left upper corner.
size - the distance of the right bottom corner from the origin.
Method Detail

setX

public void setX(double value)
Sets the x-coordinate. If the value is negative, x is set to zero. If the value plus the element width would be larger than the maximal x-value MAX_X, x is set to MAX_X-width.

Parameters:
value - the x-coordinate.

getX

public double getX()
Returns the x-coordinate of the left upper corner.

Returns:
the x-coordinate value.

setY

public void setY(double value)
Sets the y-coordinate. If the value is negative, y is set to zero. If the value plus the element height would be larger than the maximal y-value MAX_Y, y is set to MAX_Y-height.

Parameters:
value - the y-coordinate.

getY

public double getY()
Returns the y-coordinate of the left upper corner.

Returns:
the y-coordinate.

setPosition

public void setPosition(java.awt.geom.Point2D pos)
Sets the position.

Parameters:
pos - the coordinates of the left upper corner.

getPosition

public java.awt.geom.Point2D getPosition()
Returns the coordinates.

Returns:
the position of the left upper corner.

setWidth

public void setWidth(double value)
Sets the width. If the value is negative, width is set to zero. If the value plus the x-coordinate would be larger than the maximal x-value MAX_X, the width is set to MAX_X-x.

Parameters:
value - the width.

getWidth

public double getWidth()
Returns the width in x-direction.

Returns:
the width.

setHeight

public void setHeight(double value)
Sets the height. If the value is negative, height is set to zero. If the value plus the y-coordinate would be larger than the maximal y-value MAX_Y, the height is set to MAX_Y-y.

Parameters:
value - the height.

getHeight

public double getHeight()
Returns the height in y-direction.

Returns:
the height.

setSize

public void setSize(java.awt.geom.Dimension2D size)
Sets the size.

Parameters:
size - the width in x-direction and the height in y-direction.

getSize

public java.awt.geom.Dimension2D getSize()
Returns the size.

Returns:
the width in x-direction and the height in y-direction.

setSize

public void setSize(double width,
                    double height)
Sets the size.

Parameters:
width - the width in x-direction.
height - the height in y-direction.

getToGlobalTransform

public java.awt.geom.AffineTransform getToGlobalTransform()
The returned transform matrix can be used to transform the local coordinates of any point contained in this NetElementGeometry into the coordinates system of the host of its owner. This is useful to transform the geometry of a Port on the boundary of this NetElementGeometry (which is owned by an inner Node in a HyperGraph) to global coordinates in the Graph coordinate system, as well as for inner NetElements in a hierarchical Block that has this NetElementGeometry.

Returns:
the transform.
Throws:
IllegalStateExcpetion - if the owner does not have a host.

getToLocalTransform

public java.awt.geom.AffineTransform getToLocalTransform()
The returned transform matrix can be used to transform global graph coordinates into local coordinates of the owner of this geometry.

Returns:
the inverse transform of the transform delivered by getToGlobalTransform().
Throws:
IllegalStateExcpetion - if the owner does not have a host.

getGlobalPosition

public java.awt.geom.Point2D getGlobalPosition()
Returns the position of this NetElementGeometry in the global coordinate system of the host of its owner (that is, the graph space coordinates for an inner block).

Returns:
the coordinates in the host coordinate system.
Throws:
IllegalStateExcpetion - if the owner does not have a host.

getGlobalX

public double getGlobalX()
Returns the x-coordinate of this NetElementGeometry in the global coordinate system of the host of its owner.

Returns:
the x-coordinate in the host coordinate system.
Throws:
IllegalStateExcpetion - if the owner does not have a host.

getGlobalY

public double getGlobalY()
Returns the y-coordinate of this NetElementGeometry in the global coordinate system of the host of its owner.

Returns:
the y-coordinate in the host coordinate system.
Throws:
IllegalStateExcpetion - if the owner does not have a host.

getGlobalSize

public java.awt.geom.Dimension2D getGlobalSize()
Returns the size of this NetElementGeometry in the global coordinate system of the host of its owner.

Returns:
the size in the host coordinate system.
Throws:
IllegalStateExcpetion - if the owner does not have a host.

getGlobalWidth

public double getGlobalWidth()
Returns the width of this NetElementGeometry in the global coordinate system of the host of its owner.

Returns:
the width in the host coordinate system.
Throws:
IllegalStateExcpetion - if the owner does not have a host.

getGlobalHeight

public double getGlobalHeight()
Returns the height of this NetElementGeometry in the global coordinate system of the host of its owner.

Returns:
the height in the host coordinate system.
Throws:
IllegalStateExcpetion - if the owner does not have a host.

isGridSnappingOn

public boolean isGridSnappingOn()
Getter for property gridSnappingOn.

Returns:
value of property gridSnappingOn.

setGridSnappingOn

public void setGridSnappingOn(boolean gridSnappingOn)
Setter for property gridSnappingOn.

Parameters:
gridSnappingOn - new value of property gridSnappingOn.

getXGrid

public double getXGrid()
Getter for property xGrid. Delivers the distance between vertical grid lines that are used when grid snapping is on.

Returns:
the distance between vertical grid lines.

setXGrid

public void setXGrid(double xGrid)
Setter for property xGrid. Sets the distance between vertical grid lines to use when grid snapping is on.

Parameters:
xGrid - the distance between vertical grid lines.

getYGrid

public double getYGrid()
Getter for property yGrid. Delivers the distance between horizontal grid lines that are used when grid snapping is on.

Returns:
the distance between horizontal grid lines.

setYGrid

public void setYGrid(double yGrid)
Setter for property yGrid. Sets the distance between horizontal grid lines to use when grid snapping is on.

Parameters:
yGrid - the distance between horizontal grid lines.

getOwner

public NetElement getOwner()
Getter for property owner.

Returns:
the NetElement to which this geometry belongs.

setOwner

public void setOwner(NetElement el)
Restricted setter for property owner. Should be called only after cloning!

Parameters:
el - the new owner.
Throws:
java.lang.UnsupportedOperationException - if the current owner is not null.

clone

public java.lang.Object clone()
Creates and returns a copy of this NetElementGeometry. The owner of the clone is set to null and should be changed by the caller immediatly!

Overrides:
clone in class java.lang.Object
Returns:
a new NetElementGeometry object equal to this one.

toString

public java.lang.String toString()
Returns a String representation of the NetElementGeometry.

Overrides:
toString in class java.lang.Object
Returns:
[(x, y) - (x+width, y+height)]
See Also:
Object.toString()

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other Object is equal to this NetElementGeometry. Coordinates are considered with precision EPS.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the reference Object with which to compare.
Returns:
true if this NetElementGeometry is equal to obj.
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Returns a hash code value for this NetElementGeometry.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value.
See Also:
Object.hashCode()

equals

public static boolean equals(double one,
                             double two)
Compares two double values for equality upto EPS.

Parameters:
one - first value to be compared.
two - second value to be compared.
Returns:
true, if one and two differ by at most EPS.