using CollaborativePlatformMain.CADStartUtil; using CollaborativePlatformMain.DFEntity; using CollaborativePlatformMain.DFEntity.MessageSubUtil; using CollaborativePlatformMain.Form.MessageSubPage.Project; using CollaborativePlatformMain.Form.UserControlForm; using DFBIM.CADNETCommon.XmlConfig; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace CollaborativePlatformMain.Form { /// /// UploadDrawingForm.xaml 的交互逻辑 /// public partial class UploadDrawingForm : Window { /// /// 父级窗体 /// public OperatingFloorPage OperatingFloorPage; /// /// 是否为更新图纸 /// public bool IsRenew = false; /// /// 更新、上传图纸 /// /// public UploadDrawingForm(OperatingFloorPage operatingFloorPage, bool isRenew) { InitializeComponent(); OperatingFloorPage = operatingFloorPage; IsRenew = isRenew; } /// /// 窗体初始化 /// /// /// private void Window_Loaded(object sender, RoutedEventArgs e) { if (IsRenew) { sp_duibi.Visibility = Visibility.Visible; } #region 对比版本 ObservableCollection operatEntities = OperatingFloorPage.ArchOperaDatas; //版本号 List versions = new List(); foreach (var operatEntity in operatEntities) { versions.AddRange(operatEntity.SubDatas.Select(x => x.Node)); } cb_dwgName.ItemsSource = null; cb_dwgName.ItemsSource = versions; #endregion } /// /// 单选框点击事件 /// /// /// private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { RadioButton radioButton = sender as RadioButton; if (radioButton.Content.Equals("是")) { sp_contrast.Visibility = Visibility.Visible; } else { sp_contrast.Visibility = Visibility.Collapsed; } } /// /// 上传图纸 /// /// /// private void Button_Click(object sender, RoutedEventArgs e) { //List operatEntities = OperatingFloorPage.AllOperatDatas; SetOPerData(ArchLayerDatas, ref OperatingFloorPage.ArchOperaDatas); SetOPerData(WarmLayerDatas, ref OperatingFloorPage.WarmOperaDatas); //更新数据 OperatingFloorPage.ReplaceData(); this.Close(); } /// /// 更换数据 /// /// /// public void SetOPerData(List floorLayerDatas, ref ObservableCollection operatEntities) { //D盘 string dPath = Global.GetDriveLetterExceptC(); //原图纸 WholePictureDataConfigUtil wholePictureDataConfigUtil = new WholePictureDataConfigUtil(); WholePictureData wholePictureData = wholePictureDataConfigUtil.Load(string.Format(@"{0}\DFBIM\WholePicture.config", dPath)); //二级 ObservableCollection twoDatas = new ObservableCollection(); twoDatas.Add(new OperatEntity("原图纸", wholePictureData.Path, new ObservableCollection(), false)); //对比图 if (IsRenew) { //对比版本 string banben = cb_dwgName.SelectedItem as string; //选择的对比范围 if (cb_floor.ItemsSource != null) { List selNativeDatas = cb_floor.ItemsSource.Where(x => x.IsSelect).ToList(); ObservableCollection duibiDatas = new ObservableCollection(); foreach (var nativeDataInfo in selNativeDatas) { if (nativeDataInfo.Name.Contains("F1")) { string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F1-对比.dwg", dPath); duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path, new ObservableCollection(), false)); } else if (nativeDataInfo.Name.Contains("F2")) { string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F2-对比.dwg", dPath); duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path, new ObservableCollection(), false)); } else if (nativeDataInfo.Name.Contains("F3")) { string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F3-对比.dwg", dPath); duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path, new ObservableCollection(), false)); } else if (nativeDataInfo.Name.Contains("F4")) { string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F4-对比.dwg", dPath); duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path, new ObservableCollection(), false)); } else if (nativeDataInfo.Name.Contains("F5")) { string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F5-对比.dwg", dPath); duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path, new ObservableCollection(), false)); } else if (nativeDataInfo.Name.Contains("F6")) { string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F6-对比.dwg", dPath); duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path, new ObservableCollection(), false)); } } twoDatas.Add(new OperatEntity("对比图-" + banben, "", duibiDatas, false)); } } //三级 ObservableCollection threeDatas = new ObservableCollection(); threeDatas.Add(new OperatEntity("整栋图", wholePictureData.Path, new ObservableCollection(), false)); //四级 ObservableCollection fourDatas = new ObservableCollection(); foreach (var floorLayerData in floorLayerDatas) { //五级 ObservableCollection fiveDatas = new ObservableCollection(); List layersDatas = floorLayerData.SubDatas; foreach (var layerData in layersDatas) { fiveDatas.Add(new OperatEntity(layerData.LayerName, "", new ObservableCollection(), true)); } fourDatas.Add(new OperatEntity(floorLayerData.FloorName, floorLayerData.DWGPath, fiveDatas, false)); } threeDatas.Add(new OperatEntity("分层图", "", fourDatas, false)); twoDatas.Add(new OperatEntity("治理图纸", "", threeDatas, false)); OperatEntity firstData = new OperatEntity(tb_dwgName.Text.ToString(), "", twoDatas, false); //添加数据 foreach (var operatEntity in operatEntities) { operatEntity.SubDatas.Add(firstData); break; } } /// /// 窗体数据 /// public List ArchLayerDatas = new List(); public List StruLayerDatas = new List(); public List WaterLayerDatas = new List(); public List WarmLayerDatas = new List(); public List EleLayerDatas = new List(); /// /// 选择图纸 /// /// /// private void bt_xaunze_Click(object sender, RoutedEventArgs e) { //FloorDrawingForm floorDrawingForm = new FloorDrawingForm(this); //floorDrawingForm.Show(); StartCADUtil.StartCADMath(); MonitorFloorDataFilePath(); //this.Hide(); } /// /// 监听文件 /// public FileSystemWatcher fileSystemWatcher; /// /// 计时器 /// public System.Threading.Timer m_timer = null; /// /// 定时器触发间隔 /// private int TimeoutMillis = 2000; public void MonitorFloorDataFilePath() { ArchLayerDatas = new List(); // 创建FileSystemWatcher实例 fileSystemWatcher = new FileSystemWatcher(); // 设置要监视的文件夹路径 string dPath = Global.GetDriveLetterExceptC(); fileSystemWatcher.Path = string.Format(@"{0}\DFBIM", dPath); // 设置要监视的更改类型 fileSystemWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; // 如果有需要,设置过滤条件,例如只监视txt文件 fileSystemWatcher.Filter = "*.config"; // 添加事件处理程序 fileSystemWatcher.Changed += fsw_Changed; //fileSystemWatcher.Created += OnChanged; //fileSystemWatcher.Deleted += OnChanged; //fileSystemWatcher.Renamed += OnRenamed; // 开始监视 fileSystemWatcher.EnableRaisingEvents = true; if (m_timer == null) { //设置定时器的回调函数。此时定时器未启动 m_timer = new System.Threading.Timer(new TimerCallback(OnChanged), null, Timeout.Infinite, Timeout.Infinite); } } /// /// 文件监听时间 /// /// /// void fsw_Changed(object sender, FileSystemEventArgs e) { if (e.Name.Contains("FloorLayerData")) { //重新设置定时器的触发间隔,并且仅仅触发一次 m_timer.Change(TimeoutMillis, Timeout.Infinite); } } /// /// 当文件被更改、创建或删除时调用 /// /// /// private void OnChanged(object source) { string dPath = Global.GetDriveLetterExceptC(); //读取配置文件数据 FloorDataConfigUtil xmlInfo = new FloorDataConfigUtil(); ArchLayerDatas.AddRange(xmlInfo.Load>(string.Format(@"{0}\DFBIM\FloorLayerData.config", dPath))); Dictionary keyValuePairs = new Dictionary(); keyValuePairs.Add(0, "风管"); keyValuePairs.Add(1, "风机"); keyValuePairs.Add(2, "风口"); keyValuePairs.Add(3, "水管"); keyValuePairs.Add(4, "套管"); List warmDatas = new List(); for (int i = 0; i < ArchLayerDatas.Count; i++) { List layerDatas = new List(); for (int j = 0; j < 5; j++) { FloorLayerData layerData = new FloorLayerData(keyValuePairs[j]); layerDatas.Add(layerData); } warmDatas.Add(new FloorLayerData(ArchLayerDatas[i].FloorName, "", layerDatas)); } WarmLayerDatas = warmDatas; //// 停止监视 //fileSystemWatcher.EnableRaisingEvents = false; } /// /// 对比版本改变事件 /// 目的:实时刷新对比范围 /// /// /// private void cb_dwgName_SelectionChanged(object sender, SelectionChangedEventArgs e) { //选中的对比版本 string selValue = cb_dwgName.SelectedItem.ToString(); //对比范围 List floorValues = new List(); bool isBreak = false; ObservableCollection operatEntities = OperatingFloorPage.ArchOperaDatas; foreach (var operatEntity in operatEntities) { //版本号 foreach (var twoData in operatEntity.SubDatas) { if (twoData.Node == selValue) { //原图、对比图、治理图 foreach (var threeData in twoData.SubDatas) { if (threeData.Node.Contains("治理")) { //整栋图、分层图 foreach (var fourData in threeData.SubDatas) { if (fourData.Node.Contains("分层")) { foreach (var fiveData in fourData.SubDatas) { floorValues.Add(fiveData.Node); } } } } } isBreak = true; break; } } if (isBreak) break; } //赋值 List nativeDataInfos = new List(); foreach (var floorValue in floorValues) { nativeDataInfos.Add(new NativeDataInfo(Guid.NewGuid().ToString(), floorValue)); } cb_floor.ItemsSource = nativeDataInfos; } } }