267 lines
8.9 KiB
C#
267 lines
8.9 KiB
C#
/*using ArcGIS.Core.Data;
|
|
using ArcGIS.Core.Geometry;
|
|
using ArcGIS.Core.Internal.CIM;
|
|
using ArcGIS.Desktop.Framework.Threading.Tasks;*/
|
|
using ActiproSoftware.Windows.Extensions;
|
|
using OliviaAddInPro.Helper;
|
|
using OliviaAddInPro.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using static OliviaAddInPro.Model.ComunDef;
|
|
|
|
namespace OliviaAddInPro.Services
|
|
{
|
|
public class LimpiezaServ : EjecServ
|
|
{
|
|
private Limpieza limp;
|
|
|
|
public LimpiezaServ(Limpieza _limp)
|
|
{
|
|
if (_limp == null)
|
|
_limp = OliviaGlob.Limp;
|
|
limp = _limp;
|
|
}
|
|
/**
|
|
* Acciones para comenzar ejecución
|
|
* Modo 0, sectorizar
|
|
* Modo 1, planificar
|
|
*/
|
|
public Respuesta<bool> Ejecuta(ModosEjec modo)
|
|
{
|
|
var modos_viaje = ConfigServ.Serv.Leer().ListaMV;
|
|
if (modos_viaje != null && modos_viaje.Count > TipoMv && TipoMv >= 0)
|
|
{
|
|
ComunDef.configMV = modos_viaje[TipoMv];
|
|
}
|
|
else
|
|
{
|
|
ComunDef.configMV = new OliviaConfMV();
|
|
}
|
|
var res = new Respuesta<bool>()
|
|
{
|
|
Value = false
|
|
};
|
|
MyCancelableProgressorSource cps = limp.ProgrSrc;
|
|
|
|
com = (TratamientoComun)limp;
|
|
string nombFileAmbs = string.Empty;
|
|
//Prepara consulta
|
|
ErrStr = string.Empty;
|
|
if (!PreparaConsulta(out nombFileAmbs))
|
|
{
|
|
res.Error.Add("No se ha seleccionado una consulta válida" + limp.ConsultaAmbs);
|
|
return res;
|
|
}
|
|
|
|
//Prepara nombre
|
|
limp.NombreShpExp_PrefTto = "T" + limp.TipoTto.ToString("00") + nombFileAmbs + DameStrPoligs();
|
|
|
|
string msg = "";
|
|
//comienza ejecucion
|
|
if(!ExportaEjec(modo, out msg))
|
|
{
|
|
res.Error.Add(msg);
|
|
//cierra y borra las capas si le ha dado tiempo a exportar
|
|
FinProcServ.BorraFiles();
|
|
return res;
|
|
}
|
|
|
|
//cierra las capas que se han abierto durante la exportación
|
|
CierraCapas();
|
|
|
|
res.Value = true;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
public bool PreparaConsulta(out string nombFileAmbs)
|
|
{
|
|
nombFileAmbs = string.Empty;
|
|
limp.ConsultaAmbs = DameAmbsConsulta(out nombFileAmbs);
|
|
if (null==limp.ConsultaAmbs)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public string DameAmbsConsulta(out string ambs_file)
|
|
{
|
|
string consulta, orstr;
|
|
|
|
consulta = string.Empty;
|
|
ambs_file = "";
|
|
orstr = null;
|
|
var n = limp.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;
|
|
}
|
|
public ObservableCollection<string> GetNombreModosViajes()
|
|
{
|
|
|
|
var conf=ConfigServ.Serv.Leer();
|
|
var res = new ObservableCollection<string>();
|
|
if (conf.ListaMV==null || conf.ListaMV.Count<=0 )
|
|
return res;
|
|
res.AddRange(conf.ListaMV.Select(c => c.nombre));
|
|
return res;
|
|
}
|
|
public int GetModosViajesDefecto(int vehiculo)
|
|
{
|
|
|
|
var conf = ConfigServ.Serv.Leer();
|
|
var res = new ObservableCollection<string>();
|
|
if (conf.ListaMV == null || conf.ListaMV.Count <= 0)
|
|
return -1;
|
|
for(int i=0; i< conf.ListaMV.Count; i++)
|
|
{
|
|
if (conf.ListaMV[i].vehiculo_def_reco == vehiculo)
|
|
return i;
|
|
}
|
|
return 0;
|
|
}
|
|
public int GetModosViajesDefecto(bool rcircu)
|
|
{
|
|
int vehiculo= rcircu? 1: 0;
|
|
var conf = ConfigServ.Serv.Leer();
|
|
var res = new ObservableCollection<string>();
|
|
if (conf.ListaMV == null || conf.ListaMV.Count <= 0)
|
|
return -1;
|
|
for (int i = 0; i < conf.ListaMV.Count; i++)
|
|
{
|
|
if (conf.ListaMV[i].vehiculo_def_lim == vehiculo)
|
|
return i;
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* Comprueba lo necesario para ver si hay campos para la planificación
|
|
*/
|
|
public bool CompruebaPlanif2()
|
|
{
|
|
//NO SE USA AQUÍ, ESTÁ EN EJECSERV
|
|
//si ha importado no hace falta que compruebe, seguro que las tiene
|
|
if (OliviaGlob.IsConfig2() && ComprCamposPlanif(limp.CapaElems))
|
|
return true;
|
|
//no ha importado, comprueba capa
|
|
if (ComprCamposPlanif(limp.CapaElems))
|
|
return true;
|
|
|
|
return false;
|
|
/*
|
|
string path = null;
|
|
if (!HelperGlobal.ponMsg("En la capa de ámbitos seleccionada no se encuentran columnas de SECTOR y/o SECUENCIA, " +
|
|
"necesarias para planificar. ¿Desea utilizar la sectorización de otra capa?",MessageBoxImage.Question,"OLIVIA",
|
|
MessageBoxButton.YesNo))
|
|
return false;
|
|
|
|
//saca diálogo para elegir capa
|
|
path = HelperGdb.OpenFileDialog(HelperGdb.TiposOpenFileDlg.OpenFtrClassLine | HelperGdb.TiposOpenFileDlg.OpenFtrClassPoint);
|
|
if (string.IsNullOrEmpty(path))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//comprueba que en la nueva capa haya columnas de planif
|
|
if (!ComprCamposPlanif(path))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//almacena la info de secto auxiliar
|
|
limp.CapaAuxPlanif = path;
|
|
return true;*/
|
|
|
|
}
|
|
|
|
/*
|
|
* Lee la capa que se ha seleccionzdo de limpieza y se comprueba que contiene los campos necesarios
|
|
*/
|
|
public bool CompruebaCamposLimp(string pathCapa)
|
|
{
|
|
string[] camps = limp.GetCampos(pathCapa);
|
|
//int res = 1;
|
|
if ((camps == null) || (HelperGdb.CheckFileds(pathCapa, camps) != 0))
|
|
{
|
|
ErrStr = HelperGdb.OutStr;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
/**
|
|
* Lee la gdb y devuelve el array de ámbitos en función de si hay en la gdb o no
|
|
*/
|
|
public bool[] BuscAmbGdb(string pathCapa)
|
|
{
|
|
string consulta;
|
|
long numero_lin;
|
|
bool[] amb_gdb = new bool[(int)LimpiezaDef.AmbitsTra.AmbN];//se inician a false
|
|
|
|
//mira a ver si hay ejes de calle
|
|
consulta = LimpiezaDef.filtro_str[(int)LimpiezaDef.AmbitsTra.AmbEjeCalle];
|
|
numero_lin = HelperGdb.GetNumElems(OliviaGlob.Paths.PathGdbNw, consulta);
|
|
if (numero_lin > 0)
|
|
{
|
|
amb_gdb[(int)LimpiezaDef.AmbitsTra.AmbEjeCalle] = true;
|
|
}
|
|
//mira a ver si hay el resto de capas y tienen entidades
|
|
for (int i = (int)LimpiezaDef.AmbitsTra.AmbBordLibreMec; i < (int)LimpiezaDef.AmbitsTra.AmbN; i++)
|
|
{
|
|
consulta = LimpiezaDef.filtro_str[i];
|
|
numero_lin = HelperGdb.GetNumElems(pathCapa, consulta);
|
|
|
|
if (numero_lin > 0)
|
|
{
|
|
amb_gdb[i] = true;
|
|
}
|
|
}
|
|
|
|
return amb_gdb;
|
|
}
|
|
/**Devuelve el array de los ámbitos comunes y no comunes de las opciones de un tratamiento tto
|
|
* Es un array de longitud el número de ámbitos totales, con true en las posiciones en los que el ámbito sea común o
|
|
* no común en las opciones
|
|
*/
|
|
public bool[] DameAmbTto(int tto)
|
|
{
|
|
int i;
|
|
bool sig;
|
|
bool[] amb_com = new bool[(int)LimpiezaDef.AmbitsTra.AmbN];
|
|
|
|
for (int j = 0; j < (int)LimpiezaDef.AmbitsTra.AmbN; j++)
|
|
{
|
|
sig = false;
|
|
for (i = 0; i < LimpiezaDef.ambs_val[tto].n_ops && !sig; i++)
|
|
{
|
|
if (LimpiezaDef.ambs_val[tto].ambs_ops[i].ambs[j]) //con que encuentre uno true lo pone y pasa al siguiente
|
|
{
|
|
amb_com[j] = sig = true;
|
|
}
|
|
}
|
|
}
|
|
return amb_com;
|
|
}
|
|
|
|
}
|
|
}
|