1 package org.jcae.opencascade.jni;
3 import static org.junit.Assert.*;
7 import java.util.ArrayList;
9 /*import org.jcae.viewer3d.View;
10 import org.jcae.viewer3d.cad.ViewableCAD;
11 import org.jcae.viewer3d.cad.occ.OCCProvider;*/
13 /** Test circles, extrude, BRepTools_Quilt */
14 public class CircleExtrudeQuilt
16 /** Easy creation of faces */
17 private static TopoDS_Face createFace(TopoDS_Edge e1)
19 TopoDS_Wire wirePlate=
20 (TopoDS_Wire) new BRepBuilderAPI_MakeWire(e1).shape();
21 return (TopoDS_Face) new BRepBuilderAPI_MakeFace(wirePlate, true).shape();
24 private static TopoDS_Edge getLastEdge(TopoDS_Shape shape)
26 TopExp_Explorer exp=new TopExp_Explorer(shape, TopAbs_ShapeEnum.EDGE);
27 TopoDS_Edge lastEdge=null;
30 lastEdge=(TopoDS_Edge) exp.current();
36 private static TopoDS_Edge createCircle(double cx, double cy, double cz, double dx, double dy, double dz, double radius)
38 GP_Circ circleB=new GP_Circ(new double[]{cx, cy, cz, dx, dy, dz}, radius);
39 return (TopoDS_Edge) new BRepBuilderAPI_MakeEdge(circleB).shape();
42 private static TopoDS_Face createFace(TopoDS_Wire wire1, TopoDS_Wire wire2)
44 TopoDS_Face face=(TopoDS_Face) new BRepBuilderAPI_MakeFace(wire1, true).shape();
45 return (TopoDS_Face) new BRepBuilderAPI_MakeFace(face, wire2).shape();
48 private static TopoDS_Shell[] createShell(TopoDS_Face[] faces)
50 BRepTools_Quilt quil=new BRepTools_Quilt();
51 for(int i=0; i<faces.length; i++)
55 TopExp_Explorer exp=new TopExp_Explorer(quil.shells(), TopAbs_ShapeEnum.SHELL);
56 ArrayList list=new ArrayList();
59 list.add(exp.current());
62 return (TopoDS_Shell[]) list.toArray(new TopoDS_Shell[0]);
65 private static TopoDS_Face extrude(TopoDS_Shape shape, double vx, double vy, double vz)
67 return (TopoDS_Face) new BRepPrimAPI_MakePrism(
68 shape, new double[]{vx, vy, vz}).shape();
71 private static TopoDS_Face[] getFaces(TopoDS_Shape shape)
73 TopExp_Explorer exp=new TopExp_Explorer(shape, TopAbs_ShapeEnum.FACE);
74 ArrayList list=new ArrayList();
77 list.add(exp.current());
80 return (TopoDS_Face[]) list.toArray(new TopoDS_Face[0]);
83 private static TopoDS_Wire[] getWires(TopoDS_Shape shape)
85 TopExp_Explorer exp=new TopExp_Explorer(shape, TopAbs_ShapeEnum.WIRE);
86 ArrayList list=new ArrayList();
89 System.out.println(exp.current());
90 list.add(exp.current());
93 return (TopoDS_Wire[]) list.toArray(new TopoDS_Wire[0]);
96 private static TopoDS_Wire createWire(TopoDS_Edge edge)
98 return (TopoDS_Wire) new BRepBuilderAPI_MakeWire(edge).shape();
101 @Test public void sample()
105 //Create a holed cylinder
106 TopoDS_Edge circleB=createCircle(0, 0, -1E-3, 0, 0, 1, 4E-3);
107 TopoDS_Edge circleSP1=createCircle(0, 0, 0, 0, 0, 1, 1E-3);
108 TopoDS_Face cylinderS=extrude(circleSP1, 0, 0, -0.016);
109 TopoDS_Face cylinderBzM=(TopoDS_Face) extrude(circleB, 0, 0, -0.015).reversed();
110 TopoDS_Face cylinderBzP=extrude(circleB, 0, 0, 1E-3);
112 TopoDS_Face hdSurface=(TopoDS_Face) createFace(
113 createWire(getLastEdge(cylinderBzM)),
114 createWire(getLastEdge(cylinderS))).reversed();
116 //Create a cylinder with a large disc sewed to it's base
118 TopoDS_Face cylinderDiscP2=createFace(
119 createWire(getLastEdge(cylinderBzP)), createWire(circleSP1));
120 TopoDS_Face cylinderSzP=extrude(circleSP1, 0, 0, 7.5E-3);
121 TopoDS_Face cylinderDiscSzP=createFace(getLastEdge(cylinderSzP));
124 TopoDS_Solid box=(TopoDS_Solid) new BRepPrimAPI_MakeBox(
125 new double[]{4.5E-2,0.03,-0.001},
126 new double[]{-4.5E-2,-0.03,0}).shape();
127 //Make a hole in the box
128 TopoDS_Face[] boxFaces=getFaces(box);
129 TopoDS_Face squareZm=boxFaces[4];
130 TopoDS_Face squareZp=boxFaces[5];
133 getWires(squareZm)[0],
134 (TopoDS_Wire) createWire(circleB).reversed());
136 squareZp=createFace(getWires(squareZp)[0], getWires(cylinderDiscP2)[0]);
137 TopoDS_Face[] holedBoxFaces=new TopoDS_Face[]{
145 TopoDS_Solid holedBox=(TopoDS_Solid) new BRepBuilderAPI_MakeSolid(
146 createShell(holedBoxFaces)[0]).shape();
148 //Put it all together
149 BRep_Builder bb=new BRep_Builder();
150 TopoDS_Compound compound=new TopoDS_Compound();
151 bb.makeCompound(compound);
152 bb.add(compound, holedBox);
153 bb.add(compound, cylinderBzM);
154 bb.add(compound, cylinderS);
155 bb.add(compound, hdSurface);
156 bb.add(compound, cylinderDiscP2);
157 bb.add(compound, cylinderSzP);
158 bb.add(compound, cylinderDiscSzP);
159 bb.add(compound, cylinderBzP);
162 BRepTools.write(compound, File.createTempFile("circleExtrude", ".brep").getPath());
165 //display("/tmp/Solid_1.brep");
169 ex.printStackTrace();
174 * Display the geometry (viewer3d required)
176 /*public static void display(String file)
178 JFrame cadFrame=new JFrame("jcae-viewer3d-cad demo");
179 cadFrame.setSize(800,600);
180 cadFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
181 final View cadView=new View(cadFrame);
183 ViewableCAD fcad=new ViewableCAD(new OCCProvider(file));
186 cadFrame.getContentPane().add(cadView);
187 cadFrame.getContentPane().add(new JButton(new AbstractAction(){
189 public void actionPerformed(ActionEvent e)
192 }}), BorderLayout.NORTH);
194 cadFrame.setVisible(true);
195 cadView.setOriginAxisVisible(true);