From 09f134d56f864ea5393a982d7bb59333a23ef814 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 30 Jan 2019 20:01:59 +1100 Subject: [PATCH] Add split tool --- src/Mod/Draft/Draft.py | 16 +++++++++++++++ src/Mod/Draft/DraftTools.py | 40 ++++++++++++++++++++++++++++++++++++- src/Mod/Draft/InitGui.py | 2 +- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 8d805bf437..a4c4b3ac37 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -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 diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index 7a1269a164..b7bf4de237 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -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()) diff --git a/src/Mod/Draft/InitGui.py b/src/Mod/Draft/InitGui.py index 39f69bf430..89a9f803b4 100644 --- a/src/Mod/Draft/InitGui.py +++ b/src/Mod/Draft/InitGui.py @@ -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",