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

📄 hpgl.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			if (layerList == null)			{				layerList = new ArrayList<PolyBase>();				outGeom.cellGeoms.put(layer, layerList);			}			return layerList;		}	}	/**	 * Method to plot the polygon "poly"	 */	private void emitPoly(PolyBase poly)	{		// ignore null layers		Layer layer = poly.getLayer();		Poly.Type style = poly.getStyle();		Point2D [] points = poly.getPoints();		if (style == Poly.Type.FILLED)		{			Rectangle2D box = poly.getBox();			if (box != null)			{				if (box.getWidth() == 0)				{					if (box.getHeight() != 0) emitLine(box.getMinX(), box.getMinY(), box.getMinX(), box.getMaxY(), layer);					return;				}				if (box.getHeight() == 0)				{					emitLine(box.getMinX(), box.getMinY(), box.getMaxX(), box.getMinY(), layer);					return;				}			}			if (points.length <= 1) return;			if (points.length == 2)			{				emitLine(points[0].getX(), points[0].getY(), points[1].getX(), points[1].getY(), layer);				return;			}			emitFilledPolygon(points, layer);			return;		}		if (style == Poly.Type.CLOSED || style == Poly.Type.OPENED ||			style == Poly.Type.OPENEDT1 || style == Poly.Type.OPENEDT2 || style == Poly.Type.OPENEDT3)		{			Rectangle2D box = poly.getBox();			if (box != null)			{				emitLine(box.getMinX(), box.getMinY(), box.getMinX(), box.getMaxY(), layer);				emitLine(box.getMinX(), box.getMaxY(), box.getMaxX(), box.getMaxY(), layer);				emitLine(box.getMaxX(), box.getMaxY(), box.getMaxX(), box.getMinY(), layer);				if (style == Poly.Type.CLOSED || points.length == 5)					emitLine(box.getMaxX(), box.getMinY(), box.getMinX(), box.getMinY(), layer);				return;			}			for (int k = 1; k < points.length; k++)				emitLine(points[k-1].getX(), points[k-1].getY(), points[k].getX(), points[k].getY(), layer);			if (style == Poly.Type.CLOSED)			{				int k = points.length - 1;				emitLine(points[k].getX(), points[k].getY(), points[0].getX(), points[0].getY(), layer);			}			return;		}		if (style == Poly.Type.VECTORS)		{			for(int k=0; k<points.length; k += 2)				emitLine(points[k].getX(), points[k].getY(), points[k+1].getX(), points[k+1].getY(), layer);			return;		}		if (style == Poly.Type.CROSS || style == Poly.Type.BIGCROSS)		{			double x = poly.getCenterX();			double y = poly.getCenterY();			emitLine(x-5, y, x+5, y, layer);			emitLine(x, y+5, x, y-5, layer);			return;		}		if (style == Poly.Type.CROSSED)		{			Rectangle2D box = poly.getBounds2D();			emitLine(box.getMinX(), box.getMinY(), box.getMinX(), box.getMaxY(), layer);			emitLine(box.getMinX(), box.getMaxY(), box.getMaxX(), box.getMaxY(), layer);			emitLine(box.getMaxX(), box.getMaxY(), box.getMaxX(), box.getMinY(), layer);			emitLine(box.getMaxX(), box.getMinY(), box.getMinX(), box.getMinY(), layer);			emitLine(box.getMaxX(), box.getMaxY(), box.getMinX(), box.getMinY(), layer);			emitLine(box.getMaxX(), box.getMinY(), box.getMinX(), box.getMaxY(), layer);			return;		}		if (style == Poly.Type.DISC)		{			// filled disc: plot it and its outline			emitDisc(points[0], points[1], layer);			style = Poly.Type.CIRCLE;		}		if (style == Poly.Type.CIRCLE || style == Poly.Type.THICKCIRCLE)		{			emitCircle(points[0], points[1], layer);			return;		}		if (style == Poly.Type.CIRCLEARC || style == Poly.Type.THICKCIRCLEARC)		{			emitArc(points[0], points[1], points[2], layer);			return;		}		if (style.isText())		{			EditWindow_ wnd = null;			Poly textPoly = (Poly)poly;			double size = textPoly.getTextDescriptor().getTrueSize(wnd);			Rectangle2D box = textPoly.getBounds2D();			emitText(style, box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY(), size, textPoly.getString(), layer);			return;		}	}	void emitLine(double x1, double y1, double x2, double y2, Layer layer)	{		doPenSelection(layer);		movePen(x1, y1);		drawPen(x2, y2);	}	private void emitArc(Point2D center, Point2D p1, Point2D p2, Layer layer)	{		double startAngle = GenMath.figureAngle(center, p1);		double endAngle = GenMath.figureAngle(center, p2);		double amt;		if (startAngle > endAngle) amt = (startAngle - endAngle + 5) / 10; else			amt = (startAngle - endAngle + 3600 + 5) / 10;		doPenSelection(layer);		movePen(p1.getX(), p1.getY());		writeLine("PD;");		writeLine("AA " + makeCoord(center.getX()) + " " + makeCoord(center.getY()) +			" " + ((int)-amt) + ";");		writeLine("PU;");	}	private void emitCircle(Point2D at, Point2D e, Layer layer)	{		double radius = at.distance(e);		doPenSelection(layer);		movePen(at.getX(), at.getY());		writeLine("PD;");		writeLine("CI " + makeCoord(radius) + ";");		writeLine("PU;");	}	private void emitDisc(Point2D at, Point2D e, Layer layer)	{		int fillType = doFillSelection(layer);		double radius = at.distance(e);		movePen(at.getX(), at.getY());		writeLine("PD;");		writeLine("PM;");		writeLine("CI " + makeCoord(radius) + ";");		writeLine("PM2;");		if (fillType != 0) writeLine("FP;");		if (fillType != 1) writeLine("EP;");		writeLine("PU;");	}	private void emitFilledPolygon(Point2D [] points, Layer layer)	{		if (points.length <= 1) return;		int fillType = doFillSelection(layer);		double firstX = points[0].getX();		// save the end point		double firstY = points[0].getY();		movePen(firstX, firstY);	// move to the start		writeLine("PM;");		for(int i=1; i<points.length; i++) drawPen(points[i].getX(), points[i].getY());		drawPen(firstX, firstY);	// close the polygon		writeLine("PM2;");		if (fillType != 0) writeLine("FP;");		if (fillType != 1) writeLine("EP;");	}	private void emitText(Poly.Type type, double xl, double xh, double yl, double yh, double size,		String text, Layer layer)	{		writeLine("SI " + TextUtils.formatDouble(size*0.01/1.3) + "," +			TextUtils.formatDouble(size*0.01) + ";");		doPenSelection(layer);		if (type == Poly.Type.TEXTBOTLEFT)		{			movePen(xl, yl);			writeLine("LO1;");		} else if (type == Poly.Type.TEXTLEFT)		{			movePen(xl, (yl+yh)/2);			writeLine("LO2;");		} else if (type == Poly.Type.TEXTTOPLEFT)		{			movePen(xh, yl);			writeLine("LO3;");		} else if (type == Poly.Type.TEXTBOT)		{			movePen((xl+xh)/2, yl);			writeLine("LO4;");		} else if (type == Poly.Type.TEXTCENT || type == Poly.Type.TEXTBOX)		{			movePen((xl+xh)/2, (yl+yh)/2);			writeLine("LO5;");		} else if (type == Poly.Type.TEXTTOP)		{			movePen((xl+xh)/2, yh);			writeLine("LO6;");		} else if (type == Poly.Type.TEXTBOTRIGHT)		{			movePen(xh, yl);			writeLine("LO7;");		} else if (type == Poly.Type.TEXTRIGHT)		{			movePen(xh, (yl+yh)/2);			writeLine("LO8;");		} else if (type == Poly.Type.TEXTTOPRIGHT)		{			movePen(xh, yh);			writeLine("LO9;");		}		writeLine("LB " + text + "\003");	}	/**	 * Method to setup pen information.	 */	private void initPenData()	{		penColorTable = new PenColor[256];		for(int i=0; i<256; i++)		{			penColorTable[i] = new PenColor();			penColorTable[i].lineType = 0;			penColorTable[i].fillType = 3;			penColorTable[i].fillDist = makeCoord(i * 2);			penColorTable[i].fillAngle = (i * 10) % 360;		}	}	/**	 * Method to accept a color from 0 to 255, and returns either an opaque	 * color (refer to egraphics.h) or a transparent color.  In other words, this	 * function masks out the bits used by the grid and highlight.  In cases where	 * a color is a combination of transparent colors, only one of the transparent	 * colors is returned.  This approximation is only significant in cases where two	 * identical transparent objects exactly overlap each other.  For our	 * applications, this will be rare.	 */	private int getPenNumber(Layer layer)	{		Integer ind = penNumbers.get(layer);		if (ind == null) return 0;		return ind.intValue();	}	private int doFillSelection(Layer layer)	{		doPenSelection(layer);		int fillType = penColorTable[currentPen].fillType;		if (!fillEmitted)		{			int fillAngle = penColorTable[currentPen].fillAngle;			int fillDist = penColorTable[currentPen].fillDist;			writeLine("FT " + fillType + "," + fillDist + "," + fillAngle + ";");			fillEmitted = true;		}		return fillType;	}	/**	 * based upon the current value of "color", this function will select the	 * proper entry from the pen table, and select an appropriate pen from the	 * penColorTable.  The appropriate pen and line type is then selected.	 */	private void doPenSelection(Layer layer)	{		int pen = getPenNumber(layer);		int desiredPen = pen;		int lineType = penColorTable[pen].lineType;		// check to see if pen is defined		if (desiredPen < 1) desiredPen = 1;		// select new pen, pen 0 returns pen to carousel and does not get new pen		if (desiredPen != currentPen)		{			writeLine("SP" + desiredPen + ";");			currentPen = desiredPen;			fillEmitted = false;		}		// set line type, line type 0 defaults to solid		if (lineType != currentLineType)		{			if (lineType == 0) writeLine("LT;"); else				writeLine("LT" + lineType + ";");			currentLineType = lineType;		}	}	/**	 * Method to move the pen to a new position	 * This has been changed - no longer check to see if we are already there.	 * This change adds a little to the output file length, but reduces the	 * amount of code significantly.  The hp spends most of its time moving	 * the pen, not reading commands. Therefore, this should be no problem.	 */	private void movePen(double x, double y)	{		writeLine("PU" + makeCoord(x) + "," + makeCoord(y) + ";");	}	/**	 * Method to draw from current point to the next, assume PA already issued	 * Changed this so that a PD (pen down) instruction is issued.  Then we	 * can use this in several other functions.	 */	private void drawPen(double x, double y)	{		writeLine("PD" + makeCoord(x) + "," + makeCoord(y) + ";");	}	private int makeCoord(double v) { return (int)Math.round(v * SCALE); }	private void writeLine(String line)	{//		printWriter.println(line);		printWriter.print(line + "\r\n");	}}

⌨️ 快捷键说明

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