Exemple #1
0
        public void OpenFile()
        {
            string filename = null;

            using (System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog())
            {
                ofd.Filter           = "Any supported file|*.nc;*.gcode;*.bmp;*.png;*.jpg;*.gif|GCODE Files|*.nc;*.gcode|Raster Image|*.bmp;*.png;*.jpg;*.gif";
                ofd.CheckFileExists  = true;
                ofd.Multiselect      = false;
                ofd.RestoreDirectory = true;
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    filename = ofd.FileName;
                }
            }

            if (filename != null)
            {
                if (ImageExtensions.Contains(System.IO.Path.GetExtension(filename).ToLowerInvariant()))                 //import raster image
                {
                    RasterConverter.RasterToLaserForm.CreateAndShowDialog(this, filename);
                }
                else                 //load GCODE file
                {
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
                    file.LoadFile(filename);
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                }
            }
        }
Exemple #2
0
        public void OpenFile(System.Windows.Forms.Form parent)
        {
            try
            {
                string filename = null;
                using (System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog())
                {
                    //pre-select last file if exist
                    string lastFN = (string)Settings.GetObject("Core.LastOpenFile", null);
                    if (lastFN != null && System.IO.File.Exists(lastFN))
                    {
                        ofd.FileName = lastFN;
                    }

                    ofd.Filter           = "Any supported file|*.nc;*.cnc;*.tap;*.gcode;*.bmp;*.png;*.jpg;*.gif|GCODE Files|*.nc;*.cnc;*.tap;*.gcode|Raster Image|*.bmp;*.png;*.jpg;*.gif";
                    ofd.CheckFileExists  = true;
                    ofd.Multiselect      = false;
                    ofd.RestoreDirectory = true;
                    if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        filename = ofd.FileName;
                    }
                }

                if (filename != null)
                {
                    Logger.LogMessage("OpenFile", "Open {0}", filename);
                    Settings.SetObject("Core.LastOpenFile", filename);

                    if (ImageExtensions.Contains(System.IO.Path.GetExtension(filename).ToLowerInvariant()))                     //import raster image
                    {
                        try
                        { RasterConverter.RasterToLaserForm.CreateAndShowDialog(this, filename, parent); }
                        catch (Exception ex)
                        { Logger.LogException("RasterImport", ex); }
                    }
                    else                     //load GCODE file
                    {
                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                        try
                        { file.LoadFile(filename); }
                        catch (Exception ex)
                        { Logger.LogException("GCodeImport", ex); }

                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("OpenFile", ex);
            }
        }