~ubuntu-branches/ubuntu/jaunty/electric/jaunty

« back to all changes in this revision

Viewing changes to com/sun/electric/plugins/j3d/utils/J3DUtils.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2009-01-08 02:05:08 UTC
  • mfrom: (1.1.2 upstream) (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090108020508-0h3li7zt9mu5gf0i
Tags: 8.08-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
package com.sun.electric.plugins.j3d.utils;
26
26
 
27
27
import com.sun.electric.database.geometry.DBMath;
28
 
import com.sun.electric.database.geometry.GenMath;
29
28
import com.sun.electric.database.text.Pref;
30
29
import com.sun.electric.plugins.j3d.View3DWindow;
31
30
import com.sun.electric.tool.Job;
32
31
import com.sun.electric.tool.io.FileType;
33
32
import com.sun.electric.tool.user.User;
 
33
import com.sun.electric.tool.user.dialogs.ColorPatternPanel;
34
34
import com.sun.electric.tool.user.dialogs.OpenFile;
35
 
import com.sun.electric.tool.user.dialogs.ColorPatternPanel;
36
35
import com.sun.electric.tool.user.dialogs.options.LayersTab;
37
36
import com.sun.j3d.utils.behaviors.interpolators.KBKeyFrame;
38
37
import com.sun.j3d.utils.behaviors.interpolators.TCBKeyFrame;
 
38
import com.sun.j3d.utils.geometry.Cylinder;
39
39
import com.sun.j3d.utils.geometry.GeometryInfo;
40
40
import com.sun.j3d.utils.geometry.NormalGenerator;
 
41
import com.sun.j3d.utils.geometry.Primitive;
41
42
import com.sun.j3d.utils.picking.PickTool;
42
43
import com.sun.j3d.utils.universe.SimpleUniverse;
43
44
 
44
45
import java.awt.Color;
45
46
import java.awt.GraphicsConfiguration;
46
47
import java.awt.geom.PathIterator;
 
48
import java.awt.geom.Point2D;
47
49
import java.awt.geom.Rectangle2D;
48
50
import java.awt.image.BufferedImage;
49
51
import java.io.FileReader;
52
54
import java.util.ArrayList;
53
55
import java.util.Arrays;
54
56
import java.util.Collections;
55
 
import java.util.HashMap;
56
57
import java.util.List;
 
58
import java.util.Map;
57
59
import java.util.Observable;
58
60
import java.util.Observer;
59
61
import java.util.StringTokenizer;
159
161
        cache3DLightDirs.setString(c);
160
162
        setDirections(null);
161
163
    }
 
164
    /**
 
165
         * Method to return the first light direction, by default.
 
166
         * @return the company name to use in schematic frames, by default.
 
167
         */
 
168
        public static String getFactory3DLightDirs() { return cache3DLightDirs.getStringFactoryValue(); }
162
169
 
163
170
    /**
164
171
         * Method to get the color of the axes on the 3D display.
175
182
    }
176
183
        /**
177
184
         * Method to set the color of the axes on the 3D display.
178
 
         * @param c the color of the axes on the 3D display.
 
185
         * @param colors the colors of the axes on the 3D display.
179
186
         */
180
187
        private static void set3DColorAxes(int[] colors)
181
188
    {
186
193
    }
187
194
 
188
195
    /**
189
 
     * Method to get maximum number of nodes to consider a scene graph bi
 
196
     * Method to get maximum number of nodes to consider a scene graph.
190
197
     * The default is "1000".
191
198
     * @return maximim number of nodes.
192
199
     */
196
203
     * @param num maximim number of nodes.
197
204
     */
198
205
    public static void set3DMaxNumNodes(int num) { cache3DMaxNumber.setInt(num); }
 
206
    /**
 
207
     * Method to get maximum number of nodes to consider a scene graph, by default.
 
208
     * @return maximim number of nodes, by default.
 
209
     */
 
210
    public static int getFactory3DMaxNumNodes() { return cache3DMaxNumber.getIntFactoryValue(); }
199
211
 
200
212
    /**
201
213
     * Method to tell whether to draw 3D axes or not.
208
220
     * @param on true to draw 3D axes.
209
221
     */
210
222
    public static void set3DAxesOn(boolean on) { cache3DAxes.setBoolean(on); }
 
223
    /**
 
224
     * Method to tell whether to draw 3D axes or not, by default.
 
225
     * @return true to draw 3D axes, by default.
 
226
     */
 
227
    public static boolean isFactory3DAxesOn() { return cache3DAxes.getBooleanFactoryValue(); }
211
228
 
212
 
        /**
 
229
    /**
213
230
         * Method to tell whether to draw bounding box for the cells.
214
231
         * The default is "true".
215
232
         * @return true to draw bounding box for the cells.
220
237
         * @param on true to draw bounding box for the cells.
221
238
         */
222
239
        public static void set3DCellBndOn(boolean on) { cache3DCellBnd.setBoolean(on); }
 
240
    /**
 
241
         * Method to tell whether to draw bounding box for the cells, by default.
 
242
         * @return true to draw bounding box for the cells, by default.
 
243
         */
 
244
        public static boolean isFactory3DCellBndOn() { return cache3DCellBnd.getBooleanFactoryValue(); }
223
245
 
224
246
        /**
225
247
         * Method to tell whether to draw 3D views with perspective.
232
254
         * @param on true to draw 3D views with perspective.
233
255
         */
234
256
        public static void set3DPerspective(boolean on) { cache3DPerspective.setBoolean(on); }
 
257
        /**
 
258
         * Method to tell whether to draw 3D views with perspective, by default.
 
259
         * @return true to draw 3D views with perspective, by default.
 
260
         */
 
261
        public static boolean isFactory3DPerspective() { return cache3DPerspective.getBooleanFactoryValue(); }
235
262
 
236
263
        /**
237
264
         * Method to tell whether to use antialiasing in 3D view.
244
271
         * @param on true to draw 3D views with perspective.
245
272
         */
246
273
        public static void set3DAntialiasing(boolean on) { cache3DAntialiasing.setBoolean(on); }
 
274
        /**
 
275
         * Method to tell whether to use antialiasing in 3D view, by default.
 
276
         * @return true to draw 3D views with perspective, by default.
 
277
         */
 
278
        public static boolean isFactory3DAntialiasing() { return cache3DAntialiasing.getBooleanFactoryValue(); }
247
279
 
248
280
    /**
249
281
         * Method to get original zoom factor for the view
258
290
         */
259
291
        public static void set3DOrigZoom(double value) { cache3DOrigZoom.setDouble(value); }
260
292
 
 
293
        /**
 
294
         * Method to get original zoom factor for the view, by default.
 
295
         * @return original zoom factor, by default.
 
296
         */
 
297
        public static double getFactory3DOrigZoom() { return cache3DOrigZoom.getDoubleFactoryValue(); }
 
298
 
261
299
    /**
262
300
         * Method to get default rotation for the view along X, Y and Z
263
301
         * The default is (0 0 0) and values are in radiant
272
310
        public static void set3DRotation(String value) { cache3DRot.setString(value); }
273
311
 
274
312
    /**
 
313
         * Method to get factory default rotation for the view along X, Y and Z
 
314
         * @return factory default rotation along X, y and Z axes.
 
315
         */
 
316
        public static String getFactory3DRotation() { return cache3DRot.getStringFactoryValue(); }
 
317
 
 
318
    /**
275
319
         * Method to get current scale factor for Z values.
276
320
         * The default is 1.0
277
321
         * @return scale factor along Z.
285
329
        public static void set3DFactor(double value) { cache3DFactor.setDouble(value); }
286
330
 
287
331
    /**
 
332
         * Method to get current scale factor for Z values, by default.
 
333
         * @return scale factor along Z, by default.
 
334
         */
 
335
        public static double getFactory3DFactor() { return cache3DFactor.getDoubleFactoryValue(); }
 
336
 
 
337
    /**
288
338
         * Method to get current alpha speed for 3D demos
289
339
         * The default is 1000
290
340
         * @return alpha speed.
301
351
        setAlpha(value);
302
352
    }
303
353
 
 
354
        /**
 
355
         * Method to get current alpha speed for 3D demos, by default.
 
356
         * @return alpha speed, by default.
 
357
         */
 
358
        public static int getFactory3DAlpha() { return cache3DAlpha.getIntFactoryValue(); }
 
359
 
304
360
    /**
305
361
     * Method to generate knots for interpolator from a file
306
362
     * @param view3D
817
873
    }
818
874
 
819
875
    /**
 
876
     * Method to add a cylindrical shaped element
 
877
     * @param points
 
878
     * @param distance
 
879
     * @param thickness
 
880
     * @param ap
 
881
     * @param objTrans
 
882
     * @return
 
883
     */
 
884
    public static Node addCylinder(Point2D[] points, double distance, double thickness,
 
885
                                   Appearance ap, TransformGroup objTrans)
 
886
        {
 
887
        double cX = points[0].getX();
 
888
        double cY = points[0].getY();
 
889
        double radius = points[0].distance(points[1]);
 
890
        Cylinder cylinder = new Cylinder((float)radius, (float)thickness, ap);
 
891
        Vector3d bottomCenter = new Vector3d(cX,cY,distance);
 
892
        Transform3D t = new Transform3D();
 
893
        t.rotX(Math.PI/2);
 
894
        t.setTranslation(bottomCenter);
 
895
        t.setScale(1);
 
896
        TransformGroup grp = new TransformGroup(t);
 
897
        grp.addChild(cylinder); // adding Primitive to TransformaGroup so location can be modified.
 
898
 
 
899
        grp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
 
900
        grp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
 
901
        grp.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
 
902
        grp.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
 
903
        grp.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
 
904
        grp.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
 
905
        grp.setCapability(TransformGroup.ALLOW_LOCAL_TO_VWORLD_READ);
 
906
        grp.setCapability(TransformGroup.ALLOW_PICKABLE_READ);
 
907
        grp.setCapability(TransformGroup.ALLOW_BOUNDS_READ);
 
908
 
 
909
        Shape3D[] shapes = new Shape3D[3];
 
910
        shapes[0] = cylinder.getShape(Cylinder.BODY);
 
911
        shapes[1] = cylinder.getShape(Cylinder.TOP);
 
912
        shapes[2] = cylinder.getShape(Cylinder.BOTTOM);
 
913
 
 
914
        for (int i = 0; i < 3; i++)
 
915
        {
 
916
            shapes[i].setCapability(Primitive.ENABLE_PICK_REPORTING);
 
917
            shapes[i].setCapability(Primitive.ENABLE_GEOMETRY_PICKING);
 
918
            shapes[i].setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
 
919
            shapes[i].setCapability(Primitive.ALLOW_PICKABLE_READ);
 
920
            shapes[i].setCapability(Shape3D.ALLOW_APPEARANCE_READ);
 
921
            shapes[i].setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
 
922
            shapes[i].setCapability(Primitive.ALLOW_BOUNDS_READ);
 
923
            shapes[i].setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
 
924
            PickTool.setCapabilities(shapes[i], PickTool.INTERSECT_COORD);
 
925
        }
 
926
 
 
927
        objTrans.addChild(grp);
 
928
        return cylinder;
 
929
    }
 
930
    
 
931
    /**
820
932
         * Method to add a polyhedron to the transformation group
821
933
         * @param objTrans
822
934
         */
823
935
        public static Shape3D addPolyhedron(Rectangle2D bounds, double distance, double thickness,
824
 
                                  Appearance ap, TransformGroup objTrans)
 
936
                                        Appearance ap, TransformGroup objTrans)
825
937
        {
826
938
        GeometryInfo gi = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
827
939
        double height = thickness + distance;
1007
1119
                }
1008
1120
 
1009
1121
                if (shapes.size()>1) System.out.println("Error: case not handled");
1010
 
                return((Shape3D)shapes.get(0));
 
1122
                return shapes.get(0);
1011
1123
        }
1012
1124
 
1013
1125
    /**
1018
1130
    public static void correctNormals(List<Point3d> topList, List<Point3d> bottomList)
1019
1131
    {
1020
1132
        // Determining normal direction
1021
 
        Point3d p0 = (Point3d)topList.get(0);
1022
 
        Point3d p1 = new Point3d((Point3d)topList.get(1));
 
1133
        Point3d p0 = topList.get(0);
 
1134
        Point3d p1 = new Point3d(topList.get(1));
1023
1135
        p1.sub(p0);
1024
 
        Point3d pn = new Point3d((Point3d)topList.get(topList.size()-1));
 
1136
        Point3d pn = new Point3d(topList.get(topList.size()-1));
1025
1137
        pn.sub(p0);
1026
1138
        Vector3d aux = new Vector3d();
1027
1139
        aux.cross(new Vector3d(p1), new Vector3d(pn));
1028
1140
        // the other layer
1029
 
        Point3d b0 = new Point3d((Point3d)bottomList.get(0));
 
1141
        Point3d b0 = new Point3d(bottomList.get(0));
1030
1142
        b0.sub(p0);
1031
1143
        // Now the dot product
1032
1144
        double dot = aux.dot(new Vector3d(b0));
1181
1293
     *******************************************************************************************************/
1182
1294
 
1183
1295
 
1184
 
    public static void get3DColorsInTab(HashMap<String,ColorPatternPanel.Info> transAndSpecialMap)
 
1296
    public static void get3DColorsInTab(Map<String,ColorPatternPanel.Info> transAndSpecialMap)
1185
1297
    {
1186
1298
        // 3D Stuff
1187
1299
                transAndSpecialMap.put("Special: 3D CELL INSTANCES", new ColorPatternPanel.Info(get3DColorInstanceCellPref()));
1228
1340
            set3DColorAxes(colors3D);
1229
1341
            colorChanged = true;
1230
1342
        }
1231
 
        return (colorChanged); // using autoboxing
 
1343
        return Boolean.valueOf(colorChanged);
1232
1344
    }
1233
1345
 
1234
1346
    /*******************************************************************************************************
1264
1376
        }
1265
1377
    }
1266
1378
 
1267
 
 
1268
1379
}