ArcObjects Library Reference  

NodeReductionRulePropertyPage

About the Reducing schematic nodes and computing a cumulative attribute via a schematic rule Sample

[C#]

NodeReductionRulePropertyPage.cs

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



namespace CustomRulesPageCS
{
    [ClassInterface(ClassInterfaceType.None)]
    [Guid(NodeReductionRulePropertyPage.GUID)]
    [ProgId(NodeReductionRulePropertyPage.PROGID)]
    public class NodeReductionRulePropertyPage : 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 = "F58F5916-3A99-49CF-9A7D-5EB97E7618FD";
        public const string PROGID = "CustomRulesPageCS.NodeReductionRulePropertyPage";

        private FrmNodeReductionRule m_form = new FrmNodeReductionRule();     // the custom form
        private NodeReductionRule m_myNodeReductionRule;                                        // the custom rule
        private string m_title = "Node Reduction Rule C#";                                    // the form title
        private int m_priority = 0;                                                                                 // the IComPage priority

        #region IComPropertyPage Membres

        public int Activate()
        {
            if (m_form == null) m_form = new FrmNodeReductionRule();
            return (int)m_form.Handle;
        }

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

        public void Apply()
        {
            try
            {
                m_myNodeReductionRule.Description = m_form.TxtDescription.Text;
            }
            catch { }

            try
            {
                m_myNodeReductionRule.ReducedNodeClassName = m_form.cmbReducedNodeClass.SelectedItem.ToString();
            }
            catch { }

            try
            {
                m_myNodeReductionRule.SuperpanLinkClassName = m_form.cmbTargetSuperspanClass.SelectedItem.ToString();
            }
            catch { }

            try
            {
                m_myNodeReductionRule.KeepVertices = m_form.chkKeepVertices.Checked;
            }
            catch { }

            try
            {
                m_myNodeReductionRule.LengthAttributeName = m_form.cmbAttributeName.SelectedItem.ToString();
            }
            catch { }

            try
            {
                m_myNodeReductionRule.LinkAttribute = m_form.chkLinkAttribute.Checked;
            }
            catch { }

            try
            {
                m_myNodeReductionRule.LinkAttributeName = m_form.txtLinkAttribute.Text;
            }
            catch { }

            m_form.IsDirty = false;
        }

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

        public void Deactivate()
        {
            m_form.DiagramClass = null;
            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_myNodeReductionRule = FindMyRule(objects);
        }


        public void Show()
        {
            Schematic.ISchematicDiagramClass diagramClass;
            diagramClass = ((Schematic.ISchematicRule)m_myNodeReductionRule).SchematicDiagramClass;
            if (diagramClass == null) return;

            m_form.DiagramClass = diagramClass;
            Schematic.ISchematicElementClass elementClass;

            Schematic.IEnumSchematicElementClass enumElementClass;
            enumElementClass = diagramClass.AssociatedSchematicElementClasses;

            m_form.cmbReducedNodeClass.Items.Clear();
            m_form.cmbTargetSuperspanClass.Items.Clear();
            m_form.cmbAttributeName.Items.Clear();

            try
            {
                enumElementClass.Reset();
                elementClass = enumElementClass.Next();
                while (elementClass != null)
                {
                    if (elementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType)
                        m_form.cmbReducedNodeClass.Items.Add(elementClass.Name);
                    else if (elementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicLinkType)
                    {
                        m_form.cmbTargetSuperspanClass.Items.Add(elementClass.Name);
                    }

                    elementClass = enumElementClass.Next();
                }

                m_form.cmbAttributeName.Text = m_myNodeReductionRule.LengthAttributeName;
                m_form.TxtDescription.Text = m_myNodeReductionRule.Description;
                m_form.cmbReducedNodeClass.Text = m_myNodeReductionRule.ReducedNodeClassName;
                m_form.cmbTargetSuperspanClass.Text = m_myNodeReductionRule.SuperpanLinkClassName;
                m_form.chkKeepVertices.Checked = m_myNodeReductionRule.KeepVertices;
                m_form.chkLinkAttribute.Checked = m_myNodeReductionRule.LinkAttribute;
                m_form.txtLinkAttribute.Text = m_myNodeReductionRule.LinkAttributeName;
                m_form.IsDirty = false;

                SetVisibleControls();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Unable to initialize property page", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void SetVisibleControls()
        {
            m_form.Visible = true;
            m_form.lblDescription.Visible = true;
            m_form.lblGroup.Visible = true;
            m_form.lblReducedNode.Visible = true;
            m_form.lblTargetSuperspan.Visible = true;
            m_form.lblAttributeName.Visible = true;
            m_form.cmbReducedNodeClass.Visible = true;
            m_form.cmbTargetSuperspanClass.Visible = true;
            m_form.chkKeepVertices.Visible = true;
            m_form.chkLinkAttribute.Visible = true;
            m_form.txtLinkAttribute.Visible = true;
        }

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

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

        #endregion

        ~NodeReductionRulePropertyPage()
        {
            m_form.DiagramClass = null;
            m_form = null;
            m_myNodeReductionRule = null;
        }

        // Find and return this rule from the passed in objects 
        private NodeReductionRule 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 CustomRulesCS.NodeReductionRule)
                {
                    break;
                }

                obj = Objectset.Next();
            }

            return (NodeReductionRule)obj;
        }
    }
}

[Visual Basic .NET]

NodeReductionRulePropertyPage.vb

Option Strict On

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



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

    Public Const GUID As String = "4B018649-6916-4713-A2C0-F5D2E81A86DE"
    Public Const PROGID As String = "CustomRulesPageVB.NodeReductionRulePropertyPage"

    ' 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 FrmNodeReductionRule = New FrmNodeReductionRule()        ' the custom form
    Private m_myNodeReductionRule As NodeReductionRule                                 ' the custom rule
    Private m_title As String = "Node Reduction 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 FrmNodeReductionRule()
        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_myNodeReductionRule.Description = m_Form.TxtDescription.Text
        Catch
        End Try

        Try
            m_myNodeReductionRule.LengthAttributeName = m_Form.cmbAttributeName.SelectedItem.ToString()
        Catch
        End Try

        Try
            m_myNodeReductionRule.ReducedNodeClassName = m_Form.cmbReducedNodeClass.SelectedItem.ToString()
        Catch
        End Try

        Try
            m_myNodeReductionRule.SuperpanLinkClassName = m_Form.cmbTargetSuperspanClass.SelectedItem.ToString()
        Catch
        End Try

        Try
            m_myNodeReductionRule.KeepVertices = m_Form.chkKeepVertices.Checked
        Catch
        End Try

        Try
            m_myNodeReductionRule.LinkAttribute = m_Form.chkLinkAttribute.Checked
        Catch
        End Try

        Try
            m_myNodeReductionRule.LinkAttributeName = m_Form.txtLinkAttribute.Text
        Catch
        End Try

        m_Form.IsDirty = True
    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.DiagramClass = Nothing
        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_myNodeReductionRule = FindMyRule(objects)
    End Sub

    Public Sub Show() Implements ESRI.ArcGIS.Framework.IComPropertyPage.Show

        Dim diagramClass As Schematic.ISchematicDiagramClass
        diagramClass = CType(m_myNodeReductionRule, Schematic.ISchematicRule).SchematicDiagramClass
        If (diagramClass Is Nothing) Then Return

        m_Form.DiagramClass = diagramClass
        Dim elementClass As Schematic.ISchematicElementClass
        Dim enumElementClass As Schematic.IEnumSchematicElementClass
        enumElementClass = diagramClass.AssociatedSchematicElementClasses

        m_Form.cmbReducedNodeClass.Items.Clear()
        m_Form.cmbTargetSuperspanClass.Items.Clear()
        m_Form.cmbAttributeName.Items.Clear()

        Try

            enumElementClass.Reset()
            elementClass = enumElementClass.Next()

            While (elementClass IsNot Nothing)

                If (elementClass.SchematicElementType = ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType) Then
                    m_Form.cmbReducedNodeClass.Items.Add(elementClass.Name)
                ElseIf (elementClass.SchematicElementType = ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicLinkType) Then
                    m_Form.cmbTargetSuperspanClass.Items.Add(elementClass.Name)
                End If

                elementClass = enumElementClass.Next()
            End While

            m_Form.cmbAttributeName.Text = m_myNodeReductionRule.LengthAttributeName
            m_Form.TxtDescription.Text = m_myNodeReductionRule.Description
            m_Form.cmbReducedNodeClass.Text = m_myNodeReductionRule.ReducedNodeClassName
            m_Form.cmbTargetSuperspanClass.Text = m_myNodeReductionRule.SuperpanLinkClassName
            m_Form.chkKeepVertices.Checked = m_myNodeReductionRule.KeepVertices
            m_Form.chkLinkAttribute.Checked = m_myNodeReductionRule.LinkAttribute
            m_Form.txtLinkAttribute.Text = m_myNodeReductionRule.LinkAttributeName
            m_Form.IsDirty = False

            SetVisibleControls()

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Unable to initialize property page", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub

    Private Sub SetVisibleControls()
        m_Form.Visible = True
        m_Form.lblDescription.Visible = True
        m_Form.lblGroup.Visible = True
        m_Form.lblReducedNode.Visible = True
        m_Form.lblTargetSuperspan.Visible = True
        m_Form.lblAttributeName.Visible = True
        m_Form.cmbReducedNodeClass.Visible = True
        m_Form.cmbTargetSuperspanClass.Visible = True
        m_Form.chkKeepVertices.Visible = True
        m_Form.txtLinkAttribute.Visible = True
        m_Form.chkLinkAttribute.Visible = True

    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.DiagramClass = Nothing
        m_Form = Nothing
        m_myNodeReductionRule = 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 NodeReductionRule
        If (Objectset.Count = 0) Then Return Nothing

        Objectset.Reset()

        Dim obj As Object
        obj = Objectset.Next()

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

            obj = Objectset.Next()
        End While

        Return CType(obj, NodeReductionRule)
    End Function
End Class