forked from yorikvanhavre/BIM_Workbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBimCurtainWall.py
137 lines (115 loc) · 5.55 KB
/
BimCurtainWall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# -*- coding: utf8 -*-
#***************************************************************************
#* *
#* Copyright (c) 2019 Yorik van Havre <[email protected]> *
#* *
#* 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 *
#* *
#***************************************************************************
"""This module contains FreeCAD commands for the BIM workbench"""
import os,FreeCAD,FreeCADGui,DraftTools,DraftVecUtils
from PySide import QtCore,QtGui
from DraftTools import translate
def QT_TRANSLATE_NOOP(ctx,txt): return txt # dummy function for the QT translator
class BIM_CurtainWall:
def GetResources(self):
return {'Pixmap' : os.path.join(os.path.dirname(__file__),"icons","BIM_CurtainWall.svg"),
'MenuText': QT_TRANSLATE_NOOP("BIM_CurtainWall", "Curtain wall"),
'ToolTip' : QT_TRANSLATE_NOOP("BIM_CurtainWall", "Builds a curtain wall from a selected object"),
'Accel': 'C,W'}
def Activated(self):
import Part
edges = []
for sel in FreeCADGui.Selection.getSelectionEx():
for sub in sel.SubObjects:
if insinstance(sub,Part.Edge):
edges.append(sub)
if edges:
makeCurtainWall(edges)
def sortedge(edge):
vdir = FreeCAD.Vector(1,0,0)
proj = DraftVecUtils.project(edge.CenterOfMass,vdir)
if proj.getAngle(vdir) < 1:
return proj.Length
else:
return -proj.Length
def makeFlatFace(mobile=[],fixed=[],vert=False):
import Part,DraftGeomUtils
if not fixed:
pol = Part.makePolygon(mobile+[mobile[0]])
pol = DraftGeomUtils.flattenWire(pol)
return Part.Face(pol)
elif len(fixed) == 3:
tempf = Part.Face(Part.makePolygon(fixed+[fixed[0]]))
v4 = mobile[0].add(DraftVecUtils.project(tempf.CenterOfMass.sub(mobile[0]),tempf.normalAt(0,0)))
pol = Part.makePolygon([fixed[0],fixed[1],v4,fixed[2],fixed[0]])
pol = DraftGeomUtils.flattenWire(pol)
return Part.Face(pol)
elif len(fixed) == 2:
tp = DraftGeomUtils.findMidpoint(Part.LineSegment(mobile[0],mobile[1]).toShape())
tempf = Part.Face(Part.makePolygon(fixed+[tp,fixed[0]]))
v4 = mobile[0].add(DraftVecUtils.project(tempf.CenterOfMass.sub(mobile[0]),tempf.normalAt(0,0)))
v5 = mobile[1].add(DraftVecUtils.project(tempf.CenterOfMass.sub(mobile[1]),tempf.normalAt(0,0)))
if vert:
pol = Part.makePolygon([fixed[0],v4,v5,fixed[1],fixed[0]])
else:
pol = Part.makePolygon(fixed+[v4,v5,fixed[0]])
pol = DraftGeomUtils.flattenWire(pol)
return Part.Face(pol)
def makeCurtainWall(edges,subdiv=5,detach=False):
import Part
edges = sorted(edges,key=sortedge)
faces = []
p0 = edges[0].Vertexes[0].Point
for i in range(len(edges)-1):
e1 = edges[i]
e2 = edges[i+1]
pts1 = e1.discretize(Number=subdiv)
if pts1[0].sub(p0).Length > pts1[-1].sub(p0).Length:
pts1.reverse()
pts2 = e2.discretize(Number=subdiv)
if pts2[0].sub(p0).Length > pts2[-1].sub(p0).Length:
pts2.reverse()
for j in range(subdiv-1):
p1 = pts1[j]
p2 = pts2[j]
p3 = pts2[j+1]
p4 = pts1[j+1]
if detach:
fac = makeFlatFace(mobile=[p1,p2,p3,p4])
elif (i == 0) and (j == 0):
fac = makeFlatFace(mobile=[p1,p2,p3,p4])
elif i == 0:
p5 = faces[-1].Vertexes[3].Point
p6 = faces[-1].Vertexes[2].Point
fac = makeFlatFace(fixed=[p5,p6],mobile=[p3,p4])
elif j == 0:
p5 = faces[-(subdiv-1)].Vertexes[1].Point
p6 = faces[-(subdiv-1)].Vertexes[2].Point
fac = makeFlatFace(fixed=[p5,p6],mobile=[p2,p3],vert=True)
else:
p5 = faces[-1].Vertexes[3].Point
p6 = faces[-1].Vertexes[2].Point
p7 = faces[-(subdiv-1)].Vertexes[2].Point
fac = makeFlatFace(fixed=[p5,p6,p7],mobile=[p3])
faces.append(fac)
if faces:
if detach:
shell = Part.makeCompound(faces)
else:
shell = Part.makeShell(faces)
Part.show(shell)