Przeglądaj źródła

蘭雅CPG插件 添加工具运行信息提示

蘭雅sRGB 2 miesięcy temu
rodzic
commit
7b23926d6b

+ 24 - 13
08_SmartGroup/ToolsBox.cpp

@@ -1,12 +1,11 @@
-#include <stdio.h>
+#include "cdrapp.h"
+#include <stdio.h>
 #include <windows.h>
-#include "cdrapi.h"
 #include "resource.h"
-#include "cdrapp.h"
 
 corel *cdr = NULL;
 static HINSTANCE g_hResource = NULL;
-
+char infobuf[256] = {0};
 BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 {
     if (fdwReason == DLL_PROCESS_ATTACH) {
@@ -192,6 +191,9 @@ void ToolsBoxPlugin::OpenToolsBox()
 }
 
 
+// MessageBox(NULL, "更新提示信息: 激活CorelDRAW窗口", "CPG代码测试", MB_ICONSTOP);
+#define UPDATE_INFO_ACTIVE_CDRWND  \
+    PutTextValue(hDlg, INFO_TEXT, infobuf); Active_CorelWindows(hDlg);
 intptr_t CALLBACK ToolsBoxPlugin::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
     // 从附加数据中获取 m_pApp 指针
@@ -204,33 +206,35 @@ intptr_t CALLBACK ToolsBoxPlugin::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, L
                     double exp = GetTextValue(hDlg, EXP_TEXT);
                     AutoMakeSelection(cdr);
                     Box_AutoGroup(cdr, exp);
+                    UPDATE_INFO_ACTIVE_CDRWND
 
-// MessageBox(NULL, "方框智能群组:Union-Find 算法\n 分组记录请查看: D:\\group.txt", "CPG代码测试", MB_ICONSTOP);
-                    Active_CorelWindows(hDlg);
                 }
                 break;
 
             case IDC_CQL_OUTLINE:
                 cql_OutlineColor(cdr);
-                Active_CorelWindows(hDlg);
+
+                UPDATE_INFO_ACTIVE_CDRWND
                 break;
 
             case IDC_CQL_FILL:
                 cql_FillColor(cdr);
-                Active_CorelWindows(hDlg);
+
+                UPDATE_INFO_ACTIVE_CDRWND
                 break;
 
             case IDC_CQL_SIZE:
                 cql_SameSize(cdr);
-                Active_CorelWindows(hDlg);
+
+                UPDATE_INFO_ACTIVE_CDRWND
                 break;
 
             case IDC_CLEAR_FILL:{
                     double exp = GetTextValue(hDlg, EXP_TEXT);
                     AutoMakeSelection(cdr);
                     BBox_DrawRectangle(cdr, exp);
-                    Active_CorelWindows(hDlg);
-                // Clear_Fill(cdr);
+                    
+                    UPDATE_INFO_ACTIVE_CDRWND
                 }
                 break;
 
@@ -238,12 +242,19 @@ intptr_t CALLBACK ToolsBoxPlugin::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, L
                 Shapes_Filp(cdr);
                 break;
 
-            case IDC_CDR2AI:
+            case IDC_CDR2AI:{    
                 CdrCopy_to_AdobeAI(cdr);
+                sprintf(infobuf, "把CorelDRAW软件中选择物件复制到剪贴板,请切换到AI软件粘贴");
+                UPDATE_INFO_ACTIVE_CDRWND
+                }
+
                 break;
 
-            case IDC_AI2CDR:
+            case IDC_AI2CDR:{
                 AdobeAI_Copy_ImportCdr(cdr);
+                sprintf(infobuf, "请先在AI软件选择物件复制,再切换到CorelDRAW软件点执行本功能");
+                UPDATE_INFO_ACTIVE_CDRWND
+                }
                 break;
 
             case IDOK:

+ 1 - 1
08_SmartGroup/ToolsBox.rc

@@ -19,7 +19,7 @@ STYLE DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_POPUP | WS_SYSMENU
 CAPTION "蘭雅 CPG 插件 福利群版"
 FONT 8, "MS Shell Dlg", 400, 0, 1
 {
-    CTEXT           "蘭雅 CorelDRAW CPG 插件 2024.8.8 智能群组版", 0, 21, 105, 94, 17, SS_CENTER, WS_EX_LEFT
+    CTEXT           "蘭雅 CorelDRAW CPG 插件\n2024.8.8 智能群组版", INFO_TEXT, 6, 105, 126, 17, SS_CENTER, WS_EX_LEFT
     PUSHBUTTON      "方框智能群组", IDC_RED, 73, 2, 59, 21, 0, WS_EX_LEFT
     PUSHBUTTON      "CQL轮廓色相同", IDC_CQL_OUTLINE, 5, 2, 59, 24, 0, WS_EX_LEFT
     PUSHBUTTON      "边界画矩形", IDC_CLEAR_FILL, 74, 36, 59, 19, 0, WS_EX_LEFT

+ 36 - 23
08_SmartGroup/boxAutoGroup.cpp

@@ -1,5 +1,6 @@
 #include "cdrapp.h"
 #include <algorithm>
+#include <cstdio>
 #include <map>
 #include <vector>
 #include <iostream>
@@ -78,6 +79,7 @@ bool BBox_DrawRectangle(corel *cdr, double exp) {
   }
   srs->CreateSelection();
   
+  sprintf(infobuf, "提示: 标记画框数量: %d 个\n容差值请使用小键盘输入", srs->Count);
   EndOpt(cdr);
   return true;
 }
@@ -128,30 +130,35 @@ bool Box_AutoGroup(corel *cdr, double exp) {
     }
   }
 
- // 输出分组结果到文件
-  std::ofstream output_file("D:\\group.txt");
-  if (output_file.is_open()) {
-      std::map<int, std::vector<int>> groups;
-      for (int i = 0; i < parent.size(); i++) {
-          int root = find(parent, i);
-          groups[root].push_back(i + 1); // CorelDRAW Shapes 物件 Item 编号从1开始
-      }
-
-      for (const auto& group : groups) {
-          output_file << "Group: ";
-          for (int index : group.second) {
-              output_file << index << " ";
-          }
-          output_file << std::endl;
-      }
+  double runtime[2] = {0,0};
+  auto end = std::chrono::high_resolution_clock::now(); 
+  std::chrono::duration<double> duration = end - start;
+  runtime[0] = duration.count();
 
-    auto end = std::chrono::high_resolution_clock::now(); // 结束时间
-    // 计算持续时间
-    std::chrono::duration<double> duration = end - start;
-    output_file << "Execution time: " << duration.count() << " seconds\n";
-
-    output_file.close();
-  } 
+ // 输出分组结果到文件
+  // std::ofstream output_file("D:\\group.txt");
+  // if (output_file.is_open()) {
+  //     std::map<int, std::vector<int>> groups;
+  //     for (int i = 0; i < parent.size(); i++) {
+  //         int root = find(parent, i);
+  //         groups[root].push_back(i + 1); // CorelDRAW Shapes 物件 Item 编号从1开始
+  //     }
+
+  //     for (const auto& group : groups) {
+  //         output_file << "Group: ";
+  //         for (int index : group.second) {
+  //             output_file << index << " ";
+  //         }
+  //         output_file << std::endl;
+  //     }
+
+  //   auto end = std::chrono::high_resolution_clock::now(); // 结束时间
+  //   // 计算持续时间
+  //   std::chrono::duration<double> duration = end - start;
+  //   output_file << "Execution time: " << duration.count() << " seconds\n";
+
+  //   output_file.close();
+  // } 
 
   // 输出分组结果
   std::map<int, std::vector<int>> groups;
@@ -195,6 +202,12 @@ bool Box_AutoGroup(corel *cdr, double exp) {
       srgp->RemoveAll();
   }
   srs->CreateSelection();
+
+  // 计算持续时间
+  duration = std::chrono::high_resolution_clock::now() - start;
+  runtime[1] = duration.count();
+
+  sprintf(infobuf, "选择物件: %d 个, 分组: %.2f秒\n总共群组: %d 组, 总时间: %.2f秒", sr->Count, runtime[0] + 0.01, srs->Count, runtime[1] + 0.02);
   EndOpt(cdr);
   return true;
 }

+ 3 - 2
08_SmartGroup/cdrPDF2Clip.cpp

@@ -163,6 +163,7 @@ bool pdf_ImportCdr(corel *cdr, const char *pdffile)
    
    auto impflt = cdr->ActiveLayer->ImportEx(_bstr_t(pdffile), cdrAutoSense , si);
    impflt->Finish();
+   return true;
 }
 
 void AdobeAI_Copy_ImportCdr(corel *cdr)
@@ -171,8 +172,8 @@ void AdobeAI_Copy_ImportCdr(corel *cdr)
     GetTempPath(MAX_PATH, path);
     char *f = strcat(path, "CDR2AI.pdf");
     if (clipboard_to_pdf(f)){
-        // 延时 0.3
-        std::this_thread::sleep_for(std::chrono::milliseconds(300));
+        // 延时 0.5
+        std::this_thread::sleep_for(std::chrono::milliseconds(500));
         pdf_ImportCdr(cdr, f);
     }
 

+ 4 - 0
08_SmartGroup/cdrapi.cpp

@@ -34,4 +34,8 @@ double GetTextValue(HWND hDlg, int IDITEM) {
     double exp = 0.0;
     sscanf_s(ibuf, "%lf", &exp);
     return exp;
+}
+
+void PutTextValue(HWND hDlg, int IDITEM, char *buf) {
+  SetWindowText(::GetDlgItem(hDlg, IDITEM), buf);
 }

+ 7 - 0
08_SmartGroup/cdrapi.h

@@ -1,6 +1,10 @@
 #ifndef CDRAPI_H_INCLUDED
 #define CDRAPI_H_INCLUDED
 
+#define _CRT_SECURE_NO_WARNINGS
+#include <string.h>
+
+
 #import "VGCoreAuto.tlb" \
 rename("GetCommandLine", "VGGetCommandLine") \
 rename("CopyFile", "VGCore") \
@@ -10,9 +14,12 @@ rename("FindWindow", "VGFindWindow")
 using namespace VGCore;
 
 
+
 void BeginOpt(corel *cdr);
 void EndOpt(corel *cdr);
 void Active_CorelWindows(HWND hDlg);
 double GetTextValue(HWND hDlg, int IDITEM);
+void PutTextValue(HWND hDlg, int IDITEM, char *buf);
+
 
 #endif // CDRAPI_H_INCLUDED

+ 6 - 0
08_SmartGroup/cdrapp.cpp

@@ -27,6 +27,8 @@ bool cql_OutlineColor(corel *cdr)
     // MessageBox(NULL, cql, "cql 轮廓颜色", MB_ICONSTOP);
     auto sr = cdr->ActivePage->Shapes->FindShapes(_bstr_t(), cdrNoShape, VARIANT_TRUE, cql);
     sr->CreateSelection();
+
+    strcpy(infobuf , buf);
     return true;
 }
 
@@ -47,6 +49,8 @@ bool cql_FillColor(corel *cdr)
 
     auto sr = cdr->ActivePage->Shapes->FindShapes(_bstr_t(), cdrNoShape, VARIANT_TRUE, cql);
     sr->CreateSelection();
+
+    strcpy(infobuf , buf);
     return true;
 }
 
@@ -62,6 +66,8 @@ bool cql_SameSize(corel *cdr)
     //  MessageBox(NULL, cql, "cql 尺寸相同", MB_ICONSTOP);
     auto sr = cdr->ActivePage->Shapes->FindShapes(_bstr_t(), cdrNoShape, VARIANT_TRUE, cql);
     sr->CreateSelection();
+
+    strcpy(infobuf , buf);
     return true;
 }
 

+ 2 - 0
08_SmartGroup/cdrapp.h

@@ -17,4 +17,6 @@ bool AutoMakeSelection(corel *cdr);
 bool Box_AutoGroup(corel *cdr, double exp = 0.0);
 bool BBox_DrawRectangle(corel *cdr, double exp = 0.0);
 
+extern char infobuf[];
+
 #endif // CDRAPP_H_INCLUDED

+ 1 - 0
08_SmartGroup/resource.h

@@ -14,3 +14,4 @@
 #define IDC_AI2CDR                              40007
 #define EXP_LT                                  40008
 #define EXP_TEXT                                40009
+#define INFO_TEXT                               40010