📄 netschem.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: NetSchem.java * Written by: Dmitry Nadezhin, Sun Microsystems. * * Copyright (c) 2003 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.network;import com.sun.electric.database.geometry.GenMath;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.hierarchy.Nodable;import com.sun.electric.database.prototype.NodeProto;import com.sun.electric.database.prototype.PortCharacteristic;import com.sun.electric.database.prototype.PortProto;import com.sun.electric.database.text.Name;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.Connection;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.topology.PortInst;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.ArcProto;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.technologies.Schematics;import java.util.Arrays;import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Map;import java.util.Set;/** * This is the mirror of group of Icon and Schematic cells in Network tool. */class NetSchem extends NetCell { static void updateCellGroup(Cell.CellGroup cellGroup) { NetworkManager mgr = cellGroup.getDatabase().getNetworkManager(); Cell mainSchematics = cellGroup.getMainSchematics(); NetSchem mainSchem = null; if (mainSchematics != null) mainSchem = (NetSchem)mgr.getNetCell(mainSchematics); for (Iterator<Cell> it = cellGroup.getCells(); it.hasNext();) { Cell cell = it.next(); if (cell.isIcon()) { NetSchem icon = (NetSchem)mgr.getNetCell(cell); if (icon == null) continue; icon.setImplementation(mainSchem != null ? mainSchem : icon); } } } private class Proxy implements Nodable { NodeInst nodeInst; int arrayIndex; int nodeOffset; Proxy(NodeInst nodeInst, int arrayIndex) { this.nodeInst = nodeInst; this.arrayIndex = arrayIndex; } /** * Method to return the prototype of this Nodable. * @return the prototype of this Nodable. */ public NodeProto getProto() { NetSchem schem = networkManager.getNetCell((Cell)nodeInst.getProto()).getSchem(); return schem.cell; } /** * Method to tell whether this is a cell instance. * @return true becaue NetSchem objects are always cell instances. */ public boolean isCellInstance() { return true; } /** * Method to return the Cell that contains this Nodable. * @return the Cell that contains this Nodable. */ public Cell getParent() { return cell; } /** * Method to return the name of this Nodable. * @return the name of this Nodable. */ public String getName() { return getNameKey().toString(); } /** * Method to return the name key of this Nodable. * @return the name key of this Nodable. */ public Name getNameKey() { return nodeInst.getNameKey().subname(arrayIndex); } /** * Method to return the Variable on this ElectricObject with a given key. * @param key the key of the Variable. * @return the Variable with that key, or null if there is no such Variable. */ public Variable getVar(Variable.Key key) { return nodeInst.getVar(key); }// /**// * Method to return an iterator over all Variables on this Nodable.// * @return an iterator over all Variables on this Nodable.// */// public Iterator<Variable> getVariables() { return nodeInst.getVariables(); } /** * Method to return the Parameter on this Nodable with the given key. * If the parameter is not found on this Nodable, it * is also searched for on the default var owner. * @param key the key of the parameter * @return the Parameter with that key, that may exist either on this Nodable * or the default owner. Returns null if none found. */ public Variable getParameter(Variable.Key key) { return nodeInst.getParameter(key); } /** * Method to return the Parameter or Variable on this Nodable with a given key. * @param key the key of the Parameter or Variable. * @return the Parameter or Variable with that key, or null if there is no such Parameter or Variable Variable. * @throws NullPointerException if key is null */ public Variable getParameterOrVariable(Variable.Key key) { return nodeInst.getParameterOrVariable(key); } /** * Method to tell if the Variable.Key is a defined parameters of this Nodable. * Parameters which are not defined on Nodable take default values from Icon Cell. * @param key the key of the parameter * @return true if the key is a definded parameter of this Nodable */ public boolean isDefinedParameter(Variable.Key key) { return nodeInst.isDefinedParameter(key); } /** * Method to return an Iterator over all Parameters on this Nodable. * This may also include any Parameters on the defaultVarOwner object that are not on this Nodable. * @return an Iterator over all Parameters on this Nodable. */ public Iterator<Variable> getParameters() { return nodeInst.getParameters(); } /** * Method to return an Iterator over defined Parameters on this Nodable. * This doesn't include any Parameters on the defaultVarOwner object that are not on this Nodable. * @return an Iterator over defined Parameters on this Nodable. */ public Iterator<Variable> getDefinedParameters() { return nodeInst.getDefinedParameters(); } /** * Returns a printable version of this Nodable. * @return a printable version of this Nodable. */ public String toString() { return "NetSchem.Proxy " + getName(); } // JKG: trying this out public boolean contains(NodeInst ni, int arrayIndex) { if (nodeInst == ni && this.arrayIndex == arrayIndex) return true; return false; } public NodeInst getNodeInst() { return nodeInst; } } /* Implementation of this NetSchem. */ NetSchem implementation; /* Mapping from ports of this to ports of implementation. */ int[] portImplementation; /** Node offsets. */ int[] nodeOffsets; /** Node offsets. */ int[] drawnOffsets; /** Node offsets. */ Proxy[] nodeProxies; /** Proxies with global rebindes. */ Map<Proxy,Set<Global>> proxyExcludeGlobals; /** Map from names to proxies. Contains non-temporary names. */ Map<Name,Proxy> name2proxy = new HashMap<Name,Proxy>(); /** */ Global.Set globals = Global.Set.empty; /** */ int[] portOffsets = new int[1]; /** */ int netNamesOffset; /** */ Name[] drawnNames; /** */ int[] drawnWidths; NetSchem(Cell cell) { super(cell); setImplementation(this); updateCellGroup(cell.getCellGroup()); }// NetSchem(Cell.CellGroup cellGroup) {// super(cellGroup.getMainSchematics());// } private void setImplementation(NetSchem implementation) { if (this.implementation == implementation) return; this.implementation = implementation; updatePortImplementation(); } private boolean updatePortImplementation() { boolean changed = false; int numPorts = cell.getNumPorts(); if (portImplementation == null || portImplementation.length != numPorts) { changed = true; portImplementation = new int[numPorts]; } Cell c = implementation.cell; for (int i = 0; i < numPorts; i++) { Export e = cell.getPort(i); int equivIndex = -1; if (c != null) { Export equiv = e.getEquivalentPort(c); if (equiv != null) equivIndex = equiv.getPortIndex(); } if (portImplementation[i] != equivIndex) { changed = true; portImplementation[i] = equivIndex; } if (equivIndex < 0) { String msg = cell + ": Icon port <"+e.getNameKey()+"> has no equivalent port"; System.out.println(msg); networkManager.pushHighlight(e); networkManager.logError(msg, NetworkTool.errorSortPorts); } } if (c != null && numPorts != c.getNumPorts()) { for (int i = 0; i < c.getNumPorts(); i++) { Export e = c.getPort(i); if (e.getEquivalentPort(cell) == null) { String msg = c + ": Schematic port <"+e.getNameKey()+"> has no equivalent port in " + cell; System.out.println(msg); networkManager.pushHighlight(e); networkManager.logError(msg, NetworkTool.errorSortPorts); } } } return changed; } @Override int getPortOffset(int portIndex, int busIndex) { portIndex = portImplementation[portIndex]; if (portIndex < 0) return -1; int portOffset = implementation.portOffsets[portIndex] + busIndex; if (busIndex < 0 || portOffset >= implementation.portOffsets[portIndex+1]) return -1; return portOffset; } @Override NetSchem getSchem() { return implementation; } static int getPortOffset(NetworkManager networkManager, PortProto pp, int busIndex) { int portIndex = pp.getPortIndex(); NodeProto np = pp.getParent(); if (!(np instanceof Cell)) return busIndex == 0 ? portIndex : -1; NetCell netCell = networkManager.getNetCell((Cell)np); return netCell.getPortOffset(portIndex, busIndex); } /** * Get an iterator over all of the Nodables of this Cell. */ @Override Iterator<Nodable> getNodables() { ArrayList<Nodable> nodables = new ArrayList<Nodable>(); for (Iterator<NodeInst> it = cell.getNodes(); it.hasNext();) { NodeInst ni = it.next(); if (nodeOffsets[ni.getNodeIndex()] < 0) continue; nodables.add(ni); } for (int i = 0; i < nodeProxies.length; i++) { Proxy proxy = nodeProxies[i]; if (proxy == null) continue; nodables.add(proxy); } return nodables.iterator(); } /** * Get a set of global signal in this Cell and its descendants. */ @Override Global.Set getGlobals() { return globals; } /* * Get offset in networks map for given global signal. */ @Override int getNetMapOffset(Global global) { return globals.indexOf(global); } /** * Get offset in networks map for given global of nodable. * @param no nodable. * @param global global signal. * @return offset in networks map. */ @Override int getNetMapOffset(Nodable no, Global global) { if (!(no instanceof Proxy)) return -1; Proxy proxy = (Proxy)no; NetSchem schem = networkManager.getNetCell((Cell)proxy.nodeInst.getProto()).getSchem(); int i = schem.globals.indexOf(global); if (i < 0) return -1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -