/// <summary> /// Deletes all splices for a cable to any other at any splice closure /// </summary> /// <param name="cable">Cable</param> /// <param name="isExistingOperation">Are we already in an edit operation?</param> /// <returns>Success</returns> public bool BreakAllSplices(FiberCableWrapper cable, bool isExistingOperation) { bool success = false; bool isOperationOpen = false; #region Validation if (null == cable) { throw new ArgumentNullException("cable"); } if (ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing == _editor.EditState) { throw new InvalidOperationException("You must be editing to perform this operation"); } #endregion if (!isExistingOperation) { _editor.StartOperation(); isOperationOpen = true; } try { ESRI.ArcGIS.Geodatabase.ITable spliceTable = _wkspHelper.FindTable(ConfigUtil.FiberSpliceTableName); // ESRI.ArcGIS.Geodatabase.ITable spliceTable = GdbUtils.GetTable(cable.Feature.Class, ConfigUtil.FiberSpliceTableName); ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); // A and B is arbitrary, so we check the given combinations going both ways. The structure is: // Where either the A or B cableID is our cable ID filter.WhereClause = string.Format("{0}='{1}' OR {2}='{1}'", ConfigUtil.ACableIdFieldName, cable.IPID, ConfigUtil.BCableIdFieldName); spliceTable.DeleteSearchedRows(filter); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(filter); if (isOperationOpen) { _editor.StopOperation("Break Splices"); isOperationOpen = false; } success = true; } catch { if (isOperationOpen) { _editor.AbortOperation(); } success = false; } return(success); }
private void OnSketchFinished() { ConfigUtil.type = "water"; IFeature pFeat = null; try { m_editor.StartOperation(); pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate as IEditTemplate, m_editor, ArcMap.Application, false, false, true); bool splitOccured = GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), m_edSketch.Geometry as IPoint, false, true, false); try { //Check to see if the source feature is the Junction FC, if so, and a edge was split, the junction will be created, do not create it as to not construct an orphaned junction //https://github.com/Esri/local-government-desktop-addins/issues/239 bool storeFeature = true; INetworkFeature netFeature = pFeat as INetworkFeature; if (netFeature != null) { if (pFeat.Class.ObjectClassID == netFeature.GeometricNetwork.OrphanJunctionFeatureClass.FeatureClassID && pFeat.Class.CLSID.Value.ToString() == netFeature.GeometricNetwork.OrphanJunctionFeatureClass.CLSID.Value.ToString() && splitOccured == true) { storeFeature = false; } } if (storeFeature == true) { pFeat.Store(); } netFeature = null; m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore")); m_editor.AbortOperation(); } } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn") + "\n" + ex.ToString()); m_editor.AbortOperation(); } finally { if (pFeat != null) { (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, pFeat, null); } pFeat = null; } }
private void OnSketchFinished() { //send a space to hide the construction toolbar SendKeys.SendWait(" "); try { m_editor.StartOperation(); } catch { m_editor.AbortOperation(); m_editor.StartOperation(); } IFeature pRoadFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, true, true); pRoadFeat.Store(); //AMGeometryTools.AddPointWithRef(m_application, pPnts.get_Point(0), configDetails, ((IFeatureLayer)m_editor.CurrentTemplate.Layer), ref idxConfig);//,config,null,true,true); AMGeometryTools.SplitAndProrate(ArcMap.Application, pRoadFeat, m_editor.CurrentTemplate.Layer as IFeatureLayer, ConfigUtil.GetAddressCenterlineConfig()); // pFeats.Add(pFeat); ((IMxDocument)ArcMap.Application.Document).ActiveView.Refresh(); try { m_editor.StopOperation("Create Point with Reference"); } catch { } pRoadFeat = null; }
private void OnSketchFinished() { IFeature pFeat; try { m_editor.StartOperation(); pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate as IEditTemplate, m_editor, ArcMap.Application, false, false, true); GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), m_edSketch.Geometry as IPoint, false, true, false); pFeat.Store(); m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn") + "\n" + ex.Message); m_editor.AbortOperation(); } finally { pFeat = null; } }
private void OnSketchFinished() { IFeature pFeat; try { m_editor.StartOperation(); pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate as IEditTemplate, m_editor, ArcMap.Application, false, false, true); GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), m_edSketch.Geometry as IPoint, false, true, false); pFeat.Store(); m_editor.StopOperation("Add Point and split line"); (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, pFeat, null); } catch (Exception ex) { MessageBox.Show("Error in the Add Point and Split\n" + ex.Message); m_editor.AbortOperation(); } finally { pFeat = null; } }
private void OnSketchFinished() { ConfigUtil.type = "water"; IFeature pFeat = null; try { m_editor.StartOperation(); pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate as IEditTemplate, m_editor, ArcMap.Application, false, false, true); GeometryTools.SplitLinesAtClick(ArcMap.Application, ConfigUtil.GetConfigValue("SplitLinesSuspendAA", "true"), ConfigUtil.GetConfigValue("SplitLinesAtLocation_Snap", 10.0), ConfigUtil.GetConfigValue("SplitLines_SkipDistance", .5), m_edSketch.Geometry as IPoint, false, true, false); pFeat.Store(); m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("AddPtsAndSplitLn") + "\n" + ex.Message); m_editor.AbortOperation(); } finally { if (pFeat != null) { (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, pFeat, null); } pFeat = null; } }
private void OnSketchFinished() { //send a space to hide the construction toolbar SendKeys.SendWait(" "); List <CreatePointWithReferenceDetails> configDetails = null; AddressReturnInfo retInfo = null; IPointCollection pPnts = null; List <IFeature> pFeats = null; IPoint pPnt = null; try { ((IMxDocument)ArcMap.Document).FocusMap.ClearSelection(); Keys ModKey = Control.ModifierKeys; pPnts = m_edSketch.Geometry as IPointCollection; if (pPnts == null) { return; } if (pPnts.PointCount < 2) { return; } try { m_editor.StartOperation(); } catch { m_editor.AbortOperation(); m_editor.StartOperation(); } int idxConfig = -1; // TODO: Add developer code here configDetails = ConfigUtil.GetCreatePointWithRefConfig(); retInfo = AMGeometryTools.AddPointWithRef(ArcMap.Application, pPnts.get_Point(0), configDetails, ((IFeatureLayer)m_editor.CurrentTemplate.Layer), ref idxConfig);//,config,null,true,true); if (idxConfig == -1) { return; } if (retInfo == null) { return; } int targetAddFieldIdx = Globals.GetFieldIndex(((IFeatureLayer)m_editor.CurrentTemplate.Layer), configDetails[idxConfig].AddressField); if (targetAddFieldIdx == -1) { return; } int targetNameFieldIdx = Globals.GetFieldIndex(((IFeatureLayer)m_editor.CurrentTemplate.Layer), configDetails[idxConfig].StreetNameField); if (targetNameFieldIdx == -1) { return; } int targetIDFieldIdx = Globals.GetFieldIndex(((IFeatureLayer)m_editor.CurrentTemplate.Layer), configDetails[idxConfig].AddressPntKeyField); //if (targetIDFieldIdx == -1) // return; //. .AddLaterals(m_application, ConfigUtil.GetAddLateralsConfig(), pFeat, false, true, false, false); //IFeature pFeat = null; pFeats = new List <IFeature>(); for (int i = 1; i < pPnts.PointCount; i++) { pFeats.Add(Globals.CreateFeature(pPnts.get_Point(i), m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true)); // pFeats.Add(pFeat); } foreach (IFeature pFeat in pFeats) { if (retInfo.AddressDetails.StreetGeometry == null) { if (targetNameFieldIdx != -1) { pFeat.set_Value(targetNameFieldIdx, retInfo.AddressDetails.Messages); } } else { bool rightSide = true; pPnt = Globals.GetPointOnLine(pFeat.Shape as IPoint, retInfo.AddressDetails.StreetGeometry as IPolyline, 400, out rightSide); if (rightSide) { pFeat.set_Value(targetAddFieldIdx, retInfo.AddressDetails.RightAddress); } else { pFeat.set_Value(targetAddFieldIdx, retInfo.AddressDetails.LeftAddress); } if (targetNameFieldIdx != -1) { pFeat.set_Value(targetNameFieldIdx, retInfo.AddressDetails.StreetName); } if (targetIDFieldIdx != -1) { pFeat.set_Value(targetIDFieldIdx, retInfo.AddressPointKey); } pFeat.Store(); } } pPnts = null; ((IMxDocument)ArcMap.Document).ActiveView.Refresh(); try { m_editor.StopOperation("Create Point with Reference"); } catch { } } catch { configDetails = null; retInfo = null; pPnts = null; pFeats = null; pPnt = null; try { m_editor.AbortOperation(); } catch { } } }
private void OnSketchFinished() { IFeature pFeat = null; ISegmentCollection pSegColl = null; IEnumSegment pESeg = null; ISegment testSegment = null; ISegmentCollection segColTest = null; object Missing = null; try { // Send a shift-tab to hide the construction toolbar try { m_editor.StartOperation(); } catch { m_editor.AbortOperation(); m_editor.StartOperation(); } bool twoPoint = false; (ArcMap.Application.Document as IMxDocument).FocusMap.ClearSelection(); List <IFeature> pLstFeat = null; if (Control.ModifierKeys == Keys.Control) { twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, false, out pLstFeat); } else { twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, true, out pLstFeat); } if (twoPoint) { pSegColl = (ISegmentCollection)m_edSketch.Geometry; pESeg = pSegColl.EnumSegments; pESeg.Reset(); int partIndex = 0; int segmentIndex = 0; pESeg.Next(out testSegment, ref partIndex, ref segmentIndex); while (testSegment != null) { segColTest = new PolylineClass(); Missing = Type.Missing; segColTest.AddSegment(testSegment, ref Missing, ref Missing); pFeat = Globals.CreateFeature(segColTest as IGeometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true); pFeat.Store(); pESeg.Next(out testSegment, ref partIndex, ref segmentIndex); } } else { pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true); pFeat.Store(); } foreach (IFeature pFt in pLstFeat) { pFt.Store(); } pLstFeat = null; m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtLnWithPts")); (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null); } catch { } finally { pFeat = null; pSegColl = null; pESeg = null; testSegment = null; segColTest = null; Missing = null; } }
private void OnSketchFinished() { //m_editor.UndoOperation(); IFeature pFeat = null; IEnvelope pEnv = null; try { m_editor.StartOperation(); Globals.ClearSelected(ArcMap.Application, false, new List <esriGeometryType>() { esriGeometryType.esriGeometryPoint }); pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true); //CreatePoint(m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate); if (pFeat == null) { return; } // addLat.AddLateralAtPoint(m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name); //((IFeatureSelection)m_editor.CurrentTemplate.Layer).Clear(); m_editor.Map.SelectFeature(m_editor.CurrentTemplate.Layer as IFeatureLayer, pFeat); string resetFlow = AddLateralsFromPoint.AddLateralsFromMainPoint(ArcMap.Application, ConfigUtil.GetAddLateralsFromMainConfig(), pFeat, false, true, false); // m_editor.Map.SelectFeature(m_editor.CurrentTemplate.Layer as IFeatureLayer, pFeat); m_editor.Display.Invalidate((ArcMap.Document as IMxDocument).ActiveView.Extent, true, (short)esriScreenCache.esriAllScreenCaches); pFeat.Store(); (ArcMap.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, (ArcMap.Document as IMxDocument).ActiveView.Extent.Envelope); if (resetFlow.ToUpper() == "DIGITIZED") { Globals.GetCommand("A4WaterUtilities_EstablishFlowDigitized", ArcMap.Application).Execute(); } else if (resetFlow.ToUpper() == "ROLE") { Globals.GetCommand("A4WaterUtilities_EstablishFlowAncillary", ArcMap.Application).Execute(); } else if (resetFlow.ToUpper() == "Ancillary".ToUpper()) { Globals.GetCommand("A4WaterUtilities_EstablishFlowAncillary", ArcMap.Application).Execute(); } else { } m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtAssetAndLat")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("ALT_1") + ex.Message); m_editor.AbortOperation(); } finally { pFeat = null; pEnv = null; } }
private void CreateParcelFromSegmentCollection(ISegmentCollection Segments, string PlanName) { int iCnt = Segments.SegmentCount; ISegment[] pSegmentArr = new ISegment[iCnt]; for (int j = 0; j < iCnt; j++) { pSegmentArr[j] = Segments.get_Segment(j); } ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); IParcelEditManager pParcEditorMan = (IParcelEditManager)pCadEd; try { ICadastralPacketManager pCadPacketMan = (ICadastralPacketManager)pCadEd; bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen; if (!bStartedWithPacketOpen) { m_editor.StartOperation(); } //1. Start map edit session ICadastralMapEdit pCadMapEdit = (ICadastralMapEdit)pCadEd; pCadMapEdit.StartMapEdit(esriMapEditType.esriMEEmpty, "NewParcel", false); //2. Get job packet ICadastralPacket pCadaPacket = pCadPacketMan.JobPacket; //3. Create Plan (new) string sPlanName = PlanName; //first check to ensure plan is not already in the database. IGSPlan pGSPlan = FindFabricPlanByName(sPlanName, pCadEd); if (pGSPlan == null) { //if plan is null, it was not found and can be created pGSPlan = new GSPlanClass(); // 3.a set values pGSPlan.Accuracy = 4; pGSPlan.Name = sPlanName; } //3.b Add the plan to the job packet ICadastralPlan pCadaPlan = (ICadastralPlan)pCadaPacket; pCadaPlan.AddPlan(pGSPlan); //4. Create Parcel ICadastralParcel pCadaParcel = (ICadastralParcel)pCadaPacket; IGSParcel pNewGSParcel = new GSParcelClass(); //Make sure that any extended attributes on the parcel have their default values set IGSAttributes pGSAttributes = (IGSAttributes)pNewGSParcel; if (pGSAttributes != null) { ICadastralObjectSetup pCadaObjSetup = (ICadastralObjectSetup)pParcEditorMan; pCadaObjSetup.AddExtendedAttributes(pGSAttributes); pCadaObjSetup.SetDefaultValues(pGSAttributes); } //4a. Add the parcel to the packet. (do this before addlines) // - This will enable us to Acquire the parcel ID, // - Having the parcel attached to the packet allows InsertLine to function. pCadaParcel.AddParcel(pNewGSParcel); pNewGSParcel.Lot = "NewParcel"; pNewGSParcel.Type = 7; //4b. Set Plan (created above) IGSPlan thePlan = pCadaPlan.GetPlan(sPlanName); pNewGSParcel.Plan = thePlan; //4c. Insert GSLines (from new) into GSParcel //4d. To bypass join, you can create GSPoints and assign those point IDs to the GSLines. ICadastralPoints pCadaPoints = (ICadastralPoints)pCadaPacket; IMetricUnitConverter pMetricUnitConv = (IMetricUnitConverter)pCadEd; //Set up the initial start point, POB IPoint pPt1 = Segments.get_Segment(0).FromPoint; IZAware pZAw = (IZAware)pPt1; pZAw.ZAware = true; pPt1.Z = 0; //defaulting to 0 //Convert the point into metric units, and get a new (in-mem) point id IGSPoint pGSPointFrom = pMetricUnitConv.SetGSPoint(pPt1); pCadaPoints.AddPoint(pGSPointFrom); int iID1 = pGSPointFrom.Id; int iID1_Orig = iID1; int index = 0; IGSLine pGSLine = null; //++++++++++++ Add Courses ++++++++++++++ int iID2 = -1; bool bIsLoop = (Math.Abs(pPt1.X - Segments.get_Segment(iCnt - 1).ToPoint.X)) < 0.01 && (Math.Abs(pPt1.Y - Segments.get_Segment(iCnt - 1).ToPoint.Y)) < 0.01; IAngularConverter pAngConv = new AngularConverterClass(); for (int j = 0; j < iCnt; j++) { pSegmentArr[j] = Segments.get_Segment(j); double dDir = 0; //radians north azimuth ILine pLineOrChord = new LineClass(); pLineOrChord.PutCoords(pSegmentArr[j].FromPoint, pSegmentArr[j].ToPoint); if (pAngConv.SetAngle(pLineOrChord.Angle, esriDirectionType.esriDTPolar, esriDirectionUnits.esriDURadians)) { dDir = pAngConv.GetAngle(esriDirectionType.esriDTNorthAzimuth, esriDirectionUnits.esriDURadians); } double dDist = pLineOrChord.Length; double dRadius = 0; int iAccuracy = -1; int iUserLineType = -1; int iCategory = -1; if (pSegmentArr[j] is ICircularArc) { ICircularArc pCircArc = pSegmentArr[j] as ICircularArc; dRadius = pCircArc.Radius; if (pCircArc.IsCounterClockwise) { dRadius = dRadius * -1; } } bool bComputeToPoint = (bIsLoop && (j < iCnt - 1)) || !bIsLoop; //From, Direction (NAz Radians), Distance (map's projection units), Radius pGSLine = CreateGSLine(pMetricUnitConv, pCadaPoints, ref pPt1, iID1, dDir, dDist, dRadius, iAccuracy, iUserLineType, iCategory, bComputeToPoint, out iID2); if (j < iCnt - 1 || !bIsLoop) { iID1 = iID2; } else if ((j == iCnt - 1) && bIsLoop) { pGSLine.ToPoint = iID1_Orig; //closing the traverse back to the POB } iID2 = -1; //Add the line to the new parcel if (pGSLine != null) { pNewGSParcel.InsertLine(++index, pGSLine); } } //Add radial lines for circular curves pNewGSParcel.AddRadialLines(); // 4.e then set join=true on the parcel. pNewGSParcel.Joined = true; //let the packet know that a change has been made pCadPacketMan.SetPacketModified(true); //save the new parcel try { pCadMapEdit.StopMapEdit(true); } catch { if (!bStartedWithPacketOpen) { m_editor.AbortOperation(); } return; } if (!bStartedWithPacketOpen) { m_editor.StopOperation("New Parcel"); } pCadPacketMan.PartialRefresh(); } catch (Exception ex) { m_editor.AbortOperation(); MessageBox.Show(ex.Message); } }
/// <summary> /// Creates given connections between cable and device /// </summary> /// <param name="cable">Cable</param> /// <param name="device">Device</param> /// <param name="units">Units to connect</param> /// <param name="isFromEnd">Is it the cable's from end?</param> /// <param name="portType">Input or Output?</param> /// <param name="isExistingOperation">Flag to control whether we need to wrap this in a new edit operation</param> /// <returns>Success</returns> public bool MakeConnections(FiberCableWrapper cable, DeviceWrapper device, Dictionary <int, int> units, bool isFromEnd, PortType portType, bool isExistingOperation) { bool success = false; bool isOperationOpen = false; #region Validation if (null == cable) { throw new ArgumentNullException("cable"); } if (null == device) { throw new ArgumentNullException("device"); } if (null == units) { throw new ArgumentNullException("units"); } if (ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing == _editor.EditState) { throw new InvalidOperationException("You must be editing to perform this operation"); } #endregion if (!isExistingOperation) { _editor.StartOperation(); isOperationOpen = true; } try { ESRI.ArcGIS.Geodatabase.IFeatureClass deviceFtClass = device.Feature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass; ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship(deviceFtClass); if (null == deviceHasPorts) { throw new Exception("Unable to get port relationship class."); } ESRI.ArcGIS.Geodatabase.ITable portTable = deviceHasPorts.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable; if (null == portTable) { throw new Exception("Invalid destination on port relationship class."); } int portIdIdx = portTable.FindField(ConfigUtil.PortIdFieldName); int fiberNumberIdx = portTable.FindField(ConfigUtil.ConnectedFiberFieldName); int cableIdIdx = portTable.FindField(ConfigUtil.ConnectedCableFieldName); int isFromEndIdx = portTable.FindField(ConfigUtil.ConnectedEndFieldName); string isFromEndValue = isFromEnd ? "T" : "F"; Dictionary <int, int> portsAsKeys = units; if (PortType.Input == portType) { portsAsKeys = new Dictionary <int, int>(); foreach (KeyValuePair <int, int> pair in units) { portsAsKeys[pair.Value] = pair.Key; } } using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); string format = "{0}='{1}' AND {2}='{3}'"; filter.WhereClause = string.Format(format, deviceHasPorts.OriginForeignKey, device.Feature.get_Value(deviceFtClass.FindField(deviceHasPorts.OriginPrimaryKey)), ConfigUtil.PortTypeFieldName, (PortType.Input == portType ? "1" : "2")); // Non recylcing cursor since we are doing updates. ESRI.ArcGIS.Geodatabase.ICursor portCursor = portTable.Update(filter, false); releaser.ManageLifetime(portCursor); ESRI.ArcGIS.Geodatabase.IRow portRow = portCursor.NextRow(); while (null != portRow) { object portIdObj = portRow.get_Value(portIdIdx); if (DBNull.Value != portIdObj) { int portId = System.Convert.ToInt32(portIdObj); if (portsAsKeys.ContainsKey(portId)) { portRow.set_Value(cableIdIdx, cable.IPID); portRow.set_Value(isFromEndIdx, isFromEndValue); portRow.set_Value(fiberNumberIdx, portsAsKeys[portId]); portRow.Store(); } } ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(portRow); portRow = portCursor.NextRow(); } if (isOperationOpen) { _editor.StopOperation("Create Connections"); isOperationOpen = false; } success = true; } } catch (Exception ex) { if (isOperationOpen) { _editor.AbortOperation(); } success = false; throw new Exception("Save operation failed."); } return(success); }
private void OnSketchFinished() { try { ConfigUtil.type = "water"; Keys ModKey = Control.ModifierKeys; // Send a shift-tab to hide the construction toolbar m_editor.StartOperation(); IFeature pFeat = null; returnFeatArray pRetVal = null; if (ModKey == Keys.Shift) { pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true); pRetVal = ConnectClosest.ConnectClosestFeatureAtPoint(ArcMap.Application, ConfigUtil.GetConnectClosestConfig(), m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name, true, ModKey); // pFeat.Store(); } else if (ModKey == (Keys.Control | Keys.Shift)) { pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true); pRetVal = ConnectClosest.ConnectClosestFeatureAtPoint(ArcMap.Application, ConfigUtil.GetConnectClosestConfig(), m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name, true, ModKey); // pFeat.Store(); } else if (ModKey == Keys.Control) { pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, true, true); pRetVal = ConnectClosest.ConnectClosestFeatureAtPoint(ArcMap.Application, ConfigUtil.GetConnectClosestConfig(), m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name, true, ModKey); // pFeat.Store(); } else { pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, true, true); pRetVal = ConnectClosest.ConnectClosestFeatureAtPoint(ArcMap.Application, ConfigUtil.GetConnectClosestConfig(), m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name, true, ModKey); } //INetworkFeature netFeature = null; //netFeature = pFeat as INetworkFeature; //if (netFeature != null) //{ // netFeature.Connect(); //} pFeat.Store(); foreach (IFeature featus in pRetVal.Features) { //netFeature = featus as INetworkFeature; //if (netFeature != null) //{ // netFeature.Connect(); //} featus.Store(); } if (pRetVal.Options == "DIGITIZED") { Globals.GetCommand("A4WaterUtilities_EstablishFlowDigitized", ArcMap.Application).Execute(); } else if (pRetVal.Options == "ROLE") { Globals.GetCommand("A4WaterUtilities_EstablishFlowAncillary", ArcMap.Application).Execute(); } else if (pRetVal.Options == "Ancillary".ToUpper()) { Globals.GetCommand("A4WaterUtilities_EstablishFlowAncillary", ArcMap.Application).Execute(); } else { } // addLat.AddLateralAtPoint(m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name); m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtAssetAndLat")); //IEnvelope pEnv = pFeat.Shape.Envelope; //pEnv.Expand(8, 8, true); (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, pFeat, null); //pEnv = null; pFeat = null; pRetVal = null; } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("ALT_1") + ex.ToString()); m_editor.AbortOperation(); } finally { } }
void m_editEvents_OnDeleteFeature(IObject obj) { // check if the deleted feature participates in a relation // applies to point, lines, and polygons // if it does participate in a relation ask the user if it is ok to delete IFeatureClass currentObjectFeatureClass = obj.Class as IFeatureClass; if ((currentObjectFeatureClass == null) || (currentObjectFeatureClass.EXTCLSID == null)) { return; } // check if the current feature class being edited is acutally an OpenStreetMap feature class // all other feature class should not be touched by this extension UID osmEditorExtensionCLSID = currentObjectFeatureClass.EXTCLSID; if (osmEditorExtensionCLSID.Value.ToString().Equals("{65CA4847-8661-45eb-8E1E-B2985CA17C78}", StringComparison.InvariantCultureIgnoreCase) == false) { return; } // at this point we are only handling geometry types // relation types are using a separate UI IFeature deletedFeature = obj as IFeature; if (deletedFeature == null) { return; } // block changing features that are supporting features for multi-part geometries (relations) if (deletedFeature.Shape is IPolygon || deletedFeature.Shape is IPolyline) { int memberOFFieldIndex = deletedFeature.Fields.FindField("osmMemberOf"); int membersFieldIndex = deletedFeature.Fields.FindField("osmMembers"); int osmIDFieldIndex = deletedFeature.Fields.FindField("OSMID"); int osmID = 0; if (osmIDFieldIndex > -1) { object osmIDValue = deletedFeature.get_Value(osmIDFieldIndex); if (osmIDValue != DBNull.Value) { osmID = Convert.ToInt32(osmIDValue); } } if (membersFieldIndex > -1) { ESRI.ArcGIS.OSM.OSMClassExtension.member[] relationMembers = _osmUtility.retrieveMembers(deletedFeature, membersFieldIndex); if (relationMembers != null) { if (relationMembers.Length > 0) { string abortMessage = String.Format(resourceManager.GetString("OSMEditor_FeatureInspector_multipartdeleteparentconflictmessage"), osmID); MessageBox.Show(abortMessage, resourceManager.GetString("OSMEditor_FeatureInspector_relationconflictcaption"), MessageBoxButtons.OK, MessageBoxIcon.Stop); m_editor3.AbortOperation(); } } } if (memberOFFieldIndex > -1) { List <string> isMemberOfList = _osmUtility.retrieveIsMemberOf(deletedFeature, memberOFFieldIndex); Dictionary <string, string> dictofParentsAndTypes = _osmUtility.parseIsMemberOfList(isMemberOfList); StringBuilder typeAndIDString = new StringBuilder(); foreach (var item in dictofParentsAndTypes) { switch (item.Value) { case "rel": typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_relationidtext") + item.Key + ","); break; case "ply": typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_polygonidtext") + item.Key + ","); break; case "ln": typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_polylineidtext") + item.Key + ","); break; case "pt": typeAndIDString.Append(resourceManager.GetString("OSMEditor_FeatureInspector_pointidtext") + item.Key + ","); break; default: break; } } if (typeAndIDString.Length > 0) { string parentsString = typeAndIDString.ToString(0, typeAndIDString.Length - 1); string abortMessage = String.Format(resourceManager.GetString("OSMEditor_FeatureInspector_relationsconflictmessage"), osmID, parentsString); MessageBox.Show(abortMessage, resourceManager.GetString("OSMEditor_FeatureInspector_relationconflictcaption"), MessageBoxButtons.OK, MessageBoxIcon.Stop); m_editor3.AbortOperation(); return; } } } else if (deletedFeature.Shape is IPoint) { // if we are dealing with points to be deleted then we'll determine the connectedness via a spatial query and then the attributes indicating that // the higher order feature is part of a relation IFeatureClass lineFeatureClass = ESRI.ArcGIS.OSM.OSMClassExtension.OpenStreetMapClassExtension.findMatchingFeatureClass(deletedFeature, esriGeometryType.esriGeometryPolyline); ISpatialFilter searchPointFilter = new SpatialFilterClass(); searchPointFilter.Geometry = deletedFeature.Shape; searchPointFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelTouches; TestRelationMembership(deletedFeature, lineFeatureClass, searchPointFilter); IFeatureClass polygonFeatureClass = ESRI.ArcGIS.OSM.OSMClassExtension.OpenStreetMapClassExtension.findMatchingFeatureClass(deletedFeature, esriGeometryType.esriGeometryPolygon); TestRelationMembership(deletedFeature, polygonFeatureClass, searchPointFilter); } string featureClassName = ((IDataset)obj.Class).Name; // find the correspoding relation table int baseIndex = featureClassName.IndexOf("_osm_"); int deleteOSMIDFieldIndex = obj.Fields.FindField("OSMID"); int deleteIsMemberOfFieldIndex = obj.Fields.FindField("osmMemberOf"); if (baseIndex > -1) { string relationTableName = featureClassName.Substring(0, baseIndex) + "_osm_relation"; IFeatureWorkspace featureWorkspace = m_editor3.EditWorkspace as IFeatureWorkspace; ITable relationTable = featureWorkspace.OpenTable(relationTableName); int relationOSMIDFieldIndex = relationTable.Fields.FindField("OSMID"); List <string> memberOfList = _osmUtility.retrieveIsMemberOf(deletedFeature, deleteIsMemberOfFieldIndex); Dictionary <string, string> isMemberOfIdsAndTypes = _osmUtility.parseIsMemberOfList(memberOfList); if (memberOfList.Count > 0) { // the deleted feature is referenced by a relation // check with the user if it is ok to delete // if OK then we are dealing with the delete upon stop editing, if cancel undo the delete string relationsString = String.Empty; int relationCount = 0; foreach (var memberOfItem in isMemberOfIdsAndTypes) { if (memberOfItem.Value == "rel") { relationCount = relationCount + 1; relationsString = relationsString + memberOfItem.Key + ","; } } string errorMessage = String.Empty; if (relationCount > 1) { errorMessage = string.Format(resourceManager.GetString("OSMEditor_FeatureInspector_relationsconflictmessage"), deletedFeature.get_Value(deleteOSMIDFieldIndex), relationsString.Substring(0, relationsString.Length - 1)); } else { errorMessage = string.Format(resourceManager.GetString("OSMEditor_FeatureInspector_relationconflictmessage"), deletedFeature.get_Value(deleteOSMIDFieldIndex), relationsString.Substring(0, relationsString.Length - 1)); } if (MessageBox.Show(errorMessage, resourceManager.GetString("OSMEditor_FeatureInspector_relationconflictcaption"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) { m_editor3.AbortOperation(); } } } }
private void OnSketchFinished() { ConfigUtil.type = "gas"; //m_editor.UndoOperation(); IFeature pFeat = null; IEnvelope pEnv = null; try { m_editor.StartOperation(); Globals.ClearSelected(ArcMap.Application, false, new List <esriGeometryType>() { esriGeometryType.esriGeometryPoint }); pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true); //CreatePoint(m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate); if (pFeat == null) { return; } // addLat.AddLateralAtPoint(m_edSketch.Geometry as IPoint, m_editor.CurrentTemplate.Layer.Name); //((IFeatureSelection)m_editor.CurrentTemplate.Layer).Clear(); m_editor.Map.SelectFeature(m_editor.CurrentTemplate.Layer as IFeatureLayer, pFeat); List <MergeSplitGeoNetFeatures> m_Config = null; m_Config = ConfigUtil.GetMergeSplitConfig(); string resetFlow = AddLateralsLinesCmds.AddLaterals(ArcMap.Application, ConfigUtil.GetAddLateralsConfig(), pFeat, false, true, false, false, m_Config[0]); // m_editor.Map.SelectFeature(m_editor.CurrentTemplate.Layer as IFeatureLayer, pFeat); m_editor.Display.Invalidate((ArcMap.Document as IMxDocument).ActiveView.Extent, true, (short)esriScreenCache.esriAllScreenCaches); pFeat.Store(); (ArcMap.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, (ArcMap.Document as IMxDocument).ActiveView.Extent.Envelope); if (resetFlow.ToUpper() == "DIGITIZED") { Globals.GetCommand("A4GasUtilities_EstablishFlowDigitized", ArcMap.Application).Execute(); } else if (resetFlow.ToUpper() == "ROLE") { Globals.GetCommand("A4GasUtilities_EstablishFlowAncillary", ArcMap.Application).Execute(); } else if (resetFlow.ToUpper() == "Ancillary".ToUpper()) { Globals.GetCommand("A4GasUtilities_EstablishFlowAncillary", ArcMap.Application).Execute(); } else { } m_editor.StopOperation("Create asset and lateral"); } catch (Exception ex) { MessageBox.Show("Error in the Add Lateral Tools: " + ex.ToString()); m_editor.AbortOperation(); } finally { pFeat = null; pEnv = null; } }
private void OnSketchFinished() { ConfigUtil.type = "gas"; IFeature pFeat = null; ISegmentCollection pSegColl = null; IEnumSegment pESeg = null; ISegment testSegment = null; ISegmentCollection segColTest = null; object Missing = null; try { // Send a shift-tab to hide the construction toolbar try { m_editor.StartOperation(); } catch { m_editor.AbortOperation(); m_editor.StartOperation(); } bool twoPoint = false; (ArcMap.Application.Document as IMxDocument).FocusMap.ClearSelection(); List <IFeature> pLstFeat = null; string storeOrder = ""; if (Control.ModifierKeys == Keys.Control) { twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, false, out pLstFeat, out storeOrder); } else { twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, true, out pLstFeat, out storeOrder); } if (storeOrder == null) { storeOrder = "Points"; } if (storeOrder.ToUpper() == "points".ToUpper()) { foreach (IFeature pFt in pLstFeat) { try { pFt.Store(); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore")); m_editor.AbortOperation(); return; } } } if (twoPoint) { pSegColl = (ISegmentCollection)m_edSketch.Geometry; pESeg = pSegColl.EnumSegments; pESeg.Reset(); int partIndex = 0; int segmentIndex = 0; pESeg.Next(out testSegment, ref partIndex, ref segmentIndex); while (testSegment != null) { segColTest = new PolylineClass(); Missing = Type.Missing; segColTest.AddSegment(testSegment, ref Missing, ref Missing); pFeat = Globals.CreateFeature(segColTest as IGeometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true); try { pFeat.Store(); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore")); m_editor.AbortOperation(); return; } pESeg.Next(out testSegment, ref partIndex, ref segmentIndex); } } else { pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true); pFeat.Store(); } if (storeOrder.ToUpper() != "points".ToUpper()) { foreach (IFeature pFt in pLstFeat) { try { pFt.Store(); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore")); m_editor.AbortOperation(); return; } } } pLstFeat = null; m_editor.StopOperation("Create line with points"); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("CrtLnWithPts") + "\n" + ex.ToString()); m_editor.AbortOperation(); } finally { pFeat = null; pSegColl = null; pESeg = null; testSegment = null; segColTest = null; Missing = null; } }