///
/// 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 System.Drawing;
using ILNumerics.Drawing;
using ILNumerics.Drawing.Platform.OpenGL;
using ILNumerics.Exceptions;
namespace ILNumerics.Drawing.Marker {
///
/// Properties for marker (e.g. used for line plots)
///
public class ILMarker {
#region eventing
///
/// Fires when the properties have changed
///
public event EventHandler Changed;
protected void OnChanged() {
if (Changed != null) {
Changed(this,new EventArgs());
}
}
#endregion
#region attributes
private ILPanel m_panel;
private int m_markerSize;
private ILMarkerShape m_shape;
private Color m_color;
protected bool m_visible;
#endregion
#region properties
///
/// Switch on or off the visibility of all markers
///
public bool Visible {
get {
return m_visible;
}
set {
m_visible = value;
OnChanged();
}
}
///
/// Marker color
///
public Color Color {
get {
return m_color;
}
set {
m_color = value;
if (!value.IsEmpty)
m_visible = true;
else
m_visible = false;
OnChanged();
}
}
///
/// Shape of markers, compatible with string, markerStyle or bitmap arguments
///
public ILMarkerShape Shape {
get {
return m_shape;
}
set {
//implement abstract factory pattern
if (value is ILMarkerShapeProxy) {
m_shape = Create(value as ILMarkerShapeProxy);
if ((m_shape is ILStyledMarkerShape) && (m_shape as ILStyledMarkerShape).Style == MarkerStyle.None )
m_visible = false;
else
m_visible = true;
//m_markerSize = 8;
}
OnChanged();
}
}
///
/// Size of markers in pixels (default: 10)
///
public int Size {
get {
return m_markerSize;
}
set {
m_markerSize = value;
if (m_markerSize > 0)
m_visible = true;
else
m_visible = false;
OnChanged();
}
}
#endregion
#region constructor
///
/// create a new marker property instance
///
public ILMarker (ILPanel panel) {
m_panel = panel;
m_shape = MarkerStyle.None;
m_markerSize = 5;
m_visible = false;
m_color = Color.DarkBlue;
}
#endregion
#region public interface
internal static ILTexMarkerShape Create(ILPanel panel, string expression) {
return new ILTexMarkerShape(panel,expression);
}
internal static ILStyledMarkerShape Create(ILPanel panel, MarkerStyle style) {
switch (panel.GraphicDeviceType) {
case GraphicDeviceType.OpenGL:
return new ILOGLStyledMarkerShape(panel,style);
default:
throw new NotImplementedException("styled markers are not implemented yet for this graphics device type!");
}
}
internal static ILBitmapMarkerShape Create(ILPanel panel, Bitmap bitmap) {
switch (panel.GraphicDeviceType) {
case GraphicDeviceType.OpenGL:
return new ILOGLBitmapMarkerShape(panel,bitmap);
default:
throw new NotImplementedException("Bitmap markers are not implemented yet for this graphics device type!");
}
}
internal ILMarkerShape Create(ILMarkerShapeProxy proxy) {
if (proxy.Source is string) {
return Create(m_panel,proxy.Source as string);
} else if (proxy.Source is MarkerStyle) {
return Create(m_panel,(MarkerStyle)proxy.Source);
} else if (proxy.Source is Bitmap) {
return Create(m_panel,proxy.Source as Bitmap);
}
throw new ILArgumentException(String.Format("Unable to create marker shape based on proxy source given: {0}",proxy.Source.ToString()));
}
#endregion
}
}