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

📄 exportchanges.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		}		// create job		int num = reExportPorts(cell, queuedExports, true, wiredPorts, unwiredPorts, false, null);		System.out.println(num+" ports exported.");	}	/**	 * Re-exports the PortInsts in the list. If sort is true, it first sorts the list by name and	 * bus index. Otherwise, they are exported in the order they are found in the list.	 * Note that ports are filtered first, then sorted.	 * @param cell the cell in which exporting is happening.	 * @param portInsts the list of PortInsts to export	 * @param sort true to re-sort the portInsts list	 * @param wiredPorts true to export ports that are already wired	 * @param unwiredPorts true to export ports that are not already wired	 * @param onlyPowerGround true to only export ports that are power and ground	 * @param originalExports a map from the entries in portInsts to original Exports.	 * This is used when re-exporting ports on a copy that were exported on the original.	 * Ignored if null.	 * @return the number of ports exported	 */	public static int reExportPorts(Cell cell, List<PortInst> portInsts, boolean sort, boolean wiredPorts,		boolean unwiredPorts, boolean onlyPowerGround, Map<PortInst,Export> originalExports)	{		EDatabase.serverDatabase().checkChanging();		// filter the ports - remove unwanted		List<PortInst> portInstsFiltered = new ArrayList<PortInst>();		for (PortInst pi : portInsts)		{			// decide whether connections on the port should exclude its reexporting			if (pi.hasConnections())			{				if (!wiredPorts) continue;			} else			{				if (!unwiredPorts) continue;			}			if (onlyPowerGround)			{				// remove ports that are not power or ground				PortProto pp = pi.getPortProto();				if (!pp.isPower() && !pp.isGround()) continue;			}			// remove exported ports			NodeInst ni = pi.getNodeInst();			for (Iterator<Export> exit = ni.getExports(); exit.hasNext(); )			{				Export e = exit.next();				if (e.getOriginalPort() == pi) continue;			}			portInstsFiltered.add(pi);		}		// sort the accepted ports by name and bus index		if (sort)			Collections.sort(portInstsFiltered, new PortInstsSortedByBusIndex());		// remember port names already used		Set<String> already = new HashSet<String>();		for(Iterator<PortProto> it = cell.getPorts(); it.hasNext(); )		{			Export e = (Export)it.next();			already.add(e.getNameKey().toString());//			already.add(e.getNameKey().canonicString());		}		// export the ports		Map<String,GenMath.MutableInteger> nextPlainIndex = new HashMap<String,GenMath.MutableInteger>();		int total = 0;		for (PortInst pi : portInstsFiltered)		{			// disallow port action if lock is on			int errorCode = CircuitChangeJobs.cantEdit(cell, pi.getNodeInst(), true, true, true);			if (errorCode < 0) break;			if (errorCode > 0) continue;			// presume the name and characteristic of the new Export			Name protoName = pi.getPortProto().getNameKey();			PortCharacteristic pc = pi.getPortProto().getCharacteristic();			// or use original export name/characteristic if there is one			Export refExport = null;			if (originalExports != null)			{				refExport = originalExports.get(pi);				if (refExport != null)				{					protoName = refExport.getNameKey();					pc = refExport.getCharacteristic();				}			}			// if the node is arrayed, extend the range of the export			int busWidth = pi.getNodeInst().getNameKey().busWidth();			if (busWidth > 1)			{				// scalar export on arrayed node: make the export an array				if (NetworkTool.isBusAscending())				{					protoName = Name.findName(protoName.toString() + "[0:" + (busWidth-1) + "]");				} else				{					protoName = Name.findName(protoName.toString() + "[" + (busWidth-1) + ":0]");				}			}			// get unique name here so Export.newInstance doesn't print message			String protoNameString = protoName.toString();			protoNameString = ElectricObject.uniqueObjectName(protoNameString, cell, PortProto.class, already, nextPlainIndex, false);			// create export			Export newPp = Export.newInstance(cell, pi, protoNameString, pc);			if (newPp != null)			{				// copy text descriptor, var, and characteristic				if (pi.getPortProto() instanceof Export)				{					newPp.copyTextDescriptorFrom((Export)pi.getPortProto(), Export.EXPORT_NAME);					newPp.copyVarsFrom(((Export)pi.getPortProto()));				}				// find original export if any, and copy text descriptor, vars, and characteristic				if (refExport != null)				{					newPp.copyTextDescriptorFrom(refExport, Export.EXPORT_NAME);					newPp.copyVarsFrom(refExport);					newPp.setCharacteristic(refExport.getCharacteristic());				}				total++;				already.add(newPp.getNameKey().toString());//				already.add(newPp.getNameKey().canonicString());			}		}		return total;	}	/**	 * This returns the port inst on newNi that corresponds to the portinst that has been exported	 * as 'referenceExport' on some other nodeinst of the same node prototype.	 * This method is useful when re-exporting ports on copied nodes because	 * the original port was exported.	 * @param newNi the new node inst on which the port inst will be found	 * @param referenceExport the export on the old node inst	 * @return the port inst on newNi which corresponds to the exported portinst on the oldNi	 * referred to through 'referenceExport'.	 */	public static PortInst getNewPortFromReferenceExport(NodeInst newNi, Export referenceExport)	{		PortInst origPi = referenceExport.getOriginalPort();		PortInst newPi = newNi.findPortInstFromProto(origPi.getPortProto());		return newPi;	}	/****************************** EXPORT DELETION ******************************/	/**	 * Method to return a list of selected exports.	 * If none are selected, the list is empty.	 */	private static List<Export> getSelectedExports()	{		List<Export> selectedExports = new ArrayList<Export>();		EditWindow wnd = EditWindow.getCurrent();		List<DisplayedText> dts = wnd.getHighlighter().getHighlightedText(true);		for(DisplayedText dt : dts)		{			if (dt.getElectricObject() instanceof Export)			{				Export pp = (Export)dt.getElectricObject();				selectedExports.add(pp);			}		}		return selectedExports;	}	/**	 * Method to delete the currently selected exports.	 */	public static void deleteExport()	{		// make sure there is a current cell		Cell cell = WindowFrame.needCurCell();		if (cell == null) return;		List<Export> exportsToDelete = getSelectedExports();		if (exportsToDelete.size() == 0)		{			System.out.println("There are no selected exports to delete");			return;		}		deleteExports(cell, exportsToDelete);	}	/**	 * Method to delete all exports on the highlighted objects.	 */	public static void deleteExportsOnSelected()	{		// make sure there is a current cell		Cell cell = WindowFrame.needCurCell();		if (cell == null) return;		List<Export> exportsToDelete = new ArrayList<Export>();		EditWindow wnd = EditWindow.getCurrent();		List<Geometric> highs = wnd.getHighlighter().getHighlightedEObjs(true, false);		for(Geometric geom : highs)		{			NodeInst ni = (NodeInst)geom;			for(Iterator<Export> eIt = ni.getExports(); eIt.hasNext(); )			{				exportsToDelete.add(eIt.next());			}		}		if (exportsToDelete.size() == 0)		{			JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(),				"There are no exports on the highlighted objects",					"Re-export failed", JOptionPane.ERROR_MESSAGE);			return;		}		deleteExports(cell, exportsToDelete);	}	/**	 * Method to delete all exports in the highlighted area.	 */	public static void deleteExportsInArea()	{		// make sure there is a current cell		Cell cell = WindowFrame.needCurCell();		if (cell == null) return;		List<Export> exportsToDelete = new ArrayList<Export>();		EditWindow wnd = EditWindow.getCurrent();		Rectangle2D bounds = wnd.getHighlighter().getHighlightedArea(null);		if (bounds == null)		{			JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(),				"Must select something before deleting the highlighted exports",					"Export delete failed", JOptionPane.ERROR_MESSAGE);			return;		}		for(Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); )		{			NodeInst ni = it.next();			for(Iterator<Export> eIt = ni.getExports(); eIt.hasNext(); )			{				Export e = eIt.next();				PortInst pi = e.getOriginalPort();				Poly poly = pi.getPoly();				if (bounds.contains(poly.getCenterX(), poly.getCenterY()))					exportsToDelete.add(e);			}		}		if (exportsToDelete.size() == 0)		{			JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(),				"There are no exports in the highlighted area",					"Re-export failed", JOptionPane.ERROR_MESSAGE);			return;		}		deleteExports(cell, exportsToDelete);	}	public static void deleteExports(Cell cell, List<Export> exportsToDelete)	{		// disallow port action if lock is on		if (CircuitChangeJobs.cantEdit(cell, null, true, false, false) != 0) return;		Set<Export> exportsConfirmed = new HashSet<Export>();		for(Export e : exportsToDelete)		{			int errorCode = CircuitChangeJobs.cantEdit(cell, e.getOriginalPort().getNodeInst(), true, true, false);			if (errorCode < 0) break;			if (errorCode > 0) continue;			exportsConfirmed.add(e);		}		if (exportsConfirmed.isEmpty())		{			System.out.println("No exports deleted");			return;		}		new DeleteExports(cell, exportsConfirmed);	}	private static class DeleteExports extends Job	{		private Cell cell;		private Set<Export> exportsToDelete;		public DeleteExports(Cell cell, Set<Export> exportsToDelete)		{			super("Delete exports", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.cell = cell;			this.exportsToDelete = exportsToDelete;			startJob();		}		public boolean doIt() throws JobException		{			cell.killExports(exportsToDelete);			System.out.println(exportsToDelete.size() + " exports deleted");			return true;		}	}	/****************************** EXPORT MOVING ******************************/	/**	 * Method to move the currently selected export from one node to another.	 */	public static void moveExport()	{		Export source = null;		PortInst dest = null;		EditWindow wnd = EditWindow.getCurrent();		for(Highlight2 h : wnd.getHighlighter().getHighlights())		{			boolean used = false;			if (h.isHighlightEOBJ())			{				if (h.getElectricObject() instanceof PortInst)				{					if (dest != null)					{						System.out.println("Must select only one node-port as a destination of the move");						return;					}					dest = (PortInst)h.getElectricObject();					used = true;				}			} else if (h.isHighlightText())			{				if (h.getVarKey() == Export.EXPORT_NAME && h.getElectricObject() instanceof Export)				{					source = (Export)h.getElectricObject();					used = true;				}			}			if (!used)			{				System.out.println("Moving exports: select one export to move, and one node-port as its destination");				return;			}		}		if (source == null || dest == null)		{			System.out.println("First select one export to move, and one node-port as its destination");			return;		}		new MoveExport(source, dest);	}	private static class MoveExport extends Job	{		private Export source;		private PortInst dest;		protected MoveExport(Export source, PortInst dest)		{			super("Move export", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.source = source;			this.dest = dest;			startJob();		}		public boolean doIt() throws JobException		{			source.move(dest);			return true;		}	}	/****************************** EXPORT RENAMING ******************************/	/**	 * Method to rename the currently selected export.	 */	public static void renameExport()	{		EditWindow wnd = EditWindow.getCurrent();		Highlight2 h = wnd.getHighlighter().getOneHighlight();		if (h == null || h.getVarKey() != Export.EXPORT_NAME || !(h.getElectricObject() instanceof Export))		{			System.out.println("Must select an export name before renaming it");			return;		}		Export pp = (Export)h.getElectricObject();		String response = JOptionPane.showInputDialog(TopLevel.getCurrentJFrame(), "Rename export", pp.getName());		if (response == null) return;		new RenameExport(pp, response);	}	/**	 * Class to rename an export in a new thread.	 */	private static class RenameExport extends Job	{		private Export pp;		private String newName;		protected RenameExport(Export pp, String newName)		{			super("Rename Export" + pp.getName(), User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.pp = pp;			this.newName = newName;			startJob();		}		public boolean doIt() throws JobException		{			pp.rename(newName);			return true;		}	}	/**	 * Class to rename a list of Exports with numeric suffixes in a new thread.	 */	public static class RenumberNumericExports extends Job	{		private List<Export> exports;		public RenumberNumericExports(List<Export> exports)		{			super("Rename Numeric Exports", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER);			this.exports = exports;			startJob();		}		public boolean doIt() throws JobException		{			Collections.sort(exports, new ExportsByNumber());			String lastPureName = "";			int lastIndex = 0;			for(Export e : exports)			{				String name = e.getName();				int numberPos = name.length();				while (numberPos > 0 && Character.isDigit(name.charAt(numberPos-1))) numberPos--;				int nameEnd = numberPos;				if (nameEnd > 0 && name.charAt(nameEnd-1) == '_') nameEnd--;				String pureName = name.substring(0, nameEnd);				if (!pureName.equals(lastPureName))					lastIndex = 0;				lastPureName = pureName;				String newName = pureName;				if (lastIndex > 0) newName += "_" + lastIndex;				lastIndex++;				if (!newName.equals(name))					e.rename(newName);			}			return true;		}	}	/**	 * Comparator class for sorting Export by their name with number considered.	 */

⌨️ 快捷键说明

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