Draft: split PointArray from Draft.py

This commit is contained in:
carlopav
2020-05-09 14:47:17 +02:00
committed by Yorik van Havre
parent ebc84af368
commit a4b5fb2cd4
4 changed files with 179 additions and 66 deletions

View File

@@ -94,6 +94,7 @@ SET(Draft_make_functions
draftmake/make_patharray.py
draftmake/make_polygon.py
draftmake/make_point.py
draftmake/make_pointarray.py
draftmake/make_rectangle.py
draftmake/make_shapestring.py
draftmake/make_shape2dview.py
@@ -123,6 +124,7 @@ SET(Draft_objects
draftobjects/dimension.py
draftobjects/patharray.py
draftobjects/point.py
draftobjects/pointarray.py
draftobjects/polygon.py
draftobjects/rectangle.py
draftobjects/shapestring.py

View File

@@ -307,6 +307,10 @@ if FreeCAD.GuiUp:
# arrays
from draftmake.make_patharray import make_path_array, makePathArray
from draftobjects.patharray import PathArray, _PathArray
from draftmake.make_pointarray import make_point_array, makePointArray
from draftobjects.pointarray import PointArray, _PointArray
if FreeCAD.GuiUp:
from draftviewproviders.view_array import ViewProviderDraftArray
from draftviewproviders.view_array import _ViewProviderDraftArray
@@ -478,21 +482,6 @@ def makeArray(baseobject,arg1,arg2,arg3,arg4=None,arg5=None,arg6=None,name="Arra
select(obj)
return obj
def makePointArray(base, ptlst):
"""makePointArray(base,pointlist):"""
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","PointArray")
_PointArray(obj, base, ptlst)
obj.Base = base
obj.PointList = ptlst
if gui:
_ViewProviderDraftArray(obj.ViewObject)
base.ViewObject.hide()
formatObject(obj,obj.Base)
if len(obj.Base.ViewObject.DiffuseColor) > 1:
obj.ViewObject.Proxy.resetColors(obj.ViewObject)
select(obj)
return obj
def getDXF(obj,direction=None):
"""getDXF(object,[direction]): returns a DXF entity from the given
@@ -867,56 +856,5 @@ class _Array(_DraftLink):
base.append(npl)
return base
class _PointArray(_DraftObject):
"""The Draft Point Array object"""
def __init__(self, obj, bobj, ptlst):
_DraftObject.__init__(self,obj,"PointArray")
obj.addProperty("App::PropertyLink","Base","Draft",QT_TRANSLATE_NOOP("App::Property","Base")).Base = bobj
obj.addProperty("App::PropertyLink","PointList","Draft",QT_TRANSLATE_NOOP("App::Property","PointList")).PointList = ptlst
obj.addProperty("App::PropertyInteger","Count","Draft",QT_TRANSLATE_NOOP("App::Property","Count")).Count = 0
obj.setEditorMode("Count", 1)
def execute(self, obj):
import Part
from FreeCAD import Base, Vector
pls = []
opl = obj.PointList
while getType(opl) == 'Clone':
opl = opl.Objects[0]
if hasattr(opl, 'Geometry'):
place = opl.Placement
for pts in opl.Geometry:
if hasattr(pts, 'X') and hasattr(pts, 'Y') and hasattr(pts, 'Z'):
pn = pts.copy()
pn.translate(place.Base)
pn.rotate(place)
pls.append(pn)
elif hasattr(opl, 'Links'):
pls = opl.Links
elif hasattr(opl, 'Components'):
pls = opl.Components
base = []
i = 0
if hasattr(obj.Base, 'Shape'):
for pts in pls:
#print pts # inspect the objects
if hasattr(pts, 'X') and hasattr(pts, 'Y') and hasattr(pts, 'Z'):
nshape = obj.Base.Shape.copy()
if hasattr(pts, 'Placement'):
place = pts.Placement
nshape.translate(place.Base)
nshape.rotate(place.Base, place.Rotation.Axis, place.Rotation.Angle * 180 / math.pi )
else:
nshape.translate(Base.Vector(pts.X,pts.Y,pts.Z))
i += 1
base.append(nshape)
obj.Count = i
if i > 0:
obj.Shape = Part.makeCompound(base)
else:
FreeCAD.Console.PrintError(translate("draft","No point found\n"))
obj.Shape = obj.Base.Shape.copy()
## @}

View File

@@ -0,0 +1,66 @@
# ***************************************************************************
# * 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_point_array function.
"""
## @package make_pointarray
# \ingroup DRAFT
# \brief This module provides the code for Draft make_point_array function.
import FreeCAD as App
import draftutils.gui_utils as gui_utils
from draftobjects.pointarray import PointArray
if App.GuiUp:
from draftviewproviders.view_array import ViewProviderDraftArray
def make_point_array(base, ptlst):
"""make_point_array(base,pointlist)
Make a Draft PointArray object.
Parameters
----------
base :
TODO: describe
plist :
TODO: describe
"""
obj = App.ActiveDocument.addObject("Part::FeaturePython", "PointArray")
PointArray(obj, base, ptlst)
obj.Base = base
obj.PointList = ptlst
if App.GuiUp:
ViewProviderDraftArray(obj.ViewObject)
base.ViewObject.hide()
gui_utils.formatObject(obj,obj.Base)
if len(obj.Base.ViewObject.DiffuseColor) > 1:
obj.ViewObject.Proxy.resetColors(obj.ViewObject)
gui_utils.select(obj)
return obj
makePointArray = make_point_array

View File

@@ -0,0 +1,107 @@
# ***************************************************************************
# * 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 the Draft PointArray object.
"""
## @package pointarray
# \ingroup DRAFT
# \brief This module provides the object code for the Draft PointArray object.
import math
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD as App
import DraftVecUtils
import draftutils.utils as utils
from draftobjects.base import DraftObject
class PointArray(DraftObject):
"""The Draft Point Array object"""
def __init__(self, obj, bobj, ptlst):
super(PointArray, self).__init__(obj, "PointArray")
_tip = "Base object"
obj.addProperty("App::PropertyLink", "Base",
"Objects", QT_TRANSLATE_NOOP("App::Property", _tip))
_tip = "List of points used to distribute the base object"
obj.addProperty("App::PropertyLink", "PointList",
"Objects", QT_TRANSLATE_NOOP("App::Property", _tip))
_tip = "Number of copies" # TODO: verify description of the tooltip
obj.addProperty("App::PropertyInteger", "Count",
"Parameters", QT_TRANSLATE_NOOP("App::Property", _tip))
obj.Base = bobj
obj.PointList = ptlst
obj.Count = 0
obj.setEditorMode("Count", 1)
def execute(self, obj):
import Part
pls = []
opl = obj.PointList
while utils.get_type(opl) == 'Clone':
opl = opl.Objects[0]
if hasattr(opl, 'Geometry'):
place = opl.Placement
for pts in opl.Geometry:
if hasattr(pts, 'X') and hasattr(pts, 'Y') and hasattr(pts, 'Z'):
pn = pts.copy()
pn.translate(place.Base)
pn.rotate(place)
pls.append(pn)
elif hasattr(opl, 'Links'):
pls = opl.Links
elif hasattr(opl, 'Components'):
pls = opl.Components
base = []
i = 0
if hasattr(obj.Base, 'Shape'):
for pts in pls:
#print pts # inspect the objects
if hasattr(pts, 'X') and hasattr(pts, 'Y') and hasattr(pts, 'Z'):
nshape = obj.Base.Shape.copy()
if hasattr(pts, 'Placement'):
place = pts.Placement
nshape.translate(place.Base)
nshape.rotate(place.Base, place.Rotation.Axis, place.Rotation.Angle * 180 / math.pi )
else:
nshape.translate(App.Vector(pts.X,pts.Y,pts.Z))
i += 1
base.append(nshape)
obj.Count = i
if i > 0:
obj.Shape = Part.makeCompound(base)
else:
App.Console.PrintError(QT_TRANSLATE_NOOP("draft","No point found\n"))
obj.Shape = obj.Base.Shape.copy()
_PointArray = PointArray