About the Implementing extended criteria for some predefined schematic rules Sample
[C#]
PlantWithoutEquipment.cs
namespace CustomExtCriteriaCS { [System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)] [System.Runtime.InteropServices.Guid(PlantWithoutEquipment.GUID)] [System.Runtime.InteropServices.ProgId(PlantWithoutEquipment.PROGID)] public class PlantWithoutEquipment : ESRI.ArcGIS.Schematic.ISchematicNodeReductionExtended { public const string GUID = "08CABF7A-1CC8-4cc2-A950-67485A56F7BA"; public const string PROGID = "CustomExtCriteriaCS.PlantWithoutEquipment"; #region Component Category Registration [System.Runtime.InteropServices.ComRegisterFunction()] public static void Register(string regKey) { ESRI.ArcGIS.ADF.CATIDs.SchematicRulesExtendedCriteria.Register(regKey); } [System.Runtime.InteropServices.ComUnregisterFunction()] public static void Unregister(string regKey) { ESRI.ArcGIS.ADF.CATIDs.SchematicRulesExtendedCriteria.Unregister(regKey); } #endregion #region ISchematicNodeReductionExtended Implementations // Implementation of a new ISchematicNodeReductionExtended interface // to be used as an additional criteria during the execution of a // Node Reduction By Priority rule // Description of the new schematic node reduction criteria public string Name { get { return "Reduce plant without equipments (C#)"; } } //The SelectReduction procedure works with the input node schematic node candidate to the //reduction and with the input linkElements list of schematic link elements incident to //this schematic node. It must return True for the output reduce boolean parameter if //the node is reduced, false if the node is kept. When the output ppLink schematic link //is not nothing, it determines the target node that will be used to reconnect the links //incidents to the reduced node. In this sample procedure, the node candidate to the //reduction is analyzed. If records related to this node exist in the plants_equipments table, //the node is kept (output reduce parameter is False); else, it is reduced (output reduce //parameter is True). public bool SelectReduction(ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode node, ESRI.ArcGIS.Schematic.IEnumSchematicInMemoryFeature enumLink, ref ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureLink link) { // if associated feature doesn't exist do nothing ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature schemAssociatedNode; schemAssociatedNode = node as ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature; if (schemAssociatedNode == null) return false; ESRI.ArcGIS.Geodatabase.IFeature plantsFeature; plantsFeature = schemAssociatedNode.SchematicElement as ESRI.ArcGIS.Geodatabase.IFeature; if (plantsFeature == null) return false; // if dataset is not plants do nothing ESRI.ArcGIS.Geodatabase.IDataset plantsDataset; plantsDataset = (ESRI.ArcGIS.Geodatabase.IDataset)plantsFeature.Class; if (plantsDataset.Name.IndexOf("plants") == 0) return false; // get workspace ESRI.ArcGIS.Geodatabase.IFeatureWorkspace plantsWorkspace; plantsWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)plantsDataset.Workspace; // open table plants_equipments ESRI.ArcGIS.Geodatabase.ITable plantsEquipment; plantsEquipment = plantsWorkspace.OpenTable("plants_equipments"); if (plantsEquipment == null) return false; // filter for the selected feature ESRI.ArcGIS.Geodatabase.IQueryFilter plantsFilter; plantsFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); plantsFilter.WhereClause = ("PlantID = " + plantsFeature.OID); ESRI.ArcGIS.Geodatabase.ICursor plantsCursor; plantsCursor = plantsEquipment.Search(plantsFilter, true); // if found equipment return false if (plantsCursor != null && plantsCursor.NextRow() != null) return false; return true; // if this far } #endregion } }
[Visual Basic .NET]
PlantWithoutEquipment.vb
Option Strict Off Option Explicit On <System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)> _ <System.Runtime.InteropServices.Guid(PlantWithoutEquipment.GUID)> _ <System.Runtime.InteropServices.ProgId(PlantWithoutEquipment.PROGID)> _ Public Class PlantWithoutEquipment Implements ESRI.ArcGIS.Schematic.ISchematicNodeReductionExtended Public Const GUID As String = "6C12F9A4-3265-4a9e-9CB6-7FBA618154F1" Public Const PROGID As String = "CustomExtCriteriaVB.PlantWithoutEquipment" ' Register/unregister categories for this class #Region "Component Category Registration" <System.Runtime.InteropServices.ComRegisterFunction()> _ Public Shared Sub Register(ByVal regKey As String) ESRI.ArcGIS.ADF.CATIDs.SchematicRulesExtendedCriteria.Register(regKey) End Sub <System.Runtime.InteropServices.ComUnregisterFunction()> _ Public Shared Sub Unregister(ByVal regKey As String) ESRI.ArcGIS.ADF.CATIDs.SchematicRulesExtendedCriteria.Unregister(regKey) End Sub #End Region #Region "ISchematicNodeReductionExtended Implementations" ' Implementation of a new ISchematicNodeReductionExtended interface ' to be used as an additional criteria during the execution of a ' Node Reduction By Priority rule ' Description of the new schematic node reduction criteria Private ReadOnly Property Name() As String _ Implements ESRI.ArcGIS.Schematic.ISchematicNodeReductionExtended.Name Get Return "Reduce plant without equipments (VBNet)" End Get End Property 'The SelectReduction procedure works with the input node schematic node candidate to the 'reduction and with the input linkElements list of schematic link elements incident to 'this schematic node. It must return True for the output reduce boolean parameter if 'the node is reduced, false if the node is kept. When the output ppLink schematic link 'is not nothing, it determines the target node that will be used to reconnect the links 'incidents to the reduced node. In this sample procedure, the node candidate to the 'reduction is analyzed. If records related to this node exist in the plants_equipments table, 'the node is kept (output reduce parameter is False); else, it is reduced (output reduce 'parameter is True). Public Function SelectReduction( _ ByVal node As ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode, _ ByVal enumLink As ESRI.ArcGIS.Schematic.IEnumSchematicInMemoryFeature, _ ByRef link As ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureLink) As Boolean _ Implements ESRI.ArcGIS.Schematic.ISchematicNodeReductionExtended.SelectReduction ' if associated feature doesn't exist do nothing Dim schemAssociatedNode As ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature schemAssociatedNode = CType(node, ESRI.ArcGIS.Schematic.ISchematicInMemoryFeature) If (schemAssociatedNode Is Nothing) Then Return False Dim plantsFeature As ESRI.ArcGIS.Geodatabase.IFeature plantsFeature = CType(schemAssociatedNode.SchematicElement, ESRI.ArcGIS.Schematic.ISchematicElementAssociatedObject) If (plantsFeature Is Nothing) Then Return False ' if dataset is not plants do nothing Dim plantsDataset As ESRI.ArcGIS.Geodatabase.IDataset plantsDataset = plantsFeature.Class If (plantsDataset.Name.IndexOf("plants") = 0) Then Return False ' get workspace Dim plantsWorkspace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace plantsWorkspace = plantsDataset.Workspace ' open table plants_equipments Dim plantsEquipment As ESRI.ArcGIS.Geodatabase.ITable plantsEquipment = plantsWorkspace.OpenTable("plants_equipments") If (plantsEquipment Is Nothing) Then Return False ' filter for the selected feature Dim plantsFilter As ESRI.ArcGIS.Geodatabase.IQueryFilter plantsFilter = New ESRI.ArcGIS.Geodatabase.QueryFilterClass plantsFilter.WhereClause = "PlantID = " & plantsFeature.OID Dim plantsCursor As ESRI.ArcGIS.Geodatabase.ICursor plantsCursor = plantsEquipment.Search(plantsFilter, True) ' if found equipment return false If (plantsCursor IsNot Nothing) AndAlso (plantsCursor.NextRow IsNot Nothing) Then Return False Return True ' if this far End Function #End Region End Class