From befb6ec6e85875ceda935dc0704d801a31ea0a05 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 3 Mar 2014 17:19:33 +0100 Subject: [PATCH] + fixes #0001356: Error message displays value in Radians (adding reduntant/conflicting angle constraint) --- src/Mod/Sketcher/App/CMakeLists.txt | 1 + src/Mod/Sketcher/App/SketchObjectPyImp.cpp | 24 ++++++++++++++++++---- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 12 +++-------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Mod/Sketcher/App/CMakeLists.txt b/src/Mod/Sketcher/App/CMakeLists.txt index e1f39d46e8..7697574d8f 100644 --- a/src/Mod/Sketcher/App/CMakeLists.txt +++ b/src/Mod/Sketcher/App/CMakeLists.txt @@ -12,6 +12,7 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${Boost_INCLUDE_DIRS} ${OCC_INCLUDE_DIR} + ${QT_QTCORE_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${PYTHON_INCLUDE_PATH} ${XERCESC_INCLUDE_DIR} diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index 26b9589f2a..0c71ba7521 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include // inclusion of the generated files (generated out of SketchObjectSFPy.xml) @@ -239,8 +241,22 @@ PyObject* SketchObjectPy::setDatum(PyObject *args) { double Datum; int Index; - if (!PyArg_ParseTuple(args, "id", &Index, &Datum)) - return 0; + PyObject* object; + Base::Quantity Quantity; + if (PyArg_ParseTuple(args,"iO!", &Index, &(Base::QuantityPy::Type), &object)) { + Quantity = *(static_cast(object)->getQuantityPtr()); + if (Quantity.getUnit() == Base::Unit::Angle) + //Datum = Quantity.getValueAs(Base::Quantity::Radian); + Datum = Base::toRadians(Quantity.getValue()); + else + Datum = Quantity.getValue(); + } + else { + PyErr_Clear(); + if (!PyArg_ParseTuple(args, "id", &Index, &Datum)) + return 0; + Quantity.setValue(Datum); + } int err=this->getSketchObjectPtr()->setDatum(Index, Datum); if (err) { @@ -250,13 +266,13 @@ PyObject* SketchObjectPy::setDatum(PyObject *args) else if (err == -3) str << "Cannot set the datum because the sketch contains conflicting constraints"; else if (err == -2) - str << "Datum " << Datum << " for the constraint with index " << Index << " is invalid"; + str << "Datum " << (const char*)Quantity.getUserString().toUtf8() << " for the constraint with index " << Index << " is invalid"; else if (err == -4) str << "Negative datum values are not valid for the constraint with index " << Index; else if (err == -5) str << "Zero is not a valid datum for the constraint with index " << Index; else - str << "Unexpected problem at setting datum " << Datum << " for the constraint with index " << Index; + str << "Unexpected problem at setting datum " << (const char*)Quantity.getUserString().toUtf8() << " for the constraint with index " << Index; PyErr_SetString(PyExc_ValueError, str.str().c_str()); return 0; } diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 5c8a31c33b..5bb30ee463 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -124,13 +124,7 @@ void EditDatumDialog::exec(bool atCursor) // save the value for the history ui_ins_datum.labelEdit->pushToHistory(); - double newDatum; - if (Constr->Type == Sketcher::Angle) - newDatum = Base::toRadians(newQuant.getValue()); - else - newDatum = newQuant.getValue(); - - + double newDatum = newQuant.getValue(); if (Constr->Type == Sketcher::Angle || ((Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY) && Constr->FirstPos == Sketcher::none || Constr->Second != Sketcher::Constraint::GeoUndef)) { @@ -143,9 +137,9 @@ void EditDatumDialog::exec(bool atCursor) try { Gui::Command::openCommand("Modify sketch constraints"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDatum(%i,%f)", + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDatum(%i,App.Units.Quantity('%f %s'))", sketch->getNameInDocument(), - ConstrNbr, newDatum); + ConstrNbr, newDatum, (const char*)newQuant.getUnit().getString().toUtf8()); Gui::Command::commitCommand(); Gui::Command::updateActive(); }