//Constructor public SignalCollection(MainWindow uiWindow) { brushes = new List <SolidColorBrush>(); brushes.Add(Brushes.MediumVioletRed); brushes.Add(Brushes.LightBlue); brushes.Add(Brushes.BurlyWood); brushes.Add(Brushes.LightPink); brushes.Add(Brushes.Yellow); brushes.Add(Brushes.LightGreen); brushes.Add(Brushes.Gold); window = uiWindow; dataDispatcher = window.Dispatcher; signals = new List <Signal>(0); this.view = uiWindow.view; //set initial view params //view.XMAX = 2000; view.YMIN = 0; view.YMAX = 255; view.XMIN = 0; view.LINESCALE = 1; horizontals = new List <gridLine>(10); verticals = new List <gridLine>(10); plotlineH = createHLine(0, false); plotlineH.hideLabel(); plotlineV = createVLine(0, false); plotlineV.hideLabel(); preparePlot(); drawWorkerDelegate w = drawWorker; w.BeginInvoke(null, null); //addSignal(true); }
//Create vertical gridlines with labels private gridLine createVLine(int x, bool addtogroup = true) { gridLine vline = new gridLine(x, LineDirection.Vertical, window); if (addtogroup == true) { verticals.Add(vline); } return(vline); }
//Create horizontal gridlines with labels private gridLine createHLine(int y, bool addtogroup = true) { gridLine hline = new gridLine(y, LineDirection.Horizontal, window); if (addtogroup == true) { horizontals.Add(hline); } return(hline); }
//Inital drawing of the grid private void preparePlot() { Canvas plot = window.plot; //RenderOptions.SetEdgeMode(plot, EdgeMode.Aliased); for (int i = 0; i < view.XMAX; i += xRes) //vertical lines { gridLine line = createVLine(i); } for (int i = 0; i < view.YMAX; i += yRes) //horizontals lines { gridLine line = createHLine(i); } }
//Function updating the plot graphics public void updatePlot() { //Horizontalls int nrlines = (int)Math.Ceiling((double)(view.YMAX - view.YMIN) / yRes); try { int hornr = horizontals.Count; while (nrlines > hornr) { gridLine line = createHLine(0); hornr = horizontals.Count; } while (nrlines < hornr) { gridLine temp = horizontals[horizontals.Count - 1]; //instance of gridLine to remove temp.remove(); horizontals.Remove(temp); hornr = horizontals.Count; } int count = 0; foreach (gridLine line in horizontals) { double Yvalue = yRes * count; //line.changeValue((int)Extra.map(Yvalue, (int)view.MIN, (int) view.MAX, 0, (int)window.plot.Height),Yvalue); line.changeValue((int)Yvalue, yRes * count); line.setThickness(factor); count++; } } catch (NullReferenceException) { } //Verticalls nrlines = (int)Math.Ceiling((double)(view.XMAX - view.XMIN) / xRes); nrlines = Math.Abs(nrlines); try { int vertnr = verticals.Count; while (nrlines > vertnr) { gridLine line = createVLine(0); vertnr = verticals.Count; } while (nrlines < vertnr) { gridLine temp = verticals[verticals.Count - 1]; temp.remove(); verticals.Remove(temp); vertnr = verticals.Count; } int count = 0; foreach (gridLine line in verticals) { int Xvalue = (int)xRes * count; line.changeValue(Xvalue, Xvalue); line.setThickness(factor); count++; } } catch (NullReferenceException) { } //PlotLines based on mouse position if (drawmouse == true) { try { plotlineH.changeValue((int)mousePosition.Y, (int)mousePosition.Y); plotlineV.changeValue((int)mousePosition.X, (int)mousePosition.X); } catch (Exception) { } //Light part of the graph foreach (Signal signal in signals) { double result = signal.getValue((int)mousePosition.X, true); signal.movePointer((int)mousePosition.X, (int)Math.Floor((decimal)result)); signal.check.Content = signal.name + ": " + signal.getValue((int)mousePosition.X).ToString(); } plotlineH.setThickness(factor); plotlineV.setThickness(factor); } else { plotlineH.changeValue(0, 0); plotlineV.changeValue(0, 0); } foreach (Signal signal in signals) //Draw the real signals { signal.createGeometry(); } //Fit plot in in canvas, using slider's values window.resetTransform(true); }