array.java
来自「The ElectricTM VLSI Design System is an 」· Java 代码 · 共 1,013 行 · 第 1/3 页
JAVA
1,013 行
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: Array.java * * Copyright (c) 2003 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.Dimension2D;import com.sun.electric.database.geometry.Orientation;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.text.Name;import com.sun.electric.database.text.Pref;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.Geometric;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.topology.PortInst;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.drc.Quick;import com.sun.electric.tool.user.CircuitChangeJobs;import com.sun.electric.tool.user.ExportChanges;import com.sun.electric.tool.user.Highlighter;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.ui.EditWindow;import com.sun.electric.tool.user.ui.MeasureListener;import com.sun.electric.tool.user.ui.TopLevel;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import javax.swing.JOptionPane;/** * Class to handle the "Array" dialog. */public class Array extends EDialog{ /** Space by edge overlap. */ private static final int SPACING_EDGE = 1; /** Space by centerline distance. */ private static final int SPACING_CENTER = 2; /** Space by characteristic distance. */ private static final int SPACING_ESSENTIALBND = 3; /** Space by measured distance. */ private static final int SPACING_MEASURED = 4; private static Pref.Group prefs = Pref.groupForPackage(Array.class); private static Pref prefLinearDiagonal = Pref.makeBooleanPref("Array_LinearDiagonal", prefs, false), prefAddNames = Pref.makeBooleanPref("Array_AddNames", prefs, false), prefDRCGood = Pref.makeBooleanPref("Array_DRCGood", prefs, false), prefTranspose = Pref.makeBooleanPref("Array_Transpose", prefs, false), prefXFlip = Pref.makeBooleanPref("Array_XFlip", prefs, false), prefYFlip = Pref.makeBooleanPref("Array_YFlip", prefs, false), prefXStagger = Pref.makeBooleanPref("Array_XStagger", prefs, false), prefYStagger = Pref.makeBooleanPref("Array_YStagger", prefs, false), prefXCenter = Pref.makeBooleanPref("Array_XCenter", prefs, false), prefYCenter = Pref.makeBooleanPref("Array_YCenter", prefs, false), prefSpacingType = Pref.makeIntPref("Array_SpacingType", prefs, SPACING_EDGE), prefXRepeat = Pref.makeIntPref("Array_XRepeat", prefs, 1), prefYRepeat = Pref.makeIntPref("Array_YRepeat", prefs, 1), prefXDistance = Pref.makeDoublePref("Array_XDistance", prefs, 0), prefYDistance = Pref.makeDoublePref("Array_YDistance", prefs, 0); /** amount when spacing by edge overlap */ private double spacingOverX, spacingOverY; /** amount when spacing by centerline distance */ private double spacingCenterlineX, spacingCenterlineY; /** amount when spacing by characteristic distance */ private double essentialBndX, essentialBndY; /** amount when spacing by measured distance */ private double spacingMeasuredX, spacingMeasuredY; /** the selected objects to be arrayed */ private Map<Geometric,Geometric> selected; /** the bounds of the selected objects */ private Rectangle2D bounds; /** * Method to display a dialog for arraying the selected circuitry. */ public static void showArrayDialog() { // first make sure something is selected EditWindow wnd = EditWindow.needCurrent(); if (wnd == null) return; Highlighter highlighter = wnd.getHighlighter(); if (highlighter == null) { JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), "Cannot array: nothing is highlighted in this window."); return; } List highs = highlighter.getHighlightedEObjs(true, true); if (highs.size() == 0) { JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), "Select some objects before arraying them."); return; } Array dialog = new Array(TopLevel.getCurrentJFrame()); dialog.setVisible(true); } /** Creates new form Array */ private Array(java.awt.Frame parent) { super(parent, true); initComponents(); getRootPane().setDefaultButton(ok); // make all text fields select-all when entered EDialog.makeTextFieldSelectAllOnTab(xRepeat); EDialog.makeTextFieldSelectAllOnTab(yRepeat); EDialog.makeTextFieldSelectAllOnTab(xSpacing); EDialog.makeTextFieldSelectAllOnTab(ySpacing); // load the repeat factors xRepeat.setText(Integer.toString(prefXRepeat.getInt())); flipAlternateColumns.setSelected(prefXFlip.getBoolean()); staggerAlternateColumns.setSelected(prefXStagger.getBoolean()); centerXAboutOriginal.setSelected(prefXCenter.getBoolean()); yRepeat.setText(Integer.toString(prefYRepeat.getInt())); flipAlternateRows.setSelected(prefYFlip.getBoolean()); staggerAlternateRows.setSelected(prefYStagger.getBoolean()); centerYAboutOriginal.setSelected(prefYCenter.getBoolean()); // see if a single cell instance is selected (in which case DRC validity can be done) onlyDRCCorrect.setEnabled(false); EditWindow wnd = EditWindow.getCurrent(); List<Geometric> highs = wnd.getHighlighter().getHighlightedEObjs(true, true); if (highs.size() == 1) { ElectricObject eObj = highs.get(0); if (eObj instanceof NodeInst) { onlyDRCCorrect.setEnabled(true); } } linearDiagonalArray.setSelected(prefLinearDiagonal.getBoolean()); generateArrayIndices.setSelected(prefAddNames.getBoolean()); onlyDRCCorrect.setSelected(prefDRCGood.getBoolean()); transposePlacement.setSelected(prefTranspose.getBoolean()); // see if a cell was selected which has a characteristic distance essentialBndX = essentialBndY = 0; boolean haveEB = false; for(Geometric eObj : highs) { if (!(eObj instanceof NodeInst)) continue; NodeInst ni = (NodeInst)eObj; if (!ni.isCellInstance()) continue; Cell subCell = (Cell)ni.getProto(); Rectangle2D spacing = subCell.findEssentialBounds(); if (spacing == null) continue; double thisDistX = spacing.getWidth(); double thisDistY = spacing.getHeight(); if (ni.isMirroredAboutXAxis() ^ ni.isMirroredAboutYAxis()) { double swap = thisDistX; thisDistX = thisDistY; thisDistY = swap; } if (haveEB) { if (essentialBndX != thisDistX || essentialBndY != thisDistY) { haveEB = false; break; } } essentialBndX = thisDistX; essentialBndY = thisDistY; haveEB = true; } spaceByEssentialBnd.setEnabled(haveEB); if (haveEB) { if (prefSpacingType.getInt() == SPACING_ESSENTIALBND) { prefXDistance.setDouble(essentialBndX); prefYDistance.setDouble(essentialBndY); } } else { if (prefSpacingType.getInt() == SPACING_ESSENTIALBND) { prefSpacingType.setInt(SPACING_EDGE); prefXDistance.setDouble(0); prefYDistance.setDouble(0); } } // see if there was a measured distance Dimension2D dim = MeasureListener.getLastMeasuredDistance(); if (dim.getWidth() > 0 || dim.getHeight() > 0) { spaceByMeasuredDistance.setEnabled(true); spacingMeasuredX = dim.getWidth(); spacingMeasuredY = dim.getHeight(); if (prefSpacingType.getInt() == SPACING_MEASURED) { prefXDistance.setDouble(spacingMeasuredX); prefYDistance.setDouble(spacingMeasuredY); } } else { spaceByMeasuredDistance.setEnabled(false); if (prefSpacingType.getInt() == SPACING_MEASURED) { prefSpacingType.setInt(SPACING_EDGE); prefXDistance.setDouble(0); prefYDistance.setDouble(0); } } // load the spacing distances xSpacing.setText(TextUtils.formatDouble(prefXDistance.getDouble())); ySpacing.setText(TextUtils.formatDouble(prefYDistance.getDouble())); switch (prefSpacingType.getInt()) { case SPACING_EDGE: spaceByEdgeOverlap.setSelected(true); break; case SPACING_CENTER: spaceByCenterlineDistance.setSelected(true); break; case SPACING_ESSENTIALBND: spaceByEssentialBnd.setSelected(true); break; case SPACING_MEASURED: spaceByMeasuredDistance.setSelected(true); break; } if (prefSpacingType.getInt() == SPACING_EDGE) { xOverlapLabel.setText("X edge overlap:"); yOverlapLabel.setText("Y edge overlap:"); } else { xOverlapLabel.setText("X centerline distance:"); yOverlapLabel.setText("Y centerline distance:"); } // mark the list of nodes and arcs in the cell that will be arrayed selected = new HashMap<Geometric,Geometric>(); for(Geometric eObj : highs) { if (eObj instanceof NodeInst) { selected.put(eObj, eObj); } else if (eObj instanceof ArcInst) { ArcInst ai = (ArcInst)eObj; NodeInst niHead = ai.getHeadPortInst().getNodeInst(); selected.put(niHead, niHead); NodeInst niTail = ai.getTailPortInst().getNodeInst(); selected.put(niTail, niTail); selected.put(ai, ai); } } // determine spacing between arrayed objects boolean first = true; bounds = new Rectangle2D.Double(); for(Geometric geom : selected.keySet()) { if (first) { bounds.setRect(geom.getBounds()); first = false; } else { Rectangle2D.union(bounds, geom.getBounds(), bounds); } } spacingCenterlineX = bounds.getWidth(); spacingCenterlineY = bounds.getHeight(); spacingOverX = spacingOverY = 0; spaceByEdgeOverlap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newSpacingSelected(); } }); spaceByCenterlineDistance.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newSpacingSelected(); } }); spaceByEssentialBnd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newSpacingSelected(); } }); spaceByMeasuredDistance.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { newSpacingSelected(); } }); finishInitialization(); pack(); } protected void escapePressed() { cancel(null); } private void newSpacingSelected() { double x = TextUtils.atof(xSpacing.getText()); double y = TextUtils.atof(ySpacing.getText()); switch (prefSpacingType.getInt()) { case SPACING_EDGE: spacingOverX = x; spacingOverY = y; break; case SPACING_CENTER: spacingCenterlineX = x; spacingCenterlineY = y; break; } if (spaceByEdgeOverlap.isSelected()) prefSpacingType.setInt(SPACING_EDGE); else if (spaceByCenterlineDistance.isSelected()) prefSpacingType.setInt(SPACING_CENTER); else if (spaceByEssentialBnd.isSelected()) prefSpacingType.setInt(SPACING_ESSENTIALBND); else if (spaceByMeasuredDistance.isSelected()) prefSpacingType.setInt(SPACING_MEASURED); if (prefSpacingType.getInt() == SPACING_EDGE) { xOverlapLabel.setText("X edge overlap:"); yOverlapLabel.setText("Y edge overlap:"); } else { xOverlapLabel.setText("X centerline distance:"); yOverlapLabel.setText("Y centerline distance:"); } switch (prefSpacingType.getInt()) { case SPACING_EDGE: x = spacingOverX; y = spacingOverY; break; case SPACING_CENTER: x = spacingCenterlineX; y = spacingCenterlineY; break; case SPACING_ESSENTIALBND: x = essentialBndX; y = essentialBndY; break; case SPACING_MEASURED: x = spacingMeasuredX; y = spacingMeasuredY; break; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?