Beispiel #1
0
        /***************************************************/

        // Calculate the display factors dependent on the size of the model and its elements.
        public static double[] sizeFactors(this Model model)
        {
            BoundingBox bBox = new BoundingBox(model.Mesh.Nodes.Select(x => x.Location));

            double forceFactor   = 0;
            double elementFactor = bBox.Diagonal.Length;

            foreach (Panel panel in model.Panels)
            {
                foreach (Element element in panel.Elements)
                {
                    Element2D      e         = element as Element2D;
                    List <Point3d> eVertices = e.GetVertices().ToList();
                    if (e.PrimaryNodeCount == 3)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            double edgeL = eVertices[i].DistanceTo(eVertices[(i + 1) % 3]);
                            if (edgeL <= elementFactor)
                            {
                                elementFactor = edgeL;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            double diagL = eVertices[i].DistanceTo(eVertices[i + 2]);
                            if (diagL <= elementFactor)
                            {
                                elementFactor = diagL;
                            }
                        }
                    }

                    if (e.Pressure != 0 && Math.Abs(e.Pressure) >= forceFactor)
                    {
                        forceFactor = Math.Abs(e.Pressure);
                    }
                }
            }

            foreach (Bar bar in model.Bars)
            {
                foreach (Element element in bar.Elements)
                {
                    Element1D e         = element as Element1D;
                    Point3d[] eVertices = e.GetVertices().ToArray();

                    double l = eVertices[0].DistanceTo(eVertices[1]);
                    if (l <= elementFactor)
                    {
                        elementFactor = l;
                    }
                }
            }

            foreach (Node n in model.Mesh.Nodes)
            {
                if (n.ForceLoad.Length != 0 && Math.Abs(n.ForceLoad.Length) >= forceFactor)
                {
                    forceFactor = Math.Abs(n.ForceLoad.Length);
                }
            }

            elementFactor *= 0.3;

            return(new double[] { elementFactor, forceFactor });
        }
Beispiel #2
0
        /***************************************************/

        // Create the preview of bars.
        public static void AddBarPreview(this Rhino.Display.CustomDisplay display, Model model, IEnumerable <int> ids, out HashSet <int> nodeIds, double graphicFactor, double elementFactor, double textFactor, bool showComponentNumbers, bool showElementNumbers, bool showLCS, bool showThk = false, string barResultType = "None", bool showResultValues = false)
        {
            nodeIds = new HashSet <int>();
            if (model.Bars.Count == 0)
            {
                return;
            }

            // Take all results out first to determine min & max, otherwise could be done inside the loop.
            Dictionary <int, double[]> barResults = new Dictionary <int, double[]>();
            double BFactor = 0;

            if (barResultType != "None")
            {
                barResults = model.Mesh.GetElementResults(barResultType);
                double barExtreme = barResults.Values.Select(r => Math.Max(Math.Abs(r[0]), Math.Abs(r[1]))).Max();
                BFactor = elementFactor / barExtreme * 10;
            }

            ids = ids.Count() == 0 ? Enumerable.Range(0, model.Bars.Count) : ids.Select(i => i - 1);

            foreach (int i in ids)
            {
                Bar   bar    = model.Bars[i];
                Plane locLCS = new Plane(bar.LCS);
                locLCS.Rotate(bar.Rotation, locLCS.ZAxis);
                locLCS.Translate(locLCS.XAxis * bar.Offset.X);
                locLCS.Translate(locLCS.YAxis * bar.Offset.Y);

                Vector3d hOffset = locLCS.XAxis * (bar.Profile.GetHeight() * 0.5);
                if (showThk)
                {
                    hOffset *= 2;
                }

                Plane tp = new Plane(locLCS.Origin, bar.LCS.YAxis, Vector3d.ZAxis);
                tp.Translate(hOffset);
                Curve[] profileCurves = bar.Profile.ToRhinoProfile();

                if (showComponentNumbers)
                {
                    Rhino.Display.Text3d t = new Rhino.Display.Text3d("Bar " + bar.CCXId(), tp, elementFactor * 0.6 * textFactor);
                    t.Bold = true;
                    display.AddText(t, Color.DarkRed);
                }

                foreach (Element element in bar.Elements)
                {
                    Element1D e   = element as Element1D;
                    int       eId = e.Id.AsInteger;

                    nodeIds.Add(e.Nodes.First().Id.AsInteger);
                    nodeIds.Add(e.Nodes.Last().Id.AsInteger);

                    Point3d[] endPts = e.GetVertices().ToArray();
                    Point3d   c      = (endPts[0] + endPts[1]) * 0.5;

                    display.AddLine(new Line(endPts[0], endPts[1]), Color.Aqua);

                    if (showThk)
                    {
                        Plane          eP = new Plane(locLCS);
                        List <Point3d> elementVertices = e.GetVertices().ToList();
                        eP.Translate(elementVertices[0] - bar.LCS.Origin);
                        Transform ptp = Transform.PlaneToPlane(Plane.WorldXY, eP);

                        // Use DisplayPipeline to get surface preview! Now a temporary solution given.
                        foreach (Curve pc in profileCurves)
                        {
                            Curve opc = pc.DuplicateCurve();
                            opc.Transform(ptp);
                            display.AddCurve(opc);
                            opc.Translate(elementVertices[1] - elementVertices[0]);
                            display.AddCurve(opc);
                        }
                    }

                    if (barResultType != "None")
                    {
                        Vector3d graphDir;
                        switch (barResultType)
                        {
                        case "Myy":
                            graphDir = locLCS.XAxis;
                            break;

                        case "Mxx":
                            graphDir = locLCS.YAxis;
                            break;

                        default:
                            string barResDir = barResultType.ToString().Substring(1, 1);
                            graphDir = barResDir == "y" ? locLCS.YAxis : locLCS.XAxis;
                            break;
                        }

                        graphDir *= BFactor * graphicFactor;
                        Point3d[] cPts = new Point3d[] { endPts[0], endPts[1], endPts[1] + graphDir * barResults[eId][1], endPts[0] + graphDir * barResults[eId][0] };
                        display.AddPolygon(cPts, Color.CornflowerBlue, Color.Black, true, true);

                        if (showResultValues && barResults.Count != 0)
                        {
                            Plane tp1 = new Plane(tp);
                            tp1.Translate(endPts[0] - tp1.Origin + graphDir * barResults[eId][0]);
                            Rhino.Display.Text3d t1 = new Rhino.Display.Text3d(barResults[eId][0].ToString("G2"), tp1, elementFactor * 0.4 * textFactor);
                            t1.Bold = true;
                            display.AddText(t1, Color.Black);
                            Plane tp2 = new Plane(tp);
                            tp2.Translate(endPts[1] - tp2.Origin + graphDir * barResults[eId][1]);
                            Rhino.Display.Text3d t2 = new Rhino.Display.Text3d(barResults[eId][1].ToString("G2"), tp2, elementFactor * 0.4 * textFactor);
                            t2.Bold = true;
                            display.AddText(t2, Color.Black);
                        }
                    }

                    if (showLCS)
                    {
                        display.AddVector(c, locLCS.XAxis * elementFactor * graphicFactor, Color.Red);
                        display.AddVector(c, locLCS.YAxis * elementFactor * graphicFactor, Color.Green);
                        display.AddVector(c, locLCS.ZAxis * elementFactor * graphicFactor, Color.Blue);
                    }

                    if (showElementNumbers)
                    {
                        Plane etp = new Plane(tp);
                        etp.Translate(c - bar.LCS.Origin);
                        Rhino.Display.Text3d t = new Rhino.Display.Text3d(e.CCXId(), etp, elementFactor * 0.4 * textFactor);
                        t.Bold = true;
                        display.AddText(t, Color.Black);
                    }
                }
            }
        }