public void Apply(ISchematicInMemoryDiagram inMemoryDiagram, ESRI.ArcGIS.esriSystem.ITrackCancel cancelTracker) { if (m_reducedNodeClassName == "" || inMemoryDiagram == null) { return; } // initialize the schematic rules helper ISchematicRulesHelper rulesHelper = new SchematicRulesHelperClass(); rulesHelper.InitHelper(inMemoryDiagram); rulesHelper.KeepVertices = m_keepVertices; //////////////////////// // get the feature classes processed by the rule ISchematicDiagramClass diagramClass = null; try { diagramClass = inMemoryDiagram.SchematicDiagramClass; } catch { } if (diagramClass == null) { return; } ISchematicDataset schematicDataset = null; try { schematicDataset = diagramClass.SchematicDataset; } catch { } ISchematicElementClassContainer elementclassContainer = (ISchematicElementClassContainer)schematicDataset; if (elementclassContainer == null) { return; } ISchematicElementClass elementClassReducedNode = null; elementClassReducedNode = elementclassContainer.GetSchematicElementClass(m_reducedNodeClassName); ISchematicElementClass elementClassSuperspan = null; elementClassSuperspan = elementclassContainer.GetSchematicElementClass(m_superspanLinkClassName); if (elementClassSuperspan == null || elementClassReducedNode == null) { return; } ISchematicInMemoryFeatureClassContainer featureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram; if (featureClassContainer == null) { return; } ISchematicInMemoryFeatureClass superspanLinkClass = featureClassContainer.GetSchematicInMemoryFeatureClass(elementClassSuperspan); // ///////////////////////// // fetch the superspan spatial reference IGeoDataset geoDataset = (IGeoDataset)superspanLinkClass; ISpatialReference spatialRef = null; if (geoDataset != null) { spatialRef = geoDataset.SpatialReference; } if (spatialRef == null) { return; } // Retrieve the schematic in memory feature nodes to reduce System.Collections.Generic.Dictionary <string, ISchematicInMemoryFeature> colSchfeatureNode = new Dictionary <string, ISchematicInMemoryFeature>(); // get all feature of parent node class IEnumSchematicInMemoryFeature enumSchematicInMemoryFeature = inMemoryDiagram.GetSchematicInMemoryFeaturesByClass(elementClassReducedNode); // retain only the nodes of degree two RetainNodesDegreeTwo(enumSchematicInMemoryFeature, colSchfeatureNode, rulesHelper); // there would be inserted a SQL query to also filter by attributes IProgressor msgProgressor = null; if (cancelTracker != null) { msgProgressor = cancelTracker.Progressor; IStepProgressor stepProgressor = (IStepProgressor)msgProgressor; if (stepProgressor != null) { stepProgressor.MinRange = 0; stepProgressor.MaxRange = colSchfeatureNode.Count; stepProgressor.StepValue = 1; stepProgressor.Position = 0; stepProgressor.Message = m_description; cancelTracker.Reset(); cancelTracker.Progressor = msgProgressor; stepProgressor.Show(); } } ISchematicInMemoryFeature schFeatureToReduce; foreach (KeyValuePair <string, ISchematicInMemoryFeature> kvp in colSchfeatureNode) { if (cancelTracker != null) { if (cancelTracker.Continue() == false) { break; } } schFeatureToReduce = colSchfeatureNode[kvp.Key]; if (schFeatureToReduce != null) { ReduceNode(rulesHelper, superspanLinkClass, spatialRef, schFeatureToReduce); } } // release memory colSchfeatureNode.Clear(); colSchfeatureNode = null; rulesHelper = null; }
void formAdvanced_doneFormEvent(object sender, AdvancedEvents e) { m_pSDS.DesignMode = true; formAdvanced.Cursor = System.Windows.Forms.Cursors.WaitCursor; //process the algorithm if there is one if (e.AlgorithmName != "") { ISchematicAlgoSmartTree a = new SchematicAlgoSmartTreeClass(); if (e.AlgorithmParams.Count > 0) { Dictionary <string, string> .KeyCollection keys = e.AlgorithmParams.Keys; string strValue = ""; foreach (string s in keys) { if (s == "Direction") { e.AlgorithmParams.TryGetValue(s, out strValue); if (strValue == "Top to Bottom") { a.Direction = esriSchematicAlgoDirection.esriSchematicAlgoTopDown; } else if (strValue == "Bottom to Top") { a.Direction = esriSchematicAlgoDirection.esriSchematicAlgoBottomUp; } else if (strValue == "Left to Right") { a.Direction = esriSchematicAlgoDirection.esriSchematicAlgoLeftRight; } else { a.Direction = esriSchematicAlgoDirection.esriSchematicAlgoRightLeft; } } } if (e.RootClass != "") { ISchematicElementClassContainer pECC = (ISchematicElementClassContainer)m_pSDS; ISchematicElementClass pEC = pECC.GetSchematicElementClass(e.RootClass); ESRI.ArcGIS.esriSystem.UID u = new ESRI.ArcGIS.esriSystem.UID(); u.Value = "{3AD9D8B8-0A1D-4F32-ABB5-54B848A46F85}"; ISchematicAttributeConstant pAttrConst = (ISchematicAttributeConstant)pEC.CreateSchematicAttribute("RootFlag", u); ISchematicAttributeManagement pAttrMgmt = (ISchematicAttributeManagement)pAttrConst; pAttrMgmt.StorageMode = esriSchematicAttributeStorageMode.esriSchematicAttributeFieldStorage; pAttrConst.ConstantValue = "-1"; } } m_pSDT.SchematicAlgorithm = (ISchematicAlgorithm)a; } //check to see if we need to add associated fields if (e.FieldsToCreate != null) { if (e.FieldsToCreate.Count > 0) { ISchematicElementClassContainer pECC = (ISchematicElementClassContainer)m_pSDS; //create the associated field attributes string[] keys = e.FieldsToCreate.AllKeys; foreach (string s in keys) { //get the feature class ISchematicElementClass pEC = pECC.GetSchematicElementClass(s); if (pEC != null) { string strName = ""; string[] values = e.FieldsToCreate.GetValues(s); foreach (string v in values) { //create the field ESRI.ArcGIS.esriSystem.UID u = new ESRI.ArcGIS.esriSystem.UID(); u.Value = "{7DE3A19D-32D0-41CD-B896-37CA3AFBD88A}"; IClass pClass = (IClass)pEC; //only handle names that don't already exist in the schematic tables if (pClass.FindField(v) == -1) { strName = v.ToString(); ISchematicAttributeAssociatedField pFieldAttr = (ISchematicAttributeAssociatedField)pEC.CreateSchematicAttribute(strName, u); pFieldAttr.AssociatedFieldName = v; ISchematicAttributeManagement pAttrMgmt = (ISchematicAttributeManagement)pFieldAttr; pAttrMgmt.StorageMode = esriSchematicAttributeStorageMode.esriSchematicAttributeFieldStorage; } } } } } } m_pSDS.Save(ESRI.ArcGIS.esriSystem.esriArcGISVersion.esriArcGISVersionCurrent, true); m_pSDS.DesignMode = false; formAdvanced.Cursor = System.Windows.Forms.Cursors.Default; formAdvanced.Close(); }