📄 circuitchanges.java
字号:
} /** * Method to rip the currently selected bus arc out into individual wires. */ public static void ripBus() { Cell cell = WindowFrame.needCurCell(); if (cell == null) return; List<ArcInst> list = MenuCommands.getSelectedArcs(); if (list.size() == 0) { System.out.println("Must select bus arcs to rip into individual signals"); return; } new CircuitChangeJobs.RipTheBus(cell, list); } /****************************** DELETE SELECTED OBJECTS ******************************/ /** * Method to delete all selected objects. */ public static void deleteSelected() { // see what type of window is selected WindowFrame wf = WindowFrame.getCurrentWindowFrame(); if (wf == null) return; Cell cell = WindowFrame.needCurCell(); if (cell == null) return; Highlighter highlighter = wf.getContent().getHighlighter(); if (highlighter == null) return; // for waveform windows, delete selected signals if (wf.getContent() instanceof WaveformWindow) { WaveformWindow ww = (WaveformWindow)wf.getContent(); ww.deleteSelectedSignals(); return; } // for edit windows doing outline editing, delete the selected point (done by listener) if (WindowFrame.getListener() == OutlineListener.theOne) return; if (ToolBar.getSelectMode() == ToolBar.SelectMode.AREA) { EditWindow wnd = EditWindow.getCurrent(); Rectangle2D bounds = highlighter.getHighlightedArea(wnd); new CircuitChangeJobs.DeleteSelectedGeometry(cell, bounds); } else { // disable the "node moves with text" because it causes nodes to be deleted with text, too boolean formerMoveWithText = User.isMoveNodeWithExport(); Pref.delayPrefFlushing(); User.setMoveNodeWithExport(false); // get what is highlighted List<DisplayedText> highlightedText = highlighter.getHighlightedText(true); List<Geometric> highlighted = highlighter.getHighlightedEObjs(true, true); // restore "node moves with text" User.setMoveNodeWithExport(formerMoveWithText); Pref.resumePrefFlushing(); // delete if anything was selected if (highlightedText.size() == 0 && highlighted.size() == 0) return; new CircuitChangeJobs.DeleteSelected(cell, highlightedText, highlighted, User.isReconstructArcsAndExportsToDeletedCells()); } } /** * Method to delete arcs connected to selected nodes. * @param both true if both ends of the arc must be selected. */ public static void deleteArcsOnSelected(boolean both) { // get the selection EditWindow wnd = EditWindow.needCurrent(); if (wnd == null) return; // make sure the cell is editable Cell cell = WindowFrame.needCurCell(); if (cell == null) return; if (CircuitChangeJobs.cantEdit(cell, null, true, false, false) != 0) return; // make a set of selected nodes Highlighter highlighter = wnd.getHighlighter(); if (highlighter == null) return; Set<NodeInst> selectedNodes = new HashSet<NodeInst>(); for(Geometric g : highlighter.getHighlightedEObjs(true, false)) selectedNodes.add((NodeInst)g); // make a set of arcs to delete Set<ArcInst> arcsToDelete = new HashSet<ArcInst>(); for(NodeInst ni : selectedNodes) { for(Iterator<Connection> it = ni.getConnections(); it.hasNext(); ) { Connection con = it.next(); ArcInst ai = con.getArc(); if (both) { if (!selectedNodes.contains(ai.getHeadPortInst().getNodeInst())) continue; if (!selectedNodes.contains(ai.getTailPortInst().getNodeInst())) continue; } arcsToDelete.add(ai); } } if (arcsToDelete.size() == 0) { System.out.println("There are no arcs on the selected nodes that can be deleted"); return; } new CircuitChangeJobs.DeleteArcs(arcsToDelete); } /****************************** DELETE A CELL ******************************/ /** * Method to delete a cell. * @param cell the cell to delete. * @param confirm true to prompt the user to confirm the deletion. * @param quiet true not to warn the user of the cell being used. * @return true if the cell will be deleted (in a separate Job). */ public static boolean deleteCell(Cell cell, boolean confirm, boolean quiet) { // see if this cell is in use anywhere if (cell.isInUse("delete", quiet, true)) return false; // make sure the user really wants to delete the cell if (confirm) { int response = JOptionPane.showConfirmDialog(TopLevel.getCurrentJFrame(), "Are you sure you want to delete " + cell + "?", "Delete Cell Dialog", JOptionPane.YES_NO_OPTION); if (response != JOptionPane.YES_OPTION) return false; } // delete references to cell cleanCellRef(cell); // delete the cell new CellChangeJobs.DeleteCell(cell); return true; } /** * Method to delete cell "cell". Validity checks are assumed to be made (i.e. the * cell is not used and is not locked). */ public static void cleanCellRef(Cell cell) { // delete random references to this cell Library lib = cell.getLibrary(); if (cell == Job.getUserInterface().getCurrentCell(lib)) Job.getUserInterface().setCurrentCell(lib, null); // close windows that reference this cell for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame wf = it.next(); WindowContent content = wf.getContent(); if (content == null) continue; if (content.getCell() == cell) { if (!(content instanceof EditWindow)) { wf.setCellWindow(null, null); } else { content.setCell(null, null, null); content.fullRepaint(); } } } } /****************************** RENAME CELLS ******************************/ public static void renameCellInJob(Cell cell, String newName) { // see if the rename should also regroup String newGroupCell = null; for(Iterator<Cell> it = cell.getLibrary().getCells(); it.hasNext(); ) { Cell oCell = it.next(); if (oCell.getName().equalsIgnoreCase(newName) && oCell.getCellGroup() != cell.getCellGroup()) { int response = JOptionPane.showConfirmDialog(TopLevel.getCurrentJFrame(), "Also place the cell into the " + oCell.getCellGroup().getName() + " group?"); if (response == JOptionPane.YES_OPTION) newGroupCell = oCell.getName(); break; } } new CellChangeJobs.RenameCell(cell, newName, newGroupCell); } public static void renameCellGroupInJob(Cell.CellGroup cellGroup, String newName) { new CellChangeJobs.RenameCellGroup(cellGroup.getCells().next(), newName); } /****************************** SHOW CELLS GRAPHICALLY ******************************/ /** * Method to graph the cells, starting from the current cell. */ public static void graphCellsFromCell() { Cell top = WindowFrame.needCurCell(); if (top == null) return; new CellChangeJobs.GraphCells(top); } /** * Method to graph all cells in the current Library. */ public static void graphCellsInLibrary() { new CellChangeJobs.GraphCells(null); } /****************************** EXTRACT CELL INSTANCES ******************************/ /** * Method to package the selected objects into a new cell. */ public static void packageIntoCell() { WindowFrame wf = WindowFrame.getCurrentWindowFrame(); if (wf == null) return; Highlighter highlighter = wf.getContent().getHighlighter(); if (highlighter == null) return; // get the specified area EditWindow wnd = EditWindow.needCurrent(); if (wnd == null) return; Cell curCell = wnd.getCell(); if (curCell == null) { System.out.println("No cell in this window"); return; } Rectangle2D bounds = highlighter.getHighlightedArea(wnd); if (bounds == null) { System.out.println("Must first select circuitry to package"); return; } String newCellName = JOptionPane.showInputDialog("New cell name:", curCell.getName()); if (newCellName == null) return; newCellName += curCell.getView().getAbbreviationExtension(); Set<Geometric> whatToPackage = new HashSet<Geometric>(); List<Geometric> highlighted = highlighter.getHighlightedEObjs(true, true); for(Geometric geom : highlighted) { whatToPackage.add(geom); if (geom instanceof ArcInst) { ArcInst ai = (ArcInst)geom; whatToPackage.add(ai.getHeadPortInst().getNodeInst()); whatToPackage.add(ai.getTailPortInst().getNodeInst()); } } new CellChangeJobs.PackageCell(curCell, whatToPackage, newCellName); } /** * Method to yank the contents of complex node instance "topno" into its * parent cell. */ public static void extractCells(int depth) { Cell cell = WindowFrame.needCurCell(); if (cell == null) return; if (depth < 0) { Object obj = JOptionPane.showInputDialog("Number of levels to extract", "1"); if (obj != null) depth = TextUtils.atoi((String)obj); if (depth <= 0) return; } List<NodeInst> selected = MenuCommands.getSelectedNodes(); List<NodeInst> instances = new ArrayList<NodeInst>(); for(NodeInst ni : selected) { if (ni.isCellInstance()) instances.add(ni); } if (instances.size() == 0) { System.out.println("No cell instances are selected...no extraction done"); return; } new CellChangeJobs.ExtractCellInstances(cell, instances, depth, User.isExtractCopiesExports(), false); } /****************************** CLEAN-UP ******************************/ public static void cleanupPinsCommand(boolean everywhere) { WindowFrame wf = WindowFrame.getCurrentWindowFrame(); if (wf == null) return; Highlighter highlighter = wf.getContent().getHighlighter(); if (highlighter == null) return; if (everywhere) { boolean cleaned = false; for(Library lib : Library.getVisibleLibraries()) { for(Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { Cell cell = it.next(); if (cleanupCell(cell, false, highlighter)) cleaned = true; } } if (!cleaned) System.out.println("Nothing to clean"); } else { // just cleanup the current cell Cell cell = WindowFrame.needCurCell(); if (cell == null) return; cleanupCell(cell, true, highlighter); } } /** * Method to clean-up cell "np" as follows: * remove stranded pins * collapse redundant (inline) arcs * highlight zero-size nodes * removes duplicate arcs * highlight oversize pins that allow arcs to connect without touching * move unattached and invisible pins with text in a different location * resize oversized pins that don't have oversized arcs on them * Returns true if changes are made. */ private static boolean cleanupCell(Cell cell, boolean justThis, Highlighter highlighter) { // look for unused pins that can be deleted Set<NodeInst> pinsToRemove = new HashSet<NodeInst>(); List<CircuitChangeJobs.Reconnect> pinsToPassThrough = CircuitChangeJobs.getPinsToPassThrough(cell); for(Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); if (ni.getFunction() != PrimitiveNode.Function.PIN) continue; // if the pin is an export, save it if (ni.hasExports()) continue;// if (ni.getNumExports() > 0) continue; // if the pin is not connected or displayed, delete it if (!ni.hasConnections())// if (ni.getNumConnections() == 0) { // see if the pin has displayable variables on it boolean hasDisplayable = false; for(Iterator<Variable> vIt = ni.getVariables(); vIt.hasNext(); ) { Variable var = vIt.next(); if (var.isDisplay()) { hasDisplayable = true; break; } } if (hasDisplayable) continue; // no displayable variables: delete it pinsToRemove.add(ni); continue; } } // look for oversized pins that can be reduced in size HashMap<NodeInst,EPoint> pinsToScale = new HashMap<NodeInst,EPoint>(); for(Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); if (ni.getFunction() != PrimitiveNode.Function.PIN) continue; // if the pin is standard size, leave it alone double overSizeX = ni.getXSize() - ni.getProto().getDefWidth(); if (overSizeX < 0) overSizeX = 0; double overSizeY = ni.getYSize() - ni.getProto().getDefHeight(); if (overSizeY < 0) overSizeY = 0; if (overSizeX == 0 && overSizeY == 0) continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -