diff --git a/src/Mod/Arch/Building.py b/src/Mod/Arch/Building.py index 01462f4d5..d04d99af9 100644 --- a/src/Mod/Arch/Building.py +++ b/src/Mod/Arch/Building.py @@ -21,20 +21,21 @@ #* * #*************************************************************************** -import Cell,FreeCAD,FreeCADGui +import Cell,FreeCAD,FreeCADGui,Draft,Commands from PyQt4 import QtCore __title__="FreeCAD Building" __author__ = "Yorik van Havre" __url__ = "http://free-cad.sourceforge.net" -def makeBuilding(objectslist,join=False,name="Building"): +def makeBuilding(objectslist=None,join=False,name="Building"): '''makeBuilding(objectslist,[joinmode]): creates a building including the objects from the given list. If joinmode is True, components will be joined.''' obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) _Building(obj) _ViewProviderBuilding(obj.ViewObject) - obj.Components = objectslist + if objectslist: + obj.Components = objectslist for comp in obj.Components: comp.ViewObject.hide() obj.JoinMode = join @@ -49,9 +50,25 @@ class _CommandBuilding: 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Building","Creates a building object including selected objects.")} def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Building") - makeBuilding(FreeCADGui.Selection.getSelection()) - FreeCAD.ActiveDocument.commitTransaction() + sel = FreeCADGui.Selection.getSelection() + transmode = True + if not sel: + transmode = False + for obj in sel: + if not (Draft.getType(obj) in ["Cell","Site","Floor"]): + transmode = False + if transmode: + FreeCAD.ActiveDocument.openTransaction("Type conversion") + for obj in sel: + nobj = makeBuilding() + Commands.copyProperties(obj,nobj) + FreeCAD.ActiveDocument.removeObject(obj.Name) + FreeCAD.ActiveDocument.commitTransaction() + else: + FreeCAD.ActiveDocument.openTransaction("Building") + makeBuilding(sel) + FreeCAD.ActiveDocument.commitTransaction() + FreeCAD.ActiveDocument.recompute() class _Building(Cell._Cell): "The Building object" diff --git a/src/Mod/Arch/Cell.py b/src/Mod/Arch/Cell.py index 84383a05b..7cdeaa5bd 100644 --- a/src/Mod/Arch/Cell.py +++ b/src/Mod/Arch/Cell.py @@ -21,7 +21,7 @@ #* * #*************************************************************************** -import FreeCAD,FreeCADGui,Part,Draft,Component +import FreeCAD,FreeCADGui,Part,Draft,Component,Commands from FreeCAD import Vector from PyQt4 import QtCore @@ -29,14 +29,15 @@ __title__="FreeCAD Cell" __author__ = "Yorik van Havre" __url__ = "http://free-cad.sourceforge.net" -def makeCell(objectslist,join=True,name="Cell"): - '''makeCell(objectslist,[joinmode]): creates a cell including the +def makeCell(objectslist=None,join=True,name="Cell"): + '''makeCell([objectslist],[joinmode]): creates a cell including the objects from the given list. If joinmode is False, contents will not be joined.''' obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) _Cell(obj) _ViewProviderCell(obj.ViewObject) - obj.Components = objectslist + if objectslist: + obj.Components = objectslist for comp in obj.Components: comp.ViewObject.hide() obj.JoinMode = join @@ -51,9 +52,25 @@ class _CommandCell: 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Cell","Creates a cell object including selected objects")} def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Cell") - makeCell(FreeCADGui.Selection.getSelection()) - FreeCAD.ActiveDocument.commitTransaction() + sel = FreeCADGui.Selection.getSelection() + transmode = True + if not sel: + transmode = False + for obj in sel: + if not (Draft.getType(obj) in ["Floor","Site","Building"]): + transmode = False + if transmode: + FreeCAD.ActiveDocument.openTransaction("Type conversion") + for obj in sel: + nobj = makeCell() + Commands.copyProperties(obj,nobj) + FreeCAD.ActiveDocument.removeObject(obj.Name) + FreeCAD.ActiveDocument.commitTransaction() + else: + FreeCAD.ActiveDocument.openTransaction("Cell") + makeCell(sel) + FreeCAD.ActiveDocument.commitTransaction() + FreeCAD.ActiveDocument.recompute() class _Cell(Component.Component): "The Cell object" diff --git a/src/Mod/Arch/Commands.py b/src/Mod/Arch/Commands.py index 0371c6151..b0dccb698 100644 --- a/src/Mod/Arch/Commands.py +++ b/src/Mod/Arch/Commands.py @@ -102,6 +102,19 @@ def removeComponents(objectsList,host=None): a.remove(o) h.Objects = a +def copyProperties(obj1,obj2): + '''copyProperties(obj1,obj2): Copies properties values from obj1 to obj2, + when that property exists in both objects''' + for prop in obj1.PropertiesList: + if prop in obj2.PropertiesList: + if not prop in ["Proxy","Shape"]: + setattr(obj2,prop,getattr(obj1,prop)) + if obj1.ViewObject and obj2.ViewObject: + for prop in obj1.ViewObject.PropertiesList: + if prop in obj2.ViewObject.PropertiesList: + if not prop in ["Proxy","Shape"]: + setattr(obj2.ViewObject,prop,getattr(obj1.ViewObject,prop)) + def splitMesh(obj,mark=True): '''splitMesh(object,[mark]): splits the given mesh object into separated components. If mark is False, nothing else is done. If True (default), non-manifold components diff --git a/src/Mod/Arch/Floor.py b/src/Mod/Arch/Floor.py index 9b2b4c327..e0217b1f3 100644 --- a/src/Mod/Arch/Floor.py +++ b/src/Mod/Arch/Floor.py @@ -21,21 +21,22 @@ #* * #*************************************************************************** -import Cell,FreeCAD,FreeCADGui +import Cell,FreeCAD,FreeCADGui,Draft,Commands from PyQt4 import QtCore __title__="FreeCAD Arch Floor" __author__ = "Yorik van Havre" __url__ = "http://free-cad.sourceforge.net" -def makeFloor(objectslist,join=True,name="Floor"): +def makeFloor(objectslist=None,join=True,name="Floor"): '''makeFloor(objectslist,[joinmode]): creates a floor including the objects from the given list. If joinmode is False, components will not be joined.''' obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) _Floor(obj) _ViewProviderFloor(obj.ViewObject) - obj.Components = objectslist + if objectslist: + obj.Components = objectslist for comp in obj.Components: comp.ViewObject.hide() obj.JoinMode = join @@ -50,10 +51,26 @@ class _CommandFloor: 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Floor","Creates a floor object including selected objects")} def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Floor") - makeFloor(FreeCADGui.Selection.getSelection()) - FreeCAD.ActiveDocument.commitTransaction() - + sel = FreeCADGui.Selection.getSelection() + transmode = True + if not sel: + transmode = False + for obj in sel: + if not (Draft.getType(obj) in ["Cell","Site","Building"]): + transmode = False + if transmode: + FreeCAD.ActiveDocument.openTransaction("Type conversion") + for obj in sel: + nobj = makeFloor() + Commands.copyProperties(obj,nobj) + FreeCAD.ActiveDocument.removeObject(obj.Name) + FreeCAD.ActiveDocument.commitTransaction() + else: + FreeCAD.ActiveDocument.openTransaction("Floor") + makeFloor(sel) + FreeCAD.ActiveDocument.commitTransaction() + FreeCAD.ActiveDocument.recompute() + class _Floor(Cell._Cell): "The Cell object" def __init__(self,obj): diff --git a/src/Mod/Arch/Site.py b/src/Mod/Arch/Site.py index b5eb3f59b..5cd59cf52 100644 --- a/src/Mod/Arch/Site.py +++ b/src/Mod/Arch/Site.py @@ -21,20 +21,21 @@ #* * #*************************************************************************** -import Cell,FreeCAD,FreeCADGui +import Cell,FreeCAD,FreeCADGui,Draft,Commands from PyQt4 import QtCore __title__="FreeCAD Site" __author__ = "Yorik van Havre" __url__ = "http://free-cad.sourceforge.net" -def makeSite(objectslist,name="Site"): +def makeSite(objectslist=None,name="Site"): '''makeBuilding(objectslist): creates a site including the objects from the given list.''' obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) _Site(obj) _ViewProviderSite(obj.ViewObject) - obj.Components = objectslist + if objectslist: + obj.Components = objectslist obj.JoinMode = False return obj @@ -47,9 +48,25 @@ class _CommandSite: 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Site","Creates a site object including selected objects.")} def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Site") - makeSite(FreeCADGui.Selection.getSelection()) - FreeCAD.ActiveDocument.commitTransaction() + sel = FreeCADGui.Selection.getSelection() + transmode = True + if not sel: + transmode = False + for obj in sel: + if not (Draft.getType(obj) in ["Cell","Building","Floor"]): + transmode = False + if transmode: + FreeCAD.ActiveDocument.openTransaction("Type conversion") + for obj in sel: + nobj = makeSite() + Commands.copyProperties(obj,nobj) + FreeCAD.ActiveDocument.removeObject(obj.Name) + FreeCAD.ActiveDocument.commitTransaction() + else: + FreeCAD.ActiveDocument.openTransaction("Site") + makeSite(sel) + FreeCAD.ActiveDocument.commitTransaction() + FreeCAD.ActiveDocument.recompute() class _Site(Cell._Cell): "The Site object"