コード例 #1
0
        /// <summary>
        /// Returns a measuring text template.
        /// </summary>
        /// <param name="data">A measurement annotation data.</param>
        /// <param name="unitOfMeasureString">A unit of measure string.</param>
        /// <returns>Measuring text template.</returns>
        private string GetMeasuringTextTemplate(MeasurementAnnotationData data, string unitOfMeasureString)
        {
            // if data is angle measuring data
            if (data.MeasuringAnnotation is AngleMeasuringData)
            {
                return(string.Format("Angle = {1}°\nReflex angle = {2}°\nLength = {3} {0} ",
                                     unitOfMeasureString, "{Angle:f2}", "{ReflexAngle:f2}", "{Length:f2}"));
            }

            // if data is line measuring data
            if (data.MeasuringAnnotation is LinearMeasuringData)
            {
                return("{Length:f2} " + unitOfMeasureString);
            }

            // if data is ellipse measuring data
            if (data.MeasuringAnnotation is EllipseMeasuringData)
            {
                return(string.Format("S = {1} {0}^2\nDx = {2} {0}, Dy = {3} {0}",
                                     unitOfMeasureString, "{Square:f2}", "{DiameterX:f2}", "{DiameterY:f2}"));
            }

            // if type is unknown
            return(data.MeasuringTextTemplate);
        }
コード例 #2
0
        /// <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);
                        }
                    }
                }
            }
        }