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

📄 polymerge.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: PolyMerge.java * * Copyright (c) 2004 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.database.geometry;import com.sun.electric.database.geometry.GenMath.MutableBoolean;import com.sun.electric.technology.Layer;import java.awt.geom.AffineTransform;import java.awt.geom.Area;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.awt.*;import java.util.Collection;import java.util.List;/** * This is the Polygon Merging facility. * <P> * Initially, call:<BR> *    PolyMerge merge = new PolyMerge();<BR> * The returned value is used in subsequent calls. * <P> * For every polygon, call:<BR> *    merge.addPolygon(layer, poly);<BR> * where "layer" is a layer and "poly" is a polygon to be added. * <P> * You can also subtract a polygon by calling:<BR> *    merge.subtract(layer, poly);<BR> * <P> * To combine two different merges, use:<BR> *    merge.addMerge(addmerge, trans)<BR> * to add the merge information in "addmerge" (transformed by "trans") * <P> * At end of merging, call:<BR> *    merge.getMergedPoints(layer)<BR> * for each layer, and it returns an array of PolyBases on that layer. */public class PolyMerge        extends GeometryHandler{	/**	 * Method to create a new "merge" object.	 */	public PolyMerge()	{	}	/**	 * Method to add a PolyBase to the merged collection.	 * @param key the layer that this PolyBase sits on.	 * @param value the PolyBase to merge. If value is only Shape type     * then it would take the bounding box. This might not be precise enough!.	 */	public void add(Layer key, Object value)	{		Layer layer = key;        PolyBase poly;        if (value instanceof PolyBase)		    poly = (PolyBase)value;        else if (value instanceof Shape)            poly = new PolyBase(((Shape)value).getBounds2D());        else            return;		addPolygon(layer, poly);	}	/**	 * Method to add a Rectangle to the merged collection.	 * @param layer the layer that this Poly sits on.	 * @param rect the Rectangle to merge.	 */	public void addRectangle(Layer layer, Rectangle2D rect)	{		Area area = (Area)layers.get(layer);		if (area == null)		{			area = new Area();			layers.put(layer, area);		}		// add "rect" to "area"		Area additionalArea = new Area(rect);		area.add(additionalArea);	}	/**	 * Method to add a PolyBase to the merged collection.	 * @param layer the layer that this Poly sits on.	 * @param poly the PolyBase to merge.	 */	public void addPolygon(Layer layer, PolyBase poly)	{		Area area = (Area)layers.get(layer);		if (area == null)		{			area = new Area();			layers.put(layer, area);		}		// add "poly" to "area"		// It can't add only rectangles otherwise it doesn't cover		// serpentine transistors.		Area additionalArea = new Area(poly);		area.add(additionalArea);	}	/**	 * Method to subtract a PolyBase from the merged collection.	 * @param layer the layer that this PolyBase sits on.	 * @param poly the PolyBase to merge.	 */	public void subtract(Object layer, Object poly)	{		Area area = (Area)layers.get(layer);		if (area == null) return;		Area subtractArea = new Area((PolyBase)poly);		area.subtract(subtractArea);	}	/**	 * Method to add another Merge to this one.	 * @param subMerge the other Merge to add in.	 * @param trans a transformation on the other Merge.	 */	public void addAll(GeometryHandler subMerge, AffineTransform trans)	{		PolyMerge other = (PolyMerge)subMerge;		addMerge(other, trans);	}	/**	 * Method to add another Merge to this one.	 * @param other the other Merge to add in.	 * @param trans a transformation on the other Merge.	 */	public void addMerge(PolyMerge other, AffineTransform trans)	{		for(Layer subLayer : other.layers.keySet())		{			Area subArea = (Area)other.layers.get(subLayer);			Area area = (Area)layers.get(subLayer);			if (area == null)			{				area = new Area();				layers.put(subLayer, area);			}			Area newArea = subArea.createTransformedArea(trans);			area.add(newArea);		}	}	/**	 * Method to add one Layer to another in this merge.	 * @param fromLayer the other Layer to add in.	 * @param toLayer the destination layer that will contain the union of itself and "fromLayer".	 */	public void addLayer(Layer fromLayer, Layer toLayer)	{		Area fromArea = (Area)layers.get(fromLayer);		if (fromArea == null) return;		Area toArea = (Area)layers.get(toLayer);		if (toArea == null)		{			toArea = new Area(fromArea);			layers.put(toLayer, toArea);			return;		}		toArea.add(fromArea);	}	/**	 * Method to determine whether a polygon intersects a layer in the merge.	 * @param layer the layer to test.	 * @param poly the polygon to examine.	 * @return true if any part of the polygon exists in that layer.	 */	public boolean intersects(Layer layer, PolyBase poly)	{		Area layerArea = (Area)layers.get(layer);		if (layerArea == null) return false;		// simple calculation for manhattan polygon		Rectangle2D box = poly.getBox();		if (box != null)		{			return layerArea.intersects(box);		}		// more complex calculation (not done yet)		Area intersectArea = new Area(poly);		intersectArea.intersect(layerArea);		return !intersectArea.isEmpty();	}	/**	 * Method to intersect two layers in this merge and produce a third.	 * @param sourceA the first Layer to intersect.	 * @param sourceB the second Layer to intersect.	 * @param dest the destination layer to place the intersection of the first two.	 * If there is no intersection, all geometry on this layer is cleared.	 */	public void intersectLayers(Layer sourceA, Layer sourceB, Layer dest)	{		Area destArea = null;		Area sourceAreaA = (Area)layers.get(sourceA);		if (sourceAreaA != null)		{			Area sourceAreaB = (Area)layers.get(sourceB);			if (sourceAreaB != null)			{				destArea = new Area(sourceAreaA);				destArea.intersect(sourceAreaB);				if (destArea.isEmpty()) destArea = null;			}		}		if (destArea == null) layers.remove(dest); else			layers.put(dest, destArea);	}	/**	 * Method to subtract one layer from another and produce a third.	 * @param sourceA the first Layer.	 * @param sourceB the second Layer, which gets subtracted from the first.	 * @param dest the destination layer to place the sourceA - sourceB.	 * If there is nothing left, all geometry on the layer is cleared.	 */	public void subtractLayers(Layer sourceA, Layer sourceB, Layer dest)	{		Area destArea = null;		Area sourceAreaA = (Area)layers.get(sourceA);		if (sourceAreaA != null)		{			Area sourceAreaB = (Area)layers.get(sourceB);

⌨️ 快捷键说明

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