Fem: [skip ci] fix several coding flaws:
* improve implementation of TaskFemConstraintForce::onButtonDirection * use QSignalBlocker to tmp. suppress signals instead of dis- and re-connecting * directly access object from SelectionObject * don't do type checks by class name but by typeid
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
|
||||
#include "ui_TaskFemConstraintForce.h"
|
||||
#include "TaskFemConstraintForce.h"
|
||||
#include <Base/Tools.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/PropertyGeo.h>
|
||||
@@ -154,14 +155,14 @@ void TaskFemConstraintForce::addToSelection()
|
||||
std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
|
||||
|
||||
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object
|
||||
if (static_cast<std::string>(it->getTypeName()).substr(0, 4).compare(std::string("Part")) != 0) {
|
||||
if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) {
|
||||
QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!"));
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> subNames = it->getSubNames();
|
||||
App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName());
|
||||
for (unsigned int subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element
|
||||
const std::vector<std::string>& subNames = it->getSubNames();
|
||||
App::DocumentObject* obj = it->getObject();
|
||||
for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element
|
||||
bool addMe = true;
|
||||
for (std::vector<std::string>::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]);
|
||||
itr != SubElements.end();
|
||||
@@ -171,16 +172,18 @@ void TaskFemConstraintForce::addToSelection()
|
||||
addMe = false;
|
||||
}
|
||||
}
|
||||
|
||||
// limit constraint such that only vertexes or faces or edges can be used depending on what was selected first
|
||||
std::string searchStr("");
|
||||
std::string searchStr;
|
||||
if (subNames[subIt].find("Vertex") != std::string::npos)
|
||||
searchStr = "Vertex";
|
||||
else if (subNames[subIt].find("Edge") != std::string::npos)
|
||||
searchStr = "Edge";
|
||||
else
|
||||
searchStr = "Face";
|
||||
for (unsigned int iStr = 0; iStr < (SubElements.size()); ++iStr) {
|
||||
if ((SubElements[iStr].find(searchStr) == std::string::npos) && (SubElements.size() > 0)) {
|
||||
|
||||
for (size_t iStr = 0; iStr < (SubElements.size()); ++iStr) {
|
||||
if (SubElements[iStr].find(searchStr) == std::string::npos) {
|
||||
QString msg = tr("Only one type of selection (vertex,face or edge) per constraint allowed!");
|
||||
QMessageBox::warning(this, tr("Selection error"), msg);
|
||||
addMe = false;
|
||||
@@ -188,16 +191,14 @@ void TaskFemConstraintForce::addToSelection()
|
||||
}
|
||||
}
|
||||
if (addMe) {
|
||||
disconnect(ui->listReferences, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
||||
this, SLOT(setSelection(QListWidgetItem*)));
|
||||
QSignalBlocker block(ui->listReferences);
|
||||
Objects.push_back(obj);
|
||||
SubElements.push_back(subNames[subIt]);
|
||||
ui->listReferences->addItem(makeRefText(obj, subNames[subIt]));
|
||||
connect(ui->listReferences, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
||||
this, SLOT(setSelection(QListWidgetItem*)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Update UI
|
||||
pcConstraint->References.setValues(Objects, SubElements);
|
||||
updateUI();
|
||||
@@ -214,17 +215,17 @@ void TaskFemConstraintForce::removeFromSelection()
|
||||
Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
|
||||
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();
|
||||
std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
|
||||
std::vector<unsigned int> itemsToDel;
|
||||
std::vector<size_t> itemsToDel;
|
||||
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object
|
||||
if (static_cast<std::string>(it->getTypeName()).substr(0, 4).compare(std::string("Part")) != 0) {
|
||||
if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) {
|
||||
QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!"));
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> subNames = it->getSubNames();
|
||||
App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName());
|
||||
const std::vector<std::string>& subNames = it->getSubNames();
|
||||
App::DocumentObject* obj = it->getObject();
|
||||
|
||||
for (unsigned int subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element
|
||||
for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element
|
||||
for (std::vector<std::string>::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]);
|
||||
itr != SubElements.end();
|
||||
itr = std::find(++itr, SubElements.end(), subNames[subIt]))
|
||||
@@ -244,19 +245,18 @@ void TaskFemConstraintForce::removeFromSelection()
|
||||
}
|
||||
|
||||
//Update UI
|
||||
disconnect(ui->listReferences, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
||||
this, SLOT(setSelection(QListWidgetItem*)));
|
||||
|
||||
ui->listReferences->clear();
|
||||
for (unsigned int j = 0; j < Objects.size(); j++) {
|
||||
ui->listReferences->addItem(makeRefText(Objects[j], SubElements[j]));
|
||||
{
|
||||
QSignalBlocker block(ui->listReferences);
|
||||
ui->listReferences->clear();
|
||||
for (unsigned int j = 0; j < Objects.size(); j++) {
|
||||
ui->listReferences->addItem(makeRefText(Objects[j], SubElements[j]));
|
||||
}
|
||||
}
|
||||
connect(ui->listReferences, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
||||
this, SLOT(setSelection(QListWidgetItem*)));
|
||||
|
||||
pcConstraint->References.setValues(Objects, SubElements);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
void TaskFemConstraintForce::onForceChanged(double f)
|
||||
{
|
||||
Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
|
||||
|
||||
Reference in New Issue
Block a user