public string Evaluate(ISchematicInMemoryFeature schematicFeature) { if (schematicFeature.SchematicElementClass.SchematicElementType != esriSchematicElementType.esriSchematicLinkType) return ""; ISchematicInMemoryFeatureLink schemLink; schemLink = (ISchematicInMemoryFeatureLink)schematicFeature; // Get From node ISchematicInMemoryFeatureNode schemFromNode; schemFromNode = schemLink.FromNode; // Get Associated feature ISchematicElementAssociatedObject scheAsso; scheAsso = (ISchematicElementAssociatedObject)schemFromNode.SchematicElement; IFeature esriFeature; esriFeature = (IFeature)scheAsso.AssociatedObject; // Get list of fields IFields esriFields; esriFields = esriFeature.Fields; int numField; // Find Field MaxOutLines numField = esriFields.FindFieldByAliasName("MaxOutLines"); if (numField <= 0) return ""; // Field not found // Return value of the field return esriFeature.get_Value(numField).ToString(); }
private string GetUniqueName(ISchematicInMemoryDiagram inMemoryDiagram, esriSchematicElementType elementType, string featureName) { string nameUnique = featureName; ISchematicInMemoryFeature schInMemoryfeature = null; int index = 1; bool endWhile = false; while (!endWhile) { schInMemoryfeature = inMemoryDiagram.GetSchematicInMemoryFeatureByType(elementType, nameUnique); if (schInMemoryfeature == null) { endWhile = true; } else if (schInMemoryfeature.Displayed) { nameUnique = nameUnique + index.ToString(); index++; } else { endWhile = true; } } return(nameUnique); }
private void ReportCumulativeValues(ISchematicInMemoryFeature schFeat1, ISchematicInMemoryFeature schFeat2, ISchematicInMemoryFeature schTargetFeat) { if (schFeat1 == null || schFeat2 == null || schTargetFeat == null) { return; } // assume the attribute field name is the same on every schematic feature link classes IFields linkFields = schFeat1.Fields; int iIndex = linkFields.FindField(m_lengthAttributeName); if (iIndex < 0) { return; // attribute field does not exist } object value1 = schFeat1.get_Value(iIndex); linkFields = schFeat2.Fields; iIndex = linkFields.FindField(m_lengthAttributeName); if (iIndex < 0) { return; // attribute field does not exist } object value2 = schFeat2.get_Value(iIndex); double dValue1 = 0; double dValue2 = 0; if (!DBNull.Value.Equals(value1)) { try { dValue1 = Convert.ToDouble(value1); } catch { } } if (!DBNull.Value.Equals(value2)) { try { dValue2 = Convert.ToDouble(value2); } catch { } } // assume the values to be numeric double dlength = dValue1 + dValue2; linkFields = schTargetFeat.Fields; iIndex = linkFields.FindField(m_lengthAttributeName); if (iIndex < 0) { return; // attribute field does not exist } schTargetFeat.set_Value(iIndex, dlength); }
public string Evaluate(ISchematicInMemoryFeature schematicFeature) { if (schematicFeature.SchematicElementClass.SchematicElementType != esriSchematicElementType.esriSchematicLinkType) { return(""); } ISchematicInMemoryFeatureLink schemLink; schemLink = (ISchematicInMemoryFeatureLink)schematicFeature; // Get From node ISchematicInMemoryFeatureNode schemFromNode; schemFromNode = schemLink.FromNode; // Get Associated feature ISchematicElementAssociatedObject scheAsso; scheAsso = (ISchematicElementAssociatedObject)schemFromNode.SchematicElement; IFeature esriFeature; esriFeature = (IFeature)scheAsso.AssociatedObject; // Get list of fields IFields esriFields; esriFields = esriFeature.Fields; int numField; // Find Field MaxOutLines numField = esriFields.FindFieldByAliasName("MaxOutLines"); if (numField <= 0) { return(""); // Field not found } // Return value of the field return(esriFeature.get_Value(numField).ToString()); }
public void Apply(ISchematicInMemoryDiagram inMemoryDiagram, ESRI.ArcGIS.esriSystem.ITrackCancel cancelTracker) { if (m_reductionLinkName == "") { return; } IEnumSchematicInMemoryFeature enumSchematicElement; ISchematicInMemoryFeature schemElement; ISchematicDiagramClass diagramClass = null; ISchematicElementClass elementClass; IEnumSchematicElementClass enumElementClass; Microsoft.VisualBasic.Collection allreadyUsed = new Microsoft.VisualBasic.Collection(); try { diagramClass = inMemoryDiagram.SchematicDiagramClass; } catch { } if (diagramClass == null) { return; } enumElementClass = diagramClass.AssociatedSchematicElementClasses; enumElementClass.Reset(); elementClass = enumElementClass.Next(); while (elementClass != null) { if (elementClass.Name == m_reductionLinkName) { break; } elementClass = enumElementClass.Next(); } if (elementClass == null) { return; } // Get all link from selected class enumSchematicElement = inMemoryDiagram.GetSchematicInMemoryFeaturesByClass(elementClass); enumSchematicElement.Reset(); ISchematicInMemoryFeatureLink link = null; ISchematicInMemoryFeatureNode fromNode = null; ISchematicInMemoryFeatureNode toNode = null; int iFromPort = 0; int iToPort = 0; ISchematicInMemoryFeature newElem = null; IEnumSchematicInMemoryFeatureLink enumIncidentLinks; ISchematicInMemoryFeatureLinkerEdit schemLinker = (ISchematicInMemoryFeatureLinkerEdit)(new SchematicLinkerClass()); bool bReduction = false; schemElement = enumSchematicElement.Next(); while (schemElement != null) { try { string elemName = allreadyUsed[schemElement.Name].ToString(); // if found, this link is allready used schemElement = enumSchematicElement.Next(); continue; } catch { // Add link to collection allreadyUsed.Add(schemElement.Name, schemElement.Name, null, null); } // Get from node and to node link = (ISchematicInMemoryFeatureLink)schemElement; fromNode = link.FromNode; toNode = link.ToNode; if (m_usePort) { iFromPort = link.FromPort; iToPort = link.ToPort; } // Get all links from this node enumIncidentLinks = fromNode.GetIncidentLinks(esriSchematicEndPointType.esriSchematicOriginOrExtremityNode); enumIncidentLinks.Reset(); newElem = enumIncidentLinks.Next(); while (newElem != null) { bReduction = false; if (newElem == schemElement) { // the new link is the same link we works on newElem = enumIncidentLinks.Next(); continue; } link = (ISchematicInMemoryFeatureLink)newElem; // 1st case of comparison if (fromNode == link.FromNode && toNode == link.ToNode) { if (m_usePort) { bReduction = (iFromPort == link.FromPort && iToPort == link.ToPort); } else { bReduction = true; } } // 2nd case of comparison else if (fromNode == link.ToNode && toNode == link.FromNode) { if (m_usePort) { bReduction = (iFromPort == link.ToPort && iToPort == link.FromPort); } else { bReduction = true; } } if (bReduction) { try { schemLinker.ReportAssociations(newElem, schemElement); // Reports asssociation to first link allreadyUsed.Add(newElem.Name, newElem.Name, null, null); // Add link to collection newElem.Displayed = false; // this link is not visible } catch { } } newElem = enumIncidentLinks.Next(); } schemElement.Displayed = true; schemElement = enumSchematicElement.Next(); } }
private void Updatecontainers(ESRI.ArcGIS.Schematic.ISchematicLayer schLayer) { if (schLayer == null) { return; } // get the inMemorydiagram if any ISchematicInMemoryDiagram inMemoryDiagram; inMemoryDiagram = schLayer.SchematicInMemoryDiagram; if (inMemoryDiagram == null) { return; } bool bCreate = false; // create or remove relations between containers and their contents if (this.State == ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled) { bCreate = true; } ISchematicElementClass schemContainerClass = null; ISchematicElementClass schemElementClass; ISchematicElementClass schemStationClass = null; IEnumSchematicInMemoryFeature enumElementsInContainer; IEnumSchematicInMemoryFeature enumContainerElements; ISchematicInMemoryFeature schemFeature = null; ISchematicInMemoryFeature schemContainerFeature = null; object feederOID; string containerNameID; IEnumSchematicElementClass enumElementClass; ISchematicAttributeContainer schemAttributeContainer; ISchematicAttribute schemAttributeRelatedFeeder; //ISchematicElement schemElement ; ISchematicRelationController schemRelationController = null; ISchematicRelationControllerEdit schemRelationControllerEdit = null; Collection colContElem = new Collection(); // Getting SchematicFeature Class Stations and Containers enumElementClass = inMemoryDiagram.SchematicDiagramClass.AssociatedSchematicElementClasses; enumElementClass.Reset(); schemElementClass = enumElementClass.Next(); while (schemElementClass != null) { if (schemElementClass.Name == "Stations") { schemStationClass = schemElementClass; } if (schemElementClass.Name == "Containers") { schemContainerClass = schemElementClass; } if (schemStationClass != null && schemContainerClass != null) { break; } schemElementClass = enumElementClass.Next(); } // go out if schemStationClass or schemContainerClass are null if (schemStationClass == null || schemContainerClass == null) { return; } // Getting the Stations elements that will be displayed in the containers enumElementsInContainer = inMemoryDiagram.GetSchematicInMemoryFeaturesByClass(schemStationClass); if (enumElementsInContainer == null) { return; } // Creating the Schematic Container Manager schemRelationController = new SchematicRelationController(); // Creating the Schematic Container Editor that will be used to define the relation between the stations and their container schemRelationControllerEdit = (ISchematicRelationControllerEdit)schemRelationController; // Defining each Container element as a schematic container enumContainerElements = inMemoryDiagram.GetSchematicInMemoryFeaturesByClass(schemContainerClass); // Add Container Element to a collection enumContainerElements.Reset(); schemContainerFeature = enumContainerElements.Next(); while (schemContainerFeature != null) { colContElem.Add(schemContainerFeature, schemContainerFeature.Name, null, null); schemContainerFeature = enumContainerElements.Next(); } // Setting the relation between each station and its related container enumElementsInContainer.Reset(); schemFeature = enumElementsInContainer.Next(); while (schemFeature != null) { // The relation is specified by the RelatedFeeder attribute value defined for each station schemAttributeContainer = (ISchematicAttributeContainer)schemFeature.SchematicElementClass; schemAttributeRelatedFeeder = schemAttributeContainer.GetSchematicAttribute("RelatedFeeder", false); feederOID = schemAttributeRelatedFeeder.GetValue((ISchematicObject)schemFeature); if (feederOID != null) { containerNameID = "Container-" + feederOID.ToString(); try { // Retrieve Container Element in the collection schemContainerFeature = (ISchematicInMemoryFeature)colContElem[containerNameID]; if (bCreate) { schemRelationControllerEdit.CreateRelation(schemFeature, schemContainerFeature); // Create relation } else { schemRelationControllerEdit.DeleteRelation(schemFeature); // delete child relation } } catch { } } schemContainerFeature = null; schemFeature = enumElementsInContainer.Next(); } if (!bCreate) { // Force container geometry enumContainerElements.Reset(); while ((schemContainerFeature = enumContainerElements.Next()) != null) { try { // set an empty geometry // container does not have content at this stage Polygon emptyRectangle = new Polygon(); IGeometry ContainerGeometry = (IGeometry)emptyRectangle; schemContainerFeature.Shape = ContainerGeometry; } catch { } } } IActiveView activeView = (IActiveView)ArcMap.Document.FocusMap; if (activeView != null) { activeView.ContentsChanged(); activeView.Refresh(); } }
private bool SameIncidentLinkAttributeValue(IEnumSchematicInMemoryFeature enumInMemoryLinks, string attributeName, ISchematicRulesHelper ruleHelper) { ISchematicInMemoryFeature inMemoryFeature = null; enumInMemoryLinks.Reset(); bool bFirstVariant = true; object vPreviousValue = null; object vCurrentValue = null; inMemoryFeature = enumInMemoryLinks.Next(); while (inMemoryFeature != null) { // Do not take account the link if the link is not displayed // // Search for an attribute with the given name // ISchematicElementClass schematicElementClass; schematicElementClass = inMemoryFeature.SchematicElementClass; ISchematicAttributeContainer attributeContainer = (ISchematicAttributeContainer)schematicElementClass; ISchematicAttribute schematicAttribute = null; if (attributeContainer != null) { schematicAttribute = attributeContainer.GetSchematicAttribute(attributeName, true); } if (schematicAttribute != null) { ISchematicObject schematicObject = (ISchematicObject)inMemoryFeature; vCurrentValue = schematicAttribute.GetValue(schematicObject); } else { // If schematic attribute not existing ==> find a field in the associated feature IObject iObject = null; ISchematicInMemoryFeaturePrimaryAssociation primaryAssociation = (ISchematicInMemoryFeaturePrimaryAssociation)inMemoryFeature; if (primaryAssociation != null) { iObject = primaryAssociation.AssociatedObject; } IRow row = (IRow)iObject; int fieldIndex = 0; if (row != null) { IFields fields = row.Fields; if (fields != null) { fieldIndex = fields.FindField(attributeName); } } if (fieldIndex > 0) { vCurrentValue = row.get_Value(fieldIndex); if (DBNull.Value.Equals(vCurrentValue)) { return(false); } } else { return(false); } } if (bFirstVariant) { vPreviousValue = vCurrentValue; bFirstVariant = false; } else { // Compare PreviousValue and CurrentValue if (vPreviousValue.GetType() != vCurrentValue.GetType()) { return(false); } if (DBNull.Value.Equals(vPreviousValue) || DBNull.Value.Equals(vCurrentValue)) { return(false); } if (vPreviousValue.GetType().FullName is System.String)//Speciale Case for string. { string str1 = (string)vPreviousValue; string str2 = (string)vCurrentValue; if (string.Compare(str1, str2, true) != 0) { return(false); } } else if (vPreviousValue != vCurrentValue)// == or != operator compare for Variant match the right type. { return(false); } } inMemoryFeature = enumInMemoryLinks.Next(); } return(true); }
private void ReduceNode(ISchematicRulesHelper rulesHelper, ISchematicInMemoryFeatureClass superspanLinkClass, ISpatialReference spatialRef, ISchematicInMemoryFeature schFeatureToReduce) { if (schFeatureToReduce.Displayed == false || rulesHelper == null || spatialRef == null) { return; } // get the two connected links IEnumSchematicInMemoryFeature enumLink = rulesHelper.GetDisplayedIncidentLinks((ISchematicInMemoryFeatureNode)schFeatureToReduce, esriSchematicEndPointType.esriSchematicOriginOrExtremityNode); if (enumLink == null || enumLink.Count != 2) { return; } enumLink.Reset(); ISchematicInMemoryFeature schFeat1 = enumLink.Next(); ISchematicInMemoryFeature schFeat2 = enumLink.Next(); ISchematicInMemoryFeatureLink schLink1 = (ISchematicInMemoryFeatureLink)schFeat1; ISchematicInMemoryFeatureLink schLink2 = (ISchematicInMemoryFeatureLink)schFeat2; if (schLink1 == null || schLink2 == null) { return; } ISchematicInMemoryFeature schFeatureSuperspan = null; ISchematicInMemoryFeature schFeatureTmp = null; ISchematicInMemoryFeatureNode schNodeToReduce = (ISchematicInMemoryFeatureNode)schFeatureToReduce; ISchematicInMemoryFeatureNode schFromNode; ISchematicInMemoryFeatureNode schToNode; int iFromPort; int iToPort; IGeometry superspanGeometry; if (schLink2.FromNode == schNodeToReduce) { superspanGeometry = BuildLinkGeometry(schLink1, schNodeToReduce, schLink2, rulesHelper); if (schLink1.ToNode == schNodeToReduce) { schFromNode = schLink1.FromNode; iFromPort = schLink1.FromPort; } else { schFromNode = schLink1.ToNode; iFromPort = schLink1.ToPort; } schToNode = schLink2.ToNode; iToPort = schLink2.ToPort; } else { superspanGeometry = BuildLinkGeometry(schLink2, schNodeToReduce, schLink1, rulesHelper); schFromNode = schLink2.FromNode; iFromPort = schLink2.FromPort; if (schLink1.FromNode == schNodeToReduce) { schToNode = schLink1.ToNode; iToPort = schLink1.ToPort; } else { schToNode = schLink1.FromNode; iToPort = schLink1.FromPort; } } if (superspanGeometry != null) { superspanGeometry.SpatialReference = spatialRef; } // find a unique name for the superspan string strFromName = schFromNode.Name; string strtoName = schToNode.Name; string strName; long lCount = 1; while (schFeatureSuperspan == null) { strName = strFromName + ";" + strtoName + ";" + lCount.ToString(); if (strName.Length >= 128) { break; // too long a name } try { schFeatureTmp = rulesHelper.AlterLink(superspanLinkClass, strName, null, superspanGeometry, -2, -2, strFromName, strtoName, esriFlowDirection.esriFDWithFlow, iFromPort, iToPort); } catch { schFeatureTmp = null; } if (schFeatureTmp == null) { continue; } // valid new feature schFeatureSuperspan = schFeatureTmp; } // last chance for a unique name lCount = 1; while (schFeatureSuperspan == null) { strName = schNodeToReduce.Name + ";" + lCount.ToString(); if (strName.Length >= 128) { break; // too long a name } try { schFeatureTmp = rulesHelper.AlterLink(superspanLinkClass, strName, null, superspanGeometry, -2, -2, strFromName, strtoName, esriFlowDirection.esriFDWithFlow, iFromPort, iToPort); } catch { schFeatureTmp = null; } if (schFeatureTmp == null) { continue; } // valid new feature schFeatureSuperspan = schFeatureTmp; } if (schFeatureSuperspan == null) { return; // cannot find a unique name } // otherwise report the cumulated length of the reduced links to the superspan ReportCumulativeValues(schFeat1, schFeat2, schFeatureSuperspan); // report the associations on the superspan link rulesHelper.ReportAssociations(schFeatureToReduce, schFeatureSuperspan); rulesHelper.ReportAssociations(schFeat1, schFeatureSuperspan); rulesHelper.ReportAssociations(schFeat2, schFeatureSuperspan); // hide the reduced objects rulesHelper.HideFeature(schFeatureToReduce); rulesHelper.HideFeature(schFeat1); rulesHelper.HideFeature(schFeat2); }
void OnBeforeRemoveFeature(ISchematicInMemoryFeature inMemoryFeature, ref bool canRemove) { if (State != ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled) return; ESRI.ArcGIS.Geodatabase.IDataset esriData = (ESRI.ArcGIS.Geodatabase.IDataset)inMemoryFeature.SchematicDiagram.SchematicDiagramClass.SchematicDataset; // Remove only elements contained in a specific Schematic dataset if (esriData.Name != SampleDatasetName) return; // Remove only elements contained in a specific type of diagram if (inMemoryFeature.SchematicDiagram.SchematicDiagramClass.Name != DiagramClassName) return; canRemove = false; // can't remove SubStation if (inMemoryFeature.SchematicElementClass.Name == "InsidePlant_SubStation") return; ISchematicDiagramClass schemDiagramClass; schemDiagramClass = (ISchematicDiagramClass)inMemoryFeature.SchematicDiagram.SchematicDiagramClass; // For this specific diagram type, we retrieve the datasource // and the tables where the elements are stored ISchematicDataSource schemDataSource = schemDiagramClass.SchematicDataSource; string tableName = ""; switch (inMemoryFeature.SchematicElementClass.SchematicElementType) { case esriSchematicElementType.esriSchematicNodeType: tableName = TableNameNodes; break; case esriSchematicElementType.esriSchematicLinkType: tableName = TableNameLinks; break; case esriSchematicElementType.esriSchematicDrawingType: return; break; } // Retrieve Feature Workspace ESRI.ArcGIS.Geodatabase.IWorkspace esriWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)schemDataSource.Object; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace esriFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)esriWorkspace; // Get Attributes values ISchematicAttributeContainer schemAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass; ISchematicAttributeContainer schemFatherAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass.Parent; if ((!(schemAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null) || !(schemFatherAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null))) { int indField = inMemoryFeature.Fields.FindFieldByAliasName(AttributeNameObjectID); int OID = int.Parse(inMemoryFeature.get_Value(indField).ToString(), System.Globalization.NumberStyles.Integer); //Get table and row ESRI.ArcGIS.Geodatabase.ITable esriTable = esriFeatureWorkspace.OpenTable(tableName); ESRI.ArcGIS.Geodatabase.IRow esriRow = esriTable.GetRow(OID); // When the row is identified in the table, it is deleted and // the CanRemove returns True so that the associated // schematic element is graphically removed from the active diagram if (!(esriRow == null)) { esriRow.Delete(); canRemove = true; } } }
void OnBeforeRemoveFeature(ISchematicInMemoryFeature inMemoryFeature, ref bool canRemove) { if (State != ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled) { return; } ESRI.ArcGIS.Geodatabase.IDataset esriData = (ESRI.ArcGIS.Geodatabase.IDataset)inMemoryFeature.SchematicDiagram.SchematicDiagramClass.SchematicDataset; // Remove only elements contained in a specific Schematic dataset if (esriData.Name != SampleDatasetName) { return; } // Remove only elements contained in a specific type of diagram if (inMemoryFeature.SchematicDiagram.SchematicDiagramClass.Name != DiagramClassName) { return; } canRemove = false; // can't remove SubStation if (inMemoryFeature.SchematicElementClass.Name == "InsidePlant_SubStation") { return; } ISchematicDiagramClass schemDiagramClass; schemDiagramClass = (ISchematicDiagramClass)inMemoryFeature.SchematicDiagram.SchematicDiagramClass; // For this specific diagram type, we retrieve the datasource // and the tables where the elements are stored ISchematicDataSource schemDataSource = schemDiagramClass.SchematicDataSource; string tableName = ""; switch (inMemoryFeature.SchematicElementClass.SchematicElementType) { case esriSchematicElementType.esriSchematicNodeType: tableName = TableNameNodes; break; case esriSchematicElementType.esriSchematicLinkType: tableName = TableNameLinks; break; case esriSchematicElementType.esriSchematicDrawingType: return; break; } // Retrieve Feature Workspace ESRI.ArcGIS.Geodatabase.IWorkspace esriWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)schemDataSource.Object; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace esriFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)esriWorkspace; // Get Attributes values ISchematicAttributeContainer schemAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass; ISchematicAttributeContainer schemFatherAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass.Parent; if ((!(schemAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null) || !(schemFatherAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null))) { int indField = inMemoryFeature.Fields.FindFieldByAliasName(AttributeNameObjectID); int OID = int.Parse(inMemoryFeature.get_Value(indField).ToString(), System.Globalization.NumberStyles.Integer); //Get table and row ESRI.ArcGIS.Geodatabase.ITable esriTable = esriFeatureWorkspace.OpenTable(tableName); ESRI.ArcGIS.Geodatabase.IRow esriRow = esriTable.GetRow(OID); // When the row is identified in the table, it is deleted and // the CanRemove returns True so that the associated // schematic element is graphically removed from the active diagram if (!(esriRow == null)) { esriRow.Delete(); canRemove = true; } } }
public void Apply(ISchematicInMemoryDiagram inMemoryDiagram, ESRI.ArcGIS.esriSystem.ITrackCancel cancelTracker) { ISchematicRulesHelper rulesHelper = new SchematicRulesHelperClass(); System.Collections.Generic.Dictionary <string, ISchematicInMemoryFeature> colSchfeatureNode = new Dictionary <string, ISchematicInMemoryFeature>(); rulesHelper.InitHelper(inMemoryDiagram); rulesHelper.KeepVertices = true; ISchematicDiagramClass diagramClass = null; ISchematicElementClass elementClass; ISchematicElementClass elementClassParentNode = null; IEnumSchematicElementClass enumSchEltCls; try { diagramClass = inMemoryDiagram.SchematicDiagramClass; } catch { } if (diagramClass == null) { return; } enumSchEltCls = diagramClass.AssociatedSchematicElementClasses; if (enumSchEltCls.Count == 0) { return; } enumSchEltCls.Reset(); elementClass = enumSchEltCls.Next(); while (elementClass != null) { if (elementClass.Name == m_parentNodeClassName) { elementClassParentNode = elementClass; m_parentNodeClass = GetSchematicInMemoryFeatureClass(inMemoryDiagram, elementClass); } if (elementClass.Name == m_targetNodeClassName) { m_targetNodeClass = GetSchematicInMemoryFeatureClass(inMemoryDiagram, elementClass); } if (elementClass.Name == m_targetLinkClassName) { m_targetLinkClass = GetSchematicInMemoryFeatureClass(inMemoryDiagram, elementClass); } elementClass = enumSchEltCls.Next(); } if (m_parentNodeClass == null || m_targetNodeClass == null || m_targetLinkClass == null) { return; } IEnumSchematicInMemoryFeature enumSchematicInMemoryFeature; // list nodes degree two // get all feature of parent node class enumSchematicInMemoryFeature = inMemoryDiagram.GetSchematicInMemoryFeaturesByClass(elementClassParentNode); enumSchematicInMemoryFeature.Reset(); // add the node into collection if it contains only 2 links displayed. AddNodesDegreeTwo(enumSchematicInMemoryFeature, colSchfeatureNode, rulesHelper); ISchematicInMemoryFeature schFeatureParent; foreach (KeyValuePair <string, ISchematicInMemoryFeature> kvp in colSchfeatureNode) { schFeatureParent = colSchfeatureNode[kvp.Key]; if (schFeatureParent == null) { continue; } // get 2 links connected of eache feature node IEnumSchematicInMemoryFeature enumLinks = rulesHelper.GetDisplayedIncidentLinks((ISchematicInMemoryFeatureNode)schFeatureParent, esriSchematicEndPointType.esriSchematicOriginOrExtremityNode); // enumLinks surely not null and it contain 2 links displayed double angle1, angle2, angleBisector; bool first = true; angle1 = angle2 = angleBisector = 0; IPoint pointParent = null; ISchematicInMemoryFeatureNodeGeometry geoParent; geoParent = (ISchematicInMemoryFeatureNodeGeometry)schFeatureParent; pointParent = geoParent.InitialPosition; IPoint pointSon = null; bool enableCalculate = true; ISchematicInMemoryFeature schInMemoryFeature = enumLinks.Next(); ISchematicInMemoryFeatureLink schInMemoryLink = (ISchematicInMemoryFeatureLink)schInMemoryFeature; while (schInMemoryLink != null) { ISchematicInMemoryFeatureNodeGeometry nodeGeo; // get angle of 2 links connected if (schInMemoryLink.FromNode.Name == schFeatureParent.Name) { nodeGeo = (ISchematicInMemoryFeatureNodeGeometry)schInMemoryLink.ToNode; } else { nodeGeo = (ISchematicInMemoryFeatureNodeGeometry)schInMemoryLink.FromNode; } if (nodeGeo == null) { enableCalculate = false; break; } pointSon = nodeGeo.InitialPosition; if (first) { angle1 = CalculateAngle(pointParent, pointSon); first = false; } else { angle2 = CalculateAngle(pointParent, pointSon); } schInMemoryFeature = enumLinks.Next(); schInMemoryLink = (ISchematicInMemoryFeatureLink)schInMemoryFeature; } // caculate angle bisector if (enableCalculate) { angleBisector = CalculateAngleBisector(angle1, angle2); } else { continue; } // construct a geometry for the new node node // now call alterNode to create a new schematic feature // construct a correct name string uniqueNodeName, featureCreateName; featureCreateName = schFeatureParent.Name + Separator + extensionName; esriSchematicElementType elementType = esriSchematicElementType.esriSchematicNodeType; uniqueNodeName = GetUniqueName(inMemoryDiagram, elementType, featureCreateName); IWorkspace workspace = null; try { workspace = inMemoryDiagram.SchematicDiagramClass.SchematicDataset.SchematicWorkspace.Workspace; } catch { } int datasourceID = -1; if (workspace != null) { datasourceID = rulesHelper.FindDataSourceID(workspace, false); } if (datasourceID == -1) { datasourceID = m_diagramClass.SchematicDataset.DefaultSchematicDataSource.ID; } ISchematicInMemoryFeature schFeatureNodeCreate = null; IPoint pointBisector = null; pointBisector = GetCoordPointBisector(pointParent, angleBisector, m_distance); try { schFeatureNodeCreate = rulesHelper.AlterNode(m_targetNodeClass, uniqueNodeName, null, (IGeometry)pointBisector, datasourceID, 0); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Impossible to create a feature Node"); } // now construct a unique link name string linkName = schFeatureParent.Name + Separator + uniqueNodeName; string uniqueLinkName; elementType = esriSchematicElementType.esriSchematicLinkType; uniqueLinkName = GetUniqueName(inMemoryDiagram, elementType, linkName); // construct a link ISchematicInMemoryFeature schFeatureLinkCreate = null; try { schFeatureLinkCreate = rulesHelper.AlterLink(m_targetLinkClass, uniqueLinkName, null, null, datasourceID, 0, schFeatureParent.Name, uniqueNodeName, esriFlowDirection.esriFDWithFlow, 0, 0); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Impossible to create a feature link"); } } if (colSchfeatureNode.Count > 0) { colSchfeatureNode.Clear(); } colSchfeatureNode = null; rulesHelper = null; }
private void ReportCumulativeValues(ISchematicInMemoryFeature schFeat1, ISchematicInMemoryFeature schFeat2, ISchematicInMemoryFeature schTargetFeat) { if (schFeat1 == null || schFeat2 == null || schTargetFeat == null) return; // assume the attribute field name is the same on every schematic feature link classes IFields linkFields = schFeat1.Fields; int iIndex = linkFields.FindField(m_lengthAttributeName); if (iIndex < 0) return; // attribute field does not exist object value1 = schFeat1.get_Value(iIndex); linkFields = schFeat2.Fields; iIndex = linkFields.FindField(m_lengthAttributeName); if (iIndex < 0) return; // attribute field does not exist object value2 = schFeat2.get_Value(iIndex); double dValue1 = 0; double dValue2 = 0; if (!DBNull.Value.Equals(value1)) { try { dValue1 = Convert.ToDouble(value1); } catch { } } if (!DBNull.Value.Equals(value2)) { try { dValue2 = Convert.ToDouble(value2); } catch{ } } // assume the values to be numeric double dlength = dValue1 + dValue2; linkFields = schTargetFeat.Fields; iIndex = linkFields.FindField(m_lengthAttributeName); if (iIndex < 0) return; // attribute field does not exist schTargetFeat.set_Value(iIndex, dlength); }
private void ReduceNode(ISchematicRulesHelper rulesHelper, ISchematicInMemoryFeatureClass superspanLinkClass , ISpatialReference spatialRef, ISchematicInMemoryFeature schFeatureToReduce) { if (schFeatureToReduce.Displayed == false || rulesHelper == null || spatialRef == null) return; // get the two connected links IEnumSchematicInMemoryFeature enumLink = rulesHelper.GetDisplayedIncidentLinks((ISchematicInMemoryFeatureNode)schFeatureToReduce, esriSchematicEndPointType.esriSchematicOriginOrExtremityNode); if (enumLink == null || enumLink.Count != 2) return; enumLink.Reset(); ISchematicInMemoryFeature schFeat1 = enumLink.Next(); ISchematicInMemoryFeature schFeat2 = enumLink.Next(); ISchematicInMemoryFeatureLink schLink1 = (ISchematicInMemoryFeatureLink)schFeat1; ISchematicInMemoryFeatureLink schLink2 = (ISchematicInMemoryFeatureLink)schFeat2; if (schLink1 == null || schLink2 == null) return; ISchematicInMemoryFeature schFeatureSuperspan = null; ISchematicInMemoryFeature schFeatureTmp = null; ISchematicInMemoryFeatureNode schNodeToReduce = (ISchematicInMemoryFeatureNode)schFeatureToReduce; ISchematicInMemoryFeatureNode schFromNode; ISchematicInMemoryFeatureNode schToNode; int iFromPort; int iToPort; IGeometry superspanGeometry; if (schLink2.FromNode == schNodeToReduce) { superspanGeometry = BuildLinkGeometry(schLink1, schNodeToReduce, schLink2, rulesHelper); if (schLink1.ToNode == schNodeToReduce) { schFromNode = schLink1.FromNode; iFromPort = schLink1.FromPort; } else { schFromNode = schLink1.ToNode; iFromPort = schLink1.ToPort; } schToNode = schLink2.ToNode; iToPort = schLink2.ToPort; } else { superspanGeometry = BuildLinkGeometry(schLink2, schNodeToReduce, schLink1, rulesHelper); schFromNode = schLink2.FromNode; iFromPort = schLink2.FromPort; if (schLink1.FromNode == schNodeToReduce) { schToNode = schLink1.ToNode; iToPort = schLink1.ToPort; } else { schToNode = schLink1.FromNode; iToPort = schLink1.FromPort; } } if (superspanGeometry != null) superspanGeometry.SpatialReference = spatialRef; // find a unique name for the superspan string strFromName = schFromNode.Name; string strtoName = schToNode.Name; string strName; long lCount = 1; while (schFeatureSuperspan == null) { strName = strFromName + ";" + strtoName + ";" + lCount.ToString(); if (strName.Length >= 128) break; // too long a name try { schFeatureTmp = rulesHelper.AlterLink(superspanLinkClass, strName, null, superspanGeometry, -2, -2, strFromName, strtoName, esriFlowDirection.esriFDWithFlow, iFromPort, iToPort); } catch { schFeatureTmp = null; } if (schFeatureTmp == null) continue; // valid new feature schFeatureSuperspan = schFeatureTmp; } // last chance for a unique name lCount = 1; while (schFeatureSuperspan == null) { strName = schNodeToReduce.Name + ";" + lCount.ToString(); if (strName.Length >= 128) break; // too long a name try { schFeatureTmp = rulesHelper.AlterLink(superspanLinkClass, strName, null, superspanGeometry, -2, -2, strFromName, strtoName, esriFlowDirection.esriFDWithFlow, iFromPort, iToPort); } catch { schFeatureTmp = null; } if (schFeatureTmp == null) continue; // valid new feature schFeatureSuperspan = schFeatureTmp; } if (schFeatureSuperspan == null) return; // cannot find a unique name // otherwise report the cumulated length of the reduced links to the superspan ReportCumulativeValues(schFeat1, schFeat2, schFeatureSuperspan); // report the associations on the superspan link rulesHelper.ReportAssociations(schFeatureToReduce, schFeatureSuperspan); rulesHelper.ReportAssociations(schFeat1, schFeatureSuperspan); rulesHelper.ReportAssociations(schFeat2, schFeatureSuperspan); // hide the reduced objects rulesHelper.HideFeature(schFeatureToReduce); rulesHelper.HideFeature(schFeat1); rulesHelper.HideFeature(schFeat2); }