array.java
来自「The ElectricTM VLSI Design System is an 」· Java 代码 · 共 1,013 行 · 第 1/3 页
JAVA
1,013 行
xSpacing.setText(TextUtils.formatDouble(x)); ySpacing.setText(TextUtils.formatDouble(y)); } private void rememberFields() { // gather all "last" values prefXRepeat.setInt((int)TextUtils.getValueOfExpression(xRepeat.getText())); prefXFlip.setBoolean(flipAlternateColumns.isSelected()); prefXStagger.setBoolean(staggerAlternateColumns.isSelected()); prefXCenter.setBoolean(centerXAboutOriginal.isSelected()); prefYRepeat.setInt((int)TextUtils.getValueOfExpression(yRepeat.getText())); prefYFlip.setBoolean(flipAlternateRows.isSelected()); prefYStagger.setBoolean(staggerAlternateRows.isSelected()); prefYCenter.setBoolean(centerYAboutOriginal.isSelected()); prefXDistance.setDouble(TextUtils.getValueOfExpression(xSpacing.getText())); prefYDistance.setDouble(TextUtils.getValueOfExpression(ySpacing.getText())); prefLinearDiagonal.setBoolean(linearDiagonalArray.isSelected()); prefAddNames.setBoolean(generateArrayIndices.isSelected()); prefDRCGood.setBoolean(onlyDRCCorrect.isSelected()); prefTranspose.setBoolean(transposePlacement.isSelected()); } private void makeArray() { // check for nonsense int xRepeat = Math.abs(prefXRepeat.getInt()); int yRepeat = Math.abs(prefYRepeat.getInt()); if (xRepeat <= 1 && yRepeat <= 1) { JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), "One dimension of the array must be greater than 1"); return; } if (prefLinearDiagonal.getBoolean() && xRepeat != 1 && yRepeat != 1) { JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), "Diagonal arrays need one dimension to be 1"); return; } // make lists of nodes and arcs that will be arrayed List<NodeInst> nodeList = new ArrayList<NodeInst>(); List<ArcInst> arcList = new ArrayList<ArcInst>(); List<Export> exportList = new ArrayList<Export>(); Cell cell = null; for(Geometric geom : selected.keySet()) { cell = geom.getParent(); if (geom instanceof NodeInst) { nodeList.add((NodeInst)geom); if (User.isDupCopiesExports()) { NodeInst ni = (NodeInst)geom; for(Iterator<Export> eIt = ni.getExports(); eIt.hasNext(); ) exportList.add(eIt.next()); } } else { arcList.add((ArcInst)geom); } } Collections.sort(nodeList); Collections.sort(arcList); Collections.sort(exportList); // determine the distance between arrayed entries double xOverlap = prefXDistance.getDouble(); double yOverlap = prefYDistance.getDouble(); if (prefSpacingType.getInt() == SPACING_EDGE) { xOverlap = bounds.getWidth() - prefXDistance.getDouble(); yOverlap = bounds.getHeight() - prefYDistance.getDouble(); } double cX = bounds.getCenterX(); double cY = bounds.getCenterY(); // disallow arraying if lock is on for(NodeInst ni : nodeList) { if (CircuitChangeJobs.cantEdit(cell, ni, true, false, false) != 0) return; } // create the array new ArrayStuff(nodeList, arcList, exportList, xRepeat, yRepeat, xOverlap, yOverlap, cX, cY, User.isArcsAutoIncremented()); } /** * Class to create an array in a new thread. */ private static class ArrayStuff extends Job { private List<NodeInst> nodeList; private List<ArcInst> arcList; private List<Export> exportList; private int xRepeat, yRepeat; private double xOverlap, yOverlap, cX, cY; private boolean arcsAutoIncrement; protected ArrayStuff(List<NodeInst> nodeList, List<ArcInst> arcList, List<Export> exportList, int xRepeat, int yRepeat, double xOverlap, double yOverlap, double cX, double cY, boolean arcsAutoIncrement) { super("Make Array", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.nodeList = nodeList; this.arcList = arcList; this.exportList = exportList; this.xRepeat = xRepeat; this.yRepeat = yRepeat; this.xOverlap = xOverlap; this.yOverlap = yOverlap; this.cX = cX; this.cY = cY; this.arcsAutoIncrement = arcsAutoIncrement; startJob(); } public boolean doIt() throws JobException { Cell cell = nodeList.get(0).getParent(); // if only arraying where DRC clean, make an array of newly created nodes Geometric [] geomsToCheck = null; boolean [] validity = null; int checkNodeCount = 0; if (prefDRCGood.getBoolean()) { geomsToCheck = new NodeInst[xRepeat * yRepeat]; validity = new boolean[xRepeat * yRepeat]; if (nodeList.size() == 1) geomsToCheck[checkNodeCount++] = nodeList.get(0); } // create the array int originalX = 0, originalY = 0; int total = yRepeat * xRepeat; for(int index = 0; index < total; index++) { int x = index % xRepeat; int y = index / xRepeat; if (prefTranspose.getBoolean()) { y = index % yRepeat; x = index / yRepeat; } int xIndex = x; int yIndex = y; if (prefXCenter.getBoolean()) xIndex = x - (xRepeat-1)/2; if (prefYCenter.getBoolean()) yIndex = y - (yRepeat-1)/2; if (prefXRepeat.getInt() < 0) xIndex = -xIndex; if (prefYRepeat.getInt() < 0) yIndex = -yIndex; if (xIndex == 0 && yIndex == 0) { originalX = x; originalY = y; continue; } // first replicate the nodes boolean firstNode = true; Map<NodeInst,NodeInst> nodeMap = new HashMap<NodeInst,NodeInst>(); for(NodeInst ni : nodeList) { double xPos = cX + xOverlap * xIndex; if (prefLinearDiagonal.getBoolean() && xRepeat == 1) xPos = cX + xOverlap * yIndex; double yPos = cY + yOverlap * yIndex; if (prefLinearDiagonal.getBoolean() && yRepeat == 1) yPos = cY + yOverlap * xIndex; double xOff = ni.getAnchorCenterX() - cX; double yOff = ni.getAnchorCenterY() - cY; if ((xIndex&1) != 0 && prefXStagger.getBoolean()) yPos += yOverlap/2; if ((yIndex&1) != 0 && prefYStagger.getBoolean()) xPos += xOverlap/2; boolean flipX = false, flipY = false; if ((xIndex&1) != 0 && prefXFlip.getBoolean()) { flipX = true; xOff = -xOff; } if ((yIndex&1) != 0 && prefYFlip.getBoolean()) { flipY = true; yOff = -yOff; } Orientation orient = Orientation.fromJava(0, flipX, flipY).concatenate(ni.getOrient()); xPos += xOff; yPos += yOff; NodeInst newNi = NodeInst.makeInstance(ni.getProto(), new Point2D.Double(xPos, yPos), ni.getXSize(), ni.getYSize(), cell, orient, null, 0); if (newNi == null) continue; newNi.copyTextDescriptorFrom(ni, NodeInst.NODE_PROTO); newNi.copyTextDescriptorFrom(ni, NodeInst.NODE_NAME); if (ni.isExpanded()) newNi.setExpanded(); else newNi.clearExpanded(); if (ni.isHardSelect()) newNi.setHardSelect(); else newNi.clearHardSelect(); newNi.setTechSpecific(ni.getTechSpecific()); newNi.copyVarsFrom(ni); if (prefAddNames.getBoolean()) { setNewName(newNi, x, y); } else { Name nodeNameKey = ni.getNameKey(); if (!nodeNameKey.isTempname()) { newNi.setName(ElectricObject.uniqueObjectName(ni.getName(), cell, NodeInst.class, false)); newNi.copyTextDescriptorFrom(ni, NodeInst.NODE_NAME); } } nodeMap.put(ni, newNi); if (prefDRCGood.getBoolean() && firstNode) { geomsToCheck[checkNodeCount++] = newNi; firstNode = false; } } // next replicate the arcs for(ArcInst ai : arcList) { double cX0 = ai.getHeadPortInst().getNodeInst().getAnchorCenterX(); double cY0 = ai.getHeadPortInst().getNodeInst().getAnchorCenterY(); double xOff0 = ai.getHeadLocation().getX() - cX0; double yOff0 = ai.getHeadLocation().getY() - cY0; double cX1 = ai.getTailPortInst().getNodeInst().getAnchorCenterX(); double cY1 = ai.getTailPortInst().getNodeInst().getAnchorCenterY(); double xOff1 = ai.getTailLocation().getX() - cX1; double yOff1 = ai.getTailLocation().getY() - cY1; if ((xIndex&1) != 0 && prefXFlip.getBoolean()) { xOff0 = -xOff0; xOff1 = -xOff1; } if ((yIndex&1) != 0 && prefYFlip.getBoolean()) { yOff0 = -yOff0; yOff1 = -yOff1; } NodeInst ni0 = nodeMap.get(ai.getHeadPortInst().getNodeInst()); if (ni0 == null) continue; NodeInst ni1 = nodeMap.get(ai.getTailPortInst().getNodeInst()); if (ni1 == null) continue; cX0 = ni0.getAnchorCenterX(); cY0 = ni0.getAnchorCenterY(); cX1 = ni1.getAnchorCenterX(); cY1 = ni1.getAnchorCenterY(); PortInst pi0 = ni0.findPortInstFromProto(ai.getHeadPortInst().getPortProto()); PortInst pi1 = ni1.findPortInstFromProto(ai.getTailPortInst().getPortProto()); ArcInst newAi = ArcInst.makeInstanceBase(ai.getProto(), ai.getLambdaBaseWidth(), pi0, pi1, new Point2D.Double(cX0+xOff0, cY0+yOff0), new Point2D.Double(cX1+xOff1, cY1+yOff1), null); if (newAi == null) continue; newAi.copyPropertiesFrom(ai); if (prefAddNames.getBoolean()) { setNewName(newAi, x, y); } else { Name arcNameKey = ai.getNameKey(); if (!arcNameKey.isTempname()) { String newName = ai.getName(); if (arcsAutoIncrement) newName = ElectricObject.uniqueObjectName(newName, cell, ArcInst.class, false); newAi.setName(newName); newAi.copyTextDescriptorFrom(ai, ArcInst.ARC_NAME); } } } // copy the exports, too List<PortInst> portInstsToExport = new ArrayList<PortInst>(); Map<PortInst,Export> originalExports = new HashMap<PortInst,Export>(); for(Export pp : exportList) { PortInst oldPI = pp.getOriginalPort(); NodeInst newNI = nodeMap.get(oldPI.getNodeInst()); if (newNI == null) continue; PortInst pi = newNI.findPortInstFromProto(oldPI.getPortProto()); portInstsToExport.add(pi); originalExports.put(pi, pp); } ExportChanges.reExportPorts(cell, portInstsToExport, false, true, true, false, originalExports); } // rename the replicated objects if (prefAddNames.getBoolean()) { for(NodeInst ni : nodeList) { setNewName(ni, originalX, originalY); } for(ArcInst ai : arcList) { setNewName(ai, originalX, originalY); } } // if only arraying where DRC valid, check them now and delete what is not valid if (prefDRCGood.getBoolean()) { Quick.checkDesignRules(null, cell, geomsToCheck, validity, null); for(int i=1; i<checkNodeCount; i++) { if (!validity[i]) { // delete the node ((NodeInst)geomsToCheck[i]).kill(); } } } return true; } private void setNewName(Geometric geom, int x, int y) { String objName = ""; Name geomNameKey = geom instanceof NodeInst ? ((NodeInst)geom).getNameKey() : ((ArcInst)geom).getNameKey(); String geomName = geomNameKey.toString(); if (geomNameKey.isTempname()) geomName = null; if (geomName != null) { if (!geomName.equals("0") && !geomName.equals("0-0")) objName = geomName.toString(); } String totalName = objName + x + "-" + y; if (Math.abs(prefXRepeat.getInt()) <= 1 || Math.abs(prefYRepeat.getInt()) <= 1) totalName = objName + (x+y); if (geom instanceof NodeInst) { NodeInst ni = (NodeInst)geom; ni.setName(totalName); if (ni.isCellInstance()) ni.setOff(NodeInst.NODE_NAME, 0, ni.getYSize() / 4); } else { ((ArcInst)geom).setName(totalName); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?