Exemplo n.º 1
0
        private void AddTextDrawing(DrawingGroup group, string name)
        {
            bool isHyperlink = false;

            if (name == "x11201_1_")
            {
                isHyperlink = true;
            }

            SolidColorBrush textBrush = null;

            if (name.StartsWith("XMLID_", StringComparison.OrdinalIgnoreCase))
            {
                textBrush = new SolidColorBrush(_colorText);
            }
            else
            {
                isHyperlink = true;
                textBrush   = new SolidColorBrush(_colorLink);
            }
            string brushName = name + "_Brush";

            SvgObject.SetName(textBrush, brushName);

            DrawingCollection drawings = group.Children;
            int itemCount = drawings != null ? drawings.Count : 0;

            for (int i = 0; i < itemCount; i++)
            {
                DrawingGroup drawing = drawings[i] as DrawingGroup;
                if (drawing != null)
                {
                    for (int j = 0; j < drawing.Children.Count; j++)
                    {
                        GlyphRunDrawing glyphDrawing = drawing.Children[j] as GlyphRunDrawing;
                        if (glyphDrawing != null)
                        {
                            glyphDrawing.ForegroundBrush = textBrush;
                        }
                    }
                }
            }

            if (isHyperlink)
            {
                _visualBrushes[name] = textBrush;

                _linkObjects.Add(group);
            }
        }
Exemplo n.º 2
0
        private void LoadLayerGroup(DrawingGroup group)
        {
            DrawingCollection drawings = group.Children;

            DrawingGroup    drawGroup    = null;
            GeometryDrawing drawGeometry = null;

            for (int i = 0; i < drawings.Count; i++)
            {
                Drawing drawing = drawings[i];
                if (TryCast(drawing, out drawGroup))
                {
                    string groupName = SvgLink.GetKey(drawGroup);
                    if (string.IsNullOrWhiteSpace(groupName))
                    {
                        groupName = SvgObject.GetId(drawGroup);
                    }
                    //string groupName = childGroup.GetValue(FrameworkElement.NameProperty) as string;
                    if (string.IsNullOrWhiteSpace(groupName))
                    {
                        LoadLayerGroup(drawGroup);
                    }
                    else
                    {
                        SvgObjectType elementType = SvgObject.GetType(drawGroup);

                        if (elementType == SvgObjectType.Text)
                        {
                            this.AddTextDrawing(drawGroup, groupName);
                        }
                        else
                        {
                            if (drawGroup.Children != null && drawGroup.Children.Count == 1)
                            {
                                this.AddDrawing(drawGroup, groupName);
                            }
                            else
                            {
                                //throw new InvalidOperationException(
                                //    String.Format("Error: The link group is in error - {0}", groupName));
                            }
                        }
                    }
                }
                else if (TryCast(drawing, out drawGeometry))
                {
                    this.AddGeometryDrawing(drawGeometry);
                }
            }
        }
Exemplo n.º 3
0
        private bool HitTestDrawing(DrawingGroup group, Point pt)
        {
            if (group.Bounds.Contains(pt))
            {
                DrawingGroup      groupDrawing    = null;
                GlyphRunDrawing   glyRunDrawing   = null;
                GeometryDrawing   geometryDrawing = null;
                DrawingCollection drawings        = group.Children;

                for (int i = 0; i < drawings.Count; i++)
                {
                    Drawing drawing = drawings[i];
                    if (TryCast.Cast(drawing, out geometryDrawing))
                    {
                        if (HitTestDrawing(geometryDrawing, pt))
                        {
                            return(true);
                        }
                    }
                    else if (TryCast.Cast(drawing, out groupDrawing))
                    {
                        if (HitTestDrawing(groupDrawing, pt))
                        {
                            return(true);
                        }
                        SvgObjectType objectType = SvgObject.GetType(groupDrawing);
                        if (objectType == SvgObjectType.Text && groupDrawing.Bounds.Contains(pt))
                        {
                            return(true);
                        }
                    }
                    else if (TryCast.Cast(drawing, out glyRunDrawing))
                    {
                        if (HitTestDrawing(glyRunDrawing, pt))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        protected override void OnMouseLeave(MouseEventArgs e)
        {
            base.OnMouseLeave(e);

            if (_animationCanvas != null && _animationCanvas.HandleMouseLeave())
            {
                return;
            }

            if (_tooltip != null)
            {
                _tooltip.IsOpen     = false;
                _tooltip.Visibility = Visibility.Hidden;
            }

            if (_hitVisual == null)
            {
                return;
            }

            string itemName = SvgObject.GetName(_hitVisual);

            if (itemName == null)
            {
                _hitVisual = null;
                return;
            }
            //if (_visualBrushes.ContainsKey(itemName))
            //{
            //    Brush brush = _visualBrushes[itemName];
            //    brush.Opacity = 0;
            //}
            _hitVisual = null;

            this.Cursor = Cursors.Arrow;
        }
Exemplo n.º 5
0
        //private Brush _testHitBrush;
        //private Brush _testHitBrushPen;
        //private Pen _testHitPen;
        //private GeometryDrawing _testHit;
        //private DrawingGroup _testHitGroup;
        private Drawing HitTest(Point pt)
        {
            if (_linkObjects == null)
            {
                return(null);
            }

            Point ptDisplay = _displayTransform.Transform(pt);

            DrawingGroup    groupDrawing    = null;
            GlyphRunDrawing glyRunDrawing   = null;
            GeometryDrawing geometryDrawing = null;

            Drawing foundDrawing = null;

            //for (int i = 0; i < _linkObjects.Count; i++)
            for (int i = _linkObjects.Count - 1; i >= 0; i--)
            {
                Drawing drawing = _linkObjects[i];
                if (TryCast.Cast(drawing, out geometryDrawing))
                {
                    if (HitTestDrawing(geometryDrawing, ptDisplay))
                    {
                        foundDrawing = drawing;
                        break;
                    }
                }
                else if (TryCast.Cast(drawing, out groupDrawing))
                {
                    if (HitTestDrawing(groupDrawing, ptDisplay))
                    {
                        foundDrawing = drawing;
                        break;
                    }
                    else if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text &&
                             groupDrawing.Bounds.Contains(ptDisplay))
                    {
                        foundDrawing = drawing;
                        break;
                    }
                }
                else if (TryCast.Cast(drawing, out glyRunDrawing))
                {
                    if (HitTestDrawing(glyRunDrawing, ptDisplay))
                    {
                        foundDrawing = drawing;
                        break;
                    }
                }
            }

            //if (_testHit != null)
            //{
            //    if (_testHitBrush != null)
            //    {
            //        _testHit.Brush = _testHitBrush;
            //    }
            //    else if (_testHitPen != null && _testHitBrushPen != null)
            //    {
            //        _testHit.Pen.Brush = _testHitBrushPen;
            //    }

            //    _testHit = null;
            //    _testHitPen = null;
            //    _testHitBrush = null;
            //}
            //if (_testHitGroup != null)
            //{
            //    _testHitGroup.BitmapEffect = null;
            //    _testHitGroup = null;
            //}

            //_testHit = foundDrawing as GeometryDrawing;
            //if (_testHit != null)
            //{
            //    _testHitBrush = _testHit.Brush;
            //    _testHitPen = _testHit.Pen;

            //    // Create and animate a Brush to set the button's Background.
            //    SolidColorBrush animationBrush = new SolidColorBrush();
            //    animationBrush.Color = Colors.Blue;

            //    ColorAnimation colorAnimation = new ColorAnimation();
            //    colorAnimation.From           = Colors.Blue;
            //    colorAnimation.To             = Colors.Red;
            //    colorAnimation.Duration       = new Duration(TimeSpan.FromMilliseconds(1000));
            //    colorAnimation.AutoReverse    = true;
            //    colorAnimation.RepeatBehavior = RepeatBehavior.Forever;

            //    if (_testHitBrush != null)
            //    {
            //        _testHit.Brush = animationBrush;
            //    }
            //    else if (_testHitPen != null)
            //    {
            //        _testHitBrushPen  = _testHitPen.Brush;
            //        _testHitPen.Brush = animationBrush;
            //    }

            //    // Apply the animation to the brush's Color property.
            //    //animationBrush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation);
            //}
            //else
            //{
            //    _testHitGroup = foundDrawing as DrawingGroup;
            //    if (_testHitGroup != null)
            //    {
            //        //// Create a blur effect.
            //        //BlurBitmapEffect blurEffect = new BlurBitmapEffect();
            //        //blurEffect.Radius = 3.0;

            //        //// Apply it to the drawing group.
            //        //_testHitGroup.BitmapEffect = blurEffect;

            //        // Initialize a new OuterGlowBitmapEffect that will be applied
            //        // to the TextBox.
            //        OuterGlowBitmapEffect glowEffect = new OuterGlowBitmapEffect();

            //        // Set the size of the glow to 30 pixels.
            //        glowEffect.GlowSize = 3;

            //        // Set the color of the glow to blue.
            //        Color glowColor = new Color();
            //        glowColor.ScA = 1;
            //        glowColor.ScB = 0;
            //        glowColor.ScG = 0;
            //        glowColor.ScR = 1;
            //        glowEffect.GlowColor = glowColor;

            //        // Set the noise of the effect to the maximum possible (range 0-1).
            //        glowEffect.Noise = 0;

            //        // Set the Opacity of the effect to 75%. Note that the same effect
            //        // could be done by setting the ScA property of the Color to 0.75.
            //        glowEffect.Opacity = 0.5;

            //        // Apply the bitmap effect to the TextBox.
            //        _testHitGroup.BitmapEffect = glowEffect;
            //    }
            //}

            return(foundDrawing);
        }
Exemplo n.º 6
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (_animationCanvas != null && _animationCanvas.HandleMouseMove(e))
            {
                return;
            }

            // Retrieve the coordinates of the mouse button event.
            Point pt = e.GetPosition(this);

            Drawing hitVisual = HitTest(pt);

            //string itemName = null;

            if (hitVisual == null)
            {
                this.Cursor = Cursors.Arrow;

                if (_hitVisual != null)
                {
                    //itemName = SvgObject.GetName(_hitVisual);
                    //if (itemName == null)
                    //{
                    //    _hitVisual = null;
                    //    return;
                    //}
                    //if (_visualBrushes.ContainsKey(itemName))
                    //{
                    //    Brush brush = _visualBrushes[itemName];
                    //    brush.Opacity = 0;
                    //}
                    _hitVisual = null;
                }

                if (_tooltip != null)
                {
                    _tooltip.IsOpen     = false;
                    _tooltip.Visibility = Visibility.Hidden;
                }

                return;
            }
            else
            {
                this.Cursor = Cursors.Hand;

                if (hitVisual == _hitVisual)
                {
                    return;
                }

                if (_hitVisual != null)
                {
                    //itemName = SvgObject.GetName(_hitVisual);
                    //if (itemName == null)
                    //{
                    //    _hitVisual = null;
                    //    return;
                    //}
                    //if (_visualBrushes.ContainsKey(itemName))
                    //{
                    //    Brush brush = _visualBrushes[itemName];
                    //    brush.Opacity = 0;
                    //}
                    _hitVisual = null;
                }

                //itemName = SvgObject.GetName(hitVisual);
                //if (itemName == null)
                //{
                //    return;
                //}
                //if (_visualBrushes.ContainsKey(itemName))
                //{
                //    Brush brush = _visualBrushes[itemName];
                //    brush.Opacity = 0.5;
                //}
                _hitVisual = hitVisual;

                string tooltipText = SvgObject.GetTitle(_hitVisual);
                Rect   rectBounds  = _hitVisual.Bounds;
                //Drawing drawing = _hitVisual.GetValue(FrameworkElement.TagProperty) as Drawing;
                //if (drawing != null)
                //{
                //    rectBounds  = drawing.Bounds;
                //    tooltipText = SvgObject.GetTitle(drawing);
                //}

                if (_tooltip != null && !string.IsNullOrWhiteSpace(tooltipText))
                {
                    _tooltip.PlacementRectangle = rectBounds;

                    _tooltipText.Text = tooltipText;

                    if (_tooltip.Visibility == Visibility.Hidden)
                    {
                        _tooltip.Visibility = Visibility.Visible;
                    }

                    _tooltip.IsOpen = true;
                }
                else
                {
                    if (_tooltip != null)
                    {
                        _tooltip.IsOpen     = false;
                        _tooltip.Visibility = Visibility.Hidden;
                    }
                }
            }
        }
Exemplo n.º 7
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);

            if (_animationCanvas != null && _animationCanvas.HandleMouseDown(e))
            {
                return;
            }

            Point pt = e.GetPosition(this);

            Drawing visual = HitTest(pt);

            if (visual == null)
            {
                if (_tooltip != null)
                {
                    _tooltip.IsOpen     = false;
                    _tooltip.Visibility = Visibility.Hidden;
                }

                this.Cursor = Cursors.Arrow;
                return;
            }

            string itemName = SvgObject.GetName(visual);

            if (itemName == null)
            {
                if (_tooltip != null)
                {
                    _tooltip.IsOpen     = false;
                    _tooltip.Visibility = Visibility.Hidden;
                }

                return;
            }
            //Brush brush = null;
            //if (_visualBrushes.ContainsKey(itemName))
            //{
            //    brush = _visualBrushes[itemName];
            //}
            //if (brush == null)
            //{
            //    if (_tooltip != null)
            //    {
            //        _tooltip.IsOpen = false;
            //        _tooltip.Visibility = Visibility.Hidden;
            //    }

            //    return;
            //}

            //if (e.ChangedButton == MouseButton.Left)
            //{
            //    string brushName = SvgObject.GetName(visual);
            //    if (!string.IsNullOrWhiteSpace(brushName))
            //    {
            //        SvgLinkAction linkAction = SvgLink.GetLinkAction(visual);
            //        if (linkAction == SvgLinkAction.LinkHtml ||
            //            linkAction == SvgLinkAction.LinkPage)
            //        {
            //            _animator.Start(brushName, brush);
            //        }
            //    }
            //}
            //else if (e.ChangedButton == MouseButton.Right)
            //{
            //    _animator.Stop();
            //}
        }
Exemplo n.º 8
0
        public bool HandleMouseDown(MouseButtonEventArgs e)
        {
            Point pt = e.GetPosition(_drawingCanvas);

            Drawing visual = HitTest(pt);

            if (visual == null)
            {
                if (_tooltip != null)
                {
                    _tooltip.IsOpen     = false;
                    _tooltip.Visibility = Visibility.Hidden;
                }

                return(false);
            }

            if (_selectedVisual != null && visual == _selectedVisual)
            {
                _drawingCanvas.Cursor = Cursors.Hand;

                return(true);
            }

            string itemName = SvgObject.GetName(visual);

            if (itemName == null)
            {
                if (_tooltip != null)
                {
                    _tooltip.IsOpen     = false;
                    _tooltip.Visibility = Visibility.Hidden;
                }

                return(false);
            }
            SolidColorBrush brush = null;

            if (_visualBrushes.ContainsKey(itemName))
            {
                brush = _visualBrushes[itemName] as SolidColorBrush;

                if (brush != null)
                {
                    brush.Color = _colorSelected;
                }
            }
            if (brush == null)
            {
                if (_tooltip != null)
                {
                    _tooltip.IsOpen     = false;
                    _tooltip.Visibility = Visibility.Hidden;
                }

                return(false);
            }
            if (_selectedVisual != null)
            {
                itemName = SvgObject.GetName(_selectedVisual);
                if (itemName == null)
                {
                    return(false);
                }
                if (_visualBrushes.ContainsKey(itemName))
                {
                    brush = _visualBrushes[itemName] as SolidColorBrush;

                    if (brush != null)
                    {
                        brush.Color = _colorLink;
                    }
                }
                else
                {
                    return(false);
                }
            }

            _selectedVisual = visual;

            if (e.ChangedButton == MouseButton.Left)
            {
                string brushName = SvgObject.GetName(brush);
                if (!string.IsNullOrWhiteSpace(brushName))
                {
                    SvgLinkAction linkAction = SvgLink.GetAction(visual);
                    if (linkAction == SvgLinkAction.LinkHtml ||
                        linkAction == SvgLinkAction.LinkPage)
                    {
                        _animator.Start(brushName, brush);
                    }
                }
            }
            else if (e.ChangedButton == MouseButton.Right)
            {
                _animator.Stop();
            }

            return(true);
        }
Exemplo n.º 9
0
        public bool HandleMouseMove(MouseEventArgs e)
        {
            // Retrieve the coordinates of the mouse button event.
            Point pt = e.GetPosition(_drawingCanvas);

            Drawing hitVisual = HitTest(pt);

            if (_selectedVisual != null && hitVisual == _selectedVisual)
            {
                _drawingCanvas.Cursor = Cursors.Hand;

                return(true);
            }

            string itemName = null;

            if (hitVisual == null)
            {
                if (_hitVisual != null)
                {
                    itemName = SvgObject.GetName(_hitVisual);
                    if (itemName == null)
                    {
                        _hitVisual = null;
                        return(false);
                    }
                    if (_visualBrushes.ContainsKey(itemName) && (_hitVisual != _selectedVisual))
                    {
                        SolidColorBrush brush = _visualBrushes[itemName] as SolidColorBrush;
                        if (brush != null)
                        {
                            brush.Color = _colorLink;
                        }
                    }
                    _hitVisual = null;
                }

                if (_tooltip != null)
                {
                    _tooltip.IsOpen     = false;
                    _tooltip.Visibility = Visibility.Hidden;
                }

                return(false);
            }
            else
            {
                _drawingCanvas.Cursor = Cursors.Hand;

                if (hitVisual == _hitVisual)
                {
                    return(false);
                }

                if (_hitVisual != null)
                {
                    itemName = SvgObject.GetName(_hitVisual);
                    if (itemName == null)
                    {
                        _hitVisual = null;
                        return(false);
                    }
                    if (_visualBrushes.ContainsKey(itemName) && (_hitVisual != _selectedVisual))
                    {
                        SolidColorBrush brush = _visualBrushes[itemName] as SolidColorBrush;
                        if (brush != null)
                        {
                            brush.Color = _colorLink;
                        }
                    }
                    _hitVisual = null;
                }

                itemName = SvgObject.GetName(hitVisual);
                if (itemName == null)
                {
                    return(false);
                }
                if (_visualBrushes.ContainsKey(itemName))
                {
                    SolidColorBrush brush = _visualBrushes[itemName] as SolidColorBrush;
                    if (brush != null)
                    {
                        brush.Color = _colorHover;
                    }
                }
                _hitVisual = hitVisual;

                string        tooltipText = itemName;
                SvgLinkAction linkAction  = SvgLink.GetAction(hitVisual);
                if (linkAction == SvgLinkAction.LinkTooltip &&
                    _tooltip != null && !string.IsNullOrWhiteSpace(tooltipText))
                {
                    Rect rectBounds = hitVisual.Bounds;

                    _tooltip.PlacementRectangle = rectBounds;

                    _tooltipText.Text = tooltipText;

                    if (_tooltip.Visibility == Visibility.Hidden)
                    {
                        _tooltip.Visibility = Visibility.Visible;
                    }

                    _tooltip.IsOpen = true;
                }
                else
                {
                    if (_tooltip != null)
                    {
                        _tooltip.IsOpen     = false;
                        _tooltip.Visibility = Visibility.Hidden;
                    }
                }
            }

            return(true);
        }
Exemplo n.º 10
0
        public void LoadDiagrams(DrawingGroup linkGroups, DrawingGroup wholeGroup)
        {
            if (linkGroups == null)
            {
                return;
            }
            DrawingCollection drawings = linkGroups.Children;

            if (drawings == null || drawings.Count == 0)
            {
                return;
            }
            else if (drawings.Count == 1)
            {
                DrawingGroup layerGroup = drawings[0] as DrawingGroup;
                if (layerGroup != null)
                {
                    string elementId = SvgObject.GetId(layerGroup);
                    if (!string.IsNullOrWhiteSpace(elementId) &&
                        string.Equals(elementId, "IndicateLayer", StringComparison.OrdinalIgnoreCase))
                    {
                        this.LoadLayerDiagrams(layerGroup);

                        _wholeDrawing = wholeGroup;
                        _linksDrawing = linkGroups;

                        return;
                    }
                }
            }

            this.UnloadDiagrams();

            for (int i = 0; i < drawings.Count; i++)
            {
                DrawingGroup childGroup = drawings[i] as DrawingGroup;
                if (childGroup != null)
                {
                    string groupName = SvgLink.GetKey(childGroup);
                    //string groupName = SvgObject.GetName(childGroup);
                    if (string.IsNullOrWhiteSpace(groupName))
                    {
                        if (childGroup.Children != null && childGroup.Children.Count == 1)
                        {
                            this.AddDrawing(childGroup);
                        }
                        else
                        {
                            throw new InvalidOperationException("Error: The link group is in error.");
                        }
                    }
                    else
                    {
                        if (childGroup.Children != null && childGroup.Children.Count == 1)
                        {
                            this.AddDrawing(childGroup, groupName);
                        }
                        else
                        {
                            throw new InvalidOperationException(
                                      String.Format("Error: The link group is in error - {0}", groupName));
                        }
                    }
                }
            }

            _wholeDrawing = wholeGroup;
            _linksDrawing = linkGroups;

            if (_drawingCanvas != null)
            {
                _displayTransform = _drawingCanvas.DisplayTransform;
            }
        }