コード例 #1
0
 public GH_Zone(GH_Zone goo)
 {
     this.Value = goo.Value;
 }
コード例 #2
0
ファイル: Target.cs プロジェクト: xiongzhaoxu/Robots
        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));
        }