-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathelementlib.py
executable file
·241 lines (215 loc) · 7.98 KB
/
elementlib.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
# --------------------------------------------------------------------------
# Blendyn -- file elementlib.py
# Copyright (C) 2015 -- 2021 Andrea Zanoni -- [email protected]
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This file is part of Blendyn, add-on script for Blender.
#
# Blendyn is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Blendyn 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Blendyn. If not, see <http://www.gnu.org/licenses/>.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------
import bpy
from mathutils import *
from math import *
from bpy.types import Operator, Panel
from bpy.props import *
import ntpath, os, csv, math
from collections import namedtuple
import logging
from .aerolib import *
from .angularjlib import *
from .axialrotjlib import *
from .beamlib import *
from .beamsliderlib import *
from .bodylib import *
from .brakejlib import *
from .carjlib import *
from .clampjlib import *
from .defdispjlib import *
from .distjlib import *
from .drivejlib import *
from .forcelib import *
from .gimbaljlib import *
from .inlinejlib import *
from .inplanejlib import *
from .linearjlib import *
from .modallib import *
from .prismjlib import *
from .revjlib import *
from .rodjlib import *
from .shell4lib import *
from .membrane4lib import *
from .sphjlib import *
from .totjlib import *
from .utilslib import *
## Function that parses the single row of the .log file and stores
# the element definition in elems
def parse_elements(context, jnt_type, rw):
objects = context.scene.objects
ed = context.scene.mbdyn.elems
joint_types = {
"aero0": parse_aero0,
"aero2": parse_aero2,
"aero3": parse_aero3,
"beam2": parse_beam2,
"beam3": parse_beam3,
"beamslider": parse_beam_slider,
"body": parse_body,
"cardanohinge": parse_cardano_hinge,
"cardanopin": parse_cardano_pin,
"clamp": parse_clamp,
"deformabledisplacementjoint": parse_deformable_displacement,
"modal": parse_modal,
"revolutehinge": parse_revolute_hinge,
"revolutepin": parse_revolute_pin,
"revoluterotation": parse_revolute_rot,
"rod": parse_rod,
# "rod bezier": parse_rod_bezier,
"shell4" : parse_shell4,
"membrane4" : parse_membrane4,
"sphericalhinge": parse_spherical_hinge,
"spericalpin": parse_spherical_pin,
"structural absolute force": parse_structural_absolute_force,
"structural absolute couple": parse_structural_absolute_couple,
"structural follower force": parse_structural_follower_force,
"structural follower couple": parse_structural_follower_couple,
"totaljoint": parse_total,
"totalpinjoint": parse_total_pin,
"prismatic": parse_prismatic,
"inplane": parse_inplane,
"inline": parse_inline,
"axialrotation": parse_axialrot,
"distance": parse_distance,
"gimbalrotation": parse_gimbal,
"brake": parse_brake,
"linearvelocity": parse_linearvelocity,
"linearacceleration": parse_linearacceleration,
"angularvelocity": parse_angularvelocity,
"angularacceleration": parse_angularacceleration,
"drivedisplacement": parse_drive_displacement
}
try:
ret_val = joint_types[jnt_type](rw, ed)
except KeyError as kerr:
message = "BLENDYN::parse_elements(): " \
+ "Element type " + jnt_type \
+ " not implemented yet. Skipping..."
print(message)
logging.warning(message)
ret_val = True
pass
return ret_val
# -----------------------------------------------------------
# end of parse_elements() function
## Displays "generic" element infos in the tools panel
def elem_info_draw(elem, layout):
nd = bpy.context.scene.mbdyn.nodes
col = layout.column(align=True)
row = layout.row()
col = row.column()
kk = 0
for elnode in elem.nodes:
kk = kk + 1
for node in nd:
if node.int_label == elnode.int_label:
col.prop(node, "int_label", text = "Node " + str(kk) + " ID")
col.prop(node, "string_label", text = "Node " + str(kk) + " label")
col.prop(node, "blender_object", text = "Node " + str(kk) + " Object")
col.enabled = False
kk = 0
for off in elem.offsets:
kk = kk + 1
row = layout.row()
row.label(text = "offset " + str(kk))
col = layout.column(align = True)
col.prop(off, "value", text = "", slider = False)
kk = 0
for rotoff in elem.rotoffsets:
kk = kk + 1
row = layout.row()
row.label(text = "orientation offset " + str(kk))
col = layout.column(align = True)
col.prop(rotoff, "value", text = "", slider = False)
# -----------------------------------------------------------
# end of elem_info_draw() function
# App handler to update the configuration of deformable elements
# after the location of the nodes has been updated
@persistent
def update_elements(scene):
ed = scene.mbdyn.elems
eu = scene.mbdyn.elems_to_update
for elem in eu:
element = ed[elem.name]
eval(ed[elem.name].update + "(element, True)")
# Blender 2.8 way of updating the scene
dg = bpy.context.evaluated_depsgraph_get()
dg.update()
bpy.app.handlers.frame_change_post.append(update_elements)
# Retrieves the types of elements present in the scene and populates
# the list to be shown in the Scene panel
def get_elems_types(self, context):
mbs = context.scene.mbdyn
ed = mbs.elems
elem_types = list()
for elem in ed:
if elem.type not in elem_types:
elem_types.append(elem.type)
return [(etype, etype, "%s elements"%etype) for etype in elem_types]
## Utility functions
def fmin(x):
min = x[0]
loc = 0
for idx in range(1, len(x)):
if x[idx] < min:
min = x[idx]
loc = idx
return (min, loc)
# -----------------------------------------------------------
# end of fmin function
def fmax(x):
max = x[0]
loc = 0
for idx in range(1, len(x)):
if x[idx] > max:
max = x[idx]
loc = idx
return (max, loc)
# -----------------------------------------------------------
# end of fmax function
## Bevel object panel, for curves
class BLENDYN_PT_bevel(bpy.types.Panel):
""" Bevel section panel in data properties """
bl_label = "Curve section"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'data'
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
ed = context.scene.mbdyn.elems
curve = context.curve
layout = self.layout
col = layout.column()
# Types of elements for which the panel is useful
eltypes = {'beam2', 'beam3', 'rodj'}
try:
if ed[context.object.name].type in eltypes:
col.operator(BLENDYN_OT_load_section.bl_idname, text="Load profile (Selig)")
if ed[context.object.name].type == 'beam3':
col.operator(BLENDYN_OT_update_beam3.bl_idname, text="Update configuration")
except KeyError:
pass
# -----------------------------------------------------------
# end of BLENDYN_PT_bevel class