private void EngineEditingForm_Load(object sender, EventArgs e) { //Set buddy controls axTOCControl1.SetBuddyControl(axMapControl1); axEditorToolbar.SetBuddyControl(axMapControl1); axToolbarControl1.SetBuddyControl(axMapControl1); //Add items to the ToolbarControl axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsSaveAsDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomToolControl", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapMeasureTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //Add items to the custom editor toolbar axEditorToolbar.AddItem("esriControls.ControlsEditingEditorMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingTargetToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingTaskToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); //share the command pool axToolbarControl1.CommandPool = axEditorToolbar.CommandPool; //Create an operation stack for the undo and redo commands to use IOperationStack operationStack = new ControlsOperationStackClass(); axEditorToolbar.OperationStack = operationStack; //add some sample point data to the map IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass(); //relative file path to the sample data from EXE location string filePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); filePath = System.IO.Path.Combine(filePath, @"ArcGIS\data\AirportsAndGolf\Golf.gdb"); IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(filePath, axMapControl1.hWnd); IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.Name = "Golf Courses"; featureLayer.Visible = true; featureLayer.FeatureClass = workspace.OpenFeatureClass("Golf"); axMapControl1.Map.MapUnits = esriUnits.esriMeters; axMapControl1.Map.AddLayer((ILayer)featureLayer); //set up the snapping environment m_engineEditor = new EngineEditorClass(); m_engineEditor.SnapToleranceUnits = esriEngineSnapToleranceUnits.esriEngineSnapToleranceMapUnits; m_engineEditor.SnapTolerance = 2000; }
public void OnMouseMove(int button, int shift, int x, int y) { IPoint point = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment; try { if (engineEditor.SnapPoint(point)) { this.m_Cursor = ToolCursor.VertexSelected; } else { this.m_Cursor = ToolCursor.Add; } } catch { } if (this.m_IsUsed) { IPoint point2 = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); this.m_LineFeedback.MoveTo(point2); } }
public override void OnClick() { this._command.OnClick(); this._cursor = this._tool.Cursor; this._lineFeedback = null; this._bStarted = false; this._bFinished = false; this._bMouse = false; try { IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment; engineEditor.SnapTolerance = 1.0; (Editor.UniqueInstance.EngineEditor as IEngineEditEvents_Event).OnSketchModified += (new IEngineEditEvents_OnSketchModifiedEventHandler(this.editEvents_OnSketchModified)); IHookHelper2 helper = this._hookHelper as IHookHelper2; IExtensionManager extensionManager = helper.ExtensionManager; if (extensionManager != null) { UID nameOrID = new UIDClass { Value = "{E07B4C52-C894-4558-B8D4-D4050018D1DA}" }; IExtension extension = extensionManager.FindExtension(nameOrID); this._snappingEnv = extension as ISnappingEnvironment; this._snapFeedback = new SnappingFeedbackClass(); this._snapFeedback.Initialize(this._hookHelper.Hook, this._snappingEnv, true); } } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "ShapeEdit.SnapEx", "OnClick", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); } }
public SnapEditor() { InitializeComponent(); //get the snapEnvironment editor = new EngineEditorClass(); editLayers = editor as IEngineEditLayers; snapEnvironment = editor as IEngineSnapEnvironment; //Update this form with the snap environment and snap tips //Note: from here on we expect all snap changes to be made via this form, so it is not updated after direct changes to the snapping //environment or the Arc Engine Snap Window. RefreshDisplay(); }
public SnapEditor() { InitializeComponent(); //get the snapEnvironment editor = new EngineEditorClass(); editLayers = editor as IEngineEditLayers; snapEnvironment = editor as IEngineSnapEnvironment; //Update this form with the snap environment and snap tips //Note: from here on we expect all snap changes to be made via this form, so it is not updated after direct changes to the snapping //environment or the Arc Engine Snap Window. RefreshDisplay(); }
public ApplicationBase() { this.IsSupportZD = false; this.MapCommands = new List <object>(); this.iselectionEnvironment_0 = new SelectionEnvironment(); this.iengineSnapEnvironment_0 = new EngineEditor() as IEngineSnapEnvironment; IEngineEditProperties2 properties = this.iengineSnapEnvironment_0 as IEngineEditProperties2; properties.SnapTips = true; this.InitConfig(); ApplicationRef.Application = this; this.UseSnap = true; this.IsSnapEndPoint = true; this.IsSnapBoundary = true; this.IsSnapPoint = true; this.IsSnapVertexPoint = true; this.iengineSnapEnvironment_0.SnapTolerance = 10.0; }
public void RefreshSnapAgent(List <SnapAgent> pSnapAgents, bool pSnapTip) { IEngineSnapEnvironment environment = this._editor as IEngineSnapEnvironment; environment.ClearSnapAgents(); this._snapLayers.Clear(); foreach (SnapAgent agent in pSnapAgents) { try { esriGeometryHitPartType esriGeometryPartNone = esriGeometryHitPartType.esriGeometryPartNone; if (agent.Vertex) { esriGeometryPartNone ^= esriGeometryHitPartType.esriGeometryPartVertex; } if (agent.Edge) { esriGeometryPartNone ^= esriGeometryHitPartType.esriGeometryPartBoundary; } if (agent.EndPoint) { esriGeometryPartNone ^= esriGeometryHitPartType.esriGeometryPartEndpoint; } if (esriGeometryPartNone != esriGeometryHitPartType.esriGeometryPartNone) { IEngineFeatureSnapAgent snapAgent = new EngineFeatureSnapClass { FeatureClass = agent.FeatureLayer.FeatureClass, HitType = esriGeometryPartNone }; environment.AddSnapAgent(snapAgent); this._snapLayers.Add(agent.FeatureLayer); } } catch { } } ((IEngineEditProperties2)this._editor).SnapTips = pSnapTip; }
private bool IsSnapPoint(IPoint pPoint) { IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment; if (engineEditor.SnapAgentCount != 1) { return(false); } try { if (engineEditor.SnapPoint(pPoint)) { this._snapPoint = pPoint; return(true); } return(false); } catch { return(false); } }
private ISnappingResult method_0(IPoint ipoint_1) { IActiveView focusMap = this._appContext.MapControl.Map as IActiveView; IPoint pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(ipoint_1.X, ipoint_1.Y); IEngineSnapEnvironment engineSnapEnvironment = ApplicationRef.AppContext.Config.EngineSnapEnvironment; ISnappingResult snappingResult = null; if (engineSnapEnvironment is ISnapEnvironment) { ISnapEnvironment snapEnvironment = engineSnapEnvironment as ISnapEnvironment; if ((snapEnvironment == null || !ApplicationRef.AppContext.Config.UseSnap ? false : snapEnvironment.SnapPoint(pointClass, ipoint_1))) { SnappingResult snappingResult1 = new SnappingResult() { X = ipoint_1.X, Y = ipoint_1.Y }; snappingResult = snappingResult1; } } else if ((engineSnapEnvironment == null || !ApplicationRef.AppContext.Config.UseSnap ? false : engineSnapEnvironment.SnapPoint(ipoint_1))) { SnappingResult snappingResult2 = new SnappingResult() { X = ipoint_1.X, Y = ipoint_1.Y }; snappingResult = snappingResult2; } return(snappingResult); }
/// <summary> /// Occurs when this tool is clicked /// </summary> public override void OnClick() { // TODO: Add ToolSplitLine.OnClick implementation //Find the Modify Feature task and set it as the current task IEngineEditTask editTask = m_engineEditor.GetTaskByUniqueName("ControlToolsEditing_ModifyFeatureTask"); m_engineEditor.CurrentTask = editTask; IEngineEditLayers editLayers = m_editLayer; snapEnvironment = m_engineEditor as IEngineSnapEnvironment; pt = new PointClass(); //Check the user is editing; otherwise, there will be no snap agent loaded. if (editLayers.TargetLayer == null) { System.Windows.Forms.MessageBox.Show("Please start an edit session"); return; } ////Create a feature snap agent. IEngineFeatureSnapAgent featureSnapAgent = new EngineFeatureSnap(); IFeatureClass layerFeatureClass = editLayers.TargetLayer.FeatureClass; featureSnapAgent.FeatureClass = layerFeatureClass; featureSnapAgent.HitType = esriGeometryHitPartType.esriGeometryPartBoundary; //Activate only the snap agent for the target layer. snapEnvironment.AddSnapAgent(featureSnapAgent); pMPfeedback = new MovePointFeedbackClass(); pMPfeedback.Display = m_hookHelper.ActiveView.ScreenDisplay; pMPfeedback.Start(pt, pt); IToolbarBuddy toolbarbuddy = (IToolbarBuddy)((IToolbarControl)m_hookHelper.Hook).Buddy; oldtool = toolbarbuddy.CurrentTool; }
public static void Snap2Point(IPoint ipoint_0, IPoint ipoint_1, esriSimpleMarkerStyle esriSimpleMarkerStyle_0, IActiveView iactiveView_0, IEngineSnapEnvironment iengineSnapEnvironment_0) { IHitTest mPPointColn; double num; int num1; int num2; bool flag; double mapUnits; IPoint pointClass; if (!Editor.UseOldSnap) { ISnappingResult snappingResult = SketchToolAssist.m_psnaper.Snap(ipoint_0); if (snappingResult == null) { if (SketchToolAssist.m_pAP == null) { SketchToolAssist.m_pAP = new AnchorPoint() { Symbol = SketchShareEx.m_pSym as ISymbol }; } SketchToolAssist.m_pAP.MoveTo(SketchShareEx.m_pAnchorPoint, iactiveView_0.ScreenDisplay); } else { SketchShareEx.m_pAnchorPoint = snappingResult.Location; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(snappingResult.Location, iactiveView_0.ScreenDisplay); } else { SketchToolAssist.AddNewAnchorPt(snappingResult.Location, esriSimpleMarkerStyle_0, iactiveView_0); } } } else { SketchShareEx.m_pSym.Style = esriSimpleMarkerStyle_0; if (iengineSnapEnvironment_0 is ISnapEnvironment) { ISnapEnvironment iengineSnapEnvironment0 = iengineSnapEnvironment_0 as ISnapEnvironment; if ((iengineSnapEnvironment0 == null || !ApplicationRef.AppContext.Config.UseSnap ? true : !iengineSnapEnvironment0.SnapPoint(SketchShareEx.LastPoint, ipoint_0))) { if (ApplicationRef.AppContext.Config.IsSnapSketch) { mPPointColn = SketchToolAssist.m_pPointColn as IHitTest; if (mPPointColn != null) { num = 0; num1 = 0; num2 = 0; flag = false; mapUnits = CommonHelper.ConvertPixelsToMapUnits(iactiveView_0, iengineSnapEnvironment0.SnapTolerance); if (mapUnits == 0) { mapUnits = 3; } pointClass = new ESRI.ArcGIS.Geometry.Point(); if ( !mPPointColn.HitTest(ipoint_0, mapUnits, esriGeometryHitPartType.esriGeometryPartVertex, pointClass, ref num, ref num1, ref num2, ref flag)) { SketchShareEx.m_bSnapSuccessful = false; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); } return; } ipoint_0.PutCoords(pointClass.X, pointClass.Y); SketchShareEx.m_bSnapSuccessful = true; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); return; } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); return; } } } } else { SketchShareEx.m_bSnapSuccessful = true; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); } } } else if ((iengineSnapEnvironment_0 == null || !ApplicationRef.AppContext.Config.UseSnap ? true : !iengineSnapEnvironment_0.SnapPoint(ipoint_0))) { if (ApplicationRef.AppContext.Config.IsSnapSketch) { mPPointColn = SketchToolAssist.m_pPointColn as IHitTest; if (mPPointColn != null) { num = 0; num1 = 0; num2 = 0; flag = false; mapUnits = iengineSnapEnvironment_0.SnapTolerance; if (iengineSnapEnvironment_0.SnapToleranceUnits == esriEngineSnapToleranceUnits.esriEngineSnapTolerancePixels) { mapUnits = CommonHelper.ConvertPixelsToMapUnits(iactiveView_0, iengineSnapEnvironment_0.SnapTolerance); } if (mapUnits == 0) { mapUnits = 3; } pointClass = new ESRI.ArcGIS.Geometry.Point(); if ( !mPPointColn.HitTest(ipoint_0, mapUnits, esriGeometryHitPartType.esriGeometryPartVertex, pointClass, ref num, ref num1, ref num2, ref flag)) { SketchShareEx.m_bSnapSuccessful = false; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); } return; } ipoint_0.PutCoords(pointClass.X, pointClass.Y); SketchShareEx.m_bSnapSuccessful = true; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); return; } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); return; } } } } else { SketchShareEx.m_bSnapSuccessful = true; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); } } } }
public static string SketchMouseMove(IPoint ipoint_0, IMap imap_0, IEngineSnapEnvironment iengineSnapEnvironment_0) { string str; string unit; if (imap_0 != null) { string str1 = ""; SketchShareEx.m_pAnchorPoint = ipoint_0; SketchShareEx.Snap2Point(ipoint_0, SketchShareEx.m_pAnchorPoint, esriSimpleMarkerStyle.esriSMSDiamond, imap_0 as IActiveView, iengineSnapEnvironment_0); if (SketchToolAssist.Feedback != null) { SketchToolAssist.Feedback.MoveTo(SketchShareEx.m_pAnchorPoint); } if (SketchToolAssist.CurrentTask != null) { str = ""; } else if (SketchShareEx.m_bInUse) { SketchShareEx.m_pPoint = new Point() { X = ipoint_0.X, Y = ipoint_0.Y }; if (SketchShareEx.m_bShowVlaue) { if (SketchToolAssist.Feedback is INewLineFeedback) { unit = CommonHelper.GetUnit(imap_0.MapUnits); double num = CommonHelper.measureLength(ipoint_0, 2, ref SketchShareEx.m_pLastPoint1, ref SketchShareEx.m_pEndPoint1, ref SketchShareEx.m_totalLength); string[] strArrays = new string[] { "距离 = ", num.ToString("0.###"), unit, ", 总长度 = ", SketchShareEx.m_totalLength.ToString("0.###"), unit }; str1 = string.Concat(strArrays); } else if (SketchToolAssist.Feedback is INewPolygonFeedback) { unit = CommonHelper.GetUnit(imap_0.MapUnits); double num1 = CommonHelper.measureArea(ipoint_0, 2, ref SketchToolAssist.m_pPointColn); try { double length = (SketchToolAssist.m_pPointColn as IPolygon).Length; if (num1 > 0) { str1 = string.Format("周长 = {0:0.###} {1} ,总面积 = {2:0.###} 平方{1}", length, unit, num1); } } catch { } } } str = str1; } else { str = ""; } } else { str = ""; } return(str); }
private void EngineEditingForm_Load(object sender, EventArgs e) { //Set buddy controls axTOCControl1.SetBuddyControl(axMapControl1); axEditorToolbar.SetBuddyControl(axMapControl1); axToolbarControl1.SetBuddyControl(axMapControl1); //Add items to the ToolbarControl axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsSaveAsDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomToolControl", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapMeasureTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //Add items to the custom editor toolbar axEditorToolbar.AddItem("esriControls.ControlsEditingEditorMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingTargetToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingTaskToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); //share the command pool axToolbarControl1.CommandPool = axEditorToolbar.CommandPool; //Create an operation stack for the undo and redo commands to use IOperationStack operationStack = new ControlsOperationStackClass(); axEditorToolbar.OperationStack = operationStack; //add some sample point data to the map IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass(); //relative file path to the sample data from EXE location string filePath = @"..\..\..\..\data\AirportsAndGolf\Golf.gdb"; IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(filePath, axMapControl1.hWnd); IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.Name = "Golf Courses"; featureLayer.Visible = true; featureLayer.FeatureClass = workspace.OpenFeatureClass("Golf"); axMapControl1.Map.MapUnits = esriUnits.esriMeters; axMapControl1.Map.AddLayer((ILayer)featureLayer); //set up the snapping environment m_engineEditor = new EngineEditorClass(); m_engineEditor.SnapToleranceUnits = esriEngineSnapToleranceUnits.esriEngineSnapToleranceMapUnits; m_engineEditor.SnapTolerance = 2000; }
public SnapHelper(IAppContext ikhookHelper_0) { this._appContext = ikhookHelper_0; this.iengineSnapEnvironment_0 = ikhookHelper_0.Config.EngineSnapEnvironment; }
public SnapHelper(IActiveView iactiveView_1, IEngineSnapEnvironment iengineSnapEnvironment_1) { this.iactiveView_0 = iactiveView_1; this.iengineSnapEnvironment_0 = iengineSnapEnvironment_1; }
internal void SetDefaults() { Logger.Current.Trace("开始设置配置默认值"); #region 编辑部分设置 _canEdited = true; _isInEdit = false; IsSnapTangent = false; UseSnap = false; _engineSnapEnvironment = new EngineEditorClass(); ((IEngineEditProperties2)_engineSnapEnvironment).SnapTips = true; _engineSnapEnvironment.SnapTolerance = 10; SnapTolerance = 10; #endregion LocatorMaxCount = 100; MapViewStyle = MapViewStyle.View2D; AnimationOnZooming = AutoToggle.Auto; UsingRibbon = true; /* CacheRenderingData = false; * CacheDbfRecords = false;*/ CoordinateAngleFormat = AngleFormat.Seconds; CoordinatesDisplay = CoordinatesDisplay.Auto; CoordinatePrecision = 3; /* CreatePyramidsOnOpening = true; * CreateSpatialIndexOnOpening = true; * DisplayDynamicVisibilityWarnings = true;*/ FirstRun = true; IdentifierMode = IdentifierMode.AllLayer; IdentifierToPixel = 5; SelectionEnvironment = new SelectionEnvironmentClass() { }; LoadLastProject = true; LocalDocumentation = false; /* GridFavorGreyscale = true; * GridDefaultColorScheme = PredefinedColors.SummerMountains; * GridRandomColorScheme = true; * GridUseHistogram = true; * * InnertiaOnPanning = AutoToggle.Auto; * LastProjectPath = ""; * LegendExpandLayersOnAdding = true; * * LoadSymbology = true; */ MapBackgroundColor = Color.White; //MeasurementsAreaFieldName = "Area"; MeasurementsAreaPrecision = 3; MeasurementsAreaUnits = AreaUnits.SquareMeters; MeasurementsAreaWidth = 14; // MeasurementsLengthFieldName = "Length"; MeasurementsLengthPrecision = 3; MeasurementsLengthUnits = LengthUnits.Meters; MeasurementsLengthWidth = 14; //MeasurementsPerimeterFieldName = "Perimeter"; MeasuringAngleFormat = AngleFormat.Degrees; MeasuringAnglePrecision = 1; MeasuringAreaPrecision = 1; MeasuringAreaUnits = AreaDisplay.Metric; /* MeasuringBearingType = BearingType.Absolute; * MeasuringFillColor = Color.Orange; * MeasuringFillTransparency = 100;*/ MeasuringLengthPrecision = 1; MeasuringLengthUnits = LengthDisplay.Metric; MeasuringLineColor = Color.Orange; MeasuringLineStyle = DashStyle.Solid; MeasuringLineWidth = 2; MeasuringPointLabelsVisible = true; MeasuringPointsVisible = true; MeasuringShowBearing = true; MeasuringShowLength = true; MeasuringShowTotalLength = true; /* MouseTolerance = 10; * MouseWheelDirection = MouseWheelDirection.Forward; * OgrMaxFeatureCount = 50000; * OgrShareConnection = false;*/ OverviewBackgroundVisible = true; /* PrintingUnits = 0; * PrintingMargins = new Margins(25, 25, 50, 50); * PrintingOrientation = Orientation.Vertical; * PrintingPaperFormat = "A4"; * PrintingTemplate = ""; * ProjectionAbsence = ProjectionAbsence.IgnoreAbsence; * ProjectionMismatch = ProjectionMismatch.Reproject; * ProjectionShowLoadingReport = true; * PyramidCompression = TiffCompression.Auto; * PyramidSampling = RasterOverviewSampling.Nearest; * QueryBuilderShowValue = true; * QueryBuilderSelectionOperation = SelectionOperation.New; * RasterDownsamplingMode = InterpolationType.Bilinear; * RasterUpsamplingMode = InterpolationType.None; * ResizeBehavior = ResizeBehavior.KeepScale; * ReuseTileBuffer = true;*/ ScalebarUnits = ScalebarUnits.GoogleStyle; /* ShapeEditorShowLabels = true; * ShapeEditorShowAttributeDialog = true; * ShapeEditorShowBearing = false; * ShapeEditorBearingType = BearingType.Absolute; * ShapeEditorBearingPrecision = 1; * ShapeEditorAngleFormat = AngleFormat.Degrees; * ShapeEditorShowLength = true; * ShapeEditorShowArea = true; * ShapeEditorUnits = LengthDisplay.Metric; * ShapeEditorUnitPrecision = 1;*/ ShowCoordinates = true; ShowMenuToolTips = false; ShowPluginInToolTip = false; // perhaps some kind of debug mode will be enough /* ShowProjectionAbsenceDialog = true; * ShowProjectionMismatchDialog = true; * ShowPyramidDialog = true; * ShowRedrawTime = false;*/ ShowScalebar = true; /* ShowSpatialIndexDialog = false; * ShowValuesOnMouseMove = true;*/ ShowWelcomeDialog = true; /* ShowZoombar = true; * SpatialIndexFeatureCount = 10000; * SymbolobyStorage = SymbologyStorage.Project; * TableEditorFormatValues = true; * TableEditorLayout = TableEditorLayout.Tabbed; * TableEditorShowAliases = true; * TaskRunInBackground = false; * TilesAutoDetectProxy = true; * TilesUseRamCache = true; * TilesMaxRamSize = 100.0; * TilesUseDiskCache = true; * TilesDatabase = string.Empty; * TilesMaxDiskSize = 300.0; * TilesMaxDiskAge = TilesMaxAge.Month3; * TilesProxyAddress = string.Empty; * TilesProxyPassword = string.Empty; * TilesProxyUserName = string.Empty; * TilesUseProxy = true; * ToolOutputAddToMap = true; * ToolOutputInMemory = true; * ToolOutputOverwrite = false; * ToolShowGdalOptionsDialog = true; * UpdaterCheckNewVersion = true; * UpdaterHasNewInstaller = false; * UpdaterIsDownloading = false; * UpdaterLastChecked = new DateTime(2015, 1, 1); * WmsDiskCaching = true; * WmsLastServer = string.Empty; * ZoomBarVerbosity = ZoomBarVerbosity.Full; * ZoomBehavior = ZoomBehavior.UseTileLevels; * ZoomBoxStyle = ZoomBoxStyle.Blue;*/ Logger.Current.Trace("End AppConfig.SetDefaults()"); }
public void OnMouseDown(int button, int shift, int x, int y) { this._tool.OnMouseDown(button, shift, x, y); IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment; if (engineEditor.SnapAgentCount < 1) { Editor.UniqueInstance.OperationStack.Undo(); MessageBox.Show("没有设置捕捉图层!"); } else { IFeatureLayer layer = EditTask.UnderLayers[0] as IFeatureLayer; IFeatureClass featureClass = layer.FeatureClass; IEngineFeatureSnapAgent agent = engineEditor.get_SnapAgent(0) as IEngineFeatureSnapAgent; IDataset dataset = featureClass as IDataset; IDataset dataset2 = agent.FeatureClass as IDataset; if (!dataset.Name.Equals(dataset2.Name)) { Editor.UniqueInstance.OperationStack.Undo(); MessageBox.Show("没有将征占点图层设置为捕捉图层!"); } else { IEngineEditSketch sketch = Editor.UniqueInstance.EngineEditor as IEngineEditSketch; int index = featureClass.FindField("XMBH"); IClone lastPoint = sketch.LastPoint as IClone; IPoint point = lastPoint.Clone() as IPoint; IGeoDataset dataset3 = featureClass as IGeoDataset; if (point.SpatialReference.Name != dataset3.SpatialReference.Name) { point.Project(dataset3.SpatialReference); } IGeometry geometry = (point as ITopologicalOperator).Buffer(0.0002); ISpatialFilter filter = new SpatialFilterClass { Geometry = geometry, SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects, SubFields = "XMBH", GeometryField = featureClass.ShapeFieldName }; IFeatureCursor o = featureClass.Search(filter, false); IFeature feature = o.NextFeature(); Marshal.ReleaseComObject(o); o = null; if (feature == null) { Editor.UniqueInstance.OperationStack.Undo(); MessageBox.Show("必须捕捉征占点!"); } else if (!feature.HasOID || feature.Shape.IsEmpty) { Editor.UniqueInstance.OperationStack.Undo(); MessageBox.Show("捕捉的征占点没有OID或图形有问题!"); } else { IPolyline polyline = sketch.Geometry as IPolyline; if (this.ps == 0) { int num2; int num3; this._firstValue = feature.get_Value(index); IPoint mapPoint = (feature.Shape as IClone).Clone() as IPoint; mapPoint.Project(polyline.SpatialReference); this._hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(mapPoint, out num2, out num3); polyline.FromPoint = mapPoint; polyline.ToPoint = mapPoint; } else if (this.ps >= 1) { object obj2 = feature.get_Value(index); if (!this._firstValue.Equals(obj2)) { Editor.UniqueInstance.OperationStack.Undo(); MessageBox.Show("必须捕捉项目编号相同的征占点!"); return; } IPoint point3 = (feature.Shape as IClone).Clone() as IPoint; point3.Project(polyline.SpatialReference); polyline.ToPoint = point3; } sketch.Geometry = polyline; this.ps++; } } } }
private void SnapPoint() { IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment; IEngineEditSketch sketch = Editor.UniqueInstance.EngineEditor as IEngineEditSketch; IPointCollection points = sketch.Geometry as IPointCollection; bool flag = false; if (sketch.GeometryType == esriGeometryType.esriGeometryPolygon) { flag = true; } if ((points.PointCount != 1) && (!flag || (points.PointCount != 2))) { IEngineFeatureSnapAgent agent2 = engineEditor.get_SnapAgent(0) as IEngineFeatureSnapAgent; esriSpatialRelEnum esriSpatialRelIntersects = esriSpatialRelEnum.esriSpatialRelIntersects; if (agent2.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { esriSpatialRelIntersects = esriSpatialRelEnum.esriSpatialRelTouches; } IPoint lastPoint = sketch.LastPoint; List <IFeature> pFeatures = new List <IFeature>(); ISpatialFilter filter = new SpatialFilterClass { Geometry = lastPoint, SpatialRel = esriSpatialRelIntersects, SubFields = agent2.FeatureClass.OIDFieldName + "," + agent2.FeatureClass.ShapeFieldName, GeometryField = agent2.FeatureClass.ShapeFieldName }; IFeatureCursor o = agent2.FeatureClass.Search(filter, false); IFeature item = o.NextFeature(); while (item != null) { if (item.HasOID && !item.Shape.IsEmpty) { pFeatures.Add(item); item = o.NextFeature(); } } Marshal.ReleaseComObject(o); if (pFeatures.Count >= 1) { IPoint queryPoint = null; if (flag) { queryPoint = points.get_Point(points.PointCount - 3); } else { queryPoint = points.get_Point(points.PointCount - 2); } List <IFeature> list2 = new List <IFeature>(); filter = new SpatialFilterClass { Geometry = queryPoint, SpatialRel = esriSpatialRelIntersects, SubFields = agent2.FeatureClass.OIDFieldName + "," + agent2.FeatureClass.ShapeFieldName, GeometryField = agent2.FeatureClass.ShapeFieldName }; o = null; o = agent2.FeatureClass.Search(filter, false); item = o.NextFeature(); while (item != null) { if (item.HasOID && !item.Shape.IsEmpty) { list2.Add(item); item = o.NextFeature(); } } Marshal.ReleaseComObject(o); if (list2.Count >= 1) { IList <IFeature> list3 = new List <IFeature>(); for (int i = 0; i < list2.Count; i++) { if (this.ContainFeature(pFeatures, list2[i])) { list3.Add(list2[i]); } } IFeature feature2 = null; if (list3.Count == 1) { feature2 = list3[0]; } else { if (list3.Count == 0) { return; } if (list3.Count == pFeatures.Count) { IFeatureLayer pLayer = Editor.UniqueInstance.SnapLayers[0]; SnapExFeatures features = new SnapExFeatures(pFeatures, this._hookHelper, pLayer); features.ShowDialog(); if (features.Index == -1) { return; } feature2 = pFeatures[features.Index]; features = null; } } double hitDistance = -1.0; int hitSegmentIndex = -1; int hitPartIndex = -1; bool bRightSide = false; IGeometry geometry = this.ProjectGeometry(feature2.Shape); IHitTest test = geometry as IHitTest; if (test.HitTest(lastPoint, engineEditor.SnapTolerance, esriGeometryHitPartType.esriGeometryPartVertex, null, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide)) { int num5 = -1; double num6 = -1.0; int num7 = -1; int num8 = -1; bool flag4 = false; int part = sketch.Part; IHitTest test2 = geometry as IHitTest; if (test2.HitTest(queryPoint, engineEditor.SnapTolerance, esriGeometryHitPartType.esriGeometryPartVertex, null, ref num6, ref num8, ref num7, ref flag4)) { IPolyline polyline3; if (flag) { num5 = points.PointCount - 2; } else { num5 = points.PointCount - 1; } IGeometryCollection geometrys = geometry as IGeometryCollection; IPointCollection points2 = geometrys.get_Geometry(hitPartIndex) as IPointCollection; IPolyline polyline = new PolylineClass(); IPolyline polyline2 = new PolylineClass(); IPointCollection points3 = polyline as IPointCollection; IPointCollection points4 = polyline2 as IPointCollection; object before = Missing.Value; object after = Missing.Value; IPoint inPoint = null; bool flag6 = false; if (num7 > hitSegmentIndex) { int num9 = hitSegmentIndex; hitSegmentIndex = num7; num7 = num9; flag6 = true; } int num10 = 0; if (flag) { for (num10 = num7; num10 <= hitSegmentIndex; num10++) { inPoint = points2.get_Point(num10); points3.AddPoint(inPoint, ref before, ref after); } int num11 = points2.PointCount - 1; for (num10 = hitSegmentIndex; num10 < num11; num10++) { inPoint = points2.get_Point(num10); points4.AddPoint(inPoint, ref before, ref after); } for (num10 = 0; num10 <= num7; num10++) { inPoint = points2.get_Point(num10); points4.AddPoint(inPoint, ref before, ref after); } if (polyline.Length <= polyline2.Length) { polyline3 = polyline; } else { polyline3 = polyline2; flag6 = true; } } else { num10 = num7; while (num10 <= hitSegmentIndex) { inPoint = points2.get_Point(num10); points3.AddPoint(inPoint, ref before, ref after); num10++; } polyline3 = polyline; } IPointCollection points5 = polyline3 as IPointCollection; int index = num5; if (flag6) { for (num10 = points5.PointCount - 2; num10 > 0; num10--) { IPoint newPoints = (points5.get_Point(num10) as IClone).Clone() as IPoint; points.InsertPoints(index, 1, ref newPoints); index++; } } else { for (num10 = 1; num10 < (points5.PointCount - 1); num10++) { IPoint point7 = (points5.get_Point(num10) as IClone).Clone() as IPoint; points.InsertPoints(index, 1, ref point7); index++; } } } } } } } }
private void DrawLinefeedback(IPoint pPoint) { try { int hDC = this._hookHelper.ActiveView.ScreenDisplay.hDC; IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment; if (this._snappingEnv != null) { ISnappingResult snappingResult = this._snappingEnv.PointSnapper.Snap(pPoint); this._snapFeedback.Update(snappingResult, hDC); if ((this._lineFeedback != null) && this._bStarted) { IPoint location = null; if (snappingResult == null) { location = pPoint; } else { location = snappingResult.Location; } try { this._lineFeedback.AddPoint(location); } catch { } IPolyline polyline = this._lineFeedback.Stop(); if (polyline == null) { if (snappingResult != null) { this._lineFeedback.Start(location); } } else { IPointCollection points = (IPointCollection)polyline; if (points.PointCount > 2) { points.RemovePoints(points.PointCount - 1, 1); } double snapTolerance = engineEditor.SnapTolerance; double hitDistance = -1.0; int hitSegmentIndex = -1; int hitPartIndex = -1; bool bRightSide = false; IGeometry geometry = (IGeometry)points; IHitTest test = geometry as IHitTest; if (!test.HitTest(location, snapTolerance, esriGeometryHitPartType.esriGeometryPartVertex, null, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide)) { hitSegmentIndex = -1; } this._lineFeedback.Start(points.get_Point(0)); if (hitSegmentIndex != 0) { for (int i = 1; i < points.PointCount; i++) { IPoint point = points.get_Point(i); this._lineFeedback.AddPoint(point); if (i == hitSegmentIndex) { break; } } } if (snappingResult != null) { this._lineFeedback.AddPoint(location); } } } } } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "ShapeEdit.SnapEx", "DrawLinefeedback", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); } }
private static ISnappingResult OldSnap(IPoint ipoint_0, IActiveView pActiveView, IEngineSnapEnvironment iengineSnapEnvironment_0) { IHitTest mPPointColn; double num; int num1; int num2; bool flag; double mapUnits; IPoint pointClass; ISnappingResult snappingResult = null; if (iengineSnapEnvironment_0 is ISnapEnvironment) { ISnapEnvironment iengineSnapEnvironment0 = iengineSnapEnvironment_0 as ISnapEnvironment; if ( !(iengineSnapEnvironment0 == null || !ApplicationRef.AppContext.Config.UseSnap ? true : !iengineSnapEnvironment0.SnapPoint(SketchToolAssist.LastPoint, ipoint_0))) { SnappingResult snappingResult1 = new SnappingResult() { X = ipoint_0.X, Y = ipoint_0.Y }; snappingResult = snappingResult1; } else if (ApplicationRef.AppContext.Config.IsSnapSketch) { mPPointColn = SketchToolAssist.m_pPointColn as IHitTest; if (mPPointColn != null) { num = 0; num1 = 0; num2 = 0; flag = false; mapUnits = CommonHelper.ConvertPixelsToMapUnits(pActiveView, iengineSnapEnvironment0.SnapTolerance); if (mapUnits == 0) { mapUnits = 3; } pointClass = new ESRI.ArcGIS.Geometry.Point(); if (mPPointColn.HitTest(ipoint_0, mapUnits, esriGeometryHitPartType.esriGeometryPartVertex, pointClass, ref num, ref num1, ref num2, ref flag)) { SnappingResult snappingResult2 = new SnappingResult() { X = pointClass.X, Y = pointClass.Y }; snappingResult = snappingResult2; } } } } else if ( !(iengineSnapEnvironment_0 == null || !ApplicationRef.AppContext.Config.UseSnap ? true : !iengineSnapEnvironment_0.SnapPoint(ipoint_0))) { SnappingResult snappingResult3 = new SnappingResult() { X = ipoint_0.X, Y = ipoint_0.Y }; snappingResult = snappingResult3; } else if (ApplicationRef.AppContext.Config.IsSnapSketch) { mPPointColn = SketchToolAssist.m_pPointColn as IHitTest; if (mPPointColn != null) { num = 0; num1 = 0; num2 = 0; flag = false; mapUnits = iengineSnapEnvironment_0.SnapTolerance; if (iengineSnapEnvironment_0.SnapToleranceUnits == esriEngineSnapToleranceUnits.esriEngineSnapTolerancePixels) { mapUnits = CommonHelper.ConvertPixelsToMapUnits(pActiveView, iengineSnapEnvironment_0.SnapTolerance); } if (mapUnits == 0) { mapUnits = 3; } pointClass = new ESRI.ArcGIS.Geometry.Point(); if (mPPointColn.HitTest(ipoint_0, mapUnits, esriGeometryHitPartType.esriGeometryPartVertex, pointClass, ref num, ref num1, ref num2, ref flag)) { SnappingResult snappingResult4 = new SnappingResult() { X = pointClass.X, Y = pointClass.Y }; snappingResult = snappingResult4; } } } return(snappingResult); }