Fem: Do not allow selection of external objects for analysis objects - fixes #23834

This commit is contained in:
marioalexis
2025-09-16 00:24:21 -03:00
committed by Chris Hennes
parent a85f53d0bb
commit df82e7b71c
13 changed files with 129 additions and 28 deletions

View File

@@ -215,9 +215,16 @@ void TaskFemConstraintContact::addToSelectionSlave()
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();
App::DocumentObject* obj = it.getObject();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
if (subNames.size() != 1) {
QMessageBox::warning(this,
tr("Selection error"),
@@ -276,9 +283,9 @@ void TaskFemConstraintContact::removeFromSelectionSlave()
QMessageBox::warning(this, tr("Selection error"), tr("Selected object is not a part!"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
const App::DocumentObject* obj = it.getObject();
for (const auto& subName : subNames) { // for every selected sub element
for (auto itr = std::ranges::find(SubElements, subName); itr != SubElements.end();
itr = std::find(++itr,
@@ -343,8 +350,15 @@ void TaskFemConstraintContact::addToSelectionMaster()
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();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
if (subNames.size() != 1) {
QMessageBox::warning(this,
tr("Selection error"),

View File

@@ -252,8 +252,16 @@ void TaskFemConstraintDisplacement::addToSelection()
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();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
for (const auto& subName : subNames) { // for every selected sub element
bool addMe = true;
for (auto itr = std::ranges::find(SubElements.begin(), SubElements.end(), subName);

View File

@@ -119,9 +119,16 @@ void TaskFemConstraintFixed::addToSelection()
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());
App::DocumentObject* obj = it.getObject();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
for (const auto& subName : subNames) { // for every selected sub element
bool addMe = true;
for (auto itr = std::ranges::find(SubElements, subName); itr != SubElements.end();

View File

@@ -831,8 +831,16 @@ void TaskFemConstraintFluidBoundary::addToSelection()
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();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
for (const auto& subName : subNames) { // for every selected sub element
bool addMe = true;
for (auto itr = std::ranges::find(SubElements, subName); itr != SubElements.end();

View File

@@ -136,8 +136,16 @@ void TaskFemConstraintForce::addToSelection()
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();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
for (const auto& subName : subNames) { // for every selected sub element
bool addMe = true;
for (auto itr = std::ranges::find(SubElements, subName); itr != SubElements.end();

View File

@@ -276,9 +276,16 @@ void TaskFemConstraintHeatflux::addToSelection()
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();
App::DocumentObject* obj = it.getObject();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
if (!subNames.empty()) {
for (const auto& subName : subNames) {
if ((subName.substr(0, 4) != "Face") && (subName.substr(0, 4) != "Edge")) {

View File

@@ -149,9 +149,16 @@ void TaskFemConstraintPlaneRotation::addToSelection()
tr("Selected object is not a part!"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
App::DocumentObject* obj = it.getObject();
App::DocumentObject* obj = it.getObject();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
if (subNames.size() == 1) {
for (const auto& subName : subNames) { // for every selected sub element
bool addMe = true;

View File

@@ -141,9 +141,16 @@ void TaskFemConstraintPressure::addToSelection()
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();
App::DocumentObject* obj = it.getObject();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
for (const auto& subName : subNames) { // for every selected sub element
bool addMe = true;
if ((subName.substr(0, 4) != "Face") && (subName.substr(0, 4) != "Edge")) {

View File

@@ -279,15 +279,21 @@ void TaskFemConstraintRigidBody::addToSelection()
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 (!it->isObjectTypeOf(Part::Feature::getClassTypeId())) {
for (auto& it : selection) { // 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());
App::DocumentObject* obj = it.getObject();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
for (size_t subIt = 0; subIt < (subNames.size());
++subIt) { // for every selected sub element
bool addMe = true;

View File

@@ -139,9 +139,16 @@ void TaskFemConstraintSpring::addToSelection()
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();
App::DocumentObject* obj = it.getObject();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
for (const auto& subName : subNames) { // for every selected sub element
bool addMe = true;
if (subName.substr(0, 4) != "Face") {

View File

@@ -200,9 +200,16 @@ void TaskFemConstraintTemperature::addToSelection()
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());
App::DocumentObject* obj = it.getObject();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
for (const auto& subName : subNames) { // for every selected sub element
bool addMe = true;
for (auto itr = std::ranges::find(SubElements, subName); itr != SubElements.end();

View File

@@ -323,8 +323,16 @@ void TaskFemConstraintTransform::addToSelection()
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();
if (obj->getDocument() != pcConstraint->getDocument()) {
QMessageBox::warning(this,
tr("Selection error"),
tr("External object selection is not supported"));
return;
}
const std::vector<std::string>& subNames = it.getSubNames();
if (subNames.size() != 1) {
QMessageBox::warning(this,
tr("Selection error"),

View File

@@ -603,6 +603,13 @@ class FemSelectionObserver:
def addSelection(self, docName, objName, sub, pos):
selected_object = FreeCAD.getDocument(docName).getObject(objName) # get the obj objName
if FreeCADGui.editDocument().getInEdit().Object.Document != selected_object.Document:
QtGui.QMessageBox.critical(
None, "Selection error", "External object selection is not supported"
)
FreeCADGui.Selection.clearSelection()
return
self.added_obj = (selected_object, sub)
# on double click on a vertex of a solid sub is None and obj is the solid
self.parseSelectionFunction(self.added_obj)