#region Copyright /* * Copyright (c) 2005,2006,2007, OpenMI Association * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the OpenMI Association nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY "OpenMI Association" ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL "OpenMI Association" BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #endregion using System; using System.Collections; namespace RTCTools.OpenMI.Sdk.Backbone { /// /// The Element class contains a spatial element. /// This is a trivial implementation for use with RTCTools.OpenMI.Sdk.Backbone.ElementSet, refer there for further details. /// [Serializable] public class Element { private ArrayList _vertices = new ArrayList(); private ArrayList _faces = new ArrayList(); private string _id=""; /// /// Constructor /// public Element() { } /// /// Copy constructor /// /// The element to copy public Element(Element source) { ID = source.ID; Vertices = source.Vertices; } /// /// Setter and getter functions for the vertex list /// public virtual Vertex[] Vertices { get { Vertex[] vertices = new Vertex[_vertices.Count]; for (int i=0;i<_vertices.Count;i++) { vertices[i] = (Vertex) _vertices[i]; } return vertices; } set { _vertices.Clear(); for (int i=0;i /// Constructor function /// /// The Element ID public Element(string ID) { _id = ID; } /// /// Returns the vertex count /// public virtual int VertexCount { get { return _vertices.Count; } } /// /// Getter and setter functions for the element ID /// public string ID { get { return _id; } set { _id = value; } } /// /// Gets a vertex /// /// The vertex index /// The vertex public virtual Vertex GetVertex(int Index) { return (Vertex) _vertices[Index]; } /// /// Adds a vertex /// /// The vertex to add public virtual void AddVertex(Vertex vertex) { _vertices.Add(vertex); } /// /// Returns the number of faces /// public int FaceCount { get {return _faces.Count;} } /// /// Adds a face /// /// The vertex indices for the face public void AddFace(int[] vertexIndices) { _faces.Add(vertexIndices); } /// /// Returns the face vertex indices for a face /// /// The face index /// The face vertex indices public int[] GetFaceVertexIndices(int faceIndex) { return ((int[]) _faces[faceIndex]); } /// /// Check if the current instance equals another instance of this class. /// ///The instance to compare the current instance with. ///true if the instances are the same instance or have the same content. public override bool Equals(Object obj) { if (obj == null || GetType() != obj.GetType()) return false; Element e = (Element) obj; if (!ID.Equals(e.ID)) return false; if (VertexCount!=e.VertexCount) return false; for (int i=0;i /// Get Hash Code. /// ///Hash Code for the current instance. public override int GetHashCode() { int hashCode = base.GetHashCode(); if (_id != null) hashCode += _id.GetHashCode(); if (_vertices != null) hashCode += _vertices.GetHashCode(); return hashCode; } /// /// String representation of the element /// /// public override string ToString() { if (_id != null) { return _id; } else { return "georef'd element"; } } } }