using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Autodesk.Navisworks.Api;
using NavisApplication = Autodesk.Navisworks.Api.Application;
namespace NavisworksTransport
{
///
/// 模型分层拆分对话框
///
public partial class ModelSplitterDialog : Form
{
#region 私有字段
private ModelSplitterManager _splitterManager;
private FloorDetector _floorDetector;
private AttributeGrouper _attributeGrouper;
private List _previewResults;
private bool _isProcessing = false;
// UI控件
private ComboBox _strategyComboBox;
private ComboBox _attributeComboBox;
private TextBox _outputDirectoryTextBox;
private Button _browseDirectoryButton;
private TextBox _fileNamePatternTextBox;
private CheckBox _includeEmptyLayersCheckBox;
private CheckBox _createSubDirectoriesCheckBox;
private CheckBox _generateReportCheckBox;
private ListView _previewListView;
private ProgressBar _progressBar;
private Label _statusLabel;
private Button _previewButton;
private Button _executeButton;
private Button _cancelButton;
private Button _helpButton;
// 高级设置控件
private NumericUpDown _elevationToleranceNumeric;
private NumericUpDown _minFloorHeightNumeric;
private ComboBox _fileFormatComboBox;
#endregion
#region 构造函数
public ModelSplitterDialog()
{
InitializeComponent();
InitializeManagers();
LoadInitialData();
}
#endregion
#region 初始化方法
private void InitializeComponent()
{
this.Text = "模型分层拆分工具";
this.Size = new Size(800, 720);
this.StartPosition = FormStartPosition.CenterParent;
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ShowInTaskbar = false;
CreateControls();
LayoutControls();
AttachEventHandlers();
}
private void CreateControls()
{
// 分层策略
var strategyLabel = new Label
{
Text = "分层策略:",
AutoSize = true,
Font = new Font("微软雅黑", 8, FontStyle.Bold)
};
_strategyComboBox = new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDownList,
Font = new Font("微软雅黑", 8)
};
_strategyComboBox.Items.AddRange(new object[]
{
"按楼层分层",
"按自定义属性分层",
"按类别分层",
"按高程范围分层"
});
_strategyComboBox.SelectedIndex = 0;
// 属性选择
var attributeLabel = new Label
{
Text = "分层属性:",
AutoSize = true,
Font = new Font("微软雅黑", 8, FontStyle.Bold)
};
_attributeComboBox = new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDownList,
Font = new Font("微软雅黑", 8)
};
// 输出目录
var outputLabel = new Label
{
Text = "输出目录:",
AutoSize = true,
Font = new Font("微软雅黑", 8, FontStyle.Bold)
};
_outputDirectoryTextBox = new TextBox
{
Font = new Font("微软雅黑", 8),
Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "NavisworksSplit")
};
_browseDirectoryButton = new Button
{
Text = "浏览...",
Font = new Font("微软雅黑", 8),
Size = new Size(80, 25)
};
// 文件命名模式
var patternLabel = new Label
{
Text = "文件命名:",
AutoSize = true,
Font = new Font("微软雅黑", 8, FontStyle.Bold)
};
_fileNamePatternTextBox = new TextBox
{
Font = new Font("微软雅黑", 8),
Text = "{ProjectName}_{LayerName}"
};
// 选项设置
_includeEmptyLayersCheckBox = new CheckBox
{
Text = "包含空分层",
Font = new Font("微软雅黑", 8),
AutoSize = true
};
_createSubDirectoriesCheckBox = new CheckBox
{
Text = "创建子目录",
Font = new Font("微软雅黑", 8),
AutoSize = true,
Checked = true
};
_generateReportCheckBox = new CheckBox
{
Text = "生成报告",
Font = new Font("微软雅黑", 8),
AutoSize = true,
Checked = true
};
// 高级设置
var toleranceLabel = new Label
{
Text = "高程容差(m):",
AutoSize = true,
Font = new Font("微软雅黑", 8)
};
_elevationToleranceNumeric = new NumericUpDown
{
Font = new Font("微软雅黑", 8),
DecimalPlaces = 1,
Minimum = 0.1m,
Maximum = 10.0m,
Value = 0.5m,
Increment = 0.1m
};
var floorHeightLabel = new Label
{
Text = "最小楼层高度(m):",
AutoSize = true,
Font = new Font("微软雅黑", 8)
};
_minFloorHeightNumeric = new NumericUpDown
{
Font = new Font("微软雅黑", 8),
DecimalPlaces = 1,
Minimum = 1.0m,
Maximum = 20.0m,
Value = 2.5m,
Increment = 0.5m
};
var formatLabel = new Label
{
Text = "文件格式:",
AutoSize = true,
Font = new Font("微软雅黑", 8)
};
_fileFormatComboBox = new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDownList,
Font = new Font("微软雅黑", 8)
};
_fileFormatComboBox.Items.AddRange(new object[] { "nwd", "nwf", "nwc" });
_fileFormatComboBox.SelectedIndex = 0;
// 预览列表
var previewLabel = new Label
{
Text = "分层预览:",
AutoSize = true,
Font = new Font("微软雅黑", 8, FontStyle.Bold)
};
_previewListView = new ListView
{
View = System.Windows.Forms.View.Details,
FullRowSelect = true,
GridLines = true,
Font = new Font("微软雅黑", 8)
};
_previewListView.Columns.Add("分层名称", 150);
_previewListView.Columns.Add("元素数量", 80);
_previewListView.Columns.Add("输出文件", 200);
_previewListView.Columns.Add("状态", 100);
// 进度和状态
_progressBar = new ProgressBar
{
Visible = false
};
_statusLabel = new Label
{
Text = "就绪",
Font = new Font("微软雅黑", 8),
ForeColor = System.Drawing.Color.DarkBlue,
AutoSize = true
};
// 按钮
_previewButton = new Button
{
Text = "预览分层",
Font = new Font("微软雅黑", 8),
Size = new Size(100, 30)
};
_executeButton = new Button
{
Text = "开始拆分",
Font = new Font("微软雅黑", 8),
Size = new Size(100, 30),
Enabled = false
};
_cancelButton = new Button
{
Text = "取消",
Font = new Font("微软雅黑", 8),
Size = new Size(80, 30),
DialogResult = DialogResult.Cancel
};
_helpButton = new Button
{
Text = "帮助",
Font = new Font("微软雅黑", 8),
Size = new Size(80, 30)
};
// 添加所有控件到窗体
this.Controls.AddRange(new Control[]
{
strategyLabel, _strategyComboBox,
attributeLabel, _attributeComboBox,
outputLabel, _outputDirectoryTextBox, _browseDirectoryButton,
patternLabel, _fileNamePatternTextBox,
_includeEmptyLayersCheckBox, _createSubDirectoriesCheckBox, _generateReportCheckBox,
toleranceLabel, _elevationToleranceNumeric,
floorHeightLabel, _minFloorHeightNumeric,
formatLabel, _fileFormatComboBox,
previewLabel, _previewListView,
_progressBar, _statusLabel,
_previewButton, _executeButton, _cancelButton, _helpButton
});
}
private void LayoutControls()
{
int margin = 15;
int currentY = margin;
int labelHeight = 20;
int controlHeight = 25;
int spacing = 8;
// 分层策略
var strategyLabel = this.Controls.OfType