增加 pdf 文档

This commit is contained in:
Tian jianyong 2024-12-31 13:05:26 +08:00
parent 2969706400
commit a8467d9e6b
7 changed files with 486 additions and 50 deletions

BIN
ThreatSource-Library.pdf Normal file

Binary file not shown.

View File

@ -6,21 +6,10 @@
"src": "./",
"files": [
"ThreatSource/ThreatSource.csproj"
],
"exclude": [
"**/obj/**",
"**/bin/**",
"**/ThreatSource.Tests/**",
"_site/**"
]
}
],
"dest": "docs/api",
"disableGitFeatures": false,
"disableDefaultFilter": false,
"properties": {
"TargetFramework": "net8.0"
}
"dest": "docs/api"
}
],
"build": {
@ -37,30 +26,18 @@
"docs/articles/**/toc.yml",
"docs/toc.yml",
"docs/*.md",
"docs/examples/**/*.md",
"docs/examples/**/*.cs"
],
"exclude": [
"docs/obj/**",
"docs/_site/**"
"docs/examples/**/*.md"
]
}
],
"resource": [
{
"files": [
"docs/images/**"
]
}
],
"overwrite": [
{
"files": [
"docs/apidoc/**.md"
],
"exclude": [
"docs/obj/**",
"docs/_site/**"
"docs/images/**",
"docs/styles/**",
"docs/cover.html",
"docs/examples/**/*.cs",
"docs/examples/**/*.cpp"
]
}
],
@ -68,20 +45,37 @@
"globalMetadata": {
"_appTitle": "威胁源仿真库",
"_appFooter": "威胁源仿真库文档",
"_enableSearch": true,
"_language": "zh-cn",
"_disableContribution": true
"pdf": true,
"_disableContribution": true,
"_baseUrl": ""
},
"globalMetadataFiles": [],
"fileMetadataFiles": [],
"template": [
"default"
"pdf": {
"content": [
{
"files": [
"docs/toc.yml",
"docs/*.md",
"docs/articles/**.md",
"docs/examples/**/*.md",
"docs/api/**.yml",
"docs/api/index.md"
]
}
],
"postProcessors": [],
"markdownEngineName": "markdig",
"noLangKeyword": false,
"keepFileLink": false,
"cleanupCacheHistory": false,
"disableGitFeatures": false
"wkhtmltopdf": {
"additionalArguments": "--enable-local-file-access --page-size A4 --margin-top 20 --margin-bottom 20 --margin-left 20 --margin-right 20 --footer-left \"威胁源仿真库文档\" --footer-right \"[page]/[topage]\" --footer-spacing 8 --footer-font-size 8"
},
"coverPage": {
"title": "威胁源仿真库文档",
"author": "ThreatSource Team",
"template": "docs/cover.html"
}
},
"template": [
"default",
"templates/pdf"
],
"markdownEngineName": "markdig"
}
}

View File

@ -13,6 +13,69 @@
- 事件的发布和订阅
- 数据的适配和转换
#### 源代码
```csharp
#if NEVER // 使用编译指令确保此文件永远不会被编译
// 第三方系统实现适配器示例代码
// 以虚幻引擎为例
// 需要实现的方法: GetEntity, PublishToExternalSimulation, ReceiveFromExternalSimulation
using ThreatSource.Simulation;
/// <summary>
/// 虚幻引擎适配器类,演示如何将第三方系统集成到仿真系统中
/// </summary>
public class UnrealEngineAdapter : ISimulationAdapter
{
/// <summary>
/// 虚幻引擎API接口定义了与虚幻引擎交互的基本方法
/// </summary>
public interface IUnrealEngine
{
/// <summary>
/// 根据ID获取虚幻引擎中的Actor对象
/// </summary>
object? GetActor(string id);
/// <summary>
/// 在虚幻引擎中生成导弹实体
/// </summary>
void SpawnMissile(string senderId, string targetId);
}
private readonly IUnrealEngine _unrealEngine;
private readonly ISimulationManager _simulationManager;
public UnrealEngineAdapter(IUnrealEngine unrealEngine, ISimulationManager simulationManager)
{
_unrealEngine = unrealEngine ?? throw new ArgumentNullException(nameof(unrealEngine));
_simulationManager = simulationManager ?? throw new ArgumentNullException(nameof(simulationManager));
}
public object? GetEntity(string id)
{
return _unrealEngine.GetActor(id);
}
public void PublishToExternalSimulation<T>(T evt)
{
if (evt is MissileFireEvent missileEvt)
{
_unrealEngine.SpawnMissile(missileEvt.SenderId, missileEvt.TargetId);
}
}
public void ReceiveFromExternalSimulation<T>(T evt)
{
// 处理来自虚幻引擎的事件
}
}
#endif
```
### [UnityExample.cs](UnityExample.cs)
Unity引擎集成示例展示了
@ -22,6 +85,101 @@ Unity引擎集成示例展示了
- MonoBehaviour生命周期管理
- 事件系统的使用
#### 源代码
```csharp
#if NEVER // 使用编译指令确保此文件永远不会被编译
// 第三方系统实现适配器示例代码
// 以Unity引擎为例
// 需要实现的方法: GetEntity, PublishToExternalSimulation, ReceiveFromExternalSimulation
using ThreatSource.Simulation;
using UnityEngine; // 仅用于示例实际项目中需要引用真实的Unity命名空间
/// <summary>
/// Unity引擎适配器类演示如何将Unity引擎集成到仿真系统中
/// </summary>
public class UnityEngineAdapter : MonoBehaviour, ISimulationAdapter
{
/// <summary>
/// Unity引擎API接口定义了与Unity引擎交互的基本方法
/// </summary>
public interface IUnityEngine
{
/// <summary>
/// 根据ID获取Unity场景中的GameObject对象
/// </summary>
GameObject GetGameObject(string id);
/// <summary>
/// 在Unity场景中实例化导弹预制体
/// </summary>
GameObject InstantiateMissile(string prefabPath, Vector3 position, Quaternion rotation);
}
private readonly IUnityEngine _unityEngine;
private readonly ISimulationManager _simulationManager;
private const string MissilePrefabPath = "Prefabs/Missile";
public UnityEngineAdapter(IUnityEngine unityEngine, ISimulationManager simulationManager)
{
_unityEngine = unityEngine ?? throw new ArgumentNullException(nameof(unityEngine));
_simulationManager = simulationManager ?? throw new ArgumentNullException(nameof(simulationManager));
}
public object? GetEntity(string id)
{
return _unityEngine.GetGameObject(id);
}
public void PublishToExternalSimulation<T>(T evt)
{
if (evt is MissileFireEvent missileEvt)
{
var sender = _unityEngine.GetGameObject(missileEvt.SenderId);
if (sender != null)
{
UnityMainThreadDispatcher.Instance.Enqueue(() =>
{
var missile = _unityEngine.InstantiateMissile(
MissilePrefabPath,
sender.transform.position,
sender.transform.rotation
);
var missileComponent = missile.GetComponent<MissileController>();
if (missileComponent != null)
{
missileComponent.SetTarget(missileEvt.TargetId);
}
});
}
}
}
public void ReceiveFromExternalSimulation<T>(T evt)
{
if (evt is CollisionEvent collisionEvt)
{
_simulationManager.HandleCollision(collisionEvt);
}
}
private void Update()
{
SyncSimulationState();
}
private void SyncSimulationState()
{
// 实现仿真状态同步逻辑
}
}
#endif
```
## 使用说明
1. 这些文件仅作为参考示例,不参与实际编译(使用 `#if NEVER` 编译指令)

View File

@ -32,6 +32,115 @@ ThreatSource 是一个基于 .NET 8.0 的类库,提供了完整的导弹仿真
- 如何配置仿真环境和参数
- 如何运行仿真并获取结果
#### 源代码
```csharp
using ThreatSource.Simulation;
using ThreatSource.Missile;
using ThreatSource.Sensor;
using ThreatSource.Target;
/// <summary>
/// 红外成像制导导弹仿真示例
/// </summary>
public class IRMissileSimulation
{
private readonly ISimulationManager _simulationManager;
private readonly IMissileFactory _missileFactory;
private readonly ITargetFactory _targetFactory;
private readonly ISensorFactory _sensorFactory;
public IRMissileSimulation()
{
_simulationManager = new SimulationManager();
_missileFactory = new MissileFactory();
_targetFactory = new TargetFactory();
_sensorFactory = new SensorFactory();
}
/// <summary>
/// 运行仿真
/// </summary>
public async Task RunSimulation()
{
// 创建目标
var target = _targetFactory.CreateTarget(new TargetConfig
{
Id = "target_001",
Position = new Vector3(1000, 0, 100),
Velocity = new Vector3(-100, 0, 0),
Signature = new IRSignature
{
Temperature = 350, // 开尔文
EmissivityFactor = 0.8f
}
});
// 创建导弹
var missile = _missileFactory.CreateMissile(new MissileConfig
{
Id = "missile_001",
Position = new Vector3(0, 0, 0),
MaxSpeed = 800, // 米/秒
MaxAcceleration = 30, // G
MaxTurnRate = 20 // 度/秒
});
// 创建红外成像传感器
var sensor = _sensorFactory.CreateSensor(new IRSensorConfig
{
Id = "sensor_001",
Resolution = new Vector2(640, 480),
FieldOfView = 60, // 度
MinTemperature = 270, // 开尔文
MaxTemperature = 400 // 开尔文
});
// 配置仿真参数
var config = new SimulationConfig
{
TimeStep = 0.02f, // 仿真步长(秒)
MaxSimulationTime = 60.0f, // 最大仿真时间(秒)
EnvironmentConditions = new EnvironmentConfig
{
Temperature = 288, // 开尔文
Pressure = 101325, // 帕斯卡
Humidity = 0.5f // 相对湿度
}
};
// 初始化仿真
await _simulationManager.Initialize(config);
// 添加实体
_simulationManager.AddEntity(target);
_simulationManager.AddEntity(missile);
_simulationManager.AddEntity(sensor);
// 启动仿真
await _simulationManager.StartSimulation();
// 等待仿真完成
while (_simulationManager.IsRunning)
{
await Task.Delay(100);
}
// 获取仿真结果
var results = _simulationManager.GetSimulationResults();
ProcessResults(results);
}
private void ProcessResults(SimulationResults results)
{
// 处理仿真结果
Console.WriteLine($"仿真完成时间: {results.CompletionTime}秒");
Console.WriteLine($"命中精度: {results.HitAccuracy}米");
Console.WriteLine($"导引头跟踪时间: {results.TrackingTime}秒");
}
}
```
### C++示例 ([IRMissileSimulation.cpp](IRMissileSimulation.cpp))
这是一个使用C++/CLI的示例代码展示了如何在C++项目中使用本库:
@ -41,6 +150,118 @@ ThreatSource 是一个基于 .NET 8.0 的类库,提供了完整的导弹仿真
- 如何设置仿真参数
- 如何运行仿真并获取结果
#### 源代码
```cpp
#include "ThreatSource.h"
using namespace System;
using namespace ThreatSource::Simulation;
using namespace ThreatSource::Missile;
using namespace ThreatSource::Sensor;
using namespace ThreatSource::Target;
/// <summary>
/// C++/CLI包装类用于在C++项目中使用仿真系统
/// </summary>
public ref class SimulationWrapper
{
private:
ISimulationManager^ _simulationManager;
IMissileFactory^ _missileFactory;
ITargetFactory^ _targetFactory;
ISensorFactory^ _sensorFactory;
public:
SimulationWrapper()
{
_simulationManager = gcnew SimulationManager();
_missileFactory = gcnew MissileFactory();
_targetFactory = gcnew TargetFactory();
_sensorFactory = gcnew SensorFactory();
}
void RunSimulation()
{
// 创建目标
auto target = _targetFactory->CreateTarget(gcnew TargetConfig {
Id = "target_001",
Position = Vector3(1000, 0, 100),
Velocity = Vector3(-100, 0, 0),
Signature = gcnew IRSignature {
Temperature = 350,
EmissivityFactor = 0.8f
}
});
// 创建导弹
auto missile = _missileFactory->CreateMissile(gcnew MissileConfig {
Id = "missile_001",
Position = Vector3(0, 0, 0),
MaxSpeed = 800,
MaxAcceleration = 30,
MaxTurnRate = 20
});
// 创建传感器
auto sensor = _sensorFactory->CreateSensor(gcnew IRSensorConfig {
Id = "sensor_001",
Resolution = Vector2(640, 480),
FieldOfView = 60,
MinTemperature = 270,
MaxTemperature = 400
});
// 配置仿真参数
auto config = gcnew SimulationConfig {
TimeStep = 0.02f,
MaxSimulationTime = 60.0f,
EnvironmentConditions = gcnew EnvironmentConfig {
Temperature = 288,
Pressure = 101325,
Humidity = 0.5f
}
};
// 初始化仿真
_simulationManager->Initialize(config)->Wait();
// 添加实体
_simulationManager->AddEntity(target);
_simulationManager->AddEntity(missile);
_simulationManager->AddEntity(sensor);
// 启动仿真
_simulationManager->StartSimulation()->Wait();
// 等待仿真完成
while (_simulationManager->IsRunning)
{
System::Threading::Thread::Sleep(100);
}
// 获取仿真结果
auto results = _simulationManager->GetSimulationResults();
ProcessResults(results);
}
private:
void ProcessResults(SimulationResults^ results)
{
Console::WriteLine("仿真完成时间: {0}秒", results->CompletionTime);
Console::WriteLine("命中精度: {0}米", results->HitAccuracy);
Console::WriteLine("导引头跟踪时间: {0}秒", results->TrackingTime);
}
};
// 在C++代码中使用
int main()
{
auto simulation = gcnew SimulationWrapper();
simulation->RunSimulation();
return 0;
}
```
## 使用说明
### C#/.NET使用方式

View File

@ -22,15 +22,15 @@
## API文档
完整的API文档请参阅[API参考](api/toc.yml)。
完整的API文档请参阅[API参考](./api/toc.yml)。
## 集成示例
### 第三方引擎集成
- [集成示例说明](examples/Integration/README.md) - 第三方引擎集成的详细说明
- [虚幻引擎示例](examples/Integration/UEExample.cs) - 虚幻引擎集成示例代码
- [Unity引擎示例](examples/Integration/UnityExample.cs) - Unity引擎集成示例代码
- [虚幻引擎示例](./examples/Integration/UEExample.cs) - 虚幻引擎集成示例代码
- [Unity引擎示例](./examples/Integration/UnityExample.cs) - Unity引擎集成示例代码
## 示例说明

View File

@ -1,9 +1,18 @@
- name: 文档首页
### YamlMime:TableOfContent
metadata:
pdf: true
pdfFileName: ThreatSource-Library.pdf
pdfTocPage: true
excludeFromPdf:
- docfx-guide.md
items:
- name: 简介
href: index.md
- name: 入门指南
href: articles/intro.md
- name: API文档
href: api/
homepage: api/toc.yml
- name: DocFX文档生成指南
href: articles/docfx-guide.md
- name: API 文档
href: api/toc.yml
- name: 集成示例
href: examples/Integration/README.md
- name: 仿真示例
href: examples/Simulation/README.md

54
scripts/generate_pdf.sh Executable file
View File

@ -0,0 +1,54 @@
#!/bin/bash
# 创建临时文件列表
temp_file="html_files.txt"
# 清空临时文件
> $temp_file
# 获取当前目录的绝对路径
current_dir=$(pwd)
# 首先添加主页
echo "file://${current_dir}/docs/_site/docs/index.html" >> $temp_file
# 添加文章
find "${current_dir}/docs/_site/docs/articles" -name "*.html" | sed 's|^|file://|' >> $temp_file
# 添加示例文档
find "${current_dir}/docs/_site/docs/examples" -name "*.html" | sed 's|^|file://|' >> $temp_file
# 添加API文档
find "${current_dir}/docs/_site/docs/api" -name "*.html" | sed 's|^|file://|' >> $temp_file
# 构建wkhtmltopdf命令
cmd="wkhtmltopdf \
--enable-local-file-access \
--page-size A4 \
--margin-top 15 \
--margin-bottom 15 \
--margin-left 20 \
--margin-right 20 \
--footer-left \"ThreatSource Library\" \
--footer-right \"[page]/[topage]\" \
--footer-spacing 5 \
--footer-font-size 8 \
--disable-smart-shrinking \
--zoom 0.8 \
--dpi 300"
# 添加所有HTML文件到命令中
while IFS= read -r file; do
cmd="$cmd \"$file\""
done < "$temp_file"
# 添加输出文件名
cmd="$cmd \"${current_dir}/ThreatSource-Library.pdf\""
# 执行命令
eval $cmd
# 删除临时文件
rm $temp_file
echo "PDF generation completed: ThreatSource-Library.pdf"