Arch: Easier creations of struct + axes systems

With structs and axes selected, both Arch_Axis and Arch_Structure
commands now create axis systems
This commit is contained in:
Yorik van Havre 2012-07-16 15:54:51 -03:00
parent 66cfcd375f
commit 519d45e1f2
4 changed files with 57 additions and 5 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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()

View File

@ -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