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

📄 j3dutils.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	 * @param value 3D alpha to set.	 */	public static void set3DAlpha(int value)    {        cache3DAlpha.setInt(value);        setAlpha(value);    }	/**	 * Method to get current alpha speed for 3D demos, by default.	 * @return alpha speed, by default.	 */	public static int getFactory3DAlpha() { return cache3DAlpha.getIntFactoryValue(); }    /**     * Method to generate knots for interpolator from a file     * @param view3D     * @return list with knot points. Null if operation was cancelled     */    public static List<J3DUtils.ThreeDDemoKnot> readDemoDataFromFile(View3DWindow view3D)    {        String fileName = OpenFile.chooseInputFile(FileType.TEXT, null);        if (fileName == null) return null; // Cancel        String[] possibleValues = { "Accept All", "OK", "Skip", "Cancel" };        List<J3DUtils.ThreeDDemoKnot> knotList = null;        try {            LineNumberReader lineReader = new LineNumberReader(new FileReader(fileName));            int response = -1;            for(;;)            {                // get keyword from file                String line = lineReader.readLine();                if (line == null) break;                // responce 0 -> Accept All                if (response != 0)                {                    response = Job.getUserInterface().askForChoice("Applying following data " + line, "Action",                  		possibleValues, possibleValues[0]);                    if (response == 2) continue; // skip                    else if (response == 3) break; // cancel option                }                String[] stringValues = parseValues(line, 0);                double[] values = convertValues(stringValues);                if (knotList == null) knotList = new ArrayList<J3DUtils.ThreeDDemoKnot>();                knotList.add(view3D.moveAndRotate(values));            }        } catch (Exception e)        {            e.printStackTrace();        }        return knotList;    }    public static double[] convertValues(String[] stringValues)    {        double[] values = new double[stringValues.length];        for (int i = 0; i < stringValues.length; i++)        {            try            {                values[i] = Double.parseDouble(stringValues[i]);            }            catch (Exception e) // invalid number in line            {                values[i] = lastValidValues[i];            }            lastValidValues[i] = values[i];            if (2 < i && i < 6 )                values[i] = convertToRadiant(values[i]);   // original value is in degrees        }        return values;    }    /**     * To parse capacitance data from line     * Format: posX posY posZ rotX rotY rotZ rotPosX rotPosY rotPosZ capacitance radius error     * @param line     * @param lineNumner     */    public static String[] parseValues(String line, int lineNumner)    {        int count = 0;        String[] strings = new String[VALUES_PER_LINE]; // 12 is the max value including errors        StringTokenizer parse = new StringTokenizer(line, " ", false);        while (parse.hasMoreTokens() && count < VALUES_PER_LINE)        {            strings[count++] = parse.nextToken();        }        if (count < 9 || count > 13)        {            System.out.println("Error reading capacitance file in line " + lineNumner);        }        return strings;    }    /**	 * Method to get the color of the cell instance on the 3D display.	 * The default is "gray".	 * @return the color of the cell instance on the 3D display.	 */	public static int get3DColorInstanceCell() { return get3DColorInstanceCellPref().getInt(); }    public static Pref get3DColorInstanceCellPref () { return cache3DColorInstanceCell; }    /**	 * Method to set the color of the cell instance on the 3D display.	 * @param c the color of the cell instance on the 3D display.	 */	public static void set3DColorInstanceCell(int c)    {        get3DColorInstanceCellPref().setInt(c);        J3DAppearance.setCellAppearanceValues(null);    }    /**	 * Method to get the color of the highlighted instance on the 3D display.	 * The default is "gray".	 * @return the color of the highlighted instance on the 3D display.	 */	public static int get3DColorHighlighted() { return get3DColorHighlightedPref().getInt(); }    public static Pref get3DColorHighlightedPref() { return cache3DColorHighlighted; }    /**	 * Method to set the color of the highlighted instance on the 3D display.	 * @param c the color of the highlighted instance on the 3D display.	 */	public static void set3DColorHighlighted(int c)    {        get3DColorHighlightedPref().setInt(c);        J3DAppearance.setHighlightedAppearanceValues(null);    }    /**	 * Method to get the ambiental color on the 3D display.	 * The default is "gray".	 * @return the ambiental color on the 3D display.	 */	public static int get3DColorAmbientLight() { return get3DColorAmbientLightPref().getInt(); }    public static Pref get3DColorAmbientLightPref() { return cache3DColorAmbient; }    /**	 * Method to set the ambiental color on the 3D display.	 * @param c the ambiental color on the 3D display.	 */	public static void set3DColorAmbientLight(int c)    {        get3DColorAmbientLightPref().setInt(c);        setAmbientalColor(null);    }    /********************************************************************************************************     *   Observer-Observable pattern for Vector3f     *******************************************************************************************************/    /**     * Class using view-model paradigm to update Vector3d-type of variables like directions     */    private static class Vector3fObservable extends Observable    {        private Vector3f vector;        public Vector3fObservable(Vector3f vec)        {            this.vector = vec;        }        public void setValue(Vector3f vec)        {            this.vector = vec;            setChanged();            notifyObservers(vector);            clearChanged();        }        public Vector3f getValue() {return vector;}    }    /**     * Observer class for directional light     */    private static class DirectionalLightObserver extends DirectionalLight implements Observer    {        public DirectionalLightObserver(Color3f color3f, Vector3f vector3f)        {            super(color3f, vector3f);        }        public void update(Observable o, Object arg)        {            if (arg != null)            {                if (arg instanceof Vector3f) // Change direction                {                    // change the direction                    setDirection((Vector3f)arg);                    return;                }                if (arg instanceof Color3f) // Change direction                {                    // change the direction                    setColor((Color3f)arg);                    return;                }            }        }    }    /********************************************************************************************************     *   Observer-Observable pattern for Color3f     *******************************************************************************************************/    private static class Color3fObservable extends Observable    {        private Color3f color;        public Color3fObservable(Color3f color)        {            this.color = color;        }        public void setValue(Color3f color)        {            this.color = color;            setChanged();            notifyObservers(color);            clearChanged();        }        public Color3f getValue() {return color;}    }    private static class AmbientLightObserver extends AmbientLight implements Observer    {        public AmbientLightObserver(Color3f color3f)        {            super(color3f);        }        public void update(Observable o, Object arg)        {            if (arg != null && arg instanceof Color3f)            {                // change the color                setColor((Color3f)arg);            }        }    }    private static class BackgroundObserver extends Background implements Observer    {        public BackgroundObserver(Color3f color3f)        {            super(color3f);            setCapability(Background.ALLOW_COLOR_WRITE);            setCapability(Background.ALLOW_COLOR_READ);        }        public void update(Observable o, Object arg)        {            if (arg != null && arg instanceof Color3f)            {                // change the color                setColor((Color3f)arg);            }        }    }    public static Vector3f[] transformIntoVectors(String dir)    {        float[][] values = new float[2][3];        StringTokenizer parse = new StringTokenizer(dir, "()", false);        int pair = 0;        while (parse.hasMoreTokens() && pair < 2)        {            String vector = parse.nextToken();            StringTokenizer parseDir = new StringTokenizer(vector, " )", false);            int count = 0;            while (parseDir.hasMoreTokens() && count < 3)            {                String value = parseDir.nextToken();                values[pair][count++] = Float.parseFloat(value);            }            pair++;        }        Vector3f[] vectors = new Vector3f[2];        for (int i = 0; i < 2; i++)        {            if (!(values[i][0] == 0 && values[i][1] == 0 && values[i][2] == 0))                vectors[i]= new Vector3f(values[i]);        }        return (vectors);    }    /**     * Method to set direction in directional light     * @param initValue     */    public static void setDirections(Object initValue)    {        Vector3f[] dirs = transformIntoVectors(get3DLightDirs());        for (int i = 0; i < dirs.length; i++)        {            if (lights[i] == null)                lights[i] = new Vector3fObservable(dirs[i]);            else if (initValue == null)                lights[i].setValue(dirs[i]); // it will notify observers        }    }    /**     * Method to set ambiental color     * @param initValue null if value has to be redone from user data     */    public static void setAmbientalColor(Object initValue)    {        Color3f userColor = new Color3f(new Color(get3DColorAmbientLight()));        if (ambientalColor == null)            ambientalColor = new Color3fObservable(userColor);        else if (initValue == null)            ambientalColor.setValue(userColor);    }    /**     * Method to set directional color     * @param initValue null if value has to be redone from user data     */    public static void setDirectionalColor(Object initValue)    {        Color3f userColor = new Color3f(new Color(get3DColorDirectionalLight()));        if (directionalColor == null)            directionalColor = new Color3fObservable(userColor);        else if (initValue == null)            directionalColor.setValue(userColor);    }    /**     * Method to set background color     * @param initValue null if value has to be redone from user data     */    public static void setBackgroundColor(Object initValue)    {        Color3f userColor = new Color3f(new Color(User.getColor(User.ColorPrefType.BACKGROUND)));        if (backgroundColor == null)            backgroundColor = new Color3fObservable(userColor);        else if (initValue == null)            backgroundColor.setValue(userColor);

⌨️ 快捷键说明

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