PySimultan 0.1.54__py3-none-any.whl → 0.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- PySimultan-0.2.dist-info/LICENSE.txt +17 -0
- PySimultan-0.2.dist-info/METADATA +36 -0
- PySimultan-0.2.dist-info/RECORD +82 -0
- {PySimultan-0.1.54.dist-info → PySimultan-0.2.dist-info}/WHEEL +1 -1
- PySimultan-0.2.dist-info/top_level.txt +1 -0
- {PySimultan → PySimultan2}/__init__.py +11 -6
- PySimultan2/config.py +52 -0
- PySimultan2/data_model.py +713 -0
- PySimultan2/default_types.py +507 -0
- PySimultan2/files.py +371 -0
- PySimultan2/geometry/__init__.py +4 -0
- PySimultan2/geometry/geometry_base.py +654 -0
- PySimultan2/geometry/utils.py +181 -0
- PySimultan2/multi_values.py +277 -0
- PySimultan2/object_mapper.py +200 -0
- PySimultan2/resources/AssimpNet.dll +0 -0
- PySimultan2/resources/AvalonDock.dll +0 -0
- PySimultan2/resources/BruTile.dll +0 -0
- PySimultan2/resources/ClosedXML.dll +0 -0
- PySimultan2/resources/ComponentBuilder.dll +0 -0
- PySimultan/resources/ComponentBuilder.exe.config → PySimultan2/resources/ComponentBuilder.dll.config +6 -2
- PySimultan2/resources/ComponentBuilder.runtimeconfig.json +18 -0
- {PySimultan → PySimultan2}/resources/ComponentBuilder.xml +11877 -6754
- PySimultan2/resources/ControlzEx.dll +0 -0
- PySimultan2/resources/Cyotek.Drawing.BitmapFont.dll +0 -0
- PySimultan2/resources/DocumentFormat.OpenXml.dll +0 -0
- PySimultan2/resources/ExcelNumberFormat.dll +0 -0
- PySimultan2/resources/Fluent.dll +0 -0
- PySimultan2/resources/GeometryViewer.dll +0 -0
- {PySimultan → PySimultan2}/resources/GeometryViewer.xml +2201 -1155
- PySimultan2/resources/HelixToolkit.Core.Wpf.dll +0 -0
- PySimultan2/resources/HelixToolkit.SharpDX.Core.Wpf.dll +0 -0
- PySimultan2/resources/HelixToolkit.SharpDX.Core.dll +0 -0
- PySimultan2/resources/HelixToolkit.dll +0 -0
- PySimultan2/resources/MathNet.Numerics.dll +0 -0
- PySimultan2/resources/Microsoft.AspNetCore.Authorization.dll +0 -0
- PySimultan2/resources/Microsoft.AspNetCore.Metadata.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.DependencyInjection.Abstractions.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.Logging.Abstractions.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.Options.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.Primitives.dll +0 -0
- PySimultan2/resources/Microsoft.WindowsAPICodePack.Shell.dll +0 -0
- PySimultan2/resources/Microsoft.WindowsAPICodePack.dll +0 -0
- PySimultan2/resources/Microsoft.Xaml.Behaviors.dll +0 -0
- PySimultan2/resources/Newtonsoft.Json.Bson.dll +0 -0
- PySimultan2/resources/Newtonsoft.Json.dll +0 -0
- PySimultan2/resources/SIMULTAN.AutoUpdate.Client.dll +0 -0
- PySimultan2/resources/SIMULTAN.AutoUpdate.DataTransferLibrary.dll +0 -0
- PySimultan2/resources/SIMULTAN.AutoUpdate.DataTransferLibrary.dll.config +15 -0
- PySimultan2/resources/SIMULTAN.Lang.dll +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.Lang.xml +5282 -3252
- PySimultan2/resources/SIMULTAN.Plugins.dll +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.Plugins.xml +110 -0
- PySimultan2/resources/SIMULTAN.UI.dll +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.UI.xml +10483 -4937
- PySimultan2/resources/SIMULTAN.dll +0 -0
- PySimultan2/resources/SIMULTAN.xml +34122 -0
- PySimultan2/resources/SharpDX.D3DCompiler.dll +0 -0
- PySimultan2/resources/SharpDX.DXGI.dll +0 -0
- PySimultan2/resources/SharpDX.Direct2D1.dll +0 -0
- PySimultan2/resources/SharpDX.Direct3D11.dll +0 -0
- PySimultan2/resources/SharpDX.Direct3D9.dll +0 -0
- {PySimultan → PySimultan2}/resources/SharpDX.Mathematics.dll +0 -0
- PySimultan2/resources/SharpDX.dll +0 -0
- {PySimultan → PySimultan2}/resources/SitePlanner.dll +0 -0
- {PySimultan → PySimultan2}/resources/SitePlanner.xml +959 -1110
- PySimultan2/resources/Sprache.dll +0 -0
- PySimultan2/resources/System.Data.OleDb.dll +0 -0
- PySimultan2/resources/System.Net.Http.Formatting.dll +0 -0
- PySimultan2/resources/XAMLMarkupExtensions.dll +0 -0
- PySimultan2/resources/assimp.dll +0 -0
- {PySimultan → PySimultan2}/resources/defaultsettings.xml +0 -0
- PySimultan2/simultan_object.py +366 -0
- PySimultan2/taxonomy_maps.py +169 -0
- PySimultan2/utils.py +1383 -0
- PySimultan/config.py +0 -57
- PySimultan/data_model.py +0 -376
- PySimultan/default_types.py +0 -1771
- PySimultan/geo_default_types.py +0 -763
- PySimultan/geometry.py +0 -309
- PySimultan/resources/AssimpNet.dll +0 -0
- PySimultan/resources/AssimpNet.xml +0 -12074
- PySimultan/resources/BruTile.dll +0 -0
- PySimultan/resources/BruTile.xml +0 -1845
- PySimultan/resources/ControlzEx.dll +0 -0
- PySimultan/resources/Cyotek.Drawing.BitmapFont.dll +0 -0
- PySimultan/resources/DXFImportExport.dll +0 -0
- PySimultan/resources/DotSpatial.Projections.xml +0 -5879
- PySimultan/resources/EXCELImportExport.dll +0 -0
- PySimultan/resources/Fluent.dll +0 -0
- PySimultan/resources/Fluent.xml +0 -9103
- PySimultan/resources/GeoJSON.Net.dll +0 -0
- PySimultan/resources/GeometryViewer.Data.dll +0 -0
- PySimultan/resources/GeometryViewer.Data.xml +0 -4443
- PySimultan/resources/GeometryViewer.Shared.dll +0 -0
- PySimultan/resources/GeometryViewer.Shared.xml +0 -588
- PySimultan/resources/GeometryViewer.dll +0 -0
- PySimultan/resources/HelixToolkit.Wpf.SharpDX.dll +0 -0
- PySimultan/resources/HelixToolkit.Wpf.SharpDX.xml +0 -43219
- PySimultan/resources/HelixToolkit.Wpf.dll +0 -0
- PySimultan/resources/HelixToolkit.Wpf.xml +0 -22363
- PySimultan/resources/HelixToolkit.dll +0 -0
- PySimultan/resources/HelixToolkit.xml +0 -144
- PySimultan/resources/ImportLog_SMART_CAMPUS_TU_WIEN_BIBLIOTHEK_20210305_ZONENMODELL_23_11_2021-06_54_54.txt +0 -1
- PySimultan/resources/LibGit2Sharp.dll +0 -0
- PySimultan/resources/LibGit2Sharp.dll.config +0 -4
- PySimultan/resources/LibGit2Sharp.xml +0 -13770
- PySimultan/resources/MathNet.Numerics.dll +0 -0
- PySimultan/resources/MathNet.Numerics.xml +0 -57152
- PySimultan/resources/Microsoft.WindowsAPICodePack.Shell.dll +0 -0
- PySimultan/resources/Microsoft.WindowsAPICodePack.Shell.xml +0 -25496
- PySimultan/resources/Microsoft.WindowsAPICodePack.dll +0 -0
- PySimultan/resources/Microsoft.WindowsAPICodePack.xml +0 -2934
- PySimultan/resources/Newtonsoft.Json.dll +0 -0
- PySimultan/resources/Newtonsoft.Json.xml +0 -11305
- PySimultan/resources/ParameterStructure.dll +0 -0
- PySimultan/resources/ParameterStructure.xml +0 -10750
- PySimultan/resources/SIMULTAN.AutoUpdate.Client.dll +0 -0
- PySimultan/resources/SIMULTAN.DataExchange.dll +0 -0
- PySimultan/resources/SIMULTAN.Lang.dll +0 -0
- PySimultan/resources/SIMULTAN.Legacy.dll +0 -0
- PySimultan/resources/SIMULTAN.Legacy.xml +0 -254
- PySimultan/resources/SIMULTAN.Plugins.dll +0 -0
- PySimultan/resources/SIMULTAN.Project.dll +0 -0
- PySimultan/resources/SIMULTAN.Project.dll.config +0 -11
- PySimultan/resources/SIMULTAN.UI.dll +0 -0
- PySimultan/resources/SIMULTAN.Util.dll +0 -0
- PySimultan/resources/SIMULTAN.Util.xml +0 -3430
- PySimultan/resources/SharpDX.D3DCompiler.dll +0 -0
- PySimultan/resources/SharpDX.D3DCompiler.xml +0 -5897
- PySimultan/resources/SharpDX.DXGI.dll +0 -0
- PySimultan/resources/SharpDX.DXGI.xml +0 -8737
- PySimultan/resources/SharpDX.Direct2D1.dll +0 -0
- PySimultan/resources/SharpDX.Direct2D1.xml +0 -46691
- PySimultan/resources/SharpDX.Direct3D11.dll +0 -0
- PySimultan/resources/SharpDX.Direct3D11.xml +0 -31826
- PySimultan/resources/SharpDX.Direct3D9.dll +0 -0
- PySimultan/resources/SharpDX.Direct3D9.xml +0 -36489
- PySimultan/resources/SharpDX.Mathematics.xml +0 -16449
- PySimultan/resources/SharpDX.dll +0 -0
- PySimultan/resources/Sprache.dll +0 -0
- PySimultan/resources/Sprache.xml +0 -1199
- PySimultan/resources/System.Net.Http.Formatting.dll +0 -0
- PySimultan/resources/System.Net.Http.Formatting.xml +0 -2094
- PySimultan/resources/System.Windows.Interactivity.dll +0 -0
- PySimultan/resources/TalkGit.dll +0 -0
- PySimultan/resources/TalkGit.dll.config +0 -11
- PySimultan/resources/WebServiceConnector.dll +0 -0
- PySimultan/resources/WebServiceConnector.dll.config +0 -11
- PySimultan/resources/XAMLMarkupExtensions.dll +0 -0
- PySimultan/resources/XAMLMarkupExtensions.xml +0 -862
- PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.Aero.dll +0 -0
- PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.Metro.dll +0 -0
- PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.VS2010.dll +0 -0
- PySimultan/resources/Xceed.Wpf.AvalonDock.dll +0 -0
- PySimultan/resources/Xceed.Wpf.Toolkit.dll +0 -0
- PySimultan/resources/assimp.dll +0 -0
- PySimultan/resources/schema.yaml +0 -13
- PySimultan/resources/simultan_exception_07_10_2021-08_34_24.txt +0 -17
- PySimultan/resources/simultan_exception_07_10_2021-10_13_31.txt +0 -17
- PySimultan/resources/simultan_exception_11_10_2021-19_45_42.txt +0 -17
- PySimultan/resources/simultan_exception_22_11_2021-16_41_52.txt +0 -14
- PySimultan/resources/simultan_exception_22_11_2021-17_37_40.txt +0 -14
- PySimultan/simultan_geometry_utils.py +0 -81
- PySimultan/simultan_utils.py +0 -165
- PySimultan/slots.py +0 -51
- PySimultan/template_tools.py +0 -631
- PySimultan/utils.py +0 -298
- PySimultan-0.1.54.dist-info/LICENSE +0 -674
- PySimultan-0.1.54.dist-info/LICENSE.txt +0 -674
- PySimultan-0.1.54.dist-info/METADATA +0 -690
- PySimultan-0.1.54.dist-info/RECORD +0 -119
- PySimultan-0.1.54.dist-info/entry_points.txt +0 -3
- PySimultan-0.1.54.dist-info/top_level.txt +0 -1
- PySimultan-0.1.54.dist-info/zip-safe +0 -1
- {PySimultan → PySimultan2}/resources/DotSpatial.Projections.dll +0 -0
- {PySimultan → PySimultan2}/resources/GeometryViewer.dll.config +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.AutoUpdate.Client.dll.config +0 -0
- {PySimultan → PySimultan2}/resources/SitePlanner.dll.config +0 -0
- {PySimultan → PySimultan2}/resources/Sprache.Calc.dll +0 -0
- {PySimultan → PySimultan2}/resources/__init__.py +0 -0
- {PySimultan → PySimultan2}/resources/setup.bat +0 -0
@@ -0,0 +1,507 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import xxsubtype
|
4
|
+
from collections.abc import Iterable
|
5
|
+
import numpy as np
|
6
|
+
import pandas as pd
|
7
|
+
import colorlog
|
8
|
+
from typing import Union, List, Type, Set, Tuple, Any, Optional
|
9
|
+
|
10
|
+
from .utils import (sort_slots, create_simultan_component_for_taxonomy, create_mapped_python_object,
|
11
|
+
set_property_to_sim_component, set_property_to_parameter, set_property_to_file_info,
|
12
|
+
set_property_to_list, set_property_to_value_field, set_property_to_unknown_type,
|
13
|
+
remove_prop_from_sim_component, get_param_indices, set_property_to_dict, get_obj_value,
|
14
|
+
get_component_taxonomy_entry)
|
15
|
+
from .simultan_object import SimultanObject
|
16
|
+
from .taxonomy_maps import TaxonomyMap, Content
|
17
|
+
|
18
|
+
from SIMULTAN.Data.Components import (ComponentWalker, SimComponent, SimBoolParameter, SimDoubleParameter,
|
19
|
+
SimEnumParameter, SimIntegerParameter, SimStringParameter, ComponentMapping,
|
20
|
+
SimSlot, SimComponentVisibility, SimChildComponentEntry, SimDefaultSlots,
|
21
|
+
SimParameterOperations, SimComponentReference)
|
22
|
+
from .files import FileInfo
|
23
|
+
|
24
|
+
from . import config
|
25
|
+
|
26
|
+
logger = colorlog.getLogger('PySimultan')
|
27
|
+
|
28
|
+
|
29
|
+
class ComponentList(SimultanObject):
|
30
|
+
|
31
|
+
_create_all = False # if true all properties are evaluated to create python objects when initialized
|
32
|
+
_taxonomy = 'ComponentList'
|
33
|
+
|
34
|
+
def __init__(self, *args, **kwargs):
|
35
|
+
super().__init__(*args, **kwargs)
|
36
|
+
self.component_policy = kwargs.get('component_policy', 'subcomponent') # component add policy of the content/parameter/property, 'reference' or 'subcomponent'
|
37
|
+
self.index = 0
|
38
|
+
|
39
|
+
@classmethod
|
40
|
+
def create_from_values(cls,
|
41
|
+
values: Union[List[SimultanObject], Set[SimultanObject], Tuple[SimultanObject]],
|
42
|
+
data_model=None,
|
43
|
+
object_mapper=None,
|
44
|
+
*args,
|
45
|
+
**kwargs,
|
46
|
+
):
|
47
|
+
|
48
|
+
# logger.debug(f'Creating new component list from values {values}')
|
49
|
+
|
50
|
+
wrapped_obj = create_simultan_component_for_taxonomy(cls,
|
51
|
+
data_model=data_model,
|
52
|
+
object_mapper=object_mapper,
|
53
|
+
add_to_data_model=kwargs.get('add_to_data_model', True))
|
54
|
+
|
55
|
+
new_component_list = cls(wrapped_obj=wrapped_obj,
|
56
|
+
data_model_id=data_model.id,
|
57
|
+
object_mapper=object_mapper,
|
58
|
+
data_model=data_model,
|
59
|
+
)
|
60
|
+
|
61
|
+
wrapped_obj.Name = kwargs.get('name', 'UnnamedComponentList')
|
62
|
+
|
63
|
+
new_component_list.append(values)
|
64
|
+
|
65
|
+
# for i, value in enumerate(values):
|
66
|
+
# if isinstance(value, SimultanObject):
|
67
|
+
# try:
|
68
|
+
# new_component_list.add_referenced_component(value._wrapped_obj,
|
69
|
+
# slot_extension=str(i),
|
70
|
+
# slot=value.slot)
|
71
|
+
# except Exception as e:
|
72
|
+
# logger.error(f'Could not add component {value} to list {new_component_list}:\n{e}')
|
73
|
+
# else:
|
74
|
+
# new_val = create_mapped_python_object(value,
|
75
|
+
# data_model=data_model,
|
76
|
+
# object_mapper=object_mapper,
|
77
|
+
# add_to_data_model=True)
|
78
|
+
#
|
79
|
+
# taxonomy = data_model.get_or_create_taxonomy(taxonomy_name=new_val._taxonomy_map.taxonomy_name,
|
80
|
+
# taxonomy_key=new_val._taxonomy_map.taxonomy_key)
|
81
|
+
#
|
82
|
+
# taxonomy_entry = data_model.get_or_create_taxonomy_entry(name=new_val._taxonomy_map.taxonomy_entry_name,
|
83
|
+
# key=new_val._taxonomy_map.taxonomy_entry_key,
|
84
|
+
# sim_taxonomy=taxonomy)
|
85
|
+
#
|
86
|
+
# new_component_list.add_subcomponent(new_val._wrapped_obj,
|
87
|
+
# slot_extension=str(i),
|
88
|
+
# slot=taxonomy_entry)
|
89
|
+
|
90
|
+
# logger.debug(f'Created new component list {new_component_list.id} from values {new_component_list}')
|
91
|
+
|
92
|
+
return new_component_list
|
93
|
+
|
94
|
+
@property
|
95
|
+
def components(self):
|
96
|
+
return [x.Component for x in self._wrapped_obj.Components.Items]
|
97
|
+
|
98
|
+
@property
|
99
|
+
def ref_components(self):
|
100
|
+
return [x.Target for x in self._wrapped_obj.ReferencedComponents.Items]
|
101
|
+
|
102
|
+
@property
|
103
|
+
def data(self) -> List[SimultanObject]:
|
104
|
+
try:
|
105
|
+
if self._wrapped_obj is None:
|
106
|
+
return
|
107
|
+
components = self.components
|
108
|
+
ref_components = self.ref_components
|
109
|
+
all_components = [*components, *ref_components]
|
110
|
+
|
111
|
+
slots = [*[x.Slot for x in self._wrapped_obj.Components.Items],
|
112
|
+
*[x.Slot for x in self._wrapped_obj.ReferencedComponents.Items]]
|
113
|
+
|
114
|
+
try:
|
115
|
+
indices = sort_slots(slots)
|
116
|
+
return [self._object_mapper.create_python_object(x) for x in
|
117
|
+
[all_components[i] for i in np.argsort(indices)]]
|
118
|
+
except TypeError as e:
|
119
|
+
logger.warning(f'Could not sort list {all_components}:\n{e}')
|
120
|
+
return [self._object_mapper.create_python_object(x) for x in all_components]
|
121
|
+
except Exception as e:
|
122
|
+
logger.error(f'Could not get data from list {self}:\n{e}')
|
123
|
+
return []
|
124
|
+
|
125
|
+
def discard(self, value: SimultanObject):
|
126
|
+
|
127
|
+
components = self.components
|
128
|
+
subcomponents = self.ref_components
|
129
|
+
|
130
|
+
if value._wrapped_obj in components:
|
131
|
+
index = components.index(value._wrapped_obj)
|
132
|
+
self.remove_subcomponent(value._wrapped_obj)
|
133
|
+
elif value._wrapped_obj in subcomponents:
|
134
|
+
index = subcomponents.index(value._wrapped_obj)
|
135
|
+
self.remove_referenced_component(value._wrapped_obj)
|
136
|
+
else:
|
137
|
+
raise ValueError(f'Component {value} not in list {self}')
|
138
|
+
self._update_slot_extensions(index)
|
139
|
+
|
140
|
+
def append(self, values: Union[SimultanObject, List]):
|
141
|
+
|
142
|
+
if not isinstance(values, Iterable):
|
143
|
+
values = [values]
|
144
|
+
|
145
|
+
for i, value in enumerate(values, start=len(self.data)):
|
146
|
+
self._set_value(value, i)
|
147
|
+
|
148
|
+
def _update_slot_extensions(self, index: int):
|
149
|
+
|
150
|
+
# update slot extension of all elements > index
|
151
|
+
for i, component in enumerate(self.data):
|
152
|
+
if i > index-1:
|
153
|
+
if component._wrapped_obj in self.components:
|
154
|
+
slot, c_entry = next((x.Slot, x) for x in self._wrapped_obj.Components.Items if x.Component == component._wrapped_obj)
|
155
|
+
elif component._wrapped_obj in self.ref_components:
|
156
|
+
slot = next(x.Slot for x in self._wrapped_obj.ReferencedComponents.Items if x.Target == component._wrapped_obj)
|
157
|
+
else:
|
158
|
+
raise ValueError(f'Component {component} not in list {self}')
|
159
|
+
c_entry.set_Slot(SimSlot(slot.SlotBase, str(i)))
|
160
|
+
|
161
|
+
def _set_value(self, value, i):
|
162
|
+
|
163
|
+
if isinstance(value, SimultanObject):
|
164
|
+
slot = value._wrapped_obj.Slots.Items[0]
|
165
|
+
|
166
|
+
if self.component_policy == 'subcomponent' and value._wrapped_obj.Parent is None:
|
167
|
+
self.add_subcomponent(value._wrapped_obj,
|
168
|
+
slot_extension=str(i),
|
169
|
+
slot=slot)
|
170
|
+
else:
|
171
|
+
self.add_referenced_component(value._wrapped_obj,
|
172
|
+
slot_extension=str(i),
|
173
|
+
slot=slot)
|
174
|
+
else:
|
175
|
+
new_val = create_mapped_python_object(value,
|
176
|
+
data_model=self._data_model,
|
177
|
+
object_mapper=self._object_mapper,
|
178
|
+
add_to_data_model=True)
|
179
|
+
|
180
|
+
taxonomy = self._data_model.get_or_create_taxonomy(taxonomy_name=new_val._taxonomy_map.taxonomy_name,
|
181
|
+
taxonomy_key=new_val._taxonomy_map.taxonomy_key)
|
182
|
+
|
183
|
+
taxonomy_entry = self._data_model.get_or_create_taxonomy_entry(name=new_val._taxonomy_map.taxonomy_entry_name,
|
184
|
+
key=new_val._taxonomy_map.taxonomy_entry_key,
|
185
|
+
sim_taxonomy=taxonomy)
|
186
|
+
|
187
|
+
if new_val._wrapped_obj.Parent is None:
|
188
|
+
self.add_subcomponent(new_val._wrapped_obj,
|
189
|
+
slot_extension=str(i),
|
190
|
+
slot=taxonomy_entry)
|
191
|
+
else:
|
192
|
+
self.add_referenced_component(new_val._wrapped_obj,
|
193
|
+
slot_extension=str(i),
|
194
|
+
slot=taxonomy_entry)
|
195
|
+
|
196
|
+
def __setitem__(self, i, value):
|
197
|
+
if isinstance(i, slice):
|
198
|
+
for j, val in enumerate(value):
|
199
|
+
self.__setitem__(i.start + j, val)
|
200
|
+
else:
|
201
|
+
if i < 0:
|
202
|
+
i += len(self.data)
|
203
|
+
|
204
|
+
if i >= len(self.data):
|
205
|
+
self.append([value])
|
206
|
+
else:
|
207
|
+
if self.data[i] is value:
|
208
|
+
return
|
209
|
+
self.discard(self.data[i])
|
210
|
+
self._set_value(value, i)
|
211
|
+
|
212
|
+
def extend(self, values: List):
|
213
|
+
self.append(values)
|
214
|
+
|
215
|
+
def remove(self, value: SimultanObject):
|
216
|
+
self.discard(value)
|
217
|
+
|
218
|
+
def add(self, value: Union[SimultanObject, List[SimultanObject]]):
|
219
|
+
if value not in self.data:
|
220
|
+
self.append(value)
|
221
|
+
|
222
|
+
def move_item(self, item: SimultanObject, new_index: int):
|
223
|
+
if item not in self.data:
|
224
|
+
raise ValueError(f'Item {item} not in list {self}')
|
225
|
+
old_index = self.data.index(item)
|
226
|
+
|
227
|
+
if new_index < 0:
|
228
|
+
new_index += len(self.data)
|
229
|
+
|
230
|
+
if new_index == old_index:
|
231
|
+
return
|
232
|
+
|
233
|
+
new_data = self.data.copy()
|
234
|
+
new_data.pop(old_index)
|
235
|
+
new_data.insert(new_index, item)
|
236
|
+
|
237
|
+
for i, item in enumerate(new_data):
|
238
|
+
if item._wrapped_obj in self.components:
|
239
|
+
slot, c_entry = next(
|
240
|
+
(x.Slot, x) for x in self._wrapped_obj.Components.Items if x.Component == item._wrapped_obj)
|
241
|
+
elif item._wrapped_obj in self.ref_components:
|
242
|
+
slot = next(
|
243
|
+
x.Slot for x in self._wrapped_obj.ReferencedComponents.Items if x.Target == item._wrapped_obj)
|
244
|
+
else:
|
245
|
+
raise ValueError(f'Component {item} not in list {self}')
|
246
|
+
c_entry.set_Slot(SimSlot(slot.SlotBase, str(i)))
|
247
|
+
|
248
|
+
def __getitem__(self, i):
|
249
|
+
if isinstance(i, slice):
|
250
|
+
if self._object_mapper is None:
|
251
|
+
return self.__class__(self.data[i])
|
252
|
+
return [self._object_mapper.create_python_object(x) for x in self.__class__(self.data[i])]
|
253
|
+
else:
|
254
|
+
if self._object_mapper is None:
|
255
|
+
return self.data[i]
|
256
|
+
return self._object_mapper.create_python_object(self.data[i])
|
257
|
+
|
258
|
+
def __repr__(self):
|
259
|
+
return f'List {self.name}: ' + repr(list(self.data))
|
260
|
+
|
261
|
+
def __iter__(self):
|
262
|
+
return iter([self._object_mapper.create_python_object(x) for x in self.data])
|
263
|
+
|
264
|
+
def __next__(self):
|
265
|
+
try:
|
266
|
+
result = self.__getitem__(self.index)
|
267
|
+
except IndexError:
|
268
|
+
raise StopIteration
|
269
|
+
self.index += 1
|
270
|
+
return result
|
271
|
+
|
272
|
+
def __len__(self):
|
273
|
+
return self.data.__len__()
|
274
|
+
|
275
|
+
@property
|
276
|
+
def parent(self):
|
277
|
+
if not hasattr(self._wrapped_obj, 'Parent'):
|
278
|
+
return None
|
279
|
+
|
280
|
+
if self._wrapped_obj.Parent is not None:
|
281
|
+
return self._object_mapper.create_python_object(self._wrapped_obj.Parent)
|
282
|
+
else:
|
283
|
+
return None
|
284
|
+
|
285
|
+
@property
|
286
|
+
def referenced_by(self):
|
287
|
+
return set([self._object_mapper.create_python_object(x.Target) for x in self._wrapped_obj.ReferencedBy if
|
288
|
+
x.Target != self._wrapped_obj])
|
289
|
+
|
290
|
+
def clear(self):
|
291
|
+
self._wrapped_obj.Components.Clear()
|
292
|
+
self._wrapped_obj.ReferencedComponents.Clear()
|
293
|
+
|
294
|
+
|
295
|
+
component_list_map = TaxonomyMap(taxonomy_name='PySimultan',
|
296
|
+
taxonomy_key='PySimultan',
|
297
|
+
taxonomy_entry_name='ComponentList',
|
298
|
+
taxonomy_entry_key='ComponentList',
|
299
|
+
)
|
300
|
+
|
301
|
+
ComponentList._taxonomy_map = component_list_map
|
302
|
+
|
303
|
+
|
304
|
+
class ComponentDictionary(SimultanObject):
|
305
|
+
|
306
|
+
component_policy = 'subcomponent' # component add policy of the content/parameter/property, 'reference'
|
307
|
+
# or 'subcomponent'
|
308
|
+
|
309
|
+
type_setter_fcn_lookup_dict = {None: lambda x: None,
|
310
|
+
SimComponent: set_property_to_sim_component,
|
311
|
+
SimultanObject: set_property_to_sim_component,
|
312
|
+
SimDoubleParameter: set_property_to_parameter,
|
313
|
+
SimIntegerParameter: set_property_to_parameter,
|
314
|
+
SimStringParameter: set_property_to_parameter,
|
315
|
+
SimBoolParameter: set_property_to_parameter,
|
316
|
+
SimEnumParameter: set_property_to_parameter,
|
317
|
+
int: set_property_to_parameter,
|
318
|
+
float: set_property_to_parameter,
|
319
|
+
str: set_property_to_parameter,
|
320
|
+
bool: set_property_to_parameter,
|
321
|
+
FileInfo: set_property_to_file_info,
|
322
|
+
list: set_property_to_list,
|
323
|
+
tuple: set_property_to_list,
|
324
|
+
set: set_property_to_list,
|
325
|
+
dict: set_property_to_dict,
|
326
|
+
ComponentList: set_property_to_list,
|
327
|
+
np.ndarray: set_property_to_value_field,
|
328
|
+
pd.DataFrame: set_property_to_value_field}
|
329
|
+
|
330
|
+
_taxonomy_map = TaxonomyMap(taxonomy_name='Dictionaries',
|
331
|
+
taxonomy_key='Dictionaries',
|
332
|
+
taxonomy_entry_name='ComponentDict',
|
333
|
+
taxonomy_entry_key='ComponentDict',
|
334
|
+
)
|
335
|
+
|
336
|
+
_taxonomy = 'ComponentDict'
|
337
|
+
|
338
|
+
def __init__(self, *args, **kwargs):
|
339
|
+
self._dict = {}
|
340
|
+
super().__init__(*args, **kwargs)
|
341
|
+
self.component_policy = kwargs.get('component_policy', 'subcomponent') # component add policy of the content/parameter/property, 'reference' or 'subcomponent'
|
342
|
+
|
343
|
+
@classmethod
|
344
|
+
def create_from_values(cls,
|
345
|
+
values: dict[str, Any],
|
346
|
+
data_model=None,
|
347
|
+
object_mapper=None,
|
348
|
+
*args,
|
349
|
+
**kwargs,
|
350
|
+
):
|
351
|
+
|
352
|
+
wrapped_obj = create_simultan_component_for_taxonomy(cls,
|
353
|
+
data_model=data_model,
|
354
|
+
object_mapper=object_mapper,
|
355
|
+
add_to_data_model=kwargs.get('add_to_data_model', True))
|
356
|
+
|
357
|
+
new_component_dict = cls(wrapped_obj=wrapped_obj,
|
358
|
+
data_model_id=data_model.id,
|
359
|
+
object_mapper=object_mapper,
|
360
|
+
data_model=data_model,
|
361
|
+
)
|
362
|
+
|
363
|
+
wrapped_obj.Name = kwargs.get('name', 'UnnamedComponentDict')
|
364
|
+
|
365
|
+
for key, value in values.items():
|
366
|
+
new_component_dict[key] = value
|
367
|
+
|
368
|
+
return new_component_dict
|
369
|
+
|
370
|
+
def __getitem__(self, key, *args, **kwargs):
|
371
|
+
|
372
|
+
comp_dict = object.__getattribute__(self, '_dict')
|
373
|
+
|
374
|
+
if kwargs.get('check_dict', True) and comp_dict is not None and key in object.__getattribute__(self,
|
375
|
+
'_dict').keys():
|
376
|
+
return object.__getattribute__(self, '_dict')[key]
|
377
|
+
else:
|
378
|
+
data_model = config.default_data_model
|
379
|
+
obj = get_component_taxonomy_entry(self._wrapped_obj, key)
|
380
|
+
if obj is not None:
|
381
|
+
val = get_obj_value(obj, data_model=data_model, object_mapper=self._object_mapper)
|
382
|
+
self._dict[key] = val
|
383
|
+
return self._dict[key]
|
384
|
+
|
385
|
+
def __setitem__(self, key, value):
|
386
|
+
|
387
|
+
if key in self._dict:
|
388
|
+
del self._dict[key]
|
389
|
+
|
390
|
+
if key in self._taxonomy_map.content_dict.keys():
|
391
|
+
content = self._taxonomy_map.content_dict[key]
|
392
|
+
else:
|
393
|
+
content = Content(text_or_key=key,
|
394
|
+
property_name=key,
|
395
|
+
type=None,
|
396
|
+
unit=None,
|
397
|
+
documentation=f'Property {key} in ComponentDictionary',
|
398
|
+
component_policy=self.component_policy)
|
399
|
+
self._taxonomy_map.add_content(content)
|
400
|
+
taxonomy_entry = content.get_taxonomie_entry(self._data_model)
|
401
|
+
|
402
|
+
component_idx, ref_component_idx, parameter_idx, ref_asset_idx = get_param_indices(self._wrapped_obj,
|
403
|
+
taxonomy_entry)
|
404
|
+
|
405
|
+
slot_extension = content.slot_extension
|
406
|
+
|
407
|
+
if slot_extension is None:
|
408
|
+
slot_extension = 0
|
409
|
+
|
410
|
+
fcn_arg_list = [value,
|
411
|
+
self,
|
412
|
+
key,
|
413
|
+
taxonomy_entry,
|
414
|
+
slot_extension,
|
415
|
+
component_idx,
|
416
|
+
ref_component_idx,
|
417
|
+
parameter_idx,
|
418
|
+
ref_asset_idx,
|
419
|
+
content]
|
420
|
+
|
421
|
+
if value is None:
|
422
|
+
remove_prop_from_sim_component(component=self._wrapped_obj,
|
423
|
+
component_idx=component_idx,
|
424
|
+
ref_component_idx=ref_component_idx,
|
425
|
+
parameter_idx=parameter_idx,
|
426
|
+
keep=[])
|
427
|
+
|
428
|
+
if isinstance(value, (list, tuple, set, ComponentList)):
|
429
|
+
setter_fcn = set_property_to_list
|
430
|
+
elif isinstance(value, SimultanObject):
|
431
|
+
setter_fcn = set_property_to_sim_component
|
432
|
+
else:
|
433
|
+
setter_fcn = self.type_setter_fcn_lookup_dict.get(type(value), set_property_to_unknown_type)
|
434
|
+
|
435
|
+
setter_fcn(*fcn_arg_list)
|
436
|
+
self._dict[key] = self.__getitem__(key, check_dict=False)
|
437
|
+
|
438
|
+
def __delitem__(self, key):
|
439
|
+
self[key] = None
|
440
|
+
del self._dict[key]
|
441
|
+
|
442
|
+
def items(self):
|
443
|
+
return self._dict.items()
|
444
|
+
|
445
|
+
def keys(self):
|
446
|
+
if not self._dict:
|
447
|
+
self._generate_internal_dict()
|
448
|
+
return self._dict.keys()
|
449
|
+
|
450
|
+
def values(self):
|
451
|
+
if not self._dict:
|
452
|
+
self._generate_internal_dict()
|
453
|
+
return self._dict.values()
|
454
|
+
|
455
|
+
def _generate_internal_dict(self):
|
456
|
+
comp_dict = {}
|
457
|
+
|
458
|
+
for parameter in self._wrapped_obj.Parameters.Items:
|
459
|
+
comp_dict[parameter.NameTaxonomyEntry.TextOrKey] = get_obj_value(parameter,
|
460
|
+
data_model=self._data_model,
|
461
|
+
object_mapper=self._object_mapper)
|
462
|
+
for component in self._wrapped_obj.Components.Items:
|
463
|
+
comp_dict[component.Name] = get_obj_value(component,
|
464
|
+
data_model=self._data_model,
|
465
|
+
object_mapper=self._object_mapper)
|
466
|
+
for ref_component in self._wrapped_obj.ReferencedComponents.Items:
|
467
|
+
comp_dict[ref_component.Slot.SlotBase.Target.Name] = get_obj_value(ref_component.Target,
|
468
|
+
data_model=self._data_model,
|
469
|
+
object_mapper=self._object_mapper)
|
470
|
+
for ref_asset in self._wrapped_obj.ReferencedAssets.Items:
|
471
|
+
for tag in ref_asset.Resource.Tags:
|
472
|
+
comp_dict[tag.Target.Key] = get_obj_value(ref_asset.Target,
|
473
|
+
data_model=self._data_model,
|
474
|
+
object_mapper=self._object_mapper)
|
475
|
+
|
476
|
+
object.__setattr__(self, '_dict', comp_dict)
|
477
|
+
|
478
|
+
def clear(self):
|
479
|
+
for key in self.keys():
|
480
|
+
del self[key]
|
481
|
+
|
482
|
+
def __repr__(self):
|
483
|
+
if not self._dict:
|
484
|
+
self._generate_internal_dict()
|
485
|
+
return repr(self._dict)
|
486
|
+
|
487
|
+
def __iter__(self):
|
488
|
+
return self._dict.__iter__()
|
489
|
+
|
490
|
+
def __next__(self):
|
491
|
+
return self._dict.__next__()
|
492
|
+
|
493
|
+
def __len__(self):
|
494
|
+
return len(self._dict)
|
495
|
+
|
496
|
+
def __contains__(self, key):
|
497
|
+
return key in self._dict
|
498
|
+
|
499
|
+
def get(self, key, default=None):
|
500
|
+
return self._dict.get(key, default)
|
501
|
+
|
502
|
+
def update(self, other):
|
503
|
+
for key, value in other.items():
|
504
|
+
self[key] = value
|
505
|
+
|
506
|
+
|
507
|
+
component_dict_map = ComponentDictionary._taxonomy_map
|