Esempio n. 1
0
        public bool?SaveLayout()
        {
            if (Layout == null)
            {
                return(false);
            }

            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)
            {
                Point gcodeOrigin = new Point(0, 0);

                // get and process parameters
                GCodeParameters parameters = Application.Current.FindResource("GCodeSetup") as GCodeParameters;

                if (parameters.OriginTypes[parameters.Origin] == "Panels Bottom Left")
                {
                    double minX = Double.MaxValue;
                    double maxY = Double.MinValue;
                    foreach (Panel panel in Layout.Panels)
                    {
                        double          x, y;
                        PointCollection points = panel.Points;
                        GeometryOperations.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(Layout.SheetWidth / 2, Layout.SheetHeight / 2);
                }

                // Do the actual output
                Open(saveDlg.FileName);
                foreach (Panel panel in Layout.Panels)
                {
                    Write(panel, gcodeOrigin);
                }

                Close();
                return(true);
            }

            return(result);
        }
Esempio n. 2
0
        private void Open(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
        }