PySimultan 0.5.3__py3-none-any.whl → 0.5.5__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.5.3'
1
+ version = '0.5.5'
PySimultan2/data_model.py CHANGED
@@ -43,7 +43,7 @@ from System.Security import *
43
43
  from System.Security.Cryptography import *
44
44
  from System.Text import *
45
45
 
46
- from .files import add_tag_to_resource, FileInfo as PythonFileInfo
46
+ from .files import add_tag_to_resource, FileInfo as PythonFileInfo, DirectoryInfo as PythonDirectoryInfo
47
47
 
48
48
 
49
49
  if TYPE_CHECKING:
@@ -165,6 +165,11 @@ class DataModel:
165
165
  def assets(self):
166
166
  return self.project_data_manager.AssetManager.Resources
167
167
 
168
+ @property
169
+ def file_directories(self):
170
+ return [PythonDirectoryInfo(resource_entry=x,
171
+ data_model=self) for x in self.project_data_manager.AssetManager.Resources if isinstance(x, ResourceDirectoryEntry)]
172
+
168
173
  @property
169
174
  def models(self) -> dict[int, 'GeometryModel']:
170
175
  """
@@ -503,7 +508,7 @@ class DataModel:
503
508
 
504
509
  def add_empty_resource(self,
505
510
  filename: str,
506
- target_dir: Union[ResourceDirectoryEntry, DirectoryInfo, str] = None) -> ResourceEntry:
511
+ target_dir: Union[ResourceDirectoryEntry, FileInfo, str] = None) -> ResourceEntry:
507
512
  """
508
513
  Add an empty resource to the project
509
514
  :param filename: name of the new resource
@@ -519,7 +524,7 @@ class DataModel:
519
524
 
520
525
  if isinstance(target_dir, ResourceDirectoryEntry):
521
526
  target_dir = target_dir.CurrentFullPath
522
- if isinstance(target_dir, DirectoryInfo):
527
+ if isinstance(target_dir, FileInfo):
523
528
  target_dir = target_dir.FullPath
524
529
 
525
530
  return self.project.AddEmptyResource(FileInfo(
@@ -571,7 +576,7 @@ class DataModel:
571
576
  target_dir = DirectoryInfo(target_dir)
572
577
  elif isinstance(target_dir, ResourceDirectoryEntry):
573
578
  target_dir = DirectoryInfo(target_dir.CurrentFullPath)
574
- elif isinstance(target_dir, DirectoryInfo):
579
+ elif isinstance(target_dir, FileInfo):
575
580
  pass
576
581
 
577
582
  resource = self.project.CopyResourceAsContainedFileEntry(filename,
PySimultan2/files.py CHANGED
@@ -69,7 +69,7 @@ def add_tag_to_resource(resource: Union[ResourceFileEntry, ContainedResourceFile
69
69
 
70
70
 
71
71
  def add_asset_to_component(comp: [SimComponent, SimultanObject],
72
- asset: Union[ResourceFileEntry, ContainedResourceFileEntry],
72
+ asset: Union[ResourceFileEntry, ContainedResourceFileEntry, ResourceDirectoryEntry],
73
73
  content_id: str = '',
74
74
  tag: SimTaxonomyEntry = None) -> Asset:
75
75
  """
@@ -127,8 +127,14 @@ def create_asset_from_string(filename: str,
127
127
  with open(filepath, 'w') as f:
128
128
  f.write(content)
129
129
 
130
- resource = data_model.add_resource(filepath,
131
- target_dir=target_dir)
130
+ if target_dir is not None:
131
+ if isinstance(target_dir, DirectoryInfo):
132
+ target_dir = target_dir.full_path
133
+
134
+ resource = data_model.add_resource(filepath,
135
+ target_dir=target_dir)
136
+ else:
137
+ resource = data_model.add_resource(filepath)
132
138
 
133
139
  if tag is not None:
134
140
  add_tag_to_resource(resource,
@@ -225,6 +231,22 @@ class MetaMock(type):
225
231
  return obj
226
232
 
227
233
 
234
+ class DirectoryInfoMetaMock(type):
235
+
236
+ def __call__(cls, *args, **kwargs):
237
+ resource_entry: Optional[ResourceDirectoryEntry] = kwargs.get('resource_entry', None)
238
+ if resource_entry is not None and hasattr(resource_entry, 'Key'):
239
+ obj = cls._cls_instances.get(resource_entry.Key, None)
240
+ if obj is not None:
241
+ return obj
242
+
243
+ obj = cls.__new__(cls)
244
+ obj.__init__(*args, **kwargs)
245
+ if obj.resource_entry is not None:
246
+ cls._cls_instances[obj.resource_entry.Key] = obj
247
+ return obj
248
+
249
+
228
250
  class FileInfo(object, metaclass=MetaMock):
229
251
 
230
252
  _cls_instances = {}
@@ -302,6 +324,11 @@ class FileInfo(object, metaclass=MetaMock):
302
324
  except Exception as e:
303
325
  return None
304
326
 
327
+ @property
328
+ def directory(self) -> DirectoryInfo:
329
+ return DirectoryInfo(resource_entry=self.resource_entry.Parent,
330
+ data_model=self.data_model)
331
+
305
332
  @property
306
333
  def resource_entry(self) -> Union[ResourceFileEntry, ContainedResourceFileEntry, None]:
307
334
  if self._resource_entry is None:
@@ -471,3 +498,136 @@ class FileInfo(object, metaclass=MetaMock):
471
498
  "$key": str(self.key)
472
499
  }
473
500
  }
501
+
502
+
503
+ class DirectoryInfo(object, metaclass=DirectoryInfoMetaMock):
504
+
505
+ _cls_instances = {}
506
+
507
+ @classmethod
508
+ def get_by_key(cls, key: int) -> Optional[DirectoryInfo]:
509
+ return cls._cls_instances.get(key, None)
510
+
511
+ def __init__(self,
512
+ path: Optional[str] = None,
513
+ helper_file: Optional[FileInfo] = None,
514
+ resource_entry: Optional[ResourceDirectoryEntry] = None,
515
+ *args,
516
+ **kwargs):
517
+
518
+ self._resource_entry: Optional[ResourceDirectoryEntry] = None
519
+ self._helper_file: Optional[FileInfo] = None
520
+ self.data_model: Optional[DataModel] = kwargs.get('data_model', None)
521
+ self.path: str = path
522
+
523
+ self.resource_entry = resource_entry
524
+ self.helper_file = helper_file
525
+
526
+ @property
527
+ def tags(self) -> List[SimTaxonomyEntry]:
528
+ return list(self.resource_entry.Tags)
529
+
530
+ @property
531
+ def full_path(self) -> str:
532
+ return self.resource_entry.CurrentFullPath
533
+
534
+ @property
535
+ def relative_path(self) -> str:
536
+ return self.resource_entry.CurrentRelativePath
537
+
538
+ @property
539
+ def helper_file(self) -> Optional[FileInfo]:
540
+ if self._helper_file is None:
541
+ self._helper_file = self.add_file('__dir_helper_file__')
542
+
543
+ return self._helper_file
544
+
545
+ @helper_file.setter
546
+ def helper_file(self, value):
547
+ self._helper_file = value
548
+
549
+ @property
550
+ def resource_entry(self) -> Optional[ResourceDirectoryEntry]:
551
+ if self._resource_entry is None:
552
+ if self.data_model is None:
553
+ logger.warning(
554
+ f'No data model provided. Using default data model: {config.get_default_data_model().id}.')
555
+ self.data_model = config.get_default_data_model()
556
+ if self.data_model is not None:
557
+ self.resource_entry = self.data_model.create_resource_directory(self.path)
558
+ self._cls_instances[self.resource_entry.Key] = self
559
+ self.path = self.resource_entry.CurrentFullPath
560
+ return self._resource_entry
561
+
562
+ @resource_entry.setter
563
+ def resource_entry(self, value):
564
+
565
+ orig_value = self._resource_entry
566
+ self._resource_entry = value
567
+
568
+ if self._resource_entry is None:
569
+ if orig_value is not None:
570
+ del self._cls_instances[orig_value.Key]
571
+ return
572
+
573
+ if self.key is not None:
574
+ if value is not None:
575
+ self._cls_instances[value.Key] = self
576
+ else:
577
+ del self._cls_instances[self._resource_entry.Key]
578
+ self._resource_entry = value
579
+
580
+ @property
581
+ def parent(self) -> Optional[ResourceDirectoryEntry]:
582
+ if self.resource_entry.Parent is not None:
583
+ if self.resource_entry.Parent.Key in self._cls_instances:
584
+ return self.get_by_key(self.resource_entry.Parent.Key)
585
+ return DirectoryInfo(resource_entry=self.resource_entry.Parent)
586
+ else:
587
+ return self.resource_entry.Parent
588
+
589
+ @property
590
+ def sub_directories(self) -> List[DirectoryInfo]:
591
+ return [DirectoryInfo(resource_entry=entry,
592
+ data_model=self.data_model) for entry in self.resource_entry.Children if isinstance(entry, ResourceDirectoryEntry)]
593
+
594
+ @property
595
+ def files(self) -> List[FileInfo]:
596
+ return [FileInfo(resource_entry=entry,
597
+ data_model=self.data_model) for entry in self.resource_entry.Children if isinstance(entry,
598
+ (
599
+ ResourceFileEntry,
600
+ ContainedResourceFileEntry)
601
+ ) and entry.Name != '__dir_helper_file__'
602
+ ]
603
+
604
+ @property
605
+ def key(self) -> Optional[int]:
606
+ if self.resource_entry is not None:
607
+ return self.resource_entry.Key
608
+ else:
609
+ return None
610
+
611
+ def add_sub_directory(self, name: str) -> DirectoryInfo:
612
+ return DirectoryInfo(path=os.path.join(self.resource_entry.current_relative_path, name),
613
+ data_model=self.data_model)
614
+
615
+ def add_file(self,
616
+ filename: str,
617
+ content: Optional[str] = None) -> FileInfo:
618
+
619
+ if content is not None:
620
+ return FileInfo.from_string(filename=filename,
621
+ content=content,
622
+ target_dir=self.resource_entry,
623
+ data_model=self.data_model)
624
+ else:
625
+ new_resource = self.data_model.add_empty_resource(filename=os.path.join(self.full_path, filename))
626
+ return FileInfo(resource_entry=new_resource,
627
+ data_model=self.data_model)
628
+
629
+ def add_tag(self, tag: SimTaxonomyEntry) -> None:
630
+ add_tag_to_resource(self.resource_entry, tag)
631
+
632
+ def __repr__(self):
633
+ return f'DirectoryInfo(key:{self.key}, hash: {hash(self)}; {self.full_path})'
@@ -5,9 +5,9 @@ import inspect
5
5
  import enum
6
6
 
7
7
  from .utils import (SimComponent, SimDoubleParameter, SimIntegerParameter, SimStringParameter,
8
- SimBoolParameter, SimEnumParameter, SimMultiValueField3D, SimMultiValueBigTable, FileInfo,
8
+ SimBoolParameter, SimEnumParameter, SimMultiValueField3D, SimMultiValueBigTable, FileInfo, DirectoryInfo,
9
9
  set_property_to_sim_component, set_property_to_parameter, set_property_to_value_field,
10
- set_property_to_file_info, set_property_to_list, set_property_to_dict)
10
+ set_property_to_file_info, set_property_to_list, set_property_to_dict, set_property_to_directory_info)
11
11
 
12
12
  from .simultan_object import SimultanObject, MetaMock
13
13
 
@@ -36,6 +36,7 @@ class TypeSetterFcnLookupDict(object):
36
36
  str: set_property_to_parameter,
37
37
  bool: set_property_to_parameter,
38
38
  FileInfo: set_property_to_file_info,
39
+ DirectoryInfo: set_property_to_directory_info,
39
40
  list: set_property_to_list,
40
41
  tuple: set_property_to_list,
41
42
  set: set_property_to_list,
PySimultan2/utils.py CHANGED
@@ -20,12 +20,13 @@ from SIMULTAN.Data.Components import SimDefaultSlotKeys
20
20
  from SIMULTAN.Data.MultiValues import (SimMultiValueField3D, SimMultiValueField3DParameterSource, SimMultiValueBigTable,
21
21
  SimMultiValueBigTableHeader, SimMultiValueBigTableParameterSource)
22
22
 
23
- from SIMULTAN.Data.Assets import ResourceEntry, ResourceFileEntry, ContainedResourceFileEntry, Asset, LinkedResourceFileEntry
23
+ from SIMULTAN.Data.Assets import (ResourceEntry, ResourceFileEntry, ContainedResourceFileEntry, Asset,
24
+ LinkedResourceFileEntry, ResourceDirectoryEntry)
24
25
  from SIMULTAN.Data.Geometry import Face, Edge, Vertex, Volume
25
26
 
26
27
  from .multi_values import (simultan_multi_value_field_3d_to_numpy, set_parameter_to_value_field,
27
28
  create_field_parameter, simultan_multi_value_big_table_to_pandas)
28
- from .files import FileInfo, remove_asset_from_component, add_asset_to_component
29
+ from .files import FileInfo, remove_asset_from_component, add_asset_to_component, DirectoryInfo
29
30
 
30
31
  if TYPE_CHECKING:
31
32
  from .default_types import ComponentList, ComponentDictionary
@@ -767,10 +768,22 @@ def get_sim_double_parameter_value(obj: SimDoubleParameter,
767
768
 
768
769
  def get_resource_entry_value(obj: ResourceEntry,
769
770
  data_model: DataModel = None,
770
- object_mapper: PythonMapper = None) -> FileInfo:
771
- return FileInfo(file_path=obj.File.FullPath,
772
- resource_entry=obj,
773
- data_model=data_model)
771
+ object_mapper: PythonMapper = None) -> Union[FileInfo, DirectoryInfo]:
772
+ if isinstance(obj, (ResourceFileEntry, ContainedResourceFileEntry, LinkedResourceFileEntry)):
773
+
774
+ if obj.Name == '__dir_helper_file__':
775
+ return DirectoryInfo(file_path=obj.Parent.CurrentFullPath,
776
+ resource_entry=obj.Parent,
777
+ helper_file=obj,
778
+ data_model=data_model)
779
+
780
+ return FileInfo(file_path=obj.File.FullPath,
781
+ resource_entry=obj,
782
+ data_model=data_model)
783
+ elif isinstance(obj, ResourceDirectoryEntry):
784
+ return DirectoryInfo(file_path=obj.CurrentFullPath,
785
+ resource_entry=obj,
786
+ data_model=data_model)
774
787
 
775
788
 
776
789
  type_convert_dict = {SimComponent: get_sim_component_value,
@@ -780,13 +793,16 @@ type_convert_dict = {SimComponent: get_sim_component_value,
780
793
  SimBoolParameter: get_parameter_value,
781
794
  SimEnumParameter: get_parameter_value,
782
795
  ResourceEntry: get_resource_entry_value,
796
+ ResourceFileEntry: get_resource_entry_value,
797
+ ResourceDirectoryEntry: get_resource_entry_value,
783
798
  ContainedResourceFileEntry: get_resource_entry_value,
784
799
  LinkedResourceFileEntry: get_resource_entry_value
785
800
  }
786
801
 
787
802
 
788
803
  def get_obj_value(obj: Union[SimComponent, SimDoubleParameter, SimIntegerParameter, SimStringParameter,
789
- SimBoolParameter, SimEnumParameter, ResourceEntry, ContainedResourceFileEntry, None],
804
+ SimBoolParameter, SimEnumParameter, ResourceEntry, ResourceFileEntry, ContainedResourceFileEntry,
805
+ ResourceDirectoryEntry, None],
790
806
  data_model: DataModel,
791
807
  object_mapper: PythonMapper) -> Union[SimultanObject, int, float, str, FileInfo, None, pd.DataFrame,
792
808
  np.ndarray]:
@@ -1161,6 +1177,44 @@ def set_property_to_file_info(value: FileInfo,
1161
1177
  tag=taxonomy_entry)
1162
1178
 
1163
1179
 
1180
+ def set_property_to_directory_info(value: DirectoryInfo,
1181
+ component: SimultanObject,
1182
+ prop_name: str,
1183
+ taxonomy_entry: SimTaxonomyEntry,
1184
+ slot_extension: Union[str, int, float],
1185
+ component_idx: int = None,
1186
+ ref_component_idx: int = None,
1187
+ parameter_idx: int = None,
1188
+ ref_asset_idx: int = None,
1189
+ content: Content = None) -> None:
1190
+
1191
+ remove_prop_from_sim_component(component=component,
1192
+ component_idx=component_idx,
1193
+ ref_component_idx=ref_component_idx,
1194
+ parameter_idx=parameter_idx,
1195
+ ref_asset_idx=ref_asset_idx,
1196
+ keep=['ref_asset_idx'])
1197
+
1198
+ value.data_model = component._data_model
1199
+
1200
+ if ref_asset_idx is not None:
1201
+ asset = component._wrapped_obj.ReferencedAssets.Items[ref_asset_idx]
1202
+
1203
+ if hasattr(value, 'resource_entry'):
1204
+ if asset.Resource.Key == value.resource_entry.Key:
1205
+ return
1206
+ elif asset.Resource.CurrentFullPath == str(value.file_path):
1207
+ return
1208
+
1209
+ remove_asset_from_component(component._wrapped_obj, asset)
1210
+ ref_asset_idx = None
1211
+
1212
+ add_asset_to_component(component._wrapped_obj,
1213
+ value.helper_file.resource_entry,
1214
+ '0',
1215
+ tag=taxonomy_entry)
1216
+
1217
+
1164
1218
  def set_property_to_parameter(value: Union[int, float, str, Enum, bool],
1165
1219
  component: SimultanObject,
1166
1220
  prop_name: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: PySimultan
3
- Version: 0.5.3
3
+ Version: 0.5.5
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
@@ -1,15 +1,15 @@
1
1
  PySimultan2/CHANGELOG.md,sha256=LeVHBC6dGDwDwgXipNrwgvgews9QkyjsqtYa_jiLMm0,217
2
- PySimultan2/__about__.py,sha256=lhcqEYOdmvV5zQ4d-IvOu1pQl5tG1hLWIoyYZuVEboM,19
2
+ PySimultan2/__about__.py,sha256=vzEzJZ6JrU1XuEoNmBm-CHsw0z44e2mWFvuJveRe8YM,19
3
3
  PySimultan2/__init__.py,sha256=PGVR1uhY01dF5tHyad-znURUZ_LVB95vsjId2BT0aJM,3245
4
- PySimultan2/data_model.py,sha256=V6myRSzIQMjJVCjHwNSIWu6FdBsUKdfGxHuLkEsrgi0,33864
4
+ PySimultan2/data_model.py,sha256=YYtfcR6jvGztng6Be8Vw9FQ02cPkl8ATHTZMoIu1ABQ,34140
5
5
  PySimultan2/default_types.py,sha256=K-Eka5BCKk8DT3HU5761Ym_-ZFmu1_Dro0zW0LVGoHA,27157
6
- PySimultan2/files.py,sha256=UWSI04x9ANpFbYbqTHo_UwSnBzVjuNDK_MlmIh1S_bY,15988
6
+ PySimultan2/files.py,sha256=BCETl4M8qedw7Bjt8QXvY6Rl3U6Lou36XqPY2ST1o9Q,22447
7
7
  PySimultan2/multi_values.py,sha256=ZFXlTLuZo32x7_7diYAp2XEjp5uwgHLgNOzN7v74-5I,13650
8
8
  PySimultan2/object_mapper.py,sha256=_SQye38NmIr4m_-X9CuvUJnVDBmjmUDdPH2bnaxpzKY,18546
9
9
  PySimultan2/simultan_object.py,sha256=akaSUZZWIVfwx1wT5EdOgRR2UeShUthX-LE2Uk6w8CQ,19058
10
10
  PySimultan2/taxonomy_maps.py,sha256=abMB2RSKEaliW-Ewegq-Inq9npHeOD1VVrMYoKJAlC0,8762
11
- PySimultan2/type_setter_lookup.py,sha256=WtopIR2Z3v3wNFtqmeVorH7ZUbKoJYTTe5I3vfQuKUI,3404
12
- PySimultan2/utils.py,sha256=R1W3F0gkmYgrb6Lhsa_-7C8tNSoxGhQM-cCdxhgRmLc,64042
11
+ PySimultan2/type_setter_lookup.py,sha256=px92E-BlnvY-11F-F7L7cOwbE1_L8FQVqi-23nJi5j4,3518
12
+ PySimultan2/utils.py,sha256=TOrMMTh6n63VgjEGVX6j67_jhUx4ImFI39X61g0OegQ,66692
13
13
  PySimultan2/geometry/__init__.py,sha256=nJolTD1i5J8qUkOQa-r3D20aq3Co3sN31Xc0n4wJpJo,248
14
14
  PySimultan2/geometry/geometry_base.py,sha256=nbb9U2W3vFviVLxISLHRi2CVyLEM-3zIKvoZ1uSYs_8,23420
15
15
  PySimultan2/geometry/utils.py,sha256=J25YsK8sso_UL7xRusItQZvyjtvxdOsSPelBQYFABhY,8519
@@ -75,7 +75,7 @@ PySimultan2/resources/assimp.dll,sha256=HwfDwXqoPDTFRyoQpA3qmgZoUdFtziJkV5fNtktE
75
75
  PySimultan2/resources/componentmanager.user,sha256=hrzr1US4pqkFnLHXcvPkvrgGd7QvlxaV8mhS6fuikEs,760
76
76
  PySimultan2/resources/defaultsettings.xml,sha256=s6Tk1tubLz5UYqXZWpD42EDHzedemRY1nEneoIVcUfg,392
77
77
  PySimultan2/resources/setup.bat,sha256=fjvvYfVM6TalS-QTSiKAbAId5nTsk8kGGo06ba-wWaY,32
78
- pysimultan-0.5.3.dist-info/METADATA,sha256=uHZ4LgdGra5hED0t2NNP_UuEdLHOiol5fZjrRQaAAn4,2665
79
- pysimultan-0.5.3.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
80
- pysimultan-0.5.3.dist-info/licenses/LICENSE.txt,sha256=pmSr98k6N005KMojnZxzLGRuRlDjDx3PUrK1lFj53HA,1126
81
- pysimultan-0.5.3.dist-info/RECORD,,
78
+ pysimultan-0.5.5.dist-info/METADATA,sha256=vqTp0MfBHnJUxHyFF_DCVeAXKICkXCsiVvuRINKvZXw,2665
79
+ pysimultan-0.5.5.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
80
+ pysimultan-0.5.5.dist-info/licenses/LICENSE.txt,sha256=pmSr98k6N005KMojnZxzLGRuRlDjDx3PUrK1lFj53HA,1126
81
+ pysimultan-0.5.5.dist-info/RECORD,,