486 lines
19 KiB
C#
486 lines
19 KiB
C#
using OliviaAddInPro.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
using Newtonsoft.Json;
|
|
using Microsoft.Win32;
|
|
using static OliviaAddInPro.Model.OliviaConf;
|
|
|
|
namespace OliviaAddInPro.Services
|
|
{
|
|
class ConfigServ
|
|
{
|
|
private static string pathConfigDef = "C:\\Olivia";
|
|
private static ConfigServ configServ=null;
|
|
private static string nameDirWork = "%dir_work%";
|
|
public const string OlvRegKey = "SOFTWARE\\Narvaling\\Olivia_3_1";
|
|
public const string OlvRegName = "workdir";
|
|
public const string OlvConfigName = "olv.conf";
|
|
public const string VersionConfiguracion = "1.1.0.2";
|
|
public static ConfigServ Serv
|
|
{
|
|
get {
|
|
if (configServ == null)
|
|
configServ = new ConfigServ();
|
|
return configServ;
|
|
}
|
|
}
|
|
|
|
public OliviaConf Leer()
|
|
{
|
|
OliviaConf res = Default();
|
|
try
|
|
{
|
|
var path_cfg = GetPathConfig();
|
|
path_cfg = Path.Combine(path_cfg, OlvConfigName);
|
|
res = JsonConvert.DeserializeObject<OliviaConf>(File.ReadAllText(path_cfg));
|
|
}catch(Exception e)
|
|
{
|
|
var ee = e;
|
|
res = null;
|
|
}
|
|
if(res==null || res.Version==null || res.Version != VersionConfiguracion)
|
|
res = Default();
|
|
|
|
EnumOpsNWToString.ListaNw = res.ListaNw;
|
|
//pilla la IP
|
|
if (res.Ip.CompareTo("0.0.0.0")==0)
|
|
{
|
|
//coge la IP local
|
|
res.Ip = OliviaGlob.Conexion.Ip;
|
|
}
|
|
|
|
res.PathGdbGen = pon_path_absoluto(res.PathGdbGen, res.path_work);
|
|
res.PathSimbVSM = pon_path_absoluto(res.PathSimbVSM, res.path_work);
|
|
res.PathSimbESRI = pon_path_absoluto(res.PathSimbESRI, res.path_work);
|
|
res.PathCartela = pon_path_absoluto(res.PathCartela, res.path_work);
|
|
res.Path_Eje_via = pon_path_absoluto(res.Path_Eje_via, res.path_work);
|
|
|
|
|
|
res.path_exe = pon_path_absoluto(res.path_exe, res.path_work);
|
|
res.path_manual = pon_path_absoluto(res.path_manual, res.path_work);
|
|
//chapa
|
|
if (res.path_manual.Contains("Manual_Olivia_3_0.pdf"))
|
|
res.path_manual.Replace("Manual_Olivia_3_0.pdf", "Manual_Olivia.pdf");
|
|
//////////////
|
|
res.path_temp = pon_path_absoluto(res.path_temp, res.path_work);
|
|
res.path_data = pon_path_absoluto(res.path_data, res.path_work);
|
|
res.path_cfg_aux = @"%dir_work%cfg.ini";
|
|
res.path_cfg_aux = pon_path_absoluto(res.path_cfg_aux, res.path_work);
|
|
return res;
|
|
}
|
|
|
|
public Respuesta<bool> Guardar(OliviaConf conf)
|
|
{
|
|
Respuesta<bool> resp = new Respuesta<bool> { Value = true };
|
|
conf.path_exe = pon_path_relativo(conf.path_exe, conf.path_work);
|
|
conf.path_manual = pon_path_relativo(conf.path_manual, conf.path_work);
|
|
conf.path_temp = pon_path_relativo(conf.path_temp, conf.path_work);
|
|
conf.path_data = pon_path_relativo(conf.path_data, conf.path_work);
|
|
conf.path_cfg_aux = pon_path_relativo(conf.path_cfg_aux, conf.path_work);
|
|
|
|
conf.PathGdbGen = pon_path_relativo(conf.PathGdbGen, conf.path_work);
|
|
conf.PathSimbVSM = pon_path_relativo(conf.PathSimbVSM, conf.path_work);
|
|
conf.PathSimbESRI = pon_path_relativo(conf.PathSimbESRI, conf.path_work);
|
|
conf.PathCartela = pon_path_relativo(conf.PathCartela, conf.path_work);
|
|
conf.Path_Eje_via = pon_path_relativo(conf.Path_Eje_via, conf.path_work);
|
|
|
|
try
|
|
{
|
|
string jsonString = JsonConvert.SerializeObject(conf);
|
|
var path_cfg = GetPathConfig();
|
|
path_cfg = Path.Combine(path_cfg, OlvConfigName);
|
|
File.WriteAllText(path_cfg, jsonString);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
resp.Error.Add("Error al guardar archivo: " + ex.Message);
|
|
resp.Value = false;
|
|
}
|
|
|
|
conf.path_exe = pon_path_absoluto(conf.path_exe, conf.path_work);
|
|
conf.path_cfg_aux = pon_path_absoluto(conf.path_cfg_aux, conf.path_work);
|
|
conf.path_temp = pon_path_absoluto(conf.path_temp, conf.path_work);
|
|
conf.path_manual = pon_path_absoluto(conf.path_manual, conf.path_work);
|
|
conf.path_data = pon_path_absoluto(conf.path_data, conf.path_work);
|
|
conf.PathGdbGen = pon_path_absoluto(conf.PathGdbGen, conf.path_work);
|
|
conf.PathSimbVSM = pon_path_absoluto(conf.PathSimbVSM, conf.path_work);
|
|
conf.PathSimbESRI = pon_path_absoluto(conf.PathSimbESRI, conf.path_work);
|
|
conf.PathCartela = pon_path_absoluto(conf.PathCartela, conf.path_work);
|
|
conf.Path_Eje_via = pon_path_absoluto(conf.Path_Eje_via, conf.path_work);
|
|
|
|
return resp;
|
|
}
|
|
/**
|
|
* cambia la carpeta referida a directorio de trabajo por los caracteres OliviaDirWork (%dir_work%)
|
|
*/
|
|
private string pon_path_relativo(string path, string DirWork)
|
|
{
|
|
if (string.IsNullOrEmpty(DirWork) || string.IsNullOrEmpty(path))
|
|
return path;
|
|
return path.Replace( DirWork, nameDirWork);
|
|
}
|
|
|
|
/**
|
|
* cambia los caracteres OliviaDirWork (%dir_work%) por la ruta correspondiente en el disco duro
|
|
*/
|
|
private string pon_path_absoluto(string path, string DirWork)
|
|
{
|
|
if (string.IsNullOrEmpty(DirWork) || string.IsNullOrEmpty(path))
|
|
return path;
|
|
return path.Replace( nameDirWork, DirWork);
|
|
}
|
|
private string GetPathConfig()
|
|
{
|
|
RegistryKey rk, rkprg;
|
|
string strky, str;
|
|
|
|
//el path del archivo de configuración se obtiene del registro
|
|
strky = OlvRegKey;
|
|
rk = Registry.CurrentUser;
|
|
rkprg = rk.CreateSubKey(strky);
|
|
str = null;
|
|
if (rkprg.ValueCount > 0)
|
|
{
|
|
str = (String)rkprg.GetValue(OlvRegName);
|
|
if (!string.IsNullOrEmpty(str))
|
|
return str;
|
|
}
|
|
|
|
return pathConfigDef; //por defecto
|
|
}
|
|
private OliviaConf Default()
|
|
{
|
|
var c = new OliviaConf();
|
|
c.path_work = "C:\\Olivia\\";
|
|
try
|
|
{
|
|
var path = GetPathConfig();
|
|
if(!string.IsNullOrEmpty(path))
|
|
{
|
|
path = Path.Combine(path, OlvConfigName);
|
|
c.path_work = Path.GetDirectoryName(path) + "\\";
|
|
}
|
|
|
|
}
|
|
catch
|
|
{
|
|
c.path_work = "C:\\Olivia\\";
|
|
}
|
|
|
|
c.Version = VersionConfiguracion;
|
|
c.PathGdbGen = @"%dir_work%gdb\\BASE DE DATOS.gdb";
|
|
c.PathSimbVSM = @"%dir_work%styles\\Simbologia.style";
|
|
c.PathSimbESRI = @"%dir_work%styles\\ESRI.style";
|
|
c.PathCartela = @"%dir_work%data\\Plantilla.mxd";
|
|
|
|
c.consulta_sector = "SECTOR";
|
|
c.consulta_secuen = "SECUENCIA";
|
|
|
|
c.Igno_ais = true;
|
|
|
|
//c.red_carreteras = @"%dir_work%Datos\gdbs\TomTom_Q4_2015.gdb";
|
|
c.Puerto = 19995;
|
|
c.buffer_export = 1000;
|
|
|
|
c.path_exe=@"%dir_work%bin\OliviaTasks.exe";
|
|
c.path_manual= @"%dir_work%Manual_Olivia.pdf";
|
|
c.path_temp = @"%dir_work%temp\";
|
|
c.path_data=@"%dir_work%data\";
|
|
c.Path_Eje_via = "";
|
|
c.Path_Gdb_Import = "";
|
|
c.Path_Guarda_Csv = "";
|
|
c.Path_Dataset_Import = "";
|
|
c.path_cfg_aux = @"%dir_work%cfg.ini";
|
|
/*c.eje_via = "TomTom_Q4_2015___nw";
|
|
c.municipios = "TomTom_Q4_2015___a8";*/
|
|
|
|
c.cons_tip_ent= "NOM_TIPO_ENTIDAD";
|
|
c.cons_mecaniz= "MECANIZABLE";
|
|
c.cons_obser= "OBSERVACIONES";
|
|
c.cons_anch_tip= "ANCHO_TIPO";
|
|
c.cons_tipolo= "TIPOLOGIA";
|
|
|
|
c.atr_acera="Aceras";
|
|
c.atr_aparc="Banda Aparcamiento";
|
|
c.atr_bord="Bordillo Libre";
|
|
c.atr_hoja="Caida Hoja";
|
|
c.atr_peat="Peatonales";
|
|
c.atr_mec_s="Si";
|
|
c.atr_mec_n="No";
|
|
c.atr_esca="Escaleras";
|
|
c.atr_fuent="Fuentes";
|
|
c.atr_infan="JuegosInfantiles";
|
|
c.atr_pape="Papelera";
|
|
c.atr_paso_niv="Paso_Dist_Nivel";
|
|
c.atr_pipi="Pipican";
|
|
c.atr_sane="Sanecan";
|
|
c.atr_terri="Areas Terrizas";
|
|
c.atr_ocio="Ocio";
|
|
c.atr_org_ofi="Organismos_Oficiales";
|
|
c.atr_parq="Parques";
|
|
c.atr_park="Parquin";
|
|
c.atr_play="Playa";
|
|
c.atr_polid="Polideportivo";
|
|
c.atr_turis="Puntos_Interes_Turistico";
|
|
c.atr_solar="Solares";
|
|
c.atr_suelo="Uso_Suelos";
|
|
c.atr_ap_lin="Linea";
|
|
c.atr_ap_bat="Bateria";
|
|
|
|
c.ejes = "";
|
|
c.bord_libre_mec=@"NOM_TIPO_ENTIDAD = 'Bordillo Libre' AND MECANIZABLE = 'Si'";
|
|
c.bord_libre_no_mec= @"NOM_TIPO_ENTIDAD = 'Bordillo Libre' AND MECANIZABLE = 'No'";
|
|
c.bord_aparc= @"NOM_TIPO_ENTIDAD = 'Banda Aparcamiento'";
|
|
c.bord_acera_mec= @"NOM_TIPO_ENTIDAD = 'Aceras' AND MECANIZABLE = 'Si'";
|
|
c.bord_acera_no_mec= @"NOM_TIPO_ENTIDAD = 'Aceras' AND MECANIZABLE = 'No'";
|
|
c.calle_peat_mec= @"NOM_TIPO_ENTIDAD = 'Peatonales' AND MECANIZABLE = 'Si'";
|
|
c.calle_peat_no_mec= @"NOM_TIPO_ENTIDAD = 'Peatonales' AND MECANIZABLE = 'No'";
|
|
c.caida_hoja_mec= @"NOM_TIPO_ENTIDAD = 'Caida Hoja' AND MECANIZABLE = 'Si'";
|
|
c.caida_hoja_no_mec= @"NOM_TIPO_ENTIDAD = 'Caida Hoja' AND MECANIZABLE = 'No'";
|
|
c.contenedores = "";
|
|
c.pape= @"NOM_TIPO_ENTIDAD = 'Papelera'";
|
|
c.zon_inf= @"NOM_TIPO_ENTIDAD = 'JuegosInfantiles'";
|
|
c.pipican= @"NOM_TIPO_ENTIDAD = 'Pipican'";
|
|
c.sanecan= @"NOM_TIPO_ENTIDAD = 'Sanecan'";
|
|
|
|
|
|
c.t_tratamiento_max = 40000;
|
|
c.t_tratamiento_min=0;
|
|
c.v_desplaz_max=40000;
|
|
c.v_desplaz_min=0;
|
|
c.t_carga_desc_max=40000;
|
|
c.t_carga_desc_min=0;
|
|
c.t_desplaz_max=40000;
|
|
c.t_desplaz_min=0;
|
|
c.t_convenio_max=40000;
|
|
c.t_convenio_min=0;
|
|
c.t_descanso_max=40000;
|
|
c.t_descanso_min=0;
|
|
c.ancho_via_max=2000;
|
|
c.ancho_via_min=0;
|
|
|
|
c.t_convenio=480;
|
|
c.t_desplaz=25;
|
|
c.t_carga_desc=40;
|
|
c.t_descanso=30;
|
|
c.hora_inicio=420; //ES UNA HORA, SON LOS MINUTOS DESDE LAS 00, PERO TIENE QUE APARECER CON FORMATO DE TIME 07:30, POR EJEMPLO
|
|
c.reduc_traf = 80;
|
|
c.ancho_via=2;
|
|
c.t_tratamiento_BarMan=2900;
|
|
c.t_tratamiento_BarManMant=2900;
|
|
c.t_tratamiento_BarMMot=3500;
|
|
c.t_tratamiento_BarMC=4000;
|
|
c.t_tratamiento_BarMAP=4200;
|
|
c.t_tratamiento_BarMix=5600;
|
|
c.t_tratamiento_BalMan=4000;
|
|
c.t_tratamiento_BalMC=5000;
|
|
c.t_tratamiento_BalMAP=4200;
|
|
c.t_tratamiento_BalMix=5600;
|
|
c.t_tratamiento_BL=4000;
|
|
c.t_tratamiento_CH=5600;
|
|
c.t_tratamiento_VPap=1;
|
|
c.t_tratamiento_LPap=5;
|
|
c.t_tratamiento_LC=5;
|
|
c.t_tratamiento_LZI=30;
|
|
c.t_tratamiento_LPip=30;
|
|
c.t_tratamiento_LS=5;
|
|
c.v_desp_BarMan=5;
|
|
c.v_desp_BarManMant=5;
|
|
c.v_desp_BarMMot=25;
|
|
c.v_desp_BarMC=15;
|
|
c.v_desp_BarMAP=15;
|
|
c.v_desp_BarMix=15;
|
|
c.v_desp_BalMan=15;
|
|
c.v_desp_BalMC=0;
|
|
c.v_desp_BalMAP=15;
|
|
c.v_desp_BalMix=15;
|
|
c.v_desp_BL=5;
|
|
c.v_desp_CH=15;
|
|
//son 0 porque van según la velocidad de la vía
|
|
c.v_desp_VPap=0;
|
|
c.v_desp_LPap=0;
|
|
c.v_desp_LC=0;
|
|
c.v_desp_LZI=0;
|
|
c.v_desp_LPip=0;
|
|
c.v_desp_LS=0;
|
|
|
|
//Reco
|
|
c.id= "_ID";
|
|
c.nomrec= "NOMB_TIP_REC";
|
|
c.lateralidad= "LATERALIDAD";
|
|
c.frac= "FRACCION";
|
|
c.capac= "CAPACIDAD";
|
|
c.uds= "UNIDADES";
|
|
c.kgrec= "Kg_Recog";
|
|
c.kgrec_val=200;
|
|
c.is_lleno=false;
|
|
c.is_campo=false;
|
|
|
|
//AtriReco
|
|
c.organica= "Organica";
|
|
c.resto= "Resto";
|
|
c.envase= "Envases";
|
|
c.papel= "PapelCarton";
|
|
c.vidrio= "Vidrio";
|
|
c.trasera= "Carga Trasera";
|
|
c.lateral= "Carga Lateral";
|
|
c.superior= "Carga Superior";
|
|
c.bilat= "Carga Bilateral";
|
|
c.bolseo= "Bolseo";
|
|
c.lavado= "Lavado de cont";
|
|
|
|
//lateral---
|
|
c.ambos= "Ambos";
|
|
c.derecha= "Derecha";
|
|
c.izquierda="Izquierda";
|
|
|
|
//RecoParam
|
|
c.t_vaciado_max=40000;
|
|
c.t_vaciado_min=0;
|
|
c.t_llega_sale_max=40000;
|
|
c.t_llega_sale_min=0;
|
|
c.t_descarga_max=40000;
|
|
c.t_descarga_min=0;
|
|
c.R_t_convenio_max = 40000;
|
|
c.R_t_convenio_min = 0;
|
|
c.R_t_descanso_max = 40000;
|
|
c.R_t_descanso_min = 0;
|
|
c.t_llega_sale=5;
|
|
c.t_descarga=40;
|
|
c.dens_vehi_org=500;
|
|
c.dens_vehi_res=500;
|
|
c.dens_vehi_env=120;
|
|
c.dens_vehi_pap=250;
|
|
c.dens_vehi_vid=350;
|
|
c.dens_vehi_otr=100;
|
|
c.dens_cont_org=150;
|
|
c.dens_cont_res=100;
|
|
c.dens_cont_env=28;
|
|
c.dens_cont_pap=90;
|
|
c.dens_cont_vid=250;
|
|
c.dens_cont_otr=100;
|
|
c.anch_vehi_3=2.4000000;
|
|
c.anch_vehi_2=2.2000000;
|
|
c.anch_vehi_s=2.0000000;
|
|
c.radio_giro_3=175.0000000;
|
|
c.radio_giro_2=175.0000000;
|
|
c.radio_giro_s=175.0000000;
|
|
c.t_vaci_trasera=30;
|
|
c.t_vaci_lateral=90;
|
|
c.t_vaci_superior=180;
|
|
c.t_vaci_bilateral=100;
|
|
c.t_vaci_bolseo=5*60;
|
|
c.t_vaci_lavado=60;
|
|
c.t_vaci_otra=60;
|
|
c.kgmax_max=20000;
|
|
c.kgmax_min=0;
|
|
c.carga_max_max=100;
|
|
c.carga_max_min=50;
|
|
//Campos NW
|
|
c.cons_onew="ONEWAY";
|
|
c.cons_kph="KPH";
|
|
c.cons_fow="FOW";
|
|
c.cons_name="NAME";
|
|
c.atr_TF="TF";
|
|
c.atr_FT="FT";
|
|
c.atr_N = "N";
|
|
c.atr_pedes="14";
|
|
|
|
c.Ancho_peat_def = 6.0000000;
|
|
c.Ancho_acera_def = 1.5000000;
|
|
c.Ancho_ap_lin_def = 2.0000000;
|
|
c.Ancho_ap_bat_def = 4.0000000;
|
|
c.Ancho_bord_lib_def = 1.5000000;
|
|
c.Giro_max_vehiculo = 175.0000000;
|
|
c.Desv_max = 0.1500000;
|
|
c.Desv_max_abs = 1800.0000000;
|
|
c.Tipo_eje_via = OpsNW.nw_0;
|
|
c.ListaNw = new List<OliviaConfNW>();
|
|
c.ListaNw.Add(new OliviaConfNW()
|
|
{
|
|
nombre = "TomTom",
|
|
campo_velocidad = "$feature.KPH",
|
|
campo_nombre = "$feature.NAME",
|
|
campo_peatonal = "IIf( $feature.FOW == 14 || $feature.FOW == 15 || $feature.FOW == 19 || $feature.ONEWAY == 'N', 1, 0)",
|
|
campo_sentidoFT = "IIF($feature.ONEWAY== 'TF' || $feature.ONEWAY == 'N', 0 , 1)",
|
|
campo_sentidoTf = "IIF($feature.ONEWAY == 'FT' || $feature.ONEWAY == 'N', 0, 1)",
|
|
campo_elevacion_from = "$feature.F_ELEV",
|
|
campo_elevacion_to = "$feature.T_ELEV",
|
|
comprueba_elevacion = true,
|
|
revisa_topologia = false,
|
|
revisa_conjunciones = false,
|
|
revisa_angulos = false,
|
|
campo_angulos = "0"
|
|
}); ;
|
|
/*
|
|
c.ListaNw.Add(new OliviaConfNW()
|
|
{
|
|
nombre = "StreetMapPremiun",
|
|
campo_velocidad = "max($feature.FT_RST_SPE, $feature.TF_RST_SPE)",
|
|
campo_nombre = "$feature.FULL_STREE",
|
|
campo_peatonal = "IIF( $feature.FT_RST_AUT == 'Y' && $feature.TF_RST_AUT == 'Y', 1, 0)",
|
|
campo_sentidoFT = "IIf( $feature.FT_RST_AUT == 'N', 1, 0)",
|
|
campo_sentidoTf = "IIf( $feature.TF_RST_AUT == 'N', 1, 0)",
|
|
campo_elevacion_from = "IIf( $feature.F_ZLEV != null, $feature.F_ZLEV, 0)",
|
|
campo_elevacion_to = "IIf( $feature.T_ZLEV != null, $feature.T_ZLEV, 0)",
|
|
comprueba_elevacion = false,
|
|
revisa_topologia = false,
|
|
revisa_conjunciones = true,
|
|
revisa_angulos = true,
|
|
campo_angulos = "IIF($feature.ROAD_CLASS== '3 - Highway Ramp' || $feature.ROAD_CLASS== '6 - Major Road' || $feature.ROAD_CLASS == '1 - Surface Street', 90 , 0)"
|
|
});
|
|
*/
|
|
c.ListaMV = new List<OliviaConfMV>();
|
|
c.ListaMV.Add(new OliviaConfMV()
|
|
{
|
|
nombre = "Default",
|
|
filtro_omitir = "",
|
|
campo_prioridad = "0",
|
|
vehiculo_def_reco = -1,
|
|
vehiculo_def_lim = -1
|
|
}) ;
|
|
c.ListaMV.Add(new OliviaConfMV()
|
|
{
|
|
nombre = "Peaton",
|
|
filtro_omitir = "(FREEWAY <> 1 AND SLIPRD = 0)",
|
|
campo_prioridad = "0",
|
|
vehiculo_def_reco = -1,
|
|
vehiculo_def_lim = 0
|
|
|
|
});
|
|
c.ListaMV.Add(new OliviaConfMV()
|
|
{
|
|
nombre = "Vehiculo pequeño",
|
|
filtro_omitir = "(FREEWAY <> 1 AND SLIPRD = 0)",
|
|
campo_prioridad = "IIF($feature.PRIVATERD==2 || $feature.RDCOND==2 || ($feature.FOW>13 && $feature.FOW<16) , -2 , 0)",
|
|
vehiculo_def_reco = 2,
|
|
vehiculo_def_lim = 1
|
|
|
|
});
|
|
c.ListaMV.Add(new OliviaConfMV()
|
|
{
|
|
nombre = "Vehiculo mediano",
|
|
filtro_omitir = "(RDCOND <> 2 AND ONEWAY = 'N' AND FOW NOT IN (14, 15, 19))",
|
|
campo_prioridad = "IIF($feature.PRIVATERD==2 || $feature.RDCOND==3 , -2 , 0)",
|
|
vehiculo_def_reco = 1,
|
|
vehiculo_def_lim = -1
|
|
|
|
});
|
|
c.ListaMV.Add(new OliviaConfMV()
|
|
{
|
|
nombre = "Vehiculo grande",
|
|
filtro_omitir = "(RDCOND NOT IN (2, 3) AND ONEWAY = 'N' AND FOW NOT IN (14, 15, 19))",
|
|
campo_prioridad = "IIF($feature.PRIVATERD==2 , -2 , 0)",
|
|
vehiculo_def_reco =0,
|
|
vehiculo_def_lim = -1
|
|
|
|
});
|
|
return c;
|
|
}
|
|
}
|
|
}
|