Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorConverters/SvgConverter.cs @ 13783

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

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

File size: 6.8 KB
Line 
1using System;
2
3using System.Windows;
4using System.Windows.Media;
5
6using SharpVectors.Renderers.Wpf;
7
8namespace SharpVectors.Converters
9{
10    /// <summary>
11    /// This is the <see langword="abstract"/> base class for all
12    /// SVG to WPF converters.
13    /// </summary>
14    public abstract class SvgConverter : DependencyObject, IDisposable
15    {
16        #region Private Fields
17
18        private bool _saveXaml;
19        private bool _saveZaml;
20        private bool _useFrameXamlWriter;
21
22        private WpfDrawingSettings _wpfSettings;
23
24        #endregion
25
26        #region Constructors and Destrutor
27
28        /// <overloads>
29        /// Initializes a new instance of the <see cref="SvgConverter"/> class.
30        /// </overloads>
31        /// <summary>
32        /// Initializes a new instance of the <see cref="SvgConverter"/> class
33        /// with the default parameters and settings.
34        /// </summary>
35        protected SvgConverter()
36            : this(null)
37        {   
38        }
39
40        /// <summary>
41        /// Initializes a new instance of the <see cref="SvgConverter"/> class
42        /// with the specified drawing or rendering settings.
43        /// </summary>
44        /// <param name="settings">
45        /// This specifies the settings used by the rendering or drawing engine.
46        /// If this is <see langword="null"/>, the default settings is used.
47        /// </param>
48        protected SvgConverter(WpfDrawingSettings settings)
49        {
50            _saveXaml    = true;
51            _saveZaml    = false;
52            _wpfSettings = settings;
53
54            if (_wpfSettings == null)
55            {
56                _wpfSettings = new WpfDrawingSettings();
57            }
58        }
59
60        /// <summary>
61        /// Initializes a new instance of the <see cref="SvgConverter"/> class
62        /// with the specified drawing or rendering settings and the saving options.
63        /// </summary>
64        /// <param name="saveXaml">
65        /// This specifies whether to save result object tree in XAML file.
66        /// </param>
67        /// <param name="saveZaml">
68        /// This specifies whether to save result object tree in ZAML file. The
69        /// ZAML is simply a G-Zip compressed XAML format, similar to the SVGZ.
70        /// </param>
71        /// <param name="settings">
72        /// This specifies the settings used by the rendering or drawing engine.
73        /// If this is <see langword="null"/>, the default settings is used.
74        /// </param>
75        protected SvgConverter(bool saveXaml, bool saveZaml,
76            WpfDrawingSettings settings) : this(settings)
77        {
78            _saveXaml    = saveXaml;
79            _saveZaml    = SaveZaml;
80        }
81
82        /// <summary>
83        /// This allows a converter to attempt to free resources and perform
84        /// other cleanup operations before the converter is reclaimed by
85        /// garbage collection.
86        /// </summary>
87        ~SvgConverter()
88        {
89            this.Dispose(false);
90        }
91
92        #endregion
93
94        #region Public Properties
95
96        /// <summary>
97        /// Gets or sets a value indicating whether to save the conversion
98        /// output to the XAML file.
99        /// </summary>
100        /// <value>
101        /// This is <see langword="true"/> if the conversion output is saved
102        /// to the XAML file; otherwise, it is <see langword="false"/>.
103        /// The default depends on the converter.
104        /// </value>
105        public bool SaveXaml
106        {
107            get
108            {
109                return _saveXaml;
110            }
111            set
112            {
113                _saveXaml = value;
114            }
115        }
116
117        /// <summary>
118        /// Gets or sets a value indicating whether to save the conversion
119        /// output to the ZAML file.
120        /// </summary>
121        /// <value>
122        /// This is <see langword="true"/> if the conversion output is saved
123        /// to the ZAML file; otherwise, it is <see langword="false"/>.
124        /// The default depends on the converter.
125        /// </value>
126        /// <remarks>
127        /// The ZAML is simply a G-Zip compressed XAML format, similar to the
128        /// SVGZ.
129        /// </remarks>
130        public bool SaveZaml
131        {
132            get
133            {
134                return _saveZaml;
135            }
136            set
137            {
138                _saveZaml = value;
139            }
140        }
141
142        /// <summary>
143        /// Gets or sets a value indicating whether to use the .NET framework
144        /// version of the XAML writer.
145        /// </summary>
146        /// <value>
147        /// This is <see langword="true"/> if the .NET framework version of the
148        /// XAML writer is used; otherwise, a customized XAML writer,
149        /// <see cref="XmlXamlWriter"/>, is used. The default is <see langword="false"/>.
150        /// </value>
151        /// <remarks>
152        /// The customized XAML writer is optimized for the conversion process,
153        /// and it is recommended as the writer, unless in cases where it fails
154        /// to produce accurate result.
155        /// </remarks>
156        public bool UseFrameXamlWriter
157        {
158            get
159            {
160                return _useFrameXamlWriter;
161            }
162            set
163            {
164                _useFrameXamlWriter = value;
165            }
166        }
167
168        /// <summary>
169        /// Gets the settings used by the rendering or drawing engine.
170        /// </summary>
171        /// <value>
172        /// An instance of <see cref="WpfDrawingSettings"/> specifying all
173        /// the options for rendering or drawing.
174        /// </value>
175        public WpfDrawingSettings DrawingSettings
176        {
177            get
178            {
179                return _wpfSettings;
180            }
181        }
182
183        #endregion
184
185        #region IDisposable Members
186
187        /// <overloads>
188        /// This releases all resources used by the <see cref="SvgConverter"/> object.
189        /// </overloads>
190        /// <summary>
191        /// This releases all resources used by the <see cref="SvgConverter"/> object.
192        /// </summary>
193        public void Dispose()
194        {
195            this.Dispose(true);
196            GC.SuppressFinalize(this);
197        }
198
199        /// <summary>
200        /// This releases the unmanaged resources used by the <see cref="SvgConverter"/>
201        /// and optionally releases the managed resources.
202        /// </summary>
203        /// <param name="disposing">
204        /// This is <see langword="true"/> if managed resources should be
205        /// disposed; otherwise, <see langword="false"/>.
206        /// </param>
207        protected virtual void Dispose(bool disposing)
208        {
209        }
210
211        #endregion
212    }
213}
Note: See TracBrowser for help on using the repository browser.