почему-то после предпросмотра не строится карта, хотя до добавления предпросмотра карта…
- User
почему-то после предпросмотра не строится карта, хотя до добавления предпросмотра карта строилась
<Window.ContextMenu> </Window.ContextMenu> <Window.Effect> </Window.Effect> <Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="10"> <Button Content="Open DAT File" Click="OpenFile_Click" Width="100" Margin="0,0,10,0"/> <ComboBox x:Name="PaletteSelector" Width="120" Margin="0,0,10,0" SelectionChanged="PaletteSelector_SelectionChanged"> <ComboBoxItem Content="Rainbow"/> <ComboBoxItem Content="Hot"/> <ComboBoxItem Content="Cool"/> <ComboBoxItem Content="Gray Scale"/> </ComboBox> <TextBlock Text="Min:" VerticalAlignment="Center" Margin="0,0,5,0"/> <TextBox x:Name="MinValueBox" Width="60" Margin="0,0,10,0" TextChanged="MinValue_TextChanged"/> <TextBlock Text="Max:" VerticalAlignment="Center" Margin="0,0,5,0"/> <TextBox x:Name="MaxValueBox" Width="60" Margin="0,0,10,0" TextChanged="MaxValue_TextChanged"/> <Button Content="Auto Range" Click="AutoRange_Click" Width="80" Margin="0,0,10,0"/> <CheckBox x:Name="ReverseScale" Content="Reverse Scale" Checked="ReverseScale_CheckedChanged" Unchecked="ReverseScale_CheckedChanged" VerticalAlignment="Center"/> </StackPanel> <Image x:Name="ContourImage" Grid.Row="1" Margin="10"/> <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Visibility="Collapsed" x:Name="ColorScalePanel"> <TextBlock x:Name="MinScaleLabel" Text="Min" Margin="5,0" VerticalAlignment="Center"/> <Image x:Name="ColorScale" Height="20" Width="256"/> <TextBlock x:Name="MaxScaleLabel" Text="Max" Margin="5,0" VerticalAlignment="Center"/> </StackPanel> </Grid>using Microsoft.Win32; using System; using System.IO; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging;
namespace ContourMapVisualizer { public partial class MainWindow : Window { private double[,] data; private double minValue = double.MaxValue; private double maxValue = double.MinValue; private string currentPalette = "Rainbow"; private bool isScaleReversed = false;
public MainWindow() { InitializeComponent(); PaletteSelector.SelectedIndex = 0; } private void OpenFile_Click(object sender, RoutedEventArgs e) { var openFileDialog = new OpenFileDialog { Filter = "DAT files (*.dat)|*.dat|All files (*.*)|*.*" }; if (openFileDialog.ShowDialog() == true) { var previewWindow = new FilePreviewWindow(openFileDialog.FileName); previewWindow.Owner = this; if (previewWindow.ShowDialog() == true) { try { LoadDataFromFile(openFileDialog.FileName, previewWindow.SkipLines); UpdateContourMap(); UpdateColorScale(); ColorScalePanel.Visibility = Visibility.Visible; } catch (Exception ex) { MessageBox.Show($"Error processing file: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } } private void LoadDataFromFile(string filename, int skipLines) { var allLines = File.ReadAllLines(filename); var lines = allLines.Skip(skipLines).ToArray(); if (lines.Length == 0) { throw new Exception("No data to display after skipping lines"); } int rows = lines.Length; int cols = lines[0].Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Length; data = new double[rows, cols]; minValue = double.MaxValue; maxValue = double.MinValue; for (int i = 0; i < rows; i++) { var values = lines[i].Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (values.Length != cols) { throw new Exception($"Invalid data format at line {i + skipLines + 1}"); } for (int j = 0; j < cols; j++) { if (!double.TryParse(values[j], out double value)) { throw new Exception($"Invalid number at line {i + skipLines + 1}, position {j + 1}"); } data[i, j] = value; minValue = Math.Min(minValue, data[i, j]); maxValue = Math.Max(maxValue, data[i, j]); } } MinValueBox.Text = minValue.ToString("F2"); MaxValueBox.Text = maxValue.ToString("F2"); MinScaleLabel.Text = minValue.ToString("F2"); MaxScaleLabel.Text = maxValue.ToString("F2"); } - Assistant