Exemplo n.º 1
0
 public ObjectHandler(string[] lines)
 {
     Xml          = new Module_XML();
     CommandList  = GetCommandList();
     Lines        = lines;
     LastSubIndex = GetLastSubIndex();
     DefineDoubleCommands();
 }
Exemplo n.º 2
0
        public virtual Dictionary <string, Func <string, bool> > ConstructDictionary(BaseFunctions FunctionClass)
        {
            string xmlRef = "";

            // Check if inherited class from BaseFunctions is HPGL or CNC
            if (FunctionClass.GetType().Name == "HPGLFunctions")
            {
                xmlRef = "HPGLCmds";
            }
            else if (FunctionClass.GetType().Name == "CNCFunctions")
            {
                xmlRef = "CNCCmds";
            }

            // Get commands from xml file
            XmlNode functions = new Module_XML().ReturnXml("Settings.xml", xmlRef);
            // Create temporary dictionary to save all commands
            Dictionary <string, string[]> dictionary = new Dictionary <string, string[]>();
            // Output dictionary
            Dictionary <string, Func <string, bool> > commands = new Dictionary <string, Func <string, bool> >();

            // Add each command to temporary dictionary
            foreach (XmlNode item in functions)
            {
                // Node can contain mutiple commands
                dictionary.Add(item.Name, item.InnerText.Split(','));
            }

            // Add all commands and functions to the output dictionary
            foreach (var item in dictionary)
            {
                foreach (string cmd in item.Value)
                {
                    // Check if command is not empty
                    if (cmd.Trim() != "")
                    {
                        // Add command to function
                        switch (item.Key)
                        {
                        case "Relative":
                            commands.Add(cmd.Trim(), FunctionClass.Relative);
                            break;

                        case "Arc":
                            commands.Add(cmd.Trim(), FunctionClass.Arc);
                            break;

                        case "Line":
                            commands.Add(cmd.Trim(), FunctionClass.Line);
                            break;

                        case "On":
                            commands.Add(cmd.Trim(), FunctionClass.On);
                            break;

                        case "Tool":
                            commands.Add(cmd.Trim(), FunctionClass.Tool);
                            break;

                        case "CallSub":
                            commands.Add(cmd.Trim(), FunctionClass.CallSubmain);
                            break;

                        case "StartSub":
                            commands.Add(cmd.Trim(), FunctionClass.StartSub);
                            break;

                        case "EndSub":
                            commands.Add(cmd.Trim(), FunctionClass.EndSub);
                            break;

                        case "Absolute":
                            commands.Add(cmd.Trim(), FunctionClass.Absolute);
                            break;

                        case "Off":
                            commands.Add(cmd.Trim(), FunctionClass.Off);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            return(commands);
        }