Merge pull request #4624 from mlampert/bugfix/dogbone-on-straight-edges-and-noop-moves
[Path]: Bugfix/dogbone on straight edges and noop moves
This commit is contained in:
@@ -40,7 +40,7 @@ Part = LazyLoader('Part', globals(), 'Part')
|
||||
LOG_MODULE = PathLog.thisModule()
|
||||
|
||||
PathLog.setLevel(PathLog.Level.NOTICE, LOG_MODULE)
|
||||
#PathLog.setLevel(PathLog.Level.DEBUG, LOG_MODULE)
|
||||
#PathLog.trackModule(LOG_MODULE)
|
||||
|
||||
|
||||
# Qt translation handling
|
||||
@@ -227,6 +227,9 @@ class Chord (object):
|
||||
def asVector(self):
|
||||
return self.End - self.Start
|
||||
|
||||
def asDirection(self):
|
||||
return self.asVector().normalize()
|
||||
|
||||
def asLine(self):
|
||||
return Part.LineSegment(self.Start, self.End)
|
||||
|
||||
@@ -237,8 +240,9 @@ class Chord (object):
|
||||
return self.asVector().Length
|
||||
|
||||
def getDirectionOfVector(self, B):
|
||||
A = self.asVector()
|
||||
A = self.asDirection()
|
||||
# if the 2 vectors are identical, they head in the same direction
|
||||
PathLog.debug(" {}.getDirectionOfVector({})".format(A, B))
|
||||
if PathGeom.pointsCoincide(A, B):
|
||||
return 'Straight'
|
||||
d = -A.x*B.y + A.y*B.x
|
||||
@@ -251,8 +255,8 @@ class Chord (object):
|
||||
|
||||
def getDirectionOf(self, chordOrVector):
|
||||
if type(chordOrVector) is Chord:
|
||||
return self.getDirectionOfVector(chordOrVector.asVector())
|
||||
return self.getDirectionOfVector(chordOrVector)
|
||||
return self.getDirectionOfVector(chordOrVector.asDirection())
|
||||
return self.getDirectionOfVector(chordOrVector.normalize())
|
||||
|
||||
def getAngleOfVector(self, ref):
|
||||
angle = self.asVector().getAngle(ref)
|
||||
@@ -265,8 +269,8 @@ class Chord (object):
|
||||
|
||||
def getAngle(self, refChordOrVector):
|
||||
if type(refChordOrVector) is Chord:
|
||||
return self.getAngleOfVector(refChordOrVector.asVector())
|
||||
return self.getAngleOfVector(refChordOrVector)
|
||||
return self.getAngleOfVector(refChordOrVector.asDirection())
|
||||
return self.getAngleOfVector(refChordOrVector.normalize())
|
||||
|
||||
def getAngleXY(self):
|
||||
return self.getAngle(FreeCAD.Vector(1, 0, 0))
|
||||
@@ -297,6 +301,10 @@ class Chord (object):
|
||||
def isAPlungeMove(self):
|
||||
return not PathGeom.isRoughly(self.End.z, self.Start.z)
|
||||
|
||||
def isANoopMove(self):
|
||||
PathLog.debug("{}.isANoopMove(): {}".format(self, PathGeom.pointsCoincide(self.Start, self.End)))
|
||||
return PathGeom.pointsCoincide(self.Start, self.End)
|
||||
|
||||
def foldsBackOrTurns(self, chord, side):
|
||||
direction = chord.getDirectionOf(self)
|
||||
PathLog.info(" - direction = %s/%s" % (direction, side))
|
||||
@@ -435,7 +443,7 @@ class ObjectDressup:
|
||||
|
||||
# Answer true if a dogbone could be on either end of the chord, given its command
|
||||
def canAttachDogbone(self, cmd, chord):
|
||||
return cmd.Name in movestraight and not chord.isAPlungeMove()
|
||||
return cmd.Name in movestraight and not chord.isAPlungeMove() and not chord.isANoopMove()
|
||||
|
||||
def shouldInsertDogbone(self, obj, inChord, outChord):
|
||||
return outChord.foldsBackOrTurns(inChord, self.theOtherSideOf(obj.Side))
|
||||
@@ -766,7 +774,7 @@ class ObjectDressup:
|
||||
thisIsACandidate = self.canAttachDogbone(thisCommand, thisChord)
|
||||
|
||||
if thisIsACandidate and lastCommand and self.shouldInsertDogbone(obj, lastChord, thisChord):
|
||||
PathLog.info(" Found bone corner")
|
||||
PathLog.info(" Found bone corner: {}".format(lastChord.End))
|
||||
bone = Bone(boneId, obj, lastCommand, lastChord, thisChord, Smooth.InAndOut, thisCommand.Parameters.get('F'))
|
||||
bones = self.insertBone(bone)
|
||||
boneId += 1
|
||||
@@ -783,6 +791,7 @@ class ObjectDressup:
|
||||
for chord in (chord for chord in oddsAndEnds if lastChord.connectsTo(chord)):
|
||||
if self.shouldInsertDogbone(obj, lastChord, chord):
|
||||
PathLog.info(" and there is one")
|
||||
PathLog.debug(" odd/end={} last={}".format(chord, lastChord))
|
||||
bone = Bone(boneId, obj, lastCommand, lastChord, chord, Smooth.In, lastCommand.Parameters.get('F'))
|
||||
bones = self.insertBone(bone)
|
||||
boneId += 1
|
||||
@@ -804,6 +813,9 @@ class ObjectDressup:
|
||||
commands.append(lastCommand)
|
||||
lastCommand = thisCommand
|
||||
lastBone = None
|
||||
elif thisChord.isANoopMove():
|
||||
PathLog.info(" ignoring and dropping noop move")
|
||||
continue
|
||||
else:
|
||||
PathLog.info(" nope")
|
||||
if lastCommand:
|
||||
@@ -818,12 +830,13 @@ class ObjectDressup:
|
||||
|
||||
lastChord = thisChord
|
||||
else:
|
||||
PathLog.info(" Clean slate")
|
||||
if lastCommand:
|
||||
commands.append(lastCommand)
|
||||
lastCommand = None
|
||||
if thisCommand.Name[0] != '(':
|
||||
PathLog.info(" Clean slate")
|
||||
if lastCommand:
|
||||
commands.append(lastCommand)
|
||||
lastCommand = None
|
||||
lastBone = None
|
||||
commands.append(thisCommand)
|
||||
lastBone = None
|
||||
# for cmd in commands:
|
||||
# PathLog.debug("cmd = '%s'" % cmd)
|
||||
path = Path.Path(commands)
|
||||
@@ -947,10 +960,10 @@ class TaskPanel:
|
||||
for obj in FreeCAD.ActiveDocument.Objects:
|
||||
if obj.Name.startswith('Shape'):
|
||||
FreeCAD.ActiveDocument.removeObject(obj.Name)
|
||||
print('object name %s' % self.obj.Name)
|
||||
PathLog.info('object name %s' % self.obj.Name)
|
||||
if hasattr(self.obj.Proxy, "shapes"):
|
||||
PathLog.info("showing shapes attribute")
|
||||
for shapes in self.obj.Proxy.shapes.itervalues():
|
||||
for shapes in self.obj.Proxy.shapes.values():
|
||||
for shape in shapes:
|
||||
Part.show(shape)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user