Merge branch 'master' of github.com:FreeCAD/FreeCAD

This commit is contained in:
Yorik van Havre
2022-04-21 14:18:17 +02:00
4 changed files with 46 additions and 13 deletions

View File

@@ -2161,7 +2161,8 @@ class DraftToolBar:
def toggleAngle(self,b):
self.alock = self.angleLock.isChecked()
if b:
self.update_cartesian_coords()
if self.alock:
if not self.globalMode:
angle_vec = FreeCAD.DraftWorkingPlane.getGlobalRot(self.angle)
else:

View File

@@ -126,7 +126,9 @@ class Plane:
def copy(self):
"""Return a new plane that is a copy of the present object."""
return plane(u=self.u, v=self.v, w=self.axis, pos=self.position)
p = plane(u=self.u, v=self.v, w=self.axis, pos=self.position)
p.weak = self.weak
return p
def offsetToPoint(self, p, direction=None):
"""Return the signed distance from a point to the plane.
@@ -1277,6 +1279,34 @@ class Plane:
norm = proj.cross(self.u)
return DraftVecUtils.angle(self.u, proj, norm)
def getParameters(self):
"""Return a dictionary with the data which define the plane:
`u`, `v`, `axis`, `weak`.
Returns
-------
dict
dictionary of the form:
{"position":position, "u":x, "v":v, "axis":axis, "weak":weak}
"""
return {"position":self.position, "u":self.u, "v":self.v, "axis":self.axis, "weak":self.weak}
def setFromParameters(self, data):
"""Set the plane according to data.
Parameters
----------
data: dict
dictionary of the form:
{"position":position, "u":x, "v":v, "axis":axis, "weak":weak}
"""
self.position = data["position"]
self.u = data["u"]
self.v = data["v"]
self.axis = data["axis"]
self.weak = data["weak"]
return None
plane = Plane

View File

@@ -133,7 +133,7 @@ class Line(gui_base_original.Creator):
"""
self.removeTemporaryObject()
if self.oldWP:
App.DraftWorkingPlane = self.oldWP
App.DraftWorkingPlane.setFromParameters(self.oldWP)
if hasattr(Gui, "Snapper"):
Gui.Snapper.setGrid()
Gui.Snapper.restack()
@@ -262,7 +262,7 @@ class Line(gui_base_original.Creator):
v = self.node[-2].sub(self.node[-1])
v = v.negative()
if not self.oldWP:
self.oldWP = App.DraftWorkingPlane.copy()
self.oldWP = App.DraftWorkingPlane.getParameters()
App.DraftWorkingPlane.alignToPointAndAxis(p, n, upvec=v)
if hasattr(Gui, "Snapper"):
Gui.Snapper.setGrid()

View File

@@ -1357,16 +1357,16 @@ class archDimTracker(Tracker):
self.string = self.dimnode.string
self.view = Draft.get3DView()
self.camera = self.view.getCameraNode()
self.plane = FreeCAD.DraftWorkingPlane
self.setMode(mode)
self.setString()
super().__init__(children=[self.transform, self.dimnode], name="archDimTracker")
def setString(self, text=None):
"""Set the dim string to the given value or auto value."""
plane = FreeCAD.DraftWorkingPlane
p1 = Vector(self.pnts.getValues()[0].getValue())
p2 = Vector(self.pnts.getValues()[-1].getValue())
self.norm.setValue(self.plane.getNormal())
self.norm.setValue(plane.getNormal())
# set the offset sign to prevent the dim line from intersecting the curve near the cursor
sign_dx = math.copysign(1, (p2.sub(p1)).x)
sign_dy = math.copysign(1, (p2.sub(p1)).y)
@@ -1381,7 +1381,7 @@ class archDimTracker(Tracker):
self.Distance = (p2.sub(p1)).Length
text = FreeCAD.Units.Quantity(self.Distance, FreeCAD.Units.Length).UserString
self.matrix.setValue(*self.plane.getPlacement().Matrix.transposed().A)
self.matrix.setValue(*plane.getPlacement().Matrix.transposed().A)
self.string.setValue(text.encode('utf8'))
# change the text position to external depending on the distance and scale values
volume = self.camera.getViewVolume()
@@ -1404,10 +1404,11 @@ class archDimTracker(Tracker):
def p1(self, point=None):
"""Set or get the first point of the dim."""
plane = FreeCAD.DraftWorkingPlane
if point:
p1_proj = self.plane.projectPoint(point)
p1_proj_u = (p1_proj - self.plane.position).dot(self.plane.u.normalize())
p1_proj_v = (p1_proj - self.plane.position).dot(self.plane.v.normalize())
p1_proj = plane.projectPoint(point)
p1_proj_u = (p1_proj - plane.position).dot(plane.u.normalize())
p1_proj_v = (p1_proj - plane.position).dot(plane.v.normalize())
self.pnts.set1Value(0, p1_proj_u, p1_proj_v, 0)
self.setString()
else:
@@ -1415,10 +1416,11 @@ class archDimTracker(Tracker):
def p2(self, point=None):
"""Set or get the second point of the dim."""
plane = FreeCAD.DraftWorkingPlane
if point:
p2_proj = self.plane.projectPoint(point)
p2_proj_u = (p2_proj - self.plane.position).dot(self.plane.u.normalize())
p2_proj_v = (p2_proj - self.plane.position).dot(self.plane.v.normalize())
p2_proj = plane.projectPoint(point)
p2_proj_u = (p2_proj - plane.position).dot(plane.u.normalize())
p2_proj_v = (p2_proj - plane.position).dot(plane.v.normalize())
self.pnts.set1Value(1, p2_proj_u, p2_proj_v, 0)
self.setString()
else: