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.

1955 lines
76 KiB
C#

1 month ago
// <copyright file="UCVtkEdit.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.Utils.Extensions;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Docking;
using DevExpress.XtraBars.Docking2010.Views;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Rows;
using GeoSigma.SigmaDrawerStyle;
using GeoSigmaDrawLib;
using Newtonsoft.Json;
using SigmaDrawerElement;
using UCDraw;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace PcgDrawR
{
public partial class UCVtkEdit : DevExpress.XtraEditors.XtraUserControl
{
/// <summary>
/// 剪贴板格式类型:三维属性
/// </summary>
public const string CLIPBOARD_FORMAT_VTK_PROPERTY = "CLIPBOARD_FORMAT_VTK_PROPERTY";
/// <summary>
/// Defines the NewFileSavedEvent.
/// </summary>
public NewFileSavedHandler NewFileSavedEvent { get; set; }
/// <summary>
/// 3维图层选择状态通知
/// </summary>
public LayerSelectedNotifyWithStatusHandler LayerSelectedStatusNotify3d { get; set; }
private SigmaDrawerElement.VtkScene vtkProerty = new SigmaDrawerElement.VtkScene();
public SigmaDrawerElement.VtkScene VtkProerty { get => vtkProerty; set => vtkProerty = value; }
/// <summary>
/// Gets or sets the draw edit.
/// </summary>
/// <value>
/// The draw edit.
/// </value>
public UCDrawEdit DrawEdit { get; set; }
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
IntPtr sceneParameter = GetSceneParameter();
DrawEdit?.SetSceneParameter(sceneParameter);
if (DrawEdit != null)
{
DrawEdit.CloseVtkEvent.Invoke(this);
DrawEdit.VtkEdit = null;
}
base.Dispose(disposing);
GeoSigmaLib.KVMS_Destory(VtkVDLNHandle);
GeoSigmaLib.KVDLN_Destory(VtkVDLNHandle);
}
/// <summary>
/// 已经打开了3维界面
/// </summary>
private bool bShownVtkForm = false;
/// <summary>
/// Defines the FileClosedEvent.
/// </summary>
public FileClosedEventHandler FileClosedEvent { get; set; }
/// <summary>
/// Occurs when [VTK show event handler].
/// </summary>
public event EventHandler VtkShowEventHandler;
/// <summary>
/// Clears the VTK show event handler.
/// </summary>
public void ClearVtkShowEventHandler()
{
VtkShowEventHandler = null;
}
/// <summary>
/// Initializes a new instance of the <see cref="UCVtkEdit"/> class.
/// </summary>
public UCVtkEdit()
{
InitializeComponent();
barButtonViewMove.Down = false;
barButtonViewReal.Down = true;
barButtonViewMove.DownChanged += (sender, e) =>
{
if (barButtonViewMove.Down)
{
barButtonViewReal.Down = false;
GeoSigmaLib.KVDLN_ViewPan(VtkVDLNHandle);
}
else
{
barButtonViewReal.Down = true;
}
};
barButtonViewReal.DownChanged += (sender, e) =>
{
if (barButtonViewReal.Down)
{
barButtonViewMove.Down = false;
GeoSigmaLib.KVDLN_ViewReal(VtkVDLNHandle);
}
else
{
barButtonViewMove.Down = true;
}
};
LayerControl = this.treeListLayer;
PropertyControl = this.propertyGridControl;
StatisticControl = this.staticsGridControl;
LayerSelectedStatusNotify3d += (layers, status) =>
{
// 3维图层树操作
treeListLayer.AfterCheckNode -= treeListLayer_AfterCheckNode;
treeListLayer.SuspendLayout();
var layerItems = layers.Split(';').ToList();
var fullNodes = TraverseTreeNode(treeListLayer.Nodes[0]);
var visible = status != LayerStatus.NOT_VIEW_NOT_EDIT;
foreach (var layerItem in fullNodes)
{
if (layerItems.Contains(GetNodeFullPath(layerItem)))
{
layerItem.StateImageIndex = visible ? 1 : 0;
//layerItem.Checked = true;
}
}
treeListLayer.ResumeLayout();
treeListLayer.AfterCheckNode += treeListLayer_AfterCheckNode;
if (update3d)
{
update3d = false;
}
LayerSelectedDrawNotify(status);
};
//string json = JsonConvert.SerializeObject(this.VtkProerty.WellTypeColors, Formatting.Indented);
//File.WriteAllText("WellTypeColor.config", json);
this.VtkProerty.WellTypeColorConfig = LoadWellTypeColors("WellTypeColor.config");
this.VtkProerty.WellTypeColorList.ListChanged += WellTypeColors_ListChanged;
PropertyControl.BestFit();
}
private void WellTypeColors_ListChanged(object sender, ListChangedEventArgs e)
{
if (this.VtkProerty.WellTypeColorsIsInitFlag)
{
UpdateWellTypeColor();
}
}
/// <summary>
/// 从WellTypeColor.config文件加载颜色配置
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public BindingList<WellTypeColorItem> LoadWellTypeColors(string filePath)
{
string startupPath = Application.StartupPath;
string path = Path.Combine(startupPath, filePath);
if (!File.Exists(path))
{
throw new FileNotFoundException("WellTypeColor.config不存在。");
}
string json = File.ReadAllText(path, Encoding.UTF8);
return JsonConvert.DeserializeObject<BindingList<WellTypeColorItem>>(json);
}
/// <summary>
/// Gets or sets the LayerControl
/// 树控件.
/// </summary>
public TreeList LayerControl { get; set; }
/// <summary>
/// Gets or sets the PropertyControl
/// 属性控件.
/// </summary>
public PropertyGridControl PropertyControl { get; set; }
/// <summary>
/// Gets or sets the StatisticControl
/// 统计数据控件.
/// </summary>
public GridControl StatisticControl { get; set; }
/// <summary>
/// Defines the layerPanel.
/// </summary>
private DockPanel layerPanel;
/// <summary>
/// Gets or sets the LayerPanel
/// 图层面板.
/// </summary>
public DockPanel LayerPanel
{
get
{
return layerPanel;
}
set
{
layerPanel = value;
//try
//{
// if (!object.ReferenceEquals(value, dcpLayer))
// {
// if (layerPanel.Parent.Controls.Count == 1)
// {
// Controls.Remove(layerPanel.Parent);
// }
// else
// {
// dockManager1.RemovePanel(layerPanel);
// }
// }
// //else
// //{
// // this.dcpLayer.Visibility = DockVisibility.Visible;
// //}
//}
//finally
//{
//}
}
}
private DockPanel propertyPanel;
/// <summary>
/// Gets or sets the PropertyPanel
/// 属性面板.
/// </summary>
public DockPanel PropertyPanel
{
get
{
return propertyPanel;
}
set
{
propertyPanel = value;
}
}
public RibbonControl RibbonControlMain
{
get
{
return vtkRibbonControl;
}
}
/// <summary>
/// Defines the drawerStatusBar.
/// </summary>
private RibbonStatusBar drawerStatusBar;
/// <summary>
/// Gets or sets the DrawerStatusBar
/// 状态条,显示鼠标位置等提示信息.
/// </summary>
public RibbonStatusBar DrawerStatusBar
{
get
{
return drawerStatusBar;
}
set
{
drawerStatusBar = value;
}
}
/// <summary>
/// Defines the statisticPanel.
/// </summary>
private DockPanel statisticPanel;
/// <summary>
/// Gets or sets the StatisticPanel
/// 统计面板.
/// </summary>
public DockPanel StatisticPanel
{
//get
//{
// return statisticPanel;
//}
//set
//{
// statisticPanel = value;
// if (!object.ReferenceEquals(dcpStatistic, value))
// {
// if (statisticPanel.Parent.Controls.Count == 1)
// {
// Controls.Remove(statisticPanel.Parent);
// }
// else
// {
// dockManager1.RemovePanel(statisticPanel);
// }
// }
// //else
// //{
// // this.dcpStatistic.Visibility = DockVisibility.Visible;
// //}
//}
get
{
return statisticPanel;
}
set
{
statisticPanel = value;
}
}
/// <summary>
/// The MergePanels.
/// </summary>
public void MergePanels()
{
// 状态条
if (DrawerStatusBar != null)
{
DrawerStatusBar.UnMergeStatusBar();
drawerStatusBar.MergeStatusBar(vtkRibbonControl.StatusBar);
}
// 图层树控件的处理
if (LayerControl != null && LayerPanel != null)
{
LayerPanel.ControlContainer.Controls.Clear();
LayerPanel.ControlContainer.Controls.Add(LayerControl);
LayerPanel.Text = "数据";
LayerControl.Dock = DockStyle.Fill;
dockManager1.RemovePanel(this.dcpLayer);
bckiPanelLayer.Checked = LayerPanel.Visibility == DockVisibility.Hidden ||
LayerPanel.Visibility == DockVisibility.AutoHide
? false
: true;
LayerPanel.VisibilityChanged -= LayerPanel_VisibilityChanged;
LayerPanel.VisibilityChanged += LayerPanel_VisibilityChanged;
if (bmLayer.Form != LayerPanel)
{
bmLayer.Form = LayerPanel;
}
}
// 属性控件的处理
if (PropertyPanel != null && PropertyControl != null)
{
PropertyPanel.ControlContainer.Controls.Clear();
PropertyPanel.ControlContainer.Controls.Add(PropertyControl);
PropertyControl.Dock = DockStyle.Fill;
dockManager1.RemovePanel(this.dcpProperty);
}
// 统计面板
if (StatisticControl != null && StatisticPanel != null)
{
StatisticPanel.ControlContainer.Controls.Clear();
StatisticPanel.ControlContainer.Controls.Add(StatisticControl);
StatisticControl.Dock = DockStyle.Fill;
dockManager1.RemovePanel(this.dcpStatistic);
bckiPanelStatistic.Checked = StatisticPanel.Visibility == DockVisibility.Hidden ||
StatisticPanel.Visibility == DockVisibility.AutoHide
? false
: true;
StatisticPanel.VisibilityChanged -= StatisticPanel_VisibilityChanged;
StatisticPanel.VisibilityChanged += StatisticPanel_VisibilityChanged;
}
}
/// <summary>
/// 取消面板合并.
/// </summary>
public void UnMergePanels()
{
DrawerStatusBar?.UnMergeStatusBar();
if (LayerPanel != null)
{
LayerPanel.ControlContainer.Controls.Clear();
LayerPanel.Text = "图层";
}
PropertyPanel?.ControlContainer.Controls.Clear();
statisticPanel?.ControlContainer.Controls.Clear();
}
/// <summary>
/// The LayerPanel_VisibilityChanged.
/// </summary>
/// <param name="sender">The sender<see cref="object"/>.</param>
/// <param name="e">The e<see cref="VisibilityChangedEventArgs"/>.</param>
private void LayerPanel_VisibilityChanged(object sender, VisibilityChangedEventArgs e)
{
SuspendLayout();
// Thread.Sleep(5000);
if (LayerPanel.Visibility == DockVisibility.Hidden)
{
if (bckiPanelLayer.Checked)
{
bckiPanelLayer.Checked = false;
}
}
if (LayerPanel.Visibility == DockVisibility.Visible ||
LayerPanel.Visibility == DockVisibility.AutoHide)
{
if (bckiPanelLayer.Checked == false)
{
bckiPanelLayer.Checked = true;
}
}
ResumeLayout();
}
/// <summary>
/// The StatisticPanel_VisibilityChanged.
/// </summary>
/// <param name="sender">The sender<see cref="object"/>.</param>
/// <param name="e">The e<see cref="VisibilityChangedEventArgs"/>.</param>
private void StatisticPanel_VisibilityChanged(object sender, VisibilityChangedEventArgs e)
{
if (StatisticPanel.Visibility == DockVisibility.Hidden)
{
if (bckiPanelStatistic.Checked)
{
bckiPanelStatistic.Checked = false;
}
}
if (StatisticPanel.Visibility == DockVisibility.Visible ||
StatisticPanel.Visibility == DockVisibility.AutoHide)
{
if (bckiPanelStatistic.Checked == false)
{
bckiPanelStatistic.Checked = true;
}
}
}
/// <summary>
/// Gets or sets a value indicating whether StatisticPanelVisible
/// get/set 统计面板的可见性.
/// </summary>
public bool StatisticPanelVisible
{
get
{
return StatisticPanel.Visibility == DockVisibility.Visible;
}
set
{
try
{
StatisticPanel.Visibility = value == true ? DockVisibility.Visible : DockVisibility.Hidden;
}
catch
{
}
}
}
/// <summary>
/// Gets or sets a value indicating whether LayerPanelVisible
/// get/set 图层面板可见性.
/// </summary>
public bool LayerPanelVisible
{
get
{
return LayerPanel.Visibility == DockVisibility.Visible;
}
set
{
try
{
LayerPanel.Visibility = value == true ? DockVisibility.Visible : DockVisibility.Hidden;
}
catch
{
}
}
}
/// <summary>
/// Gets or sets a value indicating whether PropertyPanelVisible
/// get/set 属性面板可见性.
/// </summary>
public bool PropertyPanelVisible
{
get
{
return PropertyPanel.Visibility == DockVisibility.Visible;
}
set
{
try
{
if (value == true)
{
PropertyPanel.Visibility = DockVisibility.Visible;
if (bckiPanelProperty.Checked != true)
{
bckiPanelProperty.Checked = true;
}
}
else
{
PropertyPanel.Visibility = DockVisibility.Hidden;
if (bckiPanelProperty.Checked == true)
{
bckiPanelProperty.Checked = false;
}
}
}
catch
{
}
}
}
/// <summary>
/// Gets or sets a value indicating whether StatusBarVisible
/// Gets or sets 状态条是否可见..
/// </summary>
public bool StatusBarVisible
{
get
{
return ribbonStatusBar.Visible;
}
set
{
ribbonStatusBar.Visible = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether ViewGroupVisible
/// 视图工具组是否可见.
/// </summary>
public bool ViewGroupVisible
{
get
{
return vtkRgpViews.Visible;
}
set
{
vtkRgpViews.Visible = value;
}
}
/// <summary>
/// 图层面板是否显示.
/// </summary>
/// <param name="sender">图层控制按钮.</param>
/// <param name="e">选中事件.</param>
private void bckiPanelLayer_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
LayerPanelVisible = bckiPanelLayer.Checked;
}
/// <summary>
/// 统计面板是否显示.
/// </summary>
/// <param name="sender">事件按钮.</param>
/// <param name="e">事件参数.</param>
private void bckiPanelStatistic_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
StatisticPanelVisible = bckiPanelStatistic.Checked;
}
/// <summary>
/// 获取vtk显示窗口的句柄
/// </summary>
/// <returns>IntPtr</returns>
public IntPtr GetVtkPanelHandle()
{
IntPtr panelHandle = this.vtkPanelControl.Handle;
return panelHandle;
}
/// <summary>
/// Gets or sets the VTK handle.
/// </summary>
/// <value>
/// The VTK handle.
/// </value>
public int VtkVDLNHandle { get; set; }
/// <summary>
/// Gets or sets the VTK handle.
/// </summary>
/// <value>
/// The VTK handle.
/// </value>
public int VtkVMSHandle { get; set; }
/// <summary>
/// Gets or sets the file path.
/// </summary>
/// <value>
/// The file path.
/// </value>
public string FilePath { get; set; }
/// <summary>
/// 显示XYZ数据
/// </summary>
/// <param name="filePath">filePath</param>
public void ShowXyzData(string filePath)
{
this.FilePath = filePath;
// 获取Panel控件的句柄
VtkVMSHandle = GeoSigmaLib.KVMS_Init();
GeoSigmaLib.KVMS_ParseXyzFile(VtkVMSHandle, FilePath);
//KVMS_ParseXyzFile(handle, "E:/data/xyz/small/small.xyz");
GeoSigmaLib.KVMS_CreateVtkImageData(VtkVMSHandle, 13, 13);
GeoSigmaLib.KVMS_CreateVtkLookupTable(VtkVMSHandle);
GeoSigmaLib.KVMS_MarchingSquares(VtkVMSHandle);
GeoSigmaLib.KVMS_SetParentWndId(VtkVMSHandle, vtkPanelControl.Handle);
GeoSigmaLib.KVMS_SetWndSize(VtkVMSHandle, vtkPanelControl.Width, vtkPanelControl.Height);
GeoSigmaLib.KVMS_RenderVtkIamgeData(VtkVMSHandle);
//GeoSigmaLib.KVMS_ExportImageDataToPNG(handle, "e:/xyz.png");
GeoSigmaLib.KVMS_RenderRegionalBoundaryLine(VtkVMSHandle);
OnVtkShowEvent(EventArgs.Empty);
GeoSigmaLib.KVMS_StartInteractor(VtkVMSHandle);
//Thread thread = new Thread(new ThreadStart(ShowXyz));
//thread.Start();
}
/// <summary>
/// Gets or sets the pxy.
/// </summary>
/// <value>
/// The pxy.
/// </value>
public IntPtr pMeshInfo { get; set; }
/// <summary>
/// Shows the mesh.
/// </summary>
/// <param name="filePath">filePath</param>
/// <param name="pMeshInfo">The Mesh Info.</param>
public void ShowMesh(string filePath, IntPtr pMeshInfo)
{
//运行计时
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
this.FilePath = filePath;
this.pMeshInfo = pMeshInfo;
VtkVDLNHandle = GeoSigmaLib.KVDLN_Init();
//GeoSigmaLib.KVDLN_ParseXyzFile(VtkVDLNHandle, "E:/data/xyz/k1.xyz");
//GeoSigmaLib.KVDLN_ParseMesh(VtkVDLNHandle, this.FilePath, this.pMeshInfo);
//GeoSigmaLib.KVDLN_PCLParseMesh(VtkVDLNHandle, this.FilePath, this.pMeshInfo);
GeoSigmaLib.KVDLN_SimpleTriangles(VtkVDLNHandle, this.FilePath, this.pMeshInfo);
GeoSigmaLib.KVDLN_SimpleTrianglesRender(VtkVDLNHandle);
//GeoSigmaLib.KVDLN_Delaunay2D(VtkVDLNHandle);
//GeoSigmaLib.KVDLN_PCLVtkRender(VtkVDLNHandle);
GeoSigmaLib.KVDLN_SetParentWndId(VtkVDLNHandle, vtkPanelControl.Handle);
GeoSigmaLib.KVDLN_SetWndSize(VtkVDLNHandle, vtkPanelControl.Width, vtkPanelControl.Height);
//OnVtkShowEvent(EventArgs.Empty);
GeoSigmaLib.KVDLN_StartInteractor(VtkVDLNHandle);
//运行计时
stopwatch.Stop();
Console.WriteLine("代码运行时间:" + stopwatch.ElapsedMilliseconds + " 毫秒");
//Thread thread = new Thread(new ThreadStart(ShowMeshThread));
//thread.Start();
}
private void ShowMeshThread()
{
if (vtkPanelControl.InvokeRequired)
{
vtkPanelControl.Invoke(new MethodInvoker(delegate
{
VtkVDLNHandle = GeoSigmaLib.KVDLN_Init();
//GeoSigmaLib.KVDLN_ParseXyzFile(VtkVDLNHandle, "E:/data/xyz/k1.xyz");
GeoSigmaLib.KVDLN_ParseMesh(VtkVDLNHandle, this.FilePath, this.pMeshInfo);
GeoSigmaLib.KVDLN_Delaunay2D(VtkVDLNHandle);
GeoSigmaLib.KVDLN_Render(VtkVDLNHandle);
GeoSigmaLib.KVDLN_SetParentWndId
(VtkVDLNHandle, vtkPanelControl.Handle);
GeoSigmaLib.KVDLN_SetWndSize(VtkVDLNHandle, vtkPanelControl.Width, vtkPanelControl.Height);
OnVtkShowEvent(EventArgs.Empty);
GeoSigmaLib.KVDLN_StartInteractor(VtkVDLNHandle);
}));
}
}
private void ShowXyz()
{
//只能在非UI线程中启动VTK的交互显示
if (vtkPanelControl.InvokeRequired)
{
vtkPanelControl.Invoke(new MethodInvoker(delegate
{ // 获取Panel控件的句柄
VtkVMSHandle = GeoSigmaLib.KVMS_Init();
GeoSigmaLib.KVMS_ParseXyzFile(VtkVMSHandle, FilePath);
//KVMS_ParseXyzFile(handle, "E:/data/xyz/small/small.xyz");
GeoSigmaLib.KVMS_CreateVtkImageData(VtkVMSHandle, 13, 13);
GeoSigmaLib.KVMS_CreateVtkLookupTable(VtkVMSHandle);
GeoSigmaLib.KVMS_MarchingSquares(VtkVMSHandle);
GeoSigmaLib.KVMS_SetParentWndId(VtkVMSHandle, vtkPanelControl.Handle);
GeoSigmaLib.KVMS_SetWndSize(VtkVMSHandle, vtkPanelControl.Width, vtkPanelControl.Height);
GeoSigmaLib.KVMS_RenderVtkIamgeData(VtkVMSHandle);
//GeoSigmaLib.KVMS_ExportImageDataToPNG(handle, "e:/xyz.png");
GeoSigmaLib.KVMS_RenderRegionalBoundaryLine(VtkVMSHandle);
OnVtkShowEvent(EventArgs.Empty);
GeoSigmaLib.KVMS_StartInteractor(VtkVMSHandle);
}));
}
}
/// <summary>
/// 触发事件的方法
/// </summary>
/// <param name="e">e</param>
protected virtual void OnVtkShowEvent(EventArgs e)
{
if (VtkShowEventHandler != null)
{
foreach (EventHandler handler in VtkShowEventHandler.GetInvocationList())
{
handler.BeginInvoke(this, e, null, null);
}
}
}
private void vtkPanelControl_Resize(object sender, EventArgs e)
{
//只能在非UI线程中启动VTK的交互显示
if (vtkPanelControl.InvokeRequired)
{
vtkPanelControl.Invoke(new MethodInvoker(delegate
{
//GeoSigmaLib.KVMS_SetWndSize(VtkVMSHandle, vtkPanelControl.Width, vtkPanelControl.Height);
GeoSigmaLib.KVDLN_SetWndSize(VtkVDLNHandle, vtkPanelControl.Width, vtkPanelControl.Height);
}));
}
else
{
//GeoSigmaLib.KVMS_SetWndSize(VtkVMSHandle, vtkPanelControl.Width, vtkPanelControl.Height);
GeoSigmaLib.KVDLN_SetWndSize(VtkVDLNHandle, vtkPanelControl.Width, vtkPanelControl.Height);
}
}
private void barButtonViewZoomin_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
GeoSigmaLib.KVDLN_ViewZoomin(VtkVDLNHandle);
}
private void barButtonViewZoomout_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
GeoSigmaLib.KVDLN_ViewZoomout(VtkVDLNHandle);
}
private void barButtonResetView_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
GeoSigmaLib.KVDLN_ViewReset(VtkVDLNHandle);
}
private void barButtonViewMove_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
this.Cursor = Cursors.Hand;
if (barButtonViewMove.Down)
{
GeoSigmaLib.KVDLN_ViewPan(VtkVDLNHandle);
// 按钮被按下时的操作
barButtonViewReal.Down = false;
}
else
{
barButtonViewReal.Down = true;
// 按钮弹起时的操作
}
}
private void barButtonViewReal_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
this.Cursor = Cursors.Default;
GeoSigmaLib.KVDLN_ViewReal(VtkVDLNHandle);
}
// 属性值变化事件处理程序
private void OnPropertyValueChanged(object sender, PropertyValueChangedEventArgs e)
{
// 获取属性名和新的属性值
string propertyName = e.ChangedItem.PropertyDescriptor.Name;
object newValue = e.ChangedItem.Value;
// 根据属性名和属性值更新对象的状态
if (propertyName == "Color")
{
// 更新对象的颜色属性
//myObject.Color = (Color)newValue;
}
else if (propertyName == "Opacity")
{
// 更新对象的透明度属性
//myObject.Opacity = (double)newValue;
// 执行其他相关操作
// ...
}
// 其他属性的处理
}
private void treeListLayer_AfterCheckNode(object sender, NodeEventArgs e)
{
List<TreeListNode> subNodes = TraverseTreeNode(e.Node).ToList();
if (subNodes.Count == 0)
{
subNodes.Add(e.Node);
}
if (sender is TreeList)
{
foreach (var node in subNodes)
{
node.Checked = e.Node.Checked;
}
}
}
/// <summary>
/// 3维绘图通知
/// </summary>
/// <param name="status">status</param>
public void LayerSelectedDrawNotify(LayerStatus status)
{
var shownNodes = TraverseTreeView(treeListLayer).Where(n => n.Checked);
if (shownNodes.Count() == 0)
{
return;
}
var visible = status != LayerStatus.NOT_VIEW_NOT_EDIT;
foreach (var subNode in shownNodes)
{
string nodeName = subNode.GetValue("Name").ToString();
if (nodeName == treeRootLayerText)
{
continue;
}
// 获取当前发生变化的节点
VtkTreeListNodeData data = (VtkTreeListNodeData)this.treeListLayer.GetDataRecordByNode(subNode);
this.DrawViewer.SetVtkDataNodeChecked(data.Data, visible);
GeoSigmaLib.KVDLN_ShowDataNode(VtkVDLNHandle, data.Data);
if (nodeName == "网格")
{
GeoSigmaLib.KVDLN_ShowMesh(VtkVDLNHandle, visible);
}
if (nodeName == "等值线")
{
GeoSigmaLib.KVDLN_ShowContour(VtkVDLNHandle, visible);
}
if (nodeName == "网格")
{
GeoSigmaLib.KVDLN_ShowMesh(VtkVDLNHandle, visible);
}
if (nodeName == "等值线")
{
GeoSigmaLib.KVDLN_ShowContour(VtkVDLNHandle, visible);
}
}
}
/// <summary>
/// 更新三维
/// </summary>
private bool update3d = false;
private void tsbViewEdit_ItemClick(object sender, ItemClickEventArgs e)
{
update3d = true;
var checkedNodes = TraverseTreeView(treeListLayer).Where(n => n.Checked);
foreach (var layerItem in checkedNodes)
{
if (layerItem.GetDisplayText(0) == treeRootLayerText)
{
continue;
}
layerItem.StateImageIndex = 1;
}
var shownNodes = TraverseTreeView(treeListLayer).Where(n => n.Checked && n.GetDisplayText(0) != treeRootLayerText);
var nodes = shownNodes.Select(n => GetNodeFullPath(n).Replace("二维图层\\", string.Empty)).ToList();
var syncNodes = string.Join(";", nodes);
this.DrawEdit?.LayerSelectedNotify2dWithStatus?.Invoke(syncNodes, LayerStatus.VIEW_EDIT);
}
private string treeRootLayerText = "二维图层";
private void tsbNotViewNotEdit_ItemClick(object sender, ItemClickEventArgs e)
{
update3d = true;
var checkedNodes = TraverseTreeView(treeListLayer).Where(n => n.Checked);
foreach (var layerItem in checkedNodes)
{
if (layerItem.GetDisplayText(0) == treeRootLayerText)
{
continue;
}
layerItem.StateImageIndex = 0;
}
var shownNodes = TraverseTreeView(treeListLayer).Where(n => n.Checked && n.GetDisplayText(0) != treeRootLayerText);
var nodes = shownNodes.Select(n => GetNodeFullPath(n).Replace("二维图层\\", string.Empty)).ToList();
var syncNodes = string.Join(";", nodes);
this.DrawEdit?.LayerSelectedNotify2dWithStatus?.Invoke(syncNodes, LayerStatus.NOT_VIEW_NOT_EDIT);
}
private void propertyGridControl_CellValueChanged(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
{
// 获取属性名称和新的值
string fieldName = e.Row.Properties.FieldName;
if (fieldName == nameof(VtkProerty.BackgroundColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetBackgroundColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B, newValue.A);
}
else if (fieldName == nameof(VtkProerty.MeshEdgeColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetMeshEdgeColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B, newValue.A);
}
else if (fieldName == nameof(VtkProerty.ShowCoordinateGrid))
{
GeoSigmaLib.KVDLN_ShowAxes(VtkVDLNHandle, (bool)e.Value);
}
else if (fieldName == nameof(VtkProerty.ShowMeshEdgeColorGradient))
{
GeoSigmaLib.KVDLN_ShowMeshEdgeColorGradient(VtkVDLNHandle, (bool)e.Value);
}
else if (fieldName == nameof(VtkProerty.ShowCoordinateGridLine))
{
GeoSigmaLib.KVDLN_ShowCoordinateGridLine(VtkVDLNHandle, (bool)e.Value);
}
else if (fieldName == nameof(VtkProerty.ShowScalarBar))
{
GeoSigmaLib.KVDLN_ShowScalarBar(VtkVDLNHandle, (bool)e.Value);
}
else if (fieldName == nameof(VtkProerty.SingularValueFilterFlag))
{
GeoSigmaLib.KVDLN_SetSingularValueFilterFlag(VtkVDLNHandle, (bool)e.Value);
this.DrawEdit?.RefreshVtkImage();
}
else if (fieldName == nameof(VtkProerty.SingularThreshold))
{
int newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetSingularThreshold(VtkVDLNHandle, newValue);
this.DrawEdit?.RefreshVtkImage();
}
else if (fieldName == nameof(VtkProerty.WellMode))
{
int newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetWellMode(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.FaultMode))
{
int newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetFaultMode(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.WellColumnHeight))
{
double newValue = Convert.ToDouble(e.Value);
GeoSigmaLib.KVDLN_SetWellColumnHeight(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.WellColumnThrough))
{
bool newValue = Convert.ToBoolean(e.Value);
GeoSigmaLib.KVDLN_SetWellColumnThrough(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.WellColumnRadius))
{
double newValue = Convert.ToDouble(e.Value);
GeoSigmaLib.KVDLN_SetWellColumnRadius(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.WellSymbolRadius))
{
double newValue = Convert.ToDouble(e.Value);
GeoSigmaLib.KVDLN_SetWellSymbolRadius(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.WellColumnNameSize))
{
int newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetWellColumnNameSize(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.WellColumnNameGap))
{
int newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetWellColumnNameGap(VtkVDLNHandle, newValue);
}
else if (fieldName.Contains("WellTypeColorList"))
{
// 序列化为 JSON 字符串
//string json = JsonConvert.SerializeObject(VtkProerty.WellTypeColors, Formatting.None);
UpdateWellTypeColor();
}
if (fieldName == nameof(VtkProerty.WellColumnColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetWellColumnColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B, newValue.A);
}
if (fieldName == nameof(VtkProerty.WellColumnNameColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetWellColumnNameColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B, newValue.A);
}
else if (fieldName == nameof(VtkProerty.Thickness))
{
double newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetLinearExtrusionValue(VtkVDLNHandle, newValue);
}
//else if (fieldName == nameof(VtkProerty.LineWidth))
//{
// double newValue = Convert.ToInt32(e.Value);
// //GeoSigmaLib.KVDLN_SetLinearExtrusionValue(VtkVDLNHandle, newValue);
//}else if (fieldName == nameof(VtkProerty.LineColor))
//{
// Color newValue = (Color)e.Value;
// GeoSigmaLib.KVDLN_SetLightDColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B);
//}
//else if (fieldName == nameof(VtkProerty.WellRadius))
//{
// double newValue = Convert.ToInt32(e.Value);
// GeoSigmaLib.KVDLN_SetLinearExtrusionValue(VtkVDLNHandle, newValue);
//}
else if (fieldName == nameof(VtkProerty.CameraHAngle))
{
//角度值-90 到 90
double newValue = Convert.ToInt32(e.Value);
//newValue = (newValue * Math.PI) / 180;
GeoSigmaLib.KVDLN_SetCAzimuth(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.CameraVAngle))
{
//角度值0 到 360
double newValue = Convert.ToInt32(e.Value);
//newValue = (newValue * Math.PI) / 180;
GeoSigmaLib.KVDLN_SetCElevation(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.LightAzimuth))
{
//角度值-90 到 90
double newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetLAzimuth(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.LightElevation))
{
//角度值0 到 360
double newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetLElevation(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.LightAmbientColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetLightAmbientColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B);
}
else if (fieldName == nameof(VtkProerty.LightDiffusedCorlor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetLightDiffusedCorlor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B);
}
else if (fieldName == nameof(VtkProerty.LightSpecularColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetLightSpecularColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B);
}
else if (fieldName == nameof(VtkProerty.ActorAmbientColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 1, newValue.R, newValue.G, newValue.B, 1);
}
else if (fieldName == nameof(VtkProerty.ActorDiffusedColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 2, newValue.R, newValue.G, newValue.B, 1);
}
else if (fieldName == nameof(VtkProerty.ActorSpecularColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 3, newValue.R, newValue.G, newValue.B, 1);
}
else if (fieldName == nameof(VtkProerty.ActorAmbient))
{
double newValue = Convert.ToInt32(e.Value);
newValue /= 100.0;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 4, 255, 255, 255, newValue);
}
else if (fieldName == nameof(VtkProerty.ActorDiffused))
{
double newValue = Convert.ToInt32(e.Value);
newValue /= 100.0;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 5, 255, 255, 255, newValue);
}
else if (fieldName == nameof(VtkProerty.ActorSpecular))
{
double newValue = Convert.ToInt32(e.Value);
newValue /= 100.0;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 6, 255, 255, 255, newValue);
}
else if (fieldName == nameof(VtkProerty.ZScale))
{
double newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetZScale(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.ZMaxScale))
{
double newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetZMaxScale(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.LightMode))
{
var ro = (LightModeEnum)e.Value == LightModeEnum.;
PropertyHelp.SetPropertyReadOnly(this.propertyGridControl.SelectedObject, nameof(VtkProerty.LightAzimuth), ro);
PropertyHelp.SetPropertyReadOnly(this.propertyGridControl.SelectedObject, nameof(VtkProerty.LightElevation), ro);
GeoSigmaLib.KVDLN_SetLightMode(VtkVDLNHandle, e.Value.GetHashCode());
}
else if (fieldName == nameof(VtkProerty.MeshEdgeMode))
{
GeoSigmaLib.KVDLN_SetMeshEdgeMode(VtkVDLNHandle, (int)e.Value);
}
else if (fieldName == nameof(VtkProerty.LightIntensity))
{
double newValue = Convert.ToDouble(e.Value);
newValue /= 100.0;
GeoSigmaLib.KVDLN_SetLightIntensity(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.LightColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetLightColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B);
}
else if (fieldName == nameof(VtkProerty.ShowMeshEdge))
{
GeoSigmaLib.KVDLN_ShowLinearExtrusion(VtkVDLNHandle, (bool)e.Value);
}
else if (fieldName == nameof(VtkProerty.LineWidth))
{
int newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetLineWidth(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.LineColor))
{
Color newValue = (Color)e.Value;
this.propertyGridControl.ActiveEditor.BackColor = newValue;
GeoSigmaLib.KVDLN_SetLineColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B, newValue.G);
}
else if (fieldName == nameof(VtkProerty.WellRadius))
{
double newValue = Convert.ToInt32(e.Value);
GeoSigmaLib.KVDLN_SetWellRadius(VtkVDLNHandle, newValue);
}
else if (fieldName == nameof(VtkProerty.GridColorItems))
{
int num = VtkProerty.GridColorItems.Count;
if (num > 0)
{
IntPtr pColorArray = GeoSigmaLib.KVDLN_CreatMeshColorArray(VtkVDLNHandle, num);
for (int i = 0; i < num; i++)
{
GeoSigma.SigmaDrawerUtil.GradientColorItem item = VtkProerty.GridColorItems[i];
bool gradient = (item.Smooth == GeoSigma.SigmaDrawerUtil.GradientColorItem.SmoothMode.M);
GeoSigmaLib.KVDLN_SetMeshColorItem(VtkVDLNHandle, pColorArray, i, gradient, item.Z, item.R, item.G, item.B, item.T);
}
GeoSigmaLib.KVDLN_SetMeshColor(VtkVDLNHandle, pColorArray, num);
}
}
this.propertyGridControl.Refresh();
}
public DrawViewer DrawViewer { get; set; }
/// <summary>
/// Initializes the tree list.
/// </summary>
/// <param name="vea">The <see cref="ShowVtkEventArgs"/> instance containing the event data.</param>
public void InitTreeList(ShowVtkEventArgs vea)
{
this.DrawViewer = ShowVtkEventArgs.DrawViewer;
this.treeListLayer.DataSource = vea.TreeDataSource;
this.treeListLayer.StateImageList = this.layerImg;
this.treeListLayer.ChildListFieldName = "Childs";
this.treeListLayer.CheckBoxFieldName = "IsChecked";
this.treeListLayer.ExpandAll();
var nodes = TraverseTreeView(LayerControl);
foreach (var node in nodes)
{
if (node.GetDisplayText(0) == treeRootLayerText)
{
node.StateImageIndex = 1;
}
else
{
var data = (VtkTreeListNodeData)this.treeListLayer.GetDataRecordByNode(node);
node.StateImageIndex = data.Visibility ? 1 : 0;
}
}
}
/// <summary>
/// 设置主网格
/// </summary>
/// <param name="pMeshData">pMeshData</param>
public void SetMainMesh(IntPtr pMeshData)
{
this.VtkMainMesh = pMeshData;
}
/// <summary>
/// Gets or sets the main mesh property.
/// </summary>
/// <value>
/// The main mesh property.
/// </value>
public DrawerElementProperty MainMeshProperty { get; set; }
/// <summary>
/// Sets the main mesh property.
/// </summary>
/// <param name="meshProperty">The mesh property.</param>
public void SetMainMeshProperty(DrawerElementProperty meshProperty)
{
if (meshProperty != null && meshProperty.Element is DrawerSurface surface)
{
MainMeshProperty = meshProperty;
this.VtkProerty.GridColorItems = surface?.Items;
this.VtkProerty.RangeZ = surface?.RulerRangeZ;
}
}
/// <summary>
/// 主网格
/// </summary>
public IntPtr VtkMainMesh { get; set; } = IntPtr.Zero;
/// <summary>
/// 显示三维元素
/// </summary>
/// <param name="filePath">三维图全路径</param>
public void ShowDrawData(string filePath)
{
//运行计时
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
this.FilePath = filePath;
this.pMeshInfo = pMeshInfo;
//初始化vtk组件
VtkVDLNHandle = GeoSigmaLib.KVDLN_Init();
GeoSigmaLib.KVDLN_SetMainMesh(VtkVDLNHandle, VtkMainMesh);
//初始化场景
GeoSigmaLib.KVDLN_InitScence(VtkVDLNHandle, vtkPanelControl.Handle, vtkPanelControl.Width, vtkPanelControl.Height);
//设置井别颜色
foreach (WellTypeColorItem item in this.VtkProerty.WellTypeColorList)
{
GeoSigmaLib.KVDLN_SetWellTypeColor(VtkVDLNHandle,item.Type, item.Value.R, item.Value.G, item.Value.B);
}
//显示数据
VtkTreeListNodeData data = (VtkTreeListNodeData)this.treeListLayer.GetDataRecordByNode(this.treeListLayer.Nodes[0]);
GeoSigmaLib.KVDLN_ShowData(VtkVDLNHandle, data.Data);
bShownVtkForm = true;
//运行计时
stopwatch.Stop();
Console.WriteLine("ShowDrawData 代码运行时间:" + stopwatch.ElapsedMilliseconds + " 毫秒");
}
/// <summary>
/// 更新井类别颜色
/// </summary>
public void UpdateWellTypeColor()
{
//设置井别颜色
foreach (WellTypeColorItem item in this.VtkProerty.WellTypeColorList)
{
GeoSigmaLib.KVDLN_SetWellTypeColor(VtkVDLNHandle, item.Type, item.Value.R, item.Value.G, item.Value.B);
}
GeoSigmaLib.KVDLN_UpdateWellTypeColor(VtkVDLNHandle);
}
/// <summary>
/// Gets the main mesh data.
/// </summary>
/// <returns>IntPtr</returns>
public IntPtr GetMainMeshData()
{
return GeoSigmaLib.KVDLN_GetMainMesh(VtkVDLNHandle);
}
/// <summary>
/// Gets the main mesh information.
/// </summary>
/// <param name="pMesh">The p mesh.</param>
/// <param name="mask">The mask.</param>
/// <returns>double</returns>
public double GetMainMeshInfo(IntPtr pMesh, int mask)
{
return GeoSigmaLib.KVDLN_GetMainMeshInfo(VtkVDLNHandle, pMesh, mask);
}
/// <summary>
/// Sets the main image.
/// </summary>
/// <param name="filePath">The file path.</param>
/// <param name="x0">The x0.</param>
/// <param name="y0">The y0.</param>
/// <param name="w">The w.</param>
/// <param name="h">The h.</param>
public void SetMainImage(string filePath, double x0, double y0, double w, double h)
{
GeoSigmaLib.KVDLN_SetMainIamge(VtkVDLNHandle, filePath, x0, y0, w, h);
}
/// <summary>
/// Updates the mesh bitmap.
/// </summary>
/// <param name="hBitmap">The h bitmap.</param>
/// <param name="x0">The x0.</param>
/// <param name="y0">The y0.</param>
/// <param name="w">The w.</param>
/// <param name="h">The h.</param>
public void UpdateMeshBitmap(IntPtr hBitmap, double x0, double y0, double w, double h)
{
GeoSigmaLib.KVDLN_UpdateMeshBitmap(VtkVDLNHandle, hBitmap, x0, y0, w, h);
}
/// <summary>
/// Gets the scene parameter.
/// </summary>
/// <returns>IntPtr</returns>
public IntPtr GetSceneParameter()
{
return GeoSigmaLib.KVDLN_GetSceneParameter(VtkVDLNHandle);
}
/// <summary>
/// Sets the scene parameter.
/// </summary>
/// <param name="pSceneParameter">The p scene parameter.</param>
public void SetSceneParameter(IntPtr pSceneParameter)
{
GeoSigmaLib.KVDLN_SetSceneParameter(VtkVDLNHandle, pSceneParameter);
}
private void RefreshLayerPanel()
{
if (this.bShownVtkForm)
{
LayerPanel.SuspendLayout(); // 强制刷新图层Panel
LayerPanel.Visibility = DockVisibility.Hidden;
LayerPanel.Visibility = DockVisibility.Visible;
LayerPanel.ResumeLayout();
}
}
/// <summary>
/// AfterDocumentActived
/// </summary>
/// <param name="sender">sender</param>
/// <param name="docArgs">docArgs</param>
public void AfterDocumentActived(object sender, DocumentEventArgs docArgs)
{
if (sender is DrawerTabbedView tabbedView)
{
foreach (var document in tabbedView.Documents)
{
if (document.Control is UCVtkEdit vtkEdit)
{
vtkEdit.barLayerOp.Visible = false;
}
}
if (docArgs.Document.Control is UCVtkEdit vEdit)
{
vEdit.barLayerOp.Visible = true;
vEdit.RefreshLayerPanel();
}
}
}
/// <summary>
/// 遍历节点
/// </summary>
/// <param name="node">node</param>
/// <returns>bool</returns>
public bool TraversalNode(TreeListNode node)
{
VtkTreeListNodeData data = (VtkTreeListNodeData)this.treeListLayer.GetDataRecordByNode(node);
if (data.Data != IntPtr.Zero)
{
GeoSigmaLib.KVDLN_ShowData(VtkVDLNHandle, data.Data);
return true;
}
else
{
foreach (TreeListNode nodeItem in node.Nodes)
{
VtkTreeListNodeData childData = (VtkTreeListNodeData)this.treeListLayer.GetDataRecordByNode(nodeItem);
if (childData.Data != IntPtr.Zero)
{
GeoSigmaLib.KVDLN_ShowData(VtkVDLNHandle, childData.Data);
return true;
}
else
{
return TraversalNode(nodeItem);
}
}
return false;
}
}
/// <summary>
/// 设置行的限制值范围
/// </summary>
/// <param name="row">row</param>
protected void SetupRowValueRange(PGridNumericEditorRow row)
{
row.ShowTrackBar = true;
row.IgnoreMinMaxForSpinEdit = false;
switch (row.Properties.FieldName)
{
case nameof(VtkProerty.ZScale):
row.MinValue = 1;
row.MaxValue = 1000;
break;
case nameof(VtkProerty.WellColumnHeight):
case nameof(VtkProerty.WellColumnRadius):
case nameof(VtkProerty.WellSymbolRadius):
case nameof(VtkProerty.WellColumnNameSize):
case nameof(VtkProerty.WellColumnNameGap):
case nameof(VtkProerty.ZMaxScale):
row.ShowTrackBar = false;
break;
case nameof(VtkProerty.SingularThreshold):
row.MinValue = 0;
row.MaxValue = 90;
row.ShowTrackBar = false;
break;
case nameof(VtkProerty.CameraHAngle):
case nameof(VtkProerty.CameraVAngle):
case nameof(VtkProerty.LightElevation):
1 month ago
row.MinValue = -360;
1 month ago
row.MaxValue = 360;
break;
case nameof(VtkProerty.LightAzimuth):
1 month ago
row.MinValue = -360;
1 month ago
row.MaxValue = 360;
break;
case nameof(VtkProerty.Thickness):
row.ShowTrackBar = false;
row.MinValue = 1;
row.MaxValue = 1000;
break;
case nameof(VtkProerty.LineWidth):
case nameof(VtkProerty.WellRadius):
row.ShowTrackBar = false;
break;
case nameof(VtkProerty.LightIntensity):
case nameof(VtkProerty.ActorAmbient):
case nameof(VtkProerty.ActorDiffused):
case nameof(VtkProerty.ActorSpecular):
{
row.MaxValue = 100;
row.MinValue = 0;
row.ShowTrackBar = true;
}
break;
}
}
private void propertyGridControl_CustomRowCreated(object sender, DevExpress.XtraVerticalGrid.Events.CustomRowCreatedEventArgs e)
{
if (e.Row is PGridNumericEditorRow numericEditor)
{
SetupRowValueRange(numericEditor);
}
}
private void propertyGridControl_CustomPropertyDescriptors(object sender, DevExpress.XtraVerticalGrid.Events.CustomPropertyDescriptorsEventArgs e)
{
}
private void propertyGridControl_CustomRecordCellEdit(object sender, DevExpress.XtraVerticalGrid.Events.GetCustomRowCellEditEventArgs e)
{
}
private void barButtonShot_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
FrmImageExport dialog = new FrmImageExport();
string filePath = string.Empty;
int scale = 1;
int type = 0;
bool bSaveFile = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
filePath = dialog.ImageFilePath;
scale = dialog.ImageScale;
type = 0;
if (dialog.ImageFormat == "png")
{
type = 0;
}
if (dialog.ImageFormat == "jpeg")
{
type = 1;
}
bSaveFile = true;
}
if(bSaveFile)
{
splashScreenManager1.ShowWaitForm();
splashScreenManager1.SetWaitFormDescription("正在导出图像...");
try
{
GeoSigmaLib.KVDLN_SaveImageFile(VtkVDLNHandle, filePath, scale, type);
}
catch
{
MessageBox.Show("图像过大,无法生成!");
}
splashScreenManager1.CloseWaitForm();
}
}
private void barButtonOpen_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
}
private void barButtonSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
}
private void bbtnCheckAll_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var bCheck = this.bbtnCheckAll.Checked;
var rootNode = this.treeListLayer.Nodes.FirstNode;
if (rootNode == null)
{
return;
}
var nodes = TraverseTreeNode(rootNode);
this.treeListLayer.SuspendLayout();
rootNode.Checked = bCheck;
foreach (var node in nodes)
{
node.Checked = bCheck;
}
treeListLayer_AfterCheckNode(this, new NodeEventArgs(rootNode));
this.treeListLayer.ResumeLayout();
}
private void bbtnCheckReverseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var rootNode = this.treeListLayer.Nodes.FirstNode;
if (rootNode == null)
{
return;
}
var nodes = TraverseTreeNode(rootNode);
this.treeListLayer.SuspendLayout();
rootNode.Checked = !rootNode.Checked;
foreach (var node in nodes)
{
node.Checked = !node.Checked;
}
treeListLayer_AfterCheckNode(this, new NodeEventArgs(rootNode));
this.treeListLayer.ResumeLayout();
}
#region 树遍历
/// <summary>
/// 遍历树所有节点
/// </summary>
/// <param name="treeView">要遍历的树</param>
/// <returns>IEnumerable</returns>
public static IEnumerable<TreeListNode> TraverseTreeView(TreeList treeView)
{
foreach (TreeListNode node in treeView.Nodes)
{
yield return node; // 返回当前节点
foreach (TreeListNode childNode in TraverseTreeNode(node))
{
yield return childNode; // 返回子节点
}
}
}
/// <summary>
/// 遍历 TreeNode 所有子孙节点,注意:这个函数不会返回当前节点本身
/// </summary>
/// <param name="node">树节点</param>
/// <returns>IEnumerable</returns>
public static IEnumerable<TreeListNode> TraverseTreeNode(TreeListNode node)
{
foreach (TreeListNode childNode in node.Nodes)
{
yield return childNode; // 返回当前子节点
foreach (TreeListNode grandchildNode in TraverseTreeNode(childNode))
{
yield return grandchildNode; // 返回孙子节点
}
}
}
/// <summary>
/// 获取Dev树节点全路径
/// </summary>
/// <param name="node">node</param>
/// <returns>string</returns>
public static string GetNodeFullPath(TreeListNode node)
{
if (node == null)
{
return string.Empty;
}
var path = string.Empty;
BuildFullPath(node, ref path);
return path;
}
private static void BuildFullPath(TreeListNode node, ref string path)
{
if (node == null)
{
return;
}
if (node.ParentNode != null)
{
BuildFullPath(node.ParentNode, ref path);
}
if (path.Length > 0)
{
path += "\\";
}
var nodeText = node.GetDisplayText(0);
if (!string.IsNullOrEmpty(nodeText))
{
path += nodeText;
}
}
#endregion 树遍历
private void barButtonItemPast_ItemClick(object sender, ItemClickEventArgs e)
{
string base64String = Clipboard.GetData(UCVtkEdit.CLIPBOARD_FORMAT_VTK_PROPERTY) as string;
if (base64String == null)
return;
byte[] bytes = Convert.FromBase64String(base64String);
using (MemoryStream memoryStream = new MemoryStream(bytes))
{
1 month ago
#pragma warning disable SYSLIB0011 // 类型或成员已过时
1 month ago
IFormatter formatter = new BinaryFormatter();
1 month ago
#pragma warning restore SYSLIB0011 // 类型或成员已过时
1 month ago
SigmaDrawerElement.VtkScene property = formatter.Deserialize(memoryStream) as SigmaDrawerElement.VtkScene;
if (property != null)
{
this.VtkProerty = property;
//this.VtkProerty.BackgroundColor = property.BackgroundColor;
//this.VtkProerty.MeshEdgeColor = property.MeshEdgeColor;
//this.VtkProerty.ShowMeshEdge = property.ShowMeshEdge;
//this.VtkProerty.ShowMeshEdgeColorGradient = property.ShowMeshEdgeColorGradient;
//this.VtkProerty.ShowCoordinateGrid = property.ShowCoordinateGrid;
//this.VtkProerty.ShowCoordinateGridLine = property.ShowCoordinateGridLine;
//this.VtkProerty.ShowScalarBar = property.ShowScalarBar;
//this.VtkProerty.ZScale = property.ZScale;
//this.VtkProerty.ZMaxScale = property.ZMaxScale;
//this.VtkProerty.SingularValueFilterFlag = property.SingularValueFilterFlag;
//this.VtkProerty.SingularThreshold = property.SingularThreshold;
//this.VtkProerty.WellMode = property.WellMode;
//this.VtkProerty.FaultMode = property.FaultMode;
//this.vtkProerty.WellColumnHeight = property.WellColumnHeight;
//this.vtkProerty.WellColumnRadius = property.WellColumnRadius;
//this.vtkProerty.WellColumnColor = property.WellColumnColor;
//this.vtkProerty.WellColumnNameColor = property.WellColumnNameColor;
//this.vtkProerty.WellColumnNameSize = property.WellColumnNameSize;
//this.vtkProerty.WellColumnNameGap = property.WellColumnNameGap;
//this.vtkProerty.WellSymbolRadius = property.WellSymbolRadius;
//this.VtkProerty.LightMode = property.LightMode;
//this.VtkProerty.MeshEdgeMode = property.MeshEdgeMode;
//this.VtkProerty.LightIntensity = property.LightIntensity;
//this.VtkProerty.LightColor = property.LightColor;
//this.VtkProerty.LightAzimuth = property.LightAzimuth;
//this.VtkProerty.LightElevation = property.LightElevation;
//this.VtkProerty.LightAmbientColor = property.LightAmbientColor;
//this.VtkProerty.LightDiffusedCorlor = property.LightDiffusedCorlor;
//this.vtkProerty.LightSpecularColor = property.LightSpecularColor;
//this.vtkProerty.ActorAmbient = property.ActorAmbient;
//this.vtkProerty.ActorDiffused = property.ActorDiffused;
//this.vtkProerty.ActorSpecular = property.ActorSpecular;
//this.VtkProerty.ActorAmbientColor = property.ActorAmbientColor;
//this.VtkProerty.ActorDiffusedColor = property.ActorDiffusedColor;
//this.vtkProerty.ActorSpecularColor = property.ActorSpecularColor;
//this.vtkProerty.Thickness = property.Thickness;
this.propertyGridControl.SelectedObject = null;
this.propertyGridControl.SelectedObject = this.VtkProerty;
{
int newValue = (int)VtkProerty.LightMode;
GeoSigmaLib.KVDLN_SetLightMode(VtkVDLNHandle, newValue);
}
{
Color newValue = this.VtkProerty.LightAmbientColor;
GeoSigmaLib.KVDLN_SetLightAmbientColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B);
}
{
Color newValue = this.VtkProerty.LightDiffusedCorlor;
GeoSigmaLib.KVDLN_SetLightDiffusedCorlor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B);
}
{
Color newValue = this.VtkProerty.LightSpecularColor;
GeoSigmaLib.KVDLN_SetLightSpecularColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B);
}
//设置材质颜色影响所有actor
{
Color newValue = this.VtkProerty.ActorAmbientColor;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 1, newValue.R, newValue.G, newValue.B, 1);
}
{
Color newValue = this.VtkProerty.ActorDiffusedColor;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 2, newValue.R, newValue.G, newValue.B, 1);
}
{
Color newValue = this.VtkProerty.ActorSpecularColor;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 3, newValue.R, newValue.G, newValue.B, 1);
}
{
double newValue = this.VtkProerty.ActorAmbient;
newValue /= 100.0;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 4, 255, 255, 255, newValue);
}
{
double newValue = this.VtkProerty.ActorDiffused;
newValue /= 100.0;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 5, 255, 255, 255, newValue);
}
{
double newValue = this.VtkProerty.ActorSpecular;
newValue /= 100.0;
GeoSigmaLib.KVDLN_SetActorProperty(VtkVDLNHandle, 6, 255, 255, 255, newValue);
}
{
Color newValue = this.VtkProerty.BackgroundColor;
GeoSigmaLib.KVDLN_SetBackgroundColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B, newValue.A);
}
{
bool newValue = this.VtkProerty.ShowMeshEdgeColorGradient;
GeoSigmaLib.KVDLN_ShowMeshEdgeColorGradient(VtkVDLNHandle, newValue);
}
{
bool newValue = VtkProerty.ShowMeshEdge;
GeoSigmaLib.KVDLN_ShowLinearExtrusion(VtkVDLNHandle, newValue);
}
{
Color newValue = (Color)this.VtkProerty.MeshEdgeColor;
GeoSigmaLib.KVDLN_SetMeshEdgeColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B, newValue.A);
}
{
bool newValue = this.VtkProerty.ShowCoordinateGrid;
GeoSigmaLib.KVDLN_ShowAxes(VtkVDLNHandle, newValue);
}
{
bool newValue = this.VtkProerty.ShowCoordinateGridLine;
GeoSigmaLib.KVDLN_ShowCoordinateGridLine(VtkVDLNHandle, newValue);
}
{
bool newValue = this.VtkProerty.ShowScalarBar;
GeoSigmaLib.KVDLN_ShowScalarBar(VtkVDLNHandle, newValue);
}
{
int newValue = (int)VtkProerty.MeshEdgeMode;
GeoSigmaLib.KVDLN_SetMeshEdgeMode(VtkVDLNHandle, newValue);
}
{
double newValue = VtkProerty.LightIntensity;
newValue = newValue / 100.0f;
GeoSigmaLib.KVDLN_SetLightIntensity(VtkVDLNHandle, newValue);
}
{
//角度值-90 到 90
double newValue = this.VtkProerty.LightAzimuth;
GeoSigmaLib.KVDLN_SetLAzimuth(VtkVDLNHandle, newValue);
}
{
//角度值0 到 360
double newValue = this.VtkProerty.LightElevation;
GeoSigmaLib.KVDLN_SetLElevation(VtkVDLNHandle, newValue);
}
{
double newValue = this.VtkProerty.ZScale;
GeoSigmaLib.KVDLN_SetZScale(VtkVDLNHandle, newValue);
}
{
double newValue = this.VtkProerty.ZMaxScale;
GeoSigmaLib.KVDLN_SetZMaxScale(VtkVDLNHandle, newValue);
}
{
bool newValue = this.VtkProerty.SingularValueFilterFlag;
GeoSigmaLib.KVDLN_SetSingularValueFilterFlag(VtkVDLNHandle, newValue);
}
{
int newValue = this.VtkProerty.SingularThreshold;
GeoSigmaLib.KVDLN_SetSingularThreshold(VtkVDLNHandle, newValue);
}
{
double newValue = this.VtkProerty.Thickness;
GeoSigmaLib.KVDLN_SetLinearExtrusionValue(VtkVDLNHandle, newValue);
}
{
int newValue = (int)this.VtkProerty.WellMode;
GeoSigmaLib.KVDLN_SetWellMode(VtkVDLNHandle, newValue);
}
{
int newValue = (int)this.VtkProerty.FaultMode;
GeoSigmaLib.KVDLN_SetFaultMode(VtkVDLNHandle, newValue);
}
{
double newValue = this.VtkProerty.WellColumnRadius;
GeoSigmaLib.KVDLN_SetWellColumnRadius(VtkVDLNHandle, newValue);
}
{
double newValue = this.VtkProerty.WellSymbolRadius;
GeoSigmaLib.KVDLN_SetWellSymbolRadius(VtkVDLNHandle, newValue);
}
{
int newValue = this.VtkProerty.WellColumnNameSize;
GeoSigmaLib.KVDLN_SetWellColumnNameSize(VtkVDLNHandle, newValue);
}
{
int newValue = this.VtkProerty.WellColumnNameGap;
GeoSigmaLib.KVDLN_SetWellColumnNameGap(VtkVDLNHandle, newValue);
}
{
double newValue = this.VtkProerty.WellColumnHeight;
GeoSigmaLib.KVDLN_SetWellColumnHeight(VtkVDLNHandle, newValue);
}
{
bool newValue = this.VtkProerty.WellColumnThrough;
GeoSigmaLib.KVDLN_SetWellColumnThrough(VtkVDLNHandle, newValue);
}
{
Color newValue = this.VtkProerty.WellColumnNameColor;
GeoSigmaLib.KVDLN_SetWellColumnNameColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B, newValue.A);
}
{
//Color newValue = this.VtkProerty.WellColumnColor;
//GeoSigmaLib.KVDLN_SetWellColumnColor(VtkVDLNHandle, newValue.R, newValue.G, newValue.B, newValue.A);
UpdateWellTypeColor();
}
}
}
}
private void barButtonItemCopy_ItemClick(object sender, ItemClickEventArgs e)
{
using (MemoryStream memoryStream = new MemoryStream())
{
1 month ago
#pragma warning disable SYSLIB0011 // 类型或成员已过时
1 month ago
IFormatter formatter = new BinaryFormatter();
1 month ago
#pragma warning restore SYSLIB0011 // 类型或成员已过时
1 month ago
formatter.Serialize(memoryStream, this.VtkProerty);
string base64String = Convert.ToBase64String(memoryStream.ToArray());
Clipboard.SetData(UCVtkEdit.CLIPBOARD_FORMAT_VTK_PROPERTY, base64String);
}
}
private void timerUI_Tick(object sender, EventArgs e)
{
this.barButtonItemPast.Enabled = Clipboard.ContainsData(UCVtkEdit.CLIPBOARD_FORMAT_VTK_PROPERTY) ? true : false;
}
}
}