Arch: Better support for App::Parts in Arch Windows
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
import os
|
||||
|
||||
import FreeCAD,Draft,ArchComponent,DraftVecUtils,ArchCommands
|
||||
import ArchWindowPresets
|
||||
from FreeCAD import Units
|
||||
from FreeCAD import Vector
|
||||
if FreeCAD.GuiUp:
|
||||
@@ -54,11 +55,9 @@ __url__ = "http://www.freecadweb.org"
|
||||
# presets
|
||||
WindowPartTypes = ["Frame","Solid panel","Glass panel","Louvre"]
|
||||
AllowedHosts = ["Wall","Structure","Roof"]
|
||||
WindowPresets = ["Fixed", "Open 1-pane", "Open 2-pane", "Sash 2-pane",
|
||||
"Sliding 2-pane", "Simple door", "Glass door", "Sliding 4-pane"]
|
||||
WindowOpeningModes = ["None","Arc 90","Arc 90 inv","Arc 45","Arc 45 inv","Arc 180",
|
||||
"Arc 180 inv","Triangle","Triangle inv","Sliding","Sliding inv"]
|
||||
|
||||
WindowPresets = ArchWindowPresets.WindowPresets
|
||||
|
||||
|
||||
def makeWindow(baseobj=None,width=None,height=None,parts=None,name="Window"):
|
||||
@@ -101,6 +100,13 @@ def makeWindow(baseobj=None,width=None,height=None,parts=None,name="Window"):
|
||||
ws += "Wire" + str(i)
|
||||
i += 1
|
||||
obj.WindowParts = ["Default","Frame",ws,"1","0"]
|
||||
else:
|
||||
# bind properties from base obj if existing
|
||||
for prop in ["Height","Width","Subvolume","Tag","Description","Material"]:
|
||||
for p in baseobj.PropertiesList:
|
||||
if (p == prop) or p.endswith("_"+prop):
|
||||
obj.setExpression(prop, baseobj.Name+"."+p)
|
||||
|
||||
if obj.Base and FreeCAD.GuiUp:
|
||||
obj.Base.ViewObject.DisplayMode = "Wireframe"
|
||||
obj.Base.ViewObject.hide()
|
||||
@@ -108,475 +114,26 @@ def makeWindow(baseobj=None,width=None,height=None,parts=None,name="Window"):
|
||||
todo.delay(recolorize,[obj.Document.Name,obj.Name])
|
||||
return obj
|
||||
|
||||
def recolorize(names): # names is [docname,objname]
|
||||
def recolorize(attr): # names is [docname,objname]
|
||||
|
||||
if names[0] in FreeCAD.listDocuments():
|
||||
doc = FreeCAD.getDocument(names[0])
|
||||
obj = doc.getObject(names[1])
|
||||
if obj:
|
||||
if obj.ViewObject:
|
||||
if obj.ViewObject.Proxy:
|
||||
obj.ViewObject.Proxy.colorize(obj,force=True)
|
||||
"""Recolorizes an object or a [documentname,objectname] list
|
||||
This basically calls the Proxy.colorize(obj) methods of objects that
|
||||
have one."""
|
||||
|
||||
def makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,placement=None):
|
||||
if isinstance(attr,list):
|
||||
if attr[0] in FreeCAD.listDocuments():
|
||||
doc = FreeCAD.getDocument(attr[0])
|
||||
obj = doc.getObject(attr[1])
|
||||
if obj:
|
||||
if obj.ViewObject:
|
||||
if obj.ViewObject.Proxy:
|
||||
obj.ViewObject.Proxy.colorize(obj,force=True)
|
||||
elif hasattr(attr,"ViewObject") and attr.ViewObject:
|
||||
obj = attr
|
||||
if hasattr(obj.ViewObject,"Proxy") and hasattr(obj.ViewObject.Proxy,"colorize"):
|
||||
obj.ViewObject.Proxy.colorize(obj,force=True)
|
||||
|
||||
"""makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,[placement]): makes a
|
||||
window object based on the given data. windowtype must be one of the names
|
||||
defined in Arch.WindowPresets"""
|
||||
|
||||
if not FreeCAD.ActiveDocument:
|
||||
FreeCAD.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
|
||||
def makeSketch(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2):
|
||||
|
||||
import Part,Sketcher
|
||||
width = float(width)
|
||||
height = float(height)
|
||||
h1 = float(h1)
|
||||
h2 = float(h2)
|
||||
h3 = float(h3)
|
||||
w1 = float(w1)
|
||||
w2 = float(w2)
|
||||
o1 = float(o1)
|
||||
o2 = float(o2)
|
||||
# small spacing to avoid wrong auto-wires in sketch
|
||||
tol = h1/10
|
||||
# glass size divider
|
||||
gla = 10
|
||||
s = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','Sketch')
|
||||
|
||||
def addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8):
|
||||
|
||||
"adds two rectangles to the given sketch"
|
||||
|
||||
idx = s.GeometryCount
|
||||
s.addGeometry(Part.LineSegment(p1,p2))
|
||||
s.addGeometry(Part.LineSegment(p2,p3))
|
||||
s.addGeometry(Part.LineSegment(p3,p4))
|
||||
s.addGeometry(Part.LineSegment(p4,p1))
|
||||
s.addConstraint(Sketcher.Constraint('Coincident',idx,2,idx+1,1))
|
||||
s.addConstraint(Sketcher.Constraint('Coincident',idx+1,2,idx+2,1))
|
||||
s.addConstraint(Sketcher.Constraint('Coincident',idx+2,2,idx+3,1))
|
||||
s.addConstraint(Sketcher.Constraint('Coincident',idx+3,2,idx,1))
|
||||
s.addConstraint(Sketcher.Constraint('Horizontal',idx))
|
||||
s.addConstraint(Sketcher.Constraint('Horizontal',idx+2))
|
||||
s.addConstraint(Sketcher.Constraint('Vertical',idx+1))
|
||||
s.addConstraint(Sketcher.Constraint('Vertical',idx+3))
|
||||
s.addGeometry(Part.LineSegment(p5,p6))
|
||||
s.addGeometry(Part.LineSegment(p6,p7))
|
||||
s.addGeometry(Part.LineSegment(p7,p8))
|
||||
s.addGeometry(Part.LineSegment(p8,p5))
|
||||
s.addConstraint(Sketcher.Constraint('Coincident',idx+4,2,idx+5,1))
|
||||
s.addConstraint(Sketcher.Constraint('Coincident',idx+5,2,idx+6,1))
|
||||
s.addConstraint(Sketcher.Constraint('Coincident',idx+6,2,idx+7,1))
|
||||
s.addConstraint(Sketcher.Constraint('Coincident',idx+7,2,idx+4,1))
|
||||
s.addConstraint(Sketcher.Constraint('Horizontal',idx+4))
|
||||
s.addConstraint(Sketcher.Constraint('Horizontal',idx+6))
|
||||
s.addConstraint(Sketcher.Constraint('Vertical',idx+5))
|
||||
s.addConstraint(Sketcher.Constraint('Vertical',idx+7))
|
||||
|
||||
def outerFrame(s,width,height,h1,w1,o1):
|
||||
|
||||
p1 = Vector(0,0,0)
|
||||
p2 = Vector(width,0,0)
|
||||
p3 = Vector(width,height,0)
|
||||
p4 = Vector(0,height,0)
|
||||
p5 = Vector(h1,h1,0)
|
||||
p6 = Vector(width-h1,h1,0)
|
||||
p7 = Vector(width-h1,height-h1,0)
|
||||
p8 = Vector(h1,height-h1,0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',1,height)) #16
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',0,width)) #17
|
||||
s.renameConstraint(16, 'Height')
|
||||
s.renameConstraint(17, 'Width')
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',6,2,2,2,h1))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',2,2,6,2,h1))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',4,2,0,2,h1))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',0,2,4,2,h1))
|
||||
s.renameConstraint(18, 'Frame1')
|
||||
s.renameConstraint(19, 'Frame2')
|
||||
s.renameConstraint(20, 'Frame3')
|
||||
s.renameConstraint(21, 'Frame4')
|
||||
s.addConstraint(Sketcher.Constraint('Coincident',0,1,-1,1))
|
||||
return ["OuterFrame","Frame","Wire0,Wire1",str(w1-w2)+"+V","0.00+V"]
|
||||
|
||||
def doorFrame(s,width,height,h1,w1,o1):
|
||||
|
||||
p1 = Vector(0,0,0)
|
||||
p2 = Vector(width,0,0)
|
||||
p3 = Vector(width,height,0)
|
||||
p4 = Vector(0,height,0)
|
||||
p5 = Vector(h1,0,0)
|
||||
p6 = Vector(width-h1,0,0)
|
||||
p7 = Vector(width-h1,height-h1,0)
|
||||
p8 = Vector(h1,height-h1,0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',1,height)) #16
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',0,width)) #17
|
||||
s.renameConstraint(16, 'Height')
|
||||
s.renameConstraint(17, 'Width')
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',6,2,2,2,h1))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',2,2,6,2,h1))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',4,2,0,2,h1))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',0,2,4,2,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('Coincident',0,1,-1,1))
|
||||
s.renameConstraint(18, 'Frame1')
|
||||
s.renameConstraint(19, 'Frame2')
|
||||
s.renameConstraint(20, 'Frame3')
|
||||
return ["OuterFrame","Frame","Wire0,Wire1",str(w1-w2)+"+V","0.00+V"]
|
||||
|
||||
if windowtype == "Fixed":
|
||||
|
||||
wp = outerFrame(s,width,height,h1,w1,o1)
|
||||
wp.extend(["Glass","Glass panel","Wire1",str(w1/gla),str(w1/2)+"+V"])
|
||||
|
||||
elif windowtype == "Open 1-pane":
|
||||
|
||||
wp = outerFrame(s,width,height,h1,w1,o1)
|
||||
p1 = Vector(h1+tol,h1+tol,0)
|
||||
p2 = Vector(width-(h1+tol),h1+tol,0)
|
||||
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
|
||||
p4 = Vector(h1+tol,height-(h1+tol),0)
|
||||
p5 = Vector(h1+h2,h1+h2,0)
|
||||
p6 = Vector(width-(h1+h2),h1+h2,0)
|
||||
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
|
||||
p8 = Vector(h1+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',14,1,10,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',14,1,10,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',10,1,6,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',10,1,6,1,tol))
|
||||
if h2 == h1:
|
||||
s.renameConstraint(39,'Frame5')
|
||||
s.renameConstraint(40,'Frame6')
|
||||
s.renameConstraint(42,'Frame7')
|
||||
s.renameConstraint(41,'Frame8')
|
||||
fw = str(w2)
|
||||
if w2 == w1:
|
||||
fw = "0.00+V"
|
||||
wp.extend(["InnerFrame","Frame","Wire2,Wire3",fw,str(o2)+"+V"])
|
||||
wp.extend(["InnerGlass","Glass panel","Wire3",str(w2/gla),str(o2+w2/2)+"+V"])
|
||||
|
||||
elif windowtype == "Open 2-pane":
|
||||
|
||||
wp = outerFrame(s,width,height,h1,w1,o1)
|
||||
p1 = Vector(h1+tol,h1+tol,0)
|
||||
p2 = Vector((width/2)-tol,h1+tol,0)
|
||||
p3 = Vector((width/2)-tol,height-(h1+tol),0)
|
||||
p4 = Vector(h1+tol,height-(h1+tol),0)
|
||||
p5 = Vector(h1+h2,h1+h2,0)
|
||||
p6 = Vector((width/2)-h2,h1+h2,0)
|
||||
p7 = Vector((width/2)-h2,height-(h1+h2),0)
|
||||
p8 = Vector(h1+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
p1 = Vector((width/2)+tol,h1+tol,0)
|
||||
p2 = Vector(width-(h1+tol),h1+tol,0)
|
||||
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
|
||||
p4 = Vector((width/2)+tol,height-(h1+tol),0)
|
||||
p5 = Vector((width/2)+h2,h1+h2,0)
|
||||
p6 = Vector(width-(h1+h2),h1+h2,0)
|
||||
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
|
||||
p8 = Vector((width/2)+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',21,2,17,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',21,2,17,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',16,1,20,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',14,1,10,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('Equal',22,14))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',8,2,16,1,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',10,1,18,2,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',6,1,18,1,-tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',6,1,18,1,-tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',9,1,19,2,tol))
|
||||
s.addConstraint(Sketcher.Constraint('PointOnObject',13,2,22))
|
||||
s.addConstraint(Sketcher.Constraint('PointOnObject',20,1,12))
|
||||
if h1 == h2:
|
||||
s.renameConstraint(55,'Frame5')
|
||||
s.renameConstraint(56,'Frame6')
|
||||
s.renameConstraint(57,'Frame7')
|
||||
s.renameConstraint(58,'Frame8')
|
||||
s.renameConstraint(59,'Frame9')
|
||||
s.renameConstraint(60,'Frame10')
|
||||
fw = str(w2)
|
||||
if w2 == w1:
|
||||
fw = "0.00+V"
|
||||
wp.extend(["LeftFrame","Frame","Wire2,Wire3",fw,str(o2)+"+V"])
|
||||
wp.extend(["LeftGlass","Glass panel","Wire3",str(w2/gla),str(o2+w2/2)+"+V"])
|
||||
wp.extend(["RightFrame","Frame","Wire4,Wire5",fw,str(o2)+"+V"])
|
||||
wp.extend(["RightGlass","Glass panel","Wire5",str(w2/gla),str(o2+w2/2)+"+V"])
|
||||
|
||||
elif windowtype == "Sash 2-pane":
|
||||
|
||||
wp = outerFrame(s,width,height,h1,w1,o1)
|
||||
p1 = Vector(h1+tol,h1+tol,0)
|
||||
p2 = Vector(width-(h1+tol),h1+tol,0)
|
||||
p3 = Vector(width-(h1+tol),(height/2)-tol,0)
|
||||
p4 = Vector(h1+tol,(height/2)-tol,0)
|
||||
p5 = Vector(h1+h2,h1+h2,0)
|
||||
p6 = Vector(width-(h1+h2),h1+h2,0)
|
||||
p7 = Vector(width-(h1+h2),(height/2)-h2,0)
|
||||
p8 = Vector(h1+h2,(height/2)-h2,0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
p1 = Vector(h1+tol,(height/2)+tol,0)
|
||||
p2 = Vector(width-(h1+tol),(height/2)+tol,0)
|
||||
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
|
||||
p4 = Vector(h1+tol,height-(h1+tol),0)
|
||||
p5 = Vector(h1+h2,(height/2)+h2,0)
|
||||
p6 = Vector(width-(h1+h2),(height/2)+h2,0)
|
||||
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
|
||||
p8 = Vector(h1+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',21,2,17,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',21,2,17,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',16,2,20,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',10,2,14,2,-h2))
|
||||
s.addConstraint(Sketcher.Constraint('Equal',23,15))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',12,1,20,1,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',13,2,20,2,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',6,1,18,1,-tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',6,1,18,1,-tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',10,1,16,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('PointOnObject',9,2,17))
|
||||
s.addConstraint(Sketcher.Constraint('PointOnObject',16,1,11))
|
||||
if h1 == h2:
|
||||
s.renameConstraint(55,'Frame5')
|
||||
s.renameConstraint(56,'Frame6')
|
||||
s.renameConstraint(57,'Frame7')
|
||||
s.renameConstraint(58,'Frame8')
|
||||
s.renameConstraint(59,'Frame9')
|
||||
s.renameConstraint(60,'F10')
|
||||
s.setExpression('.Constraints.F10','-.Constraints.Frame5')
|
||||
fw = str(w2)
|
||||
if w2 == w1:
|
||||
fw = "0.00+V"
|
||||
wp.extend(["LowerFrame","Frame","Wire2,Wire3",fw,str(o2+w2)+"+V"])
|
||||
wp.extend(["LowerGlass","Glass panel","Wire3",str(w2/gla),str(o2+w2+w2/2)+"+V"])
|
||||
wp.extend(["UpperFrame","Frame","Wire4,Wire5",fw,str(o2)+"+V"])
|
||||
wp.extend(["UpperGlass","Glass panel","Wire5",str(w2/gla),str(o2+w2/2)+"+V"])
|
||||
|
||||
elif windowtype == "Sliding 2-pane":
|
||||
|
||||
wp = outerFrame(s,width,height,h1,w1,o1)
|
||||
p1 = Vector(h1+tol,h1+tol,0)
|
||||
p2 = Vector((width/2)-tol,h1+tol,0)
|
||||
p3 = Vector((width/2)-tol,height-(h1+tol),0)
|
||||
p4 = Vector(h1+tol,height-(h1+tol),0)
|
||||
p5 = Vector(h1+h2,h1+h2,0)
|
||||
p6 = Vector((width/2)-h2,h1+h2,0)
|
||||
p7 = Vector((width/2)-h2,height-(h1+h2),0)
|
||||
p8 = Vector(h1+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
p1 = Vector((width/2)+tol,h1+tol,0)
|
||||
p2 = Vector(width-(h1+tol),h1+tol,0)
|
||||
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
|
||||
p4 = Vector((width/2)+tol,height-(h1+tol),0)
|
||||
p5 = Vector((width/2)+h2,h1+h2,0)
|
||||
p6 = Vector(width-(h1+h2),h1+h2,0)
|
||||
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
|
||||
p8 = Vector((width/2)+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',21,2,17,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',21,2,17,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',16,1,20,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',14,1,10,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('Equal',22,14))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',8,2,16,1,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',10,1,18,2,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',6,1,18,1,-tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',6,1,18,1,-tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',9,1,19,2,tol))
|
||||
s.addConstraint(Sketcher.Constraint('PointOnObject',13,2,22))
|
||||
s.addConstraint(Sketcher.Constraint('PointOnObject',12,2,20))
|
||||
if h1 == h2:
|
||||
s.renameConstraint(55,'Frame5')
|
||||
s.renameConstraint(56,'Frame6')
|
||||
s.renameConstraint(57,'Frame7')
|
||||
s.renameConstraint(58,'Frame8')
|
||||
s.renameConstraint(59,'Frame9')
|
||||
s.renameConstraint(60,'Frame10')
|
||||
fw = str(w2)
|
||||
if w2 == w1:
|
||||
fw = "0.00+V"
|
||||
wp.extend(["LeftFrame","Frame","Wire2,Wire3",fw,str(o2)+"+V"])
|
||||
wp.extend(["LeftGlass","Glass panel","Wire3",str(w2/gla),str(o2+w2/2)+"+V"])
|
||||
wp.extend(["RightFrame","Frame","Wire4,Wire5",fw,str(o2+w2)+"+V"])
|
||||
wp.extend(["RightGlass","Glass panel","Wire5",str(w2/gla),str(o2+w2+w2/2)+"+V"])
|
||||
|
||||
elif windowtype == "Sliding 4-pane":
|
||||
|
||||
wp = outerFrame(s,width,height,h1,w1,o1)
|
||||
p1 = Vector(h1+tol,h1+tol,0)
|
||||
p2 = Vector(width/4-tol,h1+tol,0)
|
||||
p3 = Vector(width/4-tol,height-(h1+tol),0)
|
||||
p4 = Vector(h1+tol,height-(h1+tol),0)
|
||||
p5 = Vector(h1+h2,h1+h2,0)
|
||||
p6 = Vector(width/4-h2,h1+h2,0)
|
||||
p7 = Vector(width/4-h2,height-(h1+h2),0)
|
||||
p8 = Vector(h1+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
p1 = Vector(width/4+tol,h1+tol,0)
|
||||
p2 = Vector(width/2-tol,h1+tol,0)
|
||||
p3 = Vector(width/2-tol,height-(h1+tol),0)
|
||||
p4 = Vector(width/4+tol,height-(h1+tol),0)
|
||||
p5 = Vector(width/4+h2,h1+h2,0)
|
||||
p6 = Vector(width/2-h2,h1+h2,0)
|
||||
p7 = Vector(width/2-h2,height-(h1+h2),0)
|
||||
p8 = Vector(width/4+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
p1 = Vector(width/2+tol,h1+tol,0)
|
||||
p2 = Vector(width*3/4-tol,h1+tol,0)
|
||||
p3 = Vector(width*3/4-tol,height-(h1+tol),0)
|
||||
p4 = Vector(width/2+tol,height-(h1+tol),0)
|
||||
p5 = Vector(width/2+h2,h1+h2,0)
|
||||
p6 = Vector(width*3/4-h2,h1+h2,0)
|
||||
p7 = Vector(width*3/4-h2,height-(h1+h2),0)
|
||||
p8 = Vector(width/2+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
p1 = Vector(width*3/4+tol,h1+tol,0)
|
||||
p2 = Vector(width-(h1+tol),h1+tol,0)
|
||||
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
|
||||
p4 = Vector(width*3/4+tol,height-(h1+tol),0)
|
||||
p5 = Vector(width*3/4+h2,h1+h2,0)
|
||||
p6 = Vector(width-(h1+h2),h1+h2,0)
|
||||
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
|
||||
p8 = Vector(width*3/4+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',8,2,16,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',17,1,27,2,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',24,2,32,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',32,2,4,2,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',10,2,6,2,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',17,2,26,2,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',25,2,34,2,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',8,2,16,1,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',9,2,18,2,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',16,2,24,1,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',24,2,32,1,0.0))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',13,2,9,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',13,2,9,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',16,1,20,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',16,1,20,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',21,2,17,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',21,2,17,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',24,1,28,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',24,1,28,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',29,2,25,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',29,2,25,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',32,1,36,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',32,1,36,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',37,2,33,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',37,2,33,2,h2))
|
||||
s.addConstraint(Sketcher.Constraint('Equal',14,22))
|
||||
s.addConstraint(Sketcher.Constraint('Equal',22,30))
|
||||
s.addConstraint(Sketcher.Constraint('Equal',30,38))
|
||||
if h1 == h2:
|
||||
s.renameConstraint(100,'Frame5')
|
||||
s.renameConstraint(101,'Frame6')
|
||||
s.renameConstraint(102,'Frame7')
|
||||
s.renameConstraint(103,'Frame8')
|
||||
s.renameConstraint(104,'Frame9')
|
||||
s.renameConstraint(105,'Frame10')
|
||||
s.renameConstraint(106,'Frame11')
|
||||
s.renameConstraint(107,'Frame12')
|
||||
s.renameConstraint(108,'Frame13')
|
||||
s.renameConstraint(109,'Frame14')
|
||||
s.renameConstraint(110,'Frame15')
|
||||
s.renameConstraint(111,'Frame16')
|
||||
s.renameConstraint(112,'Frame17')
|
||||
s.renameConstraint(113,'Frame18')
|
||||
s.renameConstraint(114,'Frame19')
|
||||
s.renameConstraint(115,'Frame20')
|
||||
fw = str(w2)
|
||||
if w2 == w1:
|
||||
fw = "0.00+V"
|
||||
wp.extend(["LeftMostFrame","Frame","Wire2,Wire3",fw,str(o2)+"+V"])
|
||||
wp.extend(["LeftMostGlass","Glass panel","Wire3",str(w2/gla),str(o2+w2/2)+"+V"])
|
||||
wp.extend(["LeftFrame","Frame","Wire4,Wire5",fw,str(o2+w2)+"+V"])
|
||||
wp.extend(["LeftGlass","Glass panel","Wire5",str(w2/gla),str(o2+w2+w2/2)+"+V"])
|
||||
wp.extend(["RightFrame","Frame","Wire6,Wire7",fw,str(o2+w2)+"+V"])
|
||||
wp.extend(["RightGlass","Glass panel","Wire7",str(w2/gla),str(o2+w2+w2/2)+"+V"])
|
||||
wp.extend(["RightMostFrame","Frame","Wire8,Wire9",fw,str(o2)+"+V"])
|
||||
wp.extend(["RightMostGlass","Glass panel","Wire9",str(w2/gla),str(o2+w2/2)+"+V"])
|
||||
|
||||
elif windowtype == "Simple door":
|
||||
|
||||
wp = doorFrame(s,width,height,h1,w1,o1)
|
||||
wp.extend(["Door","Solid panel","Wire1",str(w2),str(o2)+"+V"])
|
||||
|
||||
elif windowtype == "Glass door":
|
||||
|
||||
wp = doorFrame(s,width,height,h1,w1,o1)
|
||||
p1 = Vector(h1+tol,h1+tol,0)
|
||||
p2 = Vector(width-(h1+tol),h1+tol,0)
|
||||
p3 = Vector(width-(h1+tol),height-(h1+tol),0)
|
||||
p4 = Vector(h1+tol,height-(h1+tol),0)
|
||||
p5 = Vector(h1+h2,h1+h3,0)
|
||||
p6 = Vector(width-(h1+h2),h1+h3,0)
|
||||
p7 = Vector(width-(h1+h2),height-(h1+h2),0)
|
||||
p8 = Vector(h1+h2,height-(h1+h2),0)
|
||||
addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8)
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',8,1,12,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',8,1,12,1,h3))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',14,1,10,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',14,1,10,1,h2))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',4,1,8,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceX',10,1,6,1,tol))
|
||||
s.addConstraint(Sketcher.Constraint('DistanceY',10,1,6,1,tol))
|
||||
if h2 == h1:
|
||||
s.renameConstraint(39,'Frame5')
|
||||
s.renameConstraint(40,'Frame6')
|
||||
s.renameConstraint(42,'Frame7')
|
||||
s.renameConstraint(41,'Frame8')
|
||||
fw = str(w2)
|
||||
if w2 == w1:
|
||||
fw = "0.00+V"
|
||||
wp.extend(["InnerFrame","Frame","Wire2,Wire3",fw,str(o2)+"+V"])
|
||||
wp.extend(["InnerGlass","Glass panel","Wire3",str(w2/gla),str(o2+w2/2)+"+V"])
|
||||
|
||||
return (s,wp)
|
||||
|
||||
if windowtype in WindowPresets:
|
||||
default = makeSketch(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2)
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
if default:
|
||||
if placement:
|
||||
default[0].Placement = placement
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
obj = makeWindow(default[0],width,height,default[1])
|
||||
obj.Preset = WindowPresets.index(windowtype)+1
|
||||
obj.Frame = h1
|
||||
obj.Offset = o1
|
||||
obj.Placement = FreeCAD.Placement() # unable to find where this bug comes from...
|
||||
if "door" in windowtype:
|
||||
obj.IfcType = "Door"
|
||||
obj.Label = translate("Arch","Door")
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
return obj
|
||||
|
||||
print("Arch: Unknown window type")
|
||||
|
||||
|
||||
|
||||
@@ -585,7 +142,7 @@ class _CommandWindow:
|
||||
"the Arch Window command definition"
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
||||
self.doormode = False
|
||||
|
||||
def GetResources(self):
|
||||
@@ -653,6 +210,17 @@ class _CommandWindow:
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
return
|
||||
|
||||
# Try to detect an object to use as a window type - TODO we must make this safer
|
||||
|
||||
elif obj.Shape.Solids and (Draft.getType(obj) not in ["Wall","Structure","Roof"]):
|
||||
# we consider the selected object as a type
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Window"))
|
||||
FreeCADGui.addModule("Arch")
|
||||
FreeCADGui.doCommand("Arch.makeWindow(FreeCAD.ActiveDocument."+obj.Name+")")
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
return
|
||||
|
||||
# interactive mode
|
||||
if hasattr(FreeCAD,"DraftWorkingPlane"):
|
||||
FreeCAD.DraftWorkingPlane.setup()
|
||||
@@ -1029,22 +597,11 @@ class _Window(ArchComponent.Component):
|
||||
# mark host to recompute so it can detect this object
|
||||
host.touch()
|
||||
if prop in ["Width","Height","Frame"]:
|
||||
if obj.Base and hasattr(obj.Base,"Constraints"):
|
||||
if prop == "Height":
|
||||
if obj.Height.Value > 0:
|
||||
for c in obj.Base.Constraints:
|
||||
if c.Name == "Height":
|
||||
obj.Base.setDatum(c.Name,obj.Height.Value)
|
||||
elif prop == "Width":
|
||||
if obj.Width.Value > 0:
|
||||
for c in obj.Base.Constraints:
|
||||
if c.Name == "Width":
|
||||
obj.Base.setDatum(c.Name,obj.Width.Value)
|
||||
elif prop == "Frame":
|
||||
if obj.Frame.Value > 0:
|
||||
for c in obj.Base.Constraints:
|
||||
if "Frame" in c.Name:
|
||||
obj.Base.setDatum(c.Name,obj.Frame.Value)
|
||||
if obj.Base:
|
||||
if hasattr(obj.Base,"Constraints") and (prop in [c.Name for c in obj.Base.Constraints]):
|
||||
val = getattr(obj,prop).Value
|
||||
if val > 0:
|
||||
obj.Base.setDatum(prop,val)
|
||||
else:
|
||||
ArchComponent.Component.onChanged(self,obj,prop)
|
||||
|
||||
@@ -1272,8 +829,9 @@ class _Window(ArchComponent.Component):
|
||||
elif not obj.WindowParts:
|
||||
if not obj.Base.Shape.isNull():
|
||||
base = obj.Base.Shape.copy()
|
||||
if not DraftGeomUtils.isNull(pl):
|
||||
base.Placement = base.Placement.multiply(pl)
|
||||
# obj placement is already added by applyShape() below
|
||||
#if not DraftGeomUtils.isNull(pl):
|
||||
# base.Placement = base.Placement.multiply(pl)
|
||||
else:
|
||||
print("Arch: Bad formatting of window parts definitions")
|
||||
|
||||
@@ -1311,8 +869,11 @@ class _Window(ArchComponent.Component):
|
||||
if hasattr(obj.Subvolume,'Shape'):
|
||||
if not obj.Subvolume.Shape.isNull():
|
||||
sh = obj.Subvolume.Shape.copy()
|
||||
pl = FreeCAD.Placement(sh.Placement)
|
||||
pl = pl.multiply(obj.Placement)
|
||||
if plac:
|
||||
sh.Placement = plac
|
||||
pl = pl.multiply(plac)
|
||||
sh.Placement = pl
|
||||
return sh
|
||||
|
||||
# getting extrusion depth
|
||||
@@ -1366,7 +927,7 @@ class _Window(ArchComponent.Component):
|
||||
f = base.Shape.Wires[obj.HoleWire-1]
|
||||
|
||||
if not f:
|
||||
if Draft.isClone(obj,"Window"):
|
||||
if Draft.isClone(obj,"Window"):
|
||||
# check original HoleWire then
|
||||
if orig.HoleWire > 0:
|
||||
if orig.HoleWire <= len(base.Shape.Wires):
|
||||
@@ -1487,8 +1048,6 @@ class _ViewProviderWindow(ArchComponent.ViewProviderComponent):
|
||||
if self.areDifferentColors(obj.ViewObject.DiffuseColor,obj.CloneOf.ViewObject.DiffuseColor) or force:
|
||||
obj.ViewObject.DiffuseColor = obj.CloneOf.ViewObject.DiffuseColor
|
||||
return
|
||||
if not obj.WindowParts:
|
||||
return
|
||||
if not obj.Shape:
|
||||
return
|
||||
if not obj.Shape.Solids:
|
||||
@@ -1499,25 +1058,23 @@ class _ViewProviderWindow(ArchComponent.ViewProviderComponent):
|
||||
base = obj.ViewObject.ShapeColor
|
||||
for i in range(len(solids)):
|
||||
ccol = None
|
||||
if len(obj.WindowParts) > i*5:
|
||||
if obj.WindowParts and len(obj.WindowParts) > i*5:
|
||||
# WindowParts-based window
|
||||
name = obj.WindowParts[(i*5)]
|
||||
mtype = obj.WindowParts[(i*5)+1]
|
||||
if hasattr(obj,"Material"):
|
||||
if obj.Material:
|
||||
if hasattr(obj.Material,"Materials"):
|
||||
if obj.Material.Names:
|
||||
mat = None
|
||||
if name in obj.Material.Names:
|
||||
mat = obj.Material.Materials[obj.Material.Names.index(name)]
|
||||
elif mtype in obj.Material.Names:
|
||||
mat = obj.Material.Materials[obj.Material.Names.index(mtype)]
|
||||
if mat:
|
||||
if 'DiffuseColor' in mat.Material:
|
||||
if "(" in mat.Material['DiffuseColor']:
|
||||
ccol = tuple([float(f) for f in mat.Material['DiffuseColor'].strip("()").split(",")])
|
||||
if ccol and ('Transparency' in mat.Material):
|
||||
t = float(mat.Material['Transparency'])/100.0
|
||||
ccol = (ccol[0],ccol[1],ccol[2],t)
|
||||
ccol = self.getSolidMaterial(obj,name,mtype)
|
||||
elif obj.Base and hasattr(obj.Base,"Shape"):
|
||||
# Type-based window: obj.Base furnishes the window solids
|
||||
sol1 = self.getSolidSignature(solids[i])
|
||||
# here we look for all the ways to retrieve a name for each
|
||||
# solid. Currently we look for similar solids in the
|
||||
if hasattr(obj.Base,"Group"):
|
||||
for child in obj.Base.Group:
|
||||
if hasattr(child,"Shape") and child.Shape and child.Shape.Solids:
|
||||
sol2 = self.getSolidSignature(child.Shape)
|
||||
if sol1 == sol2:
|
||||
ccol = self.getSolidMaterial(obj,child.Label)
|
||||
break
|
||||
if not ccol:
|
||||
typeidx = (i*5)+1
|
||||
if typeidx < len(obj.WindowParts):
|
||||
@@ -1531,6 +1088,32 @@ class _ViewProviderWindow(ArchComponent.ViewProviderComponent):
|
||||
if self.areDifferentColors(colors,obj.ViewObject.DiffuseColor) or force:
|
||||
obj.ViewObject.DiffuseColor = colors
|
||||
|
||||
def getSolidSignature(self,solid):
|
||||
|
||||
"""Returns a tuple defining as uniquely as possible a solid"""
|
||||
|
||||
return (solid.ShapeType,solid.Volume,solid.Area,solid.Length)
|
||||
|
||||
def getSolidMaterial(self,obj,name,mtype=None):
|
||||
|
||||
ccol = None
|
||||
if hasattr(obj,"Material"):
|
||||
if obj.Material:
|
||||
if hasattr(obj.Material,"Materials"):
|
||||
if obj.Material.Names:
|
||||
mat = None
|
||||
if name in obj.Material.Names:
|
||||
mat = obj.Material.Materials[obj.Material.Names.index(name)]
|
||||
elif mtype and (mtype in obj.Material.Names):
|
||||
mat = obj.Material.Materials[obj.Material.Names.index(mtype)]
|
||||
if mat:
|
||||
if 'DiffuseColor' in mat.Material:
|
||||
if "(" in mat.Material['DiffuseColor']:
|
||||
ccol = tuple([float(f) for f in mat.Material['DiffuseColor'].strip("()").split(",")])
|
||||
if ccol and ('Transparency' in mat.Material):
|
||||
t = float(mat.Material['Transparency'])/100.0
|
||||
ccol = (ccol[0],ccol[1],ccol[2],t)
|
||||
return ccol
|
||||
|
||||
class _ArchWindowTaskPanel:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user