Avances importación

Elena/develop
Elena 2022-05-17 15:06:02 +02:00
parent 7f824052a3
commit 7ab639b800
8 changed files with 400 additions and 145 deletions

View File

@ -29,7 +29,8 @@ namespace OliviaAddInPro.Helper
{
private static string ObjectId = "OBJECTID";
private static string out_str = string.Empty;
public static string OutStr {
public static string OutStr
{
get
{
/*string val = "";
@ -43,7 +44,8 @@ namespace OliviaAddInPro.Helper
private static string texto_sal = string.Empty;
public static string TextoSal
{
get {
get
{
/*string val = "";
val.CopyFrom(texto_sal);
texto_sal = string.Empty; //lo borra cada vez que se consulta
@ -145,7 +147,7 @@ namespace OliviaAddInPro.Helper
}
//Devuelve el Path del archivo seleccionado o un string vacío si se ha cancelado
public static string OpenFileDialog(TiposOpenFileDlg tipo, string initialLoc="")
public static string OpenFileDialog(TiposOpenFileDlg tipo, string initialLoc = "", string tit_ = "")
{
string titulo;
ReiniciaOutStr();
@ -179,15 +181,20 @@ namespace OliviaAddInPro.Helper
{
filtro.AddFilter(BrowseProjectFilter.GetFilter(""));
}
if (!string.IsNullOrEmpty(tit_))
titulo = tit_;
//Display the filter in an Open Item dialog
OpenItemDialog aNewFilter = new OpenItemDialog
{
Title = titulo,
InitialLocation = initialLoc,
MultiSelect = false,
//Set the BrowseFilter property to Pro's Geodatabase filter.
BrowseFilter = filtro
};
if (!string.IsNullOrEmpty(initialLoc))
aNewFilter.InitialLocation = initialLoc;
bool? ok = aNewFilter.ShowDialog();
if ((ok ?? true) && aNewFilter.Items.Count() > 0)
return aNewFilter.Items.First().Path;
@ -1241,7 +1248,8 @@ namespace OliviaAddInPro.Helper
string message = String.Empty;
bool deletionResult = false;
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => {
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
EditOperation editOperation = new EditOperation();
editOperation.Callback(context =>
@ -1440,5 +1448,30 @@ namespace OliviaAddInPro.Helper
}
}
/**
* Saca diálogo para guardar un archivo
*/
public static string SaveFileDlg(string title_, string initloc_, string ext_, string filt_)
{
//Display the filter in an Open Item dialog
SaveItemDialog dlg = new SaveItemDialog
{
Title = title_,
OverwritePrompt = true,
};
if (!string.IsNullOrEmpty(initloc_))
dlg.InitialLocation = initloc_;
if (!string.IsNullOrEmpty(filt_))
dlg.Filter = filt_;
if (!string.IsNullOrEmpty(ext_))
dlg.DefaultExt = ext_;
bool? ok = dlg.ShowDialog();
if ((ok ?? true) && dlg.FilePath.Length > 0)
return dlg.FilePath;
else
return string.Empty;
}
}
}

View File

@ -36,7 +36,17 @@ namespace OliviaAddInPro.Model
* Instancia para las funciones de exportación y demás
*/
public LimpiezaServ Serv { get; set; } = null;
public LimpiezaServ Serv
{
get
{
return (LimpiezaServ)ServCom;
}
set
{
ServCom = value;
}
}
public LanzaLimpSrv LanzaSrv { get; set; } = null;
/**
@ -47,8 +57,6 @@ namespace OliviaAddInPro.Model
{
Serv = new LimpiezaServ(this);
LanzaSrv = new LanzaLimpSrv();
ProceSrv = new ProcesoEjecServ();
ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog.GetViewModel());
}
public override Respuesta<TiposEjecucion> Ejecuta(ModosEjec modo)
@ -73,5 +81,55 @@ namespace OliviaAddInPro.Model
}
return res2;
}
/**
* Descodifica el nombre del sahpefile de entrada identificando el tipo de tratamiento y los ámbitos de trabajo
*/
public override void decode_gdb(string shapefile, out string tratamiento, out string ambitos)
{
int aux, auxl, mbito, indice, tratamient;
string auxili, ambi, auxi;
indice = shapefile.IndexOf("_");
indice = indice + 2;//para saltarse la T que va antes del identificador del tipo de tratamiento
auxili = shapefile.Substring(indice, 2);
tratamient = Convert.ToInt32(auxili);
tratamiento = LimpiezaDef.tto_gdb[tratamient];
indice = shapefile.IndexOf("_", indice);
indice = indice + 2;//para saltarse la A que va antes del identificador de los ámbitos que intervienen
aux = shapefile.IndexOf("_", indice);
auxl = aux - indice;
auxi = "";
while (auxl > 0)
{
ambi = shapefile.Substring(indice, 2);
mbito = Convert.ToInt32(ambi);
indice = indice + 2;
auxl = auxl - 2;
if (auxl != 0)
auxi = auxi + LimpiezaDef.ambs_gdb[mbito] + "_";
else
auxi = auxi + LimpiezaDef.ambs_gdb[mbito];
}
ambitos = LimpiezaDef.preftto_gdb[tratamient] + "_" + auxi;
//quita los espacios
tratamiento = tratamiento.Replace(" ", "_");
ambitos = ambitos.Replace(" ", "_");
auxi = shapefile;
//para poner la zona cuando es seleccionada
for (int i = 0; i < 2; i++)
{
indice = auxi.LastIndexOf("_");
auxi = auxi.Substring(0, indice);
}
auxl = indice - aux;
if (auxl <= 0)
return;
auxili = shapefile.Substring(aux, auxl);
ambitos = ambitos + auxili;
}
}
}

View File

@ -100,7 +100,6 @@ namespace OliviaAddInPro.Model
get { return reco; }
set { reco = value; }
}
public static EjecServ Serv { get; } = new EjecServ();
public static SpatialReference SpatRef { get; set; } = null;
public static MarchandoUnaDe progrDialog { get; set; } = null;
#endregion Properties

View File

@ -69,7 +69,17 @@ namespace OliviaAddInPro.Model
get;
set;
}
public RecogidaServ Serv { get; set; } = null;
public RecogidaServ Serv
{
get
{
return (RecogidaServ)ServCom;
}
set
{
ServCom = value;
}
}
public LanzaRecoSrv LanzaSrv { get; set; } = null;
public Recogida()
{
@ -99,5 +109,48 @@ namespace OliviaAddInPro.Model
}
return res2;
}
/**
* Descodifica el nombre del sahpefile de entrada identificando el tipo de fracción y la carga para la recogida de residuos
*/
public override void decode_gdb(string shapefile, out string fraccion, out string carga)
{
int aux, auxl, carg, indice, fracc;
string auxili, fra, auxi;
indice = shapefile.IndexOf("_");
indice = indice + 2;//para saltarse la F que va antes del identificador del tipo de fracción
auxili = shapefile.Substring(indice, 2);
fracc = Convert.ToInt32(auxili);
fraccion = RecogidaDef.tipos_fracc_str[fracc];
indice = shapefile.IndexOf("_", indice);
indice = indice + 2;//para saltarse la C que va antes del identificador de los tipos de carga de los vehículos
aux = shapefile.IndexOf("_", indice);
auxi = "";
fra = shapefile.Substring(indice, 2);
carg = Convert.ToInt32(fra);
carga = RecogidaDef.tipos_fracc_str[fracc] + "_" + RecogidaDef.tipos_carg_str[carg];
//quita los espacios
fraccion = fraccion.Replace(" ", "_");
carga = carga.Replace(" ", "_");
////////////////////////
auxi = shapefile;
for (int i = 0; i < 2; i++)
{
indice = auxi.LastIndexOf("_");
auxi = auxi.Substring(0, indice);
}
auxl = indice - aux;
if (auxl <= 0)
return;
auxili = shapefile.Substring(aux, auxl);
carga = carga + auxili;
}
}
}

View File

@ -136,6 +136,7 @@ namespace OliviaAddInPro.Model
public MyCancelableProgressorSource ProgrSrc { get; set; } = null;
public ProcesoEjecServ ProceSrv { get; set; } = null;
public FinProcServ FinProceSrv { get; set; } = null;
public EjecServ ServCom { get; set; } = null;
public TratamientoComun()
{
@ -151,15 +152,15 @@ namespace OliviaAddInPro.Model
//oculta la ventana
OliviaGlob.ShowHidePane(false);
//comienza ejecución
Action<Respuesta<TiposEjecucion>> ac = FinProceSrv.finEjecuta;
Action<Respuesta<TiposEjecucion>, TratamientoComun> ac = FinProceSrv.finEjecuta;
EjecutaAsync(modo, ac);
}
public async void EjecutaAsync(ModosEjec modo, Action<Respuesta<TiposEjecucion>> ffin)
public async void EjecutaAsync(ModosEjec modo, Action<Respuesta<TiposEjecucion>, TratamientoComun> ffin)
{
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
var res = Ejecuta(modo);
ffin(res);
ffin(res, this);
return res;
});
@ -170,5 +171,14 @@ namespace OliviaAddInPro.Model
res.Error.Add("No implementado");
return res;
}
/**
* Descodifica el nombre del sahpefile de entrada identificando el tipo de tratamiento y los ámbitos de trabajo
*/
public virtual void decode_gdb(string shapefile, out string tratamiento, out string ambitos)
{
tratamiento = string.Empty;
ambitos = string.Empty;
}
}
}

View File

@ -73,14 +73,6 @@ namespace OliviaAddInPro.Services
//mira spatialreference de los datos de entrada
spatRefData = geom_export.SpatialReference;
//AQUÍ COMPARAR SI ES IGUAL QUE SPATREFDEF Y SI NO, REPROYECTAR
/*if(spatRef.Wkid!=GeneralDef.SpatRefDef)
{
/*
* FALTA HACER
* dame_geom_coords en v2010
*/
//}
//crea el filtro de exportación
filtroEspacial = HelperGdb.CreateFiler(com.ConsultaAmbs, geom_export);
@ -204,8 +196,7 @@ namespace OliviaAddInPro.Services
}
//mira spatialreference del nw
FeatureClass fc = HelperGdb.GetFtClass(OliviaGlob.Paths.PathGdbNw);
/*
/*FeatureClass fc = HelperGdb.GetFtClass(OliviaGlob.Paths.PathGdbNw);
if (fc != null)
{
spatRef = fc.GetDefinition().GetSpatialReference();
@ -368,5 +359,51 @@ namespace OliviaAddInPro.Services
return false;
}
/**
* Realiza las funciones de importación de la sectorización
*/
public Respuesta<bool> ImportSecto(string GdbFileName)
{
var res = new Respuesta<bool> { Value = false };
/*
try
{
//temp
string name;
res = import_secto_fin(GdbFileName, out name);
if (!res.Value)
{
res.Error.Add("Error al importar resultados.");
return res;
}
res = pinta_sectores(GdbFileName, name, 4);
if (!res.Value)
{
res.Error.Add("Error al pintar sectores.");
return res;
}
}
catch (Exception)
{
res.Error.Add("Se ha cancelado la importación de resultados.");
return res;
}
res.Value = true;
return res;*/
return res;
}
/**
* Realiza las funciones de importación de la planificación
*/
public Respuesta<bool> ImportPlanif(string GdbFileName)
{
var res = new Respuesta<bool> { Value = false };
return res;
}
}
}

View File

@ -12,8 +12,9 @@ namespace OliviaAddInPro.Services
{
public class FinProcServ
{
public void finEjecuta(Respuesta<TiposEjecucion> res)
public void finEjecuta(Respuesta<TiposEjecucion> res, TratamientoComun inst)
{
//REVISAR CUANDO ACABA, SE CAMBIE EL MARCHANDO PARA QUE SE LE DE A FINALIZAR Y TERMINA OK
String msg=string.Empty;
//gestiona los flags, el estado de finok o finnok va en res.Vale
@ -25,42 +26,43 @@ namespace OliviaAddInPro.Services
}
else
{
msg = Resource1.String_exito;
bool todoOk = true;
//actualiza los flags
OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecOk);
//importa resultados
var resp = IniImport();
if (resp.HasError)
msg = resp.Error.First();
else
{
string GdbFileName = resp.Value;
var resp2 = new Respuesta<bool> { Value=false};
if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecSecto)) //Ha terminado bien la sectorización
{
/*if (!gdb.import_secto_ini())
{
todoOk=false;
msg = msg + " " + gdb.err_st;
}*/
resp2 = inst.ServCom.ImportSecto(GdbFileName);
}
else if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecPlanif)) //Ha terminado bien la planificación
{
/*guarda_csv();
if (!gdb.import_planif())
{
todoOk=false;
msg = msg + " " + gdb.err_st;
}*/
GuardaCsv(inst);
resp2 = inst.ServCom.ImportPlanif(GdbFileName);
}
//actualiza los flags
OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecOk);
if (todoOk)
if (!resp2.Value)
{
msg = resp2.Error.First();
}
else
{
msg = Resource1.String_exito;
//pone modo config2
OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config2);
}
}
}
//borra los archivos que le toca borrar
BorraFiles();
HelperGlobal.ponMsg(msg);
Application.Current.Dispatcher.Invoke(new Action(() => { finEjecuta2(); }));
}
public void finEjecuta2()
{
OliviaGlob.progrDialog.Hide();
@ -68,8 +70,6 @@ namespace OliviaAddInPro.Services
OliviaGlob.ShowHidePane(true);
}
/**
* Borra los archivos exportados para el proceso
*/
@ -113,5 +113,69 @@ namespace OliviaAddInPro.Services
MessageBox.Show(ex.Message);
}
}
public static string NAME_CSV = "_L";
public static string EXT_CSV = ".csv";
/*
* Permite guardar el archivo CSV que contiene la secuencia que se ha llevado a cabo en las rutas en la planificación.
*/
public static void GuardaCsv(TratamientoComun inst)
{
string auxi, nombre = null;
string[] nameDokL;
string DirData = System.IO.Path.GetDirectoryName(OliviaGlob.Paths.PathData);
nameDokL = Directory.GetFiles(DirData,
System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData) + NAME_CSV + ".*");
string Title = "Guardar Secuencia de la Planificación";
string Filter = "Secuencia en formato CSV (*.csv)|*.csv";
inst.decode_gdb(System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData),
out auxi, out nombre);
string InitialDirectory = System.IO.Path.Combine(DirData, nombre);
string FileName = HelperGdb.SaveFileDlg(Title, InitialDirectory, EXT_CSV, Filter);
if (string.IsNullOrEmpty(FileName) || FileName.Length == 0)
{
bool ok = HelperGlobal.ponMsg("Se va a perder el archivo que contiene la secuencia en planificación, ¿está seguro?",
MessageBoxImage.Question,"OLIVIA",MessageBoxButton.YesNo);
if (!ok)
GuardaCsv(inst);
}
else
{
if (File.Exists(FileName))
File.Delete(FileName);
File.Move(nameDokL[0], FileName);
}
}
/*
* Inicializa la importación
*/
public Respuesta<string> IniImport()
{
var res = new Respuesta<string>() { Value = string.Empty };
//Lanza ventana para elegir gdb a la que importar resultados
bool sal = true;
string GdbFileName="";
do
{
sal = true;
//repite por si se ha equivocado hasta que elige la gdb
GdbFileName = HelperGdb.OpenFileDialog(HelperGdb.TiposOpenFileDlg.OpenGdb,"", "Seleccionar GDB a la que importar los resultados");
if(string.IsNullOrEmpty(GdbFileName))
sal= HelperGlobal.ponMsg("¿Desea cancelar el proceso de imporación?",
MessageBoxImage.Question, "OLIVIA", MessageBoxButton.YesNo);
} while (!sal);
if (string.IsNullOrEmpty(GdbFileName) || !Directory.Exists(GdbFileName))
{
res.Error.Add("Se ha cancelado la importación de resultados.");
return res;
}
res.Value = GdbFileName;
return res;
}
}
}

View File

@ -208,5 +208,6 @@ namespace OliviaAddInPro.Services
}
return amb_com;
}
}
}