diff --git a/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp b/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp index ddd0e47358..f8d5959d41 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp @@ -215,9 +215,16 @@ void TaskFemConstraintContact::addToSelectionSlave() 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(); + 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& 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& 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& 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& subNames = it.getSubNames(); if (subNames.size() != 1) { QMessageBox::warning(this, tr("Selection error"), diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp index 03d60d5a83..7a929b9212 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp @@ -252,8 +252,16 @@ void TaskFemConstraintDisplacement::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(); + if (obj->getDocument() != pcConstraint->getDocument()) { + QMessageBox::warning(this, + tr("Selection error"), + tr("External object selection is not supported")); + return; + } + + const std::vector& 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); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp index f18e4ce6f4..334afac77f 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp @@ -119,9 +119,16 @@ void TaskFemConstraintFixed::addToSelection() 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()); + + 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& 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(); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp index 8f5088640a..6c0e196ab7 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp @@ -831,8 +831,16 @@ 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(); + if (obj->getDocument() != pcConstraint->getDocument()) { + QMessageBox::warning(this, + tr("Selection error"), + tr("External object selection is not supported")); + return; + } + + const std::vector& 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(); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp index d95938440e..a2d8c70d2c 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp @@ -136,8 +136,16 @@ 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(); + if (obj->getDocument() != pcConstraint->getDocument()) { + QMessageBox::warning(this, + tr("Selection error"), + tr("External object selection is not supported")); + return; + } + + const std::vector& 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(); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp index 9978a32a3d..a47e600982 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp @@ -276,9 +276,16 @@ void TaskFemConstraintHeatflux::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(); + 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& subNames = it.getSubNames(); if (!subNames.empty()) { for (const auto& subName : subNames) { if ((subName.substr(0, 4) != "Face") && (subName.substr(0, 4) != "Edge")) { diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp index a4457735b0..cafc4bbf47 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPlaneRotation.cpp @@ -149,9 +149,16 @@ void TaskFemConstraintPlaneRotation::addToSelection() tr("Selected object is not a part!")); return; } - const std::vector& 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& subNames = it.getSubNames(); if (subNames.size() == 1) { for (const auto& subName : subNames) { // for every selected sub element bool addMe = true; diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp index 86694f4bfc..a39931be50 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp @@ -141,9 +141,16 @@ void TaskFemConstraintPressure::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(); + 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& 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")) { diff --git a/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp b/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp index 67854bd768..f18a6f4692 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp @@ -279,15 +279,21 @@ void TaskFemConstraintRigidBody::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 (!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 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& subNames = it.getSubNames(); for (size_t subIt = 0; subIt < (subNames.size()); ++subIt) { // for every selected sub element bool addMe = true; diff --git a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp index 434dd60c5e..0657f8a40e 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp @@ -139,9 +139,16 @@ void TaskFemConstraintSpring::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(); + 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& subNames = it.getSubNames(); for (const auto& subName : subNames) { // for every selected sub element bool addMe = true; if (subName.substr(0, 4) != "Face") { diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp index 789c5f3779..1d412182cd 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp @@ -200,9 +200,16 @@ void TaskFemConstraintTemperature::addToSelection() 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()); + + 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& 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(); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp index 4b399e1737..3a91e79c1a 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp @@ -323,8 +323,16 @@ void TaskFemConstraintTransform::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(); + if (obj->getDocument() != pcConstraint->getDocument()) { + QMessageBox::warning(this, + tr("Selection error"), + tr("External object selection is not supported")); + return; + } + + const std::vector& subNames = it.getSubNames(); if (subNames.size() != 1) { QMessageBox::warning(this, tr("Selection error"), diff --git a/src/Mod/Fem/femguiutils/selection_widgets.py b/src/Mod/Fem/femguiutils/selection_widgets.py index 908a8932b1..48730817bf 100644 --- a/src/Mod/Fem/femguiutils/selection_widgets.py +++ b/src/Mod/Fem/femguiutils/selection_widgets.py @@ -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)