Skip to content

Commit

Permalink
Add new draft join tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Moult authored and yorikvanhavre committed Jan 31, 2019
1 parent 6e91ae9 commit 882c4ca
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Mod/Draft/Draft.py
Expand Up @@ -1339,6 +1339,21 @@ def extrude(obj,vector,solid=False):
FreeCAD.ActiveDocument.recompute()
return newobj

def joinWires(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]:
wire1AbsPoints = list(reversed(wire1AbsPoints))
elif wire1AbsPoints[0] == wire2AbsPoints[-1]:
wire1AbsPoints = list(reversed(wire1AbsPoints))
wire2AbsPoints = list(reversed(wire2AbsPoints))
elif wire1AbsPoints[-1] == wire2AbsPoints[-1]:
wire2AbsPoints = list(reversed(wire2AbsPoints))
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
the union of the 2 given objects. If the objects are
Expand Down
31 changes: 31 additions & 0 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -3207,6 +3207,36 @@ def doStretch(self):
self.commit(translate("draft","Stretch"),commitops)
self.finish()

class Join(Modifier):
'''The Draft_Join FreeCAD command definition.'''

def GetResources(self):
return {'Pixmap' : 'Draft_Upgrade',
'Accel' : "F, U",
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_Join", "Join"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft_Join", "Does funky!")}

def Activated(self):
Modifier.Activated(self,"Upgrade")
if not self.ui:
return
if not FreeCADGui.Selection.getSelection():
self.ui.selectUi()
msg(translate("draft", "Select an object to upgrade")+"\n")
self.call = self.view.addEventCallback("SoEvent",selectObject)
else:
self.proceed()

def proceed(self):
if self.call:
self.view.removeEventCallback("SoEvent",self.call)
if FreeCADGui.Selection.getSelection():
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()'])
self.finish()


class Upgrade(Modifier):
'''The Draft_Upgrade FreeCAD command definition.'''
Expand Down Expand Up @@ -5823,6 +5853,7 @@ def Activated(self):
FreeCADGui.addCommand('Draft_Move',Move())
FreeCADGui.addCommand('Draft_Rotate',Rotate())
FreeCADGui.addCommand('Draft_Offset',Offset())
FreeCADGui.addCommand('Draft_Join',Join())
FreeCADGui.addCommand('Draft_Upgrade',Upgrade())
FreeCADGui.addCommand('Draft_Downgrade',Downgrade())
FreeCADGui.addCommand('Draft_Trimex',Trimex())
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Draft/InitGui.py
Expand Up @@ -73,7 +73,7 @@ def QT_TRANSLATE_NOOP(scope, text):
"Draft_Dimension", "Draft_BSpline","Draft_Point",
"Draft_ShapeString","Draft_Facebinder","Draft_BezCurve","Draft_Label"]
self.modList = ["Draft_Move","Draft_Rotate","Draft_Offset",
"Draft_Trimex", "Draft_Upgrade", "Draft_Downgrade", "Draft_Scale",
"Draft_Trimex", "Draft_Join", "Draft_Upgrade", "Draft_Downgrade", "Draft_Scale",
"Draft_Edit","Draft_WireToBSpline","Draft_AddPoint",
"Draft_DelPoint","Draft_Shape2DView","Draft_Draft2Sketch","Draft_Array",
"Draft_PathArray", "Draft_PointArray","Draft_Clone",
Expand Down

0 comments on commit 882c4ca

Please sign in to comment.