Skip to content

Commit

Permalink
Draft: Sync input fields in task panel
Browse files Browse the repository at this point in the history
  • Loading branch information
marioalexis84 committed Apr 7, 2021
1 parent d759292 commit e4a64af
Showing 1 changed file with 61 additions and 36 deletions.
97 changes: 61 additions & 36 deletions src/Mod/Draft/DraftGui.py
Expand Up @@ -273,11 +273,13 @@ def __init__(self):
self.fillmode = Draft.getParam("fillmode",False)
self.mask = None
self.alock = False
self.angle = None
self.avalue = None
self.x = 0
self.y = 0
self.z = 0
self.lvalue = 0
self.pvalue = 90
self.avalue = 0
self.angle = None
self.radius = 0
self.offset = 0
self.uiloader = FreeCADGui.UiLoader()
Expand Down Expand Up @@ -835,11 +837,7 @@ def retranslateTray(self,widget=None):

def taskUi(self,title="Draft",extra=None,icon="Draft_Draft"):
# reset InputField values
self.x = 0
self.y = 0
self.z = 0
self.radius = 0
self.offset = 0
self.reset_ui_values()
if self.taskmode:
self.isTaskOn = True
todo.delay(FreeCADGui.Control.closeDialog,None)
Expand Down Expand Up @@ -1577,7 +1575,6 @@ def closeLine(self):

def wipeLine(self):
"""wipes existing segments of a line"""
FreeCAD.Console.PrintMessage("el de wipe\n")
self.sourceCmd.wipe()

def orientWP(self):
Expand Down Expand Up @@ -1791,16 +1788,18 @@ def displayPoint(self, point=None, last=None, plane=None, mask=None):

# set length and angle
if last and dp and plane:
self.lengthValue.setText(displayExternal(dp.Length,None,'Length'))
a = math.degrees(-DraftVecUtils.angle(dp,plane.u,plane.axis))
if not self.angleLock.isChecked():
self.angleValue.setText(displayExternal(a,None,'Angle'))
length, theta, phi = DraftVecUtils.get_spherical_coords(*dp)
theta = math.degrees(theta)
phi = math.degrees(phi)
self.lengthValue.setText(displayExternal(length,None,'Length'))
#if not self.angleLock.isChecked():
self.angleValue.setText(displayExternal(phi,None,'Angle'))
if not mask:
# automask, a is rounded to identify one of the below cases
a = round(a, Draft.getParam("precision"))
if a in [0,180,-180]:
# automask, phi is rounded to identify one of the below cases
phi = round(phi, Draft.getParam("precision"))
if phi in [0,180,-180]:
mask = "x"
elif a in [90,270,-90,-270]:
elif phi in [90,270,-90,-270]:
mask = "y"

# set masks
Expand Down Expand Up @@ -2108,12 +2107,21 @@ def constrain(self,val):

def changeXValue(self,d):
self.x = d
if not self.xValue.hasFocus():
return None
self.update_spherical_coords()

def changeYValue(self,d):
self.y = d
if not self.yValue.hasFocus():
return None
self.update_spherical_coords()

def changeZValue(self,d):
self.z = d
if not self.zValue.hasFocus():
return None
self.update_spherical_coords()

def changeRadiusValue(self,d):
self.radius = d
Expand All @@ -2126,29 +2134,15 @@ def changeSTrackValue(self,d):

def changeLengthValue(self,d):
self.lvalue = d
v = FreeCAD.Vector(self.x,self.y,self.z)
if not v.Length:
if self.angle:
v = FreeCAD.Vector(self.angle)
else:
v = FreeCAD.Vector(FreeCAD.DraftWorkingPlane.u)
if self.avalue:
v = DraftVecUtils.rotate(v,math.radians(d),FreeCAD.DraftWorkingPlane.axis)
v = DraftVecUtils.scaleTo(v,d)
self.xValue.setText(displayExternal(v.x,None,'Length'))
self.yValue.setText(displayExternal(v.y,None,'Length'))
self.zValue.setText(displayExternal(v.z,None,'Length'))
if not self.lengthValue.hasFocus():
return None
self.update_cartesian_coords()

def changeAngleValue(self,d):
self.avalue = d
v = FreeCAD.Vector(self.x,self.y,self.z)
a = DraftVecUtils.angle(v,FreeCAD.DraftWorkingPlane.u,FreeCAD.DraftWorkingPlane.axis)
a = math.radians(d)+a
v = DraftVecUtils.rotate(v,a,FreeCAD.DraftWorkingPlane.axis)
self.angle = v
self.xValue.setText(displayExternal(v.x,None,'Length'))
self.yValue.setText(displayExternal(v.y,None,'Length'))
self.zValue.setText(displayExternal(v.z,None,'Length'))
if not self.angleValue.hasFocus():
return None
self.update_cartesian_coords()
if self.angleLock.isChecked():
FreeCADGui.Snapper.setAngle(self.angle)

Expand All @@ -2160,6 +2154,25 @@ def toggleAngle(self,b):
FreeCADGui.Snapper.setAngle()
self.angle = None

def update_spherical_coords(self):
length, theta, phi = DraftVecUtils.get_spherical_coords(
self.x,self.y,self.z)
self.lvalue = length
self.pvalue = math.degrees(theta)
self.avalue = math.degrees(phi)
self.angle = FreeCAD.Vector(DraftVecUtils.get_cartesian_coords(
1, theta, phi))
self.lengthValue.setText(displayExternal(self.lvalue,None,'Length'))
self.angleValue.setText(displayExternal(self.avalue,None,'Angle'))

def update_cartesian_coords(self):
self.x, self.y, self.z = DraftVecUtils.get_cartesian_coords(
self.lvalue,math.radians(self.pvalue),math.radians(self.avalue))
self.angle = FreeCAD.Vector(DraftVecUtils.get_cartesian_coords(
1, math.radians(self.pvalue), math.radians(self.avalue)))
self.xValue.setText(displayExternal(self.x,None,'Length'))
self.yValue.setText(displayExternal(self.y,None,'Length'))
self.zValue.setText(displayExternal(self.z,None,'Length'))

#---------------------------------------------------------------------------
# TaskView operations
Expand Down Expand Up @@ -2235,6 +2248,18 @@ def Deactivated(self):
self.draftWidget.setVisible(False)
self.draftWidget.toggleViewAction().setVisible(False)

def reset_ui_values(self):
"""Method to reset task panel values"""
self.x = 0
self.y = 0
self.z = 0
self.lvalue = 0
self.pvalue = 90
self.avalue = 0
self.angle = None
self.radius = 0
self.offset = 0


class FacebinderTaskPanel:
'''A TaskPanel for the facebinder'''
Expand Down

0 comments on commit e4a64af

Please sign in to comment.