/// <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)
        {
            // Warning that this component is OBSOLETE
            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This component is OBSOLETE and will be removed " +
                              "in the future. Remove this component from your canvas and replace it by picking the new component " +
                              "from the ribbon.");

            // Input variables
            RobotTarget target = null;

            // Catch the input data
            if (!DA.GetData(0, ref target))
            {
                return;
            }

            // Check if the object is valid
            if (!target.IsValid)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The Target is not valid");
            }

            // Output
            DA.SetData(0, target.Name);
            DA.SetData(1, target.Plane);
            DA.SetData(2, target.AxisConfig);
            DA.SetDataList(3, target.ExternalJointPosition.ToList());
        }
        /// <summary>
        /// This method displays the data associated to the targets.
        /// </summary>
        /// <param name="args"> Preview display arguments for IGH_PreviewObjects.</param>
        public override void DrawViewportMeshes(IGH_PreviewArgs args)
        {
            // Loop over all the branches in the datatree structure with targets
            for (int i = 0; i < _targetGoos.Branches.Count; i++)
            {
                // Get the indvidual branch
                var branches = _targetGoos.Branches[i];

                // Loop over all the items in the individual branch
                for (int j = 0; j < branches.Count; j++)
                {
                    // Get the target
                    RobotTarget target = branches[j].Value as RobotTarget;

                    // Display the name of the target
                    if (_displayNames == true)
                    {
                        double pixelsPerUnit;
                        args.Viewport.GetWorldToScreenScale(target.Plane.Origin, out pixelsPerUnit);

                        Plane plane;
                        args.Viewport.GetCameraFrame(out plane);
                        plane.Origin = target.Plane.Origin + target.Plane.ZAxis * 2;

                        args.Display.Draw3dText(target.Name, _color, plane, _textSize / pixelsPerUnit, "Lucida Console");
                    }

                    // Display the origin of the target plane
                    if (_displayPoints == true)
                    {
                        args.Display.DrawPoint(target.Plane.Origin, Rhino.Display.PointStyle.Simple, _pointSize, _color);
                    }

                    // Display the direction / orientation of the target plane
                    if (_displayDirections == true)
                    {
                        Plane planeVisual = target.Plane;
                        args.Display.DrawDirectionArrow(planeVisual.Origin, planeVisual.ZAxis, System.Drawing.Color.Blue);
                        args.Display.DrawDirectionArrow(planeVisual.Origin, planeVisual.XAxis, System.Drawing.Color.Red);
                        args.Display.DrawDirectionArrow(planeVisual.Origin, planeVisual.YAxis, System.Drawing.Color.Green);
                    }
                }
            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Sets inputs and creates target
            string name           = "defaultTar";
            Plane  plane          = Plane.WorldXY;
            Plane  referencePlane = Plane.WorldXY;
            int    axisConfig     = 0;
            ExternalJointPosition externalJointPosition = new ExternalJointPosition();

            // Catch inputs
            if (!DA.GetData(0, ref name))
            {
                return;
            }
            if (!DA.GetData(1, ref plane))
            {
                return;
            }
            if (!DA.GetData(2, ref referencePlane))
            {
                return;
            }
            if (!DA.GetData(3, ref axisConfig))
            {
                return;
            }
            if (!DA.GetData(4, ref externalJointPosition))
            {
                return;
            }

            // Replace spaces
            name = HelperMethods.ReplaceSpacesAndRemoveNewLines(name);

            RobotTarget target = new RobotTarget(name, plane, referencePlane, axisConfig, externalJointPosition);

            // Sets Output
            DA.SetData(0, target);
        }
示例#4
0
        /// <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)
        {
            // Input variables
            RobotTarget target = null;

            // Catch the input data
            if (!DA.GetData(0, ref target))
            {
                return;
            }

            // Check if the object is valid
            if (!target.IsValid)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The Robot Target is not valid");
            }

            // Output
            DA.SetData(0, target.Name);
            DA.SetData(1, target.Plane);
            DA.SetData(2, target.AxisConfig);
            DA.SetData(3, target.ExternalJointPosition);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Warning that this component is OBSOLETE
            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This component is OBSOLETE and will be removed " +
                              "in the future. Remove this component from your canvas and replace it by picking the new component " +
                              "from the ribbon.");

            // Gets the Object Manager of this document
            objectManager = DocumentManager.GetDocumentObjectManager(this.OnPingDocument());

            // Clears targetNames
            for (int i = 0; i < targetNames.Count; i++)
            {
                objectManager.TargetNames.Remove(targetNames[i]);
            }
            targetNames.Clear();

            // Adds Component to TargetByGuid Dictionary
            if (!objectManager.OldTargetsByGuid.ContainsKey(this.InstanceGuid))
            {
                objectManager.OldTargetsByGuid.Add(this.InstanceGuid, this);
            }

            // Removes lastName from targetNameList
            if (objectManager.TargetNames.Contains(lastName))
            {
                objectManager.TargetNames.Remove(lastName);
            }

            // Sets inputs and creates target
            Guid          instanceGUID = this.InstanceGuid;
            List <string> names        = new List <string>();
            List <Plane>  planes       = new List <Plane>();
            List <int>    axisConfigs  = new List <int>();

            // Catch the input data
            if (!DA.GetDataList(0, names))
            {
                return;
            }
            if (!DA.GetDataList(1, planes))
            {
                return;
            }
            if (!DA.GetDataList(2, axisConfigs))
            {
                return;
            }

            // Get longest Input List
            int[] sizeValues = new int[3];
            sizeValues[0] = names.Count;
            sizeValues[1] = planes.Count;
            sizeValues[2] = axisConfigs.Count;
            int biggestSize = HelperMethods.GetBiggestValue(sizeValues);

            // Keeps track of used indicies
            int nameCounter       = -1;
            int planesCounter     = -1;
            int axisConfigCounter = -1;

            // Clear list
            _targets.Clear();

            // Creates targets
            for (int i = 0; i < biggestSize; i++)
            {
                string name       = "";
                Plane  plane      = new Plane();
                int    axisConfig = 0;

                if (i < names.Count)
                {
                    name = names[i];
                    nameCounter++;
                }
                else
                {
                    name = names[nameCounter] + "_" + (i - nameCounter);
                }

                if (i < planes.Count)
                {
                    plane = planes[i];
                    planesCounter++;
                }
                else
                {
                    plane = planes[planesCounter];
                }

                if (i < axisConfigs.Count)
                {
                    axisConfig = axisConfigs[i];
                    axisConfigCounter++;
                }
                else
                {
                    axisConfig = axisConfigs[axisConfigCounter];
                }

                RobotTarget target = new RobotTarget(name, plane, axisConfig);
                _targets.Add(target);
            }

            // Checks if target name is already in use and counts duplicates
            #region NameCheck
            namesUnique = true;
            for (int i = 0; i < names.Count; i++)
            {
                if (objectManager.TargetNames.Contains(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name already in use.");
                    namesUnique = false;
                    lastName    = "";
                    break;
                }
                else
                {
                    // Adds Target Name to list
                    targetNames.Add(names[i]);
                    objectManager.TargetNames.Add(names[i]);

                    // Run SolveInstance on other Targets with no unique Name to check if their name is now available
                    objectManager.UpdateTargets();

                    lastName = names[i];
                }

                // Checks if variable name exceeds max character limit for RAPID Code
                if (HelperMethods.VariableExeedsCharacterLimit32(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name exceeds character limit of 32 characters.");
                    break;
                }

                // Checks if variable name starts with a number
                if (HelperMethods.VariableStartsWithNumber(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name starts with a number which is not allowed in RAPID Code.");
                    break;
                }
            }
            #endregion

            // Sets Output
            DA.SetDataList(0, _targets);

            // Recognizes if Component is Deleted and removes it from Object Managers target and name list
            GH_Document doc = this.OnPingDocument();
            if (doc != null)
            {
                doc.ObjectsDeleted += DocumentObjectsDeleted;
            }
        }
示例#6
0
        /// <summary>
        /// Attempt a cast from generic object.
        /// </summary>
        /// <param name="source"> Reference to source of cast. </param>
        /// <returns> True on success, false on failure. </returns>
        public override bool CastFrom(object source)
        {
            if (source == null)
            {
                return(false);
            }

            //Cast from Movement
            if (typeof(Movement).IsAssignableFrom(source.GetType()))
            {
                Value = source as Movement;
                return(true);
            }

            //Cast from Target
            if (typeof(ITarget).IsAssignableFrom(source.GetType()))
            {
                Value = new Movement(source as ITarget);
                return(true);
            }

            //Cast from Target Goo
            if (typeof(GH_Target).IsAssignableFrom(source.GetType()))
            {
                GH_Target targetGoo = source as GH_Target;
                Value = new Movement(targetGoo.Value);
                return(true);
            }

            //Cast from Robot Target
            if (typeof(RobotTarget).IsAssignableFrom(source.GetType()))
            {
                RobotTarget target = (RobotTarget)source;
                Value = new Movement(target);
                return(true);
            }

            //Cast from Robot Target Goo
            if (typeof(GH_RobotTarget).IsAssignableFrom(source.GetType()))
            {
                GH_RobotTarget targetGoo = (GH_RobotTarget)source;
                Value = new Movement(targetGoo.Value);
                return(true);
            }

            //Cast from Joint Target
            if (typeof(JointTarget).IsAssignableFrom(source.GetType()))
            {
                JointTarget target = (JointTarget)source;
                Value = new Movement(target);
                return(true);
            }

            //Cast from Joint Target Goo
            if (typeof(GH_JointTarget).IsAssignableFrom(source.GetType()))
            {
                GH_JointTarget targetGoo = (GH_JointTarget)source;
                Value = new Movement(targetGoo.Value);
                return(true);
            }

            //Cast from Action
            if (typeof(Action).IsAssignableFrom(source.GetType()))
            {
                if (source is Movement action)
                {
                    Value = action;
                    return(true);
                }
            }

            //Cast from Action Goo
            if (typeof(GH_Action).IsAssignableFrom(source.GetType()))
            {
                GH_Action actionGoo = source as GH_Action;
                if (actionGoo.Value is Movement action)
                {
                    Value = action;
                    return(true);
                }
            }

            //Cast from Instruction
            if (typeof(IInstruction).IsAssignableFrom(source.GetType()))
            {
                if (source is Movement instruction)
                {
                    Value = instruction;
                    return(true);
                }
            }

            //Cast from Instruction Goo
            if (typeof(GH_Instruction).IsAssignableFrom(source.GetType()))
            {
                GH_Instruction instructionGoo = source as GH_Instruction;
                if (instructionGoo.Value is Movement instruction)
                {
                    Value = instruction;
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Warning that this component is OBSOLETE
            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This component is OBSOLETE and will be removed in the future.");

            // Variable for catchint the datatree
            GH_Structure <IGH_Goo> actions;

            // Clear the list with targets before catching new input data
            _targetGoos.Clear();

            // Catch the input data
            if (!DA.GetDataTree(0, out actions))
            {
                return;
            }
            if (!DA.GetData(1, ref _displayNames))
            {
                return;
            }
            if (!DA.GetData(2, ref _displayPoints))
            {
                return;
            }
            if (!DA.GetData(3, ref _displayDirections))
            {
                return;
            }
            if (!DA.GetData(4, ref _color))
            {
                return;
            }
            if (!DA.GetData(5, ref _textSize))
            {
                return;
            }
            if (!DA.GetData(6, ref _pointSize))
            {
                return;
            }

            // Get the paths of the datatree with actions
            var paths = actions.Paths;

            // Check and concert the input data to the right datatype (target)
            for (int i = 0; i < actions.Branches.Count; i++)
            {
                var     branches = actions.Branches[i];
                GH_Path iPath    = paths[i];

                for (int j = 0; j < branches.Count; j++)
                {
                    // Get the target from the movement instance if the input data is a movement
                    if (actions.Branches[i][j] is GH_Movement)
                    {
                        GH_Movement movementGoo = actions.Branches[i][j] as GH_Movement;
                        GH_Target   targetGoo   = new GH_Target(movementGoo.Value.Target);
                        _targetGoos.Append(targetGoo, iPath);
                    }
                    // Get the target data directly if the input data is a target
                    else if (actions.Branches[i][j] is GH_Target)
                    {
                        GH_Target targetGoo = actions.Branches[i][j] as GH_Target;
                        _targetGoos.Append(targetGoo, iPath);
                    }
                    // Make a target from the input plane if the input data is a plane
                    else if (actions.Branches[i][j] is GH_Plane)
                    {
                        string targetName;
                        if (actions.Branches.Count == 1)
                        {
                            targetName = "plane" + "_" + j;
                        }
                        else
                        {
                            targetName = "plane" + "_" + i + "_" + j;
                        }

                        GH_Plane    planeGoo  = actions.Branches[i][j] as GH_Plane;
                        RobotTarget target    = new RobotTarget(targetName, planeGoo.Value);
                        GH_Target   targetGoo = new GH_Target(target);
                        _targetGoos.Append(targetGoo, iPath);
                    }
                    // Let all other data pass (raise no warning or error)
                    else
                    {
                        // empty
                    }
                }
            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Warning that this component is OBSOLETE
            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This component is OBSOLETE and will be removed " +
                              "in the future. Remove this component from your canvas and replace it by picking the new component " +
                              "from the ribbon.");

            // Sets inputs and creates target
            List <string> names           = new List <string>();
            List <Plane>  planes          = new List <Plane>();
            List <Plane>  referencePlanes = new List <Plane>();
            List <int>    axisConfigs     = new List <int>();

            // Override external axis values input variables
            List <double> externalAxisValueA = new List <double>();
            List <double> externalAxisValueB = new List <double>();
            List <double> externalAxisValueC = new List <double>();
            List <double> externalAxisValueD = new List <double>();
            List <double> externalAxisValueE = new List <double>();
            List <double> externalAxisValueF = new List <double>();

            // Catch name input
            if (!DA.GetDataList(0, names))
            {
                return;
            }                                          // Fixed index

            // Catch target planes input
            if (!DA.GetDataList(1, planes))
            {
                return;
            }                                           // Fixed index

            // Catch reference plane input
            if (Params.Input.Any(x => x.Name == "Reference Plane"))
            {
                if (!DA.GetDataList("Reference Plane", referencePlanes))
                {
                    referencePlanes = new List <Plane>()
                    {
                        Plane.WorldXY
                    };
                }
            }

            // Catch axis configuration input
            if (Params.Input.Any(x => x.Name == "Axis Configuration"))
            {
                if (!DA.GetDataList("Axis Configuration", axisConfigs))
                {
                    return;
                }
            }

            // Catch input data for overriding external axis values
            if (Params.Input.Any(x => x.Name == externalAxisParameters[0].Name))
            {
                // External axis A
                if (!DA.GetDataList(externalAxisParameters[0].Name, externalAxisValueA))
                {
                    externalAxisValueA = new List <double>()
                    {
                        9e9
                    };
                }
            }
            // External axis B
            if (Params.Input.Any(x => x.Name == externalAxisParameters[1].Name))
            {
                if (!DA.GetDataList(externalAxisParameters[1].Name, externalAxisValueB))
                {
                    externalAxisValueB = new List <double>()
                    {
                        9e9
                    };
                }
            }
            // External axis C
            if (Params.Input.Any(x => x.Name == externalAxisParameters[2].Name))
            {
                if (!DA.GetDataList(externalAxisParameters[2].Name, externalAxisValueC))
                {
                    externalAxisValueC = new List <double>()
                    {
                        9e9
                    };
                }
            }
            // External axis D
            if (Params.Input.Any(x => x.Name == externalAxisParameters[3].Name))
            {
                if (!DA.GetDataList(externalAxisParameters[3].Name, externalAxisValueD))
                {
                    externalAxisValueD = new List <double>()
                    {
                        9e9
                    };
                }
            }
            // External axis E
            if (Params.Input.Any(x => x.Name == externalAxisParameters[4].Name))
            {
                if (!DA.GetDataList(externalAxisParameters[4].Name, externalAxisValueE))
                {
                    externalAxisValueE = new List <double>()
                    {
                        9e9
                    };
                }
            }
            // External axis F
            if (Params.Input.Any(x => x.Name == externalAxisParameters[5].Name))
            {
                if (!DA.GetDataList(externalAxisParameters[5].Name, externalAxisValueF))
                {
                    externalAxisValueF = new List <double>()
                    {
                        9e9
                    };
                }
            }

            // Make sure variable input has a default value
            if (referencePlanes.Count == 0)
            {
                referencePlanes.Add(Plane.WorldXY);
            }
            if (externalAxisValueA.Count == 0)
            {
                externalAxisValueA.Add(9e9);
            }
            if (externalAxisValueB.Count == 0)
            {
                externalAxisValueB.Add(9e9);
            }
            if (externalAxisValueC.Count == 0)
            {
                externalAxisValueC.Add(9e9);
            }
            if (externalAxisValueD.Count == 0)
            {
                externalAxisValueD.Add(9e9);
            }
            if (externalAxisValueE.Count == 0)
            {
                externalAxisValueE.Add(9e9);
            }
            if (externalAxisValueF.Count == 0)
            {
                externalAxisValueF.Add(9e9);
            }

            // Get longest Input List
            int[] sizeValues = new int[10];
            sizeValues[0] = names.Count;
            sizeValues[1] = planes.Count;
            sizeValues[2] = referencePlanes.Count;
            sizeValues[3] = axisConfigs.Count;

            sizeValues[4] = externalAxisValueA.Count;
            sizeValues[5] = externalAxisValueB.Count;
            sizeValues[6] = externalAxisValueC.Count;
            sizeValues[7] = externalAxisValueD.Count;
            sizeValues[8] = externalAxisValueE.Count;
            sizeValues[9] = externalAxisValueF.Count;

            int biggestSize = HelperMethods.GetBiggestValue(sizeValues);

            // Keeps track of used indicies
            int nameCounter           = -1;
            int planesCounter         = -1;
            int referencePlaneCounter = -1;
            int axisConfigCounter     = -1;

            int externalAxisValueCounterA = -1;
            int externalAxisValueCounterB = -1;
            int externalAxisValueCounterC = -1;
            int externalAxisValueCounterD = -1;
            int externalAxisValueCounterE = -1;
            int externalAxisValueCounterF = -1;

            // Clear list
            _targets.Clear();

            // Creates targets
            for (int i = 0; i < biggestSize; i++)
            {
                string name           = "";
                Plane  plane          = new Plane();
                Plane  referencePlane = new Plane();
                int    axisConfig     = 0;

                double[] axisValues = new double[6];

                // Names counter
                if (i < sizeValues[0])
                {
                    name = names[i];
                    nameCounter++;
                }
                else
                {
                    name = names[nameCounter] + "_" + (i - nameCounter);
                }

                // Target planes counter
                if (i < sizeValues[1])
                {
                    plane = planes[i];
                    planesCounter++;
                }
                else
                {
                    plane = planes[planesCounter];
                }

                // Reference plane counter
                if (i < sizeValues[2])
                {
                    referencePlane = referencePlanes[i];
                    referencePlaneCounter++;
                }
                else
                {
                    referencePlane = referencePlanes[referencePlaneCounter];
                }

                // Axis configuration counter
                if (i < sizeValues[3])
                {
                    axisConfig = axisConfigs[i];
                    axisConfigCounter++;
                }
                else
                {
                    axisConfig = axisConfigs[axisConfigCounter];
                }

                // External Axis Value A
                if (i < sizeValues[4])
                {
                    axisValues[0] = externalAxisValueA[i];
                    externalAxisValueCounterA++;
                }
                else
                {
                    axisValues[0] = externalAxisValueA[externalAxisValueCounterA];
                }

                // External Axis Value B
                if (i < sizeValues[5])
                {
                    axisValues[1] = externalAxisValueB[i];
                    externalAxisValueCounterB++;
                }
                else
                {
                    axisValues[1] = externalAxisValueB[externalAxisValueCounterB];
                }

                // External Axis Value C
                if (i < sizeValues[6])
                {
                    axisValues[2] = externalAxisValueC[i];
                    externalAxisValueCounterC++;
                }
                else
                {
                    axisValues[2] = externalAxisValueC[externalAxisValueCounterC];
                }

                // External Axis Value D
                if (i < sizeValues[7])
                {
                    axisValues[3] = externalAxisValueD[i];
                    externalAxisValueCounterD++;
                }
                else
                {
                    axisValues[3] = externalAxisValueD[externalAxisValueCounterD];
                }

                // External Axis Value E
                if (i < sizeValues[8])
                {
                    axisValues[4] = externalAxisValueE[i];
                    externalAxisValueCounterE++;
                }
                else
                {
                    axisValues[4] = externalAxisValueE[externalAxisValueCounterE];
                }

                // External Axis Value F
                if (i < sizeValues[9])
                {
                    axisValues[5] = externalAxisValueF[i];
                    externalAxisValueCounterF++;
                }
                else
                {
                    axisValues[5] = externalAxisValueF[externalAxisValueCounterF];
                }

                RobotTarget target = new RobotTarget(name, plane, referencePlane, axisConfig, new ExternalJointPosition(axisValues));
                _targets.Add(target);
            }

            // Sets Output
            DA.SetDataList(0, _targets);

            #region Object manager
            // Gets ObjectManager of this document
            _objectManager = DocumentManager.GetDocumentObjectManager(this.OnPingDocument());

            // Clears targetNames
            for (int i = 0; i < _targetNames.Count; i++)
            {
                _objectManager.TargetNames.Remove(_targetNames[i]);
            }
            _targetNames.Clear();

            // Removes lastName from targetNameList
            if (_objectManager.TargetNames.Contains(_lastName))
            {
                _objectManager.TargetNames.Remove(_lastName);
            }

            // Adds Component to TargetByGuid Dictionary
            if (!_objectManager.OldTargetsByGuid2.ContainsKey(this.InstanceGuid))
            {
                _objectManager.OldTargetsByGuid2.Add(this.InstanceGuid, this);
            }

            // Checks if target name is already in use and counts duplicates
            #region Check name in object manager
            _namesUnique = true;
            for (int i = 0; i < names.Count; i++)
            {
                if (_objectManager.TargetNames.Contains(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name already in use.");
                    _namesUnique = false;
                    _lastName    = "";
                    break;
                }
                else
                {
                    // Adds Target Name to list
                    _targetNames.Add(names[i]);
                    _objectManager.TargetNames.Add(names[i]);

                    // Run SolveInstance on other Targets with no unique Name to check if their name is now available
                    _objectManager.UpdateTargets();

                    _lastName = names[i];
                }

                // Checks if variable name exceeds max character limit for RAPID Code
                if (HelperMethods.VariableExeedsCharacterLimit32(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name exceeds character limit of 32 characters.");
                    break;
                }

                // Checks if variable name starts with a number
                if (HelperMethods.VariableStartsWithNumber(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name starts with a number which is not allowed in RAPID Code.");
                    break;
                }
            }
            #endregion

            // Recognizes if Component is Deleted and removes it from Object Managers target and name list
            GH_Document doc = this.OnPingDocument();
            if (doc != null)
            {
                doc.ObjectsDeleted += DocumentObjectsDeleted;
            }
            #endregion
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Sets inputs and creates target
            List <string> names           = new List <string>();
            List <Plane>  planes          = new List <Plane>();
            List <Plane>  referencePlanes = new List <Plane>();
            List <int>    axisConfigs     = new List <int>();
            List <ExternalJointPosition> externalJointPositions = new List <ExternalJointPosition>();

            // Catch name input
            if (!DA.GetDataList(0, names))
            {
                return;
            }                                          // Fixed index

            // Catch target planes input
            if (!DA.GetDataList(1, planes))
            {
                return;
            }                                           // Fixed index

            // Catch reference plane input
            if (Params.Input.Any(x => x.Name == "Reference Plane"))
            {
                if (!DA.GetDataList("Reference Plane", referencePlanes))
                {
                    referencePlanes = new List <Plane>()
                    {
                        Plane.WorldXY
                    };
                }
            }

            // Catch axis configuration input
            if (Params.Input.Any(x => x.Name == "Axis Configuration"))
            {
                if (!DA.GetDataList("Axis Configuration", axisConfigs))
                {
                    return;
                }
            }

            // Catch input data for setting the external joint position
            if (Params.Input.Any(x => x.Name == parameters[1].Name))
            {
                if (!DA.GetDataList(parameters[1].Name, externalJointPositions))
                {
                    externalJointPositions = new List <ExternalJointPosition>()
                    {
                        new ExternalJointPosition()
                    };
                }
            }

            // Make sure variable input has a default value
            if (referencePlanes.Count == 0)
            {
                referencePlanes.Add(Plane.WorldXY);
            }
            if (externalJointPositions.Count == 0)
            {
                externalJointPositions.Add(new ExternalJointPosition());
            }

            // Replace spaces
            names = HelperMethods.ReplaceSpacesAndRemoveNewLines(names);

            // Get longest Input List
            int[] sizeValues = new int[5];
            sizeValues[0] = names.Count;
            sizeValues[1] = planes.Count;
            sizeValues[2] = referencePlanes.Count;
            sizeValues[3] = axisConfigs.Count;
            sizeValues[4] = externalJointPositions.Count;

            int biggestSize = HelperMethods.GetBiggestValue(sizeValues);

            // Keeps track of used indicies
            int nameCounter                  = -1;
            int planesCounter                = -1;
            int referencePlaneCounter        = -1;
            int axisConfigCounter            = -1;
            int externalJointPositionCounter = -1;

            // Clear list
            _targets.Clear();

            // Creates targets
            for (int i = 0; i < biggestSize; i++)
            {
                string name           = "";
                Plane  plane          = new Plane();
                Plane  referencePlane = new Plane();
                int    axisConfig     = 0;
                ExternalJointPosition externalJointPosition = new ExternalJointPosition();

                // Names counter
                if (i < sizeValues[0])
                {
                    name = names[i];
                    nameCounter++;
                }
                else
                {
                    name = names[nameCounter] + "_" + (i - nameCounter);
                }

                // Target planes counter
                if (i < sizeValues[1])
                {
                    plane = planes[i];
                    planesCounter++;
                }
                else
                {
                    plane = planes[planesCounter];
                }

                // Reference plane counter
                if (i < sizeValues[2])
                {
                    referencePlane = referencePlanes[i];
                    referencePlaneCounter++;
                }
                else
                {
                    referencePlane = referencePlanes[referencePlaneCounter];
                }

                // Axis configuration counter
                if (i < sizeValues[3])
                {
                    axisConfig = axisConfigs[i];
                    axisConfigCounter++;
                }
                else
                {
                    axisConfig = axisConfigs[axisConfigCounter];
                }

                // External Joint Position
                if (i < sizeValues[4])
                {
                    externalJointPosition = externalJointPositions[i];
                    externalJointPositionCounter++;
                }
                else
                {
                    externalJointPosition = externalJointPositions[externalJointPositionCounter];
                }

                RobotTarget target = new RobotTarget(name, plane, referencePlane, axisConfig, externalJointPosition);
                _targets.Add(target);
            }

            // Sets Output
            DA.SetDataList(0, _targets);

            #region Object manager
            // Gets ObjectManager of this document
            _objectManager = DocumentManager.GetDocumentObjectManager(this.OnPingDocument());

            // Clears targetNames
            for (int i = 0; i < _targetNames.Count; i++)
            {
                _objectManager.TargetNames.Remove(_targetNames[i]);
            }
            _targetNames.Clear();

            // Removes lastName from targetNameList
            if (_objectManager.TargetNames.Contains(_lastName))
            {
                _objectManager.TargetNames.Remove(_lastName);
            }

            // Adds Component to TargetByGuid Dictionary
            if (!_objectManager.OldRobotTargetsByGuid.ContainsKey(this.InstanceGuid))
            {
                _objectManager.OldRobotTargetsByGuid.Add(this.InstanceGuid, this); //TODO
            }

            // Checks if target name is already in use and counts duplicates
            #region Check name in object manager
            _namesUnique = true;
            for (int i = 0; i < names.Count; i++)
            {
                if (_objectManager.TargetNames.Contains(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name already in use.");
                    _namesUnique = false;
                    _lastName    = "";
                    break;
                }
                else
                {
                    // Adds Target Name to list
                    _targetNames.Add(names[i]);
                    _objectManager.TargetNames.Add(names[i]);

                    // Run SolveInstance on other Targets with no unique Name to check if their name is now available
                    _objectManager.UpdateTargets();

                    _lastName = names[i];
                }

                // Checks if variable name exceeds max character limit for RAPID Code
                if (HelperMethods.VariableExeedsCharacterLimit32(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name exceeds character limit of 32 characters.");
                    break;
                }

                // Checks if variable name starts with a number
                if (HelperMethods.VariableStartsWithNumber(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Target Name starts with a number which is not allowed in RAPID Code.");
                    break;
                }
            }
            #endregion

            // Recognizes if Component is Deleted and removes it from Object Managers target and name list
            GH_Document doc = this.OnPingDocument();
            if (doc != null)
            {
                doc.ObjectsDeleted += DocumentObjectsDeleted;
            }
            #endregion
        }
        /// <summary>
        /// Calculates the interpolated path for a linear movement.
        /// </summary>
        /// <param name="movement"> The movement as a linear movement type. </param>
        private void LinearMovementFromRobotTarget(Movement movement)
        {
            // Set the correct tool for this movement
            SetRobotTool(movement);

            // Points for path
            List <Point3d> points = new List <Point3d>();

            // Get the final joint positions of this movement
            _robot.InverseKinematics.Movement = movement;
            _robot.InverseKinematics.CalculateExternalJointPosition();

            // Get the External Joint Positions
            ExternalJointPosition towardsExternalJointPosition = _robot.InverseKinematics.ExternalJointPosition.Duplicate();

            // External Joint Position change
            ExternalJointPosition externalJointPositionChange = (towardsExternalJointPosition - _lastExternalJointPosition) / _interpolations;

            // TODO: Check with last movement to speed up the process? As in old path generator?

            // First target plane in WORLD coordinate space
            _robot.ForwardKinematics.Calculate(_lastRobotJointPosition, _lastExternalJointPosition);
            Plane plane1 = _robot.ForwardKinematics.TCPPlane;

            // Second target plane in WORK OBJECT coordinate space
            RobotTarget robotTarget = movement.Target as RobotTarget;
            Plane       plane2      = robotTarget.Plane;

            // Correction for rotation of the target plane on a movable work object
            if (movement.WorkObject.ExternalAxis != null)
            {
                ExternalAxis externalAxis = movement.WorkObject.ExternalAxis;
                Transform    trans        = externalAxis.CalculateTransformationMatrix(_lastExternalJointPosition * -1, out _);
                plane1.Transform(trans);
            }

            // Re-orient the starting plane to the work object coordinate space of the second target plane
            Plane     globalWorkObjectPlane = new Plane(movement.WorkObject.GlobalWorkObjectPlane);
            Transform orient = Transform.ChangeBasis(Plane.WorldXY, globalWorkObjectPlane);

            plane1.Transform(orient);

            // Target plane position and orientation change per interpolation step
            Vector3d posChange   = (plane2.Origin - plane1.Origin) / _interpolations;
            Vector3d xAxisChange = (plane2.XAxis - plane1.XAxis) / _interpolations;
            Vector3d yAxisChange = (plane2.YAxis - plane1.YAxis) / _interpolations;

            // Correct axis configuration, tool and work object
            RobotTarget subTarget   = new RobotTarget(robotTarget.Name, Plane.WorldXY, robotTarget.AxisConfig);
            Movement    subMovement = new Movement(subTarget);

            subMovement.RobotTool  = movement.RobotTool;
            subMovement.WorkObject = movement.WorkObject;

            // New external joint position
            ExternalJointPosition newExternalJointPosition = _lastExternalJointPosition;

            // Create the sub target planes, robot joint positions and external joint positions for every interpolation step
            for (int i = 0; i < _interpolations; i++)
            {
                // Create new plane: the local target plane (in work object coordinate space)
                Plane plane = new Plane(plane1.Origin + posChange * i, plane1.XAxis + xAxisChange * i, plane1.YAxis + yAxisChange * i);

                // Update the target and movement
                subTarget.Plane = plane;
                subTarget.ExternalJointPosition = newExternalJointPosition;
                subMovement.Target = subTarget;

                // Calculate joint positions
                _robot.InverseKinematics.Movement = subMovement;
                _robot.InverseKinematics.Calculate();

                // Auto Axis Config
                if (_linearConfigurationControl == false)
                {
                    if (i == 0)
                    {
                        _robot.InverseKinematics.CalculateClosestRobotJointPosition(_lastRobotJointPosition);
                    }
                    else
                    {
                        _robot.InverseKinematics.CalculateClosestRobotJointPosition(_robotJointPositions.Last());
                    }
                }

                // Add te calculated joint positions and plane to the class property
                _robotJointPositions.Add(_robot.InverseKinematics.RobotJointPosition.Duplicate());
                _externalJointPositions.Add(_robot.InverseKinematics.ExternalJointPosition.Duplicate());

                // Add error messages (check axis limits)
                _errorText.AddRange(_robot.InverseKinematics.ErrorText.ConvertAll(item => string.Copy(item)));

                // Add the plane
                Plane globalPlane = subMovement.GetPosedGlobalTargetPlane();
                _planes.Add(globalPlane);

                // Always add the first point to list with paths
                if (i == 0)
                {
                    points.Add(new Point3d(globalPlane.Origin));
                }

                // Only add the other point if this point is different
                else if (points[points.Count - 1] != globalPlane.Origin)
                {
                    points.Add(new Point3d(globalPlane.Origin));
                }

                // Update the external joint position
                newExternalJointPosition += externalJointPositionChange;
            }

            // Add last point
            Point3d lastPoint = movement.GetPosedGlobalTargetPlane().Origin;

            if (points[points.Count - 1] != lastPoint)
            {
                points.Add(lastPoint);
            }

            // Generate path curve
            if (points.Count > 1)
            {
                _paths.Add(Curve.CreateInterpolatedCurve(points, 3));
            }
            else
            {
                _paths.Add(null);
            }

            // Get the final joint positions of this movement
            _robot.InverseKinematics.Movement = movement;
            _robot.InverseKinematics.Calculate();

            // Auto Axis Config
            if (_linearConfigurationControl == false)
            {
                _robot.InverseKinematics.CalculateClosestRobotJointPosition(_robotJointPositions.Last());
            }

            // Add error messages (check axis limits)
            _errorText.AddRange(_robot.InverseKinematics.ErrorText.ConvertAll(item => string.Copy(item)));

            // Add last Joint Poistions
            _lastRobotJointPosition    = _robot.InverseKinematics.RobotJointPosition.Duplicate();
            _lastExternalJointPosition = _robot.InverseKinematics.ExternalJointPosition.Duplicate();
        }