📄 library.java
字号:
/** * Method to indicate that this Library is hidden. * Hidden libraries are not seen by the user. * For example, the "clipboard" library is hidden because it is only used * internally for copying and pasting circuitry. */ public void setHidden() { setFlag(HIDDENLIBRARY, true); } /** * Method to indicate that this Library is not hidden. * Hidden libraries are not seen by the user. * For example, the "clipboard" library is hidden because it is only used * internally for copying and pasting circuitry. */ public void clearHidden() { setFlag(HIDDENLIBRARY, false); } /** * Method to return true if this Library is hidden. * Hidden libraries are not seen by the user. * For example, the "clipboard" library is hidden because it is only used * internally for copying and pasting circuitry. * @return true if this Library is hidden. */ public boolean isHidden() { return isFlag(HIDDENLIBRARY); } /** * Method to return the current Library. * @return the current Library. */ public static Library getCurrent() { return curLib; } /** * Method to make this the current Library. */ public void setCurrent() { curLib = this; } /** * Method to get the Preferences associated with this Library. * @return the Preferences associated with this Library. */ public Pref.Group getPrefs() { return prefsGroup; } /** * Low-level method to get the user bits. * The "user bits" are a collection of flags that are more sensibly accessed * through special methods. * This general access to the bits is required because the ELIB * file format stores it as a full integer. * This should not normally be called by any other part of the system. * @return the "user bits". */ public int lowLevelGetUserBits() { return d.flags; } /** * Low-level method to set the user bits. * The "user bits" are a collection of flags that are more sensibly accessed * through special methods. * This general access to the bits is required because the ELIB * file format stores it as a full integer. * This should not normally be called by any other part of the system. * @param userBits the new "user bits". */ public void lowLevelSetUserBits(int userBits) { setD(d.withFlags(userBits)); } /** * Get list of cells contained in other libraries * that refer to cells contained in this library * @param elib to search for * @return list of cells refering to elements in this library */ public static Set<Cell> findReferenceInCell(Library elib) { return EDatabase.theDatabase.findReferenceInCell(elib); } /** * Method to find a Library with the specified name. * @param libName the name of the Library. * Note that this is the Library name, and not the Library file. * @return the Library, or null if there is no known Library by that name. */ public static Library findLibrary(String libName) { return EDatabase.theDatabase.findLibrary(libName); } /** * Method to return an iterator over all libraries. * @return an iterator over all libraries. */ public static Iterator<Library> getLibraries() { return EDatabase.theDatabase.getLibraries(); } /** * Method to return the number of libraries. * @return the number of libraries. */ public static int getNumLibraries() { return EDatabase.theDatabase.getNumLibraries(); } /** * Method to return an iterator over all visible libraries. * @return an iterator over all visible libraries. */ public static List<Library> getVisibleLibraries() { return EDatabase.theDatabase.getVisibleLibraries(); } /** * Method to return the name of this Library. * @return the name of this Library. */ public String getName() { return d.libId.libName; } /** * Method to set the name of this Library. * @param libName the new name of this Library. * @return mapping of Library/Cell/Export ids, null if the library was renamed. */ public IdMapper setName(String libName) { if (d.libId.libName.equals(libName)) return null; // make sure the name is legal if (LibId.legalLibraryName(libName) != libName) { System.out.println("Error: '"+libName+"' is not a valid name"); return null; } Library already = findLibrary(libName); if (already != null) { System.out.println("Already a library called " + already.getName()); return null; } Snapshot oldSnapshot = database.backup(); LibId newLibId = oldSnapshot.idManager.newLibId(libName); IdMapper idMapper = IdMapper.renameLibrary(oldSnapshot, d.libId, newLibId); Snapshot newSnapshot = oldSnapshot.withRenamedIds(idMapper, null, null); LibraryBackup[] libBackups = newSnapshot.libBackups.toArray(new LibraryBackup[newSnapshot.libBackups.size()]); LibraryBackup libBackup = libBackups[newLibId.libIndex]; String newLibFile = TextUtils.getFilePath(d.libFile) + libName; String extension = TextUtils.getExtension(d.libFile); if (extension.length() > 0) newLibFile += "." + extension; URL libFile = TextUtils.makeURLToFile(newLibFile); libBackups[newLibId.libIndex] = new LibraryBackup(libBackup.d.withLibFile(libFile), true, libBackup.referencedLibs); newSnapshot = newSnapshot.with(null, null, null, libBackups); checkChanging(); boolean isCurrent = getCurrent() == this; database.lowLevelSetCanUndoing(true); database.undo(newSnapshot); database.lowLevelSetCanUndoing(false); Constraints.getCurrent().renameIds(idMapper); Library newLib = database.getLib(newLibId); if (isCurrent) newLib.setCurrent(); return idMapper;// String oldName = d.libId.libName;// lowLevelRename(libName);// Constraints.getCurrent().renameObject(this, oldName);//// setChanged();// assert isLinked();// database.unfreshSnapshot();// for (Cell cell: cells.values())// cell.notifyRename();// return this; }// /**// * Method to rename this Library.// * This method is for low-level use by the database, and should not be called elsewhere.// * @param libName the new name of the Library.// */// private void lowLevelRename(String libName)// {// String newLibFile = TextUtils.getFilePath(d.libFile) + libName;// String extension = TextUtils.getExtension(d.libFile);// if (extension.length() > 0) newLibFile += "." + extension;// URL libFile = TextUtils.makeURLToFile(newLibFile);//// database.libraries.remove(d.libName);// setD(d.withName(libName, libFile));// database.libraries.put(libName, this);// assert isLinked();// database.unfreshSnapshot();//// Cell curCell = getCurCell();// prefs = allPrefs.node(libName);// prefs.put("LIB", libName);// curCellPref = null;// setCurCell(curCell);// for (Iterator<Cell> it = getCells(); it.hasNext(); ) {// Cell cell = it.next();// cell.expandStatusChanged();// }// } /** * Method to return the URL of this Library. * @return the URL of this Library. */ public URL getLibFile() { return d.libFile; } /** * Method to set the URL of this Library. * @param libFile the new URL of this Library. */ public void setLibFile(URL libFile) { setD(d.withLibFile(libFile)); } /** * Compares two <code>Library</code> objects. * @param that the Library to be compared. * @return the result of comparison. */ public int compareTo(Library that) { return TextUtils.STRING_NUMBER_ORDER.compare(getName(), that.getName()); } /** * Returns a printable version of this Library. * @return a printable version of this Library. */ public String toString() { return "library '" + getName() + "'"; } // ----------------- cells -------------------- private void getCurCellPref() { if (curCellPref == null) { curCellPref = Pref.makeStringPref("CurrentCell", getPrefs(), ""); } } /** * Method to get the current Cell in this Library. * @return the current Cell in this Library. * Returns NULL if there is no current Cell. */ public Cell getCurCell() { getCurCellPref(); String cellName = curCellPref.getString(); if (cellName.length() == 0) return null; Cell cell = this.findNodeProto(cellName); if (cell == null) curCellPref.setString(""); return cell; } /** * Method to set the current Cell in this Library. * @param curCell the new current Cell in this Library. */ public void setCurCell(Cell curCell) { getCurCellPref(); String cellName = ""; if (curCell != null) cellName = curCell.noLibDescribe(); curCellPref.setString(cellName); } /** * Method to save isExpanded status of NodeInsts in this Library to Preferences. */ public static void saveExpandStatus() throws BackingStoreException { for (Iterator<Library> lit = getLibraries(); lit.hasNext(); ) { Library lib = lit.next(); for (Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { Cell cell = it.next(); cell.saveExpandStatus(); } lib.prefs.flush(); } } public static Cell findCellInLibraries(String cellName, View view, String libraryName) { if (libraryName != null) { Library lib = findLibrary(libraryName); if (lib != null) { Cell cell = lib.findNodeProto(cellName); // Either first match in name or check that view matches if (cell != null && (view == null || cell.getView() == view)) return cell; } // search in other libraries if no library is found with given name } for (Iterator<Library> it = Library.getLibraries(); it.hasNext();) { Library lib = it.next(); Cell cell = lib.findNodeProto(cellName); // Either first match in name or check that view matches if (cell != null && (view == null || cell.getView() == view)) return cell; } return null; } /** * Method to find the Cell with the given name in this Library. * @param name the name of the desired Cell. * @return the Cell with the given name in this Library. */ public Cell findNodeProto(String name) { if (name == null) return null; CellName n = CellName.parseName(name); if (n == null) return null; synchronized (cells) { Cell cell = cells.get(n); if (cell != null) return cell; Cell onlyWithName = null; for (Cell c : cells.values()) { if (!n.getName().equals(c.getName())) continue;// if (!n.getName().equalsIgnoreCase(c.getName())) continue; onlyWithName = c; if (n.getView() != c.getView()) continue; if (n.getVersion() > 0 && n.getVersion() != c.getVersion()) continue; if (n.getVersion() == 0 && c.getNewestVersion() != c) continue; return c; } if (n.getView() == View.UNKNOWN && onlyWithName != null) return onlyWithName; } return null; } public int getNumCells() { synchronized(cells) { return cells.size(); } } /** * Method to return an Iterator over all Cells in this Library. * @return an Iterator over all Cells in this Library. */ public Iterator<Cell> getCells() { synchronized(cells) { ArrayList<Cell> cellsCopy = new ArrayList<Cell>(cells.values()); return cellsCopy.iterator(); } } /** * Method to return an Iterator over all Cells in this Library after given CellName. * @param cn starting CellName * @return an Iterator over all Cells in this Library after given CellName. */ Iterator<Cell> getCellsTail(CellName cn) { synchronized(cells) { return cells.tailMap(cn).values().iterator(); } } /** * Returns verison of Electric which wrote this library. * Returns null for ReadableDumps, for new libraries and for dummy libraries. * @return version */ public Version getVersion() { return d.version; } /** * Method to set library version found in header. * @param version */ public void setVersion(Version version) { setD(d.withVersion(version)); } /** * Returns DELIB cell files. * @return DELIB cell files. */ public Set<String> getDelibCellFiles() { return delibCellFiles; } /** * Sets DELIB cell files. * @param delibCellFiles DELIB cell files. */ public void setDelibCellFiles(HashSet<String> delibCellFiles) { this.delibCellFiles.clear(); this.delibCellFiles.addAll(delibCellFiles); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -