[Draft] Improved Autogroup to handle Draft Annotations
Draft Dimension, Label and Text are now correctly auto-added to Part container
This commit is contained in:
committed by
Yorik van Havre
parent
1d7b62e6ee
commit
ff3bdf86bc
@@ -5274,6 +5274,7 @@ class Draft_Label(Creator):
|
|||||||
FreeCAD.ActiveDocument.openTransaction("Create Label")
|
FreeCAD.ActiveDocument.openTransaction("Create Label")
|
||||||
FreeCADGui.addModule("Draft")
|
FreeCADGui.addModule("Draft")
|
||||||
FreeCADGui.doCommand("l = Draft.makeLabel("+tp+sel+"direction='"+direction+"',distance="+str(dist)+",labeltype='"+self.labeltype+"',"+pl+")")
|
FreeCADGui.doCommand("l = Draft.makeLabel("+tp+sel+"direction='"+direction+"',distance="+str(dist)+",labeltype='"+self.labeltype+"',"+pl+")")
|
||||||
|
FreeCADGui.doCommand("Draft.autogroup(l)")
|
||||||
FreeCAD.ActiveDocument.recompute()
|
FreeCAD.ActiveDocument.recompute()
|
||||||
FreeCAD.ActiveDocument.commitTransaction()
|
FreeCAD.ActiveDocument.commitTransaction()
|
||||||
self.finish()
|
self.finish()
|
||||||
|
|||||||
@@ -98,55 +98,68 @@ def autogroup(obj):
|
|||||||
obj: App::DocumentObject
|
obj: App::DocumentObject
|
||||||
Any type of object that will be stored in the group.
|
Any type of object that will be stored in the group.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# check for required conditions for autogroup to work
|
||||||
if not App.GuiUp:
|
if not App.GuiUp:
|
||||||
return
|
return
|
||||||
|
if not hasattr(Gui,"draftToolBar"):
|
||||||
|
return
|
||||||
|
if not hasattr(Gui.draftToolBar,"autogroup"):
|
||||||
|
return
|
||||||
|
if Gui.draftToolBar.isConstructionMode():
|
||||||
|
return
|
||||||
|
|
||||||
|
# autogroup code
|
||||||
|
if Gui.draftToolBar.autogroup is not None:
|
||||||
|
active_group = App.ActiveDocument.getObject(Gui.draftToolBar.autogroup)
|
||||||
|
if active_group:
|
||||||
|
found = False
|
||||||
|
for o in active_group.Group:
|
||||||
|
if o.Name == obj.Name:
|
||||||
|
found = True
|
||||||
|
if not found:
|
||||||
|
gr = active_group.Group
|
||||||
|
gr.append(obj)
|
||||||
|
active_group.Group = gr
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
doc = App.ActiveDocument
|
if Gui.ActiveDocument.ActiveView.getActiveObject("Arch"):
|
||||||
view = Gui.ActiveDocument.ActiveView
|
# add object to active Arch Container
|
||||||
|
Gui.ActiveDocument.ActiveView.getActiveObject("Arch").addObject(obj)
|
||||||
# Look for active Arch container
|
|
||||||
active_arch_obj = Gui.ActiveDocument.ActiveView.getActiveObject("Arch")
|
elif Gui.ActiveDocument.ActiveView.getActiveObject("part", False) is not None:
|
||||||
if hasattr(Gui, "draftToolBar"):
|
# add object to active part and change it's placement accordingly
|
||||||
if (hasattr(Gui.draftToolBar, "autogroup")
|
# so object does not jump to different position, works with App::Link
|
||||||
and not Gui.draftToolBar.isConstructionMode()):
|
# if not scaled. Modified accordingly to realthunder suggestions
|
||||||
if Gui.draftToolBar.autogroup is not None:
|
p, parent, sub = Gui.ActiveDocument.ActiveView.getActiveObject("part", False)
|
||||||
active_group = doc.getObject(Gui.draftToolBar.autogroup)
|
matrix = parent.getSubObject(sub, retType=4)
|
||||||
if active_group:
|
if matrix.hasScale() == 1:
|
||||||
found = False
|
err = translate("Draft",
|
||||||
for o in active_group.Group:
|
"Unable to insert new object into "
|
||||||
if o.Name == obj.Name:
|
"a scaled part")
|
||||||
found = True
|
App.Console.PrintMessage(err)
|
||||||
if not found:
|
return
|
||||||
gr = active_group.Group
|
inverse_placement = App.Placement(matrix.inverse())
|
||||||
gr.append(obj)
|
if get_type(obj) == 'Point':
|
||||||
active_group.Group = gr
|
point_vector = App.Vector(obj.X, obj.Y, obj.Z)
|
||||||
elif active_arch_obj:
|
real_point = inverse_placement.multVec(point_vector)
|
||||||
active_arch_obj.addObject(obj)
|
obj.X = real_point.x
|
||||||
elif view.getActiveObject("part", False) is not None:
|
obj.Y = real_point.y
|
||||||
# Add object to active part and change its placement
|
obj.Z = real_point.z
|
||||||
# accordingly so the object does not jump
|
elif get_type(obj) in ["Dimension"]:
|
||||||
# to a different position, works with App::Link if not scaled.
|
obj.Start = inverse_placement.multVec(obj.Start)
|
||||||
# Modified accordingly to realthunder suggestions
|
obj.End = inverse_placement.multVec(obj.End)
|
||||||
p, parent, sub = view.getActiveObject("part", False)
|
obj.Dimline = inverse_placement.multVec(obj.Dimline)
|
||||||
matrix = parent.getSubObject(sub, retType=4)
|
obj.Normal = inverse_placement.Rotation.multVec(obj.Normal)
|
||||||
if matrix.hasScale() == 1:
|
obj.Direction = inverse_placement.Rotation.multVec(obj.Direction)
|
||||||
_msg(translate("Draft",
|
elif get_type(obj) in ["Label"]:
|
||||||
"Unable to insert new object into "
|
obj.Placement = App.Placement(inverse_placement.multiply(obj.Placement))
|
||||||
"a scaled part"))
|
obj.TargetPoint = inverse_placement.multVec(obj.TargetPoint)
|
||||||
return
|
elif hasattr(obj,"Placement"):
|
||||||
inverse_placement = App.Placement(matrix.inverse())
|
# every object that have a placement is processed here
|
||||||
if get_type(obj) == 'Point':
|
obj.Placement = App.Placement(inverse_placement.multiply(obj.Placement))
|
||||||
# point vector have a kind of placement, so should be
|
p.addObject(obj)
|
||||||
# processed before generic object with placement
|
|
||||||
point_vector = App.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
|
|
||||||
elif hasattr(obj, "Placement"):
|
|
||||||
place = inverse_placement.multiply(obj.Placement)
|
|
||||||
obj.Placement = App.Placement(place)
|
|
||||||
p.addObject(obj)
|
|
||||||
|
|
||||||
|
|
||||||
def dim_symbol(symbol=None, invert=False):
|
def dim_symbol(symbol=None, invert=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user