+ revert to previous values when setDatum fails
+ detect well known invalid values for setDatum + hide some negative distance datums in the gui git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5133 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
parent
8c65bec480
commit
85b2fec8f6
|
@ -136,6 +136,9 @@ int SketchObject::setDatum(int ConstrId, double Datum)
|
|||
type != Angle)
|
||||
return -1;
|
||||
|
||||
if ((type == Distance || type == Radius) && Datum <= 0)
|
||||
return (Datum == 0) ? -5 : -4;
|
||||
|
||||
// copy the list
|
||||
std::vector<Constraint *> newVals(vals);
|
||||
// clone the changed Constraint
|
||||
|
@ -148,21 +151,25 @@ int SketchObject::setDatum(int ConstrId, double Datum)
|
|||
// set up a sketch (including dofs counting and diagnosing of conflicts)
|
||||
Sketch sketch;
|
||||
int dofs = sketch.setUpSketch(Geometry.getValues(), Constraints.getValues());
|
||||
int err=0;
|
||||
if (dofs < 0) // over-constrained sketch
|
||||
return -3;
|
||||
if (sketch.hasConflicts()) // conflicting constraints
|
||||
return -3;
|
||||
// solving
|
||||
if (sketch.solve() != 0)
|
||||
return -2;
|
||||
err = -3;
|
||||
else if (sketch.hasConflicts()) // conflicting constraints
|
||||
err = -3;
|
||||
else if (sketch.solve() != 0) // solving
|
||||
err = -2;
|
||||
|
||||
// set the newly solved geometry
|
||||
std::vector<Part::Geometry *> geomlist = sketch.getGeometry();
|
||||
Geometry.setValues(geomlist);
|
||||
for (std::vector<Part::Geometry *>::iterator it = geomlist.begin(); it != geomlist.end(); ++it)
|
||||
if (*it) delete *it;
|
||||
if (err == 0) {
|
||||
// set the newly solved geometry
|
||||
std::vector<Part::Geometry *> geomlist = sketch.getGeometry();
|
||||
Geometry.setValues(geomlist);
|
||||
for (std::vector<Part::Geometry *>::iterator it = geomlist.begin(); it != geomlist.end(); ++it)
|
||||
if (*it) delete *it;
|
||||
}
|
||||
else
|
||||
this->Constraints.setValues(vals);
|
||||
|
||||
return 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
int SketchObject::movePoint(int geoIndex, PointPos PosId, const Base::Vector3d& toPoint, bool relative)
|
||||
|
|
|
@ -198,6 +198,10 @@ PyObject* SketchObjectPy::setDatum(PyObject *args)
|
|||
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";
|
||||
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;
|
||||
PyErr_SetString(PyExc_ValueError, str.str().c_str());
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
# include <Inventor/sensors/SoSensor.h>
|
||||
|
||||
#include <Base/Tools.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Document.h>
|
||||
|
@ -75,7 +76,7 @@ void EditDatumDialog::exec(bool atCursor)
|
|||
|
||||
double datum = Constr->Value;
|
||||
if (Constr->Type == Sketcher::Angle)
|
||||
datum = datum * 180./M_PI;
|
||||
datum = Base::toDegrees<double>(datum);
|
||||
|
||||
Gui::MDIView *mdi = Gui::Application::Instance->activeDocument()->getActiveView();
|
||||
Gui::View3DInventorViewer *viewer = static_cast<Gui::View3DInventor *>(mdi)->getViewer();
|
||||
|
@ -85,7 +86,14 @@ void EditDatumDialog::exec(bool atCursor)
|
|||
Ui::InsertDatum ui_ins_datum;
|
||||
ui_ins_datum.setupUi(&dlg);
|
||||
|
||||
ui_ins_datum.lineEdit->setText(QLocale::system().toString(datum,'g',6));
|
||||
double init_val;
|
||||
if (Constr->Type == Sketcher::Angle ||
|
||||
Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY)
|
||||
init_val = std::abs(datum);
|
||||
else
|
||||
init_val = datum;
|
||||
|
||||
ui_ins_datum.lineEdit->setText(QLocale::system().toString(init_val,'g',6));
|
||||
ui_ins_datum.lineEdit->selectAll();
|
||||
|
||||
if (atCursor)
|
||||
|
@ -96,15 +104,25 @@ void EditDatumDialog::exec(bool atCursor)
|
|||
double newDatum = ui_ins_datum.lineEdit->text().toDouble(&ok);
|
||||
if (ok) {
|
||||
if (Constr->Type == Sketcher::Angle)
|
||||
newDatum = newDatum * M_PI/180.;
|
||||
newDatum = Base::toRadians<double>(newDatum);
|
||||
|
||||
if (newDatum < 0 &&
|
||||
(Constr->Type == Sketcher::Angle ||
|
||||
Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY)) {
|
||||
// Permit negative values to flip the sign of the constraint
|
||||
newDatum = ((datum >= 0) ? -1 : 1) * std::abs(newDatum);
|
||||
}
|
||||
|
||||
try {
|
||||
Gui::Command::openCommand("Modify sketch constraints");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDatum(%i,%f)",
|
||||
vp->getObject()->getNameInDocument(),
|
||||
ConstrNbr, newDatum);
|
||||
Gui::Command::commitCommand();
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
QMessageBox::critical(qApp->activeWindow(), QObject::tr("Distance constraint"), QString::fromUtf8(e.what()));
|
||||
QMessageBox::critical(qApp->activeWindow(), QObject::tr("Dimensional constraint"), QString::fromUtf8(e.what()));
|
||||
Gui::Command::abortCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
#include <Mod/Sketcher/App/SketchObject.h>
|
||||
|
||||
#include <Base/Tools.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
|
@ -261,13 +262,13 @@ void TaskSketcherConstrains::slotConstraintsChanged(void)
|
|||
break;
|
||||
case Sketcher::DistanceX:
|
||||
if(Filter<3 || (*it)->Name != ""){
|
||||
name = QString::fromLatin1("%1 (%2)").arg(name).arg((*it)->Value);
|
||||
name = QString::fromLatin1("%1 (%2)").arg(name).arg(std::abs((*it)->Value));
|
||||
ui->listWidgetConstraints->addItem(new ConstraintItem(hdist,name,i-1,(*it)->Type));
|
||||
}
|
||||
break;
|
||||
case Sketcher::DistanceY:
|
||||
if(Filter<3 || (*it)->Name != ""){
|
||||
name = QString::fromLatin1("%1 (%2)").arg(name).arg((*it)->Value);
|
||||
name = QString::fromLatin1("%1 (%2)").arg(name).arg(std::abs((*it)->Value));
|
||||
ui->listWidgetConstraints->addItem(new ConstraintItem(vdist,name,i-1,(*it)->Type));
|
||||
}
|
||||
break;
|
||||
|
@ -279,7 +280,7 @@ void TaskSketcherConstrains::slotConstraintsChanged(void)
|
|||
break;
|
||||
case Sketcher::Angle:
|
||||
if(Filter<3 || (*it)->Name != ""){
|
||||
name = QString::fromLatin1("%1 (%2)").arg(name).arg((*it)->Value * 180./M_PI);
|
||||
name = QString::fromLatin1("%1 (%2)").arg(name).arg(Base::toDegrees<double>(std::abs((*it)->Value)));
|
||||
ui->listWidgetConstraints->addItem(new ConstraintItem(angl,name,i-1,(*it)->Type));
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
#include <Inventor/SbTime.h>
|
||||
|
||||
/// Here the FreeCAD includes sorted by Base,App,Gui......
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Vector3D.h>
|
||||
|
@ -1917,7 +1918,7 @@ Restart:
|
|||
SbVec3f midpos = (p1_ + p2)/2;
|
||||
|
||||
SoDatumLabel *asciiText = dynamic_cast<SoDatumLabel *>(sep->getChild(4));
|
||||
asciiText->string = SbString().sprintf("%.2f",Constr->Value);
|
||||
asciiText->string = SbString().sprintf("%.2f",std::abs(Constr->Value));
|
||||
|
||||
// Get Bounding box dimensions for Datum text
|
||||
Gui::View3DInventorViewer *viewer = static_cast<Gui::View3DInventor *>(mdi)->getViewer();
|
||||
|
@ -2197,7 +2198,7 @@ Restart:
|
|||
break;
|
||||
|
||||
SoDatumLabel *asciiText = dynamic_cast<SoDatumLabel *>(sep->getChild(4));
|
||||
asciiText->string = SbString().sprintf("%.2f",Constr->Value * 180./M_PI);
|
||||
asciiText->string = SbString().sprintf("%.2f",Base::toDegrees<double>(std::abs(Constr->Value)));
|
||||
|
||||
// Get Bounding box dimensions for Datum text
|
||||
Gui::View3DInventorViewer *viewer = static_cast<Gui::View3DInventor *>(mdi)->getViewer();
|
||||
|
|
Loading…
Reference in New Issue
Block a user