[FEM] use std::unique_ptr for all dialog objects

- also fix too long line
- also further clang automatic code style changes
This commit is contained in:
Uwe
2023-03-22 19:13:24 +01:00
parent 48a921d2b7
commit 97103b3bf3
42 changed files with 1463 additions and 831 deletions

View File

@@ -47,12 +47,13 @@ using namespace Gui;
/* TRANSLATOR FemGui::TaskFemConstraintForce */
TaskFemConstraintForce::TaskFemConstraintForce(ViewProviderFemConstraintForce* ConstraintView, QWidget* parent)
: TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintForce")
TaskFemConstraintForce::TaskFemConstraintForce(ViewProviderFemConstraintForce* ConstraintView,
QWidget* parent)
: TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintForce"),
ui(new Ui_TaskFemConstraintForce)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskFemConstraintForce();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
@@ -78,7 +79,8 @@ TaskFemConstraintForce::TaskFemConstraintForce(ViewProviderFemConstraintForce* C
ui->checkReverse->blockSignals(true);
// Get the feature data
Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
Fem::ConstraintForce* pcConstraint =
static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
double f = pcConstraint->Force.getValue();
std::vector<App::DocumentObject*> Objects = pcConstraint->References.getValues();
std::vector<std::string> SubElements = pcConstraint->References.getSubValues();
@@ -123,33 +125,45 @@ void TaskFemConstraintForce::updateUI()
void TaskFemConstraintForce::addToSelection()
{
std::vector<Gui::SelectionObject> selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document
std::vector<Gui::SelectionObject> selection =
Gui::Selection().getSelectionEx();// gets vector of selected objects of active document
if (selection.empty()) {
QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!"));
return;
}
Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
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();
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object
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();
for (size_t 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;
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
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;
}
}
// limit constraint such that only vertexes or faces or edges can be used depending on what was selected first
// 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)
searchStr = "Vertex";
@@ -160,7 +174,8 @@ void TaskFemConstraintForce::addToSelection()
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!");
QString msg = tr(
"Only one type of selection (vertex,face or edge) per constraint allowed!");
QMessageBox::warning(this, tr("Selection error"), msg);
addMe = false;
break;
@@ -174,23 +189,26 @@ void TaskFemConstraintForce::addToSelection()
}
}
}
//Update UI
// Update UI
pcConstraint->References.setValues(Objects, SubElements);
updateUI();
}
void TaskFemConstraintForce::removeFromSelection()
{
std::vector<Gui::SelectionObject> selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document
std::vector<Gui::SelectionObject> selection =
Gui::Selection().getSelectionEx();// gets vector of selected objects of active document
if (selection.empty()) {
QMessageBox::warning(this, tr("Selection error"), tr("Nothing selected!"));
return;
}
Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
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<size_t> itemsToDel;
for (std::vector<Gui::SelectionObject>::iterator it = selection.begin(); it != selection.end(); ++it) {//for every selected object
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;
@@ -198,12 +216,20 @@ void TaskFemConstraintForce::removeFromSelection()
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
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
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));
}
}
@@ -215,7 +241,7 @@ void TaskFemConstraintForce::removeFromSelection()
SubElements.erase(SubElements.begin() + itemsToDel.back());
itemsToDel.pop_back();
}
//Update UI
// Update UI
{
QSignalBlocker block(ui->listReferences);
ui->listReferences->clear();
@@ -229,12 +255,15 @@ void TaskFemConstraintForce::removeFromSelection()
void TaskFemConstraintForce::onForceChanged(double f)
{
Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
Fem::ConstraintForce* pcConstraint =
static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
pcConstraint->Force.setValue(f);
}
void TaskFemConstraintForce::onReferenceDeleted() {
TaskFemConstraintForce::removeFromSelection(); //OvG: On right-click face is automatically selected, so just remove
void TaskFemConstraintForce::onReferenceDeleted()
{
TaskFemConstraintForce::removeFromSelection();// OvG: On right-click face is automatically
// selected, so just remove
}
std::pair<App::DocumentObject*, std::string>
@@ -303,7 +332,8 @@ void TaskFemConstraintForce::onButtonDirection(const bool pressed)
try {
std::vector<std::string> direction(1, link.second);
Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
Fem::ConstraintForce* pcConstraint =
static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
// update the direction
pcConstraint->Direction.setValue(link.first, direction);
@@ -318,7 +348,8 @@ void TaskFemConstraintForce::onButtonDirection(const bool pressed)
void TaskFemConstraintForce::onCheckReverse(const bool pressed)
{
Fem::ConstraintForce* pcConstraint = static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
Fem::ConstraintForce* pcConstraint =
static_cast<Fem::ConstraintForce*>(ConstraintView->getObject());
pcConstraint->Reversed.setValue(pressed);
}
@@ -363,9 +394,7 @@ bool TaskFemConstraintForce::getReverse() const
}
TaskFemConstraintForce::~TaskFemConstraintForce()
{
delete ui;
}
{}
bool TaskFemConstraintForce::event(QEvent* e)
{
@@ -413,27 +442,32 @@ void TaskDlgFemConstraintForce::open()
QString msg = QObject::tr("Constraint force");
Gui::Command::openCommand((const char*)msg.toUtf8());
ConstraintView->setVisible(true);
Gui::Command::doCommand(Gui::Command::Doc, ViewProviderFemConstraint::gethideMeshShowPartStr((static_cast<Fem::Constraint*>(ConstraintView->getObject()))->getNameInDocument()).c_str()); //OvG: Hide meshes and show parts
Gui::Command::doCommand(
Gui::Command::Doc,
ViewProviderFemConstraint::gethideMeshShowPartStr(
(static_cast<Fem::Constraint*>(ConstraintView->getObject()))->getNameInDocument())
.c_str());// OvG: Hide meshes and show parts
}
}
bool TaskDlgFemConstraintForce::accept()
{
std::string name = ConstraintView->getObject()->getNameInDocument();
const TaskFemConstraintForce* parameterForce = static_cast<const TaskFemConstraintForce*>(parameter);
const TaskFemConstraintForce* parameterForce =
static_cast<const TaskFemConstraintForce*>(parameter);
try {
//Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "FEM force constraint changed"));
// Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "FEM force constraint changed"));
if (parameterForce->getForce() <= 0)
{
QMessageBox::warning(parameter, tr("Input error"), tr("Please specify a force greater than 0"));
if (parameterForce->getForce() <= 0) {
QMessageBox::warning(
parameter, tr("Input error"), tr("Please specify a force greater than 0"));
return false;
}
else
{
else {
QByteArray num = QByteArray::number(parameterForce->getForce());
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Force = %s", name.c_str(), num.data());
Gui::Command::doCommand(
Gui::Command::Doc, "App.ActiveDocument.%s.Force = %s", name.c_str(), num.data());
}
std::string dirname = parameterForce->getDirectionName().data();
@@ -444,16 +478,26 @@ bool TaskDlgFemConstraintForce::accept()
QString buf = QString::fromUtf8("(App.ActiveDocument.%1,[\"%2\"])");
buf = buf.arg(QString::fromStdString(dirname));
buf = buf.arg(QString::fromStdString(dirobj));
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Direction = %s", name.c_str(), buf.toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Direction = %s",
name.c_str(),
buf.toStdString().c_str());
}
else {
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Direction = None", name.c_str());
Gui::Command::doCommand(
Gui::Command::Doc, "App.ActiveDocument.%s.Direction = None", name.c_str());
}
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Reversed = %s", name.c_str(), parameterForce->getReverse() ? "True" : "False");
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Reversed = %s",
name.c_str(),
parameterForce->getReverse() ? "True" : "False");
scale = parameterForce->getScale(); //OvG: determine modified scale
Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.%s.Scale = %s", name.c_str(), scale.c_str()); //OvG: implement modified scale
scale = parameterForce->getScale();// OvG: determine modified scale
Gui::Command::doCommand(Gui::Command::Doc,
"App.ActiveDocument.%s.Scale = %s",
name.c_str(),
scale.c_str());// OvG: implement modified scale
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));