优化汇总图逻辑

This commit is contained in:
2026-01-09 14:52:40 +08:00
parent 65b7d96aa2
commit 153e6fdb6e
2 changed files with 259 additions and 100 deletions

View File

@@ -11,16 +11,16 @@ Imports VGCore
Public Class CorelDRAW
Public M_Redisip As String = "127.0.0.1"
Public M_Redisport As Integer = 6379 ' 10079 '10079 ' 10079
Public M_Redispassword As String = "" '"blw@redis-ser@123" ' "blw@redis-ser@123" ' "" '
Public M_Redisport As Integer = 10079 ' 6379 ' 10079 ' 10079 '10079 ' 10079
Public M_Redispassword As String = "blw@redis-ser@123" ' "" ' "blw@redis-ser@123" '"blw@redis-ser@123" ' "blw@redis-ser@123" ' "" '
'redis消息队列
Public M_RedisQueue As Queue
'事件处理线程
Public M_EventThread As Thread
'服务器文件路径
Private M_ServerPath As String = "D:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic\" ' "R:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic\" '"D:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic\" ' "R:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic\" '
Private M_ServerPath As String = "R:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic\" ' "D:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic\" ' "R:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic\" ' "R:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic\" '"D:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic\" ' "R:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic\" '
'素材库路径
Private M_MaterialPath As String = "D:\Canvas\material\" ' "R:\Canvas\material\" ' "R:\Canvas\material\" '
Private M_MaterialPath As String = "R:\Canvas\material\" '"D:\Canvas\material\" ' "R:\Canvas\material\" ' "R:\Canvas\material\" ' "R:\Canvas\material\" '
'成平文件路径
Private M_TplPath As String = "D:\CorelDRAW\"
Public G_RedisSub, G_Redislish As RedisSubscriber
@@ -52,7 +52,7 @@ Public Class CorelDRAW
'End If
APP = New Application()
Thread.Sleep(300)
APP.Visible = True
APP.Visible = False
' Dim MaterialPath As String = M_MaterialPath & "素材模板.cdr"
'G_LibDoc = APP.OpenDocument(MaterialPath, False)
G_Log = New RuningLog(RichTextBox1, System.Windows.Forms.Application.StartupPath & "\log")
@@ -75,7 +75,7 @@ Public Class CorelDRAW
DisposeRedisMsgNode1(MsgNode)
Case 2
Dim MsgNode = JsonConvert.DeserializeObject(Of PreviewRoomTypePanel)(item.MsgNode.ToString)
DisposeRedisMsgNode3(MsgNode)
DisposeOverviewRedisMsgNode(MsgNode)
'DisposeRedisMsgNode2(MsgNode)
End Select
@@ -387,7 +387,7 @@ Public Class CorelDRAW
End Try
End Sub
Sub DisposeRedisMsgNode3(node As PreviewRoomTypePanel)
Sub DisposeOverviewRedisMsgNode(node As PreviewRoomTypePanel)
Dim gLogNode As LogNode
Dim filedir As String = M_ServerPath ' "D:\IIS ROOT\BLWLog\Web\wwwroot\PanelSelectionPic"
@@ -398,7 +398,7 @@ Public Class CorelDRAW
Dim RMNode As New RedisMsgNode
RMNode.MsgType = 2
RMNode.MsgNode = RsNode
Dim hotelText, hotelnodeText As Shape
Dim hotelText, hotelnodeText, kuang_lin As Shape
Dim nodeText As String
Dim bProject As Project = Nothing
Dim remark As String() = {"思源黑体", "36"}
@@ -425,8 +425,9 @@ Public Class CorelDRAW
Dim overviewFilePath As String = Path.Combine(M_MaterialPath, "BLV_总览框.cdr")
Dim overviewDoc As Document = Nothing
Dim previewBox As Shape = Nothing
Dim currentY As Double
Dim hotelName As String = ""
Dim projectTitleShape As Shape = Nothing
If Not File.Exists(overviewFilePath) Then
RsNode.Status = RedisSendNode.StatusType.MaterialLibraryNotExist
@@ -470,75 +471,82 @@ Public Class CorelDRAW
'设置总览框图形原点 为垂直居上水平居中
ZcdrDoc.Close()
'查找hotelText中名称为 Frame_Blv_Overview 的形状
For Each shape As Shape In hotelText.Shapes
If shape.Name.ToLower.Equals("Project_Title".ToLower) Then
'遍历其子形状,查找名称为 PreviewBox 的形状
'查找hotelText中名称为 Project_Title 的形状
hotelText.Ungroup()
For Each childShape As Shape In shape.Shapes
nodeText = ""
'当名称分别为Txt_EnglishFont、Txt_SocketSeries、Txt_ChineseFont、Txt_SwitchSeries、Txt_Data、Txt_Protocol、Txt_SocketSizeText、Txt_SwitchSizeText、Txt_ProjectName时
Select Case childShape.Name.ToLower
Case "Txt_EnglishFont".ToLower
nodeText = $"{bProject.en_font} {bProject.en_font_size.ToString}PT"
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
'移动到childShape对象中心位置
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_SocketSeries".ToLower
nodeText = bProject.socket_series
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_ChineseFont".ToLower
nodeText = $"{bProject.cn_font} {bProject.cn_font_size.ToString}PT"
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_SwitchSeries".ToLower
nodeText = bProject.switch_series
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_Data".ToLower
nodeText = node.RecordDate
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_Protocol".ToLower
nodeText = bProject.protocol
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_SocketSizeText".ToLower
nodeText = bProject.SocketSizeText.Replace("_", vbCrLf)
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_SwitchSizeText".ToLower
nodeText = bProject.SwitchSizeText.Replace("_", vbCrLf)
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_ProjectName".ToLower
nodeText = bProject.project_name
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
End Select
Next
Exit For
For Each shape As Shape In doc.Pages(1).ActiveLayer.Shapes
If shape.Name.ToLower.Equals("Project_Title".ToLower) Then
projectTitleShape = shape
'遍历其子形状,查找名称为 PreviewBox 的形状
End If
'kuang_lin
If shape.Name.ToLower.Equals("kuang_lin".ToLower) Then
kuang_lin = shape
End If
Next
For Each childShape As Shape In projectTitleShape.Shapes
nodeText = ""
'当名称分别为Txt_EnglishFont、Txt_SocketSeries、Txt_ChineseFont、Txt_SwitchSeries、Txt_Data、Txt_Protocol、Txt_SocketSizeText、Txt_SwitchSizeText、Txt_ProjectName时
Select Case childShape.Name.ToLower
Case "Txt_EnglishFont".ToLower
nodeText = $"{bProject.en_font} {bProject.en_font_size.ToString}PT"
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
'移动到childShape对象中心位置
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_SocketSeries".ToLower
nodeText = bProject.socket_series
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_ChineseFont".ToLower
nodeText = $"{bProject.cn_font} {bProject.cn_font_size.ToString}PT"
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_SwitchSeries".ToLower
nodeText = bProject.switch_series
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_Data".ToLower
nodeText = node.RecordDate
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_Protocol".ToLower
nodeText = bProject.protocol
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_SocketSizeText".ToLower
nodeText = bProject.SocketSizeText.Replace("_", vbCrLf)
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_SwitchSizeText".ToLower
nodeText = bProject.SwitchSizeText.Replace("_", vbCrLf)
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
Case "Txt_ProjectName".ToLower
nodeText = bProject.project_name
hotelnodeText = CreateTextImage2(doc.ActiveLayer, nodeText, remark)
hotelnodeText.Fill.ApplyUniformFill(chpcolor)
hotelnodeText.CenterX = childShape.CenterX
hotelnodeText.CenterY = childShape.CenterY
End Select
Next
Else
RsNode.Status = RedisSendNode.StatusType.MaterialNotExist
RsNode.Msg = $"未找到文件{vbCrLf}{overviewFilePath}{vbCrLf}中的图像!!"
@@ -553,41 +561,46 @@ Public Class CorelDRAW
End If
InpotMessage1("4、标题信息处理完成")
Dim currentY As Double = hotelText.CenterY - 20 ' 标题底部向下50mm
InpotMessage1("5、数据分组处理")
' 设置起始坐标Project_Title对象的左边值作为起始X下边值+50mm作为起始Y
Dim startX As Double = projectTitleShape.LeftX
Dim startY As Double = projectTitleShape.BottomY - 50 ' 起始Y坐标Project_Title对象的下边值+50mm
Dim Panelli As List(Of Panel)
Dim roomGroups As Dictionary(Of String, List(Of Panel)) = New Dictionary(Of String, List(Of Panel))()
For Each panel As Panel In node.panels
If Not roomGroups.ContainsKey(panel.room_name) Then
roomGroups.Add(panel.room_name, New List(Of Panel)())
Panelli = New List(Of Panel)()
roomGroups.Add(panel.room_name, Panelli)
Else
Panelli = roomGroups(panel.room_name)
End If
roomGroups(panel.room_name).Add(panel)
'roomGroups(panel.room_name).Add(panel)
SortPanelListBySize(Panelli, panel)
Console.WriteLine($"添加面板:{panel.room_name} - {panel.model_type}")
Next
InpotMessage1("6、房型分类处理")
currentY = startY ' 设置当前Y坐标为起始Y
For Each roomName As String In roomGroups.Keys
InpotMessage1("创建房型标题文本")
RsNode.Status = RedisSendNode.StatusType.BuildImageFail
RsNode.Msg = "创建酒店房型标题失败!!"
remark = {"思源黑体", "28"}
remark = {"思源黑体", "38"}
Dim roomText As Shape = CreateTextImage2(doc.ActiveLayer, roomName, remark)
roomText.CenterY = currentY
roomText.LeftX = 0
'Dim roomText As Shape = doc.ActiveLayer.CreateArtisticText(0, currentY, roomName)
'With roomText.Text.Properties
' .Font = "Source Han Sans SC"
' .Size = 28
'End With
roomText.LeftX = startX ' 房型标题左对齐到起始X
' 房型标题下方留出空间
currentY = roomText.CenterY - (roomText.OriginalHeight / 2) - 10
currentY = roomText.CenterY - (roomText.OriginalHeight / 2) - 10 ' 房型标题底部向下30mm
Dim currentX As Double = 0 ' 当前行的X坐标
Dim maxHeight As Double = 0 ' 当前行最高图像的高度
Dim currentX As Double = startX + 50 ' 当前行的X坐标行左边距50mm
Dim maxHeight As Double = 0 ' 当前行最高面板高度
Dim rowWidth As Double = 0 ' 当前行已排布宽度
Dim firstPanelInRow As Boolean = True ' 是否是行内第一个面板
InpotMessage1("遍历该房型对应的所有panel")
For Each panel As Panel In roomGroups(roomName)
@@ -607,6 +620,22 @@ Public Class CorelDRAW
InpotMessage1("粘贴到当前文档")
Dim pastedShape As Shape = doc.ActiveLayer.Paste() 'doc.ActiveLayer.Shapes(doc.ActiveLayer.Shapes.Count)
'延时(500)
Thread.Sleep(100)
pastedShape.Name = $"{roomName}_{ pastedShape.Name }"
' 计算面板宽度
Dim panelWidth As Double = pastedShape.SizeWidth
' 检查是否需要换行(当前行已排布宽度 + 新面板宽度 + 间距 > 1300mm
If Not firstPanelInRow AndAlso (rowWidth + panelWidth + 50) > 1250 Then
' 换行换行间距30mm+上一行最高面板高度
currentY = currentY - maxHeight - 30
currentX = startX + 50 ' 重置X坐标到行左边距
maxHeight = 0 ' 重置最大高度
rowWidth = 0 ' 重置行宽度
firstPanelInRow = True ' 重置为行内第一个面板
End If
InpotMessage1("设置图像位置")
pastedShape.LeftX = currentX
@@ -673,12 +702,19 @@ Public Class CorelDRAW
quantityText.Selected = False
InpotMessage1("更新X坐标为下一个图像留出50mm间距")
InpotMessage1("计算当前行的最大高度")
If group.OriginalHeight > maxHeight Then
maxHeight = group.OriginalHeight
End If
currentX += pastedShape.SizeWidth + 50
InpotMessage1("更新行宽度和X坐标")
If firstPanelInRow Then
rowWidth = panelWidth
firstPanelInRow = False
Else
rowWidth += panelWidth + 50 ' 行内面板间距50mm
End If
currentX += panelWidth + 50 ' 更新X坐标为下一个面板留出50mm间距
Else
RsNode.Status = RedisSendNode.StatusType.MaterialNotExist
RsNode.Msg = $"未找到文件{vbCrLf}{cdr_filename}{vbCrLf}中的图像!!"
@@ -717,6 +753,20 @@ Public Class CorelDRAW
Directory.CreateDirectory(savePath)
End If
''判断kuang_lin是否为空
If kuang_lin IsNot Nothing Then
Dim heigth As Double = kuang_lin.TopY - currentY + 50
Dim kuang_linTopY As Double = kuang_lin.TopY
kuang_lin.SizeHeight = heigth
kuang_lin.TopY = kuang_linTopY
'kuang_lin.TransformationMatrix.Rotate()
'' 可选:设置变换原点的可见性
'kuang_lin.TransformationOriginVisible = True
End If
Dim cdrFileName As String = $"{node.picNum}.cdr"
Dim cdrFilePath As String = Path.Combine(savePath, cdrFileName)
Dim ssao As New StructSaveAsOptions
@@ -725,11 +775,20 @@ Public Class CorelDRAW
ssao.Version = VGCore.cdrFileVersion.cdrVersion19
doc.SaveAs(cdrFilePath, ssao)
Dim nngroup As Shape = doc.Pages(1).ActiveLayer.Shapes.All.Group()
nngroup.Selected = True
Dim ptfFilePath As String = cdrFilePath.Replace(".cdr", ".pdf")
'Dim pngFilePath As String = cdrFilePath.Replace(".cdr", ".png")
'Dim Ef As ExportFilter = doc.ExportBitmap(pngFilePath, VGCore.cdrFilter.cdrPNG, VGCore.cdrExportRange.cdrSelection, VGCore.cdrImageType.cdrRGBColorImage)
'Ef.Finish()
'Dim Options As New StructExportOptions
'Dim PaletteOptions As New StructPaletteOptions
doc.PublishToPDF(ptfFilePath)
'Ef = doc.ExportEx(ptfFilePath, VGCore.cdrFilter.cdrPPF, VGCore.cdrExportRange.cdrSelection, Options, PaletteOptions)
'Ef.Finish()
'InpotMessage1("9、文档导出")
'Dim pltFileName As String = $"PreviewRoomTypePanel{node.picNum}.plt"
'Dim pltFilePath As String = Path.Combine(savePath, pltFileName)
@@ -825,6 +884,59 @@ Public Class CorelDRAW
End Try
End Function
''' <summary>
''' 将Panel按照最小高度优先、最小宽度优先的顺序插入到List(Of Panel)中并重新排序
''' </summary>
''' <param name="panelList">要排序的Panel列表</param>
''' <param name="newPanel">要插入的新Panel</param>
''' <returns>排序后的Panel列表</returns>
Public Shared Function SortPanelListBySize(ByRef panelList As List(Of Panel), ByVal newPanel As Panel) As List(Of Panel)
' 创建列表副本,避免修改原始列表
' 添加新Panel到列表
' 定义一个函数来从model_type中提取宽度和高度
Dim getSize As Func(Of Panel, Tuple(Of Double, Double)) = Function(panel)
If String.IsNullOrEmpty(panel.model_type) Then
Return Tuple.Create(0.0, 0.0)
End If
Dim parts() As String = panel.model_type.Split("_")
If parts.Length < 6 Then
Return Tuple.Create(0.0, 0.0)
End If
Dim width As Double = 0.0
Dim height As Double = 0.0
Double.TryParse(parts(parts.Length - 2), width)
Double.TryParse(parts(parts.Length - 1), height)
Return Tuple.Create(width, height)
End Function
If panelList.Count = 0 Then
panelList.Add(newPanel)
Return panelList
End If
Dim currentSize, newSize As Tuple(Of Double, Double)
For i As Integer = 0 To panelList.Count - 1
'取得当前Panel的宽度和高
currentSize = getSize(panelList(i))
'取得新Panel的宽度和高
newSize = getSize(newPanel)
'比较高度 高度低的在前
If currentSize.Item2 > newSize.Item2 Then
panelList.Insert(i, newPanel)
End If
Next
' 如果没有找到合适的位置则将新Panel添加到列表末尾
If Not panelList.Contains(newPanel) Then
panelList.Add(newPanel)
End If
Return panelList
End Function
''' <summary>
''' 检查单个图像名称是否符合规范
''' </summary>
@@ -1681,8 +1793,8 @@ Public Class CorelDRAW
G_LibDoc = APP.OpenDocument(MaterialPath, True)
MLibDoc = APP.CreateDocument()
End Try
'APP.EventsEnabled = False
'APP.Optimization = True
APP.EventsEnabled = False
APP.Optimization = True
'APP.EventsEnabled = True
'APP.Optimization = False
@@ -2002,9 +2114,9 @@ Public Class CorelDRAW
InpotMessage1($"14、开始将整个图像移动至中心位置")
SetIconToCentered(npage, fshp)
'Dim sel As ShapeRange = APP.ActiveSelectionRange
'APP.EventsEnabled = True
'APP.Optimization = False
'APP.Refresh()
APP.EventsEnabled = True
APP.Optimization = False
APP.Refresh()
'fshp.SetSize(Math.Abs(fshp.SizeWidth) * 10000, Math.Abs(fshp.SizeHeight) * 10000)
InpotMessage1($"15、开始保存图像成文件")

47
TestSortFunction.vb Normal file
View File

@@ -0,0 +1,47 @@
Imports System
Imports System.Collections.Generic
Imports System.Linq
' 测试类用于验证SortPanelListBySize函数的功能
Public Class TestSortFunction
Public Shared Sub Main()
' 创建测试用的Panel对象
Dim panel1 As New Panel()
panel1.model_type = "Mode_2连体_竖向_灰色_104_189.5" ' w:104, h:189.5
Dim panel2 As New Panel()
panel2.model_type = "Mode_3连体_横向_白色_156_94.75" ' w:156, h:94.75
Dim panel3 As New Panel()
panel3.model_type = "Mode_1连体_竖向_黑色_52_189.5" ' w:52, h:189.5
Dim panel4 As New Panel()
panel4.model_type = "Mode_2连体_横向_灰色_104_94.75" ' w:104, h:94.75
' 创建初始列表
Dim panelList As New List(Of Panel)()
panelList.Add(panel1)
panelList.Add(panel2)
panelList.Add(panel3)
' 直接调用静态排序函数,无需创建实例
Dim sortedList As List(Of Panel) = CorelDRAW.SortPanelListBySize(panelList, panel4)
' 输出排序结果
Console.WriteLine("排序后的Panel列表按最小高度优先、最小宽度优先")
For Each panel As Panel In sortedList
Dim parts() As String = panel.model_type.Split("_")
Dim width As Double = 0.0
Dim height As Double = 0.0
If parts.Length >= 6 Then
Double.TryParse(parts(parts.Length - 2), width)
Double.TryParse(parts(parts.Length - 1), height)
End If
Console.WriteLine($"model_type: {panel.model_type}, 宽度: {width}, 高度: {height}")
Next
Console.ReadKey()
End Sub
End Class