//检测根元素的非NULL元素集合是否相交 //private static bool IsAllLinkedToRoot(LadderNetworkViewModel ladderNetwork) //{ // var rootElements = ladderNetwork.LadderElements.Values.Where(x => { return x.Type == ElementType.Output; }); // var tempList = new List<BaseViewModel>(); // tempList = GetRootLinkedEles(ladderNetwork, rootElements.ElementAt(0)); // for (int x = 1; x < rootElements.Count(); x++) // { // tempList = tempList.Intersect(GetRootLinkedEles(ladderNetwork,rootElements.ElementAt(x))).ToList(); // if (tempList.Count == 0) // { // ladderNetwork.ErrorModels.Clear(); // ladderNetwork.ErrorModels.Add(rootElements.First());//add error element // return false; // } // } // return true; //} //得到与根元素相关的最后一个非NULL元素集合 //private static List<BaseViewModel> GetRootLinkedEles(LadderNetworkViewModel ladderNetwork,BaseViewModel rootElement) //{ // ladderNetwork.ClearSearchedFlag(); // List<BaseViewModel> tempList = new List<BaseViewModel>(); // Queue<BaseViewModel> tempQueue = new Queue<BaseViewModel>(rootElement.NextElements); // while (tempQueue.Count > 0) // { // var ele = tempQueue.Dequeue(); // if (!ele.IsSearched) // { // ele.IsSearched = true; // if (ele.NextElements.Exists(x => { return x.Type == ElementType.Null; })) // { // tempList.Add(ele); // } // else // { // foreach (var item in ele.NextElements) // { // tempQueue.Enqueue(item); // } // } // } // } // return tempList; //} private static bool CheckElements(LadderNetworkViewModel ladderNetwork) { var tempElements = ladderNetwork.LadderElements.ToList(); for (int i = 0; i <= ladderNetwork.GetMaxY(); i++) { var tempList = tempElements.Where(x => { return(x.Y == i); }).ToList(); if (tempList.Count != 0 && tempList.Where(x => { return(x.Type == ElementType.Output || x.X == 0); }).Count() == 0) { tempList = tempElements.Where(x => { return(x.Y == i && x.Type == ElementType.HLine); }).ToList(); for (int j = 0; j < tempList.Count; j++) { if (!CheckHElement(ladderNetwork, tempList[j])) { return(false); } } } } return(true); }
/// <summary> /// 删除移动后多余的空行 /// </summary> /// <param name="ladderNetwork"></param> private static void RemoveEmptyLines(LadderNetworkViewModel ladderNetwork) { ladderNetwork.RowCount = ladderNetwork.GetMaxY() + 1; }