/// <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)
        {
            // Gets ObjectManager of this document
            _objectManager = DocumentManager.GetDocumentObjectManager(this.OnPingDocument());

            // Input variables
            Robot robInfo = new Robot();
            List <RobotComponents.Actions.Action> actions = new List <RobotComponents.Actions.Action>();
            string        programName     = "";
            string        systemName      = "";
            List <string> customCodeLines = new List <string>()
            {
            };
            bool update = true;

            // Catch the input data
            if (!DA.GetData(0, ref robInfo))
            {
                return;
            }
            if (!DA.GetDataList(1, actions))
            {
                return;
            }
            if (!DA.GetData(2, ref programName))
            {
                programName = "MainModule";
            }
            if (!DA.GetData(3, ref systemName))
            {
                systemName = "BASE";
            }
            if (!DA.GetDataList(4, customCodeLines))
            {
                customCodeLines = new List <string>()
                {
                };
            }
            if (!DA.GetData(5, ref update))
            {
                update = true;
            }

            // Checks if module name exceeds max character limit for RAPID Code
            if (HelperMethods.VariableExeedsCharacterLimit32(programName))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Program Module Name exceeds character limit of 32 characters.");
            }
            if (HelperMethods.VariableExeedsCharacterLimit32(systemName))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "System Module Name exceeds character limit of 32 characters.");
            }

            // Checks if module name starts with a number
            if (HelperMethods.VariableStartsWithNumber(programName))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Program Module Name starts with a number which is not allowed in RAPID Code.");
            }
            if (HelperMethods.VariableStartsWithNumber(systemName))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "System Module Name starts with a number which is not allowed in RAPID Code.");
            }

            // Updates the rapid Progam and System code
            if (update == true)
            {
                // Initiaties the rapidGenerator
                _rapidGenerator = new RAPIDGenerator(programName, systemName, actions, null, false, robInfo);

                // Generator code
                _rapidGenerator.CreateProgramCode();
                _rapidGenerator.CreateSystemCode(customCodeLines);
                _programCode = _rapidGenerator.ProgramCode;
                _systemCode  = _rapidGenerator.SystemCode;

                // Check if the first movement is an absolute joint movement.
                _firstMovementIsMoveAbsJ = _rapidGenerator.FirstMovementIsMoveAbsJ;

                // Raise warnings?
                if (_rapidGenerator.ErrorText.Count != 0)
                {
                    _raiseWarnings = true;
                }
                else
                {
                    _raiseWarnings = false;
                }
            }

            // Checks if first Movement is MoveAbsJ
            if (_firstMovementIsMoveAbsJ == false)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The first movement is not set as an absolute joint movement.");
            }

            // Show warning messages
            if (_raiseWarnings == true)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Only axis values of absolute joint movements are checked.");

                for (int i = 0; i < _rapidGenerator.ErrorText.Count; i++)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, _rapidGenerator.ErrorText[i]);
                    if (i == 30)
                    {
                        break;
                    }
                }
            }

            // Output
            DA.SetData(0, _programCode);
            DA.SetData(1, _systemCode);
        }
Example #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)
        {
            // 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 ObjectManager of this document
            _objectManager = DocumentManager.GetDocumentObjectManager(this.OnPingDocument());

            // Input variables
            Robot robInfo = new Robot();
            List <RobotComponents.Actions.Action> actions = new List <RobotComponents.Actions.Action>();
            string moduleName = "";
            string filePath   = "";
            bool   saveToFile = false;
            bool   update     = true;

            // Catch the input data
            if (!DA.GetData(0, ref robInfo))
            {
                return;
            }
            if (!DA.GetDataList(1, actions))
            {
                return;
            }
            if (!DA.GetData(2, ref moduleName))
            {
                moduleName = "MainModule";
            }
            if (!DA.GetData(3, ref filePath))
            {
                return;
            }
            if (!DA.GetData(4, ref saveToFile))
            {
                return;
            }
            if (!DA.GetData(5, ref update))
            {
                return;
            }

            // Checks if module name exceeds max character limit for RAPID Code
            if (HelperMethods.VariableExeedsCharacterLimit32(moduleName))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Module Name exceeds character limit of 32 characters.");
            }

            // Checks if module name starts with a number
            if (HelperMethods.VariableStartsWithNumber(moduleName))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Module Name starts with a number which is not allowed in RAPID Code.");
            }

            // Saved file
            bool updated = false; // Avoids saving the file two times in one run

            // Updates the rapid BASE and MAIN code
            if (update == true)
            {
                // Initiaties the rapidGenerator
                _rapidGenerator = new RAPIDGenerator(moduleName, "BASE", actions, filePath, saveToFile, robInfo.Duplicate());

                // Get tools data for system module
                List <RobotTool>  robotTools  = _objectManager.GetRobotTools();  // Gets all the robot tools from the object manager
                List <WorkObject> workObjects = _objectManager.GetWorkObjects(); // Gets all the work objects from the object manager
                List <string>     customCode  = new List <string>()
                {
                };

                // Generator code
                _rapidGenerator.CreateSystemCode(robotTools, workObjects, customCode);
                _rapidGenerator.CreateProgramCode();
                _MAINCode = _rapidGenerator.ProgramCode;
                _BASECode = _rapidGenerator.SystemCode;

                // Check if the first movement is an absolute joint movement.
                _firstMovementIsMoveAbsJ = _rapidGenerator.FirstMovementIsMoveAbsJ;

                // Saved file
                updated = true; // Avoids saving the file two times in one run
            }

            // Save to file
            if (saveToFile == true && updated == false) // Avoids saving the file two times in one run
            {
                _rapidGenerator.FilePath = filePath;
                _rapidGenerator.WriteProgramCodeToFile();
                _rapidGenerator.WriteSystemCodeToFile();
            }

            // Checks if first Movement is MoveAbsJ
            if (_firstMovementIsMoveAbsJ == false)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The first movement is not set as an absolute joint movement.");
            }

            // Output
            DA.SetData(0, _MAINCode);
            DA.SetData(1, _BASECode);
        }