/// <summary> /// Open GUI for editting selected crack /// </summary> private void btnEditSequence_Click(object sender, EventArgs e) { if (this.crackIndexValid()) { MeasurementSequence crack = this.cracks[this.ActiveIndex]; Console.WriteLine(crack.Mode); NewMeasurementForm form = new NewMeasurementForm(crack); DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { MeasurementSequence crack2 = findCrackName(form.GetName()); // Check if name is unique if (crack2 == null || crack2 == crack) { crack.Name = form.GetName(); crack.Color = Color.FromArgb(128, form.GetColor()); crack.LineSize = form.GetLineSize(); crack.Orientation = form.GetOrientation(); crack.Mode = form.GetMode(); this.updateMeasurementControls(); } else { MessageBox.Show("Please use a unique name"); } } } }
/// <summary> /// Draw cracks overlay on WFOV display /// </summary> private void wfovOverlayPaint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.ResetTransform(); // Draw crosshair if (this.checkCrosshair.Checked) { float midX = (g.VisibleClipBounds.Right + g.VisibleClipBounds.Left) / 2.0f; float midY = (g.VisibleClipBounds.Bottom + g.VisibleClipBounds.Top) / 2.0f; Pen pen = new Pen(Color.FromArgb(255, 0, 255, 0), 1); g.DrawLine(pen, new PointF(g.VisibleClipBounds.Left, midY), new PointF(g.VisibleClipBounds.Right, midY)); g.DrawLine(pen, new PointF(midX, g.VisibleClipBounds.Top), new PointF(midX, g.VisibleClipBounds.Bottom)); } // Now transform to world coordinates // Move image center to origin and rotate RectangleF bounds = g.VisibleClipBounds; g.TranslateTransform(bounds.Width / 2, bounds.Height / 2); g.RotateTransform((float)rccm.FineStageAngle); g.TranslateTransform(-bounds.Width / 2, -bounds.Height / 2); // Scale coordinate system by pixel to mm scaling float scaleX = bounds.Width / (float)this.camera.Width; float scaleY = bounds.Height / (float)this.camera.Height; g.ScaleTransform(scaleX, scaleY); // Move to WFOV location (first move origin to image center) g.TranslateTransform((float)this.camera.Width / 2, (float)this.camera.Height / 2); PointF pos = this.rccm.GetWFOVLocation(this.stage, CoordinateSystem.Global); g.TranslateTransform(-pos.X, -pos.Y); // Draw each crack on the image foreach (MeasurementSequence crack in cracks) { if (crack.Camera == this.cameraName) { crack.Plot(g, scaleX); } } // Draw segment that user is creating with mouse if (this.crackIndexValid() && this.Drawing) { Color c = cracks[ActiveIndex].Color; g.DrawLine(new Pen(Color.FromArgb(128, c), cracks[ActiveIndex].LineSize / scaleX), this.drawnLineStart, this.drawnLineEnd); } // Highlight selected point if (this.pointIndexValid()) { MeasurementSequence crack = this.cracks[this.ActiveIndex]; Measurement m = crack.GetPoint(this.ActivePoint); RectangleF point = new RectangleF(0, 0, 10.0f * crack.LineSize / scaleX, 10.0f * crack.LineSize / scaleX); point.X = (float)m.X - point.Width / 2.0f; point.Y = (float)m.Y - point.Height / 2.0f; g.FillEllipse(new SolidBrush(crack.Color), point); } }
/// <summary> /// Create new measurement /// </summary> private void btnNewSequence_Click(object sender, EventArgs e) { string cameraName = this.stage == RCCMStage.RCCM1 ? "wfov 1" : "wfov 2"; NewMeasurementForm dlg = new NewMeasurementForm("Crack " + MeasurementSequence.CrackCount, cameraName); DialogResult result = dlg.ShowDialog(); if (result == DialogResult.OK) { MeasurementSequence newCrack = new MeasurementSequence(dlg); // Check that name is unique MeasurementSequence crack2 = findCrackName(newCrack.Name); if (crack2 == null) { this.cracks.Add(newCrack); this.listMeasurements.SelectedIndex = this.cracks.Count - 1; } else { MessageBox.Show("Please use a unique name"); } } dlg.Dispose(); }
/// <summary> /// Open a form to edit the given crack /// </summary> /// <param name="crack">Crack to be editted</param> public NewMeasurementForm(MeasurementSequence crack) { InitializeComponent(); this.camera = crack.Camera; this.textName.Text = crack.Name; this.colorPicker.BackColor = crack.Color; this.editLineSize.Value = (decimal)crack.LineSize; this.editOrientation.Value = (decimal)crack.Orientation; switch (crack.Mode) { case MeasurementMode.Projection: this.radioMeasureProjection.Checked = true; break; case MeasurementMode.Tip: this.radioMeasureTip.Checked = true; break; case MeasurementMode.Total: this.radioMeasureTotal.Checked = true; break; } }
/// <summary> /// Draw NFOV image and cracks on given graphics object /// </summary> /// <param name="g">Canvas on which NFOV display will be drawn</param> private void nfovImage_Paint(object sender, PaintEventArgs e) { e.Graphics.ResetTransform(); // Reset transform to draw NFOV image Pen pen = new Pen(Color.FromArgb(128, Color.Black), 0); // Display live image from NFOV camera if (this.camera.Connected && this.camera.ProcessedImage.dataSize != 0) { Bitmap img = new Bitmap(this.camera.GetLiveImage(), 612, 512); e.Graphics.DrawImage(img, 0, 0, 612, 512); img.Dispose(); } // Draw crosshair if (this.checkCrosshair.Checked) { float midX = e.Graphics.ClipBounds.Width / 2.0f; float midY = e.Graphics.ClipBounds.Height / 2.0f; // Draw crosshair e.Graphics.DrawLine(pen, 0, midY, e.Graphics.ClipBounds.Width, midY); e.Graphics.DrawLine(pen, midX, 0, midX, e.Graphics.ClipBounds.Height); } // Now transform to world coordinates // Move image center to origin and rotate RectangleF bounds = e.Graphics.VisibleClipBounds; e.Graphics.TranslateTransform(bounds.Width / 2, bounds.Height / 2); e.Graphics.RotateTransform((float)rccm.FineStageAngle); e.Graphics.TranslateTransform(-bounds.Width / 2, -bounds.Height / 2); // Scale coordinate system by pixel to mm scaling float scaleX = bounds.Width / (float)this.camera.Width; float scaleY = bounds.Height / (float)this.camera.Height; e.Graphics.ScaleTransform(scaleX, scaleY); // Draw ruler (ticks on crosshair at defined spacing) if (this.checkCrosshair.Checked) { float size = (float)Program.Settings.json["ruler spacing"]; float x, y; float midX = e.Graphics.ClipBounds.X + e.Graphics.ClipBounds.Width / 2; float midY = e.Graphics.ClipBounds.Y + e.Graphics.ClipBounds.Height / 2; x = midX + size; while (x < e.Graphics.ClipBounds.X + e.Graphics.ClipBounds.Width) { float tempSize = Math.Round(Math.Abs(x - midX) / size) == 10.0 ? size : size / 2f; e.Graphics.DrawLine(pen, x, midY - tempSize, x, midY + tempSize); x += size; } x = midX - size; while (x > e.Graphics.ClipBounds.X) { float tempSize = Math.Round(Math.Abs(x - midX) / size) == 10.0 ? size : size / 2f; e.Graphics.DrawLine(pen, x, midY - tempSize, x, midY + tempSize); x -= size; } y = midY + size; while (y < e.Graphics.ClipBounds.Y + e.Graphics.ClipBounds.Height) { float tempSize = Math.Round(Math.Abs(y - midY) / size) == 10.0 ? size : size / 2f; e.Graphics.DrawLine(pen, midX - tempSize, y, midX + tempSize, y); y += size; } y = midY - size; while (y > e.Graphics.ClipBounds.Y) { float tempSize = Math.Round(Math.Abs(y - midY) / size) == 10.0 ? size : size / 2f; e.Graphics.DrawLine(pen, midX - tempSize, y, midX + tempSize, y); y -= size; } } // Move to NFOV location (first move origin to image center) e.Graphics.TranslateTransform((float)this.camera.Width / 2, (float)this.camera.Height / 2); PointF pos = this.rccm.GetNFOVLocation(this.stage, CoordinateSystem.Global); e.Graphics.TranslateTransform(-pos.X, -pos.Y); // Draw each crack on the image foreach (MeasurementSequence crack in cracks) { if (crack.Camera == this.cameraName) { crack.Plot(e.Graphics, scaleX); } } // Draw segment that user is creating with mouse if (this.crackIndexValid() && this.Drawing) { Color c = cracks[ActiveIndex].Color; e.Graphics.DrawLine(new Pen(Color.FromArgb(128, c), cracks[ActiveIndex].LineSize / scaleX), this.drawnLineStart, this.drawnLineEnd); } // Highlight selected point if (this.pointIndexValid()) { MeasurementSequence crack = this.cracks[this.ActiveIndex]; Measurement m = crack.GetPoint(this.ActivePoint); RectangleF point = new RectangleF(0, 0, 10.0f * crack.LineSize / scaleX, 10.0f * crack.LineSize / scaleX); point.X = (float)m.X - point.Width / 2.0f; point.Y = (float)m.Y - point.Height / 2.0f; e.Graphics.FillEllipse(new SolidBrush(crack.Color), point); } }