From 091204606836198592ffac09f49a898c7ed5d244 Mon Sep 17 00:00:00 2001 From: carlopav Date: Sat, 25 Apr 2020 17:37:32 +0200 Subject: [PATCH] Draft: split Block from Draft.py --- src/Mod/Draft/CMakeLists.txt | 2 + src/Mod/Draft/Draft.py | 37 ++-------------- src/Mod/Draft/draftmake/make_block.py | 63 +++++++++++++++++++++++++++ src/Mod/Draft/draftobjects/block.py | 56 ++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 33 deletions(-) create mode 100644 src/Mod/Draft/draftmake/make_block.py create mode 100644 src/Mod/Draft/draftobjects/block.py diff --git a/src/Mod/Draft/CMakeLists.txt b/src/Mod/Draft/CMakeLists.txt index 4e5103dde5ab..f99ee4b2853b 100644 --- a/src/Mod/Draft/CMakeLists.txt +++ b/src/Mod/Draft/CMakeLists.txt @@ -65,6 +65,7 @@ SET(Draft_functions SET(Draft_make_functions draftmake/__init__.py draftmake/make_bezcurve.py + draftmake/make_block.py draftmake/make_bspline.py draftmake/make_circle.py draftmake/make_clone.py @@ -84,6 +85,7 @@ SET(Draft_objects draftobjects/__init__.py draftobjects/base.py draftobjects/bezcurve.py + draftobjects/block.py draftobjects/bspline.py draftobjects/circulararray.py draftobjects/circle.py diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index ea40ec1df02e..0303b4e12187 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -253,6 +253,10 @@ from draftviewproviders.view_facebinder import ViewProviderFacebinder from draftviewproviders.view_facebinder import _ViewProviderFacebinder +# shapestring +from draftmake.make_block import make_block, makeBlock +from draftobjects.block import Block, _Block + # shapestring from draftmake.make_shapestring import make_shapestring, makeShapeString from draftobjects.shapestring import ShapeString, _ShapeString @@ -490,20 +494,6 @@ def makeCopy(obj,force=None,reparent=False): formatObject(newobj,obj) return newobj -def makeBlock(objectslist): - """makeBlock(objectslist): Creates a Draft Block from the given objects""" - if not FreeCAD.ActiveDocument: - FreeCAD.Console.PrintError("No active document. Aborting\n") - return - obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Block") - _Block(obj) - obj.Components = objectslist - if gui: - _ViewProviderDraftPart(obj.ViewObject) - for o in objectslist: - o.ViewObject.Visibility = False - select(obj) - return obj def makeArray(baseobject,arg1,arg2,arg3,arg4=None,arg5=None,arg6=None,name="Array",use_link=False): """makeArray(object,xvector,yvector,xnum,ynum,[name]) for rectangular array, or @@ -2604,25 +2594,6 @@ def getDXF(self,obj): return getDXF(obj) -class _Block(_DraftObject): - """The Block object""" - - def __init__(self, obj): - _DraftObject.__init__(self,obj,"Block") - obj.addProperty("App::PropertyLinkList","Components","Draft",QT_TRANSLATE_NOOP("App::Property","The components of this block")) - - def execute(self, obj): - import Part - plm = obj.Placement - shps = [] - for c in obj.Components: - shps.append(c.Shape) - if shps: - shape = Part.makeCompound(shps) - obj.Shape = shape - obj.Placement = plm - obj.positionBySupport() - class _Shape2DView(_DraftObject): """The Shape2DView object""" diff --git a/src/Mod/Draft/draftmake/make_block.py b/src/Mod/Draft/draftmake/make_block.py new file mode 100644 index 000000000000..199a8a1f5d3d --- /dev/null +++ b/src/Mod/Draft/draftmake/make_block.py @@ -0,0 +1,63 @@ +# *************************************************************************** +# * Copyright (c) 2009, 2010 Yorik van Havre * +# * Copyright (c) 2009, 2010 Ken Cline * +# * Copyright (c) 2020 FreeCAD Developers * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""This module provides the code for Draft make_block function. +""" +## @package make_block +# \ingroup DRAFT +# \brief This module provides the code for Draft make_block function. + +import FreeCAD as App + +from draftutils.gui_utils import select + +from draftobjects.block import Block +if App.GuiUp: + from draftviewproviders.view_base import ViewProviderDraftPart + + +def make_block(objectslist): + """make_block(objectslist) + + Creates a Draft Block from the given objects. + + Parameters + ---------- + objectlist : list + Major radius of the ellipse. + + """ + if not App.ActiveDocument: + App.Console.PrintError("No active document. Aborting\n") + return + obj = App.ActiveDocument.addObject("Part::Part2DObjectPython","Block") + Block(obj) + obj.Components = objectslist + if App.GuiUp: + ViewProviderDraftPart(obj.ViewObject) + for o in objectslist: + o.ViewObject.Visibility = False + select(obj) + return obj + + +makeBlock = make_block \ No newline at end of file diff --git a/src/Mod/Draft/draftobjects/block.py b/src/Mod/Draft/draftobjects/block.py new file mode 100644 index 000000000000..323152cd4865 --- /dev/null +++ b/src/Mod/Draft/draftobjects/block.py @@ -0,0 +1,56 @@ +# *************************************************************************** +# * Copyright (c) 2009, 2010 Yorik van Havre * +# * Copyright (c) 2009, 2010 Ken Cline * +# * Copyright (c) 2020 FreeCAD Developers * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +"""This module provides the object code for Draft Block. +""" +## @package block +# \ingroup DRAFT +# \brief This module provides the object code for Draft Block. + +from PySide.QtCore import QT_TRANSLATE_NOOP + +from draftobjects.base import DraftObject + + +class Block(DraftObject): + """The Block object""" + + def __init__(self, obj): + super(Block, self).__init__(obj, "Block") + + _tip = "The components of this block" + obj.addProperty("App::PropertyLinkList","Components", + "Draft",QT_TRANSLATE_NOOP("App::Property", _tip)) + + def execute(self, obj): + import Part + plm = obj.Placement + shps = [] + for c in obj.Components: + shps.append(c.Shape) + if shps: + shape = Part.makeCompound(shps) + obj.Shape = shape + obj.Placement = plm + obj.positionBySupport() + +_Block = Block \ No newline at end of file