📄 primitiveport.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: PrimitivePort.java * * 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.technology;import com.sun.electric.database.EObjectInputStream;import com.sun.electric.database.EObjectOutputStream;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.geometry.EGraphics;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.hierarchy.EDatabase;import com.sun.electric.database.id.PrimitivePortId;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.text.TextUtils;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.technology.xml.XmlParam;import java.awt.Color;import java.io.IOException;import java.io.InvalidObjectException;import java.io.PrintWriter;import java.io.Serializable;import java.util.HashSet;import java.util.Iterator;import java.util.Set;/** * A PrimitivePort lives in a PrimitiveNode in a Tecnology. * It contains a list of ArcProto types that it * accepts connections from. */public class PrimitivePort implements PortProto, Comparable<PrimitivePort>, Serializable{ // ---------------------------- private data -------------------------- private PrimitivePortId portId; // The Id of this PrimitivePort. private final Name name; // The Name of this PrimitivePort private final PrimitiveNode parent; // The parent PrimitiveNode of this PrimitivePort. private final int portIndex; // Index of this PrimitivePort in PrimitiveNode ports. private ArcProto portArcs[]; // Immutable list of possible connection types. private EdgeH left; private EdgeV bottom; private EdgeH right; private EdgeV top;// private Technology tech; private PortCharacteristic characteristic; private int angle; private int angleRange; private int portTopology; private boolean isolated; private boolean negatable; // ---------------------- protected and private methods ---------------- /** * The constructor is only called from the factory method "newInstance". */ private PrimitivePort(Technology tech, PrimitiveNode parent, ArcProto [] portArcs, String protoName, int portAngle, int portRange, int portTopology, EdgeH left, EdgeV bottom, EdgeH right, EdgeV top) { this.name = Name.findName(protoName); this.portId = parent.getId().newPortId(name.toString()); this.parent = parent; this.portIndex = parent.getNumPorts(); parent.addPrimitivePort(this); if (!Technology.jelibSafeName(protoName)) System.out.println("PrimitivePort name " + protoName + " is not safe to write into JELIB"); setAngle(portAngle); setAngleRange(portRange); this.portTopology = portTopology; // initialize this object// this.tech = tech; this.portArcs = portArcs; for (ArcProto ap: portArcs) { Technology apTech = ap.getTechnology(); if (apTech != tech && apTech != apTech.generic) throw new IllegalArgumentException("portArcs in " + name); } this.left = left; this.bottom = bottom; this.right = right; this.top = top; this.negatable = false;// tech.addPortProto(this); } protected Object writeReplace() { return new PrimitivePortKey(this); } private static class PrimitivePortKey extends EObjectInputStream.Key<PrimitivePort> { public PrimitivePortKey() {} private PrimitivePortKey(PrimitivePort pp) { super(pp); } @Override public void writeExternal(EObjectOutputStream out, PrimitivePort pp) throws IOException { out.writeObject(pp.getParent()); out.writeInt(pp.getId().chronIndex); } @Override public PrimitivePort readExternal(EObjectInputStream in) throws IOException, ClassNotFoundException { PrimitiveNode pn = (PrimitiveNode)in.readObject(); int chronIndex = in.readInt(); PrimitivePort pp = pn.getPrimitivePortByChronIndex(chronIndex); if (pp == null) throw new InvalidObjectException("primitive port not linked"); return pp; } } /** * Method to create a new PrimitivePort from the parameters. * @param tech the Technology in which this PrimitivePort is being created. * @param parent the PrimitiveNode on which this PrimitivePort resides. * @param portArcs an array of ArcProtos which can connect to this PrimitivePort. * @param protoName the name of this PrimitivePort. * It may not have unprintable characters, spaces, or tabs in it. * @param portAngle the primary angle that the PrimitivePort faces on the PrimitiveNode (in degrees). * This angle is measured counter-clockwise from a right-pointing direction. * @param portRange the range about the angle of allowable connections (in degrees). * Arcs must connect to this port within this many degrees of the port connection angle. * When this value is 180, then all angles are permissible, since arcs * can connect at up to 180 degrees in either direction from the port angle. * @param portTopology is a small integer that is unique among PrimitivePorts on the PrimitiveNode. * When two PrimitivePorts have the same topology number, it indicates that these ports are connected. * @param characteristic describes the nature of this PrimitivePort (input, output, power, ground, etc.) * @param left is an EdgeH that describes the left side of the port in a scalable way. * @param bottom is an EdgeV that describes the bottom side of the port in a scalable way. * @param right is an EdgeH that describes the right side of the port in a scalable way. * @param top is an EdgeV that describes the top side of the port in a scalable way. * @return the newly created PrimitivePort. */ public static PrimitivePort newInstance(Technology tech, PrimitiveNode parent, ArcProto [] portArcs, String protoName, int portAngle, int portRange, int portTopology, PortCharacteristic characteristic, EdgeH left, EdgeV bottom, EdgeH right, EdgeV top) { if (parent == null) System.out.println("PrimitivePort " + protoName + " has no parent"); assert tech == parent.getTechnology(); if (!(tech instanceof Generic)) { Generic generic = tech.generic; ArcProto [] realPortArcs = new ArcProto[portArcs.length + 3]; for(int i=0; i<portArcs.length; i++) realPortArcs[i] = portArcs[i]; realPortArcs[portArcs.length] = generic.universal_arc; realPortArcs[portArcs.length+1] = generic.invisible_arc; realPortArcs[portArcs.length+2] = generic.unrouted_arc; portArcs = realPortArcs; } PrimitivePort pp = new PrimitivePort(tech, parent, portArcs, protoName, portAngle, portRange, portTopology, left, bottom, right, top); pp.characteristic = characteristic; return pp; } // ------------------------ public methods ------------------------ /** Method to return PortProtoId of this PrimitivePort. * PortProtoId identifies PrimitivePort independently of threads. * @return PortProtoId of this PrimtivePort. */ public PrimitivePortId getId() { return portId; } PrimitivePortId setEmptyId() { assert parent.getNumPorts() == 1; portId = parent.getId().newPortId(""); return portId; } /** * Method to return the name key of this PrimitivePort. * @return the Name key of this PrimitivePort. */ public Name getNameKey() { return name; } /** * Method to return the name of this PrimitivePort. * @return the name of this PrimitivePort. */ public String getName() { return name.toString(); } /** * Method to return the parent NodeProto of this PrimitivePort. * @return the parent NodeProto of this PrimitivePort. */ public PrimitiveNode getParent() { return parent; } /** * Method to get the index of this PrimitivePort. * This is a zero-based index of ports on the PrimitiveNode. * @return the index of this PrimitivePort. */ public int getPortIndex() { return portIndex; } /** * Method to set the list of allowable connections on this PrimitivePort. * @param portArcs an array of ArcProtos which can connect to this PrimitivePort. */ public void setConnections(ArcProto [] portArcs) { this.portArcs = portArcs; } /** * Method to return the list of allowable connections on this PrimitivePort. * @param allTechs pool of all known technologies * @return an array of ArcProtos which can connect to this PrimitivePort. */ public ArcProto [] getConnections(TechPool allTechs) { if (parent.getTechnology().isUniversalConnectivityPort(this)) return allTechs.getUnivList(); return portArcs; } /** * Method to return the list of allowable connections on this PrimitivePort. * @return an array of ArcProtos which can connect to this PrimitivePort. */ public ArcProto [] getConnections() { if (parent.getTechnology().isUniversalConnectivityPort(this)) return EDatabase.theDatabase.getTechPool().getUnivList(); return portArcs; } /** * Method to return one of allowable connections on this PrimitivePort. * @return ArcProto which can connect to this PrimitivePort. */ public ArcProto getConnection() { return portArcs[0]; } /** * Method to return the base-level port that this PortProto is created from. * Since it is a PrimitivePort, it simply returns itself. * @return the base-level port that this PortProto is created from (this). */ public PrimitivePort getBasePort() { return this; } /** * Method to return the left edge of the PrimitivePort as a value that scales with the actual NodeInst. * @return an EdgeH object that describes the left edge of the PrimitivePort. */ public EdgeH getLeft() { return left; } /** * Method to return the right edge of the PrimitivePort as a value that scales with the actual NodeInst. * @return an EdgeH object that describes the right edge of the PrimitivePort. */ public EdgeH getRight() { return right; } /** * Method to return the top edge of the PrimitivePort as a value that scales with the actual NodeInst. * @return an EdgeV object that describes the top edge of the PrimitivePort. */ public EdgeV getTop() { return top; } /** * Method to return the bottom edge of the PrimitivePort as a value that scales with the actual NodeInst. * @return an EdgeV object that describes the bottom edge of the PrimitivePort.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -