From d3a7e9a9284f213fabd3853d94ec460e364b60b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Fri, 22 May 2015 06:59:18 +0200 Subject: [PATCH] fix selection error on datum exception and add user feedback for failed selections --- src/Mod/PartDesign/App/DatumCS.cpp | 64 +++++++------------ src/Mod/PartDesign/App/DatumLine.cpp | 8 +-- src/Mod/PartDesign/App/DatumPlane.cpp | 4 +- src/Mod/PartDesign/App/DatumPoint.cpp | 6 +- .../PartDesign/Gui/TaskDatumParameters.cpp | 21 ++++-- src/Mod/PartDesign/Gui/TaskDatumParameters.h | 2 +- src/Mod/PartDesign/Gui/TaskDatumParameters.ui | 10 +++ 7 files changed, 61 insertions(+), 54 deletions(-) diff --git a/src/Mod/PartDesign/App/DatumCS.cpp b/src/Mod/PartDesign/App/DatumCS.cpp index 5337eabfa..814bea41d 100644 --- a/src/Mod/PartDesign/App/DatumCS.cpp +++ b/src/Mod/PartDesign/App/DatumCS.cpp @@ -124,16 +124,9 @@ void CoordinateSystem::initHints() key.insert(PLANE); key.insert(LINE); value.insert(POINT); - value.insert(LINE); value.insert(DONE); hints[key] = value; - - key.clear(); value.clear(); - key.insert(PLANE); - key.insert(LINE); - key.insert(LINE); - hints[key] = Done; - + key.clear(); value.clear(); key.insert(PLANE); key.insert(LINE); @@ -167,16 +160,9 @@ void CoordinateSystem::initHints() key.insert(LINE); key.insert(PLANE); value.insert(POINT); - value.insert(LINE); value.insert(DONE); hints[key] = value; - - key.clear(); value.clear(); - key.insert(LINE); - key.insert(PLANE); - key.insert(LINE); - hints[key] = Done; - + key.clear(); value.clear(); key.insert(LINE); key.insert(PLANE); @@ -186,17 +172,10 @@ void CoordinateSystem::initHints() key.clear(); value.clear(); key.insert(LINE); key.insert(LINE); - value.insert(PLANE); value.insert(POINT); value.insert(DONE); hints[key] = value; - key.clear(); value.clear(); - key.insert(LINE); - key.insert(LINE); - key.insert(PLANE); - hints[key] = Done; - key.clear(); value.clear(); key.insert(LINE); key.insert(LINE); @@ -260,7 +239,7 @@ void CoordinateSystem::onChanged(const App::Property *prop) const std::vector& subrefs = References.getSubValues(); if (refs.size() != subrefs.size()) - return; //throw Base::Exception("Size of references and subreferences do not match"); + throw Base::Exception("Size of references and subreferences do not match"); refTypes.clear(); for (int r = 0; r < refs.size(); r++) @@ -268,7 +247,7 @@ void CoordinateSystem::onChanged(const App::Property *prop) std::set hint = getHint(); if (refs.size() != 0 && !(hint.find(QObject::tr("Done")) != hint.end())) - return; //throw Base::Exception("Can not build coordinate system from given references"); // incomplete references + throw Base::Exception("Can not build coordinate system from given references"); // incomplete references //build the placement from the references bool plane = false, line1 = false, line2 = false, origin = false; @@ -286,7 +265,7 @@ void CoordinateSystem::onChanged(const App::Property *prop) origin=true; } else - return; //throw Base::Exception("Too many points in coordinate system references"); //too much points selected + throw Base::Exception("Too many points in coordinate system references"); //too much points selected } else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) { PartDesign::Plane* p = static_cast(refs[i]); @@ -295,7 +274,7 @@ void CoordinateSystem::onChanged(const App::Property *prop) plane=true; } else - return; //throw Base::Exception("Too many planes in coordinate syste references"); + throw Base::Exception("Too many planes in coordinate syste references"); } else if (refs[i]->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { App::Plane* p = static_cast(refs[i]); if(!plane) { @@ -312,7 +291,7 @@ void CoordinateSystem::onChanged(const App::Property *prop) plane=true; } else - return; //throw Base::Exception("Too many planes in coordinate syste references"); //too much planes selected + throw Base::Exception("Too many planes in coordinate syste references"); //too much planes selected } else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) { PartDesign::Line* p = static_cast(refs[i]); @@ -325,7 +304,7 @@ void CoordinateSystem::onChanged(const App::Property *prop) line2 = true; } else - return; //throw Base::Exception("Too many lines in coordinate syste references");; //too much lines selected + throw Base::Exception("Too many lines in coordinate syste references");; //too much lines selected } else if (refs[i]->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) { App::Line* p = static_cast(refs[i]); @@ -347,17 +326,17 @@ void CoordinateSystem::onChanged(const App::Property *prop) line2=true; } else - return; //throw Base::Exception("Too many lines in coordinate syste references"); + throw Base::Exception("Too many lines in coordinate syste references"); } else if (refs[i]->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { Part::Feature* feature = static_cast(refs[i]); const TopoDS_Shape& sh = feature->Shape.getValue(); if (sh.IsNull()) - return; //throw Base::Exception("Invalid shape in reference"); + throw Base::Exception("Invalid shape in reference"); // Get subshape TopoDS_Shape subshape = feature->Shape.getShape().getSubShape(subrefs[i].c_str()); if (subshape.IsNull()) - return; //throw Base::Exception("Reference has Null shape"); + throw Base::Exception("Reference has Null shape"); if (subshape.ShapeType() == TopAbs_VERTEX) { TopoDS_Vertex v = TopoDS::Vertex(subshape); @@ -367,13 +346,13 @@ void CoordinateSystem::onChanged(const App::Property *prop) origin=true; } else - return; //throw Base::Exception("Too many points in coordinate system references"); + throw Base::Exception("Too many points in coordinate system references"); } else if (subshape.ShapeType() == TopAbs_EDGE) { TopoDS_Edge e = TopoDS::Edge(subshape); BRepAdaptor_Curve adapt(e); if (adapt.GetType() != GeomAbs_Line) - return; //throw Base::Exception("Only straight edges are supported"); + throw Base::Exception("Only straight edges are supported"); if(!line1) { lin1 = adapt.Line(); @@ -384,7 +363,7 @@ void CoordinateSystem::onChanged(const App::Property *prop) line2=true; } else - return; //throw Base::Exception("Too many lines in coordinate system references"); + throw Base::Exception("Too many lines in coordinate system references"); } else if (subshape.ShapeType() == TopAbs_FACE) { TopoDS_Face f = TopoDS::Face(subshape); @@ -402,10 +381,10 @@ void CoordinateSystem::onChanged(const App::Property *prop) plane = true; } else - return; //throw Base::Exception("Too many planes in coordinate system references"); + throw Base::Exception("Too many planes in coordinate system references"); } else { - return; //throw Base::Exception("Only planar faces allowed"); + throw Base::Exception("Only planar faces allowed"); } } } @@ -418,11 +397,14 @@ void CoordinateSystem::onChanged(const App::Property *prop) if(plane) { if(!pln.Contains(org, Precision::Confusion())) - return; //throw Base::Exception("Point must lie on plane"); + throw Base::Exception("Point must lie on plane"); if(line1) { if(!pln.Contains(lin1, Precision::Confusion(), Precision::Confusion())) - return; //throw Base::Exception("Line must lie on plane"); + throw Base::Exception("Line must lie on plane"); + + if(line2) + throw Base::Exception("Two lines and a plain are not supportet"); ax = gp_Ax3(org, pln.Axis().Direction(), lin1.Direction()); } @@ -448,7 +430,7 @@ void CoordinateSystem::onChanged(const App::Property *prop) if(line1) { if(!pln.Contains(lin1, Precision::Confusion(), Precision::Confusion())) - return; //throw Base::Exception("Line must lie on plane"); + throw Base::Exception("Line must lie on plane"); ax = gp_Ax3(pln.Location(), pln.Axis().Direction(), lin1.Direction()); } @@ -459,6 +441,8 @@ void CoordinateSystem::onChanged(const App::Property *prop) else if(line1) { if(line2) { + if(! ((lin1.Angle(lin2) - M_PI<2) < Precision::Angular()) ) + throw Base::Exception("Lines must be perpendicular"); ax = gp_Ax3(lin1.Location(), lin1.Direction(), lin2.Direction()); } else diff --git a/src/Mod/PartDesign/App/DatumLine.cpp b/src/Mod/PartDesign/App/DatumLine.cpp index 683b5ca2c..047563dd5 100644 --- a/src/Mod/PartDesign/App/DatumLine.cpp +++ b/src/Mod/PartDesign/App/DatumLine.cpp @@ -159,14 +159,14 @@ void Line::onChanged(const App::Property *prop) std::vector refs = References.getValues(); std::vector refnames = References.getSubValues(); if (refs.size() != refnames.size()) - return; + throw Base::Exception("Reference Missmatch"); for (int r = 0; r < refs.size(); r++) refTypes.insert(getRefType(refs[r], refnames[r])); std::set hint = getHint(); if (!((hint.size() == 1) && (hint.find(QObject::tr("Done")) != hint.end()))) - return; // incomplete references + throw Base::Exception("Incomplete References"); // incomplete references // Extract the geometry of the references Base::Vector3d* base = NULL; @@ -226,7 +226,7 @@ void Line::onChanged(const App::Property *prop) // Create plane through line normal to s1 Handle_Geom_Plane pl = Handle_Geom_Plane::DownCast(s1); if (pl.IsNull()) - return; // Non-planar first surface + throw Base::Exception("Non-planar first surface"); // Non-planar first surface gp_Dir normal = ldir.Crossed(pl->Axis().Direction()); double offset1 = Offset.getValue(); double offset2 = Offset2.getValue(); @@ -375,7 +375,7 @@ void Line::onChanged(const App::Property *prop) // Line from two surfaces GeomAPI_IntSS intersectorSS(s1, s2, Precision::Confusion()); if (!intersectorSS.IsDone() || (intersectorSS.NbLines() == 0)) - return; + throw Base::Exception("Intersection of surfaces failed"); if (intersectorSS.NbLines() > 1) Base::Console().Warning("More than one intersection curve for datum line from surfaces\n"); Handle_Geom_Line l = Handle_Geom_Line::DownCast(intersectorSS.Line(1)); diff --git a/src/Mod/PartDesign/App/DatumPlane.cpp b/src/Mod/PartDesign/App/DatumPlane.cpp index 0efb487dc..1e5ae1733 100644 --- a/src/Mod/PartDesign/App/DatumPlane.cpp +++ b/src/Mod/PartDesign/App/DatumPlane.cpp @@ -326,7 +326,7 @@ void Plane::onChanged(const App::Property *prop) // Intersect a line through the base point of the cylinder and normal to the plane with the cylinder itself GeomAPI_IntCS intersector(normalLine, cylinder); if (!intersector.IsDone() || (intersector.NbPoints() == 0)) - return; + throw Base::Exception("Curve - Surface intersection failed"); if (intersector.NbPoints() > 1) Base::Console().Warning("More than one intersection point for datum plane from cylinder and plane\n"); @@ -349,7 +349,7 @@ void Plane::onChanged(const App::Property *prop) Base::Vector3d vec2 = *p3 - *p1; normal = new Base::Vector3d(vec1 % vec2); } else { - return; + throw Base::Exception("Unvalid references"); } *normal = normal->Normalize(); diff --git a/src/Mod/PartDesign/App/DatumPoint.cpp b/src/Mod/PartDesign/App/DatumPoint.cpp index d4bb30267..86fbd11cb 100644 --- a/src/Mod/PartDesign/App/DatumPoint.cpp +++ b/src/Mod/PartDesign/App/DatumPoint.cpp @@ -310,7 +310,7 @@ void Point::onChanged(const App::Property* prop) // Point from intersection of two curves GeomAPI_ExtremaCurveCurve intersector(c1, c2); if ((intersector.LowerDistance() > Precision::Confusion()) || (intersector.NbExtrema() == 0)) - return; // No intersection + throw Base::Exception("Curve-Curve intersection failed"); // No intersection // Note: We don't check for multiple intersection points gp_Pnt p, p2; intersector.Points(1, p, p2); @@ -330,7 +330,7 @@ void Point::onChanged(const App::Property* prop) // Intersect again intersector = GeomAPI_ExtremaCurveCurve(c1, c2); if ((intersector.LowerDistance() > Precision::Confusion()) || (intersector.NbExtrema() == 0)) - return; // No intersection + throw Base::Exception("Curve-Curve intersection failed"); // No intersection // Note: We don't check for multiple intersection points intersector.Points(1, p, p2); } @@ -339,7 +339,7 @@ void Point::onChanged(const App::Property* prop) } else if (!s1.IsNull()) { GeomAPI_IntCS intersector(c1, s1); if (!intersector.IsDone() || (intersector.NbPoints() == 0)) - return; + throw Base::Exception("Curve-Surface intersection failed"); if (intersector.NbPoints() > 1) Base::Console().Warning("More than one intersection point for datum point from curve and surface\n"); diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp index 09427876b..02f8548cc 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp @@ -229,8 +229,13 @@ const QString makeRefText(std::set hint) return result; } -void TaskDatumParameters::updateUI() +void TaskDatumParameters::updateUI(std::string message, bool error) { + //set text if available + if(!message.empty()) { + ui->message->setText(QString::fromStdString(message)); + } + ui->checkBoxFlip->setVisible(false); int numOffsets = static_cast(DatumView->getObject())->offsetsAllowed(); @@ -401,8 +406,16 @@ void TaskDatumParameters::onSelectionChanged(const Gui::SelectionChanges& msg) refs.push_back(selObj); refnames.push_back(subname); } - pcDatum->References.setValues(refs, refnames); - //pcDatum->getDocument()->recomputeFeature(pcDatum); + + bool error = false; + std::string message("Selection accepted"); + try { + pcDatum->References.setValues(refs, refnames); + } + catch(Base::Exception& e) { + error = true; + message = std::string(e.what()); + } QLineEdit* line = getLine(refSelectionMode); if (line != NULL) { @@ -412,7 +425,7 @@ void TaskDatumParameters::onSelectionChanged(const Gui::SelectionChanges& msg) line->blockSignals(false); } - updateUI(); + updateUI(message, error); } } diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.h b/src/Mod/PartDesign/Gui/TaskDatumParameters.h index e2a8e61a2..f4b15d239 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.h +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.h @@ -79,7 +79,7 @@ protected: private: void onSelectionChanged(const Gui::SelectionChanges& msg); - void updateUI(); + void updateUI(std::string message = std::string(), bool isWarning = false); void makeRefStrings(std::vector& refstrings, std::vector& refnames); QLineEdit* getLine(const int idx); diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.ui b/src/Mod/PartDesign/Gui/TaskDatumParameters.ui index af3a667b0..2f44865c9 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.ui @@ -14,6 +14,16 @@ Form + + + + Selection accepted + + + true + + +