Draft: split Block from Draft.py
This commit is contained in:
committed by
Yorik van Havre
parent
0cbdba0245
commit
d53e53dc4e
@@ -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
|
||||
|
||||
@@ -253,6 +253,10 @@ if FreeCAD.GuiUp:
|
||||
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 @@ class _DrawingView(_DraftObject):
|
||||
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"""
|
||||
|
||||
|
||||
63
src/Mod/Draft/draftmake/make_block.py
Normal file
63
src/Mod/Draft/draftmake/make_block.py
Normal file
@@ -0,0 +1,63 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> *
|
||||
# * 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
|
||||
56
src/Mod/Draft/draftobjects/block.py
Normal file
56
src/Mod/Draft/draftobjects/block.py
Normal file
@@ -0,0 +1,56 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> *
|
||||
# * 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
|
||||
Reference in New Issue
Block a user