📄 snapshot.java
字号:
if (cellBoundsArray == null) cellBoundsArray = this.cellBounds; Snapshot snapshot = new Snapshot(idManager, idManager.newSnapshotId(), tool, cellBackups, cellGroups, groupMainSchematics, libBackups, this.techPool, cellBoundsArray);// long endTime = System.currentTimeMillis();// System.out.println("Creating snapshot took: " + (endTime - startTime) + " msec"); return snapshot; } /** * Sets cell bounds for a cell with given CellId * @param cellId given CellId * @param r cell boubds * @throws IllegalArgumentException if snapshot has not cell with given cellId or on bounds conflict. */ public void setCellBounds(CellId cellId, ERectangle r) { if (r == null) throw new NullPointerException(); CellBackup cellBackup = getCell(cellId); if (cellBackup == null) throw new IllegalArgumentException(); int cellIndex = cellId.cellIndex; ERectangle oldR = cellBounds[cellIndex]; if (oldR != null && oldR != r) throw new IllegalArgumentException(); cellBounds[cellIndex] = r; }// private void checkUsedLibs(BitSet usedLibs) {// if (usedLibs.isEmpty()) return;// int usedLibsLength = usedLibs.length();// if (usedLibsLength > libBackups.size())// throw new IllegalArgumentException("usedLibsLength");// for (int libIndex = 0; libIndex < usedLibsLength; libIndex++) {// if (usedLibs.get(libIndex) && libBackups.get(libIndex) == null)// throw new IllegalArgumentException("usedLibs");// }// } private static <T> ImmutableArrayList<T> copyArray(T[] newArray, ImmutableArrayList<T> oldList) { if (newArray == null) return oldList; int l; for (l = newArray.length; l > 0 && newArray[l - 1] == null; l--); if (l == oldList.size()) { int i = 0; while (i < oldList.size() && newArray[i] == oldList.get(i)) i++; if (i == l) return oldList; } return new ImmutableArrayList<T>(newArray, 0, l); }// private static int[] copyArray(int[] newArray, int[] oldArray) {// if (newArray == null) return oldArray;// int l;// for (l = newArray.length; l > 0 && newArray[l - 1] < 0; l--);// if (l == oldArray.length) {// int i = 0;// while (i < oldArray.length && newArray[i] == oldArray[i]) i++;// if (i == l) return oldArray;// }// int[] copyArray = new int[l];// System.arraycopy(newArray, 0, copyArray, 0, l);// if (l > 0 && copyArray[l - 1] < 0)// throw new ConcurrentModificationException();// return copyArray;// } /** * Returns Snapshot which differs from this Snapshot by renamed Ids. * @param idMapper a map from old Ids to new Ids. * @return Snapshot with renamed Ids. */ public Snapshot withRenamedIds(IdMapper idMapper, CellId fromGroup, String toGroup) { int maxCellIndex = -1; for (CellBackup cellBackup: cellBackups) { if (cellBackup == null) continue; maxCellIndex = Math.max(maxCellIndex, idMapper.get(cellBackup.cellRevision.d.cellId).cellIndex); } int maxLibIndex = -1; for (LibraryBackup libBackup: libBackups) { if (libBackup == null) continue; maxLibIndex = Math.max(maxLibIndex, idMapper.get(libBackup.d.libId).libIndex); } CellBackup[] cellBackupsArray = new CellBackup[maxCellIndex + 1]; ERectangle[] cellBoundsArray = new ERectangle[maxCellIndex + 1]; LibraryBackup[] libBackupsArray = new LibraryBackup[maxLibIndex + 1]; BitSet cellBackupsChangedInLib = new BitSet(); boolean cellIdsChanged = false; BitSet fromGroupCellIds = new BitSet(); BitSet toGroupCellIds = new BitSet(); CellName fromGroupName = null; CellName toGroupName = null; if (fromGroup != null) { assert getCell(fromGroup) != null; CellId toGroupCellId = idMapper.get(fromGroup); assert toGroupCellId != null; assert getCell(toGroupCellId) == null; int fromGroupIndex = cellGroups[fromGroup.cellIndex]; assert fromGroupIndex >= 0; int toGroupIndex1 = -1, toGroupIndex2 = -1; if (toGroup == null) toGroupIndex2 = fromGroupIndex; for (int cellIndex = 0; cellIndex < cellBackups.size(); cellIndex++) { CellBackup cellBackup = cellBackups.get(cellIndex); if (cellBackup == null) continue; CellId cellId = cellBackup.cellRevision.d.cellId; if (cellId.libId == fromGroup.libId) { if (cellId.cellName.getName().equals(toGroupCellId.cellName.getName())) toGroupIndex1 = cellGroups[cellIndex]; if (toGroup != null && cellId.cellName.getName().equals(toGroup)) toGroupIndex2 = cellGroups[cellIndex]; } } ArrayList<CellName> fromCellNames = new ArrayList<CellName>(); ArrayList<CellName> toCellNames = new ArrayList<CellName>(); toGroupCellIds.set(toGroupCellId.cellIndex); toCellNames.add(toGroupCellId.cellName); for (int cellIndex = 0; cellIndex < cellBackups.size(); cellIndex++) { CellBackup cellBackup = cellBackups.get(cellIndex); if (cellBackup == null || cellIndex == fromGroup.cellIndex) continue; CellId cellId = cellBackup.cellRevision.d.cellId; if (cellGroups[cellIndex] == fromGroupIndex) { fromGroupCellIds.set(cellIndex); fromCellNames.add(cellId.cellName); } if (cellGroups[cellIndex] == toGroupIndex1 || cellGroups[cellIndex] == toGroupIndex2) { toGroupCellIds.set(cellIndex); toCellNames.add(cellId.cellName); } } if (!fromCellNames.isEmpty()) fromGroupName = makeCellGroupName(fromCellNames); if (!toCellNames.isEmpty()) toGroupName = makeCellGroupName(toCellNames); } for (int cellIndex = 0; cellIndex < cellBackups.size(); cellIndex++) { CellBackup oldCellBackup = cellBackups.get(cellIndex); if (oldCellBackup == null) continue; CellName newGroupName = oldCellBackup.cellRevision.d.groupName; if (fromGroup != null) { if (toGroupCellIds.get(cellIndex) || cellIndex == fromGroup.cellIndex) newGroupName = toGroupName; else if (fromGroupCellIds.get(cellIndex)) newGroupName = fromGroupName; } CellBackup newCellBackup = oldCellBackup.withRenamedIds(idMapper, newGroupName); if (newCellBackup != oldCellBackup) cellBackupsChangedInLib.set(newCellBackup.cellRevision.d.cellId.libId.libIndex); int newCellIndex = newCellBackup.cellRevision.d.cellId.cellIndex; if (newCellIndex != cellIndex) cellIdsChanged = true; cellBackupsArray[newCellIndex] = newCellBackup; cellBoundsArray[newCellIndex] = this.cellBounds[cellIndex]; } if (cellBackupsChangedInLib.isEmpty()) cellBackupsArray = null; if (!cellIdsChanged) cellBoundsArray = null; boolean libBackupsChanged = false; for (int libIndex = 0; libIndex < libBackups.size(); libIndex++) { LibraryBackup oldLibBackup = libBackups.get(libIndex); if (oldLibBackup == null) continue; LibraryBackup newLibBackup = oldLibBackup.withRenamedIds(idMapper); if (cellBackupsChangedInLib.get(libIndex)) newLibBackup = newLibBackup.withModified(); if (newLibBackup != oldLibBackup) libBackupsChanged = true; libBackupsArray[newLibBackup.d.libId.libIndex] = newLibBackup; } if (!libBackupsChanged) libBackupsArray = null; if (cellBackupsArray == null && cellBounds == null && libBackups == null) return this; return with(tool, cellBackupsArray, cellBoundsArray, libBackupsArray); } public List<LibId> getChangedLibraries(Snapshot oldSnapshot) { if (oldSnapshot == null) oldSnapshot = idManager.getInitialSnapshot(); if (idManager != oldSnapshot.idManager) throw new IllegalArgumentException(); List<LibId> changed = null; if (oldSnapshot.libBackups != libBackups) { int numLibs = Math.max(oldSnapshot.libBackups.size(), libBackups.size()); for (int i = 0; i < numLibs; i++) { LibraryBackup oldBackup = oldSnapshot.getLib(i); LibraryBackup newBackup = getLib(i); if (oldBackup == newBackup) continue; if (changed == null) changed = new ArrayList<LibId>(); changed.add(idManager.getLibId(i)); } } if (changed == null) changed = Collections.emptyList(); return changed; } public List<CellId> getChangedCells(Snapshot oldSnapshot) { if (oldSnapshot == null) oldSnapshot = idManager.getInitialSnapshot(); List<CellId> changed = null; int numCells = Math.max(oldSnapshot.cellBackups.size(), cellBackups.size()); for (int i = 0; i < numCells; i++) { CellBackup oldBackup = oldSnapshot.getCell(i); CellBackup newBackup = getCell(i); if (oldBackup == newBackup) continue; if (changed == null) changed = new ArrayList<CellId>(); changed.add(idManager.getCellId(i)); } if (changed == null) changed = Collections.emptyList(); return changed; } public Collection<CellId> getCellsDownTop() { LinkedHashSet<CellId> order = new LinkedHashSet<CellId>(); for (CellBackup cellBackup: cellBackups) { if (cellBackup == null) continue; getCellsDownTop(cellBackup.cellRevision.d.cellId, order); } return order; } private void getCellsDownTop(CellId root, LinkedHashSet<CellId> order) { if (order.contains(root)) return; CellBackup cellBackup = getCell(root); CellRevision cellRevision = cellBackup.cellRevision; for (int i = 0; i < cellRevision.cellUsages.length; i++) { if (cellRevision.cellUsages[i] == null) continue; CellUsage cu = root.getUsageIn(i); getCellsDownTop(cu.protoId, order); } boolean added = order.add(root); assert added; } public CellBackup getCell(CellId cellId) { if (cellId.getIdManager() != idManager) throw new IllegalArgumentException(); return getCell(cellId.cellIndex); } public CellRevision getCellRevision(CellId cellId) { CellBackup cellBackup = getCell(cellId); return cellBackup != null ? cellBackup.cellRevision : null; } public CellBackup getCell(int cellIndex) { return cellIndex < cellBackups.size() ? cellBackups.get(cellIndex) : null; } public CellRevision getCellRevision(int cellIndex) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -