📄 viewform.cs
字号:
///GeoCon, free tool to create gml & svg from gis files.
///Copyright(C) 2005 Amri Rosyada
///Distributed under GNU-LGPL, see a copy of the license in root directory
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using GeoCon.Data;
using GeoCon.Classification;
namespace GeoCon
{
/// <summary>
/// Form for viewing map.
/// </summary>
public class ViewForm : System.Windows.Forms.Form
{
/// <summary>
/// mapdata collection to display
/// </summary>
private MapDataCollection srcs;
/// <summary>
/// current zoomvalue
/// </summary>
private float zoomvalue=1.0f;
#region private components
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuZoomin;
private System.Windows.Forms.MenuItem menuZoomout;
private System.Windows.Forms.MenuItem menuZoomoriginal;
#endregion
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ViewForm()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.Load+=new EventHandler(ViewForm_Load);
this.Resize+=new EventHandler(ViewForm_Resize);
//this.ResizeRedraw =true;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ViewForm));
this.panel1 = new System.Windows.Forms.Panel();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuZoomin = new System.Windows.Forms.MenuItem();
this.menuZoomout = new System.Windows.Forms.MenuItem();
this.menuZoomoriginal = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(144, 104);
this.panel1.TabIndex = 0;
this.panel1.Resize += new System.EventHandler(this.panel1_Resize);
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuZoomin,
this.menuZoomout,
this.menuZoomoriginal,
this.menuItem5,
this.menuItem4});
this.menuItem1.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.menuItem1.Text = "Menu";
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Text = "Refresh";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuZoomin
//
this.menuZoomin.Index = 1;
this.menuZoomin.Text = "Zoom In";
this.menuZoomin.Click += new System.EventHandler(this.menuZoomin_Click);
//
// menuZoomout
//
this.menuZoomout.Index = 2;
this.menuZoomout.Text = "Zoom Out";
this.menuZoomout.Click += new System.EventHandler(this.menuZoomout_Click);
//
// menuZoomoriginal
//
this.menuZoomoriginal.Index = 3;
this.menuZoomoriginal.Text = "Zoom Original";
this.menuZoomoriginal.Click += new System.EventHandler(this.menuZoomoriginal_Click);
//
// menuItem5
//
this.menuItem5.Index = 4;
this.menuItem5.Text = "-";
//
// menuItem4
//
this.menuItem4.Index = 5;
this.menuItem4.Text = "Close";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// ViewForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(304, 217);
this.Controls.Add(this.panel1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.MinimumSize = new System.Drawing.Size(50, 50);
this.Name = "ViewForm";
this.Text = "View";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// close the form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem4_Click(object sender, System.EventArgs e)
{
this.Close();
}
/// <summary>
/// Refresh this view for specified mapdata collection
/// </summary>
/// <param name="maps">mapdata collection to display</param>
public void DrawGraphics(MapDataCollection maps)
{
srcs=maps;
panel1.Update();
}
/// <summary>
/// Refresh view
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem3_Click(object sender, System.EventArgs e)
{
panel1.Invalidate();
//panel1.Update();
}
/// <summary>
/// Draws shape of current mapdata collection
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void panel1_Paint(object sender, PaintEventArgs e)
{
MapDataCollection maps=srcs;
if(maps==null) return;
int activelayers=0;
for(int i=0;i<maps.Count;i++) activelayers+=maps[i].Fields.getActiveCount(false);
if(activelayers<1) return; //no active layers
gml.BoxType box=maps.GetBoundingBox();
float l = (float)box.Left;
float b = (float)box.Bottom;
float r = (float)box.Right;
float t = (float)box.Top;
float scl = zoomvalue*Math.Min(panel1.Bounds.Width/(r-l),panel1.Bounds.Height/(t-b));
Graphics g = e.Graphics;
g.Transform = new System.Drawing.Drawing2D.Matrix(1,0,0,-1,0,scl*(b+t));
g.TranslateTransform(-l*scl,-b*scl,System.Drawing.Drawing2D.MatrixOrder.Append);
g.ScaleTransform(scl,scl,System.Drawing.Drawing2D.MatrixOrder.Prepend);
float maxdim = Math.Max(r-l,t-b);
double diagonal = (Math.Sqrt((r-l)*(r-l)+(t-b)*(t-b)));
Pen p = new Pen(Color.Red,maxdim/200);
Brush br = Brushes.DarkBlue;
//for(int i=0;i<maps.Count;i++)
for(int i=maps.Count-1; i>=0;i--)
{
if(!maps[i].isActive) continue;
GeometryField fgeo=maps[i].Fields.GetGeometryField();
for(int k=0;k<maps[i].Bins.Count;k++)
{
Bin bin = maps[i].Bins[k];
p = bin.Symbol.Pen;
br= bin.Symbol.Brush;
//point-radius scaling
double pr = 0.01*bin.Symbol.PointRadiusMap*diagonal;
//line-width scaling
float oldwidth=p.Width;
p.Width = (float)(0.01*bin.Symbol.LineWidthMap*diagonal);
foreach (int ci in bin.ContentsIndex)
{
if(fgeo[ci]==null || fgeo[ci]==fgeo.NullSymbol) continue;
gml.GeometryPropertyType gpt = (gml.GeometryPropertyType)(fgeo[ci]);
if(gpt.Item==null) continue;
gpt.Item.PointRadius=pr;
gpt.Item.DrawGraphics(ref g, ref p, ref br);
gpt=null;
}
p.Width = oldwidth;//width re-scaling
}
}
}
private void panel1_Resize(object sender, EventArgs e)
{
panel1.Invalidate();
}
private void menuCopy_Click(object sender, System.EventArgs e)
{
//TODO : Add code to capture and paste graphics to clipboard
//but why would i want do that? export to svg will do just fine
}
private void menuSave_Click(object sender, System.EventArgs e)
{
}
private void menuZoomoriginal_Click(object sender, System.EventArgs e)
{
panel1.Size=this.ClientSize;
panel1.Invalidate();
}
private void menuZoomout_Click(object sender, System.EventArgs e)
{
panel1.Size=new Size(panel1.Size.Width*2/3,panel1.Size.Height*2/3);
panel1.Invalidate();
}
private void menuZoomin_Click(object sender, System.EventArgs e)
{
panel1.Size=new Size(panel1.Size.Width*3/2,panel1.Size.Height*3/2);
panel1.Invalidate();
}
private void ViewForm_Load(object sender, EventArgs e)
{
System.Drawing.Point loc = new Point();
loc.X = this.Owner.DesktopLocation.X;
loc.Y = this.Owner.DesktopLocation.Y+this.Owner.DesktopBounds.Height/2;
this.DesktopLocation=loc;
this.panel1.Size=this.ClientSize;
}
private void ViewForm_Resize(object sender, EventArgs e)
{
if(this.panel1.Size.Width>this.ClientSize.Width || this.panel1.Size.Height>this.ClientSize.Height) return;
this.panel1.Size=this.ClientSize;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -