/// <summary> /// This procedure contains the user code. Input parameters are provided as regular arguments, /// Output parameters as ref arguments. You don't have to assign output parameters, /// they will have a default value. /// </summary> private void RunScript(bool reset, bool go, List <Plane> Pl, double sR, List <Polyline> body, ref object iter, ref object Bodies, ref object Planes, ref object TipPoints) { // <Custom code> // . . . . . . . . . . . . . . . . . . . . . . . . return on null data if (Pl == null || body == null) { return; } // variables for data extraction DataTree <Polyline> outBodies = new DataTree <Polyline>(); GH_Plane[] outPlanes = new GH_Plane[Pl.Count]; List <GH_Point> tipPoints = new List <GH_Point>(); // . . . . . . . . . . . . . . . . . . . . . . . . initialize system if (reset || ABS == null) { ABS = new AgentBodySimulation(Pl, body, sR); iterationsCount = 0; Status = ""; } //Print("{0}", ABS.Agents[0].Neighbours.Count); //Print(Status); if (go) { // update parameters //ABS.searchRadius = sR; ABS.Update(); iterationsCount++; Component.ExpireSolution(true); } // . . . . . . . . . . . . . . . . . . . . . . . . extract geometries and data // necessary only in case of parallelization //for (int i = 0; i < ABS.Agents.Length; i++) // outBodies.EnsurePath(new GH_Path(i)); for (int i = 0; i < ABS.Agents.Length; i++) { outBodies.AddRange(ABS.Agents[i].ExtractBody(), new GH_Path(i)); outPlanes[i] = new GH_Plane(ABS.Agents[i].agentPlane); for (int j = 0; j < ABS.Agents[i].body.Tips.Count; j++) { tipPoints.Add(new GH_Point(ABS.Agents[i].body.Tips[j].pos)); } } iter = iterationsCount; Bodies = outBodies; Planes = outPlanes; TipPoints = tipPoints; // </Custom code> }
/// <summary> /// Provides an user-friendly description of a <see cref="Slot"/>. /// Required by Grasshopper. /// </summary> /// <returns>A string.</returns> public override string ToString( ) { if (!IsValid) { return(IsValidWhyNot); } var pt = new GH_Point(AbsoluteCenter); var diagonal = new GH_Vector(Diagonal); var plane = new GH_Plane(BasePlane); var containment = ""; if (AllowsAnyModule) { containment = "all Modules"; } if (IsContradictory) { containment = "no Modules"; } if (!IsContradictory && !AllowsAnyModule) { var count = AllowedModuleNames.Count; if (count == 1) { containment = "Module '" + AllowedModuleNames[0] + "'"; } else { containment = count + " Modules"; } } return("Slot allows placement of " + containment + ". Slot dimensions are " + diagonal + ", center is at " + pt + ", base plane is " + plane + "."); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Plane plane = null; int coupledGroup = -1; int coupledMechanism = -1; string name = null; if (!DA.GetData(0, ref plane)) { return; } if (!DA.GetData(1, ref coupledGroup)) { return; } if (!DA.GetData(2, ref coupledMechanism)) { return; } DA.GetData(3, ref name); var frame = new Frame(plane.Value, coupledMechanism, coupledGroup, name); DA.SetData(0, new GH_Frame(frame)); }
/// <summary> /// /// </summary> /// <param name="nodesList"></param> /// <param name="trimLengthBase"></param> /// <param name="trimLengthTop"></param> /// <returns></returns> private List <List <List <GH_Plane> > > TrimNodes(List <List <List <GH_Plane> > > nodesList, int trimLengthBase, int trimLengthTop) { List <List <List <GH_Plane> > > trimmedNodesList = new List <List <List <GH_Plane> > >(); for (int i = 0; i < nodesList.Count; i++) { List <List <GH_Plane> > trimmedNode = new List <List <GH_Plane> >(); for (int j = 0; j < nodesList[i].Count; j++) { List <GH_Plane> trimmedMember = new List <GH_Plane>(); if (j == 0) { for (int k = (nodesList[i][j].Count - trimLengthBase); k < nodesList[i][j].Count; k++) { GH_Plane p = nodesList[i][j][k]; trimmedMember.Add(p); } } else { for (int k = 0; k < trimLengthTop; k++) { GH_Plane p = nodesList[i][j][k]; trimmedMember.Add(p); } } trimmedNode.Add(trimmedMember); } trimmedNodesList.Add(trimmedNode); } return(trimmedNodesList); }
/// <summary> /// /// </summary> /// <param name="planes"></param> /// <param name="trimLengthBase"></param> /// <param name="trimLengthTop"></param> /// <returns></returns> private GH_Structure <GH_Plane> ExtractStems(GH_Structure <GH_Plane> planes, int trimLengthBase, int trimLengthTop) { GH_Structure <GH_Plane> stems = new GH_Structure <GH_Plane>(); for (int i = 0; i < planes.PathCount; i++) { GH_Plane plane = planes.get_DataItem(planes.get_Path(i), 0); List <GH_Plane> stemPlanes = new List <GH_Plane>(); if (plane.Value.OriginZ == 0) { for (int j = 0; j < planes.get_Branch(i).Count - trimLengthBase + 1; j++) { stemPlanes.Add(planes.get_DataItem(planes.get_Path(i), j)); } } else { for (int j = trimLengthTop - 1; j < planes.get_Branch(i).Count - trimLengthBase + 1; j++) { stemPlanes.Add(planes.get_DataItem(planes.get_Path(i), j)); } } GH_Path path = new GH_Path(i); stems.AppendRange(stemPlanes, path); } return(stems); }
//----------------------------------------------- TO RHINO TYPES public static Plane CastToPlane(GH_Plane p) { Plane pl = new Plane(); p.CastTo <Plane>(out pl); return(pl); }
/// <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) { GH_Plane tempPlane = new GH_Plane(); if (!DA.GetData("OriginPlane", ref tempPlane)) { return; } DA.GetData("Calibrate", ref calibrate); DA.GetData("Reset", ref reset); if (calibrate) { if (StartVive.CalibrationPlane == null) { StartVive.CalibrationPlane = tempPlane; } Plane iPlane = StartVive.CalibrationPlane.Value; Plane xyPlane = Plane.WorldXY; StartVive.CalibrationTransform = Transform.ChangeBasis(xyPlane, iPlane); } ; if (reset) { StartVive.CalibrationTransform = Transform.Identity; StartVive.CalibrationPlane = null; } //DA.SetData("Matrix", CalibrationTransform); }
public GH_Plane[] ExtractPlanes() { GH_Plane[] gP = new GH_Plane[agentPlanes.Length]; Parallel.For(0, agentPlanes.Length, i => { gP[i] = new GH_Plane(agentPlanes[i].ExtractPlane()); }); return(gP); }
public bool ToGH_Plane <T>(ref T target) { if (Axes != null) { object obj = new GH_Plane(Axes); target = (T)obj; } return(true); }
public bool ConvertToGH_Plane <T>(ref T target) { if (Orientation.Count == 1) { object obj = new GH_Plane(Orientation[0]); target = (T)obj; return(true); } return(false); }
public override void DrawViewportWires(GH_PreviewWireArgs args) { var location = Location; if (!location.IsValid) { return; } GH_Plane.DrawPlane(args.Pipeline, Location, Grasshopper.CentralSettings.PreviewPlaneRadius, 4, args.Color, System.Drawing.Color.DarkRed, System.Drawing.Color.DarkGreen); }
// Implement `Solveinstance` as usual protected override void SolveInstance(IGH_DataAccess DA) { //this.ClearRuntimeMessages(); object obj = null; if (!DA.GetData(0, ref obj)) { return; } if (obj == null) { return; } // Be verbose about data types if (obj is GH_Point) { if (this.Relative) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "WARNING: using Point in Relative mode, did you mean to work in Absolute mode instead? This Move action will take the Point as a Vector for relative motion."); } GH_Point p = obj as GH_Point; DA.SetData(0, new ActionTranslation(new MVector(p.Value.X, p.Value.Y, p.Value.Z), this.Relative)); } else if (obj is GH_Plane) { if (this.Relative) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "WARNING: using Plane in Relative mode, did you mean to work in Absolute mode instead? This Move action will take the Plane's origin Point as a Vector for relative motion."); } GH_Plane p = obj as GH_Plane; DA.SetData(0, new ActionTranslation(new MVector(p.Value.OriginX, p.Value.OriginY, p.Value.OriginZ), this.Relative)); } else if (obj is GH_Vector) { if (!this.Relative) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "WARNING: using Vector in Absolute mode, did you mean to work in Relative mode instead? This Move action will take the Vector's coordinates as the target Point for absolute motion."); } GH_Vector p = obj as GH_Vector; DA.SetData(0, new ActionTranslation(new MVector(p.Value.X, p.Value.Y, p.Value.Z), this.Relative)); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"ERROR: Can't take {obj.GetType()} as argument for a Move action; please use Point, Vector or Plane."); //DA.SetData(0, null); // not necessary } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Point ghpt = new GH_Point(); if (DA.GetData(0, ref ghpt)) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghpt, ref pt, GH_Conversion.Both)) { GH_Plane gH_Plane = new GH_Plane(); Plane localAxis = Plane.WorldXY; if (DA.GetData(1, ref gH_Plane)) { GH_Convert.ToPlane(gH_Plane, ref localAxis, GH_Conversion.Both); } GsaNode node = new GsaNode(pt); GsaBool6 bool6 = new GsaBool6(); if (DA.GetData(2, ref bool6)) { x = bool6.X; y = bool6.Y; z = bool6.Z; xx = bool6.XX; yy = bool6.YY; zz = bool6.ZZ; } GsaSpring spring = new GsaSpring(); if (DA.GetData(3, ref spring)) { node.Spring = spring; } node.LocalAxis = localAxis; node.Node.Restraint.X = x; node.Node.Restraint.Y = y; node.Node.Restraint.Z = z; node.Node.Restraint.XX = xx; node.Node.Restraint.YY = yy; node.Node.Restraint.ZZ = zz; DA.SetData(0, new GsaNodeGoo(node.Duplicate())); } } }
public override void DrawViewportWires(GH_PreviewWireArgs args) { var location = Location; if (!location.IsValid) { return; } GH_Plane.DrawPlane(args.Pipeline, location, Grasshopper.CentralSettings.PreviewPlaneRadius, 4, args.Color, System.Drawing.Color.DarkRed, System.Drawing.Color.DarkGreen); foreach (var loop in Profile) { args.Pipeline.DrawCurve(loop, args.Color, args.Thickness); } }
/// <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) { GH_Plane SourcePlane = default(GH_Plane), TargetPlane = default(GH_Plane); if (!DA.GetData(0, ref SourcePlane)) { return; } if (!DA.GetData(1, ref TargetPlane)) { return; } Transform Tran = Rhino.Geometry.Transform.ChangeBasis(SourcePlane.Value, TargetPlane.Value); DA.SetData(0, Tran); }
protected override void SolveInstance(IGH_DataAccess DA) { string name = null; GH_Plane basePlane = null; if (!DA.GetData(0, ref name)) { return; } if (!DA.GetData(1, ref basePlane)) { return; } var robotSystem = RobotSystem.Load(name, basePlane.Value);; DA.SetData(0, new GH_RobotSystem(robotSystem)); }
protected override void SolveInstance(IGH_DataAccess DA) { string name = null; GH_Plane tcp = null; double weight = 0; GH_Mesh mesh = null; GH_Point centroid = null; List <GH_Plane> planes = new List <GH_Plane>(); if (!DA.GetData(0, ref name)) { return; } if (!DA.GetData(1, ref tcp)) { return; } DA.GetDataList(2, planes); if (!DA.GetData(3, ref weight)) { return; } DA.GetData(4, ref centroid); DA.GetData(5, ref mesh); var tool = new Tool(tcp.Value, name, weight, centroid?.Value, mesh?.Value); if (planes.Count > 0) { if (planes.Count != 4) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, " Calibration input must be 4 planes"); } else { tool.FourPointCalibration(planes[0].Value, planes[1].Value, planes[2].Value, planes[3].Value); } } DA.SetData(0, new GH_Tool(tool)); DA.SetData(1, tool.Tcp); }
/// <summary> /// 将二维树转化为列表 /// </summary> /// <param name="tree"></param> /// <returns></returns> public static List <List <Plane> > TreeToList2(GH_Structure <GH_Plane> tree) { IList <GH_Path> paths = tree.Paths; List <List <Plane> > list = new List <List <Plane> >(); IEnumerable <GH_Plane> this_branch = new List <GH_Plane>(); for (int i = 0; i < paths.Count; i++) { list.Add(new List <Plane>()); this_branch = tree.get_Branch(paths[i]).Cast <GH_Plane>(); List <GH_Plane> this_list = this_branch.ToList(); for (int j = 0; j < this_list.Count(); j++) { GH_Plane raw_item = this_list[j]; Plane item = new Plane(); raw_item.CastTo(out item); list[i].Add(item); } } return(list); }
public void DrawViewportWires(GH_PreviewWireArgs args) { if (Value == null) { return; } if (Value.Plane.IsValid) { if (args.Color == System.Drawing.Color.FromArgb(255, 150, 0, 0)) // this is a workaround to change colour between selected and not { GH_Plane.DrawPlane(args.Pipeline, Value.Plane, 16, 16, System.Drawing.Color.Gray, System.Drawing.Color.Red, System.Drawing.Color.Green); args.Pipeline.DrawPoint(Value.Plane.Origin, Rhino.Display.PointStyle.RoundSimple, 3, UI.Colour.Node); } else { GH_Plane.DrawPlane(args.Pipeline, Value.Plane, 16, 16, System.Drawing.Color.LightGray, System.Drawing.Color.Red, System.Drawing.Color.Green); args.Pipeline.DrawPoint(Value.Plane.Origin, Rhino.Display.PointStyle.RoundControlPoint, 3, UI.Colour.NodeSelected); } } }
protected override void SolveInstance(IGH_DataAccess DA) { double[] numbers; GH_Plane plane = null; GH_RobotSystem robotSystem = null; if (!DA.GetData(0, ref plane)) { return; } DA.GetData(1, ref robotSystem); if (robotSystem == null) { numbers = RobotCellAbb.PlaneToQuaternion(plane.Value); } else { numbers = robotSystem.Value.PlaneToNumbers(plane.Value); } DA.SetDataList(0, numbers); }
public override bool CastTo <Q>(out Q target) { // This function is called when Grasshopper needs to convert this // instance of GsaGridPlane into some other type Q. if (typeof(Q).IsAssignableFrom(typeof(GsaGridPlaneSurface))) { if (Value == null) { target = default; } else { target = (Q)(object)Value.Duplicate(); } return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Plane))) { if (Value == null) { target = default; } else { GH_Plane pln = new GH_Plane(); GH_Convert.ToGHPlane(Value.Plane, GH_Conversion.Both, ref pln); target = (Q)(object)pln; } return(true); } target = default; return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { GsaNode gsaNode = new GsaNode(); Point3d tempPt = new Point3d(); if (gh_typ.Value is GsaNodeGoo) { gh_typ.CastTo(ref gsaNode); if (gsaNode == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Node input is null"); } if (gsaNode.Node == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Node input is null"); } } else if (GH_Convert.ToPoint3d(gh_typ.Value, ref tempPt, GH_Conversion.Both)) { gsaNode = new GsaNode(tempPt); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert input to Node"); return; } GsaNode node = gsaNode.Duplicate(); // #### inputs #### // 1 ID GH_Integer ghInt = new GH_Integer(); if (DA.GetData(1, ref ghInt)) { if (GH_Convert.ToInt32(ghInt, out int id, GH_Conversion.Both)) { node.ID = id; } } // 2 Point GH_Point ghPt = new GH_Point(); if (DA.GetData(2, ref ghPt)) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghPt, ref pt, GH_Conversion.Both)) { node.Point = pt; node.Node.Position.X = pt.X; node.Node.Position.Y = pt.Y; node.Node.Position.Z = pt.Z; } } // 3 plane GH_Plane ghPln = new GH_Plane(); if (DA.GetData(3, ref ghPln)) { Plane pln = new Plane(); if (GH_Convert.ToPlane(ghPln, ref pln, GH_Conversion.Both)) { pln.Origin = node.Point; node.LocalAxis = pln; } } // 4 Restraint GsaBool6 restraint = new GsaBool6(); if (DA.GetData(4, ref restraint)) { node.Node.Restraint.X = restraint.X; node.Node.Restraint.Y = restraint.Y; node.Node.Restraint.Z = restraint.Z; node.Node.Restraint.XX = restraint.XX; node.Node.Restraint.YY = restraint.YY; node.Node.Restraint.ZZ = restraint.ZZ; } // 5 Spring GsaSpring spring = new GsaSpring(); if (DA.GetData(5, ref spring)) { if (spring != null) { node.Spring = spring; } } // 6 Name GH_String ghStr = new GH_String(); if (DA.GetData(6, ref ghStr)) { if (GH_Convert.ToString(ghStr, out string name, GH_Conversion.Both)) { node.Node.Name = name; } } // 7 Colour GH_Colour ghcol = new GH_Colour(); if (DA.GetData(7, ref ghcol)) { if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both)) { node.Colour = col; } } // #### outputs #### DA.SetData(0, new GsaNodeGoo(node)); DA.SetData(1, node.ID); DA.SetData(2, node.Point); DA.SetData(3, node.LocalAxis); GsaBool6 restraint1 = new GsaBool6 { X = node.Node.Restraint.X, Y = node.Node.Restraint.Y, Z = node.Node.Restraint.Z, XX = node.Node.Restraint.XX, YY = node.Node.Restraint.YY, ZZ = node.Node.Restraint.ZZ }; DA.SetData(4, restraint1); GsaSpring spring1 = new GsaSpring(); if (node.Spring != null) { spring1 = node.Spring.Duplicate(); } DA.SetData(5, new GsaSpringGoo(spring1)); DA.SetData(6, node.Node.Name); DA.SetData(7, node.Colour); try { DA.SetDataList(8, node.Node.ConnectedElements); } catch (Exception) { } try { DA.SetDataList(9, node.Node.ConnectedMembers); } catch (Exception) { } } }
public override bool CastTo <Q>(ref Q target) { // This function is called when Grasshopper needs to convert this // instance of GsaLoad into some other type Q. if (typeof(Q).IsAssignableFrom(typeof(GsaLoad))) { if (Value == null) { target = default; } else { target = (Q)(object)Value.Duplicate(); } return(true); } if (typeof(Q).IsAssignableFrom(typeof(GsaGridPlaneSurfaceGoo))) { if (Value == null) { target = default; } else { if (Value.AreaLoad != null) { GsaGridPlaneSurface gridplane = Value.AreaLoad.GridPlaneSurface; GsaGridPlaneSurfaceGoo gpgoo = new GsaGridPlaneSurfaceGoo(gridplane); target = (Q)(object)gpgoo; return(true); } if (Value.LineLoad != null) { GsaGridPlaneSurface gridplane = Value.LineLoad.GridPlaneSurface; GsaGridPlaneSurfaceGoo gpgoo = new GsaGridPlaneSurfaceGoo(gridplane); target = (Q)(object)gpgoo; return(true); } if (Value.PointLoad != null) { GsaGridPlaneSurface gridplane = Value.PointLoad.GridPlaneSurface; GsaGridPlaneSurfaceGoo gpgoo = new GsaGridPlaneSurfaceGoo(gridplane); target = (Q)(object)gpgoo; return(true); } } return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Plane))) { if (Value == null) { target = default; } else { if (Value.LoadType == GsaLoad.LoadTypes.GridArea) { GH_Plane ghpln = new GH_Plane(); GH_Convert.ToGHPlane(Value.AreaLoad.GridPlaneSurface.Plane, GH_Conversion.Both, ref ghpln); target = (Q)(object)ghpln; return(true); } if (Value.LoadType == GsaLoad.LoadTypes.GridLine) { GH_Plane ghpln = new GH_Plane(); GH_Convert.ToGHPlane(Value.LineLoad.GridPlaneSurface.Plane, GH_Conversion.Both, ref ghpln); target = (Q)(object)ghpln; return(true); } if (Value.LoadType == GsaLoad.LoadTypes.GridPoint) { GH_Plane ghpln = new GH_Plane(); GH_Convert.ToGHPlane(Value.PointLoad.GridPlaneSurface.Plane, GH_Conversion.Both, ref ghpln); target = (Q)(object)ghpln; return(true); } } return(false); } if (typeof(Q).IsAssignableFrom(typeof(GH_Point))) { if (Value == null) { target = default; } else { if (Value.LoadType == GsaLoad.LoadTypes.GridPoint) { Point3d point = new Point3d { X = Value.PointLoad.GridPointLoad.X, Y = Value.PointLoad.GridPointLoad.Y, Z = Value.PointLoad.GridPlaneSurface.Plane.OriginZ }; GH_Point ghpt = new GH_Point(); GH_Convert.ToGHPoint(point, GH_Conversion.Both, ref ghpt); target = (Q)(object)ghpt; return(true); } } return(false); } if (typeof(Q).IsAssignableFrom(typeof(GH_Curve))) { if (Value == null) { target = default; } else { if (Value.LoadType == GsaLoad.LoadTypes.GridLine) { List <Point3d> pts = new List <Point3d>(); string def = Value.LineLoad.GridLineLoad.PolyLineDefinition; //implement converter // to be done //target = (Q)(object)ghpt; //return true; } } return(false); } target = default; return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { bool hasTarget = Params.Input.Any(x => x.Name == "Target"); bool hasJoints = Params.Input.Any(x => x.Name == "Joints"); bool hasPlane = Params.Input.Any(x => x.Name == "Plane"); bool hasConfig = Params.Input.Any(x => x.Name == "RobConf"); bool hasMotion = Params.Input.Any(x => x.Name == "Motion"); bool hasTool = Params.Input.Any(x => x.Name == "Tool"); bool hasSpeed = Params.Input.Any(x => x.Name == "Speed"); bool hasZone = Params.Input.Any(x => x.Name == "Zone"); bool hasCommand = Params.Input.Any(x => x.Name == "Command"); bool hasFrame = Params.Input.Any(x => x.Name == "Frame"); bool hasExternal = Params.Input.Any(x => x.Name == "External"); GH_Target sourceTarget = null; if (hasTarget) { if (!DA.GetData("Target", ref sourceTarget)) { return; } } double[] joints = null; var plane = new Plane(); Target.RobotConfigurations?configuration = null; Target.Motions motion = Target.Motions.Joint; Tool tool = null; Speed speed = null; Zone zone = null; Command command = null; Frame frame = null; double[] external = null; if (hasJoints) { GH_String jointsGH = null; if (!DA.GetData("Joints", ref jointsGH)) { return; } string[] jointsText = jointsGH.Value.Split(','); if (jointsText.Length != 6) { return; } joints = new double[6]; for (int i = 0; i < 6; i++) { if (!GH_Convert.ToDouble_Secondary(jointsText[i], ref joints[i])) { return; } } } else if (sourceTarget != null) { if (sourceTarget.Value is JointTarget) { joints = (sourceTarget.Value as JointTarget).Joints; } } if (hasPlane) { GH_Plane planeGH = null; if (hasPlane) { if (!DA.GetData("Plane", ref planeGH)) { return; } } plane = planeGH.Value; } else if (sourceTarget != null) { if (sourceTarget.Value is CartesianTarget) { plane = (sourceTarget.Value as CartesianTarget).Plane; } } if (hasConfig) { GH_Integer configGH = null; if (hasConfig) { DA.GetData("RobConf", ref configGH); } configuration = (configGH == null) ? null : (Target.RobotConfigurations?)configGH.Value; } else if (sourceTarget != null) { if (sourceTarget.Value is CartesianTarget) { configuration = (sourceTarget.Value as CartesianTarget).Configuration; } } if (hasMotion) { GH_String motionGH = null; DA.GetData("Motion", ref motionGH); motion = (motionGH == null) ? Target.Motions.Joint : (Target.Motions)Enum.Parse(typeof(Target.Motions), motionGH.Value); } else if (sourceTarget != null) { if (sourceTarget.Value is CartesianTarget) { motion = (sourceTarget.Value as CartesianTarget).Motion; } } if (hasTool) { GH_Tool toolGH = null; DA.GetData("Tool", ref toolGH); tool = toolGH?.Value; } else if (sourceTarget != null) { tool = sourceTarget.Value.Tool; } if (hasSpeed) { GH_Speed speedGH = null; DA.GetData("Speed", ref speedGH); speed = speedGH?.Value; } else if (sourceTarget != null) { speed = sourceTarget.Value.Speed; } if (hasZone) { GH_Zone zoneGH = null; DA.GetData("Zone", ref zoneGH); zone = zoneGH?.Value; } else if (sourceTarget != null) { zone = sourceTarget.Value.Zone; } if (hasCommand) { GH_Command commandGH = null; DA.GetData("Command", ref commandGH); command = commandGH?.Value; } else if (sourceTarget != null) { command = sourceTarget.Value.Command; } if (hasFrame) { GH_Frame frameGH = null; DA.GetData("Frame", ref frameGH); frame = frameGH?.Value; } else if (sourceTarget != null) { frame = sourceTarget.Value.Frame; } if (hasExternal) { GH_String externalGH = null; if (!DA.GetData("External", ref externalGH)) { external = new double[0]; } else { string[] externalText = externalGH.Value.Split(','); int length = externalText.Length; external = new double[length]; for (int i = 0; i < length; i++) { if (!GH_Convert.ToDouble_Secondary(externalText[i], ref external[i])) { return; } } } } else if (sourceTarget != null) { external = sourceTarget.Value.External; } Target target; bool localCartesian = isCartesian; if (hasTarget && !hasPlane && !hasJoints) { localCartesian = sourceTarget.Value is CartesianTarget; } if (localCartesian) { target = new CartesianTarget(plane, configuration, motion, tool, speed, zone, command, frame, external); } else { target = new JointTarget(joints, tool, speed, zone, command, frame, external); } if (sourceTarget != null) { target.ExternalCustom = sourceTarget.Value.ExternalCustom; } DA.SetData(0, new GH_Target(target)); }
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()); }
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)) { 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; } } }
/** * Does the computation */ protected override void SolveRabbitInstance(IGH_DataAccess DA) { //PARSE THE INPUT PARAMS: String sourceString = null; DA.GetData <String>(0, ref sourceString);//param index, place holder Double defaultStep = 0.0; DA.GetData <Double>(1, ref defaultStep);//param index, variable Double stepLengthScale = 0.0; DA.GetData <Double>(2, ref stepLengthScale);//param index, variable Double defaultAngleIncrement = 0.0; DA.GetData <Double>(3, ref defaultAngleIncrement); Double defaultAngleScale = 0.7; DA.GetData <Double>(4, ref defaultAngleScale);//param index, variable GH_Plane ghPlane = null; DA.GetData <GH_Plane>(5, ref ghPlane);//param index, variable Plane rhinoPlane = ghPlane.Value; //Loft settings Boolean loftSkeleton = false; GH_ObjectWrapper loftSkeletonSettingsWrapper = null; DA.GetData <GH_ObjectWrapper>(6, ref loftSkeletonSettingsWrapper); Double defaultThickness = -1; Double defaultThicknessScale = -1; Curve profile = new Circle(5).ToNurbsCurve(); Plane profilePivot = Plane.Unset; if (loftSkeletonSettingsWrapper != null && loftSkeletonSettingsWrapper.Value != null) { loftSkeleton = true; GH_TubeSettings loftSkeletonSettings = (GH_TubeSettings)loftSkeletonSettingsWrapper.Value; defaultThickness = loftSkeletonSettings.defaultThickness; defaultThicknessScale = loftSkeletonSettings.defaultThicknessScale; profile = loftSkeletonSettings.profile; profilePivot = loftSkeletonSettings.profilePivot; } //clear the canvas canvas.Clear(); Turtle3d Turtle = new Turtle3d(canvas, new Point3d(rhinoPlane.Origin.X, rhinoPlane.Origin.Y, rhinoPlane.Origin.Z), new Plane(rhinoPlane.Origin, rhinoPlane.XAxis, rhinoPlane.YAxis), defaultStep, stepLengthScale, defaultAngleIncrement, profile, profilePivot, defaultThickness, defaultThicknessScale, loftSkeleton);//clone the input variables, because they could have been modified in a previous solution //interpret the specified source string RLogoInterpreter rlogoInterpreter = new RLogoInterpreter(Turtle); rlogoInterpreter.Interpret(sourceString); if (loftSkeleton) { Brep[] breps = Turtle.LoftSkeleton(); foreach (Brep brep in breps) { canvas.AddGeometry(brep); } } Boolean showTurtlePositions = false; //Set the resulting Graphics in the output: DA.SetDataList(0, canvas.GetEdges()); DA.SetDataList(1, canvas.GetVertices()); DA.SetDataList(2, canvas.GetGeometry()); if (showTurtlePositions) { DA.SetDataList(3, canvas.GetPlanes()); } DA.SetDataList(4, canvas.GetProfiles()); //DA.SetDataTree }
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; } } }
/// <summary> /// This procedure contains the user code. Input parameters are provided as regular arguments, /// Output parameters as ref arguments. You don't have to assign output parameters, /// they will have a default value. /// </summary> private void RunScript(bool reset, bool go, List <Point3d> P, List <Vector3d> V, Mesh Ms, Mesh Mv, double pR, double nR, double cS, double aS, double sS, double fS, double meR, double meS, double coS, double mF, ref object iter, ref object Planes, ref object MeshPlanes) { // <Custom code> /* * align planes with mesh field - C# * code by Alessio Erioli - (c) Co-de-iT 2019 * * NOTE ON CUSTOM BEHAVIORS * * If you feel like implementing your custom behaviors: * . hit CTRL+F and search for "DBD2020" - you should find 2 more locations (apart from this line) * . . one location is in the Update() method of the AgentPlaneSimulationClass - uncomment the line to call the CustomBehavior method * . . the other location is in the CustomAgentBehavior() method of the AgentPlane class - here is where you can write your code * * Keep in mind that you are writing a behavior for the single agent, that then will be executed by all agents in the system */ if (P == null || P.Count == 0) { return; } if (reset || aPS == null) { // passing the essential parameters to the new simulation aPS = new AgentPlaneSystem(P, V); MEnvironment = Ms; // the environment mesh can be either Ms or Mv (color is ignored) MeshRTree = RTreeFromMesh(Ms); TensorField = TensorFieldFromMeshes(Ms, Mv); // passing scalar and vector data to the Tensor Field // initializing arrays for export gP = new GH_Plane[aPS.agentPlanes.Length]; //initialize iterations counter iterationsCount = 0; } if (go) { // update parameters aPS.PlaneRadius = pR; aPS.NeighborhoodRadius = nR; aPS.CohesionStrength = cS; aPS.AlignmentStrength = aS; aPS.SeparationStrength = sS; aPS.FieldStrength = fS; aPS.MeshSeekRadius = meR; aPS.MeshStrength = meS; aPS.SeekColorStrength = coS; aPS.MaxForce = mF; // update system aPS.Update(); iterationsCount++; Component.ExpireSolution(true); } // extract output geometries and information Parallel.For(0, aPS.agentPlanes.Length, i => { // extract planes gP[i] = new GH_Plane(aPS.agentPlanes[i].PlaneOut()); }); iter = iterationsCount; Planes = gP; // </Custom code> }