public static void AddFlagsForSewerProfile(IApplication app, double snapTol, List<ProfileGraphDetails> ProfileGraph)
{
IFeatureCursor pFeatCursor = null;
IMxDocument pMxDoc = null;
IPoint pTracePoint = null;
ISpatialFilter pSpatialFilter = null;
// set the symbol for the flag, red circle
IMarkerSymbol pMarkerSym = null;
IRgbColor pRGBColor = null;
IFeatureLayer pManholeLayer = null;
IFeatureLayer pMainLayer = null;
IFeatureLayer pTapLayer = null;
IGraphicsContainer gc = null;
IElement pProfileElemFirst = null;
IElementProperties3 pProfileElemPropFirst = null;
IElement element = null;
IElementProperties3 elementProp = null;
ITopologicalOperator pTopoOp = null;
IFeature pFeature = null;
double snapdistnet; // NetworkExt search tolerance
IPolygon pBuffGeometry = null;
IMarkerElement markerelem = null;
IGeometricNetwork gn = null;
IEnumNetEID juncEIDs = null;
IEnumNetEID edgeEIDs = null;
try
{
pMxDoc = ((IMxDocument)app.Document);
pTracePoint = pMxDoc.CurrentLocation;
pMarkerSym = Globals.FindMarkerSym("Esri.style", "Default", "Circle 2", pMxDoc);
pRGBColor = Globals.GetColor(255, 0, 0);
pMarkerSym.Color = pRGBColor;
pMarkerSym.Size = 11;
gc = pMxDoc.FocusMap as IGraphicsContainer;
pProfileElemFirst = null;
pProfileElemPropFirst = null;
gc.Reset();
element = gc.Next();
while (element != null)
{
elementProp = element as IElementProperties3;
if (elementProp.Name.Contains("ProfileGraphFlag"))
{
if (pProfileElemFirst == null)
{
pProfileElemFirst = element;
pProfileElemPropFirst = elementProp;
break;
}
}
element = gc.Next();
}
for (int i = 0; i < ProfileGraph.Count; i++)
{
if (pProfileElemFirst != null)
{
if (!pProfileElemPropFirst.Name.Contains(ProfileGraph[i].Network_Name))
{
//MessageBox.Show("The network (" + ProfileGraph[i].Network_Name + ") was not found, please update the config to make the name of the layer in the mxd");
continue;
}
}
bool FCorLayerManhole = true;
pManholeLayer = (IFeatureLayer)Globals.FindLayer(pMxDoc.FocusMap, ProfileGraph[i].Point_LayerName, ref FCorLayerManhole);
if (pManholeLayer == null)
{
// MessageBox.Show("The point layer (" + ProfileGraph[i].Point_LayerName + ") was not found, please update the config to make the name of the layer in the mxd");
continue;
}
bool FCorLayerMain = true;
pMainLayer = (IFeatureLayer)Globals.FindLayer(pMxDoc.FocusMap, ProfileGraph[i].Line_LayerName, ref FCorLayerMain);
if (pMainLayer == null)
{
// MessageBox.Show("The Main layer (" + ProfileGraph[i].Line_LayerName + ") was not found, please update the config to make the name of the layer in the mxd");
continue;
}
bool FCorLayerTap = true;
if (ProfileGraph[i].PointAlong_LayerName != "")
{
pTapLayer = (IFeatureLayer)Globals.FindLayer(pMxDoc.FocusMap, ProfileGraph[i].PointAlong_LayerName, ref FCorLayerTap);
}
else
pTapLayer = null;
// make sure a manhole was selected
// buffer the point by the snap tolerance, this is faster than checking
//the flag to see if it is on a manhole
pTopoOp = (ITopologicalOperator)pTracePoint; // QI
snapdistnet = Globals.ConvertPixelsToMap(snapTol, pMxDoc.FocusMap);
pBuffGeometry = (IPolygon)pTopoOp.Buffer(snapdistnet);
// get the feature the user clicked to be sure it's a manhole
pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pBuffGeometry;
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;
pFeatCursor = pManholeLayer.Search(pSpatialFilter, true);
// there is a layer definition set to show only manholes, cursor
// will return nothing if user didn't click on a manhole
pFeature = pFeatCursor.NextFeature();
if (pFeature != null)
{
pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pBuffGeometry.Envelope);
markerelem = new MarkerElementClass();
markerelem.Symbol = pMarkerSym;
element = (IElement)markerelem;
element.Geometry = pFeature.ShapeCopy;
elementProp = element as IElementProperties3;
elementProp.Name = "ProfileGraphFlag-" + ProfileGraph[i].Network_Name;
elementProp.ReferenceScale = pMxDoc.FocusMap.ReferenceScale;
gc.AddElement(element, 0);
if (pProfileElemFirst == null)
return;
else
{
ESRI.ArcGIS.esriSystem.IStatusBar statusBar = null;
ESRI.ArcGIS.esriSystem.IAnimationProgressor animationProgressor = null;
ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = null;
ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null;
ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null;
ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = null;
statusBar = app.StatusBar;
animationProgressor = statusBar.ProgressAnimation;
animationProgressor.Show();
animationProgressor.Play(0, -1, -1);
statusBar.set_Message(0, A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_19a"));
// Create a CancelTracker
trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();
progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();
// Set the properties of the Step Progressor
System.Int32 int32_hWnd = app.hWnd;
stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
stepProgressor.MinRange = 0;
stepProgressor.MaxRange = 3;
stepProgressor.StepValue = 1;
stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDesc_19a");
// Create the ProgressDialog. This automatically displays the dialog
progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast
// Set the properties of the ProgressDialog
progressDialog2.CancelEnabled = true;
progressDialog2.Description = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDesc_19a");
progressDialog2.Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsTitle_19a");
progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
// Step. Do your big process here.
System.Boolean boolean_Continue = false;
boolean_Continue = true;
stepProgressor.Step();
GeoNetTools.TracePath(new double[] { (pProfileElemFirst.Geometry as IPoint).X, (element.Geometry as IPoint).X },
new double[] { (pProfileElemFirst.Geometry as IPoint).Y, (element.Geometry as IPoint).Y },
ProfileGraph[i].Network_Name, app, pMxDoc.FocusMap, true, snapTol, true, out juncEIDs, out edgeEIDs, out gn);
boolean_Continue = trackCancel.Continue();
if (!boolean_Continue)
{
return;
}
stepProgressor.Step();
stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_19a");
if (juncEIDs != null && edgeEIDs != null)
{
GeoNetTools.ProfileGetRelatedElevData(app, ProfileGraph, gn, edgeEIDs, juncEIDs, i, ref pManholeLayer, ref pMainLayer, ref pTapLayer);
}
else
{
}
//ProfileFindPath();
// unpress the UIToolControl button
app.CurrentTool = null;
app.RefreshWindow();
progressDialog2.HideDialog();
progressDialog2 = null;
return;
}
}
else//Next Layer in the config
{
}
}
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19a"));
}
catch (Exception Ex)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + "AddFlagsForSewerProfile " + Ex.Message);
}
finally
{
if (pFeatCursor != null)
{
Marshal.ReleaseComObject(pFeatCursor);
}
pMxDoc.ActiveView.Refresh();
pFeatCursor = null;
pMxDoc = null;
pTracePoint = null;
pSpatialFilter = null;
// set the symbol for the flag, red circle
pMarkerSym = null;
pRGBColor = null;
pManholeLayer = null;
pMainLayer = null;
pTapLayer = null;
gc = null;
pProfileElemFirst = null;
pProfileElemPropFirst = null;
element = null;
elementProp = null;
pTopoOp = null;
pFeature = null;
pBuffGeometry = null;
markerelem = null;
gn = null;
juncEIDs = null;
edgeEIDs = null;
}
}