#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;
using OpenMI.Standard;
namespace RTCTools.OpenMI.Sdk.Backbone
{
///
/// The ElementSet class describes a collection of spatial elements.
/// This is a trivial implementation of OpenMI.Standard.IElementSet, refer there for further details.
///
[Serializable]
public class ElementSet:IElementSet
{
private ArrayList _elements = new ArrayList();
private string _description="";
private string _id="";
private ElementType _elementType = new ElementType();
private ISpatialReference _spatialReference = new SpatialReference();
///
/// Constructor
///
public ElementSet()
{
}
///
/// Copy constructor
///
/// The element set to copy
public ElementSet(IElementSet source)
{
_description = source.Description;
_id = source.ID;
_elementType = source.ElementType;
_spatialReference = source.SpatialReference;
for (int i=0;i
/// ElementSet version
///
public virtual int Version
{
get { return 0;}
}
///
/// Constructor
///
/// Description
/// ID
/// Element type
/// Spatial reference
public ElementSet(string Description, string ID,
ElementType ElementType,ISpatialReference SpatialReference)
{
_description = Description;
_id = ID;
_elementType = ElementType;
_spatialReference = SpatialReference;
}
///
/// Adds an element
///
/// The element to add
public virtual void AddElement (Element element)
{
_elements.Add(element);
}
///
/// Gets an element
///
/// The element index
/// The element
public virtual Element GetElement(int ElementIndex)
{
return (Element) _elements[ElementIndex];
}
///
/// Getter and setter functions for the element list
///
public virtual Element[] Elements
{
get
{
Element[] elements = new Element[_elements.Count];
for (int i=0;i<_elements.Count;i++)
{
elements[i] = (Element) _elements[i];
}
return elements;
}
set
{
_elements.Clear();
for (int i=0;i
/// Returns an element ID for an element
///
/// The element index
/// The element ID
public virtual string GetElementID(int ElementIndex)
{
Element element = (Element) _elements[ElementIndex];
return element.ID;
}
///
/// Setter and getter for the element set description
///
public virtual string Description
{
get
{
return _description;
}
set
{
_description = value;
}
}
///
/// Setter and getter for the element set ID
///
public string ID
{
get
{
return _id;
}
set
{
_id = value;
}
}
///
/// Setter and getter for the element type
///
public virtual ElementType ElementType
{
get
{
return _elementType;
}
set
{
_elementType = value;
}
}
///
/// Returns the x coordinate for a vertex
///
/// The element index
/// The vertex index
/// The x coordinate
public virtual double GetXCoordinate(int ElementIndex, int VertexIndex)
{
Element element = (Element) _elements[ElementIndex];
Vertex vertex = element.GetVertex(VertexIndex);
return vertex.x;
}
///
/// Returns the y coordinate for a vertex
///
/// The element index
/// The vertex index
/// The y coordinate
public virtual double GetYCoordinate(int ElementIndex, int VertexIndex)
{
Element element = (Element) _elements[ElementIndex];
Vertex vertex = element.GetVertex(VertexIndex);
return vertex.y;
}
///
/// Returns the z coordinate for a vertex
///
/// The element index
/// The vertex index
/// The z coordinate
public virtual double GetZCoordinate(int ElementIndex, int VertexIndex)
{
Element element = (Element) _elements[ElementIndex];
Vertex vertex = element.GetVertex(VertexIndex);
return vertex.z;
}
///
/// Returns the number of elements
///
public virtual int ElementCount
{
get
{
return _elements.Count;
}
}
///
/// Returns the number of vertices for an element
///
/// The element index
/// The number of vertices for this element
public virtual int GetVertexCount(int ElementIndex)
{
Element element = (Element) _elements[ElementIndex];
return element.VertexCount;
}
///
/// Getter and setter for the spatial reference
///
public virtual ISpatialReference SpatialReference
{
get
{
return _spatialReference;
}
set
{
_spatialReference = value;
}
}
///
/// Returns the element index for a given element ID
///
/// The element ID
/// The element index
public virtual int GetElementIndex(string ElementID)
{
for (int i=0;i<_elements.Count;i++)
{
Element element = (Element) _elements[i];
if (element.ID.Equals(ElementID))
{
return i;
}
}
throw new Exception("Element with ID "+ElementID+ " not found.");
}
///
/// Returns the list of face vertex indices for a given element and face
///
/// The element index
/// The face index
/// List of face vertex indices
public int[] GetFaceVertexIndices(int elementIndex, int faceIndex)
{
return ((Element)_elements[elementIndex]).GetFaceVertexIndices(faceIndex);
}
///
/// Returns the face count for a given element
///
/// The element index
/// The face count for the given element
public int GetFaceCount(int elementIndex)
{
return ((Element)_elements[elementIndex]).FaceCount;
}
///
/// 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;
ElementSet s = (ElementSet)obj;
if (!Description.Equals(s.Description))
return false;
if (!ID.Equals(s.ID))
return false;
if (!SpatialReference.Equals(s.SpatialReference))
return false;
if (!ElementType.Equals(s.ElementType))
return false;
if (ElementCount != s.ElementCount)
return false;
for (int i = 0; i < ElementCount; i++)
if (!GetElement(i).Equals(s.GetElement(i)))
return false;
return true;
}
///
/// Get Hash Code.
///
///Hash Code for the current instance.
public override int GetHashCode()
{
int hashCode = base.GetHashCode();
if (_id != null) hashCode += _id.GetHashCode();
hashCode += _elementType.GetHashCode();
return hashCode;
}
///
/// String representation of the
///
///
public override string ToString()
{
return ID;
}
}
}