📄 project.java
字号:
if (!oldD.equalsExceptVariables(newD)) return true; int oldLength = oldD.getNumVariables(); int newLength = newD.getNumVariables(); int oldIndex = oldD.searchVar(PROJLOCKEDKEY); int newIndex = newD.searchVar(PROJLOCKEDKEY); if (oldLength == newLength) { if (oldIndex != newIndex) return true; if (oldIndex < 0) return variablesDiffers(oldD, 0, newD, 0, oldLength); return variablesDiffers(oldD, 0, newD, 0, oldIndex) || variablesDiffers(oldD, oldIndex + 1, newD, oldIndex + 1, oldLength - oldIndex - 1); } if (oldLength == newLength + 1) { if (oldIndex < 0 || oldIndex != ~newIndex) return true; return variablesDiffers(oldD, 0, newD, 0, oldIndex) || variablesDiffers(oldD, oldIndex + 1, newD, ~newIndex, oldLength - oldIndex - 1); } if (newLength == oldIndex + 1) { if (newIndex < 0 || newIndex != ~oldIndex) return true; return variablesDiffers(oldD, 0, newD, 0, newIndex) || variablesDiffers(oldD, newIndex, newD, newIndex + 1, newLength - newIndex - 1); } return true; } private boolean variablesDiffers(ImmutableElectricObject oldImmutable, int oldStart, ImmutableElectricObject newImmutable, int newStart, int count) { for (int i = 0; i < count; i++) if (oldImmutable.getVar(oldStart + i) != newImmutable.getVar(newStart + i)) return true; return false; } private static void queueCheck(CellId cellId, int batchNumber) { // see if the cell is already queued for(FCheck f : fCheckList) { if (f.entry == cellId && f.batchNumber == batchNumber) return; } FCheck f = new FCheck(); f.entry = cellId; f.batchNumber = batchNumber; fCheckList.add(f); } /************************ SUPPORT ***********************/ static boolean ensureRepository() { if (Project.getRepositoryLocation().length() == 0) { Job.getUserInterface().showInformationMessage( "Before entering a library, set a repository location in the 'Project Management' tab under General Preferences", "Must Setup Project Management"); return true; } return false; } static void setChangeStatus(boolean quiet) { if (quiet) ignoreChanges = quiet; Input.changesQuiet(quiet); } static void markLocked(Cell cell, boolean locked) { if (!locked) { for(Iterator<Cell> it = cell.getCellGroup().getCells(); it.hasNext(); ) { Cell oCell = it.next(); if (oCell.getView() != cell.getView()) continue; if (oCell.getVar(PROJLOCKEDKEY) != null) oCell.delVar(PROJLOCKEDKEY); } } else { for(Iterator<Cell> it = cell.getCellGroup().getCells(); it.hasNext(); ) { Cell oCell = it.next(); if (oCell.getView() != cell.getView()) continue; if (oCell.getNewestVersion() == oCell) { if (oCell.getVar(PROJLOCKEDKEY) == null) oCell.newVar(PROJLOCKEDKEY, new Integer(1)); } else { if (oCell.getVar(PROJLOCKEDKEY) != null) oCell.delVar(PROJLOCKEDKEY); } } } } /** * Method to get the latest version of the cell described by "pc" and return * the newly created cell. */ static void getCellFromRepository(ProjectDB pdb, ProjectCell pc, Library lib, boolean recursively, boolean report) { // figure out the library name ProjectLibrary pl = pc.getProjectLibrary(); String libName = pl.getProjectDirectory() + File.separator + pc.getCellName() + File.separator + pc.getVersion() + "-" + pc.getView().getFullName() + "." + pc.getLibExtension(); // read the library Cell newCell = null; String tempLibName = getTempLibraryName(); NetworkTool.setInformationOutput(false); Library fLib = LibraryFiles.readLibrary(TextUtils.makeURLToFile(libName), tempLibName, pc.getLibType(), true); NetworkTool.setInformationOutput(true); if (fLib == null) System.out.println("Cannot read library " + libName); else { String cellNameInRepository = pc.describe(); Cell cur = fLib.findNodeProto(cellNameInRepository); if (cur == null) System.out.println("Cannot find cell " + cellNameInRepository + " in library " + libName); else { // make the mapping from repository dummy cells to real cells HashMap<NodeInst,NodeProto> nodePrototypes = new HashMap<NodeInst,NodeProto>(); for(Iterator<NodeInst> it = cur.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); if (ni.isCellInstance()) { Cell subCell = (Cell)ni.getProto(); Library subLib = lib; String cellName = subCell.noLibDescribe(); Variable var = subCell.getVar(PROJLIBRARYKEY); if (var != null) { String subLibName = (String)var.getObject(); subLib = Library.findLibrary(subLibName); if (cellName.startsWith(subLibName+"__")) cellName = cellName.substring(subLibName.length()+2); if (subLib == null && recursively) { // find a new library in the repository subLib = Library.newInstance(subLibName, null); String projFile = Project.getRepositoryLocation() + File.separator + subLibName + File.separator + PROJECTFILE; File pf = new File(projFile); if (!pf.exists()) { System.out.println("Cannot find project file '" + projFile + "'...retrieve aborted."); } else { subLib.newVar(PROJPATHKEY, projFile); ProjectLibrary subPL = pdb.findProjectLibrary(subLib); // get all recent cells String userName = getCurrentUserName(); for(Iterator<ProjectCell> pIt = subPL.getProjectCells(); pIt.hasNext(); ) { ProjectCell recPC = pIt.next(); if (!recPC.isLatestVersion()) continue; if (recPC.getCell() == null) { getCellFromRepository(pdb, recPC, subLib, true, report); if (recPC.getCell() == null) System.out.println("Error retrieving cell from repository"); } if (recPC.getCell() != null) { boolean youOwn = userName.length() > 0 && recPC.getOwner().equals(userName); markLocked(recPC.getCell(), !youOwn); // CHANGES DATABASE } } } } } Cell realSubCell = null; if (subLib != null) realSubCell = subLib.findNodeProto(cellName); // if doing a recursive cell copy, see if others should be copied first if (realSubCell == null && recursively) { ProjectLibrary subPL = pdb.findProjectLibrary(subLib); ProjectCell subPC = subPL.findProjectCellByNameViewVersion(subCell.getName(), subCell.getView(), subCell.getVersion()); if (subPC == null) { // could not find that cell, see if a different version is available for(Iterator<ProjectCell> pIt = subPL.getProjectCells(); pIt.hasNext(); ) { ProjectCell oPc = pIt.next(); if (oPc.getCellName().equals(subCell.getName()) && oPc.getView() == subCell.getView()) { if (subPC != null && subPC.getVersion() > oPc.getVersion()) continue; subPC = oPc; } } } if (subPC != null) { if (subPC.getCell() != null) { System.out.println("ERROR: cell " + cellName + " does not exist, but it appears as " + subPC.getCell()); } getCellFromRepository(pdb, subPC, subLib, recursively, false); realSubCell = subPC.getCell(); } } if (realSubCell == null) { System.out.println("Cannot find subcell " + cellName + " referenced by cell " + cellNameInRepository); continue; } nodePrototypes.put(ni, realSubCell); } } String cellName = describeFullCellName(cur); if (report) System.out.println("Retrieving cell " + lib.getName() + ":" + cellName); newCell = Cell.copyNodeProtoUsingMapping(cur, lib, cellName, nodePrototypes); if (newCell == null) System.out.println("Cannot copy " + cur + " from new library"); } // kill the library fLib.kill("delete"); } // return the new cell if (newCell != null) pl.linkProjectCellToCell(pc, newCell); } static boolean useNewestVersion(Cell oldCell, Cell newCell) { // replace all instances List<NodeInst> instances = new ArrayList<NodeInst>(); for(Iterator<NodeInst> it = oldCell.getInstancesOf(); it.hasNext(); ) instances.add(it.next()); for(NodeInst ni : instances) { NodeInst newNi = ni.replace(newCell, false, false); if (newNi == null) { System.out.println("Failed to update instance of " + newCell + " in " + ni.getParent()); return true; } } // replace library references for(Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) { Library lib = it.next(); if (lib.getCurCell() == oldCell) lib.setCurCell(newCell); } // finally delete the former cell oldCell.kill(); return false; } /** * Method to save a Cell to the repository. * @param cell the Cell to save. * @param pc the ProjectCell record associated with the Cell. * @return true on error. */ static boolean writeCell(Cell cell, ProjectCell pc) { String dirName = pc.getProjectLibrary().getProjectDirectory() + File.separator + cell.getName(); File dir = new File(dirName); if (!dir.exists()) { if (!dir.mkdir()) { System.out.println("Unable to create directory " + dirName); return true; } } String libName = dirName + File.separator + cell.getVersion() + "-" + cell.getView().getFullName() + ".elib"; String tempLibName = getTempLibraryName(); Library fLib = Library.newInstance(tempLibName, TextUtils.makeURLToFile(libName)); if (fLib == null) { System.out.println("Cannot create library " + libName); return true; } Cell cellCopy = copyRecursively(cell, fLib); // CHANGES DATABASE if (cellCopy == null) { System.out.println("Could not place " + cell + " in a library"); fLib.kill("delete"); return true; } fLib.setCurCell(cellCopy); fLib.setFromDisk(); boolean error = Output.writeLibrary(fLib, pc.getLibType(), false, true, false); if (error) { System.out.println("Could not save library with " + cell + " in it"); fLib.kill("delete"); return true; } fLib.kill("delete"); return false; } static String getTempLibraryName() { for(int i=1; ; i++) { String libName = "projecttemp" + i; if (Library.findLibrary(libName) == null) return libName; } } static String describeFullCellName(Cell cell) { String cellName = cell.getName() + ";" + cell.getVersion(); if (cell.getView() != View.UNKNOWN) cellName += cell.getView().getAbbreviationExtension(); return cellName; } /** * Method to copy a Cell to a different Library, including skeleton copies of any subcells. * @param fromCell the cell to copy. * @param toLib the destination Library. * @return the Cell in that Library which was created. */ private static Cell copyRecursively(Cell fromCell, Library toLib) { Cell newFromCell = toLib.findNodeProto(fromCell.noLibDescribe()); if (newFromCell != null) return newFromCell; // must copy subcells HashMap<NodeInst,NodeProto> nodePrototypes = new HashMap<NodeInst,NodeProto>(); for(Iterator<NodeInst> it = fromCell.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); NodeProto np = ni.getProto(); nodePrototypes.put(ni, np); if (!ni.isCellInstance()) continue; Cell cell = (Cell)np; if (cell.getView().isTextView()) continue; // get proper subcell name String subCellName = describeFullCellName(cell); if (cell.getLibrary() != fromCell.getLibrary()) subCellName = cell.getLibrary().getName() + "__" + subCellName; // see if there is already a cell with this name Cell oCell = toLib.findNodeProto(subCellName); if (oCell == null) { oCell = Cell.makeInstance(toLib, subCellName); if (oCell == null) { System.out.println("Could not create subcell " + subCellName); continue; } if (cell.getLibrary() != fromCell.getLibrary()) oCell.newVar(PROJLIBRARYKEY, cell.getLibrary().getName()); if (ViewChanges.skeletonizeCell(cell, oCell)) { System.out.println("Copy of sub" + cell + " failed"); return null; } } nodePrototypes.put(ni, oCell); } // copy the cell newFromCell = Cell.copyNodeProtoUsingMapping(fromCell, toLib, describeFullCellName(fromCell), nodePrototypes); return newFromCell; } /************************ PREFERENCES ***********************/ private static Pref cacheCurrentUserName = Pref.makeStringPref("CurrentUserName", tool.prefs, ""); /** * Method to tell the name of the current user of Project Management. * The default is "". * @return the name of the current user of Project Management. */ public static String getCurrentUserName() { return cacheCurrentUserName.getString(); } /** * Method to set the name of the current user of Project Management. * @param u the name of the current user of Project Management. */ public static void setCurrentUserName(String u) { cacheCurrentUserName.setString(u); } /** * Method to tell the default name of the current user of Project Management. * @return the default name of the current user of Project Management. */ public static String getFactoryCurrentUserName() { return cacheCurrentUserName.getStringFactoryValue(); } private static Pref cacheRepositoryLocation = Pref.makeStringPref("RepositoryLocation", tool.prefs, ""); /** * Method to tell the location of the project management repository. * The default is "". * @return the location of the project management repository. */ public static String getRepositoryLocation() { return cacheRepositoryLocation.getString(); } /** * Method to set the location of the project management repository. * @param r the location of the project management repository. */ public static void setRepositoryLocation(String r) { boolean alter = getRepositoryLocation().length() > 0; cacheRepositoryLocation.setString(r); if (alter) projectDB.clearDatabase(); } /** * Method to tell the default location of the project management repository. * @return the default location of the project management repository. */ public static String getFactoryRepositoryLocation() { return cacheRepositoryLocation.getStringFactoryValue(); } private static Pref cacheAuthorizationPassword = Pref.makeStringPref("e", tool.prefs, "e"); /** * Method to tell the authorization password for administering users in Project Management. * The default is "". * @return the authorization password for administering users in Project Management. */ public static String getAuthorizationPassword() { return cacheAuthorizationPassword.getString(); } /** * Method to set the authorization password for administering users in Project Management. * @param a the authorization password for administering users in Project Management. */ public static void setAuthorizationPassword(String a) { cacheAuthorizationPassword.setString(a); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -