Пример #1
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;

            List<Brep> things = new List<Brep>();
            if (!DA.GetDataList(1, things)) return;
            // import Silkworm Movement

            SilkwormUtility sUtil = new SilkwormUtility();
            Dictionary<string, string> Settings = sUtil.convertSettings(silkwormSettings);
            SilkwormCalculator calc = new SilkwormCalculator(Settings);

            #region Optional Inputs

            int infType = 0;
            if (!DA.GetData(2, ref infType)) { }

            List<double> spacing = new List<double>();
            if (!DA.GetDataList(3, spacing)) { }

            List<double> infDens = new List<double>();
            if (!DA.GetDataList(4, infDens)) { }
            List<double> infRot = new List<double>();
            if (!DA.GetDataList(5, infRot)) { }

            #endregion

            if (spacing.Count<1)
            {
                spacing.Add(0.66);
                //TODO Calculator

            }
            if (infDens.Count < 1)
            {
                infDens.Add(double.Parse(Settings["fill_density"]));

            }
            if (infRot.Count < 1)
            {
                infRot.Add(double.Parse(Settings["fill_angle"]));

            }
            #endregion

            SilkwormSkein skein = new SilkwormSkein(Settings, things);

            //Switch depending on which infill type is selected by input
            if (infType == 0)
            {
                //Match length of data
                if (spacing.Count != things.Count)
                {
                    List<double> newspacing = new List<double>();
                    for (int e = 0; e < things.Count; e++)
                    {
                        newspacing.Add(spacing[0]);
                    }
                    spacing = newspacing;
                }

                skein.Skinner(spacing);
            }
            if (infType == 1)
            {
                //Match length of data
                if (infDens.Count != things.Count)
                {
                    List<double> newinfDens = new List<double>();
                    for (int e = 0; e < things.Count; e++)
                    {
                        newinfDens.Add(infDens[0]);
                    }
                    spacing = newinfDens;
                }
                if (infRot.Count != things.Count)
                {
                    List<double> newinfRot = new List<double>();
                    for (int e = 0; e < things.Count; e++)
                    {
                        newinfRot.Add(infRot[0]);
                    }
                    spacing = newinfRot;
                }

                skein.Filler(infDens, infRot);
            }

            //Reflect Errors and Warnings

            foreach (string message in skein.ErrorMessages)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message);

            }
            foreach (string message in skein.WarningMessages)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, message);

            }

            //Output Holders
            List<Curve>[] plPerimeter = skein.curvePerimeter;
            List<Curve>[] plInfill = skein.curveInfill;

            GH_Structure<GH_Curve> InfillRegion = new GH_Structure<GH_Curve>();

            //Create GH_Structure
            #region Create Structure from Curves

            if (plPerimeter.Length > 0)
            {
                for (int i = 0; i < plPerimeter.Length; i++)
                {
                  if (plPerimeter[i] != null)
                        {
                    for (int j = 0; j < plPerimeter[i].Count; j++)
                    {

                            Curve aShape = plPerimeter[i][j].ToNurbsCurve();

                            GH_Curve gShapes = new GH_Curve(aShape);
                            InfillRegion.Insert(gShapes, new GH_Path(i, 0), j);
                            //}
                        }
                    }
                }
            }
            if (plInfill.Length > 0)
            {
                for (int i = 0; i < plInfill.Length; i++)
                {
            if (plInfill[i] != null)
                        {
                    for (int j = 0; j < plInfill[i].Count; j++)
                    {

                            Curve aShape = plInfill[i][j].ToNurbsCurve();

                            GH_Curve gShapes = new GH_Curve(aShape);
                            InfillRegion.Insert(gShapes, new GH_Path(i, 1), j);
                        }
                    }
                }
            }

            #endregion

            //Output
            if (!DA.SetDataTree(0, InfillRegion)) { return; }
        }
Пример #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            #region INPUTS
            // import silkwormSettings file
            List <string> silkwormSettings = new List <string>();
            if (!DA.GetDataList(0, silkwormSettings))
            {
                return;
            }

            List <Brep> things = new List <Brep>();
            if (!DA.GetDataList(1, things))
            {
                return;
            }
            // import Silkworm Movement


            SilkwormUtility             sUtil    = new SilkwormUtility();
            Dictionary <string, string> Settings = sUtil.convertSettings(silkwormSettings);
            SilkwormCalculator          calc     = new SilkwormCalculator(Settings);

            #region Optional Inputs

            int infType = 0;
            if (!DA.GetData(2, ref infType))
            {
            }

            List <double> spacing = new List <double>();
            if (!DA.GetDataList(3, spacing))
            {
            }

            List <double> infDens = new List <double>();
            if (!DA.GetDataList(4, infDens))
            {
            }
            List <double> infRot = new List <double>();
            if (!DA.GetDataList(5, infRot))
            {
            }

            #endregion

            if (spacing.Count < 1)
            {
                spacing.Add(0.66);
                //TODO Calculator
            }
            if (infDens.Count < 1)
            {
                infDens.Add(double.Parse(Settings["fill_density"]));
            }
            if (infRot.Count < 1)
            {
                infRot.Add(double.Parse(Settings["fill_angle"]));
            }
            #endregion

            SilkwormSkein skein = new SilkwormSkein(Settings, things);

            //Switch depending on which infill type is selected by input
            if (infType == 0)
            {
                //Match length of data
                if (spacing.Count != things.Count)
                {
                    List <double> newspacing = new List <double>();
                    for (int e = 0; e < things.Count; e++)
                    {
                        newspacing.Add(spacing[0]);
                    }
                    spacing = newspacing;
                }

                skein.Skinner(spacing);
            }
            if (infType == 1)
            {
                //Match length of data
                if (infDens.Count != things.Count)
                {
                    List <double> newinfDens = new List <double>();
                    for (int e = 0; e < things.Count; e++)
                    {
                        newinfDens.Add(infDens[0]);
                    }
                    spacing = newinfDens;
                }
                if (infRot.Count != things.Count)
                {
                    List <double> newinfRot = new List <double>();
                    for (int e = 0; e < things.Count; e++)
                    {
                        newinfRot.Add(infRot[0]);
                    }
                    spacing = newinfRot;
                }


                skein.Filler(infDens, infRot);
            }

            //Reflect Errors and Warnings

            foreach (string message in skein.ErrorMessages)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message);
            }
            foreach (string message in skein.WarningMessages)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, message);
            }

            //Output Holders
            List <Curve>[] plPerimeter = skein.curvePerimeter;
            List <Curve>[] plInfill    = skein.curveInfill;



            GH_Structure <GH_Curve> InfillRegion = new GH_Structure <GH_Curve>();

            //Create GH_Structure
            #region Create Structure from Curves

            if (plPerimeter.Length > 0)
            {
                for (int i = 0; i < plPerimeter.Length; i++)
                {
                    if (plPerimeter[i] != null)
                    {
                        for (int j = 0; j < plPerimeter[i].Count; j++)
                        {
                            Curve aShape = plPerimeter[i][j].ToNurbsCurve();


                            GH_Curve gShapes = new GH_Curve(aShape);
                            InfillRegion.Insert(gShapes, new GH_Path(i, 0), j);
                            //}
                        }
                    }
                }
            }
            if (plInfill.Length > 0)
            {
                for (int i = 0; i < plInfill.Length; i++)
                {
                    if (plInfill[i] != null)
                    {
                        for (int j = 0; j < plInfill[i].Count; j++)
                        {
                            Curve aShape = plInfill[i][j].ToNurbsCurve();

                            GH_Curve gShapes = new GH_Curve(aShape);
                            InfillRegion.Insert(gShapes, new GH_Path(i, 1), j);
                        }
                    }
                }
            }

            #endregion

            //Output
            if (!DA.SetDataTree(0, InfillRegion))
            {
                return;
            }
        }
Пример #3
0
        public List<SilkwormMovement> addsolidBrep(Dictionary<string, string> Settings, List<Brep> solids)
        {
            List<SilkwormMovement> unMovements = new List<SilkwormMovement>();

            //List<Brep> solidS = new List<Brep>();
            //solidS.Add((Brep)solid);
            int shell = int.Parse(Settings["perimeters"]);
            int verticalshell = int.Parse(Settings["solid_layers"]);
            double filldensity = double.Parse(Settings["fill_density"]);
            double fillangle = (double.Parse(Settings["fill_density"])/0.0174532925);
            double layerheight = double.Parse(Settings["layer_height"]);
            List<Plane> sliceplanes = new List<Plane>();
            sliceplanes.Add(Plane.WorldXY);

            List<Polyline> pInfill = new List<Polyline>();

            //Slice, Skin and Fill Breps
            SilkwormSkein solidskein = new SilkwormSkein(Settings, solids, sliceplanes, shell, layerheight);
            solidskein.BrepSlice(false);

            if (solidskein.validPos)
            {
                List<Curve> cInfill = new List<Curve>();

                //Use imported settings for shelling and infilling

                List<double>[] spacing = new List<double>[solidskein.slicePlanes.Count];
                for (int c = 0; c < solidskein.slicePlanes.Count; c++)
                {
                    spacing[c] = new List<double>();
                    spacing[c].Add(0.66);
                }
                List<double>[] infDens = new List<double>[solidskein.slicePlanes.Count];
                for (int a = 0; a < solidskein.slicePlanes.Count; a++)
                {
                    if (a < verticalshell)
                    {
                        infDens[a] = new List<double>();
                        infDens[a].Add(1.0);
                    }
                    else if (a >= solidskein.slicePlanes.Count - verticalshell)
                    {
                        infDens[a] = new List<double>();
                        infDens[a].Add(1.0);
                    }
                    else
                    {
                        infDens[a] = new List<double>();
                        infDens[a].Add(filldensity);
                    }
                }

                List<double>[] infRot = new List<double>[solidskein.slicePlanes.Count];
                for (int b = 0; b < solidskein.slicePlanes.Count; b++)
                {
                    if (IsOdd(b))
                    {
                        infRot[b] = new List<double>();
                        infRot[b].Add(fillangle + 90);
                    }
                    else
                    {
                        infRot[b] = new List<double>();
                        infRot[b].Add(fillangle);
                    }
                }

                if (solidskein.openRegions.Length > 0)
                {

                    for (int h = 0; h < solidskein.openRegions.Length; h++)
                    {

                        if (solidskein.openRegions[h] != null)
                        {
                            cInfill.AddRange(solidskein.openRegions[h]);
                        }
                    }
                }

                if (solidskein.Regions.Length > 0)
                {

                    for (int h = 0; h < solidskein.Regions.Length; h++)
                    {

                        if (solidskein.Regions[h] != null)
                        {
                            SilkwormSkein planarskein = new SilkwormSkein(Settings, solidskein.Regions[h]);
                            planarskein.Filler(infDens[h], infRot[h]);

                            for (int i = 0; i < planarskein.curvePerimeter.Length; i++)
                            {
                                cInfill.AddRange(planarskein.curvePerimeter[i]);
                            }
                        }

                    }
                }

                if (solidskein.regionPerimeter.Length > 0)
                {

                    for (int h = 0; h < solidskein.regionPerimeter.Length; h++)
                    {

                        if (solidskein.regionPerimeter[h] != null)
                        {
                            SilkwormSkein planarskein = new SilkwormSkein(Settings, solidskein.regionPerimeter[h]);
                            planarskein.Skinner(spacing[h]);

                            for (int i = 0; i < planarskein.curvePerimeter.Length; i++)
                            {
                                cInfill.AddRange(planarskein.curvePerimeter[i]);
                            }
                        }

                    }
                }

                if (solidskein.regionInfill.Length > 0)
                {

                    for (int h = 0; h < solidskein.regionInfill.Length; h++)
                    {

                        if (solidskein.regionInfill[h] != null)
                        {
                            SilkwormSkein planarskein = new SilkwormSkein(Settings, solidskein.regionInfill[h]);
                            planarskein.Filler(infDens[h], infRot[h]);

                            for (int i = 0; i < planarskein.curveInfill.Length; i++)
                            {
                                cInfill.AddRange(planarskein.curveInfill[i]);
                            }
                        }

                    }
                }

                if (solidskein.regionOverhangs.Length > 0)
                {

                    //TODO
                }

                if (solidskein.regionBridges.Length > 0)
                {

                    //TODO
                }

                //Segment Curves
                foreach (Curve curve in cInfill)
                {
                    SilkwormSegment segment = new SilkwormSegment(curve);
                    pInfill.Add(segment.Pline);
                }

            }

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

            //Add to List of Movements

            foreach (Polyline pline in pInfill)
            {
                //List<SilkwormMovement> sList = new List<SilkwormMovement>();
                //sList.Add(new SilkwormMovement(Settings, pline, true));
                solidMovements.Add(new SilkwormMovement(Settings, pline));
            }

            unMovements.AddRange(solidMovements);

            return unMovements;
        }
Пример #4
0
        public List <SilkwormMovement> addsolidBrep(Dictionary <string, string> Settings, List <Brep> solids)
        {
            List <SilkwormMovement> unMovements = new List <SilkwormMovement>();

            //List<Brep> solidS = new List<Brep>();
            //solidS.Add((Brep)solid);
            int          shell         = int.Parse(Settings["perimeters"]);
            int          verticalshell = int.Parse(Settings["solid_layers"]);
            double       filldensity   = double.Parse(Settings["fill_density"]);
            double       fillangle     = (double.Parse(Settings["fill_density"]) / 0.0174532925);
            double       layerheight   = double.Parse(Settings["layer_height"]);
            List <Plane> sliceplanes   = new List <Plane>();

            sliceplanes.Add(Plane.WorldXY);

            List <Polyline> pInfill = new List <Polyline>();

            //Slice, Skin and Fill Breps
            SilkwormSkein solidskein = new SilkwormSkein(Settings, solids, sliceplanes, shell, layerheight);

            solidskein.BrepSlice(false);

            if (solidskein.validPos)
            {
                List <Curve> cInfill = new List <Curve>();

                //Use imported settings for shelling and infilling


                List <double>[] spacing = new List <double> [solidskein.slicePlanes.Count];
                for (int c = 0; c < solidskein.slicePlanes.Count; c++)
                {
                    spacing[c] = new List <double>();
                    spacing[c].Add(0.66);
                }
                List <double>[] infDens = new List <double> [solidskein.slicePlanes.Count];
                for (int a = 0; a < solidskein.slicePlanes.Count; a++)
                {
                    if (a < verticalshell)
                    {
                        infDens[a] = new List <double>();
                        infDens[a].Add(1.0);
                    }
                    else if (a >= solidskein.slicePlanes.Count - verticalshell)
                    {
                        infDens[a] = new List <double>();
                        infDens[a].Add(1.0);
                    }
                    else
                    {
                        infDens[a] = new List <double>();
                        infDens[a].Add(filldensity);
                    }
                }

                List <double>[] infRot = new List <double> [solidskein.slicePlanes.Count];
                for (int b = 0; b < solidskein.slicePlanes.Count; b++)
                {
                    if (IsOdd(b))
                    {
                        infRot[b] = new List <double>();
                        infRot[b].Add(fillangle + 90);
                    }
                    else
                    {
                        infRot[b] = new List <double>();
                        infRot[b].Add(fillangle);
                    }
                }

                if (solidskein.openRegions.Length > 0)
                {
                    for (int h = 0; h < solidskein.openRegions.Length; h++)
                    {
                        if (solidskein.openRegions[h] != null)
                        {
                            cInfill.AddRange(solidskein.openRegions[h]);
                        }
                    }
                }

                if (solidskein.Regions.Length > 0)
                {
                    for (int h = 0; h < solidskein.Regions.Length; h++)
                    {
                        if (solidskein.Regions[h] != null)
                        {
                            SilkwormSkein planarskein = new SilkwormSkein(Settings, solidskein.Regions[h]);
                            planarskein.Filler(infDens[h], infRot[h]);

                            for (int i = 0; i < planarskein.curvePerimeter.Length; i++)
                            {
                                cInfill.AddRange(planarskein.curvePerimeter[i]);
                            }
                        }
                    }
                }

                if (solidskein.regionPerimeter.Length > 0)
                {
                    for (int h = 0; h < solidskein.regionPerimeter.Length; h++)
                    {
                        if (solidskein.regionPerimeter[h] != null)
                        {
                            SilkwormSkein planarskein = new SilkwormSkein(Settings, solidskein.regionPerimeter[h]);
                            planarskein.Skinner(spacing[h]);

                            for (int i = 0; i < planarskein.curvePerimeter.Length; i++)
                            {
                                cInfill.AddRange(planarskein.curvePerimeter[i]);
                            }
                        }
                    }
                }


                if (solidskein.regionInfill.Length > 0)
                {
                    for (int h = 0; h < solidskein.regionInfill.Length; h++)
                    {
                        if (solidskein.regionInfill[h] != null)
                        {
                            SilkwormSkein planarskein = new SilkwormSkein(Settings, solidskein.regionInfill[h]);
                            planarskein.Filler(infDens[h], infRot[h]);

                            for (int i = 0; i < planarskein.curveInfill.Length; i++)
                            {
                                cInfill.AddRange(planarskein.curveInfill[i]);
                            }
                        }
                    }
                }

                if (solidskein.regionOverhangs.Length > 0)
                {
                    //TODO
                }

                if (solidskein.regionBridges.Length > 0)
                {
                    //TODO
                }

                //Segment Curves
                foreach (Curve curve in cInfill)
                {
                    SilkwormSegment segment = new SilkwormSegment(curve);
                    pInfill.Add(segment.Pline);
                }
            }

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

            //Add to List of Movements

            foreach (Polyline pline in pInfill)
            {
                //List<SilkwormMovement> sList = new List<SilkwormMovement>();
                //sList.Add(new SilkwormMovement(Settings, pline, true));
                solidMovements.Add(new SilkwormMovement(Settings, pline));
            }


            unMovements.AddRange(solidMovements);

            return(unMovements);
        }