From 519d45e1f27868d69aa20f73161c834dc653f3e0 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 16 Jul 2012 15:54:51 -0300 Subject: [PATCH] Arch: Easier creations of struct + axes systems With structs and axes selected, both Arch_Axis and Arch_Structure commands now create axis systems --- src/Mod/Arch/ArchAxis.py | 8 +++++++- src/Mod/Arch/ArchCommands.py | 20 +++++++++++++++++++- src/Mod/Arch/ArchStructure.py | 25 ++++++++++++++++++++++--- src/Mod/Draft/Draft.py | 9 +++++++++ 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/Mod/Arch/ArchAxis.py b/src/Mod/Arch/ArchAxis.py index a2ea31033..5bd132941 100644 --- a/src/Mod/Arch/ArchAxis.py +++ b/src/Mod/Arch/ArchAxis.py @@ -59,7 +59,13 @@ class _CommandAxis: def Activated(self): FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Axis"))) FreeCADGui.doCommand("import Arch") - FreeCADGui.doCommand("Arch.makeAxis()") + sel = FreeCADGui.Selection.getSelection() + st = Draft.getObjectsOfType(sel,"Structure") + if st: + FreeCADGui.doCommand("axe = Arch.makeAxis()") + FreeCADGui.doCommand("Arch.makeStructuralSystem(" + ArchCommands.getStringList(st) + ",[axe])") + else: + FreeCADGui.doCommand("Arch.makeAxis()") FreeCAD.ActiveDocument.commitTransaction() class _Axis: diff --git a/src/Mod/Arch/ArchCommands.py b/src/Mod/Arch/ArchCommands.py index 66babfc7c..f98c61c88 100644 --- a/src/Mod/Arch/ArchCommands.py +++ b/src/Mod/Arch/ArchCommands.py @@ -32,6 +32,17 @@ __url__ = "http://free-cad.sourceforge.net" # module functions ############################################### +def getStringList(objects): + '''getStringList(objects): returns a string defining a list + of objects''' + result = "[" + for o in objects: + if len(result) > 1: + result += "," + result += "FreeCAD.ActiveDocument." + o.Name + result += "]" + return result + def addComponents(objectsList,host): '''addComponents(objectsList,hostObject): adds the given object or the objects from the given list as components to the given host Object. Use this for @@ -53,11 +64,18 @@ def addComponents(objectsList,host): host.Group = c elif tp in ["Wall","Structure"]: a = host.Additions + if hasattr(host,"Axes"): + x = host.Axes for o in objectsList: - if not o in a: + if Draft.getType(o) == "Axis": + if not o in x: + x.append(o) + elif not o in a: if hasattr(o,"Shape"): a.append(o) host.Additions = a + if hasattr(host,"Axes"): + host.Axes = x elif tp in ["SectionPlane"]: a = host.Objects for o in objectsList: diff --git a/src/Mod/Arch/ArchStructure.py b/src/Mod/Arch/ArchStructure.py index b63853fe1..d249a8a83 100644 --- a/src/Mod/Arch/ArchStructure.py +++ b/src/Mod/Arch/ArchStructure.py @@ -21,7 +21,7 @@ #* * #*************************************************************************** -import FreeCAD,FreeCADGui,Draft,ArchComponent,DraftVecUtils +import FreeCAD,FreeCADGui,Draft,ArchComponent,DraftVecUtils,ArchCommands from FreeCAD import Vector from PyQt4 import QtCore from DraftTools import translate @@ -52,6 +52,18 @@ def makeStructure(baseobj=None,length=1,width=1,height=1,name=str(translate("Arc obj.ViewObject.ShapeColor = (r,g,b,1.0) return obj +def makeStructuralSystem(objects,axes): + '''makeStructuralSystem(objects,axes): makes a structural system + based on the given objects and axes''' + result = [] + if objects and axes: + for o in objects: + s = makeStructure(o) + s.Axes = axes + result.append(s) + FreeCAD.ActiveDocument.recompute() + return result + class _CommandStructure: "the Arch Structure command definition" def GetResources(self): @@ -65,8 +77,15 @@ class _CommandStructure: FreeCADGui.doCommand("import Arch") sel = FreeCADGui.Selection.getSelection() if sel: - for obj in sel: - FreeCADGui.doCommand("Arch.makeStructure(FreeCAD.ActiveDocument."+obj.Name+")") + # if selection contains structs and axes, make a system + st = Draft.getObjectsOfType(sel,"Structure") + ax = Draft.getObjectsOfType(sel,"Axis") + if st and ax: + FreeCADGui.doCommand("Arch.makeStructuralSystem(" + ArchCommands.getStringList(st) + "," + ArchCommands.getStringList(ax) + ")") + else: + # else, do normal structs + for obj in sel: + FreeCADGui.doCommand("Arch.makeStructure(FreeCAD.ActiveDocument." + obj.Name + ")") else: FreeCADGui.doCommand("Arch.makeStructure()") FreeCAD.ActiveDocument.commitTransaction() diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index aa5aeb18e..200e9fbbd 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -173,6 +173,15 @@ def getType(obj): return "Group" return "Unknown" +def getObjectsOfType(objectslist,typ): + """getObjectsOfType(objectslist,typ): returns a list of objects of type "typ" found + in the given object list""" + objs = [] + for o in objectslist: + if getType(o) == typ: + objs.append(o) + return objs + def get3DView(): "get3DView(): returns the current view if it is 3D, or the first 3D view found, or None" v = FreeCADGui.ActiveDocument.ActiveView