private void SaveModel(string fileName, bool saveLayout) { var s = System.IO.Path.GetFileNameWithoutExtension(fileName); XmlDocument doc = null; doc = Pnml.SavePnml(s, Net.arcs, saveLayout); doc.Save(fileName); //doc.Save(currentFileName); }
public void MenuOpen_Click() { EnableAddButtons(); btnSelect.IsEnabled = true; MessageBoxResult result; if (currentFileName == null) { result = MessageBox.Show("Do you want to save the current file?", "Save..", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { SaveFileDialog SFdialog = new SaveFileDialog(); SetFilterToSaveFileDialog(SFdialog); if (SFdialog.ShowDialog() == true) { SaveModel(SFdialog.FileName, true); menuSave.IsEnabled = true; MainController.Self.SetMenuItemEnabled(Core.Util.PathOfMethod(MenuSave_Click), true); } } } else { result = MessageBox.Show("Do you want to save changes in " + System.IO.Path.GetFileName(currentFileName) + "?", "Save..", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { SaveModel(currentFileName, true); } } currentFileName = null; if (result == MessageBoxResult.Cancel) { return; } var OFdialog = new OpenFileDialog { Filter = "PNML files(*.pnml)|*.pnml" }; if (OFdialog.ShowDialog() == true) { //clear the model DeleteArcs(Net.arcs); while (Net.Nodes.Count != 0) { RemoveNode(Net.Nodes[0]); } //Net.arcs.Clear(); ClearCanvasWithoutLoss(); HideAllProperties(); _selectedFigures.Clear(); _selectedArcs.Clear(); _selectedArc = null; _selectedFigure = null; var net = new XmlDocument(); var exception = false; try { net.Load(OFdialog.FileName); var s = System.IO.Path.GetFileNameWithoutExtension(OFdialog.FileName); ShowMainWindowTitleDelegate("Carassius - Petri Net Editor | " + s); //OFdialog.FileName); } catch (XmlException) { MessageBox.Show("The file contains data, that don't match with format of PNML"); exception = true; } if (exception == false) { bool flag = false; if (net.LastChild.Name == "pnml") { Net.arcs.AddRange(Pnml.OpenPnml(net, out flag)); foreach (var figure in Net.Nodes) { foreach (var arc in Net.arcs) { if (arc.From == figure || arc.To == figure) { figure.ThisArcs.Add(arc); } } } btnAddPlace.Visibility = Visibility.Visible; btnAddTransition.Visibility = Visibility.Visible; btnAddArc.Visibility = Visibility.Visible; btnNonOrientedArc.Visibility = Visibility.Collapsed; btnAddToken.Visibility = Visibility.Visible; pnlTopToolPanel.Visibility = Visibility.Visible; btnArrangeModel.IsEnabled = true; } //todo тут ClearCommandStacks(); if (flag == false) { currentFileName = OFdialog.FileName; menuSave.IsEnabled = true; MainController.Self.SetMenuItemEnabled(Core.Util.PathOfMethod(MenuSave_Click), true); foreach (PetriNetNode figure in Net.Nodes) { DrawFigure(figure); } foreach (VArc arc in Net.arcs) { DisplayArc(arc); } VisUtil.ResizeCanvas(Net.Nodes, MainControl, MainModelCanvas); } } } if (_thisScale != 1) { _scaleTransform.ScaleX = 1; _scaleTransform.ScaleY = 1; _thisScale = 1; MainModelCanvas.LayoutTransform = _scaleTransform; MainModelCanvas.UpdateLayout(); } btnGrid.IsEnabled = true; btnShowHideLabels.IsEnabled = true; hideLabels = false; TurnOnSelectMode(); }