예제 #1
0
        /***************************************************/

        // Create the preview of a rotation support.
        public static void PreviewRotationSupport(this Rhino.Display.CustomDisplay display, Node node, Vector3d axis, double displayFactor)
        {
            double   circRadius = Math.Sqrt(0.5) * displayFactor;
            Plane    p          = new Plane(node.Location, axis);
            Circle   c          = new Circle(p, displayFactor);
            Vector3d v1         = (new Vector3d(1, 1, 1) - axis) * circRadius;
            Vector3d v2         = v1.X == 0 ? new Vector3d(0, -v1.Y, v1.Z) : new Vector3d(-v1.X, v1.Y, v1.Z);
            Point3d  s1         = node.Location - v1;
            Point3d  s2         = node.Location - v2;
            Line     l1         = new Line(s1, v1 * 2);
            Line     l2         = new Line(s2, v2 * 2);

            display.AddLine(l1);
            display.AddLine(l2);
            display.AddCircle(c);
        }
예제 #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);
                    }
                }
            }
        }