📄 cellchangejobs.java
字号:
{ newPp.copyTextDescriptorFrom(pp, Export.EXPORT_NAME); newPp.copyVarsFrom(pp); } } } // copy the arcs into the new cell for(Geometric look : whatToPackage) { if (!(look instanceof ArcInst)) continue; ArcInst ai = (ArcInst)look; NodeInst niTail = newNodes.get(ai.getTailPortInst().getNodeInst()); NodeInst niHead = newNodes.get(ai.getHeadPortInst().getNodeInst()); if (niTail == null || niHead == null) continue; PortInst piTail = niTail.findPortInstFromProto(ai.getTailPortInst().getPortProto()); PortInst piHead = niHead.findPortInstFromProto(ai.getHeadPortInst().getPortProto()); String name = null; Name oldName = ai.getNameKey(); if (!oldName.isTempname()) name = oldName.toString(); ArcInst newAi = ArcInst.makeInstanceBase(ai.getProto(), ai.getLambdaBaseWidth(), piHead, piTail, ai.getHeadLocation(), ai.getTailLocation(), name); if (newAi == null) return false; newAi.copyPropertiesFrom(ai); } System.out.println("Cell " + cell.describe(true) + " created"); return true; } } /** * This class implement the command to extract the contents of cell instances. */ public static class ExtractCellInstances extends Job { private Cell cell; private List<NodeInst> nodes; private boolean copyExports; private int depth; public ExtractCellInstances(Cell cell, List<NodeInst> highlighted, int depth, boolean copyExports, boolean startNow) { super("Extract Cell Instances", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cell = cell; this.nodes = highlighted; this.copyExports = copyExports; this.depth = depth; if (!startNow) startJob(); else { try {doIt(); } catch (Exception e) {e.printStackTrace();} } } public boolean doIt() throws JobException { doArbitraryExtraction(cell, nodes, copyExports, depth); return true; } } private static void doArbitraryExtraction(Cell cell, List<NodeInst> nodes, boolean copyExports, int depth) { Job.getUserInterface().startProgressDialog("Extracting " + nodes.size() + " cells", null); Map<NodeInst,Map<PortInst,PortInst>> newNodes = new HashMap<NodeInst,Map<PortInst,PortInst>>(); int done = 0; Set<NodeInst> nodesToKill = new HashSet<NodeInst>(); List<Export> exportsToCopy = new ArrayList<Export>(); for(NodeInst ni : nodes) { if (!ni.isCellInstance()) continue; Map<PortInst,PortInst> portMap = new HashMap<PortInst,PortInst>(); extractOneLevel(cell, ni, GenMath.MATID, portMap, 1, depth); newNodes.put(ni, portMap); for (Iterator<Export> it = ni.getExports(); it.hasNext(); ) exportsToCopy.add(it.next()); done++; Job.getUserInterface().setProgressValue(done * 100 / nodes.size()); nodesToKill.add(ni); } // replace arcs to the cell and exports on the cell Job.getUserInterface().setProgressNote("Replacing top-level arcs and exports"); replaceExtractedArcs(cell, newNodes, GenMath.MATID); // replace the exports if needed if (copyExports) { for(Export pp : exportsToCopy) { PortInst oldPi = pp.getOriginalPort(); Map<PortInst,PortInst> nodePortMap = newNodes.get(oldPi.getNodeInst()); if (nodePortMap == null) continue; PortInst newPi = nodePortMap.get(oldPi); if (newPi == null) { pp.kill(); continue; } pp.move(newPi); } } // delete original nodes cell.killNodes(nodesToKill); Job.getUserInterface().stopProgressDialog(); } private static void extractOneLevel(Cell cell, NodeInst topno, AffineTransform prevTrans, Map<PortInst,PortInst> portMap, int curDepth, int totDepth) { Map<NodeInst,Map<PortInst,PortInst>> newNodes = new HashMap<NodeInst,Map<PortInst,PortInst>>(); // see if there are already Essential Bounds nodes in the top cell boolean hasEssentialBounds = false; for(Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); NodeProto np = ni.getProto(); if (np == Generic.tech().essentialBoundsNode) { hasEssentialBounds = true; break; } } // make transformation matrix for this cell Cell subCell = (Cell)topno.getProto(); AffineTransform localTrans = topno.translateOut(topno.rotateOut()); localTrans.preConcatenate(prevTrans); for(Iterator<NodeInst> it = subCell.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); Map<PortInst,PortInst> subPortMap = new HashMap<PortInst,PortInst>(); newNodes.put(ni, subPortMap); // do not extract "cell center" primitives NodeProto np = ni.getProto(); if (np == Generic.tech().cellCenterNode) continue; // do not extract "essential bounds" primitives if they exist in the top-level cell if (np == Generic.tech().essentialBoundsNode && hasEssentialBounds) continue; boolean extractCell = false; if (ni.isCellInstance() && curDepth < totDepth) extractCell = true; if (extractCell) { extractOneLevel(cell, ni, localTrans, subPortMap, curDepth+1, totDepth); // add to the portmap for(Iterator<Export> eIt = ni.getExports(); eIt.hasNext(); ) { Export e = eIt.next(); PortInst fromPi = topno.findPortInstFromProto(e); PortInst toPi = subPortMap.get(e.getOriginalPort()); portMap.put(fromPi, toPi); } } else { String name = null; if (ni.isUsernamed()) name = ElectricObject.uniqueObjectName(ni.getName(), cell, NodeInst.class, false); Orientation orient = topno.getOrient().concatenate(ni.getOrient()); Point2D pt = new Point2D.Double(ni.getAnchorCenterX(), ni.getAnchorCenterY()); AffineTransform instTrans = ni.rotateOut(localTrans); instTrans.transform(pt, pt); NodeInst newNi = NodeInst.makeInstance(np, pt, ni.getXSize(), ni.getYSize(), cell, orient, name, 0); if (newNi == null) continue; newNi.copyTextDescriptorFrom(ni, NodeInst.NODE_NAME); newNi.copyStateBits(ni); newNi.copyVarsFrom(ni); // add ports to the new node's portmap for(Iterator<PortInst> pIt = ni.getPortInsts(); pIt.hasNext(); ) { PortInst oldPi = pIt.next(); PortInst newPi = newNi.findPortInstFromProto(oldPi.getPortProto()); subPortMap.put(oldPi, newPi); } // add exports to the parent portmap for(Iterator<Export> eIt = ni.getExports(); eIt.hasNext(); ) { Export e = eIt.next(); PortInst fromPi = topno.findPortInstFromProto(e); PortInst toPi = newNi.findPortInstFromProto(e.getOriginalPort().getPortProto()); portMap.put(fromPi, toPi); } } } replaceExtractedArcs(subCell, newNodes, localTrans); } private static void replaceExtractedArcs(Cell cell, Map<NodeInst,Map<PortInst,PortInst>> nodeMaps, AffineTransform trans) { for(Iterator<ArcInst> it = cell.getArcs(); it.hasNext(); ) { ArcInst ai = it.next(); PortInst oldHeadPi = ai.getHeadPortInst(); NodeInst headNi = oldHeadPi.getNodeInst(); Map<PortInst,PortInst> headMap = nodeMaps.get(headNi); PortInst oldTailPi = ai.getTailPortInst(); NodeInst tailNi = oldTailPi.getNodeInst(); Map<PortInst,PortInst> tailMap = nodeMaps.get(tailNi); if (headMap == null && tailMap == null) continue; PortInst newHeadPi = oldHeadPi; if (headMap != null) { newHeadPi = headMap.get(oldHeadPi); if (newHeadPi == null) { System.out.println("Warning: arc " + ai.describe(false) + " in cell " + cell.describe(false) + " is missing head connectivity information"); continue; } } PortInst newTailPi = oldTailPi; if (tailMap != null) { newTailPi = tailMap.get(oldTailPi); if (newTailPi == null) { System.out.println("Warning: arc " + ai.describe(false) + " in cell " + cell.describe(false) + " is missing tail connectivity information"); continue; } } if (newHeadPi == null || newTailPi == null) { System.out.println("Warning: cannot reconnect arc in cell " + cell.describe(false) + " from " + oldHeadPi + " to " + oldTailPi); continue; } Point2D headLoc = new Point2D.Double(ai.getHeadLocation().getX(), ai.getHeadLocation().getY()); trans.transform(headLoc, headLoc); Point2D tailLoc = new Point2D.Double(ai.getTailLocation().getX(), ai.getTailLocation().getY()); trans.transform(tailLoc, tailLoc); ArcProto ap = ai.getProto(); double wid = ai.getLambdaBaseWidth(); String name = null; if (ai.isUsernamed()) name = ElectricObject.uniqueObjectName(ai.getName(), cell, ArcInst.class, false); ArcInst newAi = ArcInst.makeInstanceBase(ap, wid, newHeadPi, newTailPi, headLoc, tailLoc, name); if (newAi == null) { System.out.println("Error: arc " + ai.describe(false) + " in cell " + cell.describe(false) + " was not extracted"); continue; } newAi.copyPropertiesFrom(ai); } } /****************************** MAKE A NEW VERSION OF A CELL ******************************/ /** * This class implement the command to make a new version of a cell. */ public static class NewCellVersion extends Job { private Cell cell; private Cell newVersion; public NewCellVersion(Cell cell) { super("Create new Version of " + cell, User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cell = cell; startJob(); } public boolean doIt() throws JobException { newVersion = cell.makeNewVersion(); if (newVersion == null) return false; fieldVariableChanged("newVersion"); return true; } public void terminateOK() { if (newVersion == null) return; // change the display of old versions to the new one for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame wf = it.next(); WindowContent content = wf.getContent(); if (content == null) continue; if (content.getCell() == cell) wf.setCellWindow(newVersion, null); } EditWindow.repaintAll(); System.out.println("Created new version: "+newVersion+", old version renamed to "+cell); } } /****************************** MAKE A COPY OF A CELL ******************************/ /** * This class implement the command to duplicate a cell. */ public static class DuplicateCell extends Job { private Cell cell; private String newName; private boolean entireGroup; private Cell dupCell; public DuplicateCell(Cell cell, String newName, boolean entireGroup) { super("Duplicate " + cell, User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cell = cell; this.newName = newName; this.entireGroup = entireGroup; startJob(); } public boolean doIt() throws JobException { Map<Cell,Cell> newCells = new HashMap<Cell,Cell>(); String newCellName = newName + cell.getView().getAbbreviationExtension(); dupCell = Cell.copyNodeProto(cell, cell.getLibrary(), newCellName, false); if (dupCell == null) { System.out.println("Could not duplicate "+cell); return false; } newCells.put(cell, dupCell); fieldVariableChanged("dupCell"); System.out.println("Duplicated cell "+cell+". New cell is "+dupCell+"."); // examine all other cells in the group Cell.CellGroup group = cell.getCellGroup(); for(Iterator<Cell> it = group.getCells(); it.hasNext(); ) { Cell otherCell = it.next(); if (otherCell == cell) continue; // Only when copy an schematic, we should copy the icon if entireGroup == false if (!entireGroup && !(cell.isSchematic() && otherCell.isIcon())) continue; Cell copyCell = Cell.copyNodeProto(otherCell, otherCell.getLibrary(), newName + otherCell.getView().getAbbreviationExtension(), false); if (copyCell == null) { System.out.println("Could not duplicate cell "+otherCell); break; } newCells.put(otherCell, copyCell); System.out.println(" Also duplicated cell "+otherCell+". New cell is "+copyCell+"."); } // if icon of cell is present, replace old icon with new icon in new schematics cell for(Cell oldCell : newCells.keySet()) { Cell newCell = newCells.get(oldCell); if (!newCell.isSchematic()) continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -