Add a new array type: PointArray.

This commit is contained in:
ageeye
2018-06-16 09:03:24 +02:00
committed by Yorik van Havre
parent 70c190f5dc
commit ec16d82c96
5 changed files with 481 additions and 1 deletions

View File

@@ -1243,6 +1243,22 @@ def makePathArray(baseobject,pathobject,count,xlate=None,align=False,pathobjsubs
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:
FreeCAD.ActiveDocument.recompute()
obj.ViewObject.Proxy.resetColors(obj.ViewObject)
select(obj)
return obj
def makeEllipse(majradius,minradius,placement=None,face=True,support=None):
'''makeEllipse(majradius,minradius,[placement],[face],[support]): makes
an ellipse with the given major and minor radius, and optionally
@@ -6066,6 +6082,44 @@ class _PathArray(_DraftObject):
travel += step
return(Part.makeCompound(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'):
pls = opl.Geometry
elif hasattr(opl, 'Links'):
pls = opl.Links
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, 'Y'):
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 )
nshape.translate(Base.Vector(pts.X,pts.Y,pts.Z))
i += 1
base.append(nshape)
obj.Count = i
obj.Shape = Part.makeCompound(base)
class _Point(_DraftObject):
"The Draft Point object"
def __init__(self, obj,x=0,y=0,z=0):
@@ -6243,6 +6297,8 @@ class _ViewProviderDraftArray(_ViewProviderDraft):
def getIcon(self):
if hasattr(self.Object,"ArrayType"):
return ":/icons/Draft_Array.svg"
elif hasattr(self.Object,"PointList"):
return ":/icons/Draft_PointArray.svg"
return ":/icons/Draft_PathArray.svg"
def resetColors(self, vobj):

View File

@@ -4788,6 +4788,37 @@ class PathArray(Modifier):
FreeCAD.ActiveDocument.recompute() # feature won't appear until recompute.
self.finish()
class PointArray(Modifier):
"The PointArray FreeCAD command definition"
def GetResources(self):
return {'Pixmap' : 'Draft_PointArray',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Draft_PointArray", "PointArray"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Draft_PointArray", "Creates copies of a selected object on the position of points.")}
def Activated(self):
Modifier.Activated(self)
if not FreeCADGui.Selection.getSelectionEx():
if self.ui:
self.ui.selectUi()
msg(translate("draft", "Please select base and pointlist objects\n"))
self.call = self.view.addEventCallback("SoEvent",selectObject)
else:
self.proceed()
def proceed(self):
if self.call:
self.view.removeEventCallback("SoEvent",self.call)
sel = FreeCADGui.Selection.getSelectionEx()
if sel:
base = sel[0].Object
ptlst = sel[1].Object
FreeCAD.ActiveDocument.openTransaction("PointArray")
Draft.makePointArray(base, ptlst)
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
self.finish()
class Point(Creator):
"this class will create a vertex after the user clicks a point on the screen"
@@ -5657,6 +5688,7 @@ FreeCADGui.addCommand('Draft_Draft2Sketch',Draft2Sketch())
FreeCADGui.addCommand('Draft_Array',Array())
FreeCADGui.addCommand('Draft_Clone',Draft_Clone())
FreeCADGui.addCommand('Draft_PathArray',PathArray())
FreeCADGui.addCommand('Draft_PointArray',PointArray())
FreeCADGui.addCommand('Draft_Heal',Heal())
FreeCADGui.addCommand('Draft_VisGroup',VisGroup())
FreeCADGui.addCommand('Draft_Mirror',Mirror())

View File

@@ -76,7 +76,8 @@ class DraftWorkbench (Workbench):
"Draft_Trimex", "Draft_Upgrade", "Draft_Downgrade", "Draft_Scale",
"Draft_Edit","Draft_WireToBSpline","Draft_AddPoint",
"Draft_DelPoint","Draft_Shape2DView","Draft_Draft2Sketch","Draft_Array",
"Draft_PathArray","Draft_Clone","Draft_Drawing","Draft_Mirror","Draft_Stretch"]
"Draft_PathArray", "Draft_PointArray","Draft_Clone",
"Draft_Drawing","Draft_Mirror","Draft_Stretch"]
self.treecmdList = ["Draft_ApplyStyle","Draft_ToggleDisplayMode","Draft_AddToGroup",
"Draft_SelectGroup","Draft_SelectPlane",
"Draft_ShowSnapBar","Draft_ToggleGrid","Draft_AutoGroup"]

View File

@@ -45,6 +45,7 @@
<file>icons/Draft_Point.svg</file>
<file>icons/Draft_Snap.svg</file>
<file>icons/Draft_PathArray.svg</file>
<file>icons/Draft_PointArray.svg</file>
<file>icons/Draft_VisGroup.svg</file>
<file>icons/Snap_Lock.svg</file>
<file>icons/Snap_Endpoint.svg</file>

View File

@@ -0,0 +1,390 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64px"
height="64px"
id="svg5821"
sodipodi:version="0.32"
inkscape:version="0.91 r13725"
sodipodi:docname="Draft_PointArray.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.1"
inkscape:export-filename="/home/user/Downloads/cad/mystuff/icons/Draft_wb_primitives/Draft_Array/Draft_Array_Ortho_16px.png"
inkscape:export-xdpi="22.5"
inkscape:export-ydpi="22.5">
<defs
id="defs5823">
<linearGradient
inkscape:collect="always"
id="linearGradient3791">
<stop
style="stop-color:#204a87;stop-opacity:1"
offset="0"
id="stop3793" />
<stop
style="stop-color:#729fcf;stop-opacity:1"
offset="1"
id="stop3795" />
</linearGradient>
<linearGradient
inkscape:collect="always"
id="linearGradient6349">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop6351" />
<stop
style="stop-color:#000000;stop-opacity:0;"
offset="1"
id="stop6353" />
</linearGradient>
<linearGradient
id="linearGradient3377">
<stop
style="stop-color:#0019a3;stop-opacity:1;"
offset="0"
id="stop3379" />
<stop
style="stop-color:#0069ff;stop-opacity:1;"
offset="1"
id="stop3381" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3377"
id="linearGradient3383"
x1="901.1875"
y1="1190.875"
x2="1267.9062"
y2="1190.875"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-1,0,0,1,2199.356,0)" />
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 32 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="64 : 32 : 1"
inkscape:persp3d-origin="32 : 21.333333 : 1"
id="perspective5829" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient6349"
id="radialGradient6355"
cx="1103.6399"
cy="1424.4465"
fx="1103.6399"
fy="1424.4465"
r="194.40614"
gradientTransform="matrix(-1.4307499,-1.3605156e-7,-1.202713e-8,0.1264801,2674.7488,1244.2826)"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3791"
id="linearGradient3797"
x1="939.98767"
y1="1097.5122"
x2="893.2572"
y2="989.77716"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
id="linearGradient3791-6">
<stop
style="stop-color:#204a87;stop-opacity:1"
offset="0"
id="stop3793-7" />
<stop
style="stop-color:#729fcf;stop-opacity:1"
offset="1"
id="stop3795-5" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3791-6"
id="linearGradient3820"
x1="939.98767"
y1="1097.5122"
x2="893.2572"
y2="989.77716"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3791-6-7"
id="linearGradient3797-3-2"
x1="939.98767"
y1="1097.5122"
x2="893.2572"
y2="989.77716"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
id="linearGradient3791-6-7">
<stop
style="stop-color:#204a87;stop-opacity:1"
offset="0"
id="stop3793-7-0" />
<stop
style="stop-color:#729fcf;stop-opacity:1"
offset="1"
id="stop3795-5-9" />
</linearGradient>
<linearGradient
y2="989.77716"
x2="893.2572"
y1="1097.5122"
x1="939.98767"
gradientUnits="userSpaceOnUse"
id="linearGradient3834-3"
xlink:href="#linearGradient3791-6-7"
inkscape:collect="always" />
<linearGradient
inkscape:collect="always"
id="linearGradient3791-0">
<stop
style="stop-color:#204a87;stop-opacity:1"
offset="0"
id="stop3793-6" />
<stop
style="stop-color:#729fcf;stop-opacity:1"
offset="1"
id="stop3795-2" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3791-0"
id="linearGradient3896"
x1="939.98767"
y1="1097.5122"
x2="893.2572"
y2="989.77716"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3791-2"
id="linearGradient3797-1"
x1="939.98767"
y1="1097.5122"
x2="893.2572"
y2="989.77716"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
id="linearGradient3791-2">
<stop
style="stop-color:#204a87;stop-opacity:1"
offset="0"
id="stop3793-9" />
<stop
style="stop-color:#729fcf;stop-opacity:1"
offset="1"
id="stop3795-3" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3791-2"
id="linearGradient3896-1"
x1="939.98767"
y1="1097.5122"
x2="893.2572"
y2="989.77716"
gradientUnits="userSpaceOnUse" />
<linearGradient
y2="989.77716"
x2="893.2572"
y1="1097.5122"
x1="939.98767"
gradientUnits="userSpaceOnUse"
id="linearGradient3916-9"
xlink:href="#linearGradient3791-2"
inkscape:collect="always" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="10.299484"
inkscape:cx="35.198497"
inkscape:cy="32.167922"
inkscape:current-layer="g3360"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1280"
inkscape:window-height="747"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:snap-global="true"
inkscape:snap-bbox="true">
<inkscape:grid
type="xygrid"
id="grid3010"
units="px"
empspacing="2"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true"
spacingx="1px"
spacingy="1px" />
</sodipodi:namedview>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<g
id="g3360"
inkscape:export-filename="/home/yorik/Documents/Lab/Draft/icons/draft.png"
inkscape:export-xdpi="3.2478156"
inkscape:export-ydpi="3.2478156"
transform="matrix(0.1367863,0,0,0.1367863,-119.15519,-134.86962)">
<g
id="g3799">
<g
id="g3956">
<g
id="g3812"
transform="matrix(1.7521655,0,0,1.4657307,-647.24141,-419.43277)"
style="fill:#3465a4;stroke:#0b1521;stroke-width:9.12373734;stroke-opacity:1">
<rect
y="983.79187"
x="887.41589"
height="119.7056"
width="58.413097"
id="rect3808"
style="fill:#3465a4;fill-opacity:1;fill-rule:nonzero;stroke:#0b1521;stroke-width:9.12373734;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
</g>
<g
id="g3812-0"
transform="matrix(1.251547,0,0,1.2214422,-188.36328,-164.48243)"
style="fill:url(#linearGradient3797);stroke:#729fcf;stroke-width:11.82571345000000029;stroke-opacity:1;stroke-linecap:square;stroke-miterlimit:4;stroke-dasharray:none;stroke-linejoin:miter;fill-opacity:1">
<rect
y="983.79187"
x="887.41589"
height="119.7056"
width="58.413097"
id="rect3808-6"
style="fill:url(#linearGradient3797);fill-opacity:1.0;fill-rule:nonzero;stroke:#729fcf;stroke-width:11.82571345000000029;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
</g>
</g>
</g>
<g
transform="translate(146.21345,219.32019)"
id="g3799-3-2">
<g
id="g3956-5-3">
<g
id="g3812-6-7"
transform="matrix(1.7521655,0,0,1.4657307,-647.24141,-419.43277)"
style="fill:#3465a4;stroke:#0b1521;stroke-width:9.12373734;stroke-opacity:1">
<rect
y="983.79187"
x="887.41589"
height="119.7056"
width="58.413097"
id="rect3808-2-5"
style="fill:#3465a4;fill-opacity:1;fill-rule:nonzero;stroke:#0b1521;stroke-width:9.12373734;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
</g>
<g
id="g3812-0-9-9"
transform="matrix(1.251547,0,0,1.2214422,-188.36328,-164.48243)"
style="fill:url(#linearGradient3797-3-2);fill-opacity:1;stroke:#729fcf;stroke-width:11.82571316;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none">
<rect
y="983.79187"
x="887.41589"
height="119.7056"
width="58.413097"
id="rect3808-6-1-2"
style="fill:url(#linearGradient3834-3);fill-opacity:1;fill-rule:nonzero;stroke:#729fcf;stroke-width:11.82571316;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
</g>
</g>
</g>
<g
transform="translate(292.42692,-3.1029367e-7)"
id="g3799-4">
<g
id="g3956-7">
<g
id="g3812-84"
transform="matrix(1.7521655,0,0,1.4657307,-647.24141,-419.43277)"
style="fill:#3465a4;stroke:#0b1521;stroke-width:9.12373734;stroke-opacity:1">
<rect
y="983.79187"
x="887.41589"
height="119.7056"
width="58.413097"
id="rect3808-5"
style="fill:#3465a4;fill-opacity:1;fill-rule:nonzero;stroke:#0b1521;stroke-width:9.12373734;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
</g>
<g
id="g3812-0-0"
transform="matrix(1.251547,0,0,1.2214422,-188.36328,-164.48243)"
style="fill:url(#linearGradient3797-1);fill-opacity:1;stroke:#729fcf;stroke-width:11.82571316;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none">
<rect
y="983.79187"
x="887.41589"
height="119.7056"
width="58.413097"
id="rect3808-6-3"
style="fill:url(#linearGradient3916-9);fill-opacity:1;fill-rule:nonzero;stroke:#729fcf;stroke-width:11.82571316;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
</g>
</g>
</g>
</g>
</g>
<metadata
id="metadata3357">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>Draft_Array</dc:title>
<cc:license
rdf:resource="" />
<dc:date>Sat Dec 10 18:31:32 2011 +0000</dc:date>
<dc:creator>
<cc:Agent>
<dc:title>[yorikvanhavre]</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>FreeCAD LGPL2+</dc:title>
</cc:Agent>
</dc:rights>
<dc:publisher>
<cc:Agent>
<dc:title>FreeCAD</dc:title>
</cc:Agent>
</dc:publisher>
<dc:identifier>FreeCAD/src/Mod/Draft/Resources/icons/Draft_Array.svg</dc:identifier>
<dc:relation>http://www.freecadweb.org/wiki/index.php?title=Artwork</dc:relation>
<dc:contributor>
<cc:Agent>
<dc:title>[agryson] Alexander Gryson</dc:title>
</cc:Agent>
</dc:contributor>
<dc:description>Six rectangles in a 2 x 3 linear array</dc:description>
<dc:subject>
<rdf:Bag>
<rdf:li>rectangle</rdf:li>
<rdf:li>array</rdf:li>
</rdf:Bag>
</dc:subject>
</cc:Work>
</rdf:RDF>
</metadata>
</svg>

After

Width:  |  Height:  |  Size: 13 KiB