protected override void SolveInstance(IGH_DataAccess DA) { GH_Target target = null; if (!DA.GetData("Target", ref target)) { return; } bool isCartesian = target.Value is CartesianTarget; // if (isTargetCartesian != isCartesian) SwitchCartesian(); bool hasJoints = Params.Output.Any(x => x.Name == "Joints"); bool hasPlane = Params.Output.Any(x => x.Name == "Plane"); bool hasConfig = Params.Output.Any(x => x.Name == "RobConf"); bool hasMotion = Params.Output.Any(x => x.Name == "Motion"); bool hasTool = Params.Output.Any(x => x.Name == "Tool"); bool hasSpeed = Params.Output.Any(x => x.Name == "Speed"); bool hasZone = Params.Output.Any(x => x.Name == "Zone"); bool hasCommand = Params.Output.Any(x => x.Name == "Command"); bool hasFrame = Params.Output.Any(x => x.Name == "Frame"); bool hasExternal = Params.Output.Any(x => x.Name == "External"); if (hasJoints) { DA.SetData("Joints", isCartesian ? null : new GH_String(string.Join(",", (target.Value as JointTarget).Joints.Select(x => $"{x:0.000}")))); } if (hasPlane) { DA.SetData("Plane", isCartesian ? new GH_Plane((target.Value as CartesianTarget).Plane) : null); } if (hasConfig) { DA.SetData("RobConf", isCartesian ? (target.Value as CartesianTarget).Configuration == null ? null : new GH_Integer((int)(target.Value as CartesianTarget).Configuration) : null); } if (hasMotion) { DA.SetData("Motion", isCartesian ? new GH_String((target.Value as CartesianTarget).Motion.ToString()) : null); } if (hasTool && (target.Value.Tool != null)) { DA.SetData("Tool", new GH_Tool(target.Value.Tool)); } if (hasSpeed && (target.Value.Speed != null)) { DA.SetData("Speed", new GH_Speed(target.Value.Speed)); } if (hasZone && (target.Value.Zone != null)) { DA.SetData("Zone", new GH_Zone(target.Value.Zone)); } if (hasCommand) { DA.SetData("Command", new GH_Command(target.Value.Command)); } if (hasFrame) { DA.SetData("Frame", new GH_Frame(target.Value.Frame)); } if (hasExternal) { DA.SetData("External", new GH_String(string.Join(",", target.Value.External.Select(x => $"{x:0.000}")))); } }
public GH_Target(GH_Target goo) { this.Value = goo.Value; }
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)); }