Skip to content

Commit

Permalink
Draft: Reducing memory leak in snapper - ussie #3340
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Feb 21, 2018
1 parent b2cd2e0 commit 35ee3f0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/Mod/Draft/DraftTools.py
Expand Up @@ -127,11 +127,12 @@ def getPoint(target,args,mobile=False,sym=False,workingplane=True,noTracker=Fals
amod = hasMod(args,MODSNAP)
cmod = hasMod(args,MODCONSTRAIN)

point = None
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
else:
if not point:
p = FreeCADGui.ActiveDocument.ActiveView.getCursorPos()
point = FreeCADGui.ActiveDocument.ActiveView.getPoint(p)
info = FreeCADGui.ActiveDocument.ActiveView.getObjectInfo(p)
Expand Down
45 changes: 25 additions & 20 deletions src/Mod/Draft/DraftTrackers.py
Expand Up @@ -162,14 +162,16 @@ def __init__(self,dotted=False,scolor=None,swidth=None,ontop=False):
def p1(self,point=None):
"sets or gets the first point of the line"
if point:
self.coords.point.set1Value(0,point.x,point.y,point.z)
if self.coords.point.getValues()[0].getValue() != tuple(point):
self.coords.point.set1Value(0,point.x,point.y,point.z)
else:
return Vector(self.coords.point.getValues()[0].getValue())

def p2(self,point=None):
"sets or gets the second point of the line"
if point:
self.coords.point.set1Value(1,point.x,point.y,point.z)
if self.coords.point.getValues()[-1].getValue() != tuple(point):
self.coords.point.set1Value(1,point.x,point.y,point.z)
else:
return Vector(self.coords.point.getValues()[-1].getValue())

Expand Down Expand Up @@ -796,6 +798,7 @@ def __init__(self):
mat3.diffuseColor.setValue(col)
self.coords3 = coin.SoCoordinate3()
self.lines3 = coin.SoLineSet()
self.pts = []
s = coin.SoSeparator()
s.addChild(pick)
s.addChild(self.trans)
Expand Down Expand Up @@ -832,24 +835,26 @@ def update(self):
else:
pts.extend([[-bound,curr,z],[bound,curr,z]])
pts.extend([[curr,-bound,z],[curr,bound,z]])
idx = []
midx = []
aidx = []
for p in range(0,len(pts),2):
idx.append(2)
for mp in range(0,len(mpts),2):
midx.append(2)
for ap in range(0,len(apts),2):
aidx.append(2)
self.lines1.numVertices.deleteValues(0)
self.lines2.numVertices.deleteValues(0)
self.lines3.numVertices.deleteValues(0)
self.coords1.point.setValues(pts)
self.lines1.numVertices.setValues(idx)
self.coords2.point.setValues(mpts)
self.lines2.numVertices.setValues(midx)
self.coords3.point.setValues(apts)
self.lines3.numVertices.setValues(aidx)
if pts != self.pts:
idx = []
midx = []
aidx = []
for p in range(0,len(pts),2):
idx.append(2)
for mp in range(0,len(mpts),2):
midx.append(2)
for ap in range(0,len(apts),2):
aidx.append(2)
self.lines1.numVertices.deleteValues(0)
self.lines2.numVertices.deleteValues(0)
self.lines3.numVertices.deleteValues(0)
self.coords1.point.setValues(pts)
self.lines1.numVertices.setValues(idx)
self.coords2.point.setValues(mpts)
self.lines2.numVertices.setValues(midx)
self.coords3.point.setValues(apts)
self.lines3.numVertices.setValues(aidx)
self.pts = pts

def setSize(self,size):
self.numlines = size
Expand Down

0 comments on commit 35ee3f0

Please sign in to comment.