Draft: project point in split operation and copy original wire (#22452)
* Roy 043 patch 1 (#6) * Update split.py * Update gui_split.py * Add recompute to update wire in split test * Avoid circular import: init_draft_statusbar -> params -> init_draft_statusbar * Remove accidentally added "ui/preferences-webgl.ui"
This commit is contained in:
@@ -27,9 +27,8 @@
|
||||
|
||||
## \addtogroup draftfunctions
|
||||
# @{
|
||||
import draftutils.utils as utils
|
||||
import draftmake.make_wire as make_wire
|
||||
|
||||
from draftmake import make_copy
|
||||
from draftutils import utils
|
||||
|
||||
def split(wire, newPoint, edgeIndex):
|
||||
if utils.get_type(wire) != "Wire":
|
||||
@@ -41,12 +40,11 @@ def split(wire, newPoint, edgeIndex):
|
||||
|
||||
def split_closed_wire(wire, edgeIndex):
|
||||
wire.Closed = False
|
||||
new = make_copy.make_copy(wire)
|
||||
if edgeIndex == len(wire.Points):
|
||||
new = make_wire.make_wire([wire.Placement.multVec(wire.Points[0]),
|
||||
wire.Placement.multVec(wire.Points[-1])], placement=wire.Placement)
|
||||
new.Points = [wire.Points[0], wire.Points[-1]]
|
||||
else:
|
||||
new = make_wire.make_wire([wire.Placement.multVec(wire.Points[edgeIndex-1]),
|
||||
wire.Placement.multVec(wire.Points[edgeIndex])], placement=wire.Placement)
|
||||
new.Points = [wire.Points[edgeIndex-1], wire.Points[edgeIndex]]
|
||||
wire.Points = list(reversed(wire.Points[0:edgeIndex])) + list(reversed(wire.Points[edgeIndex:]))
|
||||
return new
|
||||
|
||||
@@ -55,19 +53,23 @@ splitClosedWire = split_closed_wire
|
||||
|
||||
|
||||
def split_open_wire(wire, newPoint, edgeIndex):
|
||||
new = make_copy.make_copy(wire)
|
||||
wire1Points = []
|
||||
wire2Points = []
|
||||
for index, point in enumerate(wire.Points):
|
||||
if index == edgeIndex:
|
||||
wire1Points.append(wire.Placement.inverse().multVec(newPoint))
|
||||
edge = wire.getSubObject("Edge" + str(edgeIndex))
|
||||
newPoint = wire.Placement.inverse().multVec(edge.Curve.projectPoint(newPoint))
|
||||
wire1Points.append(newPoint)
|
||||
wire2Points.append(newPoint)
|
||||
wire2Points.append(wire.Placement.multVec(point))
|
||||
wire2Points.append(point)
|
||||
elif index < edgeIndex:
|
||||
wire1Points.append(point)
|
||||
elif index > edgeIndex:
|
||||
wire2Points.append(wire.Placement.multVec(point))
|
||||
wire2Points.append(point)
|
||||
wire.Points = wire1Points
|
||||
return make_wire.make_wire(wire2Points, placement=wire.Placement)
|
||||
new.Points = wire2Points
|
||||
return new
|
||||
|
||||
|
||||
splitOpenWire = split_open_wire
|
||||
|
||||
@@ -95,7 +95,6 @@ class Split(gui_base_original.Modifier):
|
||||
cmd_list = [
|
||||
"obj = FreeCAD.ActiveDocument." + wire,
|
||||
"new = Draft.split(obj, " + point + ", " + index + ")",
|
||||
"Draft.format_object(new, obj)",
|
||||
"FreeCAD.ActiveDocument.recompute()"
|
||||
]
|
||||
|
||||
|
||||
@@ -236,6 +236,7 @@ class DraftModification(test_base.DraftTestCaseDoc):
|
||||
_msg(" a={0}, b={1}".format(a, b))
|
||||
_msg(" c={0}, d={1}".format(c, d))
|
||||
wire = Draft.make_wire([a, b, c, d])
|
||||
self.doc.recompute()
|
||||
|
||||
index = 1
|
||||
_msg(" Split at")
|
||||
|
||||
@@ -34,7 +34,6 @@ try:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
from draftutils import init_draft_statusbar
|
||||
from draftutils.translate import translate
|
||||
|
||||
if App.GuiUp:
|
||||
@@ -95,6 +94,8 @@ def _param_observer_callback_tray():
|
||||
|
||||
def _param_observer_callback_scalemultiplier(value):
|
||||
# value is a string.
|
||||
# import has to happen here to avoid circular imports
|
||||
from draftutils import init_draft_statusbar
|
||||
if not value:
|
||||
return
|
||||
value = float(value)
|
||||
|
||||
Reference in New Issue
Block a user