private void WriteCustomXML(CustomTool tool) { string xmlPath = @"data/data_custom.xml"; XDocument xDocument = XDocument.Load(xmlPath); XElement root = xDocument.Element(@"tools"); IEnumerable <XElement> rows = root.Descendants("tool"); if (rows.Count() == 0) { root.Add(new XElement("tool", new XElement("name", tool.name), new XElement("desc", tool.desc), new XElement("path", tool.path))); } else { XElement lastRow = rows.Last(); lastRow.AddAfterSelf( new XElement("tool", new XElement("name", tool.name), new XElement("desc", tool.desc), new XElement("path", tool.path))); } xDocument.Save(xmlPath); }
//平移 private void ToolButtonPan_Click(object sender, EventArgs e) { ICommand pan = new ControlsMapPanTool(); pan.OnCreate(m_mapControl); m_mapControl.CurrentTool = pan as ITool; currentTool = CustomTool.None; }
//缩小 private void ToolButtonZoomOut_Click(object sender, EventArgs e) { ICommand zoomOut = new ControlsMapZoomOutTool(); zoomOut.OnCreate(m_mapControl); m_mapControl.CurrentTool = zoomOut as ITool; currentTool = CustomTool.None; }
//激活或者关闭公路断点删除工具 private void barButtonItem28_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (currentTool == CustomTool.BarryRemove) { currentTool = CustomTool.None; return; } currentTool = CustomTool.BarryRemove; }
//激活或者关闭公路断点插入工具 private void barButtonItem27_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (currentTool == CustomTool.BarryInsert) { currentTool = CustomTool.None; return; } currentTool = CustomTool.BarryInsert; routeUI.DealRoutenetLayer(axMapControl1); }
private static string GenerateCodeForType(Type type, string targetNamespace, string previousOutput) { string output = GetXmlSerializerOutput(type); System.CodeDom.CodeNamespace ns = InitializeCodeDom(targetNamespace); output = CleanupXmlSerializerCode(targetNamespace, output); // Find the methods that are the entry points for reading and writing the object. Match readMatch = PublicRead.Match(output); Match writeMatch = PublicWrite.Match(output); string rootObject = readMatch.Groups[MethodObjectName].Value; output = MakeSerializerPartial(output, rootObject); output = RenameClasses(output, rootObject); output = NestTypesOnSerialier(output, rootObject); output = AppendReaderWriterMembersToObjectSerializer(type, output, rootObject); CodeTypeDeclaration readerDeclaration = CreateAndAddEventRisingReader(targetNamespace, ns, rootObject, output, previousOutput); output = PrivateReadMethodsToProtectedVirtual(output); CodeTypeDeclaration writerDeclaration = CreateAndAddTypedWriter(targetNamespace, ns, rootObject); // Renders TemplateReadMethod (see that constant declaration) output = AddTypedRead(readerDeclaration, type, output, readMatch); // Renders TemplateWriteMethod (see that constant declaration) output = AddTypedWrite(writerDeclaration, type, output, writeMatch); output = MergeOutputWithCodeDom(output, ns); output = MakeClassesInternal(output); output = NormalizeLineEndings(output); output = NestTypesOnSerialier(output, rootObject); output = FixInstantiationOfNestedTypes(output, rootObject); output = @" #pragma warning disable 0642, 0219 " + output + @" #pragma warning restore 0642, 0219"; output = CustomTool.GetToolGeneratedCodeWarning(typeof(XGenTool)) + output; #if DEBUG return(@"#region Original XmlSerializer code /* ------------------------------------------------------------------------------------- " + GetXmlSerializerOutput(type) + @" -------------------------------------------------------------------------------------*/ " + @"#endregion " + output); #else return(output); #endif }
//计算最优路线 //最后可以考虑使用async进行异步查询 private void barButtonItem16_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (routeUI.StopPoints.Count < 2) { MessageBox.Show("路线经过点少于两个"); return; } this.routeNetLayer = routeUI.DealRoutenetLayer(this.axMapControl1); if (routeNetLayer == null) { MessageBox.Show("未找到公路网图层"); return; } currentTool = CustomTool.None; infoWindow = new ProInfoWindow(); infoWindow.Show(); timer1.Enabled = true; }
private void AddButton_Click(object sender, RoutedEventArgs e) { if (NameInputBox.Text != String.Empty && DescInputBox.Text != String.Empty && FileOK.IsChecked == true) { toolName = NameInputBox.Text; toolDesc = DescInputBox.Text; //MessageBox.Show(toolName + "\n" + toolPath + "\n" + toolDesc); var tool = new CustomTool() { name = toolName, path = toolPath, desc = toolDesc }; WriteCustomXML(tool); this.Close(); } else { MessageBox.Show("Fill"); } }
//激活或者关闭公路经过点插入工具 private void barButtonItem26_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (currentTool == CustomTool.StopInsert) { currentTool = CustomTool.None; return; } currentTool = CustomTool.StopInsert; //m_mapControl.MousePointer = esriControlsMousePointer.esriPointerLabel; routeUI.DealRoutenetLayer(axMapControl1); /* * if (this.axMapControl1.CurrentTool == stopsInsertTool) * { * this.axMapControl1.CurrentTool = null; * return; * } * stopsInsertTool.OnCreate(this.axMapControl1);//绑定到mapcontrol * stopsInsertTool.OnClick();//执行itool的click事件 * this.axMapControl1.CurrentTool = stopsInsertTool;//设置当前工具 */ }
//操作图层选择 private void LayerSelect_Click(object sender, EventArgs e) { if (currentTool == CustomTool.RectSelect) { this.toolStripButton9.Text = "矩形框查询"; currentTool = CustomTool.None; this.axMapControl1.Map.ClearSelection(); this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGeography, null, null); return; } //if (string.IsNullOrEmpty(toolComboBox.Text)) //{ // MessageBox.Show("请先选择操作图层"); // return; //} //改变鼠标形状 m_mapControl.MousePointer = esriControlsMousePointer.esriPointerArrow; this.toolStripButton9.Text = "停止查询"; // //将mapcontrol的tool设为nothing,不然会影响效果 m_mapControl.CurrentTool = null; currentTool = CustomTool.RectSelect; }
public static void UnregisterClass(Type t) { CustomTool.UnRegister(typeof(XGenTool)); }
public static void RegisterClass(Type type) { CustomTool.Register(typeof(XGenTool)); }
//指针按钮事件 去除其它操作鼠标命令 private void toolStripButton2_Click(object sender, EventArgs e) { this.axMapControl1.CurrentTool = null; this.currentTool = CustomTool.None; }
/// <summary>Adds a custom tool to the toolbar.</summary> /// <param name="toolbar">The toolbar to add to.</param> /// <param name="viewModel">The view-model for the custom tool UI.</param> /// <param name="id">The unique identifier of the tool.</param> /// <param name="minWidth">The minimum width of the tool.</param> /// <param name="column">The index of the column the tool is in (0-based, zero by default).</param> /// <param name="row">The index of the row the tool is in (0-based, zero by default).</param> /// <param name="columnSpan">The number of rows the tool spans (1-based, one by default. Must be 1 or greater).</param> /// <param name="rowSpan">The number of columns the tool spans (1-based, one by default. Must be 1 or greater).</param> public static ICustomTool AddCustomTool( this IToolBar toolbar, IViewFactory viewModel, object id = null, int minWidth = 0, int? column = null, int? row = null, int? columnSpan = 1, int? rowSpan = 1) { // Setup initial conditions. if (toolbar == null) throw new ArgumentNullException("toolbar"); if (viewModel == null) throw new ArgumentNullException("viewModel"); // Create the tool and add it to the toolbar. var tool = new CustomTool(viewModel) { Id = id, MinWidth = minWidth }; toolbar.Add(tool, column, row, columnSpan, rowSpan); // Finish up. return tool; }