Arch: Fix Site, Building, Floor objects creation

-New param : GetBool("FreeLinking",False), unavailable in pref see
parameters
-by default :
allow create Site on Building only
deny create Building on Site or Building
deny create Floor on Site, Building,Floor
-option:
allow create and linking what you want (until non-DAG)
This commit is contained in:
Jonathan Wiedemann 2016-07-08 13:12:29 +02:00 committed by Yorik van Havre
parent 1f3c2ef2c8
commit 7425394df9
3 changed files with 96 additions and 56 deletions

View File

@ -201,30 +201,44 @@ class _CommandBuilding:
def Activated(self): def Activated(self):
sel = FreeCADGui.Selection.getSelection() sel = FreeCADGui.Selection.getSelection()
ok = False p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
if (len(sel) == 1): link = p.GetBool("FreeLinking",False)
if Draft.getType(sel[0]) in ["Cell","Site","Floor"]: buildingobj = []
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Type conversion")) warning = False
FreeCADGui.addModule("Arch") for obj in sel :
FreeCADGui.doCommand("obj = Arch.makeBuilding()") if not Draft.getType(obj) in ["Site", "Building"] :
FreeCADGui.doCommand("Arch.copyProperties(FreeCAD.ActiveDocument."+sel[0].Name+",obj)") buildingobj.append(obj)
FreeCADGui.doCommand('FreeCAD.ActiveDocument.removeObject("'+sel[0].Name+'")') else :
FreeCAD.ActiveDocument.commitTransaction() if link == True :
ok = True buildingobj.append(obj)
if not ok: else:
FreeCAD.ActiveDocument.openTransaction(translate("Arch"," Create Building")) warning = True
ss = "[" if warning :
for o in sel: message = "You can put anything but Site and Building object in a Building object.\n\
if len(ss) > 1: Building object are not allowed to accept Site and Building object.\n\
ss += "," Site and Building objects will be removed from the selection.\n\
ss += "FreeCAD.ActiveDocument."+o.Name You can change that in the preferences.\n"
self.printMessage( message )
if sel and len(buildingobj) == 0:
message = "There is no valid object in the selection.\n\
Building creation aborted.\n"
self.printMessage( message )
else :
ss = "[ "
for o in buildingobj:
ss += "FreeCAD.ActiveDocument." + o.Name + ", "
ss += "]" ss += "]"
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Floor")) FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Building"))
FreeCADGui.addModule("Arch") FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makeBuilding("+ss+")") FreeCADGui.doCommand("Arch.makeBuilding("+ss+")")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
def printMessage(self, message):
FreeCAD.Console.PrintMessage(translate("Arch", message))
if FreeCAD.GuiUp :
reply = QtGui.QMessageBox.information(None,"", message)
class _Building(ArchFloor._Floor): class _Building(ArchFloor._Floor):
"The Building object" "The Building object"
def __init__(self,obj): def __init__(self,obj):

View File

@ -59,28 +59,43 @@ class _CommandFloor:
def Activated(self): def Activated(self):
sel = FreeCADGui.Selection.getSelection() sel = FreeCADGui.Selection.getSelection()
ok = False p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
if (len(sel) == 1): link = p.GetBool("FreeLinking",False)
if Draft.getType(sel[0]) in ["Cell","Site","Building"]: floorobj = []
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Type conversion")) warning = False
FreeCADGui.addModule("Arch") for obj in sel :
FreeCADGui.doCommand("obj = Arch.makeFloor()") if not Draft.getType(obj) in ["Site", "Building","Floor"] :
FreeCADGui.doCommand("Arch.copyProperties(FreeCAD.ActiveDocument."+sel[0].Name+",obj)") floorobj.append(obj)
FreeCADGui.doCommand('FreeCAD.ActiveDocument.removeObject("'+sel[0].Name+'")') else :
FreeCAD.ActiveDocument.commitTransaction() if link == True :
ok = True floorobj.append(obj)
if not ok: else:
ss = "[" warning = True
for o in sel: if warning :
if len(ss) > 1: message = "You can put anything but Site, Building, Floor object in a Floor object.\n\
ss += "," Floor object are not allowed to accept Site, Building or Floor object.\n\
ss += "FreeCAD.ActiveDocument."+o.Name Site, Building and Floor objects will be removed from the selection.\n\
You can change that in the preferences.\n"
self.printMessage( message )
if sel and len(floorobj) == 0:
message = "There is no valid object in the selection.\n\
Floor creation aborted.\n"
self.printMessage( message )
else :
ss = "[ "
for o in floorobj:
ss += "FreeCAD.ActiveDocument." + o.Name + ", "
ss += "]" ss += "]"
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Floor")) FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Floor"))
FreeCADGui.addModule("Arch") FreeCADGui.addModule("Arch")
FreeCADGui.doCommand("Arch.makeFloor("+ss+")") FreeCADGui.doCommand("Arch.makeFloor("+ss+")")
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
def printMessage(self, message):
FreeCAD.Console.PrintMessage(translate("Arch", message))
if FreeCAD.GuiUp :
reply = QtGui.QMessageBox.information(None,"", message)
class _Floor: class _Floor:
"The Floor object" "The Floor object"

View File

@ -61,26 +61,32 @@ class _CommandSite:
def Activated(self): def Activated(self):
sel = FreeCADGui.Selection.getSelection() sel = FreeCADGui.Selection.getSelection()
ok = False p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
if (len(sel) == 1): link = p.GetBool("FreeLinking",False)
if Draft.getType(sel[0]) in ["Cell","Building","Floor"]: siteobj = []
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Type conversion")) warning = False
FreeCADGui.addModule("Arch") for obj in sel :
FreeCADGui.doCommand("obj = Arch.makeSite()") if Draft.getType(obj) == "Building":
FreeCADGui.doCommand("Arch.copyProperties(FreeCAD.ActiveDocument."+sel[0].Name+",obj)") siteobj.append(obj)
FreeCADGui.doCommand('FreeCAD.ActiveDocument.removeObject("'+sel[0].Name+'")') else :
if link == True :
nobj = makeSite() siteobj.append(obj)
ArchCommands.copyProperties(sel[0],nobj) else:
FreeCAD.ActiveDocument.removeObject(sel[0].Name) warning = True
FreeCAD.ActiveDocument.commitTransaction() if warning :
ok = True message = "Please select only Building objects or nothing!\n\
if not ok: Site are not allowed to accept other object than Building.\n\
ss = "[" Other objects will be removed from the selection.\n\
for o in sel: You can change that in the preferences."
if len(ss) > 1: self.printMessage( message )
ss += "," if sel and len(siteobj) == 0:
ss += "FreeCAD.ActiveDocument."+o.Name message = "There is no valid object in the selection.\n\
Site creation aborted."
self.printMessage( message )
else :
ss = "[ "
for o in siteobj:
ss += "FreeCAD.ActiveDocument." + o.Name + ", "
ss += "]" ss += "]"
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Site")) FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Site"))
FreeCADGui.addModule("Arch") FreeCADGui.addModule("Arch")
@ -88,6 +94,11 @@ class _CommandSite:
FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
def printMessage(self, message):
FreeCAD.Console.PrintMessage(translate("Arch", message))
if FreeCAD.GuiUp :
reply = QtGui.QMessageBox.information(None,"", message)
class _Site(ArchFloor._Floor): class _Site(ArchFloor._Floor):
"The Site object" "The Site object"
def __init__(self,obj): def __init__(self,obj):