View Issue Details

IDProjectCategoryView StatusLast Update
0003787DraftBugpublic2019-11-12 23:18
Reporterrschaeuble Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status confirmedResolutionopen 
Platformx64OSWindowsOS Version10
Product Version0.18 
Target Version0.19Fixed in Version 
Summary0003787: Can't add point to wire
DescriptionAfter 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:
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}

Forum entry: https://forum.freecadweb.org/viewtopic.php?f=3&t=33622
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.
Additional InformationVersion 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.
TagsNo tags attached.
FreeCAD Information

Activities

Kunda1

2019-09-05 19:58

administrator   ~0013536

@wmayer writes:


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 [commit]041a550815e00[/commit].

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:


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

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.

wmayer

carlopav

2019-11-12 23:15

developer   ~0013824

I made quite a lot of changes to draft edit since that version. Is it working as expected in 0.19?

Issue History

Date Modified Username Field Change
2019-01-21 18:57 rschaeuble New Issue
2019-09-05 19:58 Kunda1 Note Added: 0013536
2019-09-05 19:58 Kunda1 Status new => confirmed
2019-09-05 19:58 Kunda1 Target Version => 0.19
2019-11-12 23:15 carlopav Note Added: 0013824