Assembly: Fix small bugs in AssemblyObject.cpp, JointObject.py and UtilsAssembly.py
This commit is contained in:
committed by
Yorik van Havre
parent
d5beaf900e
commit
b44505db39
@@ -159,7 +159,7 @@ int AssemblyObject::solve(bool enableRedo, bool updateJCS)
|
||||
}
|
||||
|
||||
try {
|
||||
mbdAssembly->solve();
|
||||
mbdAssembly->runPreDrag(); // solve() is causing some issues with limits.
|
||||
}
|
||||
catch (...) {
|
||||
Base::Console().Error("Solve failed\n");
|
||||
|
||||
@@ -160,7 +160,7 @@ class TestCore(unittest.TestCase):
|
||||
|
||||
# Step 2 : box with placement. Edge + Vertex
|
||||
plc = joint.Proxy.findPlacement(joint, box.Name, box, "Edge8", "Vertex8")
|
||||
targetPlc = App.Placement(App.Vector(L, W, 0), App.Rotation(0, 0, -90))
|
||||
targetPlc = App.Placement(App.Vector(L, W, 0), App.Rotation(0, -90, 270))
|
||||
self.assertTrue(plc.isSame(targetPlc, 1e-6), "'{}' failed - Step 2".format(operation))
|
||||
|
||||
# Step 3 : box with placement. Vertex
|
||||
|
||||
@@ -615,7 +615,7 @@ class Joint:
|
||||
return False
|
||||
|
||||
def undoPreSolve(self, joint):
|
||||
if self.partMovedByPresolved:
|
||||
if hasattr(self, "partMovedByPresolved") and self.partMovedByPresolved:
|
||||
self.partMovedByPresolved.Placement = self.presolveBackupPlc
|
||||
self.partMovedByPresolved = None
|
||||
|
||||
@@ -625,9 +625,7 @@ class Joint:
|
||||
globalJcsPlc1 = UtilsAssembly.getJcsGlobalPlc(joint.Placement1, joint.Object1, joint.Part1)
|
||||
globalJcsPlc2 = UtilsAssembly.getJcsGlobalPlc(joint.Placement2, joint.Object2, joint.Part2)
|
||||
|
||||
zAxis1 = globalJcsPlc1.Rotation.multVec(App.Vector(0, 0, 1))
|
||||
zAxis2 = globalJcsPlc2.Rotation.multVec(App.Vector(0, 0, 1))
|
||||
return zAxis1.dot(zAxis2) > 0
|
||||
return UtilsAssembly.arePlacementSameDir(globalJcsPlc1, globalJcsPlc2)
|
||||
|
||||
|
||||
class ViewProviderJoint:
|
||||
|
||||
@@ -844,6 +844,12 @@ def flipPlacement(plc):
|
||||
return applyRotationToPlacementAlongAxis(plc, 180, App.Vector(1, 0, 0))
|
||||
|
||||
|
||||
def arePlacementSameDir(plc1, plc2):
|
||||
zAxis1 = plc1.Rotation.multVec(App.Vector(0, 0, 1))
|
||||
zAxis2 = plc2.Rotation.multVec(App.Vector(0, 0, 1))
|
||||
return zAxis1.dot(zAxis2) > 0
|
||||
|
||||
|
||||
"""
|
||||
So here we want to find a placement that corresponds to a local coordinate system that would be placed at the selected vertex.
|
||||
- obj is usually a App::Link to a PartDesign::Body, or primitive, fasteners. But can also be directly the object.1
|
||||
@@ -905,7 +911,7 @@ def findPlacement(obj, part, elt, vtx, ignoreVertex=False):
|
||||
|
||||
if curve.TypeId == "Part::GeomLine":
|
||||
isLine = True
|
||||
plane_normal = curve.Direction
|
||||
plane_normal = round_vector(curve.Direction)
|
||||
plane_origin = App.Vector(0, 0, 0)
|
||||
plane = Part.Plane(plane_origin, plane_normal)
|
||||
plc.Rotation = App.Rotation(plane.Rotation)
|
||||
@@ -959,7 +965,7 @@ def findPlacement(obj, part, elt, vtx, ignoreVertex=False):
|
||||
if elt_type == "Vertex":
|
||||
plc.Rotation = App.Rotation()
|
||||
elif isLine:
|
||||
plane_normal = plc.Rotation.multVec(App.Vector(0, 0, 1))
|
||||
plane_normal = round_vector(plc.Rotation.multVec(App.Vector(0, 0, 1)))
|
||||
plane_origin = App.Vector(0, 0, 0)
|
||||
plane = Part.Plane(plane_origin, plane_normal)
|
||||
plc.Rotation = App.Rotation(plane.Rotation)
|
||||
@@ -974,6 +980,11 @@ def findPlacement(obj, part, elt, vtx, ignoreVertex=False):
|
||||
return plc
|
||||
|
||||
|
||||
def round_vector(v, decimals=10):
|
||||
"""Round each component of the vector to a specified number of decimal places."""
|
||||
return App.Vector(round(v.x, decimals), round(v.y, decimals), round(v.z, decimals))
|
||||
|
||||
|
||||
def saveAssemblyPartsPlacements(assembly):
|
||||
initialPlcs = {}
|
||||
assemblyParts = getMovablePartsWithin(assembly)
|
||||
|
||||
Reference in New Issue
Block a user