示例#1
0
        //Gets all the members in the model and bakes them as breps to the rhino.
        public static Tuple <Member[], Dlubal.RFEM5.CrossSection[]> GetMembers(string comment)
        {
            OpenConnection();
            try
            {
                IModelData rData = RModel.GetModelData();

                Dlubal.RFEM5.Line[]         lines     = rData.GetLines();
                Dlubal.RFEM5.CrossSection[] crossSecs = rData.GetCrossSections();
                Member[] members = rData.GetMembers();
                members = members.Where(o => o.Comment == comment).ToArray();
                List <Member> mList = new List <Member>();

                Dictionary <int, Brep> rCrossSecs = new Dictionary <int, Brep>();
                foreach (Dlubal.RFEM5.CrossSection crossSec in crossSecs)
                {
                    rCrossSecs.Add(crossSec.No, GetCrscDBShape(crossSec.TextID));
                }

                foreach (Member member in members)
                {
                    Dlubal.RFEM5.Line   line      = rData.GetLine(member.LineNo, ItemAt.AtNo).GetData();
                    Rhino.Geometry.Line rhLine    = lineRfemToRhino(line, rData);
                    Vector3d            direction = new Vector3d(rhLine.To - rhLine.From);
                    Plane     plane     = new Plane(rhLine.From, direction);
                    Brep      tempCross = (Brep)rCrossSecs[member.StartCrossSectionNo].Duplicate();
                    Transform tr        = Transform.PlaneToPlane(Plane.WorldXY, plane);
                    tempCross.Transform(tr);

                    Brep extruded = tempCross.Faces[0].CreateExtrusion(rhLine.ToNurbsCurve(), true);
                    ProjectPlugIn.Instance.beamBreps.Add(Tuple.Create(member.No, extruded));
                }

                foreach (Member m in members)
                {
                    Dlubal.RFEM5.CrossSection c = Array.Find(crossSecs, o => o.No == m.StartCrossSectionNo);
                    if (c.TextID.Split(' ')[0] == "Rechteck" || c.TextID.Split(' ')[0] == "Kreis")
                    {
                        mList.Add(m);
                    }
                }
                CloseConnection();
                return(Tuple.Create(mList.ToArray(), crossSecs));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Cleans Garbage collector for releasing all COM interfaces and objects
                System.GC.Collect();
                System.GC.WaitForPendingFinalizers();
                CloseConnection();
            }


            return(Tuple.Create <Member[], Dlubal.RFEM5.CrossSection[]>(null, null));
        }
示例#2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare variables
            Point3d position   = new Point3d(0, 10, 0);
            Color   color      = Color.White;
            double  intensity  = 1;
            double  angle      = 0.35;
            double  distance   = 0;
            double  decay      = 1;
            Boolean castShadow = false;
            string  name       = "";

            // Reference the inputs
            DA.GetData(0, ref position);
            DA.GetData(1, ref color);
            DA.GetData(2, ref intensity);
            DA.GetData(3, ref angle);
            DA.GetData(4, ref distance);
            DA.GetData(5, ref decay);
            DA.GetData(6, ref castShadow);
            DA.GetData(7, ref name);

            // Build the light object
            dynamic lightObject = new ExpandoObject();

            lightObject.Uuid = Guid.NewGuid();
            lightObject.Type = "SpotLight";
            if (name.Length > 0)
            {
                lightObject.Name = name;
            }
            lightObject.Color      = Convert.ToInt32(color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"), 16);;
            lightObject.Intensity  = intensity;
            lightObject.Angle      = (Math.PI / 180) * angle;
            lightObject.CastShadow = castShadow;
            lightObject.Distance   = distance;
            lightObject.Decay      = decay;
            lightObject.Matrix     = new Matrix(position).Array;

            // Create a helper to aid in visualizing the light's behavior
            List <Curve> helper = new List <Curve>();

            var line = new Rhino.Geometry.Line(position, new Point3d(0, 0, 0));

            helper.Add(line.ToNurbsCurve());

            Vector3d vector = new Vector3d(new Point3d(0, 0, 0) - position);
            Plane    plane  = new Plane(position, vector);
            double   radius = vector.Length * Math.Tan((Math.PI / 180) * angle);
            Cone     cone   = new Cone(plane, vector.Length, radius);

            Brep brep = cone.ToBrep(false);

            for (int i = 0; i < brep.Edges.Count; i++)
            {
                helper.Add(brep.Edges[i].EdgeCurve);
            }

            // Create object3d
            Object3d object3d = new Object3d(lightObject);

            // Set outputs
            DA.SetDataList(0, helper);
            DA.SetData(1, object3d);
        }
示例#3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare variables
            Point3d position   = new Point3d(0, 10, 0);
            Color   color      = Color.White;
            double  intensity  = 1;
            double  distance   = 0;
            double  decay      = 1;
            Boolean castShadow = false;
            string  name       = "";

            // Reference the inputs
            DA.GetData(0, ref position);
            DA.GetData(1, ref color);
            DA.GetData(2, ref intensity);
            DA.GetData(3, ref distance);
            DA.GetData(4, ref decay);
            DA.GetData(5, ref castShadow);
            DA.GetData(6, ref name);

            // Build the light object
            dynamic lightObject = new ExpandoObject();

            lightObject.Uuid = Guid.NewGuid();
            lightObject.Type = "PointLight";
            if (name.Length > 0)
            {
                lightObject.Name = name;
            }
            lightObject.Color      = Convert.ToInt32(color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2"), 16);;
            lightObject.Intensity  = intensity;
            lightObject.CastShadow = castShadow;
            lightObject.Distance   = distance;
            lightObject.Decay      = decay;
            lightObject.Matrix     = new Matrix(position).Array;

            // Create a helper to aid in visualizing the light's behavior
            List <Curve> helper  = new List <Curve>();
            Circle       circle1 = new Circle(Plane.WorldXY, position, 0.5);
            Circle       circle2 = new Circle(Plane.WorldYZ, position, 0.5);
            Circle       circle3 = new Circle(Plane.WorldZX, position, 0.5);

            helper.Add(circle1.ToNurbsCurve());
            helper.Add(circle2.ToNurbsCurve());
            helper.Add(circle3.ToNurbsCurve());

            var lineX0 = new Rhino.Geometry.Line(position, position + new Point3d(1, 0, 0));
            var lineX1 = new Rhino.Geometry.Line(position, position + new Point3d(-1, 0, 0));
            var lineY0 = new Rhino.Geometry.Line(position, position + new Point3d(0, 1, 0));
            var lineY1 = new Rhino.Geometry.Line(position, position + new Point3d(0, -1, 0));
            var lineZ0 = new Rhino.Geometry.Line(position, position + new Point3d(0, 0, 1));
            var lineZ1 = new Rhino.Geometry.Line(position, position + new Point3d(0, 0, -1));

            helper.Add(lineX0.ToNurbsCurve());
            helper.Add(lineX1.ToNurbsCurve());
            helper.Add(lineY0.ToNurbsCurve());
            helper.Add(lineY1.ToNurbsCurve());
            helper.Add(lineZ0.ToNurbsCurve());
            helper.Add(lineZ1.ToNurbsCurve());

            // Create light
            Object3d object3d = new Object3d(lightObject);

            // Set outputs
            DA.SetDataList(0, helper);
            DA.SetData(1, object3d);
        }
示例#4
0
        //Create Bottom and Top Chord Pts
        public static List <List <Point3d> > TrussPtsFromLines(Curve PCCurve, Curve SCCurve, int Segments, int ForceVert)
        {
            List <List <Point3d> > ChordPts = new List <List <Point3d> >();

            //Check if truss is planar



            //define Primary and Secondary cord points
            List <Point3d> PCPts = new List <Point3d>();
            List <Point3d> SCPts = new List <Point3d>();

            //Create PC Points
            Point3d[] PCPtArray = new Point3d[] { };
            var       t         = PCCurve.DivideByCount(Segments, true, out PCPtArray);

            PCPts = PCPtArray.ToList();

            //splits boths curves evenly and joins lines
            if (ForceVert == 0)
            {
                Point3d[] SCPtArray = new Point3d[] { };
                var       breaks    = SCCurve.DivideByCount(Segments, true, out SCPtArray);
                SCPts = SCPtArray.ToList();
            }

            //Creates points on SC curve based on verticals to a directions z,x,y defualt to y for now.
            else if (ForceVert == 1)
            {
                foreach (Point3d pt in PCPts)
                {
                    //create temp line for intersection. <<<This needs improvement>>>!!!
                    Point3d tempPT = pt;
                    tempPT.Y = pt.Y + 5;
                    Line tempLine = new Rhino.Geometry.Line(pt, tempPT);
                    //intersection event
                    var tempevent = Rhino.Geometry.Intersect.Intersection.CurveCurve(SCCurve, tempLine.ToNurbsCurve(), 0.001, 0.001);
                    SCPts.Add(tempevent[0].PointA);
                }
            }

            //splits PC curves evenly and produces verticals perpendicular to the line
            //else if(ForceVert == 2)
            //{}

            ChordPts.Add(PCPts);
            ChordPts.Add(SCPts);

            return(ChordPts);
        }
示例#5
0
 public Geometry(Rg.Line line)
 {
     curveType = CurveTypes.Line;
     curve     = line.ToNurbsCurve();
 }
示例#6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare variables
            Point3d position     = new Point3d(0, 10, 10);
            Color   color        = Color.White;
            double  intensity    = 0.5;
            string  name         = "";
            Boolean castShadow   = false;
            double  shadowTop    = 10;
            double  shadowBottom = -10;
            double  shadowRight  = 10;
            double  shadowLeft   = -10;
            double  shadowNear   = 0;
            double  shadowFar    = 100;

            // Reference the inputs
            DA.GetData(0, ref position);
            DA.GetData(1, ref color);
            DA.GetData(2, ref intensity);
            DA.GetData(3, ref name);
            DA.GetData(4, ref castShadow);
            DA.GetData(5, ref shadowTop);
            DA.GetData(6, ref shadowBottom);
            DA.GetData(7, ref shadowRight);
            DA.GetData(8, ref shadowLeft);
            DA.GetData(9, ref shadowNear);
            DA.GetData(10, ref shadowFar);

            // Build the shadow camera
            dynamic camera = new ExpandoObject();

            camera.Uuid   = Guid.NewGuid();
            camera.Type   = "OrthographicCamera";
            camera.Top    = shadowTop;
            camera.Bottom = shadowBottom;
            camera.Right  = shadowRight;
            camera.Left   = shadowLeft;
            camera.Near   = shadowNear;
            camera.Far    = shadowFar;

            dynamic shadow = new ExpandoObject();

            shadow.camera = camera;

            // Build the light object
            dynamic lightObject = new ExpandoObject();

            lightObject.Uuid = Guid.NewGuid();
            lightObject.Type = "DirectionalLight";
            if (name.Length > 0)
            {
                lightObject.Name = name;
            }
            lightObject.Color      = new DecimalColor(color).Color;
            lightObject.Intensity  = intensity;
            lightObject.Matrix     = new Matrix(position).Array;
            lightObject.CastShadow = castShadow;
            lightObject.Shadow     = shadow;

            // Create a helper to aid in visualizing the light's behavior
            List <Curve> helper = new List <Curve>();

            Circle circle1 = new Circle(Plane.WorldXY, position, 0.5);
            Circle circle2 = new Circle(Plane.WorldYZ, position, 0.5);
            Circle circle3 = new Circle(Plane.WorldZX, position, 0.5);

            helper.Add(circle1.ToNurbsCurve());
            helper.Add(circle2.ToNurbsCurve());
            helper.Add(circle3.ToNurbsCurve());

            var line = new Rhino.Geometry.Line(position, new Point3d(0, 0, 0));

            helper.Add(line.ToNurbsCurve());

            // If it casts a shadow, create a shadow helper
            if (castShadow)
            {
                // Create the plane's x vector
                Vector3d vectorX = new Vector3d(-position);
                vectorX.Rotate(90 * (Math.PI / 180), Vector3d.ZAxis);
                vectorX.Z = 0;

                // Create the plane's y vector
                Vector3d vectorY = new Vector3d(-position);
                vectorY.Rotate(-90 * (Math.PI / 180), vectorX);

                Plane    plane     = new Plane(position, vectorX, vectorY);
                Interval xSize     = new Interval(-shadowRight, -shadowLeft);
                Interval ySize     = new Interval(shadowBottom, shadowTop);
                Interval zSize     = new Interval(shadowNear, shadowFar);
                Box      shadowBox = new Box(plane, xSize, ySize, zSize);
                Brep     brep      = shadowBox.ToBrep();

                for (int i = 0; i < brep.Edges.Count; i++)
                {
                    helper.Add(brep.Edges[i].EdgeCurve);
                }
            }

            // Create object3d
            Object3d object3d = new Object3d(lightObject);

            // Set outputs
            DA.SetDataList(0, helper);
            DA.SetData(1, object3d);
        }