|
|
|
@ -3,12 +3,14 @@ using System.Collections.ObjectModel; |
|
|
|
|
using System.Diagnostics; |
|
|
|
|
using System.Drawing.Text; |
|
|
|
|
using System.IO; |
|
|
|
|
using System.Text.Json.Nodes; |
|
|
|
|
using System.Windows; |
|
|
|
|
using System.Windows.Media; |
|
|
|
|
using System.Windows.Media.Animation; |
|
|
|
|
using System.Windows.Media.Imaging; |
|
|
|
|
using System.Windows.Media.Media3D; |
|
|
|
|
using System.Windows.Threading; |
|
|
|
|
using HandyControl.Controls; |
|
|
|
|
using HelixToolkit.Wpf.SharpDX; |
|
|
|
|
using log4net; |
|
|
|
|
using NPOI.OpenXmlFormats.Vml.Office; |
|
|
|
@ -415,8 +417,8 @@ public class ViewportHelperPro |
|
|
|
|
else |
|
|
|
|
ViewportManager.GirdleTopLines.Add(vector); |
|
|
|
|
} |
|
|
|
|
result.Add(DisplayLineModel3D( VectorClockwiseSort(ViewportManager.GirdleBottomLines), color??ViewportManager.ColorConfig.MainBorderColor, thickness)); |
|
|
|
|
result.Add(DisplayLineModel3D( VectorClockwiseSort(ViewportManager.GirdleTopLines), color??ViewportManager.ColorConfig.MainBorderColor, thickness)); |
|
|
|
|
// result.Add(DisplayLineModel3D( VectorClockwiseSort(ViewportManager.GirdleBottomLines), color??ViewportManager.ColorConfig.MainBorderColor, thickness)); |
|
|
|
|
// result.Add(DisplayLineModel3D( VectorClockwiseSort(ViewportManager.GirdleTopLines), color??ViewportManager.ColorConfig.MainBorderColor, thickness)); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -474,24 +476,99 @@ public class ViewportHelperPro |
|
|
|
|
var groupedDic = facetTypeAll.GroupBy(entity => entity.PlaneCode) |
|
|
|
|
.ToDictionary(group => group.Key, group => group.ToList()); |
|
|
|
|
Logger.Info($"【面文本生成】 腰由{groupedDic.Count}个面组成"); |
|
|
|
|
foreach (var kv in groupedDic) |
|
|
|
|
|
|
|
|
|
var selPlaneCode = entities.First().PlaneCode; |
|
|
|
|
Logger.Info($"【面文本生成】 当前选择{selPlaneCode}"); |
|
|
|
|
|
|
|
|
|
List<Vector3> facetPoints = new List<Vector3>(); |
|
|
|
|
entities.ForEach(e => { facetPoints.Add(e.Point1); facetPoints.Add(e.Point2); facetPoints.Add(e.Point3); }); |
|
|
|
|
var facetIndex = -1; |
|
|
|
|
int.TryParse(selPlaneCode.Split("_")[1], out facetIndex); |
|
|
|
|
|
|
|
|
|
if (facetIndex == -1) |
|
|
|
|
{ |
|
|
|
|
var value = kv.Value; |
|
|
|
|
var key = kv.Key; |
|
|
|
|
var facetIndex = -1; |
|
|
|
|
int.TryParse(key.Split("_")[1], out facetIndex); |
|
|
|
|
List<Vector3> facetPoints = new List<Vector3>(); |
|
|
|
|
value.ForEach(e => { facetPoints.Add(e.Point1); facetPoints.Add(e.Point2); facetPoints.Add(e.Point3); }); |
|
|
|
|
/*** |
|
|
|
|
* 0 1 2 3 |
|
|
|
|
* 4 5 6 7 |
|
|
|
|
* 面id-loop4 = 0 - 高亮左边的竖线 - 波峰 - |
|
|
|
|
* 面id-loop4 = 1 - 高亮右边的竖线 - 波谷 |
|
|
|
|
* 面id-loop4 = 2 - 高亮左边的竖线 - 波谷 |
|
|
|
|
* 面id-loop4 = 3 - 高亮右边的竖线 - 波峰 |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
Logger.Info($"【面文本生成】 面索引解析失败{selPlaneCode}"); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
int linePointType = facetIndex % 4; |
|
|
|
|
|
|
|
|
|
switch (linePointType) |
|
|
|
|
{ |
|
|
|
|
case 0: |
|
|
|
|
case 3: |
|
|
|
|
var longestLine1 = GetLongestOrShortestLineSegment(facetPoints, returnLongest: true); |
|
|
|
|
result.Add(DisplayLineModel3D(new List<Tuple<Vector3,Vector3>>(){longestLine1}, new Color4(1f, 0, 0, 1f) , 2f)); |
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
case 2: |
|
|
|
|
var longestLine2 = GetLongestOrShortestLineSegment(facetPoints, returnLongest: false); |
|
|
|
|
result.Add(DisplayLineModel3D(new List<Tuple<Vector3,Vector3>>(){longestLine2}, new Color4(1f, 0, 0, 1f) , 2f)); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
//开始找值 |
|
|
|
|
string param = string.Empty; |
|
|
|
|
var valueIndex = 0; |
|
|
|
|
if (facetIndex % 8 == 0 || (facetIndex+1) % 8 == 0) |
|
|
|
|
{ |
|
|
|
|
//上腰面 |
|
|
|
|
Logger.Info($"【面文本生成】 腰面值 波峰【上腰面】"); |
|
|
|
|
valueIndex = (int)Math.Ceiling(facetIndex / 8.0) == 8 ? 0 : (int)Math.Ceiling(facetIndex / 8.0); |
|
|
|
|
param = "GIRDLE_BONE"; |
|
|
|
|
}else if (linePointType == 3 || linePointType == 0) |
|
|
|
|
{ |
|
|
|
|
//风筝面 |
|
|
|
|
Logger.Info($"【面文本生成】 腰面值 波峰【风筝面】"); |
|
|
|
|
valueIndex = (facetIndex / 8) ; |
|
|
|
|
param = "GIRDLE_BEZEL"; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
//腰厚比 |
|
|
|
|
Logger.Info($"【面文本生成】 腰面值 波峰【腰厚比】"); |
|
|
|
|
valueIndex = (facetIndex / 4) ; |
|
|
|
|
param = "GIRDLE_VALLEY"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
valueIndex += 1; |
|
|
|
|
var detail = ViewportManager.DiamondData[$"{param}_DETAIL"]; |
|
|
|
|
if (detail == null) |
|
|
|
|
{ |
|
|
|
|
Logger.Info($"【面文本生成】 {param}_DETAIL Key不存在"); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
Logger.Info($"【面文本生成】 {param}_DETAIL == {detail}"); |
|
|
|
|
var paramValue = detail[$"{param}_{valueIndex}"]; |
|
|
|
|
if (paramValue == null) |
|
|
|
|
{ |
|
|
|
|
Logger.Info($"【面文本生成】 {param}_DETAIL.{param}_{valueIndex} Key不存在"); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
Logger.Info($"【面文本生成】 {param}_DETAIL.{param}_{valueIndex} ==={paramValue}"); |
|
|
|
|
var valueFloat = (Math.Floor(float.Parse(paramValue.ToString())*1000)/10).ToString(); |
|
|
|
|
Logger.Info($"【面文本生成】 {valueFloat} -- {valueIndex}"); |
|
|
|
|
var facetTextPoint = GetOffsetCenter(facetPoints, ViewportManager.CenterVector); |
|
|
|
|
result.Add(DisplayText3D($"{valueFloat}", facetTextPoint, textColor)); |
|
|
|
|
// foreach (var kv in groupedDic) |
|
|
|
|
// { |
|
|
|
|
// var value = kv.Value; |
|
|
|
|
// var key = kv.Key; |
|
|
|
|
// var facetIndex = -1; |
|
|
|
|
// int.TryParse(key.Split("_")[1], out facetIndex); |
|
|
|
|
// List<Vector3> facetPoints = new List<Vector3>(); |
|
|
|
|
// value.ForEach(e => { facetPoints.Add(e.Point1); facetPoints.Add(e.Point2); facetPoints.Add(e.Point3); }); |
|
|
|
|
// |
|
|
|
|
// int linePointType = facetIndex % 4; |
|
|
|
|
// /*** |
|
|
|
|
// * 0 1 2 3 |
|
|
|
|
// * 4 5 6 7 |
|
|
|
|
// * 面index+1 % 4 = 0 |
|
|
|
|
// * 面id-loop4 = 0 - 高亮左边的竖线 - 波峰 - |
|
|
|
|
// * 面id-loop4 = 1 - 高亮右边的竖线 - 波谷 |
|
|
|
|
// * 面id-loop4 = 2 - 高亮左边的竖线 - 波谷 |
|
|
|
|
// * 面id-loop4 = 3 - 高亮右边的竖线 - 波峰 |
|
|
|
|
// */ |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
@ -515,7 +592,12 @@ public class ViewportHelperPro |
|
|
|
|
{ |
|
|
|
|
Logger.Info($"【面文本生成】 钻石数据有效,Index有效"); |
|
|
|
|
facetIndex += 1; |
|
|
|
|
var param = ViewportManager.DicFacetToValueParam[selFacetType]; |
|
|
|
|
var param = ViewportManager.DicFacetToValueParam.ContainsKey(selFacetType) ? ViewportManager.DicFacetToValueParam[selFacetType] : null; |
|
|
|
|
if (param == null) |
|
|
|
|
{ continue; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var detail = ViewportManager.DiamondData[$"{param}_DETAIL"]; |
|
|
|
|
if (detail == null) |
|
|
|
|
{ |
|
|
|
@ -531,10 +613,10 @@ public class ViewportHelperPro |
|
|
|
|
} |
|
|
|
|
Logger.Info($"【面文本生成】 {param}_DETAIL.{param}_{facetIndex} ==={paramValue}"); |
|
|
|
|
|
|
|
|
|
var valueFloat = Math.Round(float.Parse(paramValue.ToString()), MidpointRounding.ToZero); |
|
|
|
|
var valueFloat = float.Parse(paramValue.ToString()).ToString("F1"); |
|
|
|
|
Logger.Info($"【面文本生成】 {valueFloat} -- {facetIndex}"); |
|
|
|
|
var facetTextPoint = GetOffsetCenter(facetPoints, ViewportManager.CenterVector); |
|
|
|
|
result.Add(DisplayText3D($" {facetIndex} \r\n {valueFloat}", facetTextPoint, textColor)); |
|
|
|
|
result.Add(DisplayText3D($" {facetIndex} \r\n {valueFloat}", facetTextPoint, textColor)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1213,6 +1295,41 @@ public class ViewportHelperPro |
|
|
|
|
} |
|
|
|
|
return false; // 不平行于 Y 轴 |
|
|
|
|
} |
|
|
|
|
// 计算两个点之间的距离 |
|
|
|
|
private static float GetDistance(Vector3 point1, Vector3 point2) |
|
|
|
|
{ |
|
|
|
|
return (float)Math.Sqrt(Math.Pow(point2.X - point1.X, 2) + Math.Pow(point2.Y - point1.Y, 2) + Math.Pow(point2.Z - point1.Z, 2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 判断是否平行于Y轴的线段,返回较长或者较短的线段 |
|
|
|
|
private static Tuple<Vector3, Vector3> GetLongestOrShortestLineSegment(List<Vector3> facetPoints, bool returnLongest = true) |
|
|
|
|
{ |
|
|
|
|
Tuple<Vector3, Vector3> resultSegment = null; |
|
|
|
|
float resultLength = returnLongest ? float.MinValue : float.MaxValue; // 初始化为最小或最大长度 |
|
|
|
|
|
|
|
|
|
// 遍历所有相邻的点,构成线段 |
|
|
|
|
for (int i = 0; i < facetPoints.Count; i++) |
|
|
|
|
{ |
|
|
|
|
Vector3 currentPoint = facetPoints[i]; |
|
|
|
|
Vector3 nextPoint = facetPoints[(i + 1) % facetPoints.Count]; // 用模运算实现环形结构,最后一个点与第一个点连接 |
|
|
|
|
|
|
|
|
|
// 计算线段是否平行于 Y 轴 |
|
|
|
|
if (IsLineSegmentParallelToYAxis(new Tuple<Vector3, Vector3>(currentPoint, nextPoint))) |
|
|
|
|
{ |
|
|
|
|
// 计算线段的长度 |
|
|
|
|
float segmentLength = GetDistance(currentPoint, nextPoint); |
|
|
|
|
|
|
|
|
|
// 根据需要选择较长或较短的线段 |
|
|
|
|
if ((returnLongest && segmentLength > resultLength) || (!returnLongest && segmentLength < resultLength)) |
|
|
|
|
{ |
|
|
|
|
resultSegment = new Tuple<Vector3, Vector3>(currentPoint, nextPoint); |
|
|
|
|
resultLength = segmentLength; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return resultSegment; // 返回符合条件的线段 |
|
|
|
|
} |
|
|
|
|
private static void CalculateLineSegmentStats(List<Tuple<Vector3, Vector3>> lines, |
|
|
|
|
out Tuple<Vector3, Vector3> maxLine, |
|
|
|
|
out Tuple<Vector3, Vector3> minLine, |
|
|
|
|