void HandleSave(UIGraph g) { if (string.IsNullOrEmpty(g.FilePath)) { System.Windows.Forms.SaveFileDialog svf = new System.Windows.Forms.SaveFileDialog(); svf.CheckPathExists = true; svf.DefaultExt = ".mtg"; svf.Filter = "Materia Graph (*.mtg)|*.mtg"; if (svf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (g != null) { g.Save(svf.FileName); } } } else { if (g != null) { g.Save(); } } }
void ShowSaveDialog(UIGraph g, LayoutDocument doc, bool saveAs = false) { try { if (g != null) { System.Windows.Forms.SaveFileDialog svf = new System.Windows.Forms.SaveFileDialog(); svf.CheckPathExists = true; svf.DefaultExt = ".mtg"; svf.Filter = "Materia Graph (*.mtg)|*.mtg|Materia Graph Archive (*.mtga)|*.mtga"; if (svf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { g.Save(svf.FileName, saveAs); doc.Title = g.GraphName; recent.Add(svf.FileName); BuildRecentSubMenu(); } } } catch (Exception e) { Log.Error(e); } }
UIGraph NewGraph(Graph template = null) { UIGraph g = new UIGraph(template); LayoutDocument doc = new LayoutDocument(); doc.Content = g; doc.Title = g.GraphName; doc.Closing += Doc_Closing; doc.ContentId = g.GraphName + graphs.Count; doc.CanFloat = false; doc.CanMove = false; documents.Add(doc); graphs.Add(g); GraphDocuments.Children.Add(doc); GraphDocuments.SelectedContentIndex = documents.Count - 1; mnuGraphSettings.IsEnabled = true; SaveAsMenuItem.IsEnabled = true; SaveMenuItem.IsEnabled = true; ExportMenuItem.IsEnabled = true; return(g); }
void HandleSave(UIGraph g) { if (string.IsNullOrEmpty(g.FilePath)) { System.Windows.Forms.SaveFileDialog svf = new System.Windows.Forms.SaveFileDialog(); svf.CheckPathExists = true; svf.DefaultExt = ".mtg"; svf.Filter = "Materia Graph (*.mtg)|*.mtg|Materia Graph Archive (*.mtga)|*.mtga"; if (svf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (g != null) { g.Save(svf.FileName); recent.Add(svf.FileName); BuildRecentSubMenu(); } } } else { if (g != null) { g.Save(); } } Log.Info("Saved Graph {0}", g.GraphName); }
public void MarkModified() { if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count) { UIGraph ugraph = graphs[GraphDocuments.SelectedContentIndex]; ugraph.MarkModified(); } }
public void Push(Node n, Graph g, string param = null, GraphStackType type = GraphStackType.Parameter) { if (GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count) { UIGraph ugraph = graphs[GraphDocuments.SelectedContentIndex]; ugraph.Push(n, g, type, param); } }
public UINode(Node n, UIGraph graph, double ox, double oy, double xs, double xy, double sc = 1) { InitializeComponent(); Width = defaultSize; Height = defaultSize; Focusable = true; InputNodes = new List <UINodePoint>(); OutputNodes = new List <UINodePoint>(); Graph = graph; xShift = xs; yShift = xy; scale = sc; Node = n; Id = n.Id; originX = ox; originY = oy; Margin = new Thickness(0, 0, 0, 0); NodeName.Text = n.Name; foreach (NodeOutput op in n.Outputs) { UINodePoint outpoint = new UINodePoint(this, graph); outpoint.Output = op; outpoint.VerticalAlignment = VerticalAlignment.Center; OutputNodes.Add(outpoint); OutputStack.Children.Add(outpoint); outpoint.UpdateColor(); } foreach (NodeInput i in n.Inputs) { UINodePoint inputpoint = new UINodePoint(this, graph); inputpoint.Input = i; inputpoint.VerticalAlignment = VerticalAlignment.Center; InputStack.Children.Add(inputpoint); InputNodes.Add(inputpoint); inputpoint.UpdateColor(); } n.OnUpdate += N_OnUpdate; n.OnNameUpdate += N_OnNameUpdate; n.OnInputAddedToNode += N_OnInputAddedToNode; n.OnInputRemovedFromNode += N_OnInputRemovedFromNode; n.OnOutputAddedToNode += N_OnOutputAddedToNode; n.OnOutputRemovedFromNode += N_OnOutputRemovedFromNode; N_OnUpdate(n); }
public UINodePoint(UINode n, UIGraph pc) { InitializeComponent(); loaded = false; graph = pc; Name = "NodePoint" + nodeCount++; paths = new Dictionary <UINodePoint, NodePath>(); to = new List <UINodePoint>(); Node = n; }
public UINodePoint(UINode n, UIGraph pc) { InitializeComponent(); graph = pc; Name = "NodePoint" + nodeCount++; paths = new Dictionary <UINodePoint, Path>(); to = new List <UINodePoint>(); Node = n; LayoutUpdated += UINodePoint_LayoutUpdated; }
void HandleOpen(string path) { HideStartup(); if (File.Exists(path)) { string originalPath = path; string tempFolder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "temp", System.IO.Path.GetFileNameWithoutExtension(path)); bool isFromArchive = false; if (System.IO.Path.GetExtension(path).Contains("mtga")) { MTGArchive archive = new MTGArchive(path); if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } if (!archive.UnzipTo(tempFolder)) { Log.Error("Failed to uncompress materia archive"); return; } isFromArchive = true; } UIGraph g = NewGraph(); if (g != null) { if (isFromArchive) { g.FromArchive = isFromArchive; g.FromArchivePath = path; path = System.IO.Path.Combine(tempFolder, System.IO.Path.GetFileName(path).Replace(".mtga", ".mtg")); } g.LoadGraph(path); var doc = documents[GraphDocuments.SelectedContentIndex]; doc.Title = g.GraphName; Log.Info("Opened Graph {0}", g.GraphName); recent.Add(originalPath); BuildRecentSubMenu(); } } else { Log.Warn("File does not exist: " + path); } }
void HandleOpen(string path) { if (File.Exists(path)) { UIGraph g = NewGraph(); if (g != null) { g.LoadGraph(path); var doc = documents[GraphDocuments.SelectedContentIndex]; doc.Title = g.GraphName; } } }
void HandleSave(UIGraph g, LayoutDocument doc) { if (string.IsNullOrEmpty(g.FilePath)) { ShowSaveDialog(g, doc); } else { if (g != null) { g.Save(); } } Log.Info("Saved Graph {0}", g.GraphName); }
void HandleOpen(string path) { if (File.Exists(path)) { UIGraph g = NewGraph(); if (g != null) { g.LoadGraph(path); var doc = documents[GraphDocuments.SelectedContentIndex]; //TabItem tb = (TabItem)GraphTabs.Items[GraphTabs.SelectedIndex]; //tb.Header = g.Graph.Name; doc.Title = g.Graph.Name; } } }
UIGraph NewGraph() { UIGraph g = new UIGraph(); LayoutDocument doc = new LayoutDocument(); doc.Content = g; doc.Title = g.Graph.Name; doc.Closing += Doc_Closing; doc.ContentId = g.Graph.Name + graphs.Count; doc.CanFloat = false; doc.CanMove = false; documents.Add(doc); graphs.Add(g); GraphDocuments.Children.Add(doc); GraphDocuments.SelectedContentIndex = documents.Count - 1; mnuGraphSettings.IsEnabled = true; return(g); }
public void CleanUp(System.ComponentModel.CancelEventArgs e = null, bool crash = false) { if (!crash) { for (int i = 0; i < graphs.Count; ++i) { UIGraph g = graphs[i]; LayoutDocument doc = documents[i]; if (g.Modified && !g.ReadOnly) { var result = MessageBox.Show(this, g.GraphName + " " + Properties.Resources.TITLE_HAS_BEEN_MODIFIED, Properties.Resources.TITLE_SAVE_CHANGES, MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { HandleSave(g, doc); } else if (result == MessageBoxResult.Cancel) { if (e != null) { e.Cancel = true; return; } } } } } recent.Save(); //release all opengl content foreach (UIGraph g in graphs) { if (crash) { if (!string.IsNullOrEmpty(g.FilePath)) { if (g.FromArchive) { if (string.IsNullOrEmpty(g.FromArchivePath)) { g.Save(g.FilePath + ".recovery.mtga", true); } else { g.Save(g.FromArchivePath + ".recovery.mtga", true); } } else { g.Save(g.FilePath + ".recovery.mtg", true); } } } g.DeleteTempArchiveData(); g.Release(); } graphs.Clear(); FontManager.Release(); FunctionGraph.ReleaseShaderBuffer(); //clear material and shader caches PBRMaterial.ReleaseBRDF(); ImageProcessor.ReleaseAll(); Material.Material.ReleaseAll(); //release gl view if (UI3DPreview.Instance != null) { UI3DPreview.Instance.Release(); } if (UIPreviewPane.Instance != null) { UIPreviewPane.Instance.Release(); } ViewContext.Dispose(); }
private void MenuItem_Click(object sender, RoutedEventArgs e) { MenuItem item = sender as MenuItem; ///edit if (item.Header.ToString().ToLower().Contains("graph setting")) { if (UINodeParameters.Instance != null && graphs.Count > 0) { if (GraphDocuments.SelectedContentIndex > -1) { var graph = graphs[GraphDocuments.SelectedContentIndex]; UINodeParameters.Instance.SetActive(graph.Graph); } } } ///windows else if (item.Header.ToString().ToLower().Contains("3d")) { if (Preview3DPane.IsVisible) { Preview3DPane.Hide(); } else { Preview3DPane.Show(); } } else if (item.Header.ToString().ToLower().Contains("2d")) { if (Preview2DPane.IsVisible) { Preview2DPane.Hide(); } else { Preview2DPane.Show(); } } else if (item.Header.ToString().ToLower().Contains("parameters")) { if (ParametersPane.IsVisible) { ParametersPane.Hide(); } else { ParametersPane.Show(); } } else if (item.Header.ToString().ToLower().Contains("shelf")) { if (ShelfPane.IsVisible) { ShelfPane.Hide(); } else { ShelfPane.Show(); } } //file menu else if (item.Header.ToString().ToLower().Contains("save as")) { if (graphs.Count > 0) { System.Windows.Forms.SaveFileDialog svf = new System.Windows.Forms.SaveFileDialog(); svf.CheckPathExists = true; svf.DefaultExt = ".mtg"; svf.Filter = "Materia Graph (*.mtg)|*.mtg"; if (svf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { UIGraph g = graphs[GraphDocuments.SelectedContentIndex]; if (g != null) { g.SaveAs(svf.FileName); var doc = documents[GraphDocuments.SelectedContentIndex]; doc.Title = g.Graph.Name; } } } } else if (item.Header.ToString().ToLower().Contains("save")) { if (graphs.Count > 0) { UIGraph g = graphs[GraphDocuments.SelectedContentIndex]; HandleSave(g); var doc = documents[GraphDocuments.SelectedContentIndex]; doc.Title = g.Graph.Name; } } else if (item.Header.ToString().ToLower().Contains("open")) { System.Windows.Forms.OpenFileDialog ovf = new System.Windows.Forms.OpenFileDialog(); ovf.CheckFileExists = true; ovf.CheckPathExists = true; ovf.DefaultExt = ".mtg"; ovf.Filter = "Materia Graph (*.mtg)|*.mtg"; if (ovf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { HandleOpen(ovf.FileName); } } else if (item.Header.ToString().ToLower().Contains("new")) { NewGraph(); } else if (item.Header.ToString().ToLower().Contains("export output")) { if (graphs.Count > 0 && GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count) { UIExportOutputs exportdialog = new UIExportOutputs(graphs[GraphDocuments.SelectedContentIndex]); exportdialog.ShowDialog(); } } }
private void MenuItem_Click(object sender, RoutedEventArgs e) { MenuItem item = sender as MenuItem; ///edit if (item.Header.ToString().Equals(Properties.Resources.MENU_GRAPH_SETTINGS)) { if (UINodeParameters.Instance != null && graphs.Count > 0) { if (GraphDocuments.SelectedContentIndex > -1) { var graph = graphs[GraphDocuments.SelectedContentIndex]; if (graph.Graph != null) { UINodeParameters.Instance.SetActive(graph.Graph); } } } } else if (item.Header.ToString().Equals(Properties.Resources.MENU_REDO)) { if (GraphDocuments.SelectedContentIndex > -1) { var graph = graphs[GraphDocuments.SelectedContentIndex]; graph.TryAndRedo(); } } else if (item.Header.ToString().Equals(Properties.Resources.MENU_UNDO)) { if (GraphDocuments.SelectedContentIndex > -1) { var graph = graphs[GraphDocuments.SelectedContentIndex]; graph.TryAndUndo(); } } ///windows else if (item.Header.ToString().Equals(Properties.Resources.MENU_3D_PREVIEW)) { if (Preview3DPane.IsVisible) { Preview3DPane.Hide(); } else { Preview3DPane.Show(); } } else if (item.Header.ToString().Equals(Properties.Resources.MENU_2D_PREVIEW)) { if (Preview2DPane.IsVisible) { Preview2DPane.Hide(); } else { Preview2DPane.Show(); } } else if (item.Header.ToString().Equals(Properties.Resources.MENU_PARAMETERS)) { if (ParametersPane.IsVisible) { ParametersPane.Hide(); } else { ParametersPane.Show(); } } else if (item.Header.ToString().Equals(Properties.Resources.MENU_SHELF)) { if (ShelfPane.IsVisible) { ShelfPane.Hide(); } else { ShelfPane.Show(); } } else if (item.Header.ToString().Equals(Properties.Resources.MENU_LOG)) { if (LogPane.IsVisible) { LogPane.Hide(); } else { LogPane.Show(); } } else if (item.Header.ToString().Equals(Properties.Resources.MENU_CLOSE_ALL)) { for (int i = 0; i < documents.Count; ++i) { var doc = documents[i]; doc.Close(); } } //file menu else if (item.Header.ToString().Equals(Properties.Resources.MENU_SAVE_AS)) { if (graphs.Count > 0 && GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count) { UIGraph graph = graphs[GraphDocuments.SelectedContentIndex]; LayoutDocument doc = documents[GraphDocuments.SelectedContentIndex]; ShowSaveDialog(graph, doc, true); } } else if (item.Header.ToString().Equals(Properties.Resources.MENU_SAVE)) { if (graphs.Count > 0 && GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count) { UIGraph graph = graphs[GraphDocuments.SelectedContentIndex]; LayoutDocument doc = documents[GraphDocuments.SelectedContentIndex]; HandleSave(graph, doc); } } else if (item.Header.ToString().Equals(Properties.Resources.MENU_OPEN)) { ShowOpenDialog(); } else if (item.Header.ToString().Equals(Properties.Resources.MENU_NEW)) { HandleCreate(); } else if (item.Header.ToString().Equals(Properties.Resources.MENU_EXPORT_OUTPUTS)) { if (graphs.Count > 0 && GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count) { UIExportOutputs exportdialog = new UIExportOutputs(graphs[GraphDocuments.SelectedContentIndex]); exportdialog.ShowDialog(); } } else if (item.Header.ToString().Equals("_Layers")) { if (LayersPane.IsVisible) { LayersPane.Hide(); } else { LayersPane.Show(); } } }
public UINode(Node n, UIGraph graph, double ox, double oy, double xs, double xy, double sc = 1) { InitializeComponent(); Focusable = true; InputNodes = new List <UINodePoint>(); OutputNodes = new List <UINodePoint>(); Graph = graph; xShift = xs; yShift = xy; scale = sc; Node = n; Id = n.Id; originX = ox; originY = oy; NodeName.Text = n.Name; for (int i = 0; i < n.Outputs.Count; i++) { NodeOutput op = n.Outputs[i]; UINodePoint outpoint = new UINodePoint(this, graph); outpoint.Output = op; outpoint.VerticalAlignment = VerticalAlignment.Center; OutputNodes.Add(outpoint); OutputStack.Children.Add(outpoint); } for (int i = 0; i < n.Inputs.Count; i++) { NodeInput inp = n.Inputs[i]; UINodePoint inputpoint = new UINodePoint(this, graph); inputpoint.Input = inp; inputpoint.VerticalAlignment = VerticalAlignment.Center; InputStack.Children.Add(inputpoint); InputNodes.Add(inputpoint); } n.OnNameUpdate += N_OnNameUpdate; n.OnInputAddedToNode += N_OnInputAddedToNode; n.OnInputRemovedFromNode += N_OnInputRemovedFromNode; n.OnOutputAddedToNode += N_OnOutputAddedToNode; n.OnOutputRemovedFromNode += N_OnOutputRemovedFromNode; n.OnDescriptionChanged += N_OnDescriptionChanged; if (n is MathNode) { DescPreview.Visibility = Visibility.Visible; Desc.Text = n.GetDescription(); LoadIcon(); } if (graph.Graph is FunctionGraph) { FunctionGraph f = graph.Graph as FunctionGraph; f.OnOutputSet += F_OnOutputSet; if (n == f.OutputNode) { OutputIcon.Visibility = Visibility.Visible; DescPreview.Background = HighlightBrush; } else { DescPreview.Background = DefaultBrush; OutputIcon.Visibility = Visibility.Collapsed; } if (n == f.Execute) { InputIcon.Visibility = Visibility.Visible; } else { InputIcon.Visibility = Visibility.Collapsed; } } else { if (n is OutputNode) { OutputIcon.Visibility = Visibility.Visible; } else { OutputIcon.Visibility = Visibility.Collapsed; } if (n is InputNode) { InputIcon.Visibility = Visibility.Visible; } else { InputIcon.Visibility = Visibility.Collapsed; } } }
private void MenuItem_Click(object sender, RoutedEventArgs e) { MenuItem item = sender as MenuItem; ///edit if (item.Header.ToString().ToLower().Contains("graph setting")) { if (UINodeParameters.Instance != null && graphs.Count > 0) { if (GraphDocuments.SelectedContentIndex > -1) { var graph = graphs[GraphDocuments.SelectedContentIndex]; if (graph.Graph != null) { UINodeParameters.Instance.SetActive(graph.Graph); } } } } else if (item.Header.ToString().ToLower().Contains("redo")) { if (GraphDocuments.SelectedContentIndex > -1) { var graph = graphs[GraphDocuments.SelectedContentIndex]; graph.TryAndRedo(); } } else if (item.Header.ToString().ToLower().Contains("undo")) { if (GraphDocuments.SelectedContentIndex > -1) { var graph = graphs[GraphDocuments.SelectedContentIndex]; graph.TryAndUndo(); } } ///windows else if (item.Header.ToString().ToLower().Contains("3d")) { if (Preview3DPane.IsVisible) { Preview3DPane.Hide(); } else { Preview3DPane.Show(); } } else if (item.Header.ToString().ToLower().Contains("2d")) { if (Preview2DPane.IsVisible) { Preview2DPane.Hide(); } else { Preview2DPane.Show(); } } else if (item.Header.ToString().ToLower().Contains("parameters")) { if (ParametersPane.IsVisible) { ParametersPane.Hide(); } else { ParametersPane.Show(); } } else if (item.Header.ToString().ToLower().Contains("shelf")) { if (ShelfPane.IsVisible) { ShelfPane.Hide(); } else { ShelfPane.Show(); } } else if (item.Header.ToString().ToLower().Contains("log")) { if (LogPane.IsVisible) { LogPane.Hide(); } else { LogPane.Show(); } } else if (item.Header.ToString().ToLower().Contains("close all graph")) { for (int i = 0; i < documents.Count; i++) { var doc = documents[i]; doc.Close(); } } //file menu else if (item.Header.ToString().ToLower().Contains("save as")) { if (graphs.Count > 0) { System.Windows.Forms.SaveFileDialog svf = new System.Windows.Forms.SaveFileDialog(); svf.CheckPathExists = true; svf.DefaultExt = ".mtg"; svf.Filter = "Materia Graph (*.mtg)|*.mtg|Materia Graph Archive (*.mtga)|*.mtga"; if (svf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { UIGraph g = graphs[GraphDocuments.SelectedContentIndex]; if (g != null) { g.Save(svf.FileName, true); var doc = documents[GraphDocuments.SelectedContentIndex]; doc.Title = g.GraphName; recent.Add(svf.FileName); BuildRecentSubMenu(); } } } } else if (item.Header.ToString().ToLower().Contains("save")) { if (graphs.Count > 0) { UIGraph g = graphs[GraphDocuments.SelectedContentIndex]; HandleSave(g); var doc = documents[GraphDocuments.SelectedContentIndex]; doc.Title = g.GraphName; } } else if (item.Header.ToString().ToLower().Contains("open")) { System.Windows.Forms.OpenFileDialog ovf = new System.Windows.Forms.OpenFileDialog(); ovf.CheckFileExists = true; ovf.CheckPathExists = true; ovf.DefaultExt = ".mtg"; ovf.Filter = "Materia Graph (*.mtg;*.mtga)|*.mtg;*.mtga"; if (ovf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { HandleOpen(ovf.FileName); } } else if (item.Header.ToString().ToLower().Contains("new")) { UINewGraph ngraphDialog = new UINewGraph(); ngraphDialog.Owner = this; if (ngraphDialog.ShowDialog() == false) { return; } NewGraph(ngraphDialog.Result); Log.Info("New Graph Created"); } else if (item.Header.ToString().ToLower().Contains("export output")) { if (graphs.Count > 0 && GraphDocuments.SelectedContentIndex > -1 && GraphDocuments.SelectedContentIndex < graphs.Count) { UIExportOutputs exportdialog = new UIExportOutputs(graphs[GraphDocuments.SelectedContentIndex]); exportdialog.ShowDialog(); } } }
public void CleanUp(System.ComponentModel.CancelEventArgs e = null, bool crash = false) { if (!crash) { for (int i = 0; i < graphs.Count; i++) { UIGraph g = graphs[i]; if (g.Modified && !g.ReadOnly) { var result = MessageBox.Show(this, g.GraphName + " has been modified. Do you want to save the changes?", "Save Changes", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { HandleSave(g); } else if (result == MessageBoxResult.Cancel) { if (e != null) { e.Cancel = true; return; } } } } } recent.Save(); //release all opengl content foreach (UIGraph g in graphs) { if (crash) { if (!string.IsNullOrEmpty(g.FilePath)) { if (g.FromArchive) { if (string.IsNullOrEmpty(g.FromArchivePath)) { g.Save(g.FilePath + ".recovery.mtga", true); } else { g.Save(g.FromArchivePath + ".recovery.mtga", true); } } else { g.Save(g.FilePath + ".recovery.mtg", true); } } } g.DeleteTempArchiveData(); g.Release(); } graphs.Clear(); FontManager.Release(); //clear material and shader caches PBRMaterial.ReleaseBRDF(); ImageProcessor.ReleaseAll(); Material.Material.ReleaseAll(); //release gl view if (UI3DPreview.Instance != null) { UI3DPreview.Instance.Release(); } if (UIPreviewPane.Instance != null) { UIPreviewPane.Instance.Release(); } ViewContext.Dispose(); }