diff --git a/Button/ButtonLimp.cs b/Button/ButtonLimp.cs index 48f2c19..8810a7a 100644 --- a/Button/ButtonLimp.cs +++ b/Button/ButtonLimp.cs @@ -29,8 +29,7 @@ namespace OliviaAddInPro if (OliviaGlob.TipoView == TiposEjecucion.Ninguno) { - ///Comprueba que existe la red navegable configurada - + ///Comprueba que existe la red navegable configurada if (!OliviaGlob.CompruebaNwYCampos()) { HelperGlobal.ponMsg("No se encuentra red navegable, cambie Configuración: " + HelperGdb.OutStr, diff --git a/Helper/HelperGdb.cs b/Helper/HelperGdb.cs index 23f93cb..cf3bbf9 100644 --- a/Helper/HelperGdb.cs +++ b/Helper/HelperGdb.cs @@ -13,6 +13,7 @@ using ArcGIS.Core.Data; using ArcGIS.Desktop.Mapping; using ArcGIS.Core.Internal.CIM; using ArcGIS.Desktop.Internal.Layouts.Utilities; + using ArcGIS.Desktop.Core.Geoprocessing; using ArcGIS.Desktop.Framework.Threading.Tasks; using ArcGIS.Desktop.Editing; @@ -25,6 +26,7 @@ using ArcGIS.Core.Data.DDL; using ArcGIS.Core.CIM; using System.Threading; using ArcGIS.Core.Data.Exceptions; +using Microsoft.Win32; namespace OliviaAddInPro.Helper { @@ -434,44 +436,123 @@ namespace OliviaAddInPro.Helper } - //Dado un path de una feature class devuelve la ftclass abierta directamente, - //o null si ha habido algún problema o no lo ha encontrado - public static FeatureClass GetFtClass(string pathFtClss) - { - FeatureClass ftclss = null; - if (string.IsNullOrEmpty(pathFtClss)) - return null; - Geodatabase gdb = GetGdb(pathFtClss).Result; - ReiniciaOutStr(); - if (gdb != null) - { - ftclss = GetFtClass(System.IO.Path.GetFileNameWithoutExtension(pathFtClss), gdb).Result; - } - else //mira a ver si es shapefile - { - ftclss = GetFtClassFromShp(pathFtClss).Result; - } - Free(gdb); - return ftclss; - } //Dado un path de una feature class devuelve la ftclass abierta directamente, //o null si ha habido algún problema o no lo ha encontrado public static FeatureClass GetFtClassSync(string pathFtClss) { FeatureClass ftclss = null; + FeatureDataset dtset = null; if (string.IsNullOrEmpty(pathFtClss)) return null; Geodatabase gdb = GetGdbSync(pathFtClss); ReiniciaOutStr(); if (gdb != null) { - ftclss = GetFtClassSync(System.IO.Path.GetFileNameWithoutExtension(pathFtClss), gdb); + string dtsetName = new DirectoryInfo(System.IO.Path.GetDirectoryName(pathFtClss)).Name; + try + { + dtset = gdb.OpenDataset(dtsetName); + } + catch (Exception ex) + { + HelperGdb.OutStr = "Error al abrir Dataset " + dtsetName + ": " + ex.Message; + dtset= null; + } + + string ftclassName = System.IO.Path.GetFileNameWithoutExtension(pathFtClss); + if (dtset != null) + { + try + { + ftclss = dtset.OpenDataset(ftclassName); + } + catch (Exception ex) + { + ftclss = null; + } + } + else + { + try + { + ftclss = gdb.OpenDataset(ftclassName); + } + catch (Exception ex) + { + ftclss = null; + } + } + if(ftclss==null) + HelperGdb.OutStr = "Error al abrir Feature Class " + ftclassName; } else //mira a ver si es shapefile { - ftclss = GetFtClassFromShpSync(pathFtClss); + ftclss = GetFtClassFromShpSync(pathFtClss).Result; } Free(gdb); + Free(dtset); + return ftclss; + } + //Dado un path de una feature class devuelve la ftclass abierta directamente, + //o null si ha habido algún problema o no lo ha encontrado + public static FeatureClass GetFtClass(string pathFtClss) + { + FeatureClass ftclss = null; + FeatureDataset dtset = null; + if (string.IsNullOrEmpty(pathFtClss)) + return null; + Geodatabase gdb = GetGdb(pathFtClss).Result; + ReiniciaOutStr(); + if (gdb != null) + { + var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => + { + string dtsetName = new DirectoryInfo(System.IO.Path.GetDirectoryName(pathFtClss)).Name; + try + { + dtset = gdb.OpenDataset(dtsetName); + } + catch (Exception ex) + { + HelperGdb.OutStr = "Error al abrir Dataset " + dtsetName + ": " + ex.Message; + dtset = null; + } + + string ftclassName = System.IO.Path.GetFileNameWithoutExtension(pathFtClss); + if (dtset != null) + { + try + { + ftclss = dtset.OpenDataset(ftclassName); + } + catch (Exception ex) + { + ftclss = null; + } + } + else + { + try + { + ftclss = gdb.OpenDataset(ftclassName); + } + catch (Exception ex) + { + ftclss = null; + } + } + if (ftclss == null) + HelperGdb.OutStr = "Error al abrir Feature Class " + ftclassName; + return ftclss; + })); + task.Wait(); + } + else //mira a ver si es shapefile + { + ftclss = GetFtClassFromShp(pathFtClss).Result; + } + Free(gdb); + Free(dtset); return ftclss; } //Dado el path de una gdb y el nombre de una feature class, devuelve la @@ -486,7 +567,7 @@ namespace OliviaAddInPro.Helper { try { - ftclss = gdb.OpenDataset(nameFtclss); + ftclss = gdb.OpenDataset(nameFtclss); } catch (Exception ex) { @@ -2005,12 +2086,13 @@ namespace OliviaAddInPro.Helper if (!string.IsNullOrEmpty(ext_)) dlg.DefaultExt = ext_; if (brwsFilt != null) + { + brwsFilt.BrowsingFilesMode = true; dlg.BrowseFilter = brwsFilt; - + } try { bool? ok = dlg.ShowDialog(); - if ((ok ?? true) && dlg.FilePath.Length > 0) return dlg.FilePath; else @@ -2088,7 +2170,8 @@ namespace OliviaAddInPro.Helper try { FeatureDatasetDefinition featureDatasetDefinition = gdb.GetDefinition(datasetName); - if(featureDatasetDefinition.GetSpatialReference().Equals(spatref)) + ArcGIS.Core.Geometry.SpatialReference entr = featureDatasetDefinition.GetSpatialReference(); + if (entr.Wkid==spatref.Wkid) return 0; return 2; } @@ -2101,7 +2184,10 @@ namespace OliviaAddInPro.Helper /** * Crea un FeatureDataset con el nombre dado y la spatialrefernece dada en la gdb dada - * Devuelve 0 si no hay que crear nada o si lo ha creado bien, 2 si existe el dataset pero con otra referencia espacial, 1 si da error + * Devuelve 0 si no hay que crear nada, existe y coincide ref espac + * 2 si existe el dataset pero con otra referencia espacial, así que se crea otro + * 1 si da error + * 4 si no existe así que se crea */ public static Respuesta CreateDataset(string gdbPath, string datasetName, ArcGIS.Core.Geometry.SpatialReference spatref, out string datasetNameOut) { @@ -2123,6 +2209,7 @@ namespace OliviaAddInPro.Helper bool crea = false; int idat = 1; int r = 2; + bool refspatdif = false; while(r==2) { var task1 = CheckDataset(gdb, datasetName); @@ -2140,7 +2227,8 @@ namespace OliviaAddInPro.Helper { //existe ese nombre, pero con otra ref espacial //crea un nuevo dataset y avisa - datasetName = string.Format("{0}_{1}",datasetName,idat); + datasetName = string.Format("{0}_{1}",datasetName,idat); + refspatdif = true; idat++; } else//r==1 @@ -2186,10 +2274,11 @@ namespace OliviaAddInPro.Helper task.Wait(); if (task.Result.Value)//ha ido bien { - if (string.IsNullOrEmpty(datasetNameOut)) - res.Value = 0; + //avisa + if (refspatdif) + res.Value = 2; else - res.Value = 2;//avisa + res.Value = 4; //actualiza la gdb Refresh(gdbPath); } @@ -2314,17 +2403,73 @@ namespace OliviaAddInPro.Helper /** * Borrar una feature class de un dataset + * Devuelve -1 si da error al abrir la gdb, -2 si da error al abrir el ftclass (igual porque no existe) + * y 0 si da error el proceso de borrar, y 1 si va todo bien */ - public static Respuesta DeleteFeatureClass(string gdbPath, string featureClassPath) + public static Respuesta DeleteFeatureClassSync(string gdbPathDataset, string featureClassName) + { + var res = new Respuesta { Value = 0 }; + + Geodatabase gdb = GetGdbSync(gdbPathDataset); + if (gdb == null) + { + res.Value = -1; + return res; + } + + FeatureClass ftclss = GetFtClassSync(gdbPathDataset + " \\"+ featureClassName); + if (ftclss == null) + { + res.Value = -2; + return res; + } + + Respuesta resp = new Respuesta { Value = false }; + SchemaBuilder schemaBuilder = null; + try + { + // Create a FeatureClassDescription object + FeatureClassDescription featureClassDescription = new FeatureClassDescription(ftclss.GetDefinition()); + // Create a SchemaBuilder object + schemaBuilder = new SchemaBuilder(gdb); + // Add the deletion fo the feature class to our list of DDL tasks + schemaBuilder.Delete(featureClassDescription); + // Execute the DDL + resp.Value = schemaBuilder.Build(); + if (!resp.Value && schemaBuilder.ErrorMessages.Count > 0) + resp.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault()); + } + catch + { + resp.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault()); + } + + if (resp.Value) + res.Value = 1; + else + { + res.Error.Add(resp.Error.FirstOrDefault()); + } + Free(gdb); + Free(ftclss); + return res; + } + + /** + * Borrar una feature class de un dataset + */ + public static Respuesta DeleteFeatureClass(string gdbPathDataset, string featureClassName) { var res = new Respuesta { Value = false }; - FeatureClass ftclss = GetFtClass(featureClassPath); - if (ftclss == null) - return res; - Geodatabase gdb = GetGdb(gdbPath).Result; + + Geodatabase gdb = GetGdb(gdbPathDataset).Result; if (gdb == null) return res; + FeatureClass ftclss = GetFtClass(gdbPathDataset + " \\" + featureClassName); + if (ftclss == null) + return res; + var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func>)(() => { Respuesta resp = new Respuesta { Value = false }; diff --git a/Model/ComunDef.cs b/Model/ComunDef.cs index 5b90c07..7702d33 100644 --- a/Model/ComunDef.cs +++ b/Model/ComunDef.cs @@ -33,5 +33,18 @@ namespace OliviaAddInPro.Model public static string atr_pedes; // nombCamposOrig = new ObservableCollection(); + /** * Para la ventana de progreso */ @@ -202,10 +204,30 @@ namespace OliviaAddInPro.Model return null; } + /** * Restaura el nombre original del campo si se ha truncado a 10 car al exportar a shp */ - public Respuesta RestauraNomCampos(string nombFtClass) + public virtual string[] GetCamposOrig() + { + string[] camps = null; + + if (nombCamposOrig.Count > 0) + { + camps = new string[nombCamposOrig.Count]; + for (int i=0;i RestauraNomCampos(string nombFtClass) { int LENGTHCAMPSHP = 10; Respuesta resp = new Respuesta { Value = false }; @@ -213,7 +235,9 @@ namespace OliviaAddInPro.Model if (fc == null) return resp; //////////////////////////////////////////////////////// - string[] camps = GetCampos(); + string[] camps = GetCamposOrig(); + if (camps == null) + return resp; ObservableCollection fields = HelperGdb.GetFieldsSync(fc); HelperGdb.Free(fc); @@ -228,7 +252,9 @@ namespace OliviaAddInPro.Model { if (camps[i].Length <= LENGTHCAMPSHP) continue; - campTrunc = camps[i].Substring(0, LENGTHCAMPSHP); + if (EstaRepeNomb(fields, camps[i])) + continue; + campTrunc = camps[i].Substring(0, LENGTHCAMPSHP); //si tiene más de 10 caracteres, lo ha truncado al exportar //busca el nombre actual del campo en la fc indx = fields.IndexOf(campTrunc); @@ -251,5 +277,30 @@ namespace OliviaAddInPro.Model return resp; } + + private bool EstaRepeNomb(ObservableCollection fields, string nomb) + { + foreach( string fnomb in fields) + { + if (string.Compare(fnomb, nomb, true)==0) + return true; + } + return false; + } + + /** + * Guarda el nombre de los campos originales para luego restaurarlos + */ + public void GuardaNombCamposOrig(string pathFtClass) + { + FeatureClass fc = HelperGdb.GetFtClassSync(pathFtClass); + if (fc != null) + { + nombCamposOrig = HelperGdb.GetFieldsSync(fc); + } + else + nombCamposOrig = new ObservableCollection(); + HelperGdb.Free(fc); + } } } diff --git a/Services/ConfigServ.cs b/Services/ConfigServ.cs index e6c9df8..4218f48 100644 --- a/Services/ConfigServ.cs +++ b/Services/ConfigServ.cs @@ -356,7 +356,7 @@ namespace OliviaAddInPro.Services c.t_vaci_lateral=90; c.t_vaci_superior=180; c.t_vaci_bilateral=100; - c.t_vaci_bolseo=5; + c.t_vaci_bolseo=5*60; c.t_vaci_lavado=60; c.t_vaci_otra=60; c.kgmax_max=20000; diff --git a/Services/EjecServ.cs b/Services/EjecServ.cs index f2a7306..cf38b14 100644 --- a/Services/EjecServ.cs +++ b/Services/EjecServ.cs @@ -10,6 +10,7 @@ using OliviaAddInPro.Helper; using ArcGIS.Core.Internal.Data; using ArcGIS.Desktop.Framework.Threading.Tasks; using System.Windows; +using System.IO; namespace OliviaAddInPro.Services { @@ -77,6 +78,12 @@ namespace OliviaAddInPro.Services ErrStr = Resource1.String_cancel_progreso; return false; } + + ////////////////////////////////////////////// + ///Se guarda el nombre de los campos originales + /// + com.GuardaNombCamposOrig(com.CapaElems); + //Cuenta las filas que cumplen la consulta var nelems = HelperGdb.GetNumElemsSync(com.CapaElems, com.ConsultaAmbs); if (nelems <= 0) @@ -174,9 +181,17 @@ namespace OliviaAddInPro.Services return false; } + ///////////////////////////////////////////////////////////////////// + ///Comprueba si está la columna de ObjectId y si no, la crea + if(!ComprCreaColOid(OliviaGlob.Paths.PathData, com.CapaElems, filtroEspacial)) + { + ErrStr = "Error al exportar columna " + ComunDef.CamposCom.camp_oid; + return false; + } + /////////////////////////////////////////////////////////////////////// - //ahora si está en modo planificación y la capa no tiene esa columna, exporta la sectorización - if (modo==ModosEjec.Planifica && !string.IsNullOrEmpty(com.CapaPlanif)) + //ahora si está en modo planificación, ya ha hecho una ejec antes y la capa no tiene esa columna pero la tiene guardada de la ejec anterior, exporta la sectorización + if (modo==ModosEjec.Planifica && !string.IsNullOrEmpty(com.CapaPlanif) && OliviaGlob.IsConfig2()) { string capa_principal = System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData); HelperGdb.CloseLayer(capa_principal); @@ -239,22 +254,7 @@ namespace OliviaAddInPro.Services { ErrStr = "Error al añadir buffer a la geometría"; return false; - } - //quita las restricciones - if (com.GeomRestr != null) - { - geom_export = HelperGdb.QuitaGeom(geom_export, com.GeomRestr); - if (geom_export == null) - { - ErrStr = "Error al intersecar con las restricciones."; - return false; - } - } - if (com.ProgrSrc._ProgrSrc.Getcancelled()) - { - ErrStr = Resource1.String_cancel_progreso; - return false; - } + } ////////////////////////////////////////////////////////////// //comprueba si la geometría de exportación contiene a la instalación y a la planta de descarga for (int i = 0; i < coords.Length; i++) @@ -287,13 +287,28 @@ namespace OliviaAddInPro.Services else ErrStr = "Error al incluir punto de instalación en polígono de exportación."; return false; - } + } //actualiza la geometría geom_export = respGeom.Value; } } } } + //quita las restricciones de circ + if (com.GeomRestr != null) + { + geom_export = HelperGdb.QuitaGeom(geom_export, com.GeomRestr); + if (geom_export == null) + { + ErrStr = "Error al intersecar con las restricciones."; + return false; + } + } + if (com.ProgrSrc._ProgrSrc.Getcancelled()) + { + ErrStr = Resource1.String_cancel_progreso; + return false; + } //mira spatialreference del nw /*FeatureClass fc = HelperGdb.GetFtClass(OliviaGlob.Paths.PathGdbNw); @@ -365,13 +380,13 @@ namespace OliviaAddInPro.Services //Añade al shp exportado la columna de sector y secuencia HelperGdb.FieldToAdd[] fields = new HelperGdb.FieldToAdd[2]; //campo SECTOR - fields[0].Name = LimpiezaDef.Campos.consulta_sector; - fields[0].Alias = LimpiezaDef.Campos.consulta_sector; + fields[0].Name = ComunDef.CamposCom.consulta_sector; + fields[0].Alias = ComunDef.CamposCom.consulta_sector; fields[0].Tipo = "LONG"; fields[0].Length = 0; //campo SECUENCIA - fields[1].Name = LimpiezaDef.Campos.consulta_secuen; - fields[1].Alias = LimpiezaDef.Campos.consulta_secuen; + fields[1].Name = ComunDef.CamposCom.consulta_secuen; + fields[1].Alias = ComunDef.CamposCom.consulta_secuen; fields[1].Tipo = "LONG"; fields[1].Length = 0; @@ -412,8 +427,8 @@ namespace OliviaAddInPro.Services { //context.Invalidate(rowshp); // modify and execute - modifyOp.Modify(rowshp, LimpiezaDef.Campos.consulta_sector, rowsecto[LimpiezaDef.Campos.consulta_sector]); - modifyOp.Modify(rowshp, LimpiezaDef.Campos.consulta_secuen, rowsecto[LimpiezaDef.Campos.consulta_secuen]); + modifyOp.Modify(rowshp, ComunDef.CamposCom.consulta_sector, rowsecto[ComunDef.CamposCom.consulta_sector]); + modifyOp.Modify(rowshp, ComunDef.CamposCom.consulta_secuen, rowsecto[ComunDef.CamposCom.consulta_secuen]); rowshp.Store(); //context.Invalidate(rowshp); } @@ -495,8 +510,107 @@ namespace OliviaAddInPro.Services } /** - * Prepara la geometría para exportar los ámbitos + * Comrpueba si existe la columna de oid y si no, la crea y la rellena */ + public bool ComprCreaColOid(string pathCapa, string pathCapaOrig, SpatialQueryFilter filter) + { + //comprueba si está el campo + int NCAMPS = 1; + string[] camps; + camps = new string[NCAMPS]; + camps[0] = ComunDef.CamposCom.camp_oid; + int compCamp = HelperGdb.CheckFileds(pathCapa, camps); + ErrStr = HelperGdb.OutStr; + if (compCamp == 0) + return true; //tiene el campo + + //no lo tiene, lo crea + //Añade al shp exportado la columna de sector y secuencia + HelperGdb.FieldToAdd[] fields = new HelperGdb.FieldToAdd[1]; + //campo + fields[0].Name = ComunDef.CamposCom.camp_oid; + fields[0].Alias = ComunDef.CamposCom.camp_oid; + fields[0].Tipo = "LONG"; + fields[0].Length = 0; + + if (!HelperGdb.AddFieldsSync(pathCapa, fields)) + return false; + //vuelve a cerrar la capa + string capa_principal = System.IO.Path.GetFileNameWithoutExtension(pathCapa); + HelperGdb.CloseLayer(capa_principal); + + ///////////////////////////////////////////////////// + //Coge los ids de la capa de la que ha exportado + using (FeatureClass fc_orig = HelperGdb.GetFtClassSync(pathCapaOrig)) + { + if (fc_orig == null) + return false; + List ids = new List(); + //Añade a la lista los ids que cumplen el filtro espacial + try + { + ids = fc_orig.Select(filter, SelectionType.ObjectID, SelectionOption.Normal).GetObjectIDs().ToList(); + } + catch + { + ids = new List(); + } + //Comprueba que hay tantos ids como elementos en el shp + using (FeatureClass fc_shp = HelperGdb.GetFtClassSync(pathCapa)) + { + if (fc_shp == null) + return false; + int nelem_shp = HelperGdb.GetNumElemsSync(fc_shp); + if (nelem_shp != ids.Count) + return false; + + ///////////////////////////////////////////////////// + //ahora rellena las columnas + try + { + using (RowCursor rc_shp = fc_shp.Search()) + { + if (rc_shp == null) + return false; + + var modifyOp = new ArcGIS.Desktop.Editing.EditOperation(); + modifyOp.Name = "Actualiza OID"; + bool ex = false; + //modifyOp.Callback((context) => + //{ + int i = 0; + while (rc_shp.MoveNext() && i < ids.Count) + { + using (Row rowshp = rc_shp.Current) + { + //context.Invalidate(rowshp); + // modify and execute + modifyOp.Modify(rowshp, ComunDef.CamposCom.camp_oid, ids[i++]); + rowshp.Store(); + //context.Invalidate(rowshp); + } + } + //}, fc_shp); + ex = modifyOp.Execute(); + ArcGIS.Desktop.Core.Project.Current.SaveEditsAsync(); + if (ex && modifyOp.IsDone) + return true; + else + return false; + } + } + catch + { + return false; + } + return true; + } + } + } + + /** + * Prepara la geometría para exportar los ámbitos + */ public Geometry GetGeomAmbitsExport() { Geometry geomAux = null; @@ -538,7 +652,7 @@ namespace OliviaAddInPro.Services //if (geomAux == null) { //Ahora hace la geometría de los ámbitos que cumplen la consulta - geomAmbits = HelperGdb.GetGeomConvexHullSync(fc, filtro); + geomAmbits = HelperGdb.GetGeomUnique(fc, filtro); if (geomAmbits == null || geomAmbits.IsEmpty) { ErrStr = "No se ha podido generar geometría de los ámbitos" + com.ConsultaAmbs + HelperGdb.OutStr; @@ -549,7 +663,7 @@ namespace OliviaAddInPro.Services else { geomAux = HelperGdb.IntersectGeom(geomAux, geomAmbits); - geomAux = GeometryEngine.Instance.ConvexHull(geomAux); + //geomAux = GeometryEngine.Instance.ConvexHull(geomAux); } } //le quita las restricciones @@ -588,8 +702,8 @@ namespace OliviaAddInPro.Services int NCAMPS = 2; string[] camps; camps = new string[NCAMPS]; - camps[0] = LimpiezaDef.Campos.consulta_sector; - camps[1] = LimpiezaDef.Campos.consulta_secuen; + camps[0] = ComunDef.CamposCom.consulta_sector; + camps[1] = ComunDef.CamposCom.consulta_secuen; return HelperGdb.CheckFiledsSync(pathCapa, camps) == 0; } @@ -615,10 +729,10 @@ namespace OliviaAddInPro.Services /** * Realiza las funciones de importación de la sectorización */ - public Respuesta ImportSecto(string GdbFileName) + public Respuesta ImportSecto(string GdbFileName, string FtClssName) { com.ProgrSrc.IncMessage(10,"Importando capas"); - var res = Import(GdbFileName, 0); + var res = Import(GdbFileName, 0, FtClssName); if (res.HasError || string.IsNullOrEmpty(res.Value)) { return res; @@ -630,7 +744,7 @@ namespace OliviaAddInPro.Services string path_import = res.Value; //abre con valor único string path_lyr = path_import; - var resb = HelperGdb.OpenLayerUniqueValue(path_lyr, LimpiezaDef.Campos.consulta_sector); + var resb = HelperGdb.OpenLayerUniqueValue(path_lyr, ComunDef.CamposCom.consulta_sector); if (!resb.Value) { res.Error.Add("Error al abrir capa "+ path_lyr + " con Valor único. " + resb.Error.FirstOrDefault()); @@ -644,10 +758,10 @@ namespace OliviaAddInPro.Services /** * Realiza las funciones de importación de la planificación */ - public Respuesta ImportPlanif(string GdbFileName) + public Respuesta ImportPlanif(string GdbFileName, string FtClssName) { com.ProgrSrc.IncMessage(10, "Importando capas"); - var res = Import(GdbFileName, 1); + var res = Import(GdbFileName, 1, FtClssName); if (res.HasError || string.IsNullOrEmpty(res.Value)) { res.Value = string.Empty; @@ -685,7 +799,7 @@ namespace OliviaAddInPro.Services for(i =0;i Import(string GdbFileName, int modo) + public Respuesta Import(string GdbFileName, int modo, string FtClssName="") { var res = new Respuesta { Value = string.Empty }; @@ -734,6 +848,8 @@ namespace OliviaAddInPro.Services ///////////////////////////////////////// /////mira a ver si tiene configurado Dataset string msg_avisa = string.Empty; + string amb_aux = string.Empty; + bool sobreescribe = false; if (!string.IsNullOrEmpty(OliviaGlob.Paths.PathDatasetImport)) { var datname = new System.IO.DirectoryInfo(OliviaGlob.Paths.PathDatasetImport).Name; @@ -748,10 +864,29 @@ namespace OliviaAddInPro.Services msg_avisa = "No se encuentra el Dataset " + datname + ". "; } } + else + { + ///////////////////////////////////////// + //no tiene un dataset configurado, saca ventana para elegir uno + //saca ventana para elegir Dataset, si se cancela, se guarda en el nombre por defecto en función del tratamiento y los ámbitos + //HelperGlobal.ponMsg("A continuación, introduzca nombre de Feature Class y ubicación (Dataset) para importación. Si cancela el proceso, se establecerán el nombre y Dataset por defecto en función de los ámbitos y el tratamiento"); + string path_aux = FtClssName; + //HelperGdb.SaveFileDlg("Introduzca nombre de Feature Class a importar", GdbFileName, null, ArcGIS.Desktop.Catalog.ItemFilters.featureClasses_all); + if (!string.IsNullOrEmpty(path_aux)) + { + tratamiento = new DirectoryInfo(System.IO.Path.GetDirectoryName(path_aux)).Name; + //tratamiento = System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(path_aux)); + amb_aux = System.IO.Path.GetFileNameWithoutExtension(path_aux); + //comprueba si ya existe ese ft class + FeatureClass ft = HelperGdb.GetFtClass(path_aux); + if (ft != null) + sobreescribe = true; + } + } //crea el dataset o comprueba si existe string datasetNameOut = string.Empty; var resp = HelperGdb.CreateDataset(GdbFileName, tratamiento, spatRefData, out datasetNameOut); - string err_spatref = "Atención, no coincide la proyección de las FeatureClass del Dataset ya creado con la del FeatureClass a importar"; + if(resp.Value==0) { //avisa @@ -764,19 +899,33 @@ namespace OliviaAddInPro.Services res.Error.Add("Error al crear el Dataset para importar " + tratamiento); return res; } - else if (resp.Value == 2) + else //2 o 4 if (resp.Value == 2) { //avisa - msg_avisa = err_spatref + ", se ha creado un nuevo dataset " + datasetNameOut; + string err_spatref = string.Empty; + if (resp.Value==2) + err_spatref = "Atención, no coincide la proyección de las FeatureClass del Dataset ya creado con la del FeatureClass a importar. "; + msg_avisa = err_spatref + "Se ha creado un nuevo dataset " + datasetNameOut; //HelperGlobal.ponMsg(err_spatref +", se ha creado un nuevo dataset "+ datasetNameOut ); tratamiento = datasetNameOut; } - string dataset = tratamiento; + //avisa ahora para dar tiempo? + if (!string.IsNullOrEmpty(msg_avisa)) + { + if(!HelperGlobal.ponMsg(msg_avisa, MessageBoxImage.Question, "OLIVIA", MessageBoxButton.OKCancel)) + { + res.Error.Add("Proceso de importación Cancelado por el usuario"); + return res; + } + } + string dataset = tratamiento; + ///////////////////////////////////////// + if (!string.IsNullOrEmpty(amb_aux)) + ambitos = amb_aux; ///////////////////////////////////////// //todo ok, se pone a importar string err_st =string.Empty; - string name = ambitos; string path_import = GdbFileName + "\\" + dataset + "\\" + ambitos; int NIMPORT; string[] noms_shp = null; @@ -838,7 +987,18 @@ namespace OliviaAddInPro.Services ///////////////////////////////////////// //se embucla para hacer todas las importaciones necesarias for (i = 0; i < NIMPORT; i++) - { + { + //mira a ver si hay que borrar para reemplazar + if (sobreescribe) + { + resp = HelperGdb.DeleteFeatureClassSync(GdbFileName + "\\" + dataset, noms_gdb[i]); + if (resp.Value!=-2 && resp.Value!=1) //-2 porque puede ser que no pueda abrir la capa porque no existe + { + err_st = "Error al sobreescribir la capa " + noms_gdb[i]; + break; + } + } + resp2 = HelperGdb.ImportShp(dir_shp + "\\" + noms_shp[i] + HelperGdb.SHP_EXT, GdbFileName + "\\" + dataset, noms_gdb[i]); if (!resp2.Value) { @@ -853,9 +1013,6 @@ namespace OliviaAddInPro.Services res.Error.Add("Errores en la importación: "+err_st); return res; } - //avisa ahora para dar tiempo? - if(!string.IsNullOrEmpty(msg_avisa)) - HelperGlobal.ponMsg(msg_avisa); //cambia el nombre de los campos que había truncado a 10 caracteres al exportar a shp //solo para la capa original diff --git a/Services/FinProcServ.cs b/Services/FinProcServ.cs index d7589b8..e0ed7ef 100644 --- a/Services/FinProcServ.cs +++ b/Services/FinProcServ.cs @@ -42,7 +42,8 @@ namespace OliviaAddInPro.Services //actualiza los flags OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecOk); //importa resultados - resp = IniImport(); + string FtClssName = ""; + resp = IniImport(out FtClssName); if (resp.HasError) { msg = resp.Error.First(); @@ -59,7 +60,7 @@ namespace OliviaAddInPro.Services //actualiza los flags //OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.EjecSecto); //acciones de importación - resp2 = inst.ServCom.ImportSecto(GdbFileName); + resp2 = inst.ServCom.ImportSecto(GdbFileName, FtClssName); } else if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecPlanif)) //Ha terminado bien la planificación { @@ -68,7 +69,7 @@ namespace OliviaAddInPro.Services //guarda csv //GuardaCsv(inst); en finEjecuta3 //acciones de importación - resp2 = inst.ServCom.ImportPlanif(GdbFileName); + resp2 = inst.ServCom.ImportPlanif(GdbFileName, FtClssName); } Application.Current.Dispatcher.BeginInvoke(new Action, Respuesta, bool, string, TratamientoComun>((p, v, x, u, w) => finEjecuta3(p, v, x, u, w)), resp, resp2, mal, msg, inst); @@ -110,6 +111,8 @@ namespace OliviaAddInPro.Services { if (string.IsNullOrEmpty(resp2.Value)) { + //quita modo config2 + OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.Config2); if (resp2.HasError) { msg = resp2.Error.First(); @@ -246,9 +249,10 @@ namespace OliviaAddInPro.Services /* * Inicializa la importación */ - public Respuesta IniImport() + public Respuesta IniImport(out string FtClssName) { var res = new Respuesta() { Value = string.Empty }; + FtClssName = string.Empty; //Lanza ventana para elegir gdb a la que importar resultados string GdbFileName=""; if (OliviaGlob.CompruebaExistePath(OliviaGlob.Paths.PathGdbImport)) @@ -273,6 +277,12 @@ namespace OliviaAddInPro.Services return res; } res.Value = GdbFileName; + + if (string.IsNullOrEmpty(OliviaGlob.Paths.PathDatasetImport)) + { //ahora pide elegir nombre de ftclass + FtClssName = HelperGdb.SaveFileDlg("Seleccione ubicación e introduzca nombre de Feature Class a importar", GdbFileName, null, ArcGIS.Desktop.Catalog.ItemFilters.featureClasses_all); + } + return res; } } diff --git a/Services/LanzaSrv/LanzaOlvServ.cs b/Services/LanzaSrv/LanzaOlvServ.cs index d22065e..39f568d 100644 --- a/Services/LanzaSrv/LanzaOlvServ.cs +++ b/Services/LanzaSrv/LanzaOlvServ.cs @@ -74,10 +74,15 @@ namespace OliviaAddInPro.Services.LanzaSrv //paths de archivos GeneralDef.EjecGeoParamSep + GeneralDef.GG_pd + GeneralDef.EjecGeoParamIgual + OliviaGlob.Paths.PathData + " " + GeneralDef.EjecGeoParamSep + GeneralDef.GG_pn + GeneralDef.EjecGeoParamIgual + OliviaGlob.Paths.PathNW + " " + + //nombres de cols de sector y secuencia + GeneralDef.EjecGeoParamSep + GeneralDef.GTO_camp_sector + GeneralDef.EjecGeoParamIgual + ComunDef.CamposCom.consulta_sector + " " + + GeneralDef.EjecGeoParamSep + GeneralDef.GTO_camp_secuencia + GeneralDef.EjecGeoParamIgual + ComunDef.CamposCom.consulta_secuen + " " + + GeneralDef.EjecGeoParamSep + GeneralDef.GTO_camp_objectid + GeneralDef.EjecGeoParamIgual + ComunDef.CamposCom.camp_oid + " " + //giro max y desv - GeneralDef.EjecGeoParamSep + GeneralDef.GTO_girmax + GeneralDef.EjecGeoParamIgual + LimpiezaDef.OtrosParam.giro_max + " " + - GeneralDef.EjecGeoParamSep + GeneralDef.GTO_desv_max + GeneralDef.EjecGeoParamIgual + LimpiezaDef.OtrosParam.desv_max + " " + - GeneralDef.EjecGeoParamSep + GeneralDef.GTO_desv_max_abs + GeneralDef.EjecGeoParamIgual + LimpiezaDef.OtrosParam.desv_max_abs + " "; + GeneralDef.EjecGeoParamSep + GeneralDef.GTO_girmax + GeneralDef.EjecGeoParamIgual + ComunDef.CamposCom.giro_max + " " + + GeneralDef.EjecGeoParamSep + GeneralDef.GTO_desv_max + GeneralDef.EjecGeoParamIgual + ComunDef.CamposCom.desv_max + " " + + GeneralDef.EjecGeoParamSep + GeneralDef.GTO_desv_max_abs + GeneralDef.EjecGeoParamIgual + ComunDef.CamposCom.desv_max_abs + " "; + //LimpiezaDef.Campos.consulta_sector; } /** diff --git a/Services/LanzaSrv/LanzaRecoSrv.cs b/Services/LanzaSrv/LanzaRecoSrv.cs index 6749879..57e49be 100644 --- a/Services/LanzaSrv/LanzaRecoSrv.cs +++ b/Services/LanzaSrv/LanzaRecoSrv.cs @@ -61,7 +61,7 @@ namespace OliviaAddInPro.Services.LanzaSrv else if (modo == ModosEjec.SoloPlanifica) modo_str = GeneralDef.SockConfTodo; var conf = ConfigServ.Serv.Leer(); - //van ParamLimpN parámetros, sin incluir "CONFIGURACION", si se añaden, incrementar ParamLimpN + //van ParamLimpN parámetros, sin incluir "CONFIGURACION", si se añaden, incrementar ParamRecoN str = GeneralDef.EjecGeoParamSep + modo_str + " " + GeneralDef.EjecGeoParamSep + GeneralDef.GR_camp_cap + GeneralDef.EjecGeoParamIgual + conf.capac + " " + GeneralDef.EjecGeoParamSep + GeneralDef.GR_kgM + GeneralDef.EjecGeoParamIgual + reco.KgMaxVehic + " " + diff --git a/Services/ProcesoEjecServ.cs b/Services/ProcesoEjecServ.cs index 7796bc0..0eafe72 100644 --- a/Services/ProcesoEjecServ.cs +++ b/Services/ProcesoEjecServ.cs @@ -124,6 +124,7 @@ namespace OliviaAddInPro.Services } } + int result = Environment.TickCount & Int32.MaxValue; //para que el tickcount no sea negativo if (cps.Getcancelled()) //mira a ver si ha cancelado el usuario { //se ha cancelado, lo envía al OliviaTask @@ -137,11 +138,11 @@ namespace OliviaAddInPro.Services if(!fin) //si no ha finalizado normal, el usuario lo ha cancelado res.Error.Add("Proceso Cancelado por el usuario"); } - else if (!first_send_cfg && ((Math.Abs(Environment.TickCount) - lastprog) >= m_tm_progr) && !fin) //en caso normal, todo va bien, pide el progreso y la tarea + else if (!first_send_cfg && ((result - lastprog) >= m_tm_progr) && !fin) //en caso normal, todo va bien, pide el progreso y la tarea { //solo pide la programación cada m_tm_progr milis var pp = pide_progr(); - if (pp .Value> TiposActu.ActuFinOk) + if (pp.Value> TiposActu.ActuFinOk) fin = true; if(pp.HasError) { @@ -153,8 +154,10 @@ namespace OliviaAddInPro.Services else nint++; } + if (pp.Value == TiposActu.ActuFinNOk) + res.Error.Add("Finalizado proceso con fallos"); actualiza(pp); - lastprog = Environment.TickCount; + lastprog = result; } } while (!sal); diff --git a/Services/RecogidaServ.cs b/Services/RecogidaServ.cs index d8f0301..df8df10 100644 --- a/Services/RecogidaServ.cs +++ b/Services/RecogidaServ.cs @@ -28,15 +28,16 @@ namespace OliviaAddInPro.Services */ public int CompruebaCamposReco(string pathCapa) { - int NCAMPS = 6; + int NCAMPS = 5; string[] camps; camps = new string[NCAMPS]; - camps[0] = RecogidaDef.campos_def.cons_id; - camps[1] = RecogidaDef.campos_def.cons_fracc; - camps[2] = RecogidaDef.campos_def.cons_nomrec; - camps[3] = RecogidaDef.campos_def.cons_lateral; - camps[4] = RecogidaDef.campos_def.cons_uds; - camps[5] = RecogidaDef.campos_def.cons_kgrec; + + camps[0] = RecogidaDef.campos_def.cons_fracc; + camps[1] = RecogidaDef.campos_def.cons_nomrec; + camps[2] = RecogidaDef.campos_def.cons_lateral; + camps[3] = RecogidaDef.campos_def.cons_uds; + camps[4] = RecogidaDef.campos_def.cons_kgrec; + //camps[5] = RecogidaDef.campos_def.cons_id; int compCamp = HelperGdb.CheckFileds(pathCapa, camps); ErrStr = HelperGdb.OutStr; if (compCamp == 0) diff --git a/ViewModel/Limpieza/PaneLimpiezaSub1ViewModel.cs b/ViewModel/Limpieza/PaneLimpiezaSub1ViewModel.cs index 02b83c1..7861ab8 100644 --- a/ViewModel/Limpieza/PaneLimpiezaSub1ViewModel.cs +++ b/ViewModel/Limpieza/PaneLimpiezaSub1ViewModel.cs @@ -213,6 +213,7 @@ namespace OliviaAddInPro TipoTto = -1; VisTextAnchoVia = System.Windows.Visibility.Hidden; OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config); //lo reinicia, por si estaba después de planificar + OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.Config2); if (string.IsNullOrEmpty(capa)) return false; //comprueba los campos de limpieza diff --git a/ViewModel/Recogida/PaneRecogidaSub1ViewModel.cs b/ViewModel/Recogida/PaneRecogidaSub1ViewModel.cs index 93bf1ca..df985ba 100644 --- a/ViewModel/Recogida/PaneRecogidaSub1ViewModel.cs +++ b/ViewModel/Recogida/PaneRecogidaSub1ViewModel.cs @@ -274,6 +274,7 @@ namespace OliviaAddInPro TiposVehic.Clear(); TiposCapac.Clear(); OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config); //lo reinicia, por si estaba después de planificar + OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.Config2); if (string.IsNullOrEmpty(capa)) return false;