public SuperPolyline(GH_Line line, string guid) { parentGuid = guid; data.uvs = ""; data.normals = ""; data.faces = ""; data.vertices = new List<double>(); Point3d start = line.Value.From; Point3d end = line.Value.To; data.vertices.Add(Math.Round(start.Y * 1, 3)); data.vertices.Add(Math.Round(start.Z * 1, 3)); data.vertices.Add(Math.Round(start.X * 1, 3)); data.vertices.Add(Math.Round(end.Y * 1, 3)); data.vertices.Add(Math.Round(end.Z * 1, 3)); data.vertices.Add(Math.Round(end.X * 1, 3)); }
/// <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) { //local variables GH_Line line = null; Material material = null; Layer layer = null; string layerName = "Default"; //catch inputs and populate local variables if (!DA.GetData(0, ref line)) { return; } if (!DA.GetData(1, ref material)) { material = lineDefaultMaterial(); } if (material.Type != SpectaclesMaterialType.Line) { throw new Exception("Please use a LINE Material"); } DA.GetData(2, ref layerName); layer = new Layer(layerName); //create JSON from line string outJSON = lineJSON(line.Value); Element e = new Element(outJSON, SpectaclesElementType.Line, material, layer); //output results DA.SetData(0, e); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Line line = new GH_Line(); DA.GetData<GH_Line>("Gridline", ref line); List<Parameter> parameters = new List<Parameter>(); if (!DA.GetDataList<Parameter>("Parameters", parameters)) parameters = new List<Parameter>(); GH_String name = new GH_String(); DA.GetData<GH_String>("Name", ref name); Tuple<Grevit.Types.Point, Grevit.Types.Point> points = line.ToGrevitPoints(); Grid gridLine = new Grid(parameters, points.Item1, points.Item2,name.Value); gridLine.GID = line.ReferenceID.ToString(); DA.SetData("GrevitComponent", gridLine); }
public override bool CastTo <Q>(out Q target) { // This function is called when Grasshopper needs to convert this // instance of GsaElement into some other type Q. if (typeof(Q).IsAssignableFrom(typeof(GsaElement1d))) { if (Value == null) { target = default; } else { target = (Q)(object)Value; } return(true); } if (typeof(Q).IsAssignableFrom(typeof(Element))) { if (Value == null) { target = default; } else { target = (Q)(object)Value.Element; } return(true); } //Cast to Curve if (typeof(Q).IsAssignableFrom(typeof(Line))) { if (Value == null) { target = default; } else { target = (Q)(object)Value.Line; } return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Line))) { if (Value == null) { target = default; } else { GH_Line ghLine = new GH_Line(); GH_Convert.ToGHLine(Value.Line, GH_Conversion.Both, ref ghLine); target = (Q)(object)ghLine; } return(true); } if (typeof(Q).IsAssignableFrom(typeof(Curve))) { if (Value == null) { target = default; } else { target = (Q)(object)Value.Line; } return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Curve))) { if (Value == null) { target = default; } else { target = (Q)(object)new GH_Curve(Value.Line); } return(true); } target = default; return(false); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { object obj = null; DA.GetData(0, ref obj); // Remarks: // 1) why lines, rectangles or *any* rhinocommon object can't have user dicts? // 2) @David: i hate grasshopper typecasting and the hassle below // (why isn't there a GH_DefaultType, where i can access the .Value regardless of type...?) GeometryBase myObj = null; GH_Mesh mesh = obj as GH_Mesh; if (mesh != null) { myObj = mesh.Value; } GH_Brep brep = obj as GH_Brep; if (brep != null) { myObj = brep.Value; } GH_Surface srf = obj as GH_Surface; if (srf != null) { myObj = srf.Value; } GH_Box box = obj as GH_Box; if (box != null) { myObj = box.Value.ToBrep(); } GH_Curve crv = obj as GH_Curve; if (crv != null) { myObj = crv.Value; } GH_Line line = obj as GH_Line; if (line != null) { myObj = line.Value.ToNurbsCurve(); } GH_Rectangle rect = obj as GH_Rectangle; if (rect != null) { myObj = rect.Value.ToNurbsCurve(); } GH_Circle circle = obj as GH_Circle; if (circle != null) { myObj = circle.Value.ToNurbsCurve(); } GH_Arc arc = obj as GH_Arc; if (arc != null) { myObj = arc.Value.ToNurbsCurve(); } GH_Point pt = obj as GH_Point; if (pt != null) { myObj = new Point(pt.Value); } if (myObj == null) { // get the object out DA.SetData(0, obj); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Failed to set user dictionary to object. Probably an unsupported type."); return; } myObj.UserDictionary.Clear(); object value = null; DA.GetData(1, ref value); GH_ObjectWrapper temp = value as GH_ObjectWrapper; if (temp == null) { DA.SetData(0, obj); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Could not cast object to GH_ObjectWrapper."); return; } ArchivableDictionary dict = ((GH_ObjectWrapper)value).Value as ArchivableDictionary; if (dict == null) { DA.SetData(0, obj); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Could not cast object to Dictionary."); return; } myObj.UserDictionary.ReplaceContentsWith(dict); DA.SetData(0, myObj); }
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); } }
/// <summary> /// This one does many things, which essentially boil down to translating the geometry + performance measures into a spk instance. /// This instance subsequently gets json-ed out to a file /// </summary> public static System.Dynamic.ExpandoObject translateGeometry(List <System.Object> inputObjects, List <string> guids, String name, IGH_Component component) { dynamic myInstance = new System.Dynamic.ExpandoObject(); myInstance.metadata = new System.Dynamic.ExpandoObject(); myInstance.metadata.verion = "1.0"; myInstance.metadata.type = "Object"; myInstance.metadata.generator = "Instance Export"; // super important - name will link it to the correct group in three js myInstance.metadata.name = name; myInstance.metadata.properties = new List <String>(); foreach (IGH_Param param in component.Params.Input[1].Sources) { var myprop = getPanelNameAndVal(param); if (myprop != null) { myInstance.metadata.properties.Add(myprop); } } myInstance.geometries = new List <System.Object>(); int k = 0; foreach (System.Object myObj in inputObjects) { if (myObj != null) { string myguid = "000"; if (name != "staticGeo") { myguid = guids[k]; } k++; if (myObj is GH_Mesh) { GH_Mesh tempers = (GH_Mesh)myObj; SuperMesh mesh = new SuperMesh(tempers, myguid); myInstance.geometries.Add(mesh); } else if ((myObj is GH_Curve)) { GH_Curve tempers = (GH_Curve)myObj; Curve myCrv = tempers.Value; if (myCrv.Degree == 1) { Polyline tempP; myCrv.TryGetPolyline(out tempP); SuperPolyline polyline = new SuperPolyline(tempP, false, myguid); myInstance.geometries.Add(polyline); } else if ((myCrv.Degree == 2) || (myCrv.Degree == 3)) { bool isClosed = myCrv.IsClosed; int mainSegmentCount = 0, subSegmentCount = 1; double maxAngleRadians = 0, maxChordLengthRatio = 0, maxAspectRatio = 0, tolerance = 0.1, minEdgeLength = 0, maxEdgeLength = 0; bool keepStartPoint = true; PolylineCurve p = myCrv.ToPolyline(mainSegmentCount, subSegmentCount, maxAngleRadians, maxChordLengthRatio, maxAspectRatio, tolerance, minEdgeLength, maxEdgeLength, keepStartPoint); Polyline pp; p.TryGetPolyline(out pp); myInstance.geometries.Add(new SuperPolyline(pp, isClosed, myguid)); } } else if (myObj is Point3d) { GH_Point tempers = (GH_Point)myObj; SuperPoint point = new SuperPoint(tempers, myguid); myInstance.geometries.Add(point); } else if ((myObj is GH_Brep) || (myObj is GH_Surface)) { Mesh[] myMeshes; Brep myFutureBrep = null; GH_Convert.ToBrep(myObj, ref myFutureBrep, GH_Conversion.Primary); if (myFutureBrep != null) { myMeshes = Mesh.CreateFromBrep(myFutureBrep, MeshingParameters.Smooth); if (myMeshes == null || myMeshes.Length == 0) { // TODO throw an error } Mesh brep_mesh = new Mesh(); foreach (Mesh tempmesh in myMeshes) { brep_mesh.Append(tempmesh); } GH_Mesh temporal = new GH_Mesh(brep_mesh); SuperMesh mesh = new SuperMesh(temporal, myguid); myInstance.geometries.Add(mesh); } } else if (myObj is GH_Circle) { GH_Circle myCircle = myObj as GH_Circle; //NurbsCurve mycrv = myCircle.Value.ToNurbsCurve(); NurbsCurve mycrv = NurbsCurve.CreateFromCircle(myCircle.Value); int mainSegmentCount = 30, subSegmentCount = 1; double maxAngleRadians = 0, maxChordLengthRatio = 0, maxAspectRatio = 0, tolerance = 0.1, minEdgeLength = 0, maxEdgeLength = 0; bool keepStartPoint = true; if (mycrv != null) { PolylineCurve p = mycrv.ToPolyline(mainSegmentCount, subSegmentCount, maxAngleRadians, maxChordLengthRatio, maxAspectRatio, tolerance, minEdgeLength, maxEdgeLength, keepStartPoint); Polyline pp; p.TryGetPolyline(out pp); if (pp != null) { myInstance.geometries.Add(new SuperPolyline(pp, true, myguid)); } else { myInstance.geometries.Add("Circle error"); } } else { myInstance.geometries.Add("Circle error 2"); } } else if (myObj is GH_Line) { GH_Line myLine = myObj as GH_Line; myInstance.geometries.Add(new SuperPolyline(myLine, myguid)); } else { myInstance.geometries.Add("error - undefined type"); } } } return(myInstance); }
// SOLVER // Retrieves data from Grasshopper and changes component properties that can be accessed in the code-behind of stormcloud.xaml protected override void SolveInstance(IGH_DataAccess DA) { //// GEOMETRY //// Use IGH_GeometricGoo to deal with different geometry types List <IGH_GeometricGoo> g = new List <IGH_GeometricGoo>(); if (!DA.GetDataList <IGH_GeometricGoo>(0, g)) { return; } // retrieves list of geometries as list of IGH_GeometricGoo List <Curve> curves = new List <Curve>(); List <Mesh> meshes = new List <Mesh>(); List <Brep> breps = new List <Brep>(); foreach (IGH_GeometricGoo goo in g) { GH_Line l = goo as GH_Line; if (l != null) { GH_Curve lc = new GH_Curve(); l.CastTo <GH_Curve>(out lc); curves.Add(lc.DuplicateCurve().Value); } GH_Curve c = goo as GH_Curve; // c = null if geometry is not a curve if (c != null) { curves.Add(c.DuplicateCurve().Value); // add to curves if geometry is a curve Console.WriteLine("There is a Curve"); } GH_Mesh m = goo as GH_Mesh; if (m != null) { GH_Brep br = new GH_Brep(); m.CastTo <GH_Brep>(out br); breps.Add(br.DuplicateBrep().Value); } //GH_Surface s = goo as GH_Surface; //if (s != null) //{ // GH_Brep brs = new GH_Brep(); // s.CastTo<GH_Brep>(out brs); // breps.Add(brs.DuplicateBrep().Value); //} GH_Brep b = goo as GH_Brep; if (b != null) { breps.Add(b.DuplicateBrep().Value); } } //// Change values of relevant component properties DesignCurves = curves; DesignMeshes = meshes; DesignBreps = breps; // DesignLines //List<Line> lines = new List<Line>(); //if (!DA.GetDataList(0, lines)) { return; } //DesignLines = lines; // SCORE double score = 0; // instantiate score if (!DA.GetData(1, ref score)) { return; } Score = score; // Change value of component property // Update model of main 3D viewports in stormcloud if (this.DesignView.InitialDesign.Score != 0) { DesignView.UpdateCurrentScore(Score); } else { DesignView.UpdateCurrentScore(1.00); } //DesignView.UpdateCurrentModel(DesignLines, RenderingSettings.diameter, RenderingSettings.resolutiontube, RenderingSettings.mat); DesignView.UpdateCurrentModelAdvanced(DesignCurves, DesignMeshes, DesignBreps, RenderingSettings.diameter, RenderingSettings.resolution, RenderingSettings.resolutiontube, RenderingSettings.mat); }
protected CrossSectionOrientation ParseGlulamOrientation(List <object> input, Curve curve) { if (input == null || input.Count < 1) { if (curve.IsPlanar(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)) { curve.TryGetPlane(out Plane plane, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); return(new PlanarOrientation(plane)); } return(new RmfOrientation()); } if (input.Count == 1) { object single = input[0]; //AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, single.ToString()); if (single is Vector3d) { return(new VectorOrientation((Vector3d)single)); } if (single is GH_Vector) { return(new VectorOrientation((single as GH_Vector).Value)); } if (single is Plane) { return(new VectorOrientation(((Plane)single).YAxis)); } if (single is GH_Plane) { return(new VectorOrientation((single as GH_Plane).Value.YAxis)); } if (single is GH_Line) { return(new VectorOrientation((single as GH_Line).Value.Direction)); } if (single is Surface) { return(new SurfaceOrientation((single as Surface).ToBrep())); } if (single is GH_Surface) { return(new SurfaceOrientation((single as GH_Surface).Value)); } if (single is Brep) { return(new SurfaceOrientation(single as Brep)); } if (single is GH_Brep) { return(new SurfaceOrientation((single as GH_Brep).Value)); } if (single is GH_Curve) { Curve crv = (single as GH_Curve).Value; if (crv.IsLinear()) { return(new VectorOrientation(crv.TangentAtStart)); } return(new RailCurveOrientation((single as GH_Curve).Value)); } if (single == null) { return(new RmfOrientation()); } } if (input.First() is GH_Plane) { List <double> parameters = new List <double>(); List <Vector3d> vectors = new List <Vector3d>(); for (int i = 0; i < input.Count; ++i) { GH_Plane p = input[i] as GH_Plane; if (p == null) { continue; } double t; curve.ClosestPoint(p.Value.Origin, out t); parameters.Add(t); vectors.Add(p.Value.YAxis); } return(new VectorListOrientation(curve, parameters, vectors)); } if (input.First() is GH_Line) { List <double> parameters = new List <double>(); List <Vector3d> vectors = new List <Vector3d>(); for (int i = 0; i < input.Count; ++i) { GH_Line line = input[i] as GH_Line; if (line == null) { continue; } double t; curve.ClosestPoint(line.Value.From, out t); parameters.Add(t); vectors.Add(line.Value.Direction); } return(new VectorListOrientation(curve, parameters, vectors)); } if (input.First() is GH_Curve) { List <double> parameters = new List <double>(); List <Vector3d> vectors = new List <Vector3d>(); for (int i = 0; i < input.Count; ++i) { GH_Curve crv = input[i] as GH_Curve; if (crv == null) { continue; } double t; curve.ClosestPoint(crv.Value.PointAtStart, out t); parameters.Add(t); vectors.Add(crv.Value.TangentAtStart); } return(new VectorListOrientation(curve, parameters, vectors)); } if (curve.IsPlanar()) { curve.TryGetPlane(out Plane plane); return(new PlanarOrientation(plane)); } return(new RmfOrientation()); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="dataAccess"> /// The DA object is used to retrieve from inputs and store in outputs. /// </param> protected override void SolveInstance(IGH_DataAccess dataAccess) { object @object = null; double tolerance = 0.0001; if (!dataAccess.GetData(0, ref @object)) { return; } if (!dataAccess.GetData(1, ref tolerance)) { return; } if (@object == null) { return; } Type type = @object.GetType(); global::Topologic.Topology topology = null; GH_Point ghPoint = @object as GH_Point; if (ghPoint != null) { topology = ghPoint.Value.ToTopologic(); dataAccess.SetData(0, topology); return; } GH_Line ghLine = @object as GH_Line; if (ghLine != null) { topology = ghLine.Value.ToTopologic(); dataAccess.SetData(0, topology); return; } GH_Curve ghCurve = @object as GH_Curve; if (ghCurve != null) { topology = ghCurve.Value.ToTopologic(); dataAccess.SetData(0, topology); return; } GH_Surface ghSurface = @object as GH_Surface; if (ghSurface != null) { topology = ghSurface.Value.ToTopologic(tolerance); dataAccess.SetData(0, topology); return; } GH_Brep ghBrep = @object as GH_Brep; if (ghBrep != null) { topology = ghBrep.Value.ToTopologic(tolerance); dataAccess.SetData(0, topology); return; } GH_Box ghBox = @object as GH_Box; if (ghBox != null) { topology = ghBox.Value.ToTopologic(); dataAccess.SetData(0, topology); return; } GH_Mesh ghMesh = @object as GH_Mesh; if (ghMesh != null) { topology = ghMesh.Value.ToTopologic(); dataAccess.SetData(0, topology); return; } throw new Exception("Cannot convert geometry."); }
public override bool CastFrom(object source) { var switchExpr = source.GetType(); switch (switchExpr) { case var @case when @case == typeof(Tensor): { this.Value = (Tensor)source; return(true); } case var case1 when case1 == typeof(TensorSet): { TensorSet ts = (TensorSet)source; if (ts.Count != 1) { return(false); } this.Value = ts[0]; return(true); } case var case2 when case2 == typeof(Point3d): { Point3d asp = source; this.Value = new Tensor(new[] { asp.X, asp.Y, asp.Z }); return(true); } case var case3 when case3 == typeof(GH_Point): { GH_Point asp = source; this.Value = new Tensor(new[] { asp.Value.X, asp.Value.Y, asp.Value.Z }); return(true); } case var case4 when case4 == typeof(GH_Vector): { GH_Vector asp = source; this.Value = new Tensor(new[] { asp.Value.X, asp.Value.Y, asp.Value.Z }); return(true); } case var case5 when case5 == typeof(Vector3d): { Vector3d asp = source; this.Value = new Tensor(new[] { asp.X, asp.Y, asp.Z }); return(true); } case var case6 when case6 == typeof(Color): { Color asp = (Color)source; this.Value = new Tensor(new[] { Convert.ToDouble(asp.A), Convert.ToDouble(asp.R), Convert.ToDouble(asp.G), Convert.ToDouble(asp.B) }); return(true); } case var case7 when case7 == typeof(GH_Colour): { GH_Colour asp = source; this.Value = new Tensor(new[] { Convert.ToDouble(asp.Value.A), Convert.ToDouble(asp.Value.R), Convert.ToDouble(asp.Value.G), Convert.ToDouble(asp.Value.B) }); return(true); } case var case8 when case8 == typeof(Line): { Line asp = source; this.Value = new Tensor(new[] { asp.From.X, asp.From.Y, asp.From.Z, asp.To.X, asp.To.Y, asp.To.Z }); return(true); } case var case9 when case9 == typeof(GH_Line): { GH_Line thisv = source; Line asp = thisv.Value; this.Value = new Tensor(new[] { asp.From.X, asp.From.Y, asp.From.Z, asp.To.X, asp.To.Y, asp.To.Z }); return(true); } } return(false); }
/// <summary> /// Updates the geometry for an input chromosome /// </summary> /// <param name="chromo">The chromosome used to get geometry from the gh canvas</param> /// <returns></returns> public int GetGeometry(Chromosome chromo) { // Collect the object at the current instance List <object> localObjs = new List <object>(); // Thank you Dimitrie :) foreach (IGH_Param param in Params.Input[1].Sources) { foreach (Object myObj in param.VolatileData.AllData(true)) // AllData flattens the tree { localObjs.Add(myObj); } } // Gets lists of different geometry List <Mesh> meshGeometry = new List <Mesh>(); List <PolylineCurve> polyGeometry = new List <PolylineCurve>(); // Get only mesh geometry from the object list for (int i = 0; i < localObjs.Count; i++) { // Need to replace with a Switch if (localObjs[i] is GH_Mesh) { GH_Mesh myGHMesh = new GH_Mesh(); myGHMesh = (GH_Mesh)localObjs[i]; Mesh myLocalMesh = new Mesh(); GH_Convert.ToMesh(myGHMesh, ref myLocalMesh, GH_Conversion.Primary); myLocalMesh.Faces.ConvertQuadsToTriangles(); meshGeometry.Add(myLocalMesh); //Mesh joinedMesh = new Mesh(); //joinedMesh.Append(myLocalMesh); } if (localObjs[i] is GH_Brep) { GH_Brep myBrep = new GH_Brep(); myBrep = (GH_Brep)localObjs[i]; Mesh[] meshes = Mesh.CreateFromBrep(myBrep.Value, MeshingParameters.FastRenderMesh); Mesh mesh = new Mesh(); mesh.Append(meshes); mesh.Faces.ConvertQuadsToTriangles(); meshGeometry.Add(mesh); } if (localObjs[i] is GH_Box) { GH_Box myBox = new GH_Box((GH_Box)localObjs[i]); Mesh[] meshes = Mesh.CreateFromBrep(myBox.Brep(), MeshingParameters.FastRenderMesh); Mesh mesh = new Mesh(); mesh.Append(meshes); mesh.Faces.ConvertQuadsToTriangles(); meshGeometry.Add(mesh); } if (localObjs[i] is GH_Surface) { GH_Surface mySurface = (GH_Surface)localObjs[i]; Mesh[] meshes = Mesh.CreateFromBrep(mySurface.Value, MeshingParameters.FastRenderMesh); Mesh mesh = new Mesh(); mesh.Append(meshes); mesh.Faces.ConvertQuadsToTriangles(); meshGeometry.Add(mesh); } if (localObjs[i] is GH_Curve) { GH_Curve myGHCurve = (GH_Curve)localObjs[i]; PolylineCurve myPoly = myGHCurve.Value.ToPolyline(0, 0, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0, true); polyGeometry.Add(myPoly); } if (localObjs[i] is GH_Arc) { GH_Arc myGHArc = (GH_Arc)localObjs[i]; PolylineCurve myPoly = myGHArc.Value.ToNurbsCurve().ToPolyline(0, 0, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0, true); polyGeometry.Add(myPoly); } if (localObjs[i] is GH_Line) { GH_Line myGHLine = (GH_Line)localObjs[i]; List <Point3d> pts = new List <Point3d> { myGHLine.Value.From, myGHLine.Value.To }; PolylineCurve myPoly = new PolylineCurve(pts); polyGeometry.Add(myPoly); } } // Get performance data List <double> performas = new List <double>(); List <string> criteria = new List <string>(); // Cap at eight criteria max. int pCount = 0; int repeatCounter = 1; foreach (IGH_Param param in Params.Input[2].Sources) { foreach (Object myObj in param.VolatileData.AllData(true)) { if (myObj is GH_Number && pCount < 8) { GH_Number temp = (GH_Number)myObj; performas.Add(temp.Value); if (!criteria.Contains(param.NickName)) { criteria.Add(param.NickName); } else { criteria.Add(param.NickName + " (" + repeatCounter + ")"); repeatCounter++; } pCount++; } else if (myObj is GH_Integer && pCount < 8) { GH_Integer temp = (GH_Integer)myObj; performas.Add((double)temp.Value); if (!criteria.Contains(param.NickName)) { criteria.Add(param.NickName); } else { criteria.Add(param.NickName + " (" + repeatCounter + ")"); repeatCounter++; } pCount++; } } } // Set the phenotype within the chromosome class chromo.SetPhenotype(meshGeometry, polyGeometry, performas, criteria); // Return the number of performance criteria return(performas.Count); }
public static Line FromIO(this GH_Line l) { return(new Line(l.A.FromIO(), l.B.FromIO())); }
/// <summary> /// Determines object type and calls the appropriate conversion call. /// </summary> /// <param name="o">Object to convert.</param> /// <param name="getEncoded">If set to true, will return a base64 encoded value of more complex objects (ie, breps).</param> /// <returns></returns> private static SpeckleObject fromGhRhObject(object o, bool getEncoded = false, bool getAbstract = true) { GH_Interval int1d = o as GH_Interval; if (int1d != null) { return(GhRhConveter.fromInterval(int1d.Value)); } if (o is Interval) { return(GhRhConveter.fromInterval((Interval)o)); } GH_Interval2D int2d = o as GH_Interval2D; if (int2d != null) { return(GhRhConveter.fromInterval2d(int2d.Value)); } if (o is UVInterval) { return(GhRhConveter.fromInterval2d((UVInterval)o)); } // basic stuff GH_Number num = o as GH_Number; if (num != null) { return(SpeckleConverter.fromNumber(num.Value)); } if (o is double || o is int) { return(SpeckleConverter.fromNumber((double)o)); } GH_Boolean bul = o as GH_Boolean; if (bul != null) { return(SpeckleConverter.fromBoolean(bul.Value)); } if (o is Boolean) { return(GhRhConveter.fromBoolean((bool)o)); } GH_String str = o as GH_String; if (str != null) { return(SpeckleConverter.fromString(str.Value)); } if (o is string) { return(SpeckleConverter.fromString((string)o)); } // simple geometry GH_Point point = o as GH_Point; if (point != null) { return(GhRhConveter.fromPoint(point.Value)); } if (o is Point3d) { return(GhRhConveter.fromPoint((Point3d)o)); } // added because when we assign user data to points they get converted to points. // the above comment does makes sense. check the sdk. if (o is Rhino.Geometry.Point) { return(GhRhConveter.fromPoint(((Rhino.Geometry.Point)o).Location)); } GH_Vector vector = o as GH_Vector; if (vector != null) { return(GhRhConveter.fromVector(vector.Value)); } if (o is Vector3d) { return(GhRhConveter.fromVector((Vector3d)o)); } GH_Plane plane = o as GH_Plane; if (plane != null) { return(GhRhConveter.fromPlane(plane.Value)); } if (o is Plane) { return(GhRhConveter.fromPlane((Plane)o)); } GH_Line line = o as GH_Line; if (line != null) { return(GhRhConveter.fromLine(line.Value)); } if (o is Line) { return(GhRhConveter.fromLine((Line)o)); } GH_Arc arc = o as GH_Arc; if (arc != null) { return(GhRhConveter.fromArc(arc.Value)); } if (o is Arc) { return(GhRhConveter.fromArc((Arc)o)); } GH_Circle circle = o as GH_Circle; if (circle != null) { return(GhRhConveter.fromCircle(circle.Value)); } if (o is Circle) { return(GhRhConveter.fromCircle((Circle)o)); } GH_Rectangle rectangle = o as GH_Rectangle; if (rectangle != null) { return(GhRhConveter.fromRectangle(rectangle.Value)); } if (o is Rectangle3d) { return(GhRhConveter.fromRectangle((Rectangle3d)o)); } GH_Box box = o as GH_Box; if (box != null) { return(GhRhConveter.fromBox(box.Value)); } if (o is Box) { return(GhRhConveter.fromBox((Box)o)); } // getting complex GH_Curve curve = o as GH_Curve; if (curve != null) { Polyline poly; if (curve.Value.TryGetPolyline(out poly)) { return(GhRhConveter.fromPolyline(poly)); } return(GhRhConveter.fromCurve(curve.Value, getEncoded, getAbstract)); } if (o is Polyline) { return(GhRhConveter.fromPolyline((Polyline)o)); } if (o is Curve) { return(GhRhConveter.fromCurve((Curve)o, getEncoded, getAbstract)); } GH_Surface surface = o as GH_Surface; if (surface != null) { return(GhRhConveter.fromBrep(surface.Value, getEncoded, getAbstract)); } GH_Brep brep = o as GH_Brep; if (brep != null) { return(GhRhConveter.fromBrep(brep.Value, getEncoded, getAbstract)); } if (o is Brep) { return(GhRhConveter.fromBrep((Brep)o, getEncoded, getAbstract)); } GH_Mesh mesh = o as GH_Mesh; if (mesh != null) { return(GhRhConveter.fromMesh(mesh.Value)); } if (o is Mesh) { return(GhRhConveter.fromMesh((Mesh)o)); } return(new SpeckleObject() { hash = "404", value = "Type not supported", type = "404" }); }
/*******************************************/ public static bool CastToGoo(object value, ref GH_Line target) { return(GH_Convert.ToGHLine(value, GH_Conversion.Both, ref target)); }
public static Response Grasshopper(NancyContext ctx) { // load grasshopper file var archive = new GH_Archive(); // TODO: stream to string var body = ctx.Request.Body.ToString(); string json = string.Empty; using (var reader = new StreamReader(ctx.Request.Body)) { json = reader.ReadToEnd(); } //GrasshopperInput input = Newtonsoft.Json.JsonConvert.DeserializeObject<GrasshopperInput>(json); //JsonSerializerSettings settings = new JsonSerializerSettings(); //settings.ContractResolver = new DictionaryAsArrayResolver(); Schema input = JsonConvert.DeserializeObject <Schema>(json); string grasshopperXml = string.Empty; if (input.Algo != null) { // If request contains markup byte[] byteArray = Convert.FromBase64String(input.Algo); grasshopperXml = System.Text.Encoding.UTF8.GetString(byteArray); } else { // If request contains pointer string pointer = input.Pointer; grasshopperXml = GetGhxFromPointer(pointer); } if (!archive.Deserialize_Xml(grasshopperXml)) { throw new Exception(); } var definition = new GH_Document(); if (!archive.ExtractObject(definition, "Definition")) { throw new Exception(); } // Set input params foreach (var obj in definition.Objects) { var group = obj as GH_Group; if (group == null) { continue; } if (group.NickName.Contains("RH_IN")) { // It is a RestHopper input group! GHTypeCodes code = (GHTypeCodes)Int32.Parse(group.NickName.Split(':')[1]); var param = group.Objects()[0]; //GH_Param<IGH_Goo> goo = obj as GH_Param<IGH_Goo>; // SetData foreach (Resthopper.IO.DataTree <ResthopperObject> tree in input.Values) { string paramname = tree.ParamName; if (group.NickName == paramname) { switch (code) { case GHTypeCodes.Boolean: //PopulateParam<GH_Boolean>(goo, tree); Param_Boolean boolParam = param as Param_Boolean; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Boolean> objectList = new List <GH_Boolean>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool boolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(boolean); boolParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Point: //PopulateParam<GH_Point>(goo, tree); Param_Point ptParam = param as Param_Point; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Point> objectList = new List <GH_Point>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Point3d rPt = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); GH_Point data = new GH_Point(rPt); ptParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Vector: //PopulateParam<GH_Vector>(goo, tree); Param_Vector vectorParam = param as Param_Vector; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Vector> objectList = new List <GH_Vector>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data); GH_Vector data = new GH_Vector(rhVector); vectorParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Integer: //PopulateParam<GH_Integer>(goo, tree); Param_Integer integerParam = param as Param_Integer; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Integer> objectList = new List <GH_Integer>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; int rhinoInt = JsonConvert.DeserializeObject <int>(restobj.Data); GH_Integer data = new GH_Integer(rhinoInt); integerParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Number: //PopulateParam<GH_Number>(goo, tree); Param_Number numberParam = param as Param_Number; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Number> objectList = new List <GH_Number>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); numberParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Text: //PopulateParam<GH_String>(goo, tree); Param_String stringParam = param as Param_String; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_String> objectList = new List <GH_String>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); stringParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Line: //PopulateParam<GH_Line>(goo, tree); Param_Line lineParam = param as Param_Line; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Line> objectList = new List <GH_Line>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Line rhLine = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); GH_Line data = new GH_Line(rhLine); lineParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Curve: //PopulateParam<GH_Curve>(goo, tree); Param_Curve curveParam = param as Param_Curve; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Curve> objectList = new List <GH_Curve>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; GH_Curve ghCurve; try { Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.PolylineCurve(data); ghCurve = new GH_Curve(c); } catch { Rhino.Geometry.NurbsCurve data = JsonConvert.DeserializeObject <Rhino.Geometry.NurbsCurve>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.NurbsCurve(data); ghCurve = new GH_Curve(c); } curveParam.AddVolatileData(path, i, ghCurve); } } break; case GHTypeCodes.Circle: //PopulateParam<GH_Circle>(goo, tree); Param_Circle circleParam = param as Param_Circle; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Circle> objectList = new List <GH_Circle>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data); GH_Circle data = new GH_Circle(rhCircle); circleParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.PLane: //PopulateParam<GH_Plane>(goo, tree); Param_Plane planeParam = param as Param_Plane; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Plane> objectList = new List <GH_Plane>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data); GH_Plane data = new GH_Plane(rhPlane); planeParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Rectangle: //PopulateParam<GH_Rectangle>(goo, tree); Param_Rectangle rectangleParam = param as Param_Rectangle; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Rectangle> objectList = new List <GH_Rectangle>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data); GH_Rectangle data = new GH_Rectangle(rhRectangle); rectangleParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Box: //PopulateParam<GH_Box>(goo, tree); Param_Box boxParam = param as Param_Box; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Box> objectList = new List <GH_Box>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Box rhBox = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data); GH_Box data = new GH_Box(rhBox); boxParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Surface: //PopulateParam<GH_Surface>(goo, tree); Param_Surface surfaceParam = param as Param_Surface; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Surface> objectList = new List <GH_Surface>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data); GH_Surface data = new GH_Surface(rhSurface); surfaceParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Brep: //PopulateParam<GH_Brep>(goo, tree); Param_Brep brepParam = param as Param_Brep; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Brep> objectList = new List <GH_Brep>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Brep rhBrep = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data); GH_Brep data = new GH_Brep(rhBrep); brepParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Mesh: //PopulateParam<GH_Mesh>(goo, tree); Param_Mesh meshParam = param as Param_Mesh; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Mesh> objectList = new List <GH_Mesh>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Mesh rhMesh = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data); GH_Mesh data = new GH_Mesh(rhMesh); meshParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Slider: //PopulateParam<GH_Number>(goo, tree); GH_NumberSlider sliderParam = param as GH_NumberSlider; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Number> objectList = new List <GH_Number>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); sliderParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.BooleanToggle: //PopulateParam<GH_Boolean>(goo, tree); GH_BooleanToggle toggleParam = param as GH_BooleanToggle; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Boolean> objectList = new List <GH_Boolean>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool rhBoolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(rhBoolean); toggleParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Panel: //PopulateParam<GH_String>(goo, tree); GH_Panel panelParam = param as GH_Panel; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Panel> objectList = new List <GH_Panel>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); panelParam.AddVolatileData(path, i, data); } } break; } } } } } Schema OutputSchema = new Schema(); OutputSchema.Algo = Utils.Base64Encode(string.Empty); // Parse output params foreach (var obj in definition.Objects) { var group = obj as GH_Group; if (group == null) { continue; } if (group.NickName.Contains("RH_OUT")) { // It is a RestHopper output group! GHTypeCodes code = (GHTypeCodes)Int32.Parse(group.NickName.Split(':')[1]); var param = group.Objects()[0] as IGH_Param; if (param == null) { continue; } try { param.CollectData(); param.ComputeData(); } catch (Exception) { param.Phase = GH_SolutionPhase.Failed; // TODO: throw something better throw; } // Get data Resthopper.IO.DataTree <ResthopperObject> OutputTree = new Resthopper.IO.DataTree <ResthopperObject>(); OutputTree.ParamName = group.NickName; var volatileData = param.VolatileData; for (int p = 0; p < volatileData.PathCount; p++) { List <ResthopperObject> ResthopperObjectList = new List <ResthopperObject>(); foreach (var goo in volatileData.get_Branch(p)) { if (goo == null) { continue; } else if (goo.GetType() == typeof(GH_Boolean)) { GH_Boolean ghValue = goo as GH_Boolean; bool rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <bool>(rhValue)); } else if (goo.GetType() == typeof(GH_Point)) { GH_Point ghValue = goo as GH_Point; Point3d rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Point3d>(rhValue)); } else if (goo.GetType() == typeof(GH_Vector)) { GH_Vector ghValue = goo as GH_Vector; Vector3d rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Vector3d>(rhValue)); } else if (goo.GetType() == typeof(GH_Integer)) { GH_Integer ghValue = goo as GH_Integer; int rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <int>(rhValue)); } else if (goo.GetType() == typeof(GH_Number)) { GH_Number ghValue = goo as GH_Number; double rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <double>(rhValue)); } else if (goo.GetType() == typeof(GH_String)) { GH_String ghValue = goo as GH_String; string rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <string>(rhValue)); } else if (goo.GetType() == typeof(GH_Line)) { GH_Line ghValue = goo as GH_Line; Line rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Line>(rhValue)); } else if (goo.GetType() == typeof(GH_Curve)) { GH_Curve ghValue = goo as GH_Curve; Curve rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Curve>(rhValue)); } else if (goo.GetType() == typeof(GH_Circle)) { GH_Circle ghValue = goo as GH_Circle; Circle rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Circle>(rhValue)); } else if (goo.GetType() == typeof(GH_Plane)) { GH_Plane ghValue = goo as GH_Plane; Plane rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Plane>(rhValue)); } else if (goo.GetType() == typeof(GH_Rectangle)) { GH_Rectangle ghValue = goo as GH_Rectangle; Rectangle3d rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Rectangle3d>(rhValue)); } else if (goo.GetType() == typeof(GH_Box)) { GH_Box ghValue = goo as GH_Box; Box rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Box>(rhValue)); } else if (goo.GetType() == typeof(GH_Surface)) { GH_Surface ghValue = goo as GH_Surface; Brep rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Brep>(rhValue)); } else if (goo.GetType() == typeof(GH_Brep)) { GH_Brep ghValue = goo as GH_Brep; Brep rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Brep>(rhValue)); } else if (goo.GetType() == typeof(GH_Mesh)) { GH_Mesh ghValue = goo as GH_Mesh; Mesh rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Mesh>(rhValue)); } } GhPath path = new GhPath(new int[] { p }); OutputTree.Add(path.ToString(), ResthopperObjectList); } OutputSchema.Values.Add(OutputTree); } } if (OutputSchema.Values.Count < 1) { throw new System.Exceptions.PayAttentionException("Looks like you've missed something..."); // TODO } string returnJson = JsonConvert.SerializeObject(OutputSchema); return(returnJson); }
public void SetInputs(List <DataTree <ResthopperObject> > values) { foreach (var tree in values) { if (!_input.TryGetValue(tree.ParamName, out var inputGroup)) { continue; } if (inputGroup.AlreadySet(tree)) { LogDebug("Skipping input tree... same input"); continue; } inputGroup.CacheTree(tree); IGH_ContextualParameter contextualParameter = inputGroup.Param as IGH_ContextualParameter; if (contextualParameter != null) { switch (ParamTypeName(inputGroup.Param)) { case "Number": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { double[] doubles = new double[entree.Value.Count]; for (int i = 0; i < doubles.Length; i++) { ResthopperObject restobj = entree.Value[i]; doubles[i] = JsonConvert.DeserializeObject <double>(restobj.Data); } contextualParameter.AssignContextualData(doubles); break; } } break; case "Integer": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { int[] integers = new int[entree.Value.Count]; for (int i = 0; i < integers.Length; i++) { ResthopperObject restobj = entree.Value[i]; integers[i] = JsonConvert.DeserializeObject <int>(restobj.Data); } contextualParameter.AssignContextualData(integers); break; } } break; case "Point": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { Point3d[] points = new Point3d[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; points[i] = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); } contextualParameter.AssignContextualData(points); break; } } break; case "Line": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { Line[] lines = new Line[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; lines[i] = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); } contextualParameter.AssignContextualData(lines); break; } } break; case "Text": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { string[] strings = new string[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; strings[i] = restobj.Data.Trim(new char[] { '"' }); } contextualParameter.AssignContextualData(strings); break; } } break; case "Geometry": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GeometryBase[] geometries = new GeometryBase[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data); geometries[i] = Rhino.Runtime.CommonObject.FromJSON(dict) as GeometryBase; } contextualParameter.AssignContextualData(geometries); break; } } break; } continue; } inputGroup.Param.VolatileData.Clear(); inputGroup.Param.ExpireSolution(false); // mark param as expired but don't recompute just yet! if (inputGroup.Param is Param_Point) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Point3d rPt = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); GH_Point data = new GH_Point(rPt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Vector) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data); GH_Vector data = new GH_Vector(rhVector); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Integer) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; int rhinoInt = JsonConvert.DeserializeObject <int>(restobj.Data); GH_Integer data = new GH_Integer(rhinoInt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Number) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_String) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = restobj.Data; GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Line) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Line rhLine = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); GH_Line data = new GH_Line(rhLine); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Curve) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; GH_Curve ghCurve; try { Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.PolylineCurve(data); ghCurve = new GH_Curve(c); } catch { var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data); var c = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict); ghCurve = new GH_Curve(c); } inputGroup.Param.AddVolatileData(path, i, ghCurve); } } continue; } if (inputGroup.Param is Param_Circle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data); GH_Circle data = new GH_Circle(rhCircle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Plane) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data); GH_Plane data = new GH_Plane(rhPlane); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Rectangle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data); GH_Rectangle data = new GH_Rectangle(rhRectangle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Box) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Box rhBox = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data); GH_Box data = new GH_Box(rhBox); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Surface) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data); GH_Surface data = new GH_Surface(rhSurface); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Brep) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Brep rhBrep = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data); GH_Brep data = new GH_Brep(rhBrep); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Mesh) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Mesh rhMesh = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data); GH_Mesh data = new GH_Mesh(rhMesh); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_NumberSlider) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool boolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(boolean); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_Panel) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } } }
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) { Object ghGeometryBase = null; double tolerance = 0.0001; if (!DA.GetData(0, ref ghGeometryBase)) { return; } if (!DA.GetData(1, ref tolerance)) { return; } if (ghGeometryBase == null) { return; } Type type = ghGeometryBase.GetType(); Topologic.Topology topology = null; GH_Point ghPoint = ghGeometryBase as GH_Point; if (ghPoint != null) { topology = ByPoint(ghPoint.Value); DA.SetData(0, topology); return; } GH_Line ghLine = ghGeometryBase as GH_Line; if (ghLine != null) { topology = ByLine(ghLine.Value); DA.SetData(0, topology); return; } GH_Curve ghCurve = ghGeometryBase as GH_Curve; if (ghCurve != null) { topology = ByCurve(ghCurve.Value); DA.SetData(0, topology); return; } GH_Surface ghSurface = ghGeometryBase as GH_Surface; if (ghSurface != null) { //topology = ByBrep(ghSurface.Value.Faces[0].ToBrep(), tolerance); //topology = ByBrepFace(ghSurface.Value.Faces[0]); topology = ByBrep(ghSurface.Value, tolerance); DA.SetData(0, topology); return; } GH_Brep ghBrep = ghGeometryBase as GH_Brep; if (ghBrep != null) { topology = ByBrep(ghBrep.Value, tolerance); DA.SetData(0, topology); return; } GH_Box ghBox = ghGeometryBase as GH_Box; if (ghBox != null) { topology = ByBox(ghBox.Value); DA.SetData(0, topology); return; } GH_Mesh ghMesh = ghGeometryBase as GH_Mesh; if (ghMesh != null) { topology = ByMesh(ghMesh.Value); DA.SetData(0, topology); return; } //BrepLoop ghBrepLoop = ghGeometryBase as BrepLoop; //if (ghBrepLoop != null) //{ // topology = ByBrepLoop(ghBrepLoop); // DA.SetData(0, topology); // return; //} throw new Exception("This type of geometry is not yet supported."); }
public SilkwormMovement(Dictionary <string, string> Settings, List <Line> lines) { double eLengthAll = 0; double fTimeAll = 0; SilkwormCalculator calc = new SilkwormCalculator(Settings); //Core Default Settings for extrusion flow and speed generated in here #region Build Silkworm Model from Geometry and Printer Settings //Output Holder List <SilkwormLine> sLines = new List <SilkwormLine>(); for (int i = 0; i < lines.Count; i++) { GH_Line sMove = new GH_Line(lines[i]); //if((GH_Line)MInnerArray[j-1] = null){return ;} GH_Line sMove_1 = new GH_Line(); if (i == 0) { sMove_1 = new GH_Line(lines[i]); } else { sMove_1 = new GH_Line(lines[i - 1]); } #region Extrusion Flow Module /* * Some Extrusion Calculation Guidelines (from Josef Prusa's Calculator: http://calculator.josefprusa.cz/) *-- WOH smaller than 2.0 produces weak parts * --WOH bigger than 3 decreases the detail of printed part, because of thick line * * layer height (LH)= height of each printed layer above the previous * width over height (WOH) = line width/ layer height * free extrusion diameter (extDia) = nozzle diamter + 0.08mm * line width (LW) = LH * WOH * free extrusion cross section area (freeExt) = (extDia/2)*(extDia/2)*Math.PI * minimal extrusion cross section area for stable extrusion (minExt) = freeExt*0.5 * Extruded line cross section area (extLine) = extLine = LW * LH; * Suggested bridge flow-rate multiplier = (freeExt*0.7)/extLine * Predicted smallest feature printable in XY = lineWidth/2 * angleHelp = Math.sqrt((lineWidth/2)*(lineWidth/2)+LH*LH) * angleHelp = Math.asin((lineWidth/2)/angleHelp) * Predicted maximim overhang angle = angleHelp * (180/Math.PI) */ double nozDia = double.Parse(Settings["nozzle_diameter"]); double filDia = double.Parse(Settings["filament_diameter"]); //Calculate Flow Rate as a Ratio of Filament Diameter to Nozzle Diameter double FlM = ((Math.Pow(nozDia / 2, 2) * Math.PI) / (Math.Pow(filDia / 2, 2) * Math.PI)); //double FlM = 0.66; #endregion #region Print Feedrate Module Line line = sMove.Value; Line line_1 = sMove_1.Value; Vector3d vecA = line.Direction; Vector3d vecA_1 = line_1.Direction; Arc arc = new Rhino.Geometry.Arc(line_1.From, vecA_1, line.To); //double vecAngle = Rhino.Geometry.Vector3d.VectorAngle(vecA, vecA_1); //Speed on an Arc = sqrt((Accel * Radius) / sqrt(2)) double accel = double.Parse(Settings["perimeter_acceleration"]); double fRate = ( Math.Max( Math.Min( Math.Sqrt((accel * arc.Radius) / (Math.Sqrt(2))), double.Parse(Settings["perimeter_speed"])), double.Parse(Settings["min_print_speed"])) * 60); //Start speed as perimeter speed if (i == 0) { fRate = double.Parse(Settings["perimeter_speed"]) * 60; } #endregion sLines.Add(new SilkwormLine(FlM, fRate, line)); } #endregion //Property Assignment sMovement = sLines; Length = eLengthAll; Time = fTimeAll; ZDomain = new Interval(sLines[0].sLine.FromZ, sLines[sLines.Count - 1].sLine.ToZ); complete = true; Configuration = Settings; //Add Lift Delimiter sDelimiter = new Type.Delimiter( double.Parse(Settings["retract_lift"]), double.Parse(Settings["retract_length"]), double.Parse(Settings["retract_restart_extra"]), double.Parse(Settings["retract_speed"]), double.Parse(Settings["travel_speed"])); }
public void SetInputs(List <DataTree <ResthopperObject> > values) { foreach (var tree in values) { if (!_input.TryGetValue(tree.ParamName, out var inputGroup)) { continue; } if (inputGroup.AlreadySet(tree)) { Console.WriteLine("Skipping input tree... same input"); continue; } inputGroup.CacheTree(tree); inputGroup.Param.VolatileData.Clear(); inputGroup.Param.ExpireSolution(true); if (inputGroup.Param is Param_Point) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Point3d rPt = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); GH_Point data = new GH_Point(rPt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Vector) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data); GH_Vector data = new GH_Vector(rhVector); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Integer) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; int rhinoInt = JsonConvert.DeserializeObject <int>(restobj.Data); GH_Integer data = new GH_Integer(rhinoInt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Number) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_String) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = restobj.Data; GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Line) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Line rhLine = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); GH_Line data = new GH_Line(rhLine); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Curve) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; GH_Curve ghCurve; try { Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.PolylineCurve(data); ghCurve = new GH_Curve(c); } catch { var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data); var c = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict); ghCurve = new GH_Curve(c); } inputGroup.Param.AddVolatileData(path, i, ghCurve); } } continue; } if (inputGroup.Param is Param_Circle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data); GH_Circle data = new GH_Circle(rhCircle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Plane) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data); GH_Plane data = new GH_Plane(rhPlane); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Rectangle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data); GH_Rectangle data = new GH_Rectangle(rhRectangle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Box) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Box rhBox = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data); GH_Box data = new GH_Box(rhBox); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Surface) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data); GH_Surface data = new GH_Surface(rhSurface); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Brep) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Brep rhBrep = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data); GH_Brep data = new GH_Brep(rhBrep); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Mesh) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Mesh rhMesh = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data); GH_Mesh data = new GH_Mesh(rhMesh); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_NumberSlider) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool boolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(boolean); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_Panel) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } } }
protected override void SolveInstance(IGH_DataAccess DA) { counter++; DA.GetData(1, ref n); n = Math.Max(1, n); if (counter % n == 0) { Flex flex = null; bool drawP = true; List <SpringSystem> springs = new List <SpringSystem>(); DA.GetData(0, ref flex); DA.GetData(2, ref drawP); DA.GetDataList(3, springs); if (flex != null) { List <FlexParticle> part = flex.Scene.GetSpringParticles(); if (drawP) { pts = new GH_Structure <GH_Point>(); vel = new GH_Structure <GH_Vector>(); foreach (FlexParticle fp in part) { GH_Path p = new GH_Path(fp.GroupIndex); pts.Append(new GH_Point(new Point3d(fp.PositionX, fp.PositionY, fp.PositionZ)), p); vel.Append(new GH_Vector(new Vector3d(fp.VelocityX, fp.VelocityY, fp.VelocityZ)), p); } } else { pts = new GH_Structure <GH_Point>(); vel = new GH_Structure <GH_Vector>(); } if (springs.Count > 0) { lns = new GH_Structure <GH_Line>(); msh = new GH_Structure <GH_Mesh>(); foreach (SpringSystem ss in springs) { GH_Path p = new GH_Path(ss.GroupIndex); if (ss.HasMesh()) { for (int i = 0; i < ss.Mesh.Vertices.Count; i++) { ss.Mesh.TopologyVertices[i] = new Point3f(part[i + ss.SpringOffset].PositionX, part[i + ss.SpringOffset].PositionY, part[i + ss.SpringOffset].PositionZ); } msh.Append(new GH_Mesh(ss.Mesh), p); } if (!ss.HasMesh() || ss.IsSheetMesh) { for (int i = 0; i < ss.SpringPairIndices.Length / 2; i++) { GH_Line l = new GH_Line( new Line( new Point3d( part[ss.SpringPairIndices[i * 2] + ss.SpringOffset].PositionX, part[ss.SpringPairIndices[i * 2] + ss.SpringOffset].PositionY, part[ss.SpringPairIndices[i * 2] + ss.SpringOffset].PositionZ), new Point3d( part[ss.SpringPairIndices[i * 2 + 1] + ss.SpringOffset].PositionX, part[ss.SpringPairIndices[i * 2 + 1] + ss.SpringOffset].PositionY, part[ss.SpringPairIndices[i * 2 + 1] + ss.SpringOffset].PositionZ))); lns.Append(l, p); } } } } } } DA.SetDataTree(0, pts); DA.SetDataTree(1, vel); DA.SetDataTree(2, lns); DA.SetDataTree(3, msh); }