Esempio n. 1
0
        public GCodeWriter(string filename)
        {
            parameters = (GCodeParameters)Application.Current.FindResource("GCodeSetup");

            gCodeFile = new System.IO.StreamWriter(filename);
            gCodeFile.WriteLine("%");
            gCodeFile.WriteLine("O1234 ({0})", filename);
            gCodeFile.WriteLine("G20 G90 G40 M05");     // inches, absolute, no offset, Spindle ON. Could add G17: XY plane, but not supported
            gCodeFile.WriteLine("G00 Z0.25 M03");       // 0.25 inches above the surface
        }
        private void outputGCode(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveDlg = new SaveFileDialog();

            saveDlg.Filter           = "GCode files (*.nc)|*.nc|All files (*.*)|*.*";
            saveDlg.FilterIndex      = 1;
            saveDlg.RestoreDirectory = true;

            Nullable <bool> result = saveDlg.ShowDialog();

            if (result == true)
            {
                GCodeSetupPanel setup = new GCodeSetupPanel();
                setup.ShowDialog();
                Point gcodeOrigin = new Point(0, 0);
                if (setup.OK)
                {
                    GCodeParameters parameters = new GCodeParameters();
                    parameters = (GCodeParameters)Application.Current.FindResource("GCodeSetup");
                    if (parameters.OriginTypes[parameters.Origin] == "Panels Bottom Left")
                    {
                        double minX = Double.MaxValue;
                        double maxY = Double.MinValue;
                        foreach (PanelDisplay panel in m_displayPanels)
                        {
                            double          x, y;
                            PointCollection points = panel.GetPoints();
                            Geometry.TopLeft(points, out x, out y);
                            minX = Math.Min(minX, x);
                            maxY = Math.Max(maxY, y);
                        }
                        gcodeOrigin = new Point(minX, maxY);
                    }
                    else if (parameters.OriginTypes[parameters.Origin] == "Sheet Bottom Left")
                    {
                        gcodeOrigin = new Point(0, 0);
                    }
                    else if (parameters.OriginTypes[parameters.Origin] == "Sheet Center")
                    {
                        gcodeOrigin = new Point(m_panelWidth / 2, m_panelHeight / 2);
                    }
                    GCodeWriter output = new GCodeWriter(saveDlg.FileName);
                    foreach (PanelDisplay panel in m_displayPanels)
                    {
                        output.Write(panel, gcodeOrigin);
                    }

                    output.Close();
                }
            }
        }