Arch: Added Tool property to Structs to define an extrusion path

This commit is contained in:
Yorik van Havre 2013-07-27 17:12:48 -03:00
parent 03be0d39ec
commit cb789a25d8
4 changed files with 60 additions and 29 deletions

View File

@ -67,25 +67,24 @@ def addComponents(objectsList,host):
example to add windows to a wall, or to add walls to a cell or floor.'''
if not isinstance(objectsList,list):
objectsList = [objectsList]
tp = Draft.getType(host)
if tp in ["Cell"]:
c = host.Components
for o in objectsList:
if not o in c:
c.append(o)
host.Components = c
elif tp in ["Floor","Building","Site"]:
hostType = Draft.getType(host)
if hostType in ["Floor","Building","Site"]:
c = host.Group
for o in objectsList:
if not o in c:
c.append(o)
host.Group = c
elif tp in ["Wall","Structure","Window","Roof"]:
elif hostType in ["Wall","Structure","Window","Roof"]:
import DraftGeomUtils
a = host.Additions
if hasattr(host,"Axes"):
x = host.Axes
for o in objectsList:
if Draft.getType(o) == "Axis":
if DraftGeomUtils.isValidPath(o.Shape) and (hostType == "Structure"):
if o.Support == host:
o.Support = None
host.Tool = o
elif Draft.getType(o) == "Axis":
if not o in x:
x.append(o)
elif not o in a:
@ -94,7 +93,7 @@ def addComponents(objectsList,host):
host.Additions = a
if hasattr(host,"Axes"):
host.Axes = x
elif tp in ["SectionPlane"]:
elif hostType in ["SectionPlane"]:
a = host.Objects
for o in objectsList:
if not o in a:
@ -117,6 +116,9 @@ def removeComponents(objectsList,host=None):
objectsList = [objectsList]
if host:
if Draft.getType(host) in ["Wall","Structure"]:
if hasattr(host,"Tool"):
if objectsList[0] == host.Tool:
host.Tool = None
if hasattr(host,"Axes"):
a = host.Axes
for o in objectsList[:]:
@ -150,7 +152,7 @@ def removeComponents(objectsList,host=None):
if o.InList:
h = o.InList[0]
tp = Draft.getType(h)
if tp in ["Cell","Floor","Building","Site"]:
if tp in ["Floor","Building","Site"]:
c = h.Components
if o in c:
c.remove(o)

View File

@ -448,6 +448,9 @@ class ViewProviderComponent:
c = [self.Object.Base]+self.Object.Additions+self.Object.Subtractions
if hasattr(self.Object,"Fixtures"):
c.extend(self.Object.Fixtures)
if hasattr(self.Object,"Tool"):
if self.Object.Tool:
c.append(self.Object.Tool)
return c
return []

View File

@ -291,6 +291,8 @@ class _Structure(ArchComponent.Component):
"The Structure object"
def __init__(self,obj):
ArchComponent.Component.__init__(self,obj)
obj.addProperty("App::PropertyLink","Tool","Base",
"An optional extrusion path for this element")
obj.addProperty("App::PropertyLength","Length","Base",
str(translate("Arch","The length of this element, if not based on a profile")))
obj.addProperty("App::PropertyLength","Width","Base",
@ -313,7 +315,7 @@ class _Structure(ArchComponent.Component):
def onChanged(self,obj,prop):
self.hideSubobjects(obj,prop)
if prop in ["Base","Length","Width","Height","Normal","Additions","Subtractions","Axes"]:
if prop in ["Base","Tool","Length","Width","Height","Normal","Additions","Subtractions","Axes"]:
self.createGeometry(obj)
def getAxisPoints(self,obj):
@ -357,21 +359,30 @@ class _Structure(ArchComponent.Component):
base = None
if obj.Base:
if obj.Base.isDerivedFrom("Part::Feature"):
if obj.Normal == Vector(0,0,0):
p = FreeCAD.Placement(obj.Base.Placement)
normal = p.Rotation.multVec(Vector(0,0,1))
else:
normal = Vector(obj.Normal)
normal = normal.multiply(height)
base = obj.Base.Shape.copy()
if base.Solids:
pass
elif base.Faces:
base = base.extrude(normal)
elif (len(base.Wires) == 1):
if base.Wires[0].isClosed():
base = Part.Face(base.Wires[0])
if hasattr(obj,"Tool"):
if obj.Tool:
try:
base = obj.Tool.Shape.copy().makePipe(obj.Base.Shape.copy())
except:
FreeCAD.Console.PrintError(str(translate("Arch","Error: The base shape couldn't be extruded along this tool object")))
return
if not base:
if obj.Normal == Vector(0,0,0):
p = FreeCAD.Placement(obj.Base.Placement)
normal = p.Rotation.multVec(Vector(0,0,1))
else:
normal = Vector(obj.Normal)
normal = normal.multiply(height)
base = obj.Base.Shape.copy()
if base.Solids:
pass
elif base.Faces:
base = base.extrude(normal)
elif (len(base.Wires) == 1):
if base.Wires[0].isClosed():
base = Part.Face(base.Wires[0])
base = base.extrude(normal)
elif obj.Base.isDerivedFrom("Mesh::Feature"):
if obj.Base.Mesh.isSolid():
if obj.Base.Mesh.countComponents() == 1:
@ -428,7 +439,8 @@ class _Structure(ArchComponent.Component):
obj.Shape = base
if not DraftGeomUtils.isNull(pl):
obj.Placement = pl
class _ViewProviderStructure(ArchComponent.ViewProviderComponent):
"A View Provider for the Structure object"
@ -438,7 +450,8 @@ class _ViewProviderStructure(ArchComponent.ViewProviderComponent):
def getIcon(self):
import Arch_rc
return ":/icons/Arch_Structure_Tree.svg"
class _Profile(Draft._DraftObject):
"A parametric beam profile object"

View File

@ -177,6 +177,19 @@ def geomType(edge):
return "Unknown"
except:
return "Unknown"
def isValidPath(shape):
"isValidPath(shape): returns True if the shape can be used as an extrusion path"
if shape.Faces:
return False
if len(shape.Wires) > 1:
return False
if shape.Wires:
if shape.Wires[0].isClosed():
return False
if shape.isClosed():
return False
return True
# edge functions *****************************************************************