private bool CreateSectionSweeps(List <ResultElement> res, string loadComb, bool showDeformed, double sFac)
        {
            // Clear lists
            ResetDrawingData();

            List <Point3d> pts     = new List <Point3d>();      // Points to create curve from
            List <Brep>    sSweeps = new List <Brep>(res.Count);

            foreach (ResultElement re in res)
            {
                List <Curve> crvs;
                List <Curve> sweepCrvs = new List <Curve>();

                // Start and end caps
                List <Curve> sCap = new List <Curve>();
                List <Curve> eCap = new List <Curve>();

                if (CrossSectionCasts.GetSectionPropertyCrvs(re.SectionPropertyString, out crvs))
                {
                    pts.Clear();

                    // Create rail
                    Curve rail;
                    if (showDeformed)
                    {
                        for (int i = 0; i < re.pos.Count; i++)
                        {
                            Point3d pt = CalcDeformedPosition(re, i, loadComb, sFac);

                            // Add points to list
                            pts.Add(pt);
                        }

                        rail = Curve.CreateInterpolatedCurve(pts, 3);
                    }
                    else
                    {
                        // Add points to list for transform of curves to positions
                        for (int i = 0; i < re.pos.Count; i++)
                        {
                            pts.Add(CalcUndeformedPosition(re, i));
                        }

                        rail = (Curve) new Line(re.sPos, re.ePos).ToNurbsCurve();
                    }

                    foreach (Curve crv in crvs)
                    {
                        // Rotation to local coordinates
                        Transform rotTrans = Transform.Rotation(Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, re.LocalX, re.LocalY, re.elNormal);
                        crv.Transform(rotTrans);

                        sweepCrvs.Clear();

                        for (int i = 0; i < re.pos.Count; i++)
                        {
                            Curve c = (Curve)crv.Duplicate();

                            Transform defTrans;
                            if (showDeformed)
                            {
                                // Rotation to deformed shape
                                Vector3d defTan = CalcDeformedTangent(rail, pts[i]);
                                defTrans = GetDeformationTransform(re, defTan, i, loadComb, sFac);
                            }
                            else
                            {
                                defTrans = Transform.Identity;
                            }

                            // Calculate move to element positions
                            Transform tTrans = Transform.Translation((Vector3d)pts[i]);

                            // Perform transformation
                            c.Transform(defTrans);
                            c.Transform(tTrans);

                            // Add curves
                            _secCrvs.Add(c);
                            sweepCrvs.Add(c);
                        }

                        //Add curves to cap curves
                        if (sweepCrvs.Count > 0)
                        {
                            sCap.Add(sweepCrvs[0]);
                            eCap.Add(sweepCrvs[sweepCrvs.Count - 1]);
                        }

                        //Create sweep
                        Brep[] b = Brep.CreateFromSweep(rail, sweepCrvs, true, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                        _breps.AddRange(b);
                    }

                    // Cap sections
                    _breps.Add(Utilities.CapSections(sCap));
                    _breps.Add(Utilities.CapSections(eCap));
                }
            }

            _bb = new BoundingBox(pts);

            return(true);
        }
Esempio n. 2
0
        static public List <Brep> CreateSectionSweeps(WR_Elem3dRcp er)
        {
            List <Curve> crvs;
            List <Brep>  eSBreps = new List <Brep>();

            // Start and end caps
            List <Curve> sCap = new List <Curve>();
            List <Curve> eCap = new List <Curve>();

            if (CrossSectionCasts.GetSectionPropertyCrvs(er.GetSectionString(), out crvs))
            {
                // Get x vector
                Point3d  sPos     = er.GetStartPos().ConvertToRhinoPoint();
                Point3d  ePos     = er.GetEndPos().ConvertToRhinoPoint();
                Vector3d elX      = new Vector3d(ePos.X - sPos.X, ePos.Y - sPos.Y, ePos.Z - sPos.Z);
                double   elLength = elX.Length;
                elX.Unitize();
                Vector3d move = elX * elLength;

                // Get normal (z vector)
                WR_Vector elWrZ = er.GetElementNormal();
                Vector3d  elZ   = new Vector3d(elWrZ.X, elWrZ.Y, elWrZ.Z);

                // Get y vector
                Vector3d elY = Vector3d.CrossProduct(elZ, elX);

                // Rotation to local coordinates
                Transform rotTrans = Transform.Rotation(Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, elX, elY, elZ);

                // Add start and end point to a list
                List <Point3d> endPts = new List <Point3d> {
                    sPos, ePos
                };

                foreach (Curve crv in crvs)
                {
                    // Rotate to local coordinates
                    crv.Transform(rotTrans);
                    crv.Translate((Vector3d)sPos);

                    // Create and add extrusion
                    Brep extrusion = Extrusion.CreateExtrusion(crv, move).ToBrep();
                    eSBreps.Add(extrusion);

                    // Add curve to cap list
                    sCap.Add(crv);

                    // Move to end and add
                    Curve eCrv = (Curve)crv.Duplicate();
                    eCrv.Translate(move);
                    eCap.Add(eCrv);
                }

                // Cap sections
                eSBreps.Add(CapSections(sCap));
                eSBreps.Add(CapSections(eCap));
            }


            return(eSBreps);
        }