Arch: New behaviour against circular dependency can now be switched off in preferences

This commit is contained in:
Yorik van Havre 2016-01-29 12:29:03 -02:00
parent 3702820f00
commit 645a83ad32
4 changed files with 69 additions and 28 deletions

View File

@ -140,7 +140,7 @@ def removeComponents(objectsList,host=None):
for o in objectsList:
if not o in s:
s.append(o)
#fixDAG(o)
fixDAG(o)
if FreeCAD.GuiUp:
if not Draft.getType(o) in ["Window","Roof"]:
o.ViewObject.hide()
@ -202,17 +202,19 @@ def makeComponent(baseobj=None,name="Component",delete=False):
def fixDAG(obj):
'''fixDAG(object): Fixes non-DAG problems in windows and rebars
by removing supports and external geometry from underlying sketches'''
if Draft.getType(obj) in ["Window","Rebar"]:
if obj.Base:
if hasattr(obj.Base,"Support"):
if obj.Base.Support:
FreeCAD.Console.PrintMessage(translate("Arch","removing sketch support to avoid cross-referencing"))
obj.Base.Support = None
if hasattr(obj.Base,"ExternalGeometry"):
if obj.Base.ExternalGeometry:
for g in obj.Base.ExternalGeometry:
obj.Base.delExternal(0)
FreeCAD.Console.PrintMessage(translate("Arch","removing sketch external reference to avoid cross-referencing"))
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
if p.GetBool("archRemoveExternal",False):
if Draft.getType(obj) in ["Window","Rebar"]:
if obj.Base:
if hasattr(obj.Base,"Support"):
if obj.Base.Support:
FreeCAD.Console.PrintMessage(translate("Arch","removing sketch support to avoid cross-referencing"))
obj.Base.Support = None
if hasattr(obj.Base,"ExternalGeometry"):
if obj.Base.ExternalGeometry:
for g in obj.Base.ExternalGeometry:
obj.Base.delExternal(0)
FreeCAD.Console.PrintMessage(translate("Arch","removing sketch external reference to avoid cross-referencing"))
def copyProperties(obj1,obj2):
'''copyProperties(obj1,obj2): Copies properties values from obj1 to obj2,

View File

@ -56,11 +56,17 @@ def makeRebar(baseobj=None,sketch=None,diameter=None,amount=1,offset=None,name="
obj.Base = sketch
if FreeCAD.GuiUp:
sketch.ViewObject.hide()
import Arch
host = getattr(Arch,"make"+Draft.getType(baseobj))(baseobj)
a = host.Armatures
a.append(obj)
host.Armatures = a
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
if p.GetBool("archRemoveExternal",False):
a = baseobj.Armatures
a.append(obj)
baseobj.Armatures = a
else:
import Arch
host = getattr(Arch,"make"+Draft.getType(baseobj))(baseobj)
a = host.Armatures
a.append(obj)
host.Armatures = a
if diameter:
obj.Diameter = diameter
else:
@ -72,7 +78,7 @@ def makeRebar(baseobj=None,sketch=None,diameter=None,amount=1,offset=None,name="
else:
obj.OffsetStart = p.GetFloat("RebarOffset",30)
obj.OffsetEnd = p.GetFloat("RebarOffset",30)
#ArchCommands.fixDAG(obj)
ArchCommands.fixDAG(obj)
return obj

View File

@ -391,6 +391,7 @@ class _CommandWindow:
self.Thickness = p.GetFloat("WindowThickness",50)
self.Width = p.GetFloat("WindowWidth",1000)
self.Height = p.GetFloat("WindowHeight",1000)
self.RemoveExternal = p.GetBool("archRemoveExternal",False)
self.Preset = 0
self.Sill = 0
self.baseFace = None
@ -431,13 +432,19 @@ class _CommandWindow:
FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("win = Arch.makeWindow(FreeCAD.ActiveDocument."+obj.Name+")")
if host:
# make a new object to avoid circular references
FreeCADGui.doCommand("host=Arch.make"+Draft.getType(host)+"(FreeCAD.ActiveDocument."+host.Name+")")
FreeCADGui.doCommand("Arch.removeComponents(win,host)")
if self.RemoveExternal:
FreeCADGui.doCommand("Arch.removeComponents(win,host=FreeCAD.ActiveDocument."+host.Name+")")
else:
# make a new object to avoid circular references
FreeCADGui.doCommand("host=Arch.make"+Draft.getType(host)+"(FreeCAD.ActiveDocument."+host.Name+")")
FreeCADGui.doCommand("Arch.removeComponents(win,host)")
siblings = host.Proxy.getSiblings(host)
for sibling in siblings:
FreeCADGui.doCommand("host=Arch.make"+Draft.getType(sibling)+"(FreeCAD.ActiveDocument."+sibling.Name+")")
FreeCADGui.doCommand("Arch.removeComponents(win,host)")
if self.RemoveExternal:
FreeCADGui.doCommand("Arch.removeComponents(win,host=FreeCAD.ActiveDocument."+sibling.Name+")")
else:
FreeCADGui.doCommand("host=Arch.make"+Draft.getType(sibling)+"(FreeCAD.ActiveDocument."+sibling.Name+")")
FreeCADGui.doCommand("Arch.removeComponents(win,host)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
return
@ -477,12 +484,18 @@ class _CommandWindow:
FreeCADGui.doCommand("win = Arch.makeWindowPreset(\"" + WindowPresets[self.Preset] + "\"," + wp + "placement=pl)")
if obj:
if Draft.getType(obj) in AllowedHosts:
FreeCADGui.doCommand("host=Arch.make"+Draft.getType(obj)+"(FreeCAD.ActiveDocument."+obj.Name+")")
FreeCADGui.doCommand("Arch.removeComponents(win,host)")
if self.RemoveExternal:
FreeCADGui.doCommand("Arch.removeComponents(win,host=FreeCAD.ActiveDocument."+obj.Name+")")
else:
FreeCADGui.doCommand("host=Arch.make"+Draft.getType(obj)+"(FreeCAD.ActiveDocument."+obj.Name+")")
FreeCADGui.doCommand("Arch.removeComponents(win,host)")
siblings = obj.Proxy.getSiblings(obj)
for sibling in siblings:
FreeCADGui.doCommand("host=Arch.make"+Draft.getType(sibling)+"(FreeCAD.ActiveDocument."+sibling.Name+")")
FreeCADGui.doCommand("Arch.removeComponents(win,host)")
if self.RemoveExternal:
FreeCADGui.doCommand("Arch.removeComponents(win,host=FreeCAD.ActiveDocument."+sibling.Name+")")
else:
FreeCADGui.doCommand("host=Arch.make"+Draft.getType(sibling)+"(FreeCAD.ActiveDocument."+sibling.Name+")")
FreeCADGui.doCommand("Arch.removeComponents(win,host)")
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
return

View File

@ -52,7 +52,7 @@
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Walls drawing</string>
<string>Object creation</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
@ -95,6 +95,26 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox">
<property name="toolTip">
<string>Two possible strategies to avoid circular dependencies: Create one more object (unchecked) or remove external geometry of base sketch (checked)</string>
</property>
<property name="text">
<string>Remove external geometry of base sketches when needed</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>archRemoveExternal</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>