📄 annularring.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: AnnularRing.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.tool.user.dialogs;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.geometry.Dimension2D;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.ui.TopLevel;import com.sun.electric.tool.user.ui.WindowFrame;import java.awt.Frame;import java.awt.geom.Point2D;import java.util.Iterator;import javax.swing.DefaultListModel;import javax.swing.JList;import javax.swing.ListSelectionModel;/** * Class to handle the "Annular Ring" dialog. */public class AnnularRing extends EDialog{ private static double lastInner = 5; private static double lastOuter = 10; private static int lastSegments = 32; private static int lastDegrees = 360; private JList layerJList; private DefaultListModel layerModel; private Cell cell; // To have ability to store directly the PrimitiveNode and not // to depende on names to search the PrimitiveNode instance // and have ability to handle DRC Exclusion node private static class AnnularRingNode { public PrimitiveNode node; AnnularRingNode(PrimitiveNode t) { node = t; } // This avoids to call PrimitiveNode.toString() and get // extra text. public String toString() { return node.getName(); } } /** * Method to display the dialog for building annular rings. */ public static void showAnnularRingDialog() { Cell cell = WindowFrame.needCurCell(); if (cell == null) return; int total = 0; for(Iterator<PrimitiveNode> it = Technology.getCurrent().getNodes(); it.hasNext(); ) { PrimitiveNode np = it.next(); if (np.getFunction() == PrimitiveNode.Function.NODE) total++; } if (total == 0) { System.out.println("The " + Technology.getCurrent().getTechName() + " technology has no pure-layer nodes"); return; } AnnularRing dialog = new AnnularRing(TopLevel.getCurrentJFrame(), cell); dialog.setVisible(true); } /** Creates new form AnnularRing */ private AnnularRing(Frame parent, Cell cell) { super(parent, true); this.cell = cell; initComponents(); getRootPane().setDefaultButton(ok); // make all text fields select-all when entered EDialog.makeTextFieldSelectAllOnTab(innerRadius); EDialog.makeTextFieldSelectAllOnTab(outerRadius); EDialog.makeTextFieldSelectAllOnTab(numSegments); EDialog.makeTextFieldSelectAllOnTab(numDegrees); layerModel = new DefaultListModel(); layerJList = new JList(layerModel); layerJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); layerPane.setViewportView(layerJList); for(Iterator<PrimitiveNode> it = Technology.getCurrent().getNodes(); it.hasNext(); ) { PrimitiveNode np = it.next(); if (np.getFunction() != PrimitiveNode.Function.NODE) continue; layerModel.addElement(new AnnularRingNode(np)); } layerModel.addElement(new AnnularRingNode(Generic.tech().drcNode)); layerModel.addElement(new AnnularRingNode(Generic.tech().afgNode)); layerJList.setSelectedIndex(0); innerRadius.setText(TextUtils.formatDouble(lastInner)); outerRadius.setText(TextUtils.formatDouble(lastOuter)); numSegments.setText(Integer.toString(lastSegments)); numDegrees.setText(Integer.toString(lastDegrees)); finishInitialization(); } protected void escapePressed() { cancelActionPerformed(null); } private void cacheValues() { lastInner = TextUtils.atof(innerRadius.getText()); lastOuter = TextUtils.atof(outerRadius.getText()); lastSegments = TextUtils.atoi(numSegments.getText()); lastDegrees = TextUtils.atoi(numDegrees.getText()); } private void makeRing() { cacheValues(); if (lastSegments < 4) lastSegments = 4; if (lastDegrees <= 0) lastDegrees = 360; if (lastDegrees > 360) lastDegrees = 360; int degrees = lastDegrees * 10; // figure out what node to use PrimitiveNode np = ((AnnularRingNode)layerJList.getSelectedValue()).node; if (np == null) return; (new MakeAnnulus(cell, np, lastSegments, degrees, lastInner, lastOuter)).startJob(); } /** * This class finishes the Annular Ring command by creating the ring. */ public static class MakeAnnulus extends Job { private Cell cell; private PrimitiveNode np; private int segments, degrees; private double inner, outer; private NodeInst ni; public MakeAnnulus(Cell cell, PrimitiveNode np, int segments, int degrees, double inner, double outer) { super("Make Annular Ring", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cell = cell; this.np = np; this.segments = segments; this.degrees = degrees; this.inner = inner; this.outer = outer; this.ni = null; //startJob(); } public boolean doIt() throws JobException { double snap = cell.getTechnology().getResolution(); Dimension2D dimSnap = new Dimension2D.Double(snap, snap); // allocate space for the trace int numSegments = segments + 1; if (inner == 0 && degrees < 3600) numSegments += 2; if (inner > 0) numSegments *= 2; EPoint [] points = new EPoint[numSegments]; int l = 0; if (inner > 0) { for(int i=0; i<=segments; i++) { int p = degrees * i / segments; double x = inner * DBMath.cos(p); double y = inner * DBMath.sin(p); Point2D pt = new Point2D.Double(x, y); DBMath.gridAlign(pt, dimSnap); points[l++] = new EPoint(pt.getX(), pt.getY()); } } if (inner == 0 && degrees < 3600) points[l++] = new EPoint(0, 0); for(int i=segments; i>=0; i--) { int p = degrees*i/segments; double x = outer * DBMath.cos(p); double y = outer * DBMath.sin(p); Point2D pt = new Point2D.Double(x, y); DBMath.gridAlign(pt, dimSnap);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -