I am using C++ to write a CPG plugin. There are tens of thousands of overlapping objects that need to be grouped. The C++ algorithm runs very quickly, in less than 0.25 seconds. However, when using ShapeRange.Group in CorelDRAW to group 2,000 objects, it takes 30 seconds. How can I solve the software bottleneck?
Not sure how to implement it but with macros this code speeds things up greatly
Somewhere in the beginning
Optimization = True whatever code here thenOptimization=False: Refresh
void BeginOpt(corel *cdr)
{
auto name = _bstr_t("Undo");
cdr->EventsEnabled = false;
cdr->ActiveDocument->BeginCommandGroup(name);
cdr->ActiveDocument->Unit = cdrMillimeter;
cdr->Optimization = true;
}
void EndOpt(corel *cdr)
cdr->EventsEnabled = true;
cdr->Optimization = false;
cdr->ActiveDocument->ReferencePoint = cdrBottomLeft;
cdr->Application->Refresh();
cdr->ActiveDocument->EndCommandGroup();
I have already used window refresh optimization and called the above optimization function. The current bottleneck is the 2,000 times execution of the ShapeRange.Group traversal, which is causing CorelDRAW to hang. Is it possible to solve this problem through multi-threading or by calling similar APIs through the SDK?
Also you can use ActiveDocument.BeginCommandGroup
your routine
ActiveDocument.EndCommandGroup
Using multi-threading to call ShapeRange.Group() in batches. The good result is that the program does not crash. The bad result is that it did not improve the speed.
// =================================
My algorithm hasn't changed, I just took a detour. Previously, I would group the shapes in one step using srgp.Group().
Now, I first get the bounding box of the srgp, then use the bounding box to select the shapes, and then group them.
However, I'm not sure why ShapeRange->Group() is so slow. It could be a bug in CorelDRAW.