Ejemplo n.º 1
0
        private void PreviewPanel_Paint(object sender, PaintEventArgs e)
        {
            //Graphics g = e.Graphics;
            using (Bitmap bmp = new Bitmap(PreviewPanel.Width, PreviewPanel.Height))
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.Clip = new Region();
                    using (SolidBrush b = new SolidBrush(PreviewPanel.BackColor))
                        g.FillRectangle(b, 0, 0, PreviewPanel.Width, PreviewPanel.Height);

                    if (ScanInfo != null)
                    {
                        try
                        {
                            ScanLine        line       = null;
                            LaserCorrection corr       = null;
                            double          size       = ScanInfo.Size() * 0.66f;
                            double          factor     = Math.Min(PreviewPanel.Width, PreviewPanel.Height) / size;
                            Matrix4d        baseMatrix = Matrix4d.Scale(factor);
                            PointF          center     = new PointF(PreviewPanel.Width / 2, PreviewPanel.Height / 2);
                            DrawGrid(g, center, (float)factor);
                            int             currentLaser      = CurrentLaserIndex;
                            List <ScanLine> selectedLaserLine = new List <ScanLine>();
                            for (int i = 0; i < ScanInfo.Count; i++)
                            {
                                line = ScanInfo[i];

                                corr = new LaserCorrection();
                                corr.LoadFromSettings(line.LaserID);
                                bool selected = currentLaser == line.LaserID;
                                if (!selected)
                                {
                                    DrawScanLine(g, center, factor, line, corr, false);
                                }
                                else
                                {
                                    selectedLaserLine.Add(line);
                                }
                            }

                            corr = new LaserCorrection();
                            corr.LoadFromSettings(selectedLaserLine[Math.Max(0, currentLaser)].LaserID);
                            corr.Apply(Drag);
                            for (int i = 0; i < selectedLaserLine.Count; i++)
                            {
                                DrawScanLine(g, center, factor, selectedLaserLine[i], corr, true);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                e.Graphics.Clip = new Region();
                e.Graphics.DrawImageUnscaled(bmp, new Point(0, 0));
            }
        }
Ejemplo n.º 2
0
 void CommitCorrection()
 {
     if (CurrentLaserIndex >= 0)
     {
         LaserCorrection cor = new LaserCorrection();
         cor.LoadFromSettings(CurrentLaserIndex);
         cor.Apply(Drag);
         cor.SaveToSettings(CurrentLaserIndex);
         Drag.Init();
     }
 }