📄 snapshot.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: Snapshot.java * Written by: Dmitry Nadezhin, Sun Microsystems. * * Copyright (c) 2005 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.database;import com.sun.electric.database.geometry.ERectangle;import com.sun.electric.database.id.CellId;import com.sun.electric.database.id.CellUsage;import com.sun.electric.database.id.IdManager;import com.sun.electric.database.id.IdReader;import com.sun.electric.database.id.IdWriter;import com.sun.electric.database.id.LibId;import com.sun.electric.database.id.TechId;import com.sun.electric.database.text.CellName;import com.sun.electric.database.text.ImmutableArrayList;import com.sun.electric.database.text.TextUtils;import com.sun.electric.technology.TechPool;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Artwork;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.technology.technologies.Schematics;import com.sun.electric.tool.Job;import com.sun.electric.tool.Tool;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.BitSet;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.HashSet;import java.util.LinkedHashSet;import java.util.List;/** * */public class Snapshot { public final IdManager idManager; public final int snapshotId; public final Tool tool; public final ImmutableArrayList<CellBackup> cellBackups; public final int[] cellGroups; public final CellId[] groupMainSchematics; public final ImmutableArrayList<LibraryBackup> libBackups; public final TechPool techPool; private final ERectangle[] cellBounds; /** Creates a new instance of Snapshot */ private Snapshot(IdManager idManager, int snapshotId, Tool tool, ImmutableArrayList<CellBackup> cellBackups, int[] cellGroups, CellId[] groupMainSchematics, ImmutableArrayList<LibraryBackup> libBackups, TechPool techPool, ERectangle[] cellBounds) { this.idManager = idManager; this.snapshotId = snapshotId; this.tool = tool; this.cellBackups = cellBackups; this.cellGroups = cellGroups; this.groupMainSchematics = groupMainSchematics; this.libBackups = libBackups; this.techPool = techPool; this.cellBounds = new ERectangle[cellBackups.size()]; for (int cellIndex = 0; cellIndex < cellBounds.length; cellIndex++) { ERectangle r = cellBounds[cellIndex]; if (r == null) continue; if (cellBackups.get(cellIndex) == null) throw new IllegalArgumentException(); this.cellBounds[cellIndex] = r; }// if (Job.getDebug())// check(); } /** * Creates empty snapshot. */ public Snapshot(IdManager idManager) { this(idManager, 0, null, CellBackup.EMPTY_LIST, new int[0], new CellId[0], LibraryBackup.EMPTY_LIST, idManager.getInitialTechPool(), ERectangle.NULL_ARRAY); } /** * Creates a new instance of Snapshot which differs from this Snapshot by TechPool. * New TechPool must be extension of old TechPool * @param techPool new Technology pool * @return new snapshot which differs froms this Snapshot by TechPool * @throws IllegalArgumentException if new TechPool isn't extension of old TechPool. */ public Snapshot withTechPool(TechPool techPool) { if (this.techPool == techPool) return this; CellBackup[] cellBackupArray = cellBackups.toArray(new CellBackup[cellBackups.size()]); for (int cellIndex = 0; cellIndex < cellBackupArray.length; cellIndex++) { CellBackup cellBackup = cellBackups.get(cellIndex); if (cellBackup == null) continue; cellBackupArray[cellIndex] = cellBackup.withTechPool(techPool); } return new Snapshot(idManager, idManager.newSnapshotId(), this.tool, new ImmutableArrayList(cellBackupArray), this.cellGroups, this.groupMainSchematics, this.libBackups, techPool, this.cellBounds); } /** * Creates a new instance of Snapshot which differs from this Snapshot. * Four array parameters are supplied. Each parameter may be null if its contents is the same as in this Snapshot. * @param tool tool which initiated database changes/ * @param cellBackupsArray array indexed by cellIndex of new CellBackups. * @param cellBoundsArray array indexed by cellIndex of cell bounds. * @param libBackupsArray array indexed by libIndex of LibraryBackups. * @return new snapshot which differs froms this Snapshot or this Snapshot. * @throws IllegalArgumentException on invariant violation. * @throws ArrayOutOfBoundsException on some invariant violations. */ public Snapshot with(Tool tool, CellBackup[] cellBackupsArray, ERectangle[] cellBoundsArray, LibraryBackup[] libBackupsArray) {// long startTime = System.currentTimeMillis(); ImmutableArrayList<CellBackup> cellBackups = copyArray(cellBackupsArray, this.cellBackups); ImmutableArrayList<LibraryBackup> libBackups = copyArray(libBackupsArray, this.libBackups); boolean namesChanged = this.libBackups != libBackups || this.cellBackups.size() != cellBackups.size(); if (!namesChanged && this.cellBackups == cellBackups) { if (cellBoundsArray != null) { for (int cellIndex = 0; cellIndex < cellBoundsArray.length; cellIndex++) { ERectangle r = cellBoundsArray[cellIndex]; if (r == null) continue; setCellBounds(cellBackups.get(cellIndex).cellRevision.d.cellId, r); } } return this; } // Check usages in cells boolean needCheckRecursion = false; BitSet newUsedTechs = new BitSet(); for (int cellIndex = 0; cellIndex < cellBackups.size(); cellIndex++) { CellBackup newBackup = cellBackups.get(cellIndex); CellRevision newRevision = null; CellBackup oldBackup = getCell(cellIndex); CellId cellId; if (newBackup != null) { newRevision = newBackup.cellRevision; if (oldBackup == null || newRevision.d.groupName != oldBackup.cellRevision.d.groupName || newRevision.d.params != oldBackup.cellRevision.d.params) namesChanged = true; // If usages changed, check CellUsagesIn. newUsedTechs.or(newRevision.techUsages); cellId = newRevision.d.cellId; if (oldBackup == null || newRevision.cellUsages != oldBackup.cellRevision.cellUsages) { needCheckRecursion = true; for (int i = 0; i < newRevision.cellUsages.length; i++) { CellRevision.CellUsageInfo cui = newRevision.cellUsages[i]; if (cui == null) continue; if (oldBackup != null) { CellRevision oldRevision = oldBackup.cellRevision; if (i < oldRevision.cellUsages.length) { CellRevision.CellUsageInfo oldCui = oldRevision.cellUsages[i]; if (oldCui != null && cui.usedExports == oldCui.usedExports) continue; } } CellUsage u = cellId.getUsageIn(i); CellRevision protoRevision = cellBackups.get(u.protoId.cellIndex).cellRevision; cui.checkUsage(protoRevision); } } } else { if (oldBackup == null) continue; cellId = oldBackup.cellRevision.d.cellId; namesChanged = true; } // If some exports deleted or parameters changed, check CellUsagesOf if (oldBackup == null) continue; CellRevision oldRevision = oldBackup.cellRevision; if (newRevision != null && newRevision.definedExportsLength >= oldRevision.definedExportsLength && (newRevision.deletedExports == oldRevision.deletedExports || !newRevision.deletedExports.intersects(oldRevision.definedExports)) && newRevision.d.params == oldRevision.d.params) continue; for (int i = 0, numUsages = cellId.numUsagesOf(); i < numUsages; i++) { CellUsage u = cellId.getUsageOf(i); int parentCellIndex = u.parentId.cellIndex; if (parentCellIndex >= cellBackups.size()) continue; CellBackup parentBackup = cellBackups.get(parentCellIndex); if (parentBackup == null) continue; CellRevision parentRevision = parentBackup.cellRevision; if (u.indexInParent >= parentRevision.cellUsages.length) continue; CellRevision.CellUsageInfo cui = parentRevision.cellUsages[u.indexInParent]; if (cui == null) continue; cui.checkUsage(newBackup.cellRevision); } } if (needCheckRecursion) checkRecursion(cellBackups); for (int techIndex = 0; techIndex < newUsedTechs.length(); techIndex++) { if (!newUsedTechs.get(techIndex)) continue; TechId techId = idManager.getTechId(techIndex); if (techPool.getTech(techId) == null) throw new IllegalArgumentException(); } // Check names int[] cellGroups = this.cellGroups; CellId[] groupMainSchematics = this.groupMainSchematics; if (namesChanged) { cellGroups = new int[cellBackups.size()]; checkNames(idManager, cellBackups, cellGroups, libBackups); if (Arrays.equals(this.cellGroups, cellGroups)) { cellGroups = this.cellGroups; } else { int maxGroup = -1; for (int groupIndex: cellGroups) maxGroup = Math.max(maxGroup, groupIndex); groupMainSchematics = new CellId[maxGroup + 1]; 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.isSchematic()) continue; int groupIndex = cellGroups[cellIndex]; CellId mainSchematics = groupMainSchematics[groupIndex]; if (mainSchematics == null || cellId.cellName.compareTo(mainSchematics.cellName) < 0) groupMainSchematics[groupIndex] = cellId; } if (Arrays.equals(this.groupMainSchematics, groupMainSchematics)) groupMainSchematics = this.groupMainSchematics; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -