public static void MoveConnectionsToNewLine(IApplication app, double snapTol, List<MoveConnectionsDetails> moveConDetails)
{
IEditor editor = null;
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;
ICommandItem pCmdItem;
IMxDocument pMxDoc = ((IMxDocument)app.Document);
IGeometricNetwork pGN = null;
IFeature pFeature = null;
IPoint pTracePoint = null;
ISimpleLineSymbol pSimpleLineSym = null;
IRgbColor pRGBColor = null;
IGraphicsContainer gc = null;
IElement pMoveElemFirst = null;
IElementProperties3 pMoveElemPropFirst = null;
IElement element = null;
IElementProperties3 elementProp = null;
ILineElement lineElem = null;
IJunctionFeature pJuncFeat = null;
IFeatureLayer pSourceLayer = null;
IFeature pSourceFeature = null;
IFeature pMoveFeat = null;
INetworkFeature pNetworkSourceFeature = null;
IEdgeFeature iTargetEdgeFeat = null;
IComplexEdgeFeature iCEdge = null;
IFeatureClass pOraphFC = null;
List<int> OIDs = new List<int>();
List<string> FeatLoc = new List<string>();
List<IObjectClass> FCs = new List<IObjectClass>();
IPolyline pL;
IHitTest pHtTest = null;//= pPolyline as IHitTest;
IPoint pHitPntOne = new PointClass();
double pHitDistOne = -1;
int pHitPrtOne = -1;
int pHitSegOne = -1;
bool pHitSideOne = false;
//IFeatureCursor pFeatCursor = null;
IFeatureLayer pMainLayer = null;
//IFeatureLayer pMainLayer = null;
//IFeatureLayer pTapLayer = null;
ILayer pLay = null;
try
{
editor = Globals.getEditor(ref app);
if (editor.EditState != esriEditState.esriStateEditing)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg"), A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_2"));
return;
}
pTracePoint = pMxDoc.CurrentLocation;
pFeature = Globals.GetNetworkAndFeatureAtLocation(pTracePoint, app, esriElementType.esriETEdge, out pGN, snapTol);
if (pFeature == null)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("NoFtrFndOnClck"));
return;
}
int idxDet = -1;
for (int i = 0; i < moveConDetails.Count; i++)
{
//MoveConnectionsDetails conDet = moveConDetails[i];
bool FCorLayerTemp = true;
pMainLayer = (IFeatureLayer)Globals.FindLayer(app, moveConDetails[i].LineLayer, ref FCorLayerTemp);
if (pMainLayer != null)
{
if (pMainLayer.FeatureClass.ObjectClassID == pFeature.Class.ObjectClassID)
{
idxDet = i;
break;
}
}
}
if (idxDet == -1)
return;
if (Globals.IsEditable(ref pFeature, ref editor) == false)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_13b"));
return;
}
if (pFeature.FeatureType != esriFeatureType.esriFTComplexEdge)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_13c"));
return;
}
pRGBColor = Globals.GetColor(255, 0, 0);
pSimpleLineSym = Globals.CreateSimpleLineSymbol(pRGBColor, 2, esriSimpleLineStyle.esriSLSSolid);
gc = pMxDoc.FocusMap as IGraphicsContainer;
gc.Reset();
element = gc.Next();
while (element != null)
{
elementProp = element as IElementProperties3;
if (elementProp.Name.Contains("MoveFeatureFlag"))
{
if (pMoveElemFirst == null)
{
pMoveElemFirst = element;
pMoveElemPropFirst = elementProp;
string[] firstVals = pMoveElemPropFirst.Name.ToString().Split(':');
if (firstVals[1] != pFeature.Class.ObjectClassID.ToString())
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13a"));
return;
}
break;
}
}
element = gc.Next();
}
lineElem = new LineElementClass();
lineElem.Symbol = pSimpleLineSym;
element = (IElement)lineElem;
element.Geometry = pFeature.ShapeCopy;
elementProp = element as IElementProperties3;
elementProp.Name = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_13a") + ": " + pFeature.Class.ObjectClassID.ToString() + ":" + pFeature.OID;
elementProp.ReferenceScale = pMxDoc.FocusMap.ReferenceScale;
gc.AddElement(element, 0);
pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pFeature.Shape.Envelope);
if (pMoveElemFirst == null)
return;
else
{
List<int> LayersToMoveIDs = new List<int>();
foreach (string Lay in moveConDetails[idxDet].LayersToMove)
{
bool FCorLayerTemp = true;
pLay = Globals.FindLayer(app, Lay, ref FCorLayerTemp);
if (pLay != null)
{
LayersToMoveIDs.Add(((IFeatureLayer)pLay).FeatureClass.ObjectClassID);
}
}
statusBar = app.StatusBar;
animationProgressor = statusBar.ProgressAnimation;
animationProgressor.Show();
animationProgressor.Play(0, -1, -1);
statusBar.set_Message(0, A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13a"));
// 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 = 4;
stepProgressor.StepValue = 1;
stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13a");
// 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("GeoNetToolsProc_13a");
progressDialog2.Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13a");
progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
System.Boolean boolean_Continue = true;
stepProgressor.Step();
boolean_Continue = trackCancel.Continue();
if (!boolean_Continue)
{
return;
}
stepProgressor.Step();
stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_13b");
//ProfileFindPath();
pCmdItem = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOffCommand", app);
if (pCmdItem != null)
{
pCmdItem.Execute();
}
string[] elemInfo = (elementProp = pMoveElemFirst as IElementProperties3).Name.Split(':');
pSourceLayer = Globals.FindLayerByClassID(pMxDoc.FocusMap, elemInfo[1]) as IFeatureLayer;
pSourceFeature = pSourceLayer.FeatureClass.GetFeature(Convert.ToInt32(elemInfo[2]));
pNetworkSourceFeature = (INetworkFeature)pSourceFeature;
iTargetEdgeFeat = (IEdgeFeature)pNetworkSourceFeature;
iCEdge = (pNetworkSourceFeature) as IComplexEdgeFeature;
pOraphFC = pGN.OrphanJunctionFeatureClass;
editor.StartOperation();
pL = pSourceFeature.ShapeCopy as IPolyline;
boolean_Continue = trackCancel.Continue();
if (!boolean_Continue)
{
return;
}
stepProgressor.Step();
stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13b");
for (int i = 0; i < iCEdge.JunctionFeatureCount; i++)
{
pJuncFeat = iCEdge.get_JunctionFeature(i);
if ((pJuncFeat as IFeature).Class.ObjectClassID != pOraphFC.ObjectClassID && LayersToMoveIDs.Contains((pJuncFeat as IFeature).Class.ObjectClassID))
{
if (pL.FromPoint.X == ((pJuncFeat as IFeature).Shape as IPoint).X && pL.FromPoint.Y == ((pJuncFeat as IFeature).Shape as IPoint).Y)
{
FeatLoc.Add("From");
}
else if (pL.ToPoint.X == ((pJuncFeat as IFeature).Shape as IPoint).X && pL.ToPoint.Y == ((pJuncFeat as IFeature).Shape as IPoint).Y)
{
FeatLoc.Add("To");
}
else
{
FeatLoc.Add("Along");
}
OIDs.Add((pJuncFeat as IFeature).OID);
FCs.Add((pJuncFeat as IFeature).Class);
}
}
boolean_Continue = trackCancel.Continue();
if (!boolean_Continue)
{
return;
}
stepProgressor.Step();
stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13c");
pNetworkSourceFeature.Disconnect();
boolean_Continue = trackCancel.Continue();
if (!boolean_Continue)
{
return;
}
stepProgressor.Step();
stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13d");
string msg = "";
List<IFeature> pM = new List<IFeature>();
for (int i = 0; i < OIDs.Count; i++)
{
pMoveFeat = (FCs[i] as IFeatureClass).GetFeature(OIDs[i]);
esriGeometryHitPartType pSearchLoc;
if (FeatLoc[i] == "From" || FeatLoc[i] == "To")
{
pSearchLoc = esriGeometryHitPartType.esriGeometryPartEndpoint;
}
else
{
pSearchLoc = esriGeometryHitPartType.esriGeometryPartBoundary;
}
pHtTest = pFeature.ShapeCopy as IHitTest;
bool bHitOne = pHtTest.HitTest(pMoveFeat.Shape as IPoint, 50, pSearchLoc,
pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne);
if (bHitOne != false)
{
if ((pMoveFeat.Shape as IPoint).Z != null && Globals.IsNumeric((pMoveFeat.Shape as IPoint).Z.ToString()))
pHitPntOne.Z = (pMoveFeat.Shape as IPoint).Z;
pMoveFeat.Shape = pHitPntOne;
pM.Add(pMoveFeat);
try
{
pMoveFeat.Store();
INetworkFeature netFeature = null;
netFeature = pMoveFeat as INetworkFeature;
netFeature.Connect();
}
catch
{
if (msg == "")
{
msg = A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (FCs[i] as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b");
}
else
{
msg = msg + "\n" + A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (FCs[i] as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b");
}
}
}
}
////foreach (IFeature pF in pM)
////{
//// try
//// {
//// pF.Store();
//// INetworkFeature netFeature = null;
//// netFeature = pF as INetworkFeature;
//// netFeature.Connect();
//// }
//// catch
//// {
//// if (msg == "")
//// {
//// msg = A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (pF.Class as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b");
//// }
//// else
//// {
//// msg = msg + "\n" + A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (pF.Class as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b");
//// }
//// }
//// if (msg != "")
//// {
//// MessageBox.Show(msg);
//// }
////}
//INetworkFeature pNetworkTargetFeature = (INetworkFeature)pFeature;
// IFeatureLayer pTargetLayer = Globals.FindLayerByClassID(pMxDoc.FocusMap,pFeature.Class.CLSID.ToString()) as IFeatureLayer;
boolean_Continue = trackCancel.Continue();
if (!boolean_Continue)
{
return;
}
stepProgressor.Step();
stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("Complete");
try
{
Globals.RemoveTraceGraphics(pMxDoc.FocusMap, true);
}
catch
{ }
// unpress the UIToolControl button
app.CurrentTool = null;
app.RefreshWindow();
pMxDoc.ActiveView.Refresh();
return;
}
}
catch (Exception ex)
{
try
{
editor.AbortOperation();
}
catch
{ }
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13c") + ex.Message);
return;
}
finally
{
try
{
editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDone_13a"));
}
catch
{ }
if (progressDialog2 != null)
progressDialog2.HideDialog();
progressDialog2 = null;
pCmdItem = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOnCommand", app);
if (pCmdItem != null)
{
pCmdItem.Execute();
}
pLay = null;
statusBar = null;
animationProgressor = null;
trackCancel = null;
progressDialogFactory = null;
stepProgressor = null;
progressDialog2 = null;
pCmdItem = null;
pMxDoc = null;
pGN = null;
pFeature = null;
pTracePoint = null;
pSimpleLineSym = null;
pRGBColor = null;
gc = null;
pMoveElemFirst = null;
pMoveElemPropFirst = null;
element = null;
elementProp = null;
lineElem = null;
pJuncFeat = null;
pSourceLayer = null;
pSourceFeature = null;
pMoveFeat = null;
pNetworkSourceFeature = null;
iTargetEdgeFeat = null;
iCEdge = null;
pOraphFC = null;
OIDs = null;
FeatLoc = null;
FCs = null;
pL = null;
pHtTest = null;//= pPolyline as IHitTest;
pHitPntOne = null;
editor = null;
}
}