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); }
private IFolderStructure GetFolderTree(Folder folder) { IFolderStructure tree = BranchFactory.Create(folder); List <Folder> childFolders = _context.Folders.Where(z => z.ParentFolder == folder.FolderId).ToList(); if (childFolders == null || childFolders.Count == 0) { return(tree); } IFolderStructure branch; foreach (Folder f in childFolders) { branch = BranchFactory.Create(f); branch.ChildBranches = GetFolderTree(f).ChildBranches; tree.ChildBranches.Add(branch); } return(tree); }
/// <summary> /// 添加电路图中的元件,并设置其位置 /// </summary> private void drawGraph(ISet <ShortBranchNode> brs, bool left, bool right) { //绘制并联电路的封闭垂线 if (view.Type) { ISet <ShortBranchNode> total = DigraphBuilder.expandBranch(brs); foreach (ShortBranchNode node in view.LabelToBranch.Values) { if (node == null || node.EndName == "GND" || node.EndName == "DC110V") { continue; } var filterNodes = total.Where(p => node.EndName == p.EndName).ToList(); if (filterNodes.Count == 0 || filterNodes.Count == 1) { continue; } double max = filterNodes.Max(p => p.Uis[p.Uis.Count - 1].Pos.Y); double min = filterNodes.Min(p => p.Uis[p.Uis.Count - 1].Pos.Y); INotifyComponentChanged info = node.Nodes.First().Uis[node.Nodes.First().Uis.Count - 1].Info; INotifyComponentChanged cpinfo = info.clone(); view.Observer.addListener(cpinfo); VerticalLine line = new VerticalLine(cpinfo); line.setLineLength((max - min) * 60); ShortBranchNode brnode = filterNodes.FirstOrDefault(p => p.Uis[p.Uis.Count - 1].Pos.Y == min); Canvas.SetLeft(line, DigraphBuilder.START_POS.X + brnode.Uis[brnode.Uis.Count - 1].Pos.X * 150 + 150); Canvas.SetTop(line, DigraphBuilder.START_POS.Y + brnode.Uis[0].Pos.Y * 60 + 37.5); map.Children.Add(line); } } //总正垂线 if (left) { Line line = new Line(); line.Stroke = Brushes.Black; line.StrokeThickness = 1; line.X1 = 0; line.Y1 = 0; line.X2 = 0; line.Y2 = (brs.Last().Uis[0].Pos.Y - brs.First().Uis[0].Pos.Y) * 60; Canvas.SetLeft(line, DigraphBuilder.START_POS.X + brs.First().Uis[0].Pos.X * 150); Canvas.SetTop(line, DigraphBuilder.START_POS.Y + brs.First().Uis[0].Pos.Y * 60 + 37.5); map.Children.Add(line); } /*核心元器件*/ List <TNodeUI> uis = new List <TNodeUI>(); double widthMax = 0, heightMax = 0; double miny = double.MaxValue, maxy = double.MinValue, maxx = double.MinValue; ISet <ShortBranchNode> branchs = new HashSet <ShortBranchNode>(brs); while (branchs.Count != 0) { ISet <ShortBranchNode> temp = new HashSet <ShortBranchNode>(); foreach (ShortBranchNode brNode in branchs) { foreach (ShortBranchNode child in brNode.Nodes) { temp.Add(child); } if (brNode.Nodes.Count == 0) { if (brNode.Uis[0].Pos.Y < miny) { miny = brNode.Uis[0].Pos.Y; } if (brNode.Uis[0].Pos.Y > maxy) { maxy = brNode.Uis[0].Pos.Y; } if (brNode.Uis.Last().Pos.X > maxx) { maxx = brNode.Uis.Last().Pos.X; } if (brNode.EndName == "GND") { uis.Add(brNode.Uis.Last()); } } foreach (TNodeUI ui in brNode.Uis) { UIElement ele = BranchFactory.convert(ui); map.Children.Add(ele); ElectricAnalysis.Graph.Point realPos = ui.RealPos; Canvas.SetLeft(ele, realPos.X); Canvas.SetTop(ele, realPos.Y); if (DigraphBuilder.START_POS.X + ui.Pos.X * 150 > widthMax) { widthMax = DigraphBuilder.START_POS.X + ui.Pos.X * 150; } if (DigraphBuilder.START_POS.Y + ui.Pos.Y * 60 > heightMax) { heightMax = DigraphBuilder.START_POS.Y + ui.Pos.Y * 60; } } //绘垂线 if (brNode.Nodes.Count > 1) { INotifyComponentChanged cpinfo = brNode.Uis[brNode.Uis.Count - 1].Info.clone(); view.Observer.addListener(cpinfo); VerticalLine line = new VerticalLine(cpinfo); line.setLineLength((brNode.Nodes.Last().Uis[0].Pos.Y - brNode.Nodes.First().Uis[0].Pos.Y) * 60); Canvas.SetLeft(line, DigraphBuilder.START_POS.X + brNode.Nodes.First().Uis[0].Pos.X * 150); Canvas.SetTop(line, DigraphBuilder.START_POS.Y + brNode.Nodes.First().Uis[0].Pos.Y * 60 + 37.5); map.Children.Add(line); } } branchs = temp; } outerBd.Width = widthMax + 250; outerBd.Height = heightMax + 150; //总负垂线 if (right) { Line line = new Line(); line.Stroke = Brushes.Black; line.StrokeThickness = 1; line.X1 = 0; line.Y1 = 0; line.X2 = 0; line.Y2 = (maxy - miny) * 60; Canvas.SetLeft(line, widthMax + 150); Canvas.SetTop(line, DigraphBuilder.START_POS.Y + brs.First().Uis[0].Pos.Y * 60 + 37.5); map.Children.Add(line); foreach (TNodeUI ui in uis) { for (double i = ui.Pos.X + 1; i <= maxx; i++) { BlankLine bk = new BlankLine(ui.Info); map.Children.Add(bk); Canvas.SetLeft(bk, DigraphBuilder.START_POS.X + i * 150); Canvas.SetTop(bk, DigraphBuilder.START_POS.Y + ui.Pos.Y * 60); } } } }