예제 #1
0
        private void LoadProgram()
        {
            // Create an instance of the open file dialog box.
            OpenFileDialog fileDialog = new OpenFileDialog();

            // Set filter options and filter index.
            fileDialog.Filter      = "XML Files (.xml)|*.xml|All Files (*.*)|*.*";
            fileDialog.FilterIndex = 1;
            fileDialog.Multiselect = false;

            // Show the dialog and get result.
            DialogResult result = fileDialog.ShowDialog();

            if (result == DialogResult.OK) // Test result.
            {
                string         path     = fileDialog.FileName;
                MotionCommands commands = CommandsStore.Load(path);

                if (commands != null && commands.Count > 0)
                {
                    this.programControl.Commands = commands;

                    this.lstCommands.Items.Clear();
                    MotionCommand[] test = new MotionCommand[this.programControl.Commands.Count];
                    this.programControl.Commands.CopyTo(test, 0);
                    this.lstCommands.Items.AddRange(test);
                }

                this.programName = Path.GetFileNameWithoutExtension(path);

                this.lblProgramName.Text = String.Format("Program: {0}", this.programName);
            }
        }
 /// <summary>
 /// Save commmands to XML.
 /// </summary>
 /// <remarks>
 /// @"c:\temp\SerializationOverview.xml"
 /// </remarks>
 /// <param name="commands">Commands</param>
 /// <param name="path">File</param>
 public static void Save(MotionCommands commands, string path)
 {
     XmlSerializer writer = new XmlSerializer(typeof(MotionCommands));
     StreamWriter file = new System.IO.StreamWriter(path);
     writer.Serialize(file, commands);
     file.Close();
 }
        /// <summary>
        /// Read commands from XML.
        /// </summary>
        /// <remarks>@"c:\temp\SerializationOverview.xml"</remarks>
        /// <param name="path">File</param>
        /// <returns>Commands</returns>
        public static MotionCommands Load(string path)
        {
            XmlSerializer reader = new XmlSerializer(typeof(MotionCommands));
            MotionCommands commands = new MotionCommands();
            StreamReader file = new StreamReader(path);
            commands = (MotionCommands)reader.Deserialize(file);
            file.Close();

            return commands;
        }
        private void Prune(List <Word> words, string line, int lineNumber)
        {
            while (words.Count > 0)
            {
                /* Ignore for now,
                 * From comment that generates parameter:
                 #If we're using pronterface, we need to change raster data / and + in the base64 alphabet to letter 9. This loses a little intensity in pure blacks but keeps pronterface happy.
                 *  if( self.options.pronterface ):
                 *      b64 = b64.replace("+", "9").replace("/", "9");
                 */
                var prontoFaceDCommand = words.Where(wrd => wrd.Command == 'D').FirstOrDefault();
                if (prontoFaceDCommand != null)
                {
                    words.Remove(prontoFaceDCommand);
                    continue;
                }

                /* ???? */
                var unknown = words.Where(wrd => wrd.Command == 'B').FirstOrDefault();
                if (unknown != null)
                {
                    words.Remove(unknown);
                    continue;
                }


                if (words.First().Command == 'G' && !MotionCommands.Contains(words.First().Parameter))
                {
                    #region UnitPlaneDistanceMode

                    double param = words.First().Parameter;

                    if (param == 90)
                    {
                        State.DistanceMode = ParseDistanceMode.Absolute;
                        words.RemoveAt(0);
                        continue;
                    }
                    if (param == 91)
                    {
                        State.DistanceMode = ParseDistanceMode.Relative;
                        words.RemoveAt(0);
                        continue;
                    }
                    if (param == 90.1)
                    {
                        State.ArcDistanceMode = ParseDistanceMode.Absolute;
                        words.RemoveAt(0);
                        continue;
                    }
                    if (param == 91.1)
                    {
                        State.ArcDistanceMode = ParseDistanceMode.Relative;
                        words.RemoveAt(0);
                        continue;
                    }
                    if (param == 21)
                    {
                        State.Unit = ParseUnit.Metric;
                        words.RemoveAt(0);
                        continue;
                    }
                    if (param == 20)
                    {
                        State.Unit = ParseUnit.Imperial;
                        words.RemoveAt(0);
                        continue;
                    }
                    if (param == 17)
                    {
                        State.Plane = ArcPlane.XY;
                        words.RemoveAt(0);
                        continue;
                    }
                    if (param == 18)
                    {
                        State.Plane = ArcPlane.ZX;
                        words.RemoveAt(0);
                        continue;
                    }
                    if (param == 19)
                    {
                        State.Plane = ArcPlane.YZ;
                        words.RemoveAt(0);
                        continue;
                    }

                    words.RemoveAt(0);  //unsupported G-Command
                    continue;
                    #endregion
                }

                break;
            }
        }