ArcObjects Library Reference  

EnumCollapsedElts

About the Implementing extended criteria for some predefined schematic rules Sample

[C#]

EnumCollapsedElts.cs

namespace CustomExtCriteriaCS
{
	public class EnumCollapsedElts : ESRI.ArcGIS.Schematic.IEnumSchematicInMemoryFeature
	{
		private System.Collections.Generic.List<ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature> m_listElements;
		private int m_maxElements;
		private int m_currentIndex;

		public EnumCollapsedElts()
		{
			m_listElements = new System.Collections.Generic.List<ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature>();
			m_maxElements = 100; // Default
		}

		~EnumCollapsedElts()
		{
			m_listElements = null;
		}

		public int MaxElements
		{
			get
			{
				return m_maxElements;
			}
			set
			{
				m_maxElements = value;
			}
		}

		public void Initialize(ref ESRI.ArcGIS.Schematic.IEnumSchematicInMemoryFeature relatedElements)
		{
			m_currentIndex = 0;
			m_listElements = new System.Collections.Generic.List<ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature>();

			relatedElements.Reset();
			ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature schemElement = relatedElements.Next();

			// add all Schematic feature to the list
			while ((schemElement != null) && (m_listElements.Count < m_maxElements))
			{
				m_listElements.Add(schemElement);
				schemElement = relatedElements.Next();
			}
		}

		#region IEnumSchematicElement Implementations
		public int Count
		{
			get
			{
				return m_listElements.Count;
			}
		}

		public ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature Next()
		{
			if (m_currentIndex < (m_listElements.Count - 1))
			{
				// return the element at m_currentIndex, then increment it
				return m_listElements[m_currentIndex++];
			}
			else
			{
				return null;
			}
		}

		public void Reset()
		{
			m_currentIndex = 0;
		}
		#endregion

		public void Add(ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature value)
		{
			if (m_listElements == null)
			{
				m_listElements = new System.Collections.Generic.List<ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature>();
			}

			if (m_listElements.Count < m_maxElements)
			{
				m_listElements.Add(value);
			}
		}
	}
}

[Visual Basic .NET]

EnumCollapsedElts.vb

Option Strict Off
Option Explicit On

Public Class EnumCollapsedElts
	Implements ESRI.ArcGIS.Schematic.IEnumSchematicInMemoryFeature

	Private m_listElements As Generic.List(Of ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature)
	Private m_maxElements As Integer
	Private m_currentIndex As Integer

	Public Sub New()
		m_listElements = New Generic.List(Of ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature)
		m_maxElements = 100	' Default
	End Sub

	Protected Overrides Sub Finalize()
		m_listElements = Nothing
		MyBase.Finalize()
	End Sub

	Public Property MaxElements() As Integer
		Get
			Return m_maxElements
		End Get

		Set(ByVal value As Integer)
			m_maxElements = value
		End Set
	End Property

	Public Sub Initialize(ByRef relatedElements As ESRI.ArcGIS.Schematic.IEnumSchematicInMemoryFeature)
		On Error Resume Next

		m_currentIndex = 0
		m_listElements = New Generic.List(Of ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature)

		relatedElements.Reset()
		Dim schemElement As ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature = relatedElements.Next

		' add all Schematic feature to the list
		While (schemElement IsNot Nothing AndAlso m_listElements.Count < m_maxElements)
			m_listElements.Add(schemElement)
			schemElement = relatedElements.Next
		End While
	End Sub

#Region "IEnumSchematicElement Implementations"
	Private ReadOnly Property Count() As Integer _
	Implements ESRI.ArcGIS.Schematic.IEnumSchematicInMemoryFeature.Count

		Get
			Return m_listElements.Count
		End Get
	End Property

	Private Function [Next]() As ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature _
 Implements ESRI.ArcGIS.Schematic.IEnumSchematicInMemoryFeature.Next

		If m_currentIndex < m_listElements.Count - 1 Then
			m_currentIndex = m_currentIndex + 1
			Return m_listElements(m_currentIndex - 1)
		Else
			Return Nothing
		End If
	End Function

	Private Sub Reset() _
	Implements ESRI.ArcGIS.Schematic.IEnumSchematicInMemoryFeature.Reset

		m_currentIndex = 0
	End Sub
#End Region

	Public Sub Add(ByVal value As ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature)
		If m_listElements Is Nothing Then
			m_listElements = New Generic.List(Of ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature)
		End If
		If m_listElements.Count < m_maxElements Then
			m_listElements.Add(value)
		End If
	End Sub


End Class