Window.py

Go to the documentation of this file.
00001 #***************************************************************************
00002 #*                                                                         *
00003 #*   Copyright (c) 2011                                                    *  
00004 #*   Yorik van Havre <yorik@uncreated.net>                                 *  
00005 #*                                                                         *
00006 #*   This program is free software; you can redistribute it and/or modify  *
00007 #*   it under the terms of the GNU General Public License (GPL)            *
00008 #*   as published by the Free Software Foundation; either version 2 of     *
00009 #*   the License, or (at your option) any later version.                   *
00010 #*   for detail see the LICENCE text file.                                 *
00011 #*                                                                         *
00012 #*   This program is distributed in the hope that it will be useful,       *
00013 #*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014 #*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015 #*   GNU Library General Public License for more details.                  *
00016 #*                                                                         *
00017 #*   You should have received a copy of the GNU Library General Public     *
00018 #*   License along with this program; if not, write to the Free Software   *
00019 #*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00020 #*   USA                                                                   *
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     #p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
00042     #c = p.GetUnsigned("WindowColor")
00043     #r = float((c>>24)&0xFF)/255.0
00044     #g = float((c>>16)&0xFF)/255.0
00045     #b = float((c>>8)&0xFF)/255.0
00046     #obj.ViewObject.ShapeColor = (r,g,b,1.0)
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         #obj.addProperty("App::PropertyLink","Support","Base",
00075         #                "The support object (wall usually) of this window")
00076         #obj.addProperty("App::PropertyLength","Jamb","Base",
00077         #                "The distance between the window and the exterior face of its supporting object")
00078         #obj.addProperty("Part::PropertyPartShape","Subvolume","Base",
00079         #                "the volume to be subtracted when inserting this window into its support")
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())

Generated on Wed Nov 23 19:01:02 2011 for FreeCAD by  doxygen 1.6.1