Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Drawing/Collections/ILAxisCollection.cs @ 11826

Last change on this file since 11826 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 9.3 KB
Line 
1///
2///    This file is part of ILNumerics Community Edition.
3///
4///    ILNumerics Community Edition - high performance computing for applications.
5///    Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
6///
7///    ILNumerics Community Edition is free software: you can redistribute it and/or modify
8///    it under the terms of the GNU General Public License version 3 as published by
9///    the Free Software Foundation.
10///
11///    ILNumerics Community Edition is distributed in the hope that it will be useful,
12///    but WITHOUT ANY WARRANTY; without even the implied warranty of
13///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14///    GNU General Public License for more details.
15///
16///    You should have received a copy of the GNU General Public License
17///    along with ILNumerics Community Edition. See the file License.txt in the root
18///    of your distribution package. If not, see <http://www.gnu.org/licenses/>.
19///
20///    In addition this software uses the following components and/or licenses:
21///
22///    =================================================================================
23///    The Open Toolkit Library License
24///   
25///    Copyright (c) 2006 - 2009 the Open Toolkit library.
26///   
27///    Permission is hereby granted, free of charge, to any person obtaining a copy
28///    of this software and associated documentation files (the "Software"), to deal
29///    in the Software without restriction, including without limitation the rights to
30///    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31///    the Software, and to permit persons to whom the Software is furnished to do
32///    so, subject to the following conditions:
33///
34///    The above copyright notice and this permission notice shall be included in all
35///    copies or substantial portions of the Software.
36///
37///    =================================================================================
38///   
39
40using System;
41using System.Collections.Generic;
42using System.Text;
43using ILNumerics.Exceptions;
44using System.Drawing;
45using ILNumerics.Drawing.Interfaces;
46using System.Reflection; 
47
48
49namespace ILNumerics.Drawing.Collections {
50       
51    /// <summary>
52    /// Collection of all 3 axes contained in each subfigure
53    /// </summary>
54    public class ILAxisCollection {
55
56        #region event + trigger
57        public event AxisChangedEventHandler Changed;
58        internal void OnChanged(ILAxis sender, AxisNames axis) {
59            if (Changed != null)
60                Changed(sender ,new ILAxisChangedEventArgs(axis));
61        }
62        #endregion
63
64        #region  attributes / properties
65        private int m_optimizeCounter;
66        private ILAxis[] m_axes;
67        private Size m_maximumSize;
68        /// <summary>
69        /// Get / set ILAxis by index
70        /// </summary>
71        /// <param name="index">index of axis: XAxis = 0, YAxis = 1, ZAxis = 2</param>
72        /// <returns>ILAxis specified by index</returns>
73        /// <value>new ILAxis to be stored into the collection</value>
74        public ILAxis this[int index] {
75            get {
76                if (index < 0 || index > 2)
77                    throw new ILArgumentException("ILAxisCollection: axis index out of bounds!");
78                return m_axes[index];
79            }
80            set {
81                if (index < 0 || index > 2)
82                    throw new ILArgumentException("ILAxisCollection: axis index out of bounds!");
83                m_axes [index] = value;
84                Invalidate();
85            }
86        }
87        /// <summary>
88        /// Get / set ILAxis by name enum
89        /// </summary>
90        /// <param name="name">one of the enum values: XAxis, YAxis, ZAxis</param>
91        /// <returns>ILAxis specified by name</returns>
92        /// <value>new ILAxis to be stored into the collection</value>
93        public ILAxis this[AxisNames name] {
94            get {
95                switch (name) {
96                    case AxisNames.XAxis:
97                        return m_axes[0];
98                    case AxisNames.YAxis:
99                        return m_axes[1];
100                    default:
101                        return m_axes[2];
102                }
103            }
104            set {
105                m_axes [(int)name] = value;
106                Invalidate();
107            }
108        }
109        /// <summary>
110        /// Get access to the X-axis
111        /// </summary>
112        public ILAxis XAxis {
113            get {
114                return m_axes[0];
115            }
116        }
117        /// <summary>
118        /// Get access to the Y-axis
119        /// </summary>
120        public ILAxis YAxis {
121            get {
122                return m_axes[1];
123            }
124        }
125        /// <summary>
126        /// Get access to the Z-axis
127        /// </summary>
128        public ILAxis ZAxis {
129            get {
130                return m_axes[2];
131            }
132        }
133        /// <summary>
134        /// Maximum size of all axes contained in the collection
135        /// </summary>
136        public Size MaxTicLabelSize {
137            get {
138                System.Diagnostics.Debug.Assert(m_maximumSize.Width >= 0);
139                return m_maximumSize;
140            }
141        }
142        /// <summary>
143        /// Set visibility for all axes simultaneously
144        /// </summary>
145        public bool Visible {
146            set {
147                m_axes[0].Visible = value;
148                m_axes[1].Visible = value;
149                m_axes[2].Visible = value;
150            }
151        }
152        /// <summary>
153        /// set visibility of axis lines simultaneously
154        /// </summary>
155        public bool LinesVisible {
156            set {
157                m_axes[0].NearLines.Visible = value;
158                m_axes[1].NearLines.Visible = value;
159                m_axes[2].NearLines.Visible = value;
160                m_axes[0].FarLines.Visible = value;
161                m_axes[1].FarLines.Visible = value;
162                m_axes[2].FarLines.Visible = value;
163            }
164        }
165        /// <summary>
166        /// set visibility of all axis grid lines simultaneously
167        /// </summary>
168        public bool GridVisible {
169            set {
170                m_axes[0].Grid.Visible = value;
171                m_axes[1].Grid.Visible = value;
172                m_axes[2].Grid.Visible = value;
173             }
174        }
175
176        #endregion
177
178        #region contructor
179        /// <summary>
180        /// create new ILAxisCollection
181        /// </summary>
182        internal ILAxisCollection(ILClippingData clippingView, IILCreationFactory factory) {
183            m_axes = new ILAxis[3];
184            m_axes[0] = factory.CreateAxis(AxisNames.XAxis,clippingView);
185            m_axes[1] = factory.CreateAxis(AxisNames.YAxis,clippingView);
186            m_axes[2] = factory.CreateAxis(AxisNames.ZAxis,clippingView);
187            EventHandler handler = new EventHandler(Axis_Changed);
188            m_axes[0].Changed += handler;
189            m_axes[1].Changed += handler;
190            m_axes[2].Changed += handler;
191        }
192        #endregion
193
194        #region public methods 
195        public void Initialize()  {
196
197        }
198        public void Invalidate() {
199            //m_maximumSize = Size.Empty;
200            m_axes[0].Invalidate();
201            m_axes[1].Invalidate();
202            m_axes[2].Invalidate();
203        }
204
205        public void Dispose() {
206            if (m_axes.Length > 0 && m_axes[0] != null)
207                m_axes[0].Dispose();
208            if (m_axes.Length > 1 && m_axes[1] != null)
209                m_axes[1].Dispose();
210            if (m_axes.Length > 2 && m_axes[2] != null)
211                m_axes[2].Dispose();
212        }
213        #endregion
214
215        #region helper functions
216        protected void Axis_Changed(object sender, EventArgs e) {
217            Invalidate();
218            if (sender is ILAxis && sender != null) {
219                ILAxis ax = (ILAxis)sender;
220                OnChanged(ax,(AxisNames)ax.Index);
221            }
222        }
223        internal Size MeasureMaxTickLabelSize(Graphics gr) {
224            Size max = new Size();
225            for (int i = 0; i < m_axes.Length; i++) {
226                if (m_axes[i].Visible) {
227                    int pad = 2 * m_axes[i].LabeledTicks.Padding;
228                    int x = m_axes[i].LabeledTicks.Size.Width + pad;
229                    int y = m_axes[i].LabeledTicks.Size.Height + pad;
230                    if (y > max.Height) {
231                        max.Height = y;
232                    }
233                    if (x > max.Width) {
234                        max.Width = x;
235                    }
236                }
237            }
238            //if (max.Width > m_maximumSize.Width || max.Height > m_maximumSize.Height) {
239            //    m_maximumSize = max;
240            //    m_optimizeCounter = 0;
241            //    return max;
242            //} else if (max.Width < m_maximumSize.Width
243            //    || max.Height < m_maximumSize.Height) {
244            //    if (++m_optimizeCounter > 10) {
245            //        m_maximumSize = max;
246            //        m_optimizeCounter = 0;
247            //        return max;
248            //    }
249            //}
250            return max;
251        }
252        #endregion
253    }
254}
Note: See TracBrowser for help on using the repository browser.