Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorModel/BasicTypes/SvgElement.cs @ 13321

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

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

File size: 7.0 KB
Line 
1// <developer>niklas@protocol7.com</developer>
2// <developer>kevin@kevlindev.com</developer>
3// <completed>75</completed>
4
5using System;
6using System.Xml;
7
8using SharpVectors.Dom.Css;
9
10namespace SharpVectors.Dom.Svg
11{
12    /// <summary>
13    /// Summary description for SvgElement.
14    /// </summary>
15    public class SvgElement : CssXmlElement, ISvgElement
16    {
17        #region Private Fields
18
19        private bool                _isImported;
20        private SvgElement          _importNode;
21        private SvgDocument         _importDocument;
22        private ISvgElementInstance _elementInstance;
23
24        #endregion
25
26        #region Constructors and Destructors
27
28        public SvgElement(string prefix, string localname, string ns, SvgDocument doc)
29            : base(prefix, localname, ns, doc)
30        {
31        }
32
33        #endregion
34
35        #region Public Properties
36
37        public bool Imported
38        {
39            get
40            {
41                return _isImported;
42            }
43            set
44            {
45                _isImported = value;
46            }
47        }
48
49        public SvgElement ImportNode
50        {
51            get
52            {
53                return _importNode;
54            }
55            set
56            {
57                _importNode = value;
58            }
59        }
60
61        public SvgDocument ImportDocument
62        {
63            get
64            {
65                return _importDocument;
66            }
67            set
68            {
69                _importDocument = value;
70            }
71        }
72
73        #endregion
74
75        #region ISvgElement Members
76
77        public new SvgDocument OwnerDocument
78        {
79            get
80            {
81                return base.OwnerDocument as SvgDocument;
82            }
83        }
84
85        public string Id
86        {
87            get
88            {
89                return GetAttribute("id");
90            }
91            set
92            {
93                SetAttribute("id", value);
94            }
95        }
96
97        public ISvgSvgElement OwnerSvgElement
98        {
99            get
100            {
101                if (this.Equals(OwnerDocument.DocumentElement))
102                {
103                    return null;
104                }
105                else
106                {
107                    XmlNode parent = ParentNode;
108                    while (parent != null && !(parent is SvgSvgElement))
109                    {
110                        parent = parent.ParentNode;
111                    }
112                    return parent as SvgSvgElement;
113                }
114            }
115        }
116
117        public ISvgElement ViewportElement
118        {
119            get
120            {
121                if (this.Equals(OwnerDocument.DocumentElement))
122                {
123                    return null;
124                }
125                else
126                {
127                    XmlNode parent = ParentNode;
128                    while (parent != null && !(parent is SvgSvgElement) && !(parent is SvgSymbolElement))
129                    {
130                        parent = parent.ParentNode;
131                    }
132
133                    return parent as SvgElement;
134                }
135            }
136        }
137
138        /// <summary>
139        /// Gets a value indicating whether this SVG element is renderable.
140        /// </summary>
141        /// <value>
142        /// This is <see langword="'true"/> if the element is renderable; otherwise,
143        /// it is <see langword="false"/>.
144        /// </value>
145        public virtual bool IsRenderable
146        {
147            get
148            {
149                return true;
150            }
151        }
152
153        /// <summary>
154        /// Gets a value providing a hint on the rendering defined by this element.
155        /// </summary>
156        /// <value>
157        /// An enumeration of the <see cref="SvgRenderingHint"/> specifying the rendering hint.
158        /// </value>
159        public virtual SvgRenderingHint RenderingHint
160        {
161            get
162            {
163                return SvgRenderingHint.None;
164            }
165        }
166
167        #endregion
168
169        #region ISvgLangSpace Members
170
171        public string XmlSpace
172        {
173            get
174            {
175                string s = GetAttribute("xml:space");
176                if (String.IsNullOrEmpty(s))
177                {
178                    SvgElement par = this.ParentNode as SvgElement;
179                    if (par != null)
180                    {
181                        s = par.XmlSpace;
182                    }
183                    else
184                    {
185                        s = "default";
186                    }
187                }
188
189                return s;
190            }
191            set
192            {
193                SetAttribute("xml:space", value);
194            }
195        }
196
197        public string XmlLang
198        {
199            get
200            {
201                string s = this.GetAttribute("xml:lang");
202                if (String.IsNullOrEmpty(s))
203                {
204                    SvgElement par = this.ParentNode as SvgElement;
205                    if (par != null)
206                    {
207                        s = par.XmlLang;
208                    }
209                    else
210                    {
211                        s = String.Empty;
212                    }
213                }
214
215                return s;
216            }
217            set
218            {
219                this.SetAttribute("xml:lang", value);
220            }
221        }
222
223        #endregion
224
225        #region Other public methods
226
227        public string ResolveUri(string uri)
228        {
229            uri = uri.Trim();
230            if (uri.StartsWith("#"))
231            {
232                return uri;
233            }
234            else
235            {
236                string baseUri = BaseURI;
237                if (baseUri.Length == 0)
238                {
239                    return uri;
240                }
241                else
242                {
243                    return new Uri(new Uri(baseUri), uri).AbsoluteUri;
244                }
245            }
246        }
247
248        /// <summary>
249        /// Whenever an SvgElementInstance is created for an SvgElement this
250        /// property is set. The value of this property is used by the renderer
251        /// to dispatch events. SvgElements that are &lt;use&gt;d exist in a
252        /// conceptual "instance tree" and the target of events for those elements
253        /// is the conceptual instance node represented by the SvgElementInstance.
254        /// <see cref="http://www.w3.org/TR/SVG/struct.html#UseElement"/>
255        /// <see cref="http://www.w3.org/TR/SVG/struct.html#InterfaceSVGElementInstance"/>
256        /// </summary>
257        public ISvgElementInstance ElementInstance
258        {
259            get
260            {
261                return _elementInstance;
262            }
263            set
264            {
265                _elementInstance = value;
266            }
267        }
268
269        #endregion
270    }
271}
Note: See TracBrowser for help on using the repository browser.