public static bool AddBarrier(IPoint pPnt, IApplication app, double snapTol, bool showDialog)
{
IProgressDialogFactory pProDFact = null;
IStepProgressor pStepPro = null;
IProgressDialog2 pProDlg = null;
ITrackCancel pTrkCan = null;
List<IGeometricNetwork> gnList = null;
IGeometricNetwork gn = null;
IPoint snappedPoint = null;
IFlagDisplay pFlagDisplay = null;
INetFlag startNetFlag = null;
INetworkAnalysisExt pNetAnalysisExt = null;
UID pID = null;
IMap pMap = null;
int EID = -1;
double distanceAlong;
try
{
pMap = (app.Document as IMxDocument).FocusMap;
bool boolCont = true;
if (showDialog)
{
// Create a CancelTracker
pTrkCan = new CancelTrackerClass();
// Create the ProgressDialog. This automatically displays the dialog
pProDFact = new ProgressDialogFactoryClass();
pProDlg = (IProgressDialog2)pProDFact.Create(pTrkCan, 0);
// Set the properties of the ProgressDialog
pProDlg.CancelEnabled = true;
pProDlg.Animation = esriProgressAnimationTypes.esriProgressGlobe;
// Set the properties of the Step Progressor
pStepPro = (IStepProgressor)pProDlg;
pStepPro.MinRange = 0;
pStepPro.MaxRange = 6;
pStepPro.StepValue = 1;
pStepPro.Position = 0;
pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_4");
}
gnList = Globals.GetGeometricNetworksCurrentlyVisible(ref pMap);
int gnIdx = -1;
if (gnList == null || gnList.Count == 0)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_2"), A4LGSharedFunctions.Localizer.GetString("GeoNetToolsErrorLbl_2"));
return false;
}
if (showDialog)
{
// Create junction or edge flag at start of trace - also returns geometric network, snapped point, and EID of junction
pStepPro.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_6");
pStepPro.Step();
boolCont = pTrkCan.Continue();
if (!boolCont)
{
pStepPro.Hide();
pProDlg.HideDialog();
pStepPro = null;
pProDlg = null;
pProDFact = null;
return true;
}
}
startNetFlag = Globals.GetJunctionFlag(ref pPnt, ref pMap, ref gnList, snapTol, ref gnIdx, out snappedPoint, out EID, out pFlagDisplay, false) as INetFlag;
if (startNetFlag == null)
{
startNetFlag = Globals.GetEdgeFlag(ref pPnt, ref pMap, ref gnList, snapTol, ref gnIdx, out snappedPoint, out EID, out distanceAlong, out pFlagDisplay, false) as INetFlag;
}
//Set network to trace
if (gnIdx > -1)
gn = gnList[gnIdx] as IGeometricNetwork;
// Stop if user point was not on a visible network feature, old trace results and selection are cleared
if (gn == null || startNetFlag == null)
{
return true;
}
if (app != null)
{
pID = new UID();
pID.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
pNetAnalysisExt = (INetworkAnalysisExt)app.FindExtensionByCLSID(pID);
Globals.SetCurrentNetwork(ref pNetAnalysisExt, ref gn);
Globals.AddBarrierToGN(pNetAnalysisExt, gn, pFlagDisplay);
// pFlagDisplay
pNetAnalysisExt = null;
pID = null;
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_3") + ": " + ex.ToString());
return false;
}
finally
{
if (showDialog)
{
if (pProDlg != null)
{
pProDlg.HideDialog();
}
pStepPro = null;
pProDlg = null;
pProDFact = null;
pTrkCan = null;
}
pMap = null;
gnList = null;
gn = null;
snappedPoint = null;
pFlagDisplay = null;
startNetFlag = null;
pNetAnalysisExt = null;
pID = null;
pMap = null;
}
}