📄 libraryfiles.java
字号:
boolean error = in.readProjectSettings(); in.closeInput(); if (error) { System.out.println("Error reading " + lib); if (in.topLevelLibrary) mainLibDirectory = null; return null; } long endTime = System.currentTimeMillis(); float finalTime = (endTime - startTime) / 1000F; System.out.println("Library " + fileURL.getFile() + " read, took " + finalTime + " seconds"); errorLogger.termLogging(true); return in.projectSettings; } /** * Method to read a single library file. * @param fileURL the URL to the file. * @param lib the Library to read. * If the "lib" is null, this is an entry-level library read, and one is created. * If "lib" is not null, this is a recursive read caused by a cross-library * reference from inside another library. * @param type the type of library file (ELIB, CIF, GDS, etc.) * @return the read Library, or null if an error occurred. */ protected static Library readALibrary(URL fileURL, Library lib, String libName, FileType type) { // handle different file types LibraryFiles in; if (type == FileType.ELIB) { in = new ELIB(); if (in.openBinaryInput(fileURL)) return null; } else if (type == FileType.JELIB || type == FileType.DELIB) { try { LibId libId = lib != null ? lib.getId() : EDatabase.serverDatabase().getIdManager().newLibId(libName); in = new JELIB(libId, fileURL, type); } catch (IOException e) { return null; } } else if (type == FileType.READABLEDUMP) { in = new ReadableDump(); if (in.openTextInput(fileURL)) return null; } else { System.out.println("Unknown import type: " + type); return null; } // determine whether this is top-level in.topLevelLibrary = false; if (lib == null) { mainLibDirectory = TextUtils.getFilePath(fileURL); if (type == FileType.DELIB) { mainLibDirectory = mainLibDirectory.replaceAll(libName+"."+type.getExtensions()[0], ""); } in.topLevelLibrary = true; } if (lib == null) { // create a new library lib = Library.newInstance(libName, fileURL); } in.lib = lib; // read the library boolean error = in.readInputLibrary(); in.closeInput(); if (error) { System.out.println("Error reading " + lib); if (in.topLevelLibrary) mainLibDirectory = null; return null; } if (CVS.isEnabled()) { CVSLibrary.addLibrary(lib); } return in.lib; } /** * Reload a library from disk. Note this is different from calling * reloadLibraryCells(List<Cell>) with a list of Cells in the library, * because it also reloads new cells from disk that are not currently in memory. * @param lib the Library to reload. * @return mapping of Library/Cell/Export ids, null if the library was renamed. */ public static IdMapper reloadLibrary(Library lib) { if (!lib.isFromDisk()) { System.out.println("No disk file associated with this library, cannot reload from disk"); return null; } FileType type = OpenFile.getOpenFileType(lib.getLibFile().getPath(), FileType.JELIB); // rename old library, read in disk library as replacement // replace all cells in old library by newly read-in cells from disk library String name = lib.getName(); URL libFile = lib.getLibFile(); IdMapper idMapper = lib.setName("___old___"+name); if (idMapper == null) return null; lib = idMapper.get(lib.getId()).inDatabase(EDatabase.serverDatabase()); lib.setHidden(); // hide the old library startProgressDialog("library", name); Library newLib = readLibrary(libFile, name, type, true); stopProgressDialog(); // replace all old cells with new cells Cell.setAllowCircularLibraryDependences(true); for (Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { Cell oldCell = it.next(); String cellName = oldCell.getCellName().toString(); Cell newCell = newLib.findNodeProto(cellName); if (newCell == null) { // doesn't exist in new library, copy it over System.out.println("Warning, Cell "+oldCell.describe(false)+" does not exist in reloaded library. Copying it to reloaded library."); newCell = Cell.copyNodeProto(oldCell, newLib, cellName, true); } // replace all usages of old cell with new cell List<NodeInst> instances = new ArrayList<NodeInst>(); for(Iterator<NodeInst> it2 = oldCell.getInstancesOf(); it2.hasNext(); ) { instances.add(it2.next()); } for (NodeInst ni : instances) { CircuitChangeJobs.replaceNodeInst(ni, newCell, true, true); } } Cell.setAllowCircularLibraryDependences(false); // close temp library lib.kill("delete old library"); System.out.println("Reloaded library "+newLib.getName()+" from disk."); return idMapper; } /** * Reload Cells from disk. Other cells in the library will not be affected. * These cells must all be from the same library. */ public static void reloadLibraryCells(List<Cell> cellList) { if (cellList == null || cellList.size() == 0) return; Library lib = cellList.get(0).getLibrary(); if (!lib.isFromDisk()) { System.out.println("No disk file associated with this library, cannot reload from disk"); return; } FileType type = OpenFile.getOpenFileType(lib.getLibFile().getPath(), FileType.JELIB); // Load disk library as temp library. // Then, copy over new cells from temp library to replace current cells in memory, // then close temp library. String name = lib.getName(); URL libFile = lib.getLibFile(); startProgressDialog("library", name); Library newLib = readLibrary(libFile, "___reloaded___"+name, type, true); stopProgressDialog(); newLib.setHidden(); // replace all old cells with new cells Cell.setAllowCircularLibraryDependences(true); for (Cell oldCell : cellList) { String cellName = oldCell.getCellName().toString(); // contains version and view info Cell newCell = newLib.findNodeProto(cellName); if (newCell == null) { System.out.println("Cell "+oldCell.describe(false)+" cannot be reloaded, it does not exist in disk library"); continue; } // rename oldCell String renamedName = "___old___"+oldCell.getName(); IdMapper idMapper = oldCell.rename(renamedName, renamedName); // must not contain version or view info if (idMapper == null) continue; oldCell = idMapper.get(oldCell.getId()).inDatabase(EDatabase.serverDatabase()); // copy newCell over with oldCell's name newCell = Cell.copyNodeProto(newCell, lib, cellName, true); // replace all usages of old cell with new cell List<NodeInst> instances = new ArrayList<NodeInst>(); for(Iterator<NodeInst> it2 = oldCell.getInstancesOf(); it2.hasNext(); ) { instances.add(it2.next()); } for (NodeInst ni : instances) { CircuitChangeJobs.replaceNodeInst(ni, newCell, true, true); } // kill oldCell oldCell.kill(); } Cell.setAllowCircularLibraryDependences(false); // close temp library newLib.kill("delete temp library"); System.out.println("Reloaded Cells from disk."); } // *************************** THE CREATION INTERFACE *************************** public static void initializeLibraryInput() { libsBeingRead = new ArrayList<LibraryFiles>(); undefinedTechsAndPrimitives = new HashMap<TechId, Set<PrimitiveNodeId>>(); } public boolean readInputLibrary() { // add this reader to the list assert(!libsBeingRead.contains(this)); libsBeingRead.add(this); //libsBeingRead.put(lib, this); scaledCells = new ArrayList<Cell>(); try { if (readTheLibrary(false, null)) return true; Map<Cell,Variable[]> originalVars = createLibraryCells(false); realizeCellVariables(originalVars); return false; } catch (IOException e) { System.out.println("End of file reached while reading " + filePath); return true; } } abstract boolean readTheLibrary(boolean onlyProjectSettings, LibraryStatistics.FileContents fc) throws IOException; abstract Map<Cell,Variable[]> createLibraryCells(boolean onlyProjectSettings); private void realizeCellVariables(Map<Cell,Variable[]> originalVars) { HashSet<Cell.CellGroup> visitedCellGroups = new HashSet<Cell.CellGroup>(); for (Cell cell: originalVars.keySet()) { Cell.CellGroup cellGroup = cell.getCellGroup(); if (visitedCellGroups.contains(cellGroup)) continue; realizeCellVariables(cellGroup, originalVars); visitedCellGroups.add(cellGroup); } } /** * Realize cell variables on all cells of a cell group * @param cellGroup the cell group to realize variables * @param originalVars original variables from disk library */ private void realizeCellVariables(Cell.CellGroup cellGroup, Map<Cell,Variable[]> originalVars) { // Determine and create group parameters Cell cellOwner = cellGroup.getParameterOwner(); HashMap<Variable.AttrKey,Variable> groupParams = null; if (cellOwner != null) { groupParams = new HashMap<Variable.AttrKey,Variable>(); Variable[] ownerVars = originalVars.get(cellOwner); for (Variable var: ownerVars) { if (!var.getTextDescriptor().isParam()) continue; if (cellOwner.isDeprecatedVariable(var.getKey())) continue; if (var.getKey() == NccCellAnnotations.NCC_ANNOTATION_KEY) continue; var = var.withInherit(true); cellGroup.addParam(var); groupParams.put((Variable.AttrKey)var.getKey(), var); } } /** * Modify attributes of group parameters in each icon and schematic cell * Realize variables */ for (Iterator<Cell> it = cellGroup.getCells(); it.hasNext(); ) { Cell cell = it.next(); Variable[] origVars = originalVars.get(cell); if (cell.isIcon() || cell.isSchematic()) realizeCellVariables(cell, origVars, groupParams); else realizeVariables(cell, origVars); } } private void realizeCellVariables(Cell cell, Variable[] origVars, HashMap<Variable.AttrKey,Variable> groupParams) { int foundParams = 0; for (Variable var: origVars) { if (var.isAttribute()) { Variable.Key varKey = var.getKey(); Variable groupParam = groupParams.get(varKey); if (groupParam != null) { if (!var.getTextDescriptor().isParam()) { String msg = "Attribute \"" + var.getTrueName() + "\" on " + cell + " must be parameter as on " + cell.getCellGroup().getParameterOwner(); errorLogger.logError(msg, EPoint.fromLambda(var.getXOff(), var.getYOff()), cell, 2); var = var.withParam(true); } var = var.withInherit(true); if (!var.getObject().equals(groupParam.getObject())) { String msg = "Parameter \"" + var.getTrueName() + "\" has value " + var.getPureValue(-1) + " on " + cell + " instead of " + groupParam.getPureValue(-1) + " as on " + cell.getCellGroup().getParameterOwner(); errorLogger.logError(msg, EPoint.fromLambda(var.getXOff(), var.getYOff()), cell, 2); var = var.withObject(groupParam.getObject()); } if (var.getUnit() != groupParam.getUnit()) { String msg = "Parameter \"" + var.getTrueName() + "\" has unit " + var.getUnit() + " on " + cell + " instead of " + groupParam.getUnit() + " as on " + cell.getCellGroup().getParameterOwner(); errorLogger.logError(msg, EPoint.fromLambda(var.getXOff(), var.getYOff()), cell, 2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -