Sketcher: Ellipse support

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!
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Sketcher: Ellipse support

Post by jmaustpc »

abdullah wrote:Jim. You definitely want to check this out... when you are home and have time...
OK, will do.

abdullah wrote:I do not want to make this go much longer. The longer it goes the more complicated it gets, more code, and much more work for Werner to review at once, and higher chance of divergence from master.

Specifically: Any solver improvements shall be made the subject of a separate topic.
I must admit that I have been thinking along those lines for a while. Without understanding any technical issues, I would think it is best to get the basics of your work into master and then have these "extra" methods etc. worked on and then added to master as separate issues, if that makes sense at a coding level.

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

Re: Sketcher: Ellipse support

Post by abdullah »

jmaustpc wrote:I must admit that I have been thinking along those lines for a while. Without understanding any technical issues, I would think it is best to get the basics of your work into master and then have these "extra" methods etc. worked on and then added to master as separate issues, if that makes sense at a coding level.
I wanted to it earlier. But everytime I have tried to push the last line, new issues have appeared (which is good, because it needs to work properly from the user perspective). Then my last push was suddenly interrupted by this work peak...

Putting DeepSOIC's constraint aside for a second. In my current list sits the following:

OPEN ISSUES
===========
1. DeepSOIC's comment on Mark's construction method above
2. Possible centralization of code for internal geometry (separate implementation to be included in both CreoGeo and Constraints or python command). This can allow tangency to ellipse on creation again...
3. Jim's observation of autoconstraints (see above)
4. Ellipse dragged by center when intended dragged by edge

So, I depend on Mark for the fixing whatever needs fixing in the construction methods of Ellipse and ArcOfEllipse, with the exception of autoconstraints, that come in a separate package.

I need to do 2 myself. But I need some hours in a row in front of the computer (now I am jumping from one task to another). If I manage to do something good out of 2, 3 should be easy.

Then I will have to fight with you, dear users, about 4...

I hope I will manage to use some time for this during the next week...
User avatar
bejant
Veteran
Posts: 6075
Joined: Thu Jul 11, 2013 3:06 pm

Re: Sketcher: Ellipse support

Post by bejant »

I've been following the thread, and there's a lot I don't understand, but this jumped out at me:
abdullah wrote:9. In src/Mod/Sketcher/Gui/CommandConstraints.cpp:

- This may be the reason for those in point 6 above. If you want to see if a point is on the object, why do not look if there is a constraint point on object between point and object? I really dislike mixing UI and solver. To me they should belong to almost totally independent sets of code, with the minimum dependence among them.
Does this make FreeCAD dependent on the GUI?
Shouldn't FreeCAD be able to run without it?
(Please forgive my coding ignorance by asking what may be obvious to a coder...)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Sketcher: Ellipse support

Post by DeepSOIC »

abdullah wrote:1. I hate labels in c++.
Just delete them. I was a bit of hacking into the existing code, it is worth reformatting a bit. I just tried to kill one of the two equal hard-coded messageboxes.
2. I hate reusing fields for a purpose different of what they were designed (and named for). This is the case of: src/Mod/Sketcher/App/ConstraintPyImp.cpp:
The fields of the constraint structure are used as intended. These are the python arguments assigned to C variables with irrelevant names. Otherwise, this requires the whole reformatting of the if(parsetuple(..."siiiO"...)){...} Well, maybe I just didn't find the right place.. Actually I had a temptation to completely rewrite the whole python implementation there, making it to start from getting the constraint name and doing argument parsing afterwards. Feel free to do whatever you want with it.
4. ... Maybe (I am not sure), less code can be repeated by making the last parameter of addAngleViaPointConstraint default to 0.
Not really useful because angle=0 is not just any tangency, it is internal tangency. But yes, it can be done, I just didn't feel the need for it.
6. About "SketchObject.cpp". Why do we need those functions? who calls them? Maybe I am totally off. But at this moment, I do not see it. Help me understand.
This one is important, and yes, 9 is related. For the constraint to work properly, the point must be on both curves. So we need to add necessary point-on-curve constraints without causing redundancy.
Testing if there already is a point-on-object constraint doesn't really solve the problem, because the point might be forced onto object in more complex ways, for example:
* the point is coincident to a point that is on the object (e.g. when selecting an endpoint of the line which was previously made coincident to an endpoint of an ellipse arc)
* the point might be an endpoint of an internal-aligned major diameter, which is on an ellipse but is not a point-on-object
* due to a complex action of a number of other constraints
This is also the reason for a repeated test for point on object1: if the point was on curve by accident, it could have been pulled off object1 when it was being constraining onto object2.
There is also an important decision to expose those autoadded point-on-object constraints. It was done to be able to manually resolve a redundancy in case this smart detection system does it the wrong way. It is also important to make saving/loading of files independent of this smartness.
7.... i. You are basing your implementation in: controlling a remap (via the remapped boolean), so as to "reconstruct" the object, you make copies of the curve objects. Why do you need a copy of the curves? Why do not you use a pointer assignment instead? I may not understand all that you are doing here, so go easy on me ;-)
This is also very important. I assumed (but didn't really check) that remap is called from within solver (to account for simplification of parameters vector done during system analysis for example). I don't like the idea of unexpectedly messing with objects that were passed by reference, this is why a copy is needed.
8. A new Vector2D implementation in src/Mod/Sketcher/App/freegcs/Geo.h
Just do it. I only warn you that I have made a method getNormalized which doesn't exist in the available implementations, so some change will be necessary in calculateNormal in ellipse and maybe (I don't remember) in the constraint. (there is a more invasive normalize() method in existing 2d vector, which changes the underlying vector instead of creating a new one)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Sketcher: Ellipse support

Post by DeepSOIC »

bejant wrote:
abdullah wrote:why do not look if there is a constraint point on object between point and object? I really dislike mixing UI and solver. To me they should belong to almost totally independent sets of code, with the minimum dependence among them.
Does this make FreeCAD dependent on the GUI?
Shouldn't FreeCAD be able to run without it?
(Please forgive my coding ignorance by asking what may be obvious to a coder...)
FreeCAD should be able to run without gui perfectly fine, except that adding angle-via-point constraint must be accompanied by (manual) addition of necessary point-on-object constraints.
EDIT: it can be useful to expose the isPointOnObject function to python.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Ellipse support

Post by abdullah »

DeepSOIC wrote:
bejant wrote:
abdullah wrote:why do not look if there is a constraint point on object between point and object? I really dislike mixing UI and solver. To me they should belong to almost totally independent sets of code, with the minimum dependence among them.
Does this make FreeCAD dependent on the GUI?
Shouldn't FreeCAD be able to run without it?
(Please forgive my coding ignorance by asking what may be obvious to a coder...)
FreeCAD should be able to run without gui perfectly fine, except that adding angle-via-point constraint must be accompanied by (manual) addition of necessary point-on-object constraints.
EDIT: it can be useful to expose the isPointOnObject function to python.
No part of FreeCAD commandline depends on GUI. This I confirm here.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Ellipse support

Post by abdullah »

@DeepSOIC

I really really hope you are not mad at me.

Currently I have very scarce time available. I think this code needs some reworking. But that is just my opinion. In normal time availability I would myself rework it, show it to you, and we could decide. But currently I can not.

I propose:
1. We do the minimum required for pushing Ellipse into master.
2. When that is done and I have some more time available, we revisit this and prepare it for master as a separate commit.

or alternatively, if you so wish, after 1 is in master, you can try to get this merged into master without my intervention (your code, your choice, your rules).

I really think your work is worth to be in master. I think it might help make more robust sketches (see notes by Jim at the beginning of this thread), and I really hope you will still want to cooperate with me in the future for hyperbola and parabola and other topics.

Regards,
Abdullah
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Sketcher: Ellipse support

Post by DeepSOIC »

Ok, I'll polish my code a bit and finish the ui stuff in the meantime, after my quick vacation is over. All I really needed actually was some overall acceptance (thanks =), before potentially wasting more time completing the thing. What I did was the essence - the functional part. Thanks for pointing out that nullptr is not recognized by Linux compiler (gcc?).
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Ellipse support

Post by abdullah »

DeepSOIC wrote:Ok, I'll polish my code a bit and finish the ui stuff in the meantime, after my quick vacation is over. All I really needed actually was some overall acceptance (thanks =), before potentially wasting more time completing the thing. What I did was the essence - the functional part. Thanks for pointing out that nullptr is not recognized by Linux compiler (gcc?).
My acceptance as functionality, you have. It is a very flexible constraint concept. I believe it will be of much use for users, specially the advance ones. The code will take shape, this for sure. After the rework, I think it would be useful to start a new thread and discuss it with the users. Take their feedback. It will be great!! :)

Yes, the compiler is gcc. There might be some header that can be added to make it work. I have seen this in no other part of FreeCAD, so I use 0. But I only know a small part of FreeCAD...

Thanks for your understanding.
Abdullah
User avatar
bejant
Veteran
Posts: 6075
Joined: Thu Jul 11, 2013 3:06 pm

Re: Sketcher: Ellipse support

Post by bejant »

abdullah wrote:BTW. Those who like to test:
Thanks! I've been using it only a little bit but haven't hit any snags, so I'm eagerly awaiting the arrival into master!
20141109a_ellipse.png
20141109a_ellipse.png (9.04 KiB) Viewed 1739 times
abdullah wrote:I think it would be useful to start a new thread and discuss it with the users. Take their feedback. It will be great!!
I think so too; then you won't have me bugging you here :lol:
Post Reply