Skip to content

Commit 737f03e

Browse files
authored
Merge pull request #383 from Dlubal-Software/heet-centerOfGravityAndObjectInfo
Heet center of gravity and object info
2 parents 4960d1a + a9bedf6 commit 737f03e

3 files changed

Lines changed: 244 additions & 91 deletions

File tree

Lines changed: 189 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,219 @@
11
from RFEM.initModel import Model
2-
from RFEM.enums import ObjectTypes, SelectedObjectInformation
32

4-
class ObjectInformation():
3+
def GetCOGTableParameters(results):
4+
'''
5+
Returns dict with attributes: base, row, and error.
6+
'''
7+
params = {'base': [], 'row': [], 'error': None}
8+
9+
if not results:
10+
return params
11+
12+
if results[0][0]:
13+
for section in results[0]:
14+
params['base'] = list(set(params['base'] + section.__keylist__))
15+
if 'rows' in section.__keylist__ and 'row' in section['rows']:
16+
for row in section['rows']['row']:
17+
params['row'] = list(set(params['row'] + row.__keylist__))
18+
else:
19+
params['error'] = "Result table doesn't have attribute 'rows' or 'row'."
20+
21+
return params
22+
23+
def ConvertCOGInfoToListOfDct(cog):
24+
'''
25+
Args:
26+
cog (dict): Dictionary object of center of gravity and objects information
27+
Returns:
28+
List of dictionaries. Each dictionary corresponds to one line in center of gravity and objects information table.
29+
'''
30+
if not cog:
31+
return ''
32+
33+
params = GetCOGTableParameters(cog)
34+
lstOfDct = []
35+
36+
for c in cog[0]:
37+
dct1 = {}
38+
if 'title' in params['base']:
39+
try:
40+
dct1['title'] = float(c['title'])
41+
except:
42+
try:
43+
dct1['title'] = c['title']
44+
except:
45+
pass
46+
47+
if 'rows' in params['base']:
48+
49+
for row in c['rows'][0]:
50+
dct = {}
51+
dct.update(dct1)
52+
for y in params['row']:
53+
try:
54+
dct[y] = float(row[y])
55+
except:
56+
try:
57+
dct[y] = row[y]
58+
except:
59+
pass
60+
lstOfDct.append(dct)
61+
62+
if params['error']:
63+
return lstOfDct.append({'error': params['error']})
64+
65+
return lstOfDct
66+
67+
class ObjectsInfo():
568

669
@staticmethod
7-
def CentreOfGravity(
8-
object_type = ObjectTypes.E_OBJECT_TYPE_MEMBER,
9-
parent_no = 0,
10-
no: int = 1,
11-
coord: str = 'X'):
70+
def AllInfo(objects: list = None,
71+
model = Model):
1272
'''
13-
This function returns the centre of gravity position (X, Y or Z) for a selected object.
1473
Args:
15-
type (enum): Object Type
16-
parent_no (int): Object Parent Number
17-
Note:
18-
(1) A geometric object has, in general, a parent_no = 0
19-
(2) The parent_no parameter becomes significant for example with loads
20-
no (int): The Object Tag
21-
coord (str): Desired global basis vector component of the Centre of Gravity (i.e. X, Y or Z)
74+
objects (list of lists): List of Selected Objects
75+
objects = [[ObjectTypes enumeration, Object number], ...] (e.g. [[ObjectTypes.E_OBJECT_TYPE_MEMBER,1], [ObjectTypes.E_OBJECT_TYPE_MEMBER, 2]])
76+
model (class, optional): Model instance
77+
78+
Returns:
79+
List of dictionaries.
2280
'''
23-
result = ObjectInformation.__BuildResultsArray(object_type, no, parent_no)
24-
if coord == 'X' or coord.lstrip().rstrip().upper() == 'X':
25-
return result['section'][0].rows[0][0].value
26-
elif coord == 'Y' or coord.lstrip().rstrip().upper() == 'Y':
27-
return result['section'][0].rows[0][1].value
28-
elif coord == 'Z' or coord.lstrip().rstrip().upper() == 'Z':
29-
return result['section'][0].rows[0][2].value
81+
82+
if objects:
83+
cog_objects = {'center_of_gravity_objects' : []}
84+
85+
for obj in objects:
86+
cog_objects["center_of_gravity_objects"].append({
87+
"type": obj[0].name,
88+
"no": obj[1]
89+
})
90+
return ConvertCOGInfoToListOfDct(model.clientModel.service.get_center_of_gravity_and_objects_info(cog_objects))
91+
3092
else:
31-
raise Exception ('WARNING: The desired Coordinate input not requested. Please provide either "X", "Y" or "Z"')
93+
raise AssertionError('WARNING! Please give at lease one object.')
3294

3395
@staticmethod
34-
def MemberInformation(
35-
no: int = 1,
36-
information = SelectedObjectInformation.LENGTH):
96+
def CenterofGravity(objects: list = None,
97+
model = Model):
3798
'''
38-
This function returns further information associated with a member.
3999
Args:
40-
no (int): Member Tag
41-
information (enum): Desired Information (Length / Volume / Mass)
100+
objects (list of lists): List of Selected Objects
101+
objects = [[ObjectTypes enumeration, Object number], ...] (e.g. [[ObjectTypes.E_OBJECT_TYPE_MEMBER,1], [ObjectTypes.E_OBJECT_TYPE_MEMBER, 2]])
102+
model (class, optional): Model instance
103+
104+
Returns:
105+
List of dictionary.
42106
'''
43-
if information.name == 'AREA':
44-
raise Exception ('WARNING: Area information is only relevant for Surface and Volume Information.')
45107

46-
result = ObjectInformation.__BuildResultsArray(ObjectTypes.E_OBJECT_TYPE_MEMBER, no, 0)
47-
return ObjectInformation.__AreaVolumeMassInformationLength(information, result, 2)
108+
allList = ObjectsInfo.AllInfo(objects, model)
109+
cog_Info = {}
110+
for item in allList:
111+
if item['title'] == 'Center of Gravity':
112+
cog_Info[item.get('name')] = item.get('value')
113+
114+
return cog_Info
48115

49116
@staticmethod
50-
def SurfaceInformation(
51-
no: int = 1,
52-
information = SelectedObjectInformation.AREA):
117+
def AllSelectedObjectsInfo(objects: list = None,
118+
model = Model):
53119
'''
54-
This function returns further information associated with a surface.
55120
Args:
56-
no (int): Surface Tag
57-
information (enum): Desired Information (Area / Volume / Mass)
121+
objects (list of lists): List of Selected Objects
122+
objects = [[ObjectTypes enumeration, Object number], ...] (e.g. [[ObjectTypes.E_OBJECT_TYPE_MEMBER,1], [ObjectTypes.E_OBJECT_TYPE_MEMBER, 2]])
123+
model (class, optional): Model instance
124+
125+
Returns:
126+
List of dictionary.
58127
'''
59-
if information.name == 'LENGTH':
60-
raise Exception ('WARNING: Length information is only relevant for Member Information.')
61128

62-
result = ObjectInformation.__BuildResultsArray(ObjectTypes.E_OBJECT_TYPE_SURFACE, no, 0)
63-
return ObjectInformation.__AreaVolumeMassInformationLength(information, result, 3)
129+
allList = ObjectsInfo.AllInfo(objects, model)
130+
cog_Info = {}
131+
for item in allList:
132+
if item['title'] == 'Information About All Selected Objects':
133+
cog_Info[item.get('name')] = item.get('value')
134+
135+
return cog_Info
64136

65137
@staticmethod
66-
def SolidInformation(
67-
no: int = 1,
68-
information = SelectedObjectInformation.AREA):
138+
def MembersInfo(objects: list = None,
139+
model = Model):
69140
'''
70-
This function returns further information associated with a solid.
71141
Args:
72-
no (int): Solid Tag
73-
information (enum): Desired Information (Area / Volume / Mass)
142+
objects (list of lists): List of Selected Objects
143+
objects = [[ObjectTypes enumeration, Object number], ...] (e.g. [[ObjectTypes.E_OBJECT_TYPE_MEMBER,1], [ObjectTypes.E_OBJECT_TYPE_MEMBER, 2]])
144+
model (class, optional): Model instance
145+
146+
Returns:
147+
List of dictionary.
74148
'''
75-
if information.name == 'LENGTH':
76-
raise Exception ('WARNING: Length information is only relevant for Member Information.')
77149

78-
result = ObjectInformation.__BuildResultsArray(ObjectTypes.E_OBJECT_TYPE_SOLID, no, 0)
79-
return ObjectInformation.__AreaVolumeMassInformationLength(information,result, 4)
150+
allList = ObjectsInfo.AllInfo(objects, model)
151+
cog_Info = {}
152+
for item in allList:
153+
if item['title'] == 'Information About Members':
154+
cog_Info[item.get('name')] = item.get('value')
155+
156+
return cog_Info
80157

81158
@staticmethod
82-
def __BuildResultsArray(object_type, no, parent_no, model = Model):
83-
elements = model.clientModel.factory.create('ns0:array_of_get_center_of_gravity_and_objects_info_elements_type')
84-
clientObject = model.clientModel.factory.create('ns0:get_center_of_gravity_and_objects_info_element_type')
85-
clientObject.parent_no = parent_no
86-
clientObject.no = no
87-
clientObject.type = object_type.name
88-
elements.element.append(clientObject)
89-
result = model.clientModel.service.get_center_of_gravity_and_objects_info(elements)
90-
result = model.clientModel.dict(result)
91-
return result
159+
def SurfacesInfo(objects: list = None,
160+
model = Model):
161+
'''
162+
Args:
163+
objects (list of lists): List of Selected Objects
164+
objects = [[ObjectTypes enumeration, Object number], ...] (e.g. [[ObjectTypes.E_OBJECT_TYPE_MEMBER,1], [ObjectTypes.E_OBJECT_TYPE_MEMBER, 2]])
165+
model (class, optional): Model instance
166+
167+
Returns:
168+
List of dictionary.
169+
'''
170+
171+
allList = ObjectsInfo.AllInfo(objects, model)
172+
cog_Info = {}
173+
for item in allList:
174+
if item['title'] == 'Information About Surfaces':
175+
cog_Info[item.get('name')] = item.get('value')
176+
177+
return cog_Info
178+
179+
@staticmethod
180+
def SolidsInfo(objects: list = None,
181+
model = Model):
182+
'''
183+
Args:
184+
objects (list of lists): List of Selected Objects
185+
objects = [[ObjectTypes enumeration, Object number], ...] (e.g. [[ObjectTypes.E_OBJECT_TYPE_MEMBER,1], [ObjectTypes.E_OBJECT_TYPE_MEMBER, 2]])
186+
model (class, optional): Model instance
187+
188+
Returns:
189+
List of dictionary.
190+
'''
191+
192+
allList = ObjectsInfo.AllInfo(objects, model)
193+
cog_Info = {}
194+
for item in allList:
195+
if item['title'] == 'Information About Solids':
196+
cog_Info[item.get('name')] = item.get('value')
197+
198+
return cog_Info
92199

93200
@staticmethod
94-
def __AreaVolumeMassInformationLength(information, result, row_key):
95-
if information.name == "LENGTH" or information.name == "AREA":
96-
return result['section'][row_key].rows[0][0].value
97-
elif information.name == "VOLUME":
98-
return result['section'][row_key].rows[0][1].value
99-
elif information.name == "MASS":
100-
return result['section'][row_key].rows[0][2].value
201+
def EnvelopeSize(objects: list = None,
202+
model = Model):
203+
'''
204+
Args:
205+
objects (list of lists): List of Selected Objects
206+
objects = [[ObjectTypes enumeration, Object number], ...] (e.g. [[ObjectTypes.E_OBJECT_TYPE_MEMBER,1], [ObjectTypes.E_OBJECT_TYPE_MEMBER, 2]])
207+
model (class, optional): Model instance
208+
209+
Returns:
210+
List of dictionary.
211+
'''
212+
213+
allList = ObjectsInfo.AllInfo(objects, model)
214+
cog_Info = {}
215+
for item in allList:
216+
if item['title'] == 'Envelope Size':
217+
cog_Info[item.get('name')] = item.get('value')
218+
219+
return cog_Info

RFEM/enums.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,13 +1104,6 @@ class AnchorageEndAnchorType(Enum):
11041104
ANCHORAGE_TYPE_STRAIGHT, ANCHORAGE_TYPE_STRAIGHT_WITH_TRANSVERSE_BAR, ANCHORAGE_TYPE_STRAIGHT_WITH_TWO_TRANSVERSE_BARS = range(7)
11051105

11061106

1107-
class SelectedObjectInformation(Enum):
1108-
'''
1109-
Information About Members | Enum
1110-
'''
1111-
LENGTH, VOLUME, MASS, AREA = range(4)
1112-
1113-
11141107
class GlobalAxesOrientationType(Enum):
11151108
'''
11161109
Model Settings and Options Global Axes Orientation Type

0 commit comments

Comments
 (0)