OliviaAddInPro/Model/Limpieza.cs

167 lines
6.0 KiB
C#

using ArcGIS.Core.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OliviaAddInPro.Helper;
using System.Collections.ObjectModel;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using OliviaAddInPro.Services;
using static OliviaAddInPro.Model.ComunDef;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using OliviaAddInPro.Services.LanzaSrv;
namespace OliviaAddInPro.Model
{
public class Limpieza : TratamientoComun
{
//**********************************************
//Se recogen en PaneLimpiezaSub1
/**
* Ámbitos de trabajo elegidos
*/
public bool[] AmbitosSel { get; set; } = new bool[(int)LimpiezaDef.AmbitsTra.AmbN];
/**
* Indica si respeta el sentido de circulación o no
*/
public bool RespCirc { get; set; } = false;
/**
* Tipo de unidades del tiempo de tto
*/
public int UdsTTto { get; set; } = (int)GeneralDef.OlvTiposTto.OlvTipTtoNoDef;
/**
* Instancia para las funciones de exportación y demás
*/
public LimpiezaServ Serv
{
get
{
return (LimpiezaServ)ServCom;
}
set
{
ServCom = value;
}
}
public LanzaLimpSrv LanzaSrv { get; set; } = null;
/**
* Ancho de vía, en metros
*/
public double AnchoVia { get; set; } = LimpiezaDef.Parametros.ancho_via;
public Limpieza()
{
Serv = new LimpiezaServ(this);
LanzaSrv = new LanzaLimpSrv();
}
public override Respuesta<TiposEjecucion> Ejecuta(ModosEjec modo)
{
/////////////////////////////
/////
///DEBUG
///
//Respuesta<TiposEjecucion> res1 = new Respuesta<TiposEjecucion> { Value = TiposEjecucion.FinEjecOk };
//HelperGdb.OpenLayer(@"C:\Users\Elena\Documents\ArcGIS\Projects\MyProject3\MyProject3.gdb\Barrido_man\BarMan_AceM_AceNM_20220529_134336", "SECTOR", true);
//Serv.ActualizaSecto(@"D:\Proyectos\Olivia\Instal2.0\data\data_T00_A0405_20220628_214902.shp", @"C:\\Users\\Elena\\Documents\\ArcGIS\\Projects\\MyProject3\\MyProject3.gdb\\Barrido_man\\BarMan_AceM_AceNM_20220628_214613");
//return res1;
//////////////////
/////////////////////////////
Respuesta<bool> res = new Respuesta<bool> { Value=false};
Respuesta<TiposEjecucion> res2 = new Respuesta<TiposEjecucion> (){ Value = TiposEjecucion.FinEjecNOk };
res = Serv.Ejecuta(modo);
if (res.Value)
{
res=LanzaSrv.ejec(this, modo, TipoTtoStr);
if (res.Value)
{
ProceSrv.ConfigConex();
res2 = ProceSrv.start(LanzaSrv.str_cfg, ProgrSrc._ProgrSrc);
if(!LanzaSrv.EsperaProcess(GeneralDef.NombOlvTasks))
res2.Error.Add("No se ha podido cerrar oliviaTask.");
}
}
if (res.HasError)
{
res2.Error.AddRange(res.Error);
}
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)
{
auxili = shapefile.Substring(aux, auxl);
ambitos = ambitos + auxili;
}
//concatena el timestamp
ambitos = ambitos + shapefile.Substring(aux);
}
/**
* Restaura el nombre original del campo si se ha truncado a 10 car al exportar a shp
*/
public override string[] GetCamposRestaura()
{
string[] camps = {
LimpiezaDef.Campos.consulta_entidad,
LimpiezaDef.Campos.consulta_mecan,
LimpiezaDef.Campos.consulta_observ,
LimpiezaDef.Campos.consulta_anch_tip,
LimpiezaDef.Campos.consulta_tipolo,
/*LimpiezaDef.Campos.consulta_sector,
LimpiezaDef.Campos.consulta_secuen */};
return camps;
}
}
}