FreeCAD/src/Mod/Arch/ArchWindow.py
Yorik van Havre 3badfeea98 + changed Arch module license block to LGPL
+ removed express schema file from Arch sources due to license
+ added explanations in Arch settings for the user to get one himself
2012-01-03 20:46:55 -02:00

122 lines
5.4 KiB
Python

#***************************************************************************
#* *
#* Copyright (c) 2011 *
#* Yorik van Havre <yorik@uncreated.net> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
import FreeCAD,FreeCADGui,Draft,ArchComponent
from draftlibs import fcvec
from FreeCAD import Vector
from PyQt4 import QtCore
__title__="FreeCAD Wall"
__author__ = "Yorik van Havre"
__url__ = "http://free-cad.sourceforge.net"
def makeWindow(baseobj=None,name="Window"):
'''makeWindow(obj,[name]): creates a window based on the
given object'''
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
_Window(obj)
_ViewProviderWindow(obj.ViewObject)
if baseobj: obj.Base = baseobj
if obj.Base: obj.Base.ViewObject.hide()
#p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
#c = p.GetUnsigned("WindowColor")
#r = float((c>>24)&0xFF)/255.0
#g = float((c>>16)&0xFF)/255.0
#b = float((c>>8)&0xFF)/255.0
#obj.ViewObject.ShapeColor = (r,g,b,1.0)
return obj
class _CommandWindow:
"the Arch Window command definition"
def GetResources(self):
return {'Pixmap' : 'Arch_Window',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Arch_Window","Window"),
'Accel': "W, N",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_Window","Creates a window object from scratch or from a selected object (wire, rectangle or sketch)")}
def Activated(self):
sel = FreeCADGui.Selection.getSelection()
FreeCAD.ActiveDocument.openTransaction("Window")
if sel:
for obj in sel:
makeWindow(obj)
else:
rect = Draft.makeRectangle(1,1)
makeWindow(rect)
FreeCAD.ActiveDocument.commitTransaction()
class _Window(ArchComponent.Component):
"The Window object"
def __init__(self,obj):
ArchComponent.Component.__init__(self,obj)
obj.addProperty("App::PropertyFloat","Thickness","Base",
"the thickness to be associated with the wire of the Base object")
#obj.addProperty("App::PropertyLink","Support","Base",
# "The support object (wall usually) of this window")
#obj.addProperty("App::PropertyLength","Jamb","Base",
# "The distance between the window and the exterior face of its supporting object")
#obj.addProperty("Part::PropertyPartShape","Subvolume","Base",
# "the volume to be subtracted when inserting this window into its support")
self.Type = "Window"
obj.Thickness = .1
def execute(self,obj):
self.createGeometry(obj)
def onChanged(self,obj,prop):
if prop in ["Base","Thickness"]:
self.createGeometry(obj)
def createGeometry(self,obj):
import Part
from draftlibs import fcgeo
pl = obj.Placement
if obj.Base:
if obj.Base.isDerivedFrom("Part::Feature"):
if obj.Base.Shape.Wires:
basewire = obj.Base.Shape.Wires[0]
if obj.Thickness:
offwire = basewire.makeOffset(-obj.Thickness)
f1 = Part.Face(basewire)
f2 = Part.Face(offwire)
bf = f1.cut(f2)
sh = bf.extrude(Vector(0,0,obj.Thickness))
obj.Shape = sh
f1.translate(Vector(0,0,-.5))
svol = f1.extrude(Vector(0,0,1))
self.Subvolume = svol
if not fcgeo.isNull(pl):
obj.Placement = pl
self.Subvolume.Placement = pl
class _ViewProviderWindow(ArchComponent.ViewProviderComponent):
"A View Provider for the Window object"
def __init__(self,vobj):
ArchComponent.ViewProviderComponent.__init__(self,vobj)
def getIcon(self):
return ":/icons/Arch_Window_Tree.svg"
FreeCADGui.addCommand('Arch_Window',_CommandWindow())