You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1500 lines
52 KiB
C#

1 month ago
// <copyright file="FormMain.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
1 month ago
using System.Threading;
1 month ago
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.Pdf.Native;
using DevExpress.Utils;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Docking;
using DevExpress.XtraBars.Docking2010.Views;
using DevExpress.XtraBars.Docking2010.Views.Tabbed;
using DevExpress.XtraBars.Ribbon;
using FlexenabledLic;
using GeoSigma.SigmaDrawerUtil;
using GeoSigma.UCDraw;
using GeoSigmaDrawLib;
1 month ago
using AI.AgentIntegration;
1 month ago
using SigmaDrawerElement;
using UCDraw;
namespace PcgDrawR
{
/// <summary>
/// 软件主窗体.
/// </summary>
public partial class FormMain : RibbonForm
{
/// <summary>
/// Tab 页签最长长度
/// </summary>
private const int TABMAXLENGTH = 10;
private readonly string fileLayout = Path.Combine(Application.StartupPath, "layout.xml");
private readonly string workspaceName1 = "MyLayout";
1 month ago
private readonly LicHelp licHelp;
1 month ago
// 启动参数
private readonly string startFile = string.Empty;
private readonly List<string> lstArgs = new List<string>();
private bool batchSetZColorFlag = false;
private Security security;
1 month ago
private bool isDQLogin = false;
private bool isLogin = false;
1 month ago
/// <summary>
/// Gets or sets the z color width.
/// </summary>
public double ZColorWidth { get; set; } = 25;
private RecentFileConfig recentConfig = null;
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string lpFileName);
1 month ago
[DllImport("kernel32", EntryPoint = "FreeLibrary", SetLastError = true)]
1 month ago
private static extern bool FreeLibrary(IntPtr hModule);
private static void ValidateDll(string dllName)
{
string dllPath = Path.Combine(Application.StartupPath, dllName);
IntPtr hModule = IntPtr.Zero;
try
{
hModule = LoadLibrary(dllPath);
if (hModule == IntPtr.Zero)
{
1 month ago
throw new Win32Exception(Marshal.GetLastWin32Error(), dllName);
1 month ago
}
}
finally
{
if (hModule != IntPtr.Zero)
{
FreeLibrary(hModule);
}
}
}
1 month ago
1 month ago
/// <summary>
/// Initializes a new instance of the <see cref="FormMain"/> class.
/// </summary>
public FormMain()
{
1 month ago
this.InitializeComponent();
1 month ago
this.barButtonItem8.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
1 month ago
this.tabbedView1.Ribbon = this.ribbonControl1;
if (this.tabbedView1.InvalidDocumentTypes == null)
{
this.tabbedView1.InvalidDocumentTypes = new List<Type>();
}
this.tabbedView1.InvalidDocumentTypes.Add(
1 month ago
typeof(DevExpress.XtraBars.Docking.FloatForm));
1 month ago
this.licHelp = new LicHelp("KEPlatform");
this.licHelp.LoginResultEvent += async (LoginResult result) =>
1 month ago
{
int nStatus = result.Status;
1 month ago
await this.setDQLoginStatusAsync(nStatus);
// Task.Delay 和 DoLogin 可以在后台线程继续执行,不会影响 UI
if (nStatus != 2 && nStatus != 0)
{
await Task.Delay(TimeSpan.FromSeconds(60));
this.licHelp.DoLogin();
1 month ago
}
};
// 属性面板关闭时,将主菜单开关闭“属性”按钮设置为 unchecked
1 month ago
this.dckPanelProperty.ClosedPanel += (sender, e) =>
1 month ago
{
1 month ago
this.btnViewProperty.Checked = false;
1 month ago
};
// 关闭图层时把对应属性改为 unchecked
1 month ago
this.dckPanelLayer.ClosedPanel += (sender, e) =>
1 month ago
{
1 month ago
this.btnViewLayer.Checked = false;
1 month ago
};
// 关闭统计元素时把对应属性改为 unchecked
1 month ago
this.dckPanelStatic.ClosedPanel += (sender, e) =>
1 month ago
{
1 month ago
this.btnViewStatic.Checked = false;
1 month ago
};
1 month ago
this.ribbonControl1.OptionsMenuMinWidth = 0;
this.KeyPreview = true;
1 month ago
1 month ago
NativeLibraryPathRegistrar.Register();
1 month ago
}
1 month ago
1 month ago
/// <summary>
1 month ago
/// 获取一下当前 TabbedView方便后续进行操作
/// </summary>
public DrawerTabbedView TabbedView1 => tabbedView1;
/// <summary>
/// 设置登录状态.
1 month ago
/// </summary>
/// <param name="statusCode">The status code.</param>
private async Task setDQLoginStatusAsync(int statusCode)
{
if (this.InvokeRequired)
{
// 使用 BeginInvoke 异步调用
this.Invoke(
new Action<int>(async (code) =>
1 month ago
await this.setDQLoginStatusAsync(code)), statusCode);
1 month ago
return;
}
1 month ago
1 month ago
if (statusCode == 0)
{ // 登录成功
1 month ago
this.isDQLogin = true;
1 month ago
await this.setLoginStatusAsync();
}
else if (statusCode == 2)
{
// 不需要登录大庆服务器,不设置登录状态。
1 month ago
this.isDQLogin = true;
1 month ago
}
else
{ // 登录失败
1 month ago
this.isDQLogin = false;
1 month ago
await this.setLoginStatusAsync();
// 大庆版本
MessageBox.Show(this, "登录失败,请尽快保存文件!", "登录许可失败");
}
}
1 month ago
/// <inheritdoc/>
protected override void OnKeyUp(KeyEventArgs e)
{
1 month ago
// if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
// {
1 month ago
// CurrentForm.SaveFile();
1 month ago
// }
1 month ago
if (e.KeyCode == Keys.O && e.Modifiers == Keys.Control)
{
1 month ago
this.btnFileOpen_ItemClick(this, null);
1 month ago
}
else if (e.KeyCode == Keys.N && e.Modifiers == Keys.Control)
{
1 month ago
this.btnFileNew_ItemClick(this, null);
1 month ago
}
}
/// <summary>
/// Initializes a new instance of the <see cref="FormMain"/> class.
/// </summary>
/// <param name="args">参数 /ZC-按块显示散点Z值</param>
public FormMain(string[] args)
: this()
{
if (args.Length > 0)
{
this.startFile = args[0].Trim();
}
if (args.Length > 1)
{
1 month ago
this.lstArgs.Clear();
1 month ago
for (int i = 1; i < args.Length; i++)
{
1 month ago
this.lstArgs.Add(args[i]);
1 month ago
}
}
1 month ago
this.bbtnMeshAntiAlias.Checked = DrawerGlobalConfig.Instance.MeshNode.AntiAliasingEnable;
this.ribbonControl1.OptionsMenuMinWidth = 0;
// 注册
AppController.Instance.MainForm = this;
NativeLibraryPathRegistrar.Register();
}
1 month ago
1 month ago
protected override void OnLoad(EventArgs e)
{
// 必须在事件循环启动之后调用
UiDispatcher.Instance.Initialize(SynchronizationContext.Current);
1 month ago
1 month ago
base.OnLoad(e);
1 month ago
}
/// <summary>
1 month ago
/// Gets 当前激活的文档
1 month ago
/// </summary>
private UCDrawEdit CurrentForm
{
get
{
if (this.tabbedView1.ActiveDocument != null)
{
1 month ago
return this.tabbedView1.ActiveDocument.Control as UCDrawEdit;
1 month ago
}
else if (this.tabbedView1.ActiveFloatDocument != null)
{
1 month ago
return this.tabbedView1.ActiveFloatDocument.Control as UCDrawEdit;
1 month ago
}
return null;
}
}
/// <summary>
1 month ago
/// Gets 所有打开的标签页
/// </summary>
public List<string> OpenTabs
{
get
{
return tabbedView1
.Documents
.Cast<Document>()
.Select(document => document.Caption)
.ToList();
}
}
/// <summary>
/// Gets 当前激活标签
/// </summary>
public string ActivateTab
{
get
{
return tabbedView1.ActiveDocument?.Caption;
}
set
{
if (value != null)
{
foreach (Document document in tabbedView1.Documents.Cast<Document>())
{
if (document.Caption == value)
{
tabbedView1.ActivateDocument(document.Control);
break;
}
}
}
}
}
/// <summary>
/// 保存所有文件
/// </summary>
public void SaveAll()
{
foreach (Document document in tabbedView1.Documents.Cast<Document>())
{
if (document.Control is UCDrawEdit edit)
{
edit.SaveFile();
}
}
}
/// <summary>
/// 重新加载当前文件
/// </summary>
public void ReloadFile()
{
if (tabbedView1.ActiveDocument != null && tabbedView1.ActiveDocument.Control is UCDrawEdit edit)
{
edit.DrawerView.ReloadFile();
}
}
/// <summary>
/// Gets or sets drawerGlobalConfig
1 month ago
/// </summary>
public DrawerGlobalConfig DrawerGlobalConfig { get; set; } = DrawerGlobalConfig.Instance;
private FileDropHandler fileDroper;
/// <summary>
/// Forms the main_ load.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
1 month ago
private async void FormMain_Load(object sender, EventArgs e)
1 month ago
{
try
{
1 month ago
if (Security.CurentLicenseInfo.IsNetServer == true)
{
1 month ago
this.isLogin = false;
1 month ago
await this.setLoginStatusAsync();
}
else
{
1 month ago
this.isLogin = true;
1 month ago
}
1 month ago
1 month ago
this.security = new Security();
1 month ago
this.security.LicenseInvalidateEvent += async (status, message) =>
1 month ago
{
1 month ago
this.isLogin = status == 1;
1 month ago
await this.setLoginStatusAsync();
};
1 month ago
this.security.CheckLicense(this);
1 month ago
}
catch
{
Application.Exit();
}
1 month ago
this.fileDroper = new FileDropHandler(this);
1 month ago
try
{
// Disable layout load animation effects
1 month ago
this.workspaceManager1.AllowTransitionAnimation = DevExpress.Utils.DefaultBoolean.False;
1 month ago
WorkspaceManager.SetSerializationEnabled(this.ribbonControl1, false);
// Load DevExpress controls' layouts from a file
1 month ago
if (this.workspaceManager1.LoadWorkspace(this.workspaceName1, this.fileLayout, true))
1 month ago
{
1 month ago
this.workspaceManager1.ApplyWorkspace(this.workspaceName1);
1 month ago
this.dckPanelLayer.Text = "图层";
}
1 month ago
this.InitRecentConfig();
1 month ago
}
finally
{
1 month ago
this.licHelp.DoLogin();
1 month ago
}
#if !DEBUG
CheckEnvironment();
#endif
}
1 month ago
private async Task setLoginStatusAsync()
{
bool isLoggedIn = this.isDQLogin && this.isLogin;
string tooltipText = isLoggedIn ? "已登录" : "未登录";
string resourceName = isLoggedIn
? "bsiLoginInfo.ImageOptions.SvgImage"
: "bsiLoginInfo.ImageOptions.DisabledSvgImage";
// 更新非资源依赖的UI部分
this.bsiLoginInfo.Enabled = true;
((ToolTipItem)this.bsiLoginInfo.SuperTip.Items[0]).Text = tooltipText;
// 异步加载资源
var resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain));
var svgImage = await Task.Run(() => resources.GetObject(resourceName));
// 回到UI线程更新图像实际上await会自动回到UI线程
this.bsiLoginInfo.ImageOptions.SvgImage = (DevExpress.Utils.Svg.SvgImage)svgImage;
}
1 month ago
/// <summary>
/// Forms the main_ shown.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void FormMain_Shown(object sender, EventArgs e)
{
1 month ago
this.LoadStartFile();
// SplashScreenManager.CloseForm(true);
this.ribbonStatusBar1.Visible = true;
1 month ago
}
/// <summary>
/// Inits the recent config.
/// </summary>
private void InitRecentConfig()
{
1 month ago
this.recentConfig = new RecentFileConfig();
1 month ago
this.ResetOpenMenu();
}
/// <summary>
/// 加载启动参数指定的文件async
/// </summary>
private void LoadStartFile()
{
if (string.IsNullOrEmpty(this.startFile))
{
return;
}
string ext = Path.GetExtension(this.startFile);
if (this.lstArgs.Count > 0)
{
string strVtk = this.lstArgs.Find(it => { return it.ToUpper().StartsWith("/VTK"); });
if (ext == ".xyz" && !string.IsNullOrEmpty(strVtk))
{
1 month ago
this.OpenVtkView();
1 month ago
return;
}
string strZC = this.lstArgs.Find(it => { return it.ToUpper().StartsWith("/ZC"); });
if (!string.IsNullOrEmpty(strZC))
{
int nSizeIndex = strZC.IndexOf(':');
if (nSizeIndex > 0)
{
1 month ago
this.ZColorWidth = Convert.ToInt32(strZC.Substring(nSizeIndex + 1));
1 month ago
}
1 month ago
// string ext = Path.GetExtension(this.startFile);
// if(ext == ".xyz")
// {
this.batchSetZColorFlag = true;
// }
this.OpenFile(this.startFile, true);
1 month ago
this.lstArgs.Clear();
}
}
else
{
1 month ago
this.OpenFile(this.startFile);
1 month ago
}
}
/// <summary>
/// Sets the VTK main mesh.
/// </summary>
/// <param name="filePath">The file path.</param>
/// <param name="pMesh">The p mesh.</param>
public void SetVtkMainMesh(string filePath, IntPtr pMesh)
{
1 month ago
this.CurrentForm.SetVtkMainMesh(pMesh);
this.CurrentForm.MainMeshProperty = this.CurrentForm.PropertyControl.ElementProperty;
1 month ago
var vtkEdit = this.CurrentForm.VtkEdit;
if (vtkEdit != null && !vtkEdit.IsDisposed)
{
vtkEdit.VtkMainMesh = pMesh;
1 month ago
vtkEdit.SetMainMeshProperty(this.CurrentForm.MainMeshProperty);
1 month ago
vtkEdit.PropertyControl.SelectedObject = vtkEdit.VtkProerty;
}
}
private void CloseVtkHandler(UCVtkEdit vtkEdit)
{
if (vtkEdit != null && vtkEdit.DrawEdit != null)
{
vtkEdit.DrawEdit.SetVtkMainMesh(IntPtr.Zero);
vtkEdit.DrawEdit.VtkEdit = null;
this.tabbedView1.RemoveDocument(vtkEdit);
}
}
1 month ago
private void tabbedView1_DocumentActivated(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e)
{
if (e.Document == null) return;
// 判断当前激活的文档内容是否为三维编辑控件
if (e.Document.Control is UCVtkEdit)
{
// 处于三维模式:屏蔽成图
if (this.dcpCreateMap != null)
{
this.dcpCreateMap.Visibility = DockVisibility.Hidden;
}
}
else
{
// 切换到了其他文档(如二维图):还原成图并选中属性
if (this.dcpCreateMap != null && this.dckPanelProperty != null)
{
// 还原成图面板可见性
this.dcpCreateMap.Visibility = DockVisibility.Visible;
// 确保属性面板可见
this.dckPanelProperty.Visibility = DockVisibility.Visible;
// 切换 Tab 到属性页
if (this.dckPanelProperty.ParentPanel != null)
{
this.dckPanelProperty.ParentPanel.ActiveChild = this.dckPanelProperty;
}
}
}
}
1 month ago
private void ShowVtkHandler(object sender, ShowVtkEventArgs e)
{
1 month ago
UCDrawEdit ucdraw = this.CurrentForm;
1 month ago
if (ucdraw == null)
{
return;
}
// 按分号分割(移除空条目)
string[] segments = e.WellLayer.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
1 month ago
// 一个二维图只打开一个三维窗口,已经打开了三维窗口的情况
1 month ago
if (ucdraw.VtkEdit != null)
{
ucdraw.VtkEdit.VtkProerty.InitWellTypeColors(segments);
1 month ago
ucdraw.VtkEdit.propertyGridControl.UpdateData();
1 month ago
// 激活文档
1 month ago
this.tabbedView1.ActivateDocument(ucdraw.VtkEdit);
return;
}
Drawer drawer = ucdraw.DrawerView.ViewControl.Drawer;
// 初始化vtk控件
UCVtkEdit vtkEdit = new UCVtkEdit();
1 month ago
//vtkEdit.Disposed += (s, args) => {
// if (this.dcpCreateMap != null)
// {
// // 还原成图面板
// this.dcpCreateMap.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
// }
//};
1 month ago
// 双向绑定
1 month ago
this.CurrentForm.VtkEdit = vtkEdit;
vtkEdit.DrawEdit = this.CurrentForm;
// 设置主网格
vtkEdit.VtkMainMesh = this.CurrentForm.VtkMainMesh;
vtkEdit.SetMainMeshProperty(this.CurrentForm.MainMeshProperty);
1 month ago
vtkEdit.PropertyControl.SelectedObject = vtkEdit.VtkProerty;
// 初始化井类别颜色
vtkEdit.VtkProerty.InitWellTypeColors(segments);
1 month ago
vtkEdit.propertyGridControl.UpdateData();
1 month ago
vtkEdit.LayerPanel = this.dckPanelLayer;
vtkEdit.PropertyPanel = this.dckPanelProperty;
vtkEdit.StatisticPanel = this.dckPanelStatic;
vtkEdit.DrawerStatusBar = this.ribbonControl1.StatusBar;
var vtkdoc = this.tabbedView1.AddDocument(vtkEdit);
string fileName = Path.GetFileName(e.FilePath) + "三维";
vtkdoc.Caption = fileName;
vtkEdit.Show();
this.ribbonControl1.MergeRibbon(vtkEdit.RibbonControlMain);
this.SuspendLayout();
1 month ago
this.splashScreenManager1.ShowWaitForm();
this.splashScreenManager1.SetWaitFormDescription("正在打开三维...");
// 初始化vtk数据树
1 month ago
vtkEdit.InitTreeList(e);
1 month ago
// 显示图数据
1 month ago
vtkEdit.ShowDrawData(e.FilePath);
1 month ago
// 检测是否有网络数据
1 month ago
IntPtr pMeshData = vtkEdit.GetMainMeshData();
if (pMeshData == IntPtr.Zero)
{
this.tabbedView1.RemoveDocument(vtkEdit);
ucdraw.VtkEdit = null;
1 month ago
this.splashScreenManager1.CloseWaitForm();
1 month ago
MessageBox.Show("没有网格数据!", "数据错误!");
return;
}
double rx0 = vtkEdit.GetMainMeshInfo(pMeshData, 0);
double rx1 = vtkEdit.GetMainMeshInfo(pMeshData, 1);
double ry0 = vtkEdit.GetMainMeshInfo(pMeshData, 2);
double ry1 = vtkEdit.GetMainMeshInfo(pMeshData, 3);
1 month ago
// IntPtr hBitmap = drawer.Geo.Draw2ImageMemory(rx0, ry1, rx1, ry0);
1 month ago
IntPtr hBitmap = drawer.Geo.GetKevMeshImage(pMeshData);
if (hBitmap == IntPtr.Zero)
{
this.tabbedView1.RemoveDocument(vtkEdit);
ucdraw.VtkEdit = null;
1 month ago
this.splashScreenManager1.CloseWaitForm();
1 month ago
MessageBox.Show("图像显示比例过大,无法生成!", "数据错误!");
return;
}
vtkEdit.UpdateMeshBitmap(hBitmap, rx0, ry1, Math.Abs(rx0 - rx1), Math.Abs(ry0 - ry1));
drawer.Geo.DeleteImage(hBitmap);
// 加载三维配置信息
ucdraw.SetVtkSettings(vtkEdit);
1 month ago
ucdraw.VtkEdit.UpdateWellTypeColor();
1 month ago
1 month ago
//切换标签 是否显示成图
this.tabbedView1.DocumentActivated += tabbedView1_DocumentActivated;
if (this.tabbedView1.OtherDocumentActivated == null)
1 month ago
{
1 month ago
this.tabbedView1.OtherDocumentActivated += vtkEdit.AfterDocumentActived;
1 month ago
}
1 month ago
this.dcpCreateMap.Visibility = DockVisibility.Hidden;
this.splashScreenManager1.CloseWaitForm();
1 month ago
this.ResumeLayout();
}
/// <summary>
/// 新建文件
/// </summary>
private void OpenVtkView()
{
1 month ago
// documentIndex++;
// string strFile = $"新建文件{documentIndex}";
// UCDrawEdit drawEdit = new UCDrawEdit();
// drawEdit.LayerPanel = this.dckPanelLayer;
// drawEdit.PropertyPanel = this.dckPanelProperty;
// drawEdit.StatisticPanel = this.dckPanelStatic;
// drawEdit.DrawerStatusBar = this.ribbonControl1.StatusBar;
// drawEdit.EnableMeshPack = DrawerGlobalConfig.Instance.MeshNode.AntiAliasingEnable;
// drawEdit.ZColorWidth = this.ZColorWidth;
// if (drawEdit.CreateNewFile(strFile) == false)
// {
1 month ago
// documentIndex--;
// return;
1 month ago
// }
// drawEdit.NewFileSavedEvent += new NewFileSavedHandler((fileName) =>
// {
1 month ago
// SetRecent(fileName);
1 month ago
// });
1 month ago
1 month ago
// var doc = this.tabbedView1.AddDocument(drawEdit);
// drawEdit.Show();
// doc.Caption = drawEdit.Text;
1 month ago
1 month ago
// this.ribbonControl1.MergeRibbon(drawEdit.ribbonMain);
1 month ago
UCVtkEdit vtkChild = new UCVtkEdit();
vtkChild.LayerPanel = this.dckPanelLayer;
vtkChild.PropertyPanel = this.dckPanelProperty;
vtkChild.StatisticPanel = this.dckPanelStatic;
vtkChild.DrawerStatusBar = this.ribbonControl1.StatusBar;
this.ribbonControl1.MergeRibbon(vtkChild.RibbonControlMain);
var vtkdoc = this.tabbedView1.AddDocument(vtkChild);
vtkChild.Show();
vtkChild.ClearVtkShowEventHandler();
1 month ago
this.splashScreenManager1.ShowWaitForm();
this.splashScreenManager1.SetWaitFormDescription("正在打开三维...");
1 month ago
this.SuspendLayout();
vtkChild.VtkShowEventHandler += (sender, e) =>
{
1 month ago
this.splashScreenManager1.CloseWaitForm();
1 month ago
};
vtkChild.ShowXyzData(this.startFile);
vtkdoc.Caption = this.startFile + "三维";
}
/// <summary>
/// Forms the main_ form closed.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
{
1 month ago
// Save DevExpress controls' layouts to a file
this.workspaceManager1.CaptureWorkspace(this.workspaceName1, true);
this.workspaceManager1.SaveWorkspace(this.workspaceName1, this.fileLayout, true);
1 month ago
1 month ago
this.licHelp.LogOut();
1 month ago
}
/// <summary>
/// 合并子窗体控件
/// </summary>
/// <param name="sender">ribbon控件</param>
/// <param name="e">事件参数</param>
private void ribbonControl1_Merge(object sender, DevExpress.XtraBars.Ribbon.RibbonMergeEventArgs e)
{
1 month ago
// RibbonControl parentRRibbon = sender as RibbonControl;
1 month ago
RibbonControl childRibbon = e.MergedChild;
childRibbon.Dock = DockStyle.None;
if (childRibbon.Parent is UCDrawEdit)
{
UCDrawEdit child = childRibbon.Parent as UCDrawEdit;
child.ViewGroupVisible = false;
child.MergePanels();
1 month ago
if (this.btnViewProperty.Checked != child.PropertyPanelVisible)
1 month ago
{
1 month ago
this.btnViewProperty.Checked = child.PropertyPanelVisible;
1 month ago
}
1 month ago
if (this.btnViewLayer.Checked != child.PropertyPanelVisible)
1 month ago
{
1 month ago
this.btnViewLayer.Checked = child.PropertyPanelVisible;
1 month ago
}
1 month ago
if (this.btnViewStatic.Checked != child.StatisticPanelVisible)
1 month ago
{
1 month ago
this.btnViewStatic.Checked = child.StatisticPanelVisible;
1 month ago
}
}
else if (childRibbon.Parent is UCVtkEdit)
{
UCVtkEdit child = childRibbon.Parent as UCVtkEdit;
child.ViewGroupVisible = false;
child.MergePanels();
1 month ago
if (this.btnViewProperty.Checked != child.PropertyPanelVisible)
1 month ago
{
1 month ago
this.btnViewProperty.Checked = child.PropertyPanelVisible;
1 month ago
}
1 month ago
if (this.btnViewLayer.Checked != child.PropertyPanelVisible)
1 month ago
{
1 month ago
this.btnViewLayer.Checked = child.PropertyPanelVisible;
1 month ago
}
1 month ago
if (this.btnViewStatic.Checked != child.StatisticPanelVisible)
1 month ago
{
1 month ago
this.btnViewStatic.Checked = child.StatisticPanelVisible;
1 month ago
}
}
}
/// <summary>
/// ribbons the control1_ un merge.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void ribbonControl1_UnMerge(object sender, RibbonMergeEventArgs e)
{
try
{
RibbonControl childRibbon = e.MergedChild;
if (childRibbon.Parent is UCDrawEdit)
{
UCDrawEdit child = childRibbon.Parent as UCDrawEdit;
child.UnMergePanels();
}
else if (childRibbon.Parent is UCVtkEdit)
{
UCVtkEdit child = childRibbon.Parent as UCVtkEdit;
child.UnMergePanels();
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}
}
/// <summary>
/// ribbons the control1_ show customization menu.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void ribbonControl1_ShowCustomizationMenu(object sender, RibbonCustomizationMenuEventArgs e)
{
e.ShowCustomizationMenu = false;
}
/// <summary>
/// 激活图件
/// </summary>
/// <param name="fullFile">名称</param>
private bool ActiveDoc(string fullFile)
{
BaseDocument frmDoc =
this.docManager.View.Documents.FirstOrDefault(it =>
{
1 month ago
if (it.Control is UCDrawEdit child)
1 month ago
{
1 month ago
if (fullFile.Equals(child.FileFullName, StringComparison.CurrentCultureIgnoreCase))
{
return true;
}
1 month ago
}
1 month ago
return false;
});
1 month ago
if (frmDoc != null)
{
this.docManager.View.Controller.Activate(frmDoc);
return true;
}
return false;
}
/// <summary>
/// 打开文件
/// </summary>
/// <param name="sender">事件按钮</param>
/// <param name="e">事件参数</param>
private void btnFileOpen_ItemClick(object sender, ItemClickEventArgs e)
{
string[] fileNames = DocHelper.SelectMutiFiles();
foreach (var item in fileNames)
{
if (!string.IsNullOrEmpty(item))
{
1 month ago
this.OpenFile(item);
1 month ago
}
}
}
private void TryRecoverFileWhenUnexpectedShutdown(UCDrawEdit drawEdit, string filePath)
{
if (GeoSigmaXY.SigmaDocBackupExists(filePath))
{
var result = MessageBox.Show("检测到文件异常关闭,是否恢复?", "恢复选项"
, MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
drawEdit.DrawerView.ViewControl.Drawer.RecoverMode = true;
}
}
}
/// <summary>
/// 打开文件
/// </summary>
/// <param name="strFile">文件路径</param>
/// <param name="setZColor">是否以方块方式显示散点数据</param>
1 month ago
// private Task<bool> OpenFile(string strFile, bool setZColor = false)
public bool OpenFile(string strFile, bool setZColor = false)
1 month ago
{
// 已存在的文件仅激活
if (this.ActiveDoc(strFile))
{
return true;
1 month ago
// return Task.FromResult(true);
1 month ago
}
try
{
bool bOpend = false;
UCDrawEdit drawerChild = new UCDrawEdit();
1 month ago
drawerChild.OpenNewFile += this.OnOpenNewFile;
if (this.batchSetZColorFlag)
1 month ago
{
1 month ago
drawerChild.BatchSetZColorFlag = this.batchSetZColorFlag;
this.batchSetZColorFlag = !this.batchSetZColorFlag;
1 month ago
}
drawerChild.LayerPanel = this.dckPanelLayer;
drawerChild.PropertyPanel = this.dckPanelProperty;
drawerChild.CreateMapPanel = this.dcpCreateMap;
drawerChild.StatisticPanel = this.dckPanelStatic;
drawerChild.DrawerStatusBar = this.ribbonControl1.StatusBar;
1 month ago
this.TryRecoverFileWhenUnexpectedShutdown(drawerChild, strFile);
1 month ago
1 month ago
this.splashScreenManager1.ShowWaitForm();
this.splashScreenManager1.SetWaitFormDescription("正在打开文件...");
1 month ago
this.SuspendLayout();
// drawerChild.ribbonMain.Visible = false;
drawerChild.ZColorWidth = this.ZColorWidth;
drawerChild.EnableMeshPack = DrawerGlobalConfig.Instance.MeshNode.AntiAliasingEnable;
bOpend = drawerChild.OpenFile(strFile, setZColor);
if (bOpend == false)
{
1 month ago
this.splashScreenManager1.CloseWaitForm();
1 month ago
// frmChild.Close();
MessageBox.Show($"打开文件{strFile}失败", "打开");
1 month ago
// return Task.FromResult(false);
1 month ago
return false;
}
var doc = this.tabbedView1.AddDocument(drawerChild);
// 标签页上显示短名称
1 month ago
doc.Caption = this.TabName(drawerChild.Text);
1 month ago
// 光标移动上去时显示全名
if (doc is Document document)
{
document.Tooltip = drawerChild.Text;
}
this.ribbonControl1.MergeRibbon(drawerChild.ribbonMain, false);
drawerChild.NewFileSavedEvent += new NewFileSavedHandler((fileName) =>
{
1 month ago
this.SetRecent(fileName);
1 month ago
});
// 打开文件时,三维初始化设置
drawerChild.DrawerView.ViewControl.Drawer.SetVtkMainMeshEvent += new SetVtkMainMeshHandler((filePath, pMesh) =>
{
1 month ago
this.SetVtkMainMesh(filePath, pMesh);
1 month ago
});
1 month ago
drawerChild.ShowVtkEvent += new ShowVtkEventHandler(this.ShowVtkHandler);
drawerChild.CloseVtkEvent = new CloseVtkHandler(this.CloseVtkHandler);
1 month ago
// 加载主网格与图层设置
drawerChild.LoadVtkMainMesh();
drawerChild.LoadLayerSetting();
1 month ago
this.SetRecent(strFile);
this.splashScreenManager1.CloseWaitForm();
1 month ago
#if DEBUG
this.TestEventHandler(drawerChild);
#endif
1 month ago
// return Task.FromResult(true);
1 month ago
return true;
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
1 month ago
// return Task.FromResult(false);
1 month ago
return false;
}
finally
{
this.ResumeLayout();
}
}
/// <summary>
/// 获取 Tab 页显示名称,如果太长会被截断,防止一个标签页占非常长的位置
/// </summary>
/// <param name="caption">要显示的目标名称</param>
/// <returns>最终会被显示的名称</returns>
private string TabName(string caption)
{
return caption.Length > TABMAXLENGTH ? caption.Substring(0, TABMAXLENGTH) : caption;
}
/// <summary>
/// Tests the event handler.
/// </summary>
/// <param name="editor">The editor.</param>
private void TestEventHandler(UCDrawEdit editor)
{
editor.DrawerView.InsertCommonCommand("克隆到其它井组",
new EventHandler((obj, args) =>
{
SelectedElementsArgs selArgs = args as SelectedElementsArgs;
if (selArgs == null)
{ return; }
List<SigmaDrawerElement.DrawerElementProperty> elements = selArgs.Elements;
if (elements != null)
{
1 month ago
// editor.DrawerView.GetSelectedElements()[0];
1 month ago
foreach (DrawerElementProperty ele in elements)
{
1 month ago
// ele.Element
// strbContent.AppendLine(ele.Element.ToDfdString());
1 month ago
}
}
}), true, DrawElementType.ELEMENT_WELL_GROUP);
}
private int documentIndex = 0;
/// <summary>
/// 新建文件
/// </summary>
/// <param name="sender">按钮</param>
/// <param name="e">事件参数</param>
private void btnFileNew_ItemClick(object sender, ItemClickEventArgs e)
{
1 month ago
this.documentIndex++;
string strFile = $"新建文件{this.documentIndex}";
1 month ago
UCDrawEdit frmChild = new UCDrawEdit();
1 month ago
frmChild.OpenNewFile += this.OnOpenNewFile;
1 month ago
frmChild.LayerPanel = this.dckPanelLayer;
frmChild.CreateMapPanel = this.dcpCreateMap;
frmChild.PropertyPanel = this.dckPanelProperty;
frmChild.StatisticPanel = this.dckPanelStatic;
frmChild.DrawerStatusBar = this.ribbonControl1.StatusBar;
frmChild.EnableMeshPack = DrawerGlobalConfig.Instance.MeshNode.AntiAliasingEnable;
frmChild.ZColorWidth = this.ZColorWidth;
if (frmChild.CreateNewFile(strFile) == false)
{
1 month ago
this.documentIndex--;
1 month ago
return;
}
frmChild.NewFileSavedEvent += new NewFileSavedHandler((fileName) =>
{
1 month ago
this.SetRecent(fileName);
1 month ago
});
// 加载子窗体布局
frmChild.Show();
var doc = this.tabbedView1.AddDocument(frmChild);
doc.Caption = frmChild.Text;
// 打开文件时,三维初始化设置
frmChild.DrawerView.ViewControl.Drawer.SetVtkMainMeshEvent += new SetVtkMainMeshHandler((filePath, pMesh) =>
{
1 month ago
this.SetVtkMainMesh(filePath, pMesh);
1 month ago
});
1 month ago
frmChild.ShowVtkEvent += new ShowVtkEventHandler(this.ShowVtkHandler);
frmChild.CloseVtkEvent = new CloseVtkHandler(this.CloseVtkHandler);
1 month ago
this.ribbonControl1.MergeRibbon(frmChild.ribbonMain);
}
/// <summary>
/// Files the closed.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void FileClosed(object sender, EventArgs e)
{
if (sender is UCDrawEdit child)
{
1 month ago
child.ShowStatisticResult -= this.ShowStatic;
1 month ago
}
}
/// <summary>
/// 显示统计面板.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void ShowStatic(object sender, EventArgs e)
{
try
{
this.dckPanelStatic.Visibility = DockVisibility.Visible;
}
finally
{
}
}
/// <summary>
/// Sets the recent.
/// </summary>
/// <param name="file">The file.</param>
private void SetRecent(string file)
{
if (string.IsNullOrEmpty(file))
{
return;
}
if (this.recentConfig.AddTop(file) == false)
{
return;
}
1 month ago
this.ResetOpenMenu();
1 month ago
this.recentConfig.Save();
}
/// <summary>
/// Resets the open menu.
/// </summary>
private void ResetOpenMenu()
{
this.ppmOpen.ClearLinks();
for (int i = 0; i < this.recentConfig.Files.Count; i++)
{
string strFile = this.recentConfig.Files[i];
BarButtonItem item = new BarButtonItem();
item.Caption = strFile;
1 month ago
item.ImageOptions.Image = this.imgsMain.Images["fileNew"];
1 month ago
item.ItemClick += new ItemClickEventHandler(async (object sender, ItemClickEventArgs e) =>
{
1 month ago
this.OpenFile(strFile);
1 month ago
});
this.ppmOpen.AddItem(item);
}
}
/// <summary>
/// 保存文件
/// </summary>
/// <param name="sender">按钮</param>
/// <param name="e">事件参数</param>
private void btnSaveMain_ItemClick(object sender, ItemClickEventArgs e)
{
1 month ago
if (this.CurrentForm == null)
1 month ago
{
return;
}
1 month ago
if (this.CurrentForm.SaveFile())
1 month ago
{
1 month ago
this.SetRecent(this.CurrentForm.FileFullName);
1 month ago
}
}
/// <summary>
/// 另存为
/// </summary>
/// <param name="sender">事件按钮</param>
/// <param name="e">事件参数</param>
private void btnSaveAs_ItemClick(object sender, ItemClickEventArgs e)
{
1 month ago
if (this.CurrentForm == null)
1 month ago
{
return;
}
1 month ago
if (this.CurrentForm.SaveAs())
1 month ago
{
1 month ago
this.SetRecent(this.CurrentForm.FileFullName);
1 month ago
}
}
/// <summary>
/// 符号管理
/// </summary>
/// <param name="sender">按钮</param>
/// <param name="e">事件参数</param>
private void btnSymbolManager_ItemClick(object sender, ItemClickEventArgs e)
{
1 month ago
//DirectoryInfo symbolFilePath = Directory.GetParent(Application.StartupPath);
string parentPath = Path.GetFullPath(Path.Combine(Application.StartupPath, ".."));
string symbolFile = Path.Combine(parentPath, "Symbol");
1 month ago
1 month ago
if (this.CurrentForm == null)
1 month ago
{
SymbolLibInterface.SymbolHelp.ShowSymbolUI(null, symbolFile);
}
else
{
1 month ago
SymbolLibInterface.SymbolHelp.ShowSymbolUI(this.CurrentForm.DrawerView, symbolFile);
1 month ago
}
}
/// <summary>
/// 选项按纽
/// </summary>
/// <param name="sender">菜单项</param>
/// <param name="e">事件参数</param>
private void btnSetting_Clicked(object sender, ItemClickEventArgs e)
{
1 month ago
// FormGlobalOptions formGlobal = new FormGlobalOptions();
1 month ago
FrmOptions formGlobal = new FrmOptions();
formGlobal.ShowDialog(this);
}
/// <summary>
/// 图层面板
/// </summary>
/// <param name="sender">菜单项</param>
/// <param name="e">事件参数</param>
private void btnViewLayer_CheckedChanged(object sender, ItemClickEventArgs e)
{
try
{
1 month ago
if (this.CurrentForm == null)
1 month ago
{
1 month ago
if (this.btnViewLayer.Checked)
1 month ago
{
this.dckPanelLayer.Visibility = DockVisibility.AutoHide;
}
else
{
1 month ago
if (!this.dockManager1.AutoHideContainers[0].Controls.Contains(this.dckPanelLayer))
1 month ago
{
1 month ago
// this.dockManager1.AutoHideContainers[0].Controls.Add(dckPanelLayer);
this.dockManager1.AddPanel(DockingStyle.Left, this.dckPanelLayer);
1 month ago
}
this.dckPanelLayer.Visibility = DockVisibility.Visible;
}
}
else
{
1 month ago
this.CurrentForm.LayerPanelVisible = this.btnViewLayer.Checked;
1 month ago
}
}
finally
{
}
}
/// <summary>
/// 属性面板可见性设置
/// </summary>
/// <param name="sender">菜单项</param>
/// <param name="e">事件参数</param>
private void btnViewProperty_CheckedChanged(object sender, ItemClickEventArgs e)
{
1 month ago
// LayerPanelVIsible = btnViewProperty.Checked;
1 month ago
try
{
1 month ago
if (this.CurrentForm == null)
1 month ago
{
1 month ago
if (this.btnViewProperty.Checked)
1 month ago
{
this.dckPanelProperty.Visibility = DockVisibility.AutoHide;
}
else
{
this.dckPanelProperty.Visibility = DockVisibility.Visible;
this.dckPanelProperty.ParentPanel.ActiveChild = this.dckPanelProperty;
}
}
else
{
1 month ago
this.CurrentForm.PropertyPanelVisible = this.btnViewProperty.Checked;
1 month ago
}
}
catch
{
}
}
/// <summary>
/// 统计面板
/// </summary>
/// <param name="sender">菜单项</param>
/// <param name="e">事件参数</param>
private void btnViewStatic_CheckedChanged(object sender, ItemClickEventArgs e)
{
try
{
1 month ago
if (this.CurrentForm == null)
1 month ago
{
1 month ago
if (this.btnViewStatic.Checked)
1 month ago
{
this.dckPanelStatic.Visibility = DockVisibility.AutoHide;
}
else
{
this.dckPanelStatic.Visibility = DockVisibility.Visible;
}
}
else
{
1 month ago
this.CurrentForm.StatisticPanelVisible = this.btnViewStatic.Checked;
1 month ago
}
}
catch
{
}
}
/// <summary>
/// 默认消除网格锯齿
/// </summary>
/// <param name="sender">事件菜单</param>
/// <param name="e">事件参数</param>
private void bbtnMeshAntiAlias_CheckedChanged(object sender, ItemClickEventArgs e)
{
Task.Run(() =>
{
1 month ago
DrawerGlobalConfig.Instance.MeshNode.AntiAliasingEnable = this.bbtnMeshAntiAlias.Checked;
1 month ago
DrawerGlobalConfig.Instance.Save();
});
}
/// <summary>
/// 拖放文件
/// </summary>
/// <param name="sender">窗体</param>
/// <param name="e">事件参数</param>
private void FormMain_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);
for (int i = 0; i < filePaths.Length; i++)
{
// 数组中的每个元素都是一个文件或目录的完整路径
string path = filePaths[i];
if (File.Exists(path))
{
1 month ago
this.OpenFile(path, false);
1 month ago
}
}
}
}
/// <summary>
/// 拖放进入事件
/// </summary>
/// <param name="sender">窗体</param>
/// <param name="e">事件参数</param>
private void FormMain_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
// 管理员模式处理文件拖放,不要删除,有作用
string[] filePaths = (string[])e.Data.GetData(typeof(string[]));
for (int i = 0; i < filePaths.Length; i++)
{
// 数组中的每个元素都是一个文件或目录的完整路径
string path = filePaths[i];
if (File.Exists(path))
{
1 month ago
this.OpenFile(path, false);
1 month ago
}
}
}
/// <summary>
/// Gets the neighbor document.
/// </summary>
/// <param name="documents">The documents.</param>
/// <param name="document">The document.</param>
/// <returns>A BaseDocument.</returns>
protected BaseDocument GetNeighborDocument(BaseDocument[] documents, BaseDocument document)
{
int nLength = documents.Length;
if (nLength == 1)
{
return null;
}
int nIndex = Array.IndexOf<BaseDocument>(documents, document);
if (nIndex == nLength - 1)
{
return documents[nIndex - 1];
}
return documents[nIndex + 1];
}
private bool isCloseCanceled = false;
1 month ago
private DrawerTabbedView tabbedView11;
1 month ago
/// <summary>
/// tabbeds the view1_ document closing.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void tabbedView1_DocumentClosing(object sender, DocumentCancelEventArgs e)
{
BaseDocument doc = e.Document as BaseDocument;
if (doc.Control is UCDrawEdit child)
{
FormClosingEventArgs ea = new FormClosingEventArgs(CloseReason.MdiFormClosing, false);
child.UCDrawEdit_FormClosing(sender, ea);
1 month ago
this.isCloseCanceled = e.Cancel = ea.Cancel;
1 month ago
if (e.Cancel)
{
1 month ago
// child.UnMergePanels();
1 month ago
if (doc.IsActive)
{
this.ribbonControl1.MergeRibbon(child.ribbonMain, false);
}
}
else
{
child.SaveLayout();
}
}
}
/// <summary>
/// 窗体关闭事件
/// </summary>
/// <param name="sender">窗体</param>
/// <param name="e">事件参数</param>
private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
{
1 month ago
for (int i = 0; i < this.tabbedView1.Documents.Count; i++)
1 month ago
{
1 month ago
this.tabbedView1.Controller.Close(this.tabbedView1.Documents[i]);
if (this.isCloseCanceled == true)
1 month ago
{
e.Cancel = true;
break;
}
}
if (e.Cancel != true)
{
this.security?.CloseLicense();
}
}
/// <summary>
/// 关于.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param>
private void btnAbout_ItemClick(object sender, ItemClickEventArgs e)
{
FrmAbout frmAbout = new FrmAbout();
frmAbout.Show(this);
}
private void OnOpenNewFile(string filePath)
{
1 month ago
foreach (var doc in this.tabbedView1.Documents)
1 month ago
{
if (doc.Control is UCDrawEdit ucDrawEdit && ucDrawEdit.FileFullName == filePath)
{
ucDrawEdit.OpenFile(filePath);
return;
}
}
1 month ago
this.OpenFile(filePath);
1 month ago
}
/// <summary>
/// 检测运行环境
/// </summary>
private void CheckEnvironment()
{
try
{
1 month ago
this.CheckBaseDependencies();
this.CheckGriddingDependencies();
this.CheckMeshProcessDependencies();
1 month ago
}
catch (Exception ex)
{
MessageBox.Show($"运行错误(E003){ex.Message}, 请联系服务人员!");
Application.Exit();
}
}
private void CheckBaseDependencies()
{
try
{
GeoSigmaLib.GeoSigmaLibInit();
}
catch
{
throw new DllNotFoundException("加载基础库失败");
}
}
private void CheckGriddingDependencies()
{
string[] griddingDependencies =
{
// 生成等值线,和 GridModel.exe 配合使用
"CurveModel.exe",
// 最小张力
"GridModel.exe",
// 最小曲率
"SurfaceGrid.exe",
// 快速网格化
"QuikGridCS.dll",
// 反距离加权
"ModelCreateIDW.dll",
// 自然临近
"NaturalNeighbor.dll",
};
foreach (string depend in griddingDependencies)
{
if (!File.Exists(Path.Combine(Application.StartupPath, depend)))
{
throw new FileNotFoundException($"依赖的 {depend} 文件未找到");
}
if (depend.EndsWith(".dll"))
{
ValidateDll(depend);
}
}
}
private void CheckMeshProcessDependencies()
{
string fileName = "MeshProcess.exe";
if (!File.Exists(Path.Combine(Application.StartupPath, fileName)))
{
1 month ago
throw new FileNotFoundException($"依赖的 {fileName} 文件未找到");
1 month ago
}
}
1 month ago
private void FormMain_MdiChildActivate(object sender, EventArgs e)
1 month ago
{
1 month ago
// string strText = this.Text;
1 month ago
}
1 month ago
/// <summary>
/// 登录信息点击事件处理函数
/// </summary>
/// <param name="sender">事件发送者</param>
/// <param name="e">事件参数,包含点击项的详细信息</param>
private async void bsiLoginInfo_ItemClick(object sender, ItemClickEventArgs e)
1 month ago
{
1 month ago
await this.security.ShowServerConfig();
1 month ago
}
}
}