00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 import FreeCAD,FreeCADGui,Part,Draft
00025 from FreeCAD import Vector
00026 from PyQt4 import QtCore
00027
00028 __title__="FreeCAD Cell"
00029 __author__ = "Yorik van Havre"
00030 __url__ = "http://free-cad.sourceforge.net"
00031
00032 def makeCell(objectslist,join=True,name="Cell"):
00033 '''makeCell(objectslist,[joinmode]): creates a cell including the
00034 objects from the given list. If joinmode is False, contents will
00035 not be joined.'''
00036 obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
00037 Cell(obj)
00038 ViewProviderCell(obj.ViewObject)
00039 obj.Components = objectslist
00040 for comp in obj.Components:
00041 comp.ViewObject.hide()
00042 obj.JoinMode = join
00043 return obj
00044
00045 class CommandCell:
00046 "the Arch Cell command definition"
00047 def GetResources(self):
00048 return {'Pixmap' : 'Arch_Cell',
00049 'MenuText': QtCore.QT_TRANSLATE_NOOP("Arch_Cell","Cell"),
00050 'Accel': "C, E",
00051 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Cell","Creates a cell object including selected objects")}
00052
00053 def Activated(self):
00054 FreeCAD.ActiveDocument.openTransaction("Cell")
00055 makeCell(FreeCADGui.Selection.getSelection())
00056 FreeCAD.ActiveDocument.commitTransaction()
00057
00058 class Cell:
00059 "The Cell object"
00060 def __init__(self,obj):
00061 obj.addProperty("App::PropertyLinkList","Components","Base",
00062 "The objects that make part of this cell")
00063 obj.addProperty("App::PropertyBool","JoinMode","Base",
00064 "If True, underlying geometry will be joined")
00065 obj.Proxy = self
00066 self.Type = "Cell"
00067
00068 def execute(self,obj):
00069 self.createGeometry(obj)
00070
00071 def onChanged(self,obj,prop):
00072 if prop in ["Components","JoinMode"]:
00073 self.createGeometry(obj)
00074
00075 def createGeometry(self,obj):
00076 pl = obj.Placement
00077 if obj.Components:
00078 if obj.JoinMode:
00079 components = obj.Components[:]
00080 f = components.pop(0)
00081 baseShape = f.Shape
00082 for comp in components:
00083 if Draft.getType(comp) in ["Wall","Cell","Shape"]:
00084 baseShape = baseShape.oldFuse(comp.Shape)
00085 else:
00086 compshapes = []
00087 for o in obj.Components:
00088 compshapes.append(o.Shape)
00089 baseShape = Part.makeCompound(compshapes)
00090 obj.Shape = baseShape
00091 obj.Placement = pl
00092
00093 class ViewProviderCell:
00094 "A View Provider for the Cell object"
00095 def __init__(self,vobj):
00096 vobj.Proxy = self
00097 self.Object = vobj.Object
00098
00099 def getIcon(self):
00100 return """
00101 /* XPM */
00102 static char * Arch_Cell_xpm[] = {
00103 "16 16 9 1",
00104 " c None",
00105 ". c #0C0A04",
00106 "+ c #413F37",
00107 "@ c #636057",
00108 "# c #7E7D75",
00109 "$ c #9C9B95",
00110 "% c #B7B8B3",
00111 "& c #D2D4D1",
00112 "* c #FCFEFB",
00113 " +++ ",
00114 " ++#++@$+ ",
00115 " +@$%**@%#@++++ ",
00116 " #&**%*@%%%$@+##",
00117 " #&%@@*@%$@+@&*%",
00118 " #&% @*@$@@%***%",
00119 " #&% @*@+@#****%",
00120 " #&%.@*@+@#****%",
00121 " #&%$&*@+@#****%",
00122 ".@&****@+@#****%",
00123 " @&***&@+@#****%",
00124 " @&**$ .@#****%",
00125 " @&%# @#****#",
00126 " +@ @#**& ",
00127 " @#*$ ",
00128 " @@# "};
00129 """
00130
00131 def updateData(self,obj,prop):
00132 return
00133
00134 def onChanged(self,vobj,prop):
00135 return
00136
00137 def claimChildren(self):
00138 return self.Object.Components
00139
00140 def attach(self,vobj):
00141 self.Object = vobj.Object
00142 return
00143
00144 def getDisplayModes(self,obj):
00145 modes=[]
00146 return modes
00147
00148 def setDisplayMode(self,mode):
00149 return mode
00150
00151 def __getstate__(self):
00152 return None
00153
00154 def __setstate__(self,state):
00155 return None
00156
00157 FreeCADGui.addCommand('Arch_Cell',CommandCell())