diff --git a/src/Mod/Arch/ArchBuilding.py b/src/Mod/Arch/ArchBuilding.py index 8a88788a7..59e731259 100644 --- a/src/Mod/Arch/ArchBuilding.py +++ b/src/Mod/Arch/ArchBuilding.py @@ -201,30 +201,44 @@ class _CommandBuilding: def Activated(self): sel = FreeCADGui.Selection.getSelection() - ok = False - if (len(sel) == 1): - if Draft.getType(sel[0]) in ["Cell","Site","Floor"]: - FreeCAD.ActiveDocument.openTransaction(translate("Arch","Type conversion")) - FreeCADGui.addModule("Arch") - FreeCADGui.doCommand("obj = Arch.makeBuilding()") - FreeCADGui.doCommand("Arch.copyProperties(FreeCAD.ActiveDocument."+sel[0].Name+",obj)") - FreeCADGui.doCommand('FreeCAD.ActiveDocument.removeObject("'+sel[0].Name+'")') - FreeCAD.ActiveDocument.commitTransaction() - ok = True - if not ok: - FreeCAD.ActiveDocument.openTransaction(translate("Arch"," Create Building")) - ss = "[" - for o in sel: - if len(ss) > 1: - ss += "," - ss += "FreeCAD.ActiveDocument."+o.Name + p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") + link = p.GetBool("FreeLinking",False) + buildingobj = [] + warning = False + for obj in sel : + if not Draft.getType(obj) in ["Site", "Building"] : + buildingobj.append(obj) + else : + if link == True : + buildingobj.append(obj) + else: + warning = True + if warning : + message = "You can put anything but Site and Building object in a Building object.\n\ +Building object are not allowed to accept Site and Building object.\n\ +Site and Building objects will be removed from the selection.\n\ +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 += "]" - FreeCAD.ActiveDocument.openTransaction(translate("Arch","Floor")) + FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Building")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand("Arch.makeBuilding("+ss+")") FreeCAD.ActiveDocument.commitTransaction() 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): "The Building object" def __init__(self,obj): diff --git a/src/Mod/Arch/ArchFloor.py b/src/Mod/Arch/ArchFloor.py index 51059db71..b55c148d5 100644 --- a/src/Mod/Arch/ArchFloor.py +++ b/src/Mod/Arch/ArchFloor.py @@ -59,28 +59,43 @@ class _CommandFloor: def Activated(self): sel = FreeCADGui.Selection.getSelection() - ok = False - if (len(sel) == 1): - if Draft.getType(sel[0]) in ["Cell","Site","Building"]: - FreeCAD.ActiveDocument.openTransaction(translate("Arch","Type conversion")) - FreeCADGui.addModule("Arch") - FreeCADGui.doCommand("obj = Arch.makeFloor()") - FreeCADGui.doCommand("Arch.copyProperties(FreeCAD.ActiveDocument."+sel[0].Name+",obj)") - FreeCADGui.doCommand('FreeCAD.ActiveDocument.removeObject("'+sel[0].Name+'")') - FreeCAD.ActiveDocument.commitTransaction() - ok = True - if not ok: - ss = "[" - for o in sel: - if len(ss) > 1: - ss += "," - ss += "FreeCAD.ActiveDocument."+o.Name + p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") + link = p.GetBool("FreeLinking",False) + floorobj = [] + warning = False + for obj in sel : + if not Draft.getType(obj) in ["Site", "Building","Floor"] : + floorobj.append(obj) + else : + if link == True : + floorobj.append(obj) + else: + warning = True + if warning : + message = "You can put anything but Site, Building, Floor object in a Floor object.\n\ +Floor object are not allowed to accept Site, Building or Floor object.\n\ +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 += "]" - FreeCAD.ActiveDocument.openTransaction(translate("Arch","Floor")) + FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Floor")) FreeCADGui.addModule("Arch") FreeCADGui.doCommand("Arch.makeFloor("+ss+")") 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: "The Floor object" diff --git a/src/Mod/Arch/ArchSite.py b/src/Mod/Arch/ArchSite.py index da316d385..e6a673732 100644 --- a/src/Mod/Arch/ArchSite.py +++ b/src/Mod/Arch/ArchSite.py @@ -61,26 +61,32 @@ class _CommandSite: def Activated(self): sel = FreeCADGui.Selection.getSelection() - ok = False - if (len(sel) == 1): - if Draft.getType(sel[0]) in ["Cell","Building","Floor"]: - FreeCAD.ActiveDocument.openTransaction(translate("Arch","Type conversion")) - FreeCADGui.addModule("Arch") - FreeCADGui.doCommand("obj = Arch.makeSite()") - FreeCADGui.doCommand("Arch.copyProperties(FreeCAD.ActiveDocument."+sel[0].Name+",obj)") - FreeCADGui.doCommand('FreeCAD.ActiveDocument.removeObject("'+sel[0].Name+'")') - - nobj = makeSite() - ArchCommands.copyProperties(sel[0],nobj) - FreeCAD.ActiveDocument.removeObject(sel[0].Name) - FreeCAD.ActiveDocument.commitTransaction() - ok = True - if not ok: - ss = "[" - for o in sel: - if len(ss) > 1: - ss += "," - ss += "FreeCAD.ActiveDocument."+o.Name + p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") + link = p.GetBool("FreeLinking",False) + siteobj = [] + warning = False + for obj in sel : + if Draft.getType(obj) == "Building": + siteobj.append(obj) + else : + if link == True : + siteobj.append(obj) + else: + warning = True + if warning : + message = "Please select only Building objects or nothing!\n\ +Site are not allowed to accept other object than Building.\n\ +Other objects will be removed from the selection.\n\ +You can change that in the preferences." + self.printMessage( message ) + if sel and len(siteobj) == 0: + 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 += "]" FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Site")) FreeCADGui.addModule("Arch") @@ -88,6 +94,11 @@ class _CommandSite: FreeCAD.ActiveDocument.commitTransaction() 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): "The Site object" def __init__(self,obj):