private void ReohordSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (cbRun.IsChecked == false) { return; } Slider slider = sender as Slider; Reohord reohord = slider.DataContext as Reohord; reohord.LengthAC = slider.Value; if (!RunLayout()) { StopSim(); } }
public Element CreateElement(Type type, int x, int y) { if (type.BaseType.Name == "Element") { if (type.Name == "ResistorX" && Connectors.Count(i => i is ResistorX) > 0) { throw new ResistorXPlacedException(); } var element = Activator.CreateInstance(type) as Element; //создание элемента Node pina = new Node(); //создание пинов Node pinb = new Node(); if (type.Name == "Reohord") //реохорд { Node pinc = new Node(); Reohord reohord = element as Reohord; reohord.ResistorAC = new NoDrawConnector() { Resistance = 100 }; //создание соединителей reohord.ResistorBC = new NoDrawConnector(); ConnectNodes(pina, pinc, reohord.ResistorAC); //соединение пинов при помощи коннекторов ConnectNodes(pinb, pinc, reohord.ResistorBC); reohord.LengthAC = 50; reohord.NodeA = pina; //привязка ножек к нодам reohord.NodeB = pinb; reohord.NodeC = pinc; Nodes.Add(reohord.NodeC); //отрисовка нода C ConnectorsToDraw.Add(element); //отрисовка реохорда } else { ConnectNodes(pina, pinb, element); //соединение пинов при помощи элемента } Nodes.Add(element.NodeA); //отрисовка нодов Nodes.Add(element.NodeB); element.X = x; //перемещение по координатам (учитывая обновление свойств X и Y у пинов) element.Y = y; return(element); } return(null); }
private void SaveData() { Element element = Tag as Element; element.Name = tbName.Text; if (element is Resistor) { Resistor resistor = element as Resistor; resistor.Resistance = double.Parse(tbResistance.Text); resistor.IsEditable = cbEditable.IsChecked == true; resistor.DisplayVoltage = cbVoltage.IsChecked == true; } else if (element is Reohord) { Reohord reohord = element as Reohord; reohord.Resistance = double.Parse(tbResistance.Text); reohord.DisplayLength = cbReohordDisplayMode.SelectedIndex == 0; } else if (element is Battery) { Battery battery = element as Battery; battery.Resistance = double.Parse(tbResistance.Text); battery.Eds = double.Parse(tbEds.Text); battery.DisplayVoltage = cbVoltage.IsChecked == true; } else if (element is Amperemeter) { Amperemeter galvanometr = element as Amperemeter; galvanometr.Division = double.Parse(tbDivision.Text); } else if (element is Potentiometer) { Potentiometer pot = element as Potentiometer; pot.MaxResistance = double.Parse(tbMaxResistance.Text); pot.DisplayVoltage = cbVoltage.IsChecked == true; } }
public void RemoveElement(Element element) { Node nodea = element.NodeA; Node nodeb = element.NodeB; if (element is Reohord) { Reohord reohord = element as Reohord; Node nodec = reohord.NodeC; RemoveConnector(reohord.ResistorAC); RemoveConnector(reohord.ResistorBC); Connectors.Remove(reohord); ConnectorsToDraw.Remove(reohord); Nodes.Remove(nodec); while (nodec.Connections.Count > 0) { RemoveConnector(nodec.Connections.Values.First()); } } else { RemoveConnector(element); } Nodes.Remove(nodea); //удаление пинов из отрисовки Nodes.Remove(nodeb); while (nodea.Connections.Count > 0) //удаление соединителей, связанных с нодами { RemoveConnector(nodea.Connections.Values.First()); } while (nodeb.Connections.Count > 0) { RemoveConnector(nodeb.Connections.Values.First()); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { Element element = Tag as Element; tbName.Text = element.Name; if (element is Resistor) { this.Title = Properties.Resources.ew_edit_resistor; spResistance.Visibility = System.Windows.Visibility.Visible; tbResistance.Text = element.Resistance.ToString(); spEditable.Visibility = Visibility.Visible; cbEditable.IsChecked = (element as Resistor).IsEditable; spVoltage.Visibility = Visibility.Visible; cbVoltage.IsChecked = element.DisplayVoltage; Height = 210; } else if (element is Reohord) { this.Title = Properties.Resources.ew_edit_reohord; spResistance.Visibility = System.Windows.Visibility.Visible; spReohordDisplayMode.Visibility = System.Windows.Visibility.Visible; Reohord reohord = element as Reohord; tbResistance.Text = reohord.Resistance.ToString(); cbReohordDisplayMode.SelectedIndex = reohord.DisplayLength ? 0 : 1; Height = 180; } else if (element is Battery) { this.Title = Properties.Resources.ew_edit_battery; spEds.Visibility = System.Windows.Visibility.Visible; spResistance.Visibility = System.Windows.Visibility.Visible; Battery battery = element as Battery; tbEds.Text = battery.Eds.ToString(); tbResistance.Text = battery.Resistance.ToString(); spVoltage.Visibility = Visibility.Visible; cbVoltage.IsChecked = element.DisplayVoltage; Height = 210; } else if (element is Amperemeter) { this.Title = Properties.Resources.ew_edit_ampermeter; spDivision.Visibility = System.Windows.Visibility.Visible; Amperemeter galvanometr = element as Amperemeter; tbDivision.Text = galvanometr.Division.ToString(); Height = 150; } else if (element is Potentiometer) { this.Title = Properties.Resources.ew_edit_potentiometer; spMaxResistance.Visibility = Visibility.Visible; Potentiometer pot = element as Potentiometer; tbMaxResistance.Text = pot.MaxResistance.ToString(); spVoltage.Visibility = Visibility.Visible; cbVoltage.IsChecked = element.DisplayVoltage; Height = 180; } else if (element is ResistorX) { this.Title = Properties.Resources.ew_edit_resistorx; } }