Ejemplo n.º 1
0
        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();
            }
        }