Arch: Enabled multilayer walls

This commit is contained in:
Yorik van Havre 2013-10-11 15:11:41 -03:00
parent 7d2b885caf
commit fe06740133
3 changed files with 47 additions and 10 deletions

View File

@ -300,6 +300,21 @@ class Component:
def onChanged(self,obj,prop): def onChanged(self,obj,prop):
pass pass
def getSiblings(self,obj):
"returns a list of objects with the same base as this object"
if not hasattr(obj,"Base"):
return []
if not obj.Base:
return []
siblings = []
for o in obj.Base.InList:
if hasattr(o,"Base"):
if o.Base:
if o.Base.Name == obj.Base.Name:
if o.Name != obj.Name:
siblings.append(o)
return siblings
def hideSubobjects(self,obj,prop): def hideSubobjects(self,obj,prop):
"Hides subobjects when a subobject lists change" "Hides subobjects when a subobject lists change"
if prop in ["Additions","Subtractions"]: if prop in ["Additions","Subtractions"]:

View File

@ -35,6 +35,7 @@ def makeWall(baseobj=None,length=None,width=None,height=None,align="Center",face
given object, which can be a sketch, a draft object, a face or a solid, or no object at given object, which can be a sketch, a draft object, a face or a solid, or no object at
all, then you must provide length, width and height. Align can be "Center","Left" or "Right", all, then you must provide length, width and height. Align can be "Center","Left" or "Right",
face can be an index number of a face in the base object to base the wall on.''' face can be an index number of a face in the base object to base the wall on.'''
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
_Wall(obj) _Wall(obj)
_ViewProviderWall(obj.ViewObject) _ViewProviderWall(obj.ViewObject)
@ -46,8 +47,12 @@ def makeWall(baseobj=None,length=None,width=None,height=None,align="Center",face
obj.Length = length obj.Length = length
if width: if width:
obj.Width = width obj.Width = width
else:
width = p.GetFloat("WallWidth",200)
if height: if height:
obj.Height = height obj.Height = height
else:
p.GetFloat("WallHeight",3000)
obj.Align = align obj.Align = align
if obj.Base: if obj.Base:
if Draft.getType(obj.Base) != "Space": if Draft.getType(obj.Base) != "Space":
@ -380,6 +385,8 @@ class _Wall(ArchComponent.Component):
str(translate("Arch","If True, if this wall is based on a face, it will use its border wire as trace, and disconsider the face."))) str(translate("Arch","If True, if this wall is based on a face, it will use its border wire as trace, and disconsider the face.")))
obj.addProperty("App::PropertyInteger","Face","Arch", obj.addProperty("App::PropertyInteger","Face","Arch",
str(translate("Arch","The face number of the base object used to build this wall"))) str(translate("Arch","The face number of the base object used to build this wall")))
obj.addProperty("App::PropertyLength","Offset","Arch",
str(translate("Arch","The offset between this wall and its baseline (only for left and right alignments)")))
obj.Align = ['Left','Right','Center'] obj.Align = ['Left','Right','Center']
obj.ForceWire = False obj.ForceWire = False
self.Type = "Wall" self.Type = "Wall"
@ -447,12 +454,20 @@ class _Wall(ArchComponent.Component):
dvec.normalize() dvec.normalize()
if obj.Align == "Left": if obj.Align == "Left":
dvec.multiply(width) dvec.multiply(width)
if hasattr(obj,"Offset"):
if obj.Offset:
dvec2 = DraftVecUtils.scaleTo(dvec,obj.Offset)
wire = DraftGeomUtils.offsetWire(wire,dvec2)
w2 = DraftGeomUtils.offsetWire(wire,dvec) w2 = DraftGeomUtils.offsetWire(wire,dvec)
w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges)) w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges))
sh = DraftGeomUtils.bind(w1,w2) sh = DraftGeomUtils.bind(w1,w2)
elif obj.Align == "Right": elif obj.Align == "Right":
dvec.multiply(width) dvec.multiply(width)
dvec = dvec.negative() dvec = dvec.negative()
if hasattr(obj,"Offset"):
if obj.Offset:
dvec2 = DraftVecUtils.scaleTo(dvec,obj.Offset)
wire = DraftGeomUtils.offsetWire(wire,dvec2)
w2 = DraftGeomUtils.offsetWire(wire,dvec) w2 = DraftGeomUtils.offsetWire(wire,dvec)
w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges)) w1 = Part.Wire(DraftGeomUtils.sortEdges(wire.Edges))
sh = DraftGeomUtils.bind(w1,w2) sh = DraftGeomUtils.bind(w1,w2)

View File

@ -89,20 +89,26 @@ class _CommandWindow:
FreeCADGui.Selection.addObserver(FreeCAD.ArchObserver) FreeCADGui.Selection.addObserver(FreeCAD.ArchObserver)
else: else:
FreeCADGui.Control.closeDialog() FreeCADGui.Control.closeDialog()
FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Window"))) host = None
FreeCADGui.doCommand("import Arch")
FreeCADGui.doCommand("Arch.makeWindow(FreeCAD.ActiveDocument."+obj.Name+")")
if hasattr(obj,"Support"): if hasattr(obj,"Support"):
if obj.Support: if obj.Support:
if isinstance(obj.Support,tuple): if isinstance(obj.Support,tuple):
s = obj.Support[0] host = obj.Support[0]
else: else:
s = obj.Support host = obj.Support
w = FreeCAD.ActiveDocument.Objects[-1] # last created object obj.Support = None # remove
FreeCADGui.doCommand("Arch.removeComponents(FreeCAD.ActiveDocument."+w.Name+",host=FreeCAD.ActiveDocument."+s.Name+")")
elif Draft.isClone(obj,"Window"): elif Draft.isClone(obj,"Window"):
if obj.Objects[0].Inlist: if obj.Objects[0].Inlist:
FreeCADGui.doCommand("Arch.removeComponents(FreeCAD.ActiveDocument."+obj.Name+",host=FreeCAD.ActiveDocument."+obj.Objects[0].Inlist[0].Name+")") host = obj.Objects[0].Inlist[0]
FreeCAD.ActiveDocument.openTransaction(str(translate("Arch","Create Window")))
FreeCADGui.doCommand("import Arch")
FreeCADGui.doCommand("win = Arch.makeWindow(FreeCAD.ActiveDocument."+obj.Name+")")
if host:
FreeCADGui.doCommand("Arch.removeComponents(win,host=FreeCAD.ActiveDocument."+host.Name+")")
siblings = host.Proxy.getSiblings(host)
for sibling in siblings:
FreeCADGui.doCommand("Arch.removeComponents(win,host=FreeCAD.ActiveDocument."+sibling.Name+")")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
else: else:
@ -187,6 +193,7 @@ class _Window(ArchComponent.Component):
if not base.isNull(): if not base.isNull():
obj.Shape = base obj.Shape = base
def getSubVolume(self,obj,plac=None): def getSubVolume(self,obj,plac=None):
"returns a subvolume for cutting in a base object" "returns a subvolume for cutting in a base object"