private void Trajet_Import_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog openFileDlg = new Microsoft.Win32.OpenFileDialog(); openFileDlg.DefaultExt = ".csv"; openFileDlg.Filter = "csv document (.csv)|*.csv"; openFileDlg.ShowDialog(); Polyline newPolyline = new Polyline(); string[] lines = File.ReadAllLines(openFileDlg.FileName); Console.WriteLine(lines.Length); if (lines.Length < 2) { //Erreur on essaye d'importer un POI MessageBox.Show("Erreur,impossible d'ajouter un POI comme trajet!"); return; } for (int i = 0; i < lines.Length; i++) { string[] lines2 = lines[i].Split(';'); newPolyline.Collection.Add(new POI(lines2[2], new Coordonnees(double.Parse(lines2[0]), double.Parse(lines2[1])))); if (i == 0) { newPolyline.Description = lines2[2]; } if (i == lines.Length - 1) { newPolyline.Description += " vers " + lines2[2]; } } myPersonalMapData.ObservableCollection.Add(newPolyline); UpdateMainWindow(); }
private void Polyline_Click(object sender, RoutedEventArgs e) //APRES AVOIR SELECTIONNER LES ELEMENTS SUR LA LISTE, ON CLICK SUR POLYLINE ET LA POLYLINE EST CONSTRUITE { MyCartographyObjects.Polyline line = new MyCartographyObjects.Polyline(LineP); if (listBox.SelectedItems.Count < 2) { return; } var selectedElems = listBox.SelectedItems; List <int> ListIdDelete = new List <int>(); for (int i = 0; i < selectedElems.Count; i++) { ListIdDelete.Add((selectedElems[i] as Coordonnees).Id); line.coord.Add(selectedElems[i] as Coordonnees); } DrawLine(line.coord, line.Id, LineP); foreach (var selid in ListIdDelete) { _myMapData.ObservableCollection.Remove(_myMapData.ObservableCollection.Cast <CartoObj>().First(a => a.Id == selid)); } _myMapData.ObservableCollection.Add(line); listBox.Items.Refresh(); }
public PolylineWindow(Polyline newPolyline) { InitializeComponent(); DataContext = this; foreach (PropertyInfo property in typeof(System.Drawing.Color).GetProperties(BindingFlags.Static | BindingFlags.Public)) { if (property.PropertyType == typeof(System.Drawing.Color)) { ComboBoxColors.Items.Add(property.Name); } } //Ajouteur les couleurs dans la combobox _temp = newPolyline; Latitude = "0,000"; Longitude = "0,000"; Couleur = MainWindow.GetColorName(newPolyline.Color); Epaisseur = newPolyline.Epaisseur.ToString(); Description = newPolyline.Description; DescriptionCoordonnees = ""; foreach (Coordonnees c in newPolyline.Collection) { ListBoxCoordonnees.Items.Add(c.ToString()); } hasAppliquerBeenClicked = true; modifier = true; }
private void MenuItem_File_Travel_Import_Click(object sender, RoutedEventArgs e) { string filename = MapData.GetFilenameToOpen("csv"); if (File.Exists(filename)) { List <Coordonnees> coordList = new List <Coordonnees>(); if (MapData.LoadFromCsvFormat(filename, "Travel", coordList)) { MyCartographyObjects.Polyline newPolyline = new MyCartographyObjects.Polyline(); LocationCollection locations = new LocationCollection(); foreach (Coordonnees coord in coordList) { newPolyline.Add(coord); Location location = new Location(coord.Latitude, coord.Longitude); locations.Add(location); } MapData.Add(newPolyline); MapPolyline newMapPolyline = new MapPolyline() { Stroke = new SolidColorBrush(newPolyline.Stroke), StrokeThickness = newPolyline.Thickness, Opacity = newPolyline.Opacity, Locations = locations }; newPolyline.Tag = newMapPolyline; MyMap.Children.Add(newMapPolyline); } else { MessageBox.Show("L'élément sélectionné n'est pas un trajet.", "Attention!", MessageBoxButton.OK, MessageBoxImage.Information); } } }
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; } } }
private void ButtunOk_Click(object sender, RoutedEventArgs e) { if (hasAppliquerBeenClicked) { _polyline = _temp; _polyline.Collection = _temp.Collection; Hide(); } }
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 Connexion_Click(object sender, RoutedEventArgs e) { MyPersonalMapData utilisateur = new MyPersonalMapData(NomTB.Text, PrenomTB.Text, emailTB.Text); WindowPrincipal w = new WindowPrincipal(utilisateur); Coordonnees A = new Coordonnees(40.25, 48.25); MyCartographyObjects.Polyline Poly1 = new MyCartographyObjects.Polyline(new List <Coordonnees>() { A }, 10, Color.FromArgb(255, 201, 200, 152), 1); ObservableCollection <ICartoObj> ListeTest = new ObservableCollection <ICartoObj>(); ListeTest.Add(Poly1); utilisateur.ObservableCollection = ListeTest; Coordonnees B = new Coordonnees(40.25, 48.25); Coordonnees D = new Coordonnees(3.25, 10.45); Coordonnees E = new Coordonnees(4.254, 5.2545); Polygone Polygone = new Polygone(new List <Coordonnees>() { B, D, E }, Color.FromArgb(165, 187, 195, 0), Color.FromArgb(165, 200, 140, 165), 1, 1); ListeTest.Add(Polygone); utilisateur.ObservableCollection = ListeTest; string filename = utilisateur.Nom + utilisateur.Prenom + ".dat"; if (NomTB.Text.Length < 1 || PrenomTB.Text.Length < 1 || emailTB.Text.Length < 1) { ApresConnexion.Text = "Erreur : Veuillez remplir tous les champs"; MessageBox.Show("Erreur : Veuillez remplir tous les champs"); } else { // ApresConnexion.Text = filename; if (!(File.Exists(@"C:\Users\gaetan\source\repos\CartoProject\Test\bin\Debug\" + filename))) { ApresConnexion.Text = "Utilisateur n'existe pas"; MessageBox.Show("Utilisateur n'existe pas"); utilisateur.Save(); w.Show(); this.Close(); } else { ApresConnexion.Text = "Utilisateur existe deja"; MessageBox.Show("Utilisateur existe deja"); // utilisateur.Load(); w.Show(); this.Close(); } } }
private void ButtonAppliquer_Click(object sender, RoutedEventArgs e) { if (_temp == null) { _temp = new MyCartographyObjects.Polyline(); } _temp.Color = (Color)ColorConverter.ConvertFromString(Couleur); _temp.Epaisseur = int.Parse(Epaisseur); _temp.Description = Description; hasAppliquerBeenClicked = true; }
private void MainWindow_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter && Keyboard.IsKeyDown(Key.LeftCtrl)) // CTRL + Enter { if (IsDrawingTravel) { MyCartographyObjects.Polyline newPolyline = new MyCartographyObjects.Polyline(CurrentTravel); MapData.Add(newPolyline); MapPolyline currentTravelMapPolyline = (MapPolyline)(CurrentTravel.Tag); MapPolyline newMapPolyline = new MapPolyline() { Stroke = currentTravelMapPolyline.Stroke, StrokeThickness = currentTravelMapPolyline.StrokeThickness, Opacity = currentTravelMapPolyline.Opacity, Locations = new LocationCollection() }; foreach (Location location in currentTravelMapPolyline.Locations) { newMapPolyline.Locations.Add(location); } MyMap.Children.Add(newMapPolyline); newPolyline.Tag = newMapPolyline; ResetCurrentTravel(); } else if (IsDrawingSurface) { MyCartographyObjects.Polygon newPolygon = new MyCartographyObjects.Polygon(CurrentSurface); MapData.Add(newPolygon); MapPolygon currentSurfaceMapPolygon = (MapPolygon)(CurrentSurface.Tag); MapPolygon newMapPolygon = new MapPolygon() { Fill = currentSurfaceMapPolygon.Fill, Stroke = currentSurfaceMapPolygon.Stroke, StrokeThickness = currentSurfaceMapPolygon.StrokeThickness, Opacity = currentSurfaceMapPolygon.Opacity, Locations = new LocationCollection() }; foreach (Location location in currentSurfaceMapPolygon.Locations) { newMapPolygon.Locations.Add(location); } MyMap.Children.Add(newMapPolygon); newPolygon.Tag = newMapPolygon; ResetCurrentSurface(); } } }
private void MenuFileTrajetExport_Click(object sender, RoutedEventArgs e)//EXPORTE UNE SEULE POYLINE DES DONNES DANS UN FICHIER CSV { int cpt = 0; Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.DefaultExt = ".csv"; dlg.Filter = "CSV Files (*.csv)|*.csv"; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { string filename = dlg.FileName; StreamWriter sw = new StreamWriter(filename, false); // POI poi = _myMapData.ObservableCollection[0] as POI; foreach (ICartoObj car in _myMapData.ObservableCollection) { if (car is MyCartographyObjects.Polyline && cpt == 0) { MyCartographyObjects.Polyline line = car as MyCartographyObjects.Polyline; //sw.WriteLine(line.Id + ";" + line.Colrs + ";"); foreach (var cord in line.coord) { if (cord is POI) { POI poin = cord as POI; sw.WriteLine(poin.Latitude + ";" + poin.Longitude + ";" + poin.Description + ";"); } else { sw.WriteLine(cord.Latitude + ";" + cord.Longitude + ";"); } } cpt++; } } cpt = 0; sw.Close(); } }
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(); }
public MappingWindow(MyPersonnalMapData mapData) { InitializeComponent(); MapData = mapData; CurrentTravel = new MyCartographyObjects.Polyline(); CurrentTravel.Tag = new MapPolyline() { Stroke = new SolidColorBrush(CurrentTravel.Stroke), StrokeThickness = CurrentTravel.Thickness, Opacity = CurrentTravel.Opacity, Locations = new LocationCollection() }; CurrentSurface = new MyCartographyObjects.Polygon(); CurrentSurface.Tag = new MapPolygon() { Fill = new SolidColorBrush(CurrentSurface.Fill), Stroke = new SolidColorBrush(CurrentSurface.Stroke), StrokeThickness = CurrentSurface.Thickness, Opacity = CurrentSurface.Opacity, Locations = new LocationCollection() }; string sessionFileFullPath = MyPersonnalMapData.BINARIES_DIR + "\\" + MapData.GetSessionFilename(); if (File.Exists(sessionFileFullPath)) // If the user has a session file { LoadBinaryFile(MyPersonnalMapData.BINARIES_DIR + "\\" + MapData.GetSessionFilename()); } else { File.WriteAllText(sessionFileFullPath, ""); // If not, we create a new file without any data } UpdateLbCartographyObjectsItemsSource(); }
private void LoadCoordoonees() //CHARGE LE CONTENU DU FICHIER S'IL EXISTE { foreach (var co in _myMapData.ObservableCollection) { if ((co as Coordonnees) is var point && point != null) { Location loc = new Location(point.Latitude, point.Longitude); Pushpin pin = new Pushpin(); pin.Location = loc; pin.Tag = point.Id; MyMap.Children.Add(pin); } if (co is MyCartographyObjects.Polyline) { List <Coordonnees> c = new List <Coordonnees>(); var ac = co as MyCartographyObjects.Polyline; MyCartographyObjects.Polyline line = new MyCartographyObjects.Polyline(ac.coord, LineP); foreach (var pt in line.coord) { AddPushPin(pt); } DrawLine(line.coord, line.Id, line.Colrs); } if (co is Polygone) { List <Coordonnees> c = new List <Coordonnees>(); var ac = co as Polygone; Polygone gone = new Polygone(ac.coord, LineP, BackP); foreach (var pt in gone.coord) { AddPushPin(pt); } DrawGone(gone.coord, gone.Id, gone.Contour, gone.Remplissage); } } }
private void BtnCancel_Click(object sender, RoutedEventArgs e) { ReceivedObj.Description = SaveReceivedObj.Description; if (ReceivedObj is POI receivedPOI) { POI savedPOI = SaveReceivedObj as POI; receivedPOI.Latitude = savedPOI.Latitude; receivedPOI.Longitude = savedPOI.Longitude; receivedPOI.Fill = savedPOI.Fill; Pushpin receivedPushpin = (Pushpin)receivedPOI.Tag; receivedPushpin.Location.Latitude = savedPOI.Latitude; receivedPushpin.Location.Longitude = savedPOI.Longitude; receivedPushpin.Background = new SolidColorBrush(savedPOI.Fill); } else if (ReceivedObj is MyCartographyObjects.Polyline receivedPolyline) { MyCartographyObjects.Polyline savedPolyline = SaveReceivedObj as MyCartographyObjects.Polyline; receivedPolyline.Stroke = savedPolyline.Stroke; MapPolyline mapPolyline = (MapPolyline)receivedPolyline.Tag; mapPolyline.Stroke = new SolidColorBrush(savedPolyline.Stroke); } else if (ReceivedObj is MyCartographyObjects.Polygon receivedPolygon) { MyCartographyObjects.Polygon savedPolygon = SaveReceivedObj as MyCartographyObjects.Polygon; receivedPolygon.Fill = savedPolygon.Fill; receivedPolygon.Stroke = savedPolygon.Stroke; MapPolygon mapPolygon = (MapPolygon)receivedPolygon.Tag; mapPolygon.Fill = new SolidColorBrush(savedPolygon.Fill); mapPolygon.Stroke = new SolidColorBrush(savedPolygon.Stroke); } send?.Invoke(); Close(); }
public void UpdateMainWindow() { if (myPersonalMapData != null) { Map.Children.Clear(); ListBox.Items.Clear(); foreach (ICartoObj i in myPersonalMapData.ObservableCollection) { if (i is POI) { POI p = i as POI; Pushpin pushpin = new Pushpin(); pushpin.Opacity = 0.7; pushpin.Location = new Location(p.Latitude, p.Longitude); ListBox.Items.Add("POI: " + p.Description); pushpin.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue); Map.Children.Add(pushpin); } if (i is Polyline) { Polyline p = i as Polyline; MapPolyline mapPolyline = new MapPolyline(); mapPolyline.Opacity = 0.7; mapPolyline.StrokeThickness = p.Epaisseur; ListBox.Items.Add("Trajet: " + p.Description); mapPolyline.Stroke = new SolidColorBrush(p.Color); mapPolyline.Locations = new LocationCollection(); foreach (object obj in p.Collection) { if (obj is POI) { POI poi = obj as POI; Pushpin pushpin = new Pushpin(); pushpin.Opacity = 0.7; pushpin.Location = new Location(poi.Latitude, poi.Longitude); pushpin.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Green); Map.Children.Add(pushpin); } mapPolyline.Locations.Add(new Location(((Coordonnees)obj).Latitude, ((Coordonnees)obj).Longitude)); } Map.Children.Add(mapPolyline); } if (i is Polygon) { Polygon p = i as Polygon; MapPolygon mapPolygon = new MapPolygon(); mapPolygon.Opacity = 0.7; mapPolygon.StrokeThickness = 3; ListBox.Items.Add("Surface: " + p.Description); mapPolygon.Fill = new System.Windows.Media.SolidColorBrush(p.RemplissageColor); mapPolygon.Stroke = new System.Windows.Media.SolidColorBrush(p.ContourColor); mapPolygon.Locations = new LocationCollection(); foreach (Coordonnees coords in p.Collection) { mapPolygon.Locations.Add(new Location(coords.Latitude, coords.Longitude)); } Map.Children.Add(mapPolygon); } } for (int i = 0; i < collectionCoordonnees.Count; i++) { if (collectionCoordonnees[i] is POI) { POI poi = (POI)collectionCoordonnees[i]; Pushpin pushpin = new Pushpin(); pushpin.Opacity = 0.7; pushpin.Location = new Location(poi.Latitude, poi.Longitude); pushpin.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Green); Map.Children.Add(pushpin); } else if (collectionCoordonnees[i] is Coordonnees) { Coordonnees coordonnees = collectionCoordonnees[i]; Pushpin pushpin = new Pushpin(); pushpin.Opacity = 0.7; pushpin.Location = new Location(coordonnees.Latitude, coordonnees.Longitude); pushpin.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red); Map.Children.Add(pushpin); } } } ListBox.SelectedIndex = ListBox.Items.Count - 1; }
private void MenuFileTrajetImport_Click(object sender, RoutedEventArgs e)//IMPORTE UNE POLYLINE D'UN FICHIER CSV { string filename = ""; Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".csv"; dlg.Filter = "CSV Files (*.csv)|*.csv"; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { filename = dlg.FileName; using (TextFieldParser parser = new TextFieldParser(@filename)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(";"); POI poi = new POI(); MyCartographyObjects.Polyline line = new MyCartographyObjects.Polyline(); List <Coordonnees> c = new List <Coordonnees>(); LocationCollection loc = new LocationCollection(); while (!parser.EndOfData) { string[] fields = parser.ReadFields(); for (int i = 2; i <= fields.Length; i += 3) { poi = new POI(fields[i], Double.Parse(fields[i - 2]), Double.Parse(fields[i - 1])); Pushpin pin = new Pushpin(); pin.Location = new Location(Double.Parse(fields[i - 2]), Double.Parse(fields[i - 1])); if (String.IsNullOrEmpty(poi.Description)) { c.Add(new Coordonnees(poi.Latitude, poi.Longitude)); loc.Add(new Location(poi.Latitude, poi.Longitude)); } else { _myMapData.ObservableCollection.Add(poi); } i += 3; } } if (loc.Count() > 0) { line = new MyCartographyObjects.Polyline(c, LineP); foreach (var point in line.coord) { AddPushPin(point); } DrawLine(line.coord, line.Id, line.Colrs); _myMapData.ObservableCollection.Add(line); } } } listBox.Items.Refresh(); }