+ allow Arch Cell tools to convert other cell types

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5229 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
yorikvanhavre 2011-12-07 15:27:06 +00:00
parent 271291a2d0
commit c95dd75624
5 changed files with 107 additions and 26 deletions

View File

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

View File

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

View File

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

View File

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

View File

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