/// <summary> /// 克隆一个仿真器 /// </summary> private Simulation clone() { Simulation cp = (Simulation)this.MemberwiseClone(); cp.pows = new HashSet <string>(pows); cp.coils = new HashSet <string>(coils); cp.switches = new HashSet <string>(switches); cp.vccToGndRoutes = new List <List <INotifyComponentChanged> >(); cp.cfToGndRoutes = new List <List <INotifyComponentChanged> >(); cp.cfToVccRoutes = new List <List <INotifyComponentChanged> >(); cp.vccConductRoutes = new List <List <INotifyComponentChanged> >(); cp.cfConductRoutes = new List <List <INotifyComponentChanged> >(); vccToGndRoutes.ForEach(p => cp.vccToGndRoutes.Add(new List <INotifyComponentChanged>(p))); cfToGndRoutes.ForEach(p => cp.cfToGndRoutes.Add(new List <INotifyComponentChanged>(p))); cfToVccRoutes.ForEach(p => cp.cfToVccRoutes.Add(new List <INotifyComponentChanged>(p))); vccConductRoutes.ForEach(p => cp.vccConductRoutes.Add(new List <INotifyComponentChanged>(p))); cfConductRoutes.ForEach(p => cp.cfConductRoutes.Add(new List <INotifyComponentChanged>(p))); ISet <INotifyComponentChanged> cpts = new HashSet <INotifyComponentChanged>(); foreach (INotifyComponentChanged one in allCpts) { INotifyComponentChanged ncp = one.clone(); replaceElement(cp.vccToGndRoutes, one, ncp); replaceElement(cp.cfToGndRoutes, one, ncp); replaceElement(cp.cfToVccRoutes, one, ncp); replaceElement(cp.vccConductRoutes, one, ncp); replaceElement(cp.cfConductRoutes, one, ncp); cpts.Add(ncp); } cp.allCpts = cpts; return(cp); }
public Indicator(INotifyComponentChanged info) { InitializeComponent(); info.initStatus(info.CptType); this.info = info; this.DataContext = info; }
public void removeNodeFault(INotifyComponentChanged node) { this.faultPoints.Remove(this.faultPoints.FirstOrDefault(p => ComponentViewModel.compare(p, node))); modifyComponent(node, p => p.State = ComponentState.UnConnected); }
public VerticalLine(INotifyComponentChanged info) { InitializeComponent(); info.initStatus(ComponentType.Blank); this.info = info; this.DataContext = info; }
public Resistance(INotifyComponentChanged info) { InitializeComponent(); info.initStatus(info.CptType); this.info = (INotifyComponentChanged)info; this.DataContext = info; }
public Terminal(ComponentType type, TNode node) { InitializeComponent(); INotifyComponentChanged VM = new ComponentViewModel(Tuple.Create <TNode, TNode>(node, null), type); VM.initStatus(type); this.info = (INotifyComponentChanged)VM; this.DataContext = VM; }
public VerticalLine(ComponentType type, TNode node1, TNode node2) { InitializeComponent(); INotifyComponentChanged VM = new ComponentViewModel(Tuple.Create <TNode, TNode>(node1, node2), type); VM.initStatus(type); this.info = VM; this.DataContext = VM; }
private void replaceElement(List <List <INotifyComponentChanged> > src, INotifyComponentChanged old, INotifyComponentChanged cp) { List <INotifyComponentChanged> col = src.FirstOrDefault(p => p.Contains(old)); if (col != null) { col[col.IndexOf(old)] = cp; } }
public TNodeUI(INotifyComponentChanged cpInfo, bool reverse, IObserver observer) { this.info = cpInfo; this.reverse = reverse; if (observer != null) { observer.addListener(cpInfo); } }
public Indicator(ComponentType type, TNode node1, TNode node2) { InitializeComponent(); INotifyComponentChanged VM = new ComponentViewModel(Tuple.Create <TNode, TNode>(node1, node2), type); VM.initStatus(ComponentType.Indicator); this.info = (INotifyComponentChanged)VM; this.DataContext = VM; }
public void updateFaultNode(INotifyComponentChanged node) { foreach (INotifyComponentChanged notify in listeners) { if (ComponentViewModel.compare(notify, node)) { notify.State = node.State; } } }
public Diode(INotifyComponentChanged info, bool reverse) { InitializeComponent(); this.reverse = reverse; if (reverse) { dioAngel.Angle = 180; } info.initStatus(info.CptType); this.info = info; this.DataContext = info; }
public StandardContact(INotifyComponentChanged info) { InitializeComponent(); if (info.CptType == ComponentType.ContactOpen) { open.Visibility = Visibility.Visible; close.Visibility = Visibility.Hidden; } info.initStatus(info.CptType); this.info = info; this.DataContext = info; }
public Diode(ComponentType type, TNode node1, TNode node2, bool reverse) { InitializeComponent(); this.reverse = reverse; if (reverse) { dioAngel.Angle = 180; } INotifyComponentChanged VM = new ComponentViewModel(Tuple.Create <TNode, TNode>(node1, node2), type); VM.initStatus(type); this.info = (INotifyComponentChanged)VM; this.DataContext = VM; }
public StandardContact(ComponentType type, TNode node1, TNode node2) { InitializeComponent(); if (type == ComponentType.ContactOpen) { open.Visibility = Visibility.Visible; close.Visibility = Visibility.Hidden; } INotifyComponentChanged VM = new ComponentViewModel(Tuple.Create <TNode, TNode>(node1, node2), type); VM.initStatus(type); this.info = (INotifyComponentChanged)VM; this.DataContext = VM; }
/// <summary> /// 注入故障 /// </summary> /// <param name="faultType">true:固定1故障 false:固定0故障</param> /// <param name="node">故障节点</param> public void addNodeFault(bool faultType, INotifyComponentChanged node) { this.faultPoints.Add(node.clone()); if (faultType) { modifyComponent(node, p => p.State = ComponentState.Fault1); } else { modifyComponent(node, p => p.State = ComponentState.Fault0); } }
private void modifyComponent(INotifyComponentChanged node, Action <INotifyComponentChanged> action) { foreach (INotifyComponentChanged cpt in allCpts) { if (ComponentViewModel.compare(cpt, node)) { action(cpt); } } ISet <string> ele = new HashSet <string>(); while (!powUpRoute(ele)) { ; } }
public void removeListener(INotifyComponentChanged listener) { listeners.Remove(listener); }
public void addListener(INotifyComponentChanged listener) { listeners.Add(listener); }
/// <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); } } } }
public static bool compare(INotifyComponentChanged a, INotifyComponentChanged b) { return((a.getHeadNode() == b.getHeadNode() && a.getTailNode() == b.getTailNode()) || (a.getHeadNode() == b.getTailNode() && a.getTailNode() == b.getHeadNode())); }