///
/// This file is part of ILNumerics Community Edition.
///
/// ILNumerics Community Edition - high performance computing for applications.
/// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
///
/// ILNumerics Community Edition is free software: you can redistribute it and/or modify
/// it under the terms of the GNU General Public License version 3 as published by
/// the Free Software Foundation.
///
/// ILNumerics Community Edition is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with ILNumerics Community Edition. See the file License.txt in the root
/// of your distribution package. If not, see .
///
/// In addition this software uses the following components and/or licenses:
///
/// =================================================================================
/// The Open Toolkit Library License
///
/// Copyright (c) 2006 - 2009 the Open Toolkit library.
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights to
/// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
/// the Software, and to permit persons to whom the Software is furnished to do
/// so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all
/// copies or substantial portions of the Software.
///
/// =================================================================================
///
using System;
using System.Collections.Generic;
using System.Text;
using ILNumerics.Exceptions;
using System.Drawing;
using ILNumerics.Drawing.Interfaces;
using System.Reflection;
namespace ILNumerics.Drawing.Collections {
///
/// Collection of all 3 axes contained in each subfigure
///
public class ILAxisCollection {
#region event + trigger
public event AxisChangedEventHandler Changed;
internal void OnChanged(ILAxis sender, AxisNames axis) {
if (Changed != null)
Changed(sender ,new ILAxisChangedEventArgs(axis));
}
#endregion
#region attributes / properties
private int m_optimizeCounter;
private ILAxis[] m_axes;
private Size m_maximumSize;
///
/// Get / set ILAxis by index
///
/// index of axis: XAxis = 0, YAxis = 1, ZAxis = 2
/// ILAxis specified by index
/// new ILAxis to be stored into the collection
public ILAxis this[int index] {
get {
if (index < 0 || index > 2)
throw new ILArgumentException("ILAxisCollection: axis index out of bounds!");
return m_axes[index];
}
set {
if (index < 0 || index > 2)
throw new ILArgumentException("ILAxisCollection: axis index out of bounds!");
m_axes [index] = value;
Invalidate();
}
}
///
/// Get / set ILAxis by name enum
///
/// one of the enum values: XAxis, YAxis, ZAxis
/// ILAxis specified by name
/// new ILAxis to be stored into the collection
public ILAxis this[AxisNames name] {
get {
switch (name) {
case AxisNames.XAxis:
return m_axes[0];
case AxisNames.YAxis:
return m_axes[1];
default:
return m_axes[2];
}
}
set {
m_axes [(int)name] = value;
Invalidate();
}
}
///
/// Get access to the X-axis
///
public ILAxis XAxis {
get {
return m_axes[0];
}
}
///
/// Get access to the Y-axis
///
public ILAxis YAxis {
get {
return m_axes[1];
}
}
///
/// Get access to the Z-axis
///
public ILAxis ZAxis {
get {
return m_axes[2];
}
}
///
/// Maximum size of all axes contained in the collection
///
public Size MaxTicLabelSize {
get {
System.Diagnostics.Debug.Assert(m_maximumSize.Width >= 0);
return m_maximumSize;
}
}
///
/// Set visibility for all axes simultaneously
///
public bool Visible {
set {
m_axes[0].Visible = value;
m_axes[1].Visible = value;
m_axes[2].Visible = value;
}
}
///
/// set visibility of axis lines simultaneously
///
public bool LinesVisible {
set {
m_axes[0].NearLines.Visible = value;
m_axes[1].NearLines.Visible = value;
m_axes[2].NearLines.Visible = value;
m_axes[0].FarLines.Visible = value;
m_axes[1].FarLines.Visible = value;
m_axes[2].FarLines.Visible = value;
}
}
///
/// set visibility of all axis grid lines simultaneously
///
public bool GridVisible {
set {
m_axes[0].Grid.Visible = value;
m_axes[1].Grid.Visible = value;
m_axes[2].Grid.Visible = value;
}
}
#endregion
#region contructor
///
/// create new ILAxisCollection
///
internal ILAxisCollection(ILClippingData clippingView, IILCreationFactory factory) {
m_axes = new ILAxis[3];
m_axes[0] = factory.CreateAxis(AxisNames.XAxis,clippingView);
m_axes[1] = factory.CreateAxis(AxisNames.YAxis,clippingView);
m_axes[2] = factory.CreateAxis(AxisNames.ZAxis,clippingView);
EventHandler handler = new EventHandler(Axis_Changed);
m_axes[0].Changed += handler;
m_axes[1].Changed += handler;
m_axes[2].Changed += handler;
}
#endregion
#region public methods
public void Initialize() {
}
public void Invalidate() {
//m_maximumSize = Size.Empty;
m_axes[0].Invalidate();
m_axes[1].Invalidate();
m_axes[2].Invalidate();
}
public void Dispose() {
if (m_axes.Length > 0 && m_axes[0] != null)
m_axes[0].Dispose();
if (m_axes.Length > 1 && m_axes[1] != null)
m_axes[1].Dispose();
if (m_axes.Length > 2 && m_axes[2] != null)
m_axes[2].Dispose();
}
#endregion
#region helper functions
protected void Axis_Changed(object sender, EventArgs e) {
Invalidate();
if (sender is ILAxis && sender != null) {
ILAxis ax = (ILAxis)sender;
OnChanged(ax,(AxisNames)ax.Index);
}
}
internal Size MeasureMaxTickLabelSize(Graphics gr) {
Size max = new Size();
for (int i = 0; i < m_axes.Length; i++) {
if (m_axes[i].Visible) {
int pad = 2 * m_axes[i].LabeledTicks.Padding;
int x = m_axes[i].LabeledTicks.Size.Width + pad;
int y = m_axes[i].LabeledTicks.Size.Height + pad;
if (y > max.Height) {
max.Height = y;
}
if (x > max.Width) {
max.Width = x;
}
}
}
//if (max.Width > m_maximumSize.Width || max.Height > m_maximumSize.Height) {
// m_maximumSize = max;
// m_optimizeCounter = 0;
// return max;
//} else if (max.Width < m_maximumSize.Width
// || max.Height < m_maximumSize.Height) {
// if (++m_optimizeCounter > 10) {
// m_maximumSize = max;
// m_optimizeCounter = 0;
// return max;
// }
//}
return max;
}
#endregion
}
}