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
PySimultan2/utils.py
ADDED
@@ -0,0 +1,1383 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from . import config
|
4
|
+
from enum import Enum
|
5
|
+
from functools import lru_cache
|
6
|
+
import numpy as np
|
7
|
+
import pandas as pd
|
8
|
+
from typing import List as TypeList, Union, Optional
|
9
|
+
from SIMULTAN.Data.Components import (ComponentWalker, SimComponent, SimBoolParameter, SimDoubleParameter,
|
10
|
+
SimEnumParameter, SimIntegerParameter, SimStringParameter, ComponentMapping,
|
11
|
+
SimSlot, SimComponentVisibility, SimChildComponentEntry, SimDefaultSlots,
|
12
|
+
SimParameterOperations, SimComponentReference)
|
13
|
+
from SIMULTAN.Data.Taxonomy import SimTaxonomyEntry, SimTaxonomyEntryReference, SimTaxonomy
|
14
|
+
from SIMULTAN.Data.Components import SimDefaultSlotKeys
|
15
|
+
from SIMULTAN.Data.MultiValues import (SimMultiValueField3D, SimMultiValueField3DParameterSource, SimMultiValueBigTable,
|
16
|
+
SimMultiValueBigTableHeader, SimMultiValueBigTableParameterSource)
|
17
|
+
|
18
|
+
from SIMULTAN.Data.Assets import ResourceEntry, ResourceFileEntry, ContainedResourceFileEntry, Asset, LinkedResourceFileEntry
|
19
|
+
from SIMULTAN.Data.Geometry import Face, Edge, Vertex, Volume
|
20
|
+
|
21
|
+
from .multi_values import (simultan_multi_value_field_3d_to_numpy, set_parameter_to_value_field,
|
22
|
+
create_field_parameter, simultan_multi_value_big_table_to_pandas)
|
23
|
+
from .files import FileInfo, remove_asset_from_component, add_asset_to_component
|
24
|
+
|
25
|
+
from typing import TYPE_CHECKING
|
26
|
+
if TYPE_CHECKING:
|
27
|
+
from .default_types import ComponentList, ComponentDictionary
|
28
|
+
from .simultan_object import SimultanObject
|
29
|
+
from .data_model import DataModel
|
30
|
+
from .object_mapper import PythonMapper
|
31
|
+
from .taxonomy_maps import TaxonomyMap, Content
|
32
|
+
|
33
|
+
|
34
|
+
from .config import logger
|
35
|
+
from . import config
|
36
|
+
from .simultan_object import SimultanObject
|
37
|
+
|
38
|
+
|
39
|
+
class UnresolvedObject(object):
|
40
|
+
|
41
|
+
def __init__(self, wrapped_obj, cls, *args, **kwargs):
|
42
|
+
self.wrapped_obj = wrapped_obj
|
43
|
+
self.cls = cls
|
44
|
+
|
45
|
+
def resolve(self):
|
46
|
+
return self.cls._cls_instances_dict[self.wrapped_obj.Id]
|
47
|
+
|
48
|
+
|
49
|
+
class CircularReferenceResolver(object):
|
50
|
+
|
51
|
+
def __init__(self, *args, **kwargs):
|
52
|
+
self.unresolved_objects = dict()
|
53
|
+
|
54
|
+
|
55
|
+
circ_ref_resolver = CircularReferenceResolver()
|
56
|
+
|
57
|
+
|
58
|
+
def create_python_object(wrapped_obj: SimComponent, cls: SimultanObject, *args, **kwargs):
|
59
|
+
"""
|
60
|
+
Create a new mapped python object from a wrapped object
|
61
|
+
:param wrapped_obj: wrapped object to create the python object from
|
62
|
+
:param cls: class of the python object
|
63
|
+
:param args: additional arguments
|
64
|
+
:param kwargs: additional keyword arguments
|
65
|
+
:return:
|
66
|
+
"""
|
67
|
+
|
68
|
+
if kwargs.get('data_model_id', None) is None:
|
69
|
+
from .data_model import data_models
|
70
|
+
kwargs['data_model_id'] = list(data_models)[0].id
|
71
|
+
|
72
|
+
if wrapped_obj is None:
|
73
|
+
return None
|
74
|
+
else:
|
75
|
+
|
76
|
+
if wrapped_obj.Id in circ_ref_resolver.unresolved_objects.keys():
|
77
|
+
return circ_ref_resolver.unresolved_objects[wrapped_obj.Id]
|
78
|
+
else:
|
79
|
+
circ_ref_resolver.unresolved_objects[wrapped_obj.Id] = UnresolvedObject(wrapped_obj,
|
80
|
+
cls,
|
81
|
+
*args, **kwargs)
|
82
|
+
|
83
|
+
# get existing object
|
84
|
+
if wrapped_obj.Id in cls._cls_instances_dict.keys():
|
85
|
+
return cls._cls_instances_dict[wrapped_obj.Id]
|
86
|
+
|
87
|
+
if cls._taxonomy_map is not None:
|
88
|
+
for content in cls._taxonomy_map.content:
|
89
|
+
# logger.debug(f'Get property {content.text_or_key} from wrapped object {wrapped_obj.Name}')
|
90
|
+
kwargs[content.text_or_key] = get_property(wrapped_obj=wrapped_obj,
|
91
|
+
prop_name=content.text_or_key,
|
92
|
+
object_mapper=kwargs.get('object_mapper', None),
|
93
|
+
)
|
94
|
+
kwargs['name'] = wrapped_obj.Name
|
95
|
+
kwargs['__obj_init__'] = True
|
96
|
+
obj = cls(wrapped_obj=wrapped_obj, *args, **kwargs)
|
97
|
+
obj.__obj_init__ = False
|
98
|
+
|
99
|
+
circ_ref_resolver.unresolved_objects.pop(wrapped_obj.Id)
|
100
|
+
|
101
|
+
return obj
|
102
|
+
|
103
|
+
|
104
|
+
def create_taxonomy(name, key, description='', data_model=None) -> SimTaxonomy:
|
105
|
+
"""
|
106
|
+
Create a new taxonomy
|
107
|
+
:param name: name of the taxonomy
|
108
|
+
:param key: key of the taxonomy
|
109
|
+
:param description: description of the taxonomy
|
110
|
+
:param data_model: data model; if not None, the taxonomy will be added to the data model
|
111
|
+
:return: SimTaxonomy
|
112
|
+
"""
|
113
|
+
new_taxonomy = SimTaxonomy(key, name, description)
|
114
|
+
if data_model is not None:
|
115
|
+
data_model.taxonomies.Add(new_taxonomy)
|
116
|
+
return new_taxonomy
|
117
|
+
|
118
|
+
|
119
|
+
def get_or_create_taxonomy_entry(name: str,
|
120
|
+
key: str,
|
121
|
+
description='',
|
122
|
+
sim_taxonomy: Optional[SimTaxonomy] = None,
|
123
|
+
data_model: Optional[DataModel] = None,
|
124
|
+
create=True) -> SimTaxonomyEntry:
|
125
|
+
"""
|
126
|
+
Create a new taxonomy entry
|
127
|
+
:param name: name of the taxonomy entry
|
128
|
+
:param key: key of the taxonomy entry
|
129
|
+
:param description: description of the taxonomy entry
|
130
|
+
:param sim_taxonomy: sim taxonomy; if not None, the taxonomy entry will be added to the sim taxonomy
|
131
|
+
:param data_model: data model; if not None, the taxonomy entry will be added to the data model
|
132
|
+
:param create: if True, the taxonomy entry will be created if it does not exist
|
133
|
+
:return: SimTaxonomyEntry
|
134
|
+
"""
|
135
|
+
|
136
|
+
if data_model is not None:
|
137
|
+
taxonomy_entries = data_model.get_taxonomy_entries()
|
138
|
+
|
139
|
+
if key in taxonomy_entries.keys():
|
140
|
+
return taxonomy_entries[key]
|
141
|
+
if create:
|
142
|
+
new_sim_taxonomy_entry = SimTaxonomyEntry(key, name, description)
|
143
|
+
if sim_taxonomy is not None:
|
144
|
+
sim_taxonomy.Entries.Add(new_sim_taxonomy_entry)
|
145
|
+
return new_sim_taxonomy_entry
|
146
|
+
|
147
|
+
|
148
|
+
def create_str_sim_slot(slot_name: str,
|
149
|
+
slot_extension: Union[str, int, float],
|
150
|
+
data_model: DataModel = None):
|
151
|
+
return SimSlot(SimTaxonomyEntry(slot_name), str(slot_extension))
|
152
|
+
|
153
|
+
|
154
|
+
def create_component(name: Union[str, None] = None,
|
155
|
+
data_model: Union[DataModel, None] = None,
|
156
|
+
**kwargs) -> SimComponent:
|
157
|
+
"""
|
158
|
+
Create a new Simultan component
|
159
|
+
:param data_model: DataModel
|
160
|
+
:param name: Name of the component; string
|
161
|
+
:param kwargs: dictionary; set the components value of the key entry to to key value; Example: {'Visibility': 0,
|
162
|
+
'IsAutomaticallyGenerated': True}
|
163
|
+
:return: SimComponent
|
164
|
+
"""
|
165
|
+
new_comp = SimComponent()
|
166
|
+
|
167
|
+
slot = kwargs.get('slot', None)
|
168
|
+
|
169
|
+
if name is not None:
|
170
|
+
new_comp.Name = name
|
171
|
+
|
172
|
+
# set the components value of the key entry to key value
|
173
|
+
for key, value in kwargs.items():
|
174
|
+
if key == 'Visibility':
|
175
|
+
if value:
|
176
|
+
new_comp.Visibility = SimComponentVisibility.AlwaysVisible
|
177
|
+
else:
|
178
|
+
new_comp.Visibility = SimComponentVisibility.Hidden
|
179
|
+
else:
|
180
|
+
setattr(new_comp, key, value)
|
181
|
+
|
182
|
+
if slot is None:
|
183
|
+
slot = SimTaxonomyEntryReference(SimDefaultSlotKeys.GetDefaultSlot(data_model.project_data_manager.Taxonomies,
|
184
|
+
SimDefaultSlotKeys.Undefined))
|
185
|
+
elif isinstance(slot, SimTaxonomyEntry):
|
186
|
+
slot = SimTaxonomyEntryReference(slot)
|
187
|
+
|
188
|
+
elif isinstance(slot, SimTaxonomyEntryReference):
|
189
|
+
pass
|
190
|
+
|
191
|
+
new_comp.Slots.InsertItem(0, slot)
|
192
|
+
|
193
|
+
return new_comp
|
194
|
+
|
195
|
+
|
196
|
+
def get_default_slot(default_type: Union[SimTaxonomyEntryReference, SimTaxonomyEntry, str]) -> SimTaxonomyEntryReference:
|
197
|
+
"""
|
198
|
+
Get the default slot of the project
|
199
|
+
:param default_type:
|
200
|
+
:return:
|
201
|
+
"""
|
202
|
+
|
203
|
+
default_taxonomy_entry = SimDefaultSlotKeys.GetDefaultSlot(config.default_data_model.project_data_manager.Taxonomies,
|
204
|
+
SimDefaultSlotKeys.Undefined)
|
205
|
+
|
206
|
+
if default_type is SimTaxonomyEntryReference:
|
207
|
+
return SimTaxonomyEntryReference(default_taxonomy_entry)
|
208
|
+
elif default_type is SimTaxonomyEntry:
|
209
|
+
return default_taxonomy_entry
|
210
|
+
|
211
|
+
|
212
|
+
def create_sim_double_parameter(**kwargs) -> SimDoubleParameter:
|
213
|
+
"""
|
214
|
+
Creates a new SIMULTAN double parameter
|
215
|
+
:param name: Name of the parameter
|
216
|
+
:param unit: Unit of the parameter
|
217
|
+
:param value: Value of the parameter
|
218
|
+
:param slot: SimTaxonomyEntry or SimTaxonomyEntryReference
|
219
|
+
:param min_value: If None, the value is not limited
|
220
|
+
:param max_value: If None, the value is not limited
|
221
|
+
:param allowed_operations: SimParameterOperations
|
222
|
+
:return: SimDoubleParameter
|
223
|
+
"""
|
224
|
+
|
225
|
+
init_dict = ['slot', 'unit', 'value', 'min_value', 'ValueMin', 'max_value', 'ValueMax', 'allowed_operations']
|
226
|
+
|
227
|
+
args = [x for x in [kwargs.get(key, None) for key in init_dict] if x is not None]
|
228
|
+
|
229
|
+
if 'allowed_operations' not in kwargs.keys():
|
230
|
+
args.append(SimParameterOperations(0).All)
|
231
|
+
|
232
|
+
return SimDoubleParameter(*args)
|
233
|
+
|
234
|
+
|
235
|
+
def create_sim_integer_parameter(**kwargs) -> SimIntegerParameter:
|
236
|
+
"""
|
237
|
+
Creates a new SIMULTAN integer parameter
|
238
|
+
:param name: Name of the parameter
|
239
|
+
:param unit: Unit of the parameter
|
240
|
+
:param value: Value of the parameter
|
241
|
+
:param slot: SimTaxonomyEntry or SimTaxonomyEntryReference
|
242
|
+
:param min_value: If None, the value is not limited
|
243
|
+
:param max_value: If None, the value is not limited
|
244
|
+
:param allowed_operations: SimParameterOperations
|
245
|
+
:return:
|
246
|
+
"""
|
247
|
+
|
248
|
+
kwargs['value'] = int(kwargs['value'])
|
249
|
+
init_dict = ['slot', 'unit', 'value', 'min_value', 'max_value', 'allowed_operations']
|
250
|
+
|
251
|
+
args = [x for x in [kwargs.get(key, None) for key in init_dict] if x is not None]
|
252
|
+
args.append(SimParameterOperations(0).All)
|
253
|
+
|
254
|
+
return SimIntegerParameter(*args)
|
255
|
+
|
256
|
+
|
257
|
+
def create_sim_string_parameter(**kwargs) -> SimStringParameter:
|
258
|
+
"""
|
259
|
+
Creates a new SIMULTAN string parameter
|
260
|
+
:param name: Name of the parameter
|
261
|
+
:param value: Value of the parameter
|
262
|
+
:param slot: SimTaxonomyEntry or SimTaxonomyEntryReference
|
263
|
+
:param allowed_operations: SimParameterOperations
|
264
|
+
:return:
|
265
|
+
"""
|
266
|
+
|
267
|
+
init_dict = ['slot', 'value']
|
268
|
+
|
269
|
+
args = [x for x in [kwargs.get(key, None) for key in init_dict] if x is not None]
|
270
|
+
args.append(SimParameterOperations(0).All)
|
271
|
+
|
272
|
+
return SimStringParameter(*args)
|
273
|
+
|
274
|
+
|
275
|
+
def create_sim_bool_parameter(**kwargs) -> SimBoolParameter:
|
276
|
+
"""
|
277
|
+
Creates a new SIMULTAN bool parameter
|
278
|
+
:param name: Name of the parameter
|
279
|
+
:param value: Value of the parameter
|
280
|
+
:param slot: SimTaxonomyEntry or SimTaxonomyEntryReference
|
281
|
+
:param allowed_operations: SimParameterOperations
|
282
|
+
:return:
|
283
|
+
"""
|
284
|
+
|
285
|
+
init_dict = ['slot', 'value']
|
286
|
+
|
287
|
+
args = [x for x in [kwargs.get(key, None) for key in init_dict] if x is not None]
|
288
|
+
args.append(SimParameterOperations(0).All)
|
289
|
+
|
290
|
+
return SimBoolParameter(*args)
|
291
|
+
|
292
|
+
|
293
|
+
def create_parameter(value: Union[int, float, str, SimTaxonomyEntry] = 0,
|
294
|
+
name: str = None,
|
295
|
+
parameter_type: Union[int, float, str, Enum] = None,
|
296
|
+
taxonomy_entry: SimTaxonomyEntry = None,
|
297
|
+
**kwargs) -> Union[SimDoubleParameter, SimIntegerParameter, SimStringParameter, SimEnumParameter]:
|
298
|
+
"""
|
299
|
+
Creates a new SIMULTAN parameter
|
300
|
+
|
301
|
+
- either parameter_type or value must be set, if parameter_type is not set, parameter_type
|
302
|
+
is set automatically by the type of value
|
303
|
+
- if name and taxonomy_entry_or_string is not set, the default slot is used.
|
304
|
+
- If name is set, the slot is taxonomy_entry_or_string -> string
|
305
|
+
- if taxonomy_entry_or_string is set, the slot is taxonomy_entry_or_string -> SimTaxonomyEntryReference
|
306
|
+
|
307
|
+
:param name: Parameter name, string
|
308
|
+
:param value: Value of the parameter; int or float
|
309
|
+
:param parameter_type: Parameter type, int, float, string or enum
|
310
|
+
:param taxonomy_entry: Taxonomy entry or string
|
311
|
+
:return: SimParameter
|
312
|
+
"""
|
313
|
+
|
314
|
+
if taxonomy_entry is None and name is None:
|
315
|
+
taxonomy_entry = get_default_slot(SimTaxonomyEntry)
|
316
|
+
|
317
|
+
if parameter_type is None:
|
318
|
+
if type(value) is float:
|
319
|
+
parameter_type = float
|
320
|
+
elif type(value) is int:
|
321
|
+
parameter_type = float
|
322
|
+
elif type(value) is str:
|
323
|
+
parameter_type = str
|
324
|
+
elif type(value) is SimTaxonomyEntry:
|
325
|
+
parameter_type = Enum
|
326
|
+
elif type(value) is bool:
|
327
|
+
parameter_type = bool
|
328
|
+
else:
|
329
|
+
raise ValueError(f'Parameter type {type(value)} not supported.')
|
330
|
+
|
331
|
+
if parameter_type == float:
|
332
|
+
return create_sim_double_parameter(name=name,
|
333
|
+
value=value,
|
334
|
+
slot=taxonomy_entry,
|
335
|
+
unit=kwargs.pop('unit', ''),
|
336
|
+
**kwargs)
|
337
|
+
elif parameter_type == int:
|
338
|
+
return create_sim_integer_parameter(name=name,
|
339
|
+
value=value,
|
340
|
+
slot=taxonomy_entry,
|
341
|
+
unit=kwargs.pop('unit', ''),
|
342
|
+
**kwargs)
|
343
|
+
elif parameter_type == str:
|
344
|
+
return create_sim_string_parameter(name=name,
|
345
|
+
value=value,
|
346
|
+
slot=taxonomy_entry,
|
347
|
+
**kwargs)
|
348
|
+
elif parameter_type == bool:
|
349
|
+
return create_sim_bool_parameter(name=name,
|
350
|
+
value=value,
|
351
|
+
slot=taxonomy_entry,
|
352
|
+
**kwargs)
|
353
|
+
elif parameter_type == SimTaxonomyEntry:
|
354
|
+
raise NotImplementedError('Parameter for Enum not implemented yet.')
|
355
|
+
else:
|
356
|
+
raise ValueError(f'Parameter type {parameter_type} not supported.')
|
357
|
+
|
358
|
+
|
359
|
+
def add_sub_component(comp: SimComponent,
|
360
|
+
sub_comp: SimComponent,
|
361
|
+
slot_extension: Union[str, int, float],
|
362
|
+
slot: Union[str, SimTaxonomyEntry, SimTaxonomyEntryReference] = None):
|
363
|
+
"""
|
364
|
+
Add a sub component to a component.
|
365
|
+
|
366
|
+
:param comp: Component to add the subcomponent; ParameterStructure.Components.SimComponent
|
367
|
+
:param sub_comp: Component to be added; ParameterStructure.Components.SimComponent
|
368
|
+
:param slot: Target slot name or taxonomie of the subcomponent; If string, a new slot is created with the string as
|
369
|
+
target;
|
370
|
+
:param slot_extension: Target slot extension of the subcomponent;
|
371
|
+
"""
|
372
|
+
|
373
|
+
if slot is not None:
|
374
|
+
if isinstance(slot, str):
|
375
|
+
slot = SimTaxonomyEntry(slot)
|
376
|
+
slot = create_str_sim_slot(slot, slot_extension)
|
377
|
+
elif isinstance(slot, SimTaxonomyEntry):
|
378
|
+
slot = SimTaxonomyEntryReference(slot)
|
379
|
+
if slot not in sub_comp.Slots:
|
380
|
+
sub_comp.Slots.InsertItem(0, slot)
|
381
|
+
|
382
|
+
if slot_extension is None:
|
383
|
+
new_slot = comp.Components.FindAvailableSlot(slot, "{0}")
|
384
|
+
else:
|
385
|
+
new_slot = SimSlot(sub_comp.Slots[0].Target, str(slot_extension))
|
386
|
+
|
387
|
+
entry = SimChildComponentEntry(new_slot, sub_comp)
|
388
|
+
if entry not in comp.Components.Items:
|
389
|
+
comp.Components.InsertItem(0, entry)
|
390
|
+
return True
|
391
|
+
|
392
|
+
|
393
|
+
# def add_asset_to_component(comp: SimComponent,
|
394
|
+
# asset: Union[ResourceFileEntry, ContainedResourceFileEntry],
|
395
|
+
# content_id: str = '') -> Asset:
|
396
|
+
# """
|
397
|
+
# Add an asset to a component
|
398
|
+
# :param comp: Component to add the asset; ParameterStructure.Components.SimComponent
|
399
|
+
# :param asset: Asset to be added; ParameterStructure.Assets.ResourceFileEntry
|
400
|
+
# :param content_id: Content id of the asset; string; E.g. '0' as the page of a pdf
|
401
|
+
# :return:
|
402
|
+
# """
|
403
|
+
# return ComponentMapping.AddAsset(comp, asset, content_id)
|
404
|
+
|
405
|
+
|
406
|
+
def remove_sub_component(comp: Union[SimComponent, SimultanObject],
|
407
|
+
sub_comp: Union[SimComponent, SimultanObject],
|
408
|
+
index: int = None):
|
409
|
+
"""
|
410
|
+
Remove a sub component from a component.
|
411
|
+
:param comp: Component to remove the subcomponent; ParameterStructure.Components.SimComponent
|
412
|
+
:type comp: Union[SimComponent, SimultanObject]
|
413
|
+
:param sub_comp: Component to be removed; ParameterStructure.Components.SimComponent
|
414
|
+
:type sub_comp: Union[SimComponent, SimultanObject]
|
415
|
+
:param index: Index of the subcomponent to be removed; int
|
416
|
+
"""
|
417
|
+
|
418
|
+
sub_comp_wrapped_obj = sub_comp if isinstance(sub_comp, SimComponent) else sub_comp._wrapped_obj
|
419
|
+
component_wrapped_obj = comp if isinstance(comp, SimComponent) else comp._wrapped_obj
|
420
|
+
|
421
|
+
if index is not None:
|
422
|
+
component_wrapped_obj.Components.RemoveItem(index)
|
423
|
+
return
|
424
|
+
|
425
|
+
for i, sub_comp_entry in enumerate(component_wrapped_obj.Components.Items):
|
426
|
+
if sub_comp_entry.Component == sub_comp_wrapped_obj:
|
427
|
+
component_wrapped_obj.Components.RemoveItem(i)
|
428
|
+
return
|
429
|
+
|
430
|
+
|
431
|
+
def create_resource_reference(component: Union[SimComponent, SimultanObject],
|
432
|
+
resource: ContainedResourceFileEntry) -> Asset:
|
433
|
+
"""
|
434
|
+
Add a reference to a resource file to a component
|
435
|
+
:param component: Component to which to add the resource reference, Union[SimComponent, SimultanObject]
|
436
|
+
:type component: Union[SimComponent, SimultanObject]
|
437
|
+
:param resource: ParameterStructure.Assets.ContainedResourceFileEntry
|
438
|
+
:type resource: ContainedResourceFileEntry
|
439
|
+
:return: Created asset
|
440
|
+
:rtype: Asset
|
441
|
+
"""
|
442
|
+
component_wrapped_obj = component if isinstance(component, SimComponent) else component._wrapped_obj
|
443
|
+
return ComponentMapping.AddAsset(component_wrapped_obj, resource, '')
|
444
|
+
|
445
|
+
|
446
|
+
def add_referenced_component(component: Union[SimComponent, SimultanObject],
|
447
|
+
referenced_component: Union[SimComponent, SimultanObject],
|
448
|
+
slot_extension: Union[str, int, float],
|
449
|
+
slot: SimTaxonomyEntry = None):
|
450
|
+
"""
|
451
|
+
Add a reference to a component to a component
|
452
|
+
:param component: ParameterStructure.Components.SimComponent
|
453
|
+
:param referenced_component: ParameterStructure.Components.SimComponent
|
454
|
+
:param slot_extension: SLot extension of the referenced component
|
455
|
+
:param slot: ParameterStructure.Slots.SimSlot
|
456
|
+
:return:
|
457
|
+
"""
|
458
|
+
|
459
|
+
referenced_wrapped_obj = referenced_component if isinstance(referenced_component,
|
460
|
+
SimComponent) else referenced_component._wrapped_obj
|
461
|
+
|
462
|
+
component_wrapped_obj = component if isinstance(component, SimComponent) else component._wrapped_obj
|
463
|
+
|
464
|
+
if slot is None:
|
465
|
+
slot = referenced_wrapped_obj.Slots[0].Target
|
466
|
+
|
467
|
+
if isinstance(slot, SimTaxonomyEntry):
|
468
|
+
if slot not in [x.Target for x in referenced_wrapped_obj.Slots.Items]:
|
469
|
+
index = referenced_wrapped_obj.Slots.Items.__len__()
|
470
|
+
referenced_wrapped_obj.Slots.InsertItem(index, SimTaxonomyEntryReference(slot))
|
471
|
+
elif isinstance(slot, SimTaxonomyEntryReference):
|
472
|
+
if slot.Target not in [x.Target for x in referenced_wrapped_obj.Slots.Items]:
|
473
|
+
index = referenced_wrapped_obj.Slots.Items.__len__()
|
474
|
+
referenced_wrapped_obj.Slots.InsertItem(index, slot.SlotBase)
|
475
|
+
|
476
|
+
if isinstance(slot, SimTaxonomyEntryReference):
|
477
|
+
slot = slot.Target
|
478
|
+
|
479
|
+
if slot_extension is None:
|
480
|
+
new_slot = component_wrapped_obj.Components.FindAvailableSlot(slot, "{0}")
|
481
|
+
else:
|
482
|
+
new_slot = SimSlot(slot, str(slot_extension))
|
483
|
+
|
484
|
+
if isinstance(referenced_component, SimComponent):
|
485
|
+
ref = SimComponentReference(new_slot, referenced_wrapped_obj)
|
486
|
+
else:
|
487
|
+
ref = SimComponentReference(new_slot, referenced_wrapped_obj._wrapped_obj)
|
488
|
+
component_wrapped_obj.ReferencedComponents.Add(ref)
|
489
|
+
|
490
|
+
|
491
|
+
def remove_referenced_component(component: Union[SimComponent, SimultanObject],
|
492
|
+
referenced_component: Union[SimComponent, SimultanObject]):
|
493
|
+
"""
|
494
|
+
Remove a reference to a component from a component
|
495
|
+
:param component: ParameterStructure.Components.SimComponent
|
496
|
+
:param referenced_component: ParameterStructure.Components.SimComponent
|
497
|
+
:return:
|
498
|
+
"""
|
499
|
+
|
500
|
+
referenced_wrapped_obj = referenced_component if isinstance(referenced_component,
|
501
|
+
SimComponent) else referenced_component._wrapped_obj
|
502
|
+
|
503
|
+
component_wrapped_obj = component if isinstance(component, SimComponent) else component._wrapped_obj
|
504
|
+
|
505
|
+
for i, ref_comp in enumerate(component.ReferencedComponents.Items):
|
506
|
+
if ref_comp.Target == referenced_wrapped_obj:
|
507
|
+
component_wrapped_obj.ReferencedComponents.RemoveItem(i)
|
508
|
+
return
|
509
|
+
|
510
|
+
|
511
|
+
def find_components_with_taxonomy(component_list: list[SimComponent], key, first=False) -> set[SimComponent]:
|
512
|
+
|
513
|
+
components = set()
|
514
|
+
|
515
|
+
for component in component_list:
|
516
|
+
|
517
|
+
try:
|
518
|
+
for slot_item in component.Slots.Items:
|
519
|
+
if slot_item.Target.Key == key:
|
520
|
+
if first:
|
521
|
+
return component
|
522
|
+
components.add(component)
|
523
|
+
|
524
|
+
components.update(find_components_with_taxonomy([x.Component for x in component.Components], key, first))
|
525
|
+
except Exception as e:
|
526
|
+
print(e)
|
527
|
+
|
528
|
+
return components
|
529
|
+
|
530
|
+
|
531
|
+
def get_component_geometry(data_model, geometry_model, component) -> tuple[list[Vertex], list[Edge], list[Face], list[Volume]]:
|
532
|
+
"""
|
533
|
+
Get the geometry of a component from a geometry model
|
534
|
+
:param data_model:
|
535
|
+
:param geometry_model:
|
536
|
+
:param component:
|
537
|
+
:return:
|
538
|
+
"""
|
539
|
+
|
540
|
+
points = list()
|
541
|
+
pot_points = geometry_model.Geometry.Vertices
|
542
|
+
for point in pot_points:
|
543
|
+
if component in list(data_model.exch.GetComponents(point)):
|
544
|
+
points.append(point)
|
545
|
+
|
546
|
+
edges = list()
|
547
|
+
pot_edges = geometry_model.Geometry.Edges
|
548
|
+
for edge in pot_edges:
|
549
|
+
if component in list(data_model.exch.GetComponents(edge)):
|
550
|
+
edges.append(edge)
|
551
|
+
|
552
|
+
faces = list()
|
553
|
+
pot_faces = geometry_model.Geometry.Faces
|
554
|
+
for face in pot_faces:
|
555
|
+
if component in list(data_model.exch.GetComponents(face)):
|
556
|
+
faces.append(face)
|
557
|
+
|
558
|
+
volumes = list()
|
559
|
+
pot_volumes = geometry_model.Geometry.Volumes
|
560
|
+
for volume in pot_volumes:
|
561
|
+
if component in list(data_model.exch.GetComponents(volume)):
|
562
|
+
volumes.append(volume)
|
563
|
+
|
564
|
+
return points, edges, faces, volumes
|
565
|
+
|
566
|
+
|
567
|
+
def create_simultan_component_for_taxonomy(cls, *args, **kwargs) -> SimComponent:
|
568
|
+
"""
|
569
|
+
Create a new Simultan component for a taxonomy
|
570
|
+
:param cls:
|
571
|
+
:param args:
|
572
|
+
:param kwargs: add_to_data_model: if True, the component is added to the data model
|
573
|
+
:return:
|
574
|
+
"""
|
575
|
+
|
576
|
+
data_model = kwargs.get('data_model', None)
|
577
|
+
if data_model is None:
|
578
|
+
data_model = config.default_data_model
|
579
|
+
|
580
|
+
# simultan_taxonomy = cls._taxonomy_map.get_or_create_simultan_taxonomy(data_model=data_model)
|
581
|
+
# tayonomy_entry = cls._taxonomy_map.get_or_create_simultan_taxonomy_entry(data_model=data_model)
|
582
|
+
slot = cls._taxonomy_map.get_slot(data_model=data_model)
|
583
|
+
|
584
|
+
new_component = create_component(data_model=data_model,
|
585
|
+
slot=slot)
|
586
|
+
|
587
|
+
add_to_data_model = kwargs.get('add_to_data_model', True)
|
588
|
+
|
589
|
+
if add_to_data_model:
|
590
|
+
data_model.add_component(new_component)
|
591
|
+
|
592
|
+
return new_component
|
593
|
+
|
594
|
+
|
595
|
+
def get_component_taxonomy_entry(component, taxonomy: str):
|
596
|
+
|
597
|
+
obj = None
|
598
|
+
|
599
|
+
# search in subcomponents
|
600
|
+
for sub_comp in component.Components:
|
601
|
+
if sub_comp.Slot.get_SlotBase().Target.Key == taxonomy:
|
602
|
+
return sub_comp.Component
|
603
|
+
|
604
|
+
# search in referenced components
|
605
|
+
for comp in component.ReferencedComponents:
|
606
|
+
if comp.Slot.SlotBase.Target.Key == taxonomy:
|
607
|
+
return comp.Target
|
608
|
+
|
609
|
+
# search in parameters
|
610
|
+
for param in component.Parameters:
|
611
|
+
if param.NameTaxonomyEntry.TextOrKey == taxonomy:
|
612
|
+
return param
|
613
|
+
|
614
|
+
for referenced_asset in component.ReferencedAssets:
|
615
|
+
resource_taxonomy_keys = [x.Target.Key for x in referenced_asset.Resource.Tags]
|
616
|
+
if taxonomy in resource_taxonomy_keys:
|
617
|
+
return referenced_asset.Resource
|
618
|
+
|
619
|
+
if obj is None:
|
620
|
+
return None
|
621
|
+
|
622
|
+
|
623
|
+
def sort_slots(slots, check_same_slot=False) -> list[SimSlot]:
|
624
|
+
|
625
|
+
if slots.__len__() == 0:
|
626
|
+
return slots
|
627
|
+
|
628
|
+
if check_same_slot:
|
629
|
+
if not all(slots[0].SlotBase == x.SlotBase for x in slots):
|
630
|
+
raise TypeError(f'List elements do not have same slot')
|
631
|
+
|
632
|
+
slot_extensions = [x.SlotExtension for x in slots]
|
633
|
+
return slot_extensions
|
634
|
+
|
635
|
+
|
636
|
+
def get_property(prop_name, component=None, wrapped_obj=None, object_mapper=None):
|
637
|
+
|
638
|
+
if component is not None:
|
639
|
+
obj = get_component_taxonomy_entry(component._wrapped_obj, prop_name)
|
640
|
+
data_model = component._data_model
|
641
|
+
object_mapper = component._object_mapper
|
642
|
+
else:
|
643
|
+
data_model = config.default_data_model
|
644
|
+
obj = get_component_taxonomy_entry(wrapped_obj, prop_name)
|
645
|
+
|
646
|
+
return get_obj_value(obj, data_model=data_model, object_mapper=object_mapper)
|
647
|
+
|
648
|
+
|
649
|
+
def get_parameter_value(obj, data_model=None, object_mapper=None):
|
650
|
+
return obj.Value
|
651
|
+
|
652
|
+
|
653
|
+
def get_sim_component_value(obj: SimComponent,
|
654
|
+
object_mapper: PythonMapper,
|
655
|
+
data_model: DataModel) -> SimComponent:
|
656
|
+
return object_mapper.create_python_object(obj, data_model=data_model)
|
657
|
+
|
658
|
+
|
659
|
+
def get_sim_double_parameter_value(obj: SimDoubleParameter,
|
660
|
+
*args,
|
661
|
+
**kwargs) -> Union[int, float, pd.DataFrame, np.ndarray]:
|
662
|
+
if obj.ValueSource is not None:
|
663
|
+
if isinstance(obj.ValueSource, SimMultiValueField3DParameterSource):
|
664
|
+
return simultan_multi_value_field_3d_to_numpy(obj.ValueSource.Field)
|
665
|
+
elif isinstance(obj.ValueSource, SimMultiValueBigTableParameterSource):
|
666
|
+
return simultan_multi_value_big_table_to_pandas(obj.ValueSource.Table)
|
667
|
+
else:
|
668
|
+
raise ValueError(f'Value source {obj.ValueSource} not supported.')
|
669
|
+
return obj.Value
|
670
|
+
|
671
|
+
|
672
|
+
def get_resource_entry_value(obj: ResourceEntry,
|
673
|
+
data_model: DataModel = None,
|
674
|
+
object_mapper: PythonMapper = None) -> FileInfo:
|
675
|
+
return FileInfo(file_path=obj.File.FullPath,
|
676
|
+
resource_entry=obj,
|
677
|
+
data_model=data_model)
|
678
|
+
|
679
|
+
|
680
|
+
type_convert_dict = {SimComponent: get_sim_component_value,
|
681
|
+
SimDoubleParameter: get_sim_double_parameter_value,
|
682
|
+
SimIntegerParameter: get_parameter_value,
|
683
|
+
SimStringParameter: get_parameter_value,
|
684
|
+
SimBoolParameter: get_parameter_value,
|
685
|
+
SimEnumParameter: get_parameter_value,
|
686
|
+
ResourceEntry: get_resource_entry_value,
|
687
|
+
ContainedResourceFileEntry: get_resource_entry_value,
|
688
|
+
LinkedResourceFileEntry: get_resource_entry_value}
|
689
|
+
|
690
|
+
|
691
|
+
def get_obj_value(obj: Union[SimComponent, SimDoubleParameter, SimIntegerParameter, SimStringParameter,
|
692
|
+
SimBoolParameter, SimEnumParameter, ResourceEntry, ContainedResourceFileEntry, None],
|
693
|
+
data_model: DataModel,
|
694
|
+
object_mapper: PythonMapper) -> Union[SimultanObject, int, float, str, FileInfo, None, pd.DataFrame,
|
695
|
+
np.ndarray]:
|
696
|
+
|
697
|
+
if obj is None:
|
698
|
+
return
|
699
|
+
elif type(obj) in type_convert_dict.keys():
|
700
|
+
return type_convert_dict[type(obj)](obj, data_model=data_model, object_mapper=object_mapper)
|
701
|
+
else:
|
702
|
+
logger.warning(f'Object type {type(obj)} not supported.')
|
703
|
+
return obj
|
704
|
+
|
705
|
+
#
|
706
|
+
# if obj is None:
|
707
|
+
# return None
|
708
|
+
# elif isinstance(obj, SimComponent):
|
709
|
+
# return object_mapper.create_python_object(obj, data_model=data_model)
|
710
|
+
# elif isinstance(obj, SimDoubleParameter):
|
711
|
+
# if obj.ValueSource is not None:
|
712
|
+
# if isinstance(obj.ValueSource, SimMultiValueField3DParameterSource):
|
713
|
+
# return simultan_multi_value_field_3d_to_numpy(obj.ValueSource.Field)
|
714
|
+
# elif isinstance(obj.ValueSource, SimMultiValueBigTableParameterSource):
|
715
|
+
# return simultan_multi_value_big_table_to_pandas(obj.ValueSource.Table)
|
716
|
+
# else:
|
717
|
+
# raise ValueError(f'Value source {obj.ValueSource} not supported.')
|
718
|
+
# return obj.Value
|
719
|
+
# elif isinstance(obj, SimIntegerParameter):
|
720
|
+
# return obj.Value
|
721
|
+
# elif isinstance(obj, SimStringParameter):
|
722
|
+
# return obj.Value
|
723
|
+
# elif isinstance(obj, SimBoolParameter):
|
724
|
+
# return obj.Value
|
725
|
+
# elif isinstance(obj, SimEnumParameter):
|
726
|
+
# return obj.Value
|
727
|
+
# elif isinstance(obj, ResourceEntry):
|
728
|
+
# return FileInfo(file_path=obj.File.FullPath,
|
729
|
+
# resource_entry=obj,
|
730
|
+
# data_model=data_model)
|
731
|
+
# else:
|
732
|
+
# return obj
|
733
|
+
|
734
|
+
|
735
|
+
def get_param_indices(wrapped_obj: SimComponent,
|
736
|
+
taxonomy_entry: SimTaxonomyEntry) -> tuple[int, int, int, int]:
|
737
|
+
"""
|
738
|
+
Get the indices of a taxonomy entry in a component
|
739
|
+
:param wrapped_obj:
|
740
|
+
:param taxonomy_entry:
|
741
|
+
:return: Index of the component, index of the referenced component, index of the parameter,
|
742
|
+
index of the referenced asset
|
743
|
+
"""
|
744
|
+
|
745
|
+
parameter_idx = next((i for i, x in enumerate(wrapped_obj.Parameters.Items) if
|
746
|
+
x.NameTaxonomyEntry.TextOrKey == taxonomy_entry.Key), None)
|
747
|
+
|
748
|
+
component_idx = next((i for i, x in enumerate(wrapped_obj.Components.Items) if
|
749
|
+
x.Slot.SlotBase.Target.Key == taxonomy_entry.Key), None)
|
750
|
+
|
751
|
+
ref_component_idx = next((i for i, x in enumerate(wrapped_obj.ReferencedComponents.Items) if
|
752
|
+
x.Slot.SlotBase.Target.Key == taxonomy_entry.Key), None)
|
753
|
+
|
754
|
+
ref_asset_idx = next((i for i, x in enumerate(wrapped_obj.ReferencedAssets.Items) if taxonomy_entry.Key in
|
755
|
+
[y.Target.Key for y in x.Resource.Tags]), None)
|
756
|
+
|
757
|
+
return component_idx, ref_component_idx, parameter_idx, ref_asset_idx
|
758
|
+
|
759
|
+
|
760
|
+
def create_component_list(values,
|
761
|
+
name=None,
|
762
|
+
data_model: Union[DataModel, None] = None,
|
763
|
+
additional_slots: Union[TypeList[SimSlot], TypeList[SimTaxonomyEntryReference]] = None,
|
764
|
+
object_mapper: Union[PythonMapper, None] = None,
|
765
|
+
add_to_data_model: bool = True) -> ComponentList:
|
766
|
+
"""
|
767
|
+
Create a new component list
|
768
|
+
:param values: values of the component list
|
769
|
+
:param name: name of the component list
|
770
|
+
:param data_model: data model to use
|
771
|
+
:param additional_slots: additional slots to use
|
772
|
+
:param object_mapper: object mapper to use
|
773
|
+
:param add_to_data_model: if True, the component list is added to the data model
|
774
|
+
:return: ComponentList
|
775
|
+
"""
|
776
|
+
from .default_types import ComponentList
|
777
|
+
|
778
|
+
new_component_list = ComponentList.create_from_values(data_model=data_model,
|
779
|
+
values=values,
|
780
|
+
object_mapper=object_mapper,
|
781
|
+
add_to_data_model=add_to_data_model)
|
782
|
+
new_component_list._wrapped_obj.Name = name
|
783
|
+
|
784
|
+
if additional_slots is not None:
|
785
|
+
for i, slot in enumerate(additional_slots):
|
786
|
+
if isinstance(slot, SimTaxonomyEntryReference):
|
787
|
+
new_component_list.add_taxonomy_entry_reference(slot, index=i)
|
788
|
+
elif isinstance(slot, SimSlot):
|
789
|
+
new_component_list.add_taxonomy_entry_reference(slot.SlotBase, index=i)
|
790
|
+
elif isinstance(slot, SimTaxonomyEntry):
|
791
|
+
new_component_list.add_taxonomy_entry_reference(SimTaxonomyEntryReference(slot), index=i)
|
792
|
+
|
793
|
+
return new_component_list
|
794
|
+
|
795
|
+
|
796
|
+
def create_component_dict(values,
|
797
|
+
name=None,
|
798
|
+
data_model: Union[DataModel, None] = None,
|
799
|
+
additional_slots: Union[TypeList[SimSlot], TypeList[SimTaxonomyEntryReference]] = None,
|
800
|
+
object_mapper: Union[PythonMapper, None] = None,
|
801
|
+
add_to_data_model: bool = True):
|
802
|
+
from .default_types import ComponentDictionary
|
803
|
+
new_component_dict = ComponentDictionary.create_from_values(data_model=data_model,
|
804
|
+
values=values,
|
805
|
+
object_mapper=object_mapper,
|
806
|
+
add_to_data_model=add_to_data_model)
|
807
|
+
new_component_dict._wrapped_obj.Name = name
|
808
|
+
|
809
|
+
if additional_slots is not None:
|
810
|
+
for i, slot in enumerate(additional_slots):
|
811
|
+
if isinstance(slot, SimTaxonomyEntryReference):
|
812
|
+
new_component_dict.add_taxonomy_entry_reference(slot, index=i)
|
813
|
+
elif isinstance(slot, SimSlot):
|
814
|
+
new_component_dict.add_taxonomy_entry_reference(slot.SlotBase, index=i)
|
815
|
+
elif isinstance(slot, SimTaxonomyEntry):
|
816
|
+
new_component_dict.add_taxonomy_entry_reference(SimTaxonomyEntryReference(slot), index=i)
|
817
|
+
|
818
|
+
return new_component_dict
|
819
|
+
|
820
|
+
|
821
|
+
param_type_lookup_dict = {str: SimStringParameter,
|
822
|
+
int: SimIntegerParameter,
|
823
|
+
float: SimDoubleParameter,
|
824
|
+
bool: SimBoolParameter}
|
825
|
+
|
826
|
+
|
827
|
+
def create_mapped_python_object(value: SimComponent,
|
828
|
+
object_mapper: PythonMapper,
|
829
|
+
data_model: DataModel,
|
830
|
+
add_to_data_model=True) -> SimultanObject:
|
831
|
+
"""
|
832
|
+
Create a mapped python object from a python object and add it to the data model or as subcomponent to a parent
|
833
|
+
:param value: python object to map
|
834
|
+
:param object_mapper: object mapper to use
|
835
|
+
:param data_model: data model to use
|
836
|
+
:param add_to_data_model: if True, the object is added to the data model
|
837
|
+
:return: mapped python object
|
838
|
+
"""
|
839
|
+
|
840
|
+
if object_mapper is None:
|
841
|
+
object_mapper = config.default_mapper
|
842
|
+
|
843
|
+
# logger.debug(f'Creating mapped python object for {value}.')
|
844
|
+
if type(value) in object_mapper.registered_classes.values():
|
845
|
+
key = list(filter(lambda x: object_mapper.registered_classes[x] ==
|
846
|
+
type(value), object_mapper.registered_classes))[0]
|
847
|
+
mapped_cls = object_mapper.get_mapped_class(key)
|
848
|
+
new_val = mapped_cls(**value.__dict__,
|
849
|
+
data_model=data_model,
|
850
|
+
object_mapper=object_mapper,
|
851
|
+
add_to_data_model=add_to_data_model)
|
852
|
+
|
853
|
+
# logger.debug(f'Created mapped python object {new_val} for {value}.')
|
854
|
+
return new_val
|
855
|
+
elif isinstance(value, dict):
|
856
|
+
from .default_types import ComponentDictionary
|
857
|
+
new_val = ComponentDictionary.create_from_values(data_model=data_model,
|
858
|
+
values=value,
|
859
|
+
object_mapper=object_mapper,
|
860
|
+
add_to_data_model=add_to_data_model)
|
861
|
+
return new_val
|
862
|
+
elif isinstance(value, (list, set, tuple)):
|
863
|
+
from .default_types import ComponentList
|
864
|
+
new_val = ComponentList.create_from_values(data_model=data_model,
|
865
|
+
values=value,
|
866
|
+
object_mapper=object_mapper,
|
867
|
+
add_to_data_model=add_to_data_model)
|
868
|
+
return new_val
|
869
|
+
elif isinstance(value, UnresolvedObject):
|
870
|
+
return value.resolve()
|
871
|
+
else:
|
872
|
+
raise TypeError(f'Error creating mapped python object for {value}.')
|
873
|
+
|
874
|
+
|
875
|
+
def remove_prop_from_sim_component(component: SimComponent,
|
876
|
+
component_idx: int = None,
|
877
|
+
ref_component_idx: int = None,
|
878
|
+
parameter_idx: int = None,
|
879
|
+
ref_asset_idx: int = None,
|
880
|
+
keep: list[str] = None):
|
881
|
+
|
882
|
+
if keep is None:
|
883
|
+
keep = []
|
884
|
+
|
885
|
+
if component_idx is not None and 'component_idx' not in keep:
|
886
|
+
component.Components.RemoveItem(component_idx)
|
887
|
+
component_idx = None
|
888
|
+
if ref_component_idx is not None and 'ref_component_idx'not in keep:
|
889
|
+
component.ReferencedComponents.RemoveItem(ref_component_idx)
|
890
|
+
ref_component_idx = None
|
891
|
+
if parameter_idx is not None and 'parameter_idx' not in keep:
|
892
|
+
component.Parameters.RemoveItem(parameter_idx)
|
893
|
+
parameter_idx = None
|
894
|
+
|
895
|
+
if ref_asset_idx is not None and 'ref_asset_idx' not in keep:
|
896
|
+
asset = component.ReferencedAssets.Items[ref_asset_idx]
|
897
|
+
remove_asset_from_component(component, asset)
|
898
|
+
|
899
|
+
|
900
|
+
def set_property_to_list(value: Union[list, tuple, set, ComponentList],
|
901
|
+
component: SimultanObject,
|
902
|
+
prop_name: str,
|
903
|
+
taxonomy_entry: SimTaxonomyEntry,
|
904
|
+
slot_extension: Union[str, int, float],
|
905
|
+
component_idx: int = None,
|
906
|
+
ref_component_idx: int = None,
|
907
|
+
parameter_idx: int = None,
|
908
|
+
ref_asset_idx: int = None,
|
909
|
+
content: Content = None):
|
910
|
+
|
911
|
+
from .default_types import ComponentList
|
912
|
+
|
913
|
+
remove_prop_from_sim_component(component=component,
|
914
|
+
component_idx=component_idx,
|
915
|
+
ref_component_idx=ref_component_idx,
|
916
|
+
parameter_idx=parameter_idx,
|
917
|
+
ref_asset_idx=ref_asset_idx,
|
918
|
+
keep=['component_idx', 'ref_component_idx'])
|
919
|
+
|
920
|
+
if isinstance(value, ComponentList):
|
921
|
+
if component_idx is not None:
|
922
|
+
if value._wrapped_obj.Id.Equals(component._wrapped_obj.Components.Items[component_idx].Component.Id):
|
923
|
+
return
|
924
|
+
else:
|
925
|
+
component._wrapped_obj.Components.RemoveItem(component_idx)
|
926
|
+
component_idx = None
|
927
|
+
if ref_component_idx is not None:
|
928
|
+
if value._wrapped_obj.Id.Equals(
|
929
|
+
component._wrapped_obj.ReferencedComponents.Items[ref_component_idx].Target.Id):
|
930
|
+
return
|
931
|
+
|
932
|
+
if component_idx is not None:
|
933
|
+
component = component._wrapped_obj.Components.Items[component_idx].Component
|
934
|
+
|
935
|
+
if 'ComponentList' in [x.Target.Key for x in component.Slots]:
|
936
|
+
if not hasattr(component, '_object_mapper'):
|
937
|
+
mapper = config.default_mapper
|
938
|
+
component._object_mapper = mapper
|
939
|
+
else:
|
940
|
+
mapper = component._object_mapper
|
941
|
+
|
942
|
+
if not hasattr(component, '_data_model'):
|
943
|
+
data_model = config.default_data_model
|
944
|
+
component._data_model = data_model
|
945
|
+
else:
|
946
|
+
data_model = component._data_model
|
947
|
+
|
948
|
+
component_list = mapper.create_python_object(component, data_model=data_model)
|
949
|
+
component_list.clear()
|
950
|
+
component_list.extend(value)
|
951
|
+
return component_list
|
952
|
+
else:
|
953
|
+
component._data_model.remove_subcomponent(component)
|
954
|
+
component._wrapped_obj.Components.RemoveItem(component_idx)
|
955
|
+
component_idx = None
|
956
|
+
if ref_component_idx is not None:
|
957
|
+
# component._data_model.remove_referenced_component(component, ref_component_idx)
|
958
|
+
component._wrapped_obj.ReferencedComponents.RemoveItem(ref_component_idx)
|
959
|
+
ref_component_idx = None
|
960
|
+
|
961
|
+
slot = SimTaxonomyEntryReference(taxonomy_entry)
|
962
|
+
|
963
|
+
new_component_list = create_component_list(values=value,
|
964
|
+
name=prop_name,
|
965
|
+
additional_slots=[slot],
|
966
|
+
data_model=component._data_model,
|
967
|
+
object_mapper=component._object_mapper,
|
968
|
+
add_to_data_model=True)
|
969
|
+
|
970
|
+
component.add_subcomponent(new_component_list,
|
971
|
+
slot_extension=slot_extension,
|
972
|
+
slot=slot)
|
973
|
+
|
974
|
+
|
975
|
+
def set_property_to_sim_component(value: Union[SimComponent, SimultanObject, list, tuple, set, ComponentList],
|
976
|
+
component: SimultanObject,
|
977
|
+
prop_name: str,
|
978
|
+
taxonomy_entry: SimTaxonomyEntry,
|
979
|
+
slot_extension: Union[str, int, float],
|
980
|
+
component_idx: int = None,
|
981
|
+
ref_component_idx: int = None,
|
982
|
+
parameter_idx: int = None,
|
983
|
+
ref_asset_idx: int = None,
|
984
|
+
content: Content = None) -> None:
|
985
|
+
|
986
|
+
wrapped_obj = value if isinstance(value, SimComponent) else value._wrapped_obj
|
987
|
+
remove_prop_from_sim_component(component=component,
|
988
|
+
component_idx=component_idx,
|
989
|
+
ref_component_idx=ref_component_idx,
|
990
|
+
parameter_idx=parameter_idx,
|
991
|
+
ref_asset_idx=ref_asset_idx,
|
992
|
+
keep=['component_idx', 'ref_component_idx'])
|
993
|
+
|
994
|
+
if component_idx is not None:
|
995
|
+
if wrapped_obj.Id.Equals(component._wrapped_obj.Components.Items[component_idx].Component.Id):
|
996
|
+
return
|
997
|
+
else:
|
998
|
+
component._wrapped_obj.Components.RemoveItem(component_idx)
|
999
|
+
if ref_component_idx is not None:
|
1000
|
+
if wrapped_obj.Id.Equals(component._wrapped_obj.ReferencedComponents.Items[ref_component_idx].Target.Id):
|
1001
|
+
return
|
1002
|
+
else:
|
1003
|
+
component._wrapped_obj.ReferencedComponents.RemoveItem(ref_component_idx)
|
1004
|
+
|
1005
|
+
if content.component_policy in (None, 'reference') or wrapped_obj.Parent is not None:
|
1006
|
+
component.add_referenced_component(value,
|
1007
|
+
slot_extension=slot_extension,
|
1008
|
+
slot=taxonomy_entry)
|
1009
|
+
elif content.component_policy == 'subcomponent':
|
1010
|
+
component.add_subcomponent(value,
|
1011
|
+
slot_extension=slot_extension,
|
1012
|
+
slot=taxonomy_entry)
|
1013
|
+
|
1014
|
+
|
1015
|
+
def set_property_to_file_info(value: FileInfo,
|
1016
|
+
component: SimultanObject,
|
1017
|
+
prop_name: str,
|
1018
|
+
taxonomy_entry: SimTaxonomyEntry,
|
1019
|
+
slot_extension: Union[str, int, float],
|
1020
|
+
component_idx: int = None,
|
1021
|
+
ref_component_idx: int = None,
|
1022
|
+
parameter_idx: int = None,
|
1023
|
+
ref_asset_idx: int = None,
|
1024
|
+
content: Content = None) -> None:
|
1025
|
+
|
1026
|
+
remove_prop_from_sim_component(component=component,
|
1027
|
+
component_idx=component_idx,
|
1028
|
+
ref_component_idx=ref_component_idx,
|
1029
|
+
parameter_idx=parameter_idx,
|
1030
|
+
ref_asset_idx=ref_asset_idx,
|
1031
|
+
keep=['ref_asset_idx'])
|
1032
|
+
|
1033
|
+
value.data_model = component._data_model
|
1034
|
+
|
1035
|
+
if ref_asset_idx is not None:
|
1036
|
+
asset = component._wrapped_obj.ReferencedAssets.Items[ref_asset_idx]
|
1037
|
+
|
1038
|
+
if hasattr(value, 'resource_entry'):
|
1039
|
+
if asset.Resource.Key == value.resource_entry.Key:
|
1040
|
+
return
|
1041
|
+
elif asset.Resource.CurrentFullPath == str(value.file_path):
|
1042
|
+
return
|
1043
|
+
|
1044
|
+
remove_asset_from_component(component._wrapped_obj, asset)
|
1045
|
+
ref_asset_idx = None
|
1046
|
+
|
1047
|
+
add_asset_to_component(component._wrapped_obj,
|
1048
|
+
value.resource_entry,
|
1049
|
+
'0',
|
1050
|
+
tag=taxonomy_entry)
|
1051
|
+
|
1052
|
+
|
1053
|
+
def set_property_to_parameter(value: Union[int, float, str],
|
1054
|
+
component: SimultanObject,
|
1055
|
+
prop_name: str,
|
1056
|
+
taxonomy_entry: SimTaxonomyEntry,
|
1057
|
+
slot_extension: Union[str, int, float],
|
1058
|
+
component_idx: int = None,
|
1059
|
+
ref_component_idx: int = None,
|
1060
|
+
parameter_idx: int = None,
|
1061
|
+
ref_asset_idx: int = None,
|
1062
|
+
content: Content = None) -> None:
|
1063
|
+
|
1064
|
+
remove_prop_from_sim_component(component=component,
|
1065
|
+
component_idx=component_idx,
|
1066
|
+
ref_component_idx=ref_component_idx,
|
1067
|
+
parameter_idx=parameter_idx,
|
1068
|
+
ref_asset_idx=ref_asset_idx,
|
1069
|
+
keep=['parameter_idx'])
|
1070
|
+
|
1071
|
+
wrapped_obj = component._wrapped_obj
|
1072
|
+
|
1073
|
+
if parameter_idx is not None:
|
1074
|
+
existing_parameter_type = type(wrapped_obj.Parameters.Items[parameter_idx])
|
1075
|
+
|
1076
|
+
new_param_type = content.type if content.type is not None else param_type_lookup_dict[type(value)]
|
1077
|
+
|
1078
|
+
if new_param_type is not existing_parameter_type:
|
1079
|
+
wrapped_obj.Parameters.RemoveItem(parameter_idx)
|
1080
|
+
parameter_idx = None
|
1081
|
+
else:
|
1082
|
+
if wrapped_obj.Parameters.Items[parameter_idx].Value == value:
|
1083
|
+
return
|
1084
|
+
else:
|
1085
|
+
wrapped_obj.Parameters.Items[parameter_idx].set_Value(value)
|
1086
|
+
return
|
1087
|
+
|
1088
|
+
if parameter_idx is None:
|
1089
|
+
param = create_parameter(value=value,
|
1090
|
+
name=prop_name,
|
1091
|
+
unit=content.unit if content.unit is not None else '',
|
1092
|
+
taxonomy_entry=taxonomy_entry,
|
1093
|
+
parameter_type=content.type)
|
1094
|
+
for key, value in content.additional_attributes.items():
|
1095
|
+
if hasattr(param, key):
|
1096
|
+
setattr(param, key, value)
|
1097
|
+
wrapped_obj.Parameters.Add(param)
|
1098
|
+
elif parameter_idx is not None:
|
1099
|
+
wrapped_obj.Parameters.Items[parameter_idx].set_Value(value)
|
1100
|
+
|
1101
|
+
|
1102
|
+
def set_property_to_value_field(value: Union[np.ndarray, pd.DataFrame],
|
1103
|
+
component: SimultanObject,
|
1104
|
+
prop_name: str,
|
1105
|
+
taxonomy_entry: SimTaxonomyEntry,
|
1106
|
+
slot_extension: Union[str, int, float],
|
1107
|
+
component_idx: int = None,
|
1108
|
+
ref_component_idx: int = None,
|
1109
|
+
parameter_idx: int = None,
|
1110
|
+
ref_asset_idx: int = None,
|
1111
|
+
content: Content = None
|
1112
|
+
) -> None:
|
1113
|
+
|
1114
|
+
remove_prop_from_sim_component(component=component,
|
1115
|
+
component_idx=component_idx,
|
1116
|
+
ref_component_idx=ref_component_idx,
|
1117
|
+
parameter_idx=parameter_idx,
|
1118
|
+
ref_asset_idx=ref_asset_idx,
|
1119
|
+
keep=['parameter_idx'])
|
1120
|
+
|
1121
|
+
wrapped_obj = component._wrapped_obj
|
1122
|
+
|
1123
|
+
if parameter_idx is not None:
|
1124
|
+
existing_parameter_type = type(wrapped_obj.Parameters.Items[parameter_idx])
|
1125
|
+
|
1126
|
+
if existing_parameter_type is not SimDoubleParameter:
|
1127
|
+
wrapped_obj.Parameters.RemoveItem(parameter_idx)
|
1128
|
+
parameter_idx = None
|
1129
|
+
else:
|
1130
|
+
value_source = wrapped_obj.Parameters.Items[parameter_idx].ValueSource
|
1131
|
+
|
1132
|
+
if isinstance(value_source, SimMultiValueField3DParameterSource):
|
1133
|
+
value_field = wrapped_obj.Parameters.Items[parameter_idx].ValueSource.Field
|
1134
|
+
elif isinstance(value_source, SimMultiValueBigTableParameterSource):
|
1135
|
+
value_field = wrapped_obj.Parameters.Items[parameter_idx].ValueSource.Table
|
1136
|
+
else:
|
1137
|
+
raise ValueError(f'Value source {value_source} not supported.')
|
1138
|
+
|
1139
|
+
component._data_model.remove_field(value_field)
|
1140
|
+
set_parameter_to_value_field(wrapped_obj.Parameters.Items[parameter_idx],
|
1141
|
+
value,
|
1142
|
+
field_name=str(component.id) + '_' + prop_name,
|
1143
|
+
data_model=component._data_model)
|
1144
|
+
|
1145
|
+
if parameter_idx is None:
|
1146
|
+
param = create_field_parameter(field_name=str(component.id) + '_' + prop_name,
|
1147
|
+
value=value,
|
1148
|
+
slot=taxonomy_entry,
|
1149
|
+
data_model=component._data_model)
|
1150
|
+
wrapped_obj.Parameters.Add(param)
|
1151
|
+
|
1152
|
+
|
1153
|
+
def set_property_to_unknown_type(value,
|
1154
|
+
component: SimultanObject,
|
1155
|
+
prop_name: str,
|
1156
|
+
*args, **kwargs):
|
1157
|
+
from .default_types import ComponentList, ComponentDictionary
|
1158
|
+
|
1159
|
+
new_val = create_mapped_python_object(value, component._object_mapper, component._data_model)
|
1160
|
+
if isinstance(component, ComponentDictionary):
|
1161
|
+
component[prop_name] = new_val
|
1162
|
+
else:
|
1163
|
+
setattr(component, prop_name, new_val)
|
1164
|
+
|
1165
|
+
|
1166
|
+
def set_property_to_dict(value: dict,
|
1167
|
+
component: SimultanObject,
|
1168
|
+
prop_name: str,
|
1169
|
+
taxonomy_entry: SimTaxonomyEntry,
|
1170
|
+
slot_extension: Union[str, int, float],
|
1171
|
+
component_idx: int = None,
|
1172
|
+
ref_component_idx: int = None,
|
1173
|
+
parameter_idx: int = None,
|
1174
|
+
ref_asset_idx: int = None,
|
1175
|
+
content: Content = None):
|
1176
|
+
|
1177
|
+
from .default_types import ComponentDictionary
|
1178
|
+
|
1179
|
+
remove_prop_from_sim_component(component=component,
|
1180
|
+
component_idx=component_idx,
|
1181
|
+
ref_component_idx=ref_component_idx,
|
1182
|
+
parameter_idx=parameter_idx,
|
1183
|
+
ref_asset_idx=ref_asset_idx,
|
1184
|
+
keep=['component_idx', 'ref_component_idx'])
|
1185
|
+
|
1186
|
+
if isinstance(value, ComponentDictionary):
|
1187
|
+
if component_idx is not None:
|
1188
|
+
if value._wrapped_obj.Id.Equals(component._wrapped_obj.Components.Items[component_idx].Component.Id):
|
1189
|
+
return
|
1190
|
+
else:
|
1191
|
+
component._wrapped_obj.Components.RemoveItem(component_idx)
|
1192
|
+
component_idx = None
|
1193
|
+
if ref_component_idx is not None:
|
1194
|
+
if value._wrapped_obj.Id.Equals(
|
1195
|
+
component._wrapped_obj.ReferencedComponents.Items[ref_component_idx].Target.Id):
|
1196
|
+
return
|
1197
|
+
|
1198
|
+
if component_idx is not None:
|
1199
|
+
component = component._wrapped_obj.Components.Items[component_idx].Component
|
1200
|
+
|
1201
|
+
if 'ComponentDictionary' in [x.Target.Key for x in component.Slots]:
|
1202
|
+
if not hasattr(component, '_object_mapper'):
|
1203
|
+
mapper = config.default_mapper
|
1204
|
+
component._object_mapper = mapper
|
1205
|
+
else:
|
1206
|
+
mapper = component._object_mapper
|
1207
|
+
|
1208
|
+
if not hasattr(component, '_data_model'):
|
1209
|
+
data_model = config.default_data_model
|
1210
|
+
component._data_model = data_model
|
1211
|
+
else:
|
1212
|
+
data_model = component._data_model
|
1213
|
+
|
1214
|
+
component_dict = mapper.create_python_object(component, data_model=data_model)
|
1215
|
+
component_dict.clear()
|
1216
|
+
component_dict.update(value)
|
1217
|
+
return component_dict
|
1218
|
+
else:
|
1219
|
+
component._data_model.remove_subcomponent(component)
|
1220
|
+
component._wrapped_obj.Components.RemoveItem(component_idx)
|
1221
|
+
component_idx = None
|
1222
|
+
if ref_component_idx is not None:
|
1223
|
+
# component._data_model.remove_referenced_component(component, ref_component_idx)
|
1224
|
+
component._wrapped_obj.ReferencedComponents.RemoveItem(ref_component_idx)
|
1225
|
+
ref_component_idx = None
|
1226
|
+
|
1227
|
+
slot = SimTaxonomyEntryReference(taxonomy_entry)
|
1228
|
+
|
1229
|
+
new_component_dict = create_component_dict(values=value,
|
1230
|
+
name=prop_name,
|
1231
|
+
additional_slots=[slot],
|
1232
|
+
data_model=component._data_model,
|
1233
|
+
object_mapper=component._object_mapper,
|
1234
|
+
add_to_data_model=True)
|
1235
|
+
|
1236
|
+
component.add_subcomponent(new_component_dict,
|
1237
|
+
slot_extension=slot_extension,
|
1238
|
+
slot=slot)
|
1239
|
+
|
1240
|
+
|
1241
|
+
def add_properties(prop_name: str,
|
1242
|
+
content: Content,
|
1243
|
+
taxonomy: str,
|
1244
|
+
taxonomy_map: 'TaxonomyMap') -> property:
|
1245
|
+
|
1246
|
+
"""
|
1247
|
+
create property for a class
|
1248
|
+
:param prop_name: name of the property (str)
|
1249
|
+
:param content: content of the property (Content)
|
1250
|
+
:param prop_name: name of the synonym (str)
|
1251
|
+
:param taxonomy: taxonomy to use (str)
|
1252
|
+
:param syn_name: name of the synonym (str)
|
1253
|
+
:param taxonomy_map: taxonomy map to use (TaxonomyMap)
|
1254
|
+
:return: property
|
1255
|
+
"""
|
1256
|
+
|
1257
|
+
from .default_types import ComponentList, ComponentDictionary
|
1258
|
+
|
1259
|
+
type_setter_fcn_lookup_dict = {None: lambda x: None,
|
1260
|
+
SimComponent: set_property_to_sim_component,
|
1261
|
+
SimultanObject: set_property_to_sim_component,
|
1262
|
+
SimDoubleParameter: set_property_to_parameter,
|
1263
|
+
SimIntegerParameter: set_property_to_parameter,
|
1264
|
+
SimStringParameter: set_property_to_parameter,
|
1265
|
+
SimBoolParameter: set_property_to_parameter,
|
1266
|
+
SimEnumParameter: set_property_to_parameter,
|
1267
|
+
int: set_property_to_parameter,
|
1268
|
+
float: set_property_to_parameter,
|
1269
|
+
str: set_property_to_parameter,
|
1270
|
+
bool: set_property_to_parameter,
|
1271
|
+
FileInfo: set_property_to_file_info,
|
1272
|
+
list: set_property_to_list,
|
1273
|
+
tuple: set_property_to_list,
|
1274
|
+
set: set_property_to_list,
|
1275
|
+
dict: set_property_to_dict,
|
1276
|
+
ComponentDictionary: set_property_to_dict,
|
1277
|
+
ComponentList: set_property_to_list,
|
1278
|
+
np.ndarray: set_property_to_value_field,
|
1279
|
+
pd.DataFrame: set_property_to_value_field}
|
1280
|
+
|
1281
|
+
# @lru_cache()
|
1282
|
+
def getx(self):
|
1283
|
+
return get_property(component=self,
|
1284
|
+
prop_name=content.text_or_key,
|
1285
|
+
object_mapper=self._object_mapper)
|
1286
|
+
|
1287
|
+
getx.__taxonomy__ = taxonomy
|
1288
|
+
|
1289
|
+
content = next((x for x in taxonomy_map.content if x.property_name == prop_name), None)
|
1290
|
+
|
1291
|
+
def setx(self, value: Union[int, float, SimComponent, SimultanObject]):
|
1292
|
+
# logger.debug(f'{self.name} {self.id}: Setting {prop_name} to {value}.')
|
1293
|
+
slot_extension = content.slot_extension
|
1294
|
+
|
1295
|
+
if slot_extension is None:
|
1296
|
+
slot_extension = 0
|
1297
|
+
|
1298
|
+
# sim_taxonomy = taxonomy_map.get_or_create_simultan_taxonomy(self._data_model)
|
1299
|
+
taxonomy_entry = content.get_taxonomie_entry(self._data_model)
|
1300
|
+
|
1301
|
+
# sim_taxonomy = self._data_model.get_or_create_taxonomy(taxonomy_name=taxonomy_map.taxonomy_name,
|
1302
|
+
# taxonomy_key=taxonomy_map.taxonomy_key)
|
1303
|
+
# taxonomy_entry = self._data_model.get_or_create_taxonomy_entry(key=content.text_or_key,
|
1304
|
+
# name=content.property_name,
|
1305
|
+
# sim_taxonomy=sim_taxonomy)
|
1306
|
+
# getx.cache_clear()
|
1307
|
+
|
1308
|
+
component_idx, ref_component_idx, parameter_idx, ref_asset_idx = get_param_indices(self._wrapped_obj,
|
1309
|
+
taxonomy_entry)
|
1310
|
+
|
1311
|
+
fcn_arg_list = [value,
|
1312
|
+
self,
|
1313
|
+
prop_name,
|
1314
|
+
taxonomy_entry,
|
1315
|
+
slot_extension,
|
1316
|
+
component_idx,
|
1317
|
+
ref_component_idx,
|
1318
|
+
parameter_idx,
|
1319
|
+
ref_asset_idx,
|
1320
|
+
content]
|
1321
|
+
|
1322
|
+
if value is None:
|
1323
|
+
remove_prop_from_sim_component(component=self._wrapped_obj,
|
1324
|
+
component_idx=component_idx,
|
1325
|
+
ref_component_idx=ref_component_idx,
|
1326
|
+
parameter_idx=parameter_idx,
|
1327
|
+
keep=[])
|
1328
|
+
return
|
1329
|
+
|
1330
|
+
if isinstance(value, UnresolvedObject):
|
1331
|
+
return
|
1332
|
+
|
1333
|
+
if isinstance(value, (list, tuple, set, ComponentList)):
|
1334
|
+
setter_fcn = set_property_to_list
|
1335
|
+
elif isinstance(value, SimultanObject):
|
1336
|
+
setter_fcn = set_property_to_sim_component
|
1337
|
+
elif isinstance(value, dict):
|
1338
|
+
setter_fcn = set_property_to_dict
|
1339
|
+
else:
|
1340
|
+
setter_fcn = type_setter_fcn_lookup_dict.get(type(value), set_property_to_unknown_type)
|
1341
|
+
|
1342
|
+
setter_fcn(*fcn_arg_list)
|
1343
|
+
|
1344
|
+
# elif isinstance(value, (SimComponent, SimultanObject)) and not isinstance(value, ComponentList):
|
1345
|
+
# set_property_to_sim_component(*fcn_arg_list)
|
1346
|
+
#
|
1347
|
+
# elif isinstance(value, (str, int, float)):
|
1348
|
+
# set_property_to_parameter(*fcn_arg_list)
|
1349
|
+
#
|
1350
|
+
# elif isinstance(value, (np.ndarray, pd.DataFrame)):
|
1351
|
+
# set_propperty_to_value_field(*fcn_arg_list)
|
1352
|
+
#
|
1353
|
+
# elif isinstance(value, (list, tuple, set, ComponentList)):
|
1354
|
+
# set_property_to_list(*fcn_arg_list)
|
1355
|
+
#
|
1356
|
+
# elif isinstance(value, FileInfo):
|
1357
|
+
# set_property_to_file_info(*fcn_arg_list, content=content)
|
1358
|
+
#
|
1359
|
+
# else:
|
1360
|
+
# new_val = create_mapped_python_object(value, self._object_mapper, self._data_model)
|
1361
|
+
# setattr(self, prop_name, new_val)
|
1362
|
+
|
1363
|
+
setx.__taxonomy__ = taxonomy
|
1364
|
+
|
1365
|
+
def delx(self):
|
1366
|
+
|
1367
|
+
sim_taxonomy = self._data_model.get_or_create_taxonomy(taxonomy_name=taxonomy_map.taxonomy_name,
|
1368
|
+
taxonomy_key=taxonomy_map.taxonomy_key)
|
1369
|
+
taxonomy_entry = self._data_model.get_or_create_taxonomy_entry(key=content.text_or_key,
|
1370
|
+
name=content.property_name,
|
1371
|
+
sim_taxonomy=sim_taxonomy)
|
1372
|
+
component_idx, ref_component_idx, parameter_idx, ref_asset_idx = get_param_indices(self._wrapped_obj,
|
1373
|
+
taxonomy_entry)
|
1374
|
+
|
1375
|
+
remove_prop_from_sim_component(component=self,
|
1376
|
+
component_idx=component_idx,
|
1377
|
+
ref_component_idx=ref_component_idx,
|
1378
|
+
parameter_idx=parameter_idx,
|
1379
|
+
ref_asset_idx=ref_asset_idx)
|
1380
|
+
|
1381
|
+
delx.__taxonomy__ = taxonomy
|
1382
|
+
|
1383
|
+
return property(getx, setx, delx, "automatic created property")
|