示例#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
        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);
        }