diff --git a/src/Mod/Assembly/App/AssemblyObject.cpp b/src/Mod/Assembly/App/AssemblyObject.cpp index 495536f6c8..d0c0e2fe26 100644 --- a/src/Mod/Assembly/App/AssemblyObject.cpp +++ b/src/Mod/Assembly/App/AssemblyObject.cpp @@ -1091,77 +1091,82 @@ void Assembly::AssemblyObject::create_mbdSimulationParameters(App::DocumentObjec std::shared_ptr AssemblyObject::makeMbdJointOfType(App::DocumentObject* joint, JointType type) { - if (type == JointType::Fixed) { - if (bundleFixed) { - return nullptr; - } - return CREATE::With(); - } - else if (type == JointType::Revolute) { - return CREATE::With(); - } - else if (type == JointType::Cylindrical) { - return CREATE::With(); - } - else if (type == JointType::Slider) { - return CREATE::With(); - } - else if (type == JointType::Ball) { - return CREATE::With(); - } - else if (type == JointType::Distance) { - return makeMbdJointDistance(joint); - } - else if (type == JointType::Parallel) { - return CREATE::With(); - } - else if (type == JointType::Perpendicular) { - return CREATE::With(); - } - else if (type == JointType::Angle) { - double angle = fabs(Base::toRadians(getJointDistance(joint))); - if (fmod(angle, 2 * std::numbers::pi) < Precision::Confusion()) { + switch (type) { + case JointType::Fixed: + if (bundleFixed) { + return nullptr; + } + return CREATE::With(); + + case JointType::Revolute: + return CREATE::With(); + + case JointType::Cylindrical: + return CREATE::With(); + + case JointType::Slider: + return CREATE::With(); + + case JointType::Ball: + return CREATE::With(); + + case JointType::Distance: + return makeMbdJointDistance(joint); + + case JointType::Parallel: return CREATE::With(); - } - else { + + case JointType::Perpendicular: + return CREATE::With(); + + case JointType::Angle: { + double angle = fabs(Base::toRadians(getJointDistance(joint))); + if (fmod(angle, 2 * std::numbers::pi) < Precision::Confusion()) { + return CREATE::With(); + } auto mbdJoint = CREATE::With(); mbdJoint->theIzJz = angle; return mbdJoint; } - } - else if (type == JointType::RackPinion) { - auto mbdJoint = CREATE::With(); - mbdJoint->pitchRadius = getJointDistance(joint); - return mbdJoint; - } - else if (type == JointType::Screw) { - int slidingIndex = slidingPartIndex(joint); - if (slidingIndex == 0) { // invalid this joint needs a slider + + case JointType::RackPinion: { + auto mbdJoint = CREATE::With(); + mbdJoint->pitchRadius = getJointDistance(joint); + return mbdJoint; + } + + case JointType::Screw: { + int slidingIndex = slidingPartIndex(joint); + if (slidingIndex == 0) { // invalid this joint needs a slider + return nullptr; + } + + if (slidingIndex != 1) { + swapJCS(joint); // make sure that sliding is first. + } + + auto mbdJoint = CREATE::With(); + mbdJoint->pitch = getJointDistance(joint); + return mbdJoint; + } + + case JointType::Gears: { + auto mbdJoint = CREATE::With(); + mbdJoint->radiusI = getJointDistance(joint); + mbdJoint->radiusJ = getJointDistance2(joint); + return mbdJoint; + } + + case JointType::Belt: { + auto mbdJoint = CREATE::With(); + mbdJoint->radiusI = getJointDistance(joint); + mbdJoint->radiusJ = -getJointDistance2(joint); + return mbdJoint; + } + + default: return nullptr; - } - - if (slidingIndex != 1) { - swapJCS(joint); // make sure that sliding is first. - } - - auto mbdJoint = CREATE::With(); - mbdJoint->pitch = getJointDistance(joint); - return mbdJoint; } - else if (type == JointType::Gears) { - auto mbdJoint = CREATE::With(); - mbdJoint->radiusI = getJointDistance(joint); - mbdJoint->radiusJ = getJointDistance2(joint); - return mbdJoint; - } - else if (type == JointType::Belt) { - auto mbdJoint = CREATE::With(); - mbdJoint->radiusI = getJointDistance(joint); - mbdJoint->radiusJ = -getJointDistance2(joint); - return mbdJoint; - } - - return nullptr; } std::shared_ptr AssemblyObject::makeMbdJointDistance(App::DocumentObject* joint) @@ -1173,186 +1178,154 @@ std::shared_ptr AssemblyObject::makeMbdJointDistance(App::DocumentObj auto* obj1 = getLinkedObjFromRef(joint, "Reference1"); auto* obj2 = getLinkedObjFromRef(joint, "Reference2"); - if (type == DistanceType::PointPoint) { - // Point to point distance, or ball joint if distance=0. - double distance = getJointDistance(joint); - if (distance < Precision::Confusion()) { - return CREATE::With(); + switch (type) { + case DistanceType::PointPoint: { + // Point to point distance, or ball joint if distance=0. + double distance = getJointDistance(joint); + if (distance < Precision::Confusion()) { + return CREATE::With(); + } + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = distance; + return mbdJoint; } - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = distance; - return mbdJoint; - } - // Edge - edge cases - else if (type == DistanceType::LineLine) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = getJointDistance(joint); - return mbdJoint; - } - else if (type == DistanceType::LineCircle) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = getJointDistance(joint) + getEdgeRadius(obj2, elt2); - return mbdJoint; - } - else if (type == DistanceType::CircleCircle) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = - getJointDistance(joint) + getEdgeRadius(obj1, elt1) + getEdgeRadius(obj2, elt2); - return mbdJoint; - } - // TODO : other cases od edge-edge : Ellipse, parabola, hyperbola... + // Edge - edge cases + case DistanceType::LineLine: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = getJointDistance(joint); + return mbdJoint; + } - // Face - Face cases - else if (type == DistanceType::PlanePlane) { - auto mbdJoint = CREATE::With(); - mbdJoint->offset = getJointDistance(joint); - return mbdJoint; - } - else if (type == DistanceType::PlaneCylinder) { - auto mbdJoint = CREATE::With(); - mbdJoint->offset = getJointDistance(joint) + getFaceRadius(obj2, elt2); - return mbdJoint; - } - else if (type == DistanceType::PlaneSphere) { - auto mbdJoint = CREATE::With(); - mbdJoint->offset = getJointDistance(joint) + getFaceRadius(obj2, elt2); - return mbdJoint; - } - else if (type == DistanceType::PlaneCone) { - // TODO - } - else if (type == DistanceType::PlaneTorus) { - auto mbdJoint = CREATE::With(); - mbdJoint->offset = getJointDistance(joint); - return mbdJoint; - } - else if (type == DistanceType::CylinderCylinder) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = - getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2); - return mbdJoint; - } - else if (type == DistanceType::CylinderSphere) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = - getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2); - return mbdJoint; - } - else if (type == DistanceType::CylinderCone) { - // TODO - } - else if (type == DistanceType::CylinderTorus) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = - getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2); - return mbdJoint; - } - else if (type == DistanceType::ConeCone) { - // TODO - } - else if (type == DistanceType::ConeTorus) { - // TODO - } - else if (type == DistanceType::ConeSphere) { - // TODO - } - else if (type == DistanceType::TorusTorus) { - auto mbdJoint = CREATE::With(); - mbdJoint->offset = getJointDistance(joint); - return mbdJoint; - } - else if (type == DistanceType::TorusSphere) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = - getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2); - return mbdJoint; - } - else if (type == DistanceType::SphereSphere) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = - getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2); - return mbdJoint; - } + case DistanceType::LineCircle: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = getJointDistance(joint) + getEdgeRadius(obj2, elt2); + return mbdJoint; + } - // Point - Face cases - else if (type == DistanceType::PointPlane) { - auto mbdJoint = CREATE::With(); - mbdJoint->offset = getJointDistance(joint); - return mbdJoint; - } - else if (type == DistanceType::PointCylinder) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = getJointDistance(joint) + getFaceRadius(obj1, elt1); - return mbdJoint; - } - else if (type == DistanceType::PointSphere) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = getJointDistance(joint) + getFaceRadius(obj1, elt1); - return mbdJoint; - } - else if (type == DistanceType::PointCone) { - // TODO - } - else if (type == DistanceType::PointTorus) { - // TODO - } + case DistanceType::CircleCircle: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = + getJointDistance(joint) + getEdgeRadius(obj1, elt1) + getEdgeRadius(obj2, elt2); + return mbdJoint; + } - // Edge - Face cases - else if (type == DistanceType::LinePlane) { - auto mbdJoint = CREATE::With(); - mbdJoint->offset = getJointDistance(joint); - return mbdJoint; - } - else if (type == DistanceType::LineCylinder) { - // TODO - } - else if (type == DistanceType::LineSphere) { - // TODO - } - else if (type == DistanceType::LineCone) { - // TODO - } - else if (type == DistanceType::LineTorus) { - // TODO - } + // Face - Face cases + case DistanceType::PlanePlane: { + auto mbdJoint = CREATE::With(); + mbdJoint->offset = getJointDistance(joint); + return mbdJoint; + } - else if (type == DistanceType::CurvePlane) { - // TODO - } - else if (type == DistanceType::CurveCylinder) { - // TODO - } - else if (type == DistanceType::CurveSphere) { - // TODO - } - else if (type == DistanceType::CurveCone) { - // TODO - } - else if (type == DistanceType::CurveTorus) { - // TODO - } + case DistanceType::PlaneCylinder: { + auto mbdJoint = CREATE::With(); + mbdJoint->offset = getJointDistance(joint) + getFaceRadius(obj2, elt2); + return mbdJoint; + } - // Point - Edge cases - else if (type == DistanceType::PointLine) { - auto mbdJoint = CREATE::With(); - mbdJoint->distanceIJ = getJointDistance(joint); - return mbdJoint; - } - else if (type == DistanceType::PointCurve) { - // For other curves we do a point in plane-of-the-curve. - // Maybe it would be best tangent / distance to the conic? - // For arcs and circles we could use ASMTRevSphJoint. But is it better than pointInPlane? - auto mbdJoint = CREATE::With(); - mbdJoint->offset = getJointDistance(joint); - return mbdJoint; - } + case DistanceType::PlaneSphere: { + auto mbdJoint = CREATE::With(); + mbdJoint->offset = getJointDistance(joint) + getFaceRadius(obj2, elt2); + return mbdJoint; + } + case DistanceType::PlaneTorus: { + auto mbdJoint = CREATE::With(); + mbdJoint->offset = getJointDistance(joint); + return mbdJoint; + } - // by default we make a planar joint. - auto mbdJoint = CREATE::With(); - mbdJoint->offset = getJointDistance(joint); - return mbdJoint; + case DistanceType::CylinderCylinder: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = + getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2); + return mbdJoint; + } + + case DistanceType::CylinderSphere: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = + getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2); + return mbdJoint; + } + + case DistanceType::CylinderTorus: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = + getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2); + return mbdJoint; + } + + case DistanceType::TorusTorus: { + auto mbdJoint = CREATE::With(); + mbdJoint->offset = getJointDistance(joint); + return mbdJoint; + } + + case DistanceType::TorusSphere: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = + getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2); + return mbdJoint; + } + + case DistanceType::SphereSphere: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = + getJointDistance(joint) + getFaceRadius(obj1, elt1) + getFaceRadius(obj2, elt2); + return mbdJoint; + } + + // Point - Face cases + case DistanceType::PointPlane: { + auto mbdJoint = CREATE::With(); + mbdJoint->offset = getJointDistance(joint); + return mbdJoint; + } + + case DistanceType::PointCylinder: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = getJointDistance(joint) + getFaceRadius(obj1, elt1); + return mbdJoint; + } + + case DistanceType::PointSphere: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = getJointDistance(joint) + getFaceRadius(obj1, elt1); + return mbdJoint; + } + + // Edge - Face cases + case DistanceType::LinePlane: { + auto mbdJoint = CREATE::With(); + mbdJoint->offset = getJointDistance(joint); + return mbdJoint; + } + + // Point - Edge cases + case DistanceType::PointLine: { + auto mbdJoint = CREATE::With(); + mbdJoint->distanceIJ = getJointDistance(joint); + return mbdJoint; + } + + case DistanceType::PointCurve: { + // For other curves we do a point in plane-of-the-curve. + // Maybe it would be best tangent / distance to the conic? + // For arcs and circles we could use ASMTRevSphJoint. But is it better than + // pointInPlane? + auto mbdJoint = CREATE::With(); + mbdJoint->offset = getJointDistance(joint); + return mbdJoint; + } + + default: { + // by default we make a planar joint. + auto mbdJoint = CREATE::With(); + mbdJoint->offset = getJointDistance(joint); + return mbdJoint; + } + } } std::vector>