+ fixes #0001808: Double Clicking Sketcher PolyLine Causing Crash

This commit is contained in:
wmayer 2014-11-09 17:59:54 +01:00
parent efe414e4c2
commit d30eb39a1e

View File

@ -29,6 +29,7 @@
#include <boost/math/special_functions/fpclassify.hpp> #include <boost/math/special_functions/fpclassify.hpp>
#include <Base/Console.h> #include <Base/Console.h>
#include <Base/Exception.h>
#include <Gui/Action.h> #include <Gui/Action.h>
#include <Gui/Application.h> #include <Gui/Application.h>
@ -802,6 +803,7 @@ public:
resetPositionText(); resetPositionText();
sketchgui->drawEdit(EditCurve); sketchgui->drawEdit(EditCurve);
sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider sketchgui->purgeHandler(); // no code after this line, Handler get deleted in ViewProvider
return true; // 'this' instance is destroyed now!
} }
Mode = STATUS_Do; Mode = STATUS_Do;
@ -824,22 +826,30 @@ public:
virtual bool releaseButton(Base::Vector2D onSketchPos) virtual bool releaseButton(Base::Vector2D onSketchPos)
{ {
if (Mode == STATUS_Do || Mode == STATUS_Close) { if (Mode == STATUS_Do || Mode == STATUS_Close) {
bool addedGeometry = true;
if (SegmentMode == SEGMENT_MODE_Line) { if (SegmentMode == SEGMENT_MODE_Line) {
// open the transaction // open the transaction
Gui::Command::openCommand("Add line to sketch wire"); Gui::Command::openCommand("Add line to sketch wire");
// issue the geometry // issue the geometry
try {
Gui::Command::doCommand(Gui::Command::Doc, Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.addGeometry(Part.Line(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))", "App.ActiveDocument.%s.addGeometry(Part.Line(App.Vector(%f,%f,0),App.Vector(%f,%f,0)))",
sketchgui->getObject()->getNameInDocument(), sketchgui->getObject()->getNameInDocument(),
EditCurve[0].fX,EditCurve[0].fY,EditCurve[1].fX,EditCurve[1].fY); EditCurve[0].fX,EditCurve[0].fY,EditCurve[1].fX,EditCurve[1].fY);
} }
catch (const Base::Exception& e) {
addedGeometry = false;
Base::Console().Error("Failed to add line: %s\n", e.what());
Gui::Command::abortCommand();
}
}
else if (SegmentMode == SEGMENT_MODE_Arc) { // We're dealing with an Arc else if (SegmentMode == SEGMENT_MODE_Arc) { // We're dealing with an Arc
if (!boost::math::isnormal(arcRadius)) { if (!boost::math::isnormal(arcRadius)) {
Mode = STATUS_SEEK_Second; Mode = STATUS_SEEK_Second;
return true; return true;
} }
Gui::Command::openCommand("Add arc to sketch wire"); Gui::Command::openCommand("Add arc to sketch wire");
try {
Gui::Command::doCommand(Gui::Command::Doc, Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.addGeometry(Part.ArcOfCircle" "App.ActiveDocument.%s.addGeometry(Part.ArcOfCircle"
"(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),%f),%f,%f))", "(Part.Circle(App.Vector(%f,%f,0),App.Vector(0,0,1),%f),%f,%f))",
@ -847,8 +857,14 @@ public:
CenterPoint.fX, CenterPoint.fY, std::abs(arcRadius), CenterPoint.fX, CenterPoint.fY, std::abs(arcRadius),
std::min(startAngle,endAngle), std::max(startAngle,endAngle)); std::min(startAngle,endAngle), std::max(startAngle,endAngle));
} }
catch (const Base::Exception& e) {
addedGeometry = false;
Base::Console().Error("Failed to add arc: %s\n", e.what());
Gui::Command::abortCommand();
}
}
// issue the constraint // issue the constraint
if (previousPosId != Sketcher::none) { if (addedGeometry && (previousPosId != Sketcher::none)) {
int lastCurve = getHighestCurveIndex(); int lastCurve = getHighestCurveIndex();
Sketcher::PointPos lastStartPosId = (SegmentMode == SEGMENT_MODE_Arc && startAngle > endAngle) ? Sketcher::PointPos lastStartPosId = (SegmentMode == SEGMENT_MODE_Arc && startAngle > endAngle) ?
Sketcher::end : Sketcher::start; Sketcher::end : Sketcher::start;