Skip to content

Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.

C#

The scene image row: "…" picks, a save glyph writes the embedded image out, the X drops it

Alexander Graefd1a5c27b7b77
diff --git a/CLAUDE.md b/CLAUDE.md
index 22d4137..3f9866c 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -250,8 +250,10 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDA
`%LOCALAPPDATA%\WaveDudeNext\ColorSchemes`, project ones in the `.wdproj`; an in-house picker edits stops;
renaming a project scheme repoints its layers. **The scene image** is embedded and follows its file on disk, the
path being where it came from (2026-10-26, Jeroen's report: the scene form shows the image rows for an image scene
- only, says "(not found)" beside a path whose file is gone, which changes nothing, and has an X beside Browse, which
- drops the name, the path and the bytes and leaves a blank canvas of the image's size);
+ only, says "(not found)" beside a path whose file is gone, which changes nothing, and has three buttons beside the name,
+ 2026-10-29, the user's design: "…" picks a file, a save glyph writes the embedded bytes to a file, an export that
+ changes nothing in the project, and the X drops the name, the path and the bytes and leaves a blank canvas of the
+ image's size);
the "glowing edges" outline overlays the pictures. **Import** of Jeroen's `configuration.json` is key for key; a source whose position was
never picked (`has_position` false) stays enabled at its x/y, since his program simulated it there (Example 11's
lattice came in disabled and ran black until 2026-10-16).
diff --git a/WaveDudeNext.WPF/Commands/ProjectCommands.cs b/WaveDudeNext.WPF/Commands/ProjectCommands.cs
index bfe1eb5..1c5570e 100644
--- a/WaveDudeNext.WPF/Commands/ProjectCommands.cs
+++ b/WaveDudeNext.WPF/Commands/ProjectCommands.cs
@@ -62,6 +62,9 @@ public static class ProjectCommands
/// <summary>Picks an image file and embeds it as the scene image.</summary>
public static readonly RoutedUICommand BrowseSceneImage = new("Browse for a scene image", nameof(BrowseSceneImage), typeof(ProjectCommands));
+ /// <summary>Writes the embedded scene image to a file of the user's choice, the bytes as they were embedded (2026-10-29, the user's design); the project is not changed.</summary>
+ public static readonly RoutedUICommand SaveSceneImage = new("Save the scene image to a file", nameof(SaveSceneImage), typeof(ProjectCommands));
+
/// <summary>Drops the scene image: a blank canvas of the image's size remains (2026-10-26, Jeroen's report: there was no way).</summary>
public static readonly RoutedUICommand RemoveSceneImage = new("Remove the scene image", nameof(RemoveSceneImage), typeof(ProjectCommands));
}
diff --git a/WaveDudeNext.WPF/MainWindow.Project.cs b/WaveDudeNext.WPF/MainWindow.Project.cs
index 1cddfb2..27dd791 100644
--- a/WaveDudeNext.WPF/MainWindow.Project.cs
+++ b/WaveDudeNext.WPF/MainWindow.Project.cs
@@ -386,4 +386,63 @@ public partial class MainWindow
scene.RemoveImage();
Logger.Info("Scene image removed: a blank canvas of {Width}×{Height}", scene.Width, scene.Height);
}
+
+ private void CanSaveSceneImage(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = Project.Scene is { ImageData: not null };
+
+ /// <summary>
+ /// The save button between the picker and the X (2026-10-29, the user's design): writes the embedded bytes, the file as
+ /// it was embedded, to a file of the user's choice, proposed under the image's name in its folder when that exists, else
+ /// the project's. An export: the project, its path and the watcher stay as they are.
+ /// </summary>
+ private void OnSaveSceneImage(object sender, ExecutedRoutedEventArgs e)
+ {
+ Scene scene = Project.Scene;
+ if (scene.ImageData is not { } bytes)
+ {
+ return;
+ }
+ string extension = Path.GetExtension(scene.Image);
+ if (extension.Length == 0)
+ {
+ extension = ImageExtension(bytes);
+ }
+ string resolved = scene.ResolveImagePath(ProjectFolder);
+ string? folder = resolved.Length > 0 ? Path.GetDirectoryName(resolved) : null;
+ var dialog = new SaveFileDialog
+ {
+ Title = (string)FindResource("TipSaveSceneImage"),
+ // the embedded file's own type; an unknown one gets the picker's list
+ Filter = extension.Length > 0 ? string.Format((string)FindResource("SceneImageSaveFilterFormat"), extension) : (string)FindResource("SceneImageFilter"),
+ AddExtension = extension.Length > 0,
+ DefaultExt = extension,
+ FileName = scene.Image.Length > 0 ? scene.Image : ProjectName() + "_scene" + extension,
+ InitialDirectory = folder != null && Directory.Exists(folder) ? folder : ProjectFolder ?? "",
+ };
+ if (dialog.ShowDialog(this) != true)
+ {
+ Logger.Debug("Scene image save cancelled in the Save dialog");
+ return;
+ }
+ try
+ {
+ File.WriteAllBytes(dialog.FileName, bytes);
+ Logger.Info("Scene image saved: {Size} KB to {Path}", Math.Max(1, bytes.Length / 1024), dialog.FileName);
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
+ {
+ Logger.Error(ex, "The scene image could not be saved: {Message}", ex.Message);
+ ShowError(string.Format((string)FindResource("SceneImageSaveError"), dialog.FileName), ex);
+ }
+ }
+
+ /// <summary>The file extension of an image's bytes by their signature: PNG, JPEG, BMP, GIF or TIFF; "" when unknown.</summary>
+ private static string ImageExtension(byte[] bytes) => bytes switch
+ {
+ [0x89, 0x50, 0x4E, 0x47, ..] => ".png",
+ [0xFF, 0xD8, 0xFF, ..] => ".jpg",
+ [0x42, 0x4D, ..] => ".bmp",
+ [0x47, 0x49, 0x46, 0x38, ..] => ".gif",
+ [0x49, 0x49, 0x2A, 0x00, ..] or [0x4D, 0x4D, 0x00, 0x2A, ..] => ".tif",
+ _ => "",
+ };
}
diff --git a/WaveDudeNext.WPF/MainWindow.xaml b/WaveDudeNext.WPF/MainWindow.xaml
index 516b10a..7a7ffc6 100644
--- a/WaveDudeNext.WPF/MainWindow.xaml
+++ b/WaveDudeNext.WPF/MainWindow.xaml
@@ -208,6 +208,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<CommandBinding Command="{x:Static commands:ProjectCommands.SelectAll}" CanExecute="CanSelectAll" Executed="OnSelectAll" />
<CommandBinding Command="{x:Static commands:ProjectCommands.ToggleSelected}" CanExecute="CanToggleSelected" Executed="OnToggleSelected" />
<CommandBinding Command="{x:Static commands:ProjectCommands.BrowseSceneImage}" Executed="OnBrowseSceneImage" />
+ <CommandBinding Command="{x:Static commands:ProjectCommands.SaveSceneImage}" CanExecute="CanSaveSceneImage" Executed="OnSaveSceneImage" />
<CommandBinding Command="{x:Static commands:ProjectCommands.RemoveSceneImage}" CanExecute="CanRemoveSceneImage" Executed="OnRemoveSceneImage" />
<CommandBinding Command="{x:Static commands:HelpCommands.About}" Executed="OnHelpAbout" />
</Window.CommandBindings>
diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
index e2c3678..bab38b5 100644
--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
@@ -332,7 +332,9 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ItemCountOne">1 Eintrag</s:String>
<s:String x:Key="ItemCountMany">{0} Einträge</s:String>
- <s:String x:Key="ButtonBrowse">Durchsuchen…</s:String>
+ <s:String x:Key="TipSaveSceneImage">Eingebettetes Bild in eine Datei speichern</s:String>
+ <s:String x:Key="SceneImageSaveFilterFormat">Bilddatei (*{0})|*{0}|Alle Dateien (*.*)|*.*</s:String>
+ <s:String x:Key="SceneImageSaveError">Das Bild konnte nicht nach '{0}' gespeichert werden</s:String>
<s:String x:Key="TipBrowseSceneImage">Bilddatei wählen; sie wird in das Projekt eingebettet</s:String>
<s:String x:Key="TipRemoveSceneImage">Eingebettetes Bild und Dateipfad verwerfen; die Leinwand behält die Bildgröße</s:String>
<s:String x:Key="SceneImageNotFound">(nicht gefunden)</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
index 149a912..47f95f7 100644
--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
@@ -334,7 +334,9 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ItemCountOne">1 entry</s:String>
<s:String x:Key="ItemCountMany">{0} entries</s:String>
- <s:String x:Key="ButtonBrowse">Browse…</s:String>
+ <s:String x:Key="TipSaveSceneImage">Save the embedded image to a file</s:String>
+ <s:String x:Key="SceneImageSaveFilterFormat">Image file (*{0})|*{0}|All files (*.*)|*.*</s:String>
+ <s:String x:Key="SceneImageSaveError">The image could not be saved to '{0}'</s:String>
<s:String x:Key="TipBrowseSceneImage">Pick an image file; it is embedded in the project</s:String>
<s:String x:Key="TipRemoveSceneImage">Drop the embedded image and its file path; the canvas keeps the image's size</s:String>
<s:String x:Key="SceneImageNotFound">(not found)</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
index 4df4b5a..99f70a8 100644
--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
@@ -332,7 +332,9 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ItemCountOne">1 entrée</s:String>
<s:String x:Key="ItemCountMany">{0} entrées</s:String>
- <s:String x:Key="ButtonBrowse">Parcourir…</s:String>
+ <s:String x:Key="TipSaveSceneImage">Enregistrer l'image intégrée dans un fichier</s:String>
+ <s:String x:Key="SceneImageSaveFilterFormat">Fichier image (*{0})|*{0}|Tous les fichiers (*.*)|*.*</s:String>
+ <s:String x:Key="SceneImageSaveError">L'image n'a pas pu être enregistrée dans '{0}'</s:String>
<s:String x:Key="TipBrowseSceneImage">Choisir un fichier image ; il est intégré au projet</s:String>
<s:String x:Key="TipRemoveSceneImage">Abandonne l'image intégrée et son chemin ; la toile garde la taille de l'image</s:String>
<s:String x:Key="SceneImageNotFound">(introuvable)</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
index 7fc9944..c6d2ba6 100644
--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
@@ -332,7 +332,9 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ItemCountOne">1 item</s:String>
<s:String x:Key="ItemCountMany">{0} items</s:String>
- <s:String x:Key="ButtonBrowse">Bladeren…</s:String>
+ <s:String x:Key="TipSaveSceneImage">Ingebedde afbeelding naar een bestand opslaan</s:String>
+ <s:String x:Key="SceneImageSaveFilterFormat">Afbeeldingsbestand (*{0})|*{0}|Alle bestanden (*.*)|*.*</s:String>
+ <s:String x:Key="SceneImageSaveError">De afbeelding kon niet naar '{0}' worden opgeslagen</s:String>
<s:String x:Key="TipBrowseSceneImage">Kies een afbeeldingsbestand; het wordt in het project ingebed</s:String>
<s:String x:Key="TipRemoveSceneImage">Laat de ingebedde afbeelding en het bestandspad vallen; het canvas houdt de grootte van de afbeelding</s:String>
<s:String x:Key="SceneImageNotFound">(niet gevonden)</s:String>
diff --git a/WaveDudeNext.WPF/Views/SceneView.xaml b/WaveDudeNext.WPF/Views/SceneView.xaml
index 5e677b4..8590a8b 100644
--- a/WaveDudeNext.WPF/Views/SceneView.xaml
+++ b/WaveDudeNext.WPF/Views/SceneView.xaml
@@ -63,20 +63,34 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
SelectedItem="{Binding Mode}" ToolTip="{meta:Hint model:Scene.Mode}" />
<TextBlock Style="{StaticResource ImageRowLabel}" Text="{meta:Label model:Scene.Image}" />
- <!-- the name of the embedded image (or a legacy path), the picker that embeds a file, and the X that removes the image
- (2026-10-26, Jeroen's report: there was no way to drop one), leaving a blank canvas of the image's size; the X is
- the panes' close glyph in the button's text colour, so it greys with the button -->
- <DockPanel Style="{StaticResource ImageRow}">
- <Button DockPanel.Dock="Right" Margin="4,0,0,0" Padding="7,0" ToolTip="{DynamicResource TipRemoveSceneImage}"
+ <!-- the name of the embedded image (or a legacy path) and three buttons (2026-10-29, the user's design): "…" picks a file
+ and embeds it, the save glyph (the File menu's) writes the embedded image to a file and changes nothing in the
+ project, and the X removes the image (2026-10-26, Jeroen's report: there was no way to drop one), leaving a blank
+ canvas of the image's size; the X is the panes' close glyph in the button's text colour, so it greys with the button -->
+ <!-- a grid in visual order, so Tab walks the name, then "…", save, X (a dock panel's right-docked buttons are declared
+ right to left and tabbed that way, and a tab index sorts ahead of the whole window) -->
+ <Grid Style="{StaticResource ImageRow}">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*" />
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition Width="Auto" />
+ </Grid.ColumnDefinitions>
+ <TextBox Text="{Binding Image, UpdateSourceTrigger=PropertyChanged}" ToolTip="{meta:Hint model:Scene.Image}" />
+ <Button Grid.Column="1" Margin="4,0,0,0" Padding="8,0" Content="…" ToolTip="{DynamicResource TipBrowseSceneImage}"
+ AutomationProperties.Name="{DynamicResource TipBrowseSceneImage}" Command="{x:Static commands:ProjectCommands.BrowseSceneImage}"
+ AutomationProperties.AutomationId="SceneBrowse" />
+ <Button Grid.Column="2" Margin="4,0,0,0" Padding="5,0" ToolTip="{DynamicResource TipSaveSceneImage}"
+ AutomationProperties.Name="{DynamicResource TipSaveSceneImage}" Command="{x:Static commands:ProjectCommands.SaveSceneImage}"
+ AutomationProperties.AutomationId="SceneSaveImage">
+ <controls:IconView Glyph="&#xE74E;" />
+ </Button>
+ <Button Grid.Column="3" Margin="4,0,0,0" Padding="7,0" ToolTip="{DynamicResource TipRemoveSceneImage}"
AutomationProperties.Name="{DynamicResource TipRemoveSceneImage}" Command="{x:Static commands:ProjectCommands.RemoveSceneImage}"
AutomationProperties.AutomationId="SceneRemoveImage">
<Path Data="{StaticResource CloseGeometry}" Width="8" Height="8" Stretch="Uniform" Fill="{Binding (TextElement.Foreground), RelativeSource={RelativeSource Self}}" />
</Button>
- <Button DockPanel.Dock="Right" Margin="4,0,0,0" Padding="8,0" Content="{DynamicResource ButtonBrowse}"
- ToolTip="{DynamicResource TipBrowseSceneImage}" Command="{x:Static commands:ProjectCommands.BrowseSceneImage}"
- AutomationProperties.AutomationId="SceneBrowse" />
- <TextBox Text="{Binding Image, UpdateSourceTrigger=PropertyChanged}" ToolTip="{meta:Hint model:Scene.Image}" />
- </DockPanel>
+ </Grid>
<TextBlock Style="{StaticResource ImageRowLabel}" Text="{meta:Label model:Scene.ImagePath}" />
<!-- the path and, when the file is not on disk, a note (the window checks; the embedded image is what is simulated) -->