public static ImmutableArray <PrimitiveTriangle> NewWall(double x, double y) { var color = VisUtil.RandomOpaqueColor(); var verts = ImmutableArray.CreateBuilder <Vertex>(); verts.Add(new Vertex(x / 2, y / 2, 0, color, Vector3.K)); verts.Add(new Vertex(-x / 2, y / 2, 0, color, Vector3.K)); verts.Add(new Vertex(-x / 2, -y / 2, 0, color, Vector3.K)); verts.Add(new Vertex(x / 2, -y / 2, 0, color, Vector3.K)); var prims = ImmutableArray.CreateBuilder <PrimitiveTriangle>(); prims.Add(new PrimitiveTriangle(verts[0], verts[1], verts[3], false)); prims.Add(new PrimitiveTriangle(verts[1], verts[2], verts[3], false)); return(prims.ToImmutable()); }
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(); }
public void MenuNew_Click(object sender, RoutedEventArgs e) { btnSelect.IsEnabled = true; IsCancelPressed = false; EnableAddButtons(); var result = MessageBoxResult.None; if (isSomethingChanged) { if (currentFileName == null) { result = MessageBox.Show("Do you want to save the current file?", "Save..", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { var 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); } currentFileName = SFdialog.FileName; } } 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); } } } if (result == MessageBoxResult.No || result == MessageBoxResult.Yes || isSomethingChanged == false) { if (IsWindowClosing == false) { DeleteArcs(Net.arcs); while (Net.Nodes.Count != 0) { RemoveNode(Net.Nodes[0]); } //Net.arcs.Clear(); //SetOfFigures.Figures.Clear(); ClearCanvasWithoutLoss(); _selectedFigures.Clear(); _selectedArcs.Clear(); _selectedArc = null; _selectedFigure = null; VisUtil.ResizeCanvas(Net.Nodes, MainControl, MainModelCanvas); btnUndo.IsEnabled = true; HideAllProperties(); if (_thisScale != 1) { _scaleTransform.ScaleX = 1; _scaleTransform.ScaleY = 1; _thisScale = 1; MainModelCanvas.LayoutTransform = _scaleTransform; MainModelCanvas.UpdateLayout(); } btnGrid.IsEnabled = true; currentFileName = null; menuSave.IsEnabled = false; MainController.Self.SetMenuItemEnabled(Core.Util.PathOfMethod(MenuSave_Click), false); } ShowMainWindowTitleDelegate("Carassius - Petri Net Editor"); } else { IsCancelPressed = true; } TurnOnSelectMode(); }