General question about freecad invalid objects

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
PaulG
Posts: 37
Joined: Mon Feb 25, 2019 5:38 pm

General question about freecad invalid objects

Postby PaulG » Tue May 21, 2019 2:53 pm

It seems to me to be a mistake to return an object which is not valid, and especially not to signal it with an error or warning. I would think returning None and signalling an error would be more usual when an invalid object results. Since this seems to be a feature of freecad, I'm wondering if there is a design consideration that makes it necessary to return a not valid object and no signal?
[The context where I'm finding this is python scripting with the TopoShape method revolve().]
vocx
Posts: 3921
Joined: Thu Oct 18, 2018 9:18 pm

Re: General question about freecad invalid objects

Postby vocx » Tue May 21, 2019 5:52 pm

PaulG wrote:
Tue May 21, 2019 2:53 pm
...
[The context where I'm finding this is python scripting with the TopoShape method revolve().]
Please provide a complete example of what you are talking about. People cannot guess what you are doing to create the invalid objects you talk about.
Always add the important information to your posts if you need help.
To support the documentation effort, and code development, your donation is appreciated: paypal.
PaulG
Posts: 37
Joined: Mon Feb 25, 2019 5:38 pm

Re: General question about freecad invalid objects

Postby PaulG » Tue May 21, 2019 6:14 pm

Your response suggests this is not a commonly recognized behaviour. If that's correct then this may be a bug rather than expected. One example is discussed on this thread https://forum.freecadweb.org/viewtopic.php?f=22&t=36282 the last few days. I'm working through more details but am trying to understand whether I'm looking at a bug or a design feature.
PaulG
Posts: 37
Joined: Mon Feb 25, 2019 5:38 pm

Re: General question about freecad invalid objects

Postby PaulG » Tue May 21, 2019 9:34 pm

[using 0.18.1 and 0.19R16786 on Mint 18.1 xenial with python 2.]
Here are a few quick examples where a not valid object is returned but there is no warning or error thrown.

Code: Select all

import Part
from FreeCAD import Base
V= Base.Vector

r3 =Part.Circle().toShape().revolve(V(0,0,0),V(1,0,0), 180)
r3.isValid()  #False

r4 =Part.Circle().toShape().revolve(V(0,0,0),V(0,1,0), 180)
r4.isValid()  #False

zc =Part.Point(V(10,0,0)).toShape().revolve(V(0,0,0),V(0,0,1),360)
zs = zc.revolve(V(0,0,0),V(1,0,0), 180) 
zs.isValid()  #False
Do you think of it as normal to return an object like this that is not valid, and not throw an exception?
mlampert
Posts: 1462
Joined: Fri Sep 16, 2016 9:28 pm

Re: General question about freecad invalid objects

Postby mlampert » Tue May 21, 2019 10:59 pm

PaulG wrote:
Tue May 21, 2019 9:34 pm
Do you think of it as normal to return an object like this that is not valid, and not throw an exception?
if you wanted to fix your shape this is the kind of behaviour you want - so, yes, I do think this is normal/the better approach than just throwing an exception.
PaulG
Posts: 37
Joined: Mon Feb 25, 2019 5:38 pm

Re: General question about freecad invalid objects

Postby PaulG » Wed May 22, 2019 1:28 am

mlampert wrote:
Tue May 21, 2019 10:59 pm
if you wanted to fix your shape this is the kind of behaviour you want - so, yes, I do think this is normal/the better approach than just throwing an exception.
Ok, now I'm confused about two things, the first is a real newbie question. Do you distinguish "fix your shape" from re-doing the last operation with better parameter choices to get your shape, and if so, how? The second is more about the program structure of freecad. Why can you not return an object that is not valid and also throw an exception (warning)?
mlampert
Posts: 1462
Joined: Fri Sep 16, 2016 9:28 pm

Re: General question about freecad invalid objects

Postby mlampert » Wed May 22, 2019 3:58 am

PaulG wrote:
Wed May 22, 2019 1:28 am
Ok, now I'm confused about two things, the first is a real newbie question. Do you distinguish "fix your shape" from re-doing the last operation with better parameter choices to get your shape, and if so, how?
That depends on the algorithm and where and when it broke doing what. Sometimes changing parameters to a function is the route to success, sometimes you have to change the approach and sometimes there's just nothing that can be done.
Why can you not return an object that is not valid and also throw an exception (warning)?
It can only be one of the two, either the function returns or it throws an exception.
PaulG
Posts: 37
Joined: Mon Feb 25, 2019 5:38 pm

Re: General question about freecad invalid objects

Postby PaulG » Wed May 22, 2019 3:34 pm

mlampert wrote:
Wed May 22, 2019 3:58 am
That depends on the algorithm and where and when it broke doing what. Sometimes changing parameters to a function is the route to success, sometimes you have to change the approach and sometimes there's just nothing that can be done.
But don't those all mean starting the last operation over, or maybe even things before it? I am trying to understand a situation where you would actually want the result (the not valid object) from an algorithm. That is, an example where you actual fix the object rather than fixing the process that produced it.

mlampert wrote:
Wed May 22, 2019 3:58 am
Why can you not return an object that is not valid and also throw an exception (warning)?

It can only be one of the two, either the function returns or it throws an exception.
That is true for an error exception, but I think not for a warning. I'm pretty sure you can raise a warning and also return a result.
PaulG
Posts: 37
Joined: Mon Feb 25, 2019 5:38 pm

Re: General question about freecad invalid objects

Postby PaulG » Wed May 22, 2019 4:39 pm

PaulG wrote:
Wed May 22, 2019 3:34 pm
But don't those all mean starting the last operation over, or maybe even things before it? I am trying to understand a situation where you would actually want the result (the not valid object) from an algorithm. That is, an example where you actual fix the object rather than fixing the process that produced it.
Ok, I figured this out. I didn't understand recompute(). You can actually go back and edit the underlying object and the generated object gets reconstructed and changed from not valid to valid.

But i'm still not sure if there is a reason for not raising a warning. The GUI model tree displays what amounts to a warning flag, I guess coming from the isValid() value. Would a work flow sometimes involve generating a model with not valid objects and then adjusting some primary objects until the model objects all became valid? If so, warning messages could be unnecessarily annoying.
Jee-Bee
Posts: 2011
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: General question about freecad invalid objects

Postby Jee-Bee » Wed May 22, 2019 6:02 pm

I person prefer a fail above a warning.

I am hired for a few months to another company who using another CAD software as i'm used too. With tons of warning messages and other messages.
I'm becoming tiered of it...