📄 padgenerator.java
字号:
PortProto pp = (lastni.getProto()).findPortProto(lastaa.outport); if (pp == null) { err("no port called '" + lastaa.outport + "' on " + lastni); continue; } Poly poly = (lastni.findPortInstFromProto(pp)).getPoly(); centerX = poly.getCenterX(); centerY = poly.getCenterY(); } Point2D pointCenter = new Point2D.Double(centerX, centerY); boolean flipLR = false; boolean flipUD = false; if (reversed) flipUD = true; Orientation orient = Orientation.fromJava(angle, flipLR, flipUD); NodeInst ni = NodeInst.makeInstance(cell, pointCenter, cell.getDefWidth(), cell.getDefHeight(), framecell, orient, null, 0); if (ni == null) { err("problem creating" + cell + " instance"); continue; } if (lastni != null) { int gap = pad.gap; if (reversed) gap = -gap; switch (lastRotate) { case 0: gapx = gap; gapy = 0; break; case 900: gapx = 0; gapy = gap; break; case 1800: gapx = -gap; gapy = 0; break; case 2700: gapx = 0; gapy = -gap; break; } PortProto inport = cell.findPortProto(aa.inport); if (inport == null) { err("No port called '" + aa.inport + "' on " + cell); continue; } Poly poly = ni.findPortInstFromProto(inport).getPoly(); double tempx = centerX - poly.getCenterX() + gapx; double tempy = centerY - poly.getCenterY() + gapy; ni.move(tempx, tempy); } double dx = 0, dy = 0; if (pad.locx != null) dx = pad.locx.doubleValue() - ni.getAnchorCenterX(); if (pad.locy != null) dy = pad.locy.doubleValue() - ni.getAnchorCenterY(); ni.move(dx, dy); // create exports // get export for this cell, if any if (pad.exportsname != null) { PadExports pe = exports.get(pad.cellname); if (pe != null) { // pad export Export pppad = cell.findExport(pe.padname); if (pppad == null) { err("no port called '" + pe.padname + "' on Cell " + cell.noLibDescribe()); } else { pppad = Export.newInstance(framecell, ni.findPortInstFromProto(pppad), pad.exportsname); if (pppad == null) err("Creating export " + pad.exportsname); else { TextDescriptor td = pppad.getTextDescriptor(Export.EXPORT_NAME); pppad.setTextDescriptor(Export.EXPORT_NAME, td.withAbsSize(14)); padPorts.add(pppad); } } // core export if (pe.corename != null) { Export ppcore = cell.findExport(pe.corename); if (ppcore == null) { err("no port called '" + pe.corename + "' on Cell " + cell.noLibDescribe()); } else { ppcore = Export.newInstance(framecell, ni.findPortInstFromProto(ppcore), "core_" + pad.exportsname); if (ppcore == null) err("Creating export core_" + pad.exportsname); else { TextDescriptor td = ppcore.getTextDescriptor(Export.EXPORT_NAME).withAbsSize(14); corePorts.add(ppcore); ppcore.setTextDescriptor(Export.EXPORT_NAME, td); } } } else { corePorts.add(null); } } } // create exports from export pad=name command for (ExportAssociate ea : pad.exportAssociations) { Export pp = cell.findExport(ea.padportName); if (pp == null) { err("no port called '" + ea.padportName + "' on Cell " + cell.noLibDescribe()); } else { pp = Export.newInstance(framecell, ni.findPortInstFromProto(pp), ea.exportName); if (pp == null) err("Creating export "+ea.exportName); else { TextDescriptor td = pp.getTextDescriptor(Export.EXPORT_NAME).withAbsSize(14); corePorts.add(pp); pp.setTextDescriptor(Export.EXPORT_NAME, td); } } } lastni = ni; lastRotate = angle; lastpadname = pad.cellname; pad.ni = ni; } // auto stitch everything AutoStitch.runAutoStitch(framecell, null, null, job, null, null, true, false, false); if (corename != null) { // first, try to create cell String corenameview = corename; if (view != null) { corenameview = corename + "{" + view.getAbbreviation() + "}"; } Cell corenp = destLib.findNodeProto(corenameview); if (corenp == null) { System.out.println("Line " + lineno + ": cannot find core cell " + corenameview); } else { Rectangle2D bounds = framecell.getBounds(); Point2D center = new Point2D.Double(bounds.getCenterX(), bounds.getCenterY()); DBMath.gridAlign(center, alignment); NodeInst ni = NodeInst.makeInstance(corenp, center, corenp.getDefWidth(), corenp.getDefHeight(), framecell); Map<Export,PortInst> trueBusEnd = new HashMap<Export,PortInst>(); for (Object obj : orderedCommands) { if (obj instanceof PlacePad) { PlacePad pad = (PlacePad) obj; for (PortAssociate pa : pad.associations) { if (pad.ni == null) continue; boolean nameArc = false; PortInst pi1 = null; PortProto corepp = corenp.findPortProto(pa.assocname); if (corepp != null) pi1 = ni.findPortInstFromProto(corepp); if (pi1 == null) { // see if there are bus ports on the core for(Iterator<PortProto> it = corenp.getPorts(); it.hasNext(); ) { Export e = (Export)it.next(); Name eName = e.getNameKey(); int wid = eName.busWidth(); if (wid <= 1) continue; for(int i=0; i<wid; i++) { if (eName.subname(i).toString().equals(pa.assocname)) { pi1 = trueBusEnd.get(e); if (pi1 == null) { // make a short bus arc from the port to a bus pin which gets used for connections PortInst pi = ni.findPortInstFromProto(e); PolyBase portPoly = pi.getPoly(); Rectangle2D portRect = portPoly.getBounds2D(); PrimitiveNode busPinProto = Schematics.tech().busPinNode; NodeInst busPin = NodeInst.makeInstance(busPinProto, new EPoint(portRect.getCenterX(), portRect.getCenterY()), busPinProto.getDefWidth(), busPinProto.getDefHeight(), framecell); pi1 = busPin.getOnlyPortInst(); ArcProto busArcProto = Schematics.tech().bus_arc; ArcInst.makeInstance(busArcProto, pi, pi1); trueBusEnd.put(e, pi1); } nameArc = true; break; } } if (pi1 != null) break; } } if (pi1 == null) { PortInst pi = pad.ni.findPortInst(pa.portname); Export.newInstance(pad.ni.getParent(), pi, pa.assocname); continue; } PortInst pi2 = pad.ni.findPortInst(pa.portname); ArcProto ap = Generic.tech().unrouted_arc; ArcInst ai = ArcInst.newInstanceBase(ap, ap.getDefaultLambdaBaseWidth(), pi1, pi2); if (nameArc) { ai.setName(pa.assocname); } else { // give generated name based on the connection String netName = "PADFRAME"; if (pad.exportAssociations != null && pad.exportAssociations.size() > 0) netName += "_" + pad.exportAssociations.get(0).exportName; netName += "_" + pa.assocname; ai.setName(netName); } } } } } } if (view == View.ICON) { // This is a crock until the functionality here can be folded // into CircuitChanges.makeIconViewCommand() // get icon style controls double leadLength = User.getIconGenLeadLength(); double leadSpacing = User.getIconGenLeadSpacing(); // create the new icon cell String iconCellName = framecell.getName() + "{ic}"; Cell iconCell = Cell.makeInstance(destLib, iconCellName); if (iconCell == null) { Job.getUserInterface().showErrorMessage("Cannot create Icon cell " + iconCellName, "Icon creation failed"); return framecell; } iconCell.setWantExpanded(); // determine the size of the "black box" core double ySize = Math.max(Math.max(padPorts.size(), corePorts.size()), 5) * leadSpacing; double xSize = 3 * leadSpacing; // create the "black box" NodeInst bbNi = null; if (User.isIconGenDrawBody()) { bbNi = NodeInst.newInstance(Artwork.tech().openedThickerPolygonNode, new Point2D.Double(0, 0), xSize, ySize, iconCell); if (bbNi == null) return framecell; bbNi.newVar(Artwork.ART_COLOR, new Integer(EGraphics.RED)); EPoint[] points = new EPoint[5]; points[0] = new EPoint(-0.5 * xSize, -0.5 * ySize); points[1] = new EPoint(-0.5 * xSize, 0.5 * ySize); points[2] = new EPoint(0.5 * xSize, 0.5 * ySize); points[3] = new EPoint(0.5 * xSize, -0.5 * ySize); points[4] = new EPoint(-0.5 * xSize, -0.5 * ySize); bbNi.setTrace(points); // put the original cell name on it bbNi.newDisplayVar(Schematics.SCHEM_FUNCTION, framecell.getName()); } // get icon preferences int exportTech = User.getIconGenExportTech(); boolean drawLeads = User.isIconGenDrawLeads(); int exportStyle = User.getIconGenExportStyle(); int exportLocation = User.getIconGenExportLocation(); boolean ad = User.isIconsAlwaysDrawn(); if (coreAllOnOneSide) { List<Export> padTemp = new ArrayList<Export>(); List<Export> coreTemp = new ArrayList<Export>(); for (Export pp : padPorts) { if (pp.getName().startsWith("core_")) coreTemp.add(pp); else padTemp.add(pp); } for (Export pp : corePorts) { if (pp == null) { coreTemp.add(pp); continue; } if (pp.getName().startsWith("core_")) coreTemp.add(pp); else padTemp.add(pp); } padPorts = padTemp; corePorts = coreTemp; } // place pins around the Black Box int total = 0; int leftSide = padPorts.size(); int rightSide = corePorts.size(); for (Export pp : padPorts) { if (pp.isBodyOnly()) continue; // determine location of the port double spacing = leadSpacing; double xPos = 0, yPos = 0; double xBBPos = 0, yBBPos = 0; xBBPos = -xSize / 2; xPos = xBBPos - leadLength; if (leftSide * 2 < rightSide) spacing = leadSpacing * 2; yBBPos = yPos = ySize / 2 - ((ySize - (leftSide - 1) * spacing) / 2 + total * spacing); int rotation = ViewChanges.iconTextRotation(pp, User.getIconGenInputRot(), User.getIconGenOutputRot(), User.getIconGenBidirRot(), User.getIconGenPowerRot(), User.getIconGenGroundRot(), User.getIconGenClockRot()); if (ViewChanges.makeIconExport(pp, 0, xPos, yPos, xBBPos, yBBPos, iconCell, exportTech, drawLeads, exportStyle, exportLocation, rotation, ad)) total++; } total = 0; for (Export pp : corePorts) { if (pp == null) { total++; continue; } if (pp.isBodyOnly()) continue; // determine location of the port double spacing = leadSpacing; double xPos = 0, yPos = 0; double xBBPos = 0, yBBPos = 0; xBBPos = xSize / 2; xPos = xBBPos + leadLength; if (rightSide * 2 < leftSide) spacing = leadSpacing * 2; yBBPos = yPos = ySize / 2 - ((ySize - (rightSide - 1) * spacing) / 2 + total * spacing); int rotation = ViewChanges.iconTextRotation(pp, User.getIconGenInputRot(), User.getIconGenOutputRot(), User.getIconGenBidirRot(), User.getIconGenPowerRot(), User.getIconGenGroundRot(), User.getIconGenClockRot()); if (ViewChanges.makeIconExport(pp, 1, xPos, yPos, xBBPos, yBBPos, iconCell, exportTech, drawLeads, exportStyle, exportLocation, rotation, ad)) total++; } // if no body, leads, or cell center is drawn, and there is only 1 export, add more if (!User.isIconGenDrawBody() && !User.isIconGenDrawLeads() && User.isPlaceCellCenter() && total <= 1) { NodeInst.newInstance(Generic.tech().invisiblePinNode, new Point2D.Double(0, 0), xSize, ySize, iconCell); } // place an icon in the schematic int exampleLocation = User.getIconGenInstanceLocation(); Point2D iconPos = new Point2D.Double(0, 0); Rectangle2D cellBounds = framecell.getBounds(); Rectangle2D iconBounds = iconCell.getBounds(); double halfWidth = iconBounds.getWidth() / 2; double halfHeight = iconBounds.getHeight() / 2; switch (exampleLocation) { case 0: // upper-right iconPos.setLocation(cellBounds.getMaxX() + halfWidth, cellBounds.getMaxY() + halfHeight); break; case 1: // upper-left iconPos.setLocation(cellBounds.getMinX() - halfWidth, cellBounds.getMaxY() + halfHeight); break; case 2: // lower-right iconPos.setLocation(cellBounds.getMaxX() + halfWidth, cellBounds.getMinY() - halfHeight); break; case 3: // lower-left iconPos.setLocation(cellBounds.getMinX() - halfWidth, cellBounds.getMinY() - halfHeight); break; } DBMath.gridAlign(iconPos, alignment); double px = iconCell.getBounds().getWidth(); double py = iconCell.getBounds().getHeight(); NodeInst.makeInstance(iconCell, iconPos, px, py, framecell); } return framecell; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -