com.sun.electric.database.variable
Class ElectricObject

java.lang.Object
  extended by com.sun.electric.database.variable.ElectricObject
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Cell, Export, Geometric, Library, PortInst

public abstract class ElectricObject
extends java.lang.Object
implements java.io.Serializable

This class is the base class of all Electric objects that can be extended with "Variables".

This class should be thread-safe.

See Also:
Serialized Form

Constructor Summary
protected ElectricObject()
          The protected constructor.
 
Method Summary
 int addDisplayableVariables(java.awt.geom.Rectangle2D rect, Poly[] polys, int start, EditWindow0 wnd, boolean multipleStrings)
          Method to add all displayable Variables on this Electric object to an array of Poly objects.
abstract  void addVar(Variable var)
          Method to add a Variable on this ElectricObject.
protected  void check()
          Method to check invariants in this ElectricObject.
 void checkChanging()
          Routing to check whether changing of this cell allowed or not.
 void checkExamine()
          Method to make sure that this object can be examined.
 void checkUndoing()
          Routing to check whether undoing of this cell allowed or not.
 Poly computeTextPoly(EditWindow0 wnd, Variable.Key varKey)
          Method to compute a Poly that describes text.
 void copyTextDescriptorFrom(ElectricObject other, Variable.Key varKey)
          Method to copy text descriptor from another ElectricObject to this ElectricObject.
 void copyVarsFrom(ElectricObject other)
          Method to copy all variables from another ElectricObject to this ElectricObject.
abstract  void delVar(Variable.Key key)
          Method to delete a Variable from this ElectricObject.
 Artwork getArtwork()
          Returns Artwork technology in this database
 CodeExpression.Code getCode(Variable.Key varKey)
          Returns the Code on this ElectricObject selected by variable key.
abstract  ImmutableElectricObject getD()
          Returns persistent data of this ElectricObject with Variables.
abstract  EDatabase getDatabase()
          Returns database to which this ElectricObject belongs.
 Poly[] getDisplayableVariables(java.awt.geom.Rectangle2D rect, EditWindow0 wnd, boolean multipleStrings)
          Method to get all displayable Variables on this ElectricObject and its PortInsts to an array of Poly objects.
 EditingPreferences getEditingPreferences()
          Returns editing preferences for the database of this ElectricObject in current Thread
 Generic getGeneric()
          Returns Generic technology in this database
 void getInfo()
          Method to write a description of this ElectricObject (lists all Variables).
 MutableTextDescriptor getMutableTextDescriptor(Variable.Key varKey)
          Returns the TextDescriptor on this ElectricObject selected by variable key.
 int getNumVariables()
          Method to return the number of Variables on this ElectricObject.
 Variable getParameterOrVariable(java.lang.String name)
          Method to return the Parameter or Variable on this ElectricObject with a given name.
 Variable getParameterOrVariable(Variable.Key key)
          Method to return the Parameter or Variable on this ElectricObject with a given key.
 java.util.Iterator<Variable> getParametersAndVariables()
          Method to return an Iterator over all Parameters and Variables on this ElectricObject.
 Poly[] getPolyList(Variable var, double cX, double cY, EditWindow0 wnd, boolean multipleStrings)
          Method to create an array of Poly objects that describes a displayable Variable on this Electric object.
 Schematics getSchematics()
          Returns Schematics technology in this database
 Technology getTech(TechId techId)
          Get Technology by TechId TechId must belong to same IdManager as TechPool
 TechPool getTechPool()
          Returns TechPool of this database
 java.awt.geom.Rectangle2D getTextBounds(EditWindow0 wnd)
          Method to return the bounds of this ElectricObject in an EditWindow.
 TextDescriptor getTextDescriptor(Variable.Key varKey)
          Returns the TextDescriptor on this ElectricObject selected by variable key.
 Variable getVar(java.lang.String name)
          Method to return the Variable on this ElectricObject with a given name.
 Variable getVar(Variable.Key key)
          Method to return the Variable on this ElectricObject with a given key.
 java.util.Iterator<Variable> getVariables()
          Method to return an Iterator over all Variables on this ElectricObject.
<T> T
getVarValue(Variable.Key key, java.lang.Class<T> type)
          Method to return the value of the the Variable on this ElectricObject with a given key and type.
<T> T
getVarValue(Variable.Key key, java.lang.Class<T> type, T defaultValue)
          Method to return the value of the the Variable on this ElectricObject with a given key and type.
protected  boolean isDatabaseObject()
          Method which indicates that this object is in database.
 boolean isDeprecatedVariable(Variable.Key key)
          Method to determine whether a Variable key on this object is deprecated.
abstract  boolean isLinked()
          Returns true if object is linked into database
 boolean isParam(Variable.Key varKey)
          Method to return true if the Variable on this ElectricObject with given key is a parameter.
 Variable newDisplayVar(Variable.Key key, java.lang.Object value)
          Method to create a displayable Variable on this ElectricObject with the specified values.
 Variable newVar(java.lang.String name, java.lang.Object value)
          Method to create a non-displayable Variable on this ElectricObject with the specified values.
 Variable newVar(Variable.Key key, java.lang.Object value)
          Method to create a non-displayable Variable on this ElectricObject with the specified values.
 Variable newVar(Variable.Key key, java.lang.Object value, boolean display)
          Method to create a Variable on this ElectricObject with the specified values.
 Variable newVar(Variable.Key key, java.lang.Object value, TextDescriptor td)
          Method to create a Variable on this ElectricObject with the specified values.
 int numDisplayableVariables(boolean multipleStrings)
          Method to return the number of displayable Variables on this ElectricObject.
 Variable renameVar(java.lang.String name, java.lang.String newName)
          Rename a Variable.
 Variable renameVar(Variable.Key key, java.lang.String newName)
          Rename a Variable.
 void setOff(Variable.Key varKey, double xd, double yd)
          Method to set the X and Y offsets of the text in the TextDescriptor selected by key of variable or special key.
 void setTextDescriptor(Variable.Key varKey, TextDescriptor td)
          Updates the TextDescriptor on this ElectricObject selected by varKey.
 java.lang.String toString()
          Returns a printable version of this ElectricObject.
static java.lang.String uniqueObjectName(java.lang.String name, Cell cell, java.lang.Class cls, boolean leaveIndexValues)
          Method to return a unique object name in a Cell.
static java.lang.String uniqueObjectName(java.lang.String name, Cell cell, java.lang.Class cls, java.util.Set already, java.util.Map<java.lang.String,GenMath.MutableInteger> nextPlainIndex, boolean leaveIndexValues)
          Method to return a unique object name in a Cell.
 Variable updateVar(Variable.Key key, java.lang.Object value)
          Method to update a Variable on this ElectricObject with the specified values.
 Variable updateVarCode(Variable.Key key, CodeExpression.Code code)
          Method to update a Variable on this ElectricObject with the specified code.
 Variable updateVarText(Variable.Key key, java.lang.String text)
          Method to update a text Variable on this ElectricObject with the specified values.
 Cell whichCell()
          Method to determine the appropriate Cell associated with this ElectricObject.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ElectricObject

protected ElectricObject()
The protected constructor.

Method Detail

getD

public abstract ImmutableElectricObject getD()
Returns persistent data of this ElectricObject with Variables.

Returns:
persistent data of this ElectricObject.

isLinked

public abstract boolean isLinked()
Returns true if object is linked into database


getVarValue

public <T> T getVarValue(Variable.Key key,
                         java.lang.Class<T> type)
Method to return the value of the the Variable on this ElectricObject with a given key and type.

Parameters:
key - the key of the Variable.
type - the required type of the Variable.
Returns:
the value Variable with that key and type, or null if there is no such Variable
Throws:
java.lang.NullPointerException - if key is null

getVarValue

public <T> T getVarValue(Variable.Key key,
                         java.lang.Class<T> type,
                         T defaultValue)
Method to return the value of the the Variable on this ElectricObject with a given key and type.

Parameters:
key - the key of the Variable.
type - the required type of the Variable.
defaultValue - default value
Returns:
the value Variable with that key and type, or defaultValue if there is no such Variable
Throws:
java.lang.NullPointerException - if key or type is null

getVar

public Variable getVar(java.lang.String name)
Method to return the Variable on this ElectricObject with a given name.

Parameters:
name - the name of the Variable.
Returns:
the Variable with that name, or null if there is no such Variable.
Throws:
java.lang.NullPointerException - if name is null

getVar

public Variable getVar(Variable.Key key)
Method to return the Variable on this ElectricObject with a given key.

Parameters:
key - the key of the Variable.
Returns:
the Variable with that key, or null if there is no such Variable.
Throws:
java.lang.NullPointerException - if key is null

getParameterOrVariable

public Variable getParameterOrVariable(java.lang.String name)
Method to return the Parameter or Variable on this ElectricObject with a given name.

Parameters:
name - the name of the Parameter or Variable.
Returns:
the Parameter or Variable with that key, or null if there is no such Parameter or Variable Variable.
Throws:
java.lang.NullPointerException - if key is null

getParameterOrVariable

public Variable getParameterOrVariable(Variable.Key key)
Method to return the Parameter or Variable on this ElectricObject with a given key.

Parameters:
key - the key of the Parameter or Variable.
Returns:
the Parameter or Variable with that key, or null if there is no such Parameter or Variable Variable.
Throws:
java.lang.NullPointerException - if key is null

getTextDescriptor

public TextDescriptor getTextDescriptor(Variable.Key varKey)
Returns the TextDescriptor on this ElectricObject selected by variable key. This key may be a key of variable on this ElectricObject or one of the special keys: NodeInst.NODE_NAME NodeInst.NODE_PROTO ArcInst.ARC_NAME Export.EXPORT_NAME The TextDescriptor gives information for displaying the Variable.

Parameters:
varKey - key of variable or special key.
Returns:
the TextDescriptor on this ElectricObject.

getMutableTextDescriptor

public MutableTextDescriptor getMutableTextDescriptor(Variable.Key varKey)
Returns the TextDescriptor on this ElectricObject selected by variable key. This key may be a key of variable on this ElectricObject or one of the special keys: NodeInst.NODE_NAME NodeInst.NODE_PROTO ArcInst.ARC_NAME Export.EXPORT_NAME The TextDescriptor gives information for displaying the Variable.

Parameters:
varKey - key of variable or special key.
Returns:
the TextDescriptor on this ElectricObject.

getCode

public CodeExpression.Code getCode(Variable.Key varKey)
Returns the Code on this ElectricObject selected by variable key. This key may be a key of variable on this ElectricObject or one of the special keys: NodeInst.NODE_NAME NodeInst.NODE_PROTO ArcInst.ARC_NAME Export.EXPORT_NAME The Code gives information for displaying the Variable.

Parameters:
varKey - key of variable or special key.
Returns:
the Code on this ElectricObject.

isParam

public boolean isParam(Variable.Key varKey)
Method to return true if the Variable on this ElectricObject with given key is a parameter. Parameters are those Variables that have values on instances which are passed down the hierarchy into the contents. Parameters can only exist on Cell and NodeInst objects.

Parameters:
varKey - key to test
Returns:
true if the Variable with given key is a parameter.

numDisplayableVariables

public int numDisplayableVariables(boolean multipleStrings)
Method to return the number of displayable Variables on this ElectricObject. A displayable Variable is one that will be shown with its object. Displayable Variables can only sensibly exist on NodeInst and ArcInst objects.

Returns:
the number of displayable Variables on this ElectricObject.

addDisplayableVariables

public int addDisplayableVariables(java.awt.geom.Rectangle2D rect,
                                   Poly[] polys,
                                   int start,
                                   EditWindow0 wnd,
                                   boolean multipleStrings)
Method to add all displayable Variables on this Electric object to an array of Poly objects.

Parameters:
rect - a rectangle describing the bounds of the object on which the Variables will be displayed.
polys - an array of Poly objects that will be filled with the displayable Variables.
start - the starting index in the array of Poly objects to fill with displayable Variables.
wnd - window in which the Variables will be displayed.
multipleStrings - true to break multiline text into multiple Polys.
Returns:
the number of Polys that were added.

getDisplayableVariables

public Poly[] getDisplayableVariables(java.awt.geom.Rectangle2D rect,
                                      EditWindow0 wnd,
                                      boolean multipleStrings)
Method to get all displayable Variables on this ElectricObject and its PortInsts to an array of Poly objects.

Parameters:
rect - a rectangle describing the bounds of the object on which the Variables will be displayed.
wnd - window in which the Variables will be displayed.
multipleStrings - true to break multiline text into multiple Polys.
Returns:
an array of Poly objects with displayable variables.

computeTextPoly

public Poly computeTextPoly(EditWindow0 wnd,
                            Variable.Key varKey)
Method to compute a Poly that describes text. The text can be described by an ElectricObject (Exports or cell instance names). The text can be described by a node or arc name. The text can be described by a variable on an ElectricObject.

Parameters:
wnd - the EditWindow0 in which the text will be drawn.
varKey - the Variable.Key on the ElectricObject (may be null).
Returns:
a Poly that covers the text completely. Even though the Poly is scaled for a particular EditWindow, its coordinates are in object space, not screen space.

getTextBounds

public java.awt.geom.Rectangle2D getTextBounds(EditWindow0 wnd)
Method to return the bounds of this ElectricObject in an EditWindow.

Parameters:
wnd - the EditWindow0 in which the object is being displayed.
Returns:
the bounds of the text (does not include the bounds of the object).

getPolyList

public Poly[] getPolyList(Variable var,
                          double cX,
                          double cY,
                          EditWindow0 wnd,
                          boolean multipleStrings)
Method to create an array of Poly objects that describes a displayable Variable on this Electric object.

Parameters:
var - the Variable on this ElectricObject to describe.
cX - the center X coordinate of the ElectricObject.
cY - the center Y coordinate of the ElectricObject.
wnd - window in which the Variable will be displayed.
multipleStrings - true to break multiline text into multiple Polys.
Returns:
an array of Poly objects that describe the Variable. May return zero length array.

newVar

public Variable newVar(java.lang.String name,
                       java.lang.Object value)
Method to create a non-displayable Variable on this ElectricObject with the specified values.

Parameters:
name - the name of the Variable.
value - the object to store in the Variable.
Returns:
the Variable that has been created.

newDisplayVar

public Variable newDisplayVar(Variable.Key key,
                              java.lang.Object value)
Method to create a displayable Variable on this ElectricObject with the specified values.

Parameters:
key - the key of the Variable.
value - the object to store in the Variable.
Returns:
the Variable that has been created.

newVar

public Variable newVar(Variable.Key key,
                       java.lang.Object value)
Method to create a non-displayable Variable on this ElectricObject with the specified values. Notify to observers as well.

Parameters:
key - the key of the Variable.
value - the object to store in the Variable.
Returns:
the Variable that has been created.

newVar

public Variable newVar(Variable.Key key,
                       java.lang.Object value,
                       boolean display)
Method to create a Variable on this ElectricObject with the specified values.

Parameters:
key - the key of the Variable.
value - the object to store in the Variable.
display - true if the Variale is displayable.
Returns:
the Variable that has been created.

newVar

public Variable newVar(Variable.Key key,
                       java.lang.Object value,
                       TextDescriptor td)
Method to create a Variable on this ElectricObject with the specified values.

Parameters:
key - the key of the Variable.
value - the object to store in the Variable.
td - text descriptor of the Variable
Returns:
the Variable that has been created.

addVar

public abstract void addVar(Variable var)
Method to add a Variable on this ElectricObject. It may add a repaired copy of this Variable in some cases.

Parameters:
var - Variable to add.

updateVar

public Variable updateVar(Variable.Key key,
                          java.lang.Object value)
Method to update a Variable on this ElectricObject with the specified values. If the Variable already exists, only the value is changed; the displayable attributes are preserved.

Parameters:
key - the key of the Variable.
value - the object to store in the Variable.
Returns:
the Variable that has been updated.

updateVarText

public Variable updateVarText(Variable.Key key,
                              java.lang.String text)
Method to update a text Variable on this ElectricObject with the specified values. If the Variable already exists, only the value is changed; the displayable attributes and Code are preserved.

Parameters:
key - the key of the Variable.
text - the text to store in the Variable.
Returns:
the Variable that has been updated.

updateVarCode

public Variable updateVarCode(Variable.Key key,
                              CodeExpression.Code code)
Method to update a Variable on this ElectricObject with the specified code. If the Variable already exists, only the code is changed; the displayable attributes and value are preserved.

Parameters:
key - the key of the Variable.
code - the new code of the Variable.
Returns:
the Variable that has been updated.

setTextDescriptor

public void setTextDescriptor(Variable.Key varKey,
                              TextDescriptor td)
Updates the TextDescriptor on this ElectricObject selected by varKey. The varKey may be a key of variable on this ElectricObject or one of the special keys: NodeInst.NODE_NAME NodeInst.NODE_PROTO ArcInst.ARC_NAME Export.EXPORT_NAME If varKey doesn't select any text descriptor, no action is performed. The TextDescriptor gives information for displaying the Variable.

Parameters:
varKey - key of variable or special key.
td - new value TextDescriptor

setOff

public void setOff(Variable.Key varKey,
                   double xd,
                   double yd)
Method to set the X and Y offsets of the text in the TextDescriptor selected by key of variable or special key. The values are scaled by 4, so a value of 3 indicates a shift of 0.75 and a value of 4 shifts by 1.

Parameters:
varKey - key of variable or special key.
xd - the X offset of the text in the TextDescriptor.
yd - the Y offset of the text in the TextDescriptor.
See Also:
setTextDescriptor(com.sun.electric.database.variable.Variable.Key,com.sun.electric.database.variable.TextDescriptor), Variable.withOff(double,double)

copyTextDescriptorFrom

public void copyTextDescriptorFrom(ElectricObject other,
                                   Variable.Key varKey)
Method to copy text descriptor from another ElectricObject to this ElectricObject.

Parameters:
other - the other ElectricObject from which to copy Variables.
varKey - selector of textdescriptor

renameVar

public Variable renameVar(java.lang.String name,
                          java.lang.String newName)
Rename a Variable. Note that this creates a new variable of the new name and copies all values from the old variable, and then deletes the old variable.

Parameters:
name - the name of the var to rename
newName - the new name of the variable
Returns:
the new renamed variable

renameVar

public Variable renameVar(Variable.Key key,
                          java.lang.String newName)
Rename a Variable. Note that this creates a new variable of the new name and copies all values from the old variable, and then deletes the old variable.

Parameters:
key - the name key of the var to rename
newName - the new name of the variable
Returns:
the new renamed variable, or null on error (no action taken)

delVar

public abstract void delVar(Variable.Key key)
Method to delete a Variable from this ElectricObject.

Parameters:
key - the key of the Variable to delete.

copyVarsFrom

public void copyVarsFrom(ElectricObject other)
Method to copy all variables from another ElectricObject to this ElectricObject.

Parameters:
other - the other ElectricObject from which to copy Variables.

uniqueObjectName

public static java.lang.String uniqueObjectName(java.lang.String name,
                                                Cell cell,
                                                java.lang.Class cls,
                                                boolean leaveIndexValues)
Method to return a unique object name in a Cell.

Parameters:
name - the original name that is not unique.
cell - the Cell in which this name resides.
cls - the class of the object on which this name resides.
leaveIndexValues - true to leave the index values untouched (i.e. "m[17]" will become "m_1[17]" instead of "m[18]").
Returns:
a unique name for that class in that Cell.

uniqueObjectName

public static java.lang.String uniqueObjectName(java.lang.String name,
                                                Cell cell,
                                                java.lang.Class cls,
                                                java.util.Set already,
                                                java.util.Map<java.lang.String,GenMath.MutableInteger> nextPlainIndex,
                                                boolean leaveIndexValues)
Method to return a unique object name in a Cell.

Parameters:
name - the original name that is not unique.
cell - the Cell in which this name resides.
cls - the class of the object on which this name resides.
already - a Set of names already in use (lower case).
leaveIndexValues - true to leave the index values untouches (i.e. "m[17]" will become "m_1[17]" instead of "m[18]").
Returns:
a unique name for that class in that Cell.

isDeprecatedVariable

public boolean isDeprecatedVariable(Variable.Key key)
Method to determine whether a Variable key on this object is deprecated. Deprecated Variable keys are those that were used in old versions of Electric, but are no longer valid.

Parameters:
key - the key of the Variable.
Returns:
true if the Variable key is deprecated.

getVariables

public java.util.Iterator<Variable> getVariables()
Method to return an Iterator over all Variables on this ElectricObject.

Returns:
an Iterator over all Variables on this ElectricObject.

getNumVariables

public int getNumVariables()
Method to return the number of Variables on this ElectricObject.

Returns:
the number of Variables on this ElectricObject.

getParametersAndVariables

public java.util.Iterator<Variable> getParametersAndVariables()
Method to return an Iterator over all Parameters and Variables on this ElectricObject.

Returns:
an Iterator over all Parameters and Variables on this ElectricObject.

checkChanging

public void checkChanging()
Routing to check whether changing of this cell allowed or not. By default checks whole database change. Overriden in subclasses.


checkUndoing

public void checkUndoing()
Routing to check whether undoing of this cell allowed or not. By default checks whole database undo. Overriden in subclasses.


checkExamine

public void checkExamine()
Method to make sure that this object can be examined. Ensures that an examine job is running.


getDatabase

public abstract EDatabase getDatabase()
Returns database to which this ElectricObject belongs. Some objects are not in database, for example Geometrics in PaletteFrame. Method returns null for non-database objects.

Returns:
database to which this ElectricObject belongs.

getTechPool

public TechPool getTechPool()
Returns TechPool of this database


getEditingPreferences

public EditingPreferences getEditingPreferences()
Returns editing preferences for the database of this ElectricObject in current Thread

Returns:
editing preferences

getTech

public Technology getTech(TechId techId)
Get Technology by TechId TechId must belong to same IdManager as TechPool

Parameters:
techId - TechId to find
Returns:
Technology b giben TechId or null
Throws:
java.lang.IllegalArgumentException - of TechId is not from this IdManager

getArtwork

public Artwork getArtwork()
Returns Artwork technology in this database


getGeneric

public Generic getGeneric()
Returns Generic technology in this database


getSchematics

public Schematics getSchematics()
Returns Schematics technology in this database


isDatabaseObject

protected boolean isDatabaseObject()
Method which indicates that this object is in database. Some objects are not in database, for example Geometrics in PaletteFrame.

Returns:
true if this object is in database, false if it is not a database object, or if it is a dummy database object (considered not to be in the database).

whichCell

public Cell whichCell()
Method to determine the appropriate Cell associated with this ElectricObject.

Returns:
the appropriate Cell associated with this ElectricObject. Returns null if no Cell can be found.

getInfo

public void getInfo()
Method to write a description of this ElectricObject (lists all Variables). Displays the description in the Messages Window.


toString

public java.lang.String toString()
Returns a printable version of this ElectricObject.

Overrides:
toString in class java.lang.Object
Returns:
a printable version of this ElectricObject.

check

protected void check()
Method to check invariants in this ElectricObject.

Throws:
java.lang.AssertionError - if invariants are not valid