Skip to content

Commit

Permalink
Draft: Draft_Split: apply original view props to split off object
Browse files Browse the repository at this point in the history
Fixes FreeCAD#16210.

Note that `Draft.format_object` is called from gui_split.py (in the commit). This is not consistent with other tools where this is handled in the `make_*` functions. In this case the new object is formatted twice. The 1st time by the `make_wire` code which (wrongly) applies the current default props.
  • Loading branch information
Roy-043 authored and yorikvanhavre committed Nov 29, 2024
1 parent 42d09e0 commit 735a076
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
16 changes: 8 additions & 8 deletions src/Mod/Draft/draftfunctions/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@

def split(wire, newPoint, edgeIndex):
if utils.get_type(wire) != "Wire":
return
elif wire.Closed:
split_closed_wire(wire, edgeIndex)
else:
split_open_wire(wire, newPoint, edgeIndex)
return None
if wire.Closed:
return split_closed_wire(wire, edgeIndex)
return split_open_wire(wire, newPoint, edgeIndex)


def split_closed_wire(wire, edgeIndex):
wire.Closed = False
if edgeIndex == len(wire.Points):
make_wire.make_wire([wire.Placement.multVec(wire.Points[0]),
new = make_wire.make_wire([wire.Placement.multVec(wire.Points[0]),
wire.Placement.multVec(wire.Points[-1])], placement=wire.Placement)
else:
make_wire.make_wire([wire.Placement.multVec(wire.Points[edgeIndex-1]),
new = make_wire.make_wire([wire.Placement.multVec(wire.Points[edgeIndex-1]),
wire.Placement.multVec(wire.Points[edgeIndex])], placement=wire.Placement)
wire.Points = list(reversed(wire.Points[0:edgeIndex])) + list(reversed(wire.Points[edgeIndex:]))
return new


splitClosedWire = split_closed_wire
Expand All @@ -67,7 +67,7 @@ def split_open_wire(wire, newPoint, edgeIndex):
elif index > edgeIndex:
wire2Points.append(wire.Placement.multVec(point))
wire.Points = wire1Points
make_wire.make_wire(wire2Points, placement=wire.Placement)
return make_wire.make_wire(wire2Points, placement=wire.Placement)


splitOpenWire = split_open_wire
Expand Down
25 changes: 11 additions & 14 deletions src/Mod/Draft/draftguitools/gui_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,19 @@ def action(self, arg):
def proceed(self, info):
"""Proceed with execution of the command after click on an edge."""
self.end_callbacks(self.call)
wire = App.ActiveDocument.getObject(info["Object"])
edge_index = int(info["Component"][4:])
wire = info["Object"]
index = info["Component"][4:]
point = DraftVecUtils.toString(self.point)

Gui.addModule("Draft")
_cmd = "Draft.split"
_cmd += "("
_cmd += "FreeCAD.ActiveDocument." + wire.Name + ", "
_cmd += DraftVecUtils.toString(self.point) + ", "
_cmd += str(edge_index)
_cmd += ")"
_cmd_list = ["s = " + _cmd,
"FreeCAD.ActiveDocument.recompute()"]

self.commit(translate("draft", "Split line"),
_cmd_list)

cmd_list = [
"obj = FreeCAD.ActiveDocument." + wire,
"new = Draft.split(obj, " + point + ", " + index + ")",
"Draft.format_object(new, obj)",
"FreeCAD.ActiveDocument.recompute()"
]

self.commit(translate("draft", "Split line"), cmd_list)
self.finish()

def finish(self, cont=False):
Expand Down

0 comments on commit 735a076

Please sign in to comment.