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)); } }
void CommitCorrection() { if (CurrentLaserIndex >= 0) { LaserCorrection cor = new LaserCorrection(); cor.LoadFromSettings(CurrentLaserIndex); cor.Apply(Drag); cor.SaveToSettings(CurrentLaserIndex); Drag.Init(); } }
void ClearCorrection(int index) { LaserCorrection cor = new LaserCorrection(); cor.SaveToSettings(index); }
protected void DrawScanLine(Graphics g, PointF translation, double scale, ScanLine line, LaserCorrection corr, bool selected) { List <PointF> points = new List <PointF>(line.Count); Matrix4d m = corr.GetMatrix(); int laserid = line.LaserID; int count = line.Count; Color baseCol = GetLaserColor(laserid); Color col = Color.FromArgb(selected ? 128 / NumClass : 64 / NumClass, baseCol); for (int i = 0; i < line.Count; i++) { Point3D p = line[i]; Vector3d v = Vector3d.Transform(p.Position, m); PointF pt = new PointF((float)(v.X * scale), (float)(v.Z * scale)); pt.X += translation.X; pt.Y += translation.Y; points.Add(pt); } using (SolidBrush b = new SolidBrush(col)) g.FillPolygon(b, points.ToArray()); using (Pen b = new Pen(Color.FromArgb(selected ? 128 : 64, baseCol))) g.DrawPolygon(b, points.ToArray()); }