/// <summary> /// Adds annotation that requires no control points. /// There can be only one of those annotations per annotation name. /// </summary> /// <param name="annotationName"></param> public void AddSimpleAnnotation(string annotationName) { Annotation ann = AnnotationFactory.Create(annotationName); foreach (Annotation ann2 in PictureBox.Annotations) { if (ann2.GetType() == ann.GetType()) { return; // This annotation is already visible, do not add a second one. } } PictureBox.Annotations.Add(ann); Refresh(); }
private void buttonActivateAnnotationClick(object sender, EventArgs e) { string annotationName = ((ToolStripButton)sender).Name; if (AnnotationFactory.Create(annotationName).RequiredPointCount > 0) { PictureViewer.NewAnnotationName = annotationName; PictureViewer.Mode = Pi2PictureViewer.MouseMode.AddAnnotation; } else { PictureViewer.AddSimpleAnnotation(annotationName); } UpdateToolButtons(); }
private void PictureBox_MouseDown(object sender, MouseEventArgs e) { if ((Mode == MouseMode.Pan && e.Button == MouseButtons.Left) || (e.Button == MouseButtons.Middle)) { // Start panning the image PanStartMousePosition = e.Location; PanStartPicturePosition = PictureBox.PicturePosition; } else if ((Mode == MouseMode.Pick || Mode == MouseMode.Erase) && e.Button == MouseButtons.Left && ActiveAnnotation == null) { // Pick and activate annotation and possibly also control point var result = PictureBox.FindAnnotation(e.Location); if (result != null) { if (Mode == MouseMode.Pick) { ActiveAnnotation = result.Item1; ActiveControlPoint = result.Item2; oldControlPointLocations.Clear(); oldControlPointLocations.AddRange(ActiveAnnotation.ControlPoints); controlPointSelectLocation = new Vec3(PictureBox.ScreenToPicture(new Vec2(e.Location)), PictureBox.Slice); } else { // Erase annotation PictureBox.Annotations.Remove(result.Item1); Refresh(); } } } else if ((Mode == MouseMode.AddAnnotation || Mode == MouseMode.Profile) && e.Button == MouseButtons.Left && ActiveAnnotation == null) { if (Mode == MouseMode.Profile) { NewAnnotationName = "Line segment"; EraseProfileAnnotation(); } // Add new annotation object if (!String.IsNullOrEmpty(NewAnnotationName)) { ActiveAnnotation = AnnotationFactory.Create(NewAnnotationName); PictureBox.Annotations.Add(ActiveAnnotation); Vec3 pos = new Vec3(PictureBox.ScreenToPicture(new Vec2(e.Location)), PictureBox.Slice); ActiveAnnotation.ControlPoints.Add(pos); ActiveControlPoint = 0; // Add another control point right away if multiple points are required. if (ActiveAnnotation.RequiredPointCount > 1) { ActiveAnnotation.ControlPoints.Add(pos); ActiveControlPoint = 1; } Refresh(); if (Mode != MouseMode.Profile) { if (ToolStrip != null) { ToolStrip.ResetAnnotation(); } } } if (Mode == MouseMode.Profile) { ProfileAnnotation = ActiveAnnotation; UpdateProfile(); } } }