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

📄 explorertreemodel.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *     * @param aNode  the TreeNode to get the path for     * @param depth  an int giving the number of steps already taken towards     *        the root (on recursive calls), used to size the returned array     * @return an array of TreeNodes giving the path from the root to the     *         specified node     */    protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) {        TreeNode[]              retNodes;        // This method recurses, traversing towards the root in order        // size the array. On the way back, it fills in the nodes,        // starting from the root and working back to the original node.        /* Check for null, in case someone passed in a null node, or           they passed in an element that isn't rooted at root. */        if (aNode == null) {            if (depth == 0) return null;            retNodes = new TreeNode[depth];        } else {            depth++;            if(aNode == root)                retNodes = new TreeNode[depth];            else {                TreeNode parent = aNode.getParent();                if (parent == null && root.getIndex(aNode) >= 0) {                    retNodes = new TreeNode[depth + 1];                    retNodes[0] = root;                } else {                    retNodes = getPathToRoot(parent, depth);                }            }            retNodes[retNodes.length - depth] = aNode;        }        return retNodes;    }    void updateContentExplorerNodes(List<MutableTreeNode> newContentExplorerNodes) {        Object[] children = contentExplorerNodes.toArray();        int[] childIndices = new int[children.length];        for (int i = 0; i < children.length; i++) childIndices[i] = i;        contentExplorerNodes.clear();        nodesWereRemoved(rootPath, childIndices, children);        contentExplorerNodes.addAll(newContentExplorerNodes);        childIndices = new int[contentExplorerNodes.size()];        for (int i = 0; i < childIndices.length; i++) childIndices[i] = i;        nodesWereInserted(rootPath, childIndices);    }    /**	 * A static object is used so that its open/closed tree state can be maintained.	 */	private static String libraryNode = "LIBRARIES";    static boolean isShownAlphabetically()    {        return howToShow == SHOWALPHABETICALLY;    }    static void showAlphabeticallyAction()    {        howToShow = SHOWALPHABETICALLY;        WindowFrame.wantToRedoLibraryTree();    }    static boolean isShownByGroup()    {        return howToShow == SHOWBYCELLGROUP;    }    static void showByGroupAction()    {        howToShow = SHOWBYCELLGROUP;        WindowFrame.wantToRedoLibraryTree();    }    static boolean isShownByHierarchy()    {        return howToShow == SHOWBYHIERARCHY;    }    static void showByHierarchyAction()    {        howToShow = SHOWBYHIERARCHY;        WindowFrame.wantToRedoLibraryTree();    }    static boolean getSortLexically()    {    	return sortLexically;    }    static void setSortLexically(ActionEvent e)    {    	JCheckBoxMenuItem sl = (JCheckBoxMenuItem)e.getSource();    	sortLexically = !sl.isSelected();        WindowFrame.wantToRedoLibraryTree();    }    public static DefaultMutableTreeNode makeLibraryTree()	{		DefaultMutableTreeNode libraryExplorerTree = new DefaultMutableTreeNode(libraryNode);		// reconstruct the tree		switch (howToShow)		{			case SHOWALPHABETICALLY:				rebuildExplorerTreeByName(libraryExplorerTree);				break;			case SHOWBYCELLGROUP:				rebuildExplorerTreeByGroups(libraryExplorerTree);				break;			case SHOWBYHIERARCHY:				rebuildExplorerTreeByHierarchy(libraryExplorerTree);				break;		}		return libraryExplorerTree;	}	private static synchronized void rebuildExplorerTreeByName(DefaultMutableTreeNode libraryExplorerTree)	{		for(Library lib : Library.getVisibleLibraries())		{			DefaultMutableTreeNode libTree = new DefaultMutableTreeNode(lib);			if (!addTechnologyLibraryToTree(lib, libTree))			{				List<Cell> cellList = new ArrayList<Cell>();				for(Iterator<Cell> eit = lib.getCells(); eit.hasNext(); )					cellList.add(eit.next());				if (sortLexically)		        	Collections.sort(cellList, new TextUtils.CellsByName());	        	for(Cell cell : cellList)	        	{					DefaultMutableTreeNode cellTree = new DefaultMutableTreeNode(cell);					libTree.add(cellTree);	        	}			}			libraryExplorerTree.add(libTree);		}	}	private static boolean addTechnologyLibraryToTree(Library lib, DefaultMutableTreeNode libTree)	{		boolean techLib = false;		for(Iterator<Cell> it = lib.getCells(); it.hasNext(); )		{			Cell cell = it.next();			if (cell.isInTechnologyLibrary())			{				techLib = true;				break;			}		}		if (!techLib) return false;		// add this library as a technology library		DefaultMutableTreeNode layerTree = new DefaultMutableTreeNode("TECHNOLOGY LAYERS");		DefaultMutableTreeNode arcTree = new DefaultMutableTreeNode("TECHNOLOGY ARCS");		DefaultMutableTreeNode nodeTree = new DefaultMutableTreeNode("TECHNOLOGY NODES");		DefaultMutableTreeNode miscTree = new DefaultMutableTreeNode("TECHNOLOGY SUPPORT");		libTree.add(layerTree);		libTree.add(arcTree);		libTree.add(nodeTree);		libTree.add(miscTree);		HashSet<Cell> allCells = new HashSet<Cell>();		Cell [] layerCells = LayerInfo.getLayerCells(lib);		for(int i=0; i<layerCells.length; i++)		{			allCells.add(layerCells[i]);			layerTree.add(new DefaultMutableTreeNode(layerCells[i]));		}		Cell [] arcCells = ArcInfo.getArcCells(lib);		for(int i=0; i<arcCells.length; i++)		{			allCells.add(arcCells[i]);			arcTree.add(new DefaultMutableTreeNode(arcCells[i]));		}		Cell [] nodeCells = NodeInfo.getNodeCells(lib);		for(int i=0; i<nodeCells.length; i++)		{			allCells.add(nodeCells[i]);			nodeTree.add(new DefaultMutableTreeNode(nodeCells[i]));		}		for(Iterator<Cell> it = lib.getCells(); it.hasNext(); )		{			Cell cell = it.next();			if (allCells.contains(cell)) continue;			miscTree.add(new DefaultMutableTreeNode(cell));		}		return true;	}	private static synchronized void rebuildExplorerTreeByHierarchy(DefaultMutableTreeNode libraryExplorerTree)	{		for(Library lib : Library.getVisibleLibraries())		{			DefaultMutableTreeNode libTree = new DefaultMutableTreeNode(lib);			if (!addTechnologyLibraryToTree(lib, libTree))			{				List<Cell> cellList = new ArrayList<Cell>();				for(Iterator<Cell> eit = lib.getCells(); eit.hasNext(); )					cellList.add(eit.next());				if (sortLexically)		        	Collections.sort(cellList, new TextUtils.CellsByName());	        	for(Cell cell : cellList)	        	{						// ignore icons and text views					if (cell.isIcon()) continue;					if (cell.getView().isTextView()) continue;				        HashSet<Cell> addedCells = new HashSet<Cell>();					for(Iterator<Cell> vIt = cell.getVersions(); vIt.hasNext(); )					{						Cell cellVersion = vIt.next();						Iterator insts = cellVersion.getInstancesOf();						if (insts.hasNext()) continue;							// no children: add this as root node	                    if (addedCells.contains(cellVersion)) continue;          // prevent duplicate entries						DefaultMutableTreeNode cellTree = new DefaultMutableTreeNode(cellVersion);						libTree.add(cellTree);	                    addedCells.add(cellVersion);						createHierarchicalExplorerTree(cellVersion, cellTree);					}				}			}			libraryExplorerTree.add(libTree);		}	}	/**	 * Method to build a hierarchical explorer structure.	 */	private static void createHierarchicalExplorerTree(Cell cell, DefaultMutableTreeNode cellTree)	{		// see what is inside		HashMap<Cell,DBMath.MutableInteger> cellCount = new HashMap<Cell,DBMath.MutableInteger>();		for(Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); )		{			NodeInst ni = it.next();			if (!ni.isCellInstance()) continue;			Cell subCell = (Cell)ni.getProto();			if (subCell.isIcon())			{				if (ni.isIconOfParent()) continue;				subCell = subCell.contentsView();				if (subCell == null) continue;			}			DBMath.MutableInteger mi = cellCount.get(subCell);			if (mi == null)			{				mi = new DBMath.MutableInteger(0);				cellCount.put(subCell, mi);			}			mi.setValue(mi.intValue()+1);		}		// show what is there		for(Cell subCell : cellCount.keySet())		{			DBMath.MutableInteger mi = cellCount.get(subCell);			if (mi == null) continue;			CellAndCount cc = new CellAndCount(subCell, mi.intValue());			DefaultMutableTreeNode subCellTree = new DefaultMutableTreeNode(cc);			cellTree.add(subCellTree);			createHierarchicalExplorerTree(subCell, subCellTree);		}	}	private static synchronized void rebuildExplorerTreeByGroups(DefaultMutableTreeNode libraryExplorerTree)	{		HashSet<Cell> cellsSeen = new HashSet<Cell>();		for(Library lib : Library.getVisibleLibraries())		{			DefaultMutableTreeNode libTree = new DefaultMutableTreeNode(lib);			if (!addTechnologyLibraryToTree(lib, libTree))			{				for(Iterator<Cell> eit = lib.getCells(); eit.hasNext(); )				{					Cell cell = eit.next();					cellsSeen.remove(cell);				}				List<Cell> cellList = new ArrayList<Cell>();				for(Iterator<Cell> eit = lib.getCells(); eit.hasNext(); )					cellList.add(eit.next());				if (sortLexically)		        	Collections.sort(cellList, new TextUtils.CellsByName());	        	for(Cell cell : cellList)	        	{					if (cell.getNewestVersion() != cell) continue;					Cell.CellGroup group = cell.getCellGroup();					int numNewCells = 0;					for(Iterator<Cell> gIt = group.getCells(); gIt.hasNext(); )					{						Cell cellInGroup = gIt.next();						if (cellInGroup.getNewestVersion() == cellInGroup) numNewCells++;					}					if (numNewCells == 1)					{						addCellAndAllVersions(cell, libTree);						continue;					}						List<Cell> cellsInGroup = group.getCellsSortedByView();					DefaultMutableTreeNode groupTree = null;					for(Cell cellInGroup : cellsInGroup)					{	                    if ((cellInGroup.getNumVersions() > 1) && (cellInGroup.getNewestVersion() != cellInGroup)) continue;						if (cellsSeen.contains(cellInGroup)) continue;						if (groupTree == null)						{							groupTree = new DefaultMutableTreeNode(group);						}						cellsSeen.add(cellInGroup);						addCellAndAllVersions(cellInGroup, groupTree);					}					if (groupTree != null)						libTree.add(groupTree);				}			}			libraryExplorerTree.add(libTree);		}	}	private static void addCellAndAllVersions(Cell cell, DefaultMutableTreeNode libTree)	{		DefaultMutableTreeNode cellTree = new DefaultMutableTreeNode(cell);		libTree.add(cellTree);		if (cell.isMultiPage())		{			int pageCount = cell.getNumMultiPages();			for(int i=0; i<pageCount; i++)			{				MultiPageCell mpc = new MultiPageCell();				mpc.cell = cell;				mpc.pageNo = i;				DefaultMutableTreeNode pageTree = new DefaultMutableTreeNode(mpc);				cellTree.add(pageTree);			}		}		if (cell.getNumVersions() > 1)		{			for(Iterator<Cell> vIt = cell.getVersions(); vIt.hasNext(); )			{				Cell oldVersion = vIt.next();				if (oldVersion == cell) continue;				DefaultMutableTreeNode oldCellTree = new DefaultMutableTreeNode(oldVersion);				cellTree.add(oldCellTree);				if (oldVersion.isMultiPage())				{					int pageCount = oldVersion.getNumMultiPages();					for(int i=0; i<pageCount; i++)					{						MultiPageCell mpc = new MultiPageCell();						mpc.cell = oldVersion;						mpc.pageNo = i;						DefaultMutableTreeNode pageTree = new DefaultMutableTreeNode(mpc);						oldCellTree.add(pageTree);					}				}			}		}	}}

⌨️ 快捷键说明

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