From 46b1a1ebfc4f77a02fe9ccd686df817c96fc453a Mon Sep 17 00:00:00 2001 From: Paddle Date: Thu, 11 Jan 2024 12:26:30 +0100 Subject: [PATCH] Assembly: set the rotating joint visible when dragging. --- src/Mod/Assembly/Gui/ViewProviderAssembly.cpp | 34 ++++++++++++++----- src/Mod/Assembly/Gui/ViewProviderAssembly.h | 4 +++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp index 2c90bcd1ac..8c70690d04 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp @@ -78,6 +78,7 @@ ViewProviderAssembly::ViewProviderAssembly() , canStartDragging(false) , partMoving(false) , enableMovement(true) + , jointVisibilityBackup(false) , docsToMove({}) {} @@ -536,14 +537,14 @@ ViewProviderAssembly::MoveMode ViewProviderAssembly::findMoveMode() if (docsToMove.size() == 1) { auto* assemblyPart = static_cast(getObject()); std::string partPropName; - App::DocumentObject* joint = + movingJoint = assemblyPart->getJointOfPartConnectingToGround(docsToMove[0].first, partPropName); - if (!joint) { + if (!movingJoint) { return MoveMode::Translation; } - JointType jointType = AssemblyObject::getJointType(joint); + JointType jointType = AssemblyObject::getJointType(movingJoint); if (jointType == JointType::Fixed) { // If fixed joint we need to find the upstream joint to find move mode. // For example : Gnd -(revolute)- A -(fixed)- B : if user try to move B, then we should @@ -561,27 +562,27 @@ ViewProviderAssembly::MoveMode ViewProviderAssembly::findMoveMode() docsToMove.emplace_back(upstreamPart, propPlacement->getValue()); } - joint = + movingJoint = assemblyPart->getJointOfPartConnectingToGround(docsToMove[0].first, partPropName); - if (!joint) { + if (!movingJoint) { return MoveMode::Translation; } - jointType = AssemblyObject::getJointType(joint); + jointType = AssemblyObject::getJointType(movingJoint); } const char* plcPropName = (partPropName == "Part1") ? "Placement1" : "Placement2"; const char* objPropName = (partPropName == "Part1") ? "Object1" : "Object2"; // jcsPlc is relative to the Object - jcsPlc = AssemblyObject::getPlacementFromProp(joint, plcPropName); + jcsPlc = AssemblyObject::getPlacementFromProp(movingJoint, plcPropName); // Make jcsGlobalPlc relative to the origin of the doc Base::Placement global_plc = - AssemblyObject::getGlobalPlacement(joint, objPropName, partPropName.c_str()); + AssemblyObject::getGlobalPlacement(movingJoint, objPropName, partPropName.c_str()); jcsGlobalPlc = global_plc * jcsPlc; // Add downstream parts so that they move together - auto downstreamParts = assemblyPart->getDownstreamParts(docsToMove[0].first, joint); + auto downstreamParts = assemblyPart->getDownstreamParts(docsToMove[0].first, movingJoint); for (auto part : downstreamParts) { auto* propPlacement = dynamic_cast(part->getPropertyByName("Placement")); @@ -590,6 +591,11 @@ ViewProviderAssembly::MoveMode ViewProviderAssembly::findMoveMode() } } + jointVisibilityBackup = movingJoint->Visibility.getValue(); + if (!jointVisibilityBackup) { + movingJoint->Visibility.setValue(true); + } + if (jointType == JointType::Revolute) { return MoveMode::RotationOnPlane; } @@ -599,6 +605,10 @@ ViewProviderAssembly::MoveMode ViewProviderAssembly::findMoveMode() else if (jointType == JointType::Cylindrical) { return MoveMode::TranslationOnAxisAndRotationOnePlane; } + else if (jointType == JointType::Distance) { + // depends on the type of distance. For example plane-plane: + // return MoveMode::TranslationOnPlane; + } } return MoveMode::Translation; } @@ -633,6 +643,12 @@ void ViewProviderAssembly::endMove() partMoving = false; canStartDragging = false; + if (movingJoint && !jointVisibilityBackup) { + movingJoint->Visibility.setValue(false); + } + + movingJoint = nullptr; + // enable selection after the move auto* view = dynamic_cast( Gui::Application::Instance->editDocument()->getActiveView()); diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.h b/src/Mod/Assembly/Gui/ViewProviderAssembly.h index 727a934d9d..9f57192e19 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.h +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.h @@ -75,6 +75,7 @@ public: { Translation, TranslationOnAxis, + TranslationOnPlane, Rotation, RotationOnPlane, TranslationOnAxisAndRotationOnePlane, @@ -119,12 +120,15 @@ public: bool canStartDragging; bool partMoving; bool enableMovement; + bool jointVisibilityBackup; int numberOfSel; Base::Vector3d initialPosition; Base::Vector3d initialPositionRot; Base::Placement jcsPlc; Base::Placement jcsGlobalPlc; + App::DocumentObject* movingJoint; + std::vector> objectMasses; std::vector> docsToMove; };