Esempio n. 1
0
        ////////////////////////////////////////////////////////////////////////////////////////////
        private void MouseLeftButtonUpEventHandler(object sender, MouseButtonEventArgs e)
        {
            // If the map doesn't currently have mouse capture, abort any further processing.
            if (!Map.IsMouseCaptured)
            {
                return;
            }

            if (_drawingAnnotation)
            {
                _drawingAnnotation = false;
                Map.ReleaseMouseCapture();
                AnnotationElement drawnAnnotation = Annotations.LastOrDefault();
                if ((drawnAnnotation != null) && (drawnAnnotation.Width == 0) && (drawnAnnotation.Height == 0))
                {
                    HandleAnnotationElementSelected(null);
                    Annotations.Remove(drawnAnnotation);
                }
                return;
            }

            // Apply a translation to the map transform using the drag displacement
            Point  mousePos             = e.GetPosition(Map);
            Matrix scaleTransformMatrix = Map.RenderTransform.Value;
            double mouseDisplacementX   = mousePos.X - _dragStartPos.X;
            double mouseDisplacementY   = mousePos.Y - _dragStartPos.Y;

            scaleTransformMatrix.TranslatePrepend(mouseDisplacementX, mouseDisplacementY);

            // Apply the new transform to the map
            Map.RenderTransform = new MatrixTransform(scaleTransformMatrix);

            // Ensure mouse capture has been released by the map
            Map.ReleaseMouseCapture();
        }
Esempio n. 2
0
        ////////////////////////////////////////////////////////////////////////////////////////////
        private void AddAnnotationElementToDisplay(AnnotationElement element)
        {
            ContentControl annotationControl = new ContentControl()
            {
                DataContext = element
            };

            annotationControl.Style = FindResource("AnnotationElementStyle") as Style;
            annotationControl.SetBinding(Canvas.TopProperty, new Binding(nameof(element.PosX))
            {
                Source = element, Mode = BindingMode.TwoWay
            });
            annotationControl.SetBinding(Canvas.LeftProperty, new Binding(nameof(element.PosY))
            {
                Source = element, Mode = BindingMode.TwoWay
            });
            annotationControl.SetBinding(FrameworkElement.WidthProperty, new Binding(nameof(element.Width))
            {
                Source = element, Mode = BindingMode.TwoWay
            });
            annotationControl.SetBinding(FrameworkElement.HeightProperty, new Binding(nameof(element.Height))
            {
                Source = element, Mode = BindingMode.TwoWay
            });
            annotationControl.SetBinding(FrameworkElement.RenderTransformProperty, new Binding(nameof(element.Angle))
            {
                Source = element, Mode = BindingMode.TwoWay, Converter = new AngleToTransformConverter()
            });
            annotationControl.RenderTransform      = new AngleToTransformConverter().Convert(element.Angle, typeof(double), null, CultureInfo.CurrentCulture) as Transform;
            annotationControl.MouseLeftButtonDown += (sender, e) =>
            {
                if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
                {
                    HandleAnnotationElementSelected(element);
                    e.Handled = true;
                }
            };
            element.Color             = _annotationLayerColors[element.Layer];
            element.StrokeColor       = _annotationLayerStrokeColors[element.Layer];
            element.AnnotationControl = annotationControl;

            switch (element.Layer)
            {
            case 0:
                AnnotationLayer0.Children.Add(annotationControl);
                break;

            case 1:
                AnnotationLayer1.Children.Add(annotationControl);
                break;

            case 2:
                AnnotationLayer2.Children.Add(annotationControl);
                break;
            }
        }
Esempio n. 3
0
        ////////////////////////////////////////////////////////////////////////////////////////////
        private void DeleteAnnotationEventHandler(object sender, RoutedEventArgs e)
        {
            AnnotationElement element = SelectedAnnotation;

            if (element != null)
            {
                HandleAnnotationElementSelected(null);
                Annotations.Remove(element);
                AnnotationLayer0.Children.Remove(element.AnnotationControl);
                AnnotationLayer1.Children.Remove(element.AnnotationControl);
                AnnotationLayer2.Children.Remove(element.AnnotationControl);
            }
        }
Esempio n. 4
0
 ////////////////////////////////////////////////////////////////////////////////////////////
 private void HandleAnnotationElementSelected(AnnotationElement element)
 {
     if (SelectedAnnotation != null)
     {
         Selector.SetIsSelected(SelectedAnnotation.AnnotationControl, false);
     }
     if (SelectedAnnotation == element)
     {
         SelectedAnnotation = null;
         return;
     }
     SelectedAnnotation = element;
     if (element != null)
     {
         Selector.SetIsSelected(element.AnnotationControl, true);
     }
 }
Esempio n. 5
0
        ////////////////////////////////////////////////////////////////////////////////////////////
        private void MouseLeftButtonDownEventHandler(object sender, MouseButtonEventArgs e)
        {
            // If the map has already captured the mouse, abort any further processing.
            if (Map.IsMouseCaptured)
            {
                return;
            }

            // Begin a pan operation, capturing the mouse and the initial drag position.
            _dragStartPos = e.GetPosition(Map);
            Map.CaptureMouse();

            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
            {
                _drawingAnnotation = true;
                AnnotationElement annotationElement = new AnnotationElement();
                annotationElement.Layer = (IsOverlayEnabled0 ? 0 : (IsOverlayEnabled1 ? 1 : 2));
                Annotations.Add(annotationElement);
                AddAnnotationElementToDisplay(annotationElement);
                HandleAnnotationElementSelected(annotationElement);
            }
        }
Esempio n. 6
0
        ////////////////////////////////////////////////////////////////////////////////////////////
        private bool LoadAnnotationsFile(string commentsFilePath, List <SvgElement> elements, out List <AnnotationElement> annotations)
        {
            // Load the XML document contents from the data
            byte[]      schematicFileData = File.ReadAllBytes(commentsFilePath);
            XmlDocument document          = new XmlDocument();

            using (MemoryStream memoryStream = new MemoryStream(schematicFileData))
            {
                using (XmlReader xmlReader = XmlReader.Create(memoryStream))
                {
                    document.Load(xmlReader);
                }
            }

            // Obtain and validate the root node of the document
            XmlElement root = document.DocumentElement;

            if (!String.Equals(root.Name, "SchematicAnnotations", StringComparison.Ordinal))
            {
                annotations = null;
                return(false);
            }

            // Load the comments
            XmlElement commentsGroupNode = root.ChildNodes.OfType <XmlElement>().FirstOrDefault((x) => String.Equals(x.Name, "Comments", StringComparison.OrdinalIgnoreCase));

            if (commentsGroupNode != null)
            {
                foreach (XmlElement childElement in commentsGroupNode.ChildNodes.OfType <XmlElement>().Where((x) => String.Equals(x.Name, "Comment", StringComparison.OrdinalIgnoreCase)))
                {
                    string nodeID  = childElement.GetAttribute("NodeID");
                    string comment = childElement.InnerText;

                    SvgElement element = elements.FirstOrDefault((x) => String.Equals(x.ID, nodeID, StringComparison.OrdinalIgnoreCase));
                    if (element != null)
                    {
                        element.Comments = comment;
                    }
                }
            }

            // Load the annotations
            annotations = new List <AnnotationElement>();
            XmlElement annotationsGroupNode = root.ChildNodes.OfType <XmlElement>().FirstOrDefault((x) => String.Equals(x.Name, "Annotations", StringComparison.OrdinalIgnoreCase));

            if (annotationsGroupNode != null)
            {
                foreach (XmlElement childElement in annotationsGroupNode.ChildNodes.OfType <XmlElement>().Where((x) => String.Equals(x.Name, "Annotation", StringComparison.OrdinalIgnoreCase)))
                {
                    string name     = childElement.GetAttribute("Name");
                    string comment  = childElement.InnerText;
                    double width    = Convert.ToDouble(childElement.GetAttribute("Width"));
                    double height   = Convert.ToDouble(childElement.GetAttribute("Height"));
                    double posX     = Convert.ToDouble(childElement.GetAttribute("PosX"));
                    double posY     = Convert.ToDouble(childElement.GetAttribute("PosY"));
                    double rotation = Convert.ToDouble(childElement.GetAttribute("Rotation"));
                    int    layer    = Convert.ToInt32(childElement.GetAttribute("Layer"));

                    AnnotationElement element = new AnnotationElement()
                    {
                        Name = name, Description = comment, Width = width, Height = height, PosX = posX, PosY = posY, Angle = rotation, Layer = layer
                    };
                    element.Description = comment;
                    annotations.Add(element);
                }
            }
            return(true);
        }