Esempio n. 1
0
        private void RetainNodesDegreeTwo(IEnumSchematicInMemoryFeature enumInMemoryFeature,
                                          Dictionary <string, ISchematicInMemoryFeature> colSchfeatureNode, ISchematicRulesHelper ruleHelper)
        {
            ISchematicInMemoryFeature schInMemoryfeature;

            if (ruleHelper == null)
            {
                return;
            }

            enumInMemoryFeature.Reset();
            schInMemoryfeature = enumInMemoryFeature.Next();
            while (schInMemoryfeature != null)
            {
                if (schInMemoryfeature.Displayed)
                {
                    IEnumSchematicInMemoryFeature enumLinks = ruleHelper.GetDisplayedIncidentLinks((ISchematicInMemoryFeatureNode)schInMemoryfeature, esriSchematicEndPointType.esriSchematicOriginOrExtremityNode);
                    if (enumLinks != null && enumLinks.Count == 2)
                    {
                        // Valid degree two node
                        if (!colSchfeatureNode.ContainsKey(schInMemoryfeature.Name))
                        {
                            if (!LinkAttribute)
                            {
                                colSchfeatureNode.Add(schInMemoryfeature.Name, schInMemoryfeature);
                            }
                            else
                            {
                                if (SameIncidentLinkAttributeValue(enumLinks, LinkAttributeName, ruleHelper))
                                {
                                    colSchfeatureNode.Add(schInMemoryfeature.Name, schInMemoryfeature);
                                }
                            }
                        }
                    }
                }

                schInMemoryfeature = enumInMemoryFeature.Next();
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        private IGeometry BuildLinkGeometry(ISchematicInMemoryFeatureLink schLink1, ISchematicInMemoryFeatureNode schNodeToReduce, ISchematicInMemoryFeatureLink schLink2, ISchematicRulesHelper rulesHelper)
        {
            if (schLink1 == null || schLink2 == null || schNodeToReduce == null || rulesHelper == null)
            {
                return(null);
            }

            if (m_keepVertices == false)
            {
                return(null); // no geometry
            }
            Polyline  newPoly   = new Polyline();
            IPolyline polyLink1 = rulesHelper.GetLinkPoints(schLink1, (schLink1.FromNode == schNodeToReduce));
            IPolyline polyLink2 = rulesHelper.GetLinkPoints(schLink2, (schLink2.ToNode == schNodeToReduce));
            IPoint    nodePt    = rulesHelper.GetNodePoint(schNodeToReduce);
            IPoint    Pt;

            IPointCollection newPts   = (IPointCollection)newPoly;
            IPointCollection link1Pts = (IPointCollection)polyLink1;
            IPointCollection link2Pts = (IPointCollection)polyLink2;

            int Count = link1Pts.PointCount;
            int i;

            for (i = 0; i < Count - 1; i++)
            {
                Pt = link1Pts.get_Point(i);
                newPts.AddPoint(Pt);
            }

            newPts.AddPoint(nodePt);

            Count = link2Pts.PointCount;
            for (i = 1; i < Count; i++)
            {
                Pt = link2Pts.get_Point(i);
                newPts.AddPoint(Pt);
            }

            IGeometry buildGeometry = (IGeometry)newPoly;

            return(buildGeometry);
        }
        private void AddNodesDegreeTwo(IEnumSchematicInMemoryFeature enumInMemoryFeature,
                Dictionary<string, ISchematicInMemoryFeature> colSchfeatureNode, ISchematicRulesHelper rulesHelper)
        {
            ISchematicInMemoryFeature schInMemoryfeature;

            if (enumInMemoryFeature == null || colSchfeatureNode == null || rulesHelper == null) 
                return;

            enumInMemoryFeature.Reset();
            schInMemoryfeature = enumInMemoryFeature.Next();
            while (schInMemoryfeature != null)
            {
                if (schInMemoryfeature.Displayed)
                {
                    IEnumSchematicInMemoryFeature enumLinks = rulesHelper.GetDisplayedIncidentLinks((ISchematicInMemoryFeatureNode)schInMemoryfeature, esriSchematicEndPointType.esriSchematicOriginOrExtremityNode);
                    if (enumLinks != null && enumLinks.Count == 2)
                    {
                        if (!colSchfeatureNode.ContainsKey(schInMemoryfeature.Name))
                            colSchfeatureNode.Add(schInMemoryfeature.Name, schInMemoryfeature);
                    }
                }

                schInMemoryfeature = enumInMemoryFeature.Next();
            }
        }
        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 RetainNodesDegreeTwo(IEnumSchematicInMemoryFeature enumInMemoryFeature,
                Dictionary<string, ISchematicInMemoryFeature> colSchfeatureNode, ISchematicRulesHelper ruleHelper)
        {
            ISchematicInMemoryFeature schInMemoryfeature;

            if (ruleHelper == null) return;

            enumInMemoryFeature.Reset();
            schInMemoryfeature = enumInMemoryFeature.Next();
            while (schInMemoryfeature != null)
            {
                if (schInMemoryfeature.Displayed)
                {
                    IEnumSchematicInMemoryFeature enumLinks = ruleHelper.GetDisplayedIncidentLinks((ISchematicInMemoryFeatureNode)schInMemoryfeature, esriSchematicEndPointType.esriSchematicOriginOrExtremityNode);
                    if (enumLinks != null && enumLinks.Count == 2)
                    {
                        // Valid degree two node
                        if (!colSchfeatureNode.ContainsKey(schInMemoryfeature.Name))
                        {
                            if (!LinkAttribute)
                                colSchfeatureNode.Add(schInMemoryfeature.Name, schInMemoryfeature);
                            else
                            {
                                if(SameIncidentLinkAttributeValue(enumLinks, LinkAttributeName, ruleHelper))
                                    colSchfeatureNode.Add(schInMemoryfeature.Name, schInMemoryfeature);
                            }
                        }
                    }
                }

                schInMemoryfeature = enumInMemoryFeature.Next();
            }
        }
        private IGeometry BuildLinkGeometry(ISchematicInMemoryFeatureLink schLink1, ISchematicInMemoryFeatureNode schNodeToReduce, ISchematicInMemoryFeatureLink schLink2, ISchematicRulesHelper rulesHelper)
        {

            if (schLink1 == null || schLink2 == null || schNodeToReduce == null || rulesHelper == null)
                return null;

            if (m_keepVertices == false)
                return null; // no geometry

            Polyline newPoly = new Polyline();
            IPolyline polyLink1 = rulesHelper.GetLinkPoints(schLink1, (schLink1.FromNode == schNodeToReduce));
            IPolyline polyLink2 = rulesHelper.GetLinkPoints(schLink2, (schLink2.ToNode == schNodeToReduce));
            IPoint nodePt = rulesHelper.GetNodePoint(schNodeToReduce);
            IPoint Pt;

            IPointCollection newPts = (IPointCollection)newPoly;
            IPointCollection link1Pts = (IPointCollection)polyLink1;
            IPointCollection link2Pts = (IPointCollection)polyLink2;

            int Count = link1Pts.PointCount;
            int i;
            for (i = 0; i < Count - 1; i++)
            {
                Pt = link1Pts.get_Point(i);
                newPts.AddPoint(Pt);
            }

            newPts.AddPoint(nodePt);

            Count = link2Pts.PointCount;
            for (i = 1; i < Count; i++)
            {
                Pt = link2Pts.get_Point(i);
                newPts.AddPoint(Pt);
            }

            IGeometry buildGeometry = (IGeometry)newPoly;
            return buildGeometry;
        }
        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);
        }