Skip to content

Commit

Permalink
Fix draft missing line tracker when snapper detects an object without…
Browse files Browse the repository at this point in the history
… any snap targets
  • Loading branch information
Moult authored and yorikvanhavre committed Jun 3, 2019
1 parent 1c243cf commit 95378e5
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 131 deletions.
121 changes: 61 additions & 60 deletions src/Mod/Draft/DraftGui.py
Expand Up @@ -1875,69 +1875,70 @@ def lineUp(self):
def displayPoint(self, point=None, last=None, plane=None, mask=None):
"this function displays the passed coords in the x, y, and z widgets"

if (not self.taskmode) or self.isTaskOn:
if self.taskmode and (not self.isTaskOn):
return

# get coords to display
dp = None
if point:
dp = point
if self.relativeMode and (last != None):
if plane:
dp = plane.getLocalRot(FreeCAD.Vector(point.x-last.x, point.y-last.y, point.z-last.z))
else:
dp = FreeCAD.Vector(point.x-last.x, point.y-last.y, point.z-last.z)
elif plane:
dp = plane.getLocalCoords(point)

# set widgets
if dp:
if self.mask in ['y','z']:
self.xValue.setText(displayExternal(dp.x,None,'Length'))
else:
self.xValue.setText(displayExternal(dp.x,None,'Length'))
if self.mask in ['x','z']:
self.yValue.setText(displayExternal(dp.y,None,'Length'))
else:
self.yValue.setText(displayExternal(dp.y,None,'Length'))
if self.mask in ['x','y']:
self.zValue.setText(displayExternal(dp.z,None,'Length'))
# get coords to display
dp = None
if point:
dp = point
if self.relativeMode and (last != None):
if plane:
dp = plane.getLocalRot(FreeCAD.Vector(point.x-last.x, point.y-last.y, point.z-last.z))
else:
self.zValue.setText(displayExternal(dp.z,None,'Length'))

# 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'))
if not mask:
# automask
if a in [0,180,-180]:
mask = "x"
elif a in [90,270,-90]:
mask = "y"

# set masks
if (mask == "x") or (self.mask == "x"):
self.xValue.setEnabled(True)
self.yValue.setEnabled(False)
self.zValue.setEnabled(False)
self.setFocus()
elif (mask == "y") or (self.mask == "y"):
self.xValue.setEnabled(False)
self.yValue.setEnabled(True)
self.zValue.setEnabled(False)
self.setFocus("y")
elif (mask == "z") or (self.mask == "z"):
self.xValue.setEnabled(False)
self.yValue.setEnabled(False)
self.zValue.setEnabled(True)
self.setFocus("z")
dp = FreeCAD.Vector(point.x-last.x, point.y-last.y, point.z-last.z)
elif plane:
dp = plane.getLocalCoords(point)

# set widgets
if dp:
if self.mask in ['y','z']:
self.xValue.setText(displayExternal(dp.x,None,'Length'))
else:
self.xValue.setEnabled(True)
self.yValue.setEnabled(True)
self.zValue.setEnabled(True)
self.setFocus()
self.xValue.setText(displayExternal(dp.x,None,'Length'))
if self.mask in ['x','z']:
self.yValue.setText(displayExternal(dp.y,None,'Length'))
else:
self.yValue.setText(displayExternal(dp.y,None,'Length'))
if self.mask in ['x','y']:
self.zValue.setText(displayExternal(dp.z,None,'Length'))
else:
self.zValue.setText(displayExternal(dp.z,None,'Length'))

# 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'))
if not mask:
# automask
if a in [0,180,-180]:
mask = "x"
elif a in [90,270,-90]:
mask = "y"

# set masks
if (mask == "x") or (self.mask == "x"):
self.xValue.setEnabled(True)
self.yValue.setEnabled(False)
self.zValue.setEnabled(False)
self.setFocus()
elif (mask == "y") or (self.mask == "y"):
self.xValue.setEnabled(False)
self.yValue.setEnabled(True)
self.zValue.setEnabled(False)
self.setFocus("y")
elif (mask == "z") or (self.mask == "z"):
self.xValue.setEnabled(False)
self.yValue.setEnabled(False)
self.zValue.setEnabled(True)
self.setFocus("z")
else:
self.xValue.setEnabled(True)
self.yValue.setEnabled(True)
self.zValue.setEnabled(True)
self.setFocus()


def getDefaultColor(self,type,rgb=False):
Expand Down
10 changes: 5 additions & 5 deletions src/Mod/Draft/DraftSnap.py
Expand Up @@ -225,9 +225,8 @@ def snap(self,screenpos,lastpoint=None,active=True,constrain=False,noTracker=Fal
point = self.getApparentPoint(screenpos[0],screenpos[1])

# setup a track line if we got a last point
if lastpoint:
if self.trackLine:
self.trackLine.p1(lastpoint)
if lastpoint and self.trackLine:
self.trackLine.p1(lastpoint)

# checking if parallel to one of the edges of the last objects or to a polar direction
if active:
Expand Down Expand Up @@ -286,12 +285,10 @@ def snapToObject(self, lastpoint, active, constrain, eline, point, oldActive):
return self.spoint

if not active:

# passive snapping
snaps = [self.snapToVertex(self.snapInfo)]

else:

# first stick to the snapped object
s = self.snapToVertex(self.snapInfo)
if s:
Expand Down Expand Up @@ -383,6 +380,9 @@ def snapToObject(self, lastpoint, active, constrain, eline, point, oldActive):
if not snaps:
self.spoint = self.cstr(lastpoint, constrain, point)
self.running = False
if self.trackLine and lastpoint:
self.trackLine.p2(self.spoint)
self.trackLine.on()
return self.spoint

# calculating the nearest snap point
Expand Down
130 changes: 64 additions & 66 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -108,16 +108,16 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True,noTracker=Fals

ui = FreeCADGui.draftToolBar

# get point
if target.node:
last = target.node[-1]
else:
last = None
amod = hasMod(args,MODSNAP)
cmod = hasMod(args,MODCONSTRAIN)

amod = hasMod(args, MODSNAP)
cmod = hasMod(args, MODCONSTRAIN)
point = None
if hasattr(FreeCADGui,"Snapper"):

if hasattr(FreeCADGui, "Snapper"):
point = FreeCADGui.Snapper.snap(args["Position"],lastpoint=last,active=amod,constrain=cmod,noTracker=noTracker)
info = FreeCADGui.Snapper.snapInfo
mask = FreeCADGui.Snapper.affinity
Expand All @@ -133,7 +133,8 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True,noTracker=Fals
ui.displayPoint(point, target.node[0], plane=plane, mask=mask)
else:
ui.displayPoint(point, target.node[-1], plane=plane, mask=mask)
else: ui.displayPoint(point, plane=plane, mask=mask)
else:
ui.displayPoint(point, plane=plane, mask=mask)
return point,ctrlPoint,info

def getSupport(args=None):
Expand Down Expand Up @@ -528,42 +529,60 @@ def __init__(self, wiremode=False):
self.isWire = wiremode

def GetResources(self):
return {'Pixmap' : 'Draft_Line',
'Accel' : "L,I",
return {'Pixmap': 'Draft_Line',
'Accel': "L,I",
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_Line", "Line"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft_Line", "Creates a 2-point line. CTRL to snap, SHIFT to constrain")}

def Activated(self,name=translate("draft","Line")):
Creator.Activated(self,name)
if self.doc:
self.obj = None # stores the temp shape
self.oldWP = None # stores the WP if we modify it
if self.isWire:
self.ui.wireUi(name)
else:
self.ui.lineUi(name)
self.ui.setTitle(translate("draft", "Line"))
if sys.version_info.major < 3:
if isinstance(self.featureName,unicode):
self.featureName = self.featureName.encode("utf8")
self.obj=self.doc.addObject("Part::Feature",self.featureName)
# self.obj.ViewObject.Selectable = False
Draft.formatObject(self.obj)
self.call = self.view.addEventCallback("SoEvent",self.action)
FreeCAD.Console.PrintMessage(translate("draft", "Pick first point")+"\n")
if not self.doc:
return
self.obj = None # stores the temp shape
self.oldWP = None # stores the WP if we modify it
if self.isWire:
self.ui.wireUi(name)
else:
self.ui.lineUi(name)
self.ui.setTitle(translate("draft", "Line"))
if sys.version_info.major < 3:
if isinstance(self.featureName,unicode):
self.featureName = self.featureName.encode("utf8")
self.obj=self.doc.addObject("Part::Feature",self.featureName)
Draft.formatObject(self.obj)
self.call = self.view.addEventCallback("SoEvent", self.action)
FreeCAD.Console.PrintMessage(translate("draft", "Pick first point")+"\n")

def action(self, arg):
"scene event handler"
if arg["Type"] == "SoKeyboardEvent" and arg["Key"] == "ESCAPE":
self.finish()
elif arg["Type"] == "SoLocation2Event":
self.point, ctrlPoint, info = getPoint(self, arg)
redraw3DView()
elif arg["Type"] == "SoMouseButtonEvent" and \
arg["State"] == "DOWN" and \
arg["Button"] == "BUTTON1":
if (arg["Position"] == self.pos):
return self.finish(False,cont=True)
if (not self.node) and (not self.support):
getSupport(arg)
self.point,ctrlPoint,info = getPoint(self,arg)
if self.point:
self.ui.redraw()
self.pos = arg["Position"]
self.node.append(self.point)
self.drawSegment(self.point)
if (not self.isWire and len(self.node) == 2):
self.finish(False,cont=True)
if (len(self.node) > 2):
if ((self.point-self.node[0]).Length < Draft.tolerance()):
self.undolast()
self.finish(True,cont=True)

def finish(self,closed=False,cont=False):
"terminates the operation and closes the poly if asked"
if self.obj:
# remove temporary object, if any
try:
old = self.obj.Name
except ReferenceError:
# object already deleted, for some reason
pass
else:
todo.delay(self.doc.removeObject,old)
self.obj = None
self.removeTemporaryObject()
if self.oldWP:
FreeCAD.DraftWorkingPlane = self.oldWP
if hasattr(FreeCADGui,"Snapper"):
Expand Down Expand Up @@ -598,40 +617,19 @@ def finish(self,closed=False,cont=False):
'Draft.autogroup(line)',
'FreeCAD.ActiveDocument.recompute()'])
Creator.finish(self)
if self.ui:
if self.ui.continueMode:
self.Activated()
if self.ui and self.ui.continueMode:
self.Activated()

def action(self,arg):
"scene event handler"
if arg["Type"] == "SoKeyboardEvent":
# key detection
if arg["Key"] == "ESCAPE":
self.finish()
elif arg["Type"] == "SoLocation2Event":
# mouse movement detection
self.point,ctrlPoint,info = getPoint(self,arg)
redraw3DView()
elif arg["Type"] == "SoMouseButtonEvent":
# mouse button detection
if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
if (arg["Position"] == self.pos):
self.finish(False,cont=True)
else:
if (not self.node) and (not self.support):
getSupport(arg)
self.point,ctrlPoint,info = getPoint(self,arg)
if self.point:
self.ui.redraw()
self.pos = arg["Position"]
self.node.append(self.point)
self.drawSegment(self.point)
if (not self.isWire and len(self.node) == 2):
self.finish(False,cont=True)
if (len(self.node) > 2):
if ((self.point-self.node[0]).Length < Draft.tolerance()):
self.undolast()
self.finish(True,cont=True)
def removeTemporaryObject(self):
if self.obj:
try:
old = self.obj.Name
except ReferenceError:
# object already deleted, for some reason
pass
else:
todo.delay(self.doc.removeObject,old)
self.obj = None

def undolast(self):
"undoes last line segment"
Expand Down

0 comments on commit 95378e5

Please sign in to comment.