I have been working on the “GSoC editing grease pencil strokes using curves” project with Antonio. But we hit a structural code design issue that we both don’t really know how to solve. We thought it would be a good idea to share the problem with other developers and see if we can get some help.
So here is the problem: the new “mode” (in the code it’s not a mode per se. It’s a boolean flag attached to the grease pencil object) that we are trying to build, allows the user to convert strokes to bezier curves and vice versa. We call it “curve edit mode”. One important aspect of the conversion from stroke to curve is that, ideally, the user has control over how good the curve fits the stroke. We call this parameter the
error_threshold. A conversion from stroke to curve should happen automatically when:
- the user is in Edit Mode, selects one or more stroke(s), and enters curve edit mode.
- the user is in curve edit mode and selects a stroke that was not yet converted.
In the two cases above, the user should have control over the
error_threshold to adjust the fit as needed.
We think it would be best to have the conversion (from stroke to curve) be capsulated inside an operator (say
GPENCIL_OT_convert_stroke_to_curve). This way, the
error_threshold value can be added as a parameter and changed in the redo panel. Now our issue is that we don’t know how to achieve this in the Blender operator architecture. We need to call an operator conditionally from another one (select operator), such that the redo panel contains the parameters from both the first and second one (namely the
If the current operator system does not allow for what is described above, then we need to think of some other way of achieving this goal. Maybe there are some tricks here that we just don’t know about.
We already tried the following (which ended up not working): Simply put the
error_threshold parameter in the select operator and call the
BKE functions for the conversion directly. The issue with that is there is no good way of not showing the parameter in the redo panel, when it is not needed (e.g. the user selects a stroke that already was converted to a curve). We can only decide when we need the conversion after we find which stroke to select (which gets done in the execute-part of the select operator). So we can’t check for this in the poll function. Either way, we think its not a good idea to have the select operators handle these two different functionalities.