From 482a73b302215677d7146574795e52bf9b357193 Mon Sep 17 00:00:00 2001 From: logari81 Date: Sat, 3 Nov 2012 23:23:58 +0100 Subject: [PATCH] PartDesign: improve error handling in Pocket task dialog --- .../PartDesign/Gui/TaskPocketParameters.cpp | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp index 6fe3e2c6ef..b29be9fab4 100644 --- a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp @@ -27,6 +27,7 @@ # include # include # include +# include # include #endif @@ -402,22 +403,30 @@ bool TaskDlgPocketParameters::accept() { std::string name = PocketView->getObject()->getNameInDocument(); - //Gui::Command::openCommand("Pocket changed"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),parameter->getLength()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",name.c_str(),parameter->getMode()); - const char* facename = parameter->getFaceName().data(); - PartDesign::Pocket* pcPocket = static_cast(PocketView->getObject()); - Part::Feature* support = pcPocket->getSupport(); - if (support != NULL && facename && facename[0] != '\0') { - QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); - buf = buf.arg(QString::fromUtf8(support->getNameInDocument())); - buf = buf.arg(QString::fromUtf8(facename)); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", name.c_str(), buf.toStdString().c_str()); - } else - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", name.c_str()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); - Gui::Command::commitCommand(); + try { + //Gui::Command::openCommand("Pocket changed"); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Length = %f",name.c_str(),parameter->getLength()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",name.c_str(),parameter->getMode()); + const char* facename = parameter->getFaceName().data(); + PartDesign::Pocket* pcPocket = static_cast(PocketView->getObject()); + Part::Feature* support = pcPocket->getSupport(); + if (support != NULL && facename && facename[0] != '\0') { + QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])"); + buf = buf.arg(QString::fromUtf8(support->getNameInDocument())); + buf = buf.arg(QString::fromUtf8(facename)); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s", name.c_str(), buf.toStdString().c_str()); + } else + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", name.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); + if (!PocketView->getObject()->isValid()) + throw Base::Exception(PocketView->getObject()->getStatusString()); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::commitCommand(); + } + catch (const Base::Exception& e) { + QMessageBox::warning(parameter, tr("Input error"), QString::fromAscii(e.what())); + return false; + } return true; }