[pull requested] Sketcher: New Features: Symmetry, Copy and 2D Array transformations

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

[pull requested] Sketcher: New Features: Symmetry, Copy and 2D Array transformations

Postby abdullah » Sat Jul 18, 2015 5:17 pm

Hi folks,

I have been coding in breaks lately.

Because I can not engage in long meaningful discussions of important topics (like the solver ones), I have started coding some of the features I would like to see in the sketcher. Creation of symmetric elements (together with copy in sketcher and array in sketcher) is one of them and the subject of this post.

What is this?
It creates the geometric elements (and constraints) symmetric to the selected ones with respect to the last selected line (axis) or point.

What is the status?
Practically untested. I am using an old slow laptop 32 bits with limited memory, extra slow and it goes out of memory when debugging after stalling while swapping...

What do I seek?
- Show the feature. Let you play with it. I am sure you will come with problems and change requests and other ideas... ;)
- An icon?

What can you expect from me?
- I will read the forum (provided I have time, I have had it so far).
- I will try to participate in the discussion (provided I have time).
- You can not expect the usual "tomorrow is solved" at this time.

Example?
sketcher_symmetry_tool.png
sketcher_symmetry_tool.png (23.45 KiB) Viewed 1742 times
So, I created the left side, selected everything with a box selection (it is programmed to ignore the extra vertex belonging to the edges), unselected the "origin" (that gets selected with the box), selected the vertical axis, and hit that beautiful cross showing that no icon is available. Then I got the right part.

Does it support all the constraints?

No, directional constraints (angle, distanceX, distanceY, SnellLaw), tend to break the symmetry and I have not found a nice way of handling them (yet?). The rest should more or less work, report any misbehaving.

The code is in here:
https://github.com/abdullahtahiriyo/Fre ... 687c901a55
Last edited by abdullah on Thu Aug 20, 2015 8:36 pm, edited 2 times in total.
triplus
Posts: 8839
Joined: Mon Dec 12, 2011 4:45 pm

Re: [ALPHA testing, user input] Sketcher: New Feature: Add Symmetric elements

Postby triplus » Sun Jul 19, 2015 4:10 pm

I see new set of tools used for creating symmetry and transformations on existing geometry. No relations are added like when adding constraints but creating symmetric geometry, geometry copies or geometry arrays becomes faster.

I tested symmetry and it does the job as described. As for the icons i am guessing this will be on new toolbar? For example Transform geometry. Therefore i am guessing the design will need to differ compared to constraint icons.
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

Re: [ALPHA testing, user input] Sketcher: New Feature: Add Symmetric elements

Postby abdullah » Mon Jul 20, 2015 3:13 am

triplus wrote:I see new set of tools used for creating symmetry and transformations on existing geometry. No relations are added like when adding constraints but creating symmetric geometry, geometry copies or geometry arrays becomes faster.
Yes, good summary!! :D

There is an additional use case that was the one that motivated the creation of this symmetry tool. Imagine you have an "almost symmetric" part (like this one viewtopic.php?f=3&t=11533#p92816). You can not use the Part Design symmetry because they are not fully symmetric. In a good implementation this should be one click away.
triplus wrote:I tested symmetry and it does the job as described.
Maybe you were lucky ;)

I mean, it does what it says to my knowledge, but I am still struggling to shape the tool.

The original implementation did a mere copy of geometric elements without constraints and worked flawlessly in all cases I tried. But I see little use (or maybe better said less convenience) if constraints are not copied.

The second implementation did copy all the constraint types (constraints that involved only elements under the symmetric transformation), but this messed up the geometry mainly because the directional nature of some constraints (so I removed them from the constraint copy process leading to the current implementation, the third).

There are still some cases where constraint addition leads to very unexpected results, for example this symmetry about the origin:
wrong_symmetry.png
wrong_symmetry.png (17.81 KiB) Viewed 1667 times
Here you have the file if you wanna try:
symmetry_trial.fcstd
(5.04 KiB) Downloaded 34 times
Therefore I am thinking of a way of letting the user control whether constraints should be copied at all or not. But this would involve asking things to the user (with pop ups which I wanted to avoid). In fact in the original conception, there was an extra symmetry constraint to "lock" the symmetry in place and the user was asked, but I disposed this idea because the user can always add just an extra symmetry constraint after executing the command.

Anyway, I would appreciate some more user input in this aspect.
triplus wrote:As for the icons i am guessing this will be on new toolbar? For example Transform geometry. Therefore i am guessing the design will need to differ compared to constraint icons.
I was not thinking of creating a new toolbar, although I have nothing against it. As of today only symmetry is implemented and is in the Sketcher tools toolbar:
currentlocationicons.png
currentlocationicons.png (9.24 KiB) Viewed 1667 times
I tend not to give an opinion on icon design as I am severely handicap from the artistic point of view. I am happy with what you guys decide :)
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

Re: [ALPHA testing, user input] Sketcher: New Feature: Add Symmetric elements

Postby abdullah » Mon Jul 20, 2015 3:19 am

And just discussing this with you made me realize of a bug. I failed to remove the vertical/horiz constraints when it involved a single element (on a line instead of on two points). The same example as in the previous post, when changing those vert/horiz constraints with length constraints:
good_symmetry.png
good_symmetry.png (19.48 KiB) Viewed 1667 times
triplus
Posts: 8839
Joined: Mon Dec 12, 2011 4:45 pm

Re: [ALPHA testing, user input] Sketcher: New Feature: Add Symmetric elements

Postby triplus » Tue Jul 21, 2015 9:01 pm

The way i see it if you can't fix "constraint issues" or at least until then transformations should only be used on sketcher geometry for now. I could be wrong but i am guessing transforming geometry is easier in Draft WB exactly because of the lack of constraints.

You said by using only sketcher geometry you get better results and maybe that is a good starting point for now.
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

Re: [ALPHA testing, user input] Sketcher: New Feature: Add Symmetric elements

Postby abdullah » Wed Jul 22, 2015 4:44 pm

It seems to work ok after the fix. I will look into any case where it misbehaves if somebody makes me aware.

I am not thinking of changing the implementation unless I receive new input.

Is this auto-mirroring as described here?:
viewtopic.php?f=10&t=10870#p87406

I guess it is mirroring as described in here:
viewtopic.php?f=10&t=11130#p89558

I have not had time to code since that previous bug fix.

That same day I implemented linear 2D arrays and copy as python commands (it is already in github), but no UI commands are available yet (this works fine as far I gave tested).

I plan to make the UI commands next time I have time for FC.

Thanks for your feedback triplus. :)
triplus
Posts: 8839
Joined: Mon Dec 12, 2011 4:45 pm

Re: [ALPHA testing, user input] Sketcher: New Feature: Add Symmetric elements

Postby triplus » Thu Jul 23, 2015 12:21 pm

abdullah wrote:It seems to work ok after the fix. I will look into any case where it misbehaves if somebody makes me aware.
I was thinking in this direction:
No, directional constraints (angle, distanceX, distanceY, SnellLaw), tend to break the symmetry and I have not found a nice way of handling them (yet?). The rest should more or less work, report any misbehaving.
Anyway about:
I am not thinking of changing the implementation unless I receive new input.
I am fine with that.
and copy as python commands
Will this be a separate tool on toolbar or implemented as Edit -> Copy?

I am asking as today i have some spare time and will try to do icon you asked for. I am wondering if i should do one for linear pattern and copy. Should this be general array icon like in Draft Array or will you implement more array tools and each should have different icon?
abdullah
Posts: 3174
Joined: Sun May 04, 2014 3:16 pm

Re: [ALPHA testing, user input] Sketcher: New Feature: Add Symmetric elements

Postby abdullah » Thu Jul 23, 2015 8:38 pm

@triplus

In principle it will be a separate icon in the toolbar. It may be possible to assign ctrl-C as shortcut. I am still thinking about how it will work exactly.

Originally I only considered 2d linear arrays, but I might implement polar arrays, specially if there is demand for it...

I may also consider an offset tool, as there is demand, but I have to learn to use the one in draft first. ;)

Thanks for offering to make icons. :D
triplus
Posts: 8839
Joined: Mon Dec 12, 2011 4:45 pm

Re: [ALPHA testing, user input] Sketcher: New Feature: Add Symmetric elements

Postby triplus » Fri Jul 24, 2015 12:01 am

OK this is what i made. I reused available icons in FreeCAD as much as possible.
Sketcher_Symmetry.png
Sketcher_Symmetry.png (2.79 KiB) Viewed 1466 times
And i made icons for everything you mentioned you might do:
Sketcher_LinearPattern.png
Sketcher_LinearPattern.png (398 Bytes) Viewed 1466 times
Attachments
Sketcher_LinearPattern.svg
(2.61 KiB) Downloaded 91 times
Sketcher_Symmetry.svg
(7.04 KiB) Downloaded 114 times