mirror of
https://github.com/denglihong2007/CRSim
synced 2026-08-04 16:26:24 +08:00
feat: 站台占用图自定义宽度
This commit is contained in:
@@ -8,14 +8,14 @@ using iText.Kernel.Pdf.Canvas;
|
||||
using iText.Layout;
|
||||
using iText.Layout.Element;
|
||||
using iText.Layout.Properties;
|
||||
using System.Reflection;
|
||||
|
||||
namespace CRSim.PlatformDiagram
|
||||
{
|
||||
public class Generator
|
||||
{
|
||||
public static void Generate(Station station, string savePath)
|
||||
{
|
||||
float PageWidth = 5000;
|
||||
public static void Generate(Station station, string savePath, float pageWidth)
|
||||
{
|
||||
float Padding = 40;
|
||||
float HeaderHeight = 16;
|
||||
float PlatformTableVerticalMargin = 9;
|
||||
@@ -31,7 +31,7 @@ namespace CRSim.PlatformDiagram
|
||||
|
||||
int platformCount = station.Platforms.Count;
|
||||
float pageHeight = (Padding + TimelineHeight + PlatformTableVerticalMargin) * 2 + platformCount * PlatformHeight + HeaderHeight;
|
||||
Document doc = new(pdf, new PageSize(PageWidth, pageHeight)); doc.SetMargins(Padding, Padding, Padding, Padding);
|
||||
Document doc = new(pdf, new PageSize(pageWidth, pageHeight)); doc.SetMargins(Padding, Padding, Padding, Padding);
|
||||
var canvas = new PdfCanvas(pdf.AddNewPage());
|
||||
TimeSpan startTime = TimeSpan.FromHours(0);
|
||||
TimeSpan endTime = TimeSpan.FromHours(24);
|
||||
@@ -44,7 +44,7 @@ namespace CRSim.PlatformDiagram
|
||||
// 绘制整条横线
|
||||
canvas.SetLineWidth(1f);
|
||||
var xStart = Padding + InfoBarWidth + PlatformTableHorizontalMargin - TimelineExtLength;
|
||||
var xEnd = PageWidth - Padding;
|
||||
var xEnd = pageWidth - Padding;
|
||||
var yTop = pageHeight - Padding - HeaderHeight - TimelineHeight;
|
||||
var yBottom = Padding + TimelineHeight;
|
||||
canvas.MoveTo(xStart, yTop).LineTo(xEnd, yTop).Stroke();
|
||||
@@ -54,7 +54,7 @@ namespace CRSim.PlatformDiagram
|
||||
var xBase = Padding + InfoBarWidth + PlatformTableHorizontalMargin;
|
||||
yTop = pageHeight - Padding - HeaderHeight - TimelineHeight - PlatformTableVerticalMargin;
|
||||
yBottom = Padding + TimelineHeight + PlatformTableVerticalMargin;
|
||||
var PlatformTableLength = PageWidth - Padding * 2 - InfoBarWidth - PlatformTableHorizontalMargin - TimelineExtLength;
|
||||
var PlatformTableLength = pageWidth - Padding * 2 - InfoBarWidth - PlatformTableHorizontalMargin - TimelineExtLength;
|
||||
for (TimeSpan t = startTime; t <= endTime; t += TimeSpan.FromMinutes(intervalMin))
|
||||
{
|
||||
float x = xBase + MapTime(t, startTime, endTime, PlatformTableLength);
|
||||
@@ -221,7 +221,19 @@ namespace CRSim.PlatformDiagram
|
||||
.SetFontSize(18)
|
||||
.SetFontColor(ColorConstants.BLUE)
|
||||
.SetMargins(0,0,0,0));
|
||||
foreach(var kvp in platformHeights)
|
||||
|
||||
string text = $"使用 CRSim v{Assembly.GetExecutingAssembly().GetName().Version} 绘制";
|
||||
float fontSize = 12f;
|
||||
var para = new Paragraph(text)
|
||||
.SetFont(font)
|
||||
.SetFontSize(fontSize)
|
||||
.SetFontColor(ColorConstants.BLUE)
|
||||
.SetMargins(0, 0, 0, 0);
|
||||
rect1 = new(pageWidth - Padding - font.GetWidth(text, fontSize), pageHeight - Padding, 500, HeaderHeight);
|
||||
layoutCanvas = new Canvas(canvas, rect1);
|
||||
layoutCanvas.Add(para);
|
||||
|
||||
foreach (var kvp in platformHeights)
|
||||
{
|
||||
rect1 = new(Padding, kvp.Value + PlatformHeight / 2 - 10, InfoBarWidth, 20);
|
||||
layoutCanvas = new Canvas(canvas, rect1);
|
||||
|
||||
@@ -9,7 +9,10 @@ public partial class PlatformDiagramPageViewModel(IDialogService _dialogService,
|
||||
public List<Station> Stations => _databaseService.GetAllStations();
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsSelected { get; set; } = false;
|
||||
public partial bool Validated { get; set; } = false;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial int PageWidth { get; set; } = 5000;
|
||||
|
||||
[RelayCommand]
|
||||
public void StationSelected(object s)
|
||||
@@ -17,10 +20,14 @@ public partial class PlatformDiagramPageViewModel(IDialogService _dialogService,
|
||||
if(s is Station station)
|
||||
{
|
||||
SelectedStation = station;
|
||||
IsSelected = true;
|
||||
}
|
||||
Validate();
|
||||
}
|
||||
[RelayCommand]
|
||||
public void Validate()
|
||||
{
|
||||
Validated = SelectedStation != null && PageWidth > 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task Generate()
|
||||
{
|
||||
@@ -30,7 +37,7 @@ public partial class PlatformDiagramPageViewModel(IDialogService _dialogService,
|
||||
}
|
||||
var path = _dialogService.SaveFile(".pdf", $"{SelectedStation.Name}站台占用图");
|
||||
if(string.IsNullOrEmpty(path) || SelectedStation == null) return;
|
||||
await Task.Run(() => Generator.Generate(SelectedStation, path));
|
||||
await Task.Run(() => Generator.Generate(SelectedStation, path,PageWidth));
|
||||
}
|
||||
|
||||
public static bool CheckStation(Station station,out string detail)
|
||||
|
||||
@@ -22,18 +22,30 @@
|
||||
Style="{StaticResource TitleTextBlockStyle}"/>
|
||||
<ScrollViewer Grid.Row="1" Padding="0,0,36,0">
|
||||
<StackPanel>
|
||||
<TextBlock Text="参数配置" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Margin="0,0,0,12"/>
|
||||
<StackPanel Spacing="4" Orientation="Vertical" Margin="0,0,0,24">
|
||||
<controls:SettingsCard Header="车站" Description="选择目标车站。" HeaderIcon="{winui:FontIcon Glyph=}">
|
||||
<ComboBox ItemsSource="{x:Bind ViewModel.Stations}" DisplayMemberPath="Name" Name="StationsComboBox">
|
||||
<i:Interaction.Behaviors>
|
||||
<i:EventTriggerBehavior EventName="SelectionChanged">
|
||||
<i:InvokeCommandAction Command="{x:Bind ViewModel.StationSelectedCommand}" CommandParameter="{x:Bind StationsComboBox.SelectedItem, Mode=OneWay}"/>
|
||||
</i:EventTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
</ComboBox>
|
||||
</controls:SettingsCard>
|
||||
<controls:SettingsCard Header="页宽" Description="生成的 PDF 页面宽度。" HeaderIcon="{winui:FontIcon Glyph=}">
|
||||
<NumberBox Value="{x:Bind ViewModel.PageWidth, Mode=TwoWay}" Width="120">
|
||||
<i:Interaction.Behaviors>
|
||||
<i:EventTriggerBehavior EventName="ValueChanged">
|
||||
<i:InvokeCommandAction Command="{x:Bind ViewModel.ValidateCommand}"/>
|
||||
</i:EventTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
</NumberBox>
|
||||
</controls:SettingsCard>
|
||||
</StackPanel>
|
||||
<TextBlock Text="操作" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Margin="0,0,0,12"/>
|
||||
<controls:SettingsCard Header="车站" Description="选择目标车站。" HeaderIcon="{winui:FontIcon Glyph=}">
|
||||
<ComboBox ItemsSource="{x:Bind ViewModel.Stations}" DisplayMemberPath="Name" Name="StationsComboBox">
|
||||
<i:Interaction.Behaviors>
|
||||
<i:EventTriggerBehavior EventName="SelectionChanged">
|
||||
<i:InvokeCommandAction Command="{x:Bind ViewModel.StationSelectedCommand}" CommandParameter="{x:Bind StationsComboBox.SelectedItem, Mode=OneWay}"/>
|
||||
</i:EventTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
</ComboBox>
|
||||
</controls:SettingsCard>
|
||||
<controls:SettingsCard Margin="0,4,0,0" Header="生成并保存图示" Description="选择位置保存图示。" HeaderIcon="{winui:FontIcon Glyph=}">
|
||||
<Button Content="生成" IsEnabled="{x:Bind ViewModel.IsSelected, Mode=OneWay}" Style="{StaticResource AccentButtonStyle}"
|
||||
<Button Content="生成" IsEnabled="{x:Bind ViewModel.Validated, Mode=OneWay}" Style="{StaticResource AccentButtonStyle}"
|
||||
Command="{x:Bind ViewModel.GenerateCommand}"/>
|
||||
</controls:SettingsCard>
|
||||
</StackPanel>
|
||||
|
||||
Reference in New Issue
Block a user