//************************************************************************** public MainWindow() { dataObject = new Model(); dataSaver = new Serializer(); InitializeComponent(); Directory.CreateDirectory("c:/log"); dataSaver.SaveData("c:/log/0", dataObject); }
/*Сохранить объект модели в xml файл * @path путь к файлу * @msc объект модели */ public void SaveData(string path, Model msc) { XmlTextWriter xw = new XmlTextWriter(path, Encoding.UTF8); xw.Formatting = Formatting.Indented; XmlDictionaryWriter writer = XmlDictionaryWriter.CreateDictionaryWriter(xw); DataContractSerializer ser = new DataContractSerializer(typeof(Model)); ser.WriteObject(writer, msc); writer.Close(); xw.Close(); }
public void merge(Model obj) { foreach (KeyValuePair<int, UmlObject> i in obj.objects_list) { objects_list.Add(i.Key, i.Value); } foreach (KeyValuePair<int, Relation> i in obj.relations_list) { relations_list.Add(i.Key, i.Value); } max_id += obj.max_id + 1; }
public Model(Model model) { max_id = model.max_id; objects_list = model.objects_list; relations_list = model.relations_list; }
private void Undo() { if (currentId > 0) { //BtnRedo.IsEnabled = true; ImageBrush myBrush = new ImageBrush(); string packUri = "pack://application:,,,/Wpf;component/Images/BtnRedo.png"; myBrush.ImageSource = new ImageSourceConverter().ConvertFromString(packUri) as ImageSource; BtnRedo.Background = myBrush; currentId--; myCanvas.Children.Clear(); Model model = new Model(); model = (Model)model.DeepClone(dataSaver.LoadData("c:/log/" + currentId.ToString())); dataObject = model; ShowInCanvas(dataObject); if (currentId == 0) { myBrush = new ImageBrush(); packUri = "pack://application:,,,/Wpf;component/Images/BtnUndoNotActive.png"; myBrush.ImageSource = new ImageSourceConverter().ConvertFromString(packUri) as ImageSource; BtnUndo.Background = myBrush; } } else { ImageBrush myBrush = new ImageBrush(); string packUri = "pack://application:,,,/Wpf;component/Images/BtnUndoNotActive.png"; myBrush.ImageSource = new ImageSourceConverter().ConvertFromString(packUri) as ImageSource; BtnUndo.Background = myBrush; } }
/// <summary> /// Обработчик события нажатия клавиш. Служит для "отмены удаления" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) this.Cursor = Cursors.Arrow; if (e.Key == Key.System) AltFlag = true; if (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl) CtrlFlag = true; if (e.Key == Key.LeftShift || e.Key == Key.RightShift) ShiftFlag = true; if (e.Key == Key.Delete) { List<int> allSelected = dataObject.get_selected_ids(); foreach (int i in allSelected) { MoveRelation(i, false); dataObject.delete_object(i); myCanvas.Children.Remove((UIElement)getChildrenById(i)); } IncStatus(); } if (CtrlFlag && e.Key == Key.C) { Model copy = new Model(); copy = (Model)dataObject.DeepClone(dataObject); copy.clear_for_copy(); Clipboard.SetData("CustomerFormat", copy); copy.clear(); } if (CtrlFlag && e.Key == Key.X) { Model copy = new Model(); copy = (Model)dataObject.DeepClone(dataObject); copy.clear_for_copy(); Clipboard.SetData("CustomerFormat", copy); copy.clear(); List<int> allSelected = dataObject.get_selected_ids(); foreach (int i in allSelected) { MoveRelation(i, false); dataObject.delete_object(i); myCanvas.Children.Remove((UIElement)getChildrenById(i)); } IncStatus(); } if (CtrlFlag && e.Key == Key.V) { Model CopyModel = new Model(); if (Clipboard.ContainsData("CustomerFormat")) { CopyModel = Clipboard.GetData("CustomerFormat") as Model; CopyModel.editIds(dataObject.max_id+1); ResetAllSelected(); dataObject.reset_flags(); dataObject.merge(CopyModel); ShowInCanvas(CopyModel); List <int> newSelectedIds = dataObject.get_selected_ids(); foreach (int i in newSelectedIds) { SelectObject(getChildrenById(i)); } IncStatus(); } } if (CtrlFlag && e.Key == Key.A) { for (int i = 0; i < myCanvas.Children.Count; ++i) { SelectObject(myCanvas.Children[i]); } dataObject.select_all_flags(); } if (CtrlFlag && e.Key == Key.Z) { Undo(); } if (CtrlFlag && e.Key == Key.Y) { Redo(); } }
private void ShowInCanvas(Model model) { SortedList<int, UmlObject> objects_list = model.objects_list; SortedList<int, Relation> relations_list = model.relations_list; myCanvas.Width = model.widght; myCanvas.Height = model.height; foreach (KeyValuePair<int, UmlObject> i in objects_list) { if (i.Value.type == "Actor") { addActorToCanvas(i.Value.x, i.Value.y, i.Key, i.Value.text); int x = 0; x++; } else if (i.Value.type == "Precedent") { addPrecedentToCanvas(i.Value.x, i.Value.y, i.Key, i.Value.text, i.Value.getColor()); } else if (i.Value.type == "Comment") { addCommentToCanvas(i.Value.x, i.Value.y, i.Key, i.Value.text, i.Value.widht, i.Value.height); } } foreach (KeyValuePair<int, Relation> i in relations_list) { AddLine(getChildrenById(i.Value.from), getChildrenById(i.Value.to), i.Value.type, i.Key); } }
private void BtnLoad_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Filter = "Text documents (.usd)|*.usd"; // Filter files by extension if (dlg.ShowDialog().Value) { int index = dlg.FileName.LastIndexOf("."); string str = dlg.FileName.Remove(0, index+1); if (str == "usd") { File.Copy(dlg.FileName, "c:/log/0", true); currentId = 0; maxId = 0; myCanvas.Children.Clear(); dataObject = dataSaver.LoadData(dlg.FileName); ShowInCanvas(dataObject); } else { MessageBox.Show("Неверное расширение!"); } } }