+ Arch Add tool can now merge several cells of the same type

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5239 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
yorikvanhavre
2011-12-08 17:11:59 +00:00
parent 4f408105f9
commit 43134ea110
5 changed files with 72 additions and 62 deletions

View File

@@ -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):

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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):