Exemple #1
0
        //累加模型面积
        private int AddAreaProperty(AreaProperties ap, Entity ent, out bool blockReferenceNotScaled, bool isParentSelected = false, bool all = false)
        {
            int count = 0;

            blockReferenceNotScaled = true;

            if (all || ent.Selected || isParentSelected)
            {
                if (ent is IFace)
                {
                    IFace itfFace = (IFace)ent;

                    Mesh[] meshes = itfFace.GetPolygonMeshes();

                    foreach (Mesh mesh in meshes)
                    {
                        ap.Add(mesh.Vertices, mesh.Triangles);
                    }
                    count++;
                }
                else if (ent is BlockReference)
                {
                    var br = (BlockReference)ent;

                    if (br.GetScaleFactorX() != 1 &&
                        br.GetScaleFactorY() != 1 &&
                        br.GetScaleFactorZ() != 1)
                    {
                        blockReferenceNotScaled = false;
                        return(count);
                    }

                    foreach (var e in br.GetEntities(model.Blocks))
                    {
                        count += AddAreaProperty(ap, e, out blockReferenceNotScaled, true);

                        if (!blockReferenceNotScaled)
                        {
                            return(count);
                        }
                    }
                }
                else
                {
                    ICurve itfCurve = (ICurve)ent;

                    if (itfCurve.IsClosed)
                    {
                        ap.Add(ent.Vertices);
                    }

                    count++;
                }
            }
            else if (ent is Brep)
            {
                Brep brep = (Brep)ent;

                for (int j = 0; j < brep.Faces.Length; j++)
                {
                    Brep.Face sf = brep.Faces[j];
                    Mesh[]    faceTessellation = sf.Tessellation;

                    if (brep.GetFaceSelection(j))
                    {
                        foreach (Mesh m in faceTessellation)
                        {
                            ap.Add(m.Vertices, m.Triangles);
                        }

                        count++;
                    }
                }
            }
            return(count);
        }
Exemple #2
0
        private void areaButton_OnClick(object sender, RoutedEventArgs e)
        {
            AreaProperties ap = new AreaProperties();

            int count = 0;

            for (int i = 0; i < model1.Entities.Count; i++)
            {
                Entity ent = model1.Entities[i];

                if (ent.Selected)
                {
                    ICurve itfCurve = (ICurve)ent;

                    if (itfCurve.IsClosed)
                    {
                        ap.Add(ent.Vertices);
                    }

                    count++;
                }
            }

            StringBuilder text = new StringBuilder();

            text.AppendLine(count + " entity(ies) selected");
            text.AppendLine("---------------------");

            if (ap.Centroid != null)
            {
                double          x, y, z;
                double          xx, yy, zz, xy, zx, yz;
                MomentOfInertia world, centroid;

                ap.GetResults(ap.Area, ap.Centroid, out x, out y, out z, out xx, out yy, out zz, out xy, out zx, out yz, out world, out centroid);

                text.AppendLine("Cumulative area: " + ap.Area + " square " + model1.Units.ToString().ToLower());
                text.AppendLine("Cumulative centroid: " + ap.Centroid);
                text.AppendLine("Cumulative area moments:");
                text.AppendLine(" First moments");
                text.AppendLine("  x: " + x.ToString("g6"));
                text.AppendLine("  y: " + y.ToString("g6"));
                text.AppendLine("  z: " + z.ToString("g6"));
                text.AppendLine(" Second moments");
                text.AppendLine("  xx: " + xx.ToString("g6"));
                text.AppendLine("  yy: " + yy.ToString("g6"));
                text.AppendLine("  zz: " + zz.ToString("g6"));
                text.AppendLine(" Product moments");
                text.AppendLine("  xy: " + xx.ToString("g6"));
                text.AppendLine("  yz: " + yy.ToString("g6"));
                text.AppendLine("  zx: " + zz.ToString("g6"));
                text.AppendLine(" Area Moments of Inertia about World Coordinate Axes");
                text.AppendLine("  Ix: " + world.Ix.ToString("g6"));
                text.AppendLine("  Iy: " + world.Iy.ToString("g6"));
                text.AppendLine("  Iz: " + world.Iz.ToString("g6"));
                text.AppendLine(" Area Radii of Gyration about World Coordinate Axes");
                text.AppendLine("  Rx: " + world.Rx.ToString("g6"));
                text.AppendLine("  Ry: " + world.Ry.ToString("g6"));
                text.AppendLine("  Rz: " + world.Rz.ToString("g6"));
                text.AppendLine(" Area Moments of Inertia about Centroid Coordinate Axes:");
                text.AppendLine("  Ix: " + centroid.Ix.ToString("g6"));
                text.AppendLine("  Iy: " + centroid.Iy.ToString("g6"));
                text.AppendLine("  Iz: " + centroid.Iz.ToString("g6"));
                text.AppendLine(" Area Radii of Gyration about Centroid Coordinate Axes");
                text.AppendLine("  Rx: " + centroid.Rx.ToString("g6"));
                text.AppendLine("  Ry: " + centroid.Ry.ToString("g6"));
                text.AppendLine("  Rz: " + centroid.Rz.ToString("g6"));
            }

            DetailsWindow rf = new DetailsWindow();

            rf.Title = "Area Properties";

            rf.contentTextBox.Text = text.ToString();

            rf.Show();
        }