mirror of
https://github.com/bvanroll/cs-map-project.git
synced 2025-08-30 04:12:45 +00:00
nog rare dinge, ma tga beter of normaal
This commit is contained in:
@@ -23,6 +23,8 @@ using Globals;
|
||||
using Brush = System.Windows.Media.Brush;
|
||||
using Brushes = System.Windows.Media.Brushes;
|
||||
using Point = System.Windows.Point;
|
||||
using Datalaag;
|
||||
using Logica;
|
||||
|
||||
namespace opdracht2
|
||||
{
|
||||
@@ -35,6 +37,10 @@ namespace opdracht2
|
||||
List<Polygon> f;
|
||||
List<Ellipse> el;
|
||||
List<Polygon> buffer;
|
||||
ListBox l;
|
||||
|
||||
PolygonManipulatie pm;
|
||||
JsonReader j;
|
||||
public MainWindow()
|
||||
{
|
||||
//todo logica toevoegen als object
|
||||
@@ -46,34 +52,7 @@ namespace opdracht2
|
||||
InitializeComponent();
|
||||
c = (Canvas)this.FindName("someCanvas");
|
||||
CompositionTarget.Rendering += DoUpdates;
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
if (openFileDialog.ShowDialog() == true)
|
||||
{
|
||||
//TODO remove
|
||||
//Tuple<List<Polygon>, List<Ellipse>> t = GeoJsonParser.TriangulateJsonData(File.ReadAllText(openFileDialog.FileName), c.Width, c.Height);
|
||||
f = GeoJsonParser.TriangulateJsonData(File.ReadAllText(openFileDialog.FileName), 800, 800);
|
||||
el = new List<Ellipse>();
|
||||
}
|
||||
var st = new ScaleTransform();
|
||||
c.RenderTransform = st;
|
||||
foreach (Ellipse eli in el)
|
||||
{
|
||||
c.Children.Add(eli);
|
||||
}
|
||||
c.MouseWheel += (sender, e) =>
|
||||
{
|
||||
|
||||
if (e.Delta > 0)
|
||||
{
|
||||
st.ScaleX *= 2;
|
||||
st.ScaleY *= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
st.ScaleX /= 2;
|
||||
st.ScaleY /= 2;
|
||||
}
|
||||
};
|
||||
l = (ListBox)this.FindName("lb");
|
||||
|
||||
Debug.Write("done");
|
||||
}
|
||||
@@ -125,6 +104,119 @@ namespace opdracht2
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LoadFile_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
if (openFileDialog.ShowDialog() == true)
|
||||
{
|
||||
//TODO remove
|
||||
//Tuple<List<Polygon>, List<Ellipse>> t = GeoJsonParser.TriangulateJsonData(File.ReadAllText(openFileDialog.FileName), c.Width, c.Height);
|
||||
//f = GeoJsonParser.TriangulateJsonData(File.ReadAllText(openFileDialog.FileName), 200, 200);
|
||||
j = new JsonReader(openFileDialog.FileName);
|
||||
el = new List<Ellipse>();
|
||||
pm = new PolygonManipulatie(j);
|
||||
}
|
||||
foreach (object o in pm.GetPolygons())
|
||||
{
|
||||
try { l.Items.Add(o); } catch (Exception) { };
|
||||
|
||||
}
|
||||
foreach (object o in pm.GetMultiPolygons())
|
||||
{
|
||||
try { l.Items.Add(o); } catch (Exception) { };
|
||||
|
||||
}
|
||||
var st = new ScaleTransform();
|
||||
c.RenderTransform = st;
|
||||
foreach (Ellipse eli in el)
|
||||
{
|
||||
c.Children.Add(eli);
|
||||
}
|
||||
c.MouseWheel += (sender, e) =>
|
||||
{
|
||||
|
||||
if (e.Delta > 0)
|
||||
{
|
||||
st.ScaleX *= 2;
|
||||
st.ScaleY *= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
st.ScaleX /= 2;
|
||||
st.ScaleY /= 2;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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 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
|
||||
switch (lb.SelectedItem.GetType().Name)
|
||||
{
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<Polygon> getPolygon(MultiPolygonPunten mp)
|
||||
{
|
||||
List<Polygon> lijst = new List<Polygon>();
|
||||
foreach(PolygonPunten p in mp.PolygonPunten)
|
||||
{
|
||||
lijst.Add(getPolygon(p));
|
||||
}
|
||||
return lijst;
|
||||
}
|
||||
private Polygon getPolygon(PolygonPunten p)
|
||||
{
|
||||
Polygon returnWaarde = new Polygon();
|
||||
PointCollection puntCollectie = new PointCollection();
|
||||
foreach(Punt punt in p.Punten)
|
||||
{
|
||||
puntCollectie.Add(new Point(punt.X, punt.Y));
|
||||
}
|
||||
returnWaarde.Points = puntCollectie;
|
||||
returnWaarde.StrokeThickness = 1;
|
||||
|
||||
|
||||
// deze code zorgt ervoor dat de driehoeken duidelijker zijn op de afbeelding door de kleur willekeurig te selecteren
|
||||
Random random = new Random();
|
||||
Type brushType = typeof(Brushes);
|
||||
PropertyInfo[] properties = brushType.GetProperties();
|
||||
int randomIndex = random.Next(properties.Length);
|
||||
Brush willekeurigeBrush = (Brush)properties[randomIndex].GetValue(null, null);
|
||||
if (willekeurigeBrush == Brushes.White) willekeurigeBrush = Brushes.Black;
|
||||
returnWaarde.Fill = willekeurigeBrush;
|
||||
returnWaarde.Stroke = willekeurigeBrush;
|
||||
return returnWaarde;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user