automated hover symmetrical constraint

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
michav
Posts: 52
Joined: Mon Sep 09, 2019 7:34 am

automated hover symmetrical constraint

Post by michav »

Developers,
I want to develop a feature of automated hover symmetrical contstraint,
inside sketcher
if there is a line or curve already drawn (line A), and the user wants to add an additional line or curve (Line B)
if the user's tool tip hovers close enough to the center of line A, I want to suggest a symmetrical constraint.
upon sketching Line B, it should snap to the center point of Line A and establish a symmetrical constraint.

there are already a number of automated hover constraints available including coincident, point on object, vertical, horizontal, concentric ...
this is available in solid works and was always my most used feature in order to help make symmetrical parts.

Some questions:
a. if I work on this feature, would the freecad community accept it?
b. how do you guys suggest that I implement, (given that this sort of thing is very common in FREECAD)

thanks!
-micha
User avatar
NewJoker
Veteran
Posts: 3089
Joined: Sun Oct 11, 2020 7:49 pm

Re: automated hover symmetrical constraint

Post by NewJoker »

michav wrote: Sat May 07, 2022 7:38 pm a. if I work on this feature, would the freecad community accept it?
I'm sure that it would be highly appreciated by many users. For me, it's one of the largest potential improvements of the sketcher waiting for the implementation.

This was already discussed briefly here: https://forum.freecadweb.org/viewtopic. ... 0&start=10

and here: https://forum.freecadweb.org/viewtopic.php?f=8&t=59890

but there are no works on that at the moment.

michav wrote: Sat May 07, 2022 7:38 pm b. how do you guys suggest that I implement, (given that this sort of thing is very common in FREECAD)
Let's start with the fact that the Draft workbench offers a similar feature. It's called snap and several other types are available (like snap to center). However, in the Sketcher the nomenclature is different. The feature that allows you e.g. to constrain points together and make lines vertical/horizontal with proper placement of the cursor is called an auto constraint. Unfortunately, it doesn't support several important constraints such as the symmetry one mentioned here. It doesn't detect centers of objects like rectangles too but that could be partially replaced with automatic symmetry constraint for now. Anyway, if you want to implement the auto symmetry constraint (which is really great), I think that you should start by examining the part of the source code responsible for existing auto constraints. Likely some pieces of this code are what you will need: https://github.com/FreeCAD/FreeCAD/blob ... andler.cpp
chrisb
Veteran
Posts: 54273
Joined: Tue Mar 17, 2015 9:14 am

Re: automated hover symmetrical constraint

Post by chrisb »

Abdullah is the grand master of Sketcher. Let's hear his advice.
Abdullah wrote:ping
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
adrianinsaval
Veteran
Posts: 5552
Joined: Thu Apr 05, 2018 5:15 pm

Re: automated hover symmetrical constraint

Post by adrianinsaval »

It probably will be useful for some situations but keep in mind that T joints are not allowed for many sketch based features.
User avatar
NewJoker
Veteran
Posts: 3089
Joined: Sun Oct 11, 2020 7:49 pm

Re: automated hover symmetrical constraint

Post by NewJoker »

adrianinsaval wrote: Sun May 08, 2022 3:56 pm It probably will be useful for some situations but keep in mind that T joints are not allowed for many sketch based features.
Yes, but construction lines placed this way are often helpful.
User avatar
paddle
Veteran
Posts: 1413
Joined: Mon Feb 03, 2020 4:47 pm

Re: automated hover symmetrical constraint

Post by paddle »

This has been discussed indeed and is a welcome addition.
So there are 2 aspects to this:

1 - The autoconstraint (what you called hover constraint). For this I'm not familiar with the current code so I don't know how to implement it. Looking at the auto constraint code should shed some light on it. It shouldn't be too hard to follow the current auto constraint code logic to replicate for this case.

2 - The snapping into position. And more largely snapping to objects in general. This is basically overridding the position of the mouse when close to an object.
This snapping feature (snap to object and snap 5 degree) has already been developped and is waiting merging. Adding the special case of snapping to the center of lines will be easy to do.

To give more details about merging : We're currently working with Abdullah on a development branch called "paddle_widget" to merge tool settings widget. On this branch many tools have been reimplemented in the new code framework. While working on this I made the snap feature but it has not yet been merged to paddle_widget because Abdullah wants to finish work on the tool settings first before adding snap.

So long story short, snap will be merged sooner or later and adding line middle is no problem for me.

So you can focus on the autoconstraint task.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: automated hover symmetrical constraint

Post by abdullah »

chrisb wrote: Sat May 07, 2022 9:34 pm Let's hear his advice.
Little coding should support a symmetric autoconstraint in the master framework. It is more about looking into ensuring that it does not interfere with other autoconstraints. This is specially the case if the autoconstraint only has two objects (one in the sketch and the new one to be created). For a more general symmetric autoconstraint three objects are necessary (two preexisting + new one). This would require to extend the autoconstraint framework as only two objects are currently supported.

If the code is clean, I would either merge it into master or to the paddle_widget branch on which we are working (and then from there to master). This depends on the amount of conflict that this work and the paddle_widget work would generate. If there is no conflict, it will go directly into master.

So, yes, please, go ahead.

Some heads-up. Look here:
https://github.com/FreeCAD/FreeCAD/blob ... dler.h#L93

and here:
https://github.com/FreeCAD/FreeCAD/blob ... r.cpp#L492

and here:
https://github.com/FreeCAD/FreeCAD/blob ... r.cpp#L761
Post Reply