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,Component
00025 from draftlibs import fcgeo,fcvec
00026 from FreeCAD import Vector
00027 from PyQt4 import QtCore
00028
00029 __title__="FreeCAD Wall"
00030 __author__ = "Yorik van Havre"
00031 __url__ = "http://free-cad.sourceforge.net"
00032
00033 def makeWindow(baseobj=None,name="Window"):
00034 '''makeWindow(obj,[name]): creates a window based on the
00035 given object'''
00036 obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
00037 Window(obj)
00038 ViewProviderWindow(obj.ViewObject)
00039 if baseobj: obj.Base = baseobj
00040 if obj.Base: obj.Base.ViewObject.hide()
00041
00042
00043
00044
00045
00046
00047 return obj
00048
00049 class CommandWindow:
00050 "the Arch Window command definition"
00051 def GetResources(self):
00052 return {'Pixmap' : 'Arch_Window',
00053 'MenuText': QtCore.QT_TRANSLATE_NOOP("Arch_Window","Window"),
00054 'Accel': "W, A",
00055 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Window","Creates a window object from scratch or from a selected object (wire, rectangle or sketch)")}
00056
00057 def Activated(self):
00058 sel = FreeCADGui.Selection.getSelection()
00059 FreeCAD.ActiveDocument.openTransaction("Window")
00060 if sel:
00061 for obj in sel:
00062 makeWindow(obj)
00063 else:
00064 rect = Draft.makeRectangle(1,1)
00065 makeWindow(rect)
00066 FreeCAD.ActiveDocument.commitTransaction()
00067
00068 class Window(Component.Component):
00069 "The Window object"
00070 def __init__(self,obj):
00071 Component.Component.__init__(self,obj)
00072 obj.addProperty("App::PropertyFloat","Thickness","Base",
00073 "the thickness to be associated with the wire of the Base object")
00074
00075
00076
00077
00078
00079
00080 self.Type = "Window"
00081 obj.Thickness = .1
00082
00083 def execute(self,obj):
00084 self.createGeometry(obj)
00085
00086 def onChanged(self,obj,prop):
00087 if prop in ["Base","Thickness"]:
00088 self.createGeometry(obj)
00089
00090 def createGeometry(self,obj):
00091 pl = obj.Placement
00092 if obj.Base:
00093 if obj.Base.isDerivedFrom("Part::Feature"):
00094 if obj.Base.Shape.Wires:
00095 basewire = obj.Base.Shape.Wires[0]
00096 if obj.Thickness:
00097 offwire = basewire.makeOffset(-obj.Thickness)
00098 f1 = Part.Face(basewire)
00099 f2 = Part.Face(offwire)
00100 bf = f1.cut(f2)
00101 sh = bf.extrude(Vector(0,0,obj.Thickness))
00102 obj.Shape = sh
00103 f1.translate(Vector(0,0,-.5))
00104 svol = f1.extrude(Vector(0,0,1))
00105 self.Subvolume = svol
00106 if not fcgeo.isNull(pl):
00107 obj.Placement = pl
00108 self.Subvolume.Placement = pl
00109
00110 class ViewProviderWindow(Component.ViewProviderComponent):
00111 "A View Provider for the Window object"
00112
00113 def __init__(self,vobj):
00114 Component.ViewProviderComponent.__init__(self,vobj)
00115
00116 def getIcon(self):
00117 return """
00118 /* XPM */
00119 static char * Arch_Window_xpm[] = {
00120 "16 16 5 1",
00121 " c None",
00122 ". c #0E0A00",
00123 "+ c #9B8A61",
00124 "@ c #C6B287",
00125 "# c #FEFFF8",
00126 " ",
00127 " ...... ",
00128 " ####+...... ",
00129 " #+. #####..... ",
00130 " #+. @#@####++ ",
00131 " #+. ## #++ ",
00132 " #.....## #++ ",
00133 " ####+.#....#+@ ",
00134 " #+. +###+..++@ ",
00135 " #+. @#+@###+@ ",
00136 " #... ## #+@ ",
00137 " #+....#+ #+@ ",
00138 " ####+#....#+@ ",
00139 " @####..@+@ ",
00140 " @###++ ",
00141 " . "};
00142 """
00143
00144 FreeCADGui.addCommand('Arch_Window',CommandWindow())