PySimultan 0.4.19__py3-none-any.whl → 0.4.21__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
PySimultan2/__about__.py CHANGED
@@ -1 +1 @@
1
- version = '0.4.19'
1
+ version = '0.4.21'
@@ -307,27 +307,6 @@ class ComponentDictionary(SimultanObject):
307
307
  component_policy = 'subcomponent' # component add policy of the content/parameter/property, 'reference'
308
308
  # or 'subcomponent'
309
309
 
310
- type_setter_fcn_lookup_dict = {None: lambda x: None,
311
- SimComponent: set_property_to_sim_component,
312
- SimultanObject: set_property_to_sim_component,
313
- SimDoubleParameter: set_property_to_parameter,
314
- SimIntegerParameter: set_property_to_parameter,
315
- SimStringParameter: set_property_to_parameter,
316
- SimBoolParameter: set_property_to_parameter,
317
- SimEnumParameter: set_property_to_parameter,
318
- int: set_property_to_parameter,
319
- float: set_property_to_parameter,
320
- str: set_property_to_parameter,
321
- bool: set_property_to_parameter,
322
- FileInfo: set_property_to_file_info,
323
- list: set_property_to_list,
324
- tuple: set_property_to_list,
325
- set: set_property_to_list,
326
- dict: set_property_to_dict,
327
- ComponentList: set_property_to_list,
328
- np.ndarray: set_property_to_value_field,
329
- pd.DataFrame: set_property_to_value_field}
330
-
331
310
  _taxonomy_map = TaxonomyMap(taxonomy_name='Dictionaries',
332
311
  taxonomy_key='Dictionaries',
333
312
  taxonomy_entry_name='ComponentDict',
@@ -377,12 +356,15 @@ class ComponentDictionary(SimultanObject):
377
356
 
378
357
  if kwargs.get('check_dict', True) and comp_dict is not None and key in object.__getattribute__(self,
379
358
  '_dict').keys():
380
- return object.__getattribute__(self, '_dict')[key]
359
+ return object.__getattribute__(self, '_dict').get(key, None)
381
360
  else:
382
361
  # data_model = config.default_data_model
383
362
  # obj = get_component_taxonomy_entry(self._wrapped_obj, key)
384
363
  # if obj is not None:
385
364
  # val = get_obj_value(obj, data_model=self._data_model, object_mapper=self._object_mapper)
365
+ data_model = self._data_model
366
+ object_mapper = self._object_mapper
367
+ wrapped_obj = self._wrapped_obj
386
368
 
387
369
  if key in self._taxonomy_map.parameter_taxonomy_entry_dict.keys():
388
370
  text_or_key = self._taxonomy_map.parameter_taxonomy_entry_dict[key]
@@ -397,22 +379,22 @@ class ComponentDictionary(SimultanObject):
397
379
  text_or_key = content.text_or_key
398
380
 
399
381
  try:
400
- components = list(self._wrapped_obj.Components.Items)
382
+ components = list(wrapped_obj.Components.Items)
401
383
  val = next((get_obj_value(x.Component,
402
- data_model=self._data_model,
403
- object_mapper=self._object_mapper) for x in components if
384
+ data_model=data_model,
385
+ object_mapper=object_mapper) for x in components if
404
386
  x.Slot.SlotBase.Target.Key == text_or_key), None)
405
387
  if val is None:
406
- ref_components = list(self._wrapped_obj.ReferencedComponents.Items)
388
+ ref_components = list(wrapped_obj.ReferencedComponents.Items)
407
389
  val = next((get_obj_value(x.Target,
408
- data_model=self._data_model,
409
- object_mapper=self._object_mapper) for x in ref_components
390
+ data_model=data_model,
391
+ object_mapper=object_mapper) for x in ref_components
410
392
  if x.Slot.SlotBase.Target.Key == text_or_key), None)
411
393
  if val is None:
412
- parameters = list(self._wrapped_obj.Parameters.Items)
394
+ parameters = list(wrapped_obj.Parameters.Items)
413
395
  val = next((get_obj_value(x,
414
- data_model=self._data_model,
415
- object_mapper=self._object_mapper) for x in parameters if
396
+ data_model=data_model,
397
+ object_mapper=object_mapper) for x in parameters if
416
398
  x.NameTaxonomyEntry.TextOrKey == text_or_key), None)
417
399
 
418
400
  except Exception as e:
@@ -420,8 +402,8 @@ class ComponentDictionary(SimultanObject):
420
402
  raise ValueError(f'Could not get value for key {key} ({text_or_key}) in {self}:\n{e}')
421
403
 
422
404
  self._dict[key] = get_obj_value(val,
423
- data_model=self._data_model,
424
- object_mapper=self._object_mapper)
405
+ data_model=data_model,
406
+ object_mapper=object_mapper)
425
407
  return self._dict[key]
426
408
 
427
409
  def __setitem__(self, key, value):
@@ -467,21 +449,13 @@ class ComponentDictionary(SimultanObject):
467
449
  keep=[])
468
450
  return
469
451
 
470
- if isinstance(value, (list, tuple, set, ComponentList)):
471
- setter_fcn = set_property_to_list
472
- elif isinstance(value, SimultanObject):
473
- setter_fcn = set_property_to_sim_component
474
- else:
475
- setter_fcn = self.type_setter_fcn_lookup_dict.get(type(value), set_property_to_unknown_type)
452
+ from .type_setter_lookup import type_setter_fcn_lookup_dict
453
+ setter_fcn = type_setter_fcn_lookup_dict.get(type(value), set_property_to_unknown_type)
476
454
 
477
455
  setter_fcn(*fcn_arg_list)
478
456
  item = self.__getitem__(key, check_dict=False)
479
457
 
480
- # self._object_mapper.create_python_object(self._wrapped_obj)
481
- #
482
- # if isinstance(value, ):
483
-
484
- self._dict[key] = self.__getitem__(key, check_dict=False)
458
+ self._dict[key] = item
485
459
 
486
460
  def __delitem__(self, key):
487
461
  self[key] = None
@@ -512,7 +486,7 @@ class ComponentDictionary(SimultanObject):
512
486
  data_model=self._data_model,
513
487
  object_mapper=self._object_mapper)
514
488
  for ref_component in self._wrapped_obj.ReferencedComponents.Items:
515
- comp_dict[ref_component.Slot.SlotBase.Target.Name] = get_obj_value(ref_component.Target,
489
+ comp_dict[ref_component.Slot.SlotBase.Target.Key] = get_obj_value(ref_component.Target,
516
490
  data_model=self._data_model,
517
491
  object_mapper=self._object_mapper)
518
492
  for ref_asset in self._wrapped_obj.ReferencedAssets.Items:
@@ -0,0 +1,62 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+
4
+ from .utils import (SimComponent, SimultanObject, SimDoubleParameter, SimIntegerParameter, SimStringParameter,
5
+ SimBoolParameter, SimEnumParameter, SimMultiValueField3D, SimMultiValueBigTable, FileInfo,
6
+ set_property_to_sim_component, set_property_to_parameter, set_property_to_value_field,
7
+ set_property_to_file_info, set_property_to_list, set_property_to_dict)
8
+
9
+ from .default_types import ComponentList, ComponentDictionary
10
+
11
+ from SIMULTAN.Data.Components import (ComponentWalker, SimComponent, SimBoolParameter, SimDoubleParameter,
12
+ SimEnumParameter, SimIntegerParameter, SimStringParameter, ComponentMapping,
13
+ SimSlot, SimComponentVisibility, SimChildComponentEntry, SimDefaultSlots,
14
+ SimParameterOperations, SimComponentReference)
15
+
16
+
17
+ lookup_dict = {None: lambda x: None,
18
+ SimComponent: set_property_to_sim_component,
19
+ SimultanObject: set_property_to_sim_component,
20
+ SimDoubleParameter: set_property_to_parameter,
21
+ SimIntegerParameter: set_property_to_parameter,
22
+ SimStringParameter: set_property_to_parameter,
23
+ SimBoolParameter: set_property_to_parameter,
24
+ SimEnumParameter: set_property_to_parameter,
25
+ SimMultiValueField3D: set_property_to_value_field,
26
+ SimMultiValueBigTable: set_property_to_value_field,
27
+ int: set_property_to_parameter,
28
+ float: set_property_to_parameter,
29
+ str: set_property_to_parameter,
30
+ bool: set_property_to_parameter,
31
+ FileInfo: set_property_to_file_info,
32
+ list: set_property_to_list,
33
+ tuple: set_property_to_list,
34
+ set: set_property_to_list,
35
+ dict: set_property_to_dict,
36
+ ComponentDictionary: set_property_to_dict,
37
+ ComponentList: set_property_to_list,
38
+ np.ndarray: set_property_to_value_field,
39
+ pd.DataFrame: set_property_to_value_field}
40
+
41
+
42
+ class TypeSetterFcnLookupDict(object):
43
+
44
+ def __getitem__(self, item: type):
45
+ if item in lookup_dict:
46
+ return lookup_dict[item]
47
+ elif SimultanObject in item.__bases__:
48
+ return set_property_to_sim_component
49
+ else:
50
+ return None
51
+
52
+ def get(self,
53
+ item: type,
54
+ default=None):
55
+ val = self.__getitem__(item)
56
+ if val is None:
57
+ return default
58
+ else:
59
+ return val
60
+
61
+
62
+ type_setter_fcn_lookup_dict = TypeSetterFcnLookupDict()
PySimultan2/utils.py CHANGED
@@ -1,10 +1,16 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import sys
4
+ import traceback
5
+
3
6
  from enum import Enum
4
7
  from weakref import WeakSet
5
8
  import numpy as np
6
9
  import pandas as pd
7
10
  from typing import List as TypeList, Union, Optional, Type, Any, TYPE_CHECKING
11
+
12
+ from System import ArgumentException, NotSupportedException
13
+
8
14
  from SIMULTAN.Data.Components import (ComponentWalker, SimComponent, SimBoolParameter, SimDoubleParameter,
9
15
  SimEnumParameter, SimIntegerParameter, SimStringParameter, ComponentMapping,
10
16
  SimSlot, SimComponentVisibility, SimChildComponentEntry, SimDefaultSlots,
@@ -417,8 +423,31 @@ def add_sub_component(comp: SimComponent,
417
423
  new_slot = SimSlot(sub_comp.Slots[0].Target, str(slot_extension))
418
424
 
419
425
  entry = SimChildComponentEntry(new_slot, sub_comp)
426
+
427
+ error = None
428
+ new_slot_extension = 0
429
+
420
430
  if entry not in comp.Components.Items:
421
- comp.Components.InsertItem(len(comp.Components.Items), entry)
431
+ try:
432
+ comp.Components.InsertItem(len(comp.Components.Items), entry)
433
+ except (ArgumentException, NotSupportedException) as e:
434
+ error = e
435
+
436
+ while error is not None and new_slot_extension < 100:
437
+ try:
438
+ try:
439
+ slot_extension += 1
440
+ if slot_extension > 1000:
441
+ break
442
+ except Exception as e:
443
+ new_slot_extension += 1
444
+ slot_extension = slot_extension + f'_{new_slot_extension}'
445
+ new_slot = SimSlot(sub_comp.Slots[0].Target, str(slot_extension))
446
+ entry = SimChildComponentEntry(new_slot, sub_comp)
447
+ comp.Components.InsertItem(len(comp.Components.Items), entry)
448
+ error = None
449
+ except (ArgumentException, NotSupportedException) as e:
450
+ error = e
422
451
  return True
423
452
 
424
453
 
@@ -727,7 +756,8 @@ type_convert_dict = {SimComponent: get_sim_component_value,
727
756
  SimEnumParameter: get_parameter_value,
728
757
  ResourceEntry: get_resource_entry_value,
729
758
  ContainedResourceFileEntry: get_resource_entry_value,
730
- LinkedResourceFileEntry: get_resource_entry_value}
759
+ LinkedResourceFileEntry: get_resource_entry_value
760
+ }
731
761
 
732
762
 
733
763
  def get_obj_value(obj: Union[SimComponent, SimDoubleParameter, SimIntegerParameter, SimStringParameter,
@@ -738,6 +768,8 @@ def get_obj_value(obj: Union[SimComponent, SimDoubleParameter, SimIntegerParamet
738
768
 
739
769
  if obj is None:
740
770
  return
771
+ elif isinstance(obj, (int, float, str)):
772
+ return obj
741
773
  elif type(obj) in type_convert_dict.keys():
742
774
  return type_convert_dict[type(obj)](obj, data_model=data_model, object_mapper=object_mapper)
743
775
  else:
@@ -1281,7 +1313,6 @@ def set_property_to_dict(value: dict,
1281
1313
  slot_extension=slot_extension,
1282
1314
  slot=slot)
1283
1315
 
1284
-
1285
1316
  def add_properties(prop_name: str,
1286
1317
  text_or_key: str,
1287
1318
  content: Content,
@@ -1302,30 +1333,6 @@ def add_properties(prop_name: str,
1302
1333
 
1303
1334
  from .default_types import ComponentList, ComponentDictionary
1304
1335
 
1305
- type_setter_fcn_lookup_dict = {None: lambda x: None,
1306
- SimComponent: set_property_to_sim_component,
1307
- SimultanObject: set_property_to_sim_component,
1308
- SimDoubleParameter: set_property_to_parameter,
1309
- SimIntegerParameter: set_property_to_parameter,
1310
- SimStringParameter: set_property_to_parameter,
1311
- SimBoolParameter: set_property_to_parameter,
1312
- SimEnumParameter: set_property_to_parameter,
1313
- SimMultiValueField3D: set_property_to_value_field,
1314
- SimMultiValueBigTable: set_property_to_value_field,
1315
- int: set_property_to_parameter,
1316
- float: set_property_to_parameter,
1317
- str: set_property_to_parameter,
1318
- bool: set_property_to_parameter,
1319
- FileInfo: set_property_to_file_info,
1320
- list: set_property_to_list,
1321
- tuple: set_property_to_list,
1322
- set: set_property_to_list,
1323
- dict: set_property_to_dict,
1324
- ComponentDictionary: set_property_to_dict,
1325
- ComponentList: set_property_to_list,
1326
- np.ndarray: set_property_to_value_field,
1327
- pd.DataFrame: set_property_to_value_field}
1328
-
1329
1336
  class Empty:
1330
1337
  pass
1331
1338
 
@@ -1381,15 +1388,8 @@ def add_properties(prop_name: str,
1381
1388
  if isinstance(value, UnresolvedObject):
1382
1389
  return
1383
1390
 
1384
- if isinstance(value, (list, tuple, set, ComponentList)):
1385
- setter_fcn = set_property_to_list
1386
- elif isinstance(value, SimultanObject):
1387
- setter_fcn = set_property_to_sim_component
1388
- elif isinstance(value, dict):
1389
- setter_fcn = set_property_to_dict
1390
- else:
1391
- setter_fcn = type_setter_fcn_lookup_dict.get(type(value), set_property_to_unknown_type)
1392
-
1391
+ from .type_setter_lookup import type_setter_fcn_lookup_dict
1392
+ setter_fcn = type_setter_fcn_lookup_dict.get(type(value), set_property_to_unknown_type)
1393
1393
  setter_fcn(*fcn_arg_list)
1394
1394
 
1395
1395
  setx.__taxonomy__ = taxonomy
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: PySimultan
3
- Version: 0.4.19
3
+ Version: 0.4.21
4
4
  Project-URL: Documentation, https://github.com/Bühler Maximilian/PySimultan2#readme
5
5
  Project-URL: Issues, https://github.com/Bühler Maximilian/PySimultan2/issues
6
6
  Project-URL: Source, https://github.com/Bühler Maximilian/PySimultan2
@@ -38,6 +38,9 @@ Description-Content-Type: text/markdown
38
38
 
39
39
  - [Installation](#installation)
40
40
  - [License](#license)
41
+ - [Usage](#usage)
42
+ - [FreeCAD support](#freecad-support)
43
+ - [Change Log](#change-log)
41
44
 
42
45
  ## Installation
43
46
 
@@ -82,5 +85,8 @@ C:\Program Files\FreeCAD
82
85
 
83
86
  # Change Log
84
87
 
88
+ ## [0.4.20] - 2024-07-01
89
+ - Fixed Bug in nested dictionary creation
90
+
85
91
  ## [0.4.19] - 2024-07-01
86
92
  - Refactored dictionaries
@@ -1,13 +1,14 @@
1
- PySimultan2/__about__.py,sha256=Z9VH1opxusXUHCDJeWUusEwptfCLQBbFMXR9ph5aJS4,20
1
+ PySimultan2/__about__.py,sha256=BcY2O7QAmjmLO_2EMS3Qs445TkjNXhtVzC4D0HWZntw,20
2
2
  PySimultan2/__init__.py,sha256=cabTN1Oz8xtFM31ouBKg5lwLqW5vtexDP669PYyNLnA,3224
3
3
  PySimultan2/data_model.py,sha256=xosu5TAfgsrxwyhd6SfHFp4Wvo1_YtxdHsSuZmuNVJU,27022
4
- PySimultan2/default_types.py,sha256=hE_JyKcykL3bSqpeEj-zSA04oLJ6UnsGR17SfdjkXNo,25578
4
+ PySimultan2/default_types.py,sha256=v8kfoR-csDlYEDUBk9rM89LcoH2Yyox7PbO1y2zPsmc,23862
5
5
  PySimultan2/files.py,sha256=8F1QC9nTsTSrCpu5vGx1xGx-7UgkDwoICXau_5j7UzI,12725
6
6
  PySimultan2/multi_values.py,sha256=ZFXlTLuZo32x7_7diYAp2XEjp5uwgHLgNOzN7v74-5I,13650
7
7
  PySimultan2/object_mapper.py,sha256=yYVGeIzkdYvNMqW_kz9NwVxi6IJWGAqLS8CrYzW2oEg,13210
8
8
  PySimultan2/simultan_object.py,sha256=P047pfjgScysBMIsW7Co63VlzXGnLqGwxjyAEVLh8kg,16917
9
9
  PySimultan2/taxonomy_maps.py,sha256=YXOE-vUan2vLQyk96W728Vw5elBvIwH56tTuRBYeUyQ,8420
10
- PySimultan2/utils.py,sha256=qhF46rCHmI96Hdp9sdHAAkUJtaQxoG6YJu7Hx5IM4Go,62569
10
+ PySimultan2/type_setter_lookup.py,sha256=mCOYAnxNxofPcWUl59axNCFXe1gkilV_yWz2-0MGeGM,2782
11
+ PySimultan2/utils.py,sha256=32pHmzSIITC7WjFsfxmcMxMhHZPsk5K_KtQ5Uwi-pUs,61735
11
12
  PySimultan2/geometry/__init__.py,sha256=nJolTD1i5J8qUkOQa-r3D20aq3Co3sN31Xc0n4wJpJo,248
12
13
  PySimultan2/geometry/geometry_base.py,sha256=nbb9U2W3vFviVLxISLHRi2CVyLEM-3zIKvoZ1uSYs_8,23420
13
14
  PySimultan2/geometry/utils.py,sha256=J25YsK8sso_UL7xRusItQZvyjtvxdOsSPelBQYFABhY,8519
@@ -75,7 +76,7 @@ PySimultan2/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
75
76
  PySimultan2/resources/assimp.dll,sha256=HwfDwXqoPDTFRyoQpA3qmgZoUdFtziJkV5fNtktEZEU,6081536
76
77
  PySimultan2/resources/defaultsettings.xml,sha256=s6Tk1tubLz5UYqXZWpD42EDHzedemRY1nEneoIVcUfg,392
77
78
  PySimultan2/resources/setup.bat,sha256=fjvvYfVM6TalS-QTSiKAbAId5nTsk8kGGo06ba-wWaY,32
78
- pysimultan-0.4.19.dist-info/METADATA,sha256=1uJ2SKZAtUEgv2A_EB35HQMeh0jCfA1AM0PW8EMGW1w,2551
79
- pysimultan-0.4.19.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
80
- pysimultan-0.4.19.dist-info/licenses/LICENSE.txt,sha256=pmSr98k6N005KMojnZxzLGRuRlDjDx3PUrK1lFj53HA,1126
81
- pysimultan-0.4.19.dist-info/RECORD,,
79
+ pysimultan-0.4.21.dist-info/METADATA,sha256=vPm27zwQIfL9aOCtdCIFRu5_FiCCBS5KZ3AoJEsr_nY,2703
80
+ pysimultan-0.4.21.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
81
+ pysimultan-0.4.21.dist-info/licenses/LICENSE.txt,sha256=pmSr98k6N005KMojnZxzLGRuRlDjDx3PUrK1lFj53HA,1126
82
+ pysimultan-0.4.21.dist-info/RECORD,,