/// <summary> /// Units of measure is changed. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="PropertyChangedEventArgs{UnitOfMeasure}"/> instance containing the event data.</param> private void Tool_UnitsOfMeasureChanged(object sender, PropertyChangedEventArgs <UnitOfMeasure> e) { ImageMeasureTool tool = (ImageMeasureTool)VisualTool; ImageMeasureToolUnitsOfMeasureAction unitOfMeasureAction = _unitOfMeasureToUnitOfMeasureAction[tool.UnitsOfMeasure]; unitOfMeasureAction.Activate(); // get the unit of measure as a string string unitOfMeasureString = GetUnitOfMeasureString(e.NewValue); // if image viewer is not empty if (tool.ImageViewer != null) { // for each image foreach (VintasoftImage image in tool.ImageViewer.Images) { // get annotation list IList <AnnotationView> annotations = tool.GetAnnotationsFromImage(image); // for each annotation foreach (AnnotationView annotation in annotations) { MeasurementAnnotationData data = annotation.Data as MeasurementAnnotationData; // if annotation is measurement annotation if (data != null) { // set new measuring text template data.MeasuringTextTemplate = GetMeasuringTextTemplate(data, unitOfMeasureString); } } } } }
/// <summary> /// Loads the measurement annotations from a file. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void loadMeasurementsAction_Clicked(object sender, EventArgs e) { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.FileName = null; openFileDialog.Filter = "Binary Annotations(*.vsabm)|*.vsabm|XMP Annotations(*.xmpm)|*.xmpm|All Formats(*.vsabm;*.xmpm)|*.vsabm;*.xmpm"; openFileDialog.FilterIndex = 3; if (openFileDialog.ShowDialog() == DialogResult.OK) { try { using (FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read)) { ImageMeasureTool visualTool = (ImageMeasureTool)VisualTool; // get the annotation collection AnnotationDataCollection annotations = visualTool.AnnotationViewCollection.DataCollection; // clear the annotation collection annotations.ClearAndDisposeItems(); // add annotations from stream to the annotation collection annotations.AddFromStream(fs, visualTool.ImageViewer.Image.Resolution); } } catch (Exception ex) { DemosTools.ShowErrorMessage(ex); } } } }
/// <summary> /// Begins the measurement using the specified measuremet annotation. /// </summary> /// <param name="type">The measurement annotation type.</param> private void BeginMeasurement(MeasurementType type) { ImageMeasureTool tool = (ImageMeasureTool)VisualTool; switch (type) { case MeasurementType.Line: tool.BeginLineMeasurement(); break; case MeasurementType.Lines: tool.BeginLinesMeasurement(); break; case MeasurementType.Ellipse: tool.BeginEllipseMeasurement(); break; case MeasurementType.Angle: tool.BeginAngleMeasurement(); break; default: throw new NotImplementedException(); } }
/// <summary> /// Shows the properties form for image measure tool. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void propertiesAction_Clicked(object sender, EventArgs e) { ImageMeasureTool visualTool = (ImageMeasureTool)VisualTool; using (PropertyGridForm dlg = new PropertyGridForm(visualTool, "Image measure tool settings")) { dlg.ShowDialog(); } }
/// <summary> /// Adds the properties actions to the specified action list. /// </summary> /// <param name="actions">The actions list.</param> private void AddPropertiesActions(List <VisualToolAction> actions) { List <ImageMeasureToolUnitsOfMeasureAction> unitsOfMeasureSubActions = new List <ImageMeasureToolUnitsOfMeasureAction>(); ImageMeasureTool tool = (ImageMeasureTool)VisualTool; foreach (UnitOfMeasure unitOfMeasure in Enum.GetValues(typeof(UnitOfMeasure))) { ImageMeasureToolUnitsOfMeasureAction unitsOfMeasureAction = new ImageMeasureToolUnitsOfMeasureAction( unitOfMeasure, string.Format("{0}", unitOfMeasure), string.Format("{0} ({1})", unitOfMeasure, GetUnitOfMeasureString(unitOfMeasure)), null); unitsOfMeasureAction.Activated += new EventHandler(unitOfMeasureAction_Activated); if (unitOfMeasure == tool.UnitsOfMeasure) { unitsOfMeasureAction.Activate(); } if (_unitOfMeasureToUnitOfMeasureAction == null) { _unitOfMeasureToUnitOfMeasureAction = new Dictionary <UnitOfMeasure, ImageMeasureToolUnitsOfMeasureAction>(); } _unitOfMeasureToUnitOfMeasureAction.Add(unitOfMeasure, unitsOfMeasureAction); unitsOfMeasureSubActions.Add(unitsOfMeasureAction); } actions.Add(new VisualToolAction("Units Of Measure", "Units Of Measure", null, false, unitsOfMeasureSubActions.ToArray())); VisualToolAction propertiesAction = new VisualToolAction("Properties...", "Show properties form for image measure tool", null, false); propertiesAction.Clicked += new EventHandler(propertiesAction_Clicked); actions.Add(propertiesAction); VisualToolAction measurementPropertiesAction = new VisualToolAction("Measurement Properties...", "Show properties form for focused measurement annotation", null, false); measurementPropertiesAction.Clicked += new EventHandler(measurementPropertiesAction_Clicked); actions.Add(measurementPropertiesAction); }
/// <summary> /// Shows the properties form for focused measurement annotation. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void measurementPropertiesAction_Clicked(object sender, EventArgs e) { ImageMeasureTool visualTool = (ImageMeasureTool)VisualTool; if (visualTool.FocusedAnnotationView == null) { return; } using (PropertyGridForm dlg = new PropertyGridForm(visualTool.FocusedAnnotationView, "Measurement settings")) { dlg.ShowDialog(); } }
/// <summary> /// Initializes a new instance of the <see cref="ImageMeasureToolAction"/> class. /// </summary> /// <param name="visualTool">The visual tool.</param> /// <param name="text">The action text.</param> /// <param name="toolTip">The action tool tip.</param> /// <param name="icon">The action icon.</param> /// <param name="subActions">The sub-actions of the action.</param> public ImageMeasureToolAction( ImageMeasureTool visualTool, string text, string toolTip, Image icon, params VisualToolAction[] subActions) : base(visualTool, text, toolTip, icon, subActions) { visualTool.UnitsOfMeasureChanged += new EventHandler <PropertyChangedEventArgs <UnitOfMeasure> >(Tool_UnitsOfMeasureChanged); visualTool.MeasuringTextTemplateUpdating += new EventHandler <MeasurementAnnotationDataEventArgs>(Tool_MeasuringTextTemplateUpdating); _isInitialized = true; }
/// <summary> /// The "unit of measure" action is activated. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void unitOfMeasureAction_Activated(object sender, EventArgs e) { ImageMeasureToolUnitsOfMeasureAction unitsOfMeasureAction = (ImageMeasureToolUnitsOfMeasureAction)sender; ImageMeasureTool tool = (ImageMeasureTool)VisualTool; tool.UnitsOfMeasure = unitsOfMeasureAction.UnitsOfMeasure; if (_currentUnitOfMeasureAction != null) { _currentUnitOfMeasureAction.Deactivate(); } _currentUnitOfMeasureAction = unitsOfMeasureAction; }
/// <summary> /// Saves the measurement annotations to a file. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void saveMeasurementsAction_Clicked(object sender, EventArgs e) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.FileName = null; saveFileDialog.Filter = "Binary Annotations|*.vsabm|XMP Annotations|*.xmpm"; saveFileDialog.FilterIndex = 1; if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.ReadWrite)) { IFormatter formatter = null; if (saveFileDialog.FilterIndex == 1) { formatter = new AnnotationVintasoftBinaryFormatter(); } else if (saveFileDialog.FilterIndex == 2) { formatter = new AnnotationVintasoftXmpFormatter(); } ImageMeasureTool visualTool = (ImageMeasureTool)VisualTool; AnnotationDataCollection annotations = visualTool.AnnotationViewCollection.DataCollection; formatter.Serialize(fs, annotations); } } catch (Exception ex) { DemosTools.ShowErrorMessage(ex); } } } }
/// <summary> /// Refreshes all measurements of focused image. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void refreshAction_Clicked(object sender, EventArgs e) { ImageMeasureTool visualTool = (ImageMeasureTool)VisualTool; visualTool.InvalidateMeasuringTextValue(); }