Exemplo n.º 1
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
            ExternalRotationalAxis externalRotationalAxis = null;

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

            // Check if the object is valid
            if (!externalRotationalAxis.IsValid)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The External Rotational Axis is not valid");
            }

            // Output
            DA.SetData(0, externalRotationalAxis.Name);
            DA.SetData(1, externalRotationalAxis.AxisPlane);
            DA.SetData(2, externalRotationalAxis.AxisLimits);
            DA.SetData(3, externalRotationalAxis.BaseMesh);
            DA.SetData(4, externalRotationalAxis.LinkMesh);
            DA.SetData(5, externalRotationalAxis.AxisLogic);
            DA.SetData(6, externalRotationalAxis.MovesRobot);
        }
Exemplo n.º 2
0
        /// <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)
        {
            // Input variables
            string      name       = "";
            Plane       axisPlane  = Plane.WorldXY;
            Interval    limits     = new Interval(0, 0);
            List <Mesh> baseMeshes = new List <Mesh>();
            List <Mesh> linkMeshes = new List <Mesh>();

            // Catch the input data
            if (!DA.GetData(0, ref name))
            {
                return;
            }
            if (!DA.GetData(1, ref axisPlane))
            {
                return;
            }
            if (!DA.GetData(2, ref limits))
            {
                return;
            }
            if (!DA.GetDataList(3, baseMeshes))
            {
                baseMeshes = new List <Mesh>()
                {
                    new Mesh()
                };
            }
            if (!DA.GetDataList(4, linkMeshes))
            {
                linkMeshes = new List <Mesh>()
                {
                    new Mesh()
                };
            }

            // Create the external rotational axis
            _externalRotationalAxis = new ExternalRotationalAxis(name, axisPlane, limits, baseMeshes, linkMeshes);

            // Output
            DA.SetData(0, _externalRotationalAxis);

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

            // Clears ExternalAxisNames
            _objectManager.ExternalAxisNames.Remove(_axisName);
            _axisName = String.Empty;

            // Removes lastName from ExternalAxisNames List
            if (_objectManager.ExternalAxisNames.Contains(_lastName))
            {
                _objectManager.ExternalAxisNames.Remove(_lastName);
            }

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

            // Checks if axis name is already in use and counts duplicates
            #region Check name in object manager
            if (_objectManager.ExternalAxisNames.Contains(_externalRotationalAxis.Name))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "External Axis Name already in use.");
                _nameUnique = false;
                _lastName   = "";
            }
            else
            {
                // Adds Robot Axis Name to list
                _axisName = _externalRotationalAxis.Name;
                _objectManager.ExternalAxisNames.Add(_externalRotationalAxis.Name);

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

                _lastName   = _externalRotationalAxis.Name;
                _nameUnique = true;
            }
            #endregion

            // Recognizes if Component is Deleted and removes it from Object Managers axis 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)
        {
            // Clears Work Objects List
            _workObjects.Clear();

            // Input variables
            List <string> names  = new List <string>();
            List <Plane>  planes = new List <Plane>();
            List <ExternalRotationalAxis> externalAxes = new List <ExternalRotationalAxis>();

            // Catch the input data
            if (!DA.GetDataList(0, names))
            {
                return;
            }
            if (!DA.GetDataList(1, planes))
            {
                return;
            }
            if (!DA.GetDataList(2, externalAxes))
            {
                externalAxes = new List <ExternalRotationalAxis>()
                {
                    null
                };
            }

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

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

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

            // Creates work objects
            WorkObject        workObject;
            List <WorkObject> workObjects = new List <WorkObject>();

            for (int i = 0; i < biggestSize; i++)
            {
                string name  = "";
                Plane  plane = new Plane();
                ExternalRotationalAxis externalAxis = null;

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

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

                // Axis counter
                if (i < sizeValues[2])
                {
                    externalAxis = externalAxes[i];
                    axisCounter++;
                }
                else
                {
                    externalAxis = externalAxes[axisCounter];
                }

                // Make work object
                workObject = new WorkObject(name, plane, externalAxis);
                workObjects.Add(workObject);
            }

            // Output
            _workObjects = workObjects;
            DA.SetDataList(0, workObjects);

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

            // Clears Work Object Name
            for (int i = 0; i < _woNames.Count; i++)
            {
                _objectManager.WorkObjectNames.Remove(_woNames[i]);
            }
            _woNames.Clear();

            // Removes lastName from WorkObjectNameList
            if (_objectManager.WorkObjectNames.Contains(_lastName))
            {
                _objectManager.WorkObjectNames.Remove(_lastName);
            }

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

            // Checks if the work object 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.WorkObjectNames.Contains(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Work Object Name already in use.");
                    _namesUnique = false;
                    _lastName    = "";
                    break;
                }
                else
                {
                    // Adds Work Object Name to list
                    _woNames.Add(names[i]);
                    _objectManager.WorkObjectNames.Add(names[i]);

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

                    _lastName = names[i];
                }

                // Checks if variable name exceeds max character limit for RAPID Code
                if (HelperMethods.VariableExeedsCharacterLimit32(names[i]))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Work Object 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, "Work Object 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
        }