[FEM] spread the fixes from commit ef370e6d to the other dialogs

This commit is contained in:
donovaly
2020-02-28 01:58:42 +01:00
committed by wwmayer
parent 318e5603c3
commit 10cfdceb7a
10 changed files with 383 additions and 497 deletions

View File

@@ -49,9 +49,11 @@
#include "TaskFemConstraintDisplacement.h"
#include "ui_TaskFemConstraintDisplacement.h"
#include <App/Application.h>
#include <Base/Tools.h>
#include <Gui/Command.h>
#include <Gui/Selection.h>
#include <Gui/SelectionFilter.h>
#include <Mod/Part/App/PartFeature.h>
using namespace FemGui;
@@ -410,43 +412,41 @@ void TaskFemConstraintDisplacement::rotfreez(int val){
void TaskFemConstraintDisplacement::addToSelection()
{
std::vector<Gui::SelectionObject> 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<Fem::ConstraintDisplacement*>(ConstraintView->getObject());
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();
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){
QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!"));
for (std::vector<Gui::SelectionObject>::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<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
bool addMe=true;
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]))
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();
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<Gui::SelectionObject> 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<Fem::ConstraintDisplacement*>(ConstraintView->getObject());
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();
std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
std::vector<unsigned int> 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){
QMessageBox::warning(this, tr("Selection error"),tr("Selected object is not a part!"));
std::vector<size_t> itemsToDel;
for (std::vector<Gui::SelectionObject>::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<std::string>& subNames = it->getSubNames();
App::DocumentObject* obj = it->getObject();
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
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]))
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]))
{// 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;j<Objects.size();j++){
ui->lw_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();
}