private void RemoveConnectionExecute([NotNull] object toRemove) { if (toRemove == null) { throw new Exception("Connection to Remove can't be null"); } if (toRemove is ConnectionModel connectionModel) { RemoveConnectionCommand removeConnectionCommand = new RemoveConnectionCommand(connectionModel, this); removeConnectionCommand.Execute(); MyCommandManager.AddToList(removeConnectionCommand); } }
private void RotateElementsExecute([NotNull] object ElementsToRotate) { if (ElementsToRotate == null) { throw new Exception("List of elements to rotate can't be null"); } if (ElementsToRotate is List <Element> elementsToRotate) { GroupRotationCommand groupRotationCommand = new GroupRotationCommand(elementsToRotate); groupRotationCommand.Execute(); MyCommandManager.AddToList(groupRotationCommand); } }
private void AddConnectionExecute([NotNull] object newObject) { if (newObject == null) { throw new Exception("Connection to add can't be null"); } if (newObject is ConnectionModel connectionModel) { AddConnectionCommand addConnectionCommand = new AddConnectionCommand(connectionModel, this); addConnectionCommand.Execute(); MyCommandManager.AddToList(addConnectionCommand); } }
private void RemoveElementExecute([NotNull] object toRemove) { if (toRemove == null) { throw new Exception("Element to remove can't be null"); } if (toRemove is Element toRemoveElementVM) { RemoveElementCommand removeElementCommand = new RemoveElementCommand(toRemoveElementVM, this); removeElementCommand.Execute(); MyCommandManager.AddToList(removeElementCommand); } }
private void AddElementExecute([NotNull] object newObject) { if (newObject == null) { throw new Exception("Element to add can't be null"); } if (newObject is Element element) { AddElementCommand addElementCommand = new AddElementCommand(element, this); addElementCommand.Execute(); MyCommandManager.AddToList(addElementCommand); if (element is PortModel) { RenumberPorts(Elements); } } }
public void OpenXMLFile() { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "XML Files|*.xml"; openFileDialog.Title = "Open XML File"; openFileDialog.ShowDialog(); if (openFileDialog.FileName != "") { DeleteCommand newDeleteCommand = new DeleteCommand(Elements, ConnectionModels, this); MyCommandManager.AddToList(newDeleteCommand); newDeleteCommand.Execute(); XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.IgnoreWhitespace = true; XmlReader reader = XmlReader.Create(openFileDialog.FileName, readerSettings); ReadElementsAndConnections(reader); } }
public void ReadAndShiftElementsAndConnections(XmlReader reader, Vector elementsShiftVector) { List <Element> ReadElements = new List <Element>(); List <ConnectionModel> ReadConnectionModels = new List <ConnectionModel>(); try { reader.MoveToContent(); reader.Read(); if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "SimulationProperties") { if (reader.Read() && reader.Name == "ReferenceImpedance") { ReferenceImpedance = double.Parse(reader.ReadString()); OnPropertyChanged(nameof(ReferenceImpedance)); } else { throw new Exception("ReferenceImpedance is missing or it is in the wrong place"); } if (reader.Read() && reader.Name == "FromFreq") { FromFreq = double.Parse(reader.ReadString()); OnPropertyChanged(nameof(FromFreq)); } else { throw new Exception("FromFreq is missing or it is in the wrong place"); } if (reader.Read() && reader.Name == "ToFreq") { ToFreq = double.Parse(reader.ReadString()); OnPropertyChanged(nameof(ToFreq)); } else { throw new Exception("ToFreq is missing or it is in the wrong place"); } if (reader.Read() && reader.Name == "Step") { Step = double.Parse(reader.ReadString()); OnPropertyChanged(nameof(Step)); } else { throw new Exception("Step is missing or it is in the wrong place"); } } } do { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "Element": Element readElement = ReadElement(reader); readElement.Position = Point.Add(readElement.Position, elementsShiftVector); ReadElements.Add(readElement); break; case "Connection": ReadConnectionModels.Add(ReadConnectionModel(reader, ReadElements)); break; } } } while (reader.Read()); } catch (Exception e) { Console.WriteLine(e); return; } //changing ID's that every Element, connector and connection have unique foreach (Element readElement in ReadElements) { readElement.ID = Guid.NewGuid(); foreach (ConnectorModel connectorModel in readElement.Connectors) { connectorModel.ID = Guid.NewGuid(); } } foreach (ConnectionModel readConnectionModel in ReadConnectionModels) { readConnectionModel.ID = Guid.NewGuid(); } PasteCommand newPasteCommand = new PasteCommand(ReadElements, ReadConnectionModels, this); MyCommandManager.AddToList(newPasteCommand); newPasteCommand.Execute(); RenumberPorts(Elements); }