From 79d00af2541eea271f2817c165c695e2cabd8656 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 26 Feb 2020 12:50:10 +0100 Subject: [PATCH] Fem: [skip ci] improve implementation of TaskFemConstraintForce::onButtonDirection --- src/Mod/Fem/Gui/TaskFemConstraintForce.cpp | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp index 449ed8e202..acc6d7a5f9 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp @@ -275,55 +275,55 @@ void TaskFemConstraintForce::onButtonDirection(const bool pressed) //get vector of selected objects of active document std::vector selection = Gui::Selection().getSelectionEx(); if (selection.size() == 0) { - QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); + QMessageBox::warning(this, tr("Empty selection"), tr("Select an edge or a face, please.")); return; } Fem::ConstraintForce* pcConstraint = static_cast(ConstraintView->getObject()); // we only handle the first selected object - std::vector::iterator selectionElement = selection.begin(); - std::string TypeName = static_cast(selectionElement->getTypeName()); + Gui::SelectionObject& selectionElement = selection.at(0); // we can only handle part objects - if (TypeName.substr(0, 4).compare(std::string("Part")) != 0) { - QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); + if (!selectionElement.isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Wrong selection"), tr("Selected object is not a part object!")); return; } // get the names of the subobjects - std::vector subNames = selectionElement->getSubNames(); + const std::vector& subNames = selectionElement.getSubNames(); - if (subNames.size() > 1) { - QMessageBox::warning(this, tr("Selection error"), tr("Only one planar face or edge can be selected!")); + if (subNames.size() != 1) { + QMessageBox::warning(this, tr("Wrong selection"), tr("Only one planar face or edge can be selected!")); return; } + // we are now sure we only have one object std::string subNamesElement = subNames[0]; // vector for the direction std::vector direction(1, subNamesElement); - App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(selectionElement->getFeatName()); - Part::Feature* feat = static_cast(obj); + Part::Feature* feat = static_cast(selectionElement.getObject()); TopoDS_Shape ref = feat->Shape.getShape().getSubShape(subNamesElement.c_str()); if (subNamesElement.substr(0, 4) == "Face") { if (!Fem::Tools::isPlanar(TopoDS::Face(ref))) { - QMessageBox::warning(this, tr("Selection error"), tr("Only planar faces can be picked for 3D")); + QMessageBox::warning(this, tr("Wrong selection"), tr("Only planar faces can be picked for 3D")); return; } } else if (subNamesElement.substr(0, 4) == "Edge") { // 2D or 3D can use edge as direction vector if (!Fem::Tools::isLinear(TopoDS::Edge(ref))) { - QMessageBox::warning(this, tr("Selection error"), tr("Only planar edges can be picked for 2D")); + QMessageBox::warning(this, tr("Wrong selection"), tr("Only planar edges can be picked for 2D")); return; } } else { - QMessageBox::warning(this, tr("Selection error"), tr("Only faces for 3D part or edges for 2D can be picked")); + QMessageBox::warning(this, tr("Wrong selection"), tr("Only faces for 3D part or edges for 2D can be picked")); return; } + // update the direction - pcConstraint->Direction.setValue(obj, direction); - ui->lineDirection->setText(makeRefText(obj, subNamesElement)); + pcConstraint->Direction.setValue(feat, direction); + ui->lineDirection->setText(makeRefText(feat, subNamesElement)); //Update UI updateUI();