From 3351cde4629463560ea6d7513a912173a8b6cba0 Mon Sep 17 00:00:00 2001 From: carlopav Date: Sun, 26 Apr 2020 10:44:44 +0200 Subject: [PATCH] Draft: split FilterObjectsForModifiers from Draft.py --- src/Mod/Draft/Draft.py | 27 +++++---------------------- src/Mod/Draft/draftutils/utils.py | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index ea11f79826..393693e35c 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -141,6 +141,9 @@ from draftutils.utils import svg_patterns from draftutils.utils import getMovableChildren from draftutils.utils import get_movable_children +from draftutils.utils import filter_objects_for_modifiers +from draftutils.utils import filterObjectsForModifiers + from draftutils.gui_utils import get3DView from draftutils.gui_utils import get_3d_view @@ -682,7 +685,7 @@ def move(objectslist,vector,copy=False): objectslist.extend(getMovableChildren(objectslist)) newobjlist = [] newgroups = {} - objectslist = filterObjectsForModifiers(objectslist, copy) + objectslist = filter_objects_for_modifiers(objectslist, copy) for obj in objectslist: newobj = None # real_vector have been introduced to take into account @@ -826,26 +829,6 @@ def array(objectslist,arg1,arg2,arg3,arg4=None,arg5=None,arg6=None): else: polarArray(objectslist,arg1,arg2,arg3) -def filterObjectsForModifiers(objects, isCopied=False): - filteredObjects = [] - for object in objects: - if hasattr(object, "MoveBase") and object.MoveBase and object.Base: - parents = [] - for parent in object.Base.InList: - if parent.isDerivedFrom("Part::Feature"): - parents.append(parent.Name) - if len(parents) > 1: - warningMessage = translate("draft","%s shares a base with %d other objects. Please check if you want to modify this.") % (object.Name,len(parents) - 1) - FreeCAD.Console.PrintError(warningMessage) - if FreeCAD.GuiUp: - FreeCADGui.getMainWindow().showMessage(warningMessage, 0) - filteredObjects.append(object.Base) - elif hasattr(object,"Placement") and object.getEditorMode("Placement") == ["ReadOnly"] and not isCopied: - FreeCAD.Console.PrintError(translate("Draft","%s cannot be modified because its placement is readonly.") % obj.Name) - continue - else: - filteredObjects.append(object) - return filteredObjects def rotateVertex(object, vertex_index, angle, center, axis): points = object.Points @@ -880,7 +863,7 @@ def rotate(objectslist,angle,center=Vector(0,0,0),axis=Vector(0,0,1),copy=False) objectslist.extend(getMovableChildren(objectslist)) newobjlist = [] newgroups = {} - objectslist = filterObjectsForModifiers(objectslist, copy) + objectslist = filter_objects_for_modifiers(objectslist, copy) for obj in objectslist: newobj = None # real_center and real_axis are introduced to take into account diff --git a/src/Mod/Draft/draftutils/utils.py b/src/Mod/Draft/draftutils/utils.py index ee93388f47..93304a4ba6 100644 --- a/src/Mod/Draft/draftutils/utils.py +++ b/src/Mod/Draft/draftutils/utils.py @@ -955,6 +955,31 @@ def get_movable_children(objectslist, recursive=True): getMovableChildren = get_movable_children +def filter_objects_for_modifiers(objects, isCopied=False): + filteredObjects = [] + for obj in objects: + if hasattr(obj, "MoveBase") and obj.MoveBase and obj.Base: + parents = [] + for parent in obj.Base.InList: + if parent.isDerivedFrom("Part::Feature"): + parents.append(parent.Name) + if len(parents) > 1: + warningMessage = _tr("%s shares a base with %d other objects. Please check if you want to modify this.") % (obj.Name,len(parents) - 1) + App.Console.PrintError(warningMessage) + if App.GuiUp: + FreeCADGui.getMainWindow().showMessage(warningMessage, 0) + filteredObjects.append(obj.Base) + elif hasattr(obj,"Placement") and obj.getEditorMode("Placement") == ["ReadOnly"] and not isCopied: + App.Console.PrintError(_tr("%s cannot be modified because its placement is readonly.") % obj.Name) + continue + else: + filteredObjects.append(obj) + return filteredObjects + + +filterObjectsForModifiers = filter_objects_for_modifiers + + def utf8_decode(text): r"""Decode the input string and return a unicode string.