Beispiel #1
0
        private void MenuItemTrajetImport_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Multiselect = false;
            dlg.DefaultExt  = ".csv";
            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                Excel.Application oExcel = new Excel.Application();

                Excel.Workbook  WB = oExcel.Workbooks.Open(dlg.FileName);
                string          ExcelWorkbookName = WB.Name;
                int             worksheetcount    = WB.Worksheets.Count;
                Excel.Worksheet wks = (Excel.Worksheet)WB.Worksheets[1];

                string      firstworksheetname = wks.Name;
                Excel.Range range = wks.UsedRange;

                var firestcellValue = ((Excel.Range)wks.Cells[1, 1]).Value;
                Console.WriteLine("Test row : " + range.Rows.Count);
                Console.WriteLine("Test col : " + range.Columns.Count);
                Console.WriteLine("Test val last : " + ((Excel.Range)wks.Cells[range.Rows.Count, 1]).Value);
                List <ICoord> lCoord = new List <ICoord>();
                for (int i = 1; i <= range.Rows.Count; i++)
                {
                    if (((Excel.Range)wks.Cells[i, 3]).Value == "/")
                    {
                        lCoord.Add(new Coordonnees((double)((Excel.Range)wks.Cells[i, 1]).Value, ((Excel.Range)wks.Cells[i, 2]).Value));
                    }
                    else
                    {
                        lCoord.Add(new POI((string)((Excel.Range)wks.Cells[i, 3]).Value, (double)((Excel.Range)wks.Cells[i, 1]).Value, ((Excel.Range)wks.Cells[i, 2]).Value));
                    }
                }
                ICartoObj poly;
                ///On va tester si le premier point est égale au dernier -> Si oui : Polygon    ->Sinon : Polyline
                if (((Excel.Range)wks.Cells[range.Rows.Count, 1]).Value == ((Excel.Range)wks.Cells[1, 1]).Value &&
                    ((Excel.Range)wks.Cells[range.Rows.Count, 2]).Value == ((Excel.Range)wks.Cells[1, 2]).Value &&
                    ((Excel.Range)wks.Cells[range.Rows.Count, 3]).Value == ((Excel.Range)wks.Cells[1, 3]).Value)
                {
                    Console.WriteLine("POLYGON");
                    lCoord.Remove(lCoord.Last <ICoord>());
                    poly = new ProjectLibraryClass.Polygon(lCoord, mP.Remplissage, mP.Contour, mP.Opacity, mP.LineEp);
                    AjouterPolygon(poly);
                }
                else
                {
                    poly = new ProjectLibraryClass.Polyline(mP.LineEp, mP.Contour, mP.Opacity, lCoord);
                    AjouterPolyline(poly);
                }
                mP.AddCartObj(poly);



                releaseObject(oExcel);
                releaseObject(WB);
                releaseObject(wks);
            }
        }
Beispiel #2
0
        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);
        }
        public WindowItemProperty(int index)
        {
            id = index;
            InitializeComponent();
            tIContour.Visibility     = Visibility.Hidden;
            tIRemplissage.Visibility = Visibility.Hidden;

            ListBoxPropertyX.ItemsSource    = MainWindow.mP.CartoCollection[index].lCoord;
            ListBoxPropertyY.ItemsSource    = MainWindow.mP.CartoCollection[index].lCoord;
            ListBoxPropertyDesc.ItemsSource = MainWindow.mP.CartoCollection[index].lCoord;
            lCoordBase = new List <ICoord>(MainWindow.mP.CartoCollection[index].lCoord);

            if (MainWindow.mP.CartoCollection[index] is POI)
            {
                pin          = new Pushpin();
                pin.Location = new Location(MainWindow.mP.CartoCollection[index].lCoord[0].X, MainWindow.mP.CartoCollection[index].lCoord[0].Y);
                myMapProperty.Children.Add(pin);
                tiMore.Visibility = Visibility.Hidden;
            }
            else
            {
                if (MainWindow.mP.CartoCollection[index] is ProjectLibraryClass.Polygon)
                {
                    polTmp    = MainWindow.mP.CartoCollection[index] as ProjectLibraryClass.Polygon;
                    maPolygon = new MapPolygon();
                    myMapProperty.Children.Add(maPolygon);
                    maPolygon.Locations = new LocationCollection();
                    for (int i = 0; i < MainWindow.mP.CartoCollection[index].lCoord.Count(); i++)
                    {
                        maPolygon.Locations.Add(new Location(MainWindow.mP.CartoCollection[index].lCoord[i].X, MainWindow.mP.CartoCollection[index].lCoord[i].Y));
                    }

                    maPolygon.Fill            = MainWindow.ToBrush(polTmp.Rempli);
                    maPolygon.Stroke          = MainWindow.ToBrush(polTmp.Contour);
                    remplissageBase           = polTmp.Rempli;
                    contourBase               = polTmp.Contour;
                    maPolygon.Opacity         = polTmp.Opacite;
                    maPolygon.StrokeThickness = polTmp.Epaisseur;
                    tIContour.Visibility      = Visibility.Visible;
                    tIRemplissage.Visibility  = Visibility.Visible;

                    SliderContourR.Value            = polTmp.Contour.R;
                    SliderContourG.Value            = polTmp.Contour.G;
                    SliderContourB.Value            = polTmp.Contour.B;
                    PreviewColorContour.DataContext = MainWindow.ToBrush(polTmp.Contour);

                    SliderRemplirR.Value = polTmp.Rempli.R;
                    SliderRemplirG.Value = polTmp.Rempli.G;
                    SliderRemplirB.Value = polTmp.Rempli.B;
                    PreviewColorRemplissage.DataContext = MainWindow.ToBrush(polTmp.Rempli);

                    SliderEpaisseur.Value = ((ProjectLibraryClass.Polygon)MainWindow.mP.CartoCollection[index]).Epaisseur;
                    SliderOpacite.Value   = ((ProjectLibraryClass.Polygon)MainWindow.mP.CartoCollection[index]).Opacite;
                }
                if (MainWindow.mP.CartoCollection[index] is ProjectLibraryClass.Polyline)
                {
                    polyTmp = MainWindow.mP.CartoCollection[index] as ProjectLibraryClass.Polyline;

                    contourBase = polyTmp.Couleur;

                    maPolyline = new MapPolyline();
                    myMapProperty.Children.Add(maPolyline);
                    maPolyline.Locations = new LocationCollection();
                    for (int i = 0; i < MainWindow.mP.CartoCollection[index].lCoord.Count(); i++)
                    {
                        maPolyline.Locations.Add(new Location(MainWindow.mP.CartoCollection[index].lCoord[i].X, MainWindow.mP.CartoCollection[index].lCoord[i].Y));
                    }
                    maPolyline.StrokeThickness = polyTmp.Epaisseur;
                    maPolyline.Stroke          = MainWindow.ToBrush(polyTmp.Couleur);
                    maPolyline.Opacity         = polyTmp.Opacite;
                    myMapProperty.Center       = new Location(MainWindow.mP.CartoCollection[index].lCoord[0].X, MainWindow.mP.CartoCollection[index].lCoord[0].Y);
                    myMapProperty.ZoomLevel    = 2;
                    tIContour.Visibility       = Visibility.Visible;

                    SliderContourR.Value            = polyTmp.Couleur.R;
                    SliderContourG.Value            = polyTmp.Couleur.G;
                    SliderContourB.Value            = polyTmp.Couleur.B;
                    PreviewColorContour.DataContext = MainWindow.ToBrush(polyTmp.Couleur);
                    SliderEpaisseur.Value           = ((ProjectLibraryClass.Polyline)MainWindow.mP.CartoCollection[index]).Epaisseur;
                    SliderOpacite.Value             = ((ProjectLibraryClass.Polyline)MainWindow.mP.CartoCollection[index]).Opacite;
                }
            }
        }