private void RemovePoint(object xo) { int id = (int)xo; PointViewModel x = listOfPoints.FirstOrDefault(point => point.id == id); listOfPoints.Remove(x); DrawPolyline(); }
private void AddPoint() { PointViewModel new_point = new PointViewModel(PanelX, PanelY, "B"); listOfPoints.Add(new_point); new_point.PointDettached += (sender, args) => { SortPoints((PointViewModel)sender); attachedPoint = null; }; new_point.PointAttached += (sender, args) => attachedPoint = (PointViewModel)sender; SortPoints(new_point); }
public PWMCurveViewModel() { ServiceContainer.eventAggregator.GetEvent <TemperatureMessage>().Subscribe((int temp) => { ServiceContainer.eventAggregator.GetEvent <EditingCurve>().Publish(true); lastSetTemperature = AnalyzeTemperatureChange(temp); ServiceContainer.eventAggregator.GetEvent <EditingCurve>().Publish(false); //ServiceContainer.eventAggregator.GetEvent<VoltagePWMMessage>().Publish((int)drawableFunction[temp].realPoint.y); ServiceContainer.eventAggregator.GetEvent <VoltagePWMMessage>().Publish((int)drawableFunction[lastSetTemperature].realPoint.y); ServiceContainer.eventAggregator.GetEvent <LockedTemperatureMessage>().Publish(lastSetTemperature); drawableFunction[temp].visible = true; if (temp != previousTemperature) { drawableFunction[previousTemperature].visible = false; } previousTemperature = temp; }); PointViewModel.ystop = height; PointViewModel.xstop = width; try { using (StreamReader rd = new StreamReader("settings.xml")) { List <RealPoint> listOfRealPoints; XmlSerializer xs = new XmlSerializer(typeof(List <RealPoint>)); listOfRealPoints = xs.Deserialize(rd) as List <RealPoint>; _listOfPoints = new ObservableCollection <PointViewModel>(); foreach (var x in listOfRealPoints) { _listOfPoints.Add(new PointViewModel(x, false)); } } } catch { _listOfPoints = new ObservableCollection <PointViewModel> { new PointViewModel(100, 100, "A"), new PointViewModel(150, 150, "B"), new PointViewModel(200, 200, "C"), new PointViewModel(250, 150, "B"), new PointViewModel(300, 200, "C") }; } foreach (PointViewModel p in _listOfPoints) { p.PointDettached += (sender, args) => { SortPoints((PointViewModel)sender); }; p.PointAttached += (sender, args) => { attachedPoint = (PointViewModel)sender; }; SortPoints(p); } }
public void SortPoints(PointViewModel sender) { listOfPoints = new ObservableCollection <PointViewModel>(listOfPoints.OrderBy(x => x.RectX).ToList()); bool position = false; foreach (PointViewModel point in listOfPoints) { if (point.id == sender.id) { position = true; } else if (position == false) { if (point.PanelY < sender.PanelY) { point.PanelY = sender.PanelY; } } else { if (point.PanelY > sender.PanelY) { point.PanelY = sender.PanelY; } } point.CalculateRealPosition(); } //GenerateCurve(); XmlSerializer xs = new XmlSerializer(typeof(List <RealPoint>)); using (StreamWriter wr = new StreamWriter("settings.xml")) { List <RealPoint> listOfRealPoints = new List <RealPoint>(); foreach (var x in _listOfPoints) { listOfRealPoints.Add(x.realPoint); } xs.Serialize(wr, listOfRealPoints); } DrawPolyline(); }