Sketcher bug?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
nahshon
Posts: 192
Joined: Wed Jul 24, 2013 8:06 pm

Sketcher bug?

Postby nahshon » Fri Aug 22, 2014 4:34 pm

I have experienced some cases where FreeCAD became non-responsive when editing a sketch.
Attached is a small example containing a sketch that cannot be resolved.

When I try to move any geometry in the sketch I'm getting a message "Unhandled exception in ViewProvider::eventCallback: Not able to move point with the id and type: (0, 0)".

After the error, the sketcher remains in DragPoint / DragCorve mode. It will make more attempts to resolve the sketch on any mouse move. This may take a long time for more complex sketches!

-- Itai
invalid.fcstd
(3.1 KiB) Downloaded 59 times
jmaustpc
Posts: 9619
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Sketcher bug?

Postby jmaustpc » Fri Aug 22, 2014 5:16 pm

I can confirm this in FreeCAD built from master today, on Linux.


OS: Kubuntu 14.04.1 LTS
Word size: 64-bit
Version: 0.15.3915 (Git)
Branch: master
Hash: 539e2d2f3326dc0f9532f05eca8fb7015a6d2987
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
SoQt version: 1.6.0a
OCC version: 6.7.1 OCE from their master branch
ulrich1a
Posts: 1920
Joined: Sun Jul 07, 2013 12:08 pm

Re: Sketcher bug?

Postby ulrich1a » Sat Aug 23, 2014 12:29 pm

The sketch is problematic. The last constraint is asking for an coincidence of the two vertically line-ends. In order to make this happen, both arcs must have a radius of zero. On the other side, other constraints are asking for a tangent to the arcs. Tangents to an arc of zero radius make no sense to me. I am not shure, if this is mathematically possible. I do not wonder, that this sketch is not solvable. FreeCAD could provide a better message about this situation, but it may be a difficult task to program this.

Beside this problem, the polyline makes implicite coincidence constraints without showing them:

If you want to have a line connected to an arch where the arch is tangentially to the line, two constraints needs to be added: a coincidence and a tangent constraint.
If you make the same with the polyline, only a tangent constraint is shown in the list. This is at least not consequent. Depending how the sketch was made, the list of constraints have different numbers of members. It makes it also harder to analyse a sketch for possible problems.

Ulrich
User avatar
NormandC
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Sketcher bug?

Postby NormandC » Sun Aug 24, 2014 4:15 pm

Actually the single tangent constraint is by design, logari81 the developer said so and it is the preferred way. You have to select end points rather than the line and arcs themselves.

The same goes for the perpendicular constraint.
nahshon
Posts: 192
Joined: Wed Jul 24, 2013 8:06 pm

Re: Sketcher bug?

Postby nahshon » Tue Aug 26, 2014 1:20 am

ulrich1a wrote:The sketch is problematic.
Sure it is. It's done on purpose and I did write "containing a sketch that cannot be resolved."

Now I understand that the solver is not able to solve this sketch (even when mathematically there aren't any conflicts). I do not know what would be the preferred behavior of the sketcher. Becoming non-responsive (as it is now) is IMHO not acceptable.

-- Itai
User avatar
DevJohan
Posts: 41
Joined: Sun Jul 13, 2014 2:36 pm
Location: Stockholm, Sweden

Re: Sketcher bug?

Postby DevJohan » Tue Aug 26, 2014 12:43 pm

I'm currently looking at the sketcher solver and will look at this as well. I don't think it is acceptable for the sketcher to become unresponsive while the solver is working.
wmayer
Site Admin
Posts: 15279
Joined: Thu Feb 19, 2009 10:32 am

Re: Sketcher bug?

Postby wmayer » Tue Aug 26, 2014 3:14 pm

It's very likely the same thing as here: issue #1647
The problem is that the solution doesn't converge and the algorithm aborts after doing all iteration steps.
ulrich1a
Posts: 1920
Joined: Sun Jul 07, 2013 12:08 pm

Re: Sketcher bug?

Postby ulrich1a » Tue Aug 26, 2014 3:36 pm

There are some cases, where redundant constraints are not detected by the solver. If the sketch contains more than one of those not reported redundant constraints, the sketch can not be moved anymore, even when there are several degrees of freedom left.

Here is one example with two symmetry constraints and two parallel constraints. The parallel constraints are redundant. The second parallel constraint freezes the sketch for manual movement.
FreeCAD does not give any error message or sketcher warning. The Sketch is just not manually movable.
This may have a different cause, but the effect is similar: the sketch is frozen.

Ulrich
Attachments
Redundant_constraints_not_reported.FCStd
(2.8 KiB) Downloaded 53 times
nahshon
Posts: 192
Joined: Wed Jul 24, 2013 8:06 pm

Re: Sketcher bug?

Postby nahshon » Tue Aug 26, 2014 6:07 pm

wmayer wrote:It's very likely the same thing as here: issue #1647
The problem is that the solution doesn't converge and the algorithm aborts after doing all iteration steps.
Werner, I saw that bug and also the discussion. My reported problem may be related but not the same (*).
In my case the solver is doing exactly what I expect, and it's actually fast (see note below *).
The problem is the python exception in movePoint that is not handled (see ViewProviderSketch.cpp):

Code: Select all

               case STATUS_SKETCH_DragPoint:
                    if (edit->DragPoint != -1) {
                        int GeoId;
                        Sketcher::PointPos PosId;
                        getSketchObject()->getGeoVertexIndex(edit->DragPoint, GeoId, PosId);
                        Gui::Command::openCommand("Drag Point");
                        Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.movePoint(%i,%i,App.Vector(%f,%f,0),%i)"
                                               ,getObject()->getNameInDocument()
                                               ,GeoId, PosId, x-xInit, y-yInit, relative ? 1 : 0
                                               );   
                        Gui::Command::commitCommand();
                        Gui::Command::updateActive();

                        setPreselectPoint(edit->DragPoint);
                        edit->DragPoint = -1;
                        //updateColor();
                    }    
                    resetPositionText();
                    Mode = STATUS_NONE;
                    return true;
                case STATUS_SKETCH_DragCurve:
                    if (edit->DragCurve != -1) {
                        const Part::Geometry *geo = getSketchObject()->getGeometry(edit->DragCurve);
                        if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId() ||
                            geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId() ||
                            geo->getTypeId() == Part::GeomCircle::getClassTypeId()) {
                            Gui::Command::openCommand("Drag Curve");
                            Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.movePoint(%i,%i,App.Vector(%f,%f,0),%i)"
                                                   ,getObject()->getNameInDocument()
                                                   ,edit->DragCurve, Sketcher::none, x-xInit, y-yInit, relative ? 1 : 0
                                                   );
                            Gui::Command::commitCommand();
                            Gui::Command::updateActive();
                        }
                        edit->PreselectCurve = edit->DragCurve;
                        edit->DragCurve = -1;
                        //updateColor();
                    }
                    resetPositionText();
                    Mode = STATUS_NONE;
                    return true;
This happens on button-up (?). Since the exception is not caught the sketcher is left in one of the DRAG modes. Any attempt to mode the mouse over the MDI will result in the solver called again and failing again.
The only way out of this situation is:
1. Move the mouse away from the MDI.
2. Wait till the solver returns (* note: this may take a LONG time, if there's a combination of issue #1647. In cases I have waited over 20 minutes when FreeCAD was compiled for DEBUG).
3. Hit the sketcher Close button.
4. Restart the sketcher, delete some constraints. Be careful not to touch the MDI area.

Now I have two questions:
1. What is the correct behavior (possibly error box)
2. Why is the call movePoint using the python interface? IMHO there is no real python code involved and it will just do the movePoint in SketchObjectPyImp.cpp. Why not call edit->ActSketch.movePoint() as done in other places in ViewProviderSketch.cpp?

Thanks!
-- Itai