public void addZone(string v_idZone, Zone v_Zone) { Dictionary<string, Zone> listaZonas = LoadZonas(); if (listaZonas.ContainsKey(v_idZone)) { listaZonas.Remove(v_idZone); } listaZonas.Add(v_idZone, v_Zone); SaveZonas(listaZonas); }
/// <summary> /// Algoritmo de Ray Casting para saber si un punto esta o no dentro de un poligono (Convexo o Concavo!!) /// Devuelve la cantidad de intersecciones que un rayo horizontal le hace al poligono. /// </summary> /// <param name="v_zona"></param> /// <param name="v_punto"></param> /// <returns></returns> public int RayCast(Zone v_zona, Punto v_punto) { int cantIntersecciones = 0; Punto puntoLejano = new Punto(-100.0f, v_punto.Y); // Punto horizontal lejano... foreach (KeyValuePair<string, Zone.GateDefinition> gate in v_zona.listaPuertas) { Punto C = new Punto(float.Parse(gate.Value.from.position.latitude, CultureInfo.InvariantCulture.NumberFormat), float.Parse(gate.Value.from.position.longitude, CultureInfo.InvariantCulture.NumberFormat)); Punto D = new Punto(float.Parse(gate.Value.to.position.latitude, CultureInfo.InvariantCulture.NumberFormat), float.Parse(gate.Value.to.position.longitude, CultureInfo.InvariantCulture.NumberFormat)); if (intersecta(puntoLejano, v_punto, C, D)) { cantIntersecciones++; } } return cantIntersecciones; }
public void addZone(string v_idZone, Zone v_Zone) { listaZonas.Add(v_idZone, v_Zone); }
public Dictionary<string, Zone> LoadZonasFromFeatures(Dictionary<int, string> listaIDFeatures) { // La lista desde cero.. Dictionary<string, Zone> resList = new Dictionary<string, Zone>(); foreach (KeyValuePair<int, string> Pair in listaIDFeatures) { string nombreZona = Pair.Value; int idFeature = Pair.Key; // Crea la nueva zona. Zone nuevaZona = new Zone(nombreZona); // Recorre la base para agregarle Gates... SqlConnection cnn = new SqlConnection(conexion); try { cnn.Open(); SqlCommand cmd = cnn.CreateCommand(); cmd.CommandText = "Select * from gates where idFeature =" + idFeature.ToString(); cmd.CommandType = CommandType.Text; SqlDataReader lector = cmd.ExecuteReader(); while (lector.Read()) { string NombreGate = lector["Nombre"].ToString(); Zone.ZonePoint PuntoFrom = ConstruirZonePoint(int.Parse(lector["Punto1"].ToString()), idFeature); Zone.ZonePoint PuntoTo = ConstruirZonePoint(int.Parse(lector["Punto2"].ToString()), idFeature); int LNLPanelID=-1; int LNLReaderID=-1; if (!string.IsNullOrEmpty(lector["LNLPanelID"].ToString())) { LNLPanelID = int.Parse(lector["LNLPanelID"].ToString()); } if (!string.IsNullOrEmpty(lector["LNLReaderID"].ToString())) { LNLReaderID = int.Parse(lector["LNLReaderID"].ToString()); } if ((LNLPanelID > 0) && (LNLReaderID > 0)) { GateAccessType tipoAcceso; try { tipoAcceso = (GateAccessType)Enum.Parse(typeof(GateAccessType), lector["Acceso"].ToString()); } catch (Exception ) { tipoAcceso = GateAccessType.Forbidden; } // Crea la nueva Gate Zone.GateDefinition nuevaGate = new Zone.GateDefinition(); nuevaGate.ID = NombreGate; nuevaGate.from = PuntoFrom; nuevaGate.to = PuntoTo; nuevaGate.type = tipoAcceso; nuevaGate.LNLReaderID = LNLReaderID; nuevaGate.LNLPanelID = LNLPanelID; // Agrega la gate a la Zona. nuevaZona.addGate(NombreGate, nuevaGate); } } lector.Close(); cnn.Close(); } catch (Exception ex) { loguearString("ERROR en obtenerListaFeatures: " + ex.Message, TiposLOG.ALL); } finally { cnn.Close(); } // Da de alta la zona con sus gates en el diccionario de zonas. resList.Add(nombreZona, nuevaZona); } return resList; }
private void btnCrearZona_Click(object sender, EventArgs e) { string nombreZona = Microsoft.VisualBasic.Interaction.InputBox("Nombre de la zona: ", "Crear nueva zona", "", 100, 100); if (nombreZona != "") { Zone nuevaZona = new Zone(nombreZona); Zone.GateDefinition nuevaGate = new Zone.GateDefinition(); ; nuevaZona.listaPuertas = new Dictionary<string,Zone.GateDefinition>(); string firstLat = ""; string firstLong = ""; string firstID =""; bool primerPunto = true; foreach (KeyValuePair<string, Zone.GeoCoord> pair in markerPoints) { if (primerPunto) { nuevaGate.from = new Zone.ZonePoint("Desde", pair.Value.latitude, pair.Value.longitude); nuevaGate.type = GateAccessType.Forbidden; //nuevaGate.ID = pair.Key; firstLat = pair.Value.latitude; firstLong = pair.Value.longitude; firstID = pair.Key; primerPunto=false; } else { nuevaGate.to = new Zone.ZonePoint("Hacia", pair.Value.latitude, pair.Value.longitude); nuevaGate.ID = nombreZona + "- Gate " + (nuevaZona.listaPuertas.Count+1).ToString(); nuevaZona.listaPuertas.Add(nuevaGate.ID,nuevaGate); nuevaGate = new Zone.GateDefinition(); nuevaGate.from = new Zone.ZonePoint("Desde", pair.Value.latitude, pair.Value.longitude); nuevaGate.type = GateAccessType.Forbidden; nuevaGate.ID = pair.Key; } } // La ultima puerta se genera entre el ultimo punto y el primero. nuevaGate.to = nuevaGate.to = new Zone.ZonePoint("Hacia", firstLat,firstLong); nuevaGate.ID = nombreZona + "- Gate " + (nuevaZona.listaPuertas.Count+1).ToString(); nuevaZona.listaPuertas.Add(nuevaGate.ID,nuevaGate); mainApp.DataManager.addZone(nombreZona, nuevaZona); actualizarZonasEnMapa(mainApp.DataManager.getListaZonas()); actualizarListViewZones(); actualizarListViewGates(nombreZona); deleteAllMarkers(); actualZone = nombreZona; flagAddmarker = true; btnAddPoint_Click(null, null); } }