예제 #1
0
        public static List <Curve> VennDiagramCircles()
        {
            List <Curve> TestEnvironment = new List <Curve>();

            Curve CircleLeft  = null;
            Curve CircleRight = null;

            GH_Convert.ToCurve(new Circle(new Point3d(-1, 0, 0), 2), ref CircleLeft, GH_Conversion.Both);
            GH_Convert.ToCurve(new Circle(new Point3d(1, 0, 0), 2), ref CircleRight, GH_Conversion.Both);

            TestEnvironment.Add(CircleLeft);
            TestEnvironment.Add(CircleRight);

            return(TestEnvironment);
        }
예제 #2
0
        public override bool CastFrom(object source)
        {
            // This function is called when Grasshopper needs to convert other data
            // into GsaMember.


            if (source == null)
            {
                return(false);
            }

            //Cast from GsaMember
            if (typeof(GsaMember1d).IsAssignableFrom(source.GetType()))
            {
                Value = (GsaMember1d)source;
                return(true);
            }

            //Cast from GsaAPI Member
            if (typeof(Member).IsAssignableFrom(source.GetType()))
            {
                Value.Member = (Member)source;
                return(true);
            }


            //Cast from Curve
            Curve crv = null;

            if (GH_Convert.ToCurve(source, ref crv, GH_Conversion.Both))
            {
                GsaMember1d member = new GsaMember1d(crv);
                this.Value = member;
                return(true);
            }


            return(false);
        }
예제 #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve ghcrv = new GH_Curve();

            if (DA.GetData(0, ref ghcrv))
            {
                if (ghcrv == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Curve input is null");
                }
                Curve crv = null;
                if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both))
                {
                    GsaMember1d mem = new GsaMember1d(crv);

                    GsaBool6 rel1 = new GsaBool6
                    {
                        X  = x1,
                        Y  = y1,
                        Z  = z1,
                        XX = xx1,
                        YY = yy1,
                        ZZ = zz1
                    };

                    mem.ReleaseStart = rel1;

                    GsaBool6 rel2 = new GsaBool6
                    {
                        X  = x2,
                        Y  = y2,
                        Z  = z2,
                        XX = xx2,
                        YY = yy2,
                        ZZ = zz2
                    };
                    mem.ReleaseEnd = rel2;

                    // 1 section
                    GH_ObjectWrapper gh_typ  = new GH_ObjectWrapper();
                    GsaSection       section = new GsaSection();
                    if (DA.GetData(1, ref gh_typ))
                    {
                        if (gh_typ.Value is GsaSectionGoo)
                        {
                            gh_typ.CastTo(ref section);
                            mem.Section = section;
                        }
                        else
                        {
                            if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                mem.Member.Property = idd;
                            }
                            else
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer");
                                return;
                            }
                        }
                    }

                    DA.SetData(0, new GsaMember1dGoo(mem));
                }
예제 #4
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)
        {
            // First, we need to retrieve all data from the input parameters.
            List <string>           fields           = new List <string>();
            GH_Structure <IGH_Goo>  attributes       = new GH_Structure <IGH_Goo>();
            GH_Structure <GH_Curve> inputPolygonTree = new GH_Structure <GH_Curve>();

            bool   writeFile = false;
            string filePath  = "";
            string prj       = null;

            // access the input parameter by index.
            if (!DA.GetData(5, ref writeFile))
            {
                return;
            }
            if (!DA.GetData(4, ref filePath))
            {
                return;
            }
            if (!DA.GetDataTree(0, out inputPolygonTree))
            {
                return;
            }
            if (!DA.GetDataList(1, fields))
            {
                return;
            }
            if (!DA.GetDataTree(2, out attributes))
            {
                return;
            }
            if (!DA.GetData(3, ref prj))
            {
                return;
            }



            //create new feature set to add data to
            FeatureSet fs = new FeatureSet(FeatureType.Polygon);

            //FeatureSet fs = new FeatureSet(FeatureType.Point);
            //FeatureSet fs = new FeatureSet(FeatureType.MultiPoint);
            //FeatureSet fs = new FeatureSet(FeatureType.Line);

            if (prj != null)
            {
                //load projection file
                string cur_proj = System.IO.File.ReadAllText(@prj);

                ///create Projection system
                ProjectionInfo targetProjection = new ProjectionInfo();
                targetProjection.ParseEsriString(cur_proj);
                fs.Projection = targetProjection;
            }

            if (writeFile)
            {
                // Add fields to the feature sets attribute table
                foreach (string field in fields)
                {
                    //<<<dubble chack if this is properly declaring type>>>\\
                    fs.DataTable.Columns.Add(new DataColumn(field, typeof(string)));
                }
                // for every branch  (ie feature)
                foreach (GH_Path path in inputPolygonTree.Paths)
                {
                    //set branch
                    IList branch = inputPolygonTree.get_Branch(path);
                    //List<DotSpatial.Topology.LineString> theseLines = new List<DotSpatial.Topology.LineString>();
                    List <LinearRing> theseCurves = new List <LinearRing>();

                    foreach (GH_Curve curve in branch)
                    {
                        // create vertex list for this curve
                        List <Coordinate> vertices = new List <Coordinate>();

                        //convert to rhino curve
                        Curve rhinoCurve = null;
                        GH_Convert.ToCurve(curve, ref rhinoCurve, 0);
                        //curve to nurbes
                        NurbsCurve thisNurbsCurve = rhinoCurve.ToNurbsCurve();
                        //Get list of control points
                        Rhino.Geometry.Collections.NurbsCurvePointList theseControlPoints = thisNurbsCurve.Points;
                        //for each control point
                        foreach (ControlPoint thisPoint in theseControlPoints)
                        {
                            vertices.Add(new Coordinate(thisPoint.Location.X, thisPoint.Location.Y));
                        }//end each control point

                        //create linering Geometry from coordinates
                        LinearRing thisCurve = new LinearRing(vertices);

                        // add curve to curve list
                        theseCurves.Add(thisCurve);
                    }//end curve itteration

                    //Convert Coordinates to dot spatial point or multipoint geometry
                    //DotSpatial.Topology.Point geom = new DotSpatial.Topology.Point(vertices);
                    //DotSpatial.Topology.MultiPoint geom = new DotSpatial.Topology.MultiPoint(vertices);
                    DotSpatial.Topology.ILinearRing outerCurve = theseCurves[0];
                    var innerCurves = theseCurves.GetRange(1, theseCurves.Count - 1).ToArray();

                    //convert list of line strings into single multilinestring feature
                    //MultiLineString geom = new MultiLineString(theseLines);
                    Polygon geom = new Polygon(outerCurve, innerCurves);

                    //convert geom to a feature
                    IFeature feature = fs.AddFeature(geom);

                    //begin editing to add feature attributes
                    feature.DataRow.BeginEdit();
                    //get this features attributes by its path
                    IList <string> featrueAttributes = attributes.get_Branch(path) as IList <string>;
                    int            thisIndex         = 0;
                    //add each attribute for the pt's path
                    foreach (var thisAttribute in attributes.get_Branch(path))
                    {
                        //converting all fields to (((Proper Type...?)))
                        feature.DataRow[fields[thisIndex]] = thisAttribute.ToString(); //currently everything is a string....
                                                                                       //<<<!!!!!!!!!! dubble chack if this is properly converting to the type declared above !!!!!!!!!!>>>\\
                        thisIndex++;
                    }
                    //finish attribute additions
                    feature.DataRow.EndEdit();
                }//end of itterating through branches of pt tree
                fs.SaveAs(filePath, true);
            }
        }
예제 #5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve ghcrv = new GH_Curve();

            if (DA.GetData(0, ref ghcrv))
            {
                Curve crv = null;
                if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both))
                {
                    GsaMember1d mem = new GsaMember1d(crv);

                    GsaBool6 rel1 = new GsaBool6
                    {
                        X  = x1,
                        Y  = y1,
                        Z  = z1,
                        XX = xx1,
                        YY = yy1,
                        ZZ = zz1
                    };

                    mem.ReleaseStart = rel1;

                    GsaBool6 rel2 = new GsaBool6
                    {
                        X  = x2,
                        Y  = y2,
                        Z  = z2,
                        XX = xx2,
                        YY = yy2,
                        ZZ = zz2
                    };
                    mem.ReleaseEnd = rel2;

                    // 1 section
                    GH_ObjectWrapper gh_typ  = new GH_ObjectWrapper();
                    GsaSection       section = new GsaSection();
                    if (DA.GetData(1, ref gh_typ))
                    {
                        if (gh_typ.Value is GsaSection)
                        {
                            gh_typ.CastTo(ref section);
                        }
                        else if (gh_typ.Value is GH_Number)
                        {
                            if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                section.ID = idd;
                            }
                        }
                    }
                    else
                    {
                        section.ID = 1;
                    }
                    mem.Section = section;

                    DA.SetData(0, new GsaMember1dGoo(mem));
                }
            }
        }
예제 #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)
        {
            GH_Structure <GH_Curve> crvs = new GH_Structure <GH_Curve>();

            DA.GetDataTree <GH_Curve>(0, out crvs);

            GH_Structure <GH_Number> height = new GH_Structure <GH_Number>();

            DA.GetDataTree <GH_Number>(1, out height);

            double tol = DocumentTolerance();

            //reserve one processor for GUI

            //create a dictionary that works in parallel
            var mPatchTree = new System.Collections.Concurrent.ConcurrentDictionary <GH_Path, GH_Mesh>();

            //Multi-threading the loop
            System.Threading.Tasks.Parallel.ForEach(crvs.Paths,
                                                    new System.Threading.Tasks.ParallelOptions {
                MaxDegreeOfParallelism = totalMaxConcurrancy
            },
                                                    pth =>
            {
                List <Curve> branchCrvs = new List <Curve>();
                double offset           = 0;
                if (crvs.get_Branch(pth).Count > 0)
                {
                    foreach (var ghCrv in crvs.get_Branch(pth))
                    {
                        Curve c = null;
                        GH_Convert.ToCurve(ghCrv, ref c, 0);

                        if (extrudeDir == "Extrude Z")
                        {
                            ///Ensure boundary winds clockwise
                            if (c.ClosedCurveOrientation(Vector3d.ZAxis) < 0)
                            {
                                c.Reverse();
                            }
                        }

                        branchCrvs.Add(c);
                    }

                    ///Convert first curve in branch to polyline
                    ///Don't know why the boundary parameter can't be a Curve if the holes are allowed to be Curves
                    Polyline pL = null;
                    branchCrvs[0].TryGetPolyline(out pL);
                    branchCrvs.RemoveAt(0);
                    if (!pL.IsClosed)
                    {
                        pL.Add(pL[0]);
                    }

                    ///Check validity of pL
                    if (!pL.IsValid)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Outer boundary curve could not be converted to polyline or is invalid");
                    }

                    ///The magic found here:
                    ///https://discourse.mcneel.com/t/mesh-with-holes-from-polylines-in-rhinowip-to-c/45589
                    Mesh mPatch = Mesh.CreatePatch(pL, tol, null, branchCrvs, null, null, true, 1);
                    mPatch.Ngons.AddPlanarNgons(tol);
                    //mPatch.UnifyNormals();
                    mPatch.FaceNormals.ComputeFaceNormals();
                    mPatch.Normals.ComputeNormals();
                    mPatch.Compact();

                    if (height.PathExists(pth))
                    {
                        if (height.get_Branch(pth).Count > 0)
                        {
                            GH_Convert.ToDouble(height.get_Branch(pth)[0], out offset, 0);
                            if (extrudeDir == "Extrude Z")
                            {
                                mPatch = mPatch.Offset(offset, true, Vector3d.ZAxis);
                            }
                            else
                            {
                                mPatch.Flip(true, true, true);
                                mPatch = mPatch.Offset(offset, true);
                            }
                        }
                    }
                    else if (height.get_FirstItem(true) != null)
                    {
                        GH_Convert.ToDouble(height.get_FirstItem(true), out offset, 0);
                        if (extrudeDir == "Extrude Z")
                        {
                            mPatch = mPatch.Offset(offset, true, Vector3d.ZAxis);
                        }
                        else
                        {
                            mPatch.Flip(true, true, true);
                            mPatch = mPatch.Offset(offset, true);
                        }
                    }
                    else
                    {
                    }

                    if (mPatch != null)
                    {
                        if (mPatch.SolidOrientation() < 0)
                        {
                            mPatch.Flip(true, true, true);
                        }
                    }

                    mPatchTree[pth] = new GH_Mesh(mPatch);
                }
            });
            ///End of multi-threaded loop


            ///Convert dictionary to regular old data tree
            GH_Structure <GH_Mesh> mTree = new GH_Structure <GH_Mesh>();

            foreach (KeyValuePair <GH_Path, GH_Mesh> m in mPatchTree)
            {
                mTree.Append(m.Value, m.Key);
            }

            DA.SetDataTree(0, mTree);
        }
예제 #7
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)
        {
            #region INPUTS
            // import silkwormSettings file
            List <string> silkwormSettings = new List <string>();
            if (!DA.GetDataList(0, silkwormSettings))
            {
                return;
            }

            // import raw Grasshopper Geometry to convert to Silkworm Movements
            List <GH_ObjectWrapper> MovementList = new List <GH_ObjectWrapper>();
            if (!DA.GetDataList(1, MovementList))
            {
                return;
            }

            int sorted = new int();
            if (!DA.GetData(2, ref sorted))
            {
                return;
            }
            #endregion
            #region Utilities

            //Utility to convert list of strings to Settings Dictionary
            SilkwormUtility             sUtil    = new SilkwormUtility();
            Dictionary <string, string> Settings = sUtil.convertSettings(silkwormSettings);
            #endregion

            double layerHeight   = double.Parse(Settings["layer_height"]);
            int    layerHeightDP = CountDecimalPlaces(layerHeight);

            #region Output Holders
            //GCode Lines
            List <GH_String> sGCode = new List <GH_String>();

            //Unsorted Movements
            List <SilkwormMovement> unMovements = new List <SilkwormMovement>();

            //Movements sorted by Layer
            List <SilkwormMovement>[] sMovements = new List <SilkwormMovement> [0];

            #endregion

            //Wrapper List for all types to Parse
            GH_ObjectWrapper[] Movement = MovementList.ToArray();

            //Switch sorting routine by input
            switch (sorted)
            {
            case 1:

                #region Unsorted (Sort Order of Movements by z then x and y)
                if (sorted == 1)
                {
                    //Parse
                    #region Parse Input Type

                    List <Brep> solids = new List <Brep>();
                    List <Mesh> meshes = new List <Mesh>();

                    //Incomplete Silkworm Movements
                    List <SilkwormMovement> incmovements = new List <SilkwormMovement>();

                    List <Brep>     shapes = new List <Brep>();
                    List <Curve>    curves = new List <Curve>();
                    List <Polyline> plines = new List <Polyline>();
                    List <Line>     lines  = new List <Line>();



                    for (int i = 0; i < Movement.Length; i++)
                    {
                        //Sort Types into Container Lists
                        #region IfNull
                        if ((Movement[i].Value == null))
                        {
                            continue;
                        }
                        #endregion

                        #region SilkwormMovement

                        else if ((Movement[i].Value is Silkworm.Type.SilkwormMovement))
                        {
                            SilkwormMovement aMovement = (SilkwormMovement)Movement[i].Value;

                            if (aMovement.complete)
                            {
                                aMovement.Configuration = Settings;     //make sure it has a config field
                                unMovements.Add(aMovement);
                                continue;
                            }
                            else
                            {
                                incmovements.Add(aMovement);
                                continue;
                            }
                        }
                        #endregion
                        #region Solids
                        else if (Movement[i].Value is GH_Brep)
                        {
                            Brep solid = null;
                            GH_Convert.ToBrep(Movement[i].Value, ref solid, GH_Conversion.Both);
                            solids.Add(solid);
                            continue;
                        }
                        else if (Movement[i].Value is GH_Mesh)
                        {
                            Mesh mesh = null;
                            GH_Convert.ToMesh(Movement[i].Value, ref mesh, GH_Conversion.Both);
                            meshes.Add(mesh);
                            continue;
                        }

                        #endregion
                        #region Regions
                        //TODO
                        #endregion
                        #region Curves
                        else if (Movement[i].Value is GH_Curve)
                        {
                            Curve curve = null;
                            GH_Convert.ToCurve(Movement[i].Value, ref curve, GH_Conversion.Both);
                            curves.Add(curve);
                            continue;
                        }

                        #endregion


                        #region SilkwormLine
                        else if (Movement[i].Value is SilkwormLine)
                        {
                            List <SilkwormLine> slines = new List <SilkwormLine>();
                            slines.Add((SilkwormLine)Movement[i].Value);

                            //Check if complete
                            if (isCompleteLine((SilkwormLine)Movement[i].Value))
                            {
                                unMovements.Add(new SilkwormMovement(slines, new Delimiter()));
                            }
                            else
                            {
                                incmovements.Add(new SilkwormMovement(slines, new Delimiter()));
                            }
                            continue;
                        }

                        #endregion
                        #region Line

                        else if (Movement[i].Value is GH_Line)
                        {
                            Line line = new Line();
                            GH_Convert.ToLine(Movement[i].Value, ref line, GH_Conversion.Both);
                            lines.Add(line);

                            continue;
                        }

                        #endregion
                        #region Point
                        else if (Movement[i].Value is GH_Point)
                        {
                            //TODO
                            continue;
                        }

                        #endregion

                        #region Not Supported
                        else
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Datatype Not Supported!");
                            continue;
                        }
                        #endregion
                        #endregion
                    }
                    //Build Movements from Incomplete Parts
                    #region Build Movement

                    #region List<Brep>Add to unMovements

                    if (solids.Count > 0)
                    {
                        List <SilkwormMovement> solidMovements = addsolidBrep(Settings, solids);

                        unMovements.AddRange(solidMovements);
                    }

                    #endregion

                    #region List<Mesh> Add to unMovements
                    //TODO
                    #endregion

                    #region List<Shapes> Add to unMovements
                    //TODO

                    #endregion

                    #region List<Curve> Add to unMovements
                    foreach (Curve curve in curves)
                    {
                        SilkwormMovement movement = new SilkwormMovement(Settings, curve);
                        unMovements.Add(movement);
                    }
                    #endregion

                    #region List<Line> Add to unMovements

                    foreach (Line line in lines)
                    {
                        List <Line> _lines = new List <Line>();
                        _lines.Add(line);
                        unMovements.Add(new SilkwormMovement(Settings, _lines));
                    }
                    #endregion


                    #region List<IncompleteSilkwormMovement> Add to unMovements
                    foreach (SilkwormMovement movement in incmovements)
                    {
                        unMovements.Add(completeMovement(Settings, movement));;
                        continue;
                    }

                    #endregion

                    #endregion
                }
                goto SortZ;
                #endregion
                break;

            case 2:
                #region Partially Sorted (Sort Movements by z only)

                if (sorted == 2)
                {
                    for (int u = 0; u < Movement.Length; u++)
                    {
                        #region IfNull
                        if ((Movement[u].Value == null))
                        {
                            continue;
                        }
                        #endregion

                        #region SilkwormMovement

                        else if ((Movement[u].Value is Silkworm.Type.SilkwormMovement))
                        {
                            SilkwormMovement aMovement = (SilkwormMovement)Movement[u].Value;

                            if (aMovement.complete)
                            {
                                aMovement.Configuration = Settings;     //make sure it has a config field
                                unMovements.Add(aMovement);
                                continue;
                            }
                            else
                            {
                                unMovements.Add(completeMovement(Settings, aMovement));
                                continue;
                            }
                        }
                        #endregion
                        #region Solids
                        else if (Movement[u].Value is GH_Brep)
                        {
                            Brep        solid  = null;
                            List <Brep> solids = new List <Brep>();

                            GH_Convert.ToBrep(Movement[u].Value, ref solid, GH_Conversion.Both);
                            solids.Add(solid);

                            List <SilkwormMovement> solidMovements = addsolidBrep(Settings, solids);

                            unMovements.AddRange(solidMovements);

                            continue;
                        }
                        else if (Movement[u].Value is GH_Mesh)
                        {
                            Mesh mesh = null;
                            GH_Convert.ToMesh(Movement[u].Value, ref mesh, GH_Conversion.Both);

                            continue;
                        }

                        #endregion
                        #region Regions
                        //TODO
                        #endregion
                        #region Curves
                        else if (Movement[u].Value is GH_Curve)
                        {
                            Curve curve = null;
                            GH_Convert.ToCurve(Movement[u].Value, ref curve, GH_Conversion.Both);
                            SilkwormMovement movement = new SilkwormMovement(Settings, curve);
                            unMovements.Add(movement);
                            continue;
                        }

                        #endregion


                        #region SilkwormLine
                        else if (Movement[u].Value is SilkwormLine)
                        {
                            List <SilkwormLine> s_lines = new List <SilkwormLine>();
                            s_lines.Add((SilkwormLine)Movement[u].Value);

                            //Check if complete
                            if (isCompleteLine((SilkwormLine)Movement[u].Value))
                            {
                                unMovements.Add(new SilkwormMovement(s_lines, new Delimiter()));
                            }
                            else
                            {
                                List <Line> lines = new List <Line>();

                                SilkwormLine[] s_Movement = new SilkwormLine[s_lines.Count];


                                foreach (SilkwormLine line in s_lines)
                                {
                                    lines.Add(line.sLine);
                                }

                                List <SilkwormLine> sLines = new SilkwormMovement(Settings, lines).sMovement;

                                List <SilkwormLine> Movements = new List <SilkwormLine>();

                                //Complete Movements
                                for (int j = 0; j < sLines.Count; j++)
                                {
                                    if (s_Movement[j].Flow == -1)
                                    {
                                        s_Movement[j].Flow = sLines[j].Flow;
                                    }
                                    if (s_Movement[j].Speed == -1)
                                    {
                                        s_Movement[j].Speed = sLines[j].Speed;
                                    }
                                    Movements.Add(s_Movement[j]);
                                }

                                SilkwormMovement newMovement = new SilkwormMovement(Movements, new Delimiter());

                                //Add Configuration
                                newMovement.Configuration = Settings;

                                unMovements.Add(newMovement);
                            }
                            continue;
                        }

                        #endregion
                        #region Line

                        else if (Movement[u].Value is GH_Line)
                        {
                            Line line = new Line();
                            GH_Convert.ToLine(Movement[u].Value, ref line, GH_Conversion.Both);
                            List <Line> _lines = new List <Line>();
                            _lines.Add(line);
                            unMovements.Add(new SilkwormMovement(Settings, _lines));

                            continue;
                        }


                        #endregion
                        #region Point
                        else if (Movement[u].Value is GH_Point)
                        {
                            //TODO
                            continue;
                        }

                        #endregion

                        #region Not Supported
                        else
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Datatype Not Supported!");
                            continue;
                        }
                    }
                    #endregion
                }
                goto SortZ;
                #endregion
                break;

            case 3:
                #region Completely Sorted
                if (sorted == 3)
                {
                    //Initialise sMovements
                    sMovements    = new List <SilkwormMovement> [1];
                    sMovements[0] = new List <SilkwormMovement>();


                    for (int u = 0; u < Movement.Length; u++)
                    {
                        #region IfNull
                        if ((Movement[u].Value == null))
                        {
                            continue;
                        }
                        #endregion

                        #region SilkwormMovement

                        else if ((Movement[u].Value is Silkworm.Type.SilkwormMovement))
                        {
                            SilkwormMovement aMovement = (SilkwormMovement)Movement[u].Value;

                            if (aMovement.complete)
                            {
                                aMovement.Configuration = Settings;     //Make sure it has a config field
                                sMovements[0].Add(aMovement);
                                continue;
                            }
                            else
                            {
                                sMovements[0].Add(completeMovement(Settings, aMovement));

                                //sMovements[0].Add(new SilkwormMovement(Movements, new Delimiter()));
                                continue;
                            }
                        }
                        #endregion
                        #region Solids
                        else if (Movement[u].Value is GH_Brep)
                        {
                            Brep        solid  = null;
                            List <Brep> solids = new List <Brep>();

                            GH_Convert.ToBrep(Movement[u].Value, ref solid, GH_Conversion.Both);
                            solids.Add(solid);
                            List <SilkwormMovement> solidMovements = addsolidBrep(Settings, solids);

                            sMovements[0].AddRange(solidMovements);

                            continue;
                        }
                        else if (Movement[u].Value is GH_Mesh)
                        {
                            Mesh mesh = null;
                            GH_Convert.ToMesh(Movement[u].Value, ref mesh, GH_Conversion.Both);

                            continue;
                        }

                        #endregion
                        #region Regions
                        //TODO
                        #endregion
                        #region Curves
                        else if (Movement[u].Value is GH_Curve)
                        {
                            Curve curve = null;
                            GH_Convert.ToCurve(Movement[u].Value, ref curve, GH_Conversion.Both);
                            SilkwormMovement movement = new SilkwormMovement(Settings, curve);
                            sMovements[0].Add(movement);
                            continue;
                        }

                        #endregion


                        #region SilkwormLine
                        else if (Movement[u].Value is SilkwormLine)
                        {
                            List <SilkwormLine> s_lines = new List <SilkwormLine>();
                            s_lines.Add((SilkwormLine)Movement[u].Value);

                            //Check if complete
                            if (isCompleteLine((SilkwormLine)Movement[u].Value))
                            {
                                sMovements[0].Add(new SilkwormMovement(s_lines, new Delimiter()));
                            }
                            else
                            {
                                List <Line> lines = new List <Line>();

                                SilkwormLine[] s_Movement = new SilkwormLine[s_lines.Count];


                                foreach (SilkwormLine line in s_lines)
                                {
                                    lines.Add(line.sLine);
                                }

                                List <SilkwormLine> sLines = new SilkwormMovement(Settings, lines).sMovement;

                                List <SilkwormLine> Movements = new List <SilkwormLine>();

                                //Complete Movements
                                for (int j = 0; j < sLines.Count; j++)
                                {
                                    if (s_Movement[j].Flow == -1)
                                    {
                                        s_Movement[j].Flow = sLines[j].Flow;
                                    }
                                    if (s_Movement[j].Speed == -1)
                                    {
                                        s_Movement[j].Speed = sLines[j].Speed;
                                    }
                                    Movements.Add(s_Movement[j]);
                                }

                                SilkwormMovement newMovement = new SilkwormMovement(Movements, new Delimiter());

                                //Add Configuration
                                newMovement.Configuration = Settings;

                                sMovements[0].Add(newMovement);
                            }
                            continue;
                        }

                        #endregion
                        #region Line

                        else if (Movement[u].Value is GH_Line)
                        {
                            Line line = new Line();
                            GH_Convert.ToLine(Movement[u].Value, ref line, GH_Conversion.Both);
                            List <Line> _lines = new List <Line>();
                            _lines.Add(line);
                            sMovements[0].Add(new SilkwormMovement(Settings, _lines));

                            continue;
                        }

                        #endregion
                        #region Point
                        else if (Movement[u].Value is GH_Point)
                        {
                            //TODO
                            continue;
                        }

                        #endregion

                        #region Not Supported
                        else
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Datatype Not Supported!");
                            continue;
                        }
                    }
                    #endregion
                }
                goto Compiler;
                #endregion
                break;

            default:
                break;
            }

            #region ss
            ////Parse
            //#region Parse Input Type

            //List<Brep> solids = new List<Brep>();
            //List<Mesh> meshes = new List<Mesh>();

            ////Incomplete Silkworm Movements
            //List<SilkwormMovement> incmovements = new List<SilkwormMovement>();

            //List<Brep> shapes = new List<Brep>();
            //List<Curve> curves = new List<Curve>();
            //List<Polyline> plines = new List<Polyline>();
            //List<Line> lines = new List<Line>();



            //for (int i = 0; i < Movement.Length; i++)
            //{

            ////Sort Types into Container Lists
            //    #region IfNull
            //    if ((Movement[i].Value == null))
            //    { continue; }
            //    #endregion

            //#region SilkwormMovement

            //if ((Movement[i].Value is Silkworm.Type.SilkwormMovement))
            //{


            //    SilkwormMovement aMovement = (SilkwormMovement)Movement[i].Value;

            //    if(aMovement.complete)
            //    {
            //        unMovements.Add(aMovement);
            //        continue;
            //    }
            //    else
            //    {
            //        incmovements.Add(aMovement);
            //        continue;
            //    }

            //}
            //#endregion
            //#region Solids
            //if (Movement[i].Value is GH_Brep)
            //{
            //    Brep solid = null;
            //    GH_Convert.ToBrep(Movement[i].Value, ref solid, GH_Conversion.Both);
            //    solids.Add(solid);
            //    continue;
            //}
            //if (Movement[i].Value is GH_Mesh)
            //{
            //    Mesh mesh = null;
            //    GH_Convert.ToMesh(Movement[i].Value, ref mesh, GH_Conversion.Both);
            //    meshes.Add(mesh);
            //    continue;
            //}

            //#endregion
            //#region Regions
            ////TODO
            //#endregion
            //#region Curves
            //if (Movement[i].Value is GH_Curve)
            //{
            //    Curve curve = null;
            //    GH_Convert.ToCurve(Movement[i].Value, ref curve, GH_Conversion.Both);
            //    curves.Add(curve);
            //    continue;
            //}

            //#endregion


            //#region SilkwormLine
            //if (Movement[i].Value is SilkwormLine)
            //{
            //    List<SilkwormLine> slines = new List<SilkwormLine>();
            //    slines.Add((SilkwormLine)Movement[i].Value);

            //    //Check if complete
            //    if (isCompleteLine((SilkwormLine)Movement[i].Value))
            //    {
            //        unMovements.Add(new SilkwormMovement(slines, true));
            //    }
            //    else
            //    {
            //        incmovements.Add(new SilkwormMovement(slines, true));
            //    }
            //    continue;
            //}

            //#endregion
            //#region Line

            //    if (Movement[i].Value is GH_Line)
            //{

            //    Line line = new Line();
            //    GH_Convert.ToLine(Movement[i].Value, ref line, GH_Conversion.Both);
            //    lines.Add(line);

            //}

            //#endregion
            //#region Point
            //    if (Movement[i].Value is GH_Point)
            //{
            // //TODO
            //    continue;
            //}

            //#endregion

            //else
            //{
            //    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Datatype Not Supported!");
            //    continue;
            //}
            //#endregion

            //}
            ////Build Movements from Incomplete Parts
            //#region Build Movement

            //#region List<Brep>Add to unMovements

            //    //List<Brep> solidS = new List<Brep>();
            //    //solidS.Add((Brep)solid);

            //    List<Polyline>[] rPerimeter = new List<Polyline>[0];
            //    List<Polyline>[] rInfill = new List<Polyline>[0];

            //    //Slice, Skin and Fill Breps (TODO: Add Bridge Finder)
            //    SilkwormSkein skein = new SilkwormSkein(Settings, solids);

            //    if (skein.validPos)
            //    {
            //        rPerimeter = skein.plinePerimeter;
            //        rInfill = skein.plineInfill;
            //    }

            //    List<SilkwormMovement> solidMovements = new List<SilkwormMovement>();

            //    //Add to ORGANISED List of Movements (i.e. Model)
            //    for (int b = 0; b <= rPerimeter.GetUpperBound(0); b++)
            //    {
            //        foreach (Polyline pline in rPerimeter[b])
            //        {
            //            //List<SilkwormMovement> sList = new List<SilkwormMovement>();
            //            //sList.Add(new SilkwormMovement(Settings, pline, true));
            //            solidMovements.Add(new SilkwormMovement(Settings, pline, true));
            //        }
            //        foreach (Polyline pline in rInfill[b])
            //        {
            //            //List<SilkwormMovement> sList = new List<SilkwormMovement>();
            //            //sList.Add(new SilkwormMovement(Settings, pline, true));
            //            solidMovements.Add(new SilkwormMovement(Settings, pline, true));
            //        }
            //    }


            //    unMovements.AddRange(solidMovements);

            //#endregion

            //#region List<Mesh> Add to unMovements
            ////TODO
            //#endregion

            //#region List<Shapes> Add to unMovements
            ////TODO

            //#endregion

            //#region List<Curve> Add to unMovements
            //foreach (Curve curve in curves)
            //{
            //    SilkwormMovement movement = new SilkwormMovement(Settings, curve, true);
            //    unMovements.Add(movement);
            //}
            //#endregion

            //#region List<Line> Add to unMovements

            //foreach (Line line in lines)
            //{
            //    List<Line> _lines = new List<Line>();
            //    _lines.Add(line);
            //    unMovements.Add(new SilkwormMovement(Settings, _lines, true));

            //}
            //#endregion


            //#region List<IncompleteSilkwormMovement> Add to unMovements
            //foreach (SilkwormMovement movement in incmovements)
            //    {



            //            List<Line> lines = new List<Line>();

            //            SilkwormLine[] s_Movement = new SilkwormLine[movement.Count];


            //            foreach (SilkwormLine line in movement)

            //            {

            //                lines.Add(line.Curve);

            //            }

            //    List<SilkwormLine> sLines = new SilkwormMovement(Settings, lines,true).sMovement;

            //    List<SilkwormLine> Movements = new List<SilkwormLine>();

            //    //Complete Movements
            //    for (int j = 0; j < sLines.Count; j++)
            //    {
            //        if (s_Movement[j].Flow == -1)
            //        {
            //            s_Movement[j].Flow = sLines[j].Flow;
            //        }
            //        if (s_Movement[j].Speed == -1)
            //        {
            //            s_Movement[j].Speed = sLines[j].Speed;
            //        }
            //        Movements.Add(s_Movement[j]);
            //    }

            //    //Add Configuration
            //    movement.Configuration = Settings;

            //    unMovements.Add(new SilkwormMovement(Movements, true));
            //    continue;



            //}

            //#endregion

            //#endregion
            #endregion

            //Sort Unorganised Movements into Layered Model
SortZ:
            #region Build Model

            List <double> uniqueZ = new List <double>();

            //Find Unique ZValues
            uniqueZ.AddRange(FindUniqueZValues(unMovements, layerHeightDP));


            //Sort List of Unique Z Levels
            uniqueZ.Sort();

            //Make Dictionary from List of Unique Z Levels
            Dictionary <double, int> ZLevel = new Dictionary <double, int>();
            for (int d = 0; d < uniqueZ.Count; d++)
            {
                ZLevel.Add(uniqueZ[d], d);
            }

            //Initialise Array of Lists
            sMovements = new List <SilkwormMovement> [uniqueZ.Count];
            for (int a = 0; a < sMovements.Length; a++)
            {
                sMovements[a] = new List <SilkwormMovement>();
            }
            //Sort Silkworm Movements into correct layers in Array of Lists
            foreach (SilkwormMovement movement in unMovements)
            {
                sMovements[ZLevel[Math.Round(movement.ZDomain.T0, layerHeightDP)]].Add(movement);
            }

            #endregion
            goto Compiler;

            //Compile Model to GCode
Compiler:
            #region GCode Compiler
            #region HEADER
            //Add Custom Commands at Start
            string header = Settings["start_gcode"];

            //Char[] splitChar = new Char[] {'\\','\n', 'n'};
            string[] splitChar = new string[] { "\\n" };
            string[] parts     = header.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);

            if (parts != null)
            {
                for (int i = 0; i < parts.Length; i++)
                {
                    sGCode.Add(new GH_String(parts[i]));
                }
            }
            else
            {
                sGCode.Add(new GH_String(header));
            }

            if (int.Parse(Settings["absolute_extrudersteps"]) == 1) //if true use absolute distances for extrusion, otherwise use relative
            {
                sGCode.Add(new GH_String("M82 ; use absolute distances for extrusion"));
            }

            sGCode.Add(new GH_String("G90 ; use absolute coordinates"));
            sGCode.Add(new GH_String("G21 ; set units to millimeters"));
            sGCode.Add(new GH_String("G92 E0 ; reset extrusion distance"));


            //Set Temperature
            double temp = double.Parse(Settings["temperature"]);
            sGCode.Add(new GH_String("M104 S" + temp + " ; set temperature"));
            sGCode.Add(new GH_String("M109 S" + temp + " ; wait for temperature to be reached"));

            //Extrude a bit of plastic before start
            sGCode.Add(new GH_String("G1 Z0.0 F360 E1"));
            #endregion

            for (int z = 0; z <= sMovements.GetUpperBound(0); z++)
            {
                foreach (SilkwormMovement movement in sMovements[z])
                {
                    sGCode.AddRange(movement.ToGCode());
                }
            }



            #region FOOTER

            sGCode.Add(new GH_String("G92 E0 ; reset extrusion distance"));

            //Add Custom Commands at End
            string footer = Settings["end_gcode"];

            string[] fparts = footer.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);

            if (fparts != null)
            {
                for (int i = 0; i < fparts.Length; i++)
                {
                    sGCode.Add(new GH_String(fparts[i]));
                }
            }
            else
            {
                sGCode.Add(new GH_String(footer));
            }

            #endregion

            ////Convert Array of Movements to List
            //List<SilkwormMovement> outMovements = new List<SilkwormMovement>();
            //for (int l = 0; l < sMovements.GetUpperBound(0); l++)
            //{
            //    outMovements.AddRange(sMovements[l]);
            //}
            #endregion

            #region Silkworm Model
            List <SilkwormMovement> s_Model = new List <SilkwormMovement>();
            for (int p = 0; p <= sMovements.GetUpperBound(0); p++)
            {
                for (int s = 0; s < sMovements[p].Count; s++)
                {
                    s_Model.Add(sMovements[p][s]);
                }
            }
            List <SilkwormModel> sModel = new List <SilkwormModel>();
            sModel.Add(new SilkwormModel(Settings, s_Model));
            #endregion

            //Output GCode and Model
            #region OUTPUTS

            DA.SetDataList(0, sGCode);
            DA.SetDataList(1, sModel);

            #endregion
        }
예제 #8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Input Holders
            List <double>           Flow     = new List <double>();
            List <double>           Speed    = new List <double>();
            List <GH_ObjectWrapper> Movement = new List <GH_ObjectWrapper>();
            GH_ObjectWrapper        dObject  = new GH_ObjectWrapper();

            List <SilkwormLine> sMovement = new List <SilkwormLine>();


            //Input
            if (!DA.GetData(3, ref dObject))
            {
            }

            if (!DA.GetDataList(1, Speed))
            {
            }

            if (!DA.GetDataList(2, Flow))
            {
            }

            if (!DA.GetDataList(0, Movement))
            {
                return;
            }


            //Fill Input with placeholders if empty
            if (Speed.Count < 1)
            {
                for (int j = 0; j < Movement.Count; j++)
                {
                    Speed.Add(-1);
                }
            }
            if (Speed.Count == 1)
            {
                if (Movement.Count > 1)
                {
                    for (int j = 0; j < Movement.Count; j++)
                    {
                        Speed.Add(Speed[0]);
                    }
                }
            }
            if (Flow.Count < 1)
            {
                for (int k = 0; k < Movement.Count; k++)
                {
                    Flow.Add(-1);
                }
            }
            if (Flow.Count == 1)
            {
                if (Movement.Count > 1)
                {
                    for (int k = 0; k < Movement.Count; k++)
                    {
                        Flow.Add(Flow[0]);
                    }
                }
            }


            #region Sort Geometric Input
            List <Curve>   curves = new List <Curve>();
            List <Line>    lines  = new List <Line>();
            List <Point3d> points = new List <Point3d>();

            foreach (GH_ObjectWrapper Goo in Movement)
            {
                if (Goo.Value is GH_Curve)
                {
                    Curve curve = null;
                    GH_Convert.ToCurve(Goo.Value, ref curve, GH_Conversion.Both);
                    curves.Add(curve);
                    continue;
                }
                if (Goo.Value is GH_Line)
                {
                    Line line = new Line();
                    GH_Convert.ToLine(Goo.Value, ref line, GH_Conversion.Both);
                    lines.Add(line);
                    continue;
                }

                if (Goo.Value is GH_Point)
                {
                    Point3d point = new Point3d();
                    GH_Convert.ToPoint3d(Goo.Value, ref point, GH_Conversion.Both);
                    points.Add(point);
                    continue;
                }
            }
            #endregion

            #region Sort Numerical Input
            #endregion

            //Output Holder
            SilkwormMovement sModel = new SilkwormMovement();

            //Convert Different Geometry types to Movements based on input parameters
            #region Catch Exceptions
            if (points.Count > 1 || curves.Count > 1)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Only one curve or point per movement");
            }
            if (points.Count == 1 || curves.Count == 1)
            {
                if (Flow.Count > 1 || Speed.Count > 1)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Flow or Speed Values do not match length of Input");
                }
            }
            #endregion

            #region if curve
            ////Make Silkworm Lines
            if (curves.Count > 0 && curves.Count < 2)
            {
                List <Line>     sLines    = new List <Line>();
                Curve           newcurve  = curves[0];
                SilkwormSegment segmented = new SilkwormSegment(newcurve);

                //Make lines from curves
                foreach (Curve curve in segmented.Segments)
                {
                    Line line = new Line(curve.PointAtStart, curve.PointAtEnd);
                    sLines.Add(line);
                }

                //Create Silkworm Line from each line and a single flow or speed value
                for (int i = 0; i < sLines.Count; i++)
                {
                    SilkwormLine sLine = new SilkwormLine(Flow[0], Speed[0], sLines[i]);
                    sMovement.Add(sLine);
                }

                //Add Custom Delimiter or Default Delimiter (depending if input is provided)
                if (dObject.Value is Delimiter)
                {
                    Delimiter delimiter = (Delimiter)dObject.Value;

                    sModel = new SilkwormMovement(sMovement, delimiter);
                }
                else
                {
                    sModel = new SilkwormMovement(sMovement, new Delimiter());
                }
            }
            #endregion

            #region if lines
            //Make Silkworm Lines
            if (lines.Count > 0)
            {
                #region More Error Catching
                if (Flow.Count > 1 && Flow.Count != lines.Count)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Flow Values do not match length of Line List");
                }
                if (Speed.Count > 1 && Speed.Count != lines.Count)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Speed Values do not match length of Line List");
                }
                #endregion

                //Create Silkworm Line from each line and a corresponding flow or speed value
                //(will create an incomplete movement if none are provided)
                if (Flow.Count == lines.Count && Speed.Count == lines.Count)
                {
                    for (int i = 0; i < lines.Count; i++)
                    {
                        SilkwormLine sLine = new SilkwormLine(Flow[i], Speed[i], lines[i]);
                        sMovement.Add(sLine);
                    }
                }


                //Add Custom Delimiter or Default Delimiter (depending if input is provided)
                if (dObject.Value is Delimiter)
                {
                    Delimiter delimiter = (Delimiter)dObject.Value;

                    sModel = new SilkwormMovement(sMovement, delimiter);
                }
                else
                {
                    sModel = new SilkwormMovement(sMovement, new Delimiter());
                }
            }
            #endregion

            #region if point
            if (points.Count < 2 && points.Count > 0)
            {
                if (dObject.Value is Delimiter)
                {
                    Delimiter delimiter = (Delimiter)dObject.Value;

                    sModel = new SilkwormMovement(points[0], delimiter);
                }
                else
                {
                    sModel = new SilkwormMovement(points[0], new Delimiter());
                }
            }
            #endregion

            //Output
            DA.SetData(0, sModel);
        }
예제 #9
0
        public bool ReadDataTreeBranch(List <Grasshopper.Kernel.Types.GH_Curve> branches, ref List <List <HbCurve> > curvesListListRevit, bool AllowNurbs, bool NestBranch)
        {
            try {
                Rhino.Geometry.NurbsCurve nurbsCurveRhino;
                Rhino.Geometry.LineCurve  lineCurveRhino;
                Rhino.Geometry.ArcCurve   arcCurveRhino;
                List <HbCurve>            curvesListRevit = new List <HbCurve>();

                for (int i = 0; i < branches.Count; i++)
                {
                    //if (NestBranch)  curvesListRevit.Clear();
                    if (NestBranch)
                    {
                        curvesListRevit = new List <HbCurve>();
                    }
                    GH_Curve branch       = branches[i];
                    Curve    curveBranch  = null;
                    Curve    curveBranch2 = null;
                    GH_Convert.ToCurve(branch, ref curveBranch, GH_Conversion.Both);
                    if (curveBranch == null)
                    {
                        Print("Null branch value in ReadDataTreeBranch() ignored.");
                        continue;
                    }

                    switch (curveBranch.GetType().Name)
                    {
                    case "PolyCurve":
                        // Note:  The simplify functions only used with a PolyCureve so moved inside the switch statement.
                        // Note:  Logic of this step is not clear.  It may be that only the CurveSimplifyOptions.All
                        if (curveBranch.Degree == 1)
                        {
                            curveBranch2 = curveBranch.Simplify(CurveSimplifyOptions.RebuildLines, 0, 0);
                            if (curveBranch2 == null)
                            {
                                Print("Simplify() with CurveSimplifyOptions.RebuildLines returned null.");
                            }
                            else
                            {
                                curveBranch = curveBranch2;
                            }
                        }
                        if (curveBranch.Degree == 2)
                        {
                            curveBranch2 = curveBranch.Simplify(CurveSimplifyOptions.RebuildArcs, 0, 0);
                            if (curveBranch2 == null)
                            {
                                Print("Simplify() with CurveSimplifyOptions.RebuildArcs returned null.");
                            }
                            else
                            {
                                curveBranch = curveBranch2;
                            }
                        }
                        curveBranch2 = curveBranch.Simplify(CurveSimplifyOptions.All, .0001, 1);
                        if (curveBranch2 == null)
                        {
                            Print("Simplify() with CurveSimplifyOptions.All returned null.");
                        }
                        else
                        {
                            curveBranch = curveBranch2;
                        }
                        PolyCurve polyCurve = (PolyCurve)curveBranch;
                        for (int j = 0; j < polyCurve.SegmentCount; j++)
                        {
                            Curve curveRhino = polyCurve.SegmentCurve(j);
                            switch (curveRhino.GetType().Name)
                            {
                            case "LineCurve":
                                lineCurveRhino = (LineCurve)curveRhino;
                                curvesListRevit.Add(Hb(lineCurveRhino));
                                break;

                            case "NurbsCurve":
                                if (!AllowNurbs)
                                {
                                    break;
                                }

                                nurbsCurveRhino = (NurbsCurve)curveRhino;
                                curvesListRevit.Add(Hb(nurbsCurveRhino));
                                break;

                            case "ArcCurve":
                                arcCurveRhino = (ArcCurve)curveRhino;
                                curvesListRevit.Add(Hb(arcCurveRhino));
                                break;

                            case "PolylineCurve":
                                //NurbsCurve nurbsLineCurve = (NurbsCurve)curveBranch.ToNurbsCurve();
                                NurbsCurve nurbsLineCurve = (NurbsCurve)curveRhino.ToNurbsCurve();
                                Rhino.Geometry.Collections.NurbsCurvePointList points = nurbsLineCurve.Points;

                                for (int k = 0; k < points.Count - 1; k++)
                                {
                                    HbLine lineRevit = new HbLine();
                                    Rhino.Geometry.ControlPoint controlPointStart = points[k];
                                    Rhino.Geometry.ControlPoint controlPointEnd   = points[k + 1];
                                    Point3d xyzRhinoStart = controlPointStart.Location;
                                    Point3d xyzRhinoEnd   = controlPointEnd.Location;

                                    HbXYZ xyzRevitStart = new HbXYZ(xyzRhinoStart.X, xyzRhinoStart.Y, xyzRhinoStart.Z);
                                    HbXYZ xyzRevitEnd   = new HbXYZ(xyzRhinoEnd.X, xyzRhinoEnd.Y, xyzRhinoEnd.Z);

                                    lineRevit.PointStart = new HbXYZ(xyzRevitStart.X, xyzRevitStart.Y, xyzRevitStart.Z);
                                    lineRevit.PointEnd   = new HbXYZ(xyzRevitEnd.X, xyzRevitEnd.Y, xyzRevitEnd.Z);
                                    curvesListRevit.Add(lineRevit);
                                }

                                break;

                            default:
                                Print("Unknown Rhino PolyCurve curve type: " + curveRhino.GetType().Name);
                                break;
                            }
                        }
                        break;

                    case "NurbsCurve":
                        if (!AllowNurbs)
                        {
                            break;
                        }

                        nurbsCurveRhino = (NurbsCurve)curveBranch;
                        //if !nurbsCurveRhino.IsClosed()
                        curvesListRevit.Add(Hb(nurbsCurveRhino));
                        break;

                    case "PolylineCurve":
                        NurbsCurve nurbsLineCurve2 = (NurbsCurve)curveBranch.ToNurbsCurve();
                        Rhino.Geometry.Collections.NurbsCurvePointList points2 = nurbsLineCurve2.Points;

                        for (int k = 0; k < points2.Count - 1; k++)
                        {
                            HbLine lineRevit = new HbLine();
                            Rhino.Geometry.ControlPoint controlPointStart = points2[k];
                            Rhino.Geometry.ControlPoint controlPointEnd   = points2[k + 1];
                            Point3d xyzRhinoStart = controlPointStart.Location;
                            Point3d xyzRhinoEnd   = controlPointEnd.Location;

                            HbXYZ xyzRevitStart = new HbXYZ(xyzRhinoStart.X, xyzRhinoStart.Y, xyzRhinoStart.Z);
                            HbXYZ xyzRevitEnd   = new HbXYZ(xyzRhinoEnd.X, xyzRhinoEnd.Y, xyzRhinoEnd.Z);

                            lineRevit.PointStart = new HbXYZ(xyzRevitStart.X, xyzRevitStart.Y, xyzRevitStart.Z);
                            lineRevit.PointEnd   = new HbXYZ(xyzRevitEnd.X, xyzRevitEnd.Y, xyzRevitEnd.Z);
                            curvesListRevit.Add(lineRevit);
                        }

                        break;

                    case "LineCurve":
                        lineCurveRhino = (LineCurve)curveBranch;
                        curvesListRevit.Add(Hb(lineCurveRhino));
                        break;

                    case "ArcCurve":
                        arcCurveRhino = (ArcCurve)curveBranch;
                        curvesListRevit.Add(Hb(arcCurveRhino));
                        break;

                    default:
                        Print("Unknown Rhino curve type: " + curveBranch.GetType().Name);
                        break;
                    }
                    if (NestBranch)
                    {
                        curvesListListRevit.Add(curvesListRevit);
                    }
                }

                if (!NestBranch)
                {
                    curvesListListRevit.Add(curvesListRevit);
                }

                return(true);
            }
            catch (Exception exception) {
                Print("Exception in 'ReadDataTreeBranch' w/ curves: " + exception.Message);
                return(false);
            }
        }
예제 #10
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var curves     = new DataTree <Polyline>();
            var points     = new DataTree <Point3d>();
            var frames     = new DataTree <Plane>();
            int collisions = 0;

            var gCurves = new GH_Structure <GH_Curve>();
            var gPoints = new GH_Structure <GH_Point>();
            var gFrames = new GH_Structure <GH_Plane>();

            if (!DA.GetDataTree(0, out gPoints))
            {
                return;
            }
            if (!DA.GetDataTree(1, out gFrames))
            {
                return;
            }
            DA.GetData(2, ref collisions);
            if (!DA.GetDataTree(3, out gCurves))
            {
                return;
            }

            var tempPoint = new Point3d();

            foreach (var path in gPoints.Paths)
            {
                var branch = gPoints.get_Branch(path);

                foreach (var item in branch)
                {
                    GH_Convert.ToPoint3d(item, ref tempPoint, GH_Conversion.Both);

                    points.Add(tempPoint, path);
                }
            }

            Curve tempCurve  = null;
            var   tempPoly   = new Polyline();
            var   curvesList = new List <Curve>();

            foreach (var path in gCurves.Paths)
            {
                var branch = gCurves.get_Branch(path);

                foreach (var item in branch)
                {
                    GH_Convert.ToCurve(item, ref tempCurve, GH_Conversion.Both);
                    tempCurve.TryGetPolyline(out tempPoly);

                    curves.Add(tempPoly, path);
                }
            }

            var tempPlane = new Plane();

            foreach (var path in gFrames.Paths)
            {
                var branch = gFrames.get_Branch(path);

                foreach (var item in branch)
                {
                    GH_Convert.ToPlane(item, ref tempPlane, GH_Conversion.Both);
                    frames.Add(tempPlane, path);
                }
            }

            int             branches = curves.BranchCount;
            List <Polyline> listOut  = new List <Polyline>();

            if (branches == 1)
            {
                listOut.AddRange(curves.Branch(0));
            }

            if (branches == 2)
            {
                if (collisions != 0)
                {
                    int branchOneCount = curves.Branch(0).Count;

                    var pointComparer = points.Branch(0)[curves.Branch(0).Count - 1].Z;

                    var comparer = new List <double>();

                    var listOfCurves    = new DataTree <Polyline>();
                    var listOfCurvesOne = new List <Polyline>();
                    var listOfCurvesTwo = new List <Polyline>();

                    listOfCurves.AddRange(curves.Branch(0));

                    var listOfPlanes    = new List <Plane>();
                    var listOfPlanesOne = new List <Plane>();

                    listOfPlanes.AddRange(frames.Branch(0));

                    var pathOne = new GH_Path(1);
                    var pathTwo = new GH_Path(2);

                    for (int i = 0; i < curves.Branch(1).Count; ++i)
                    {
                        comparer.Add(points.Branch(1)[i].Z);

                        if (pointComparer >= comparer[i])
                        {
                            listOfCurves.Add(curves.Branch(1)[i], pathOne);
                        }

                        else
                        {
                            listOfCurvesOne.Add(curves.Branch(1)[i]);
                            listOfPlanesOne.Add(frames.Branch(1)[i]);
                        }
                    }

                    var listOfUnions = RegionUnion(listOfCurves, listOfPlanes);

                    listOut.AddRange(listOfUnions);
                    listOut.AddRange(listOfCurvesOne);
                }

                else
                {
                    for (int i = 0; i < branches; ++i)
                    {
                        listOut.AddRange(curves.Branch(i));
                    }
                }
            }

            if (branches == 3)
            {
                if (collisions != 0)
                {
                    int branchOneCount = curves.Branch(0).Count;

                    var pointComparer    = points.Branch(0)[curves.Branch(0).Count - 1].Z;
                    var pointComparerOne = points.Branch(1)[curves.Branch(1).Count - 1].Z;

                    var comparer = new List <double>();

                    var listOfCurves    = new DataTree <Polyline>();
                    var listOfCurvesOne = new DataTree <Polyline>();
                    var listOfCurvesTwo = new List <Polyline>();

                    listOfCurves.AddRange(curves.Branch(0));

                    var listOfPlanes    = new List <Plane>();
                    var listOfPlanesOne = new List <Plane>();

                    listOfPlanes.AddRange(frames.Branch(0));

                    var pathOne = new GH_Path(1);
                    var pathTwo = new GH_Path(2);

                    for (int i = 0; i < curves.Branch(1).Count; ++i)
                    {
                        comparer.Add(points.Branch(1)[i].Z);

                        if (pointComparer >= comparer[i])
                        {
                            listOfCurves.Add(curves.Branch(1)[i], pathOne);
                        }

                        else
                        {
                            listOfCurvesOne.Add(curves.Branch(1)[i], pathOne);
                            listOfCurvesOne.Add(curves.Branch(2)[i], pathTwo);
                            listOfPlanesOne.Add(frames.Branch(1)[i]);
                        }
                    }

                    var comparerOne = new List <double>();

                    for (int i = 0; i < curves.Branch(2).Count; ++i)
                    {
                        comparerOne.Add(points.Branch(2)[i].Z);

                        if (pointComparer >= comparerOne[i])
                        {
                            listOfCurves.Add(curves.Branch(2)[i], pathTwo);
                        }

                        if (pointComparerOne >= comparerOne[i])
                        {
                        }

                        else
                        {
                            listOfCurvesTwo.Add(curves.Branch(2)[i]);
                        }
                    }

                    List <Polyline> listOfUnionObjs    = RegionUnion(listOfCurves, listOfPlanes);
                    List <Polyline> listOfUnionObjsOne = RegionUnion(listOfCurvesOne, listOfPlanesOne);

                    listOut.AddRange(listOfUnionObjs);
                    listOut.AddRange(listOfUnionObjsOne);
                    listOut.AddRange(listOfCurvesTwo);
                }

                else
                {
                    for (int i = 0; i < branches; ++i)
                    {
                        listOut.AddRange(curves.Branch(i));
                    }
                }
            }

            DA.SetDataList(0, listOut);

            var volume       = new DataTree <Brep>();
            var polyToCurves = new DataTree <Curve>();

            for (int i = 0; i < branches; ++i)
            {
                var path = new GH_Path(i);

                for (int j = 0; j < curves.Branch(i).Count; ++j)
                {
                    polyToCurves.Add(curves.Branch(i)[j].ToNurbsCurve(), path);
                }
            }

            for (int i = 0; i < branches; ++i)
            {
                volume.Add(Brep.CreateFromLoft(polyToCurves.Branch(i), Point3d.Unset, Point3d.Unset, LoftType.Tight, false)[0].CapPlanarHoles(0.0001), new GH_Path(i));
            }

            DA.SetDataTree(1, volume);

            DA.SetData(2, branches);
        }
예제 #11
0
        List <Polyline> RegionUnion(DataTree <Polyline> listOfCurves, List <Plane> frames)
        {
            int curveCount = listOfCurves.BranchCount;

            var regionUnion            = new SurfaceComponents.SolidComponents.Component_CurveBooleanUnion();
            var regionUnionInputCurves = regionUnion.Params.Input[0] as Grasshopper.Kernel.GH_PersistentParam <Grasshopper.Kernel.Types.GH_Curve>;

            regionUnionInputCurves.PersistentData.ClearData();

            var regionUnionInputPlanes = regionUnion.Params.Input[1] as Grasshopper.Kernel.GH_PersistentParam <Grasshopper.Kernel.Types.GH_Plane>;

            regionUnionInputPlanes.PersistentData.ClearData();

            var ghPlane = new GH_Plane();

            for (int i = 0; i < curveCount; ++i)
            {
                for (int j = 0; j < listOfCurves.Branch(i).Count; ++j)
                {
                    regionUnionInputCurves.PersistentData.Append(new GH_Curve(listOfCurves.Branch(i)[j].ToNurbsCurve()));

                    if (i == 0)
                    {
                        GH_Convert.ToGHPlane(frames[j], GH_Conversion.Both, ref ghPlane);
                        regionUnionInputPlanes.PersistentData.Append(new GH_Plane(ghPlane));
                    }
                }
            }

            regionUnion.ExpireSolution(true);

            var doc = new Grasshopper.Kernel.GH_Document();

            doc.AddObject(regionUnion, false);

            regionUnion.Params.Output[0].CollectData();

            int countOfUnions = regionUnion.Params.Output[0].VolatileData.PathCount;

            var listOfUnionObjs = new object();

            Curve temp     = null;
            var   polyOut  = new Polyline[countOfUnions][];
            var   polyList = new List <Polyline>();

            for (int i = 0; i < countOfUnions; ++i)
            {
                int item = regionUnion.Params.Output[0].VolatileData.get_Branch(i).Count;

                polyOut[i] = new Polyline[item];

                for (int j = 0; j < item; ++j)
                {
                    listOfUnionObjs = regionUnion.Params.Output[0].VolatileData.get_Branch(i)[j];
                    GH_Convert.ToCurve(listOfUnionObjs, ref temp, GH_Conversion.Both);
                    temp.TryGetPolyline(out polyOut[i][j]);
                    polyList.Add(polyOut[i][j]);
                }
            }

            doc.RemoveObject(regionUnion.Attributes, false);

            return(polyList);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaMember2d gsaMember2d = new GsaMember2d();

            if (DA.GetData(0, ref gsaMember2d))
            {
                GsaMember2d mem = gsaMember2d.Duplicate();

                // #### inputs ####

                // 1 brep
                Brep brep = mem.Brep; //existing brep

                GH_Brep ghbrep = new GH_Brep();
                if (DA.GetData(1, ref ghbrep))
                {
                    if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both))
                    {
                        mem.Brep = brep;
                    }
                }

                // 2 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

                if (DA.GetData(2, ref gh_typ))
                {
                    GsaProp2d prop2d = new GsaProp2d();
                    if (gh_typ.Value is GsaProp2d)
                    {
                        gh_typ.CastTo(ref prop2d);
                    }
                    else if (gh_typ.Value is GH_Number)
                    {
                        if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            prop2d.ID = idd;
                        }
                    }
                    mem.Property = prop2d;
                }

                // 3 offset
                GsaOffset offset = new GsaOffset();
                if (DA.GetData(3, ref offset))
                {
                    mem.Member.Offset.Z = offset.Z;
                }

                // 4 inclusion points
                List <Point3d>  pts   = mem.InclusionPoints;
                List <GH_Point> ghpts = new List <GH_Point>();
                if (DA.GetDataList(4, ghpts))
                {
                    for (int i = 0; i < ghpts.Count; i++)
                    {
                        Point3d pt = new Point3d();
                        if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both))
                        {
                            pts.Add(pt);
                        }
                    }
                }

                // 5 inclusion lines
                CurveList       crvlist = new CurveList(mem.InclusionLines);
                List <Curve>    crvs    = crvlist.ToList();
                List <GH_Curve> ghcrvs  = new List <GH_Curve>();
                if (DA.GetDataList(5, ghcrvs))
                {
                    for (int i = 0; i < ghcrvs.Count; i++)
                    {
                        Curve crv = null;
                        if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both))
                        {
                            crvs.Add(crv);
                        }
                    }
                }

                GsaMember2d tmpmem = new GsaMember2d(brep, crvs, pts)
                {
                    ID       = mem.ID,
                    Member   = mem.Member,
                    Property = mem.Property
                };
                mem = tmpmem;

                // 6 mesh size
                GH_Number ghmsz = new GH_Number();
                if (DA.GetData(6, ref ghmsz))
                {
                    if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both))
                    {
                        mem.Member.MeshSize = msz;
                    }
                }

                // 7 mesh with others
                GH_Boolean ghbool = new GH_Boolean();
                if (DA.GetData(7, ref ghbool))
                {
                    if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both))
                    {
                        //mem.member.MeshWithOthers
                    }
                }

                // 8 type
                GH_Integer ghint = new GH_Integer();
                if (DA.GetData(8, ref ghint))
                {
                    if (GH_Convert.ToInt32(ghint, out int type, GH_Conversion.Both))
                    {
                        mem.Member.Type = Util.Gsa.GsaToModel.Member2dType(type);
                    }
                }

                // 9 element type / analysis order
                GH_Integer ghinteg = new GH_Integer();
                if (DA.GetData(9, ref ghinteg))
                {
                    if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both))
                    {
                        mem.Member.Type2D = Util.Gsa.GsaToModel.Element2dType(type);
                    }
                }

                // 10 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(10, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        mem.ID = id;
                    }
                }

                // 11 name
                GH_String ghnm = new GH_String();
                if (DA.GetData(11, ref ghnm))
                {
                    if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both))
                    {
                        mem.Member.Name = name;
                    }
                }

                // 12 Group
                GH_Integer ghgrp = new GH_Integer();
                if (DA.GetData(12, ref ghgrp))
                {
                    if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both))
                    {
                        mem.Member.Group = grp;
                    }
                }

                // 13 Colour
                GH_Colour ghcol = new GH_Colour();
                if (DA.GetData(13, ref ghcol))
                {
                    if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                    {
                        mem.Member.Colour = col;
                    }
                }

                // 14 Dummy
                GH_Boolean ghdum = new GH_Boolean();
                if (DA.GetData(14, ref ghdum))
                {
                    if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both))
                    {
                        mem.Member.IsDummy = dum;
                    }
                }

                // #### outputs ####

                DA.SetData(0, new GsaMember2dGoo(mem));

                DA.SetData(1, mem.Brep);

                DA.SetData(2, mem.Property);

                GsaOffset gsaOffset = new GsaOffset
                {
                    Z = mem.Member.Offset.Z
                };
                DA.SetData(3, gsaOffset);

                DA.SetDataList(4, mem.InclusionPoints);
                DA.SetDataList(5, mem.InclusionLines);

                DA.SetData(6, mem.Member.MeshSize);
                //DA.SetData(7, mem.member.MeshWithOthers);

                DA.SetData(8, mem.Member.Type);
                DA.SetData(9, mem.Member.Type2D);

                DA.SetData(10, mem.ID);
                DA.SetData(11, mem.Member.Name);
                DA.SetData(12, mem.Member.Group);
                DA.SetData(13, mem.Member.Colour);

                DA.SetData(14, mem.Member.IsDummy);
            }
        }
예제 #13
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaMember2d gsaMember2d = new GsaMember2d();

            if (DA.GetData(0, ref gsaMember2d))
            {
                if (gsaMember2d == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member2D input is null");
                }
                GsaMember2d mem = gsaMember2d.Duplicate();

                // #### inputs ####

                // 1 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(1, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        mem.ID = id;
                    }
                }

                // 2/3/4 Brep, incl.pts and incl.lns
                Brep            brep    = mem.Brep; //existing brep
                GH_Brep         ghbrep  = new GH_Brep();
                CurveList       crvlist = new CurveList(mem.InclusionLines);
                List <Curve>    crvs    = crvlist.ToList();
                List <GH_Curve> ghcrvs  = new List <GH_Curve>();
                List <GH_Point> ghpts   = new List <GH_Point>();
                List <Point3d>  pts     = mem.InclusionPoints;

                if ((DA.GetData(2, ref ghbrep)) || (DA.GetDataList(3, ghpts)) || (DA.GetDataList(4, ghcrvs)))
                {
                    // 2 brep
                    if (DA.GetData(2, ref ghbrep))
                    {
                        if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both))
                        {
                            mem.Brep = brep;
                        }
                    }

                    // 3 inclusion points
                    if (DA.GetDataList(3, ghpts))
                    {
                        for (int i = 0; i < ghpts.Count; i++)
                        {
                            Point3d pt = new Point3d();
                            if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both))
                            {
                                pts.Add(pt);
                            }
                        }
                    }

                    // 4 inclusion lines
                    if (DA.GetDataList(4, ghcrvs))
                    {
                        for (int i = 0; i < ghcrvs.Count; i++)
                        {
                            Curve crv = null;
                            if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both))
                            {
                                crvs.Add(crv);
                            }
                        }
                    }

                    GsaMember2d tmpmem = new GsaMember2d(brep, crvs, pts);
                    mem.PolyCurve            = tmpmem.PolyCurve;
                    mem.Topology             = tmpmem.Topology;
                    mem.TopologyType         = tmpmem.TopologyType;
                    mem.VoidTopology         = tmpmem.VoidTopology;
                    mem.VoidTopologyType     = tmpmem.VoidTopologyType;
                    mem.InclusionLines       = tmpmem.InclusionLines;
                    mem.IncLinesTopology     = tmpmem.IncLinesTopology;
                    mem.IncLinesTopologyType = tmpmem.IncLinesTopologyType;
                    mem.InclusionPoints      = tmpmem.InclusionPoints;

                    mem = tmpmem;
                }

                // 5 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

                if (DA.GetData(5, ref gh_typ))
                {
                    GsaProp2d prop2d = new GsaProp2d();
                    if (gh_typ.Value is GsaProp2dGoo)
                    {
                        gh_typ.CastTo(ref prop2d);
                        mem.Property        = prop2d;
                        mem.Member.Property = 0;
                    }
                    else
                    {
                        if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            mem.Member.Property = idd;
                            mem.Property        = null;
                        }
                        else
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer");
                            return;
                        }
                    }
                }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaMember1d gsaMember1d = new GsaMember1d();

            if (DA.GetData(0, ref gsaMember1d))
            {
                GsaMember1d mem = gsaMember1d.Duplicate();

                // #### inputs ####

                // 1 curve
                GH_Curve ghcrv = new GH_Curve();
                if (DA.GetData(1, ref ghcrv))
                {
                    Curve crv = null;
                    if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both))
                    {
                        GsaMember1d tmpmem = new GsaMember1d(crv)
                        {
                            ID           = mem.ID,
                            Member       = mem.Member,
                            ReleaseEnd   = mem.ReleaseEnd,
                            ReleaseStart = mem.ReleaseStart
                        };
                        mem = tmpmem;
                    }
                }

                // 2 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                if (DA.GetData(2, ref gh_typ))
                {
                    GsaSection section = new GsaSection();
                    if (gh_typ.Value is GsaSection)
                    {
                        gh_typ.CastTo(ref section);
                    }
                    else if (gh_typ.Value is GH_Number)
                    {
                        if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            section.ID = idd;
                        }
                    }
                    mem.Section = section;
                }


                // 3 type
                GH_Integer ghint = new GH_Integer();
                if (DA.GetData(4, ref ghint))
                {
                    if (GH_Convert.ToInt32(ghint, out int type, GH_Conversion.Both))
                    {
                        mem.Member.Type = Util.Gsa.GsaToModel.Member1dType(type);
                    }
                }

                // 4 element type
                GH_Integer ghinteg = new GH_Integer();
                if (DA.GetData(4, ref ghinteg))
                {
                    if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both))
                    {
                        mem.Member.Type1D = Util.Gsa.GsaToModel.Element1dType(type);
                    }
                }

                // 5 offset
                GsaOffset offset = new GsaOffset();
                if (DA.GetData(5, ref offset))
                {
                    mem.Member.Offset.X1 = offset.X1;
                    mem.Member.Offset.X2 = offset.X2;
                    mem.Member.Offset.Y  = offset.Y;
                    mem.Member.Offset.Z  = offset.Z;
                }

                // 6 start release
                GsaBool6 start = new GsaBool6();
                if (DA.GetData(6, ref start))
                {
                    mem.ReleaseStart = start;
                }

                // 7 end release
                GsaBool6 end = new GsaBool6();
                if (DA.GetData(7, ref end))
                {
                    mem.ReleaseEnd = end;
                }

                // 8 orientation angle
                GH_Number ghangle = new GH_Number();
                if (DA.GetData(8, ref ghangle))
                {
                    if (GH_Convert.ToDouble(ghangle, out double angle, GH_Conversion.Both))
                    {
                        mem.Member.OrientationAngle = angle;
                    }
                }

                // 9 orientation node
                GH_Integer ghori = new GH_Integer();
                if (DA.GetData(9, ref ghori))
                {
                    if (GH_Convert.ToInt32(ghori, out int orient, GH_Conversion.Both))
                    {
                        mem.Member.OrientationNode = orient;
                    }
                }

                // 10 mesh size
                GH_Number ghmsz = new GH_Number();
                if (DA.GetData(10, ref ghmsz))
                {
                    if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both))
                    {
                        mem.Member.MeshSize = msz;
                    }
                }

                // 11 mesh with others
                GH_Boolean ghbool = new GH_Boolean();
                if (DA.GetData(11, ref ghbool))
                {
                    if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both))
                    {
                        //mem.member.MeshWithOthers
                    }
                }

                // 12 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(12, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        mem.ID = id;
                    }
                }

                // 13 name
                GH_String ghnm = new GH_String();
                if (DA.GetData(13, ref ghnm))
                {
                    if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both))
                    {
                        mem.Member.Name = name;
                    }
                }

                // 14 Group
                GH_Integer ghgrp = new GH_Integer();
                if (DA.GetData(14, ref ghgrp))
                {
                    if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both))
                    {
                        mem.Member.Group = grp;
                    }
                }

                // 15 Colour
                GH_Colour ghcol = new GH_Colour();
                if (DA.GetData(15, ref ghcol))
                {
                    if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                    {
                        mem.Member.Colour = col;
                    }
                }

                // 16 Dummy
                GH_Boolean ghdum = new GH_Boolean();
                if (DA.GetData(16, ref ghdum))
                {
                    if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both))
                    {
                        mem.Member.IsDummy = dum;
                    }
                }

                // #### outputs ####
                DA.SetData(0, new GsaMember1dGoo(mem));
                DA.SetData(1, mem.PolyCurve);
                DA.SetData(2, mem.Section);

                DA.SetData(3, mem.Member.Type);

                DA.SetData(4, mem.Member.Type1D);

                GsaOffset gsaOffset = new GsaOffset
                {
                    X1 = mem.Member.Offset.X1,
                    X2 = mem.Member.Offset.X2,
                    Y  = mem.Member.Offset.Y,
                    Z  = mem.Member.Offset.Z
                };
                DA.SetData(5, gsaOffset);

                DA.SetData(6, mem.ReleaseStart);
                DA.SetData(7, mem.ReleaseEnd);

                DA.SetData(8, mem.Member.OrientationAngle);
                DA.SetData(9, mem.Member.OrientationNode);

                DA.SetData(10, mem.Member.MeshSize);
                //DA.SetData(11, mem.member.MeshSize); //mesh with others bool

                DA.SetData(12, mem.ID);
                DA.SetData(13, mem.Member.Name);
                DA.SetData(14, mem.Member.Group);
                DA.SetData(15, mem.Member.Colour);

                DA.SetData(16, mem.Member.IsDummy);
            }
        }
예제 #15
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Brep ghbrep = new GH_Brep();

            if (DA.GetData(0, ref ghbrep))
            {
                if (ghbrep == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Brep input is null");
                }
                Brep brep = new Brep();
                if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both))
                {
                    // 1 Points
                    List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>();
                    List <Point3d>          pts      = new List <Point3d>();
                    List <GsaNode>          nodes    = new List <GsaNode>();
                    if (DA.GetDataList(1, gh_types))
                    {
                        for (int i = 0; i < gh_types.Count; i++)
                        {
                            Point3d pt = new Point3d();
                            if (gh_types[i].Value is GsaNodeGoo)
                            {
                                GsaNode gsanode = new GsaNode();
                                gh_types[i].CastTo(ref gsanode);
                                nodes.Add(gsanode);
                            }
                            else if (GH_Convert.ToPoint3d(gh_types[i].Value, ref pt, GH_Conversion.Both))
                            {
                                pts.Add(pt);
                            }
                            else
                            {
                                string type = gh_types[i].Value.GetType().ToString();
                                type = type.Replace("GhSA.Parameters.", "");
                                type = type.Replace("Goo", "");
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Point/Node input parameter of type " +
                                                  type + " to point or node");
                            }
                        }
                    }

                    // 2 Curves
                    gh_types = new List <GH_ObjectWrapper>();
                    List <Curve>       crvs   = new List <Curve>();
                    List <GsaMember1d> mem1ds = new List <GsaMember1d>();
                    if (DA.GetDataList(2, gh_types))
                    {
                        for (int i = 0; i < gh_types.Count; i++)
                        {
                            Curve crv = null;
                            if (gh_types[i].Value is GsaMember1dGoo)
                            {
                                GsaMember1d gsamem1d = new GsaMember1d();
                                gh_types[i].CastTo(ref gsamem1d);
                                mem1ds.Add(gsamem1d);
                            }
                            else if (GH_Convert.ToCurve(gh_types[i].Value, ref crv, GH_Conversion.Both))
                            {
                                crvs.Add(crv);
                            }
                            else
                            {
                                string type = gh_types[i].Value.GetType().ToString();
                                type = type.Replace("GhSA.Parameters.", "");
                                type = type.Replace("Goo", "");
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Curve/Mem1D input parameter of type " +
                                                  type + " to curve or 1D Member");
                            }
                        }
                    }

                    // 4 mesh size
                    GH_Number ghmsz    = new GH_Number();
                    double    meshSize = 0;
                    if (DA.GetData(4, ref ghmsz))
                    {
                        GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both);
                        meshSize = m_size;
                    }

                    // build new element2d with brep, crv and pts
                    GsaElement2d elem2d = new GsaElement2d(brep, crvs, pts, meshSize, mem1ds, nodes);

                    // 3 section
                    GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                    GsaProp2d        prop2d = new GsaProp2d();
                    if (DA.GetData(3, ref gh_typ))
                    {
                        if (gh_typ.Value is GsaProp2dGoo)
                        {
                            gh_typ.CastTo(ref prop2d);
                        }
                        else
                        {
                            if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                prop2d.ID = idd;
                            }
                            else
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer");
                                return;
                            }
                        }
                    }
                    else
                    {
                        prop2d.ID = 1;
                    }
                    List <GsaProp2d> prop2Ds = new List <GsaProp2d>();
                    for (int i = 0; i < elem2d.Elements.Count; i++)
                    {
                        prop2Ds.Add(prop2d);
                    }
                    elem2d.Properties = prop2Ds;

                    DA.SetData(0, new GsaElement2dGoo(elem2d));
                }
예제 #16
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)
        {
            // First, we need to retrieve all data from the input parameters.
            List <string>           fields            = new List <string>();
            GH_Structure <IGH_Goo>  attributes        = new GH_Structure <IGH_Goo>();
            GH_Structure <GH_Curve> inputPolylineTree = new GH_Structure <GH_Curve>();

            bool   writeFile = false;
            string filePath  = "";
            string prj       = null;

            // access the input parameter by index.
            if (!DA.GetData(5, ref writeFile))
            {
                return;
            }
            if (!DA.GetData(4, ref filePath))
            {
                return;
            }
            if (!DA.GetDataTree(0, out inputPolylineTree))
            {
                return;
            }
            if (!DA.GetDataList(1, fields))
            {
                return;
            }
            if (!DA.GetDataTree(2, out attributes))
            {
                return;
            }
            if (!DA.GetData(3, ref prj))
            {
                return;
            }


            //create new feature set to add data to
            //FeatureSet fs = new FeatureSet(FeatureType.Polygon);
            //FeatureSet fs = new FeatureSet(FeatureType.Point);
            //FeatureSet fs = new FeatureSet(FeatureType.MultiPoint);
            FeatureSet fs = new FeatureSet(FeatureType.Line);

            if (prj != null)
            {
                //load projection file
                string cur_proj = System.IO.File.ReadAllText(@prj);

                ///create Projection system
                ProjectionInfo targetProjection = new ProjectionInfo();
                targetProjection.ParseEsriString(cur_proj);
                fs.Projection = targetProjection;
            }



            if (writeFile)
            {
                // Add fields to the feature sets attribute table
                foreach (string field in fields)
                {
                    //check for type
                    string[] splitField = field.Split(';');
                    //if field type provided, specify it
                    if (splitField.Length == 2)
                    {
                        fs.DataTable.Columns.Add(new DataColumn(splitField[0], Type.GetType(splitField[1])));
                    }
                    else
                    {
                        //otherwise jsut use a string
                        fs.DataTable.Columns.Add(new DataColumn(field, typeof(string)));
                    }
                }


                // for every branch  (ie feature)
                foreach (GH_Path path in inputPolylineTree.Paths)
                {
                    //set branch
                    IList branch = inputPolylineTree.get_Branch(path);
                    List <DotSpatial.Topology.LineString> theseLines = new List <DotSpatial.Topology.LineString>();

                    foreach (GH_Curve curve in branch)
                    {
                        // create vertex list for this curve
                        List <Coordinate> vertices = new List <Coordinate>();

                        //convert to rhino curve
                        Curve rhinoCurve = null;
                        GH_Convert.ToCurve(curve, ref rhinoCurve, 0);
                        //curve to nurbes
                        NurbsCurve thisNurbsCurve = rhinoCurve.ToNurbsCurve();
                        //Get list of control points
                        Rhino.Geometry.Collections.NurbsCurvePointList theseControlPoints = thisNurbsCurve.Points;
                        //for each control point
                        foreach (ControlPoint thisPoint in theseControlPoints)
                        {
                            vertices.Add(new Coordinate(thisPoint.Location.X, thisPoint.Location.Y));
                        }//end each control point

                        //create lineString Geometry from coordinates
                        DotSpatial.Topology.LineString thisLine = new DotSpatial.Topology.LineString(vertices);
                        // add linestring to linestring list
                        theseLines.Add(thisLine);
                    }//end curve itteration

                    //Convert Coordinates to dot spatial point or multipoint geometry
                    //DotSpatial.Topology.Point geom = new DotSpatial.Topology.Point(vertices);
                    //DotSpatial.Topology.MultiPoint geom = new DotSpatial.Topology.MultiPoint(vertices);

                    //convert list of line strings into single multilinestring feature
                    MultiLineString geom = new MultiLineString(theseLines);

                    //convert geom to a feature
                    IFeature feature = fs.AddFeature(geom);

                    //begin editing to add feature attributes
                    feature.DataRow.BeginEdit();
                    //get this features attributes by its path
                    IList <string> featrueAttributes = attributes.get_Branch(path) as IList <string>;
                    int            thisIndex         = 0;
                    //add each attribute for the pt's path
                    foreach (var thisAttribute in attributes.get_Branch(path))
                    {
                        string thisField = fields[thisIndex].Split(';')[0];
                        feature.DataRow[thisField] = thisAttribute.ToString(); //currently everything is a string....
                        thisIndex++;
                    }

                    //finish attribute additions
                    feature.DataRow.EndEdit();
                }//end of itterating through branches of pt tree
                fs.SaveAs(filePath, true);
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaGridLineLoad gridlineload = new GsaGridLineLoad();

            // 0 Load case
            int        lc    = 1;
            GH_Integer gh_lc = new GH_Integer();

            if (DA.GetData(0, ref gh_lc))
            {
                GH_Convert.ToInt32(gh_lc, out lc, GH_Conversion.Both);
            }
            gridlineload.GridLineLoad.Case = lc;

            // Do plane input first as to see if we need to project polyline onto grid plane
            // 2 Plane
            Plane pln      = Plane.WorldXY;
            bool  planeSet = false;
            GsaGridPlaneSurface grdplnsrf = new GsaGridPlaneSurface();
            GH_ObjectWrapper    gh_typ    = new GH_ObjectWrapper();

            if (DA.GetData(2, ref gh_typ))
            {
                if (gh_typ.Value is GsaGridPlaneSurfaceGoo)
                {
                    GsaGridPlaneSurface temppln = new GsaGridPlaneSurface();
                    gh_typ.CastTo(ref temppln);
                    grdplnsrf = temppln.Duplicate();
                    pln       = grdplnsrf.Plane;
                    planeSet  = true;
                }
                else if (gh_typ.Value is Plane)
                {
                    gh_typ.CastTo(ref pln);
                    grdplnsrf = new GsaGridPlaneSurface(pln);
                    planeSet  = true;
                }
                else
                {
                    int id = 0;
                    if (GH_Convert.ToInt32(gh_typ.Value, out id, GH_Conversion.Both))
                    {
                        gridlineload.GridLineLoad.GridSurface = id;
                        gridlineload.GridPlaneSurface         = null;
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in GPS input. Accepted inputs are Grid Plane Surface or Plane. " +
                                          System.Environment.NewLine + "If no input here then the line's best-fit plane will be used");
                        return;
                    }
                }
            }

            // we wait setting the gridplanesurface until we have run the polyline input

            // 1 Polyline
            Polyline ln     = new Polyline();
            GH_Curve gh_crv = new GH_Curve();

            if (DA.GetData(1, ref gh_crv))
            {
                Curve crv = null;
                GH_Convert.ToCurve(gh_crv, ref crv, GH_Conversion.Both);

                //convert to polyline
                if (crv.TryGetPolyline(out ln))
                {
                    // get control points
                    List <Point3d> ctrl_pts = ln.ToList();

                    // plane
                    if (!planeSet)
                    {
                        // create best-fit plane from pts
                        pln = Util.GH.Convert.CreateBestFitUnitisedPlaneFromPts(ctrl_pts);

                        // create grid plane surface from best fit plane
                        grdplnsrf = new GsaGridPlaneSurface(pln, true);
                    }
                    else
                    {
                        // project original curve onto grid plane
                        crv = Curve.ProjectToPlane(crv, pln);

                        // convert to polyline again
                        crv.TryGetPolyline(out ln);

                        //get control points again
                        ctrl_pts = ln.ToList();
                    }

                    // string to write polyline description to
                    string desc = "";

                    // loop through all points
                    for (int i = 0; i < ctrl_pts.Count; i++)
                    {
                        if (i > 0)
                        {
                            desc += " ";
                        }

                        // get control points in local plane coordinates
                        Point3d temppt = new Point3d();
                        pln.RemapToPlaneSpace(ctrl_pts[i], out temppt);

                        // write point to string
                        // format accepted by GSA: (0,0) (0,1) (1,2) (3,4) (4,0)(m)
                        desc += "(" + temppt.X + "," + temppt.Y + ")";
                    }
                    // add units to the end
                    desc += "(" + Units.LengthLarge + ")";

                    // set polyline in grid line load
                    gridlineload.GridLineLoad.Type = GridLineLoad.PolyLineType.EXPLICIT_POLYLINE;
                    gridlineload.GridLineLoad.PolyLineDefinition = desc;
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not convert Curve to Polyline");
                }
            }

            // now we can set the gridplanesurface:
            if (gridlineload.GridPlaneSurface != null)
            {
                if (gridlineload.GridPlaneSurface.GridSurfaceID == 0)
                {
                    gridlineload.GridPlaneSurface = grdplnsrf;
                }
            }

            // 3 direction
            string    dir   = "Z";
            Direction direc = Direction.Z;

            GH_String gh_dir = new GH_String();

            if (DA.GetData(3, ref gh_dir))
            {
                GH_Convert.ToString(gh_dir, out dir, GH_Conversion.Both);
            }
            dir = dir.ToUpper();
            if (dir == "X")
            {
                direc = Direction.X;
            }
            if (dir == "Y")
            {
                direc = Direction.Y;
            }

            gridlineload.GridLineLoad.Direction = direc;

            // 4 Axis
            int axis = 0;

            gridlineload.GridLineLoad.AxisProperty = 0;
            GH_Integer gh_ax = new GH_Integer();

            if (DA.GetData(4, ref gh_ax))
            {
                GH_Convert.ToInt32(gh_ax, out axis, GH_Conversion.Both);
                if (axis == 0 || axis == -1)
                {
                    gridlineload.GridLineLoad.AxisProperty = axis;
                }
            }

            // 5 Projected
            bool       proj    = false;
            GH_Boolean gh_proj = new GH_Boolean();

            if (DA.GetData(5, ref gh_proj))
            {
                if (GH_Convert.ToBoolean(gh_proj, out proj, GH_Conversion.Both))
                {
                    gridlineload.GridLineLoad.IsProjected = proj;
                }
            }

            // 6 Name
            string    name    = "";
            GH_String gh_name = new GH_String();

            if (DA.GetData(6, ref gh_name))
            {
                if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both))
                {
                    gridlineload.GridLineLoad.Name = name;
                }
            }

            // 7 load value
            double load1 = 0;

            if (DA.GetData(7, ref load1))
            {
                load1 *= -1000; //convert to kN
            }
            gridlineload.GridLineLoad.ValueAtStart = load1;

            // 8 load value
            double load2 = load1;

            if (DA.GetData(8, ref load2))
            {
                load2 *= -1000; //convert to kN
            }
            gridlineload.GridLineLoad.ValueAtEnd = load2;

            // convert to goo
            GsaLoad gsaLoad = new GsaLoad(gridlineload);

            DA.SetData(0, new GsaLoadGoo(gsaLoad));
        }
예제 #18
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaMember1d gsaMember1d = new GsaMember1d();

            if (DA.GetData(0, ref gsaMember1d))
            {
                if (gsaMember1d == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member1D input is null");
                }
                GsaMember1d mem = gsaMember1d.Duplicate();

                // #### inputs ####
                // 1 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(1, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        mem.ID = id;
                    }
                }

                // 2 curve
                GH_Curve ghcrv = new GH_Curve();
                if (DA.GetData(2, ref ghcrv))
                {
                    Curve crv = null;
                    if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both))
                    {
                        GsaMember1d tempmem = new GsaMember1d(crv);
                        mem.PolyCurve    = tempmem.PolyCurve;
                        mem.Topology     = tempmem.Topology;
                        mem.TopologyType = tempmem.TopologyType;
                    }
                }

                // 3 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                if (DA.GetData(3, ref gh_typ))
                {
                    GsaSection section = new GsaSection();
                    if (gh_typ.Value is GsaSectionGoo)
                    {
                        gh_typ.CastTo(ref section);
                        mem.Section         = section;
                        mem.Member.Property = 0;
                    }
                    else
                    {
                        if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            mem.Member.Property = idd;
                            mem.Section         = null;
                        }
                        else
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer");
                            return;
                        }
                    }
                }
예제 #19
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Brep ghbrep = new GH_Brep();

            if (DA.GetData(0, ref ghbrep))
            {
                if (ghbrep == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Brep input is null");
                }
                Brep brep = new Brep();
                if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both))
                {
                    // 1 Points
                    List <Point3d>  pts   = new List <Point3d>();
                    List <GH_Point> ghpts = new List <GH_Point>();
                    if (DA.GetDataList(1, ghpts))
                    {
                        for (int i = 0; i < ghpts.Count; i++)
                        {
                            Point3d pt = new Point3d();
                            if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both))
                            {
                                pts.Add(pt);
                            }
                        }
                    }

                    // 2 Curves
                    List <Curve>    crvs   = new List <Curve>();
                    List <GH_Curve> ghcrvs = new List <GH_Curve>();
                    if (DA.GetDataList(2, ghcrvs))
                    {
                        for (int i = 0; i < ghcrvs.Count; i++)
                        {
                            Curve crv = null;
                            if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both))
                            {
                                crvs.Add(crv);
                            }
                        }
                    }

                    // build new member with brep, crv and pts
                    GsaMember2d mem = new GsaMember2d(brep, crvs, pts);

                    // 3 section
                    GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                    GsaProp2d        prop2d = new GsaProp2d();
                    if (DA.GetData(3, ref gh_typ))
                    {
                        if (gh_typ.Value is GsaProp2dGoo)
                        {
                            gh_typ.CastTo(ref prop2d);
                            mem.Property = prop2d;
                        }
                        else
                        {
                            if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                mem.Member.Property = idd;
                            }
                            else
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer");
                                return;
                            }
                        }
                    }

                    // 4 mesh size
                    GH_Number ghmsz = new GH_Number();
                    if (DA.GetData(4, ref ghmsz))
                    {
                        GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both);
                        mem.Member.MeshSize = m_size;
                    }

                    DA.SetData(0, new GsaMember2dGoo(mem));
                }
예제 #20
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // First, we need to retrieve all data from the input parameters.
            List <string>           fields         = new List <string>();
            GH_Structure <IGH_Goo>  attributes     = new GH_Structure <IGH_Goo>();
            GH_Structure <GH_Curve> inputCurveTree = new GH_Structure <GH_Curve>();

            bool   writeFile = false;
            string filePath  = "";
            int    epsg      = -1;

            if (!DA.GetData(5, ref writeFile))
            {
                return;
            }
            if (!DA.GetData(4, ref filePath))
            {
                return;
            }
            // access the input parameter by index.
            if (!DA.GetDataTree(0, out inputCurveTree))
            {
                return;
            }
            if (!DA.GetDataList(1, fields))
            {
                return;
            }
            if (!DA.GetDataTree(2, out attributes))
            {
                return;
            }
            if (!DA.GetData(3, ref epsg))
            {
                return;
            }
            // We should now validate the data and warn the user if invalid data is supplied.
            //if (radius0 < 0.0){
            //    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Inner radius must be bigger than or equal to zero");
            //    return;}

            //Create geojson dic
            Dictionary <string, Object> geoDict = new Dictionary <string, Object>();

            // We're set to create the geojson now. To keep the size of the SolveInstance() method small,
            // The actual functionality will be in a different method:
            //Curve spiral = CreateSpiral(plane, radius0, radius1, turns);


            //Basic esriJSON headder info
            geoDict.Add("displayFieldName", " ");

            Dictionary <string, string> fieldAliasDic = new Dictionary <string, string>();

            foreach (string field in fields)
            {
                fieldAliasDic.Add(field, field);
            }
            geoDict.Add("fieldAliases", fieldAliasDic);

            geoDict.Add("geometryType", "esriGeometryPolyline");
            Dictionary <string, int> sr = new Dictionary <string, int>()
            {
                { "wkid", 102729 }, { "latestWkid", 2272 }
            };

            geoDict.Add("spatialReference", sr);

            // package the below in a function
            List <Dictionary <string, string> > fieldsList = new List <Dictionary <string, string> >();

            foreach (var item in fields.Select((Value, Index) => new { Value, Index }))
            {
                Dictionary <string, string> fieldTypeDict = new Dictionary <string, string>();


                fieldTypeDict.Add("name", item.Value.ToString());

                var typeItem = attributes.get_Branch(attributes.Paths[0])[item.Index];

                if (typeItem is Grasshopper.Kernel.Types.GH_Integer)
                {
                    fieldTypeDict.Add("type", "esriFieldTypeInteger");
                }

                else if (typeItem is Grasshopper.Kernel.Types.GH_Number) // else if (typeItem is long //|| typeItem is ulong //|| typeItem is float //|| typeItem is double //|| typeItem is decimal)
                {
                    fieldTypeDict.Add("type", "esriFieldTypeDouble");
                }

                else if (typeItem is Grasshopper.Kernel.Types.GH_String)
                {
                    fieldTypeDict.Add("type", "esriFieldTypeString");
                }

                else if (typeItem is Grasshopper.Kernel.Types.GH_Time)
                {
                    fieldTypeDict.Add("type", "esriFieldTypeDate");
                }

                else
                {
                    fieldTypeDict.Add("type", "esriFieldTypeString");
                    fieldTypeDict.Add("GH_Type", typeItem.GetType().ToString());
                }
                if (item.Value.ToString().Length > 7)
                {
                    fieldTypeDict.Add("alias", item.Value.ToString().Substring(0, 7));
                }
                else
                {
                    fieldTypeDict.Add("alias", item.Value.ToString());
                }

                fieldsList.Add(fieldTypeDict);
            }//end for each fields
            geoDict.Add("fields", fieldsList);

            // package the above in a function ^^^


            //features: [
            //    {
            //        geometry:{Paths:[ [-[x,y],[x1,y1]-], [-[x,y],[x1,y1]-]  ]
            //        attributes:{ field:value, field1:value1}
            //    },
            //    {
            //        geometry:{Paths:[ [-[x,y],[x1,y1]-], [-[x,y],[x1,y1]-]  ]
            //        attributes:{ field:value, field1:value1}
            //    }
            //]

            // Start of  feature construction----------------------------------------------------
            // create feature list
            List <Object> featuresList = new List <Object>();

            // for every branch  (ie feature)
            foreach (GH_Path path in inputCurveTree.Paths)
            {
                //set branch
                IList branch = inputCurveTree.get_Branch(path);

                //create geometry key
                Dictionary <string, object> thisGeometry = new Dictionary <string, object>();
                List <object> thisPaths = new List <object>();
                // for every curve  in branch
                foreach (GH_Curve thisGhCurve in branch)
                {
                    List <List <double> > thisPath = new List <List <double> >();

                    //convert to rhino curve
                    Curve rhinoCurve = null;
                    GH_Convert.ToCurve(thisGhCurve, ref rhinoCurve, 0);
                    //curve to nurbes
                    NurbsCurve thisNurbsCurve = rhinoCurve.ToNurbsCurve();
                    //Get list of control points
                    Rhino.Geometry.Collections.NurbsCurvePointList theseControlPoints = thisNurbsCurve.Points;
                    //for each control point
                    foreach (ControlPoint thisPoint in theseControlPoints)
                    {
                        //create coordinate list and add to path list
                        List <double> thisCoordinate = new List <double>();
                        thisCoordinate.Add(thisPoint.Location.X);
                        thisCoordinate.Add(thisPoint.Location.Y);
                        thisPath.Add(thisCoordinate);
                    }//end each control point

                    //add this path or paths
                    thisPaths.Add(thisPath);
                }//end of each curve in branch
                //add all paths to geometry key for this feature
                thisGeometry.Add("Paths", thisPaths);

                //creat attriabtrues key
                Dictionary <string, object> thisAttribtues = new Dictionary <string, object>();
                IList attributesBranch = attributes.get_Branch(path);

                //foreach (var item in attributesBranch.Select((Value, Index) => new { Value, Index })) //this needs list not IList
                foreach (var item in attributesBranch)
                //for (int i = 0; i < attributesBranch.Count; i++)
                {
                    string thisField = fields[attributesBranch.IndexOf(item)]; //fields are string

                    // ---------------------this is in order add the riight type?

                    if (item is Grasshopper.Kernel.Types.GH_Integer)
                    {
                        string thisAttribute = item.ToString();
                        Convert.ChangeType(thisAttribute, typeof(int));
                        thisAttribtues.Add(thisField, thisAttribute);
                    }

                    else if (item is Grasshopper.Kernel.Types.GH_Number) // else if (typeItem is long //|| typeItem is ulong //|| typeItem is float //|| typeItem is double //|| typeItem is decimal)
                    {
                        string thisAttribute = item.ToString();
                        Convert.ChangeType(thisAttribute, typeof(double));
                        thisAttribtues.Add(thisField, thisAttribute);
                    }

                    else if (item is Grasshopper.Kernel.Types.GH_String)
                    {
                        string thisAttribute = item.ToString();
                        thisAttribtues.Add(thisField, thisAttribute);
                    }

                    else if (item is Grasshopper.Kernel.Types.GH_Time)
                    {
                        string thisAttribute = item.ToString();
                        Convert.ChangeType(thisAttribute, typeof(DateTime));
                        thisAttribtues.Add(thisField, thisAttribute);
                    }

                    else
                    {
                        string thisAttribute = "wasent a type"; item.ToString();
                        thisAttribtues.Add(thisField, thisAttribute);
                    }

                    // ------------------------how to add value of igh_goo verbatum....
                    //thisAttribtues.Add(thisField, thisAttribute);
                }


                //wrap up into feature and add to feature list;
                Dictionary <string, Object> thisFeature = new Dictionary <string, Object>();

                thisFeature.Add("geometry", thisGeometry);
                thisFeature.Add("attributes", thisAttribtues);
                featuresList.Add(thisFeature);
            }//end of each branch path

            // end of  feature construction

            // finaly add features list to master object
            geoDict.Add("features", featuresList);


            //Produces convert dictionary to json text

            var json = Newtonsoft.Json.JsonConvert.SerializeObject(geoDict, Newtonsoft.Json.Formatting.Indented);

            // Finally assign the retults to the output parameter.
            //DA.SetData(0, spiral);

            //write string to file
            if (writeFile == true)
            {
                //@"D:\path.txt"
                System.IO.File.WriteAllText(@filePath, json);
            }
            DA.SetData(0, json);
        }
예제 #21
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Brep ghbrep = new GH_Brep();

            if (DA.GetData(0, ref ghbrep))
            {
                Brep brep = new Brep();
                if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both))
                {
                    // first import points and curves for inclusion before building member

                    // 2 Points
                    List <Point3d>  pts   = new List <Point3d>();
                    List <GH_Point> ghpts = new List <GH_Point>();
                    if (DA.GetDataList(2, ghpts))
                    {
                        for (int i = 0; i < ghpts.Count; i++)
                        {
                            Point3d pt = new Point3d();
                            if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both))
                            {
                                pts.Add(pt);
                            }
                        }
                    }

                    // 3 Curves
                    List <Curve>    crvs   = new List <Curve>();
                    List <GH_Curve> ghcrvs = new List <GH_Curve>();
                    if (DA.GetDataList(3, ghcrvs))
                    {
                        for (int i = 0; i < ghcrvs.Count; i++)
                        {
                            Curve crv = null;
                            if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both))
                            {
                                crvs.Add(crv);
                            }
                        }
                    }

                    // now build new member with brep, crv and pts
                    GsaMember2d mem = new GsaMember2d(brep, crvs, pts);

                    // add the rest
                    // 1 section
                    GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                    GsaProp2d        prop2d = new GsaProp2d();
                    if (DA.GetData(1, ref gh_typ))
                    {
                        if (gh_typ.Value is GsaProp2d)
                        {
                            gh_typ.CastTo(ref prop2d);
                        }
                        else if (gh_typ.Value is GH_Number)
                        {
                            if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                            {
                                prop2d.ID = idd;
                            }
                        }
                    }
                    else
                    {
                        prop2d.ID = 1;
                    }
                    mem.Property = prop2d;

                    // 4 mesh size
                    GH_Number ghmsz = new GH_Number();
                    if (DA.GetData(4, ref ghmsz))
                    {
                        GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both);
                        mem.Member.MeshSize = m_size;
                    }

                    DA.SetData(0, new GsaMember2dGoo(mem));
                }
            }
        }