Sketcher: Can drawEdit(editCurve) draw several curves?

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
paddle
Veteran
Posts: 1392
Joined: Mon Feb 03, 2020 4:47 pm

Re: Sketcher: Can drawEdit(editCurve) draw several curves?

Post by paddle »

abdullah wrote: Mon Mar 14, 2022 3:07 pm Because, I thought while typing, here you have the functionality. You just need to rebase your functionality in master (or cherry-pick that commit):
https://github.com/FreeCAD/FreeCAD/comm ... e98484dbf5
Awesome !!
Offset is mostly done now by the way. It's not working yet for ellipse hyperbolas parabolas and bsplines but it's only a matter of adding them from the generated wires.

So I'll cherry pick your new commit and implement that in the rotate/scale/offset features. It should be much more stable with them.

By the way how is going the DSH refactoring? I have been thinking about snapping and I think it could be not too hard to integrate and would be integrated at DSH level (either if ctrl is pressed or if a toggle is activated).
For rotate/scale/offset I added a 'snapToPoint' function which basically override onSketchPos if a vertex is preselected. This way it's much better to make precise rotation/..
Thinking on this I think it would be fairly easy to extend that functionality to something more general. That would snap (override onSketchPost) not only to points but to lines (and their extensions) mid point of lines (where a symmetric auto-constraint would be great).
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Can drawEdit(editCurve) draw several curves?

Post by abdullah »

paddle wrote: Mon Mar 14, 2022 3:15 pm By the way how is going the DSH refactoring?
Well, I used up today's FC time with the multiple 2D curves. Next slot it is on Wednesday (unless life happens).
paddle wrote: Mon Mar 14, 2022 3:15 pm I have been thinking about snapping and I think it could be not too hard to integrate and would be integrated at DSH level (either if ctrl is pressed or if a toggle is activated).
When the issue with the widget focus and keystrokes is overcome, we will need to think all the functionalities we want for the modifier keys. We may have more functionalities than modifiers :lol:
paddle wrote: Mon Mar 14, 2022 3:15 pm For rotate/scale/offset I added a 'snapToPoint' function which basically override onSketchPos if a vertex is preselected. This way it's much better to make precise rotation/..
Thinking on this I think it would be fairly easy to extend that functionality to something more general. That would snap (override onSketchPost) not only to points but to lines (and their extensions) mid point of lines (where a symmetric auto-constraint would be great).
I think it makes sense to rethink snapping, as there are several tools using some kind of snap (restricting angles). As far as a modifier key must be pressed, I do not think users will freak out because they cannot get closer to a point without connecting it (which sometimes is the goal)...
User avatar
paddle
Veteran
Posts: 1392
Joined: Mon Feb 03, 2020 4:47 pm

Re: Sketcher: Can drawEdit(editCurve) draw several curves?

Post by paddle »

abdullah wrote: Mon Mar 14, 2022 3:26 pm I think it makes sense to rethink snapping, as there are several tools using some kind of snap (restricting angles). As far as a modifier key must be pressed, I do not think users will freak out because they cannot get closer to a point without connecting it (which sometimes is the goal)...
I think too that it doesn't require a modifier key. I think a setting in the task dialog, general settings (where there's grid size and all) is enough. Something like "Enable Snapping"

Doing

Code: Select all

            std::vector<Part::Geometry*> geometriesToAdd;
            ... add some geo to vector
            drawEdit(geometriesToAdd);
Is giving me a warning (even if it builds):
No suitable user-defined conversion from "std::vector<Part::Geometry*, std::allocator<Part::Geometry*>> to ...
Also there seem to be a problem with the drawn curves (arc specially):
draw geos.png
draw geos.png (19.25 KiB) Viewed 1337 times
the same with adding geometries create the expected offset
User avatar
paddle
Veteran
Posts: 1392
Joined: Mon Feb 03, 2020 4:47 pm

Re: Sketcher: Can drawEdit(editCurve) draw several curves?

Post by paddle »

A small video to better see what is happening :
phpBB [video]


Not sure what is hapenning but perhaps the startAngle of endAngle gets a +M_PI
Could be due to a range of -pi pi instead of 0 2*pi or something like this
Last edited by paddle on Mon Mar 14, 2022 4:54 pm, edited 1 time in total.
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Sketcher: Can drawEdit(editCurve) draw several curves?

Post by GeneFC »

abdullah wrote: Mon Mar 14, 2022 3:26 pm I think it makes sense to rethink snapping, as there are several tools using some kind of snap (restricting angles). As far as a modifier key must be pressed, I do not think users will freak out because they cannot get closer to a point without connecting it (which sometimes is the goal)...
I am not sure quite how to interpret that comment.

We absolutely need to keep the capability to avoid snapping. I don't care whether it is a menu item or a modifier, since I would not use it often. But it is needed at times.

Adding snapping without also adding an automatic connection will greatly increase the "help me" requests on the forum. Currently the primary issue is newbies using "Snap to Grid". If every close encounter to another element creates a snap it will also create a mess.

Gene
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Can drawEdit(editCurve) draw several curves?

Post by abdullah »

GeneFC wrote: Mon Mar 14, 2022 4:52 pm
abdullah wrote: Mon Mar 14, 2022 3:26 pm I think it makes sense to rethink snapping, as there are several tools using some kind of snap (restricting angles). As far as a modifier key must be pressed, I do not think users will freak out because they cannot get closer to a point without connecting it (which sometimes is the goal)...
We absolutely need to keep the capability to avoid snapping. I don't care whether it is a menu item or a modifier, since I would not use it often. But it is needed at times.

Adding snapping without also adding an automatic connection will greatly increase the "help me" requests on the forum. Currently the primary issue is newbies using "Snap to Grid". If every close encounter to another element creates a snap it will also create a mess.
Precisely what you say. That is the reason why I was suggesting a modifier (that you need to actively press). If a checkbox in the toolwidget (which currently does not exist in master) is provided, it is kind of better than the generally hidden snap checkbox. If we go this route, then it should be default disabled. This is the kind of things that will need discussion.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Can drawEdit(editCurve) draw several curves?

Post by abdullah »

paddle wrote: Mon Mar 14, 2022 3:50 pm Is giving me a warning (even if it builds):
No suitable user-defined conversion from "std::vector<Part::Geometry*, std::allocator<Part::Geometry*>> to ...
You have to give me the whole thing so that I try to make sense out of it. I do not have a warning.
paddle wrote: Mon Mar 14, 2022 3:50 pm Also there seem to be a problem with the drawn curves (arc specially):
draw geos.png
the same with adding geometries create the expected offset
There are two observations:
a) It represents arcs where there are no arcs in the original and there are some extra lines in the offset version, even in the end result (first case). This is a little bit odd.
b) There appears to be a bug in my code (only for trimmed curves, not being linesegments).

In:

Code: Select all

std::vector<Base::Vector2d> CurveConverter::toVector2D(const Part::Geometry * geometry)
in this section:

Code: Select all

    else if ( isconic || isbounded ) {

        auto geo = static_cast<const Part::GeomConic *>(geometry);

        double segment = (geo->getLastParameter() - geo->getFirstParameter()) / curvedEdgeCountSegments;

        for (int i=0; i < curvedEdgeCountSegments; i++)
            emplaceasvector2d(geo->value(i*segment));

        // either close the curve for untrimmed conic or set the last point for bounded curves
        emplaceasvector2d(isconic ? geo->value(0) : geo->value(geo->getLastParameter()));
    }
This line:

Code: Select all

 emplaceasvector2d(geo->value(i*segment));
should read:

Code: Select all

Base::Vector3d pnt = geo->value(geo->getFirstParameter() + i*segment);
I refactored the code for open and closed curves, but I forgot the endpoint.

Let me know if that fixes it for you.
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Sketcher: Can drawEdit(editCurve) draw several curves?

Post by GeneFC »

abdullah wrote: Mon Mar 14, 2022 4:58 pm As far as a modifier key must be pressed, I do not think users will freak out because they cannot get closer to a point without connecting it (which sometimes is the goal)...
That is the part that confused me. It appears you are saying that users will not be able to approach a point as close as desired without connecting. From your follow-up I am guessing that you do not really mean that.

Gene
User avatar
paddle
Veteran
Posts: 1392
Joined: Mon Feb 03, 2020 4:47 pm

Re: Sketcher: Can drawEdit(editCurve) draw several curves?

Post by paddle »

abdullah wrote: Mon Mar 14, 2022 5:25 pm You have to give me the whole thing so that I try to make sense out of it. I do not have a warning.
Sorry I can't copy paste it so had to write it manually. So I thought I had something wrong in my command. Here's the error :
No suitable user-defined conversion from "std::vector<Part::Geometry*, std::allocator<Part::Geometry*>> to const "std::vector<Base::Vector2D, std::allocator<Base::Vector2D>>
[/quote]
Maybe it needs a whole rebuild?
abdullah wrote: Mon Mar 14, 2022 5:25 pm There are two observations:
a) It represents arcs where there are no arcs in the original and there are some extra lines in the offset version, even in the end result (first case). This is a little bit odd.
b) There appears to be a bug in my code (only for trimmed curves, not being linesegments).
Extra arcs are created by 'arc join' mode of the offset. But the problem doesn't seem to be related to those arc in particular. Though there's a problem with them too as you can see in the second example. Somehow the end points of those arcs (those create by setHandle) seem to swap randomly at some point after tool finish. But we'll see about that when we'll be working on merging it as it's still far away :)

I'll test to fix this asap see what happens.
User avatar
paddle
Veteran
Posts: 1392
Joined: Mon Feb 03, 2020 4:47 pm

Re: Sketcher: Can drawEdit(editCurve) draw several curves?

Post by paddle »

Replaced

Code: Select all

 emplaceasvector2d(geo->value(i*segment));
With

Code: Select all

emplaceasvector2d(geo->value(geo->getFirstParameter() + i * segment));
And now it's working perfectly.
Post Reply