From 78f9bdce1e9e23e9d7d31d843ce88282ce5ce73c Mon Sep 17 00:00:00 2001 From: Elena Date: Sun, 28 Nov 2021 18:03:28 +0100 Subject: [PATCH] Terminada ventana recogida, falta hacer purebas con combos, que funcionan regu. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Empezada lectura de parámetros para exportación. --- Helper/HelperGdb.cs | 42 +++++ Model/ComunDef.cs | 7 + Model/Limpieza.cs | 15 +- Model/LimpiezaDef.cs | 6 - Model/Recogida.cs | 77 ++++++++- Model/TratamientoComun.cs | 1 + Services/EjecServ.cs | 10 ++ Services/LimpiezaServ.cs | 11 +- Services/RecogidaServ.cs | 149 +++++++++++++++++ View/Limpieza/PaneLimpieza.xaml | 2 +- View/Limpieza/PaneLimpiezaSub2.xaml | 2 +- View/Limpieza/PaneLimpiezaSub2.xaml.cs | 51 +----- View/Limpieza/PaneLimpiezaSub4.xaml | 6 +- View/Recogida/PaneRecogida.xaml | 12 +- View/Recogida/PaneRecogidaSub1.xaml | 41 +++-- View/Recogida/PaneRecogidaSub1.xaml.cs | 39 ++++- .../Limpieza/PaneLimpiezaSub2ViewModel.cs | 6 + .../Limpieza/PaneLimpiezaSub4ViewModel.cs | 12 ++ ViewModel/Limpieza/PaneLimpiezaViewModel.cs | 3 +- .../Recogida/PaneRecogidaSub1ViewModel.cs | 84 +++++++--- ViewModel/Recogida/PaneRecogidaViewModel.cs | 151 +++++++++++++++++- 21 files changed, 603 insertions(+), 124 deletions(-) diff --git a/Helper/HelperGdb.cs b/Helper/HelperGdb.cs index 0d5b855..6e673c0 100644 --- a/Helper/HelperGdb.cs +++ b/Helper/HelperGdb.cs @@ -20,6 +20,7 @@ using ArcGIS.Desktop.Editing; using OliviaAddInPro.Model; using System.IO; using System.Diagnostics; +using OliviaAddInPro.View; namespace OliviaAddInPro.Helper { @@ -66,6 +67,47 @@ namespace OliviaAddInPro.Helper out_str = string.Empty; } + //Proceso para sacar un diálogo y seleccionar una o varias geometrías de dentro de una fclass + public static ArcGIS.Core.Geometry.Geometry OpenGeom(TiposOpenFileDlg tipo, out string txt_sal, string initialLoc = "") + { + //inicialmente + ArcGIS.Core.Geometry.Geometry geom = null; + txt_sal = Resource1.String_selec_capa; + + //abre + FeatureClass fc = HelperGdb.OpenFtClassDialog(tipo); + if (fc != null) + { + //hace geom + geom = SelecLeeGeom(fc, out txt_sal, true); + if (geom == null && (HelperGdb.OutStr.Length > 0)) + HelperGlobal.ponMsg(HelperGdb.OutStr, System.Windows.MessageBoxImage.Error); + + HelperGdb.Free(fc); + } + return geom; + } + /* + * Saca ventana para seleccionar el campo del que leer para elegir la geometría + */ + private static ArcGIS.Core.Geometry.Geometry SelecLeeGeom(FeatureClass fc, out string text_sal, bool multisel) + { + ArcGIS.Core.Geometry.Geometry geomsal = null; + text_sal = ""; + if (fc != null) + { + //saca la ventana de selección de campo + ShowProWndSelectFields selfwnd = new ShowProWndSelectFields(fc, multisel); + if (selfwnd.SelFieldVals.Count > 0) + { + geomsal = HelperGdb.GetGeomSel(fc, selfwnd.SelField, selfwnd.SelFieldVals).Result; + text_sal = HelperGdb.TextoSal; + } + } + + return geomsal; + } + //Dado el tipo de FtClass y una posición inicial abre un diálogo de búsqueda de ftclass //si se cancela o no es una feature class lo que se ha abierto devuelve null //si no, devuelve la featureclass directamente abierta diff --git a/Model/ComunDef.cs b/Model/ComunDef.cs index 2ca1200..e4d7475 100644 --- a/Model/ComunDef.cs +++ b/Model/ComunDef.cs @@ -29,5 +29,12 @@ namespace OliviaAddInPro.Model public static string atr_N; // 0) - msg = Serv.ErrStr; - else - msg = "Han ocurrido errores al comenzar la ejeción."; - HelperGlobal.ponMsg(msg); - }*/ } public async void EjecutaAsync(ModosEjec modo, CancelableProgressorSource cps, Action ffin) { @@ -71,7 +62,7 @@ namespace OliviaAddInPro.Model var res = Ejecuta(modo, cps); ffin(res); return res; - + }); } diff --git a/Model/LimpiezaDef.cs b/Model/LimpiezaDef.cs index 8aa7f32..d647f94 100644 --- a/Model/LimpiezaDef.cs +++ b/Model/LimpiezaDef.cs @@ -788,12 +788,6 @@ namespace OliviaAddInPro.Model LimpiezaDef.filtro_str[(int)LimpiezaDef.AmbitsTra.AmbPipi] = LimpiezaDef.Campos.consulta_entidad + " = '" + LimpiezaDef.Atributos.atr_pipi + "'"; LimpiezaDef.filtro_str[(int)LimpiezaDef.AmbitsTra.AmbSane] = LimpiezaDef.Campos.consulta_entidad + " = '" + LimpiezaDef.Atributos.atr_sane + "'"; } - public class TareaRes - { - public bool Errores { get; set; } - public object data { get; set; } - public string msg { get; set; } - } } } diff --git a/Model/Recogida.cs b/Model/Recogida.cs index fdd89cd..00ab00e 100644 --- a/Model/Recogida.cs +++ b/Model/Recogida.cs @@ -5,19 +5,94 @@ using System.Text; using System.Threading.Tasks; using OliviaAddInPro.Helper; using OliviaAddInPro.Services; +using ArcGIS.Core.Geometry; +using static OliviaAddInPro.Model.ComunDef; +using ArcGIS.Desktop.Framework.Threading.Tasks; namespace OliviaAddInPro.Model { class Recogida : TratamientoComun { + //********************************************** + //Se recogen en PaneRecogidaSub1 + /** + * Tipo de fracción + */ + public int TipoFrac { get; set; } = -1; + /** + * Tipo de fracción + */ + public string TipoFracStr { get; set; } = string.Empty; + /** + * Tipo de carga + */ + public int TipoCarg { get; set; } = -1; + /** + * Tipo de carga + */ + public string TipoCargStr { get; set; } = string.Empty; + /** + * Tipo de Vehículo + */ + public int TipoVehic { get; set; } = -1; + /** + * Tipo de Lateralidad + */ + public int TipoLate { get; set; } = -1; + /** + * kg capac camión + */ + public int KgMaxVehic { get; set; } = 0; + /** + * dens contenedor + */ + public int DensCont { get; set; } = 0; + /** + * Tiempo de vaciado del contenedor, en seg + */ + public int TVaciCont { get; set; } = 0; + /** + * kg de carga en cada contenedor + */ + public int KgCont { get; set; } = 0; + /** + * grados en º de giro del vehículo + */ + public int GiroVehic { get; set; } = 0; + /** + * Coordenadas de la planta de descarga + */ + public Coordinate2D CoordsPlanta { get; set; } = new Coordinate2D(0, 0); + public RecogidaServ Serv { get; set; } = null; public Recogida() { Serv = new RecogidaServ(this); } - public void Ejecuta(ModosEjec modo) + + public TareaRes Ejecuta(ModosEjec modo, CancelableProgressorSource cps) { + TareaRes res = null; + if (modo == ModosEjec.Sectoriza) + res = Serv.Sectoriza(cps); + else if (modo == ModosEjec.Planifica) + res = Serv.Planifica(cps); + return res; + + } + public async void EjecutaAsync(ModosEjec modo, CancelableProgressorSource cps, Action ffin) + { + await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => + { + cps.Status = "Procesando"; + cps.Value = 0; + var res = Ejecuta(modo, cps); + ffin(res); + return res; + + }); + } } } diff --git a/Model/TratamientoComun.cs b/Model/TratamientoComun.cs index 0900481..ebcb46e 100644 --- a/Model/TratamientoComun.cs +++ b/Model/TratamientoComun.cs @@ -108,5 +108,6 @@ namespace OliviaAddInPro.Model } set { err_str = value;} } + } } diff --git a/Services/EjecServ.cs b/Services/EjecServ.cs index 73f25d7..b5b6590 100644 --- a/Services/EjecServ.cs +++ b/Services/EjecServ.cs @@ -216,5 +216,15 @@ namespace OliviaAddInPro.Services ErrStr = ""; return mal; } + + public bool ComprCamposPlanif(string pathCapa) + { + int NCAMPS = 2; + string[] camps; + camps = new string[NCAMPS]; + camps[0] = LimpiezaDef.Campos.consulta_sector; + camps[1] = LimpiezaDef.Campos.consulta_secuen; + return CompruebaCampos(pathCapa, camps) == 0; + } } } diff --git a/Services/LimpiezaServ.cs b/Services/LimpiezaServ.cs index 67141a6..217380e 100644 --- a/Services/LimpiezaServ.cs +++ b/Services/LimpiezaServ.cs @@ -10,7 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; -using static OliviaAddInPro.Model.LimpiezaDef; +using static OliviaAddInPro.Model.ComunDef; namespace OliviaAddInPro.Services { @@ -174,15 +174,6 @@ namespace OliviaAddInPro.Services return true;*/ } - public bool ComprCamposPlanif(string pathCapa) - { - int NCAMPS = 2; - string[] camps; - camps = new string[NCAMPS]; - camps[0] = LimpiezaDef.Campos.consulta_sector; - camps[1] = LimpiezaDef.Campos.consulta_secuen; - return CompruebaCampos(pathCapa, camps)==0; - } /* * Lee la capa que se ha seleccionzdo de limpieza y se comprueba que contiene los campos necesarios diff --git a/Services/RecogidaServ.cs b/Services/RecogidaServ.cs index 34641b4..64e4ea2 100644 --- a/Services/RecogidaServ.cs +++ b/Services/RecogidaServ.cs @@ -6,6 +6,8 @@ using System.Threading.Tasks; using OliviaAddInPro.Helper; using OliviaAddInPro.Model; using System.Collections.ObjectModel; +using static OliviaAddInPro.Model.ComunDef; +using ArcGIS.Desktop.Framework.Threading.Tasks; namespace OliviaAddInPro.Services { @@ -53,5 +55,152 @@ namespace OliviaAddInPro.Services return valores; } + /** + * Acciones para comenzar ejecución + * Modo 0, sectorizar + * Modo 1, planificar + */ + public TareaRes Sectoriza(CancelableProgressorSource cps) + { + var res = new TareaRes() + { + Errores = false, + data = null, + msg = "" + }; + + com = (TratamientoComun)reco; + string nombFileAmbs = string.Empty; + cps.Status = "Preparando filtro para la exportacion"; + //Prepara consulta + ErrStr = string.Empty; + + if (!PreparaConsulta(out nombFileAmbs)) + { + res.msg = "No se ha seleccionado una consulta válida" + reco.ConsultaAmbs; + res.Errores = true; + return res; + } + cps.Value = 10; + + //Prepara nombre + string fechaHora = string.Empty; + //se consigue el tiempo en este instante para añadirlo a los nombres de los archivos de salida (shapefiles) + fechaHora = DateTime.Now.ToString("yyyyMMdd_Hmmss"); + //Pone nombre al shape en función de los ámbitos, el tratamiento, y los polígonos + timestamp + //reco.NombreShpExport = prefNameExport + "T" + reco.TipoTto.ToString("00") + nombFileAmbs + DameStrPoligs() + "_" + fechaHora + extShp; + + string msg = ""; + //comienza ejecucion + if (!ComienzaEjec(ModosEjec.Sectoriza, cps, out msg)) + { + res.Errores = true; + res.msg = msg; + return res; + } + + return res; + + } + + public bool PreparaConsulta(out string nombFileAmbs) + { + nombFileAmbs = string.Empty; + reco.ConsultaAmbs = DameAmbsConsulta(out nombFileAmbs); + if (string.IsNullOrEmpty(reco.ConsultaAmbs)) + { + return false; + } + return true; + } + + public TareaRes Planifica(CancelableProgressorSource cps) + { + TareaRes res = new TareaRes() + { + Errores = false, + msg = "", + data = null + };/* + //se asegura que tiene todo para planif + //ErrStr = string.Empty; + if (!CompruebaPlanif()) + { + res.msg = "En la capa de ámbitos seleccionada no se encuentran columnas de SECTOR y/o SECUENCIA, necesarias para planificar"; + res.Errores = true; + return res; + } + //Prepara consulta + string nombFileAmbs = string.Empty; + //Prepara consulta + if (!PreparaConsulta(out nombFileAmbs)) + { + res.msg = "No se ha seleccionado una consulta válida" + reco.ConsultaAmbs; + res.Errores = true; + return res; + }*/ + + return res; + } + public string DameAmbsConsulta(out string ambs_file) + { + string consulta, orstr; + + consulta = string.Empty; + ambs_file = ""; + /*orstr = null; + var n = reco.AmbitosSel.Length; + + for (int i = 0; i < n; i++) + { + if (limp.AmbitosSel[i]) + { + consulta = consulta + orstr + "(" + LimpiezaDef.filtro_str[i] + ")"; + ambs_file = ambs_file + i.ToString("00"); + if (orstr == null) + orstr = " OR "; + } + } + ambs_file = "_A" + ambs_file; + if (consulta == "()") + consulta = ""; + */ + return consulta; + } + /** + * Comprueba lo necesario para ver si hay campos para la planificación + */ + public bool CompruebaPlanif() + { + + //si ha importado no hace falta que compruebe, seguro que las tiene + if (OliviaGlob.IsConfig2()) + return true; + //no ha importado, comprueba capa + if (ComprCamposPlanif(reco.CapaElems)) + return true; + + return false; + } + /** + * Rellena el array de filtros en base a la config + */ + public void RellenaFiltrosReco() + { + //se rellena el array de filtros + RecogidaDef.filtro_str = new string[RecogidaDef.tipos_fracc_str.Length + RecogidaDef.tipos_carg_str.Length]; + for (int i = 0; i < RecogidaDef.tipos_fracc_str.Length; i++) + { + //se comprueba que tipo de fracción se ha seleccionado. Si se ha seleccionado una fracción sin nombre (el campo en la capa es NULL, y en el comboBox de fracciiones aparece como "-") hay que modificar el filtro + if (RecogidaDef.tipos_fracc_str[i] == "-") + RecogidaDef.filtro_str[i] = RecogidaDef.campos_def.cons_fracc + " IS NULL"; + else + RecogidaDef.filtro_str[i] = RecogidaDef.campos_def.cons_fracc + "= '" + RecogidaDef.tipos_fracc_str[i] + "'"; + } + for (int i = RecogidaDef.tipos_fracc_str.Length; i < RecogidaDef.filtro_str.Length; i++) + { + RecogidaDef.filtro_str[i] = RecogidaDef.campos_def.cons_nomrec + "= '" + RecogidaDef.tipos_carg_str[i - RecogidaDef.tipos_fracc_str.Length] + "'"; + } + } } } diff --git a/View/Limpieza/PaneLimpieza.xaml b/View/Limpieza/PaneLimpieza.xaml index 2f05a45..8c83ff2 100644 --- a/View/Limpieza/PaneLimpieza.xaml +++ b/View/Limpieza/PaneLimpieza.xaml @@ -72,7 +72,7 @@