diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 4d94792a2c..13e31cfaa1 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -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): diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index 94419928ea..6b27e7024c 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -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()) diff --git a/src/Mod/Draft/InitGui.py b/src/Mod/Draft/InitGui.py index ae3b19e677..6b29a028be 100644 --- a/src/Mod/Draft/InitGui.py +++ b/src/Mod/Draft/InitGui.py @@ -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"] diff --git a/src/Mod/Draft/Resources/Draft.qrc b/src/Mod/Draft/Resources/Draft.qrc index d6135fa1df..881620f935 100644 --- a/src/Mod/Draft/Resources/Draft.qrc +++ b/src/Mod/Draft/Resources/Draft.qrc @@ -45,6 +45,7 @@ icons/Draft_Point.svg icons/Draft_Snap.svg icons/Draft_PathArray.svg + icons/Draft_PointArray.svg icons/Draft_VisGroup.svg icons/Snap_Lock.svg icons/Snap_Endpoint.svg diff --git a/src/Mod/Draft/Resources/icons/Draft_PointArray.svg b/src/Mod/Draft/Resources/icons/Draft_PointArray.svg new file mode 100644 index 0000000000..4118153747 --- /dev/null +++ b/src/Mod/Draft/Resources/icons/Draft_PointArray.svg @@ -0,0 +1,390 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Draft_Array + + Sat Dec 10 18:31:32 2011 +0000 + + + [yorikvanhavre] + + + + + FreeCAD LGPL2+ + + + + + FreeCAD + + + FreeCAD/src/Mod/Draft/Resources/icons/Draft_Array.svg + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + [agryson] Alexander Gryson + + + Six rectangles in a 2 x 3 linear array + + + rectangle + array + + + + + +