public override bool Run(FeatureContext context) { AdvFeatureTools advTool = new AdvFeatureTools(); // Create the evolution spline Primitive2dTools tool2d = new Primitive2dTools(); float radius = 50; TopoShapeGroup group = new TopoShapeGroup(); group.Add(tool2d.MakeArc(new Vector2(0, radius), radius, 0, 45)); group.Add(tool2d.MakeLine(new Vector2(radius, radius), new Vector2(radius * 2, radius))); TopoShape spline = tool2d.ToBSplineCurve(group); // Create the profile section TopoShape profile = GlobalInstance.BrepTools.MakeCircle(new Vector3(100, 100, 0), 1, Vector3.UNIT_Z); // Create the path List <Vector3> pts = new List <Vector3>(); pts.Add(new Vector3(100, 100, 0)); pts.Add(new Vector3(100, 100, 100)); pts.Add(new Vector3(100, 200, 400)); TopoShape path = GlobalInstance.BrepTools.MakeSpline(pts); // Make sweep TopoShape sweepBody = advTool.MakeSweep(profile, path, spline, true); context.ShowGeometry(sweepBody); return(true); }
public override bool Run(FeatureContext context) { float y = 10; TopoShape line1 = GlobalInstance.BrepTools.MakeLine(new Vector3(0, 0, 0 + y), new Vector3(4, 0, 0 + y)); TopoShape line2 = GlobalInstance.BrepTools.MakeLine(new Vector3(4, 0, 0 + y), new Vector3(4, 0, 0.5f + y)); TopoShape line3 = GlobalInstance.BrepTools.MakeLine(new Vector3(4, 0, 0.5f + y), new Vector3(1, 0, 0.5f + y)); TopoShape line4 = GlobalInstance.BrepTools.MakeLine(new Vector3(1, 0, 0.5f + y), new Vector3(1, 0, 4 + y)); TopoShape line5 = GlobalInstance.BrepTools.MakeLine(new Vector3(1, 0, 4 + y), new Vector3(0.5f, 0, 4 + y)); TopoShape line6 = GlobalInstance.BrepTools.MakeLine(new Vector3(0.5f, 0, 4 + y), new Vector3(0.5f, 0, 0.5f + y)); TopoShape line7 = GlobalInstance.BrepTools.MakeLine(new Vector3(0.5f, 0, 0.5f + y), new Vector3(0, 0, 0.5f + y)); TopoShape line8 = GlobalInstance.BrepTools.MakeLine(new Vector3(0, 0, 0.5f + y), new Vector3(0, 0, 0 + y)); TopoShapeGroup shapeGroup = new TopoShapeGroup(); shapeGroup.Add(line2); shapeGroup.Add(line3); shapeGroup.Add(line4); shapeGroup.Add(line5); shapeGroup.Add(line6); shapeGroup.Add(line7); shapeGroup.Add(line8); shapeGroup.Add(line1); TopoShape profile = GlobalInstance.BrepTools.MakeWire(shapeGroup); TopoShape line9 = GlobalInstance.BrepTools.MakeLine(new Vector3(0, 0, 0 + y), new Vector3(0, -20, 0 + y)); TopoShapeGroup lineGroup = new TopoShapeGroup(); lineGroup.Add(line9); TopoShape wire = GlobalInstance.BrepTools.MakeWire(lineGroup); TopoShape sweep = GlobalInstance.BrepTools.Sweep(profile, wire, true); TopoShape line10 = GlobalInstance.BrepTools.MakeLine(new Vector3(1, 0, 0.5f + y), new Vector3(1, 0, 3 + y)); TopoShape line11 = GlobalInstance.BrepTools.MakeLine(new Vector3(1, 0, 3 + y), new Vector3(2, 0, 3 + y)); TopoShape line12 = GlobalInstance.BrepTools.MakeLine(new Vector3(2, 0, 3 + y), new Vector3(2, 0, 0.5f + y)); TopoShape line13 = GlobalInstance.BrepTools.MakeLine(new Vector3(2, 0, 0.5f + y), new Vector3(1, 0, 0.5f + y)); TopoShapeGroup shapeGroup1 = new TopoShapeGroup(); shapeGroup1.Add(line10); shapeGroup1.Add(line11); shapeGroup1.Add(line12); shapeGroup1.Add(line13); TopoShape profile1 = GlobalInstance.BrepTools.MakeWire(shapeGroup1); TopoShape line14 = GlobalInstance.BrepTools.MakeLine(new Vector3(1, 0, 0.5f + y), new Vector3(1, -0.5f, 0.5f + y)); TopoShapeGroup lineGroup1 = new TopoShapeGroup(); lineGroup1.Add(line14); TopoShape wire1 = GlobalInstance.BrepTools.MakeWire(lineGroup1); TopoShape sweep1 = GlobalInstance.BrepTools.Sweep(profile1, wire1, true); TopoShape comp = GlobalInstance.BrepTools.BooleanAdd(sweep, sweep1); RepairTools rt = new RepairTools(); comp = rt.RemoveExtraEdges(comp); context.ShowGeometry(comp); return(true); }
public override bool Run(FeatureContext context) { // 1. Create Solid by extrude the section Vector3 start = new Vector3(100, 0, 0); Vector3 end = new Vector3(0, 100, 0); TopoShapeGroup group = new TopoShapeGroup(); group.Add(GlobalInstance.BrepTools.MakeArc(start, end, Vector3.ZERO, Vector3.UNIT_Z)); group.Add(GlobalInstance.BrepTools.MakeLine(Vector3.ZERO, start)); group.Add(GlobalInstance.BrepTools.MakeLine(Vector3.ZERO, end)); TopoShape section = GlobalInstance.BrepTools.MakeWire(group); TopoShape face = GlobalInstance.BrepTools.MakeFace(section); TopoShape solid = GlobalInstance.BrepTools.Extrude(face, 50, Vector3.UNIT_Z); // 2. Fillet the specified edges with different radius. int[] edges = { 4, 6, 8 }; float[] radius = { 5, 5, 10 }; TopoShape chamfer = GlobalInstance.BrepTools.MakeFillet(solid, edges, radius); context.ShowGeometry(chamfer); return(true); }
private void extrudeToolStripMenuItem_Click(object sender, EventArgs e) { int size = 20; // Create the outline edge TopoShape arc = GlobalInstance.BrepTools.MakeArc3Pts(new Vector3(-size, 0, 0), new Vector3(size, 0, 0), new Vector3(0, size, 0)); TopoShape line1 = GlobalInstance.BrepTools.MakeLine(new Vector3(-size, -size, 0), new Vector3(-size, 0, 0)); TopoShape line2 = GlobalInstance.BrepTools.MakeLine(new Vector3(size, -size, 0), new Vector3(size, 0, 0)); TopoShape line3 = GlobalInstance.BrepTools.MakeLine(new Vector3(-size, -size, 0), new Vector3(size, -size, 0)); TopoShapeGroup shapeGroup = new TopoShapeGroup(); shapeGroup.Add(line1); shapeGroup.Add(arc); shapeGroup.Add(line2); shapeGroup.Add(line3); TopoShape wire = GlobalInstance.BrepTools.MakeWire(shapeGroup); TopoShape face = GlobalInstance.BrepTools.MakeFace(wire); // Extrude TopoShape extrude = GlobalInstance.BrepTools.Extrude(face, 100, new Vector3(0, 0, 1)); renderView.ShowGeometry(extrude, ++shapeId); // Check find.... SceneNode findNode = renderView.SceneManager.FindNode(shapeId); renderView.SceneManager.SelectNode(findNode); }
public override bool Run(FeatureContext context) { // Split box with two spheres. TopoShape box = GlobalInstance.BrepTools.MakeBox(Vector3.ZERO, Vector3.UNIT_Z, new Vector3(150f, 150f, 150f)); TopoShape sphere = GlobalInstance.BrepTools.MakeSphere(Vector3.ZERO, 100f); TopoShape sphere2 = GlobalInstance.BrepTools.MakeSphere(Vector3.ZERO, 50f); TopoShapeGroup tools = new TopoShapeGroup(); tools.Add(sphere); tools.Add(sphere2); TopoShape split = GlobalInstance.BrepTools.MakeSplit(box, tools); // Display the results with customized face styles. TopoExplor expo = new TopoExplor(); TopoShapeGroup bodies = expo.ExplorSolids(split); Random random = new Random(); for (int ii = 0; ii < bodies.Size(); ++ii) { SceneNode node = context.ShowGeometry(bodies.GetTopoShape(ii)); FaceStyle fs = new FaceStyle(); fs.SetColor(new ColorValue((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 0.5f)); fs.SetTransparent(true); node.SetFaceStyle(fs); } return(true); }
private void projectionToolStripMenuItem_Click(object sender, EventArgs e) { // construct a wire; Vector3List points = new Vector3List(); points.Add(new Vector3(0, 0, 0)); points.Add(new Vector3(0, 100, 0)); points.Add(new Vector3(100, 100, 0)); TopoShape wire = GlobalInstance.BrepTools.MakePolygon(points); renderView.ShowGeometry(wire, ++shapeId); Vector3 dirPlane1 = new Vector3(0, 1, 1); dirPlane1.Normalize(); TopoShape newWire1 = GlobalInstance.BrepTools.ProjectOnPlane(wire, new Vector3(0, 0, 100), dirPlane1, new Vector3(0, 0, 1)); Vector3 dirPlane2 = new Vector3(0, 1, -1); dirPlane2.Normalize(); TopoShape newWire2 = GlobalInstance.BrepTools.ProjectOnPlane(wire, new Vector3(0, 0, 500), dirPlane2, new Vector3(0, 0, 1)); TopoShapeGroup tsg = new TopoShapeGroup(); tsg.Add(newWire1); tsg.Add(newWire2); TopoShape loft = GlobalInstance.BrepTools.MakeLoft(tsg, false); renderView.ShowGeometry(loft, ++shapeId); renderView.RequestDraw(); }
private void OnRenderWindow_MouseClick(object sender, MouseEventArgs e) { if (!m_PickPoint) { return; } //PickHelper pickHelper = renderViewDraw.PickShape(e.X, e.Y); //if (pickHelper != null) //{ // // add a ball // Platform.TopoShape shape = GlobalInstance.BrepTools.MakeSphere(pickHelper.GetPointOnShape(), 2); // renderView.ShowGeometry(shape, 100); //} //// Try the grid Vector3 pt = renderViewDraw.HitPointOnGrid(e.X, e.Y); if (pt != null) { if (Vecs.Count() == 0) { Vecs.Add(pt); TopoShape shape = GlobalInstance.BrepTools.MakeSphere(pt, 1); renderViewDraw.ShowGeometry(shape, 100); } else { var c = from m in Vecs where m.Distance(pt) <= 1 select m; if (c.Count() == 0) { var pt0 = Vecs.Last(); Vecs.Add(pt); TopoShape shape = GlobalInstance.BrepTools.MakeSphere(pt, 1); TopoShape edge = GlobalInstance.BrepTools.MakeLine(pt0, pt); EdgeG.Add(edge); renderViewDraw.ShowGeometry(shape, 100); renderViewDraw.ShowGeometry(edge, 100); } else if (Vecs.First().Equals(c.Last())) { TopoShape edge = GlobalInstance.BrepTools.MakeLine(Vecs.Last(), Vecs.First()); EdgeG.Add(edge); renderViewDraw.ShowGeometry(edge, 100); m_PickPoint = !m_PickPoint; } } } }
private void queryMultiSelectionToolStripMenuItem_Click(object sender, EventArgs e) { TopoShapeGroup group = new TopoShapeGroup(); MultiShapeQuery query = new MultiShapeQuery(); m_RenderView.QuerySelection(query); int nCount = query.GetCount(); for (int ii = 0; ii < nCount; ++ii) { SelectedShapeQuery shapeQuery = query.GetSubContext(ii); TopoShape subShape = shapeQuery.GetSubGeometry(); if (subShape != null) { group.Add(subShape); } } // clear the scene and only keep the selected shapes if (group.Size() > 0) { m_RenderView.ClearScene(); for (int ii = 0; ii < group.Size(); ++ii) { m_RenderView.ShowGeometry(group.GetAt(ii), 100 + ii);; } } }
//打开stl文件 private void openSTLToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "STEP File(*.stl)|*.stl|All Files(*.*)|*.*"; if (DialogResult.OK != dlg.ShowDialog()) { return; } TopoShape shape = GlobalInstance.BrepTools.LoadFile(new AnyCAD.Platform.Path(dlg.FileName)); renderView.RenderTimer.Enabled = false; if (shape != null) { //加载到stl文件时 TopoShapeGroup group = new TopoShapeGroup(); group.Add(shape); SceneManager sceneMgr = renderView.SceneManager; SceneNode rootNode = GlobalInstance.TopoShapeConvert.ToSceneNode(shape, 0.1f); if (rootNode != null) { sceneMgr.AddNode(rootNode); } } renderView.RenderTimer.Enabled = true; renderView.FitAll(); renderView.RequestDraw(EnumRenderHint.RH_LoadScene); }
public override bool Run(FeatureContext context) { //1. Create the path float radius = 100; TopoShape arc = GlobalInstance.BrepTools.MakeArc(Vector3.ZERO, new Vector3(-radius, -radius, 0), new Vector3(0, -radius, 0), Vector3.UNIT_Z); TopoShape line = GlobalInstance.BrepTools.MakeLine(new Vector3(-radius, -radius, 0), new Vector3(-radius, -radius * 2, 0)); TopoShapeGroup edges = new TopoShapeGroup(); edges.Add(arc); edges.Add(line); TopoShape wire = GlobalInstance.BrepTools.MakeWire(edges); Vector3 dirZ = new Vector3(1, -1, 0); dirZ.Normalize(); Vector3 dirX = dirZ.CrossProduct(Vector3.UNIT_Z); Coordinate3 coord = new Coordinate3(Vector3.ZERO, dirX, Vector3.UNIT_Z, dirZ); TopoShape path = GlobalInstance.BrepTools.Transform(wire, coord); context.ShowGeometry(path); //2. Create the profile List <Vector3> points = new List <Vector3>(); points.Add(new Vector3()); points.Add(new Vector3(200, 0, 0)); points.Add(new Vector3(200, 200, 0)); points.Add(new Vector3(0, 200, 0)); TopoShape polygon = GlobalInstance.BrepTools.MakePolygon(points); // 3. Make body AdvFeatureTools advFT = new AdvFeatureTools(); TopoShape shape = advFT.MakeEvolved(polygon, path, 0, true); context.ShowGeometry(shape); return(true); }
public override bool Run(FeatureContext context) { TopoShape box1 = GlobalInstance.BrepTools.MakeBox(Vector3.ZERO, Vector3.UNIT_Z, new Vector3(100, 100, 100)); TopoShape box2 = GlobalInstance.BrepTools.MakeBox(new Vector3(0, 0, -100), Vector3.UNIT_Z, new Vector3(100, 100, 100)); TopoShapeGroup group = new TopoShapeGroup(); group.Add(box1); group.Add(box2); TopoShape compound = GlobalInstance.BrepTools.MakeCompound(group); RepairTools repairTool = new RepairTools(); TopoShape glue = repairTool.GlueFaces(compound, 0.00001f, true); //TopoShape newBody = repairTool.RemoveExtraEdges(glue); context.ShowGeometry(glue); return(true); }
public override bool Run(FeatureContext context) { // Create sketch on XZ plane float width = 20; float height = 20; float thickness = 5; float length = 100; List <Vector3> points = new List <Vector3>(); points.Add(Vector3.ZERO); points.Add(new Vector3(width, 0, 0)); points.Add(new Vector3(width, 0, thickness)); points.Add(new Vector3(thickness, 0, thickness)); points.Add(new Vector3(thickness, 0, height)); points.Add(new Vector3(0, 0, height)); TopoShape polygon = GlobalInstance.BrepTools.MakePolygon(points); TopoShape face = GlobalInstance.BrepTools.MakeFace(polygon); // Extrude along Y direction. TopoShape extrude = GlobalInstance.BrepTools.Extrude(face, length, Vector3.UNIT_Y); // Cylinders float radius = 2; TopoShapeGroup groups = new TopoShapeGroup(); groups.Add(GlobalInstance.BrepTools.MakeCylinder(new Vector3(0, 10, 10), Vector3.UNIT_X, radius, thickness, 0)); groups.Add(GlobalInstance.BrepTools.MakeCylinder(new Vector3(0, 50, 10), Vector3.UNIT_X, radius, thickness, 0)); groups.Add(GlobalInstance.BrepTools.MakeCylinder(new Vector3(10, 50, 0), Vector3.UNIT_Z, radius, thickness, 0)); TopoShape compound = GlobalInstance.BrepTools.MakeCompound(groups); // Cut TopoShape cut = GlobalInstance.BrepTools.BooleanCut(extrude, compound); // Dispaly context.ShowGeometry(cut); return(true); }
private void revoleToolStripMenuItem_Click(object sender, EventArgs e) { int size = 10; // Create the outline edge TopoShape arc = GlobalInstance.BrepTools.MakeArc3Pts(new Vector3(-size, 0, 0), new Vector3(size, 0, 0), new Vector3(0, size, 0)); TopoShape line1 = GlobalInstance.BrepTools.MakeLine(new Vector3(-size, -size, 0), new Vector3(-size, 0, 0)); TopoShape line2 = GlobalInstance.BrepTools.MakeLine(new Vector3(size, -size, 0), new Vector3(size, 0, 0)); TopoShape line3 = GlobalInstance.BrepTools.MakeLine(new Vector3(-size, -size, 0), new Vector3(size, -size, 0)); TopoShapeGroup shapeGroup = new TopoShapeGroup(); shapeGroup.Add(line1); shapeGroup.Add(arc); shapeGroup.Add(line2); shapeGroup.Add(line3); TopoShape wire = GlobalInstance.BrepTools.MakeWire(shapeGroup); TopoShape revole = GlobalInstance.BrepTools.Revol(wire, new Vector3(size * 3, 0, 0), new Vector3(0, 1, 0), 145); renderView.ShowGeometry(revole, ++shapeId); }
public override bool Run(FeatureContext context) { int size = 10; // Create the outline edge TopoShape arc = GlobalInstance.BrepTools.MakeArc3Pts(new Vector3(-size, 0, 0), new Vector3(size, 0, 0), new Vector3(0, size, 0)); TopoShape line1 = GlobalInstance.BrepTools.MakeLine(new Vector3(-size, -size, 0), new Vector3(-size, 0, 0)); TopoShape line2 = GlobalInstance.BrepTools.MakeLine(new Vector3(size, -size, 0), new Vector3(size, 0, 0)); TopoShape line3 = GlobalInstance.BrepTools.MakeLine(new Vector3(-size, -size, 0), new Vector3(size, -size, 0)); TopoShapeGroup shapeGroup = new TopoShapeGroup(); shapeGroup.Add(line1); shapeGroup.Add(arc); shapeGroup.Add(line2); shapeGroup.Add(line3); TopoShape wire = GlobalInstance.BrepTools.MakeWire(shapeGroup); TopoShape revole = GlobalInstance.BrepTools.Revol(wire, new Vector3(size * 3, 0, 0), new Vector3(0, 1, 0), 145); context.ShowGeometry(revole); return(true); }
public override bool Run(FeatureContext context) { TopoShape arc = GlobalInstance.BrepTools.MakeArc(new Vector3(-100, 0, 0), new Vector3(100, 0, 0), Vector3.ZERO, Vector3.UNIT_Z); TopoShape line = GlobalInstance.BrepTools.MakeLine(new Vector3(100, 0, 0), new Vector3(100, 200, 0)); TopoShapeGroup group = new TopoShapeGroup(); group.Add(arc); group.Add(line); TopoShape wire = GlobalInstance.BrepTools.MakeSpline(group); TopoShape splitter1 = GlobalInstance.BrepTools.MakePoint(new Vector3(0, -100, 0)); TopoShape splitter2 = GlobalInstance.BrepTools.MakePoint(new Vector3(100, 100, 0)); TopoShapeGroup spliterGroup = new TopoShapeGroup(); spliterGroup.Add(splitter1); spliterGroup.Add(splitter2); TopoShape result = GlobalInstance.BrepTools.MakeSplit(wire, spliterGroup); TopoExplor exp = new TopoExplor(); TopoShapeGroup itmes = exp.ExplorSubShapes(result); for (int ii = 0; ii < itmes.Size(); ++ii) { SceneNode node = context.ShowGeometry(itmes.GetAt(ii)); LineStyle ls = new LineStyle(); ls.SetLineWidth(3.0f); ls.SetColor((ii + 1) * 50, ii * 20, ii * 10); node.SetLineStyle(ls); } return(true); }
public override bool Run(FeatureContext context) { // construct a wire; var points = new System.Collections.Generic.List <Vector3>(); points.Add(new Vector3(0, 0, 0)); points.Add(new Vector3(0, 100, 0)); points.Add(new Vector3(100, 100, 0)); TopoShape wire = GlobalInstance.BrepTools.MakePolygon(points); context.ShowGeometry(wire); // project the wire to two planes Vector3 dirPlane1 = new Vector3(0, 1, 1); dirPlane1.Normalize(); TopoShape newWire1 = GlobalInstance.BrepTools.ProjectOnPlane(wire, new Vector3(0, 0, 100), dirPlane1, new Vector3(0, 0, 1)); Vector3 dirPlane2 = new Vector3(0, 1, -1); dirPlane2.Normalize(); TopoShape newWire2 = GlobalInstance.BrepTools.ProjectOnPlane(wire, new Vector3(0, 0, 500), dirPlane2, new Vector3(0, 0, 1)); // make loft TopoShapeGroup tsg = new TopoShapeGroup(); tsg.Add(newWire1); tsg.Add(newWire2); TopoShape loft = GlobalInstance.BrepTools.MakeLoft(tsg, false); context.ShowGeometry(loft); return(true); }
public override bool Run(FeatureContext context) { var ptlist = new System.Collections.Generic.List <Vector3>(); ptlist.Add(Vector3.ZERO); ptlist.Add(new Vector3(100, 0, 0)); ptlist.Add(new Vector3(100, 100, 0)); ptlist.Add(new Vector3(0, 100, 0)); TopoShape polygon = GlobalInstance.BrepTools.MakePolygon(ptlist); TopoShape cir1 = GlobalInstance.BrepTools.MakeCircle(new Vector3(20, 20, 0), 15, Vector3.UNIT_Z); TopoShape cir2 = GlobalInstance.BrepTools.MakeCircle(new Vector3(80, 20, 0), 15, Vector3.UNIT_Z); TopoShape cir3 = GlobalInstance.BrepTools.MakeCircle(new Vector3(80, 80, 0), 15, Vector3.UNIT_Z); TopoShape cir4 = GlobalInstance.BrepTools.MakeCircle(new Vector3(20, 80, 0), 15, Vector3.UNIT_Z); TopoShapeGroup group = new TopoShapeGroup(); group.Add(polygon); group.Add(cir1); group.Add(cir2); group.Add(cir3); group.Add(cir4); // build faces with holes LoopsBuilder lb = new LoopsBuilder(); lb.Initialize(group); TopoShapeGroup faces = lb.BuildFacesWithHoles(); for (int ii = 0; ii < faces.Size(); ++ii) { context.ShowGeometry(faces.GetTopoShape(ii)); } return(true); }
private void exportIgesToolStripMenuItem_Click(object sender, EventArgs e) { SceneManager sceneManager = renderView.SceneManager; TopoShapeGroup group = new TopoShapeGroup(); for (ElementId ii = mBeginId; ii < mEndId; ++ii) { SceneNode node = sceneManager.FindNode(ii); if (node != null) { TopoShapeGroup shapeGroup = GlobalInstance.TopoShapeConvert.ToTopoShape(node); if (shapeGroup != null) { for (Int32 jj = 0, len = shapeGroup.Size(); jj < len; ++ii) { TopoShape shape = shapeGroup.GetTopoShape(jj); Matrix4 trf = GlobalInstance.MatrixBuilder.MakeRotation(90, Vector3.UNIT_X); shape = GlobalInstance.BrepTools.Transform(shape, trf); group.Add(shape); } } } } if (group.Size() > 0) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "IGES File (*.igs;*.iges)|*.igs;*.iges"; if (DialogResult.OK != dlg.ShowDialog()) { return; } TopoDataExchangeIges igsWriter = new TopoDataExchangeIges(); igsWriter.Write(group, new AnyCAD.Platform.Path(dlg.FileName)); } else { MessageBox.Show("No shape to save!"); } }
public void BuildGeometry() { BuildShapes(); if (Loops.Count == 1) { Loops[0].BuildGeometry(); Section = Loops[0].Geometry; } else { TopoShapeGroup list = new TopoShapeGroup(); foreach (Shape sp in Loops) { sp.BuildGeometry(); list.Add(sp.Geometry); } Section = GlobalInstance.BrepTools.MakeWire(list); } }
private void fillFaceToolStripMenuItem_Click(object sender, EventArgs e) { Vector3[] pt = new Vector3[8]; pt[0] = new Vector3(1, 2, 0.5f); pt[1] = new Vector3(2, 3, 0.2f); pt[2] = new Vector3(0, 5, 0.5f); pt[3] = new Vector3(-1, 2, 0.2f); pt[4] = new Vector3(-1, 0, 0.3f); pt[5] = new Vector3(-1, -2, 0.4f); pt[6] = new Vector3(1, -2, 0.5f); var ptlist = new System.Collections.Generic.List<Vector3>(); for (int i = 0; i < 7; i++) { ptlist.Add(pt[i]); } ptlist.Add(pt[0]); Vector3[] pd = new Vector3[7]; for (int i = 0; i < 7; i++) { pd[i] = new Vector3(pt[i].X, pt[i].Y, pt[i].Z + i+1); } var pdlist = new System.Collections.Generic.List<Vector3>(); for (int i = 0; i < 7; i++) { pdlist.Add(pd[i]); } pdlist.Add(pd[0]); TopoShape sect = GlobalInstance.BrepTools.MakePolyline(ptlist); TopoShape sectd = GlobalInstance.BrepTools.MakePolyline(pdlist); TopoShapeGroup group = new TopoShapeGroup(); group.Add(sect); group.Add(sectd); TopoShape ext_Pad = GlobalInstance.BrepTools.MakeLoft(group, true); renderView.ShowGeometry(ext_Pad, ++shapeId); renderView.FitAll(); }
private void swee2ToolStripMenuItem_Click(object sender, EventArgs e) { AdvFeatureTools advTool = new AdvFeatureTools(); { Coordinate3 coord = new Coordinate3(); coord.Origion = new Vector3(-0.5f, -1, 0); TopoShape profile = GlobalInstance.BrepTools.MakeRectangle(1,2,0.2f, coord); TopoShape path = GlobalInstance.BrepTools.MakeLine(Vector3.ZERO, new Vector3(0, 0, 100)); //define the "S" curve float[] S ={0,40,-80, 1,10,0}; TopoShape sweepBody = advTool.MakeSweep(profile, path, S, true); renderView.ShowGeometry(sweepBody, ++shapeId); } { Primitive2dTools tool2d = new Primitive2dTools(); float radius = 50; TopoShapeGroup group = new TopoShapeGroup(); group.Add(tool2d.MakeArc(new Vector2(0, radius), radius, 0, 45)); group.Add(tool2d.MakeLine(new Vector2(radius, radius), new Vector2(radius * 2, radius))); TopoShape spline = tool2d.ToBSplineCurve(group); TopoShape profile = GlobalInstance.BrepTools.MakeCircle(new Vector3(100, 100, 0), 1, Vector3.UNIT_Z); List<Vector3> pts = new List<Vector3>(); pts.Add(new Vector3(100, 100, 0)); pts.Add(new Vector3(100, 100, 100)); pts.Add(new Vector3(100, 200, 400)); TopoShape path = GlobalInstance.BrepTools.MakeSpline(pts); TopoShape sweepBody = advTool.MakeSweep(profile, path, spline, true); renderView.ShowGeometry(sweepBody, ++shapeId); } }
private void complexToolStripMenuItem_Click(object sender, EventArgs e) { float y = 10; TopoShape line1 = GlobalInstance.BrepTools.MakeLine(new Vector3(0, 0, 0 + y), new Vector3(4, 0, 0 + y)); TopoShape line2 = GlobalInstance.BrepTools.MakeLine(new Vector3(4, 0, 0 + y), new Vector3(4, 0, 0.5f + y)); TopoShape line3 = GlobalInstance.BrepTools.MakeLine(new Vector3(4, 0, 0.5f + y), new Vector3(1, 0, 0.5f + y)); TopoShape line4 = GlobalInstance.BrepTools.MakeLine(new Vector3(1, 0, 0.5f + y), new Vector3(1, 0, 4 + y)); TopoShape line5 = GlobalInstance.BrepTools.MakeLine(new Vector3(1, 0, 4 + y), new Vector3(0.5f, 0, 4 + y)); TopoShape line6 = GlobalInstance.BrepTools.MakeLine(new Vector3(0.5f, 0, 4 + y), new Vector3(0.5f, 0, 0.5f + y)); TopoShape line7 = GlobalInstance.BrepTools.MakeLine(new Vector3(0.5f, 0, 0.5f + y), new Vector3(0, 0, 0.5f + y)); TopoShape line8 = GlobalInstance.BrepTools.MakeLine(new Vector3(0, 0, 0.5f + y), new Vector3(0, 0, 0 + y)); TopoShapeGroup shapeGroup = new TopoShapeGroup(); shapeGroup.Add(line2); shapeGroup.Add(line3); shapeGroup.Add(line4); shapeGroup.Add(line5); shapeGroup.Add(line6); shapeGroup.Add(line7); shapeGroup.Add(line8); shapeGroup.Add(line1); TopoShape profile = GlobalInstance.BrepTools.MakeWire(shapeGroup); TopoShape line9 = GlobalInstance.BrepTools.MakeLine(new Vector3(0, 0, 0 + y), new Vector3(0, -20, 0 + y)); TopoShapeGroup lineGroup = new TopoShapeGroup(); lineGroup.Add(line9); TopoShape wire = GlobalInstance.BrepTools.MakeWire(lineGroup); TopoShape sweep = GlobalInstance.BrepTools.Sweep(profile, wire); //shapeGroupall.Add(sweep); //renderView.ShowGeometry(sweep, ++shapeId); TopoShape line10 = GlobalInstance.BrepTools.MakeLine(new Vector3(1, 0, 0.5f + y), new Vector3(1, 0, 3 + y)); TopoShape line11 = GlobalInstance.BrepTools.MakeLine(new Vector3(1, 0, 3 + y), new Vector3(2, 0, 3 + y)); TopoShape line12 = GlobalInstance.BrepTools.MakeLine(new Vector3(2, 0, 3 + y), new Vector3(2, 0, 0.5f + y)); TopoShape line13 = GlobalInstance.BrepTools.MakeLine(new Vector3(2, 0, 0.5f + y), new Vector3(1, 0, 0.5f + y)); TopoShapeGroup shapeGroup1 = new TopoShapeGroup(); shapeGroup1.Add(line10); shapeGroup1.Add(line11); shapeGroup1.Add(line12); shapeGroup1.Add(line13); TopoShape profile1 = GlobalInstance.BrepTools.MakeWire(shapeGroup1); TopoShape line14 = GlobalInstance.BrepTools.MakeLine(new Vector3(1, 0, 0.5f + y), new Vector3(1, -0.5f, 0.5f + y)); TopoShapeGroup lineGroup1 = new TopoShapeGroup(); lineGroup1.Add(line14); TopoShape wire1 = GlobalInstance.BrepTools.MakeWire(lineGroup1); TopoShape sweep1 = GlobalInstance.BrepTools.Sweep(profile1, wire1); //shapeGroupall.Add(sweep1); TopoShape comp = GlobalInstance.BrepTools.BooleanAdd(sweep, sweep1); RepairTools rt = new RepairTools(); comp = rt.RemoveExtraEdges(comp); renderView.ShowGeometry(comp, ++shapeId); renderView.View3d.FitAll(); }
private void extrudeToolStripMenuItem_Click(object sender, EventArgs e) { int size = 20; // Create the outline edge TopoShape arc = GlobalInstance.BrepTools.MakeArc3Pts(new Vector3(-size, 0, 0), new Vector3(size, 0, 0), new Vector3(0, size, 0)); TopoShape line1 = GlobalInstance.BrepTools.MakeLine(new Vector3(-size, -size, 0), new Vector3(-size, 0, 0)); TopoShape line2 = GlobalInstance.BrepTools.MakeLine(new Vector3(size, -size, 0), new Vector3(size, 0, 0)); TopoShape line3 = GlobalInstance.BrepTools.MakeLine(new Vector3(-size, -size, 0), new Vector3(size, -size, 0)); TopoShapeGroup shapeGroup = new TopoShapeGroup(); shapeGroup.Add(line1); shapeGroup.Add(arc); shapeGroup.Add(line2); shapeGroup.Add(line3); TopoShape wire = GlobalInstance.BrepTools.MakeWire(shapeGroup); TopoShape face = GlobalInstance.BrepTools.MakeFace(wire); // Extrude TopoShape extrude = GlobalInstance.BrepTools.Extrude(face, 100, new Vector3(0, 0, 1)); renderView.ShowGeometry(extrude, ++shapeId); // Check find.... SceneNode findNode = renderView.SceneManager.FindNode(new ElementId(shapeId)); renderView.SceneManager.SelectNode(findNode); }
private void Button_Click(object sender, RoutedEventArgs e) { try { var dialog = new OpenFileDialog() { Title = "请选择一个stl文件", CheckFileExists = true, CheckPathExists = true, Filter = "STL (*.stl)|*.stl", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }; if (dialog.ShowDialog() == true) { convert.IsEnabled = false; convert.Background = Brushes.Gray; convert.Content = "正在转换"; fileName = dialog.FileName; stpFileName = STPName.Text; isSTPSelected = convertToSTP.IsChecked.GetValueOrDefault(); isIGSSelected = convertToIGES.IsChecked.GetValueOrDefault(); //string allText = File.ReadAllText(fileName); FileStream fs = new FileStream(fileName, FileMode.Open); BinaryReader br = new BinaryReader(fs); br.ReadBytes(80); Int32 numberOfFace = br.ReadInt32(); var info = new FileInfo(fileName); var lengthOfFile = 50 * numberOfFace + 84; if (info.Length != lengthOfFile) { br.Close(); fs.Close(); readACSIIFile(fileName); } else { property.Text = $"stl文件中的片体数量为:{numberOfFace.ToString()}"; Console.WriteLine("正在读取二进制文件"); readBinaryFile(br, numberOfFace); fs.Close(); } Task.Run(() => { TopoShapeGroup group = new TopoShapeGroup(); foreach (var face in faceData) { var line1 = GlobalInstance.BrepTools.MakeLine(new Vector3(face.Point1.X, face.Point1.Y, face.Point1.Z), new Vector3(face.Point2.X, face.Point2.Y, face.Point2.Z)); var line2 = GlobalInstance.BrepTools.MakeLine(new Vector3(face.Point1.X, face.Point1.Y, face.Point1.Z), new Vector3(face.Point3.X, face.Point3.Y, face.Point3.Z)); var line3 = GlobalInstance.BrepTools.MakeLine(new Vector3(face.Point2.X, face.Point2.Y, face.Point2.Z), new Vector3(face.Point3.X, face.Point3.Y, face.Point3.Z)); TopoShapeGroup wire = new TopoShapeGroup(); wire.Add(line1); wire.Add(line2); wire.Add(line3); TopoShape wireLine = GlobalInstance.BrepTools.MakeWire(wire); var boundedFace = GlobalInstance.BrepTools.MakeFace(wireLine); group.Add(boundedFace); } var shell = GlobalInstance.BrepTools.MakeShell(group); if (isSTPSelected) { GlobalInstance.BrepTools.SaveFile(shell, new AnyCAD.Platform.Path($"D:\\{stpFileName}.stp")); } else if (isIGSSelected) { GlobalInstance.BrepTools.SaveFile(shell, new AnyCAD.Platform.Path($"D:\\{stpFileName}.igs")); } faceData.Clear(); this.Dispatcher.BeginInvoke(new Action(() => { convert.Content = "转换完毕"; convert.Background = Brushes.Green; convert.IsEnabled = true; })); var timer = new DispatcherTimer(DispatcherPriority.Normal); timer.Interval = new TimeSpan(0, 0, 0, 1); timer.Tick += new EventHandler(restoreText); timer.Start(); }); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
private void splitToolStripMenuItem1_Click(object sender, EventArgs e) { TopoShape box = GlobalInstance.BrepTools.MakeBox(Vector3.ZERO, Vector3.UNIT_Z, new Vector3(150f, 150f, 150f)); TopoShape sphere = GlobalInstance.BrepTools.MakeSphere(Vector3.ZERO, 100f); TopoShape sphere2 = GlobalInstance.BrepTools.MakeSphere(Vector3.ZERO, 50f); TopoShapeGroup tools = new TopoShapeGroup(); tools.Add(sphere); tools.Add(sphere2); TopoShape split = GlobalInstance.BrepTools.MakeSplit(box, tools); TopoExplor expo = new TopoExplor(); TopoShapeGroup faces = expo.ExplorFaces(split); TopoShapeGroup bodies = expo.ExplorSolids(split); Random random = new Random(); for (int ii = 0; ii < bodies.Size(); ++ii) { SceneNode node = renderView.ShowGeometry(bodies.GetTopoShape(ii), ++shapeId); FaceStyle fs = new FaceStyle(); fs.SetColor(new ColorValue((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 0.5f)); fs.SetTransparent(true); node.SetFaceStyle(fs); } renderView.RequestDraw(); MessageBox.Show(String.Format("Face: {0} Solid: {1}", faces.Size(), bodies.Size())); }
private void evolvedToolStripMenuItem_Click(object sender, EventArgs e) { List<Vector3> points = new List<Vector3>(); points.Add(new Vector3()); points.Add(new Vector3(200, 0, 0)); points.Add(new Vector3(200, 200, 0)); points.Add(new Vector3(0, 200, 0)); TopoShape polygon = GlobalInstance.BrepTools.MakePolygon(points); float radius = 100; TopoShape arc = GlobalInstance.BrepTools.MakeArc(Vector3.ZERO, new Vector3(-radius, -radius, 0), new Vector3(0, -radius, 0), Vector3.UNIT_Z); TopoShape line = GlobalInstance.BrepTools.MakeLine(new Vector3(-radius, -radius, 0), new Vector3(-radius, -radius * 2, 0)); TopoShapeGroup edges = new TopoShapeGroup(); edges.Add(arc); edges.Add(line); TopoShape wire = GlobalInstance.BrepTools.MakeWire(edges); Vector3 dirZ = new Vector3(1,-1,0); dirZ.Normalize(); Vector3 dirX = dirZ.CrossProduct(Vector3.UNIT_Z); Coordinate3 coord = new Coordinate3(Vector3.ZERO, dirX, Vector3.UNIT_Z, dirZ); TopoShape path = GlobalInstance.BrepTools.Transform(wire, coord); renderView.ShowGeometry(path, ++shapeId); AdvFeatureTools advFT = new AdvFeatureTools(); TopoShape shape = advFT.MakeEvolved(polygon, path, 0, true); renderView.ShowGeometry(shape, ++shapeId); }
private void exportIgesToolStripMenuItem_Click(object sender, EventArgs e) { SceneManager sceneManager = renderView.SceneManager; TopoShapeGroup group = new TopoShapeGroup(); for (ElementId ii = mBeginId; ii < mEndId; ++ii) { SceneNode node = sceneManager.FindNode(ii); if (node != null) { TopoShape shape = GlobalInstance.TopoShapeConvert.ToTopoShape(node); if (shape != null) { Matrix4 trf = GlobalInstance.MatrixBuilder.MakeRotation(90, Vector3.UNIT_X); shape = GlobalInstance.BrepTools.Transform(shape, trf); group.Add(shape); } } } if (group.Size() > 0) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "IGES File (*.igs;*.iges)|*.igs;*.iges"; if (DialogResult.OK != dlg.ShowDialog()) { return; } TopoDataExchangeIges igsWriter = new TopoDataExchangeIges(); igsWriter.Write(group, new AnyCAD.Platform.Path(dlg.FileName)); } else { MessageBox.Show("No shape to save!"); } }
private BendHelper BendDown(TopoShape face, TopoShape line, Bending bending) { #region 计算平面法向量 GeomSurface surface = new GeomSurface(); surface.Initialize(face); //参数域UV范围 double uFirst = surface.FirstUParameter(); double uLast = surface.LastUParameter(); double vFirst = surface.FirstVParameter(); double vLast = surface.LastVParameter(); //取中点 double umid = uFirst + (uLast - uFirst) * 0.5f; double vmid = vFirst + (vLast - vFirst) * 0.5f; //计算法向量 var data = surface.D1(umid, vmid); Vector3 dirU = data[1]; Vector3 dirV = data[2]; Vector3 dirF = dirV.CrossProduct(dirU); dirF.Normalize(); #endregion #region 计算边线参数 GeomCurve curve = new GeomCurve(); curve.Initialize(line); Vector3 dirL = curve.DN(curve.FirstParameter(), 1); Vector3 stPt = curve.Value(curve.FirstParameter()); //起点 Vector3 edPt = curve.Value(curve.LastParameter()); //终点 #endregion #region 绘制草图 TopoShapeGroup lineGroup = new TopoShapeGroup(); Vector3 center = stPt + dirF * bending.Radius; //圆心 Vector3 radius = stPt - center; //半径 double theta = bending.Angle * (Math.PI / 180.0); Vector3 radius2 = radius * Math.Cos(theta) + dirL.CrossProduct(radius) * Math.Sin(theta); Vector3 edArc = center + radius2; //圆弧终点 TopoShape arc = GlobalInstance.BrepTools.MakeArc(stPt, edArc, center, dirL); //绘制圆弧 if (arc != null) { lineGroup.Add(arc); } Vector3 edLine = dirL.CrossProduct(radius2) * (bending.Length / bending.Radius) + edArc; arc = GlobalInstance.BrepTools.MakeLine(edArc, edLine); lineGroup.Add(arc); //扫描生成折弯 TopoShape wireSketch = GlobalInstance.BrepTools.MakeWire(lineGroup); TopoShape sweep; if (wireSketch != null) { sweep = GlobalInstance.BrepTools.Sweep(wireSketch, line, true); } else { sweep = GlobalInstance.BrepTools.Sweep(arc, line, true); } TopoShape oFace = GlobalInstance.BrepTools.Sweep(arc, line, true).GetSubShape(0, 1); TopoShape oEdge = GlobalInstance.BrepTools.MakeLine(edLine, edLine + edPt - stPt); #endregion BendHelper bend = new BendHelper() { Sweep = sweep, EdFace = oFace, EdLine = oEdge }; return(bend); }
private void glueToolStripMenuItem_Click(object sender, EventArgs e) { TopoShape box1 = GlobalInstance.BrepTools.MakeBox(Vector3.ZERO, Vector3.UNIT_Z, new Vector3(100, 100, 100)); TopoShape box2 = GlobalInstance.BrepTools.MakeBox(new Vector3(0, 0, -100), Vector3.UNIT_Z, new Vector3(100, 100, 100)); TopoShapeGroup group = new TopoShapeGroup(); group.Add(box1); group.Add(box2); TopoShape compound = GlobalInstance.BrepTools.MakeCompound(group); renderView.ShowGeometry(compound, 300); //RepairTools repairTool = new RepairTools(); //TopoShape twoBox = repairTool.GlueFaces(compund, 0.00001f, true); //TopoDataExchangeStep step = new TopoDataExchangeStep(); //step.Write(twoBox, "d:/twobox.stp"); }
private void sTLToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "STL (*.stl)|*.stl|IGES (*.igs;*.iges)|*.igs;*.iges|STEP (*.stp;*.step)|*.stp;*.step|BREP (*.brep)|*.brep|All Files(*.*)|*.*"; if (DialogResult.OK != dlg.ShowDialog()) return; TopoShape shape = GlobalInstance.BrepTools.LoadFile(new AnyCAD.Platform.Path(dlg.FileName)); renderView.RenderTimer.Enabled = false; if (shape != null) { TopoShapeGroup group = new TopoShapeGroup(); group.Add(shape); //GlobalInstance.BrepTools.SaveFile(group, "d:\\anycad.brep"); //PhongMaterial material = new PhongMaterial(); //material.SetAmbient(new ColorValue(0.24725f, 0.2245f, 0.0645f)); //material.SetDiffuse(new ColorValue(0.84615f, 0.8143f, 0.2903f)); //material.SetSpecular(new ColorValue(0.797357f, 0.723991f, 0.208006f)); //material.SetShininess(83.2f); //FaceStyle faceStyle = new FaceStyle(); //faceStyle.SetMaterial(material); //SceneManager sceneMgr = renderView.SceneManager; //TopoShapeGroup subGroup = GlobalInstance.TopoExplor.ExplorSubShapes(shape); //int nSize = subGroup.Size(); //for (int ii = 0; ii < nSize; ++ii) //{ // SceneNode node = GlobalInstance.TopoShapeConvert.ToEntityNode(subGroup.GetTopoShape(ii), 10f); // node.SetId(++shapeId); // node.SetFaceStyle(faceStyle); // sceneMgr.AddNode(node); //} SceneManager sceneMgr = renderView.SceneManager; SceneNode rootNode = GlobalInstance.TopoShapeConvert.ToSceneNode(shape, 0.1f); if (rootNode != null) { sceneMgr.AddNode(rootNode); } } renderView.RenderTimer.Enabled = true; renderView.FitAll(); renderView.RequestDraw(EnumRenderHint.RH_LoadScene); }
private void faceWithHolesToolStripMenuItem_Click(object sender, EventArgs e) { var ptlist = new System.Collections.Generic.List<Vector3>(); ptlist.Add(Vector3.ZERO); ptlist.Add(new Vector3(100, 0, 0)); ptlist.Add(new Vector3(100, 100, 0)); ptlist.Add(new Vector3(0, 100, 0)); TopoShape polygon = GlobalInstance.BrepTools.MakePolygon(ptlist); TopoShape cir1 = GlobalInstance.BrepTools.MakeCircle(new Vector3(20, 20, 0), 15, Vector3.UNIT_Z); TopoShape cir2 = GlobalInstance.BrepTools.MakeCircle(new Vector3(80, 20, 0), 15, Vector3.UNIT_Z); TopoShape cir3 = GlobalInstance.BrepTools.MakeCircle(new Vector3(80, 80, 0), 15, Vector3.UNIT_Z); TopoShape cir4 = GlobalInstance.BrepTools.MakeCircle(new Vector3(20, 80, 0), 15, Vector3.UNIT_Z); TopoShapeGroup group = new TopoShapeGroup(); group.Add(polygon); group.Add(cir1); group.Add(cir2); group.Add(cir3); group.Add(cir4); // build faces with holes LoopsBuilder lb = new LoopsBuilder(); lb.Initialize(group); TopoShapeGroup faces = lb.BuildFacesWithHoles(); for (int ii = 0; ii < faces.Size(); ++ii) { renderView.ShowGeometry(faces.GetTopoShape(ii), ++shapeId); } renderView.RequestDraw(); }
public override bool OnBeiginComplexShape(TopoShape shape) { ShapeGroup.Add(shape); return(false); }