25
25
package com.sun.electric.plugins.j3d.utils;
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;
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;
196
203
* @param num maximim number of nodes.
198
205
public static void set3DMaxNumNodes(int num) { cache3DMaxNumber.setInt(num); }
207
* Method to get maximum number of nodes to consider a scene graph, by default.
208
* @return maximim number of nodes, by default.
210
public static int getFactory3DMaxNumNodes() { return cache3DMaxNumber.getIntFactoryValue(); }
201
213
* Method to tell whether to draw 3D axes or not.
208
220
* @param on true to draw 3D axes.
210
222
public static void set3DAxesOn(boolean on) { cache3DAxes.setBoolean(on); }
224
* Method to tell whether to draw 3D axes or not, by default.
225
* @return true to draw 3D axes, by default.
227
public static boolean isFactory3DAxesOn() { return cache3DAxes.getBooleanFactoryValue(); }
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.
222
239
public static void set3DCellBndOn(boolean on) { cache3DCellBnd.setBoolean(on); }
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.
244
public static boolean isFactory3DCellBndOn() { return cache3DCellBnd.getBooleanFactoryValue(); }
225
247
* Method to tell whether to draw 3D views with perspective.
232
254
* @param on true to draw 3D views with perspective.
234
256
public static void set3DPerspective(boolean on) { cache3DPerspective.setBoolean(on); }
258
* Method to tell whether to draw 3D views with perspective, by default.
259
* @return true to draw 3D views with perspective, by default.
261
public static boolean isFactory3DPerspective() { return cache3DPerspective.getBooleanFactoryValue(); }
237
264
* Method to tell whether to use antialiasing in 3D view.
244
271
* @param on true to draw 3D views with perspective.
246
273
public static void set3DAntialiasing(boolean on) { cache3DAntialiasing.setBoolean(on); }
275
* Method to tell whether to use antialiasing in 3D view, by default.
276
* @return true to draw 3D views with perspective, by default.
278
public static boolean isFactory3DAntialiasing() { return cache3DAntialiasing.getBooleanFactoryValue(); }
249
281
* Method to get original zoom factor for the view
259
291
public static void set3DOrigZoom(double value) { cache3DOrigZoom.setDouble(value); }
294
* Method to get original zoom factor for the view, by default.
295
* @return original zoom factor, by default.
297
public static double getFactory3DOrigZoom() { return cache3DOrigZoom.getDoubleFactoryValue(); }
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); }
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.
316
public static String getFactory3DRotation() { return cache3DRot.getStringFactoryValue(); }
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.
876
* Method to add a cylindrical shaped element
884
public static Node addCylinder(Point2D[] points, double distance, double thickness,
885
Appearance ap, TransformGroup objTrans)
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();
894
t.setTranslation(bottomCenter);
896
TransformGroup grp = new TransformGroup(t);
897
grp.addChild(cylinder); // adding Primitive to TransformaGroup so location can be modified.
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);
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);
914
for (int i = 0; i < 3; i++)
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);
927
objTrans.addChild(grp);
820
932
* Method to add a polyhedron to the transformation group
821
933
* @param objTrans
823
935
public static Shape3D addPolyhedron(Rectangle2D bounds, double distance, double thickness,
824
Appearance ap, TransformGroup objTrans)
936
Appearance ap, TransformGroup objTrans)
826
938
GeometryInfo gi = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
827
939
double height = thickness + distance;
1018
1130
public static void correctNormals(List<Point3d> topList, List<Point3d> bottomList)
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));
1024
Point3d pn = new Point3d((Point3d)topList.get(topList.size()-1));
1136
Point3d pn = new Point3d(topList.get(topList.size()-1));
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));
1031
1143
// Now the dot product
1032
1144
double dot = aux.dot(new Vector3d(b0));