/// <summary> /// 开始编辑按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStartEdit_Click(object sender, EventArgs e) { try { mEngineEditor = new EngineEditorClass(); mEngineEditTask = mEngineEditor as IEngineEditTask; mEngineEditLayers = mEngineEditor as IEngineEditLayers; mMap = MainMapControl.Map; mActiveView = mMap as IActiveView; mlistLayers = MapOperation.GetLayers(mMap); if (mlistLayers == null || mlistLayers.Count == 0) { MessageBox.Show("请加载编辑图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } mMap.ClearSelection(); mActiveView.Refresh(); InitComboBox(mlistLayers); ChangeButtonState(true); // 如果编辑已经开始,则直接退出 if (mEngineEditor.EditState != esriEngineEditState.esriEngineStateNotEditing) { return; } if (mCurrentLyr == null) { return; } // 获取当前编辑图层工作空间 IDataset dataset = mCurrentLyr.FeatureClass as IDataset; IWorkspace workspace = dataset.Workspace; // 设置编辑模式,如果是ArcSDE采用版本模式 if (workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned; } else { mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeNonVersioned; } // 设置编辑任务 mEngineEditTask = mEngineEditor.GetTaskByUniqueName("ControlToolsEditing_CreateNewFeatureTask"); mEngineEditor.CurrentTask = mEngineEditTask; //是否可以进行撤销、恢复操作 mEngineEditor.EnableUndoRedo(true); //开始编辑操作 mEngineEditor.StartEditing(workspace, mMap); } catch (Exception ex) { } }
//开始编辑 private void btnStartEdit_Click(object sender, EventArgs e) { label1.Visible = true; cmbSelLayer.Visible = true; button1.Visible = true; ChangeButtonState(true); plstLayers = MapManager.GetLayers(axMap.Map); for (int i = 0; i < plstLayers.Count; i++) { cmbSelLayer.Items.Add(plstLayers[i].Name); } try { if (plstLayers == null || plstLayers.Count == 0) { MessageBox.Show("请加载编辑图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } pMap.ClearSelection(); pActiveView.Refresh(); InitComboBox(plstLayers); ChangeButtonState(true); //如果编辑已经开始,则直接退出 if (pEngineEditor.EditState != esriEngineEditState.esriEngineStateNotEditing) { return; } if (pCurrentLyr == null) { return; } //获取当前编辑图层工作空间 IDataset pDataSet = pCurrentLyr.FeatureClass as IDataset; IWorkspace pWs = pDataSet.Workspace; //设置编辑模式,如果是ArcSDE采用版本模式 if (pWs.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { pEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned; } else { pEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeNonVersioned; } //设置编辑任务 pEngineEditTask = pEngineEditor.GetTaskByUniqueName("ControlToolsEditing_CreateNewFeatureTask"); pEngineEditor.CurrentTask = pEngineEditTask; // 设置编辑任务 pEngineEditor.EnableUndoRedo(true); //是否可以进行撤销、恢复操作 pEngineEditor.StartEditing(pWs, pMap); //开始编辑操作 } catch (Exception ex) { } }
//开始编辑 private void btnStart_Click(object sender, EventArgs e) { try { if (pCurrentLyr == null) { MessageBox.Show("请选择编辑图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } setEditToolEnable(true); //如果编辑已经开始,则直接退出 if (pEngineEditor.EditState != esriEngineEditState.esriEngineStateNotEditing) { return; } if (pCurrentLyr == null) { return; } //获取当前编辑图层工作空间 pDataSet = pCurrentLyr.FeatureClass as IDataset; pWs = pDataSet.Workspace; pEngineEditTask = pEngineEditor.GetTaskByUniqueName("ControlToolsEditing_CreateNewFeatureTask"); pEngineEditor.CurrentTask = pEngineEditTask; // 设置编辑任务 pEngineEditor.EnableUndoRedo(true); //是否可以进行撤销、恢复操作 //设置编辑模式,如果是ArcSDE采用版本模式 if (pWs.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { IVersionedObject3 versionedObject = pDataSet as IVersionedObject3; //注册版本 if (versionedObject != null && !versionedObject.IsRegisteredAsVersioned) { versionedObject.RegisterAsVersioned(true); } pEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned; } //else //{ // pEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeNonVersioned; //} //设置编辑任务 pEngineEditor.StartEditing(pWs, pMap); isEditing = true; //SysLogHelper.WriteOperationLog("数据编辑", "开始编辑", "数据管理"); } catch (Exception ex) { MessageBox.Show(ex.Message); PS.Plot.Common.LogHelper.WriteLog(typeof(Form_Editor), ex, "开始编辑"); } }
private void menuStartEdit_Click(object sender, EventArgs e) { map = axMapControl1.Map; activeView = map as IActiveView; if (axMapControl1.Map.LayerCount == 0) { MessageBox.Show("请加载编辑图层", "提示", MessageBoxButtons.OK); return; } map.ClearSelection(); activeView.Refresh(); //调用操作函数,将“开始编辑”设置为非激活状态,其他子菜单项设置为激活状态 ChangeButtonState(false); //初始化“图层选择” menuSelectLayer.Items.Clear(); for (int i = 0; i < axMapControl1.LayerCount; i++) { menuSelectLayer.Items.Add(axMapControl1.Map.get_Layer(i).Name); } //默认选择顶层图层 if (menuSelectLayer.Items.Count != 0) { menuSelectLayer.SelectedIndex = 0; } //获取当前编辑图层工作空间 IDataset dataSet = currentLayer.FeatureClass as IDataset; IWorkspace workspace = dataSet.Workspace; //设置编辑模式,如果是ArcSDE采用版本模式 if (workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { engineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned; } else { engineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeNonVersioned; } //设置编辑任务 engineEditTask = engineEditor.GetTaskByUniqueName("ControlToolsEditing_CreateNewFeatureTask"); engineEditor.CurrentTask = engineEditTask; engineEditor.EnableUndoRedo(true); //是否可以进行撤销、恢复操作 engineEditor.StartEditing(workspace, map); //开始编辑操作 }
private void EditorForm_Load(object sender, EventArgs e) { //********* Important ************* //Obtain a reference to the MainForm using the EditHelper class m_mainForm = EditHelper.TheMainForm; m_mapControl = m_mainForm.MapControl; //buddy the toolbars with the MapControl axBlankToolBar.SetBuddyControl(m_mapControl); axModifyToolbar.SetBuddyControl(m_mapControl); axReshapeToolbar.SetBuddyControl(m_mapControl); axUndoRedoToolbar.SetBuddyControl(m_mapControl); axCreateToolbar.SetBuddyControl(m_mapControl); //Create and share command pool m_pool = new CommandPoolClass(); axCreateToolbar.CommandPool = m_pool; axBlankToolBar.CommandPool = m_pool; axModifyToolbar.CommandPool = m_pool; axReshapeToolbar.CommandPool = m_pool; axUndoRedoToolbar.CommandPool = m_pool; //Create and share operation stack m_operationStack = new ControlsOperationStackClass(); axModifyToolbar.OperationStack = m_operationStack; axReshapeToolbar.OperationStack = m_operationStack; axUndoRedoToolbar.OperationStack = m_operationStack; axCreateToolbar.OperationStack = m_operationStack; //load items for the axModifyToolbar axModifyToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axModifyToolbar.AddItem("VertexCommands_CS.CustomVertexCommands", 1, 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axModifyToolbar.AddItem("VertexCommands_CS.CustomVertexCommands", 2, 2, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //load items for the axReshapeToolbar axReshapeToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axReshapeToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //load items for the axCreateToolbar axCreateToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //set up the EngineEditor m_engineEditor = new EngineEditorClass(); m_engineEditor.EnableUndoRedo(true); ((IEngineEditProperties2)m_engineEditor).StickyMoveTolerance = 10000; object tbr = (object)axCreateToolbar.Object; IExtension engineEditorExt = m_engineEditor as IExtension; engineEditorExt.Startup(ref tbr); //ensures that the operationStack will function correctly //Listen to OnSketchModified engine editor event ((IEngineEditEvents_Event)m_engineEditor).OnSketchModified += new IEngineEditEvents_OnSketchModifiedEventHandler(OnSketchModified); //listen to MainForm events in case application is closed while editing EditHelper.TheMainForm.FormClosing += new FormClosingEventHandler(TheMainForm_FormClosing); #region Form Management m_commands = new ArrayList(); m_commands.Add(cmdModify); m_commands.Add(cmdReshape); m_commands.Add(cmdCreate); DisableButtons(); txtInfo.Text = ""; this.Size = new Size(242, 208); this.FormBorderStyle = FormBorderStyle.FixedSingle; SetErrorLabel(""); EditHelper.IsEditorFormOpen = true; #endregion }
private void EditorForm_Load(object sender, EventArgs e) { //********* Important ************* //Obtain a reference to the MainForm using the EditHelper class m_mainForm = EditHelper.TheMainForm; m_mapControl = m_mainForm.MapControl; //buddy the toolbars with the MapControl axBlankToolBar.SetBuddyControl(m_mapControl); axModifyToolbar.SetBuddyControl(m_mapControl); axReshapeToolbar.SetBuddyControl(m_mapControl); axUndoRedoToolbar.SetBuddyControl(m_mapControl); axCreateToolbar.SetBuddyControl(m_mapControl); //Create and share command pool m_pool = new CommandPoolClass(); axCreateToolbar.CommandPool = m_pool; axBlankToolBar.CommandPool = m_pool; axModifyToolbar.CommandPool = m_pool; axReshapeToolbar.CommandPool = m_pool; axUndoRedoToolbar.CommandPool = m_pool; //Create and share operation stack m_operationStack = new ControlsOperationStackClass(); axModifyToolbar.OperationStack = m_operationStack; axReshapeToolbar.OperationStack = m_operationStack; axUndoRedoToolbar.OperationStack = m_operationStack; axCreateToolbar.OperationStack = m_operationStack; //load items for the axModifyToolbar axModifyToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axModifyToolbar.AddItem("VertexCommands_CS.CustomVertexCommands", 1, 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axModifyToolbar.AddItem("VertexCommands_CS.CustomVertexCommands", 2, 2, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //load items for the axReshapeToolbar axReshapeToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axReshapeToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //load items for the axCreateToolbar axCreateToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, 0, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //set up the EngineEditor m_engineEditor = new EngineEditorClass(); m_engineEditor.EnableUndoRedo(true); ((IEngineEditProperties2)m_engineEditor).StickyMoveTolerance = 10000; object tbr = (object)axCreateToolbar.Object; IExtension engineEditorExt = m_engineEditor as IExtension; engineEditorExt.Startup(ref tbr); //ensures that the operationStack will function correctly //Listen to OnSketchModified engine editor event ((IEngineEditEvents_Event)m_engineEditor).OnSketchModified += new IEngineEditEvents_OnSketchModifiedEventHandler(OnSketchModified); //listen to MainForm events in case application is closed while editing EditHelper.TheMainForm.FormClosing += new FormClosingEventHandler(TheMainForm_FormClosing); #region Form Management m_commands = new ArrayList(); m_commands.Add(cmdModify); m_commands.Add(cmdReshape); m_commands.Add(cmdCreate); DisableButtons(); txtInfo.Text = ""; this.Size = new Size(242, 208); this.FormBorderStyle = FormBorderStyle.FixedSingle; SetErrorLabel(""); EditHelper.IsEditorFormOpen = true; #endregion }
private void barButtonItem8_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { pEngineEditor = new EngineEditorClass(); MapManagement.EngineEditor = pEngineEditor; pEngineEditTask = pEngineEditor as IEngineEditTask; pEngineEditLayers = pEngineEditor as IEngineEditLayers; pMap = Variable.pMapFrm.mainMapControl.Map; pActiveView = pMap as IActiveView; pLayerlist = MapManagement.GetMapLayers(pMap); try { if (pLayerlist == null || pLayerlist.Count == 0) { MessageBox.Show("请在主视图中加载编辑图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } for (int i = 0; i < pLayerlist.Count; i++) { ((DevExpress.XtraEditors.Repository.RepositoryItemComboBox) this.barEditItem1.Edit).Items.Add(pLayerlist[i].Name); } this.barEditItem1.EditValue = ((DevExpress.XtraEditors.Repository.RepositoryItemComboBox) this.barEditItem1.Edit).Items[0]; pMap.ClearSelection(); pActiveView.Refresh(); //设置数据管理中要素管理未开始编辑状态,图层选择、添加要素、选择编辑要素、要素属性编辑、结束编辑等功能变成正常状态,使得可以操作。 barEditItem1.Enabled = true; barButtonItem12.Enabled = true; barButtonItem14.Enabled = true; barButtonItem13.Enabled = true; barButtonItem15.Enabled = true; barButtonItem4.Enabled = true; barButtonItem20.Enabled = true; barButtonItem22.Enabled = true; barButtonItem21.Enabled = true; barButtonItem23.Enabled = true; if (pEngineEditor.EditState != esriEngineEditState.esriEngineStateNotEditing) { return; } if (pCurrentLayer == null) { return; } IDataset pDataSet = pCurrentLayer.FeatureClass as IDataset; IWorkspace pWorkspace = pDataSet.Workspace; if (pWorkspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { pEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned; } else { pEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned; } pEngineEditTask = pEngineEditor.GetTaskByUniqueName("ControlToolsEditing_CreateNewFeatureTask"); pEngineEditor.CurrentTask = pEngineEditTask; pEngineEditor.EnableUndoRedo(true); pEngineEditor.StartEditing(pWorkspace, pMap); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常"); } }