diff --git a/SourceGen/WpfGui/EditVisualization.xaml.cs b/SourceGen/WpfGui/EditVisualization.xaml.cs index e213f26..d0548b0 100644 --- a/SourceGen/WpfGui/EditVisualization.xaml.cs +++ b/SourceGen/WpfGui/EditVisualization.xaml.cs @@ -376,6 +376,8 @@ namespace SourceGen.WpfGui { private void OkButton_Click(object sender, RoutedEventArgs e) { VisualizationItem item = (VisualizationItem)visComboBox.SelectedItem; Debug.Assert(item != null); + + // Generate parameter dictionary. Save a reference to it for next time. bool isWireframe = (item.VisDescriptor.VisualizationType == VisDescr.VisType.Wireframe); ReadOnlyDictionary valueDict = CreateVisGenParams(isWireframe); sLastParams = valueDict; @@ -639,6 +641,7 @@ namespace SourceGen.WpfGui { Debug.WriteLine("VisComboBox sel change: " + item.VisDescriptor.Ident); GenerateParamControls(item.VisDescriptor); + // Configure the viewer controls from the visualization, or from the previous edit. if (mOrigVis != null) { initialXSlider.Value = Util.GetFromObjDict(mOrigVis.VisGenParams, VisWireframeAnimation.P_EULER_ROT_X, 0); @@ -666,11 +669,37 @@ namespace SourceGen.WpfGui { VisWireframeAnimation.P_FRAME_COUNT, 1); FrameDelayMsec = Util.GetFromObjDict(mOrigVis.VisGenParams, VisWireframeAnimation.P_FRAME_DELAY_MSEC, 100); + } else { + initialXSlider.Value = GetLastValue(VisWireframeAnimation.P_EULER_ROT_X, 0); + initialYSlider.Value = GetLastValue(VisWireframeAnimation.P_EULER_ROT_Y, 0); + initialZSlider.Value = GetLastValue(VisWireframeAnimation.P_EULER_ROT_Z, 0); + IsWireframeAnimated = GetLastValue(VisWireframeAnimation.P_IS_ANIMATED, false); + RotDeltaX = GetLastValue(VisWireframeAnimation.P_DELTA_ROT_X, 0); + RotDeltaY = GetLastValue(VisWireframeAnimation.P_DELTA_ROT_Y, 0); + RotDeltaZ = GetLastValue(VisWireframeAnimation.P_DELTA_ROT_Z, 0); + FrameCount = GetLastValue(VisWireframeAnimation.P_FRAME_COUNT, 1); + FrameDelayMsec = GetLastValue(VisWireframeAnimation.P_FRAME_DELAY_MSEC, 100); } UpdateControls(); } + /// + /// Retrieves a value from sLastParams. + /// + /// Value's type. + /// Parameter name. + /// Default value. + /// Parameter value, or if the parameter isn't found or has the wrong type, + /// the default value. + private T GetLastValue(string name, T defVal) { + if (sLastParams.TryGetValue(name, out object val) && val is T) { + return (T)val; + } else { + return defVal; + } + } + private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { TextBox src = (TextBox)sender; ParameterValue pv = (ParameterValue)src.DataContext;