ArcObjects Library Reference  

ReductionLinkPropertyPage

About the Implementing a schematic rule and its property page Sample

[C#]

ReductionLinkPropertyPage.cs

using ESRI.ArcGIS;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.CATIDs;
using Schematic = ESRI.ArcGIS.Schematic;
using ESRI.ArcGIS.Framework;
using System.Windows.Forms;
using ESRI.ArcGIS.esriSystem;
using System;
using System.Collections.Generic;
using System.Text;


namespace CustomRulesCS
{
	[ClassInterface(ClassInterfaceType.None)]
	[Guid(ReductionLinkPropertyPage.GUID)]
	[ProgId(ReductionLinkPropertyPage.PROGID)]
	public class ReductionLinkPropertyPage : IComPropertyPage
	{
		// Register/unregister categories for this class
		#region "Component Category Registration"
		[System.Runtime.InteropServices.ComRegisterFunction()]
		public static void Register(string CLSID)
		{
			SchematicRulePropertyPages.Register(CLSID);
		}

		[System.Runtime.InteropServices.ComUnregisterFunction()]
		public static void Unregister(string CLSID)
		{
			SchematicRulePropertyPages.Unregister(CLSID);
		}
		#endregion

		public const string GUID = "9D1CD5C2-AF73-4a70-B1DD-8B092601CFE8";
		public const string PROGID = "CustomRulesCS.ReductionLinkPropertyPage";

		private frmReductionLink m_form = new frmReductionLink();   // the custom form
		private ReductionLinkRule m_mySchematicRule;                 // the custom rule
		private string m_title = "Reduction Links Rule C#";         // the form title
		private int m_priority = 0;                                   // the IComPage priority

		#region IComPropertyPage Membres

		public int Activate()
		{
			// Create a new RemoveElementForm but do not show it 
			if (m_form == null) m_form = new frmReductionLink();
			return (int)m_form.Handle;
		}

		public bool Applies(ISet objects)
		{
			Schematic.ISchematicRule mySchematicRule;
			mySchematicRule = FindMyRule(objects);
			return (mySchematicRule != null);
		}

		public void Apply()
		{
			try
			{
				m_mySchematicRule.Description = m_form.txtDescription.Text;
				m_mySchematicRule.ReductionLinkName = m_form.cboReduce.SelectedItem.ToString();
				m_mySchematicRule.UsePort = m_form.chkUsePort.Checked;
				m_form.IsDirty = false;
			}
			catch (System.Exception ex)
			{
				MessageBox.Show(ex.Message, "Unable to initialize rule properties", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}

		public void Cancel()
		{
			m_form.IsDirty = false;
		}

		public void Deactivate()
		{
			m_form.Close();
		}

		public int Height
		{
			get { return m_form.Height; }
		}

		public int get_HelpContextID(int controlID)
		{
			// TODO: return context ID if desired
			return 0;
		}

		public string HelpFile
		{
			get { return ""; }
		}

		public void Hide()
		{
			m_form.Hide();
		}

		public bool IsPageDirty
		{
			get { return m_form.IsDirty; }
		}

		public IComPropertyPageSite PageSite
		{
			set { m_form.PageSite = value; }
		}

		public int Priority
		{
			get
			{
				return m_priority;
			}
			set
			{
				m_priority = value;
			}
		}

		public void SetObjects(ISet objects)
		{
			// Search for the custom rule object instance
			m_mySchematicRule = FindMyRule(objects);
		}

		public void Show()
		{
			try
			{
				if (m_form.cboReduce.Items.Count == 0)
				{
					Schematic.ISchematicDiagramClass diagramClass;
					diagramClass = ((Schematic.ISchematicRule)m_mySchematicRule).SchematicDiagramClass;
					if (diagramClass == null) return;

					Schematic.ISchematicElementClass elementClass;
					Schematic.IEnumSchematicElementClass enumElementClass;
					enumElementClass = diagramClass.AssociatedSchematicElementClasses;
					enumElementClass.Reset();
					elementClass = enumElementClass.Next();
					while (elementClass != null)
					{
						if (elementClass.SchematicElementType == Schematic.esriSchematicElementType.esriSchematicLinkType)
							m_form.cboReduce.Items.Add(elementClass.Name);

						elementClass = enumElementClass.Next();
					}
				}

				m_form.cboReduce.Text = m_mySchematicRule.ReductionLinkName;
				m_form.txtDescription.Text = m_mySchematicRule.Description;
				m_form.chkUsePort.Checked = m_mySchematicRule.UsePort;
				m_form.IsDirty = false;

				m_form.Visible = true;
				m_form.lblDescription.Visible = true;
				m_form.lblReduce.Visible = true;
				m_form.txtDescription.Visible = true;
				m_form.cboReduce.Visible = true;
				m_form.chkUsePort.Visible = true;
			}
			catch (System.Exception ex)
			{
				MessageBox.Show(ex.Message, "Unable to initialize property page", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}

		public string Title
		{
			get
			{
				return m_title;
			}
			set
			{
				m_title = value;
			}
		}

		public int Width
		{
			get { return m_form.Width; }
		}

		#endregion

		~ReductionLinkPropertyPage()
		{
			m_form = null;
			m_mySchematicRule = null;
		}

		// Find and return this rule from the passed in objects 
		private ReductionLinkRule FindMyRule(ESRI.ArcGIS.esriSystem.ISet Objectset)
		{
			if (Objectset.Count == 0)
				return null;

			Objectset.Reset();

			object obj;
			obj = Objectset.Next();

			while (obj != null)
			{
				if (obj is ReductionLinkRule)
				{
					break;
				}

				obj = Objectset.Next();
			}

			return (ReductionLinkRule)obj;
		}

	}
}

[Visual Basic .NET]

ReductionLinkPropertyPage.vb

Imports ESRI.ArcGIS
Imports System.Runtime.InteropServices
Imports ESRI.ArcGIS.ADF.CATIDs
Imports Schematic = ESRI.ArcGIS.Schematic
Imports ESRI.ArcGIS.Framework
Imports System.Windows.Forms
Imports ESRI.ArcGIS.esriSystem
Imports System
Imports System.Collections.Generic
Imports System.Text

<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)> _
<System.Runtime.InteropServices.Guid(ReductionLinkPropertyPage.GUID)> _
<System.Runtime.InteropServices.ProgId(ReductionLinkPropertyPage.PROGID)> _
Public Class ReductionLinkPropertyPage
	Implements ESRI.ArcGIS.Framework.IComPropertyPage

	Public Const GUID As String = "4E3C6551-8594-4c51-9B8B-075E745CC622"
	Public Const PROGID As String = "CustomRulesVB.ReductionLinkPropertyPage"

	' Register/unregister categories for this class
#Region "Component Category Registration"
	<System.Runtime.InteropServices.ComRegisterFunction()> _
	Shared Sub Register(ByVal CLSID As String)
		SchematicRulePropertyPages.Register(CLSID)
	End Sub

	<System.Runtime.InteropServices.ComUnregisterFunction()> _
	Shared Sub Unregister(ByVal CLSID As String)
		SchematicRulePropertyPages.Unregister(CLSID)
	End Sub
#End Region

	Private m_Form As frmReductionLink = New frmReductionLink()		' the custom form
	Private m_mySchematicRule As ReductionLinkRule								' the custom rule
	Private m_title As String = "Reduction Links Rule VBNet"						' the form title
	Private m_priority As Integer = 0																		' the IComPage priority


#Region "IComPropertyPage Members"
	Public Function Activate() As Integer Implements ESRI.ArcGIS.Framework.IComPropertyPage.Activate
		' Create a new RemoveElementForm but do not show it 
		If m_Form Is Nothing Then m_Form = New frmReductionLink()
		Return m_Form.Handle.ToInt32
	End Function

	Public Function Applies(ByVal objects As ESRI.ArcGIS.esriSystem.ISet) As Boolean Implements ESRI.ArcGIS.Framework.IComPropertyPage.Applies
		Dim mySchematicRule As Schematic.ISchematicRule
		mySchematicRule = FindMyRule(objects)
		Return (mySchematicRule IsNot Nothing)
	End Function

	Public Sub Apply() Implements ESRI.ArcGIS.Framework.IComPropertyPage.Apply
		Try
			m_mySchematicRule.Description = m_Form.txtDescription.Text
			m_mySchematicRule.ReductionLinkName = m_Form.cboReduce.SelectedItem.ToString()
			m_mySchematicRule.UsePort = m_Form.chkUsePort.Checked
			m_Form.IsDirty = True
		Catch ex As Exception
			MessageBox.Show(ex.Message, "Unable to initialize rule properties", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
		End Try
	End Sub

	Public Sub Cancel() Implements ESRI.ArcGIS.Framework.IComPropertyPage.Cancel
		m_Form.IsDirty = False
	End Sub

	Public Sub Deactivate() Implements ESRI.ArcGIS.Framework.IComPropertyPage.Deactivate
		m_Form.Close()
	End Sub

	Public ReadOnly Property Height() As Integer Implements ESRI.ArcGIS.Framework.IComPropertyPage.Height
		Get
			Return m_Form.Height
		End Get
	End Property

	Public ReadOnly Property HelpContextID(ByVal controlID As Integer) As Integer Implements ESRI.ArcGIS.Framework.IComPropertyPage.HelpContextID
		Get
			' TODO: return context ID if desired
			Return 0
		End Get
	End Property

	Public ReadOnly Property HelpFile() As String Implements ESRI.ArcGIS.Framework.IComPropertyPage.HelpFile
		Get
			Return ""
		End Get
	End Property

	Public Sub Hide() Implements ESRI.ArcGIS.Framework.IComPropertyPage.Hide
		m_Form.Hide()
	End Sub

	Public ReadOnly Property IsPageDirty() As Boolean Implements ESRI.ArcGIS.Framework.IComPropertyPage.IsPageDirty
		Get
			Return m_Form.IsDirty
		End Get
	End Property

	Public WriteOnly Property PageSite() As ESRI.ArcGIS.Framework.IComPropertyPageSite Implements ESRI.ArcGIS.Framework.IComPropertyPage.PageSite
		Set(ByVal value As ESRI.ArcGIS.Framework.IComPropertyPageSite)
			m_Form.PageSite = value
		End Set
	End Property

	Public Property Priority() As Integer Implements ESRI.ArcGIS.Framework.IComPropertyPage.Priority
		Get
			Return m_priority
		End Get
		Set(ByVal value As Integer)
			m_priority = value
		End Set
	End Property

	Public Sub SetObjects(ByVal objects As ESRI.ArcGIS.esriSystem.ISet) Implements ESRI.ArcGIS.Framework.IComPropertyPage.SetObjects
		' Search for the custom rule object instance
		m_mySchematicRule = FindMyRule(objects)
	End Sub

	Public Sub Show() Implements ESRI.ArcGIS.Framework.IComPropertyPage.Show
		Try
			If (m_Form.cboReduce.Items.Count = 0) Then
				Dim diagramClass As Schematic.ISchematicDiagramClass
				diagramClass = m_mySchematicRule.SchematicDiagramClass
				If (diagramClass Is Nothing) Then Return

				Dim elementClass As Schematic.ISchematicElementClass
				Dim enumElementClass As Schematic.IEnumSchematicElementClass
				enumElementClass = diagramClass.AssociatedSchematicElementClasses
				enumElementClass.Reset()
				elementClass = enumElementClass.Next()
				While (elementClass IsNot Nothing)
					If (elementClass.SchematicElementType = Schematic.esriSchematicElementType.esriSchematicLinkType) Then
						m_Form.cboReduce.Items.Add(elementClass.Name)
					End If

					elementClass = enumElementClass.Next()
				End While
			End If

			m_Form.cboReduce.Text = m_mySchematicRule.ReductionLinkName
			m_Form.txtDescription.Text = m_mySchematicRule.Description
			m_Form.chkUsePort.Checked = m_mySchematicRule.UsePort
			m_Form.IsDirty = False

			m_Form.Visible = True
			m_Form.lblDescription.Visible = True
			m_Form.lblReduce.Visible = True
			m_Form.txtDescription.Visible = True
			m_Form.cboReduce.Visible = True
			m_Form.chkUsePort.Visible = True
		Catch ex As Exception
			MessageBox.Show(ex.Message, "Unable to initialize property page", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
		End Try
	End Sub

	Public Property Title() As String Implements ESRI.ArcGIS.Framework.IComPropertyPage.Title
		Get
			Return m_title
		End Get
		Set(ByVal value As String)
			m_title = value
		End Set
	End Property

	Public ReadOnly Property Width() As Integer Implements ESRI.ArcGIS.Framework.IComPropertyPage.Width
		Get
			Return m_Form.Width
		End Get
	End Property
#End Region

	Protected Overrides Sub Finalize()
		m_Form = Nothing
		m_mySchematicRule = Nothing
		MyBase.Finalize()
	End Sub

	' Find and return this rule from the passed in objects 
	Private Function FindMyRule(ByVal Objectset As ESRI.ArcGIS.esriSystem.ISet) As ReductionLinkRule
		If (Objectset.Count = 0) Then Return Nothing

		Objectset.Reset()

		Dim obj As Object
		obj = Objectset.Next()

		While (obj IsNot Nothing)
			If (TypeOf (obj) Is ReductionLinkRule) Then Exit While

			obj = Objectset.Next()
		End While

		Return CType(obj, ReductionLinkRule)
	End Function
End Class