///
/// 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.Drawing;
using ILNumerics.Drawing.Interfaces;
using ILNumerics.Exceptions;
namespace ILNumerics.Drawing.Shapes {
///
/// A simple single line
///
public class ILLine : ILBorderedShape {
#region attributes
ILLineProperties m_properties;
int m_autoLimitsUpdateCount = 0;
int m_updateCount = 0;
public int AutoLimitsUpdateCount {
get { return m_autoLimitsUpdateCount; }
set { m_autoLimitsUpdateCount = value; }
}
int m_oldestVertexID;
#endregion
#region properties
///
/// [deprecated] line properties, use individual properties of ILLine instead
///
public ILLineProperties Properties {
get { return m_properties; }
private set { m_properties = value; }
}
///
/// the oldest vertex to be removed on the next Queue() call
///
internal int OldestVertexID {
get { return m_oldestVertexID; }
}
///
/// determines, if the line is to be drawn antialiased (on width > 1 only)
///
public bool Antialiasing {
get { return m_properties.Antialiasing; }
set { m_properties.Antialiasing = value; }
}
///
/// stipple pattern for the line, if Style is set to custom pattern
///
public short Pattern {
get { return m_properties.Pattern; }
set { m_properties.Pattern = value; }
}
///
/// scaling for the stipple pattern
///
public float PatternScale {
get { return m_properties.PatternScale; }
set { m_properties.PatternScale = value; }
}
///
/// line style, default: solid
///
public LineStyle Style {
get { return m_properties.Style; }
set { m_properties.Style = value; }
}
///
/// line width (pixels)
///
public int Width {
get { return m_properties.Width; }
set { m_properties.Width = value; }
}
///
/// inner color of the line
///
public override Color FillColor {
get {
return m_properties.Color;
}
set {
m_properties.Color = value;
}
}
#endregion
#region constructors
///
/// create new simple line with 2 ends
///
///
public ILLine (ILPanel panel)
: this (panel,2) { }
///
/// create new line, determine number of vertices
///
/// panel hosting the scene
/// number of vertices for the line
public ILLine (ILPanel panel, int numVertices)
: base (panel,numVertices) {
if (numVertices < 2)
throw new ILArgumentException("line must have at least 2 points!");
m_fillColor = Color.Black;
m_border.Visible = false;
m_oldestVertexID = 0;
m_properties = new ILLineProperties();
m_properties.Changed += new EventHandler(m_properties_Changed);
m_properties.Color = Color.Blue;
m_properties.Width = 2;
m_properties.Antialiasing = true;
// default for border
m_border.Width = 5;
m_border.Antialiasing = true;
m_border.Color = Color.LightGray;
m_autoLimitsUpdateCount = numVertices;
m_shading = ShadingStyles.Flat;
}
/////
///// create new line, give vertices positions also
/////
///// panel hosting the scene
///// X coordinates
///// Y coordinates
///// Z coordinates
//public ILLine(ILPanel panel, ILBaseArray X, ILBaseArray Y, ILBaseArray Z)
// : base (panel, X,Y,Z) {
// m_fillColor = Color.Black;
// m_border.Visible = false;
// m_oldestVertexID = 0;
// m_properties = new ILLineProperties();
// m_properties.Changed += new EventHandler(m_properties_Changed);
// m_properties.Color = Color.Blue;
// m_shading = ShadingStyles.Flat;
// m_autoLimitsUpdateCount = Vertices.Length;
//}
#endregion
#region private helpers
void m_properties_Changed(object sender, EventArgs e) {
m_fillColor = m_properties.Color;
OnChanged();
}
protected override void IntDrawShape(ILRenderProperties props) {
if (m_vertCount == 0 || m_vertCount >= VerticesPerShape) {
m_renderer.Draw(props, this);
}
}
protected override void IntDrawLabel(ILRenderProperties props) {
if (m_vertCount == 0 || m_vertCount >= VerticesPerShape) {
if (!String.IsNullOrEmpty(m_label.Text) && m_vertCount > 1) {
ILPoint3Df cent = m_vertices[0].Position + m_vertices[1].Position;
m_label.Draw(props, cent / 2);
}
}
}
#endregion
#region public interface
public void Queue(IILVertexDefinition vertex) {
SetVertex(m_oldestVertexID++, vertex);
if (m_oldestVertexID >= m_vertCount) {
m_oldestVertexID = 0;
}
if (m_updateCount++ < m_autoLimitsUpdateCount) {
bool signal = false;
m_positionMax = ILPoint3Df.Max(m_positionMax, vertex.Position, ref signal);
m_positionMin = ILPoint3Df.Min(m_positionMin, vertex.Position, ref signal);
if (signal) {
OnSizeChanged();
}
} else {
m_updateCount = 0;
Invalidate();
}
}
#endregion
}
}