///
/// 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 System.Collections.Generic;
using System.Text;
using ILNumerics.Drawing.Graphs;
using ILNumerics.Exceptions;
using ILNumerics.Drawing.Interfaces;
using ILNumerics.Drawing;
namespace ILNumerics.Drawing.Shapes {
///
/// Base class for all simple shapes, rendering a primitive
/// with a border, which is independantly configurable.
///
/// inner vertex element type (struct)
public abstract class ILBorderedShape : ILShape
where VertexType : struct, IILVertexDefinition {
#region eventing
#endregion
#region attributes
protected ILLineProperties m_border;
#endregion
#region properties
///
/// get reference to the properties of the shapes border
///
public ILLineProperties Border {
get {
return m_border;
}
}
#endregion
///
/// create new bordered shape
///
/// panel hosting the scene
/// number of vertices, this bordered shape will be made out of
public ILBorderedShape (ILPanel panel, int numVertices)
: base(panel,numVertices,numVertices) {
m_border = new ILLineProperties();
m_border.Changed += new EventHandler(m_border_Changed);
m_fillColor = Color.Yellow;
m_border.Width = 1;
m_border.Antialiasing = false;
m_border.Color = Color.Bisque;
m_shading = ShadingStyles.Flat;
m_vertexStoresColor = false;
}
///
/// update vertices of the shape
///
/// X positions vector
/// Y positions vector
/// Z positions vector
/// The positions of the vertices are altered only. Other attributes are not altered. X, Y and Z must be
/// vectors, scalars or null.
/// If any of , or is a vector, its elements are transfered to the corresponding position part (X,Y or Z)
/// of the corresponding vertices. If any vector is longer than the current , the number of vertices currently managed by this shape is expanded. If any of
/// the vectors is smaller than , trailing vertices are not touched.
/// If any of , or is a scalar, its value is applied to all corresponding positioning parts of all vertices.
/// If any of , or is null, the corresponding part of the vertices are not altered.
public virtual void Update(ILInArray X = null, ILInArray Y = null, ILInArray Z = null) {
using (ILScope.Enter(X,Y,Z)) {
int minLen = 0;
ILArray x = ILMath.check(X, (a) => { if (a.IsVector) { minLen = a.Length; return a; } else { return null; } }, true, "X must be vector, scalar or null");
ILArray y = ILMath.check(Y, (a) => { if (a.IsVector) { minLen = Math.Max(minLen, a.Length); return a; } else { return null; } }, true, "Y must be vector, scalar or null");
ILArray z = ILMath.check(Z, (a) => { if (a.IsVector) { minLen = Math.Max(minLen, a.Length); return a; } else { return null; } }, true, "Z must be vector, scalar or null");
if (VertexCount < minLen) {
m_numVerticesPerShape = minLen;
Resize(minLen);
}
if (!ILMath.isnull(x)) {
if (x.IsScalar) {
float scalar = x.GetValue(0);
for (int i = 0; i < VertexCount; i++) {
Vertices[i].XPosition = scalar;
}
} else {
for (int i = 0; i < x.Length; i++) {
Vertices[i].XPosition = x.GetValue(i);
}
}
}
if (!ILMath.isnull(y)) {
if (y.IsScalar) {
float scalar = y.GetValue(0);
for (int i = 0; i < VertexCount; i++) {
Vertices[i].YPosition = scalar;
}
} else {
for (int i = 0; i < y.Length; i++) {
Vertices[i].YPosition = y.GetValue(i);
}
}
}
if (!ILMath.isnull(z)) {
if (z.IsScalar) {
float scalar = z.GetValue(0);
for (int i = 0; i < VertexCount; i++) {
Vertices[i].ZPosition = scalar;
}
} else {
for (int i = 0; i < z.Length; i++) {
Vertices[i].ZPosition = z.GetValue(i);
}
}
}
Invalidate();
}
}
void m_border_Changed(object sender, EventArgs e) {
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);
}
}
}
}
}