Esempio n. 1
0
        private bool TraceIsolating(string sOID, string sSelect)
        {
            IFeature pFeat;
            INetworkClass NetCLS;
            IGeometricNetwork pGN;
            ISimpleJunctionFeature pJuncFeat;
            Miner.Interop.IMMElectricTracingEx pElecTrace;
            Miner.Interop.IMMElectricTraceSettings pElecTraceSettings;
            IMMTracedElements pJunctions;
            IMMTracedElements pEdges;
            IMMCurrentStatus pCurrentStatus;
            int[] iJunctionBarriers;
            int[] iEdgeBarriers;

            iJunctionBarriers = new int[0];
            iEdgeBarriers = new int[0];
            pCurrentStatus = null;
            try
            {
                pElecTrace = new MMFeederTracerClass();

                pElecTraceSettings = new Miner.Interop.MMElectricTraceSettingsClass();
                pElecTraceSettings.RespectConductorPhasing = false;
                pElecTraceSettings.RespectEnabledField = false;

                SW1.Reset();
                SW1.Start();
                try
                {
                    if (FeatureClass is INetworkClass)
                    {
                        NetCLS = (INetworkClass)FeatureClass;
                        pGN = NetCLS.GeometricNetwork;
                        pFeat = FeatureClass.GetFeature(Convert.ToInt32(sOID));
                        if (pFeat is IJunctionFeature)
                        {
                            pJuncFeat = (ISimpleJunctionFeature)pFeat;

                            pElecTrace.TraceDownstream(pGN, pElecTraceSettings, pCurrentStatus,
                                pJuncFeat.EID, ESRI.ArcGIS.Geodatabase.esriElementType.esriETJunction,
                                Miner.Interop.SetOfPhases.abc, Miner.Interop.mmDirectionInfo.establishBySourceSearch, 0,
                                ESRI.ArcGIS.Geodatabase.esriElementType.esriETEdge, iJunctionBarriers,
                                iEdgeBarriers, false, out pJunctions, out pEdges);
                        }
                    }
                    SW1.Stop();
                    RecordActionTime("TraceIsolating Execution Time:",SW1.ElapsedMilliseconds);
                    return true;
                }
                catch (Exception EX)
                {
                    this.Logger.WriteLine("TraceDownStream Failed: " + EX.Message);
                    return false;
                }
            }
            catch (Exception EX)
            {
                this.Logger.WriteLine("TraceDownStream Failed: " + EX.Message);
                return false;
            }
        }
Esempio n. 2
0
        private bool ArcFMTrace(string sOID, string sSelect, int iTraceType)
        {
            IFeature pFeat;
            INetworkClass NetCLS;
            IGeometricNetwork pGN;
            ISimpleJunctionFeature pJuncFeat;
            Miner.Interop.IMMElectricTracingEx pElecTrace;
            Miner.Interop.IMMElectricTraceSettings pElecTraceSettings;
            IMMTracedElements pJunctions;
            IMMTracedElements pEdges;
            IMMCurrentStatus pCurrentStatus;
            IMMEnumFeedPath pFeedPaths;
            int[] iJunctionBarriers;
            int[] iEdgeBarriers;
            IApplication pApp;
            IMxDocument pMXDoc;
            IObjectClass pOC;
            ISelection pSel;
            SelectedObjects pSelObjs;
            IDictionary<int, SelectedObjects> dicClasses;
            int iSelectionCount;
            ESRI.ArcGIS.Geodatabase.esriElementType pElemType;
            int iEID;
            IEdgeFeature pEdge;
            IMMEnumTraceStopper pStopperJunctions;
            IMMEnumTraceStopper pStopperEdges;

            iJunctionBarriers = new int[0];
            iEdgeBarriers = new int[0];
            pCurrentStatus = null;
            iSelectionCount = 0;
            try
            {
                pElecTrace = new MMFeederTracerClass();

                pElecTraceSettings = new Miner.Interop.MMElectricTraceSettingsClass();
                pElecTraceSettings.RespectConductorPhasing = true;
                pElecTraceSettings.RespectEnabledField = false;

                SW1.Reset();
                SW1.Start();
                try
                {
                    if (FeatureClass is INetworkClass)
                    {
                        Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
                        System.Object obj = Activator.CreateInstance(t);
                        pApp = obj as IApplication;
                        pMXDoc = (IMxDocument)pApp.Document;
                        pSel = pMXDoc.FocusMap.FeatureSelection;

                        NetCLS = (INetworkClass)FeatureClass;
                        pGN = NetCLS.GeometricNetwork;
                        dicClasses = GetClassIDs(pGN);
                        pFeat = FeatureClass.GetFeature(Convert.ToInt32(sOID));
                        if (pFeat is IJunctionFeature)
                        {
                            pElemType = ESRI.ArcGIS.Geodatabase.esriElementType.esriETJunction;
                            pJuncFeat = (ISimpleJunctionFeature)pFeat;
                            iEID = pJuncFeat.EID;
                        }
                        else
                        {
                            pElemType = ESRI.ArcGIS.Geodatabase.esriElementType.esriETEdge;
                            pEdge = (IEdgeFeature)pFeat;
                            iEID = pEdge.FromJunctionEID;
                        }

                        pOC = (IObjectClass)pFeat.Class;
                        if (dicClasses.TryGetValue(pOC.ObjectClassID, out pSelObjs))
                        {
                            try
                            {
                                //pSelObjs.SelectionSet.Add(pFeat.OID);
                            }
                            catch (Exception EX2)
                            {
                                this.Logger.WriteLine("ArcFMTrace Error" + EX2.Message + " " + EX2.StackTrace);

                                Logger.WriteLine("Error adding Breaker:" + pFeat.OID);
                            }
                        }

                        //Down Stream
                        if (iTraceType == 1)
                        {
                            pElecTrace.TraceDownstream(pGN, pElecTraceSettings, pCurrentStatus,
                                iEID, pElemType, Miner.Interop.SetOfPhases.abc, Miner.Interop.mmDirectionInfo.establishBySourceSearch, 0,
                                ESRI.ArcGIS.Geodatabase.esriElementType.esriETEdge, iJunctionBarriers,
                                iEdgeBarriers, false, out pJunctions, out pEdges);
                            Logger.WriteLine("Edges Found:" + pEdges.Count);
                            Logger.WriteLine("Junctions Found:" + pJunctions.Count);
                            iSelectionCount = pEdges.Count + pJunctions.Count;
                            if (sSelect.ToUpper() == "TRUE")
                            {
                                SelectFeatures(pEdges, pJunctions, pGN.Network, true);
                            }
                            else
                            {
                                SelectFeatures(pEdges, pJunctions, pGN.Network, false);
                            }
                        }
                        //Up Stream
                        else if (iTraceType == 2)
                        {
                            try
                            {
                                pElecTrace.FindFeedPaths(pGN, pElecTraceSettings, pCurrentStatus,
                                    iEID, pElemType, Miner.Interop.SetOfPhases.abc, iJunctionBarriers,
                                    iEdgeBarriers, out pFeedPaths, out pStopperJunctions, out pStopperEdges);
                                if (pFeedPaths == null)
                                {
                                    iSelectionCount = 0;
                                }
                                else
                                {
                                    iSelectionCount = pFeedPaths.Count;
                                    Logger.WriteLine("Paths:" + pFeedPaths.Count);
                                    IMMFeedPathEx pFeedPath;
                                    IMMEnumPathElement pEPathElem;

                                    pFeedPath = pFeedPaths.Next();
                                    while (pFeedPath != null)
                                    {
                                        pEPathElem = pFeedPath.GetPathElementEnum();
                                        iSelectionCount = iSelectionCount + pEPathElem.Count;
                                        pFeedPath = pFeedPaths.Next();
                                    }
                                }

                                Logger.WriteLine("Count:" + iSelectionCount);
                                if (sSelect.ToUpper() == "TRUE")
                                {
                                    //pFeedPath
                                    //SelectFeatures((IMMTracedElements)pStopperEdges, (IMMTracedElements)pStopperJunctions, pGN.Network, true);
                                }
                                else
                                {
                                    //SelectFeatures((IMMTracedElements)pStopperEdges, (IMMTracedElements)pStopperJunctions, pGN.Network, false);
                                }
                            }
                            catch (Exception EX2)
                            {
                                this.Logger.WriteLine("TraceUpStream Failed: " + EX2.Message + ": " + EX2.StackTrace);
                                return false;
                            }
                        }
                        else
                        {
                            try
                            {
                                MMFeederTracerClass pFTC;
                                IMMNetworkAnalysisExtForFramework pMMNetExt;
                                pFTC = new MMFeederTracerClass();
                                pMMNetExt = new MMNetworkAnalysisExtForFrameworkClass();
                                IEnumNetEID pJunctionsEID;
                                IEnumNetEID pEdgesEID;

                                Miner.Interop.IMMElectricTraceSettingsEx pElecTraceSettingsEX;
                                pElecTraceSettingsEX = new Miner.Interop.MMElectricTraceSettingsClass();
                                pElecTraceSettingsEX.RespectEnabledField = false;
                                pElecTraceSettingsEX.RespectESRIBarriers = false;
                                pElecTraceSettingsEX.UseFeederManagerCircuitSources = true;
                                pElecTraceSettingsEX.UseFeederManagerProtectiveDevices = true;

                                pFTC.DistributionCircuitTrace(pGN, pMMNetExt, pElecTraceSettingsEX, iEID, pElemType, mmPhasesToTrace.mmPTT_AnySinglePhase, out pJunctionsEID, out pEdgesEID);
                                iSelectionCount = 0;
                                if (pJunctionsEID != null)
                                {
                                    iSelectionCount = pJunctionsEID.Count;
                                }
                                if (pEdgesEID != null)
                                {
                                    iSelectionCount = iSelectionCount + pEdgesEID.Count;
                                }
                                Logger.WriteLine("Found:" + iSelectionCount);
                                UID uid = new UIDClass();
                                uid.Value = "esriNetworkAnalystUI.NetworkAnalystExtension"; //ESRI Network Analyst extension
                                //IExtension ext = extMgr.FindExtension(uid);
                                IExtension ext = pApp.FindExtensionByCLSID(uid);
                                if (ext != null)
                                {
                                    IUtilityNetworkAnalysisExt utilityNetworkAnalystExt = ext as IUtilityNetworkAnalysisExt;
                                    if (utilityNetworkAnalystExt != null)
                                    {
                                        INetworkAnalysisExtResults networkAnalysisResults = (INetworkAnalysisExtResults)utilityNetworkAnalystExt;
                                        if (networkAnalysisResults != null)
                                        {
                                            networkAnalysisResults.ClearResults();
                                            networkAnalysisResults.SetResults(pJunctionsEID, pEdgesEID);
                                            //determine if results should be drawn

                                            if (sSelect.ToUpper() == "TRUE")
                                            {
                                                networkAnalysisResults.ResultsAsSelection = true;
                                                networkAnalysisResults.CreateSelection(pJunctionsEID, pEdgesEID);
                                            }
                                            else
                                            {
                                                // temporarily toggle the user's setting
                                                networkAnalysisResults.ResultsAsSelection = true;
                                                networkAnalysisResults.CreateSelection(pJunctionsEID, pEdgesEID);
                                                networkAnalysisResults.ResultsAsSelection = false;
                                            }
                                        }
                                        else
                                        {
                                            this.Logger.WriteLine("NetworkAnalysisResults Null");
                                        }
                                    }
                                    else
                                    {
                                        this.Logger.WriteLine("UtilityNetworkAnalysisExt Null");
                                    }
                                }
                            }
                            catch (Exception EX2)
                            {
                                this.Logger.WriteLine("TraceIsolation Failed: " + EX2.Message + ": " + EX2.StackTrace);
                                return false;
                            }
                        }
                        //AddSelection(pMXDoc, dicClasses);
                        //iSelectionCount = pMXDoc.FocusMap.SelectionCount;
                    }
                    SW1.Stop();
                    if (iTraceType == 1)
                    {
                        RecordActionTime("TraceDownStream Execution Time: (" + iSelectionCount.ToString() + ")" , SW1.ElapsedMilliseconds);
                    }
                    else if (iTraceType == 2)
                    {
                        RecordActionTime("TraceUpStream Execution Time: (" + iSelectionCount.ToString() + ")", SW1.ElapsedMilliseconds);
                    }
                    else
                    {
                        RecordActionTime("TraceIsolating Execution Time: (" + iSelectionCount.ToString() + ")", SW1.ElapsedMilliseconds);
                    }
                    pMXDoc = GetDoc();
                    pMXDoc.ActiveView.Refresh();
                    return true;
                }
                catch (Exception EX)
                {
                    this.Logger.WriteLine("TraceDownStream Failed: " + EX.Message + ": " + EX.StackTrace);
                    return false;
                }
            }
            catch (Exception EX)
            {
                this.Logger.WriteLine("TraceDownStream Failed: " + EX.Message);
                return false;
            }
        }