Skip to content

Commit fca4034

Browse files
committed
2 parents adb6547 + b199357 commit fca4034

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

GraphLayout/Drawing/SvgGraphWriter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.IO;
@@ -156,12 +156,12 @@ protected virtual void WriteLabel(Label label)
156156
{
157157
if (!LabelIsValid(label))
158158
return;
159-
//need to remove these hecks. TODO
159+
//need to remove the hack. TODO
160160
const double yScaleAdjustment = 1.5;
161161

162162
var x = label.Center.X - label.Width / 2;
163163
var y = label.Center.Y + label.Height / (2 * yScaleAdjustment);
164-
var fontSize = 16;
164+
var fontSize = label.fontsize;
165165
WriteStartElement("text");
166166
WriteAttribute("x", x);
167167
WriteAttribute("y", y);
@@ -955,4 +955,4 @@ public void WriteLine(Point a, Point b) {
955955
WriteEndElement();
956956
}
957957
}
958-
}
958+
}

GraphLayout/Test/TestWpfViewer/App.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ internal class App : Application {
9292

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

9697

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

606607

607608
void SetCommands() {
609+
appWindow.CommandBindings.Add(new CommandBinding(SaveSvgCommand, SaveSvg));
610+
608611
appWindow.CommandBindings.Add(new CommandBinding(SaveImageCommand, SaveImage));
609612
appWindow.CommandBindings.Add(new CommandBinding(SaveMsaglCommand, SaveMsagl));
610613
appWindow.CommandBindings.Add(new CommandBinding(ExitCommand, ExitHandler));
@@ -629,6 +632,29 @@ void SetCommands() {
629632

630633
}
631634

635+
private void SaveSvg(object sender, ExecutedRoutedEventArgs e) {
636+
if (graphViewer.Graph==null) {
637+
MessageBox.Show("Graph is not loaded", "No Graph", MessageBoxButton.OK, MessageBoxImage.Error);
638+
return;
639+
}
640+
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
641+
dlg.FileName = lastFileName + ".svg"; // Default file name
642+
dlg.DefaultExt = ".svg "; // Default file extension
643+
dlg.Filter = "svg files (.svg )|*.svg "; // Filter files by extension
644+
645+
Nullable<bool> result = dlg.ShowDialog();
646+
647+
if (result != true) {
648+
return;
649+
}
650+
651+
using (StreamWriter writer = new StreamWriter(dlg.FileName)) {
652+
var svgWriter = new SvgGraphWriter(writer.BaseStream, graphViewer.Graph);
653+
svgWriter.Write();
654+
}
655+
656+
}
657+
632658
void SaveImage(object sender, ExecutedRoutedEventArgs e)
633659
{
634660
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
@@ -641,6 +667,7 @@ void SaveImage(object sender, ExecutedRoutedEventArgs e)
641667
if (result == true)
642668
{
643669
graphViewer.DrawImage(dlg.FileName);
670+
644671
}
645672
}
646673

@@ -693,7 +720,9 @@ void SetViewMenu(Menu mainMenu) {
693720
void SetFileMenu(Menu mainMenu) {
694721
var fileMenu = new MenuItem {Header = "_File"};
695722
var openFileMenuItem = new MenuItem {Header = "_Open", Command = OpenFileCommand};
696-
fileMenu.Items.Add(openFileMenuItem);
723+
fileMenu.Items.Add(openFileMenuItem);
724+
fileMenu.Items.Add(new MenuItem { Header = "Save _SVG", Command = SaveSvgCommand });
725+
697726
var reloadFileMenuItem = new MenuItem {Header = "_Reload", Command = ReloadCommand};
698727
fileMenu.Items.Add(reloadFileMenuItem);
699728

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

705-
var saveImageMenuItem = new MenuItem { Header = "_Save Image", Command = SaveImageCommand };
734+
var saveImageMenuItem = new MenuItem { Header = "Save _Image", Command = SaveImageCommand };
706735
fileMenu.Items.Add(saveImageMenuItem);
707736

708737
var saveMsaglMenuItem = new MenuItem { Header = "_Save MSAGL", Command = SaveMsaglCommand };

GraphLayout/tools/WpfGraphControl/GraphViewer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,11 @@ static TextBlock CreateTextBlock(Label drawingLabel) {
14391439
textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
14401440
textBlock.Width = textBlock.DesiredSize.Width;
14411441
textBlock.Height = textBlock.DesiredSize.Height;
1442+
if (drawingLabel.GeometryLabel == null) {
1443+
drawingLabel.GeometryLabel = new Core.Layout.Label();
1444+
}
1445+
drawingLabel.GeometryLabel.Width = textBlock.Width;
1446+
drawingLabel.GeometryLabel.Height = textBlock.Height;
14421447
return textBlock;
14431448
}
14441449

@@ -1729,4 +1734,4 @@ void MakeRoomForNewNode(Drawing.Node drawingNode) {
17291734
public bool IncrementalDraggingModeAlways { get; set; }
17301735
public bool CreateToolTipForNodes { get => createToolTipForNodes; private set => createToolTipForNodes = value; }
17311736
}
1732-
}
1737+
}

0 commit comments

Comments
 (0)