diff --git a/src/Mod/Arch/Building.py b/src/Mod/Arch/Building.py index d04d99af9d..adc2f4b335 100644 --- a/src/Mod/Arch/Building.py +++ b/src/Mod/Arch/Building.py @@ -51,25 +51,21 @@ class _CommandBuilding: def Activated(self): 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: + ok = False + if (len(sel) == 1): + if Draft.getType(sel[0]) in ["Cell","Site","Floor"]: + FreeCAD.ActiveDocument.openTransaction("Type conversion") nobj = makeBuilding() - Commands.copyProperties(obj,nobj) - FreeCAD.ActiveDocument.removeObject(obj.Name) - FreeCAD.ActiveDocument.commitTransaction() - else: + Commands.copyProperties(sel[0],nobj) + FreeCAD.ActiveDocument.removeObject(sel[0].Name) + FreeCAD.ActiveDocument.commitTransaction() + ok = True + if not ok: FreeCAD.ActiveDocument.openTransaction("Building") makeBuilding(sel) FreeCAD.ActiveDocument.commitTransaction() - FreeCAD.ActiveDocument.recompute() - + FreeCAD.ActiveDocument.recompute() + class _Building(Cell._Cell): "The Building object" def __init__(self,obj): diff --git a/src/Mod/Arch/Cell.py b/src/Mod/Arch/Cell.py index 7cdeaa5bdc..5dac629013 100644 --- a/src/Mod/Arch/Cell.py +++ b/src/Mod/Arch/Cell.py @@ -53,24 +53,20 @@ class _CommandCell: def Activated(self): 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: + ok = False + if (len(sel) == 1): + if Draft.getType(sel[0]) in ["Floor","Site","Building"]: + FreeCAD.ActiveDocument.openTransaction("Type conversion") nobj = makeCell() - Commands.copyProperties(obj,nobj) - FreeCAD.ActiveDocument.removeObject(obj.Name) - FreeCAD.ActiveDocument.commitTransaction() - else: + Commands.copyProperties(sel[0],nobj) + FreeCAD.ActiveDocument.removeObject(sel[0].Name) + FreeCAD.ActiveDocument.commitTransaction() + ok = True + if not ok: FreeCAD.ActiveDocument.openTransaction("Cell") makeCell(sel) FreeCAD.ActiveDocument.commitTransaction() - FreeCAD.ActiveDocument.recompute() + 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 b0dccb6989..48d4983230 100644 --- a/src/Mod/Arch/Commands.py +++ b/src/Mod/Arch/Commands.py @@ -223,7 +223,33 @@ def removeShape(objs,mark=True): else: if mark: obj.ViewObject.ShapeColor = (1.0,0.0,0.0,1.0) - + +def mergeCells(objectslist): + '''mergeCells(objectslist): merges the objects in the given list + into one. All objects must be of the same type and based on the Cell + object (cells, floors, buildings, or sites).''' + if not objectslist: + return None + if not isinstance(objectslist,list): + return None + if len(objectslist) < 2: + return None + typ = Draft.getType(objectslist[0]) + if not(typ in ["Cell","Floor","Building","Site"]): + return None + for o in objectslist: + if Draft.getType(o) != typ: + return None + base = objectslist.pop(0) + for o in objectslist: + l = base.Components + for c in o.Components: + if not c in l: + l.append(c) + base.Components = l + FreeCAD.ActiveDocument.removeObject(o.Name) + FreeCAD.ActiveDocument.recompute() + return base # command definitions ############################################### @@ -242,11 +268,11 @@ class _CommandAdd: def Activated(self): sel = FreeCADGui.Selection.getSelection() - host = sel.pop() FreeCAD.ActiveDocument.openTransaction("Grouping") - addComponents(sel,host) + if not mergeCells(sel): + host = sel.pop() + addComponents(sel,host) FreeCAD.ActiveDocument.commitTransaction() - class _CommandRemove: "the Arch Add command definition" diff --git a/src/Mod/Arch/Floor.py b/src/Mod/Arch/Floor.py index e0217b1f3a..ac256f950d 100644 --- a/src/Mod/Arch/Floor.py +++ b/src/Mod/Arch/Floor.py @@ -52,24 +52,20 @@ class _CommandFloor: def Activated(self): 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: + ok = False + if (len(sel) == 1): + if Draft.getType(sel[0]) in ["Cell","Site","Building"]: + FreeCAD.ActiveDocument.openTransaction("Type conversion") nobj = makeFloor() - Commands.copyProperties(obj,nobj) - FreeCAD.ActiveDocument.removeObject(obj.Name) - FreeCAD.ActiveDocument.commitTransaction() - else: + Commands.copyProperties(sel[0],nobj) + FreeCAD.ActiveDocument.removeObject(sel[0].Name) + FreeCAD.ActiveDocument.commitTransaction() + ok = True + if not ok: FreeCAD.ActiveDocument.openTransaction("Floor") makeFloor(sel) FreeCAD.ActiveDocument.commitTransaction() - FreeCAD.ActiveDocument.recompute() + FreeCAD.ActiveDocument.recompute() class _Floor(Cell._Cell): "The Cell object" diff --git a/src/Mod/Arch/Site.py b/src/Mod/Arch/Site.py index 5cd59cf52d..8ab58052f8 100644 --- a/src/Mod/Arch/Site.py +++ b/src/Mod/Arch/Site.py @@ -49,25 +49,21 @@ class _CommandSite: def Activated(self): 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: + ok = False + if (len(sel) == 1): + if Draft.getType(sel[0]) in ["Cell","Building","Floor"]: + FreeCAD.ActiveDocument.openTransaction("Type conversion") nobj = makeSite() - Commands.copyProperties(obj,nobj) - FreeCAD.ActiveDocument.removeObject(obj.Name) - FreeCAD.ActiveDocument.commitTransaction() - else: + Commands.copyProperties(sel[0],nobj) + FreeCAD.ActiveDocument.removeObject(sel[0].Name) + FreeCAD.ActiveDocument.commitTransaction() + ok = True + if not ok: FreeCAD.ActiveDocument.openTransaction("Site") makeSite(sel) FreeCAD.ActiveDocument.commitTransaction() - FreeCAD.ActiveDocument.recompute() - + FreeCAD.ActiveDocument.recompute() + class _Site(Cell._Cell): "The Site object" def __init__(self,obj):