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);; } } }
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 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 override void OnFace(TopoShape shape) { WireClassifier wc = new WireClassifier(); if (!wc.Initialize(shape)) { return; } TopoShapeGroup innerWires = wc.GetInnerWires(); int nCount = innerWires.Size(); for (int ii = 0; ii < nCount; ++ii) { SceneNode node = _Context.ShowGeometry(innerWires.GetAt(ii)); node.SetLineStyle(_LineStyle); } SceneNode faceNode = _Context.ShowGeometry(shape); faceNode.SetFaceStyle(_FaceStyle); }
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|All Files(*.*)|*.*"; if (DialogResult.OK == dlg.ShowDialog()) { TopoShape shape = GlobalInstance.BrepTools.LoadFile(dlg.FileName); renderView.RenderTimer.Enabled = false; if (shape != null) { 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); } } renderView.RenderTimer.Enabled = true; } renderView.View3d.FitAll(); renderView.RequestDraw(EnumRenderHint.RH_LoadScene); }
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); }
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); }
private void TransOnMax(TopoShape shape) { double areaM = 0; Vector3 dirN = new Vector3(); Vector3 pos = new Vector3(); TopoExplor topo = new TopoExplor(); TopoShapeGroup group2 = topo.ExplorFaces(shape); for (int i = 0; i < group2.Size(); i++) { TopoShape face = group2.GetTopoShape(i); #region 计算面积 TopoShapeProperty property = new TopoShapeProperty(); property.SetShape(face); Console.WriteLine("Face {0}:\n\tArea {1}\n\tOrientation {2}", i, property.SurfaceArea(), face.GetOrientation()); #endregion #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 dir = dirV.CrossProduct(dirU); dir.Normalize(); Console.WriteLine("\tDir {0}", dir); #endregion #region 取最大的面 if (property.SurfaceArea() > areaM) { areaM = property.SurfaceArea(); pos = data[0]; Console.WriteLine(data[0]); if (face.GetOrientation() == EnumShapeOrientation.ShapeOrientation_REVERSED) { dirN = dir * -1; } else { dirN = dir; } } #endregion } #region 坐标变换 //Translation shape = GlobalInstance.BrepTools.Translate(shape, -pos); //Rotation Vector3 dirZ = new Vector3(0, 0, -1); shape = GlobalInstance.BrepTools.Rotation(shape, dirN.CrossProduct(dirZ), dirN.AngleBetween(dirZ)); #endregion if (shape != null) { topoShape = shape; renderView.ClearScene(); renderView.ShowGeometry(shape, shapeId); } renderView.FitAll(); renderView.RequestDraw(EnumRenderHint.RH_LoadScene); }
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!"); } }