public void Execute() { // ToList确保在遍历时可以修改 _oldRowCount = _network.RowCount; _network.RowCount++; var movedElements = _network.GetElements().Where(e => e.Y >= _rowNumber).ToList().OrderBy(x => { return(x.Y); }).Reverse(); var movedVLines = _network.GetVerticalLines().Where(e => e.Y >= _rowNumber).ToList().OrderBy(x => { return(x.Y); }).Reverse(); foreach (var ele in movedElements) { _network.RemoveEle(ele.X, ele.Y); ele.Y++; _network.ReplaceEle(ele); } foreach (var vline in movedVLines) { _network.RemoveVLine(vline.X, vline.Y); vline.Y++; _network.ReplaceVLine(vline); } //_network.INVModel.Setup(_network); // 将梯形图光标移到新生成的行的头部 _network.AcquireSelectRect(); LadderDiagramViewModel ldvmodel = _network.LDVModel; ldvmodel.SelectionRect.X = 0; ldvmodel.SelectionRect.Y = _rowNumber; ldvmodel.ProjectModel.IFacade.NavigateToNetwork( new NavigateToNetworkEventArgs( _network.NetworkNumber, ldvmodel.ProgramName, ldvmodel.SelectionRect.X, ldvmodel.SelectionRect.Y)); }
public void Execute() { _removedElements = new HashSet <BaseViewModel>(_network.GetElements().Where(e => { return((e.Y >= _startRow) && (e.Y <= _startRow + _count - 1)); })); _removedVerticalLines = new HashSet <VerticalLineViewModel>(_network.GetVerticalLines().Where(e => { return((e.Y >= _startRow) && (e.Y <= _startRow + _count - 1)); })); if (_isEndRow) { _removedVerticalLines.UnionWith(_network.GetVerticalLines().Where(e => { return(e.Y == _startRow - 1); })); } Redo(); }
public void Execute() { _removedElements = new HashSet <BaseViewModel>(_network.GetElements().Where(e => e.Y == _rowNumber)); _removedVerticalLines = new HashSet <VerticalLineViewModel>(_network.GetVerticalLines().Where(e => e.Y == _rowNumber)); if (_rowNumber == _network.RowCount - 1) { _removedVerticalLines = new HashSet <VerticalLineViewModel>(_network.GetVerticalLines().Where(e => e.Y == _rowNumber - 1)); } else { _removedVerticalLines = new HashSet <VerticalLineViewModel>(_network.GetVerticalLines().Where(e => e.Y == _rowNumber)); } Redo(); }
private static bool Assert(LadderNetworkViewModel ladderNetwork) { return(ladderNetwork.GetElements().All(x => { if (!x.Assert()) { ladderNetwork.ErrorModels.Clear(); ladderNetwork.ErrorModels.Add(x); } return x.Assert(); }) && CheckVerticalLines(ladderNetwork, ladderNetwork.GetVerticalLines())); }
/// <summary> /// 写入一个梯形图网络 /// </summary> /// <param name="lnvmodel">梯形图网络</param> /// <param name="option">选项</param> static private void Write(LadderNetworkViewModel lnvmodel, int option) { // 头标志和长度 edata.Add(0xfe); int szid = edata.Count(); edata.Add(0x00); edata.Add(0x00); // 是否写入网络注释? if ((option & OPTION_COMMENT) != 0) { Write(lnvmodel.NetworkBrief); } // 行数和每格的行列联通信息 edata.Add(Int32_Low(lnvmodel.RowCount)); int st = edata.Count(); int le = (lnvmodel.RowCount * GlobalSetting.LadderXCapacity) >> 2; edata.AddRange(new byte[le]); foreach (BaseViewModel bvmodel in lnvmodel.GetElements()) { int x = bvmodel.X; int y = bvmodel.Y; int p = y * GlobalSetting.LadderXCapacity + x; int p1 = p >> 2; int p2 = (p & 3) * 2; edata[st + p1] |= (byte)(1 << p2); // 写入一个梯形图元件 Write(bvmodel); } foreach (VerticalLineViewModel vlvmodel in lnvmodel.GetVerticalLines()) { int x = vlvmodel.X; int y = vlvmodel.Y; int p = y * GlobalSetting.LadderXCapacity + x; int p1 = p >> 2; int p2 = (p & 3) * 2 + 1; edata[st + p1] |= (byte)(1 << p2); } int sz = edata.Count() - szid - 2; edata[szid] = Int32_Low(sz); edata[szid + 1] = Int32_High(sz); }
public static XElement CreateXElementByLadderNetwork(LadderNetworkViewModel netmodel) { XElement result = new XElement("Network"); result.SetAttributeValue("Number", netmodel.NetworkNumber); result.SetAttributeValue("RowCount", netmodel.RowCount); result.SetAttributeValue("IsMasked", netmodel.IsMasked); result.SetAttributeValue("IsExpand", netmodel.ladderExpander.IsExpand); XElement briefNode = new XElement("Brief"); XElement descNode = new XElement("Description"); briefNode.SetValue(netmodel.NetworkBrief); descNode.SetValue(netmodel.NetworkDescription); result.Add(briefNode); result.Add(descNode); XElement contentNode = CreateXElementByLadderElementsAndVertialLines(netmodel.GetElements(), netmodel.GetVerticalLines()); result.Add(contentNode); return(result); }
public void Update() { int rowid = 0; RowDefinition rdef; NetworkHeader.Text = String.Format("Network {0:d}", lnvmodel?.NetworkNumber); insts = new List <PLCOriginInst>(); G_Inst.RowDefinitions.Clear(); G_Inst.Children.Clear(); rdef = new RowDefinition(); rdef.Height = new GridLength(20); TextBlock tberr = new TextBlock(); tberr.Background = Brushes.Red; Grid.SetRow(tberr, 0); Grid.SetColumn(tberr, 0); Grid.SetColumnSpan(tberr, 6); G_Inst.RowDefinitions.Add(rdef); G_Inst.Children.Add(tberr); if (lnvmodel == null) { Status = STATUS_ERROR; tberr.Text = App.CultureIsZH_CN() ? "找不到 Network。" : "Cannot found network."; return; } if (IsMasked) { tberr.Background = Brushes.Gray; tberr.Text = String.Format( App.CultureIsZH_CN() ? "Network {0:d} 已被屏蔽!" : "Network {0:d} has been masked!", lnvmodel.NetworkNumber); return; } ismodified = false; this.lchart = GenerateHelper.CreateLadderChart(lnvmodel.GetElements().Union(lnvmodel.GetVerticalLines())); if (lchart.checkOpenCircuit()) { Status = STATUS_OPEN; tberr.Text = String.Format( App.CultureIsZH_CN() ? "Network {0:d} 的梯形图存在断路错误!" : "There have broken circuit in ladder of Network {0:d}.", lnvmodel.NetworkNumber); return; } this.lgraph = lchart.Generate(); if (lgraph.checkShortCircuit()) { Status = STATUS_SHORT; tberr.Text = String.Format( App.CultureIsZH_CN() ? "Network {0:d} 的梯形图存在短路错误!" : "There have short circuit in ladder of Network {0:d}.", lnvmodel.NetworkNumber); return; } if (lgraph.CheckFusionCircuit()) { Status = STATUS_FUSION; tberr.Text = String.Format( App.CultureIsZH_CN() ? "Network {0:d} 的梯形图存在混连错误!" : "There have fusion circuit in ladder of Network {0:d}.", lnvmodel.NetworkNumber); return; } Status = STATUS_ACCEPT; List <PLCInstruction> _insts = lgraph.GenInst(); SortedSet <int> prototypeids = new SortedSet <int>(); foreach (PLCInstruction inst in _insts) { insts.Add(inst.ToOrigin()); if (inst.PrototypeID != -1) { if (prototypeids.Contains(inst.PrototypeID)) { Status = STATUS_FUSION; tberr.Text = String.Format( App.CultureIsZH_CN() ? "Network {0:d} 的梯形图存在混连错误!" : "There have fusion circuit in ladder of Network {0:d}.", lnvmodel.NetworkNumber); return; } prototypeids.Add(inst.PrototypeID); } } G_Inst.RowDefinitions.Clear(); G_Inst.Children.Clear(); foreach (PLCOriginInst inst in insts) { rdef = new RowDefinition(); rdef.Height = new GridLength(20); G_Inst.RowDefinitions.Add(rdef); TextBlock tb = new TextBlock(); tb.Text = rowid.ToString(); tb.Foreground = inst.ProtoType != null ? Brushes.Black : Brushes.Gray; tb.Background = (rowid & 1) == 0 ? Brushes.AliceBlue : Brushes.LightCyan; Grid.SetRow(tb, rowid); Grid.SetColumn(tb, 0); G_Inst.Children.Add(tb); for (int colid = 1; colid <= 6; colid++) { tb = new TextBlock(); tb.Text = inst[colid - 1]; tb.Foreground = inst.ProtoType != null ? Brushes.Black : Brushes.Gray; tb.Background = (rowid & 1) == 0 ? Brushes.AliceBlue : Brushes.LightCyan; Grid.SetRow(tb, rowid); Grid.SetColumn(tb, colid); G_Inst.Children.Add(tb); } rowid++; } rdef = new RowDefinition(); rdef.Height = new GridLength(1, GridUnitType.Star); G_Inst.RowDefinitions.Add(rdef); G_Inst.Children.Add(Cursor); UpdateComment(); }