Add split tool
This commit is contained in:
committed by
Yorik van Havre
parent
7867864456
commit
09f134d56f
@@ -1375,6 +1375,22 @@ def joinTwoWires(wire1, wire2):
|
||||
FreeCAD.ActiveDocument.removeObject(wire2.Name)
|
||||
return True
|
||||
|
||||
def split(wire, newPoint, edgeIndex):
|
||||
wire1Points = []
|
||||
wire2Points = []
|
||||
for index, point in enumerate(wire.Points):
|
||||
if index == edgeIndex:
|
||||
wire1Points.append(wire.Placement.inverse().multVec(newPoint))
|
||||
wire2Points.append(newPoint)
|
||||
wire2Points.append(wire.Placement.multVec(point))
|
||||
elif index < edgeIndex:
|
||||
wire1Points.append(point)
|
||||
elif index > edgeIndex:
|
||||
wire2Points.append(wire.Placement.multVec(point))
|
||||
wire.Points = wire1Points
|
||||
makeWire(wire2Points, placement=wire.Placement)
|
||||
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
|
||||
|
||||
@@ -3212,7 +3212,7 @@ class Join(Modifier):
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Draft_Upgrade',
|
||||
'Accel' : "F, U",
|
||||
'Accel' : "J, O",
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_Join", "Join"),
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft_Join", "Joins two wires together")}
|
||||
|
||||
@@ -3237,6 +3237,43 @@ class Join(Modifier):
|
||||
['Draft.joinWires(FreeCADGui.Selection.getSelection())', 'FreeCAD.ActiveDocument.recompute()'])
|
||||
self.finish()
|
||||
|
||||
class Split(Modifier):
|
||||
'''The Draft_Split FreeCAD command definition.'''
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Draft_Downgrade',
|
||||
'Accel' : "S, P",
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_Split", "Split"),
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft_Split", "Splits a wire into two wires")}
|
||||
|
||||
def Activated(self):
|
||||
Modifier.Activated(self,"Split")
|
||||
if not self.ui:
|
||||
return
|
||||
msg(translate("draft", "Select an object to split")+"\n")
|
||||
self.call = self.view.addEventCallback("SoEvent", self.action)
|
||||
|
||||
def action(self, arg):
|
||||
"scene event handler"
|
||||
if arg["Type"] == "SoKeyboardEvent":
|
||||
if arg["Key"] == "ESCAPE":
|
||||
self.finish()
|
||||
elif arg["Type"] == "SoLocation2Event":
|
||||
getPoint(self, arg)
|
||||
redraw3DView()
|
||||
elif arg["Type"] == "SoMouseButtonEvent" and arg["State"] == "DOWN" and arg["Button"] == "BUTTON1":
|
||||
print('clicky!')
|
||||
self.point, ctrlPoint, info = getPoint(self, arg)
|
||||
if "Edge" in info["Component"]:
|
||||
return self.proceed(info)
|
||||
|
||||
def proceed(self, info):
|
||||
Draft.split(FreeCAD.ActiveDocument.getObject(info["Object"]),
|
||||
self.point, int(info["Component"][4:]))
|
||||
if self.call:
|
||||
self.view.removeEventCallback("SoEvent", self.call)
|
||||
self.finish()
|
||||
|
||||
class Upgrade(Modifier):
|
||||
'''The Draft_Upgrade FreeCAD command definition.'''
|
||||
|
||||
@@ -5853,6 +5890,7 @@ FreeCADGui.addCommand('Draft_Move',Move())
|
||||
FreeCADGui.addCommand('Draft_Rotate',Rotate())
|
||||
FreeCADGui.addCommand('Draft_Offset',Offset())
|
||||
FreeCADGui.addCommand('Draft_Join',Join())
|
||||
FreeCADGui.addCommand('Draft_Split',Split())
|
||||
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_Join", "Draft_Upgrade", "Draft_Downgrade", "Draft_Scale",
|
||||
"Draft_Trimex", "Draft_Join", "Draft_Split", "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