From 03d242e202e022815b83720c2a6702dceca5bbdb Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 9 Apr 2017 10:00:55 +0200 Subject: [PATCH] Sketcher: New function to reuse of python exception message text in the UI --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 11 +++++++++++ src/Mod/Sketcher/Gui/CommandConstraints.h | 3 +++ src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 6ee70b36fe..e7c3b1bf36 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -674,6 +674,17 @@ void SketcherGui::makeTangentToArcOfParabolaviaNewPoint(const Sketcher::SketchOb Gui::Command::updateActive(); } +std::string SketcherGui::getStrippedPythonExceptionString(const Base::Exception e) +{ + std::string msg = e.what(); + + if( msg.length() > 26 && msg.substr(0,26) == "FreeCAD exception thrown (") { + return msg.substr(26, msg.length()-27); + } + else + return msg; +} + namespace SketcherGui { diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.h b/src/Mod/Sketcher/Gui/CommandConstraints.h index 9e7a1be935..0a5aa8446a 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.h +++ b/src/Mod/Sketcher/Gui/CommandConstraints.h @@ -98,6 +98,9 @@ void makeTangentToArcOfParabolaviaNewPoint(const Sketcher::SketchObject* Obj, int geoId1, int geoId2 ); + +std::string getStrippedPythonExceptionString(const Base::Exception); + } #endif // SKETCHERGUI_DrawSketchHandler_H diff --git a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp index c971a40db2..8fd7beb48b 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp @@ -572,7 +572,7 @@ void CmdSketcherIncreaseKnotMultiplicity::activated(int iMsg) } catch (const Base::Exception& e) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Error"), - QObject::tr(e.what())); + QObject::tr(getStrippedPythonExceptionString(e).c_str())); getSelection().clearSelection(); } @@ -726,7 +726,7 @@ void CmdSketcherDecreaseKnotMultiplicity::activated(int iMsg) } catch (const Base::Exception& e) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Error"), - QObject::tr(e.what())); + QObject::tr(getStrippedPythonExceptionString(e).c_str())); getSelection().clearSelection(); }