Add new draft join tool
This commit is contained in:
committed by
Yorik van Havre
parent
6e91ae9561
commit
882c4ca2f3
@@ -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
|
||||
|
||||
@@ -3207,6 +3207,36 @@ class Stretch(Modifier):
|
||||
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.'''
|
||||
@@ -5823,6 +5853,7 @@ FreeCADGui.addCommand('Draft_Label',Draft_Label())
|
||||
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())
|
||||
|
||||
@@ -73,7 +73,7 @@ class DraftWorkbench (Workbench):
|
||||
"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",
|
||||
|
||||
Reference in New Issue
Block a user