public GlobalLine(Signal signal, MainWindow wnd) { signal.GLines.Add(this); this.wnd = wnd; CreateCMSignal(); CreateItems(); TVIName.ContextMenu = CMSignal; TVIName.Header = signal.Name; TVIName.Style = (Style)wnd.FindResource(Signal.Modes.ToStr(signal.Mode)); wnd.TVSignals.Items.Add(TVIName); DLine = new SignalLine(signal, TVILine, this, wnd); }
public SignalLine(Signal signal, TreeViewItem LBILine, GlobalLine GLine, MainWindow Wnd) { Type = DrawingLine.Types.Signal; wnd = Wnd; Parent = GLine; //------------------- Creating Canvas ------------------------------------ CanLine = new Canvas(); CanLine.Height = Settings.LineHeight -2; CanLine.VerticalAlignment = VerticalAlignment.Top; CanLine.HorizontalAlignment = HorizontalAlignment.Stretch; CanLine.Background = Brushes.Transparent; CanLine.Margin = new Thickness(-18, 0, 0, 0); LBILine.Header = CanLine; //------------------------------------------------------------------------- // Context Menu MenuItem MITemp = new MenuItem { Header = "0"}; MITemp.Click += MISetZero_Click; CMCanLine.Items.Add(MITemp); MITemp = new MenuItem { Header = "1" }; MITemp.Click += MISetOne_Click; CMCanLine.Items.Add(MITemp); MITemp = new MenuItem { Header = "#" }; MITemp.Click += MISetHash_Click; CMCanLine.Items.Add(MITemp); MITemp = new MenuItem { Header = "*" }; MITemp.Click += MISetStar_Click; CMCanLine.Items.Add(MITemp); MITemp = new MenuItem { Header = "Z" }; MITemp.Click += MISetZ_Click; CMCanLine.Items.Add(MITemp); MITemp = new MenuItem { Header = "X" }; MITemp.Click += MISetX_Click; CMCanLine.Items.Add(MITemp); MITemp = new MenuItem { Header = "Удалить" }; MITemp.Click += MIDelete_Click; CMCanLine.Items.Add(MITemp); CanLine.ContextMenu = CMCanLine; //Signal = signal; Source = signal; //------------------------------------------------------------------------- RenewContextMenuVisibility(); Gen = Project.Gens.Pot; //Redraw(); }
public static void OpenDgm() { var xmlDocument = new XmlDocument { XmlResolver = null }; xmlDocument.Load(Project.ProjectFilePath); //Gens XmlNodeList xnGens = xmlDocument.SelectNodes("/Project/Generators/Generator"); foreach (XmlNode xnGen in xnGens) { Project.Gens.Add(new Generator(xnGen["Name"].InnerText, Generator.FromSTR(xnGen["Type"].InnerText), Convert.ToInt32(xnGen["Sdw"].InnerText), Convert.ToInt32(xnGen["Dlit"].InnerText))); } //Strobs XmlNodeList xnStrobs = xmlDocument.SelectNodes("/Project/Strobs/Strob"); foreach (XmlNode xnStrob in xnStrobs) { Project.Strobs.Add(new Strob(xnStrob["Name"].InnerText, Convert.ToInt32(xnStrob["Sdw"].InnerText), Convert.ToInt32(xnStrob["Dlit"].InnerText))); } //Items int Type; List<Change> Changes; List<Signal> Signals; Signal Sig; //XmlNodeList XmlNodeList xnSignals; XmlNodeList xnChanges; XmlNodeList xnPeriods; XmlNodeList xnItems = xmlDocument.SelectNodes("/Project/SourceItems/Item"); foreach (XmlNode xnItem in xnItems) { Type = Convert.ToInt32(xnItem["Type"].InnerText); //Type = Convert.ToInt32(xnItem["Type"].InnerText); switch (Type) { case SourceItem.Types.Signal: Sig = new Signal(xnItem["Name"].InnerText, Convert.ToInt32(xnItem["Mode"].InnerText)); xnChanges = xnItem.SelectNodes("Changes/Change"); foreach (XmlNode xnChange in xnChanges) { Sig.ChangeAdd(new Change(Convert.ToInt32(xnChange["Takt"].InnerText), Convert.ToInt32(xnChange["Value"].InnerText))); } xnPeriods = xnItem.SelectNodes("Periods/Period"); foreach (XmlNode xnPeriod in xnPeriods) { Changes = new List<Change>(); xnChanges = xnPeriod.SelectNodes("Changes/Change"); foreach (XmlNode xnChange in xnChanges) { Changes.Add(new Change(Convert.ToInt32(xnChange["Takt"].InnerText), Convert.ToInt32(xnChange["Value"].InnerText))); } Sig.Periods.Add(new Period(Convert.ToInt32(xnPeriod["Beg"].InnerText), xnPeriod["N"].InnerText, Convert.ToInt32(xnPeriod["Per"].InnerText), Changes)); } Project.Items.Add(Sig); break; case SourceItem.Types.Bus: Signals = new List<Signal>(); xnSignals = xnItem.SelectNodes("Signals/Signal"); foreach (XmlNode xnSignal in xnSignals) { Sig = new Signal(xnSignal["Name"].InnerText, Convert.ToInt32(xnSignal["Mode"].InnerText)); xnChanges = xnSignal.SelectNodes("Changes/Change"); foreach (XmlNode xnChange in xnChanges) { Sig.ChangeAdd(new Change(Convert.ToInt32(xnChange["Takt"].InnerText), Convert.ToInt32(xnChange["Value"].InnerText))); } xnPeriods = xnItem.SelectNodes("Periods/Period"); foreach (XmlNode xnPeriod in xnPeriods) { Changes = new List<Change>(); xnChanges = xnPeriod.SelectNodes("Changes/Change"); foreach (XmlNode xnChange in xnChanges) { Changes.Add(new Change(Convert.ToInt32(xnChange["Takt"].InnerText), Convert.ToInt32(xnChange["Value"].InnerText))); } Sig.Periods.Add(new Period(Convert.ToInt32(xnPeriod["Beg"].InnerText), xnPeriod["N"].InnerText, Convert.ToInt32(xnPeriod["Per"].InnerText), Changes)); } Signals.Add(Sig); } Project.Items.Add(new Bus(xnItem["Name"].InnerText, Signals, Convert.ToInt32(xnItem["N1"].InnerText), Convert.ToInt32(xnItem["N2"].InnerText))); break; case SourceItem.Types.Group: // break; } } MainWindow Window; XmlNodeList xnWindows = xmlDocument.SelectNodes("/Project/Windows/Window"); XmlNodeList xnMarkers; XmlNodeList xnLines; foreach (XmlNode xnWindow in xnWindows) { Window = new MainWindow { WndName = xnWindow["Name"].InnerText, TaktCount = Convert.ToInt32(xnWindow["TaktCount"].InnerText), Width = Convert.ToDouble(xnWindow["Width"].InnerText), Height = Convert.ToDouble(xnWindow["Height"].InnerText) }; App.Windows.Add(Window); Window.Show(); Window.GSVSignals.ColumnDefinitions[0].Width = new GridLength(Convert.ToDouble(xnWindow["GSVSignals0"].InnerText)); Window.GSVSignals.ColumnDefinitions[1].Width = new GridLength(Convert.ToDouble(xnWindow["GSVSignals1"].InnerText)); Window.Change_Workspace(Convert.ToInt32(xnWindow["BeginTakt"].InnerText), Convert.ToInt32(xnWindow["EndTakt"].InnerText)); Window.CBValueMarker.SelectedIndex = Convert.ToInt32(xnWindow["CBValueMarkerIndex"].InnerText); //Markers xnMarkers = xnWindow.SelectNodes("Markers/Marker"); int i = 0; foreach (XmlNode xnMarker in xnMarkers) { switch (i) { case 0: // CursorLine Window.CursorLine.Name = xnMarker["Name"].InnerText; Window.CursorLine.Value = Convert.ToInt32(xnMarker["Value"].InnerText); Window.CursorLine.brush = (Brush)new System.Windows.Media.BrushConverter().ConvertFromString(xnMarker["Brush"].InnerText); break; case 1: //BaseLine Window.BaseLine.Name = xnMarker["Name"].InnerText; Window.BaseLine.Value = Convert.ToInt32(xnMarker["Value"].InnerText); Window.BaseLine.brush = (Brush)new System.Windows.Media.BrushConverter().ConvertFromString(xnMarker["Brush"].InnerText); break; case 2: // EndLine Window.EndLine.Name = xnMarker["Name"].InnerText; Window.EndLine.Value = Convert.ToInt32(xnMarker["Value"].InnerText); Window.EndLine.brush = (Brush)new System.Windows.Media.BrushConverter().ConvertFromString(xnMarker["Brush"].InnerText); break; default: //Markers Window.Markers.Add(new Marker(xnMarker["Name"].InnerText, Marker.SimpleMarker, Convert.ToInt32(xnMarker["Value"].InnerText), Window)); Window.Markers.Last().brush = (Brush)new System.Windows.Media.BrushConverter().ConvertFromString(xnMarker["Brush"].InnerText); break; } i++; } //Lines xnLines = xnWindow.SelectNodes("Lines/Line"); foreach (XmlNode xnLine in xnLines) { Type = Convert.ToInt32(xnLine["Type"].InnerText); switch (Type) { case DrawingLine.Types.Signal: Window.Lines.Add(Project.Items.Find(xnLine["SourceName"].InnerText) as Signal, Window); (Window.Lines.Last.DLine as SignalLine).Gen = Project.Gens.Find(xnLine["GenName"].InnerText); break; case DrawingLine.Types.Bus: Window.Lines.Add(Project.Items.Find(xnLine["SourceName"].InnerText) as Bus, Window); (Window.Lines.Last.DLine as BusLine).Gen = Project.Gens.Find(xnLine["GenName"].InnerText); break; } } } }
public void Add(Signal signal, MainWindow wnd) { GlobalLines.Add(new GlobalLine(signal, wnd)); }
public Signal getDrawChanges(int TaktCount, int BeginTakt, int EndTakt) { Signal DrawChangesSignal = new Signal(); if (Signal.Changes.Count == 0) return DrawChangesSignal; ChPrev = Signal.Changes[0].Copy(); DrawChangesSignal.Changes.Clear(); foreach (Change ch in Signal.Changes) { if ((ch.Takt >= BeginTakt) && (ch.Takt <= EndTakt)) { DrawChangesSignal.ChangeAdd(ch.Copy()); } else if ((ch.Takt < BeginTakt) && (ch.Takt > ChPrev.Takt)) ChPrev = ch.Copy(); } int n, takt; foreach (Period p in Signal.Periods) { n = (p.N == "&") ? ((TaktCount - p.Beg) / p.Per + 1) : Convert.ToInt32(p.N); for (int i = 0; i < n; i++) { foreach (Change ch in p.Changes) { takt = p.Beg + ch.Takt + p.Per * i; if ((takt >= BeginTakt) && (takt <= EndTakt)) DrawChangesSignal.ChangeAdd(new Change(takt, ch.Value)); else if ((takt < BeginTakt) && (takt > ChPrev.Takt)) ChPrev = new Change(takt, ch.Value); } } } if (DrawChangesSignal.Changes.Count == 0) DrawChangesSignal.ChangeAdd(ChPrev); return DrawChangesSignal; }
public override void Redraw() { int i, j, BeginTakt = wnd.BeginTakt, EndTakt = wnd.EndTakt; Sig = Signal;// getDrawChanges(wnd.TaktCount, BeginTakt, EndTakt); ChPrev = Sig.Changes[0]; Canvas Can = CanLine; int TTakt = Project.TTakt; int TaktsDraw = EndTakt - BeginTakt + 1; int TimeWidth = TaktsDraw * Project.TTakt; CanWidth = (Can.Parent as TreeViewItem).ActualWidth; if (CanWidth <= 0) CanWidth = wnd.LBSigCans.ActualWidth; double TaktWidth = CanWidth * 1.0 / TaktsDraw * 1.0; double pixK = CanWidth * 1.0 / TimeWidth * 1.0; double timeK = TimeWidth * 1.0 / CanWidth * 1.0; int LineHeight = Settings.LineHeight; for (i = 0; i < PChangesGens.Count; i++) { Can.Children.Remove(PChangesGens[i]); } //Can.Children.Clear(); PChangesGens.Clear(); foreach (PeriodVisual pv in PeriodVisuals) { wnd.GSVSignals.Children.Remove(pv.Can); } PeriodVisuals.Clear(); //Change ChCurrent; int CurrentVal = ChPrev.Value; double CurrentX = 0; Polyline PLine; PeriodVisual Pv; foreach (Period p in Signal.Periods) { Pv = new PeriodVisual(p, Parent, wnd); Pv.Redraw(); PeriodVisuals.Add(Pv); } int GEN_DRAW_TYPE = (Gen.Type == Generator.RZ) ? Generator.R0 : Gen.Type; // заменяет тип RZ на R0 (для упрощения switch) switch (GEN_DRAW_TYPE) { case Generator.DNRZ: for (i=0; i<Sig.Changes.Count; i++) { PLine = new Polyline(); PLine.StrokeThickness = (isSelected) ? Settings.SelectedThickness : Settings.SignalThickness; PLine.Stroke = Sig.ChangeBrushes[CurrentVal]; PLine.Points.Add(new Point { X = CurrentX - 1, Y = Change.GetHeightDelta(CurrentVal, LineHeight) }); CurrentX = (Sig.Changes[i].Takt - BeginTakt) * TaktWidth; if (CurrentX < 0) CurrentX = 0; PLine.Points.Add(new Point { X = CurrentX, Y = Change.GetHeightDelta(CurrentVal, LineHeight) }); CurrentVal = Sig.Changes[i].Value; PLine.Points.Add(new Point { X = CurrentX, Y = Change.GetHeightDelta(CurrentVal, LineHeight) }); PChangesGens.Add(PLine); } PLine = new Polyline(); PLine.StrokeThickness = (isSelected) ? Settings.SelectedThickness : Settings.SignalThickness; PLine.Stroke = Sig.ChangeBrushes[CurrentVal]; PLine.Points.Add(new Point { X = CurrentX, Y = Change.GetHeightDelta(CurrentVal, LineHeight) }); PLine.Points.Add(new Point { X = CanWidth, Y = Change.GetHeightDelta(CurrentVal, LineHeight) }); PChangesGens.Add(PLine); foreach (Polyline P in PChangesGens) Can.Children.Add(P); return; case Generator.NRZ: return; case Generator.R0: return; case Generator.R1: return; } }
// in progress private void MIFromKappa_Click(object sender, RoutedEventArgs e) { try { Microsoft.Win32.OpenFileDialog OFD = new Microsoft.Win32.OpenFileDialog(); OFD.Filter = "KAPPA файлы(*.kap)|*.kap|Все файлы(*.*)|*.*"; OFD.DefaultExt = "kap"; OFD.AddExtension = true; string content; Regex regexTTakt = new Regex(@"T_TAKT\s*=\s*(\d+);"); Regex regexGens = new Regex(@"((?:GEN_|Gen_|gen)\d+):(?:(?:\s|\t)+)(rz|nrz|RZ|NRZ|Rz|Nrz)\s*(?:((sdw|Sdw|SDW|dlit|Dlit|DLIT)\s*=\s*(\d+))(?:\s*))+;"); Regex regexStrobs = new Regex(@"((?:STROB_|Strob_|strob_)\d+):(?:(?:\s|\t)+)(?:((sdw|Sdw|SDW|dlit|Dlit|DLIT)=(\d+))(?:\s*))+;"); Regex regexSigs = new Regex(@"\s([^\d\W][^\W\(\)\[\]]*)\s*(\[(?:,*(\w+))+\])*(?:(?:(?:\s*)|(?:\r\n\t))(?:(\d+)\s*=\s*([01#*]))|(\s*\((?:\s*(PER|BEG|N|p|b|n|P|B|per|beg|Per|Beg)\s*=\s*((?:\d+)|&)){3}(?:\s(\d+)\s*=\s*([01#*]))+\)))*(?:\s*);"); Regex regexPer = new Regex(@"(?:\s*(PER|BEG|N|p|b|n|P|B|per|beg|Per|Beg)\s*=\s*((?:\d+)|&)){3}(?:\s(\d+)\s*=\s*([01#*]))+"); Regex regexBuses = new Regex(@"(\w+)\s*(?:\((\d+)\s*:\s*(\d+)\))\s*(?:\[(?:,*(\w+))+\])*\s*(inv|INV|Inv)*\s*(?:\s*(\d+)\s*=\s*((?:[01#*])|(?:[bvh](?:\w|%)+)|(?:""(?:\w|[%*#])+)""))+\s*;"); /* ! */ Regex regexGroup = new Regex(@"\(([+-]?(CYC|FULL|cyc|full|Cyc|Full)):(?:\s*(PER|BEG|N|p|b|n|P|B|per|beg|Per|Beg)=((\d+)|&)){3}(\s*(\w+))+\s*,\s*(INIT|init|Init)\s*=\s*(([01#*])*)\)"); if (OFD.ShowDialog() == true) { int i, MaxTakt = 14; // 19(standart) - 5 Project.Gens.Clear(); Project.Gens.Add(new Generator("Pot", Generator.DNRZ, 0, 0)); Project.Strobs.Clear(); Project.Items.Clear(); string tepmstr; StreamReader file = new StreamReader(OFD.FileName, Encoding.UTF8); content = file.ReadToEnd(); file.Close(); Match TTaktMatch = regexTTakt.Match(content); if (TTaktMatch.Success) Project.TTakt = Convert.ToInt32(TTaktMatch.Groups[1].Value); Match GensMatch = regexGens.Match(content); string GenName; int GenType, GenSdw, GenDlit; while (GensMatch.Success) { GenName = GensMatch.Groups[1].Value; GenType = Generator.FromStr_KAPPA(GensMatch.Groups[2].Value); GenSdw = 0; GenDlit = 0; for (i = 0; i < GensMatch.Groups[4].Captures.Count; i++) { tepmstr = GensMatch.Groups[4].Captures[i].Value; if (tepmstr.ToLower() == "sdw") GenSdw = Convert.ToInt32(GensMatch.Groups[5].Captures[i].Value); if (tepmstr.ToLower() == "dlit") GenDlit = Convert.ToInt32(GensMatch.Groups[5].Captures[i].Value); } Project.Gens.Add(new Generator(GenName, GenType, GenSdw, GenDlit)); GensMatch = GensMatch.NextMatch(); } Match StrobsMatch = regexStrobs.Match(content); string StrobName; int StrobSdw, StrobDlit; while (StrobsMatch.Success) { StrobName = StrobsMatch.Groups[1].Value; StrobSdw = 0; StrobDlit = 0; for (i = 0; i < StrobsMatch.Groups[3].Captures.Count; i++) { tepmstr = StrobsMatch.Groups[3].Captures[i].Value; if (tepmstr.ToLower() == "sdw") StrobSdw = Convert.ToInt32(StrobsMatch.Groups[4].Captures[i].Value); if (tepmstr.ToLower() == "dlit") StrobDlit = Convert.ToInt32(StrobsMatch.Groups[4].Captures[i].Value); } Project.Strobs.Add(new Strob(StrobName, StrobSdw, StrobDlit)); StrobsMatch = StrobsMatch.NextMatch(); } Match SigsMatch = regexSigs.Match(content); Match PerMatch; Signal TSignal; List<Change> PerChs; while (SigsMatch.Success) { TSignal = new Signal(); TSignal.Name = SigsMatch.Groups[1].Value; if (SigsMatch.Groups[2].Success) { } for (i = 0; i < SigsMatch.Groups[4].Captures.Count; i++) { int Takt = Convert.ToInt32(SigsMatch.Groups[4].Captures[i].Value); TSignal.ChangeAdd(new Change(Takt, Change.FromStr(SigsMatch.Groups[5].Captures[i].Value))); if (Takt > MaxTakt) MaxTakt = Takt; } int p = 0, b = 0; string n = "&"; for (i = 0; i < SigsMatch.Groups[6].Captures.Count; i++) { PerMatch = regexPer.Match(SigsMatch.Groups[6].Captures[i].Value); // 0 - All; 1 - pbn; 2 - pbn values; 3 - takt 4- val for (int j = 0; j < 3; j++) { if ((PerMatch.Groups[1].Captures[j].Value.ToLower() == "per") || (PerMatch.Groups[1].Captures[j].Value.ToLower() == "p")) p = Convert.ToInt32(PerMatch.Groups[2].Captures[j].Value); else if ((PerMatch.Groups[1].Captures[j].Value.ToLower() == "beg") || (PerMatch.Groups[1].Captures[j].Value.ToLower() == "b")) b = Convert.ToInt32(PerMatch.Groups[2].Captures[j].Value); else n = PerMatch.Groups[2].Captures[j].Value; } PerChs = new List<Change>(); for (int j = 0; j < PerMatch.Groups[3].Captures.Count; j++) { int Takt = Convert.ToInt32(PerMatch.Groups[3].Captures[j].Value); PerChs.Add(new Change(Takt, Change.FromStr(PerMatch.Groups[4].Captures[j].Value))); if (Takt > MaxTakt) MaxTakt = Takt; } TSignal.Periods.Add(new Period(b, n, p, PerChs)); PerChs = null; } Project.Items.Add(TSignal); Lines.Add(Project.Items.Last as Signal, this); SigsMatch = SigsMatch.NextMatch(); } Match BusesMatch = regexBuses.Match(content); string BusName; int n1, n2; int t; string v; List<BusChange> BChs; while (BusesMatch.Success) { BusName = BusesMatch.Groups[1].Value; n1 = Convert.ToInt32(BusesMatch.Groups[2].Value); n2 = Convert.ToInt32(BusesMatch.Groups[3].Value); // 4 - Gen 5 - inv 6-changes takt 7 -[01*#] 8-[bvh] 9 - "___" BChs = new List<BusChange>(); for (i = 0; i < BusesMatch.Groups[6].Captures.Count; i++) { t = Convert.ToInt32(BusesMatch.Groups[6].Captures[i].Value); v = BusesMatch.Groups[7].Captures[i].Value.Replace("\"", ""); BChs.Add(new BusChange(t, v, n2 - n1 + 1)); } List<Signal> TempListSignal = new List<Signal>(); for (int j=n1; j<=n2; j++) TempListSignal.Add(new Signal(BusName+j.ToString(), Signal.Modes.Unknown)); Project.Items.Add(new Bus(BusName, TempListSignal, n1, n2)); Lines.Add(Project.Items.Last as Bus, n1, n2, BChs, this); BusesMatch = BusesMatch.NextMatch(); } Match GroupsMatch = regexGroup.Match(content); while (GroupsMatch.Success) { //MessageBox.Show(GroupsMatch.Groups[0].Value.ToString()); GroupsMatch = GroupsMatch.NextMatch(); } Change_Workspace(0, MaxTakt + 5); } //Lines.ResetLBValue(ValueMarker); } catch (Exception Ex) { Error Err = new Error(0, FileNameForErr, ClassNameForErr, "MIFromKappa_Click", Ex.ToString()); if (App.isDebugMode) MessageBox.Show(Err.ToString()); else Error.Add(Err); } }
public void Add(Signal signal) { Items.Add(new Signal(SetName(signal.Name), signal.Mode, signal.Changes, signal.Periods)); }
public Signal Copy() { Signal Sig = new Signal(Name, Mode); Sig.Changes.Clear(); foreach (Change ch in Changes) Sig.Changes.Add(ch.Copy()); foreach (Period per in Periods) Sig.Periods.Add(per.Copy()); return Sig; }