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

📄 cell.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		if (destLib != null)		{			// scan all subcells to see if they are found in the new library			for(Iterator<NodeInst> it = fromCell.getNodes(); it.hasNext(); )			{				NodeInst ni = it.next();				if (!ni.isCellInstance()) continue;				Cell niProto = (Cell)ni.getProto();				boolean maySubstitute = useExisting;				if (!maySubstitute)				{					// force substitution for documentation icons					if (niProto.isIcon())					{						if (niProto.isIconOf(fromCell)) maySubstitute = true;					}				}				if (!maySubstitute) continue;				// switch cell names if disambiguating				String oldCellName = niProto.getName();				if (cellNamesToUse != null)				{					Map<String,String> libToNameMap = cellNamesToUse.get(oldCellName);					if (libToNameMap != null)					{						String newCellName = libToNameMap.get(niProto.getLibrary().getName());						if (newCellName != null) oldCellName = newCellName;					}				}				// search for cell with same name and view in new library				Cell lnt = null;				for(Iterator<Cell> cIt = toLib.getCells(); cIt.hasNext(); )				{					lnt = cIt.next();					if (lnt.getName().equals(oldCellName) &&//					if (lnt.getName().equalsIgnoreCase(oldCellName) &&						lnt.getView() == niProto.getView()) break;					lnt = null;				}				if (lnt == null) continue;				// make sure all used ports can be found on the uncopied cell				boolean validPorts = true;				for(Iterator<PortInst> pIt = ni.getPortInsts(); pIt.hasNext(); )				{					PortInst pi = pIt.next();					PortProto pp = pi.getPortProto();					PortProto ppt = lnt.findPortProto(pp.getName());//					if (ppt != null)//					{//						// the connections must match, too//						if (pp->connects != ppt->connects) ppt = null;//					}					if (ppt == null)					{						System.out.println("Cannot use subcell " + lnt.noLibDescribe() + " in " + destLib +							": exports don't match");						validPorts = false;						break;					}				}				if (!validPorts) continue;				// match found: use the prototype from the destination library				nodePrototypes.put(ni, lnt);			}		}		return copyNodeProtoUsingMapping(fromCell, toLib, toName, nodePrototypes);	}	/**	 * Method to copy a Cell to any Library, using a preset mapping of node prototypes.	 * @param fromCell the Cell to copy.	 * @param toLib the Library to copy it to.	 * If the destination library is the same as the original Cell's library, a new version is made.	 * @param toName the name of the Cell in the destination Library.	 * @param nodePrototypes a HashMap from NodeInsts in the source Cell to proper NodeProtos to use in the new Cell.	 * @return the new Cell in the destination Library.	 */	public static Cell copyNodeProtoUsingMapping(Cell fromCell, Library toLib, String toName,		Map<NodeInst,NodeProto> nodePrototypes)	{		// create the nodeproto		String cellName = toName;		if (toName.indexOf('{') < 0 && fromCell.getView() != View.UNKNOWN)		{			cellName = toName + fromCell.getView().getAbbreviationExtension();		}		Cell newCell = Cell.newInstance(toLib, cellName);		if (newCell == null) return(null);		newCell.lowLevelSetUserbits(fromCell.lowLevelGetUserbits());		// copy nodes		Map<NodeInst,NodeInst> newNodes = new HashMap<NodeInst,NodeInst>();		for(Iterator<NodeInst> it = fromCell.getNodes(); it.hasNext(); )		{			// create the new nodeinst			NodeInst ni = it.next();			NodeProto lnt = nodePrototypes.get(ni);			if (lnt == null) lnt = ni.getProto();			double scaleX = ni.getXSize();   //if (ni.isXMirrored()) scaleX = -scaleX;			double scaleY = ni.getYSize();   //if (ni.isYMirrored()) scaleY = -scaleY;			NodeInst toNi = NodeInst.newInstance(lnt, new Point2D.Double(ni.getAnchorCenterX(), ni.getAnchorCenterY()),				scaleX, scaleY, newCell, ni.getOrient(), ni.getName(), 0);			if (toNi == null) return null;			// save the new nodeinst address in the old nodeinst			newNodes.put(ni, toNi);			// copy miscellaneous information			toNi.copyTextDescriptorFrom(ni, NodeInst.NODE_PROTO);			toNi.copyTextDescriptorFrom(ni, NodeInst.NODE_NAME);			toNi.copyStateBits(ni);		}		// now copy the variables on the nodes		for(Iterator<NodeInst> it = fromCell.getNodes(); it.hasNext(); )		{			NodeInst ni = it.next();			NodeInst toNi = newNodes.get(ni);			toNi.copyVarsFrom(ni);            // if this is an icon, and this nodeinst is the box with the name of the cell on it,            // then change the name from the old to the new            if (newCell.isIcon()) {                String name = toNi.getVarValue(Schematics.SCHEM_FUNCTION, String.class);                if (fromCell.getName().equals(name))                    toNi.updateVar(Schematics.SCHEM_FUNCTION, newCell.getName());            }		}		// copy arcs		for(Iterator<ArcInst> it = fromCell.getArcs(); it.hasNext(); )		{			ArcInst ai = it.next();			// find the nodeinst and portinst connections for this arcinst			PortInst [] opi = new PortInst[2];			Point2D [] oLoc = new Point2D[2];			for(int i=0; i<2; i++)			{				opi[i] = null;				NodeInst ono = newNodes.get(ai.getPortInst(i).getNodeInst());				PortProto pp = ai.getPortInst(i).getPortProto();				if (!ono.isCellInstance())				{					// primitives associate ports directly					opi[i] = ono.findPortInstFromProto(pp);				} else				{					// cells associate ports by name					PortProto ppt = ono.getProto().findPortProto(pp.getName());					if (ppt != null) opi[i] = ono.findPortInstFromProto(ppt);				}				if (opi[i] == null)					System.out.println("Error: no port for " + ai.getProto() +						" arc on " + ono.getProto());				oLoc[i] = ai.getLocation(i);		        Poly poly = opi[i].getPoly();		        if (!poly.isInside(oLoc[i])) oLoc[i] = poly.getCenter();			}			if (opi[0] == null || opi[1] == null) return null;			// create the arcinst			ArcInst toAi = ArcInst.newInstanceBase(ai.getProto(), ai.getLambdaBaseWidth(), opi[ArcInst.HEADEND], opi[ArcInst.TAILEND],				oLoc[ArcInst.HEADEND], oLoc[ArcInst.TAILEND], ai.getName(), ai.getAngle());			if (toAi == null) return null;			// copy arcinst information			toAi.copyPropertiesFrom(ai);		}		// copy the Exports		for(Iterator<Export> it = fromCell.getExports(); it.hasNext(); )		{			Export pp = it.next();			// match sub-portproto in old nodeinst to sub-portproto in new one			NodeInst ni = newNodes.get(pp.getOriginalPort().getNodeInst());			PortInst pi = ni.findPortInst(pp.getOriginalPort().getPortProto().getName());			if (pi == null)			{				System.out.println("Error: no port on " + pp.getOriginalPort().getNodeInst().getProto());				return null;			}			// create the nodeinst portinst			Export ppt = Export.newInstance(newCell, pi, pp.getName());			if (ppt == null) return null;			// copy portproto variables			ppt.copyVarsFrom(pp);			// copy miscellaneous information			ppt.copyStateBits(pp);			ppt.copyTextDescriptorFrom(pp, Export.EXPORT_NAME);		}		// copy cell variables        for (Iterator<Variable> it = fromCell.getParametersAndVariables(); it.hasNext(); ) {            Variable fromVar = it.next();            if (newCell.isParam(fromVar.getKey())) {                newCell.setTextDescriptor(fromVar.getKey(), fromVar.getTextDescriptor());            } else if (fromVar.getTextDescriptor().isParam()) {                newCell.getCellGroup().addParam(fromVar);                newCell.setTextDescriptor(fromVar.getKey(), fromVar.getTextDescriptor());            } else {                newCell.addVar(fromVar);            }        }		// reset (copy) date information		newCell.lowLevelSetCreationDate(fromCell.getCreationDate());		newCell.lowLevelSetRevisionDate(fromCell.getRevisionDate());		return newCell;	}	/**	 * Method to replace subcells of a Cell by cells with similar name in Cell's  	 */    public void replaceSubcellsByExisting() {        // scan all subcells to see if they are found in the new library		Map<NodeInst,Cell> nodePrototypes = new HashMap<NodeInst,Cell>();        for(Iterator<NodeInst> it = getNodes(); it.hasNext(); ) {            NodeInst ni = it.next();            if (!ni.isCellInstance()) continue;            Cell niProto = (Cell)ni.getProto();            if (niProto.lib == lib) continue;            // search for cell with same name and view in new library            Cell lnt = null;            for(Iterator<Cell> cIt = lib.getCells(); cIt.hasNext(); ) {                lnt = cIt.next();                if (lnt.getName().equals(niProto.getName()) &&//                if (lnt.getName().equalsIgnoreCase(niProto.getName()) &&                        lnt.getView() == niProto.getView()) break;                lnt = null;            }            if (lnt == null) continue;            // make sure all used ports can be found on the uncopied cell            boolean validPorts = true;            for(Iterator<PortInst> pIt = ni.getPortInsts(); pIt.hasNext(); ) {                PortInst pi = pIt.next();                PortProto pp = pi.getPortProto();                PortProto ppt = lnt.findPortProto(pp.getName());//                if (ppt != null) {//                    // the connections must match, too//						if (pp->connects != ppt->connects) ppt = null;//                }                if (ppt == null) {                    System.out.println("Cannot use subcell " + lnt.noLibDescribe() + " in " + lib +                            ": exports don't match");                    validPorts = false;                    break;                }            }            if (!validPorts) continue;            // match found: use the prototype from the destination library            nodePrototypes.put(ni, lnt);        }        for (Map.Entry<NodeInst,Cell> e: nodePrototypes.entrySet()) {            NodeInst ni = e.getKey();            Cell newProto = e.getValue();            ni.replace(newProto, false, false);        }    }	/**	 * Method to rename this Cell.	 * @param newName the new name of this cell.     * @param newGroupName the name of cell in a group to put the rename cell to.	 */	public IdMapper rename(String newName, String newGroupName)	{		return rename(CellName.parseName(newName + ";" + getVersion() + getView().getAbbreviationExtension()), newGroupName);	}	/**	 * Method to rename this Cell.	 * @param cellName the new name of this cell.	 */	private IdMapper rename(CellName cellName, String newGroupName)	{		checkChanging();		assert isLinked();		if (cellName == null) return null;		if (getCellName().equals(cellName)) return null;//		// remove temporarily from the library and from cell group//		lib.removeCell(this);//		cellGroup.remove(this);		// remember the expansion state of instances of the cell		Map<CellId,Map<Name,Boolean>> expansionRemap = new HashMap<CellId,Map<Name,Boolean>>();		for(Iterator<NodeInst> it = getInstancesOf(); it.hasNext(); )		{			NodeInst ni = it.next();			Cell cell = ni.getParent();			Map<Name,Boolean> cellExpansionRemap = expansionRemap.get(cell.getId());			if (cellExpansionRemap == null)			{				cellExpansionRemap = new HashMap<Name,Boolean>();				expansionRemap.put(cell.getId(), cellExpansionRemap);			}			Boolean isExpanded = new Boolean(ni.isExpanded());			cellExpansionRemap.put(ni.getNameKey(), isExpanded);		}		// do the rename        cellName = makeUnique(lib, cellName);//        setD(getD().withCellName(cellName));        EDatabase database = getDatabase();        Snapshot oldSnapshot = database.backup();        CellId newCellId = lib.getId().newCellId(cellName);        IdMapper idMapper = IdMapper.renameCell(oldSnapshot, d.cellId, newCellId);        Snapshot newSnapshot = oldSnapshot.withRenamedIds(idMapper, d.cellId, newGroupName);        database.lowLevelSetCanUndoing(true);        database.undo(newSnapshot);        database.lowLevelSetCanUndoing(false);        Constraints.getCurrent().renameIds(idMapper);        lib.setChanged();		// restore the expansion state of instances of the cell        for(CellId cid : expansionRemap.keySet())        {			Map<Name,Boolean> cellExpansionRemap = expansionRemap.get(cid);			Cell cell = cid.inDatabase(database);        	for(Name name : cellExpansionRemap.keySet())        	{        		NodeInst ni = cell.findNode(name.toString());        		if (ni != null)        			ni.setExpanded(cellExpansionRemap.get(name).booleanValue());        	}        }        return idMapper;	}

⌨️ 快捷键说明

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