private void tbAfficher_Click(object sender, RoutedEventArgs e) { ICartoObj o = (ICartoObj)ListBox.SelectedItem; if (o == null) { MessageBox.Show("Aucun élément de la ListBox est sélectionné", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } else { Carte.Children.Clear(); if (o is POI) { POI p = o as POI; afficherPOI(p); } if (o is Polyline) { Polyline p = o as Polyline; afficherTrajet(p); } //if (o is Polygon) //{ // Polygon p = o as Polygon; //} } }
private void tbDetails_Click(object sender, RoutedEventArgs e) { ICartoObj o = (ICartoObj)ListBox.SelectedItem; string titreFenetre = "", messageFenetre = ""; if (o == null) { MessageBox.Show("Aucun élément de la ListBox est sélectionné", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } else { if (o is POI) { POI p = o as POI; titreFenetre = "Caractéristiques détaillées du POI sélectionné"; messageFenetre = p.Draw(); } if (o is Polyline) { Polyline p = o as Polyline; titreFenetre = "Caractéristiques détaillées du trajet (Polyline) sélectionné"; messageFenetre = p.Draw(); } if (o is Polygon) { Polygon p = o as Polygon; titreFenetre = "Caractéristiques détaillées de la surface (Polygon) sélectionné"; messageFenetre = p.Draw(); } MessageBox.Show(messageFenetre, titreFenetre, MessageBoxButton.OK, MessageBoxImage.Information); } }
private void AjouterPushPin(ICartoObj carto) { Pushpin pin = new Pushpin(); pin.Location = new Location(carto.lCoord[0].X, carto.lCoord[0].Y); myMap.Children.Add(pin); }
private void Traject_Export_Click(object sender, RoutedEventArgs e) { if (myPersonalMapData.ObservableCollection.Count != 0) { ICartoObj i = myPersonalMapData.ObservableCollection[ListBox.SelectedIndex]; if (i is Polyline) { Polyline polyline = i as Polyline; string filename = polyline.Description + ".csv"; Stream fStream = new FileStream(myPersonalMapData.Path + "\\" + filename, FileMode.Create, FileAccess.Write, FileShare.None); fStream.Close(); List <string> text = new List <string> { }; foreach (Coordonnees coords in polyline.Collection) { if (coords is POI) { text.Add(coords.Latitude.ToString() + ";" + coords.Longitude.ToString() + ";" + ((POI)coords).Description); } else if (coords is Coordonnees) { text.Add(coords.Latitude.ToString() + ";" + coords.Longitude.ToString()); } } File.WriteAllLines(myPersonalMapData.Path + "\\" + filename, text); ListBox.SelectedIndex = 0; } } }
public UpdateWindow(ICartoObj receivedObj) { InitializeComponent(); TblkType.Text = receivedObj.GetType().Name + " #" + ((CartoObj)receivedObj).Id; TbDescription.Text = receivedObj.Description; switch (receivedObj.GetType().Name) { case "POI": POI receivedPOI = (POI)receivedObj; SaveReceivedObj = new POI(receivedPOI); SaveReceivedObj.Tag = receivedPOI.Tag; ReceivedObj = receivedPOI; CpStroke.IsEnabled = false; TbLatitude.Text = receivedPOI.Latitude.ToString(); TbLongitude.Text = receivedPOI.Longitude.ToString(); CpStroke.Background = Brushes.Gray; CpFill.SelectedColor = receivedPOI.Fill; break; case "Polyline": MyCartographyObjects.Polyline receivedPolyline = (MyCartographyObjects.Polyline)receivedObj; SaveReceivedObj = new MyCartographyObjects.Polyline(receivedPolyline); SaveReceivedObj.Tag = receivedPolyline.Tag; ReceivedObj = receivedPolyline; CpFill.IsEnabled = false; TbLatitude.IsEnabled = false; CpFill.IsEnabled = false; TbLatitude.Background = Brushes.Gray; TbLongitude.Background = Brushes.Gray; CpFill.Background = Brushes.Gray; CpStroke.SelectedColor = receivedPolyline.Stroke; break; case "Polygon": MyCartographyObjects.Polygon receivedPolygon = (MyCartographyObjects.Polygon)receivedObj; SaveReceivedObj = new MyCartographyObjects.Polygon(receivedPolygon); SaveReceivedObj.Tag = receivedPolygon.Tag; ReceivedObj = receivedPolygon; TbLatitude.IsEnabled = false; TbLongitude.IsEnabled = false; TbLatitude.Background = Brushes.Gray; TbLongitude.Background = Brushes.Gray; CpFill.SelectedColor = receivedPolygon.Fill; CpStroke.SelectedColor = receivedPolygon.Stroke; break; } }
private void AjouterPolyline(ICartoObj carto) { MapPolyline poly = new MapPolyline(); poly.Locations = new LocationCollection(); foreach (ICoord coord in carto.lCoord) { poly.Locations.Add(new Location(coord.X, coord.Y)); } ProjectLibraryClass.Polyline polTmp = carto as ProjectLibraryClass.Polyline; poly.StrokeThickness = polTmp.Epaisseur; poly.Stroke = ToBrush(polTmp.Couleur); poly.Opacity = polTmp.Opacite; myMap.Children.Add(poly); }
//Supprimer un item private void DeleteItem(Location pinLocation) { for (int i = 0; i < User.Liste.Count(); i++) { if (User.Liste[i] is IIsPointClose) { IIsPointClose coo = User.Liste[i] as IIsPointClose; if (coo.IsPointClose(pinLocation, 0.5)) { ICartoObj cooTmp = coo as ICartoObj; User.Liste.Remove(cooTmp); map.Children.RemoveAt(i); StatBar.Text = "Item deleted"; //Affichage dans la StatusBar } } } }
private void POI_Export_Click(object sender, RoutedEventArgs e) { if (myPersonalMapData.ObservableCollection.Count != 0) { ICartoObj i = myPersonalMapData.ObservableCollection[ListBox.SelectedIndex]; if (i is POI) { POI poi = i as POI; string filename = poi.Description + ".csv"; Stream fStream = new FileStream(myPersonalMapData.Path + "\\" + filename, FileMode.Create, FileAccess.Write, FileShare.None); fStream.Close(); string text = poi.Latitude.ToString() + ";" + poi.Longitude.ToString() + ";" + poi.Description; File.WriteAllText(myPersonalMapData.Path + "\\" + filename, text); ListBox.SelectedIndex = 0; } } }
private void MenuFileTrajetExport_Click(object sender, RoutedEventArgs e) { bool erreurExport = false; ICartoObj o = (ICartoObj)ListBox.SelectedItem; if (o == null) { MessageBox.Show("Aucun élément de la ListBox est sélectionné", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } else { if (o is Polyline) { Polyline p = o as Polyline; SaveFileDialog saveFile = new SaveFileDialog(); saveFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); saveFile.Filter = "Fichier CSV files(*.csv) | *.csv"; saveFile.ShowDialog(); try { MyPersonalMapData.saveCSVtrajet(p, saveFile.FileName); } catch (CSVexception messageErreurSaveTrajet) { MessageBox.Show(messageErreurSaveTrajet.Message, "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); erreurExport = true; } if (!erreurExport) { MessageBox.Show("Exportation réussie", "", MessageBoxButton.OK, MessageBoxImage.Information); } } else { MessageBox.Show("L'élément sélectionné n'est pas un trajet (polyline)", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public WindowExport(ICartoObj carto) { index = -1; type = new ObservableCollection <ICartoObj>(); MyApp = new Excel.Application(); MyApp.Visible = false; InitializeComponent(); if (carto is POI) { foreach (ICartoObj p in MainWindow.mP.CartoCollection) { if (p is POI) { type.Add(p); } } tbVeuillezSelectionner.Text = "Veuillez selectionner un POI"; } else { foreach (ICartoObj c in MainWindow.mP.CartoCollection) { if (!(c is POI)) { type.Add(c); } } if (carto is ProjectLibraryClass.Polyline) { tbVeuillezSelectionner.Text = "Veuillez sélectionner un Polyline"; } else { tbVeuillezSelectionner.Text = "Veuillez sélectionner un Polygon"; } } lbCartoObjExport.ItemsSource = type; }
private void Modifier_Click(object sender, RoutedEventArgs e) { if (myPersonalMapData.ObservableCollection.Count == 0) { return; } int position = ListBox.SelectedIndex; ICartoObj i = myPersonalMapData.ObservableCollection.ElementAt(position); if (i is POI) { POI p = i as POI; PoiWindow poiWindow = new PoiWindow(p); poiWindow.ShowDialog(); myPersonalMapData.ObservableCollection[position] = poiWindow.Poi; ListBox.SelectedIndex = position; poiWindow.Close(); } if (i is Polyline) { Polyline p = i as Polyline; PolylineWindow polylineWindow = new PolylineWindow(p); polylineWindow.ShowDialog(); myPersonalMapData.ObservableCollection[position] = polylineWindow.Polyline; ListBox.SelectedIndex = position; polylineWindow.Close(); } if (i is Polygon) { Polygon p = i as Polygon; PolygonWindow polygonWindow = new PolygonWindow(p); polygonWindow.ShowDialog(); myPersonalMapData.ObservableCollection[position] = polygonWindow.Polygon; ListBox.SelectedIndex = position; polygonWindow.Close(); } UpdateMainWindow(); }
private void GetCoordonneesAndLocationNearClick(Location clickLocation, ref Coordonnees newCoordonnee, ref Location newLocation) { bool stop = false; Coordonnees clickCoordonnees = new Coordonnees(clickLocation.Latitude, clickLocation.Longitude); for (int i = MapData.ICartoObjs.Count() - 1; i >= 0 && !stop; i--) // Reverse loop because the last element is the first showed on screen { ICartoObj iCartoObj = MapData.ICartoObjs[i]; if (iCartoObj is POI poi) // POI (Pushpin) { if (poi.IsPointClose(clickCoordonnees, _PRECISION)) { newCoordonnee.Latitude = poi.Latitude; newCoordonnee.Longitude = poi.Longitude; newLocation.Latitude = poi.Latitude; newLocation.Longitude = poi.Longitude; stop = true; } } else // Polyline or Polygon (Coords of the element) { IPointy iPointy = iCartoObj as IPointy; for (int j = iPointy.Coordonnees.Count() - 1; j >= 0 && !stop; j--) // Reverse loop because the last element is the first showed on screen { Coordonnees currentCoord = iPointy.Coordonnees[j]; if (currentCoord.IsPointClose(clickCoordonnees, _PRECISION)) { newCoordonnee.Latitude = currentCoord.Latitude; newCoordonnee.Longitude = currentCoord.Longitude; newLocation.Latitude = currentCoord.Latitude; newLocation.Longitude = currentCoord.Longitude; stop = true; } } } } }
/// Méthode ajoutant un objet ajoutant un objet dans la collection, objet qui implémente l'interface ICartoObj public void AddCartObj(ICartoObj cartObj) { Console.WriteLine(cartObj.ToString()); cartoCollection.Add(cartObj); Console.WriteLine("Test : " + cartoCollection.Last().ToString()); }
private void Map_DoubleClick(object sender, MouseEventArgs e) { Console.WriteLine("Double click!"); Point mousePosition = e.GetPosition(Map); Location mouseLocation = Map.ViewportPointToLocation(mousePosition); bool pinPresent = false; //Tester si on click sur une pin for (int i = 0; i < myPersonalMapData.ObservableCollection.Count; i++) { ICartoObj obj = myPersonalMapData.ObservableCollection[i]; if (obj is POI) { Coordonnees coords = new Coordonnees(((POI)obj).Latitude, ((POI)obj).Longitude); if (coords.IsPointClose(new Coordonnees(mouseLocation.Latitude, mouseLocation.Longitude), 0.001)) { Console.WriteLine("trouve: des = {0}", ((POI)obj).Description); PoiWindow poiWindow = new PoiWindow((POI)obj); poiWindow.ShowDialog(); myPersonalMapData.ObservableCollection[i] = poiWindow.Poi; poiWindow.Close(); pinPresent = true; break; } } if (obj is Polyline) { foreach (ICartoObj cartoObj in ((Polyline)obj).Collection) { if (((Coordonnees)cartoObj).IsPointClose(new Coordonnees(mouseLocation.Latitude, mouseLocation.Longitude), 0.001)) { ListBox.SelectedItem = ((Polyline)obj).Description; PolylineWindow polylineWindow = new PolylineWindow((Polyline)obj); polylineWindow.ShowDialog(); myPersonalMapData.ObservableCollection[ListBox.SelectedIndex] = polylineWindow.Polyline; polylineWindow.Close(); pinPresent = true; break; } } } e.Handled = true; } if (!pinPresent) { //Créé une pin ou trajet POI poi = new POI("", new Coordonnees(mouseLocation.Latitude, mouseLocation.Longitude)); PoiWindow poiWindow = new PoiWindow(); poiWindow.Latitude = poi.Latitude.ToString(); poiWindow.Longitude = poi.Longitude.ToString(); poiWindow.Description = ""; poiWindow.ShowDialog(); if (poiWindow.Poi != null) { myPersonalMapData.ObservableCollection.Add(poiWindow.Poi); } poiWindow.Close(); } UpdateMainWindow(); }
public void Add(ICartoObj iCartoObj) { ICartoObjs.Add(iCartoObj); }
public void Remove(ICartoObj iCartoObj) { ICartoObjs.Remove(iCartoObj); }
private void MyMap_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { Point mouseLeftButtonUpPosition = new Point(e.GetPosition(MyMap).X, e.GetPosition(MyMap).Y); if (mouseLeftButtonUpPosition == MouseLeftButtonDownPoisition) // OnClick { switch (EditMode) { case EditModes.Select: bool elementSelected = false; for (int i = MapData.ICartoObjs.Count() - 1; i >= 0; i--) // Reverse loop because the last element is the first showed on screen { Point clickPoint = e.GetPosition(MyMap); MyMap.TryViewportPointToLocation(clickPoint, out Location clickLocation); Coordonnees clickCoordonnees = new Coordonnees(clickLocation.Latitude, clickLocation.Longitude); CartoObj cartoObj = MapData.ICartoObjs[i] as CartoObj; if (cartoObj.IsPointClose(clickCoordonnees, _PRECISION)) { elementSelected = true; LbCartographyObjects.SelectedItem = MapData.ICartoObjs[i]; LbCartographyObjects.ScrollIntoView(MapData.ICartoObjs[i]); break; } } if (!elementSelected) { LbCartographyObjects.SelectedItem = null; } break; case EditModes.Add: Location ClickLocation; MyMap.TryViewportPointToLocation(e.GetPosition(MyMap), out ClickLocation); switch (CbType.SelectedIndex) { case 0: // Point of interest AddPushpin(ClickLocation); break; case 1: // Travel AddPointToTravel(ClickLocation); break; case 2: // Surface AddPointToSurface(ClickLocation); break; } UpdateLbCartographyObjectsItemsSource(); break; case EditModes.Remove: bool somethingToRemove = false; ICartoObj toRemove = new POI(); // Default value for (int i = MapData.ICartoObjs.Count() - 1; i >= 0; i--) // Reverse loop because the last element is the first showed on screen { ICartoObj iCartoObj = MapData.ICartoObjs[i]; Point clickPoint = e.GetPosition(MyMap); MyMap.TryViewportPointToLocation(clickPoint, out Location clickLocation); Coordonnees clickCoordonnees = new Coordonnees(clickLocation.Latitude, clickLocation.Longitude); CartoObj cartoObj = iCartoObj as CartoObj; if (cartoObj.IsPointClose(clickCoordonnees, _PRECISION)) { somethingToRemove = true; toRemove = iCartoObj; UIElement uiElement = (UIElement)(iCartoObj.Tag); MyMap.Children.Remove(uiElement); UpdateLbCartographyObjectsItemsSource(); break; } } if (somethingToRemove) { MapData.Remove(toRemove); } break; case EditModes.Update: bool somethingToUpdate = false; ICartoObj toUpdate = new POI(); // Default value for (int i = MapData.ICartoObjs.Count() - 1; i >= 0; i--) // Reverse loop because the last element is the first showed on screen { ICartoObj iCartoObj = MapData.ICartoObjs[i]; Point clickPoint = e.GetPosition(MyMap); MyMap.TryViewportPointToLocation(clickPoint, out Location clickLocation); Coordonnees clickCoordonnees = new Coordonnees(clickLocation.Latitude, clickLocation.Longitude); CartoObj cartoObj = iCartoObj as CartoObj; if (cartoObj.IsPointClose(clickCoordonnees, _PRECISION)) { somethingToUpdate = true; toUpdate = iCartoObj; break; } } if (somethingToUpdate) { UpdateWindow updateWindow = new UpdateWindow(toUpdate); updateWindow.send = UpdateMapAndListBox; updateWindow.Show(); } UpdateLbCartographyObjectsItemsSource(); break; } } else // OnDrag // Nothing { } }
private void tbModifier_Click(object sender, RoutedEventArgs e) { bool modificationOK = false; ICartoObj o = (ICartoObj)ListBox.SelectedItem; if (o == null) { modificationOK = true; MessageBox.Show("Aucun élément de la ListBox est sélectionné", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } else { Carte.Children.Clear(); if (o is POI) { POI p = o as POI; fenetrePOI fenetrePOI = new fenetrePOI(p); fenetrePOI.Owner = this; fenetrePOI.ShowDialog(); if (fenetrePOI.NewPOI != null) { foreach (ICartoObj oInCollection in PersonneConnectee.ObservableCollection) { if (oInCollection is POI) { POI poiInCollection = oInCollection as POI; if (poiInCollection.Id == p.Id) { if (PersonneConnectee.ObservableCollection.Remove(poiInCollection)) { POI newPOI = new POI(); newPOI.Id = p.Id; newPOI.Latitude = fenetrePOI.NewPOI.Latitude; newPOI.Longitude = fenetrePOI.NewPOI.Longitude; newPOI.Description = fenetrePOI.NewPOI.Description; Console.WriteLine("DEBUG newPoi to string : " + newPOI.Draw()); PersonneConnectee.ObservableCollection.Add(newPOI); modificationOK = true; } break; } } } } else { modificationOK = true; } } if (o is Polyline) { Polyline p = o as Polyline; Console.WriteLine("DEBUG polyline dans modifier fenetre principale:\n" + p.Draw()); FenetrePolyline fenetrePolyline = new FenetrePolyline(p); fenetrePolyline.Owner = this; fenetrePolyline.ShowDialog(); if (fenetrePolyline.NewPolyline != null) { foreach (ICartoObj oInCollection in PersonneConnectee.ObservableCollection) { if (oInCollection is Polyline) { Polyline polylineInCollection = oInCollection as Polyline; if (polylineInCollection.Id == p.Id) { if (PersonneConnectee.ObservableCollection.Remove(polylineInCollection)) { Polyline newPolyline = new Polyline(); newPolyline.Id = p.Id; newPolyline.Epaisseur = fenetrePolyline.NewPolyline.Epaisseur; newPolyline.Couleur = fenetrePolyline.NewPolyline.Couleur; newPolyline.NomTrajet = fenetrePolyline.NewPolyline.NomTrajet; newPolyline.CollectionDeCoordonnes = new List <Coordonnees>(fenetrePolyline.NewPolyline.CollectionDeCoordonnes); PersonneConnectee.ObservableCollection.Add(newPolyline); modificationOK = true; } break; } } } } else { modificationOK = true; } } //} //if (o is Polygon) //{ // Polygon p = o as Polygon; // foreach (ICartoObj oInCollection in PersonneConnectee.ObservableCollection) // { // if (oInCollection is Polygon) // { // Polygon polygonInCollection = oInCollection as Polygon; // if (polygonInCollection.Id == p.Id) // { // if (PersonneConnectee.ObservableCollection.Remove(polygonInCollection)) // { // MessageBox.Show("Suppression du polyline OK", "", MessageBoxButton.OK, MessageBoxImage.Information); // suppressionOK = true; // } // break; // } // } // } //} UpdateListBox(); } if (!modificationOK) { MessageBox.Show("La modification à échouée", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void DeleteSelectItem_Click(object sender, RoutedEventArgs e) { bool suppressionOK = false; ICartoObj o = (ICartoObj)ListBox.SelectedItem; if (o == null) { suppressionOK = true; MessageBox.Show("Aucun élément de la ListBox est sélectionné", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } else { Carte.Children.Clear(); if (o is POI) { POI p = o as POI; foreach (ICartoObj oInCollection in PersonneConnectee.ObservableCollection) { if (oInCollection is POI) { POI poiInCollection = oInCollection as POI; if (poiInCollection.Id == p.Id) { if (PersonneConnectee.ObservableCollection.Remove(poiInCollection)) { MessageBox.Show("Suppression du POI OK", "", MessageBoxButton.OK, MessageBoxImage.Information); suppressionOK = true; } break; } } } } if (o is Polyline) { Polyline p = o as Polyline; foreach (ICartoObj oInCollection in PersonneConnectee.ObservableCollection) { if (oInCollection is Polyline) { Polyline polylineInCollection = oInCollection as Polyline; if (polylineInCollection.Id == p.Id) { if (PersonneConnectee.ObservableCollection.Remove(polylineInCollection)) { MessageBox.Show("Suppression du polyline OK", "", MessageBoxButton.OK, MessageBoxImage.Information); suppressionOK = true; } break; } } } } if (o is Polygon) { Polygon p = o as Polygon; foreach (ICartoObj oInCollection in PersonneConnectee.ObservableCollection) { if (oInCollection is Polygon) { Polygon polygonInCollection = oInCollection as Polygon; if (polygonInCollection.Id == p.Id) { if (PersonneConnectee.ObservableCollection.Remove(polygonInCollection)) { MessageBox.Show("Suppression du polyline OK", "", MessageBoxButton.OK, MessageBoxImage.Information); suppressionOK = true; } break; } } } } UpdateListBox(); } if (!suppressionOK) { MessageBox.Show("La suppresion à échouée", "ERREUR", MessageBoxButton.OK, MessageBoxImage.Error); } }