⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nodeinst.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                                       Point2D center, EPoint size, Orientation orient,                                       int flags, int techBits, TextDescriptor protoDescriptor, ErrorLogger errorLogger)	{        if (protoType == null) return null;        if (parent == null) return null;		EPoint anchor = EPoint.snap(center);        Name nameKey = null;        String msg = null;        if (name != null) {            nameKey = Name.findName(name);            if (checkNameKey(nameKey, parent)) {                nameKey = null;            } else if (parent.findNode(name) != null) {                if (!nameKey.isTempname())                    msg = parent + " already has NodeInst with name \""+name+"\"";                nameKey = null;            }        }        if (nameKey == null) {            Name baseName;            if (protoType instanceof Cell) {                baseName = ((Cell)protoType).getBasename();            } else {                PrimitiveNode np = (PrimitiveNode)protoType;                baseName = np.getTechnology().getPrimitiveFunction(np, techBits).getBasename();            }            nameKey = parent.getNodeAutoname(baseName);            if (msg != null) {                msg += ", renamed to \"" + nameKey + "\"";                System.out.println(msg);            }        }        CellId parentId = parent.getId();        if (nameDescriptor == null) nameDescriptor = TextDescriptor.getNodeTextDescriptor();        if (protoDescriptor == null) protoDescriptor = TextDescriptor.getInstanceTextDescriptor();        // search for spare nodeId        int nodeId;        do {            nodeId = parentId.newNodeId();        } while (parent.getNodeById(nodeId) != null);        ImmutableNodeInst d = ImmutableNodeInst.newInstance(nodeId, protoType.getId(), nameKey, nameDescriptor,                orient, anchor, size, flags, techBits, protoDescriptor);        NodeInst ni = newInstance(parent, d);        if (ni != null && msg != null && errorLogger != null)            errorLogger.logError(msg, ni, parent, null, 1);        return ni;	}	/**	 * Method to create a NodeInst by ImmutableNodeInst.	 * @param parent the Cell in which this NodeInst will reside.	 * @param d ImmutableNodeInst of new NodeInst     * @return the newly created NodeInst, or null on error.	 */    public static NodeInst newInstance(Cell parent, ImmutableNodeInst d)	{		if (d.protoId instanceof CellId)		{            Cell subCell = parent.getDatabase().getCell((CellId)d.protoId);            if (Cell.isInstantiationRecursive(subCell, parent))			{				System.out.println("Cannot create instance of " + subCell + " in " + parent +					" because it would be a recursive case");				return null;			}            subCell.getTechnology();		}        if (ImmutableNodeInst.isCellCenter(d.protoId) && parent.alreadyCellCenter()) {            System.out.println("Can only be one cell-center in " + parent + ": new one ignored");            return null;        }		if (parent.findNode(d.name.toString()) != null)		{            System.out.println(parent + " already has NodeInst with name \""+d.name+"\"");            return null;		}		NodeInst ni = lowLevelNewInstance(parent, d);		if (ni.checkAndRepair(true, null, null) > 0) return null;		// add to linked lists		if (parent.addNode(ni)) return null;		// handle change control, constraint, and broadcast		Constraints.getCurrent().newObject(ni);		if (ImmutableNodeInst.isCellCenter(d.protoId))    		parent.adjustReferencePoint(d.anchor.getX(), d.anchor.getY());		return ni;	}    public static NodeInst lowLevelNewInstance(Cell parent, ImmutableNodeInst d)    {        if (d.protoId instanceof CellId && ((CellId)d.protoId).isIcon())            return new IconNodeInst(d, parent);        return new NodeInst(d, parent);    }	/**	 * Method to delete this NodeInst.	 */	public void kill()	{		if (!isLinked())		{			System.out.println("NodeInst already killed");			return;		}        parent.killNodes(Collections.singleton(this));	}	/**	 * Method to move this NodeInst.	 * @param dX the amount to move the NodeInst in X.	 * @param dY the amount to move the NodeInst in Y.	 */	public void move(double dX, double dY)	{//		System.out.println("Moving "+this+" [is "+getXSize()+"x"+getYSize()+" at ("+//                getAnchorCenterX()+","+getAnchorCenterY()+") rot "+getAngle()+//			"] change is dx="+dX+" dy="+dY+") drot=0");        modifyInstance(dX, dY, 0, 0, Orientation.IDENT);    }	/**	 * Method to resize this NodeInst.	 * @param dXSize the amount to scale the NodeInst in X.	 * @param dYSize the amount to scale the NodeInst in Y.	 */	public void resize(double dXSize, double dYSize)	{        modifyInstance(0, 0, dXSize, dYSize, Orientation.IDENT);    }	/**	 * Method to rotate and/or mirror this NodeInst.	 * @param dOrient the change in Orientation of the NodeInst.	 */	public void rotate(Orientation dOrient)	{        modifyInstance(0, 0, 0, 0, dOrient);    }    /**	 * Method to change this NodeInst.	 * @param dX the amount to move the NodeInst in X.	 * @param dY the amount to move the NodeInst in Y.	 * @param dXSize the amount to scale the NodeInst in X.	 * @param dYSize the amount to scale the NodeInst in Y.	 * @param dOrient the change of Orientation of the NodeInst.	 */	public void modifyInstance(double dX, double dY, double dXSize, double dYSize, Orientation dOrient)	{        if (protoType == Generic.tech().cellCenterNode) {            parent.adjustReferencePoint(dX, dY);            return;        }		// make the change        ImmutableNodeInst oldD = getD();        ImmutableNodeInst d = oldD;        if (dX != 0 || dY != 0)            d = d.withAnchor(new EPoint(d.anchor.getX() + dX, d.anchor.getY() + dY));        if (protoType instanceof PrimitiveNode) {            double lambdaX = d.size.getLambdaX() + dXSize;            double lambdaY = d.size.getLambdaY() + dYSize;            d = d.withSize(EPoint.fromLambda(lambdaX, lambdaY));        }        d = d.withOrient(dOrient.concatenate(d.orient));        lowLevelModify(d);        if (parent != null)            Constraints.getCurrent().modifyNodeInst(this, oldD);//        // change the coordinates of every arc end connected to this//        for(Iterator<Connection> it = getConnections(); it.hasNext(); ) {//            Connection con = it.next();//            if (con.getPortInst().getNodeInst() == this) {//                Point2D oldLocation = con.getLocation();//                switch (con.getEndIndex()) {//                    case ArcInst.HEADEND://                        con.getArc().modify(0, dX, dY, 0, 0);//                        break;//                    case ArcInst.TAILEND://                        con.getArc().modify(0, 0, 0, dX, dY);//                        break;//                }//            }//        }	}	/**	 * Method to change many NodeInsts.	 * @param nis the NodeInsts to change.	 * @param dXs the amount to move the NodeInsts in X, or null.	 * @param dYs the amount to move the NodeInsts in Y, or null.	 * @param dXSizes the amount to scale the NodeInsts in X, or null.	 * @param dYSizes the amount to scale the NodeInsts in Y, or null.	 */    public static void modifyInstances(NodeInst [] nis, double [] dXs, double [] dYs, double [] dXSizes, double [] dYSizes) {        // make the change        for(int i=0; i<nis.length; i++) {            NodeInst ni = nis[i];            if (ni == null) continue;            double dX = dXs != null ? dXs[i] : 0;            double dY = dYs != null ? dYs[i] : 0;            double dXSize = dXSizes != null ? dXSizes[i] : 0;            double dYSize = dYSizes != null ? dYSizes[i] : 0;            if (ni.getProto() == Generic.tech().cellCenterNode) continue;            ni.modifyInstance(dX, dY, dXSize, dYSize, Orientation.IDENT);        }        for(int i=0; i<nis.length; i++) {            NodeInst ni = nis[i];            if (ni == null) continue;            if (ni.getProto() != Generic.tech().cellCenterNode) continue;            double dX = dXs != null ? dXs[i] : 0;            double dY = dYs != null ? dYs[i] : 0;            ni.getParent().adjustReferencePoint(dX, dY);        }}	/**	 * Method to replace this NodeInst with one of another type.	 * All arcs and exports on this NodeInst are moved to the new one.	 * @param np the new type to put in place of this NodeInst.	 * @param ignorePortNames true to not use port names when determining association between old and new prototype.	 * @param allowMissingPorts true to allow replacement to have missing ports and, therefore, delete the arcs that used to be there.	 * @return the new NodeInst that replaces this one.	 * Returns null if there is an error doing the replacement.	 */	public NodeInst replace(NodeProto np, boolean ignorePortNames, boolean allowMissingPorts)	{		// check for recursion		if (np instanceof Cell)		{            if (Cell.isInstantiationRecursive((Cell)np, getParent()))            {                System.out.println("Cannot replace because it would be recursive");                return null;            }		}		// get the location of the cell-center on the old NodeInst		Point2D oldCenter = getAnchorCenter();		// create the new NodeInst		double newXS = np.getDefWidth();		double newYS = np.getDefHeight();		if ((np instanceof PrimitiveNode) && (getProto() instanceof PrimitiveNode))		{			// replacing one primitive with another: adjust sizes accordingly			SizeOffset oldSO = getProto().getProtoSizeOffset();			SizeOffset newSO = np.getProtoSizeOffset();			newXS = getXSize() - oldSO.getLowXOffset() - oldSO.getHighXOffset() + newSO.getLowXOffset() + newSO.getHighXOffset();			newYS = getYSize() - oldSO.getLowYOffset() - oldSO.getHighYOffset() + newSO.getLowYOffset() + newSO.getHighYOffset();//			// test for minimum sizes if not dealing with pure-layer nodes//			if (np.getFunction() != PrimitiveNode.Function.NODE)//			{//				// if less than min size, set it to min size//	            if (newXS < np.getDefWidth()) newXS = np.getDefWidth();//	            if (newYS < np.getDefHeight()) newYS = np.getDefHeight();////	            // if old prim is min size, set new prim to min size//	            if (getXSize() == getProto().getDefWidth()) newXS = np.getDefWidth();//	            if (getYSize() == getProto().getDefHeight()) newYS = np.getDefHeight();//			}		}		// see if nodeinst is mirrored		NodeInst newNi = NodeInst.newInstance(np, oldCenter, newXS, newYS, getParent(), getOrient(), null, 0);		if (newNi == null) return null;		// draw new node expanded if appropriate		if (np instanceof Cell)		{			if (getProto() instanceof Cell)			{				// replacing an instance: copy the expansion information				if (isExpanded()) newNi.setExpanded(); else					newNi.clearExpanded();			}		}		// associate the ports between these nodes		PortAssociation [] oldAssoc = portAssociate(this, newNi, ignorePortNames);		// see if the old arcs can connect to ports		double arcDx = 0, arcDy = 0;		int arcCount = 0;		for(Iterator<Connection> it = getConnections(); it.hasNext(); )		{			Connection con = it.next();			// make sure there is an association for this port			int index = 0;			for( ; index<oldAssoc.length; index++)				if (oldAssoc[index].portInst == con.getPortInst()) break;			if (index >= oldAssoc.length || oldAssoc[index].assn == null)			{				if (allowMissingPorts) continue;				System.out.println("No port on new node has same name and location as old node port: " + con.getPortInst().getPortProto().getName());				newNi.kill();				return null;			}			// make sure the arc can connect to this type of port			PortInst opi = oldAssoc[index].assn;			ArcInst ai = con.getArc();			if (!opi.getPortProto().connectsTo(ai.getProto()))			{				if (allowMissingPorts) continue;				System.out.println(ai + " on old port " + con.getPortInst().getPortProto().getName() +					" cannot connect to new port " + opi.getPortProto().getName());				newNi.kill();				return null;			}			// see if the arc fits in the new port			Poly poly = opi.getPoly();			if (!poly.isInside(con.getLocation()))			{				// arc doesn't fit: accumulate error distance				double xp = poly.getCenterX();				double yp = poly.getCenterY();				arcDx += xp - con.getLocation().getX();				arcDy += yp - con.getLocation().getY();			}			arcCount++;		}		// see if the old exports have the same connections		for(Iterator<Export> it = getExports(); it.hasNext(); )		{			Export pp = it.next();			// make sure there is an association for this port			int index = 0;			for( ; index<oldAssoc.length; index++)				if (oldAssoc[index].portInst == pp.getOriginalPort()) break;			if (index >= oldAssoc.length || oldAssoc[index].assn == null)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -