public static Sm.DrawingGroup ToGeometryGroup(this Drawing input) { Sm.DrawingGroup drawings = new Sm.DrawingGroup(); double scale = input.GetScale(); Rg.Curve curve = input.Frame.ToNurbsCurve(); double x0 = input.Frame.Center.X - input.Width / scale / 2; double x1 = input.Frame.Center.X + input.Width / scale / 2; double y0 = input.Frame.Center.Y - input.Height / scale / 2; double y1 = input.Frame.Center.Y + input.Height / scale / 2; Rg.Rectangle3d rect = new Rg.Rectangle3d(Rg.Plane.WorldXY, new Rg.Point3d(x0, y0, 0), new Rg.Point3d(x1, y1, 0)); drawings.Children.Add(new Shape(rect.ToNurbsCurve(), new Wg.Graphic(Wg.Strokes.Transparent, new Wg.Fill(input.Background))).ToGeometryDrawing()); foreach (Shape shape in input.Shapes) { drawings.Children.Add(shape.ToGeometryDrawing()); } drawings.ClipGeometry = input.Frame.ToPolyline().ToGeometry(); Sm.TransformGroup xform = new Sm.TransformGroup(); xform.Children.Add(new Sm.TranslateTransform(input.Frame.Center.X - input.Width / 2, input.Frame.Center.Y - input.Height / 2)); xform.Children.Add(new Sm.ScaleTransform(1, -1)); drawings.Transform = xform; return(drawings); }
public static Sm.DrawingVisual ToGeometryVisual(this Drawing input) { Sm.DrawingVisual drawings = new Sm.DrawingVisual(); double scale = input.GetScale(); Rg.Curve curve = input.Frame.ToNurbsCurve(); double x0 = input.Frame.Center.X - input.Width / scale / 2; double x1 = input.Frame.Center.X + input.Width / scale / 2; double y0 = input.Frame.Center.Y - input.Height / scale / 2; double y1 = input.Frame.Center.Y + input.Height / scale / 2; Rg.Rectangle3d rect = new Rg.Rectangle3d(Rg.Plane.WorldXY, new Rg.Point3d(x0, y0, 0), new Rg.Point3d(x1, y1, 0)); drawings.Children.Add(new Shape(rect.ToNurbsCurve(), new Wg.Graphic(Wg.Strokes.Transparent, new Wg.Fill(input.Background))).ToVisualDrawing()); foreach (Shape shape in input.Shapes) { drawings.Children.Add(shape.ToVisualDrawing()); } Sm.TransformGroup xform = new Sm.TransformGroup(); double shiftW = (input.Width / scale / 2 - input.Frame.Center.X); double shiftH = -(input.Height / scale / 2 + input.Frame.Center.Y); xform.Children.Add(new Sm.TranslateTransform(shiftW, shiftH)); xform.Children.Add(new Sm.ScaleTransform(scale, (-1) * scale)); drawings.Transform = xform; return(drawings); }
public static System.Drawing.Rectangle ToDrawingRect(this Rg.Rectangle3d input, int transposition = 0) { if (transposition > 0) { return(new System.Drawing.Rectangle((int)input.Corner(0).X, (int)(transposition - input.Corner(3).Y), (int)input.Width, (int)input.Height)); } return(new System.Drawing.Rectangle((int)input.Corner(0).X, (int)input.Corner(0).Y, (int)input.Width, (int)input.Height)); }
/// <summary> /// Returns a Windows Shapes Path from a Rhinocommon Rectangle /// </summary> /// <param name="input">Rhinocommon Rectangle</param> /// <returns>System Windows Shapes Path</returns> public static Sh.Path ToPath(this Rg.Rectangle3d input) { Sh.Path path = new Sh.Path(); path.Data = input.ToGeometry(); return(path); }
/// <summary> /// Returns a Windows Media Rect from a Rhinocommon Rectangle /// </summary> /// <param name="input">Rhinocommon Rectangle</param> /// <returns>System Windows Media Rect</returns> public static Sm.RectangleGeometry ToGeometry(this Rg.Rectangle3d input) { Sw.Point center = input.Center.ToWindowsPoint(); double angle = Rg.Vector3d.VectorAngle(Rg.Vector3d.YAxis, input.Plane.YAxis, Rg.Plane.WorldXY); Sm.Transform xform = new Sm.RotateTransform(angle, center.X, center.Y); Sw.Rect rect = new Sw.Rect(center.X - input.Width / 2, center.Y + input.Height / 2, input.Width, input.Height); return(new Sm.RectangleGeometry(rect, 0, 0, xform)); }
public static Sm.Geometry ToGeometry(this Geometry input) { Sm.Geometry geometry = null; switch (input.CurveType) { case Geometry.CurveTypes.Arc: Rg.Arc arc = new Rg.Arc(); input.Curve.TryGetArc(out arc); geometry = arc.ToGeometry(); break; case Geometry.CurveTypes.Circle: Rg.Circle circle = new Rg.Circle(); input.Curve.TryGetCircle(out circle); geometry = circle.ToGeometry(); break; case Geometry.CurveTypes.Ellipse: Rg.Ellipse ellipse = new Rg.Ellipse(); input.Curve.TryGetEllipse(out ellipse); geometry = ellipse.ToGeometry(); break; case Geometry.CurveTypes.Line: Rg.Line line = new Rg.Line(input.Curve.PointAtStart, input.Curve.PointAtEnd); geometry = line.ToGeometry(); break; case Geometry.CurveTypes.Polyline: Rg.Polyline polyline = new Rg.Polyline(); input.Curve.TryGetPolyline(out polyline); geometry = polyline.ToGeometry(); break; case Geometry.CurveTypes.Rectangle: Rg.Polyline pline = new Rg.Polyline(); input.Curve.TryGetPolyline(out pline); Rg.Rectangle3d rectangle = new Rg.Rectangle3d(Rg.Plane.WorldXY, pline[0], pline[2]); geometry = rectangle.ToGeometry(); break; default: geometry = input.Curve.ToGeometry(); break; } return(geometry); }
private static void ComputeDeviation(Rectangle3d rec, Rhino.Collections.Point3dList pts, out double dev, out double angdev) { dev = double.MaxValue; for (int i = 0; i < 4; i++) { dev = Math.Min(dev, rec.Corner(i).DistanceTo(pts[i])); } angdev = double.MaxValue; for (int i = 0; i < 4; i++) { int j = (i == 3) ? 0 : i + 1; Vector3d re = rec.Corner(i) - rec.Corner(j); Vector3d pe = pts[i] - pts[j]; double ad = Vector3d.VectorAngle(re, pe); if (RhinoMath.IsValidDouble(ad)) { angdev = Math.Min(angdev, ad); } } }
/// <summary> /// Attempts to create a Rectangle from a Polyline. In order for a polyline to qualify /// as a rectangle, it must have 4 or 5 corner points (i.e. it need not be closed). /// <para>This overload also returns deviations.</para> /// </summary> /// <param name="polyline">Polyline to parse.</param> /// <param name="deviation">On success, the deviation will contain the largest deviation between the polyline and the rectangle.</param> /// <param name="angleDeviation">On success, the angleDeviation will contain the largest deviation (in radians) between the polyline edges and the rectangle edges.</param> /// <returns>A rectangle that is shaped similarly to the polyline or Rectangle3d.Unset /// if the polyline does not represent a rectangle.</returns> public static Rectangle3d CreateFromPolyline(IEnumerable<Point3d> polyline, out double deviation, out double angleDeviation) { if (polyline == null) { throw new ArgumentNullException("polyline"); } deviation = 0.0; angleDeviation = 0.0; Rhino.Collections.Point3dList pts = new Rhino.Collections.Point3dList(5); foreach (Point3d pt in polyline) { pts.Add(pt); if (pts.Count > 5) { return Rectangle3d.Unset; } } if (pts.Count < 4) { return Rectangle3d.Unset; } if (pts.Count == 5) { pts.RemoveAt(4); } Vector3d AB = pts[1] - pts[0]; Vector3d DC = pts[2] - pts[3]; Vector3d AD = pts[3] - pts[0]; Vector3d BC = pts[2] - pts[1]; Vector3d x = AB + DC; Vector3d y = AD + BC; if (x.IsZero && y.IsZero) { Rectangle3d null_rec = new Rectangle3d(new Plane(pts[0], Vector3d.XAxis, Vector3d.YAxis), 0.0, 0.0); ComputeDeviation(null_rec, pts, out deviation, out angleDeviation); return null_rec; } if (x.IsZero) { x.PerpendicularTo(y); } if (y.IsZero) { y.PerpendicularTo(x); } if (!x.Unitize()) { return Rectangle3d.Unset; } if (!y.Unitize()) { return Rectangle3d.Unset; } Rectangle3d rc = new Rectangle3d(); rc.m_plane = new Plane(pts[0], x, y); rc.m_x = new Interval(0, 0.5 * (AB.Length + DC.Length)); rc.m_y = new Interval(0, 0.5 * (AD.Length + BC.Length)); ComputeDeviation(rc, pts, out deviation, out angleDeviation); return rc; }
protected override void SolveInstance(IGH_DataAccess DA) { List<DHr> hours = new List<DHr>(); List<String> keys = new List<string>(); if (DA.GetDataList(0, hours) && DA.GetDataList(1, keys)) { if ((hours[0].is_surrogate) && ((hours.Count != 1) && (hours.Count != 12) && (hours.Count != 52) && (hours.Count != 365))) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "This component can only plot unmasked surrogate hours for yearly, monthly, weekly, and daily statistics"); } Interval ival_y = new Interval(); bool calc_ival_y = false; if (!(DA.GetData(2, ref ival_y))) { ival_y.T0 = hours[0].val(keys[0]); ival_y.T1 = hours[0].val(keys[0]); calc_ival_y = true; } Dictionary<string, float[]> val_dict = new Dictionary<string, float[]>(); List<Interval> val_ranges = new List<Interval>(); foreach (string key in keys) { Interval ival = new Interval(); float[] vals = new float[0]; DHr.get_domain(key, hours.ToArray(), ref vals, ref ival); vals = new float[hours.Count]; for (int h = 0; h < hours.Count; h++) vals[h] = hours[h].val(key); val_dict.Add(key, vals); val_ranges.Add(ival); } bool force_start_at_zero = true; int stack_dir = StackDirection(val_ranges[0]); if (stack_dir==0) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The first key returned nothing but zero values. I can't deal!"); foreach (Interval ival in val_ranges) { if (StackDirection(ival) != stack_dir) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "A stacked graph can only handle all negative or all positive numbers."); if (calc_ival_y) { if (stack_dir < 1) { if (ival.T1 > ival_y.T0) ival_y.T0 = ival.T1; if (ival.T0 < ival_y.T1) ival_y.T1 = ival.T0; } else { if (ival.T0 < ival_y.T0) ival_y.T0 = ival.T0; if (ival.T1 > ival_y.T1) ival_y.T1 = ival.T1; } } } if (force_start_at_zero && calc_ival_y) ival_y.T0 = 0; Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval> intervalTreeOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval>(); intervalTreeOut.Append(new Grasshopper.Kernel.Types.GH_Interval(ival_y),new Grasshopper.Kernel.Data.GH_Path(0)); foreach (Interval ival in val_ranges) intervalTreeOut.Append(new Grasshopper.Kernel.Types.GH_Interval(ival), new Grasshopper.Kernel.Data.GH_Path(1)); Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)); DA.GetData(3, ref plane); Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval(); if (!DA.GetData(4, ref ival2d)) { ival2d.U0 = 0.0; ival2d.U1 = 12.0; ival2d.V0 = 0.0; ival2d.V1 = 1.0; } double barWidth = 1.0; DA.GetData(5, ref barWidth); Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>(); Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point> pointTreeOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point>(); Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle> rectTreeOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle>(); List<Point3d> basepoints = new List<Point3d>(); for (int h = 0; h < hours.Count; h++) { Point3d gpt = GraphPoint(hours[h].hr, 0.0f, plane, ival_y, ival2d); Point3d wpt = plane.PointAt(gpt.X, 0.0); basepoints.Add(wpt); } for (int k = 0; k < keys.Count; k++) { Grasshopper.Kernel.Data.GH_Path key_path = new Grasshopper.Kernel.Data.GH_Path(k); List<Point3d> points = new List<Point3d>(); List<Rectangle3d> rects = new List<Rectangle3d>(); for (int h = 0; h < hours.Count; h++) { float val = val_dict[keys[k]][h]; for (int kk = 0; kk < k; kk++) val += val_dict[keys[kk]][h]; // add in all previous values Point3d gpt = GraphPoint(hours[h].hr, val, plane, ival_y, ival2d); // returns a point in graph coordinates hours[h].pos = gpt; // the hour records the point in graph coordinates hourTreeOut.Append(new DHr(hours[h]), key_path); Point3d wpt = plane.PointAt(gpt.X, gpt.Y); points.Add(wpt); // adds this point in world coordinates Interval ival_gx; // interval of horz space occupied by this hour in graphic units Interval ival_gy = new Interval(ival2d.V0, gpt.Y); // interval of vertical space occupied by this hour in graphic units if (!hours[h].is_surrogate) { double delta_x2 = (Math.Abs(ival2d.U.Length) / 8760 / 2.0); ival_gx = new Interval(gpt.X - delta_x2, gpt.X + delta_x2); // interval of horz space occupied by this hour in graphic units } else { // if we've been passed surrogate hours, the spacing between bars may not be consistant // we assume we've been given an hour at the start of the range represented double ival_gx_0 = gpt.X; double ival_gx_1; if (h < hours.Count - 1) { Point3d pt_next = GraphPoint(hours[h + 1].hr, val_dict[keys[k]][h + 1], plane, ival_y, ival2d); ival_gx_1 = gpt.X + (pt_next.X - gpt.X) * barWidth; } else { ival_gx_1 = gpt.X + (ival2d.U1 - gpt.X) * barWidth; } ival_gx = new Interval(ival_gx_0, ival_gx_1); if (hours.Count == 1) ival_gx = ival2d.U; } Rectangle3d rect = new Rectangle3d(plane, ival_gx, ival_gy); rects.Add(rect); } List<Grasshopper.Kernel.Types.GH_Point> gh_points = new List<Grasshopper.Kernel.Types.GH_Point>(); foreach (Point3d pt in points) gh_points.Add(new Grasshopper.Kernel.Types.GH_Point(pt)); pointTreeOut.AppendRange(gh_points, key_path); List<Grasshopper.Kernel.Types.GH_Rectangle> gh_rects = new List<Grasshopper.Kernel.Types.GH_Rectangle>(); foreach (Rectangle3d rec in rects) gh_rects.Add(new Grasshopper.Kernel.Types.GH_Rectangle(rec)); rectTreeOut.AppendRange(gh_rects, key_path); } DA.SetDataTree(0, hourTreeOut); DA.SetDataTree(1, intervalTreeOut); DA.SetDataTree(2, pointTreeOut); DA.SetDataList(3, basepoints); DA.SetDataTree(4, rectTreeOut); } }
protected override void SolveInstance(IGH_DataAccess DA) { Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeIn = new Grasshopper.Kernel.Data.GH_Structure<DHr>(); if (DA.GetDataTree(0, out hourTreeIn)) { Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)); DA.GetData(1, ref plane); Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval(); if (!DA.GetData(2, ref ival2d)) { ival2d.U0 = 0.0; ival2d.U1 = 1.0; ival2d.V0 = 0.0; ival2d.V1 = 2.0; } if (ival2d.U.IsDecreasing) ival2d.U.Swap(); if (ival2d.V.IsDecreasing) ival2d.V.Swap(); double barWidthScale = 1.0; DA.GetData(3, ref barWidthScale); Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>(); Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point> points = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point>(); Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle> srects = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle>(); List<Rectangle3d> rects = new List<Rectangle3d>(); List<Mesh> meshes = new List<Mesh>(); int i = 0;//keeps track of which branch we're on... note, this assumes we've been passed a list of lists and nothing 'deeper' int maxHourCount = hourTreeIn.Branches[0].Count; foreach (List<DHr> hourList in hourTreeIn.Branches) if (hourList.Count > maxHourCount) maxHourCount = hourList.Count; Rectangle3d brect = new Rectangle3d(plane, new Interval(0, ival2d.U1), new Interval(0, ival2d.V.ParameterAt((double)hourTreeIn.DataCount / maxHourCount))); DA.SetData(5, brect); double dx = ival2d.U.Length / hourTreeIn.Branches.Count * barWidthScale; double dy = ival2d.V.Length / maxHourCount; foreach (List<DHr> hourList in hourTreeIn.Branches) { Grasshopper.Kernel.Data.GH_Path path = new Grasshopper.Kernel.Data.GH_Path(i); hourTreeOut.EnsurePath(path); points.EnsurePath(path); srects.EnsurePath(path); double x = ival2d.U.ParameterAt((i + 0.5) / hourTreeIn.Branches.Count); for (int j = 0; j < hourList.Count; j++) { DHr dhour = hourList[j]; double y = ival2d.V.ParameterAt((j + 0.5) / maxHourCount); Point3d pt = plane.PointAt(x, y); dhour.pos = new Point3d(x, y, 0); points.Append(new Grasshopper.Kernel.Types.GH_Point(pt), path); hourTreeOut.Append(dhour, path); Plane pln = new Plane(plane); pln.Origin = plane.PointAt(x - dx / 2, y - dy / 2); Rectangle3d rct = new Rectangle3d(pln, dx, dy); srects.Append(new Grasshopper.Kernel.Types.GH_Rectangle(rct), path); } // make meshes & big rectangles if (hourList.Count > 0) { Mesh mesh = new Mesh(); // add bottom pts mesh.Vertices.Add(plane.PointAt(x - dx / 2, 0)); mesh.VertexColors.Add(hourList[0].color); mesh.Vertices.Add(plane.PointAt(x + dx / 2, 0)); mesh.VertexColors.Add(hourList[0].color); for (int j = 0; j < hourList.Count; j++) { double y = ival2d.V.ParameterAt((j + 0.5) / maxHourCount); mesh.Vertices.Add(plane.PointAt(x - dx / 2, y)); mesh.VertexColors.Add(hourList[j].color); mesh.Vertices.Add(plane.PointAt(x + dx / 2, y)); mesh.VertexColors.Add(hourList[j].color); } // add top pts double yy = ival2d.V.ParameterAt((float)hourList.Count / maxHourCount); mesh.Vertices.Add(plane.PointAt(x - dx / 2, yy)); mesh.VertexColors.Add(hourList[hourList.Count - 1].color); mesh.Vertices.Add(plane.PointAt(x + dx / 2, yy)); mesh.VertexColors.Add(hourList[hourList.Count - 1].color); for (int n = 2; n < mesh.Vertices.Count; n = n + 2) mesh.Faces.AddFace(n - 2, n - 1, n + 1, n); meshes.Add(mesh); Plane pln = new Plane(plane); pln.Origin = plane.PointAt(x - dx / 2, 0); Rectangle3d rct = new Rectangle3d(pln, dx, yy); rects.Add(rct); } i++; } DA.SetDataTree(0, hourTreeOut); DA.SetDataTree(1, points); DA.SetDataList(2, srects); DA.SetDataList(3, rects); DA.SetDataList(4, meshes); } }
protected override void SolveInstance(IGH_DataAccess DA) { Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeIn = new Grasshopper.Kernel.Data.GH_Structure<DHr>(); String key = ""; if (DA.GetDataTree(0, out hourTreeIn) && DA.GetData(1, ref key)) { Interval ival_y = new Interval(); float[] garbage = new float[0]; if (!(DA.GetData(2, ref ival_y))) DHr.get_domain(key, hourTreeIn.ToArray(), ref garbage, ref ival_y); // vals are no good here, we would need a tree of values Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)); DA.GetData(3, ref plane); Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval(); if (!DA.GetData(4, ref ival2d)) { ival2d.U0 = 0.0; ival2d.U1 = 12.0; ival2d.V0 = 0.0; ival2d.V1 = 1.0; } double barWidth = 1.0; DA.GetData(5, ref barWidth); Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>(); Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point> points = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point>(); Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle> rects = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle>(); double ival2d_u_delta = ival2d.U.Length / hourTreeIn.Branches.Count; for (int b = 0; b < hourTreeIn.Branches.Count; b++) { List<DHr> hours = hourTreeIn.Branches[b]; Grasshopper.Kernel.Data.GH_Path path = new Grasshopper.Kernel.Data.GH_Path(b); hourTreeOut.EnsurePath(path); points.EnsurePath(path); rects.EnsurePath(path); Grasshopper.Kernel.Types.UVInterval ival2d_sub = new Grasshopper.Kernel.Types.UVInterval(new Interval(b * ival2d_u_delta, (b + 1) * ival2d_u_delta), ival2d.V); double t0_sub = ival2d_sub.U.Mid - (ival2d_sub.U.Mid - ival2d_sub.U.T0) * barWidth; double t1_sub = ival2d_sub.U.Mid + (ival2d_sub.U.T1 - ival2d_sub.U.Mid) * barWidth; ival2d_sub.U = new Interval(t0_sub, t1_sub); for (int h = 0; h < hours.Count; h++) { Point3d gpt = GraphPoint(hours[h].hr % 24, hours[h].val(key), plane, ival_y, ival2d_sub); // returns a point in graph coordinates hours[h].pos = gpt; // the hour records the point in graph coordinates hourTreeOut.Append(hours[h], path); Point3d wpt = plane.PointAt(gpt.X, gpt.Y); points.Append(new Grasshopper.Kernel.Types.GH_Point(wpt), path); // adds this point in world coordinates double delta_x2 = (Math.Abs(ival2d_sub.U.Length) / 24.0 / 2.0); Interval ival_gx = new Interval(gpt.X - delta_x2, gpt.X + delta_x2); // interval of horz space occupied by this hour in graphic units Interval ival_gy = new Interval(ival2d_sub.V0, gpt.Y); // interval of vertical space occupied by this hour in graphic units Rectangle3d rect = new Rectangle3d(plane, ival_gx, ival_gy); rects.Append(new Grasshopper.Kernel.Types.GH_Rectangle(rect), path); } } DA.SetDataTree(0, hourTreeOut); DA.SetDataTree(1, points); DA.SetDataTree(2, rects); } }
public Drawing(List <Shape> shapes, Rh.Rectangle3d frame) { this.Shapes = shapes; this.frame = frame; }
public static string ToSVG(this Rg.Rectangle3d input) { return("M " + input.Corner(0).ToSVG() + input.Corner(1).ToSVG() + input.Corner(2).ToSVG() + input.Corner(3).ToSVG() + input.Corner(0).ToSVG() + " "); }
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); }
/***************************************************/ private static BHG.Polyline FromRhino(this RHG.Rectangle3d rectangle) { return(FromRhino(rectangle.ToPolyline())); }
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; } } }
public void ReComputeShape() { //Shape Rhino.Geometry.Point3d origin = originVec.ToRhino(); _shapedGrid.Compute(gridSize, x_Ex, y_Ex, offsetValue, offsetValue2, maxReduceNum, minGridNum, origin, ref shapedGrid, ref shape, ref offsetShape, ref originalShape); if (Rhino.Geometry.AreaMassProperties.Compute(offsetShape.ToPolylineCurve()).Area < (Rhino.Geometry.AreaMassProperties.Compute(shape).Area / 2f)) { ReComputeShape(); Debug.Log("Failed RecomputeShape and start RecomputeShape again"); return; } _areaRatio.Compute(shape, minAreaRatio, roomNum, ref areaSize, ref areaRatio); targetAreaSize = areaSize.ToIntList(); if (debug) { debugPreview.Add(RhinoPreview.PtsShow(shapedGrid, gridSize, Color.white)); } if (show) { if (polyLines.Count != 0) { foreach (var line in polyLines) { Destroy(line); } } polyLines.Add(RhinoPreview.PolyLineShow(shape.ToPolyline(), Color.cyan, 0.3f, "shape")); polyLines.Add(RhinoPreview.PolyLineShow(offsetShape, Color.blue, 0.3f, "offsetShape")); polyLines.Add(RhinoPreview.PolyLineShow(originalShape.ToPolyline(), Color.gray, 0.3f, "originalShape")); } // make first agent position var center = Rhino.Geometry.AreaMassProperties.Compute(shape).Centroid; rectMin = RhinoWrapper.MakeRect(center, gridSize, gridSize); var areaCenters = RhinoWrapper.RandomPt(rectMin, roomNum); if (debug) { debugPreview.Add(RhinoPreview.PolyLineShow(rectMin.ToPolyline(), Color.green, 0.3f, "minRect")); debugPreview.Add(RhinoPreview.PtsShow(areaCenters, gridSize, Color.black)); var centersList = new List <Rhino.Geometry.Point3d>(); centersList.Add(center); debugPreview.Add(RhinoPreview.PtsShow(centersList, gridSize, Color.magenta)); } //relax agent position minDist = (int)Math.Ceiling(Math.Sqrt(2) * gridSize) * (minGridNum + 1); _relax.Compute(ref areaCenters, minDist, offsetShape, (double)gridSize / 2.0); if (debug) { debugPreview.Add(RhinoPreview.PtsShow(areaCenters, gridSize, Color.red)); } agentPosition = areaCenters.ToHost(); }
protected override void SolveInstance(IGH_DataAccess DA) { List<DHr> hours = new List<DHr>(); String key = ""; if (DA.GetDataList(0, hours) && DA.GetData(1, ref key)) { if ((hours[0].is_surrogate) && ((hours.Count != 1) && (hours.Count != 12) && (hours.Count != 52) && (hours.Count != 365))) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "This component can only plot unmasked surrogate hours for yearly, monthly, weekly, and daily statistics"); } Interval ival_y = new Interval(); float[] vals = new float[0]; if (!(DA.GetData(2, ref ival_y))) DHr.get_domain(key, hours.ToArray(), ref vals, ref ival_y); else { vals = new float[hours.Count]; for (int h = 0; h < hours.Count; h++) vals[h] = hours[h].val(key); } Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)); DA.GetData(3, ref plane); Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval(); if (!DA.GetData(4, ref ival2d)) { ival2d.U0 = 0.0; ival2d.U1 = 12.0; ival2d.V0 = 0.0; ival2d.V1 = 1.0; } double barWidth = 1.0; DA.GetData(5, ref barWidth); List<Point3d> points = new List<Point3d>(); List<Rectangle3d> rects = new List<Rectangle3d>(); //double delta_x = Math.Abs(ival2d.U.Length) / hours.Count; //double delta_x2 = delta_x / 2.0; for (int h = 0; h < hours.Count; h++) { Point3d gpt = GraphPoint(hours[h].hr, vals[h], plane, ival_y, ival2d); // returns a point in graph coordinates hours[h].pos = gpt; // the hour records the point in graph coordinates Point3d wpt = plane.PointAt(gpt.X, gpt.Y); points.Add(wpt); // adds this point in world coordinates Interval ival_gx; // interval of horz space occupied by this hour in graphic units Interval ival_gy = new Interval(ival2d.V0, gpt.Y); // interval of vertical space occupied by this hour in graphic units if (!hours[h].is_surrogate) { double delta_x2 = (Math.Abs(ival2d.U.Length) / 8760 / 2.0); ival_gx = new Interval(gpt.X - delta_x2, gpt.X + delta_x2); // interval of horz space occupied by this hour in graphic units } else { // if we've been passed surrogate hours, the spacing between bars may not be consistant // we assume we've been given an hour at the start of the range represented double ival_gx_0 = gpt.X; //if (h > 0) { // Point3d pt_prev = GraphPoint(hours[h - 1].hr, vals[h - 1], plane, ival_y, ival2d); // ival_gx_0 = gpt.X - (gpt.X - pt_prev.X) * barWidth; //} else { ival_gx_0 = gpt.X - (gpt.X - ival2d.U0) * barWidth; } double ival_gx_1; if (h < hours.Count - 1) { Point3d pt_next = GraphPoint(hours[h + 1].hr, vals[h + 1], plane, ival_y, ival2d); ival_gx_1 = gpt.X + (pt_next.X - gpt.X) * barWidth; } else { ival_gx_1 = gpt.X + (ival2d.U1 - gpt.X) * barWidth; } ival_gx = new Interval(ival_gx_0, ival_gx_1); if (hours.Count == 1) ival_gx = ival2d.U; } Rectangle3d rect = new Rectangle3d(plane, ival_gx, ival_gy); rects.Add(rect); } DA.SetDataList(0, hours); DA.SetDataList(1, points); DA.SetDataList(2, rects); //DA.SetData(3, mesh); } }
public Drawing(List <Shape> shapes) { this.Shapes = shapes; this.frame = GetBoundary(); }
protected override void SolveInstance(IGH_DataAccess DA) { List<DHr> hours = new List<DHr>(); if (DA.GetDataList(0, hours)) { Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)); DA.GetData(1, ref plane); Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval(); if (!DA.GetData(2, ref ival2d)) { ival2d.U0 = 0.0; ival2d.U1 = 12.0; ival2d.V0 = 1.0; ival2d.V1 = 0.0; } else { // swap v-interval so that hours start at top left of defined area ival2d.V.Swap(); } List<Point3d> points = new List<Point3d>(); List<Rectangle3d> rects = new List<Rectangle3d>(); double delta_x = Math.Abs(ival2d.U.Length) / 365.0; double delta_y = Math.Abs(ival2d.V.Length) / 24.0; double delta_x2 = delta_x / 2.0; double delta_y2 = delta_y / 2.0; // only produce a mesh if given a full year worth of hours bool doMesh = false; Rhino.Geometry.Mesh mesh = new Mesh(); if (hours.Count == 8760) doMesh = true; for (int h = 0; h < hours.Count; h++) { //x = (math.floor(hr_out.hr/24)/365.0) //y = ((hr_out.hr % 24)/24.0) float x = (float)((ival2d.U.ParameterAt(Math.Floor(hours[h].hr / 24.0) / 365.0)) + delta_x2); float y = (float)((ival2d.V.ParameterAt((hours[h].hr % 24) / 24.0)) + delta_y2); Point3d pt = plane.PointAt(x, y, 0); points.Add(pt); hours[h].pos = new Point3d(x, y, 0); if (doMesh) { mesh.Vertices.Add(pt); mesh.VertexColors.Add(hours[h].color); } Rectangle3d rect = new Rectangle3d(new Plane(new Point3d(pt.X - delta_x2, pt.Y - delta_y2, 0), new Vector3d(0, 0, 1)), delta_x, delta_y); rects.Add(rect); } if (doMesh) { for (int h = 0; h < 8760 - 24; h++) { if (h % 24 != 0) mesh.Faces.AddFace(h, h - 1, h + 23, h + 24); } mesh.Normals.ComputeNormals(); mesh.Compact(); } DA.SetDataList(0, hours); DA.SetDataList(1, points); DA.SetDataList(2, rects); DA.SetData(3, mesh); } }
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; } } }
public Geometry(Rg.Rectangle3d rectangle3D) { curveType = CurveTypes.Rectangle; curve = rectangle3D.ToNurbsCurve(); }