📄 mainform.cs
字号:
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
private void MainForm_Load(object sender, System.EventArgs e)
{
//nothing
}
#endregion
#region menuFile mouse events
//TODO : update status bar while writing?
// NYET! my precious.., my precious memory...
// using delegate while reading not a problem, they're on the same domain.
// but not on writing; GML export use separate domain;
// passing a delegate to maps will put it in default domain, therefore can't be unloaded.
/// <summary>
/// Imports new map source to the map collection.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuFileAdd_Click(object sender, System.EventArgs e)
{
try
{
System.Windows.Forms.OpenFileDialog ofd=new OpenFileDialog();
ofd.Multiselect =true;
ofd.Filter="All Supported Types|*.shp;*.mif; | ArcView Shape (*.shp)|*.shp|MapInfo Mif (*.mif)|*.mif";
ofd.ShowDialog();
this.Update();
string[] fns = ofd.FileNames;
ofd.Dispose();
ofd=null;
if (fns==null || fns.Length<1)return;
Cursor.Current = Cursors.WaitCursor;
if(maps==null) maps=new MapDataCollection();
for(int m=0;m<fns.Length;m++)
{
//UpdateStatusText("Reading "+fns[m]+"...");
int i = maps.Add(ReadMap(fns[m]));
if(i<0) continue;
string origName=System.IO.Path.GetFileNameWithoutExtension(fns[m]);
maps[i].Name=origName;
}
Cursor.Current = Cursors.Default;
UpdateStatusText("Done.");
dgLayers.SetDataBinding(null,null); //to refresh bound
dgLayers.SetDataBinding(maps,"");
dgLayers_CurrentCellChanged(dgLayers,new System.EventArgs());
if(this.tabControl1.SelectedTab.Name=="tabFields") this.menuField.Enabled=true;
}
catch (System.Exception exc)
{
System.Windows.Forms.MessageBox.Show("Error(s) when importing file \r"+exc.Message);
}
}
/// <summary>
/// Display map preview.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuFilePreview_Click(object sender, System.EventArgs e)
{
RefreshView();
}
/// <summary>
/// Exports MapDataCollection to GML schema and document.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuExportGML_Click(object sender, System.EventArgs e)
{
try
{
if(maps==null) return;
this.Update();
if(maps.Count==0)
{
MessageBox.Show("No file(s) currently loaded.\nPlease.","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
System.Windows.Forms.SaveFileDialog sfd=new SaveFileDialog();
sfd.Filter="GML |*.gml";
sfd.ShowDialog();
this.Update();
if(sfd.FileName=="" || sfd.FileName==null)return;
string fn = System.IO.Path.GetFileNameWithoutExtension(sfd.FileName)+".gml";
sfd.Dispose();
sfd=null;
Cursor.Current = Cursors.WaitCursor;
System.DateTime sebelum=System.DateTime.Now;
string xsfile=System.IO.Path.GetFileNameWithoutExtension(fn)+".xsd";
//commented out because it'll put the dynamic assembly in default domain, therefore can't be unloaded.
//maps.StatusChange+=new StatusEventHandler(myStatusHandler);;
UpdateStatusText("writing schema...");
maps.writeApplicationSchema(xsfile,false);
UpdateStatusText("writing gml...");
maps.ExportGML(fn,false);
System.TimeSpan rentang = System.DateTime.Now.Subtract(sebelum);
UpdateStatusText("Done " +"in "+rentang.TotalSeconds.ToString()+" secs.");
this.progressBar1.Value=this.progressBar1.Minimum;
Cursor.Current = Cursors.Default;
}
catch (System.Exception exc)
{
System.Windows.Forms.MessageBox.Show("Error in exporting gml file \r"+exc.Message);
//Console.WriteLine(exc.Message);
UpdateStatusText("export to GML failed.");
}
}
/// <summary>
/// Exports MapDataCollection to plain SVG document - without attribute data.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuExportSVG_Click(object sender, System.EventArgs e)
{
try
{
if(maps==null) return;
if(maps.Count==0)
{
MessageBox.Show("No map currently loaded.\rPlease.","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
System.Windows.Forms.SaveFileDialog sfd=new SaveFileDialog();
sfd.Filter="SVG |*.svg";
sfd.ShowDialog();
this.Update();
if(sfd.FileName=="" || sfd.FileName==null)return;
string fn = System.IO.Path.GetFileNameWithoutExtension(sfd.FileName)+".svg";
sfd.Dispose();
sfd=null;
Cursor.Current = Cursors.WaitCursor;
UpdateStatusText("exporting svg...");
System.DateTime sebelum=System.DateTime.Now;
//commented out because it'll put the dynamic assembly in default domain, therefore can't be unloaded.
//maps.StatusChange+=new StatusEventHandler(myStatusHandler);
maps.ExportSVG(fn);
System.TimeSpan rentang = System.DateTime.Now.Subtract(sebelum);
UpdateStatusText("Done " +"in "+rentang.TotalSeconds.ToString()+" secs.");
this.progressBar1.Value=this.progressBar1.Minimum;
Cursor.Current = Cursors.Default;
}
catch (System.Exception exc)
{
System.Windows.Forms.MessageBox.Show("Error in exporting svg file \r"+exc.Message);
UpdateStatusText("export to SVG failed.");
}
}
private void menuFileExit_Click(object sender, System.EventArgs e)
{
try
{
if(!vForm.IsDisposed) vForm.Dispose();
string exepath = Application.ExecutablePath;
string exedir = System.IO.Path.GetDirectoryName(exepath);
string dynopath = exedir+System.IO.Path.DirectorySeparatorChar.ToString()+"dyno.dll";
if (System.IO.File.Exists(dynopath)) System.IO.File.Delete(dynopath);
}
finally
{
System.Windows.Forms.Application.Exit();
}
}
#endregion
#region menuLayer mouse events
private void menuRemoveAll_Click(object sender, System.EventArgs e)
{
try
{
if(maps==null) return;
maps.Clear();
CleanApp();
}
catch(System.NullReferenceException nre)
{
Console.Write("removing all Layers : "+nre.Message);
}
}
private void menuRemoveSelected_Click(object sender, System.EventArgs e)
{
if(maps==null) return;
if(maps.Count==0) return;
if(maps.Count==1)
{
menuRemoveAll_Click(sender, e);
return;
}
try
{
if(dgLayers.CurrentRowIndex==maps.Count-1) changeLayerIndex(dgLayers.CurrentRowIndex,0);
int row = dgLayers.CurrentRowIndex;
dgLayers.BindingContext[dgLayers.DataSource].RemoveAt(row);
dgLayers.SetDataBinding(null,null); //need for refresh, we can use currencymanager though
dgLayers.SetDataBinding(maps,null);
dgLayers_CurrentCellChanged(dgLayers,new System.EventArgs());
}
catch(System.NullReferenceException nre)
{
Console.Write("removing single Layer : "+nre.Message);
}
}
private void menuLayerMove_Click(object sender, System.EventArgs e)
{
if(maps==null) return;
int rowfrom = dgLayers.CurrentRowIndex;
MenuItem mi = (MenuItem) sender;
switch (mi.Index)
{
case 0 : //top
if(rowfrom>0) changeLayerIndex(rowfrom,0);
break;
case 1 : //up
if(rowfrom>0) changeLayerIndex(rowfrom,rowfrom-1);
break;
case 2 : //down
if(rowfrom<maps.Count-1) changeLayerIndex(rowfrom,rowfrom+1);
break;
case 3 : //bottom
if(rowfrom<maps.Count-1) changeLayerIndex(rowfrom,maps.Count-1);
break;
default:
break;
}
}
#endregion
#region menuField mouse events
private void menuFieldSelection_Click(object sender, EventArgs e)
{
if(dgFields.DataSource==null) return;
FieldCollection fc = (FieldCollection) dgFields.DataSource;
MenuItem mi = (MenuItem) sender;
CurrencyManager cm = (CurrencyManager)dgFields.BindingContext[dgFields.DataSource];
for(int i=0;i<fc.Count;i++)
{
Field f = (Field) fc[i];
switch (mi.Index)
{
case 0 : //all
f.isActive = true;
break;
case 1 : //invert
f.isActive =!f.isActive;
break;
case 2 : //none
f.isActive =false;
break;
default:
break;
}
}
cm.Refresh();
}
#endregion
#region menuTable mouse events
/// <summary>
/// Show Filter form for Table datagrid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuTableFilter_Click(object sender, System.EventArgs e)
{
if(maps==null || maps.Count==0) return;
if(fForm==null || fForm.IsDisposed) fForm=new FilterForm();
fForm.Owner=this;
int cr = dgLayers.CurrentRowIndex;
fForm.FilterString=maps[cr].Fields.FilterString;
fForm.Show();
}
private void menuRefreshTable_Click(object sender, System.EventArgs e)
{
RefreshTable();
}
#endregion
#region menuHelp mouse events
private void menuHelpContent_Click(object sender, System.EventArgs e)
{
Help.ShowHelp(this, Application.StartupPath+System.IO.Path.DirectorySeparatorChar+"geoCon.chm");
}
private void menuHelpAbout_Click(object sender, System.EventArgs e)
{
string msg="GeoCon";
msg+="\rVersion 1.03";
msg+="\rCopyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -