📄 j3dutils.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: J3DUtils.java * Written by Gilda Garreton, Sun Microsystems. * * 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.plugins.j3d.utils;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.text.Pref;import com.sun.electric.plugins.j3d.View3DWindow;import com.sun.electric.tool.Job;import com.sun.electric.tool.io.FileType;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.dialogs.ColorPatternPanel;import com.sun.electric.tool.user.dialogs.OpenFile;import com.sun.electric.tool.user.dialogs.options.LayersTab;import com.sun.j3d.utils.behaviors.interpolators.KBKeyFrame;import com.sun.j3d.utils.behaviors.interpolators.TCBKeyFrame;import com.sun.j3d.utils.geometry.Cylinder;import com.sun.j3d.utils.geometry.GeometryInfo;import com.sun.j3d.utils.geometry.NormalGenerator;import com.sun.j3d.utils.geometry.Primitive;import com.sun.j3d.utils.picking.PickTool;import com.sun.j3d.utils.universe.SimpleUniverse;import java.awt.Color;import java.awt.GraphicsConfiguration;import java.awt.geom.PathIterator;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.awt.image.BufferedImage;import java.io.FileReader;import java.io.LineNumberReader;import java.io.Serializable;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.List;import java.util.Map;import java.util.Observable;import java.util.Observer;import java.util.StringTokenizer;import javax.media.j3d.AmbientLight;import javax.media.j3d.Appearance;import javax.media.j3d.Background;import javax.media.j3d.BoundingSphere;import javax.media.j3d.BranchGroup;import javax.media.j3d.Canvas3D;import javax.media.j3d.DirectionalLight;import javax.media.j3d.Geometry;import javax.media.j3d.GeometryArray;import javax.media.j3d.GeometryUpdater;import javax.media.j3d.ImageComponent;import javax.media.j3d.ImageComponent2D;import javax.media.j3d.Light;import javax.media.j3d.Node;import javax.media.j3d.Shape3D;import javax.media.j3d.Transform3D;import javax.media.j3d.TransformGroup;import javax.media.j3d.View;import javax.vecmath.Color3f;import javax.vecmath.Point3d;import javax.vecmath.Point3f;import javax.vecmath.Quat4f;import javax.vecmath.Vector3d;import javax.vecmath.Vector3f;import javax.vecmath.Vector4f;/** * Utility class for 3D module * @author Gilda Garreton * @version 0.1 */public final class J3DUtils{ /** standard colors to be used by materials **/ public static final Color3f black = new Color3f(0.0f, 0.0f, 0.0f);// /** standard colors to be used by materials **/ public static final Color3f white = new Color3f(1.0f, 1.0f, 1.0f); /** standard colors to be used by materials **/ public static final Color3f plastic = new Color3f(0.89f, 0.89f, 0.89f); /** Ambiental light color **/ private static Color3fObservable ambientalColor; /** Directional light color **/ private static Color3fObservable directionalColor; /** Background color **/ private static Color3fObservable backgroundColor; /** Directional vectors **/ private static Vector3fObservable[] lights = new Vector3fObservable[2]; // = new Vector3f(-1.0f, -1.0f, -1.0f); public static final BoundingSphere infiniteBounds = new BoundingSphere(new Point3d(), Double.MAX_VALUE); private static Pref cache3DOrigZoom = Pref.makeDoublePref("3DOrigZoom3D", User.getUserTool().prefs, 1); private static Pref cache3DRot = Pref.makeStringPref("3DRotation", User.getUserTool().prefs, "(0 0 0)"); private static Pref cache3DFactor = Pref.makeDoublePref("3DScaleZ", User.getUserTool().prefs, 1.0); private static Pref cache3DAntialiasing = Pref.makeBooleanPref("3DAntialiasing", User.getUserTool().prefs, false); private static Pref cache3DPerspective = Pref.makeBooleanPref("3DPerspective", User.getUserTool().prefs, true); private static Pref cache3DCellBnd = Pref.makeBooleanPref("3DCellBnd", User.getUserTool().prefs, true); private static Pref cache3DAxes = Pref.makeBooleanPref("3DAxes", User.getUserTool().prefs, false); private static Pref cache3DMaxNumber = Pref.makeIntPref("3DMaxNumNodes", User.getUserTool().prefs, 1000); private static Pref cache3DAlpha = Pref.makeIntPref("3DAlpha", User.getUserTool().prefs, 20000); private static Pref cache3DColorInstanceCell = Pref.makeIntPref("3DColorInstanceCell", User.getUserTool().prefs, Color.GRAY.getRGB()); private static Pref cache3DColorHighlighted = Pref.makeIntPref("3DColorHighlighted", User.getUserTool().prefs, Color.GRAY.getRGB()); private static Pref cache3DColorAmbient = Pref.makeIntPref("3DColorAmbient", User.getUserTool().prefs, Color.GRAY.getRGB()); private static Pref cache3DColorAxisX = Pref.makeIntPref("3DColorAxisX", User.getUserTool().prefs, Color.RED.getRGB()); private static Pref cache3DColorAxisY = Pref.makeIntPref("3DColorAxisY", User.getUserTool().prefs, Color.BLUE.getRGB()); private static Pref cache3DColorAxisZ = Pref.makeIntPref("3DColorAxisZ", User.getUserTool().prefs, Color.GREEN.getRGB());// private static Pref cache3DColorAxes = Pref.makeStringPref("3DColorAxes", User.getUserTool().prefs,// "("+Color.RED.getRGB()+" "+ Color.BLUE.getRGB() + " "+ Color.GREEN.getRGB() + ")"); private static Pref cache3DColorDirectionalLight = Pref.makeIntPref("3DColorDirectionalLight", User.getUserTool().prefs, Color.GRAY.getRGB()); private static Pref cache3DLightDirs = Pref.makeStringPref("3DLightDirs", User.getUserTool().prefs, "(-1 1 -1)(1 -1 -1)"); public static J3DAlpha jAlpha = null; // For reading data files (capacitance) private static final int VALUES_PER_LINE = 11; private static double[] lastValidValues = new double[VALUES_PER_LINE]; /** * Method to get the color of directional light on the 3D display. * The default is "gray". * @return the color of directional light on the 3D display. */ public static int get3DColorDirectionalLight() { return get3DColorDirectionalLightPref().getInt(); } public static Pref get3DColorDirectionalLightPref() { return cache3DColorDirectionalLight; } /** * Method to set the color of directional light on the 3D display. * @param c the color of directional light on the 3D display. */ public static void set3DColorDirectionalLight(int c) { get3DColorDirectionalLightPref().setInt(c); setDirectionalColor(null); } /** * Method to return the first light direction. * The default is the X axis. * @return the company name to use in schematic frames. */ public static String get3DLightDirs() { return cache3DLightDirs.getString(); } /** * Method to set the first light direction. * It is stored as string * @param c the company name to use in schematic frames. */ public static void set3DLightDirs(String c) { cache3DLightDirs.setString(c); setDirections(null); } /** * Method to return the first light direction, by default. * @return the company name to use in schematic frames, by default. */ public static String getFactory3DLightDirs() { return cache3DLightDirs.getStringFactoryValue(); } /** * Method to get the color of the axes on the 3D display. * The default values are "red", "blue" and "green".. * @return the color of the axes on the 3D display. */ public static int[] get3DColorAxes() { int[] values = new int[3]; values[0] = cache3DColorAxisX.getInt(); values[1] = cache3DColorAxisY.getInt(); values[2] = cache3DColorAxisZ.getInt(); return values; } /** * Method to set the color of the axes on the 3D display. * @param colors the colors of the axes on the 3D display. */ private static void set3DColorAxes(int[] colors) { cache3DColorAxisX.setInt(colors[0]); cache3DColorAxisY.setInt(colors[1]); cache3DColorAxisZ.setInt(colors[2]); J3DAppearance.setAxisAppearanceValues(null); } /** * Method to get maximum number of nodes to consider a scene graph. * The default is "1000". * @return maximim number of nodes. */ public static int get3DMaxNumNodes() { return cache3DMaxNumber.getInt(); } /** * Method to set maximum number of nodes to display in 3D view. * @param num maximim number of nodes. */ public static void set3DMaxNumNodes(int num) { cache3DMaxNumber.setInt(num); } /** * Method to get maximum number of nodes to consider a scene graph, by default. * @return maximim number of nodes, by default. */ public static int getFactory3DMaxNumNodes() { return cache3DMaxNumber.getIntFactoryValue(); } /** * Method to tell whether to draw 3D axes or not. * The default is "true". * @return true to draw 3D axes. */ public static boolean is3DAxesOn() { return cache3DAxes.getBoolean(); } /** * Method to set whether to draw 3D axes or not. * @param on true to draw 3D axes. */ public static void set3DAxesOn(boolean on) { cache3DAxes.setBoolean(on); } /** * Method to tell whether to draw 3D axes or not, by default. * @return true to draw 3D axes, by default. */ public static boolean isFactory3DAxesOn() { return cache3DAxes.getBooleanFactoryValue(); } /** * Method to tell whether to draw bounding box for the cells. * The default is "true". * @return true to draw bounding box for the cells. */ public static boolean is3DCellBndOn() { return cache3DCellBnd.getBoolean(); } /** * Method to set whether to draw bounding box for the cells. * @param on true to draw bounding box for the cells. */ public static void set3DCellBndOn(boolean on) { cache3DCellBnd.setBoolean(on); } /** * Method to tell whether to draw bounding box for the cells, by default. * @return true to draw bounding box for the cells, by default. */ public static boolean isFactory3DCellBndOn() { return cache3DCellBnd.getBooleanFactoryValue(); } /** * Method to tell whether to draw 3D views with perspective. * The default is "true". * @return true to draw 3D views with perspective. */ public static boolean is3DPerspective() { return cache3DPerspective.getBoolean(); } /** * Method to set whether to draw 3D views with perspective. * @param on true to draw 3D views with perspective. */ public static void set3DPerspective(boolean on) { cache3DPerspective.setBoolean(on); } /** * Method to tell whether to draw 3D views with perspective, by default. * @return true to draw 3D views with perspective, by default. */ public static boolean isFactory3DPerspective() { return cache3DPerspective.getBooleanFactoryValue(); } /** * Method to tell whether to use antialiasing in 3D view. * The default is "false" due to performance. * @return true to draw 3D views with perspective. */ public static boolean is3DAntialiasing() { return cache3DAntialiasing.getBoolean(); } /** * Method to set whether to draw 3D views with perspective. * @param on true to draw 3D views with perspective. */ public static void set3DAntialiasing(boolean on) { cache3DAntialiasing.setBoolean(on); } /** * Method to tell whether to use antialiasing in 3D view, by default. * @return true to draw 3D views with perspective, by default. */ public static boolean isFactory3DAntialiasing() { return cache3DAntialiasing.getBooleanFactoryValue(); } /** * Method to get original zoom factor for the view * The default is 1 * @return original zoom factor */ public static double get3DOrigZoom() { return cache3DOrigZoom.getDouble(); } /** * Method to set default zoom factor * @param value zoom factor */ public static void set3DOrigZoom(double value) { cache3DOrigZoom.setDouble(value); } /** * Method to get original zoom factor for the view, by default. * @return original zoom factor, by default. */ public static double getFactory3DOrigZoom() { return cache3DOrigZoom.getDoubleFactoryValue(); } /** * Method to get default rotation for the view along X, Y and Z * The default is (0 0 0) and values are in radiant * @return rotation along X, y and Z axes. */ public static String get3DRotation() { return cache3DRot.getString(); } /** * Method to set default rotation angles along X, Y and Z. Values are in radiant * @param value angles on X, Y and Z */ public static void set3DRotation(String value) { cache3DRot.setString(value); } /** * Method to get factory default rotation for the view along X, Y and Z * @return factory default rotation along X, y and Z axes. */ public static String getFactory3DRotation() { return cache3DRot.getStringFactoryValue(); } /** * Method to get current scale factor for Z values. * The default is 1.0 * @return scale factor along Z. */ public static double get3DFactor() { return cache3DFactor.getDouble(); } /** * Method to set 3D scale factor * @param value 3D scale factor to set. */ public static void set3DFactor(double value) { cache3DFactor.setDouble(value); } /** * Method to get current scale factor for Z values, by default. * @return scale factor along Z, by default. */ public static double getFactory3DFactor() { return cache3DFactor.getDoubleFactoryValue(); } /** * Method to get current alpha speed for 3D demos * The default is 1000 * @return alpha speed. */ public static int get3DAlpha() { return cache3DAlpha.getInt(); } /** * Method to set 3D alpha speed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -