Browse Source

优化走刀算法,增加安装包iss脚本

hongwenjun 1 year ago
parent
commit
117525b8e6
2 changed files with 117 additions and 6 deletions
  1. 89 0
      InnoSetup/CorelVBA.iss
  2. 28 6
      python/Cut_Line_Algorithm.py

+ 89 - 0
InnoSetup/CorelVBA.iss

@@ -0,0 +1,89 @@
+; Script generated by the Inno Setup Script Wizard.
+; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
+
+#define MyAppName "蘭雅CorelVBA 2023版"
+#define MyAppVersion "1.1"
+#define MyAppPublisher "蘭雅sRGB CorelDRAW 免费开源插件"
+#define MyAppURL "https://262235.xyz/"
+#define MyAppExeName "GMS"
+#define MyAppAssocName MyAppName + ""
+#define MyAppAssocExt ".myp"
+#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt
+
+[Setup]
+; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
+; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
+AppId={{0006790C-7107-4C59-A557-7F2EEDB64AFB}
+AppName={#MyAppName}
+AppVersion={#MyAppVersion}
+;AppVerName={#MyAppName} {#MyAppVersion}
+AppPublisher={#MyAppPublisher}
+AppPublisherURL={#MyAppURL}
+AppSupportURL={#MyAppURL}
+AppUpdatesURL={#MyAppURL}
+
+ChangesAssociations=yes
+DisableProgramGroupPage=yes
+; Uncomment the following line to run in non administrative install mode (install for current user only.)
+;PrivilegesRequired=lowest
+OutputDir=C:\app\CorelVBA
+OutputBaseFilename=蘭雅CorelVBA
+SetupIconFile=C:\app\CorelVBA\GMS\262235.xyz\蘭.ico
+Compression=lzma
+SolidCompression=yes
+WizardStyle=modern
+UsePreviousAppDir=no
+
+DefaultDirName={code:GetInstallDir}
+
+[Code]
+function GetInstallDir(Param: String): String;
+var
+  InstallDir: String;
+begin
+  // 从注册表中读取安装目录
+  if RegQueryStringValue(HKLM64, 'SOFTWARE\Corel\Setup\CorelDRAW Graphics Suite 2022', 'Destination', InstallDir) then
+  begin
+    Result := ExtractFilePath(InstallDir) + 'Draw\GMS';
+  end 
+
+  else if RegQueryStringValue(HKLM64, 'SOFTWARE\Corel\Setup\CorelDRAW Graphics Suite 2020', 'Destination', InstallDir) then
+  begin
+    Result := ExtractFilePath(InstallDir) + 'Draw\GMS';
+  end 
+
+  else if RegQueryStringValue(HKLM64, 'SOFTWARE\Corel\Setup\CorelDRAW Graphics Suite 16', 'Destination', InstallDir) then
+  begin
+    Result := ExtractFilePath(InstallDir) + 'Draw\GMS';
+  end 
+
+  else
+  begin
+    // 如果读取失败,则使用默认安装目录
+    Result := ExpandConstant('C:\Program Files\Corel\CorelDRAW Graphics Suite 2020\Draw\GMS');
+  end;
+end;
+
+[Languages]
+Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
+
+[Tasks]
+Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
+
+[Files]
+Source: "C:\app\CorelVBA\GMS\262235.xyz.gms"; DestDir: "{app}"; Flags: ignoreversion
+Source: "C:\app\CorelVBA\GMS\Adobe_Illustrator.gms"; DestDir: "{app}"; Flags: ignoreversion
+Source: "C:\app\CorelVBA\GMS\ColorMark.cdr"; DestDir: "{app}"; Flags: ignoreversion
+Source: "C:\app\CorelVBA\GMS\ZeroBase.gms"; DestDir: "{app}"; Flags: ignoreversion
+Source: "C:\app\CorelVBA\GMS\学习CorelVBA.gms"; DestDir: "{app}"; Flags: ignoreversion
+; NOTE: Don't use "Flags: ignoreversion" on any shared system files
+Source: "C:\app\CorelVBA\GMS\262235.xyz\*"; DestDir: "{app}\262235.xyz\"; Flags: ignoreversion
+Source: "C:\app\CorelVBA\TSP\*"; DestDir: "C:\TSP\"; Flags: ignoreversion
+
+[Icons]
+Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
+Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
+
+[Run]
+;Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: shellexec postinstall skipifsilent
+

+ 28 - 6
python/Cut_Line_Algorithm.py

@@ -1,3 +1,4 @@
+import sys
 # 从文件读取一组节点
 nodes = []
 with open(r"C:\TSP\CDR_TO_TSP", "r") as file:
@@ -21,6 +22,7 @@ def sort_and_remove_duplicates(nodes):
     return unique_nodes
 
 
+
 # 对节点进行排序和删除重复,写回文件
 unique_nodes = sort_and_remove_duplicates(nodes)
 total = len(unique_nodes)
@@ -62,18 +64,35 @@ near_boundary_points = sorted(sorted_tuples, key=lambda x: x[0])
 # 输出排序后的元组列表
 # print(near_boundary_points)
 
-# 统计 x = x_min 的坐标点个数, 也就是求边界框左边 节点个数
+# 移除相邻点
+def remove_adjacent(nodes):
+    threshold = 0.5  # 设定阈值
+
+    for i, node in enumerate(nodes):
+        remove_indices = []
+        for j, other_node in enumerate(nodes[i+1:]):
+            distance = ((node[0]-other_node[0])**2 + (node[1]-other_node[1])**2)**0.5
+            if distance < threshold:
+                remove_indices.append(i+j+1)  # 记录需要移除的点的索引
+        for index in sorted(remove_indices, reverse=True):
+            del nodes[index]  # 移除邻近的点
+    return nodes
+near_boundary_points = remove_adjacent(near_boundary_points)
+
+# 统计 x_min和y_max邻近的坐标点个数, 也就是求边界框左边 节点个数
 left_points = []
 top_points = []
 for x, y in near_boundary_points:
-    if x == x_min:
+    if abs(x - x_min) <= 0.5:
         left_points.append((x, y))
 
-    if y == y_max:
+    if abs(y - y_max) <= 0.5:
         top_points.append((x, y))
 
 left_points.reverse()
 print(left_points)
+if len(left_points) % 2 :
+    top_points.reverse()    # 控制竖线从右往左
 print(top_points)
 
 # 把裁切线节点 写文件 TSP2.tx ,完成算法
@@ -82,8 +101,11 @@ f = open(r"C:\TSP\TSP2.txt", "w")
 line = "%d %d\n" % (total, total)
 f.write(line)
 
-ext = 3  # extend 延长线  3mm
-inverter = 1
+ext = 3  # extend 延长线, 默认值 3mm
+if len(sys.argv) > 1:
+    ext = float(sys.argv[1])
+ 
+inverter = 1   # 交流频率控制
 for x, y in left_points:
     if inverter == 1:
         line = "%f %f %f %f\n" % (x - ext, y, x_max + ext, y)
@@ -94,7 +116,7 @@ for x, y in left_points:
     inverter = (inverter + 1) % 2
 
 for x, y in top_points:
-    if inverter == 1:
+    if inverter == len(left_points) % 2:  # 控制竖线从下面往上
         line = "%f %f %f %f\n" % (x, y + ext, x, y_min - ext)
     else:
         line = "%f %f %f %f\n" % (x, y_min - ext, x, y + ext)