Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorRenderingWpf/Wpf/WpfRenderingBase.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: 5.0 KB
Line 
1using System;
2using System.Linq;
3using System.Text;
4using System.Windows;
5using System.Windows.Media;
6using System.Collections.Generic;
7
8using SharpVectors.Dom.Svg;
9
10namespace SharpVectors.Renderers.Wpf
11{
12    /// <summary>     
13    /// Defines the interface required for a rendering node to interact with the renderer and the SVG DOM
14    /// </summary>
15    public abstract class WpfRenderingBase : DependencyObject, IDisposable
16    {
17        #region Private Fields
18
19        protected SvgElement _svgElement;
20
21        #endregion
22
23        #region Constructors and Destructor
24
25        protected WpfRenderingBase(SvgElement element)
26        {
27            this._svgElement = element;
28        }
29
30        ~WpfRenderingBase()
31        {
32            this.Dispose(false);
33        }
34
35        #endregion
36
37        #region Public Properties
38
39        public SvgElement Element
40        {
41            get { return _svgElement; }
42        }
43
44        public virtual bool IsRecursive
45        {
46            get
47            {
48                return false;
49            }
50        }
51
52        #endregion
53
54        #region Public Methods
55
56        public virtual bool NeedRender(WpfDrawingRenderer renderer)
57        {
58            if (_svgElement.GetAttribute("display") == "none")
59            {
60                return false;
61            }
62
63            return true;
64        }
65
66        // define empty handlers by default
67        public virtual void BeforeRender(WpfDrawingRenderer renderer) { }
68        public virtual void Render(WpfDrawingRenderer renderer) { }
69        public virtual void AfterRender(WpfDrawingRenderer renderer) { }
70
71        public string GetElementName()
72        {
73            if (_svgElement == null)
74            {
75                return String.Empty;
76            }
77            string elementId = _svgElement.Id;
78            if (elementId != null)
79            {
80                elementId = elementId.Trim();
81            }
82            if (String.IsNullOrEmpty(elementId))
83            {
84                return String.Empty;
85            }
86            if (elementId.Contains("&#x"))
87            {
88                elementId = System.Web.HttpUtility.HtmlDecode(elementId);
89            }
90            if (elementId.Contains("レイヤー"))
91            {
92                elementId = elementId.Replace("レイヤー", "Layer");
93            }
94            else if (elementId.Equals("台紙"))
95            {
96                elementId = "Mount";
97            }
98            else if (elementId.Equals("キャプション"))
99            {
100                elementId = "Caption";
101            }
102            int numberId = 0;
103            if (Int32.TryParse(elementId, out numberId))
104            {
105                return String.Empty;
106            }
107
108            elementId = elementId.Replace(':', '_');
109            elementId = elementId.Replace(' ', '_');
110            elementId = elementId.Replace('.', '_');
111            elementId = elementId.Replace('-', '_');
112
113            return elementId;
114        }
115
116        public static string GetElementName(SvgElement element)
117        {
118            if (element == null)
119            {
120                return String.Empty;
121            }
122            string elementId = element.Id;
123            if (elementId != null)
124            {
125                elementId = elementId.Trim();
126            }
127            if (String.IsNullOrEmpty(elementId))
128            {
129                return String.Empty;
130            }
131            if (elementId.Contains("&#x"))
132            {
133                elementId = System.Web.HttpUtility.HtmlDecode(elementId);
134            }
135            if (elementId.Contains("レイヤー"))
136            {
137                elementId = elementId.Replace("レイヤー", "Layer");
138            }
139            else if (elementId.Equals("イラスト"))
140            {
141                elementId = "Illustration";
142            }
143            else if (elementId.Equals("台紙"))
144            {
145                elementId = "Mount";
146            }
147            else if (elementId.Equals("キャプション"))
148            {
149                elementId = "Caption";
150            }
151            else if (elementId.Equals("細線"))
152            {
153                elementId = "ThinLine";
154            }
155            int numberId = 0;
156            if (Int32.TryParse(elementId, out numberId))
157            {
158                return String.Empty;
159            }
160     
161            elementId = elementId.Replace(':', '_');
162            elementId = elementId.Replace(' ', '_');
163            elementId = elementId.Replace('.', '_');
164            elementId = elementId.Replace('-', '_');
165
166            return elementId;
167        }
168
169        #endregion
170
171        #region IDisposable Members
172
173        public void Dispose()
174        {
175            this.Dispose(true);
176            GC.SuppressFinalize(this);
177        }
178
179        protected virtual void Dispose(bool disposing)
180        {
181        }
182
183        #endregion
184    }
185}
Note: See TracBrowser for help on using the repository browser.