private ISet <TNode> getPowedNodes() { ISet <TNode> cfs = new HashSet <TNode>(); ISet <string> labels = new HashSet <string>(); Action <INotifyComponentChanged> action = p => { labels.Add(p.getHeadNode().Equal); if (p.getTailNode() != null) { labels.Add(p.getTailNode().Equal); } }; addPowedLabels(vccToGndRoutes, action); addPowedLabels(cfToGndRoutes, action); addPowedLabels(cfToVccRoutes, action); AppProject app = AppProject.GetInstance(); foreach (string label in labels) { if (label != "GND") { var query = app.Equals[label].Where(p => p.PartType.Contains("接口连接器") && p.TNType == TerminalType.Normal); foreach (var nd in query) { cfs.Add(nd); } } } return(cfs); }
private Simulation() { AppProject app = AppProject.GetInstance(); IShortBranchTreeGenerator graph = new DigraphBuilder(); graph.buildRoutes(); if (app.VccToGnd == null) { this.VccToGndView = graph.getVccToGndBranch(); } else { this.VccToGndView = app.VccToGnd; } if (app.GndToCF == null) { this.CFToGndView = graph.getCFToGndBranch(); } else { this.CFToGndView = app.GndToCF; } if (app.VccToCF == null) { this.CFToVccView = graph.getVccToCFBranch(); } else { this.CFToVccView = app.VccToCF; } load(); }
private void showRoute() { IsDoubleClick = false; AppProject pro = AppProject.GetInstance(); TestBranch br = null; if (source.Table.TableName == "地线导通测试") { br = pro.getGndBranch(SelectedIndex); } else if (source.Table.TableName == "110V导通测试") { br = pro.getVccBranch(SelectedIndex); } else if (source.Table.TableName == "普通导通测试") { br = pro.getNormalBranch(SelectedIndex); } else if (source.Table.TableName == "测试回路") { br = pro.getLoopBranch(SelectedIndex); } else if (source.Table.TableName == "逻辑测试") { br = pro.getLogicBranch(SelectedIndex); } if (br != null) { List <UIElement> elements = BranchFactory.convertToUIElement(br.Branch); Messenger.Default.Send <List <UIElement> >(elements, "ShowBranchPicture"); } Console.WriteLine(source.Table.TableName); }
/// <summary> /// 列表显示所有的等效节点 /// </summary> private void showLabels(string label) { ISet <TNode> nodes = AppProject.GetInstance().Equals[label]; Messenger.Default.Send <Tuple <string, DataView> >( Tuple.Create <string, DataView>(label, addEqualCollection(nodes, label)) , "DisplayTestBranch"); }
public CFDisplay() { cfs = new Dictionary <TNode, CFPair>(); AppProject app = AppProject.GetInstance(); foreach (TNode node in app.CFNodes) { cfs[node] = new CFPair(node); } }
private void alignBranchNode(ISet <ShortBranchNode> expandNodes, BranchView view) { foreach (ShortBranchNode node in view.LabelToBranch.Values) { if (node == null) { continue; } var filterNodes = expandNodes.Where(p => node.EndName == p.EndName).ToList(); if (filterNodes.Count == 0 || filterNodes.Count == 1) { continue; } double maxWidth = double.MinValue; foreach (ShortBranchNode br in filterNodes) { if (br.Uis[br.Uis.Count - 1].Pos.X > maxWidth) { maxWidth = br.Uis[br.Uis.Count - 1].Pos.X; } } foreach (ShortBranchNode br in filterNodes) { double start = br.Uis[br.Uis.Count - 1].Pos.X; TNode head = br.Uis[br.Uis.Count - 1].Info.getHeadNode(); TNode tail = br.Uis[br.Uis.Count - 1].Info.getTailNode(); for (double x = start; x < maxWidth; x++) { INotifyComponentChanged info = new ComponentViewModel(Tuple.Create <TNode, TNode>(head, tail), ComponentType.Blank); TNodeUI ui = new TNodeUI(info, false, view.Observer); ui.Pos = new Point(x + 1, br.Uis[br.Uis.Count - 1].Pos.Y); br.Uis.Add(ui); } moveRight(br.Nodes, maxWidth - start); } double maxy = filterNodes.Max(p => p.Uis[p.Uis.Count - 1].Pos.Y); double miny = filterNodes.Min(p => p.Uis[p.Uis.Count - 1].Pos.Y); TNode tm = AppProject.GetInstance().Equals[node.EndName].First(); INotifyComponentChanged _info = new ComponentViewModel(Tuple.Create <TNode, TNode>(tm, null), ComponentType.Blank); TNodeUI nui = new TNodeUI(_info, false, view.Observer); nui.Pos = new Point(node.Uis[node.Uis.Count - 1].Pos.X + 1, node.Uis[node.Uis.Count - 1].Pos.Y); List <TNodeUI> uis = new List <TNodeUI>() { nui }; ShortBranchNode nnode = new ShortBranchNode(uis, node, node.EndName); foreach (ShortBranchNode nd in node.Nodes) { nnode.Nodes.Add(nd); } moveRight(node.Nodes, 1); node.Nodes.Clear(); node.Nodes.Add(nnode); } }
/// <summary> /// 整理出可测的支路 /// </summary> private void loadTestBranch() { List <LogicCircuit> testBranch = new List <LogicCircuit>(); AppProject app = AppProject.GetInstance(); foreach (var route in cfToVccRoutes) { bool needTest = route.Exists(p => p.CptType == ViewModel.ComponentType.ContactOpen); if (needTest) { testBranch.Add(new LogicCircuit(route, route[route.Count - 1].getHeadNode(), route[0].getHeadNode().Equal)); } } foreach (var route in vccToGndRoutes) { var cpt = route.FirstOrDefault(p => p.CptType == ViewModel.ComponentType.ContactOpen); if (cpt != null) { int index = route.IndexOf(cpt); for (int i = index + 1; i < route.Count; i++) { TNode cf = app.IsCFEqual(route[i].getHeadNode().Equal); if (cf != null && cf.Equal != "GND") { testBranch.Add(new LogicCircuit(route.GetRange(0, i), cf, route[0].getHeadNode().Equal)); break; } } } } foreach (var route in cfToGndRoutes) { var cpt = route.LastOrDefault(p => p.CptType == ViewModel.ComponentType.ContactOpen); if (cpt != null) { int index = route.IndexOf(cpt); for (int i = index; i >= 0; i--) { TNode cf = app.IsCFEqual(route[i].getHeadNode().Equal); if (cf != null && cf.Equal != "GND") { testBranch.Add(new LogicCircuit(route.GetRange(i, route.Count - i), cf, route[route.Count - 1].getHeadNode().Equal)); break; } } } } this.testBranch = testBranch.AsReadOnly(); }
private bool CanPowDown(string label) { if (string.IsNullOrEmpty(label)) { return(false); } else { ISet <string> pows = Simulation.getInstance().getPows(); HashSet <TNode> nodes = (HashSet <TNode>)AppProject.GetInstance().Equals[label]; return(ModeManager.getAuthority().canOperate() && (label.Equals("DC110V") || nodes.Any(p => p.PartType.StartsWith("接口连接器"))) && pows.Contains(label)); } }
/// <summary> /// 去除掉已经在VccToGnd中出现过的支路 /// </summary> private ISet <ShortBranchNode> removeRedundentRoute(ISet <ShortBranchNode> nodes, ISet <ShortBranchNode> total) { List <List <ShortBranchNode> > routes = getAllRoutes(nodes); AppProject app = AppProject.GetInstance(); if (app.VccToGnd == null) { app.VccToGnd = getVccToGndBranch(); } ISet <ShortBranchNode> allNodes = expandBranch(app.VccToGnd.Nodes); ISet <INotifyComponentChanged> allcpts = new HashSet <INotifyComponentChanged>(); foreach (ShortBranchNode brNode in allNodes) { foreach (TNodeUI nd in brNode.Uis) { allcpts.Add(nd.Info); } } List <ShortBranchNode> bans = new List <ShortBranchNode>(); foreach (List <ShortBranchNode> rt in routes) { List <INotifyComponentChanged> infos = new List <INotifyComponentChanged>(); rt.ForEach(p => p.Uis.ForEach(ui => infos.Add(ui.Info))); infos.RemoveAt(infos.Count - 1); if (infos.All(p => allcpts.FirstOrDefault(cpt => ComponentViewModel.compare(cpt, p)) != null )) { bans.Add(rt[0]); rt.ForEach(p => total.Remove(p)); } } bans.ForEach(p => nodes.Remove(p)); return(nodes); }
public BranchView getCFToGndBranch() { #region 将树状结构的节点放到一维集合中 BranchView rst = getNodes(gndNodes[0].Equal, label => label == "DC110V"); ISet <ShortBranchNode> brs = rst.Nodes; ShortBranchNode head = brs.First().Parent; ISet <ShortBranchNode> total = expandBranch(brs); #endregion #region 过滤出所有总负到测试点的通路 AppProject pro = AppProject.GetInstance(); ISet <string> remain = new HashSet <string>(); foreach (ShortBranchNode node in total) { if (node.Nodes.Count == 0) { bool mark = false; foreach (TNode tnode in pro.Equals[node.EndName]) { if (tnode.PartType.StartsWith("接口连接器")) { mark = true; break; } } if (mark) { ShortBranchNode tp = node; while (tp != null) { remain.Add(tp.EndName); tp = tp.Parent; } } } } //先把叶节点中末端是测试点的标注出来 bool next = true; while (next) { next = false; List <ShortBranchNode> temp = new List <ShortBranchNode>(); foreach (ShortBranchNode node in total) { if (node.Nodes.Count == 0) { bool mark = false; foreach (TNode tnode in pro.Equals[node.EndName]) { if (tnode.PartType.StartsWith("接口连接器")) { mark = true; if (!node.Uis[node.Uis.Count - 1].Info.isCFNode()) { INotifyComponentChanged info = new ComponentViewModel(Tuple.Create <TNode, TNode>(tnode, null), ComponentType.Terminal); node.Uis.Add(new TNodeUI(info, false, rst.Observer)); } break; } } if (!mark) { if (!remain.Contains(node.EndName)) { node.remove(); temp.Add(node); next = true; } else { ShortBranchNode tp = node; while (tp != null) { remain.Add(tp.EndName); tp = tp.Parent; } } } } } foreach (ShortBranchNode node in temp) { total.Remove(node); } } rst.Nodes = removeRedundentRoute(rst.Nodes, total);//去除冗余的支路 #endregion #region 为短支路树计算位置信息 ISet <ShortBranchNode> data = new HashSet <ShortBranchNode>(total.Where(p => p.Parent == head).ToList()); CalculatePosition(data, 0, 0); if (rst.Type) { alignBranchNode(total, rst); } rst.Nodes = data; #endregion rst.GraphType = GraphType.CFToGndGraph; rst.GraphName = "测试点至总负布线图"; return(rst); }
/// <summary> /// 获得从总正出发,总负截止的所有拼接支路 /// </summary> private BranchView getNodes(string headEqual, Func <string, bool> filter) { ComponentVMObserver _observer = new ComponentVMObserver(); AppProject pro = AppProject.GetInstance(); ((List <ShortBranch>)pro.Shorts).ForEach(p => p.HasIncluded = false); LinkedList <string> labels = new LinkedList <string>(); IDictionary <string, ShortBranchNode> allLabels = new Dictionary <string, ShortBranchNode>(); labels.AddLast(headEqual); ShortBranchNode head = new ShortBranchNode(null, null, headEqual); allLabels.Add(headEqual, head); #region 广度遍历得到短支路的树结构 while (labels.First != null) { string label = labels.First.Value; labels.RemoveFirst(); if (filter(label)) { continue; } TNodeUI item1 = null, item2 = null; foreach (ShortBranch br in pro.Shorts) { if (!br.HasIncluded) { if (br.HeadEqualNum == label || br.TailEqualNum == label) { // if (br.HeadEqualNum == "Net203" || br.TailEqualNum == "Net203") // { // // } List <TNodeUI> uis = new List <TNodeUI>(); List <TNode> brNodes = br.Branch; if (br.TailEqualNum == label) { brNodes.Reverse(); } int i = 0; while (i < brNodes.Count) { TNodeUI ui = null; if (i + 1 < brNodes.Count && brNodes[i].Brother == brNodes[i + 1]) { ui = BranchFactory.convert(brNodes[i], brNodes[i + 1], _observer); if (i == 0) { item2 = ui; } uis.Add(ui); i += 2; } else { ui = BranchFactory.convert(brNodes[i], null, _observer); if (i == 0) { item2 = ui; } uis.Add(ui); i++; } if (ui != null && item1 == null) { item1 = ui; } } ShortBranchNode bnode = new ShortBranchNode(uis, allLabels[label], brNodes[brNodes.Count - 1].Equal); allLabels[label].Nodes.Add(bnode); if (!allLabels.ContainsKey(brNodes[brNodes.Count - 1].Equal)) { allLabels.Add(brNodes[brNodes.Count - 1].Equal, bnode); labels.AddLast(brNodes[brNodes.Count - 1].Equal); } br.HasIncluded = true; } } } } #endregion #region 返回顶节点 // ISet<ShortBranchNode> branchNodes = new HashSet<ShortBranchNode>(); // foreach (ShortBranchNode brNode in allLabels.Values) // { // if (brNode.Parent == head) // branchNodes.Add(brNode); // } return(new BranchView(allLabels, head.Nodes, _observer)); #endregion }
/// <summary> /// 建立所有非重复路径 /// </summary> public void buildRoutes() { nodes = AppProject.GetInstance().Nodes; init(); }
/// <summary> /// 获取加电后可以直接得电的线圈 /// </summary> private void getNoneConditionCoil(ISet <List <INotifyComponentChanged> > allRts) { AppProject app = AppProject.GetInstance(); foreach (var route in vccToGndRoutes) { for (int i = route.Count - 1; i >= 0; i--) { if (route[i].CptType == ViewModel.ComponentType.Coil && !powCoils.ContainsKey(route[i].getName())) { string name = route[i].getName(); while (i >= 0) { if (app.IsCFEqual(route[i].getHeadNode().Equal) != null) { powCoils[name] = new List <List <string> >(); powCoils[name].Add(new List <string>() { route[i].getHeadNode().Equal }); allRts.Add(route); break; } else if (route[i].CptType == ViewModel.ComponentType.ContactOpen) { break; } i--; } if (i < 0) { powCoils[name] = new List <List <string> >(); powCoils[name].Add(new List <string>() { route[0].getHeadNode().Equal }); allRts.Add(route); } break; } else if (route[i].CptType == ViewModel.ComponentType.ContactOpen) { break; } } } foreach (var route in cfToGndRoutes) { for (int i = 0; i < route.Count; i++) { if (route[i].CptType == ViewModel.ComponentType.Coil && !powCoils.ContainsKey(route[i].getName())) { string name = route[i].getName(); i++; while (i < route.Count) { if (app.IsCFEqual(route[i].getHeadNode().Equal) != null) { powCoils[name] = new List <List <string> >(); powCoils[name].Add(new List <string>() { route[i].getHeadNode().Equal }); allRts.Add(route); break; } else if (route[i].CptType == ViewModel.ComponentType.ContactOpen) { break; } i++; } if (i >= route.Count) { powCoils[name] = new List <List <string> >(); powCoils[name].Add(new List <string>() { route[route.Count - 1].getHeadNode().Equal }); allRts.Add(route); } break; } else if (route[i].CptType == ViewModel.ComponentType.ContactOpen) { break; } } } }
private void getConditionCoil(ISet <List <INotifyComponentChanged> > allRts) { AppProject app = AppProject.GetInstance(); bool mark = false; while (!mark) { mark = true; #region vccToGndRoutes foreach (var route in vccToGndRoutes) { if (!allRts.Contains(route)) { List <List <List <string> > > condition = new List <List <List <string> > >(); for (int i = route.Count - 1; i >= 0; i--) { if (route[i].CptType == ViewModel.ComponentType.Coil && !powCoils.ContainsKey(route[i].getName())) { string name = route[i].getName(); while (i >= 0) { if (app.IsCFEqual(route[i].getHeadNode().Equal) != null) { mark = false; string src = route[i].getHeadNode().Equal; List <List <string> > val = new List <List <string> >(); combine(condition, 0, new List <string>(), val); val.ForEach(p => { if (!p.Contains(src)) { p.Add(src); } }); powCoils[name] = val; allRts.Add(route); break; } else if (route[i].CptType == ViewModel.ComponentType.ContactOpen) { if (!powCoils.ContainsKey(route[i].getName())) { break; } else { condition.Add(powCoils[route[i].getName()]); } } i--; } if (i < 0) { mark = false; string src = route[0].getHeadNode().Equal; List <List <string> > val = new List <List <string> >(); combine(condition, 0, new List <string>(), val); val.ForEach(p => { if (!p.Contains(src)) { p.Add(src); } }); powCoils[name] = val; allRts.Add(route); } break; } else if (route[i].CptType == ViewModel.ComponentType.ContactOpen) { if (!powCoils.ContainsKey(route[i].getName())) { break; } else { condition.Add(powCoils[route[i].getName()]); } } } } } #endregion #region cfToGndRoutes foreach (var route in cfToGndRoutes) { if (!allRts.Contains(route)) { List <List <List <string> > > condition = new List <List <List <string> > >(); for (int i = 0; i < route.Count; i++) { if (route[i].CptType == ViewModel.ComponentType.Coil && !powCoils.ContainsKey(route[i].getName())) { string name = route[i].getName(); i++; while (i < route.Count) { if (app.IsCFEqual(route[i].getHeadNode().Equal) != null) { mark = false; string src = route[i].getHeadNode().Equal; List <List <string> > val = new List <List <string> >(); combine(condition, 0, new List <string>(), val); val.ForEach(p => { if (!p.Contains(src)) { p.Add(src); } }); powCoils[name] = val; allRts.Add(route); break; } else if (route[i].CptType == ViewModel.ComponentType.ContactOpen) { if (!powCoils.ContainsKey(route[i].getName())) { break; } else { condition.Add(powCoils[route[i].getName()]); } } i++; } if (i >= route.Count) { mark = false; string src = route[route.Count - 1].getHeadNode().Equal; List <List <string> > val = new List <List <string> >(); combine(condition, 0, new List <string>(), val); val.ForEach(p => { if (!p.Contains(src)) { p.Add(src); } }); powCoils[name] = val; allRts.Add(route); } break; } else if (route[i].CptType == ViewModel.ComponentType.ContactOpen) { if (!powCoils.ContainsKey(route[i].getName())) { break; } else { condition.Add(powCoils[route[i].getName()]); } } } } } #endregion } }
public static void testNodesCount() { var brs = DigraphBuilder.expandBranch(AppProject.GetInstance().CompleteBr.Nodes); ISet <TNode> nodes = new HashSet <TNode>(); foreach (var br in brs) { br.Uis.ForEach(p => { nodes.Add(p.Info.getHeadNode()); if (p.Info.getTailNode() != null) { nodes.Add(p.Info.getTailNode()); } }); } Console.Write(string.Format("总图包含节点数:{0},总结点数为:{1}\r\n", nodes.Count, AppProject.GetInstance().Nodes.Count)); nodes.Clear(); brs = DigraphBuilder.expandBranch(AppProject.GetInstance().VccToGnd.Nodes); foreach (var br in brs) { br.Uis.ForEach(p => { nodes.Add(p.Info.getHeadNode()); if (p.Info.getTailNode() != null) { nodes.Add(p.Info.getTailNode()); } }); } brs = DigraphBuilder.expandBranch(AppProject.GetInstance().GndToCF.Nodes); foreach (var br in brs) { br.Uis.ForEach(p => { nodes.Add(p.Info.getHeadNode()); if (p.Info.getTailNode() != null) { nodes.Add(p.Info.getTailNode()); } }); } Console.Write(string.Format("两个子图包含节点数:{0}\r\n", nodes.Count)); HashSet <TNode> tnodes = new HashSet <TNode>(); foreach (ShortBranch br in AppProject.GetInstance().Shorts) { br.Branch.ForEach(p => tnodes.Add(p)); } Console.Write(string.Format("所有短支路中包含节点数为:{0}\r\n", tnodes.Count)); nodes.Clear(); foreach (var list in AppProject.GetInstance().Equals.Values) { foreach (var one in list) { nodes.Add(one); } } Console.Write(string.Format("所有等电位点包含的节点数为:{0}\r\n", nodes.Count)); foreach (var nd in tnodes) { nodes.Remove(nd); } foreach (var nd in nodes) { if (nd.TNType != TerminalType.Block && nd.TNType != TerminalType.RE && !nd.PartType.Contains("设备连接") && !nd.PartType.Contains("端子排") && !nd.PartType.Contains("接口连接")) { } } }