public override bool CastFrom(object source) { if (source == null) { return(false); } if (source is Line) { Value = (Line)source; return(true); } GH_Line lineGoo = source as GH_Line; if (lineGoo != null) { Value = lineGoo.Value; return(true); } Line line = new Line(); if (GH_Convert.ToLine(source, ref line, GH_Conversion.Both)) { Value = line; return(true); } return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Line ghln = new GH_Line(); if (DA.GetData(0, ref ghln)) { if (ghln == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Line input is null"); } Line ln = new Line(); if (GH_Convert.ToLine(ghln, ref ln, GH_Conversion.Both)) { GsaElement1d elem = new GsaElement1d(new LineCurve(ln)); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); elem.Section = section; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { elem.Element.Property = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } } DA.SetData(0, new GsaElement1dGoo(elem)); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Line ghln = new GH_Line(); if (DA.GetData(0, ref ghln)) { Line ln = new Line(); if (GH_Convert.ToLine(ghln, ref ln, GH_Conversion.Both)) { GsaElement1d elem = new GsaElement1d(new LineCurve(ln)); // 1 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaSection section = new GsaSection(); if (DA.GetData(1, ref gh_typ)) { if (gh_typ.Value is GsaSection) { gh_typ.CastTo(ref section); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { section.ID = idd; } } } else { section.ID = 1; } elem.Section = section; DA.SetData(0, new GsaElement1dGoo(elem)); } } }
public override bool CastFrom(object source) { // This function is called when Grasshopper needs to convert other data // into GsaElement. if (source == null) { return(false); } //Cast from GsaElement if (typeof(GsaElement1d).IsAssignableFrom(source.GetType())) { Value = (GsaElement1d)source; return(true); } //Cast from GsaAPI Member if (typeof(Element).IsAssignableFrom(source.GetType())) { Value.Element = (Element)source; return(true); } //Cast from Curve Line ln = new Line(); if (GH_Convert.ToLine(source, ref ln, GH_Conversion.Both)) { LineCurve crv = new LineCurve(ln); GsaElement1d elem = new GsaElement1d(crv); this.Value = elem; return(true); } return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { // Input Holders List <double> Flow = new List <double>(); List <double> Speed = new List <double>(); List <GH_ObjectWrapper> Movement = new List <GH_ObjectWrapper>(); GH_ObjectWrapper dObject = new GH_ObjectWrapper(); List <SilkwormLine> sMovement = new List <SilkwormLine>(); //Input if (!DA.GetData(3, ref dObject)) { } if (!DA.GetDataList(1, Speed)) { } if (!DA.GetDataList(2, Flow)) { } if (!DA.GetDataList(0, Movement)) { return; } //Fill Input with placeholders if empty if (Speed.Count < 1) { for (int j = 0; j < Movement.Count; j++) { Speed.Add(-1); } } if (Speed.Count == 1) { if (Movement.Count > 1) { for (int j = 0; j < Movement.Count; j++) { Speed.Add(Speed[0]); } } } if (Flow.Count < 1) { for (int k = 0; k < Movement.Count; k++) { Flow.Add(-1); } } if (Flow.Count == 1) { if (Movement.Count > 1) { for (int k = 0; k < Movement.Count; k++) { Flow.Add(Flow[0]); } } } #region Sort Geometric Input List <Curve> curves = new List <Curve>(); List <Line> lines = new List <Line>(); List <Point3d> points = new List <Point3d>(); foreach (GH_ObjectWrapper Goo in Movement) { if (Goo.Value is GH_Curve) { Curve curve = null; GH_Convert.ToCurve(Goo.Value, ref curve, GH_Conversion.Both); curves.Add(curve); continue; } if (Goo.Value is GH_Line) { Line line = new Line(); GH_Convert.ToLine(Goo.Value, ref line, GH_Conversion.Both); lines.Add(line); continue; } if (Goo.Value is GH_Point) { Point3d point = new Point3d(); GH_Convert.ToPoint3d(Goo.Value, ref point, GH_Conversion.Both); points.Add(point); continue; } } #endregion #region Sort Numerical Input #endregion //Output Holder SilkwormMovement sModel = new SilkwormMovement(); //Convert Different Geometry types to Movements based on input parameters #region Catch Exceptions if (points.Count > 1 || curves.Count > 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Only one curve or point per movement"); } if (points.Count == 1 || curves.Count == 1) { if (Flow.Count > 1 || Speed.Count > 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Flow or Speed Values do not match length of Input"); } } #endregion #region if curve ////Make Silkworm Lines if (curves.Count > 0 && curves.Count < 2) { List <Line> sLines = new List <Line>(); Curve newcurve = curves[0]; SilkwormSegment segmented = new SilkwormSegment(newcurve); //Make lines from curves foreach (Curve curve in segmented.Segments) { Line line = new Line(curve.PointAtStart, curve.PointAtEnd); sLines.Add(line); } //Create Silkworm Line from each line and a single flow or speed value for (int i = 0; i < sLines.Count; i++) { SilkwormLine sLine = new SilkwormLine(Flow[0], Speed[0], sLines[i]); sMovement.Add(sLine); } //Add Custom Delimiter or Default Delimiter (depending if input is provided) if (dObject.Value is Delimiter) { Delimiter delimiter = (Delimiter)dObject.Value; sModel = new SilkwormMovement(sMovement, delimiter); } else { sModel = new SilkwormMovement(sMovement, new Delimiter()); } } #endregion #region if lines //Make Silkworm Lines if (lines.Count > 0) { #region More Error Catching if (Flow.Count > 1 && Flow.Count != lines.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Flow Values do not match length of Line List"); } if (Speed.Count > 1 && Speed.Count != lines.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Speed Values do not match length of Line List"); } #endregion //Create Silkworm Line from each line and a corresponding flow or speed value //(will create an incomplete movement if none are provided) if (Flow.Count == lines.Count && Speed.Count == lines.Count) { for (int i = 0; i < lines.Count; i++) { SilkwormLine sLine = new SilkwormLine(Flow[i], Speed[i], lines[i]); sMovement.Add(sLine); } } //Add Custom Delimiter or Default Delimiter (depending if input is provided) if (dObject.Value is Delimiter) { Delimiter delimiter = (Delimiter)dObject.Value; sModel = new SilkwormMovement(sMovement, delimiter); } else { sModel = new SilkwormMovement(sMovement, new Delimiter()); } } #endregion #region if point if (points.Count < 2 && points.Count > 0) { if (dObject.Value is Delimiter) { Delimiter delimiter = (Delimiter)dObject.Value; sModel = new SilkwormMovement(points[0], delimiter); } else { sModel = new SilkwormMovement(points[0], new Delimiter()); } } #endregion //Output DA.SetData(0, sModel); }
protected override void SolveInstance(IGH_DataAccess DA) { GsaElement1d gsaElement1d = new GsaElement1d(); if (DA.GetData(0, ref gsaElement1d)) { GsaElement1d elem = gsaElement1d.Duplicate(); // #### inputs #### // 1 curve GH_Line ghcrv = new GH_Line(); if (DA.GetData(1, ref ghcrv)) { Line crv = new Line(); if (GH_Convert.ToLine(ghcrv, ref crv, GH_Conversion.Both)) { LineCurve ln = new LineCurve(crv); GsaElement1d tmpelem = new GsaElement1d(ln) { ID = elem.ID, Element = elem.Element, ReleaseEnd = elem.ReleaseEnd, ReleaseStart = elem.ReleaseStart }; elem = tmpelem; } } // 2 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(2, ref gh_typ)) { GsaSection section = new GsaSection(); if (gh_typ.Value is GsaSection) { gh_typ.CastTo(ref section); } else if (gh_typ.Value is GH_Number) { if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both)) { section.ID = idd; } } elem.Section = section; } // 3 offset GsaOffset offset = new GsaOffset(); if (DA.GetData(3, ref offset)) { elem.Element.Offset.X1 = offset.X1; elem.Element.Offset.X2 = offset.X2; elem.Element.Offset.Y = offset.Y; elem.Element.Offset.Z = offset.Z; } // 4 start release GsaBool6 start = new GsaBool6(); if (DA.GetData(4, ref start)) { elem.ReleaseStart = start; //should handle setting the release in elem.Element.SetRelease } // 5 end release GsaBool6 end = new GsaBool6(); if (DA.GetData(5, ref end)) { elem.ReleaseEnd = end; //should handle setting the release in elem.Element.SetRelease } // 6 orientation angle GH_Number ghangle = new GH_Number(); if (DA.GetData(6, ref ghangle)) { if (GH_Convert.ToDouble(ghangle, out double angle, GH_Conversion.Both)) { elem.Element.OrientationAngle = angle; } } // 7 orientation node GH_Integer ghori = new GH_Integer(); if (DA.GetData(7, ref ghori)) { if (GH_Convert.ToInt32(ghori, out int orient, GH_Conversion.Both)) { elem.Element.OrientationNode = orient; } } // 8 type GH_Integer ghinteg = new GH_Integer(); if (DA.GetData(8, ref ghinteg)) { if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both)) { elem.Element.Type = Util.Gsa.GsaToModel.Element1dType(type); } } // 9 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(9, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { elem.ID = id; } } // 10 name GH_String ghnm = new GH_String(); if (DA.GetData(10, ref ghnm)) { if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both)) { elem.Element.Name = name; } } // 11 Group GH_Integer ghgrp = new GH_Integer(); if (DA.GetData(11, ref ghgrp)) { if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both)) { elem.Element.Group = grp; } } // 12 Colour GH_Colour ghcol = new GH_Colour(); if (DA.GetData(12, ref ghcol)) { if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both)) { elem.Element.Colour = col; } } // #### outputs #### DA.SetData(0, new GsaElement1dGoo(elem)); DA.SetData(1, elem.Line); DA.SetData(2, elem.Section); GsaOffset offset1 = new GsaOffset { X1 = elem.Element.Offset.X1, X2 = elem.Element.Offset.X2, Y = elem.Element.Offset.Y, Z = elem.Element.Offset.Z }; DA.SetData(3, offset1); DA.SetData(4, elem.ReleaseStart); DA.SetData(5, elem.ReleaseEnd); DA.SetData(6, elem.Element.OrientationAngle); DA.SetData(7, elem.Element.OrientationNode); DA.SetData(8, elem.Element.Type); DA.SetData(9, elem.ID); DA.SetData(10, elem.Element.Name); DA.SetData(11, elem.Element.Group); DA.SetData(12, elem.Element.Colour); try { DA.SetData(13, elem.Element.ParentMember.Member); } catch (Exception) { } //DA.SetData(16, gsaElement1d.Element.IsDummy); } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaElement1d gsaElement1d = new GsaElement1d(); if (DA.GetData(0, ref gsaElement1d)) { if (gsaElement1d == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Element1D input is null"); } GsaElement1d elem = gsaElement1d.Duplicate(); // #### inputs #### // 1 ID GH_Integer ghID = new GH_Integer(); if (DA.GetData(1, ref ghID)) { if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both)) { elem.ID = id; } } // 2 curve GH_Line ghcrv = new GH_Line(); if (DA.GetData(2, ref ghcrv)) { Line crv = new Line(); if (GH_Convert.ToLine(ghcrv, ref crv, GH_Conversion.Both)) { LineCurve ln = new LineCurve(crv); GsaElement1d tmpelem = new GsaElement1d(ln) { ID = elem.ID, Element = elem.Element, ReleaseEnd = elem.ReleaseEnd, ReleaseStart = elem.ReleaseStart }; elem = tmpelem; } } // 3 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(3, ref gh_typ)) { GsaSection section = new GsaSection(); if (gh_typ.Value is GsaSectionGoo) { gh_typ.CastTo(ref section); elem.Section = section; elem.Element.Property = 0; } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { elem.Element.Property = idd; elem.Section = null; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PB input to a Section Property of reference integer"); return; } } }
/// <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 }