From 44a521f7c1a569c8257148743cbf22d0626fdf17 Mon Sep 17 00:00:00 2001 From: carlopav Date: Sat, 18 Jan 2020 17:51:21 +0100 Subject: [PATCH] [Draft] Autogroup: better support for App::Link https://forum.freecadweb.org/viewtopic.php?f=23&t=40400&start=30#p360248 Reference to forum topic. small fix small fix --- src/Mod/Draft/draftutils/gui_utils.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Mod/Draft/draftutils/gui_utils.py b/src/Mod/Draft/draftutils/gui_utils.py index 64812b7dcc..fca749cff8 100644 --- a/src/Mod/Draft/draftutils/gui_utils.py +++ b/src/Mod/Draft/draftutils/gui_utils.py @@ -99,8 +99,6 @@ def autogroup(obj): Any type of object that will be stored in the group. """ if FreeCAD.GuiUp: - # look for active Part container - active_part = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part") # look for active Arch container active_arch_obj = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("Arch") if hasattr(FreeCADGui,"draftToolBar"): @@ -120,21 +118,30 @@ def autogroup(obj): active_group.Group = gr elif active_arch_obj: active_arch_obj.addObject(obj) - elif active_part: - # add object to active part and change it's placement so accordingly - # so object does not jump to different position - inverse_placement = active_part.getGlobalPlacement().inverse() - if get_type(obj) == 'Point': + elif FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part", False) is not None: + # add object to active part and change it's placement accordingly + # so object does not jump to different position, works with App::Link + # if not scaled. Modified accordingly to realthunder suggestions + p, parent, sub = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part", False) + matrix = parent.getSubObject(sub, retType=4) + if matrix.hasScale() == 1: + FreeCAD.Console.PrintMessage(translate("Draft", + "Unable to insert new object into " + "a scaled part") + ) + return + inverse_placement = FreeCAD.Placement(matrix.inverse()) + if getType(obj) == 'Point': # point vector have a kind of placement, so should be # processed before generic object with placement point_vector = FreeCAD.Vector(obj.X, obj.Y, obj.Z) real_point = inverse_placement.multVec(point_vector) obj.X = real_point.x obj.Y = real_point.y - obj.Z = real_point.z + obj.Z = real_point.z elif hasattr(obj,"Placement"): obj.Placement = FreeCAD.Placement(inverse_placement.multiply(obj.Placement)) - active_part.addObject(obj) + p.addObject(obj) def dim_symbol(symbol=None, invert=False):