完善动画播放和UI
This commit is contained in:
parent
089a7c60ae
commit
5b7661955a
474
MainPlugin.cs
474
MainPlugin.cs
@ -252,6 +252,12 @@ namespace NavisworksTransport
|
||||
private static bool _isUpdatingLogisticsData = false;
|
||||
private static ModelItemCollection _savedDocumentSelection = null;
|
||||
|
||||
// 动画播放控制 - 提升为类成员以便跨方法访问
|
||||
private Button _startAnimationButton;
|
||||
private Button _stopAnimationButton;
|
||||
private Label _animationStatusLabel;
|
||||
private ProgressBar _animationProgressBar;
|
||||
|
||||
public override int Execute(params string[] parameters)
|
||||
{
|
||||
return GlobalExceptionHandler.SafeExecute(() =>
|
||||
@ -359,9 +365,9 @@ namespace NavisworksTransport
|
||||
_controlPanelForm = new Form
|
||||
{
|
||||
Text = "物流路径规划控制面板",
|
||||
Size = new Size(380, 700),
|
||||
Size = new Size(420, 700),
|
||||
StartPosition = FormStartPosition.Manual,
|
||||
Location = new Point(20, 140), // 避免遮挡菜单
|
||||
Location = new Point(50, 200), // 避免遮挡菜单
|
||||
TopMost = true,
|
||||
ShowInTaskbar = false,
|
||||
MaximizeBox = false,
|
||||
@ -430,7 +436,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
Text = "关闭",
|
||||
Size = new Size(60, 30),
|
||||
Location = new Point(290, 10),
|
||||
Location = new Point(330, 10),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
bottomPanel.Controls.Add(closeButton);
|
||||
@ -450,7 +456,7 @@ namespace NavisworksTransport
|
||||
|
||||
aboutButton.Click += (sender, e) =>
|
||||
{
|
||||
MessageBox.Show("物流路径规划插件 v1.0\n\n适用于 Navisworks 2017\n开发:AI助手\n\n功能:3D路径规划、动画创建、碰撞检测",
|
||||
MessageBox.Show("物流路径规划插件 v1.0\n\n适用于 Navisworks 2017\n\n功能:3D路径规划、动画创建、碰撞检测",
|
||||
"关于插件", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
};
|
||||
|
||||
@ -528,7 +534,7 @@ namespace NavisworksTransport
|
||||
ForeColor = System.Drawing.Color.DarkBlue,
|
||||
AutoSize = true,
|
||||
Location = new Point(10, currentY),
|
||||
MaximumSize = new Size(320, 0),
|
||||
MaximumSize = new Size(360, 0),
|
||||
Visible = false // 初始隐藏
|
||||
};
|
||||
scrollPanel.Controls.Add(_selectedModelsLabel);
|
||||
@ -539,24 +545,24 @@ namespace NavisworksTransport
|
||||
{
|
||||
Text = "类别属性设置",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(340, 80),
|
||||
Size = new Size(350, 70),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(categoryGroupBox);
|
||||
CreateCategoryDropdown(categoryGroupBox);
|
||||
currentY += 100;
|
||||
currentY += 85;
|
||||
|
||||
// 物流模型列表
|
||||
GroupBox logisticsListGroupBox = new GroupBox
|
||||
{
|
||||
Text = "物流模型列表",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(340, 180),
|
||||
Size = new Size(350, 185),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(logisticsListGroupBox);
|
||||
CreateLogisticsModelList(logisticsListGroupBox);
|
||||
currentY += 190;
|
||||
currentY += 200;
|
||||
|
||||
// 统计信息(简化为一行,保存引用)
|
||||
_statsLabel = new Label
|
||||
@ -576,7 +582,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
Text = "可见性控制",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(340, 100),
|
||||
Size = new Size(350, 100),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(visibilityGroupBox);
|
||||
@ -610,7 +616,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
Text = "路径列表管理",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(320, 160),
|
||||
Size = new Size(350, 160),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(pathListGroupBox);
|
||||
@ -622,7 +628,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
Text = "当前路径编辑",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(320, 250),
|
||||
Size = new Size(350, 250),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(currentPathGroupBox);
|
||||
@ -634,7 +640,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
Text = "路径文件管理",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(320, 80),
|
||||
Size = new Size(350, 70),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(fileManagementGroupBox);
|
||||
@ -644,11 +650,11 @@ namespace NavisworksTransport
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建动画控制Tab页
|
||||
/// 创建检测动画Tab页
|
||||
/// </summary>
|
||||
private void CreateAnimationControlTab(TabControl tabControl)
|
||||
{
|
||||
TabPage animationTab = new TabPage("动画控制");
|
||||
TabPage animationTab = new TabPage("检测动画");
|
||||
animationTab.Padding = new Padding(10);
|
||||
|
||||
Panel scrollPanel = new Panel
|
||||
@ -660,36 +666,36 @@ namespace NavisworksTransport
|
||||
|
||||
int currentY = 10;
|
||||
|
||||
// 动画参数设置
|
||||
// 动画参数设置 - 减少高度
|
||||
GroupBox animationGroupBox = new GroupBox
|
||||
{
|
||||
Text = "动画参数设置",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(320, 190),
|
||||
Size = new Size(350, 160),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(animationGroupBox);
|
||||
CreateAnimationControls(animationGroupBox);
|
||||
currentY += 210;
|
||||
currentY += 180;
|
||||
|
||||
// 播放控制
|
||||
// 播放控制 - 增加高度
|
||||
GroupBox playbackGroupBox = new GroupBox
|
||||
{
|
||||
Text = "播放控制",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(320, 100),
|
||||
Size = new Size(350, 130),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(playbackGroupBox);
|
||||
CreatePlaybackControls(playbackGroupBox);
|
||||
currentY += 120;
|
||||
currentY += 150;
|
||||
|
||||
// 碰撞检测
|
||||
GroupBox collisionGroupBox = new GroupBox
|
||||
{
|
||||
Text = "碰撞检测",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(320, 100),
|
||||
Size = new Size(350, 80),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(collisionGroupBox);
|
||||
@ -720,7 +726,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
Text = "日志管理",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(320, 120),
|
||||
Size = new Size(350, 120),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(logGroupBox);
|
||||
@ -732,7 +738,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
Text = "插件设置",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(320, 100),
|
||||
Size = new Size(350, 100),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(settingsGroupBox);
|
||||
@ -744,7 +750,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
Text = "系统信息",
|
||||
Location = new Point(10, currentY),
|
||||
Size = new Size(320, 150),
|
||||
Size = new Size(350, 160),
|
||||
Font = new Font("微软雅黑", 8, FontStyle.Bold)
|
||||
};
|
||||
scrollPanel.Controls.Add(systemInfoGroupBox);
|
||||
@ -799,16 +805,16 @@ namespace NavisworksTransport
|
||||
_pathListView = new ListView
|
||||
{
|
||||
Location = new Point(15, 60),
|
||||
Size = new Size(290, 80),
|
||||
Size = new Size(320, 80),
|
||||
View = System.Windows.Forms.View.Details,
|
||||
FullRowSelect = true,
|
||||
GridLines = true,
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
|
||||
_pathListView.Columns.Add("路径名称", 150);
|
||||
_pathListView.Columns.Add("创建时间", 80);
|
||||
_pathListView.Columns.Add("点数", 50);
|
||||
_pathListView.Columns.Add("路径名称", 140);
|
||||
_pathListView.Columns.Add("创建时间", 100);
|
||||
_pathListView.Columns.Add("点数", 60);
|
||||
|
||||
groupBox.Controls.Add(_pathListView);
|
||||
|
||||
@ -975,7 +981,7 @@ namespace NavisworksTransport
|
||||
_currentPathPointsListView = new ListView
|
||||
{
|
||||
Location = new Point(15, 105),
|
||||
Size = new Size(290, 100),
|
||||
Size = new Size(320, 100),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
View = System.Windows.Forms.View.Details, // 设置为详细信息视图
|
||||
FullRowSelect = true,
|
||||
@ -986,7 +992,7 @@ namespace NavisworksTransport
|
||||
_currentPathPointsListView.Columns.Add("序号", 40, HorizontalAlignment.Left);
|
||||
_currentPathPointsListView.Columns.Add("名称", 80, HorizontalAlignment.Left);
|
||||
_currentPathPointsListView.Columns.Add("类型", 60, HorizontalAlignment.Left);
|
||||
_currentPathPointsListView.Columns.Add("坐标 (X,Y,Z)", 110, HorizontalAlignment.Left);
|
||||
_currentPathPointsListView.Columns.Add("坐标 (X,Y,Z)", 120, HorizontalAlignment.Left);
|
||||
|
||||
groupBox.Controls.Add(_currentPathPointsListView);
|
||||
|
||||
@ -994,7 +1000,7 @@ namespace NavisworksTransport
|
||||
Button finishButton = new Button
|
||||
{
|
||||
Text = "完成编辑",
|
||||
Location = new Point(120, 215),
|
||||
Location = new Point(95, 215),
|
||||
Size = new Size(80, 25),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
Enabled = false
|
||||
@ -1004,7 +1010,7 @@ namespace NavisworksTransport
|
||||
Button cancelButton = new Button
|
||||
{
|
||||
Text = "取消编辑",
|
||||
Location = new Point(210, 215),
|
||||
Location = new Point(185, 215),
|
||||
Size = new Size(80, 25),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
Enabled = false
|
||||
@ -1104,9 +1110,9 @@ namespace NavisworksTransport
|
||||
{
|
||||
Button saveButton = new Button
|
||||
{
|
||||
Text = "保存当前路径",
|
||||
Text = "保存路径",
|
||||
Location = new Point(15, 25),
|
||||
Size = new Size(90, 30),
|
||||
Size = new Size(70, 30),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
groupBox.Controls.Add(saveButton);
|
||||
@ -1114,8 +1120,8 @@ namespace NavisworksTransport
|
||||
Button importButton = new Button
|
||||
{
|
||||
Text = "导入路径",
|
||||
Location = new Point(115, 25),
|
||||
Size = new Size(80, 30),
|
||||
Location = new Point(95, 25),
|
||||
Size = new Size(70, 30),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
groupBox.Controls.Add(importButton);
|
||||
@ -1123,8 +1129,8 @@ namespace NavisworksTransport
|
||||
Button exportButton = new Button
|
||||
{
|
||||
Text = "导出路径",
|
||||
Location = new Point(205, 25),
|
||||
Size = new Size(80, 30),
|
||||
Location = new Point(175, 25),
|
||||
Size = new Size(70, 30),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
groupBox.Controls.Add(exportButton);
|
||||
@ -1132,8 +1138,8 @@ namespace NavisworksTransport
|
||||
Button historyButton = new Button
|
||||
{
|
||||
Text = "查看历史",
|
||||
Location = new Point(15, 65),
|
||||
Size = new Size(80, 30),
|
||||
Location = new Point(255, 25),
|
||||
Size = new Size(70, 30),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
groupBox.Controls.Add(historyButton);
|
||||
@ -1159,7 +1165,7 @@ namespace NavisworksTransport
|
||||
DefaultExt = "xml"
|
||||
};
|
||||
|
||||
if (saveDialog.ShowDialog() == DialogResult.OK)
|
||||
if (saveDialog.ShowDialog(_controlPanelForm) == DialogResult.OK)
|
||||
{
|
||||
bool saveResult = false;
|
||||
var extension = System.IO.Path.GetExtension(saveDialog.FileName).ToLowerInvariant();
|
||||
@ -1210,7 +1216,7 @@ namespace NavisworksTransport
|
||||
FilterIndex = 1
|
||||
};
|
||||
|
||||
if (openDialog.ShowDialog() == DialogResult.OK)
|
||||
if (openDialog.ShowDialog(_controlPanelForm) == DialogResult.OK)
|
||||
{
|
||||
PathRoute importedRoute = null;
|
||||
var fileFormat = PathFileSerializer.DetectFileFormat(openDialog.FileName);
|
||||
@ -1275,7 +1281,7 @@ namespace NavisworksTransport
|
||||
DefaultExt = "xml"
|
||||
};
|
||||
|
||||
if (exportDialog.ShowDialog() == DialogResult.OK)
|
||||
if (exportDialog.ShowDialog(_controlPanelForm) == DialogResult.OK)
|
||||
{
|
||||
bool exportResult = false;
|
||||
var extension = System.IO.Path.GetExtension(exportDialog.FileName).ToLowerInvariant();
|
||||
@ -1337,82 +1343,42 @@ namespace NavisworksTransport
|
||||
/// </summary>
|
||||
private void CreatePlaybackControls(GroupBox groupBox)
|
||||
{
|
||||
Button playButton = new Button
|
||||
// 播放按钮
|
||||
if (_startAnimationButton != null)
|
||||
{
|
||||
Text = "▶ 播放",
|
||||
Location = new Point(15, 25),
|
||||
Size = new Size(60, 25),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
groupBox.Controls.Add(playButton);
|
||||
_startAnimationButton.Text = "▶ 播放";
|
||||
_startAnimationButton.Location = new Point(15, 25);
|
||||
_startAnimationButton.Size = new Size(70, 30);
|
||||
groupBox.Controls.Add(_startAnimationButton);
|
||||
}
|
||||
|
||||
// 停止按钮
|
||||
if (_stopAnimationButton != null)
|
||||
{
|
||||
_stopAnimationButton.Text = "⏹ 停止";
|
||||
_stopAnimationButton.Location = new Point(95, 25);
|
||||
_stopAnimationButton.Size = new Size(70, 30);
|
||||
groupBox.Controls.Add(_stopAnimationButton);
|
||||
}
|
||||
|
||||
Button pauseButton = new Button
|
||||
// 状态标签
|
||||
if (_animationStatusLabel != null)
|
||||
{
|
||||
Text = "⏸ 暂停",
|
||||
Location = new Point(85, 25),
|
||||
Size = new Size(60, 25),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
groupBox.Controls.Add(pauseButton);
|
||||
|
||||
Button stopButton = new Button
|
||||
{
|
||||
Text = "⏹ 停止",
|
||||
Location = new Point(155, 25),
|
||||
Size = new Size(60, 25),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
groupBox.Controls.Add(stopButton);
|
||||
|
||||
Button resetButton = new Button
|
||||
{
|
||||
Text = "🔄 重置",
|
||||
Location = new Point(225, 25),
|
||||
Size = new Size(60, 25),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
groupBox.Controls.Add(resetButton);
|
||||
_animationStatusLabel.Location = new Point(15, 65);
|
||||
_animationStatusLabel.Size = new Size(250, 20);
|
||||
groupBox.Controls.Add(_animationStatusLabel);
|
||||
}
|
||||
|
||||
// 进度条
|
||||
ProgressBar progressBar = new ProgressBar
|
||||
_animationProgressBar = new ProgressBar
|
||||
{
|
||||
Location = new Point(15, 65),
|
||||
Size = new Size(270, 15)
|
||||
};
|
||||
groupBox.Controls.Add(progressBar);
|
||||
|
||||
// 事件处理
|
||||
playButton.Click += (sender, e) =>
|
||||
{
|
||||
if (_animationManager != null)
|
||||
{
|
||||
_animationManager.StartAnimation();
|
||||
LogManager.Info("动画播放开始");
|
||||
}
|
||||
};
|
||||
|
||||
pauseButton.Click += (sender, e) =>
|
||||
{
|
||||
LogManager.Info("动画暂停(功能待实现)");
|
||||
};
|
||||
|
||||
stopButton.Click += (sender, e) =>
|
||||
{
|
||||
if (_animationManager != null)
|
||||
{
|
||||
_animationManager.StopAnimation();
|
||||
LogManager.Info("动画停止");
|
||||
}
|
||||
};
|
||||
|
||||
resetButton.Click += (sender, e) =>
|
||||
{
|
||||
if (_animationManager != null)
|
||||
{
|
||||
_animationManager.ResetAnimation();
|
||||
LogManager.Info("动画重置");
|
||||
}
|
||||
Location = new Point(15, 90),
|
||||
Size = new Size(320, 18),
|
||||
Minimum = 0,
|
||||
Maximum = 100,
|
||||
Value = 0
|
||||
};
|
||||
groupBox.Controls.Add(_animationProgressBar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1722,8 +1688,8 @@ namespace NavisworksTransport
|
||||
};
|
||||
|
||||
// 添加列标题
|
||||
_logisticsListView.Columns.Add("模型名称", 180);
|
||||
_logisticsListView.Columns.Add("物流类型", 120);
|
||||
_logisticsListView.Columns.Add("模型名称", 160);
|
||||
_logisticsListView.Columns.Add("物流类型", 140);
|
||||
|
||||
parent.Controls.Add(_logisticsListView);
|
||||
|
||||
@ -1788,15 +1754,6 @@ namespace NavisworksTransport
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
groupBox.Controls.Add(highlightCheckBox);
|
||||
|
||||
Label collisionStatusLabel = new Label
|
||||
{
|
||||
Text = "碰撞状态: 未检测",
|
||||
Location = new Point(15, 55),
|
||||
Size = new Size(200, 20),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
groupBox.Controls.Add(collisionStatusLabel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -2090,7 +2047,7 @@ namespace NavisworksTransport
|
||||
ComboBox categoryComboBox = new ComboBox
|
||||
{
|
||||
Location = new Point(80, 25),
|
||||
Size = new Size(80, 25),
|
||||
Size = new Size(100, 25),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
DropDownStyle = ComboBoxStyle.DropDownList
|
||||
};
|
||||
@ -2112,7 +2069,7 @@ namespace NavisworksTransport
|
||||
Button applyButton = new Button
|
||||
{
|
||||
Text = "应用类别",
|
||||
Location = new Point(170, 25),
|
||||
Location = new Point(200, 25),
|
||||
Size = new Size(80, 25),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
UseVisualStyleBackColor = true
|
||||
@ -2204,8 +2161,8 @@ namespace NavisworksTransport
|
||||
Label vehicleInstructionLabel = new Label
|
||||
{
|
||||
Text = "请在选择树中选择部件",
|
||||
Location = new Point(20, 25),
|
||||
Size = new Size(200, 20),
|
||||
Location = new Point(15, 25),
|
||||
Size = new Size(140, 20),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
ForeColor = System.Drawing.Color.Blue
|
||||
};
|
||||
@ -2213,18 +2170,16 @@ namespace NavisworksTransport
|
||||
Button getVehicleButton = new Button
|
||||
{
|
||||
Text = "获取选中部件",
|
||||
Location = new Point(230, 22),
|
||||
Size = new Size(90, 27),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
BackColor = System.Drawing.Color.LightBlue,
|
||||
UseVisualStyleBackColor = false
|
||||
Location = new Point(180, 22),
|
||||
Size = new Size(85, 27),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
|
||||
Label vehicleStatusLabel = new Label
|
||||
{
|
||||
Text = "状态: 未选择",
|
||||
Location = new Point(20, 55),
|
||||
Size = new Size(300, 20),
|
||||
Location = new Point(15, 55),
|
||||
Size = new Size(290, 20),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
ForeColor = System.Drawing.Color.Gray
|
||||
};
|
||||
@ -2233,15 +2188,15 @@ namespace NavisworksTransport
|
||||
Label pathLabel = new Label
|
||||
{
|
||||
Text = "路径选择:",
|
||||
Location = new Point(20, 85),
|
||||
Location = new Point(15, 80),
|
||||
Size = new Size(70, 20),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
|
||||
ComboBox pathComboBox = new ComboBox
|
||||
{
|
||||
Location = new Point(95, 83),
|
||||
Size = new Size(150, 25),
|
||||
Location = new Point(85, 78),
|
||||
Size = new Size(120, 25),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
DropDownStyle = ComboBoxStyle.DropDownList,
|
||||
DisplayMember = "Name" // 显示路径的Name属性
|
||||
@ -2250,8 +2205,8 @@ namespace NavisworksTransport
|
||||
Label pathInfoLabel = new Label
|
||||
{
|
||||
Text = "点数: 0",
|
||||
Location = new Point(255, 87),
|
||||
Size = new Size(60, 20),
|
||||
Location = new Point(215, 82),
|
||||
Size = new Size(50, 20),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
ForeColor = System.Drawing.Color.Gray
|
||||
};
|
||||
@ -2259,8 +2214,8 @@ namespace NavisworksTransport
|
||||
Button refreshPathButton = new Button
|
||||
{
|
||||
Text = "刷新",
|
||||
Location = new Point(320, 83),
|
||||
Size = new Size(50, 25),
|
||||
Location = new Point(270, 78),
|
||||
Size = new Size(45, 25),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
UseVisualStyleBackColor = true
|
||||
};
|
||||
@ -2269,15 +2224,15 @@ namespace NavisworksTransport
|
||||
Label durationLabel = new Label
|
||||
{
|
||||
Text = "动画时长(秒):",
|
||||
Location = new Point(20, 115),
|
||||
Location = new Point(15, 115),
|
||||
Size = new Size(80, 20),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
|
||||
NumericUpDown durationNumeric = new NumericUpDown
|
||||
{
|
||||
Location = new Point(105, 113),
|
||||
Size = new Size(60, 25),
|
||||
Location = new Point(100, 113),
|
||||
Size = new Size(55, 25),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
Minimum = 1,
|
||||
Maximum = 300,
|
||||
@ -2289,48 +2244,37 @@ namespace NavisworksTransport
|
||||
Button createAnimationButton = new Button
|
||||
{
|
||||
Text = "生成动画",
|
||||
Location = new Point(175, 112),
|
||||
Size = new Size(75, 27),
|
||||
Location = new Point(180, 112),
|
||||
Size = new Size(85, 27),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
BackColor = System.Drawing.Color.LightGreen,
|
||||
UseVisualStyleBackColor = false,
|
||||
Enabled = false
|
||||
};
|
||||
|
||||
// 播放控制按钮
|
||||
Button startAnimationButton = new Button
|
||||
// 播放控制按钮移到播放控制区域
|
||||
_startAnimationButton = new Button
|
||||
{
|
||||
Text = "播放",
|
||||
Location = new Point(260, 112),
|
||||
Size = new Size(60, 27),
|
||||
Location = new Point(245, 107),
|
||||
Size = new Size(55, 27),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
Enabled = false
|
||||
};
|
||||
|
||||
Button stopAnimationButton = new Button
|
||||
_stopAnimationButton = new Button
|
||||
{
|
||||
Text = "停止",
|
||||
Location = new Point(20, 145),
|
||||
Size = new Size(60, 27),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
Enabled = false
|
||||
};
|
||||
|
||||
Button resetAnimationButton = new Button
|
||||
{
|
||||
Text = "重置",
|
||||
Location = new Point(90, 145),
|
||||
Size = new Size(60, 27),
|
||||
Location = new Point(15, 140),
|
||||
Size = new Size(55, 27),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
Enabled = false
|
||||
};
|
||||
|
||||
// 动画状态显示
|
||||
Label statusLabel = new Label
|
||||
_animationStatusLabel = new Label
|
||||
{
|
||||
Text = "状态: 未生成动画",
|
||||
Location = new Point(160, 149),
|
||||
Size = new Size(160, 20),
|
||||
Location = new Point(80, 144),
|
||||
Size = new Size(150, 20),
|
||||
Font = new Font("微软雅黑", 8),
|
||||
ForeColor = System.Drawing.Color.Gray
|
||||
};
|
||||
@ -2518,80 +2462,29 @@ namespace NavisworksTransport
|
||||
{
|
||||
_animationManager = new PathAnimationManager();
|
||||
|
||||
// 监听动画完成事件
|
||||
_animationManager.AnimationCompleted += (animSender, animArgs) =>
|
||||
// 订阅动画管理器的事件
|
||||
_animationManager.StateChanged += (s, newState) =>
|
||||
{
|
||||
GlobalExceptionHandler.SafeExecute(() =>
|
||||
{
|
||||
// 动画自动完成时更新UI状态
|
||||
statusLabel.Text = "状态: 动画播放完成";
|
||||
statusLabel.ForeColor = System.Drawing.Color.Green;
|
||||
|
||||
startAnimationButton.Enabled = true;
|
||||
stopAnimationButton.Enabled = false;
|
||||
createAnimationButton.Enabled = true;
|
||||
|
||||
LogManager.Info("动画自动完成,UI状态已更新");
|
||||
}, "动画完成事件处理");
|
||||
// 在UI线程上更新状态
|
||||
_controlPanelForm.Invoke(new Action(() => UpdateAnimationUI(newState)));
|
||||
};
|
||||
|
||||
// 快速测试TimeLiner API(可选功能)
|
||||
bool timelineAvailable = _animationManager.TestTimeLinerAPI();
|
||||
if (timelineAvailable)
|
||||
_animationManager.ProgressChanged += (s, progress) =>
|
||||
{
|
||||
LogManager.Info("TimeLiner API可用,但当前使用Timer方案");
|
||||
}
|
||||
}
|
||||
// 在UI线程上更新进度条
|
||||
if (_animationProgressBar != null && !_animationProgressBar.IsDisposed)
|
||||
{
|
||||
_controlPanelForm.Invoke(new Action(() => _animationProgressBar.Value = progress));
|
||||
}
|
||||
};
|
||||
|
||||
// 设置动画参数
|
||||
var pathPoints = selectedPath.Points.Select(p => p.Position).ToList();
|
||||
double duration = (double)durationNumeric.Value;
|
||||
|
||||
// 添加详细的路径点坐标调试信息
|
||||
LogManager.Info("=== 路径点坐标调试信息 ===");
|
||||
LogManager.Info($"选中路径: {selectedPath.Name}, 总点数: {selectedPath.Points?.Count ?? 0}");
|
||||
|
||||
if (selectedPath.Points != null)
|
||||
{
|
||||
for (int i = 0; i < selectedPath.Points.Count; i++)
|
||||
{
|
||||
var point = selectedPath.Points[i];
|
||||
LogManager.Info($"路径点[{i}]: Name={point.Name}, Position=({point.Position.X:F2},{point.Position.Y:F2},{point.Position.Z:F2})");
|
||||
}
|
||||
// 使用动画管理器生成动画
|
||||
var pathPoints = selectedPath.GetSortedPoints().Select(p => new Point3D(p.X, p.Y, p.Z)).ToList();
|
||||
_animationManager.CreateAnimation(selectedComponent, pathPoints, (double)durationNumeric.Value);
|
||||
}
|
||||
|
||||
LogManager.Info($"转换后pathPoints列表: 共{pathPoints.Count}个点");
|
||||
for (int i = 0; i < pathPoints.Count; i++)
|
||||
{
|
||||
var pos = pathPoints[i];
|
||||
LogManager.Info($"pathPoints[{i}]: ({pos.X:F2},{pos.Y:F2},{pos.Z:F2})");
|
||||
}
|
||||
LogManager.Info("=== 路径点坐标调试信息结束 ===");
|
||||
|
||||
// 使用简化的动画设置方法
|
||||
bool success = _animationManager.SetupSimpleAnimation(selectedComponent, pathPoints, duration);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
MessageBox.Show("动画生成失败,请检查部件和路径设置", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
statusLabel.Text = "状态: 动画已生成";
|
||||
statusLabel.ForeColor = System.Drawing.Color.Green;
|
||||
|
||||
// 启用播放控制按钮
|
||||
startAnimationButton.Enabled = true;
|
||||
resetAnimationButton.Enabled = true;
|
||||
createAnimationButton.Enabled = false;
|
||||
|
||||
MessageBox.Show($"动画生成成功!\n部件: {selectedComponent.DisplayName}\n路径: {selectedPath.Name}\n路径点: {pathPoints.Count}个\n时长: {duration}秒",
|
||||
"生成成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}, "生成动画");
|
||||
};
|
||||
|
||||
startAnimationButton.Click += (sender, e) =>
|
||||
_startAnimationButton.Click += (sender, e) =>
|
||||
{
|
||||
GlobalExceptionHandler.SafeExecute(() =>
|
||||
{
|
||||
@ -2599,17 +2492,17 @@ namespace NavisworksTransport
|
||||
{
|
||||
_animationManager.StartAnimation();
|
||||
|
||||
statusLabel.Text = "状态: 动画播放中";
|
||||
statusLabel.ForeColor = System.Drawing.Color.Blue;
|
||||
_animationStatusLabel.Text = "状态: 动画播放中";
|
||||
_animationStatusLabel.ForeColor = System.Drawing.Color.Blue;
|
||||
|
||||
startAnimationButton.Enabled = false;
|
||||
stopAnimationButton.Enabled = true;
|
||||
_startAnimationButton.Enabled = false;
|
||||
_stopAnimationButton.Enabled = true;
|
||||
createAnimationButton.Enabled = false;
|
||||
}
|
||||
}, "播放动画");
|
||||
};
|
||||
|
||||
stopAnimationButton.Click += (sender, e) =>
|
||||
_stopAnimationButton.Click += (sender, e) =>
|
||||
{
|
||||
GlobalExceptionHandler.SafeExecute(() =>
|
||||
{
|
||||
@ -2617,35 +2510,17 @@ namespace NavisworksTransport
|
||||
{
|
||||
_animationManager.StopAnimation();
|
||||
|
||||
statusLabel.Text = "状态: 动画已停止";
|
||||
statusLabel.ForeColor = System.Drawing.Color.Orange;
|
||||
_animationStatusLabel.Text = "状态: 动画已停止";
|
||||
_animationStatusLabel.ForeColor = System.Drawing.Color.Orange;
|
||||
|
||||
startAnimationButton.Enabled = true;
|
||||
stopAnimationButton.Enabled = false;
|
||||
_startAnimationButton.Enabled = true;
|
||||
_stopAnimationButton.Enabled = false;
|
||||
createAnimationButton.Enabled = true;
|
||||
}
|
||||
}, "停止动画");
|
||||
};
|
||||
|
||||
resetAnimationButton.Click += (sender, e) =>
|
||||
{
|
||||
GlobalExceptionHandler.SafeExecute(() =>
|
||||
{
|
||||
if (_animationManager != null)
|
||||
{
|
||||
_animationManager.ResetAnimation();
|
||||
|
||||
statusLabel.Text = "状态: 动画已重置";
|
||||
statusLabel.ForeColor = System.Drawing.Color.Gray;
|
||||
|
||||
startAnimationButton.Enabled = true;
|
||||
stopAnimationButton.Enabled = false;
|
||||
createAnimationButton.Enabled = true;
|
||||
}
|
||||
}, "重置动画");
|
||||
};
|
||||
|
||||
// 添加控件到父容器
|
||||
// 将控件添加到父容器
|
||||
parent.Controls.Add(vehicleInstructionLabel);
|
||||
parent.Controls.Add(getVehicleButton);
|
||||
parent.Controls.Add(vehicleStatusLabel);
|
||||
@ -2656,10 +2531,67 @@ namespace NavisworksTransport
|
||||
parent.Controls.Add(durationLabel);
|
||||
parent.Controls.Add(durationNumeric);
|
||||
parent.Controls.Add(createAnimationButton);
|
||||
parent.Controls.Add(startAnimationButton);
|
||||
parent.Controls.Add(stopAnimationButton);
|
||||
parent.Controls.Add(resetAnimationButton);
|
||||
parent.Controls.Add(statusLabel);
|
||||
parent.Controls.Add(_startAnimationButton);
|
||||
parent.Controls.Add(_stopAnimationButton);
|
||||
parent.Controls.Add(_animationStatusLabel);
|
||||
}
|
||||
|
||||
private void UpdateAnimationUI(AnimationState state)
|
||||
{
|
||||
if (_controlPanelForm == null || _controlPanelForm.IsDisposed) return;
|
||||
|
||||
string statusText = "";
|
||||
System.Drawing.Color statusColor = System.Drawing.Color.Gray;
|
||||
bool startEnabled = false;
|
||||
bool stopEnabled = false;
|
||||
int progressValue = 0;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case AnimationState.Idle:
|
||||
statusText = "状态: 未生成动画";
|
||||
statusColor = System.Drawing.Color.Gray;
|
||||
break;
|
||||
case AnimationState.Ready:
|
||||
statusText = "状态: 动画已生成";
|
||||
statusColor = System.Drawing.Color.Green;
|
||||
startEnabled = true;
|
||||
break;
|
||||
case AnimationState.Playing:
|
||||
statusText = "状态: 动画播放中";
|
||||
statusColor = System.Drawing.Color.Blue;
|
||||
stopEnabled = true;
|
||||
break;
|
||||
case AnimationState.Stopped:
|
||||
statusText = "状态: 动画已停止";
|
||||
statusColor = System.Drawing.Color.Orange;
|
||||
startEnabled = true;
|
||||
break;
|
||||
case AnimationState.Finished:
|
||||
statusText = "状态: 动画播放完成";
|
||||
statusColor = System.Drawing.Color.Green;
|
||||
progressValue = 100;
|
||||
startEnabled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (_animationStatusLabel != null && !_animationStatusLabel.IsDisposed)
|
||||
{
|
||||
_animationStatusLabel.Text = statusText;
|
||||
_animationStatusLabel.ForeColor = statusColor;
|
||||
}
|
||||
if (_startAnimationButton != null && !_startAnimationButton.IsDisposed)
|
||||
{
|
||||
_startAnimationButton.Enabled = startEnabled;
|
||||
}
|
||||
if (_stopAnimationButton != null && !_stopAnimationButton.IsDisposed)
|
||||
{
|
||||
_stopAnimationButton.Enabled = stopEnabled;
|
||||
}
|
||||
if (_animationProgressBar != null && !_animationProgressBar.IsDisposed)
|
||||
{
|
||||
_animationProgressBar.Value = progressValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -3357,10 +3289,12 @@ namespace NavisworksTransport
|
||||
{
|
||||
Text = "路径历史记录",
|
||||
Size = new Size(600, 400),
|
||||
StartPosition = FormStartPosition.CenterParent,
|
||||
StartPosition = FormStartPosition.CenterScreen,
|
||||
FormBorderStyle = FormBorderStyle.FixedDialog,
|
||||
MaximizeBox = false,
|
||||
MinimizeBox = false
|
||||
MinimizeBox = false,
|
||||
TopMost = true,
|
||||
ShowInTaskbar = false
|
||||
};
|
||||
|
||||
// 创建历史记录列表
|
||||
@ -3465,7 +3399,7 @@ namespace NavisworksTransport
|
||||
DefaultExt = "txt"
|
||||
};
|
||||
|
||||
if (saveDialog.ShowDialog() == DialogResult.OK)
|
||||
if (saveDialog.ShowDialog(historyForm) == DialogResult.OK)
|
||||
{
|
||||
var content = new StringBuilder();
|
||||
content.AppendLine("路径历史记录导出");
|
||||
@ -3497,7 +3431,7 @@ namespace NavisworksTransport
|
||||
historyForm.Controls.Add(exportButton);
|
||||
historyForm.Controls.Add(closeButton);
|
||||
|
||||
historyForm.ShowDialog();
|
||||
historyForm.ShowDialog(_controlPanelForm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -7,6 +7,18 @@ using NavisApplication = Autodesk.Navisworks.Api.Application;
|
||||
|
||||
namespace NavisworksTransport
|
||||
{
|
||||
/// <summary>
|
||||
/// 定义动画播放的状态
|
||||
/// </summary>
|
||||
public enum AnimationState
|
||||
{
|
||||
Idle, // 空闲,未生成动画
|
||||
Ready, // 已就绪,动画已生成但未播放
|
||||
Playing, // 播放中
|
||||
Stopped, // 已停止
|
||||
Finished // 已完成
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 路径动画管理器 - 基于TimeLiner和动态变换实现沿路径的动画效果
|
||||
/// 注意:由于Navisworks API限制,无法直接使用Animator API,因此使用OverridePermanentTransform实现动画
|
||||
@ -22,8 +34,20 @@ namespace NavisworksTransport
|
||||
private Transform3D _originalTransform;
|
||||
private Point3D _originalCenter; // 存储部件的原始中心位置
|
||||
private Point3D _currentPosition; // 存储部件的当前位置
|
||||
private AnimationState _currentState = AnimationState.Idle;
|
||||
|
||||
// 动画完成事件
|
||||
// --- 新增事件 ---
|
||||
/// <summary>
|
||||
/// 当动画状态发生改变时触发
|
||||
/// </summary>
|
||||
public event EventHandler<AnimationState> StateChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 当动画进度更新时触发 (0-100)
|
||||
/// </summary>
|
||||
public event EventHandler<int> ProgressChanged;
|
||||
|
||||
// 动画完成事件 (旧版,保留兼容性)
|
||||
public event EventHandler AnimationCompleted;
|
||||
|
||||
public PathAnimationManager()
|
||||
@ -177,6 +201,7 @@ namespace NavisworksTransport
|
||||
_animationTimer.Tick += AnimationTimer_Tick;
|
||||
_animationTimer.Start();
|
||||
|
||||
SetState(AnimationState.Playing);
|
||||
LogManager.Info("动画开始播放");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -198,9 +223,10 @@ namespace NavisworksTransport
|
||||
_animationTimer.Stop();
|
||||
_animationTimer.Dispose();
|
||||
_animationTimer = null;
|
||||
}
|
||||
|
||||
LogManager.Info("动画已停止");
|
||||
SetState(AnimationState.Stopped);
|
||||
LogManager.Info("动画已停止");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -215,30 +241,24 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
StopAnimation();
|
||||
StopAnimation(); // 停止当前动画
|
||||
|
||||
// 恢复对象的原始变换
|
||||
if (_animatedObject != null)
|
||||
{
|
||||
var doc = NavisApplication.ActiveDocument;
|
||||
var modelItems = new ModelItemCollection { _animatedObject };
|
||||
|
||||
// 重置到原始位置(使用单位变换)
|
||||
var identityTransform = Transform3D.CreateTranslation(new Vector3D(0, 0, 0));
|
||||
doc.Models.OverridePermanentTransform(modelItems, identityTransform, true);
|
||||
|
||||
// 重置当前位置为原始中心
|
||||
_currentPosition = _originalCenter;
|
||||
|
||||
// 清除碰撞高亮
|
||||
doc.Models.ResetAllTemporaryMaterials();
|
||||
NavisApplication.ActiveDocument.Models.OverridePermanentTransform(modelItems, _originalTransform, false);
|
||||
LogManager.Info($"部件 {_animatedObject.DisplayName} 已重置到原始位置");
|
||||
}
|
||||
|
||||
_currentPathIndex = 0;
|
||||
LogManager.Info("动画已重置到初始状态");
|
||||
ProgressChanged?.Invoke(this, 0); // 重置进度条
|
||||
SetState(AnimationState.Ready); // 重置后回到就绪状态
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"重置动画失败: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,36 +269,30 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
var elapsedTime = (DateTime.Now - _animationStartTime).TotalSeconds;
|
||||
var progress = elapsedTime / _animationDuration;
|
||||
double elapsedSeconds = (DateTime.Now - _animationStartTime).TotalSeconds;
|
||||
double progress = Math.Min(elapsedSeconds / _animationDuration, 1.0);
|
||||
|
||||
// 更新UI进度条
|
||||
ProgressChanged?.Invoke(this, (int)(progress * 100));
|
||||
|
||||
Point3D newPosition = InterpolatePosition(progress);
|
||||
UpdateObjectPosition(newPosition);
|
||||
|
||||
// 检查碰撞
|
||||
CheckAndHighlightCollisions();
|
||||
|
||||
if (progress >= 1.0)
|
||||
{
|
||||
// 动画完成
|
||||
StopAnimation();
|
||||
SetState(AnimationState.Finished); // 标记为完成
|
||||
AnimationCompleted?.Invoke(this, EventArgs.Empty); // 触发旧版完成事件
|
||||
LogManager.Info("动画播放完成");
|
||||
|
||||
// 触发动画完成事件
|
||||
AnimationCompleted?.Invoke(this, EventArgs.Empty);
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算当前应该在的位置
|
||||
var currentPosition = InterpolatePosition(progress);
|
||||
|
||||
// 添加调试信息
|
||||
LogManager.Debug($"动画进度: {progress:F4}, 目标位置: ({currentPosition.X:F2},{currentPosition.Y:F2},{currentPosition.Z:F2})");
|
||||
|
||||
// 更新模型位置
|
||||
UpdateObjectPosition(currentPosition);
|
||||
|
||||
// 检查碰撞(简化版本)
|
||||
CheckAndHighlightCollisions();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"动画更新失败: {ex.Message}");
|
||||
StopAnimation();
|
||||
LogManager.Error($"动画帧更新失败: {ex.Message}");
|
||||
StopAnimation(); // 发生错误时停止动画
|
||||
}
|
||||
}
|
||||
|
||||
@ -705,5 +719,30 @@ namespace NavisworksTransport
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置并触发状态变更事件
|
||||
/// </summary>
|
||||
/// <param name="newState">新的动画状态</param>
|
||||
private void SetState(AnimationState newState)
|
||||
{
|
||||
if (_currentState != newState)
|
||||
{
|
||||
_currentState = newState;
|
||||
StateChanged?.Invoke(this, _currentState);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建动画
|
||||
/// </summary>
|
||||
/// <param name="animatedObject">要动画化的模型对象</param>
|
||||
/// <param name="pathPoints">路径点列表</param>
|
||||
/// <param name="durationSeconds">动画持续时间(秒)</param>
|
||||
public void CreateAnimation(ModelItem animatedObject, List<Point3D> pathPoints, double durationSeconds = 10.0)
|
||||
{
|
||||
SetupAnimation(animatedObject, pathPoints, durationSeconds);
|
||||
SetState(AnimationState.Ready);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user