コード例 #1
0
ファイル: SlicingComponent.cs プロジェクト: samuto/Silkworm
        /// <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<GH_ObjectWrapper> things = new List<GH_ObjectWrapper>();
            if (!DA.GetDataList(1, things)) return;

            // import Silkworm Movement
            #endregion

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

            #region Optional Variables
            int shell = -999;
            if (!DA.GetData(4, ref shell)) { }
            double layerheight = -999;
            if (!DA.GetData(3, ref layerheight)) { }
            //bool detect = false;
            //if (!DA.GetData(5, ref detect)) { }
            List<Plane> sliceplanes = new List<Plane>();
            if (!DA.GetDataList(2, sliceplanes)) { }

            if (shell == -999)
            {
                shell = int.Parse(Settings["perimeters"]);
            }
            if (layerheight == -999)
            {
                layerheight = double.Parse(Settings["layer_height"]);
            }
            if (sliceplanes.Count<1)
            {
                sliceplanes.Add(Plane.WorldXY);
            }

            #endregion

            List<Brep> Breps = new List<Brep>();

            List<Mesh> Meshes = new List<Mesh>();

            SilkwormSkein skein = new SilkwormSkein();

            #region Sort Types
            foreach (GH_ObjectWrapper obj in things)
            {
                if (obj.Value is GH_Brep)
                {
                    Brep brep = null;
                    GH_Convert.ToBrep(obj.Value, ref brep, GH_Conversion.Both);

                    Breps.Add(brep);
                    continue;

                }

                if (obj.Value is GH_Mesh)
                {
                    Mesh mesh = null;
                    GH_Convert.ToMesh(obj.Value, ref mesh, GH_Conversion.Both);
                    Meshes.Add(mesh);

                    continue;
                }
            }
            #endregion

            if (Breps.Count>0)
            {

                skein = new SilkwormSkein(Settings, Breps, sliceplanes, shell, layerheight);
                skein.BrepSlice(false);

            }

            if (Meshes.Count > 0)
            {

                //TODO
            }

            //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);

                }

            List<Curve>[] openregions = skein.openRegions;

            List<Brep>[] rRegions = skein.Regions;
            List<Brep>[] rPerimeterR = skein.regionPerimeter;
            List<Brep>[]  rInfillR = skein.regionInfill;

            GH_Structure<GH_Brep> Regions = new GH_Structure<GH_Brep>();

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

            #region Add Regions to GH_Structure

            if (rRegions.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < rRegions.Length; i++)
                {

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

                            GH_Brep gShapes = new GH_Brep(rRegions[i][j]);
                            Regions.Insert(gShapes, new GH_Path(i, 0), j);
                        }

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

                            GH_Brep gShapes = new GH_Brep(rPerimeterR[i][j]);
                            Regions.Insert(gShapes, new GH_Path(i, 1), j);
                        }

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

                            GH_Brep gShapes = new GH_Brep(rInfillR[i][j]);
                            Regions.Insert(gShapes, new GH_Path(i, 2), j);
                        }

                    }
                }
            }

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

                            GH_Curve gShapes = new GH_Curve(openregions[i][j]);
                            openRegions.Insert(gShapes, new GH_Path(i), j);
                        }

                    }
                }
            }
            //TODO
            //Add Overhang and Bridges

            #endregion

            #region Add Open Regions to GH_Structure
            if (openregions.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < openregions.Length; i++)
                {

                    for (int j = 0; j < openregions[i].Count; j++)
                    {

                        if (openregions[i][j] != null)
                        {

                            SilkwormSegment segment = new SilkwormSegment(openregions[i][j]);
                            Curve curve = segment.Pline.ToNurbsCurve();
                            GH_Curve gShapes = new GH_Curve(curve);
                            openRegions.Insert(gShapes, new GH_Path(i), j);
                        }

                    }
                }
            }
            #endregion

            #region OUTPUT

            if (!DA.SetDataTree(0, Regions)) { return; }
            if (!DA.SetDataTree(1, openRegions)) { return; }

            #endregion
        }
コード例 #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 <GH_ObjectWrapper> things = new List <GH_ObjectWrapper>();
            if (!DA.GetDataList(1, things))
            {
                return;
            }


            // import Silkworm Movement
            #endregion


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

            #region Optional Variables
            int shell = -999;
            if (!DA.GetData(4, ref shell))
            {
            }
            double layerheight = -999;
            if (!DA.GetData(3, ref layerheight))
            {
            }
            //bool detect = false;
            //if (!DA.GetData(5, ref detect)) { }
            List <Plane> sliceplanes = new List <Plane>();
            if (!DA.GetDataList(2, sliceplanes))
            {
            }

            if (shell == -999)
            {
                shell = int.Parse(Settings["perimeters"]);
            }
            if (layerheight == -999)
            {
                layerheight = double.Parse(Settings["layer_height"]);
            }
            if (sliceplanes.Count < 1)
            {
                sliceplanes.Add(Plane.WorldXY);
            }

            #endregion

            List <Brep> Breps = new List <Brep>();


            List <Mesh> Meshes = new List <Mesh>();

            SilkwormSkein skein = new SilkwormSkein();

            #region Sort Types
            foreach (GH_ObjectWrapper obj in things)
            {
                if (obj.Value is GH_Brep)
                {
                    Brep brep = null;
                    GH_Convert.ToBrep(obj.Value, ref brep, GH_Conversion.Both);

                    Breps.Add(brep);
                    continue;
                }

                if (obj.Value is GH_Mesh)
                {
                    Mesh mesh = null;
                    GH_Convert.ToMesh(obj.Value, ref mesh, GH_Conversion.Both);
                    Meshes.Add(mesh);

                    continue;
                }
            }
            #endregion


            if (Breps.Count > 0)
            {
                skein = new SilkwormSkein(Settings, Breps, sliceplanes, shell, layerheight);
                skein.BrepSlice(false);
            }


            if (Meshes.Count > 0)
            {
                //TODO
            }

            //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);
            }

            List <Curve>[] openregions = skein.openRegions;

            List <Brep>[] rRegions    = skein.Regions;
            List <Brep>[] rPerimeterR = skein.regionPerimeter;
            List <Brep>[] rInfillR    = skein.regionInfill;

            GH_Structure <GH_Brep> Regions = new GH_Structure <GH_Brep>();

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


            #region Add Regions to GH_Structure

            if (rRegions.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < rRegions.Length; i++)
                {
                    if (rRegions[i] != null)
                    {
                        for (int j = 0; j < rRegions[i].Count; j++)
                        {
                            GH_Brep gShapes = new GH_Brep(rRegions[i][j]);
                            Regions.Insert(gShapes, new GH_Path(i, 0), j);
                        }
                    }
                }
            }
            if (rPerimeterR.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < rPerimeterR.Length; i++)
                {
                    if (rPerimeterR[i] != null)
                    {
                        for (int j = 0; j < rPerimeterR[i].Count; j++)
                        {
                            GH_Brep gShapes = new GH_Brep(rPerimeterR[i][j]);
                            Regions.Insert(gShapes, new GH_Path(i, 1), j);
                        }
                    }
                }
            }
            if (rInfillR.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < rInfillR.Length; i++)
                {
                    if (rInfillR[i] != null)
                    {
                        for (int j = 0; j < rInfillR[i].Count; j++)
                        {
                            GH_Brep gShapes = new GH_Brep(rInfillR[i][j]);
                            Regions.Insert(gShapes, new GH_Path(i, 2), j);
                        }
                    }
                }
            }

            if (openregions.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < openregions.Length; i++)
                {
                    if (openregions[i] != null)
                    {
                        for (int j = 0; j < openregions[i].Count; j++)
                        {
                            GH_Curve gShapes = new GH_Curve(openregions[i][j]);
                            openRegions.Insert(gShapes, new GH_Path(i), j);
                        }
                    }
                }
            }
            //TODO
            //Add Overhang and Bridges

            #endregion


            #region Add Open Regions to GH_Structure
            if (openregions.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < openregions.Length; i++)
                {
                    for (int j = 0; j < openregions[i].Count; j++)
                    {
                        if (openregions[i][j] != null)
                        {
                            SilkwormSegment segment = new SilkwormSegment(openregions[i][j]);
                            Curve           curve   = segment.Pline.ToNurbsCurve();
                            GH_Curve        gShapes = new GH_Curve(curve);
                            openRegions.Insert(gShapes, new GH_Path(i), j);
                        }
                    }
                }
            }
            #endregion

            #region OUTPUT

            if (!DA.SetDataTree(0, Regions))
            {
                return;
            }
            if (!DA.SetDataTree(1, openRegions))
            {
                return;
            }

            #endregion
        }
コード例 #3
0
ファイル: FillingComponent.cs プロジェクト: samuto/Silkworm
        /// <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; }
        }
コード例 #4
0
ファイル: GeneratorComponent.cs プロジェクト: samuto/Silkworm
        /// <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
        }
コード例 #5
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;
            }
        }
コード例 #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)
        {
            #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
        }