📄 elib.java
字号:
writeBigInteger(cellRevision.exports.size()); for (ImmutableExport e: cellRevision.exports) { // write the portproto name writeString(e.name.toString()); } } } void writeCellInfo(CellRevision cellRevision) throws IOException { CellId cellId = cellRevision.d.cellId; if (this instanceof ReadableDump) { writeTxt("name: " + cellId.cellName.getName() + cellId.cellName.getView().getAbbreviationExtension()); } else { if (compatibleWith6) { // write cell index if creating version-6-compatible output Integer cellIndex = cellIndexMap.get(cellId.cellName.getName()); writeBigInteger(cellIndex.intValue()); } else { // write cell information writeString(cellId.cellName.getName()); // write the "next in cell group" pointer writeObj(cellInSameGroup.get(cellId)); // write the "next in continuation" pointer writeObj(null); } // write the view information writeObj(cellId.cellName.getView()); } writeInt("version: ", cellId.cellName.getVersion()); writeInt("creationdate: ", (int)(cellRevision.d.creationDate/1000)); writeInt("revisiondate: ", (int)(cellRevision.d.revisionDate/1000)); // write the nodeproto bounding box ERectangle bounds = snapshot.getCellBounds(cellId); writeGridCoord(cellRevision, "lowx: ", bounds.getGridMinX()); writeGridCoord(cellRevision, "highx: ", bounds.getGridMaxX()); writeGridCoord(cellRevision, "lowy: ", bounds.getGridMinY()); writeGridCoord(cellRevision, "highy: ", bounds.getGridMaxY());// Technology tech = cellBackup.d.tech;// int lowX = (int)Math.round((bounds.getLambdaMinX() * tech.getScale()*2));// int highX = (int)Math.round((bounds.getLambdaMaxX() * tech.getScale()*2));// int lowY = (int)Math.round((bounds.getLambdaMinY() * tech.getScale()*2));// int highY = (int)Math.round((bounds.getLambdaMaxY() * tech.getScale()*2));// writeInt("lowx: ", lowX);// writeInt("highx: ", highX);// writeInt("lowy: ", lowY);// writeInt("highy: ", highY); } private void writeNodeProto(CellRevision cellRevision) throws IOException { writeCellInfo(cellRevision); writeExports(cellRevision); // write tool information writeBigInteger(0); // was "adirty" writeBigInteger(cellRevision.d.flags & ELIBConstants.CELL_BITS); // write variable information writeVariables(cellRevision.d); } void writeNodes(CellBackup cellBackup, int arcBase) throws IOException {// Technology tech = cellBackup.d.tech; CellBackup.Memoization m = cellBackup.getMemoization(); CellRevision cellRevision = cellBackup.cellRevision; for (int nodeIndex = 0; nodeIndex < cellRevision.nodes.size(); nodeIndex++) { ImmutableNodeInst n = cellRevision.nodes.get(nodeIndex); writeTxt("**node: " + nodeIndex); // write descriptive information// int lowX, highX, lowY, highY; double trueCenterX, trueCenterY, xSize, ySize; NodeProtoId protoId = n.protoId; writeObj(protoId); if (protoId instanceof CellId) { writeTxt("type: [" + objInfo.get(protoId).intValue() + "]"); ERectangle bounds = snapshot.getCellBounds((CellId)protoId); Rectangle2D dstBounds = new Rectangle2D.Double(); n.orient.rectangleBounds(bounds.getGridMinX(), bounds.getGridMinY(), bounds.getGridMaxX(), bounds.getGridMaxY(), n.anchor.getGridX(), n.anchor.getGridY(), dstBounds); trueCenterX = dstBounds.getCenterX(); trueCenterY = dstBounds.getCenterY(); xSize = bounds.getGridWidth(); ySize = bounds.getGridHeight();// lowX = (int)Math.round((trueCenterX - xSize/2) * tech.getScale()*2);// highX = (int)Math.round((trueCenterX + xSize/2) * tech.getScale()*2);// lowY = (int)Math.round((trueCenterY - ySize/2) * tech.getScale()*2);// highY = (int)Math.round((trueCenterY + ySize/2) * tech.getScale()*2); } else { PrimitiveNodeId pn = (PrimitiveNodeId)protoId; trueCenterX = n.anchor.getGridX(); trueCenterY = n.anchor.getGridY(); EPoint size = getSizeCorrector(pn.techId).getSizeToDisk(n); xSize = size.getGridX(); ySize = size.getGridY(); writeTxt("type: " + pn.fullName);// lowX = (int)Math.round((n.anchor.getLambdaX() - n.size.getLambdaX()/2) * tech.getScale()*2);// highX = (int)Math.round((n.anchor.getLambdaX() + n.size.getLambdaX()/2) * tech.getScale()*2);// lowY = (int)Math.round((n.anchor.getLambdaY() - n.size.getLambdaY()/2) * tech.getScale()*2);// highY = (int)Math.round((n.anchor.getLambdaY() + n.size.getLambdaY()/2) * tech.getScale()*2); } writeGridCoord(cellRevision, "lowx: ", trueCenterX - xSize*0.5); writeGridCoord(cellRevision, "lowy: ", trueCenterY - ySize*0.5); writeGridCoord(cellRevision, "highx: ", trueCenterX + xSize*0.5); writeGridCoord(cellRevision, "highy: ", trueCenterY + ySize*0.5);// writeInt("lowx: ", lowX);// writeInt("lowy: ", lowY);// writeInt("highx: ", highX);// writeInt("highy: ", highY); // write anchor point too if (protoId instanceof CellId && !compatibleWith6) { writeGridCoord(cellRevision, null, n.anchor.getGridX()); writeGridCoord(cellRevision, null, n.anchor.getGridY());// int anchorX = (int)Math.round(n.anchor.getLambdaX() * tech.getScale() * 2);// int anchorY = (int)Math.round(n.anchor.getLambdaY() * tech.getScale() * 2);// writeBigInteger(anchorX);// writeBigInteger(anchorY); } Orientation or = n.orient; int transpose = 0; int rotation; if (compatibleWith6) { rotation = or.getCAngle(); transpose = or.isCTranspose() ? 1 : 0; } else { rotation = or.getAngle(); if (or.isXMirrored()) transpose |= 2; if (or.isYMirrored()) transpose |= 4; } writeOrientation(rotation, transpose); TextDescriptor td = protoId instanceof CellId ? n.protoDescriptor : null; writeTextDescriptor(-1, td); if (this instanceof ReadableDump) { // write the tool information writeInt("userbits: ", n.getElibBits()); // write variable information and arc name writeVariables(n); writeConnectionsAndReExports(m, arcBase, n); } else { writeConnectionsAndReExports(m, arcBase, n); // write the tool information writeBigInteger(n.getElibBits()); // write variable information and arc name writeVariables(n); } } } private void writeConnectionsAndReExports(CellBackup.Memoization m, int arcBase, ImmutableNodeInst n) throws IOException { int myNodeId = n.nodeId; int firstIndex = m.searchConnectionByPort(myNodeId, 0); int lastIndex = firstIndex; TreeSet<ElibConnection> sortedConnections = new TreeSet<ElibConnection>(); for (; lastIndex < m.connections.length; lastIndex++) { int con = m.connections[lastIndex]; ImmutableArcInst a = m.getArcs().get(con >>> 1); boolean end = (con & 1) != 0; int nodeId = end ? a.headNodeId : a.tailNodeId; if (nodeId != myNodeId) break; PortProtoId portId = end ? a.headPortId : a.tailPortId; sortedConnections.add(new ElibConnection(portId, con)); } int numConnections = lastIndex - firstIndex; assert sortedConnections.size() == numConnections; writeBigInteger(numConnections); for (ElibConnection c: sortedConnections) { writeConnection(c.portId, arcBase + (c.con >>> 1), c.con & 1); } // write the exports int numExports = m.getNumExports(n.nodeId); writeBigInteger(numExports); // only ELIB if (numExports > 0) { // must write exports in proper order TreeMap<String,ImmutableExport> sortedExports = new TreeMap<String,ImmutableExport>(); for(Iterator<ImmutableExport> it = m.getExports(n.nodeId); it.hasNext(); ) { ImmutableExport e = it.next(); sortedExports.put(e.exportId.externalId, e); } for(ImmutableExport e: sortedExports.values()) writeReExport(e); } } private static class ElibConnection implements Comparable<ElibConnection> { private final PortProtoId portId; private final int con; private ElibConnection(PortProtoId portId, int con) { this.portId = portId; this.con = con; } public int compareTo(ElibConnection that) { int cmp = TextUtils.STRING_NUMBER_ORDER.compare(this.portId.externalId, that.portId.externalId); if (cmp != 0) return cmp; return this.con - that.con; } } void writeArcs(CellRevision cellRevision) throws IOException {// double gridScale = cellRevision.d.tech.getScale()*2/DBMath.GRID; for (int arcIndex = 0; arcIndex < cellRevision.arcs.size(); arcIndex++) { ImmutableArcInst a = cellRevision.arcs.get(arcIndex); writeTxt("**arc: " + arcIndex); // TXT only // write the arcproto pointer writeObj(a.protoId); // ELIB only writeTxt("type: " + a.protoId.fullName); // TXT only // write basic arcinst information int userBits = a.getElibBits(); long arcWidth = getSizeCorrector(a.protoId.techId).getWidthToDisk(a); writeGridCoord(cellRevision, "width: ", arcWidth); writeTxt("length: " + (int)Math.round(a.getGridLength()*getScale(cellRevision.d.techId)*2/DBMath.GRID));// writeInt("width: ", (int)Math.round(a.getGridFullWidth() * gridScale));// writeTxt("length: " + (int)Math.round(a.getGridLength() * gridScale)); writeTxt("userbits: " + userBits); // only TXT // write the arcinst tail information writeTxt("*end: 0"); writeGridCoord(cellRevision, "xpos: ", a.tailLocation.getGridX()); writeGridCoord(cellRevision, "ypos: ", a.tailLocation.getGridY());// writeInt("xpos: ", (int)Math.round(a.tailLocation.getGridX() * gridScale));// writeInt("ypos: ", (int)Math.round(a.tailLocation.getGridY() * gridScale)); writeInt("node: ", nodeIndexByNodeId[a.tailNodeId]); writeTxt("nodeport: " + a.tailPortId.getName(snapshot)); // write the arcinst head information writeTxt("*end: 1"); writeGridCoord(cellRevision, "xpos: ", a.headLocation.getGridX()); writeGridCoord(cellRevision, "ypos: ", a.headLocation.getGridY());// writeInt("xpos: ", (int)Math.round(a.headLocation.getGridX() * gridScale));// writeInt("ypos: ", (int)Math.round(a.headLocation.getGridY() * gridScale)); writeInt("node: ", nodeIndexByNodeId[a.headNodeId]); writeTxt("nodeport: " + a.headPortId.getName(snapshot)); // write the arcinst's tool information writeBigInteger(userBits); // ELIB only // write variable information and arc name writeVariables(a); } } void writeExports(CellRevision cellRevision) throws IOException { writeBigInteger(cellRevision.exports.size()); for (int exportIndex = 0; exportIndex < cellRevision.exports.size(); exportIndex++) { ImmutableExport e = cellRevision.exports.get(exportIndex); writeTxt("**porttype: " + exportIndex); // TXT only // write the connecting subnodeinst for this portproto writeInt("subnode: ", nodeIndexByNodeId[e.originalNodeId]); // write the portproto index in the subnodeinst writeObj(e.originalPortId); // ELIB only writeTxt("subport: " + e.originalPortId.getName(snapshot)); // TXT only // write the portproto name if (!(this instanceof ReadableDump)) writeString(e.name.toString()); // ELIB only writeTxt("name: " + e.name.toString()); // TXT only // write the text descriptor writeTextDescriptor(-1, e.nameDescriptor); // write the portproto tool information writeInt("userbits: ", e.getElibBits()); // write variable information writeVariables(e); } } void writeOrientation(int angle, int transpose) throws IOException { writeBigInteger(transpose); writeBigInteger(angle); } void writeConnection(PortProtoId portId, int arcIndex, int connIndex) throws IOException { writeBigInteger((arcIndex << 1) | connIndex); // write the portinst prototype writeObj(portId); // write the variable information writeNoVariables(); } void writeReExport(ImmutableExport e) throws IOException { writeObj(e.exportId); // write the portinst prototype writeObj(e.originalPortId); // write the variable information writeNoVariables(); } // --------------------------------- VARIABLES --------------------------------- /** * Method to write the global namespace. returns true upon error */ private void writeNameSpace() throws IOException { if (nameSpace.size() > Short.MAX_VALUE) { Job.getUserInterface().showErrorMessage(new String [] {"ERROR! Too many unique variable names", "The ELIB format cannot handle this many unique variables names", "Either delete the excess variables, or save to a readable dump"}, "Error saving ELIB file"); throw new IOException("Variable.Key index too large"); } writeBigInteger(nameSpace.size()); for(String str : nameSpace.keySet()) writeString(str); } /** * Method to write an empty set of variables. */ private void writeNoVariables() throws IOException { writeBigInteger(0); } /** * Method to write a set of object variables. returns negative upon error and * otherwise returns the number of variables write */ void writeVariables(ImmutableElectricObject d) throws IOException { // write the number of Variables int count = d.getNumVariables(); if (d instanceof ImmutableCell) count += ((ImmutableCell)d).getNumParameters(); else if (d instanceof ImmutableIconInst) count += ((ImmutableIconInst)d).getNumDefinedParameters(); Variable.Key additionalVarKey = null; int additionalVarType = ELIBConstants.VSTRING; TextDescriptor additionalTextDescriptor = null; Object additionalVarValue = null; if (d instanceof ImmutableNodeInst) { ImmutableNodeInst n = (ImmutableNodeInst)d; for (Iterator<PortProtoId> pit = n.getPortsWithVariables(); pit.hasNext(); ) { PortProtoId portId = pit.next(); count += n.getPortInst(portId).getNumVariables(); } additionalVarKey = NodeInst.NODE_NAME; if (n.isUsernamed()) { additionalVarType |= ELIBConstants.VDISPLAY; additionalTextDescriptor = n.nameDescriptor; } additionalVarValue = n.name.toString(); } else if (d instanceof ImmutableArcInst) { ImmutableArcInst a = (ImmutableArcInst)d; additionalVarKey = ArcInst.ARC_NAME; if (a.isUsernamed()) { additionalVarType |= ELIBConstants.VDISPLAY; additionalTextDescriptor = a.nameDescriptor; } additionalVarValue = a.name.toString(); } else if (d instanceof ImmutableLibrary) { String[] fontAssociation = createFontAssociation(); if (fontAssociation != null) { additionalVarKey = Library.FONT_ASSOCIATIONS; additionalVarType |= ELIBConstants.VISARRAY | (fontAssociation.length << ELIBConstants.VLENGTHSH); additionalVarValue = fontAssociation; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -