From 27395bbba27fc81077d6ec428c7ec8485ecc686c Mon Sep 17 00:00:00 2001 From: donovaly Date: Fri, 28 Feb 2020 01:58:42 +0100 Subject: [PATCH] [FEM] spread the fixes from commit a5be62b8 to the other dialogs --- src/Mod/Fem/Gui/TaskFemConstraintContact.cpp | 184 ++++++++---------- .../Fem/Gui/TaskFemConstraintDisplacement.cpp | 106 +++++----- src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp | 103 +++++----- .../Gui/TaskFemConstraintFluidBoundary.cpp | 9 - src/Mod/Fem/Gui/TaskFemConstraintForce.cpp | 12 +- src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp | 103 +++++----- .../Gui/TaskFemConstraintPlaneRotation.cpp | 105 +++++----- src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp | 88 ++++----- .../Fem/Gui/TaskFemConstraintTemperature.cpp | 85 ++++---- .../Fem/Gui/TaskFemConstraintTransform.cpp | 85 ++++---- 10 files changed, 383 insertions(+), 497 deletions(-) diff --git a/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp b/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp index 2536e42993..522f2e27ba 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp @@ -46,12 +46,11 @@ #include "TaskFemConstraintContact.h" #include "ui_TaskFemConstraintContact.h" #include +#include #include - - - #include #include +#include using namespace FemGui; @@ -150,118 +149,106 @@ void TaskFemConstraintContact::addToSelectionSlave() { int rows = ui->lw_referencesSlave->model()->rowCount(); std::vector selection = Gui::Selection().getSelectionEx();//gets vector of selected objects of active document - if (rows==1){ + if (rows == 1){ QMessageBox::warning(this, tr("Selection error"), tr("Only one master face and one slave face for a contact constraint!")); Gui::Selection().clearSelection(); return; } - - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - - if ((rows==0) && (selection.size()>=2)){ + if ((rows == 0) && (selection.size() >= 2)){ QMessageBox::warning(this, tr("Selection error"), tr("Only one slave face for a contact constraint!")); Gui::Selection().clearSelection(); return; } - Fem::ConstraintContact* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); return; } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector subNames=it->getSubNames(); - App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); - if (subNames.size()!=1){ + if (subNames.size() != 1){ QMessageBox::warning(this, tr("Selection error"), tr("Only one slave face for a contact constraint!")); Gui::Selection().clearSelection(); return; } - 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 bool addMe=true; - if (subNames[subIt].substr(0,4) != "Face") { + if (subNames[subIt].substr(0, 4) != "Face") { QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); return; } - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add - addMe=false; + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + addMe = false; } } if (addMe){ - disconnect(ui->lw_referencesSlave, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); + QSignalBlocker block(ui->lw_referencesSlave); Objects.push_back(obj); SubElements.push_back(subNames[subIt]); ui->lw_referencesSlave->addItem(makeRefText(obj, subNames[subIt])); - connect(ui->lw_referencesSlave, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); } } } //Update UI - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintContact::removeFromSelectionSlave() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintContact* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ + std::vector itemsToDel; + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); return; } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector 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 - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion - itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } - - std::sort(itemsToDel.begin(),itemsToDel.end()); - while (itemsToDel.size()>0){ - Objects.erase(Objects.begin()+itemsToDel.back()); - SubElements.erase(SubElements.begin()+itemsToDel.back()); + std::sort(itemsToDel.begin(), itemsToDel.end()); + while (itemsToDel.size() > 0){ + Objects.erase(Objects.begin() + itemsToDel.back()); + SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } //Update UI - disconnect(ui->lw_referencesSlave, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - ui->lw_referencesSlave->clear(); - connect(ui->lw_referencesSlave, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - pcConstraint->References.setValues(Objects,SubElements); + { + QSignalBlocker block(ui->lw_referencesSlave); + ui->lw_referencesSlave->clear(); + } + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } @@ -269,118 +256,105 @@ void TaskFemConstraintContact::addToSelectionMaster() { int rows = ui->lw_referencesMaster->model()->rowCount(); std::vector selection = Gui::Selection().getSelectionEx();//gets vector of selected objects of active document - if (rows==1){ + if (rows == 1){ QMessageBox::warning(this, tr("Selection error"), tr("Only one master face and one slave face for a contact constraint!")); Gui::Selection().clearSelection(); return; } - - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - - if ((rows==0) && (selection.size()>=2)){ + if ((rows == 0) && (selection.size() >= 2)){ QMessageBox::warning(this, tr("Selection error"), tr("Only one master for a contact constraint!")); Gui::Selection().clearSelection(); return; } - Fem::ConstraintContact* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())){ + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } - - std::vector subNames=it->getSubNames(); - App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); - if (subNames.size()!=1){ + const std::vector& subNames=it->getSubNames(); + App::DocumentObject* obj = it->getObject(); + if (subNames.size() != 1){ QMessageBox::warning(this, tr("Selection error"), tr("Only one master face for a contact constraint!")); Gui::Selection().clearSelection(); return; } - 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 bool addMe=true; - if (subNames[subIt].substr(0,4) != "Face") { + if (subNames[subIt].substr(0, 4) != "Face") { QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); return; } - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add - addMe=false; + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + addMe = false; } } if (addMe){ - disconnect(ui->lw_referencesMaster, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); + QSignalBlocker block(ui->lw_referencesMaster); Objects.push_back(obj); SubElements.push_back(subNames[subIt]); ui->lw_referencesMaster->addItem(makeRefText(obj, subNames[subIt])); - connect(ui->lw_referencesMaster, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); } } } //Update UI - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintContact::removeFromSelectionMaster() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintContact* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + std::vector itemsToDel; + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector 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 - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr,SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion - itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } - - std::sort(itemsToDel.begin(),itemsToDel.end()); - while (itemsToDel.size()>0){ - Objects.erase(Objects.begin()+itemsToDel.back()); - SubElements.erase(SubElements.begin()+itemsToDel.back()); + std::sort(itemsToDel.begin(), itemsToDel.end()); + while (itemsToDel.size() > 0){ + Objects.erase(Objects.begin() + itemsToDel.back()); + SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } //Update UI - disconnect(ui->lw_referencesMaster, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - ui->lw_referencesMaster->clear(); - connect(ui->lw_referencesMaster, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - pcConstraint->References.setValues(Objects,SubElements); + { + QSignalBlocker block(ui->lw_referencesMaster); + ui->lw_referencesMaster->clear(); + } + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp index 09b365625a..2b403ab919 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp @@ -49,9 +49,11 @@ #include "TaskFemConstraintDisplacement.h" #include "ui_TaskFemConstraintDisplacement.h" #include +#include #include #include #include +#include using namespace FemGui; @@ -410,43 +412,41 @@ void TaskFemConstraintDisplacement::rotfreez(int val){ void TaskFemConstraintDisplacement::addToSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintDisplacement* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } - - std::vector 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 - bool addMe=true; - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + const std::vector& 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::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add - addMe=false; + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + addMe = false; } } // limit constraint such that only vertexes or faces or edges can be used depending on what was selected first - std::string searchStr(""); - if (subNames[subIt].find("Vertex")!=std::string::npos) + 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 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)){ + searchStr = "Face"; + for (unsigned int iStr = 0; iStr < (SubElements.size()); ++iStr){ + if ((SubElements[iStr].find(searchStr) == std::string::npos) && (SubElements.size() > 0)){ QString msg = tr("Only one type of selection (vertex,face or edge) per constraint allowed!"); QMessageBox::warning(this, tr("Selection error"), msg); addMe=false; @@ -454,73 +454,63 @@ void TaskFemConstraintDisplacement::addToSelection() } } if (addMe){ - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); + QSignalBlocker block(ui->lw_references); Objects.push_back(obj); SubElements.push_back(subNames[subIt]); ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); } } } //Update UI - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintDisplacement::removeFromSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintDisplacement* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + std::vector itemsToDel; + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector 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 - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion - itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } - - std::sort(itemsToDel.begin(),itemsToDel.end()); - while (itemsToDel.size()>0){ - Objects.erase(Objects.begin()+itemsToDel.back()); - SubElements.erase(SubElements.begin()+itemsToDel.back()); + std::sort(itemsToDel.begin(), itemsToDel.end()); + while (itemsToDel.size() > 0){ + Objects.erase(Objects.begin() + itemsToDel.back()); + SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - ui->lw_references->clear(); - for (unsigned int j=0;jlw_references->addItem(makeRefText(Objects[j], SubElements[j])); + { + QSignalBlocker block(ui->lw_references); + ui->lw_references->clear(); + for (unsigned int j = 0; j < Objects.size(); j++) { + ui->lw_references->addItem(makeRefText(Objects[j], SubElements[j])); + } } - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp index eb9ea92bf3..2000b2e5a3 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp @@ -47,9 +47,11 @@ #include "TaskFemConstraintFixed.h" #include "ui_TaskFemConstraintFixed.h" #include +#include #include #include #include +#include using namespace FemGui; @@ -117,116 +119,105 @@ void TaskFemConstraintFixed::updateUI() void TaskFemConstraintFixed::addToSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintFixed* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } - std::vector 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 - bool addMe=true; - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + bool addMe = true; + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add - addMe=false; + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + addMe = false; } } // limit constraint such that only vertexes or faces or edges can be used depending on what was selected first - std::string searchStr(""); - if (subNames[subIt].find("Vertex")!=std::string::npos) + 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 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)){ + searchStr = "Face"; + for (size_t iStr = 0; iStr < (SubElements.size()); ++iStr){ + if ((SubElements[iStr].find(searchStr) == std::string::npos) && (SubElements.size() > 0)){ QString msg = tr("Only one type of selection (vertex,face or edge) per constraint allowed!"); QMessageBox::warning(this, tr("Selection error"), msg); - addMe=false; + addMe = false; break; } } if (addMe){ - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); + QSignalBlocker block(ui->lw_references); Objects.push_back(obj); SubElements.push_back(subNames[subIt]); ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); } } } //Update UI - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintFixed::removeFromSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintFixed* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + std::vector itemsToDel; + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if(!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector 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 - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion - itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } - - std::sort(itemsToDel.begin(),itemsToDel.end()); - while (itemsToDel.size()>0){ - Objects.erase(Objects.begin()+itemsToDel.back()); - SubElements.erase(SubElements.begin()+itemsToDel.back()); + std::sort(itemsToDel.begin(), itemsToDel.end()); + while (itemsToDel.size() > 0){ + Objects.erase(Objects.begin() + itemsToDel.back()); + SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } //Update UI - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - ui->lw_references->clear(); - for (unsigned int j=0;jlw_references->addItem(makeRefText(Objects[j], SubElements[j])); + { + QSignalBlocker block(ui->lw_references); + ui->lw_references->clear(); + for (unsigned int j = 0; j < Objects.size(); j++) { + ui->lw_references->addItem(makeRefText(Objects[j], SubElements[j])); + } } - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp index c4acc7764a..af17e68986 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp @@ -738,7 +738,6 @@ void TaskFemConstraintFluidBoundary::addToSelection() QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -748,7 +747,6 @@ void TaskFemConstraintFluidBoundary::addToSelection() QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } - const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); for (size_t subIt = 0; subIt < subNames.size(); ++subIt) {// for every selected sub element @@ -761,7 +759,6 @@ void TaskFemConstraintFluidBoundary::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; if (subNames[subIt].find("Vertex") != std::string::npos) @@ -787,7 +784,6 @@ void TaskFemConstraintFluidBoundary::addToSelection() } } } - //Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); @@ -800,7 +796,6 @@ void TaskFemConstraintFluidBoundary::removeFromSelection() QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintFluidBoundary* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -810,7 +805,6 @@ void TaskFemConstraintFluidBoundary::removeFromSelection() QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } - const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); @@ -825,14 +819,12 @@ void TaskFemConstraintFluidBoundary::removeFromSelection() } } } - std::sort(itemsToDel.begin(), itemsToDel.end()); while (itemsToDel.size() > 0) { Objects.erase(Objects.begin() + itemsToDel.back()); SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI { QSignalBlocker block(ui->listReferences); @@ -841,7 +833,6 @@ void TaskFemConstraintFluidBoundary::removeFromSelection() ui->listReferences->addItem(makeRefText(Objects[j], SubElements[j])); } } - pcConstraint->References.setValues(Objects, SubElements); updateUI(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp index 2022bbe8d5..ea8472b6bd 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp @@ -46,6 +46,7 @@ #include "ui_TaskFemConstraintForce.h" #include "TaskFemConstraintForce.h" +#include #include #include #include @@ -61,7 +62,6 @@ #include #include -#include using namespace FemGui; using namespace Gui; @@ -149,7 +149,6 @@ void TaskFemConstraintForce::addToSelection() QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintForce* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -159,7 +158,6 @@ void TaskFemConstraintForce::addToSelection() QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } - const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) {// for every selected sub element @@ -172,7 +170,6 @@ 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; if (subNames[subIt].find("Vertex") != std::string::npos) @@ -198,7 +195,6 @@ void TaskFemConstraintForce::addToSelection() } } } - //Update UI pcConstraint->References.setValues(Objects, SubElements); updateUI(); @@ -211,7 +207,6 @@ void TaskFemConstraintForce::removeFromSelection() QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintForce* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); @@ -221,7 +216,6 @@ void TaskFemConstraintForce::removeFromSelection() QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } - const std::vector& subNames = it->getSubNames(); App::DocumentObject* obj = it->getObject(); @@ -236,14 +230,12 @@ void TaskFemConstraintForce::removeFromSelection() } } } - std::sort(itemsToDel.begin(), itemsToDel.end()); while (itemsToDel.size() > 0) { Objects.erase(Objects.begin() + itemsToDel.back()); SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } - //Update UI { QSignalBlocker block(ui->listReferences); @@ -252,7 +244,6 @@ void TaskFemConstraintForce::removeFromSelection() ui->listReferences->addItem(makeRefText(Objects[j], SubElements[j])); } } - pcConstraint->References.setValues(Objects, SubElements); updateUI(); } @@ -295,7 +286,6 @@ void TaskFemConstraintForce::onButtonDirection(const bool pressed) 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 diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp index de67cf104e..1d1d0f25e3 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp @@ -49,7 +49,9 @@ #include "TaskFemConstraintHeatflux.h" #include "ui_TaskFemConstraintHeatflux.h" #include +#include #include +#include using namespace FemGui; using namespace Gui; @@ -208,27 +210,26 @@ void TaskFemConstraintHeatflux::Flux() void TaskFemConstraintHeatflux::addToSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector subNames=it->getSubNames(); - - if (subNames.size()>0){ - for (unsigned int subIt=0;subIt<(subNames.size());++subIt){ - if (subNames[subIt].substr(0,4).compare(std::string("Face"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selection must only consist of faces!")); + if (subNames.size() > 0){ + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){ + if (subNames[subIt].substr(0, 4) != "Face") { + QMessageBox::warning(this, tr("Selection error"), tr("Selection must only consist of faces!")); return; } } @@ -236,38 +237,33 @@ void TaskFemConstraintHeatflux::addToSelection() else{ //fix me, if an object is selected completely, getSelectionEx does not return any SubElements } - - App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); - for (unsigned int subIt=0;subIt<(subNames.size());++subIt){// for every selected sub element - bool addMe=true; - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + bool addMe = true; + for (std::vector::iterator itr=std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + if (obj==Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add addMe=false; } } if (addMe){ - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); + QSignalBlocker block(ui->lw_references); Objects.push_back(obj); SubElements.push_back(subNames[subIt]); ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); } } } //Update UI - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintHeatflux::removeFromSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } @@ -275,19 +271,19 @@ void TaskFemConstraintHeatflux::removeFromSelection() Fem::ConstraintHeatflux* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - std::vector itemsToDel; + std::vector itemsToDel; for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(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; } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector subNames=it->getSubNames(); - - if (subNames.size()>0){ - for (unsigned int subIt=0;subIt<(subNames.size());++subIt){ - if (subNames[subIt].substr(0,4).compare(std::string("Face"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selection must only consist of faces!")); + if (subNames.size() > 0){ + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){ + if (subNames[subIt].substr(0, 4) != "Face") { + QMessageBox::warning(this, tr("Selection error"), tr("Selection must only consist of faces!")); return; } } @@ -295,39 +291,32 @@ void TaskFemConstraintHeatflux::removeFromSelection() else{ //fix me, if an object is selected completely, getSelectionEx does not return any SubElements } - - App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); - - for (unsigned int subIt=0;subIt<(subNames.size());++subIt){// for every selected sub element - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion - itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } - - std::sort(itemsToDel.begin(),itemsToDel.end()); - while (itemsToDel.size()>0){ - Objects.erase(Objects.begin()+itemsToDel.back()); - SubElements.erase(SubElements.begin()+itemsToDel.back()); + std::sort(itemsToDel.begin(), itemsToDel.end()); + while (itemsToDel.size() > 0){ + Objects.erase(Objects.begin() + itemsToDel.back()); + SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } //Update UI - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - ui->lw_references->clear(); - for (unsigned int j=0;jlw_references->addItem(makeRefText(Objects[j], SubElements[j])); + { + QSignalBlocker block(ui->lw_references); + ui->lw_references->clear(); + for (unsigned int j = 0; j < Objects.size(); j++) { + ui->lw_references->addItem(makeRefText(Objects[j], SubElements[j])); + } } - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp index be99decf3a..9673b23f4d 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp @@ -50,6 +50,8 @@ #include #include #include +#include +#include #include #include #include @@ -61,8 +63,6 @@ #include #include -#include - using namespace FemGui; using namespace Gui; @@ -129,15 +129,14 @@ void TaskFemConstraintPlaneRotation::updateUI() void TaskFemConstraintPlaneRotation::addToSelection() { int rows = ui->lw_references->model()->rowCount(); - if (rows==1){ + if (rows == 1){ QMessageBox::warning(this, tr("Selection error"), tr("Only one face can be selected for a plane rotation constraint!")); Gui::Selection().clearSelection(); return; } else { - std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } @@ -145,45 +144,41 @@ void TaskFemConstraintPlaneRotation::addToSelection() std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector subNames=it->getSubNames(); - App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); - - if (subNames.size()==1){ - for (unsigned int subIt=0;subIt<(subNames.size());++subIt){// for every selected sub element - bool addMe=true; - if ((subNames[subIt].substr(0,4) != "Face")) { + if (subNames.size() == 1){ + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + bool addMe = true; + if ((subNames[subIt].substr(0, 4) != "Face")) { QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); return; } Part::Feature* feat = static_cast(obj); TopoDS_Shape ref = feat->Shape.getShape().getSubShape(subNames[subIt].c_str()); - if ((subNames[subIt].substr(0,4) == "Face")) { + if ((subNames[subIt].substr(0, 4) == "Face")) { if (!Fem::Tools::isPlanar(TopoDS::Face(ref))) { QMessageBox::warning(this, tr("Selection error"), tr("Only planar faces can be picked")); return; } } - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])){// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + for (std::vector::iterator itr = std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])){// for every sub element in selection that matches one in old list + if (obj==Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add addMe=false; } } if (addMe){ - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - Objects.push_back(obj); - SubElements.push_back(subNames[subIt]); - ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); + QSignalBlocker block(ui->lw_references); + Objects.push_back(obj); + SubElements.push_back(subNames[subIt]); + ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); } } } @@ -193,7 +188,7 @@ void TaskFemConstraintPlaneRotation::addToSelection() return; } //Update UI - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } } @@ -202,54 +197,48 @@ void TaskFemConstraintPlaneRotation::addToSelection() void TaskFemConstraintPlaneRotation::removeFromSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintPlaneRotation* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + std::vector itemsToDel; + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } + const std::vector& subNames=it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector 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 - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion - itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } - - std::sort(itemsToDel.begin(),itemsToDel.end()); - while (itemsToDel.size()>0){ - Objects.erase(Objects.begin()+itemsToDel.back()); - SubElements.erase(SubElements.begin()+itemsToDel.back()); + std::sort(itemsToDel.begin(), itemsToDel.end()); + while (itemsToDel.size() > 0){ + Objects.erase(Objects.begin() + itemsToDel.back()); + SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } //Update UI - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - ui->lw_references->clear(); - for (unsigned int j=0;jlw_references->addItem(makeRefText(Objects[j], SubElements[j])); + { + QSignalBlocker block(ui->lw_references); + ui->lw_references->clear(); + for (unsigned int j = 0; j < Objects.size(); j++) { + ui->lw_references->addItem(makeRefText(Objects[j], SubElements[j])); + } } - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp index 08fba7f101..518c479cfb 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp @@ -46,9 +46,11 @@ #include "TaskFemConstraintPressure.h" #include "ui_TaskFemConstraintPressure.h" #include +#include #include #include #include +#include using namespace FemGui; @@ -132,106 +134,94 @@ void TaskFemConstraintPressure::onCheckReverse(const bool pressed) void TaskFemConstraintPressure::addToSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintPressure* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector 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 - bool addMe=true; - if (subNames[subIt].substr(0,4) != "Face") { + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + bool addMe = true; + if (subNames[subIt].substr(0, 4) != "Face") { QMessageBox::warning(this, tr("Selection error"), tr("Only faces can be picked")); return; } - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr,SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add addMe=false; } } if (addMe){ - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); + QSignalBlocker block(ui->lw_references); Objects.push_back(obj); SubElements.push_back(subNames[subIt]); ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); } } } //Update UI - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintPressure::removeFromSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintPressure* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - std::vector itemsToDel; + std::vector itemsToDel; for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(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; } + const std::vector& subNames=it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector 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 - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr,SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion - itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } - - std::sort(itemsToDel.begin(),itemsToDel.end()); - while (itemsToDel.size()>0){ - Objects.erase(Objects.begin()+itemsToDel.back()); - SubElements.erase(SubElements.begin()+itemsToDel.back()); + std::sort(itemsToDel.begin(), itemsToDel.end()); + while (itemsToDel.size() > 0){ + Objects.erase(Objects.begin() + itemsToDel.back()); + SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } //Update UI - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - ui->lw_references->clear(); - for (unsigned int j=0;jlw_references->addItem(makeRefText(Objects[j], SubElements[j])); + { + QSignalBlocker block(ui->lw_references); + ui->lw_references->clear(); + for (unsigned int j = 0; j < Objects.size(); j++) { + ui->lw_references->addItem(makeRefText(Objects[j], SubElements[j])); + } } - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp index 730689558a..c46a40a307 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp @@ -48,9 +48,11 @@ #include "TaskFemConstraintTemperature.h" #include "ui_TaskFemConstraintTemperature.h" #include +#include #include #include #include +#include using namespace FemGui; @@ -177,100 +179,89 @@ void TaskFemConstraintTemperature::Flux() void TaskFemConstraintTemperature::addToSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } - std::vector 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 - bool addMe=true; - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + bool addMe = true; + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr,SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add - addMe=false; + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + addMe = false; } } if (addMe){ - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); + QSignalBlocker block(ui->lw_references); Objects.push_back(obj); SubElements.push_back(subNames[subIt]); ui->lw_references->addItem(makeRefText(obj, subNames[subIt])); - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); } } } //Update UI - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } void TaskFemConstraintTemperature::removeFromSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintTemperature* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ + std::vector itemsToDel; + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); return; } + const std::vector& subNames=it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector 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 - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion - itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } - - std::sort(itemsToDel.begin(),itemsToDel.end()); - while (itemsToDel.size()>0){ - Objects.erase(Objects.begin()+itemsToDel.back()); - SubElements.erase(SubElements.begin()+itemsToDel.back()); + std::sort(itemsToDel.begin(), itemsToDel.end()); + while (itemsToDel.size() > 0){ + Objects.erase(Objects.begin() + itemsToDel.back()); + SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } //Update UI - disconnect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - ui->lw_references->clear(); - for (unsigned int j=0;jlw_references->addItem(makeRefText(Objects[j], SubElements[j])); + { + QSignalBlocker block(ui->lw_references); + ui->lw_references->clear(); + for (unsigned int j = 0; j < Objects.size(); j++) { + ui->lw_references->addItem(makeRefText(Objects[j], SubElements[j])); + } } - connect(ui->lw_references, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp index 348e81c3f4..101c57dc53 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp @@ -50,6 +50,7 @@ #include "ui_TaskFemConstraintTransform.h" #include #include +#include #include #include #include @@ -95,7 +96,6 @@ TaskFemConstraintTransform::TaskFemConstraintTransform(ViewProviderFemConstraint connect(ui->sp_Y, SIGNAL(valueChanged(int)), this, SLOT(y_Changed(int))); connect(ui->sp_Z, SIGNAL(valueChanged(int)), this, SLOT(z_Changed(int))); -/* Note: */ // Get the feature data Fem::ConstraintTransform* pcConstraint = static_cast(ConstraintView->getObject()); @@ -117,8 +117,6 @@ TaskFemConstraintTransform::TaskFemConstraintTransform(ViewProviderFemConstraint ui->rb_cylin->setChecked(1); } -/* */ - ui->lw_Rect->clear(); //Transformable surfaces @@ -245,7 +243,7 @@ void TaskFemConstraintTransform::addToSelection() { int rows = ui->lw_Rect->model()->rowCount(); std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } @@ -269,25 +267,24 @@ void TaskFemConstraintTransform::addToSelection() std::vector ObjDispl = pcConstraint->RefDispl.getValues(); std::vector SubElemDispl = pcConstraint->RefDispl.getSubValues(); for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(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 subNames=it->getSubNames(); - App::DocumentObject* obj = ConstraintView->getObject()->getDocument()->getObject(it->getFeatName()); - if (subNames.size()!=1){ + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); + if (subNames.size() != 1){ QMessageBox::warning(this, tr("Selection error"), tr("Only one face for transform constraint!")); Gui::Selection().clearSelection(); return; } - 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 bool addMe=true; - if (subNames[subIt].substr(0,4) != "Face") { + if (subNames[subIt].substr(0, 4) != "Face") { QMessageBox::warning(this, tr("Selection error"), tr("Only faces or edges can be picked")); return; } - if (subNames[subIt].substr(0,4) == "Face") { + if (subNames[subIt].substr(0, 4) == "Face") { if (ui->rb_cylin->isChecked()) { Part::Feature* feat = static_cast(obj); TopoDS_Shape ref = feat->Shape.getShape().getSubShape(subNames[subIt].c_str()); @@ -298,19 +295,19 @@ void TaskFemConstraintTransform::addToSelection() } } } - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (std::vector::iterator itr=std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add - addMe=false; + if (obj == Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so don't add + addMe = false; } } if (addMe){ disconnect(ui->lw_Rect, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(setSelection(QListWidgetItem*))); for (std::size_t i = 0; i < ObjDispl.size(); i++) { - if ((makeRefText(ObjDispl[i], SubElemDispl[i]))==(makeRefText(obj, subNames[subIt]))){ + if ((makeRefText(ObjDispl[i], SubElemDispl[i])) == (makeRefText(obj, subNames[subIt]))){ Objects.push_back(obj); SubElements.push_back(subNames[subIt]); ui->lw_Rect->addItem(makeRefText(obj, subNames[subIt])); @@ -327,7 +324,7 @@ void TaskFemConstraintTransform::addToSelection() } } //Update UI - pcConstraint->References.setValues(Objects,SubElements); + pcConstraint->References.setValues(Objects, SubElements); updateUI(); if (ui->rb_rect->isChecked()) { Base::Vector3d normal = pcConstraint->NormalDirection.getValue(); @@ -364,51 +361,45 @@ void TaskFemConstraintTransform::addToSelection() void TaskFemConstraintTransform::removeFromSelection() { std::vector selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document - if (selection.size()==0){ + if (selection.size() == 0){ QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!")); return; } - Fem::ConstraintTransform* pcConstraint = static_cast(ConstraintView->getObject()); std::vector Objects = pcConstraint->References.getValues(); std::vector SubElements = pcConstraint->References.getSubValues(); - std::vector itemsToDel; - for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object - if (static_cast(it->getTypeName()).substr(0,4).compare(std::string("Part"))!=0){ - QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!")); + std::vector itemsToDel; + for (std::vector::iterator it = selection.begin(); it != selection.end(); ++it){//for every selected object + if (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) { + QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!")); return; } + const std::vector& subNames = it->getSubNames(); + App::DocumentObject* obj = it->getObject(); - std::vector 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 - for (std::vector::iterator itr=std::find(SubElements.begin(),SubElements.end(),subNames[subIt]); - itr!= SubElements.end(); - itr = std::find(++itr,SubElements.end(),subNames[subIt])) + for (size_t subIt = 0; subIt < (subNames.size()); ++subIt){// for every selected sub element + for (std::vector::iterator itr = std::find(SubElements.begin(), SubElements.end(), subNames[subIt]); + itr != SubElements.end(); + itr = std::find(++itr, SubElements.end(), subNames[subIt])) {// for every sub element in selection that matches one in old list - if (obj==Objects[std::distance(SubElements.begin(),itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion - itemsToDel.push_back(std::distance(SubElements.begin(),itr)); + if (obj == Objects[std::distance(SubElements.begin(), itr)]){//if selected sub element's object equals the one in old list then it was added before so mark for deletion + itemsToDel.push_back(std::distance(SubElements.begin(), itr)); } } } } - - std::sort(itemsToDel.begin(),itemsToDel.end()); - while (itemsToDel.size()>0){ - Objects.erase(Objects.begin()+itemsToDel.back()); - SubElements.erase(SubElements.begin()+itemsToDel.back()); + std::sort(itemsToDel.begin(), itemsToDel.end()); + while (itemsToDel.size() > 0){ + Objects.erase(Objects.begin() + itemsToDel.back()); + SubElements.erase(SubElements.begin() + itemsToDel.back()); itemsToDel.pop_back(); } //Update UI - disconnect(ui->lw_Rect, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - ui->lw_Rect->clear(); - connect(ui->lw_Rect, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(setSelection(QListWidgetItem*))); - - pcConstraint->References.setValues(Objects,SubElements); + { + QSignalBlocker block(ui->lw_Rect); + ui->lw_Rect->clear(); + } + pcConstraint->References.setValues(Objects, SubElements); updateUI(); ui->sp_X->setValue(0); ui->sp_Y->setValue(0);