コード例 #1
0
        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);
        }
コード例 #2
0
        protected override void OnClick()
        {
            if (m_schematicTarget != null && m_schematicTarget.SchematicTarget != null && m_schematicTarget.SchematicTarget.IsEditingSchematicDiagram())
            {
                if (m_schematicInMemoryDiagram == null)
                {
                    m_schematicInMemoryDiagram = m_schematicTarget.SchematicTarget.SchematicInMemoryDiagram;
                }

                if (m_schematicInMemoryDiagram != null)
                {
                    if (m_formAuto == null)
                    {
                        m_formAuto = new FormAutoRefresh();
                        try
                        {
                            m_formAuto.InitializeSecond();
                            m_formAuto.InitializeMinute();
                        }
                        catch (Exception e)
                        {
                            System.Windows.Forms.MessageBox.Show(e.Message);
                        }
                    }
                    m_formAuto.SetSchematicInmemoryDiagram(m_schematicInMemoryDiagram);
                    m_formAuto.Appli = m_application;

                    m_formAuto.Show();
                }
            }
        }
		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;
		}
コード例 #4
0
		protected override void OnClick()
		{
			if (m_schematicTarget != null && m_schematicTarget.SchematicTarget != null && m_schematicTarget.SchematicTarget.IsEditingSchematicDiagram())
			{
				if (m_schematicInMemoryDiagram == null)
					m_schematicInMemoryDiagram = m_schematicTarget.SchematicTarget.SchematicInMemoryDiagram;

				if (m_schematicInMemoryDiagram != null)
				{
					if (m_formAuto == null)
					{
						m_formAuto = new FormAutoRefresh();
						try
						{
							m_formAuto.InitializeSecond();
							m_formAuto.InitializeMinute();
						}
						catch (Exception e)
						{
							System.Windows.Forms.MessageBox.Show(e.Message);
						}
					}
					m_formAuto.SetSchematicInmemoryDiagram(m_schematicInMemoryDiagram);
					m_formAuto.Appli = m_application;

					m_formAuto.Show();
				}
			}
		}
コード例 #5
0
        protected override void OnUpdate()
        {
            // the tool is enable only if the diagram is in memory
            try
            {
                if (ArcMap.Application == null)
                {
                    Enabled = false;
                    return;
                }

                SetTargetLayer();

                if (m_schematicLayer == null)
                {
                    Enabled = false;
                    return;
                }

                if (m_schematicLayer.IsEditingSchematicDiagram() == false)
                {
                    Enabled = false;
                    if (m_dockableWindow != null)
                    {
                        m_dockableWindow.Show(false);
                    }

                    return;
                }

                ISchematicInMemoryDiagram inMemoryDiagram = m_schematicLayer.SchematicInMemoryDiagram;

                if (inMemoryDiagram == null)
                {
                    Enabled = false;
                }
                else
                {
                    Enabled = true;
                }
            }
            catch (System.Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }
            return;
        }
コード例 #6
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();
            }
        }
コード例 #7
0
        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;
        }
コード例 #8
0
		public void SetSchematicInmemoryDiagram(ISchematicInMemoryDiagram SchMemoryDiag)
		{
			m_schematicInMemoryDiagram = SchMemoryDiag;
		}
コード例 #9
0
        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;
        }
コード例 #10
0
 private ISchematicInMemoryFeatureClass GetSchematicInMemoryFeatureClass(ISchematicInMemoryDiagram inMemoryDiagram, ISchematicElementClass eltClass)
 {
     ISchematicInMemoryFeatureClassContainer SchInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram;
     return SchInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(eltClass);
 }
コード例 #11
0
        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;
        }
コード例 #12
0
        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;
        }
コード例 #13
0
        private ISchematicInMemoryFeatureClass GetSchematicInMemoryFeatureClass(ISchematicInMemoryDiagram inMemoryDiagram, ISchematicElementClass eltClass)
        {
            ISchematicInMemoryFeatureClassContainer SchInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram;

            return(SchInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(eltClass));
        }
コード例 #14
0
		public void Init(ISchematicLayer schematicLayer)
		{
			// CR229717: Lost the ElementClass if the dockable window is deactivate
			if (schematicLayer == m_schematicLayer)
				if (m_schEltClass != null)
					return;

			try
			{
				if (schematicLayer == null)
					return;

				m_schematicLayer = schematicLayer;
				XmlNode col = null;
				String myString = "";

				m_schDataset = schematicLayer.SchematicDiagram.SchematicDiagramClass.SchematicDataset;

				m_schEltClassCont = (ISchematicElementClassContainer)m_schDataset;
				m_SchematicInMemoryDiagram = schematicLayer.SchematicInMemoryDiagram;

				m_dom = new XmlDocument();

				ISchematicDiagram schematicDiagram;
				schematicDiagram = m_SchematicInMemoryDiagram.SchematicDiagram;

				// get the path of the xml file that contains the definitions of the digitize dockable window
				String path;

				ISchematicDiagramClass schematicDiagramClass = schematicDiagram.SchematicDiagramClass;
				ISchematicAttributeContainer schematicAttributeContainer = (ISchematicAttributeContainer)schematicDiagramClass;

				ISchematicAttribute schematicAttribute = schematicAttributeContainer.GetSchematicAttribute("DigitizePropertiesLocation", true);

				if (schematicAttribute == null)
				{
					System.Windows.Forms.MessageBox.Show("Need an attribute named DigitizePropertiesLocation in the corresponding DiagramTemplate attributes");
					return;
				}

				path = (string)schematicAttribute.GetValue((ISchematicObject)schematicDiagram);

				if (IsRelative(path)) //Concat the workspace's path with this path
				{
					//current workspace path
					ISchematicDataset myDataset = schematicDiagramClass.SchematicDataset;
					if (myDataset != null)
					{
						ISchematicWorkspace mySchematicWorkspace = myDataset.SchematicWorkspace;
						if (mySchematicWorkspace != null)
						{
							ESRI.ArcGIS.Geodatabase.IWorkspace myWorkspace = mySchematicWorkspace.Workspace;
							if (myWorkspace != null)
							{
								string workspacePath = myWorkspace.PathName;
								//add "..\" to path to step back one level...
								string stepBack = "..\\";
								path = stepBack + path;

								path = System.IO.Path.Combine(workspacePath, path);
							}
						}
					}
				}
				//else keep the original hard path

				XmlReader reader = XmlReader.Create(path);

				m_dom.Load(reader);

				//Load Nodes
				XmlNodeList nodes = m_dom.SelectNodes("descendant::NodeFeature");

				//Clear combo box after each call
				cboNodeType.Items.Clear();
				foreach (XmlElement node in nodes)
				{
					cboNodeType.Items.Add(node.GetAttribute("FeatureClassName").ToString());
				}


				//Load Links
				XmlNodeList links = m_dom.SelectNodes("descendant::LinkFeature");

				//Clear combo box after each call
				cboLinkType.Items.Clear();
				foreach (XmlElement link in links)
				{
					cboLinkType.Items.Add(link.GetAttribute("FeatureClassName").ToString());
				}

				col = m_dom.SelectSingleNode("descendant::MandatoryColor");
				if (col != null)
				{
					myString = "System.Drawing.";
					myString = col.InnerText.ToString();
					m_MandatoryColor = System.Drawing.Color.FromName(myString);
				}

				col = m_dom.SelectSingleNode("descendant::FormName");
				if (col != null)
				{
					myString = col.InnerText.ToString();
					Text = myString;
				}


				XmlNodeList rels = m_dom.SelectNodes("descendant::Relation");
				if (rels.Count > 0)
					m_relations = rels;

				col = m_dom.SelectSingleNode("descendant::AutoClearAfterCreate");
				if ((col != null) && col.InnerText.ToString() == "True")
					m_autoClear = true;

			}
			catch (System.Exception e)
			{
				System.Windows.Forms.MessageBox.Show(e.Message);
			}

			m_Panel1 = Splitter.Panel1;
			m_Panel2 = Splitter.Panel2;
			m_curPanel = Splitter.Panel1;
			lblMode.Text = "Create Node";
			m_loading = false;
			m_clickPanel = false;
			m_schEltClass = null;

		}
コード例 #15
0
        // The execute part of the algorithm
        private void InternalExecute(ISchematicLayer schematicLayer, ISchematicInMemoryDiagram inMemoryDiagram, ITrackCancel CancelTracker)
        {
            if (schematicLayer == null || inMemoryDiagram == null)
                return;

            // get the diagram spatial reference for geometry transformation
            IGeoDataset geoDataset = (IGeoDataset)inMemoryDiagram;
            if (geoDataset == null)
                return;

            ISpatialReference spatialReference = geoDataset.SpatialReference;

            ISchematicDiagramClass diagramClass;
            diagramClass = inMemoryDiagram.SchematicDiagramClass;
            if (diagramClass == null)
                return;

            ISchematicDataset schemDataset;
            schemDataset = diagramClass.SchematicDataset;
            if (schemDataset == null)
                return;

            ISchematicAlgorithmEventsTrigger algorithmEventsTrigger;
            algorithmEventsTrigger = (ISchematicAlgorithmEventsTrigger)schemDataset;
            if (algorithmEventsTrigger == null)
                return;

            ESRI.ArcGIS.Carto.ILayer layer = (ESRI.ArcGIS.Carto.ILayer)schematicLayer;
            ISchematicAlgorithm algorithm = (ISchematicAlgorithm)this;

            bool canExecute = true;
            algorithmEventsTrigger.FireBeforeExecuteAlgorithm(layer, algorithm, ref canExecute);
            if (!canExecute)
                return; // cannot execute

            // Get the selected Features
            IEnumSchematicFeature enumFeatures = schematicLayer.GetSchematicSelectedFeatures(true);
            if (enumFeatures == null)
                return;

            // Count the selected nodes
            ISchematicInMemoryFeatureClass inMemoryFeatureClass;
            ISchematicFeature selectedFeature = null;
            int iCount = 0;
            ISchematicFeature schemFeature;
            enumFeatures.Reset();
            schemFeature = enumFeatures.Next();
            while (schemFeature != null && iCount < 2)
            {
                // just want SchematicFeatureNode
                inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)schemFeature.Class;

                if (inMemoryFeatureClass.SchematicElementClass.SchematicElementType == esriSchematicElementType.esriSchematicNodeType)
                {
                    selectedFeature = schemFeature;
                    iCount++;
                }
                schemFeature = enumFeatures.Next();
            }

            if (iCount != 1 || selectedFeature == null)
                return; // must be only one

            // Create a new SchematicAnalystFindConnected algorithm
            ISchematicAnalystFindConnected analystFindConnected = null;

            analystFindConnected = (ISchematicAnalystFindConnected)new SchematicAnalystFindConnected();
            if (analystFindConnected == null)
                return;

            // Modifying parameters value for this SchematicAnalystFindConnected algorithm so that when it is launched the trace result appears a selection set{
            analystFindConnected.SelectLink = true;
            analystFindConnected.SelectNode = true;
            analystFindConnected.UseFlow = false;
            //pAnalystFindConnected.FlowDirection = 1;
            // Execute the algorithm
            analystFindConnected.Execute(schematicLayer, CancelTracker);

            // Retrieving the trace result (if any)
            IEnumSchematicFeature resultFeatures;
            resultFeatures = analystFindConnected.TraceResult;

            // free the schematic analyst COM object
            while (System.Runtime.InteropServices.Marshal.ReleaseComObject(analystFindConnected) > 0) { }

            if (resultFeatures == null || resultFeatures.Count < 1)
                return;

            // Apply the translation to the result
            //ISchematicInMemoryDiagram inMemoryDiagram;
            //inMemoryDiagram = schematicLayer.SchematicInMemoryDiagram;

            // Translating each traced elements according to the TranslationFactorX and TranslationFactorY parameters current values
            ISchematicInMemoryFeature inMemoryFeature;
            resultFeatures.Reset();
            while ((inMemoryFeature = (ISchematicInMemoryFeature)resultFeatures.Next()) != null)
            {
                IGeometry geometry;
                ITransform2D transform;
                esriSchematicElementType elemType;

                inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)inMemoryFeature.Class;
                elemType = inMemoryFeatureClass.SchematicElementClass.SchematicElementType;
                if (elemType == esriSchematicElementType.esriSchematicLinkType || elemType == esriSchematicElementType.esriSchematicNodeType)
                {
                    // get a copy of the feature geometry
                    // then process the cloned geometry rather than the feature geometry directly
                    // Thus the modifications are stored in the heap of the current operation
                    // meaning it can be undone then redo (undo/redo)
                    geometry = inMemoryFeature.ShapeCopy;
                    // Convert the geometry into the SpatialReference of diagram class
                    geometry.Project(spatialReference);
                    // Move the geometry
                    transform = (ITransform2D)geometry;
                    if (transform != null)
                    {
                        transform.Move(m_paramX, m_paramY);

                        // Convert the moved geometry into the spatial reference of storage
                        // and feed it back to the feature
                        IObjectClass table = inMemoryFeature.Class;
                        if (table == null)
                            continue;

                        IGeoDataset featureGeoDataset = (IGeoDataset)table;
                        if (featureGeoDataset == null)
                            continue;

                        ISpatialReference featureSpatialRef = featureGeoDataset.SpatialReference;
                        if (featureSpatialRef == null)
                            continue;

                        IGeometry movedGeometry = (IGeometry)transform;
                        movedGeometry.Project(featureSpatialRef);


                        inMemoryFeature.Shape = movedGeometry;
                    }
                }
            }

            // After Execute part
            algorithmEventsTrigger.FireAfterExecuteAlgorithm(layer, algorithm);

            // update the diagram extent
            schematicLayer.UpdateExtent();
        }
コード例 #16
0
        // The execute part of the algorithm
        private void InternalExecute(ISchematicLayer schematicLayer, ISchematicInMemoryDiagram inMemoryDiagram, ITrackCancel CancelTracker)
        {
            if (schematicLayer == null || inMemoryDiagram == null)
            {
                return;
            }

            // get the diagram spatial reference for geometry transformation
            IGeoDataset geoDataset = (IGeoDataset)inMemoryDiagram;

            if (geoDataset == null)
            {
                return;
            }

            ISpatialReference spatialReference = geoDataset.SpatialReference;

            ISchematicDiagramClass diagramClass;

            diagramClass = inMemoryDiagram.SchematicDiagramClass;
            if (diagramClass == null)
            {
                return;
            }

            ISchematicDataset schemDataset;

            schemDataset = diagramClass.SchematicDataset;
            if (schemDataset == null)
            {
                return;
            }

            ISchematicAlgorithmEventsTrigger algorithmEventsTrigger;

            algorithmEventsTrigger = (ISchematicAlgorithmEventsTrigger)schemDataset;
            if (algorithmEventsTrigger == null)
            {
                return;
            }

            ESRI.ArcGIS.Carto.ILayer layer     = (ESRI.ArcGIS.Carto.ILayer)schematicLayer;
            ISchematicAlgorithm      algorithm = (ISchematicAlgorithm)this;

            bool canExecute = true;

            algorithmEventsTrigger.FireBeforeExecuteAlgorithm(layer, algorithm, ref canExecute);
            if (!canExecute)
            {
                return; // cannot execute
            }
            // Get the selected Features
            IEnumSchematicFeature enumFeatures = schematicLayer.GetSchematicSelectedFeatures(true);

            if (enumFeatures == null)
            {
                return;
            }

            // Count the selected nodes
            ISchematicInMemoryFeatureClass inMemoryFeatureClass;
            ISchematicFeature selectedFeature = null;
            int iCount = 0;
            ISchematicFeature schemFeature;

            enumFeatures.Reset();
            schemFeature = enumFeatures.Next();
            while (schemFeature != null && iCount < 2)
            {
                // just want SchematicFeatureNode
                inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)schemFeature.Class;

                if (inMemoryFeatureClass.SchematicElementClass.SchematicElementType == esriSchematicElementType.esriSchematicNodeType)
                {
                    selectedFeature = schemFeature;
                    iCount++;
                }
                schemFeature = enumFeatures.Next();
            }

            if (iCount != 1 || selectedFeature == null)
            {
                return; // must be only one
            }
            // Create a new SchematicAnalystFindConnected algorithm
            ISchematicAnalystFindConnected analystFindConnected = null;

            analystFindConnected = (ISchematicAnalystFindConnected) new SchematicAnalystFindConnected();
            if (analystFindConnected == null)
            {
                return;
            }

            // Modifying parameters value for this SchematicAnalystFindConnected algorithm so that when it is launched the trace result appears a selection set{
            analystFindConnected.SelectLink = true;
            analystFindConnected.SelectNode = true;
            analystFindConnected.UseFlow    = false;
            //pAnalystFindConnected.FlowDirection = 1;
            // Execute the algorithm
            analystFindConnected.Execute(schematicLayer, CancelTracker);

            // Retrieving the trace result (if any)
            IEnumSchematicFeature resultFeatures;

            resultFeatures = analystFindConnected.TraceResult;

            // free the schematic analyst COM object
            while (System.Runtime.InteropServices.Marshal.ReleaseComObject(analystFindConnected) > 0)
            {
            }

            if (resultFeatures == null || resultFeatures.Count < 1)
            {
                return;
            }

            // Apply the translation to the result
            //ISchematicInMemoryDiagram inMemoryDiagram;
            //inMemoryDiagram = schematicLayer.SchematicInMemoryDiagram;

            // Translating each traced elements according to the TranslationFactorX and TranslationFactorY parameters current values
            ISchematicInMemoryFeature inMemoryFeature;

            resultFeatures.Reset();
            while ((inMemoryFeature = (ISchematicInMemoryFeature)resultFeatures.Next()) != null)
            {
                IGeometry                geometry;
                ITransform2D             transform;
                esriSchematicElementType elemType;

                inMemoryFeatureClass = (ISchematicInMemoryFeatureClass)inMemoryFeature.Class;
                elemType             = inMemoryFeatureClass.SchematicElementClass.SchematicElementType;
                if (elemType == esriSchematicElementType.esriSchematicLinkType || elemType == esriSchematicElementType.esriSchematicNodeType)
                {
                    // get a copy of the feature geometry
                    // then process the cloned geometry rather than the feature geometry directly
                    // Thus the modifications are stored in the heap of the current operation
                    // meaning it can be undone then redo (undo/redo)
                    geometry = inMemoryFeature.ShapeCopy;
                    // Convert the geometry into the SpatialReference of diagram class
                    geometry.Project(spatialReference);
                    // Move the geometry
                    transform = (ITransform2D)geometry;
                    if (transform != null)
                    {
                        transform.Move(m_paramX, m_paramY);

                        // Convert the moved geometry into the spatial reference of storage
                        // and feed it back to the feature
                        IObjectClass table = inMemoryFeature.Class;
                        if (table == null)
                        {
                            continue;
                        }

                        IGeoDataset featureGeoDataset = (IGeoDataset)table;
                        if (featureGeoDataset == null)
                        {
                            continue;
                        }

                        ISpatialReference featureSpatialRef = featureGeoDataset.SpatialReference;
                        if (featureSpatialRef == null)
                        {
                            continue;
                        }

                        IGeometry movedGeometry = (IGeometry)transform;
                        movedGeometry.Project(featureSpatialRef);


                        inMemoryFeature.Shape = movedGeometry;
                    }
                }
            }

            // After Execute part
            algorithmEventsTrigger.FireAfterExecuteAlgorithm(layer, algorithm);

            // update the diagram extent
            schematicLayer.UpdateExtent();
        }
コード例 #17
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;
        }
コード例 #18
0
        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;
        }