Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
levnach committed Sep 18, 2024
2 parents adb6547 + b199357 commit fca4034
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
8 changes: 4 additions & 4 deletions GraphLayout/Drawing/SvgGraphWriter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -156,12 +156,12 @@ protected virtual void WriteLabel(Label label)
{
if (!LabelIsValid(label))
return;
//need to remove these hecks. TODO
//need to remove the hack. TODO
const double yScaleAdjustment = 1.5;

var x = label.Center.X - label.Width / 2;
var y = label.Center.Y + label.Height / (2 * yScaleAdjustment);
var fontSize = 16;
var fontSize = label.fontsize;
WriteStartElement("text");
WriteAttribute("x", x);
WriteAttribute("y", y);
Expand Down Expand Up @@ -955,4 +955,4 @@ public void WriteLine(Point a, Point b) {
WriteEndElement();
}
}
}
}
33 changes: 31 additions & 2 deletions GraphLayout/Test/TestWpfViewer/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ internal class App : Application {

public static readonly RoutedUICommand OpenFileCommand = new RoutedUICommand("Open File...", "OpenFileCommand",
typeof (App));
public static readonly RoutedUICommand SaveSvgCommand = new RoutedUICommand("Save SVG", "SaveSvgCommand", typeof(App));


public static readonly RoutedUICommand CancelLayoutCommand = new RoutedUICommand("Cancel Layout...", "CancelLayoutCommand",
Expand Down Expand Up @@ -605,6 +606,8 @@ void UpdateThumbOnDrag(Slider slider, double del, Thumb draggedThumb) {


void SetCommands() {
appWindow.CommandBindings.Add(new CommandBinding(SaveSvgCommand, SaveSvg));

appWindow.CommandBindings.Add(new CommandBinding(SaveImageCommand, SaveImage));
appWindow.CommandBindings.Add(new CommandBinding(SaveMsaglCommand, SaveMsagl));
appWindow.CommandBindings.Add(new CommandBinding(ExitCommand, ExitHandler));
Expand All @@ -629,6 +632,29 @@ void SetCommands() {

}

private void SaveSvg(object sender, ExecutedRoutedEventArgs e) {
if (graphViewer.Graph==null) {
MessageBox.Show("Graph is not loaded", "No Graph", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = lastFileName + ".svg"; // Default file name
dlg.DefaultExt = ".svg "; // Default file extension
dlg.Filter = "svg files (.svg )|*.svg "; // Filter files by extension

Nullable<bool> result = dlg.ShowDialog();

if (result != true) {
return;
}

using (StreamWriter writer = new StreamWriter(dlg.FileName)) {
var svgWriter = new SvgGraphWriter(writer.BaseStream, graphViewer.Graph);
svgWriter.Write();
}

}

void SaveImage(object sender, ExecutedRoutedEventArgs e)
{
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
Expand All @@ -641,6 +667,7 @@ void SaveImage(object sender, ExecutedRoutedEventArgs e)
if (result == true)
{
graphViewer.DrawImage(dlg.FileName);

}
}

Expand Down Expand Up @@ -693,7 +720,9 @@ void SetViewMenu(Menu mainMenu) {
void SetFileMenu(Menu mainMenu) {
var fileMenu = new MenuItem {Header = "_File"};
var openFileMenuItem = new MenuItem {Header = "_Open", Command = OpenFileCommand};
fileMenu.Items.Add(openFileMenuItem);
fileMenu.Items.Add(openFileMenuItem);
fileMenu.Items.Add(new MenuItem { Header = "Save _SVG", Command = SaveSvgCommand });

var reloadFileMenuItem = new MenuItem {Header = "_Reload", Command = ReloadCommand};
fileMenu.Items.Add(reloadFileMenuItem);

Expand All @@ -702,7 +731,7 @@ void SetFileMenu(Menu mainMenu) {
mainMenu.Items.Add(fileMenu);
toolBar.Items.Add(mainMenu);

var saveImageMenuItem = new MenuItem { Header = "_Save Image", Command = SaveImageCommand };
var saveImageMenuItem = new MenuItem { Header = "Save _Image", Command = SaveImageCommand };
fileMenu.Items.Add(saveImageMenuItem);

var saveMsaglMenuItem = new MenuItem { Header = "_Save MSAGL", Command = SaveMsaglCommand };
Expand Down
7 changes: 6 additions & 1 deletion GraphLayout/tools/WpfGraphControl/GraphViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,11 @@ static TextBlock CreateTextBlock(Label drawingLabel) {
textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
textBlock.Width = textBlock.DesiredSize.Width;
textBlock.Height = textBlock.DesiredSize.Height;
if (drawingLabel.GeometryLabel == null) {
drawingLabel.GeometryLabel = new Core.Layout.Label();
}
drawingLabel.GeometryLabel.Width = textBlock.Width;
drawingLabel.GeometryLabel.Height = textBlock.Height;
return textBlock;
}

Expand Down Expand Up @@ -1729,4 +1734,4 @@ void MakeRoomForNewNode(Drawing.Node drawingNode) {
public bool IncrementalDraggingModeAlways { get; set; }
public bool CreateToolTipForNodes { get => createToolTipForNodes; private set => createToolTipForNodes = value; }
}
}
}

0 comments on commit fca4034

Please sign in to comment.