📄 export.java
字号:
for (int i = 0; i < name.length(); i++) { char ch = name.charAt(i); if (ch == '[' || ch == ']' || ch == ':' || ch == ',' || ch == '@') ch = 'X'; sb.append(ch); } newName = sb.toString(); if (validExportName(newName, oldBusWidth)) { newName = ElectricObject.uniqueObjectName(newName, parent, PortProto.class, false); if (validExportName(newName, oldBusWidth)) return newName; } return null; } /** * Returns true if string is a valid Export name with cirtain width. * @param name string to test. * @param busWidth cirtain width. * @return true if string is a valid Export name with cirtain width. */ private static boolean validExportName(String name, int busWidth) { Name nameKey = ImmutableExport.validExportName(name, true); return nameKey != null && nameKey.busWidth() == busWidth; } /** * Compares Exports by their Cells and names. * @param that the other Export. * @return a comparison between the Exports. */ public int compareTo(Export that) { if (parent != that.parent) { int cmp = parent.compareTo(that.parent); if (cmp != 0) return cmp; } return d.name.toString().compareTo(that.d.name.toString()); } /** * Returns a printable version of this Export. * @return a printable version of this Export. */ public String toString() { return "export '" + getName() + "'"; } /****************************** MISCELLANEOUS ******************************/ /** * Method to return the port on the NodeInst inside of the cell that is the origin of this Export. * @return the port on the NodeInst inside of the cell that is the origin of this Export. */ public PortInst getOriginalPort() { return originalPort; } /** * Method to return the base-level port that this PortProto is created from. * Since this is an Export, it returns the base port of its sub-port, the port on the NodeInst * from which the Export was created. * @return the base-level port that this PortProto is created from. */ public PrimitivePort getBasePort() { PortProto pp = originalPort.getPortProto(); return pp.getBasePort(); } /** * Method to return true if the specified ArcProto can connect to this Export. * @param arc the ArcProto to test for connectivity. * @return true if this Export can connect to the ArcProto, false if it can't. */ public boolean connectsTo(ArcProto arc) { return getBasePort().connectsTo(arc); } /** * Method to return the PortCharacteristic of this Export. * @return the PortCharacteristic of this Exort. */ public PortCharacteristic getCharacteristic() { return d.characteristic; } /** * Method to set the PortCharacteristic of this Export. * @param characteristic the PortCharacteristic of this Exort. */ public void setCharacteristic(PortCharacteristic characteristic) { setD(d.withCharacteristic(characteristic), true); } /** * Method to determine whether this Export is of type Power. * This is determined by either having the proper Characteristic, or by * having the proper name (starting with "vdd", "vcc", "pwr", or "power"). * @return true if this Export is of type Power. */ public boolean isPower() { PortCharacteristic ch = getCharacteristic(); if (ch == PortCharacteristic.PWR) return true; if (ch != PortCharacteristic.UNKNOWN) return false; return isNamedPower(); } /** * Method to determine whether this Export has a name that suggests Power. * This is determined by having a name starting with "vdd", "vcc", "pwr", or "power". * @return true if this Export has a name that suggests Power. */ public boolean isNamedPower() { String name = TextUtils.canonicString(getName()); if (name.indexOf("vdd") >= 0) return true; if (name.indexOf("vcc") >= 0) return true; if (name.indexOf("pwr") >= 0) return true; if (name.indexOf("power") >= 0) return true; return false; } /** * Method to determine whether this Export is of type Ground. * This is determined by either having the proper PortCharacteristic, or by * having the proper name (starting with "vss", "gnd", or "ground"). * @return true if this Export is of type Ground. */ public boolean isGround() { PortCharacteristic ch = getCharacteristic(); if (ch == PortCharacteristic.GND) return true; if (ch != PortCharacteristic.UNKNOWN) return false; return isNamedGround(); } /** * Method to determine whether this Export has a name that suggests Ground. * This is determined by either having a name starting with "vss", "gnd", or "ground". * @return true if this Export has a name that suggests Ground. */ public boolean isNamedGround() { String name = TextUtils.canonicString(getName()); if (name.indexOf("vss") >= 0) return true; if (name.indexOf("gnd") >= 0) return true; if (name.indexOf("ground") >= 0) return true; return false; } /** * Returns true if this export has its original port on Global-Partition schematics * primitive. * @return true if this export is Global-Partition export. */ public boolean isGlobalPartition() { return originalPort.getNodeInst().getProto() == Schematics.tech().globalPartitionNode; } /** * Method to set this PortProto to be always drawn. * Ports that are always drawn have their name displayed at all times, even when an arc is connected to them. */ public void setAlwaysDrawn(boolean b) { setD(d.withAlwaysDrawn(b), true); } /** * Method to tell whether this PortProto is always drawn. * Ports that are always drawn have their name displayed at all times, even when an arc is connected to them. * @return true if this PortProto is always drawn. */ public boolean isAlwaysDrawn() { return d.alwaysDrawn; } /** * Method to set this PortProto to exist only in the body of a cell. * Ports that exist only in the body do not have an equivalent in the icon. * This is used by simulators and icon generators to recognize less significant ports. * @param b true if this Export exists only in the body of a cell. */ public void setBodyOnly(boolean b) { setD(d.withBodyOnly(b), true); } /** * Method to tell whether this PortProto exists only in the body of a cell. * Ports that exist only in the body do not have an equivalent in the icon. * This is used by simulators and icon generators to recognize less significant ports. * @return true if this PortProto exists only in the body of a cell. */ public boolean isBodyOnly() { return d.bodyOnly; } /** * Returns true if this Export is linked into database. * @return true if this Export is linked into database. */ public boolean isLinked() { try { return parent.isLinked() && parent.getPort(portIndex) == this; } catch (IndexOutOfBoundsException e) { return false; } } /** * Returns database to which this Export belongs. * @return database to which this Export belongs. */ public EDatabase getDatabase() { return parent.getDatabase(); } /** * Method to return the PortProto that is equivalent to this in the * corresponding schematic Cell. * It finds the PortProto with the same name on the corresponding Cell. * If there are multiple versions of the Schematic Cell return the latest. * @return the PortProto that is equivalent to this in the corresponding Cell. */ public PortProto getEquivalent() { Cell equiv = parent.getEquivalent(); if (equiv == parent) return this; if (equiv == null) return null; return equiv.findPortProto(getNameKey()); } /** * Method to find the Export on another Cell that is equivalent to this Export. * @param otherCell the other cell to equate. * @return the Export on that other Cell which matches this Export. * Returns null if none can be found. */ public Export getEquivalentPort(Cell otherCell) { /* don't waste time searching if the two views are the same */ if (parent == otherCell) return this; // this is the non-cached way to do it return otherCell.findExport(getName()); /* load the cache if not already there */// if (otherCell != thisCell->cachedequivcell)// {// for(Iterator it = thisCell.getPorts(); it.hasNext(); )// {// Export opp = (Export)it.next();// opp->cachedequivport = null;// }// for(Iterator it = thisCell.getPorts(); it.hasNext(); )// {// Export opp = (Export)it.next();// Export epp = otherCell.findExport(opp.getName());// if (epp != null) opp->cachedequivport = epp;// }// thisCell->cachedequivcell = otherCell;// }// epp = pp->cachedequivport;// if (epp != null) return epp;//// /* don't report errors for global ports not on icons */// if (epp == null)// {// if (!otherCell.isIcon() || !pp.isBodyOnly())// System.out.println("Warning: no port in cell %s corresponding to port %s in cell %s"),// describenodeproto(otherCell), pp->protoname, describenodeproto(thisCell));// }// pp->cachedequivport = null;// return null; } /** * helper method to ensure that all arcs connected to Export "pp" at * instances of its Cell (or any of its export sites) * can connect to Export newPP. * @return true if the connection cannot be made. */ public boolean doesntConnect(PrimitivePort newPP) { // check every instance of this node for(Iterator<NodeInst> it = parent.getInstancesOf(); it.hasNext(); ) { NodeInst ni = it.next(); // make sure all arcs on this port can connect PortInst pi = ni.findPortInstFromProto(this); for(Iterator<Connection> cIt = pi.getConnections(); cIt.hasNext(); ) { Connection con = cIt.next();// for(Iterator cIt = ni.getConnections(); cIt.hasNext(); )// {// Connection con = (Connection)cIt.next();// if (con.getPortInst().getPortProto() != this) continue; if (!newPP.connectsTo(con.getArc().getProto())) { System.out.println(con.getArc() + " in " + ni.getParent() + " cannot connect to port " + getName()); return true; } } // make sure all further exports are still valid for(Iterator<Export> eIt = ni.getExports(); eIt.hasNext(); ) { Export oPP = eIt.next(); if (oPP.getOriginalPort().getPortProto() != this) continue; if (oPP.doesntConnect(newPP)) return true; } } return false; } /****************************** SUPPORT ******************************/ /** * Method to change all usage of this Export because it has been moved. * The various state bits are changed to reflect the new Export base. */ private void changeallports() { // look at all instances of the cell that had export motion recursivelyChangeAllPorts(); // look at associated cells and change their ports if (parent.isIcon()) { // changed an export on an icon: find contents and change it there Cell onp = parent.contentsView(); if (onp != null) { Export opp = getEquivalentPort(onp); if (opp != null) { opp.setCharacteristic(getCharacteristic()); opp.recursivelyChangeAllPorts(); } } return; } // see if there is an icon to change Cell onp = parent.iconView(); if (onp != null) { Export opp = getEquivalentPort(onp); if (opp != null) { opp.setCharacteristic(getCharacteristic()); opp.recursivelyChangeAllPorts(); } } } /** * Method to recursively alter the state bit fields of this Export. */ private void recursivelyChangeAllPorts() { parent.recursivelyChangeAllPorts(Collections.singleton(this)); } /** * This function is to compare Export elements. Initiative CrossLibCopy * @param obj Object to compare to * @param buffer To store comparison messages in case of failure * @return True if objects represent same Export */ public boolean compare(Object obj, StringBuffer buffer) { if (this == obj) return (true); // Better if compare classes? but it will crash with obj=null if (obj == null || getClass() != obj.getClass()) return (false); PortProto no = (PortProto)obj; // getNameKey is required to call proper Name.equals() if (!getNameKey().equals(no.getNameKey())) { if (buffer != null) buffer.append("'" + this + "' and '" + no + "' do not have same name\n"); return (false); } PortCharacteristic noC = no.getCharacteristic(); if (!getCharacteristic().getName().equals(noC.getName())) { if (buffer != null) buffer.append("'" + this + "' and '" + no + "' do not have same characteristic\n"); return (false); } return (true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -