[9102] | 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 |
|
---|
| 40 | using System;
|
---|
| 41 | using System.Collections.Generic;
|
---|
| 42 | using System.Text;
|
---|
| 43 | using System.Drawing;
|
---|
| 44 | using ILNumerics.Drawing;
|
---|
| 45 | using ILNumerics.Drawing.Platform.OpenGL;
|
---|
| 46 | using ILNumerics.Exceptions;
|
---|
| 47 |
|
---|
| 48 | namespace ILNumerics.Drawing.Marker {
|
---|
| 49 | /// <summary>
|
---|
| 50 | /// Properties for marker (e.g. used for line plots)
|
---|
| 51 | /// </summary>
|
---|
| 52 | public class ILMarker {
|
---|
| 53 |
|
---|
| 54 | #region eventing
|
---|
| 55 | /// <summary>
|
---|
| 56 | /// Fires when the properties have changed
|
---|
| 57 | /// </summary>
|
---|
| 58 | public event EventHandler Changed;
|
---|
| 59 | protected void OnChanged() {
|
---|
| 60 | if (Changed != null) {
|
---|
| 61 | Changed(this,new EventArgs());
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | #endregion
|
---|
| 65 |
|
---|
| 66 | #region attributes
|
---|
| 67 | private ILPanel m_panel;
|
---|
| 68 | private int m_markerSize;
|
---|
| 69 | private ILMarkerShape m_shape;
|
---|
| 70 | private Color m_color;
|
---|
| 71 | protected bool m_visible;
|
---|
| 72 | #endregion
|
---|
| 73 |
|
---|
| 74 | #region properties
|
---|
| 75 | /// <summary>
|
---|
| 76 | /// Switch on or off the visibility of all markers
|
---|
| 77 | /// </summary>
|
---|
| 78 | public bool Visible {
|
---|
| 79 | get {
|
---|
| 80 | return m_visible;
|
---|
| 81 | }
|
---|
| 82 | set {
|
---|
| 83 | m_visible = value;
|
---|
| 84 | OnChanged();
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | /// <summary>
|
---|
| 88 | /// Marker color
|
---|
| 89 | /// </summary>
|
---|
| 90 | public Color Color {
|
---|
| 91 | get {
|
---|
| 92 | return m_color;
|
---|
| 93 | }
|
---|
| 94 | set {
|
---|
| 95 | m_color = value;
|
---|
| 96 | if (!value.IsEmpty)
|
---|
| 97 | m_visible = true;
|
---|
| 98 | else
|
---|
| 99 | m_visible = false;
|
---|
| 100 | OnChanged();
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | /// <summary>
|
---|
| 104 | /// Shape of markers, compatible with string, markerStyle or bitmap arguments
|
---|
| 105 | /// </summary>
|
---|
| 106 | public ILMarkerShape Shape {
|
---|
| 107 | get {
|
---|
| 108 | return m_shape;
|
---|
| 109 | }
|
---|
| 110 | set {
|
---|
| 111 | //implement abstract factory pattern
|
---|
| 112 | if (value is ILMarkerShapeProxy) {
|
---|
| 113 | m_shape = Create(value as ILMarkerShapeProxy);
|
---|
| 114 | if ((m_shape is ILStyledMarkerShape) && (m_shape as ILStyledMarkerShape).Style == MarkerStyle.None )
|
---|
| 115 | m_visible = false;
|
---|
| 116 | else
|
---|
| 117 | m_visible = true;
|
---|
| 118 | //m_markerSize = 8;
|
---|
| 119 | }
|
---|
| 120 | OnChanged();
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 | /// <summary>
|
---|
| 124 | /// Size of markers in pixels (default: 10)
|
---|
| 125 | /// </summary>
|
---|
| 126 | public int Size {
|
---|
| 127 | get {
|
---|
| 128 | return m_markerSize;
|
---|
| 129 | }
|
---|
| 130 | set {
|
---|
| 131 | m_markerSize = value;
|
---|
| 132 | if (m_markerSize > 0)
|
---|
| 133 | m_visible = true;
|
---|
| 134 | else
|
---|
| 135 | m_visible = false;
|
---|
| 136 | OnChanged();
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | #endregion
|
---|
| 140 |
|
---|
| 141 | #region constructor
|
---|
| 142 | /// <summary>
|
---|
| 143 | /// create a new marker property instance
|
---|
| 144 | /// </summary>
|
---|
| 145 | public ILMarker (ILPanel panel) {
|
---|
| 146 | m_panel = panel;
|
---|
| 147 | m_shape = MarkerStyle.None;
|
---|
| 148 | m_markerSize = 5;
|
---|
| 149 | m_visible = false;
|
---|
| 150 | m_color = Color.DarkBlue;
|
---|
| 151 | }
|
---|
| 152 | #endregion
|
---|
| 153 |
|
---|
| 154 | #region public interface
|
---|
| 155 | internal static ILTexMarkerShape Create(ILPanel panel, string expression) {
|
---|
| 156 | return new ILTexMarkerShape(panel,expression);
|
---|
| 157 | }
|
---|
| 158 | internal static ILStyledMarkerShape Create(ILPanel panel, MarkerStyle style) {
|
---|
| 159 | switch (panel.GraphicDeviceType) {
|
---|
| 160 | case GraphicDeviceType.OpenGL:
|
---|
| 161 | return new ILOGLStyledMarkerShape(panel,style);
|
---|
| 162 | default:
|
---|
| 163 | throw new NotImplementedException("styled markers are not implemented yet for this graphics device type!");
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | internal static ILBitmapMarkerShape Create(ILPanel panel, Bitmap bitmap) {
|
---|
| 167 | switch (panel.GraphicDeviceType) {
|
---|
| 168 | case GraphicDeviceType.OpenGL:
|
---|
| 169 | return new ILOGLBitmapMarkerShape(panel,bitmap);
|
---|
| 170 | default:
|
---|
| 171 | throw new NotImplementedException("Bitmap markers are not implemented yet for this graphics device type!");
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 | internal ILMarkerShape Create(ILMarkerShapeProxy proxy) {
|
---|
| 175 |
|
---|
| 176 | if (proxy.Source is string) {
|
---|
| 177 | return Create(m_panel,proxy.Source as string);
|
---|
| 178 | } else if (proxy.Source is MarkerStyle) {
|
---|
| 179 | return Create(m_panel,(MarkerStyle)proxy.Source);
|
---|
| 180 | } else if (proxy.Source is Bitmap) {
|
---|
| 181 | return Create(m_panel,proxy.Source as Bitmap);
|
---|
| 182 | }
|
---|
| 183 | throw new ILArgumentException(String.Format("Unable to create marker shape based on proxy source given: {0}",proxy.Source.ToString()));
|
---|
| 184 | }
|
---|
| 185 | #endregion
|
---|
| 186 |
|
---|
| 187 | }
|
---|
| 188 | }
|
---|