Пример #1
0
        private void DrawJobPreview(Graphics g, GrblCommand.StatePositionBuilder spb, float zoom)
        {
            bool firstline = true;             //used to draw the first line in a different color

            foreach (GrblCommand cmd in list)
            {
                try
                {
                    cmd.BuildHelper();
                    spb.AnalyzeCommand(cmd, false);


                    if (spb.TrueMovement())
                    {
                        Color linecolor = Color.FromArgb(spb.GetCurrentAlpha(mRange.SpindleRange), firstline ? ColorScheme.PreviewFirstMovement : spb.LaserBurning ? ColorScheme.PreviewLaserPower : ColorScheme.PreviewOtherMovement);
                        using (Pen pen = GetPen(linecolor))
                        {
                            pen.ScaleTransform(1 / zoom, 1 / zoom);

                            if (!spb.LaserBurning)
                            {
                                pen.DashStyle   = DashStyle.Dash;
                                pen.DashPattern = new float[] { 1f, 1f };
                            }

                            if (spb.G0G1 && cmd.IsLinearMovement && pen.Color.A > 0)
                            {
                                g.DrawLine(pen, new PointF((float)spb.X.Previous, (float)spb.Y.Previous), new PointF((float)spb.X.Number, (float)spb.Y.Number));
                            }
                            else if (spb.G2G3 && cmd.IsArcMovement && pen.Color.A > 0)
                            {
                                GrblCommand.G2G3Helper ah = spb.GetArcHelper(cmd);

                                if (ah.RectW > 0 && ah.RectH > 0)
                                {
                                    try { g.DrawArc(pen, (float)ah.RectX, (float)ah.RectY, (float)ah.RectW, (float)ah.RectH, (float)(ah.StartAngle * 180 / Math.PI), (float)(ah.AngularWidth * 180 / Math.PI)); }
                                    catch { System.Diagnostics.Debug.WriteLine(String.Format("Ex drwing arc: W{0} H{1}", ah.RectW, ah.RectH)); }
                                }
                            }
                        }

                        firstline = false;
                    }
                }
                catch (Exception ex) { throw ex; }
                finally { cmd.DeleteHelper(); }
            }
        }
Пример #2
0
        public void DrawOnGraphics(Graphics g, Size size)
        {
            if (!mRange.MovingRange.ValidRange)
            {
                return;
            }

            GrblCommand.StatePositionBuilder spb        = new GrblCommand.StatePositionBuilder();
            ProgramRange.XYRange             scaleRange = mRange.MovingRange;

            //Get scale factors for both directions. To preserve the aspect ratio, use the smaller scale factor.
            float zoom = scaleRange.Width > 0 && scaleRange.Height > 0 ? Math.Min((float)size.Width / (float)scaleRange.Width, (float)size.Height / (float)scaleRange.Height) * 0.95f : 1;


            ScaleAndPosition(g, size, scaleRange, zoom);
            DrawJobPreview(g, spb, zoom);
            DrawJobRange(g, size, zoom);
        }
Пример #3
0
        internal List <GrblCommand> BuildContinueFromIV(int position)        //create an initialization vector for re-run the file
        {
            List <GrblCommand> rv = new List <GrblCommand>();

            GrblCommand.StatePositionBuilder spb = new GrblCommand.StatePositionBuilder();

            for (int i = 0; i < position && i < Count; i++)             //find last M,F,S sent
            {
                spb.Update(this[i]);
            }

            rv.Add(new GrblCommand("G90"));                                                              //absolute coordinate
            rv.Add(new GrblCommand(string.Format("M5 G0 {0} {1} {2} {3}", spb.X, spb.Y, spb.F, spb.S))); //fast go to the computed position with laser off and set speed and power

            foreach (GrblCommand.StateBuilder.ModalElement e in spb.GetSettledModals())                  //restore modal state
            {
                rv.Add(new GrblCommand(e.ToString()));
            }

            return(rv);
        }
Пример #4
0
        private void Analyze()         //analyze the file and build global range and timing for each command
        {
            GrblCommand.StatePositionBuilder spb = new GrblCommand.StatePositionBuilder();

            mRange.ResetRange();
            mRange.UpdateXYRange("X0", "Y0", false);
            mEstimatedTotalTime = TimeSpan.Zero;

            foreach (GrblCommand cmd in list)
            {
                try
                {
                    GrblConf conf  = (GrblConf)Settings.GetObject("Grbl Configuration", new GrblConf());
                    TimeSpan delay = spb.AnalyzeCommand(cmd, true, conf);

                    mRange.UpdateSRange(spb.S);
                    mRange.UpdateXYRange(spb.X, spb.Y, spb.LaserBurning);
                    mEstimatedTotalTime += delay;
                    cmd.SetOffset(mEstimatedTotalTime);
                }
                catch (Exception ex) { throw ex; }
                finally { cmd.DeleteHelper(); }
            }
        }
Пример #5
0
        internal void DrawOnGraphics(Graphics g, Size s)
        {
            if (!mRange.MovingRange.ValidRange)
            {
                return;
            }

            GrblCommand.StatePositionBuilder spb        = new GrblCommand.StatePositionBuilder();
            ProgramRange.XYRange             scaleRange = mRange.MovingRange;

            //Get scale factors for both directions. To preserve the aspect ratio, use the smaller scale factor.
            float zoom      = scaleRange.Width > 0 && scaleRange.Height > 0 ? Math.Min((float)s.Width / (float)scaleRange.Width, (float)s.Height / (float)scaleRange.Height) * 0.95f : 1;
            bool  firstline = true;            //used to draw the first line in a different color

            ScaleAndPosition(g, s, scaleRange, zoom);

            foreach (GrblCommand cmd in list)
            {
                try
                {
                    cmd.BuildHelper();
                    spb.AnalyzeCommand(cmd, false);


                    if (spb.TrueMovement())
                    {
                        Color linecolor = Color.FromArgb(spb.GetCurrentAlpha(mRange.SpindleRange), firstline ? ColorScheme.PreviewFirstMovement : spb.LaserBurning ? ColorScheme.PreviewLaserPower : ColorScheme.PreviewOtherMovement);
                        using (Pen pen = GetPen(linecolor))
                        {
                            pen.ScaleTransform(1 / zoom, 1 / zoom);

                            if (!spb.LaserBurning)
                            {
                                pen.DashStyle   = DashStyle.Dash;
                                pen.DashPattern = new float[] { 1f, 1f };
                            }

                            if (spb.G0G1 && cmd.IsLinearMovement && pen.Color.A > 0)
                            {
                                g.DrawLine(pen, new PointF((float)spb.X.Previous, (float)spb.Y.Previous), new PointF((float)spb.X.Number, (float)spb.Y.Number));
                            }
                            else if (spb.G2G3 && cmd.IsArcMovement && pen.Color.A > 0)
                            {
                                PointF center = cmd.GetCenter((float)spb.X.Previous, (float)spb.Y.Previous);
                                double cX     = center.X;
                                double cY     = center.Y;
                                double aX     = (double)spb.X.Previous;
                                double aY     = (double)spb.Y.Previous;
                                double bX     = (double)spb.X.Number;
                                double bY     = (double)spb.Y.Number;

                                double ray   = cmd.GetArcRadius();
                                double rectX = cX - ray;
                                double rectY = cY - ray;
                                double rectW = 2 * ray;
                                double rectH = 2 * ray;

                                double aA = Tools.MathHelper.CalculateAngle(cX, cY, aX, aY); //180/Math.PI*Math.Atan2(y1-y0, x1-x0);
                                double bA = Tools.MathHelper.CalculateAngle(cX, cY, bX, bY); //180/Math.PI*Math.Atan2(y2-y0, x2-x0);

                                double sA = aA;                                              //start angle
                                double wA = Tools.MathHelper.AngularDistance(aA, bA, spb.G2);

                                if (rectW > 0 && rectH > 0)
                                {
                                    try { g.DrawArc(pen, (float)rectX, (float)rectY, (float)rectW, (float)rectH, (float)sA, (float)wA); }
                                    catch { System.Diagnostics.Debug.WriteLine(String.Format("Ex drwing arc: W{0} H{1}", rectW, rectH)); }
                                }
                            }
                        }

                        firstline = false;
                    }
                }
                catch (Exception ex) { throw ex; }
                finally { cmd.DeleteHelper(); }
            }

            DrawJobRange(g, s, zoom);
        }
Пример #6
0
        internal void DrawOnGraphics(Graphics g, Size s)
        {
            if (!mRange.MovingRange.ValidRange)
            {
                return;
            }

            GrblCommand.StatePositionBuilder spb        = new GrblCommand.StatePositionBuilder();
            ProgramRange.XYRange             scaleRange = mRange.MovingRange;

            //Get scale factors for both directions. To preserve the aspect ratio, use the smaller scale factor.
            float zoom      = scaleRange.Width > 0 && scaleRange.Height > 0 ? Math.Min((float)s.Width / (float)scaleRange.Width, (float)s.Height / (float)scaleRange.Height) * 0.95f : 1;
            bool  firstline = true;            //used to draw the first line in a different color

            ScaleAndPosition(g, s, scaleRange, zoom);

            foreach (GrblCommand cmd in list)
            {
                try
                {
                    cmd.BuildHelper();
                    spb.AnalyzeCommand(cmd, false);


                    if (spb.TrueMovement())
                    {
                        Color linecolor = Color.FromArgb(spb.GetCurrentAlpha(mRange.SpindleRange), firstline ? ColorScheme.PreviewFirstMovement : spb.LaserBurning ? ColorScheme.PreviewLaserPower : ColorScheme.PreviewOtherMovement);
                        using (Pen pen = GetPen(linecolor))
                        {
                            pen.ScaleTransform(1 / zoom, 1 / zoom);

                            if (!spb.LaserBurning)
                            {
                                pen.DashStyle   = DashStyle.Dash;
                                pen.DashPattern = new float[] { 1f, 1f };
                            }

                            if (spb.G0G1 && cmd.IsLinearMovement && pen.Color.A > 0)
                            {
                                g.DrawLine(pen, new PointF((float)spb.X.Previous, (float)spb.Y.Previous), new PointF((float)spb.X.Number, (float)spb.Y.Number));
                            }
                            else if (spb.G2G3 && cmd.IsArcMovement && pen.Color.A > 0)
                            {
                                GrblCommand.G2G3Helper ah = spb.GetArcHelper(cmd);

                                if (ah.RectW > 0 && ah.RectH > 0)
                                {
                                    try { g.DrawArc(pen, (float)ah.RectX, (float)ah.RectY, (float)ah.RectW, (float)ah.RectH, (float)(ah.StartAngle * 180 / Math.PI), (float)(ah.AngularWidth * 180 / Math.PI)); }
                                    catch { System.Diagnostics.Debug.WriteLine(String.Format("Ex drwing arc: W{0} H{1}", ah.RectW, ah.RectH)); }
                                }
                            }
                        }

                        firstline = false;
                    }
                }
                catch (Exception ex) { throw ex; }
                finally { cmd.DeleteHelper(); }
            }

            DrawJobRange(g, s, zoom);
        }