using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using OliviaDef; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.DataSourcesGDB; using System.IO; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.ADF.COMSupport; using ESRI.ArcGIS.ADF; using ESRI.ArcGIS.esriSystem; using System.Runtime.InteropServices; using ESRI.ArcGIS.DataSourcesFile; using System.Diagnostics; namespace OliviaAddIn { /** * @file InicioDlg.cs * Clase de la ventana inicial de OLIVIA. * Contiene el manejo de sus eventos como el Click o la actualización de su estado. */ /** * Clase de la ventana inicial de OLIVIA. * Contiene el manejo de sus eventos como el Click o la actualización de su estado. */ public partial class InicioDlg : Form { //Variables /** * Texto para cuando no se ha seleccionado GDB */ string text_selec_gdb = "Seleccionar GDB"; /** * Texto para cuando sí se ha seleccionado GDB */ string text_si_gdb = "GDB : "; /** * Texto para cuando no se ha seleccionado nw */ string text_selec_nw = "Seleccionar NW "; /** * Texto para cuando sí se ha seleccionado nw */ string text_si_nw = "Red Navegable : "; /** * Ventana de configuración de la limpieza viaria */ public LimpiezaDlg lim = null; /** * Ventana de configuración de la recogida de residuos */ public RecogidaDlg reco = null; //************************************************************************************* //Métodos public InicioDlg() { try { Application.EnableVisualStyles(); InitializeComponent(); enable_buttons(false); if (!Directory.Exists(OliviaGlob.Paths.PathGdbGen)) OliviaGlob.Paths.PathGdbGen = null; if (!Directory.Exists(OliviaGlob.Paths.PathGdbNw)) OliviaGlob.Paths.PathGdbNw = null; //si lee el archivo de configuracion y ya tiene paths asignados a las GDBs lo pone en los botones if (OliviaGlob.Paths.PathGdbGen != null) { pon_text_bt_gdb(); } if (OliviaGlob.Paths.PathGdbNw != null) { pon_text_bt_nw(); } if (OliviaGlob.demo_id) { Point pto; //si es modo demo para i+D, se quitan los botones menos el de limpieza y el de recogida pto = button_gdb.Location; pto.Y = pto.Y + button_gdb.Height; button_nw.Location = pto; Height = Height + button_nw.Height * 2; Width = Width + 100; } } catch (Exception) { MessageBox.Show("Error al iniciar la ventana de Inicio", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } private void enable_buttons(bool en, bool gdb_tambien=false) { button_limp.Enabled = button_resi.Enabled = button_maqueta.Enabled = en; if (gdb_tambien) { button_gdb.Enabled = en; button_nw.Enabled = en; } } //************************************************************************************* //Eventos de elementos de la ventana private void button_limp_Click(object sender, EventArgs e) { try { enable_buttons(false, true); OliviaGlob.gdb_limp = new DatosGDBLimp(); OliviaGlob.gdb = (DatosGDB)OliviaGlob.gdb_limp; //abre la ventana de configuración de limpieza lim = new LimpiezaDlg(); Hide(); enable_buttons(true, true); string err_str = ""; if (!OliviaGlob.guarda_ini_gen(out err_str)) { MessageBox.Show(err_str, "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } lim.Show(); } catch (Exception) { MessageBox.Show("Error al iniciar la ventana de Limpieza", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } private void button_resi_Click(object sender, EventArgs e) { try { enable_buttons(false, true); OliviaGlob.gdb_reco = new DatosGDBReco(); OliviaGlob.gdb = (DatosGDB)OliviaGlob.gdb_reco; //abre la ventana de configuración de recogida reco = new RecogidaDlg(); Hide(); enable_buttons(true, true); string err_str = ""; if (!OliviaGlob.guarda_ini_gen(out err_str)) { MessageBox.Show(err_str, "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } reco.Show(); } catch (Exception) { MessageBox.Show("Error al iniciar la ventana de Recogida", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } private void InicioDlg_FormClosed(object sender, FormClosedEventArgs e) { OliviaGlob.ya_open_app = false; if (OliviaGlob.demo_id) return; //borra los archivos al terminar... OliviaGlob.borra_files(); } private void button_maqueta_Click(object sender, EventArgs e) { try { Hide(); OliviaGlob.gdb = new DatosGDB(); if (!OliviaGlob.mapa.maqueta(this.Handle)) { MessageBox.Show(OliviaGlob.mapa.err_str, "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } Close();//cierro el dialogo de inicio } catch (Exception) { MessageBox.Show("Error al iniciar la ventana de Maquetación", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } /** * Permite seleccionar una GDB que contenga los ámbitos sobre los que se realizará la sectorización. */ private void button_gdb_Click(object sender, EventArgs e) { IWorkspace ws = null; try { string text_reint = "¿Desea cancelar el proceso?"; ws = FunGDB.selec_gdb("Seleccionar GDB de trabajo", this.Handle.ToInt32(), text_reint); if (ws != null) { //pone path y quita bordes e imagen OliviaGlob.Paths.PathGdbGen = ws.PathName; pon_text_bt_gdb(); } else { //quita path y pone bordes e imagen button_gdb.Text = text_selec_gdb; button_gdb.Image = global::OliviaAddIn.Properties.Resources.folder_gdb; enable_buttons(false); } } catch (Exception) { return; } } /** * Permite seleccionar una GDB que contenga la red navegable sobre la que se realizará el cálculo de rutas óptimas. */ private void button_nw_Click(object sender, EventArgs e) { IWorkspace ws = null; try { string text_reint = "¿Desea cancelar el proceso?"; ws = FunGDB.selec_gdb("Seleccionar la red navegable", this.Handle.ToInt32(), text_reint); if (ws != null) { //pone path y quita bordes e imagen OliviaGlob.Paths.PathGdbNw = ws.PathName; pon_text_bt_nw(); } else { //quita path y pone bordes e imagen button_nw.Text = text_selec_nw; button_nw.Image = global::OliviaAddIn.Properties.Resources.folder_nw; enable_buttons(false); } } catch (Exception) { return; } } /*private void InicioDlg_VisibleChanged(object sender, EventArgs e) { int a = 5; }*/ /** * Cuando se picnha en el botón de ayuda se abre el manual de Olivia */ private void btn_help_Click(object sender, EventArgs e) { string[] archivos = null; try { archivos = Directory.GetFiles(OliviaGlob.Paths.PathWork, OliviaGlob.manual + ".pdf"); if (archivos.Length <= 0) MessageBox.Show("No se encuentra el archivo " + OliviaGlob.manual + ".pdf en la ubicación " + OliviaGlob.Paths.PathWork, "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error); foreach (string f in archivos) { Process.Start(f); } } catch (Exception) { MessageBox.Show("Error al abrir el manual de ayuda " + OliviaGlob.manual + ".pdf", "Olivia", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } private void pon_text_bt_gdb() { button_gdb.Text = text_si_gdb + OliviaGlob.Paths.PathGdbGen; button_gdb.Image = null; if (button_nw.Text != text_selec_nw) enable_buttons(true); } private void pon_text_bt_nw() { button_nw.Text = text_si_nw + OliviaGlob.Paths.PathGdbNw; button_nw.Image = null; if (button_gdb.Text != text_selec_gdb) enable_buttons(true); } private void InicioDlg_Load(object sender, EventArgs e) { this.Location = Properties.Settings.Default.InicioDlg_Loc; } private void InicioDlg_FormClosing(object sender, FormClosingEventArgs e) { if (this.WindowState == FormWindowState.Normal) Properties.Settings.Default.InicioDlg_Loc = this.Location; else Properties.Settings.Default.InicioDlg_Loc = this.RestoreBounds.Location; Properties.Settings.Default.Save(); } } }