Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorRenderingWpf/Wpf/WpfSwitchRendering.cs @ 12762

Last change on this file since 12762 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 2.3 KB
Line 
1using System;
2using System.Linq;
3using System.Text;
4using System.Diagnostics;
5using System.Windows;
6using System.Windows.Media;
7using System.Collections.Generic;
8
9using SharpVectors.Dom.Svg;
10
11namespace SharpVectors.Renderers.Wpf
12{
13    public sealed class WpfSwitchRendering : WpfRendering
14    {
15        #region Private Fields
16
17        private DrawingGroup _drawGroup;
18
19        #endregion
20
21        #region Constructors and Destructor
22
23        public WpfSwitchRendering(SvgElement element)
24            : base(element)
25        {
26        }
27
28        #endregion
29
30        #region Public Methods
31
32        public override void BeforeRender(WpfDrawingRenderer renderer)
33        {
34            base.BeforeRender(renderer);
35        }
36
37        public override void Render(WpfDrawingRenderer renderer)
38        {
39            Geometry clipGeom   = this.ClipGeometry;
40            Transform transform = this.Transform;
41
42            if (clipGeom != null || transform != null)
43            {
44                WpfDrawingContext context = renderer.Context;
45                _drawGroup = new DrawingGroup();
46
47                DrawingGroup currentGroup = context.Peek();
48
49                if (currentGroup == null)
50                {
51                    throw new InvalidOperationException("An existing group is expected.");
52                }
53
54                currentGroup.Children.Add(_drawGroup);
55                context.Push(_drawGroup);
56
57                if (clipGeom != null)
58                {
59                    _drawGroup.ClipGeometry = clipGeom;
60                }
61
62                if (transform != null)
63                {
64                    _drawGroup.Transform = transform;
65                }
66            }
67
68            base.Render(renderer);
69        }
70
71        public override void AfterRender(WpfDrawingRenderer renderer)
72        {
73            if (_drawGroup != null)
74            {
75                WpfDrawingContext context = renderer.Context;
76
77                DrawingGroup currentGroup = context.Peek();
78
79                if (currentGroup == null || currentGroup != _drawGroup)
80                {
81                    throw new InvalidOperationException("An existing group is expected.");
82                }
83
84                context.Pop();
85            }
86
87            base.AfterRender(renderer);
88        }
89
90        #endregion
91    }
92}
Note: See TracBrowser for help on using the repository browser.