Can't use named constraints in 0.20 202112202219

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Can't use named constraints in 0.20 202112202219

Post by TheMarkster »

Interestingly, the Animator macro is able to find the named constraints and animate them via python.
User avatar
mfraz74
Posts: 158
Joined: Mon Apr 05, 2021 9:19 am
Contact:

Re: Can't use named constraints in 0.20 202112202219

Post by mfraz74 »

chrisb wrote: Tue Dec 21, 2021 11:12 pm Put the Python code in code tags for improved readability. You can for further improvement copy only the code, without the leading ">>>".
Edited.
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Can't use named constraints in 0.20 202112202219

Post by Syres »

As promised I carried out the Git Bisect work and determined the regression was caused by git commit 2db73c0. I'm presently recompiling the very latest master to ensure the issue is still present, I'm struggling to understand how it would be fixed without changing the ObjectIdentifier.cpp but C++ is by no means my strong point.
chrisb
Veteran
Posts: 53945
Joined: Tue Mar 17, 2015 9:14 am

Re: Can't use named constraints in 0.20 202112202219

Post by chrisb »

mfraz74 wrote: Wed Dec 22, 2021 7:41 am Edited.
Thanks! To be clear: You don't have to remove the prefixes manually, if you use "Copy command" in the Python console's context menu.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Can't use named constraints in 0.20 202112202219

Post by Syres »

As I assumed updating to the latest master hasn't fixed the issue.

OS: Linux Mint 19.3 (X-Cinnamon/cinnamon)
Word size of FreeCAD: 64-bit
Version: 0.20.26761 (Git)
Build type: Release
Branch: master
Hash: b0fc0ab0f4cfea326e047ac3166426e98d5e115f
Python version: 3.6.9
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)


wmayer wrote: ping
Sorry to trouble you Werner, but could you please have a look at the report at the start of this topic with relation to git commit 2db73c0

Is it a real regression or has this shone a light on something else being incorrect?
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Can't use named constraints in 0.20 202112202219

Post by realthunder »

I have submitted a PR for this.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Can't use named constraints in 0.20 202112202219

Post by Syres »

Thanks @realthunder
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Can't use named constraints in 0.20 202112202219

Post by wmayer »

Syres wrote: Wed Dec 22, 2021 9:46 am Sorry to trouble you Werner, but could you please have a look at the report at the start of this topic with relation to git commit 2db73c0

Is it a real regression or has this shone a light on something else being incorrect?
Sorry for the regression and thanks for the fix! :oops:

Recently we have seen this one crash reported by chrisb where chennes has found the reason for and provided a fix: git commit b1beadd2e95b442
Nobody of the Linux testers could reproduce the crash because when assigning a null pointer to a std::string it throws an exception (a sub-type of std::exception) instead of causing a segmentation fault. After studying the error analysis I could reproduce the problem and also realized why the exception didn't show up. The calling instance used a catch(...) block that silently suppressed any kind of exception without reporting it. This makes it nearly impossible to find possible bugs inside the invoked functions in a try/catch(...) block.

In general, catch(...) blocks must be used with care because using them just out of laziness they harm rather than help.

Before committing my change I have checked the commit when the catch(...) has been added if there is an explanation for it. Because I didn't find any hint and neither by doing some simple tests nor by running the unit tests it entered the catch(...) block I decided to remove it.

After applying the PR we also have to write a unit test to avoid such a regression in the future.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Can't use named constraints in 0.20 202112202219

Post by wmayer »

This is a short example that can be used for the unit tests:

Code: Select all

doc = App.newDocument()
sketch = doc.addObject('Sketcher::SketchObject','Sketch')

geoList = []
geoList.append(Part.LineSegment(App.Vector(0,5,0),App.Vector(5,5,0)))
geoList.append(Part.LineSegment(App.Vector(5,5,0),App.Vector(5,0,0)))
geoList.append(Part.LineSegment(App.Vector(5,0,0),App.Vector(0,0,0)))
geoList.append(Part.LineSegment(App.Vector(0,0,0),App.Vector(0,5,0)))
sketch.addGeometry(geoList,False)

conList = []
conList.append(Sketcher.Constraint('Coincident',0,2,1,1))
conList.append(Sketcher.Constraint('Coincident',1,2,2,1))
conList.append(Sketcher.Constraint('Coincident',2,2,3,1))
conList.append(Sketcher.Constraint('Coincident',3,2,0,1))
conList.append(Sketcher.Constraint('Horizontal',0))
conList.append(Sketcher.Constraint('Horizontal',2))
conList.append(Sketcher.Constraint('Vertical',1))
conList.append(Sketcher.Constraint('Vertical',3))
sketch.addConstraint(conList)
del geoList, conList

length = sketch.addConstraint(Sketcher.Constraint('Distance',0,6.0)) 
height = sketch.addConstraint(Sketcher.Constraint('Distance',3,5.0)) 

sketch.renameConstraint(length, u'Length')
sketch.setExpression('Constraints[{}]'.format(height), u'.Constraints.Length')
git commit 53f24f4bc2
drmacro
Veteran
Posts: 8872
Joined: Sun Mar 02, 2014 4:35 pm

Re: Can't use named constraints in 0.20 202112202219

Post by drmacro »

It doesn't appear to work in this build, has it been merged?

OS: Debian GNU/Linux 10 (buster) (XFCE/lightdm-xsession)
Word size of FreeCAD: 64-bit
Version: 0.20.26762 (Git)
Build type: Release
Branch: master
Hash: 1653d26ffa0b35d57fc3325c18bf5b7bad515703
Python version: 3.7.3
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Post Reply