Ejemplo n.º 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(); }
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }