-
Notifications
You must be signed in to change notification settings - Fork 0
/
Slab.py
278 lines (255 loc) · 8.94 KB
/
Slab.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 25 14:27:35 2016
@author: vfolomeev
"""
import xml.dom.minidom
import numpy as np
import scipy as sc
import math
import copy
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.cluster import KMeans
from sklearn import preprocessing
import scipy.integrate as spint
from OCC.Display.SimpleGui import init_display
from OCC.gp import *
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.BRepPrimAPI import BRepPrimAPI_MakePrism
#from OCC.BRepPrimAPI import BRepPrimAPI_MakePolygon
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakePolygon
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeFace
from Curve import Curve
from prim import Vector,Line,Arc,Circle
from Wall import Wall
from Floor import Floor
class Slab:
'class part definition'
def __init__(self):
self.name=''
self.normal=Vector()
self.thickness=0
self.curve=Curve()
def getNode(self,node):
nameNodes=node.getElementsByTagName('OID')
self.name=nameNodes[0].firstChild.nodeValue
normNodes=node.getElementsByTagName('Normal')
self.normal=Vector().getNode(normNodes[0])
thicknessNodes=node.getElementsByTagName('TotalThickness')
if len(thicknessNodes)==0: thicknessNodes=node.getElementsByTagName('Thickness')
self.thickness=float(thicknessNodes[0].firstChild.nodeValue)
boundaryNodes=node.getElementsByTagName('Boundary')
if len(boundaryNodes)==0: boundaryNodes=node.getElementsByTagName('Contour')
complexString3dNodes=boundaryNodes[0].getElementsByTagName('ComplexString3d')
if len(complexString3dNodes)==0: complexString3dNodes=node.getElementsByTagName('Contour')
self.curve=Curve().getNode(complexString3dNodes[0])
return self
def center(self):
R1=self.curve.center()
R2=copy.deepcopy(self.normal)
R2.scale(0.5*self.thickness)
return R1+R2
def toWall(self):
w=Wall()
w.name=self.name+'wall'
w.curve.lines.clear()
n=self.normal
deep=self.thickness
l=self.curve.lines
if n.z!=0:
if l[0].dr().mag()>l[1].dr().mag():
line=l[0]
dr=l[2].start-l[0].start
else:
line=l[1]
dr=l[3].start-l[1].start
line=line.translate(dr,0.5)
#line.out()
w.curve.lines.append(line)
w.height=deep
w.thickness=dr.mag()
else:
max=self.maxV()
min=self.minV()
diag=max-min
if diag.x>diag.y:
start=Vector(min.x,(min.y+max.y)/2,min.z)
end=Vector(max.x,(min.y+max.y)/2,min.z)
thick=diag.y
else:
start=Vector((min.x+max.x)/2,min.y,min.z)
end=Vector((min.x+max.x)/2,max.y,min.z)
thick=diag.x
line=Line(start,end)
w.curve.lines.append(line)
w.height=diag.z
w.thickness=thick
return w
def toFloor(self) :
f=Floor()
f.name=self.name+'floor'
n=self.normal
deep=self.thickness
lines=self.curve.lines
f.curve.lines.clear()
newlines1=[]
newlines1.clear()
newlines2=[]
newlines2.clear()
if n.z!=0:
f.curve.lines=copy.deepcopy(lines)
f.thickness=deep
else:
min=self.minV()
dz=self.dR().z
for l in lines:
if l.start.z==min.z and l.end.z==min.z:
newlines1.append(l)
newlines2.append(l.translate(n,deep))
start1=newlines1[len(newlines1)-1].end
end1=newlines2[len(newlines1)-1].end
start2=newlines1[0].start
end2=newlines2[0].start
newlines1.append(Line(start1,end1))
newlines1.extend(newlines2)
newlines1.append(Line(start2,end2))
f.curve.lines.extend(newlines1)
f.thickness=dz
return f
def out(self):
print ("name=",self.name)
print ("normal=")
self.normal.out()
print( " thickness=",self.thickness)
print (" lines=")
for l in self.curve.lines:
l.out()
def draw(self,display,c) :
pol=self.curve.polygon()
if pol!=None:
pol=pol.Wire()
n=copy.copy(self.normal)
n.scale(self.thickness)
n=n.gpV()
face=BRepBuilderAPI_MakeFace(pol,True).Face()
#my_shell = BRepPrimAPI_MakePrism(my_pol,n1).Shape()
prism = BRepPrimAPI_MakePrism(face,n).Shape()
if c==0: color='YELLOW'
elif c==1: color='BLUE'
elif c==2: color='GREEN'
elif c==3: color='BLACK'
elif c==4: color='RED'
elif c==5: color='WHITE'
elif c==6: color='CYAN'
else: color='ORANGE'
display.DisplayColoredShape(prism,color, update=True)
def minV(self) :
minV=copy.deepcopy(self.curve.minV())
n=copy.deepcopy(self.normal)
sign=n.x+n.y+n.z
if sign<0: return minV+n.scale(self.thickness)
else: return minV
def maxV(self) :
maxV=copy.deepcopy(self.curve.maxV())
n=copy.deepcopy(self.normal)
sign=n.x+n.y+n.z
if sign>0: return maxV+n.scale(self.thickness)
else: return maxV
def dR(self) :
return self.maxV()-self.minV()
def isWall(self):
r=self.dR()
n=self.normal
i=0
k=0
b=0
if n.x!=0:b+=1
if n.y!=0:b+=1
if n.z!=0:b+=1
for l in self.curve.lines:
if isinstance(l,Line): i+=1
else: k+=1
if r.z>2*r.y or r.z>2*r.x:
if i==4 and k==0 and b==1:return True
else : return False
else: return False
def isFloor(self):
r=self.dR()
if (self.isWall()==False):
if 2*r.z<r.y or 2*r.z<r.x: return True
else: return False
else : return False
# def isWall(self):
# n=self.normal
# l=self.curve.lines
# if len(l)==4:
# l1=l[1].end-l[0].start
# l2=l[0].end-l[3].start
# if l1.mag()==l2.mag():
# #box
# h=self.thickness
# r1=l[0].dr()
# r2=l[1].dr()
# r=r1+r2
# if (n.x==0 and n.y==0 and n.z!=0):
# Sxy=(r1*r2).mag()
# Sz1=h*r1.mag()
# Sz2=h*r2.mag()
# if Sxy<min(Sz1,Sz2): return True
# else: return False
# elif (n.x==0 and n.y!=0 and n.z==0):
# Sxz=(r1*r2).mag()
# Sxy=h*math.fabs(r.x)
# Szy=h*math.fabs(r.z)
# if Sxy<min(Sxz,Szy): return True
# else: return False
# elif (n.x!=0 and n.y==0 and n.z==0):
# Szy=(r1*r2).mag()
# Sxz=h*math.fabs(r.z)
# Sxy=h*math.fabs(r.y)
# if Sxy<min(Sxz,Szy): return True
# else: return False
# else: return False
#
#
#
#
#
# else: return False
# else: return False
# def isFloor(self):
# n=self.normal
# l=self.curve.lines
# if len(l)==4:
# l1=l[1].end-l[0].start
# l2=l[0].end-l[3].start
# if l1.mag()==l2.mag():
# #box
# h=self.thickness
# r1=l[0].dr()
# r2=l[1].dr()
# r=r1+r2
# if (n.x==0 and n.y==0 and n.z!=0):
# Sxy=(r1*r2).mag()
# Sz1=h*r1.mag()
# Sz2=h*r2.mag()
# if Sxy>max(Sz1,Sz2): return True
# else: return False
# elif (n.x==0 and n.y!=0 and n.z==0):
# if Vector.dot(r1,Vector(0,0,1))==0 or Vector.dot(r2,Vector(0,0,1))==0:
# Sxz=(r1*r2).mag()
# Sxy=h*math.fabs(r.x)
# Szy=h*math.fabs(r.z)
# if Sxy>max(Sxz,Szy): return True
# else: return False
# else: return False
# elif (n.x!=0 and n.y==0 and n.z==0):
# if Vector.dot(r1,Vector(0,0,1))==0 or Vector.dot(r2,Vector(0,0,1))==0:
# Szy=(r1*r2).mag()
# Sxz=h*math.fabs(r.z)
# Sxy=h*math.fabs(r.y)
# if Sxy>max(Sxz,Szy): return True
# else: return False
# else: return False
# else: return False