Ticket #3787 - Can't add point to wire (v0.18)

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!
Post Reply
rschaeuble
Posts: 5
Joined: Sun Jun 24, 2018 12:26 pm

Ticket #3787 - Can't add point to wire (v0.18)

Post by rschaeuble »

Hi,

after creating a wire in the draft workbench, I'm unable to add a point to it. Whenever I try it, I get an exception in the report view.
Here's the details:

Version Info
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15656 (Git)
Build type: Release
Branch: master
Hash: a60b6957db228c42a00a1e002a415cbb8309d3c8
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)

I've tried both the "regular" x64 build as well as the Conda build, with same results.


Steps to Reproduce
  • Open FreeCAD and create new document
  • Switch to Draft workbench.
  • Create a multipoint DWire (3 points / 2 segments are enough).
  • Finish the wire by pressing "A".
  • Select the wire and press the "Edit the active object" button in the toolbar.
  • In the combo view, press the "add points" button.
  • Move the mouse over one of the segments on the DWire (it will become yellow), then press the left mouse button.
By now, a new point should have been added to the DWire. And this is exactly what happens when I try it with v0.17. However, with v0.18, the following error appears in the report view:

Code: Select all

Exception (Sun Jan 20 23:22:31 2019): In bool __cdecl Part::GeomCurve::closestParameter(const class Base::Vector3<double> &,double &) const in src\Mod\Part\App\Geometry.cpp:566 
<class 'Base.FreeCADError'>
Traceback (most recent call last):
  File "C:\Users\Rolf\Downloads\FreeCAD_0.18.15656_x64_dev_win\Mod\Draft\DraftTools.py", line 4188, in action
    self.addPoint(pt,info)
  File "C:\Users\Rolf\Downloads\FreeCAD_0.18.15656_x64_dev_win\Mod\Draft\DraftTools.py", line 4429, in addPoint
    uPoints.append(curve.parameter(p))
Base.FreeCADError: {'swhat': '', 'sfunction': 'bool __cdecl Part::GeomCurve::closestParameter(const class Base::Vector3<double> &,double &) const', 'btranslatable': False, 'sfile': 'C:\\Users\\Chris\\GitHub\\FCAutoBuild\\var\\freecad-git\\src\\Mod\\Part\\App\\Geometry.cpp', 'sclassname': 'class Base::CADKernelError', 'breported': True, 'sErrMsg': '', 'iline': 566}
I couldn't find anything about this issue in the forum or the bug tracker. Is this a known issue, or should I create a ticket in the bug tracker?

Cheers,
Rolf
Last edited by Kunda1 on Thu Sep 05, 2019 7:57 pm, edited 1 time in total.
Reason: Updated thread title with ticket number
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Can't add point to wire (v0.18)

Post by NormandC »

Hello Rolf,

I confirm the issue on

OS: Ubuntu 18.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15681 (Git)
Build type: Release
Branch: master
Hash: 79a25ff6bdea634b13536aa34c46eab3ed1cba39
Python version: 3.6.7
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: French/Canada (fr_CA)

It works as intended in

OS: Ubuntu 18.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.13541 (Git)
Build type: Release
Branch: releases/FreeCAD-0-17
Hash: 9948ee4f1570df9216862a79705afb367b2c6ffb
Python version: 2.7.15rc1
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: French/Canada (fr_CA)

rschaeuble wrote: Sun Jan 20, 2019 10:26 pm should I create a ticket in the bug tracker?
Please do.
User avatar
yorik
Founder
Posts: 13642
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Can't add point to wire (v0.18)

Post by yorik »

I can't reproduce this particular problem, but indeed there are a few strange things happening when trying to add points to a wire... Yes, please open a ticket! Thanks
rschaeuble
Posts: 5
Joined: Sun Jun 24, 2018 12:26 pm

Re: Can't add point to wire (v0.18)

Post by rschaeuble »

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

Re: Can't add point to wire (v0.18)

Post by wmayer »

I can confirm the problem.

In the error report GeomCurve::closestParameter is mentioned and for B-splines or Bezier curves this function didn't work as expected when a point cannot be projected. For that case the first or last point is used depending on which is closer to the given point. But because both curve types are not of type Geom_TrimmedCurve it raised an exception. This is fixed with git commit 041a550815e00.

After the above fix adding points still doesn't work and adding some print() statement into DratTools.py reveals why. The computed points never lie on the DWire and apparently the placement information of the DWire is lost at some point. Thus, the further computation is incorrect.
So, if you reset the placement of the DWire adding points suddenly works as expected.

Btw, I find it a bit odd to compute a B-spline curve out of a DWire to get the projection point. A DWire is a polyline (open DWire) or polygon (closed DWire) and the inner corners will never be correctly described by a B-spline curve. This results into incorrect behaviour when adding a new point close to an existing corner.

It is actually pretty simple to determine if a projected point lies within a line segment.
Let's say you have a line segment described by P1 and P2 and an arbitrary point Q.
Now image an infinite line g that goes through P1 and P2 then the parameter t (which is a float) of the projected point can be obtained with:

Code: Select all

t = (Q-P1)*(P2-P1)/((P2-P1)*(P2-P1))
If t is in the range [0,1] then it lies inside the line segment and outside otherwise. The requested point can be computed with

Code: Select all

P = (1-t)*P1 + t*P2
Now to compute the closest point to a DWire go through all line segments and check if the projection is inside and use that with the minimum distance to the given point. If no such line segment exists then determine the closest corner point.
User avatar
Moult
Posts: 321
Joined: Sat Jan 05, 2019 11:46 am
Contact:

Re: Can't add point to wire (v0.18)

Post by Moult »

I have been experiencing very strange results with trying to add a point to an existing wire, closed or not. I've rewritten the code to be less complex and simply detect the edge you click on and add a point there instead of doing some match nearest sorted parameter location on the curve. I find that with this code my results are much more reliable.

PR here:
https://github.com/FreeCAD/FreeCAD/pull/1935
I also blog about 3D rendering, architecture, software and other on thinkMoult.com. RSS / Atom feed available for your convenience.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ticket #3787 - Can't add point to wire (v0.18)

Post by Kunda1 »

What's the status of issue #3787 ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply