Assembly: Use icon overlay for unconnected joints instead of annoying warning. (#22662)
* Core: FeaturePython : Add getOverlayIcons to python interface * Assembly: unconnected joints icon overlay Fix #22643 * Update src/Mod/Assembly/Gui/ViewProviderAssembly.cpp Co-authored-by: Kacper Donat <kadet1090@gmail.com> * Update AssemblyObject.cpp * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update ViewProviderFeaturePython.h * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update ViewProviderFeaturePython.h * Update JointObject.py * Update ViewProviderFeaturePython.h * Update ViewProviderFeaturePython.cpp * Update Application.cpp * Update ViewProviderFeaturePython.cpp * Update ViewProviderFeaturePython.h * Update ViewProviderAssembly.cpp --------- Co-authored-by: Kacper Donat <kadet1090@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -939,23 +939,17 @@ void AssemblyObject::removeUnconnectedJoints(std::vector<App::DocumentObject*>&
|
||||
}
|
||||
|
||||
// Filter out unconnected joints
|
||||
joints.erase(
|
||||
std::remove_if(
|
||||
joints.begin(),
|
||||
joints.end(),
|
||||
[&](App::DocumentObject* joint) {
|
||||
App::DocumentObject* obj1 = getMovingPartFromRef(this, joint, "Reference1");
|
||||
App::DocumentObject* obj2 = getMovingPartFromRef(this, joint, "Reference2");
|
||||
if (!isObjInSetOfObjRefs(obj1, connectedParts)
|
||||
|| !isObjInSetOfObjRefs(obj2, connectedParts)) {
|
||||
Base::Console().warning(
|
||||
"%s is unconnected to a grounded part so it is ignored.\n",
|
||||
joint->getFullName());
|
||||
return true; // Remove joint if any connected object is not in connectedParts
|
||||
}
|
||||
return false;
|
||||
}),
|
||||
joints.end());
|
||||
joints.erase(std::remove_if(joints.begin(),
|
||||
joints.end(),
|
||||
[&](App::DocumentObject* joint) {
|
||||
App::DocumentObject* obj1 =
|
||||
getMovingPartFromRef(this, joint, "Reference1");
|
||||
App::DocumentObject* obj2 =
|
||||
getMovingPartFromRef(this, joint, "Reference2");
|
||||
return (!isObjInSetOfObjRefs(obj1, connectedParts)
|
||||
|| !isObjInSetOfObjRefs(obj2, connectedParts));
|
||||
}),
|
||||
joints.end());
|
||||
}
|
||||
|
||||
void AssemblyObject::traverseAndMarkConnectedParts(App::DocumentObject* currentObj,
|
||||
|
||||
@@ -212,6 +212,52 @@ bool ViewProviderAssembly::canDragObjectToTarget(App::DocumentObject* obj,
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderAssembly::updateData(const App::Property* prop)
|
||||
{
|
||||
auto* obj = static_cast<Assembly::AssemblyObject*>(pcObject);
|
||||
if (prop == &obj->Group) {
|
||||
// Defer the icon update until the event loop is idle.
|
||||
// This ensures the assembly has had a chance to recompute its
|
||||
// connectivity state before we query it.
|
||||
|
||||
// We can't capture the raw 'obj' pointer because it may be deleted
|
||||
// by the time the timer fires. Instead, we capture the names of the
|
||||
// document and the object, and look them up again.
|
||||
if (!obj->getDocument()) {
|
||||
return; // Should not happen, but a good safeguard
|
||||
}
|
||||
const std::string docName = obj->getDocument()->getName();
|
||||
const std::string objName = obj->getNameInDocument();
|
||||
|
||||
QTimer::singleShot(0, [docName, objName]() {
|
||||
// Re-acquire the document and the object safely.
|
||||
App::Document* doc = App::GetApplication().getDocument(docName.c_str());
|
||||
if (!doc) {
|
||||
return; // Document was closed
|
||||
}
|
||||
|
||||
auto* pcObj = doc->getObject(objName.c_str());
|
||||
auto* obj = static_cast<Assembly::AssemblyObject*>(pcObj);
|
||||
|
||||
// Now we can safely check if the object still exists and is attached.
|
||||
if (!obj || !obj->isAttachedToDocument()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> joints = obj->getJoints(false);
|
||||
for (auto* joint : joints) {
|
||||
Gui::ViewProvider* jointVp = Gui::Application::Instance->getViewProvider(joint);
|
||||
if (jointVp) {
|
||||
jointVp->signalChangeIcon();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
Gui::ViewProviderPart::updateData(prop);
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewProviderAssembly::setEdit(int mode)
|
||||
{
|
||||
if (mode == ViewProvider::Default) {
|
||||
|
||||
@@ -107,6 +107,8 @@ public:
|
||||
bool onDelete(const std::vector<std::string>& subNames) override;
|
||||
bool canDelete(App::DocumentObject* obj) const override;
|
||||
|
||||
void updateData(const App::Property*) override;
|
||||
|
||||
/** @name enter/exit edit mode */
|
||||
//@{
|
||||
bool setEdit(int ModNum) override;
|
||||
|
||||
@@ -573,6 +573,9 @@ class Joint:
|
||||
for obj in joint.InList:
|
||||
if obj.isDerivedFrom("Assembly::AssemblyObject"):
|
||||
return obj
|
||||
elif obj.isDerivedFrom("Assembly::AssemblyLink"):
|
||||
return self.getAssembly(obj)
|
||||
|
||||
return None
|
||||
|
||||
def setJointType(self, joint, newType):
|
||||
@@ -946,6 +949,24 @@ class ViewProviderJoint:
|
||||
|
||||
return ":/icons/Assembly_CreateJoint.svg"
|
||||
|
||||
def getOverlayIcons(self):
|
||||
"""
|
||||
Return a dictionary of overlay icons.
|
||||
Keys are positions from Gui.IconPosition.
|
||||
Values are the icon resource names.
|
||||
"""
|
||||
|
||||
overlays = {}
|
||||
|
||||
assembly = self.app_obj.Proxy.getAssembly(self.app_obj)
|
||||
# Assuming Reference1 corresponds to the first part link
|
||||
if hasattr(self.app_obj, "Reference1"):
|
||||
part = UtilsAssembly.getMovingPart(assembly, self.app_obj.Reference1)
|
||||
if part is not None and not assembly.isPartConnected(part):
|
||||
overlays[Gui.IconPosition.BottomLeft] = "Part_Detached"
|
||||
|
||||
return overlays
|
||||
|
||||
def dumps(self):
|
||||
"""When saving the document this object gets stored using Python's json module.\
|
||||
Since we have some un-serializable parts here -- the Coin stuff -- we must define this method\
|
||||
|
||||
Reference in New Issue
Block a user