Ejemplo n.º 1
0
        public void OnAfterLoadDiagram(ISchematicInMemoryDiagram inMemoryDiagram)
        {
            // if add-in is not enabled then quit
            if (State != ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled)
            {
                return;
            }

            IEnumSchematicInMemoryFeature enumSchemElements;
            ISchematicInMemoryFeature     schemElement;
            string        nameRelatedCN = "";
            int           numRelatedOID = 0;
            IFeatureClass esriFeatureClass;
            IFeature      esriFeature;
            ISchematicInMemoryFeatureLinkerEdit schemFeatureLinkerEdit = (ISchematicInMemoryFeatureLinkerEdit) new SchematicLinker();
            ISchematicObjectClass        myObjectType;
            ISchematicAttribute          schemAttributeCID;
            ISchematicAttribute          schemAttributeOID;
            ISchematicAttributeContainer schemAttributeContainer;

            IWorkspace esriWorkspace;

            Microsoft.VisualBasic.Collection colFCByName;

            colFCByName   = new Microsoft.VisualBasic.Collection();
            esriWorkspace = inMemoryDiagram.SchematicDiagramClass.SchematicDataset.SchematicWorkspace.Workspace;

            // Retrieve all schematic element of the diagram

            enumSchemElements = (IEnumSchematicInMemoryFeature)inMemoryDiagram.SchematicInMemoryFeatures;
            enumSchemElements.Reset();

            schemElement = enumSchemElements.Next();
            while (schemElement != null)
            {
                // retrieve attribute
                myObjectType            = schemElement.SchematicElementClass;
                schemAttributeContainer = (ISchematicAttributeContainer)schemElement.SchematicElementClass;
                schemAttributeCID       = schemAttributeContainer.GetSchematicAttribute(AttClassNameName, false);
                schemAttributeOID       = schemAttributeContainer.GetSchematicAttribute(AttObjectIdName, false);
                if (schemAttributeCID != null && schemAttributeOID != null)
                {
                    // get value of attribute
                    nameRelatedCN = schemAttributeCID.GetValue((ISchematicObject)schemElement).ToString();
                    numRelatedOID = System.Convert.ToInt32(schemAttributeOID.GetValue((ISchematicObject)schemElement));

                    // get feature from geodatabase
                    esriFeatureClass = FindFeatureClassByName(esriWorkspace, nameRelatedCN, colFCByName);
                    if (esriFeatureClass != null)
                    {
                        // get feature from FeatureClass
                        esriFeature = esriFeatureClass.GetFeature(numRelatedOID);
                        if (esriFeature != null)
                        {
                            // Associate geographical feature with schematic feature
                            schemFeatureLinkerEdit.Associate(schemElement, esriFeature);
                        }
                    }
                }
                schemElement = enumSchemElements.Next();
            }
            colFCByName.Clear();
            colFCByName = null;
        }
Ejemplo n.º 2
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();
            }
        }