Skip to content

Commit

Permalink
Now you can join multiple wires all at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Moult authored and yorikvanhavre committed Jan 31, 2019
1 parent e25044d commit 5e6fb09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/Mod/Draft/Draft.py
Expand Up @@ -1339,7 +1339,20 @@ def extrude(obj,vector,solid=False):
FreeCAD.ActiveDocument.recompute()
return newobj

def joinWires(wire1, wire2):
def joinWires(wires, joinAttempts = 0):
if joinAttempts > len(wires):
return FreeCAD.ActiveDocument.recompute()
joinAttempts += 1
for wire1Index, wire1 in enumerate(wires):
for wire2Index, wire2 in enumerate(wires):
if wire2Index <= wire1Index:
continue
if not joinTwoWires(wire1, wire2):
wires.pop(wire2Index)
break
joinWires(wires, joinAttempts)

def joinTwoWires(wire1, wire2):
wire1AbsPoints = [wire1.Placement.multVec(point) for point in wire1.Points]
wire2AbsPoints = [wire2.Placement.multVec(point) for point in wire2.Points]
if wire1AbsPoints[0] == wire2AbsPoints[0]:
Expand All @@ -1349,10 +1362,13 @@ def joinWires(wire1, wire2):
wire2AbsPoints = list(reversed(wire2AbsPoints))
elif wire1AbsPoints[-1] == wire2AbsPoints[-1]:
wire2AbsPoints = list(reversed(wire2AbsPoints))
elif wire1AbsPoints[-1] == wire2AbsPoints[0]:
pass
else:
return False
wire2AbsPoints.pop(0)
wire1.Points = [wire1.Placement.inverse().multVec(point) for point in wire1AbsPoints] + [wire1.Placement.inverse().multVec(point) for point in wire2AbsPoints]
FreeCAD.ActiveDocument.removeObject(wire2.Name)
FreeCAD.ActiveDocument.recompute()

def fuse(object1,object2):
'''fuse(oject1,object2): returns an object made from
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Draft/DraftTools.py
Expand Up @@ -3234,7 +3234,7 @@ def proceed(self):
print(FreeCADGui.Selection.getSelection())
FreeCADGui.addModule("Draft")
self.commit(translate("draft","Upgrade"),
['Draft.joinWires(FreeCADGui.Selection.getSelection()[0], FreeCADGui.Selection.getSelection()[1])', 'FreeCAD.ActiveDocument.recompute()'])
['Draft.joinWires(FreeCADGui.Selection.getSelection())', 'FreeCAD.ActiveDocument.recompute()'])
self.finish()


Expand Down

0 comments on commit 5e6fb09

Please sign in to comment.