mogelijkheid meerdere items te selecteren (nu mss betere kaart eu?)

This commit is contained in:
BuildTools
2020-07-30 09:54:07 +02:00
parent 9f1da145a0
commit 8a0386a5c4
7 changed files with 163 additions and 77 deletions

Binary file not shown.

View File

@@ -49,6 +49,11 @@ namespace Globals
if (string.Equals(Naam, "", StringComparison.Ordinal)) return "UNKNOWN"; if (string.Equals(Naam, "", StringComparison.Ordinal)) return "UNKNOWN";
else return Naam; else return Naam;
} }
public MultiPolygonPunten ToMultiPolygonPunten()
{
return new MultiPolygonPunten(new List<PolygonPunten>() { this }, this.Naam);
}
} }
} }

View File

@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Text; using System.Text;
using Datalaag; using Datalaag;
using Globals; using Globals;
@@ -94,6 +95,37 @@ namespace Logica
return new MultiPolygonPunten(pp, multiPolygon.Naam); return new MultiPolygonPunten(pp, multiPolygon.Naam);
} }
public List<MultiPolygonPunten> ScaleMultiPolygons(List<MultiPolygonPunten> multiPolygons, double scaleX, double scaleY)
{
double maxX = multiPolygons.Max(m => m.MaximumX);
double maxY = multiPolygons.Max(m => m.MaximumY);
double minX = multiPolygons.Min(m => m.MinimumX);
double minY = multiPolygons.Min(m => m.MinimumY);
List<MultiPolygonPunten> mpps = new List<MultiPolygonPunten>();
foreach (MultiPolygonPunten mp in multiPolygons)
{
List<PolygonPunten> pp = new List<PolygonPunten>();
foreach (PolygonPunten poly in mp.PolygonPunten)
{
List<Punt> punten = new List<Punt>();
foreach (Punt punt in poly.Punten)
{
double x = punt.X - minX;
x /= maxX;
x *= scaleX;
double y = punt.Y - minY;
y /= maxY;
y *= scaleY;
punten.Add(new Punt(x, y, punt.Naam));
}
pp.Add(new PolygonPunten(punten, poly.Naam));
}
mpps.Add(new MultiPolygonPunten(pp, mp.Naam));
}
return mpps;
}
public List<PolygonPunten> GetAllPolygons() public List<PolygonPunten> GetAllPolygons()
{ {
List<PolygonPunten> lijst = new List<PolygonPunten>(); List<PolygonPunten> lijst = new List<PolygonPunten>();

View File

@@ -21,6 +21,7 @@
<Button x:Name="LoadFile" Content="LoadFile" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="27" Width="65" Click="LoadFile_Click"/> <Button x:Name="LoadFile" Content="LoadFile" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="27" Width="65" Click="LoadFile_Click"/>
<Slider HorizontalAlignment="Left" Margin="10,406,0,0" VerticalAlignment="Top" Width="120" Maximum="100" SmallChange="1"/> <Slider HorizontalAlignment="Left" Margin="10,406,0,0" VerticalAlignment="Top" Width="120" Maximum="100" SmallChange="1"/>
<Label Content="Epsilon (0.001 - 0.1%)" HorizontalAlignment="Left" Margin="8,375,0,0" VerticalAlignment="Top"/> <Label Content="Epsilon (0.001 - 0.1%)" HorizontalAlignment="Left" Margin="8,375,0,0" VerticalAlignment="Top"/>
<CheckBox x:Name="Triangulate" Content="Triangulate" HorizontalAlignment="Left" Margin="10,346,0,0" VerticalAlignment="Top"/>
</Grid> </Grid>
</Window> </Window>

View File

@@ -38,7 +38,7 @@ namespace opdracht2
List<Ellipse> el; List<Ellipse> el;
List<Polygon> buffer; List<Polygon> buffer;
ListBox l; ListBox l;
CheckBox triangulate;
PolygonManipulatie pm; PolygonManipulatie pm;
JsonReader j; JsonReader j;
public MainWindow() public MainWindow()
@@ -53,7 +53,7 @@ namespace opdracht2
c = (Canvas)this.FindName("someCanvas"); c = (Canvas)this.FindName("someCanvas");
CompositionTarget.Rendering += DoUpdates; CompositionTarget.Rendering += DoUpdates;
l = (ListBox)this.FindName("lb"); l = (ListBox)this.FindName("lb");
triangulate = (CheckBox)this.FindName("triangulate");
Debug.Write("done"); Debug.Write("done");
} }
@@ -152,36 +152,76 @@ namespace opdracht2
private void lb_SelectionChanged(object sender, SelectionChangedEventArgs e) private void lb_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
//TODO zorg ervoor dat als meerdere items geselecteerd worden, we een scaling methode hebben voor meerdere (wss gebruik van list) //TODO zorg ervoor dat als meerdere items geselecteerd worden, we een scaling methode hebben voor meerdere (wss gebruik van list)
//TODO als we zo een methode nodig hebben moeten we ook polygonpunten kunnen omzetten naar multipolygonpunten (met dan maar 1 polygon)
//zodat we een 1 lijst kunnen gebruiken voor alle polygons //zodat we een 1 lijst kunnen gebruiken voor alle polygons
switch (lb.SelectedItem.GetType().Name) if (lb.SelectedItems.Count >1)
{ {
case "MultiPolygonPunten": c.Children.Clear();
Debug.WriteLine(lb.SelectedItem.GetType().Name); List<MultiPolygonPunten> mpps = new List<MultiPolygonPunten>();
c.Children.Clear(); foreach (Object o in lb.SelectedItems)
MultiPolygonPunten mp = pm.ScaleMultiPolygon((MultiPolygonPunten)lb.SelectedItem, 100, 100); {
//hier ervoor zorgen dat scaling, triangulation etc gebeurt door gebruik van logica layer functies te callen if (o.GetType().ToString() == "PolygonPunten") {
foreach(PolygonPunten pp in mp.PolygonPunten) PolygonPunten p = (PolygonPunten)o;
mpps.Add(p.ToMultiPolygonPunten());
} else
{ {
foreach (PolygonPunten ppd in pm.TriangulatePolygon(pp)) mpps.Add((MultiPolygonPunten)o);
}
}
//peuker implementatie moet ook nog gebeuren, code is er al, maar wanneer moet deze aangeroepen worden
mpps = pm.ScaleMultiPolygons(mpps, 100, 100);
foreach(MultiPolygonPunten mp in mpps)
{
if (triangulate.IsChecked == true) //kan blkbr ook null zijn, raar
{
foreach(PolygonPunten pp in mp.PolygonPunten)
{ {
c.Children.Add(getPolygon(ppd)); foreach(PolygonPunten ppd in pm.TriangulatePolygon(pp))
{
c.Children.Add(getPolygon(ppd));
}
} }
} }
foreach(Polygon po in getPolygon(mp)) else
{ {
//c.Children.Add(po); foreach (Polygon p in getPolygon(mp))
{
c.Children.Add(p);
}
} }
break; }
case "PolygonPunten": }
Debug.WriteLine(lb.SelectedItem.GetType().Name); else
c.Children.Clear(); {
PolygonPunten p = pm.ScalePolygon((PolygonPunten)lb.SelectedItem, 100, 100); switch (lb.SelectedItem.GetType().Name)
c.Children.Add(getPolygon(p)); {
break; case "MultiPolygonPunten":
Debug.WriteLine(lb.SelectedItem.GetType().Name);
c.Children.Clear();
MultiPolygonPunten mp = pm.ScaleMultiPolygon((MultiPolygonPunten)lb.SelectedItem, 100, 100);
//hier ervoor zorgen dat scaling, triangulation etc gebeurt door gebruik van logica layer functies te callen
foreach (PolygonPunten pp in mp.PolygonPunten)
{
foreach (PolygonPunten ppd in pm.TriangulatePolygon(pp))
{
c.Children.Add(getPolygon(ppd));
}
}
foreach (Polygon po in getPolygon(mp))
{
//c.Children.Add(po);
}
break;
case "PolygonPunten":
Debug.WriteLine(lb.SelectedItem.GetType().Name);
c.Children.Clear();
PolygonPunten p = pm.ScalePolygon((PolygonPunten)lb.SelectedItem, 100, 100);
c.Children.Add(getPolygon(p));
break;
}
} }
} }

View File

@@ -1,4 +1,5 @@
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "05D515F609A8E8D2AFAF26E4ADD6AF1BBA9D6ED8" // Updated by XamlIntelliSenseFileGenerator 7/30/2020 9:49:33 AM
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "05D515F609A8E8D2AFAF26E4ADD6AF1BBA9D6ED8"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
@@ -33,92 +34,99 @@ using System.Windows.Shell;
using opdracht2; using opdracht2;
namespace opdracht2 { namespace opdracht2
{
/// <summary> /// <summary>
/// MainWindow /// MainWindow
/// </summary> /// </summary>
public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector { public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector
{
#line 10 "..\..\..\MainWindow.xaml"
#line 10 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Canvas someCanvas; internal System.Windows.Controls.Canvas someCanvas;
#line default #line default
#line hidden #line hidden
#line 20 "..\..\..\MainWindow.xaml" #line 20 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.ListBox lb; internal System.Windows.Controls.ListBox lb;
#line default #line default
#line hidden #line hidden
#line 21 "..\..\..\MainWindow.xaml" #line 21 "..\..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Button LoadFile; internal System.Windows.Controls.Button LoadFile;
#line default #line default
#line hidden #line hidden
private bool _contentLoaded; private bool _contentLoaded;
/// <summary> /// <summary>
/// InitializeComponent /// InitializeComponent
/// </summary> /// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.8.1.0")] [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.8.1.0")]
public void InitializeComponent() { public void InitializeComponent()
if (_contentLoaded) { {
if (_contentLoaded)
{
return; return;
} }
_contentLoaded = true; _contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/opdracht2;component/mainwindow.xaml", System.UriKind.Relative); System.Uri resourceLocater = new System.Uri("/opdracht2;component/mainwindow.xaml", System.UriKind.Relative);
#line 1 "..\..\..\MainWindow.xaml" #line 1 "..\..\..\MainWindow.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater); System.Windows.Application.LoadComponent(this, resourceLocater);
#line default #line default
#line hidden #line hidden
} }
[System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.8.1.0")] [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.8.1.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
{
switch (connectionId) switch (connectionId)
{ {
case 1: case 1:
this.someCanvas = ((System.Windows.Controls.Canvas)(target)); this.someCanvas = ((System.Windows.Controls.Canvas)(target));
return; return;
case 2: case 2:
this.lb = ((System.Windows.Controls.ListBox)(target)); this.lb = ((System.Windows.Controls.ListBox)(target));
#line 20 "..\..\..\MainWindow.xaml" #line 20 "..\..\..\MainWindow.xaml"
this.lb.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.lb_SelectionChanged); this.lb.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.lb_SelectionChanged);
#line default #line default
#line hidden #line hidden
return; return;
case 3: case 3:
this.LoadFile = ((System.Windows.Controls.Button)(target)); this.LoadFile = ((System.Windows.Controls.Button)(target));
#line 21 "..\..\..\MainWindow.xaml" #line 21 "..\..\..\MainWindow.xaml"
this.LoadFile.Click += new System.Windows.RoutedEventHandler(this.LoadFile_Click); this.LoadFile.Click += new System.Windows.RoutedEventHandler(this.LoadFile_Click);
#line default #line default
#line hidden #line hidden
return; return;
} }
this._contentLoaded = true; this._contentLoaded = true;
} }
internal System.Windows.Controls.CheckBox Triangulate;
} }
} }