public void UpdateView(double timestart, double timeend) { StreamReader fin = new StreamReader("simulog.log"); while (!fin.EndOfStream) { string text = fin.ReadLine(); string[] args = text.Split(' '); string name = args[0]; int time = int.Parse(args[1]); ValueSegment vs = null, vsp = null; SimulateDataModel sdmodel = vddict[name]; switch (sdmodel.Type) { case "BIT": vs = new BitSegment(); vs.Value = Int32.Parse(args[2]); break; case "WORD": vs = new WordSegment(); vs.Value = Int32.Parse(args[2]); break; case "DWORD": vs = new DWordSegment(); vs.Value = Int64.Parse(args[2]); break; case "FLOAT": vs = new FloatSegment(); vs.Value = float.Parse(args[2]); break; } if (sdmodel.Values.Count() == 0) { vsp = vs.Clone(); vsp.Value = 0; vsp.TimeStart = (int)(timestart); vs.TimeStart = vsp.TimeEnd = time; sdmodel.Add(vsp); sdmodel.Add(vs); } else { vsp = sdmodel.Values.Last(); vs.TimeStart = vsp.TimeEnd = time; sdmodel.Add(vs); } } foreach (SimulateDataModel sdmodel in vddict.Values) { if (sdmodel.Values.Count() > 0) { sdmodel.Values.Last().TimeEnd = (int)(timeend); } } }
public void SetValue(SimulateDataModel sour, SimulateDataModel dest, int sourstart, int sourend, int deststart, int destend) { sour.SortByTime(); destend = deststart + (sourend - sourstart); IEnumerator <ValueSegment> souriter = sour.Values.GetEnumerator(); souriter.MoveNext(); ValueSegment sourvseg = souriter.Current; while (sourvseg != null && sourvseg.TimeEnd < sourstart) { if (!souriter.MoveNext()) { break; } sourvseg = souriter.Current; } RemoveValue(dest, deststart, destend); sourvseg = souriter.Current; while (sourvseg != null && sourvseg.TimeStart < sourend) { int vsegstart = sourvseg.TimeStart; int vsegend = sourvseg.TimeEnd; if (vsegstart < sourstart) { vsegstart = sourstart; } if (vsegend > sourend) { vsegend = sourend; } if (vsegstart > vsegend) { continue; } ValueSegment vseg = sourvseg.Clone(); vseg.TimeStart = vsegstart + (deststart - sourstart); vseg.TimeEnd = vsegend + (deststart - sourstart); dest.Add(vseg); if (!souriter.MoveNext()) { break; } sourvseg = souriter.Current; } }
public void SetValue(SimulateDataModel sdmodel, object value, int timestart, int timeend) { RemoveValue(sdmodel, timestart, timeend); ValueSegment vseg; switch (sdmodel.Type) { case "BIT": BitSegment bseg = new BitSegment(); bseg.Value = value; vseg = bseg; break; case "WORD": WordSegment wseg = new WordSegment(); wseg.Value = value; vseg = wseg; break; case "DWORD": DWordSegment dseg = new DWordSegment(); dseg.Value = value; vseg = dseg; break; case "FLOAT": FloatSegment fseg = new FloatSegment(); fseg.Value = value; vseg = fseg; break; default: throw new ArgumentException(); } vseg.TimeStart = timestart; vseg.TimeEnd = timeend; sdmodel.Add(vseg); }
public void RemoveValue(SimulateDataModel sdmodel, int timestart, int timeend) { List <ValueSegment> delvss = new List <ValueSegment>(); List <ValueSegment> addvss = new List <ValueSegment>(); ValueSegment vs1, vs2; foreach (ValueSegment vs in sdmodel.Values) { // [()] if (vs.TimeStart <= timestart && timeend <= vs.TimeEnd) { vs1 = vs.Clone(); vs2 = vs.Clone(); vs1.TimeEnd = timestart; vs2.TimeStart = timeend; delvss.Add(vs); if (vs1.TimeStart < vs1.TimeEnd) { addvss.Add(vs1); } if (vs2.TimeStart < vs2.TimeEnd) { addvss.Add(vs2); } } else // ([]) if (timestart <= vs.TimeStart && vs.TimeEnd <= timeend) { delvss.Add(vs); } else // ([)] if (timestart <= vs.TimeStart && vs.TimeStart <= timeend && timeend <= vs.TimeEnd) { vs.TimeStart = timeend; if (vs.TimeStart >= vs.TimeEnd) { delvss.Add(vs); } } else // [(]) if (vs.TimeStart <= timestart && timestart <= vs.TimeEnd && vs.TimeEnd <= timeend) { vs.TimeEnd = timestart; if (vs.TimeStart >= vs.TimeEnd) { delvss.Add(vs); } } // []() or ()[] } foreach (ValueSegment vs in delvss) { sdmodel.Remove(vs); } foreach (ValueSegment vs in addvss) { sdmodel.Add(vs); } //sdmodel.SortByTime(); }