Chapter 6: Advanced Editing
plug
6-11: Interpretive Languages
plug


Electric has two scripting languages: Java (using the Bean Shell) and Python (using Jython). These languages enable you to load custom code that adds functionality to Electric. Neither of these languages is part of the default Electric distribution. You must add them as "plug ins" (see Section 1-5 for more on plug-ins).

To run Java code, use the Run Java Bean Shell Script... command (in menu Tools / Languages). To run Python code, use the Run Jython Script... command. Note that during execution of these pieces of code, Electric may give warning messages about preferences, which can be ignored.

You can attach code to the Tools / Languages menu by using the Manage Scripts... command. Scripts of code can have mnemonic letters assigned to them (see Section 1-9 for more on mnemonics).
Figure 6.30

Java Code Examples

Here are some example programs in the Java Bean Shell. For more information about accessing the internals of Electric, read the Javadoc in the source code.

import com.sun.electric.database.hierarchy.Cell;
import com.sun.electric.database.topology.NodeInst;
import com.sun.electric.tool.Job;
import java.util.Iterator;

// get the current cell
Cell c = Job.getUserInterface().getCurrentCell();

// find all transistors
for(Iterator it = c.getNodes(); it.hasNext(); ) {
   NodeInst ni = it.next();
   if (ni.getFunction().isTransistor())
      System.out.println("Found transistor: " + ni.describe(false));
}

// find all exports that start with "A"
for(Iterator it = c.getPorts(); it.hasNext(); ) {
   com.sun.electric.database.hierarchy.Export e = (com.sun.electric.database.hierarchy.Export)it.next();
   if (e.getName().toLowerCase().startsWith("a"))
      System.out.println("Found export: " + e.getName());
}
This program searches the current cell, printing all transistors and all exports that start with the letter "a".

Notice that Electric's "Export" object must be a fully-qualified name, because the name "Export" is used for other purposes in the Bean Shell. This also applies to Electric's "EPoint" class.

import com.sun.electric.database.hierarchy.Cell;
import com.sun.electric.database.topology.NodeInst;
import com.sun.electric.technology.PrimitiveNode;
import com.sun.electric.technology.Technology;
import com.sun.electric.tool.lang.EvalJavaBsh;
import java.awt.geom.Point2D;

Cell newCell = Cell.makeInstance(Library.getCurrent(), "samp1{lay}");
Technology tech = Technology.findTechnology("mocmos");
PrimitiveNode trP = tech.findNodeProto("P-Transistor");
NodeInst tP = NodeInst.makeInstance(trP, new Point2D.Double(10, 10),
   trP.getDefWidth(), trP.getDefHeight(), newCell);
EvalJavaBsh.displayCell(newCell);
This program creates a new cell, places a transistor in it, and displays the cell.

import com.sun.electric.database.hierarchy.Cell;
import com.sun.electric.database.topology.ArcInst;
import com.sun.electric.database.topology.NodeInst;
import com.sun.electric.technology.ArcProto;
import com.sun.electric.technology.PrimitiveNode;
import com.sun.electric.technology.Technology;
import com.sun.electric.util.math.Orientation;
import java.awt.geom.Point2D;

// create the new cell
Cell newCell = Cell.makeInstance(Library.getCurrent(), "samp2{lay}");

Technology tech = Technology.findTechnology("mocmos");

// place a rotated transistor
PrimitiveNode trP = tech.findNodeProto("P-Transistor");
NodeInst tP = NodeInst.makeInstance(trP, new Point2D.Double(0, 20),
   trP.getDefWidth(), trP.getDefHeight(), newCell,
   Orientation.R, "T1");

// place a metal-Active contact
PrimitiveNode coP = tech.findNodeProto("Metal-1-P-Active-Con");
NodeInst maP = NodeInst.makeInstance(coP, new Point2D.Double(8, 20),
   coP.getDefWidth(), coP.getDefHeight(), newCell);

// wire the transistor to the contact
ArcProto aP = tech.findArcProto("P-Active");
ArcInst.makeInstance(aP, tP.findPortInst("diff-bottom"),
   maP.findPortInst("metal-1-p-act"));

// export the contact
com.sun.electric.database.hierarchy.Export.newInst(newCell,
   maP.findPortInst("metal-1-p-act"), "IN", PortCharacteristic.IN);
This program goes a bit further: it creates a rotated transistor and a contact, wires them together, and exports the contact. The transistor is named "T1."

Python Code Examples

from com.sun.electric.database.hierarchy import Cell
from com.sun.electric.database.hierarchy import Library
from com.sun.electric.database.topology import NodeInst
from com.sun.electric.technology import Technology
from com.sun.electric.tool.lang import EvalJython
from java.awt.geom import Point2D
newCell = Cell.makeInstance(Library.getCurrent(), "sample1{lay}")
tech = Technology.findTechnology("mocmos")
trP = tech.findNodeProto("P-Transistor")
tP = NodeInst.makeInstance(trP, Point2D.Double(10, 10), trP.getDefWidth(), trP.getDefHeight(), newCell)
EvalJython.displayCell(newCell)
This program creates a new cell, places a transistor in it, and displays the cell.

from com.sun.electric.database.hierarchy import Cell
from com.sun.electric.database.hierarchy import Library
from com.sun.electric.database.hierarchy import Export
from com.sun.electric.database.prototype import PortCharacteristic
from com.sun.electric.database.topology import ArcInst
from com.sun.electric.database.topology import NodeInst
from com.sun.electric.technology import Technology
from com.sun.electric.util.math import Orientation
from java.awt.geom import Point2D

# create the new cell
newCell = Cell.makeInstance(Library.getCurrent(), "sample2{lay}")

tech = Technology.findTechnology("mocmos")

# place a rotated transistor
trP = tech.findNodeProto("P-Transistor")
tP = NodeInst.makeInstance(trP, Point2D.Double(0, 20), trP.getDefWidth(), trP.getDefHeight(), newCell, Orientation.R, "T1")

# place a metal-Active contact
coP = tech.findNodeProto("Metal-1-P-Active-Con")
maP = NodeInst.makeInstance(coP, Point2D.Double(8, 20), coP.getDefWidth(), coP.getDefHeight(), newCell)

# wire the transistor to the contact
aP = tech.findArcProto("P-Active")
ArcInst.makeInstance(aP, tP.findPortInst("diff-bottom"), maP.findPortInst("metal-1-p-act"))

# export the contact
Export.newInst(newCell, maP.findPortInst("metal-1-p-act"), "IN", PortCharacteristic.IN)
This program goes a bit further: it creates a rotated transistor and a contact, wires them together, and exports the contact. The transistor is named "T1."


Prev Previous     Contents Table of Contents     Next Next