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
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,366 @@
|
|
1
|
+
import hashlib
|
2
|
+
import json
|
3
|
+
|
4
|
+
from copy import copy
|
5
|
+
from weakref import WeakSet, WeakValueDictionary
|
6
|
+
from . import utils
|
7
|
+
from numpy import ndarray
|
8
|
+
import colorlog
|
9
|
+
from typing import Union
|
10
|
+
|
11
|
+
logger = colorlog.getLogger('PySimultan')
|
12
|
+
|
13
|
+
from SIMULTAN.Data.Taxonomy import SimTaxonomyEntry, SimTaxonomyEntryReference, SimTaxonomy
|
14
|
+
from SIMULTAN.Data.Components import (ComponentWalker, SimComponent, SimBoolParameter, SimDoubleParameter,
|
15
|
+
SimEnumParameter, SimIntegerParameter, SimStringParameter, ComponentMapping,
|
16
|
+
SimSlot, ComponentMapping)
|
17
|
+
from SIMULTAN.Data.Assets import ResourceEntry, ResourceFileEntry, ContainedResourceFileEntry, Asset
|
18
|
+
from SIMULTAN.Data import SimId
|
19
|
+
|
20
|
+
from typing import TYPE_CHECKING
|
21
|
+
if TYPE_CHECKING:
|
22
|
+
from .data_model import DataModel
|
23
|
+
from .object_mapper import PythonMapper
|
24
|
+
from .geometry.geometry_base import ExtendedBaseGeometry
|
25
|
+
|
26
|
+
from .geometry.utils import create_python_geometry
|
27
|
+
|
28
|
+
from . import config
|
29
|
+
|
30
|
+
|
31
|
+
class ComplexEncoder(json.JSONEncoder):
|
32
|
+
def default(self, obj):
|
33
|
+
if isinstance(obj, SimultanObject):
|
34
|
+
return obj.to_json()
|
35
|
+
# Let the base class default method raise the TypeError
|
36
|
+
return json.JSONEncoder.default(self, obj)
|
37
|
+
|
38
|
+
|
39
|
+
class classproperty(object):
|
40
|
+
|
41
|
+
def __init__(self, getter):
|
42
|
+
self.getter = getter
|
43
|
+
|
44
|
+
def __get__(self, instance, owner):
|
45
|
+
return self.getter(owner)
|
46
|
+
|
47
|
+
|
48
|
+
class MetaMock(type):
|
49
|
+
def __call__(cls: 'SimultanObject', *args, **kwargs) -> 'SimultanObject':
|
50
|
+
"""
|
51
|
+
Metaclass to implement object initialization either with wrapped_obj or keywords.
|
52
|
+
|
53
|
+
If a wrapped_obj is defined, create new SimultanObject which wraps a SIMULTAN component (wrapped_obj).
|
54
|
+
|
55
|
+
If no 'wrapped_obj' is defined, a new SimComponent is created with the content defined in the template and the
|
56
|
+
values are set to the values defined in kwargs.
|
57
|
+
"""
|
58
|
+
|
59
|
+
obj = cls.__new__(cls, *args, **kwargs)
|
60
|
+
|
61
|
+
wrapped_obj = kwargs.get('wrapped_obj', None)
|
62
|
+
if wrapped_obj is None:
|
63
|
+
|
64
|
+
data_model = kwargs.get('data_model', None)
|
65
|
+
if data_model is None:
|
66
|
+
from .data_model import data_models
|
67
|
+
if list(data_models.data).__len__() == 1:
|
68
|
+
data_model = list(data_models.data)[0]()
|
69
|
+
kwargs['data_model'] = data_model
|
70
|
+
else:
|
71
|
+
if config.default_data_model is not None:
|
72
|
+
data_model = config.default_data_model
|
73
|
+
kwargs['data_model'] = data_model
|
74
|
+
else:
|
75
|
+
raise TypeError((f'Error creating new instance of class {cls.__name__}:\n'
|
76
|
+
f'Any data model was defined. Tried to use default data model but there are multiple datamodels.\n'
|
77
|
+
f'Define the data model to use with the key: data_model'))
|
78
|
+
|
79
|
+
wrapped_obj = cls.create_simultan_component(*args, **kwargs)
|
80
|
+
|
81
|
+
init_dict = kwargs.copy()
|
82
|
+
init_dict['data_model_id'] = data_model.id
|
83
|
+
init_dict['object_mapper'] = cls._object_mapper
|
84
|
+
init_dict['data_model'] = data_model
|
85
|
+
init_dict['wrapped_obj'] = wrapped_obj
|
86
|
+
obj.__init__(*args, **init_dict)
|
87
|
+
|
88
|
+
# for key, value in kwargs.items():
|
89
|
+
# if key in ['data_model', 'wrapped_obj', 'object_mapper']:
|
90
|
+
# continue
|
91
|
+
# setattr(obj, key, value)
|
92
|
+
|
93
|
+
else:
|
94
|
+
obj.__init__(*args, **kwargs)
|
95
|
+
return obj
|
96
|
+
|
97
|
+
|
98
|
+
class SimultanObject(object, metaclass=MetaMock):
|
99
|
+
|
100
|
+
_cls_instances = WeakSet() # weak set with all created objects
|
101
|
+
_create_all = False # if true all properties are evaluated to create python objects when initialized
|
102
|
+
_cls_instances_dict_cache = None
|
103
|
+
__type_view__ = None # ui view cls
|
104
|
+
|
105
|
+
@classproperty
|
106
|
+
def _cls_instances_dict(cls) -> dict[SimId, 'SimultanObject']:
|
107
|
+
return dict(zip([x.id for x in cls._cls_instances], [x for x in cls._cls_instances]))
|
108
|
+
|
109
|
+
@classproperty
|
110
|
+
def cls_instances(cls) -> list['SimultanObject']:
|
111
|
+
try:
|
112
|
+
_ = cls._cls_instances
|
113
|
+
return list(cls._cls_instances)
|
114
|
+
except Exception as e:
|
115
|
+
logger.error(f'Error getting cls_instances: {e}')
|
116
|
+
return []
|
117
|
+
|
118
|
+
@classmethod
|
119
|
+
def create_simultan_component(cls, *args, **kwargs) -> SimComponent:
|
120
|
+
wrapped_obj = utils.create_simultan_component_for_taxonomy(cls, *args, **kwargs)
|
121
|
+
wrapped_obj.Name = kwargs.get('name', 'UnnamedComponent')
|
122
|
+
return wrapped_obj
|
123
|
+
|
124
|
+
def __new__(cls, *args, **kwargs):
|
125
|
+
instance = super().__new__(cls)
|
126
|
+
if not hasattr(cls, '_cls_instances'):
|
127
|
+
cls._cls_instances = WeakSet()
|
128
|
+
try:
|
129
|
+
cls._cls_instances.add(instance)
|
130
|
+
except Exception as e:
|
131
|
+
logger.error(f'Error adding instance {instance} to _cls_instances: {e}')
|
132
|
+
|
133
|
+
return instance
|
134
|
+
|
135
|
+
def __init__(self, *args, **kwargs):
|
136
|
+
self._wrapped_obj: Union[SimComponent, None] = kwargs.get('wrapped_obj', None)
|
137
|
+
self.__obj_init__ = kwargs.get('__obj_init__', False)
|
138
|
+
self._data_model_id = kwargs.get('data_model_id', None)
|
139
|
+
self._data_model: Union[DataModel, None] = kwargs.get('data_model', config.default_data_model)
|
140
|
+
self._object_mapper: Union[PythonMapper, None] = kwargs.get('object_mapper', config.default_mapper)
|
141
|
+
self.name = kwargs.get('name', None)
|
142
|
+
|
143
|
+
self.__ui_element__ = None # view object for the object
|
144
|
+
|
145
|
+
self._slot = None
|
146
|
+
|
147
|
+
def __getattribute__(self, attr):
|
148
|
+
|
149
|
+
try:
|
150
|
+
return object.__getattribute__(self, attr)
|
151
|
+
except AttributeError:
|
152
|
+
wrapped = object.__getattribute__(self, '_wrapped_obj')
|
153
|
+
if wrapped is not None:
|
154
|
+
return object.__getattribute__(wrapped, attr)
|
155
|
+
else:
|
156
|
+
raise KeyError
|
157
|
+
|
158
|
+
def __setattr__(self, attr, value):
|
159
|
+
if hasattr(self, '_wrapped_obj'):
|
160
|
+
if hasattr(self._wrapped_obj, attr) and (self._wrapped_obj is not None) and not self.__obj_init__:
|
161
|
+
object.__setattr__(self._wrapped_obj, attr, value)
|
162
|
+
return
|
163
|
+
# object.__setattr__(self, attr, value)
|
164
|
+
super().__setattr__(attr, value)
|
165
|
+
|
166
|
+
# if hasattr(super(self.__class__), attr):
|
167
|
+
# super(self.__class__).__setattr__(attr, value)
|
168
|
+
|
169
|
+
@property
|
170
|
+
def id(self) -> SimId:
|
171
|
+
if self._wrapped_obj is not None:
|
172
|
+
return self._wrapped_obj.Id
|
173
|
+
|
174
|
+
@property
|
175
|
+
def id_str(self) -> str:
|
176
|
+
return '_'.join((str(self.id.GlobalId), str(self.id.LocalId)))
|
177
|
+
|
178
|
+
@property
|
179
|
+
def json_ref(self):
|
180
|
+
return {"_ref": {
|
181
|
+
"$ref": self.__class__.__name__,
|
182
|
+
"$id": {
|
183
|
+
"$oid": self.id_str
|
184
|
+
}
|
185
|
+
}}
|
186
|
+
|
187
|
+
@property
|
188
|
+
def name(self) -> str:
|
189
|
+
if self._wrapped_obj is not None:
|
190
|
+
return self._wrapped_obj.Name
|
191
|
+
|
192
|
+
@name.setter
|
193
|
+
def name(self, value: str):
|
194
|
+
if self._wrapped_obj is not None:
|
195
|
+
self._wrapped_obj.Name = value
|
196
|
+
|
197
|
+
@property
|
198
|
+
def parent(self) -> 'SimultanObject':
|
199
|
+
if not hasattr(self._wrapped_obj, 'Parent'):
|
200
|
+
return None
|
201
|
+
|
202
|
+
if self._wrapped_obj.Parent is not None:
|
203
|
+
return self._object_mapper.create_python_object(self._wrapped_obj.Parent)
|
204
|
+
else:
|
205
|
+
return None
|
206
|
+
|
207
|
+
@property
|
208
|
+
def slots(self):
|
209
|
+
if self._wrapped_obj is not None:
|
210
|
+
return list(self._wrapped_obj.Slots.Items)
|
211
|
+
|
212
|
+
@property
|
213
|
+
def primary_slot(self):
|
214
|
+
if self._wrapped_obj is not None:
|
215
|
+
return self._wrapped_obj.Slots.Items[0]
|
216
|
+
|
217
|
+
@property
|
218
|
+
def referenced_by(self) -> set['SimultanObject']:
|
219
|
+
return set([self._object_mapper.create_python_object(x.Target) for x in self._wrapped_obj.ReferencedBy if
|
220
|
+
x.Target != self._wrapped_obj])
|
221
|
+
|
222
|
+
@property
|
223
|
+
def _parameters(self) -> dict[str, Union[str, int, float, bool, ndarray]]:
|
224
|
+
return {x.NameTaxonomyEntry.get_TextOrKey(): utils.get_obj_value(x,
|
225
|
+
data_model=self._data_model,
|
226
|
+
object_mapper=self._object_mapper) for x in
|
227
|
+
self._wrapped_obj.Parameters}
|
228
|
+
|
229
|
+
@property
|
230
|
+
def associated_geometry(self):
|
231
|
+
ref_geometries = self._data_model.get_associated_geometry(self)
|
232
|
+
|
233
|
+
return [create_python_geometry(None, geo, self._data_model, self._object_mapper, geo_model) for geo, geo_model in
|
234
|
+
ref_geometries]
|
235
|
+
|
236
|
+
def get_subcomponents(self) -> dict[[str, str], Union['SimultanObject', SimComponent]]:
|
237
|
+
subcomponents = {}
|
238
|
+
for comp in self._wrapped_obj.Components:
|
239
|
+
subcomponents[(comp.Slot.SlotBase.Target.Key, comp.Slot.SlotExtension)] = self._object_mapper.create_python_object(comp.Component)
|
240
|
+
return subcomponents
|
241
|
+
|
242
|
+
def get_subcomponent_list(self) -> list[Union['SimultanObject', SimComponent]]:
|
243
|
+
return list(self.get_subcomponents().values())
|
244
|
+
|
245
|
+
def get_referenced_components(self) -> list['SimultanObject']:
|
246
|
+
return [self._object_mapper.create_python_object(x) for x in self._wrapped_obj.ReferencedComponents]
|
247
|
+
|
248
|
+
def add_taxonomy_entry_reference(self,
|
249
|
+
taxonomy_entry_reference: SimTaxonomyEntryReference,
|
250
|
+
index: int = None):
|
251
|
+
if index is None:
|
252
|
+
index = self._wrapped_obj.Slots.Items.__len__()
|
253
|
+
self._wrapped_obj.Slots.InsertItem(index, taxonomy_entry_reference)
|
254
|
+
|
255
|
+
def add_subcomponent(self, subcomponent: Union['SimultanObject', SimComponent],
|
256
|
+
slot: SimTaxonomyEntryReference = None,
|
257
|
+
slot_extension: str = None):
|
258
|
+
|
259
|
+
if isinstance(subcomponent, SimComponent):
|
260
|
+
comp_to_add = subcomponent
|
261
|
+
elif isinstance(subcomponent, SimultanObject):
|
262
|
+
comp_to_add = subcomponent._wrapped_obj
|
263
|
+
else:
|
264
|
+
comp_to_add = utils.create_mapped_python_object(subcomponent,
|
265
|
+
object_mapper=self._object_mapper,
|
266
|
+
data_model=self._data_model,
|
267
|
+
add_to_data_model=True)
|
268
|
+
|
269
|
+
utils.add_sub_component(self._wrapped_obj,
|
270
|
+
comp_to_add,
|
271
|
+
slot_extension,
|
272
|
+
slot)
|
273
|
+
|
274
|
+
def remove_subcomponent(self, subcomponent: Union['SimultanObject', SimComponent]):
|
275
|
+
if isinstance(subcomponent, SimComponent):
|
276
|
+
utils.remove_sub_component(self._wrapped_obj, subcomponent)
|
277
|
+
elif isinstance(subcomponent, SimultanObject):
|
278
|
+
utils.remove_sub_component(self._wrapped_obj, subcomponent._wrapped_obj)
|
279
|
+
else:
|
280
|
+
raise TypeError(f'Unknown type for subcomponent: {type(subcomponent)}')
|
281
|
+
|
282
|
+
def add_referenced_component(self,
|
283
|
+
referenced_component: Union['SimultanObject', SimComponent],
|
284
|
+
slot: SimTaxonomyEntryReference = None,
|
285
|
+
slot_extension: str = None):
|
286
|
+
|
287
|
+
referenced_wrapped_obj = referenced_component if isinstance(referenced_component,
|
288
|
+
SimComponent) else referenced_component._wrapped_obj
|
289
|
+
|
290
|
+
# logger.debug(f'Adding referenced component {referenced_component} to {self}')
|
291
|
+
utils.add_referenced_component(self._wrapped_obj,
|
292
|
+
referenced_wrapped_obj,
|
293
|
+
slot_extension,
|
294
|
+
slot)
|
295
|
+
|
296
|
+
def remove_referenced_component(self, referenced_component: 'SimultanObject'):
|
297
|
+
utils.remove_referenced_component(self._wrapped_obj, referenced_component._wrapped_obj)
|
298
|
+
|
299
|
+
def add_asset(self,
|
300
|
+
resource_file_entry: 'ResourceFileEntry',
|
301
|
+
_id_contained: str = '') -> Asset:
|
302
|
+
|
303
|
+
return ComponentMapping.AddAsset(self, resource_file_entry, _id_contained)
|
304
|
+
|
305
|
+
def __repr__(self):
|
306
|
+
return f'{self.name}: ' + object.__repr__(self)
|
307
|
+
|
308
|
+
def associate(self, other: 'ExtendedBaseGeometry'):
|
309
|
+
"""
|
310
|
+
Associate this object with another object
|
311
|
+
:param other: geometry object to associate with
|
312
|
+
:return: None
|
313
|
+
"""
|
314
|
+
other.associate(self)
|
315
|
+
|
316
|
+
def get_raw_attr(self, attr: str):
|
317
|
+
return utils.get_component_taxonomy_entry(self._wrapped_obj, attr)
|
318
|
+
|
319
|
+
def set_attr_prop(self, attr: str, prop: str, value):
|
320
|
+
"""
|
321
|
+
Set attribute of the mapped property
|
322
|
+
|
323
|
+
Example:
|
324
|
+
|
325
|
+
class TestComponent(object):
|
326
|
+
def __init__(self, *args, **kwargs):
|
327
|
+
self.value = kwargs.get('value')
|
328
|
+
|
329
|
+
content0 = Content(text_or_key='value', # text or key of the content/parameter/property
|
330
|
+
property_name='value', # name of the generated property
|
331
|
+
type=float, # type of the content/parameter/property
|
332
|
+
unit=None, # unit of the content/parameter/property
|
333
|
+
documentation='value to test',
|
334
|
+
component_policy='subcomponent')
|
335
|
+
|
336
|
+
test_component_map = TaxonomyMap(taxonomy_name='PySimultan',
|
337
|
+
taxonomy_key='PySimultan',
|
338
|
+
taxonomy_entry_name='TestComponent',
|
339
|
+
taxonomy_entry_key='TestComponent',
|
340
|
+
content=[content0]
|
341
|
+
)
|
342
|
+
|
343
|
+
mapper.register(test_component_map.taxonomy_entry_key, TestComponent, taxonomy_map=test_component_map)
|
344
|
+
cls1 = mapper.get_mapped_class(test_component_map.taxonomy_entry_key)
|
345
|
+
|
346
|
+
test_component = cls1(name='test_component',
|
347
|
+
value=None)
|
348
|
+
|
349
|
+
test_component.set_attr_prop('value', 'MinValue, 0)
|
350
|
+
test_component.set_attr_prop('value', 'MaxValue, 1)
|
351
|
+
|
352
|
+
:param attr:
|
353
|
+
:param value:
|
354
|
+
:return:
|
355
|
+
"""
|
356
|
+
comp_prop = utils.get_component_taxonomy_entry(self._wrapped_obj, attr)
|
357
|
+
if comp_prop is not None:
|
358
|
+
setattr(comp_prop, prop, value)
|
359
|
+
return comp_prop
|
360
|
+
|
361
|
+
|
362
|
+
# def to_json(self):
|
363
|
+
#
|
364
|
+
# super().to_json(self)
|
365
|
+
|
366
|
+
# return {str(self.id): {'name': self.name}}
|
@@ -0,0 +1,169 @@
|
|
1
|
+
import io
|
2
|
+
from ruamel.yaml import YAML, yaml_object, add_representer
|
3
|
+
from .config import yaml
|
4
|
+
|
5
|
+
from typing import TYPE_CHECKING, Optional, Union, Literal
|
6
|
+
if TYPE_CHECKING:
|
7
|
+
from .data_model import DataModel
|
8
|
+
|
9
|
+
from SIMULTAN.Data.Taxonomy import SimTaxonomyEntryReference
|
10
|
+
|
11
|
+
|
12
|
+
@yaml_object(yaml)
|
13
|
+
class Content(object):
|
14
|
+
|
15
|
+
yaml_tag = u'!Content'
|
16
|
+
|
17
|
+
def __init__(self, *args, **kwargs):
|
18
|
+
"""
|
19
|
+
Define a content/parameter/property of a taxonomy entry in the taxonomy map.
|
20
|
+
|
21
|
+
:param args:
|
22
|
+
:Keyword Arguments
|
23
|
+
* *text_or_key* (``str``) -- text or key of the content/parameter/property
|
24
|
+
* *property_name* (``str``) -- name of the generated property
|
25
|
+
* *slot_extension* (``str``) -- slot extension of the content/parameter/property
|
26
|
+
* *type* (``str``) -- type of the content/parameter/property
|
27
|
+
* *unit* (``str``) -- unit of the content/parameter/property
|
28
|
+
* *documentation* (``str``) -- documentation of the content/parameter/property
|
29
|
+
* *component_policy* (``str``) -- component add policy of the content/parameter/property, '
|
30
|
+
reference' or 'subcomponent'
|
31
|
+
"""
|
32
|
+
|
33
|
+
self.name: str = kwargs.get('name', kwargs.get('text_or_key'))
|
34
|
+
self.text_or_key: str = kwargs.get('text_or_key') # text or key of the content/parameter/property
|
35
|
+
self.property_name: str = kwargs.get('property_name') # name of the generated property
|
36
|
+
self.slot_extension: str = kwargs.get('slot_extension') # slot extension of the content/parameter/property
|
37
|
+
self.type = kwargs.get('type', None) # type of the content/parameter/property
|
38
|
+
self.unit: Optional[str] = kwargs.get('unit', None) # unit of the content/parameter/property
|
39
|
+
self.documentation: Optional[str] = kwargs.get('documentation', None) # documentation of the content/parameter/property
|
40
|
+
self.component_policy: Literal['reference', 'subcomponent'] = kwargs.get('component_policy', 'reference') # component add policy of the content/parameter/property, 'reference' or 'subcomponent'
|
41
|
+
|
42
|
+
self._taxonomies = {}
|
43
|
+
self._taxonomy_entries = {}
|
44
|
+
self._taxonomy_map = kwargs.get('taxonomy_map', None)
|
45
|
+
|
46
|
+
add_kwargs = kwargs.copy()
|
47
|
+
_ = [add_kwargs.pop(key, None) for key in ['taxonomy_name', 'taxonomy_key', 'taxonomy_entry_name',
|
48
|
+
'taxonomy_entry_key', 'content', 'documentation', 'python_mapper',
|
49
|
+
'mapped_class', 'unit', 'type', 'component_policy',
|
50
|
+
'text_or_key', 'property_name', 'slot_extension']]
|
51
|
+
|
52
|
+
self.additional_attributes = add_kwargs
|
53
|
+
|
54
|
+
def get_taxonomie_entry(self, data_model: 'DataModel'):
|
55
|
+
if self._taxonomy_entries.get(data_model, None) is None:
|
56
|
+
|
57
|
+
taxonomy = self._taxonomy_map.get_or_create_simultan_taxonomy(data_model=data_model, create=True)
|
58
|
+
self._taxonomy_entries[data_model] = data_model.get_or_create_taxonomy_entry(name=self.text_or_key,
|
59
|
+
key=self.text_or_key,
|
60
|
+
description=self.documentation,
|
61
|
+
sim_taxonomy=taxonomy)
|
62
|
+
return self._taxonomy_entries[data_model]
|
63
|
+
|
64
|
+
def __repr__(self):
|
65
|
+
return (f"Content({self.name}, {self.text_or_key}, "
|
66
|
+
f"{self.property_name}, {self.slot_extension}, "
|
67
|
+
f"{self.type}, {self.unit}, "
|
68
|
+
f"{self.documentation}, {self.component_policy})")
|
69
|
+
|
70
|
+
|
71
|
+
verbose_output = False
|
72
|
+
|
73
|
+
|
74
|
+
@yaml_object(yaml)
|
75
|
+
class TaxonomyMap(object):
|
76
|
+
|
77
|
+
yaml_tag = u'!TaxonomyMap'
|
78
|
+
|
79
|
+
@classmethod
|
80
|
+
def from_yaml_file(cls, filename):
|
81
|
+
with open(filename, mode='r') as f:
|
82
|
+
taxonomie_map = yaml.load(f)
|
83
|
+
return taxonomie_map[0]
|
84
|
+
|
85
|
+
def __init__(self, *args, **kwargs):
|
86
|
+
|
87
|
+
self._content = []
|
88
|
+
self._content_dict = {}
|
89
|
+
|
90
|
+
self.taxonomy_name = kwargs.get('taxonomy_name', kwargs.get('taxonomy_key', None))
|
91
|
+
self.taxonomy_key = kwargs.get('taxonomy_key', None)
|
92
|
+
|
93
|
+
self.taxonomy_entry_name = kwargs.get('taxonomy_entry_name', kwargs.get('taxonomy_entry_key', None))
|
94
|
+
self.taxonomy_entry_key = kwargs.get('taxonomy_entry_key', None)
|
95
|
+
|
96
|
+
self.content = kwargs.get('content', [])
|
97
|
+
self.documentation = kwargs.get('documentation', '')
|
98
|
+
|
99
|
+
self.python_mapper = kwargs.get('python_mapper', None)
|
100
|
+
self.mapped_class = kwargs.get('mapped_class', None)
|
101
|
+
|
102
|
+
self._taxonomies = {}
|
103
|
+
self._taxonomy_entries = {}
|
104
|
+
|
105
|
+
@property
|
106
|
+
def content(self):
|
107
|
+
return self._content
|
108
|
+
|
109
|
+
@content.setter
|
110
|
+
def content(self, value: list[Content]):
|
111
|
+
self._content = value
|
112
|
+
for content in self._content:
|
113
|
+
content._taxonomy_map = self
|
114
|
+
self._content_dict = {}
|
115
|
+
|
116
|
+
@property
|
117
|
+
def content_dict(self):
|
118
|
+
if self._content_dict == {}:
|
119
|
+
for content in self._content:
|
120
|
+
self._content_dict[content.text_or_key] = content
|
121
|
+
return self._content_dict
|
122
|
+
|
123
|
+
def write(self, filename=None):
|
124
|
+
if filename is not None:
|
125
|
+
with open(filename, mode='w') as f:
|
126
|
+
yaml.dump([self], f)
|
127
|
+
else:
|
128
|
+
f = io.StringIO()
|
129
|
+
yaml.dump([self], f)
|
130
|
+
return f.getvalue()
|
131
|
+
|
132
|
+
def __getstate__(self):
|
133
|
+
data = self.__dict__.copy()
|
134
|
+
del data['python_mapper']
|
135
|
+
del data['mapped_class']
|
136
|
+
return data
|
137
|
+
|
138
|
+
def add_content(self, content: Content):
|
139
|
+
self._content.append(content)
|
140
|
+
content._taxonomy_map = self
|
141
|
+
self._content_dict = {}
|
142
|
+
|
143
|
+
def get_or_create_simultan_taxonomy_entry(self, data_model: 'DataModel', create=True):
|
144
|
+
|
145
|
+
if self._taxonomy_entries.get(data_model, None) is None:
|
146
|
+
|
147
|
+
taxonomy_entries = data_model.get_taxonomy_entries()
|
148
|
+
if self.taxonomy_entry_key in taxonomy_entries.keys():
|
149
|
+
self._taxonomy_entries[data_model] = taxonomy_entries[self.taxonomy_entry_key]
|
150
|
+
elif create:
|
151
|
+
self._taxonomy_entries[data_model] = data_model.get_or_create_taxonomy_entry(
|
152
|
+
key=self.taxonomy_entry_key,
|
153
|
+
name=self.taxonomy_entry_name,
|
154
|
+
sim_taxonomy=self.get_or_create_simultan_taxonomy(data_model=data_model,
|
155
|
+
create=create))
|
156
|
+
return self._taxonomy_entries[data_model]
|
157
|
+
|
158
|
+
def get_or_create_simultan_taxonomy(self, data_model: 'DataModel', create=True):
|
159
|
+
if self._taxonomies.get(data_model, None) is None:
|
160
|
+
self._taxonomies[data_model] = data_model.get_or_create_taxonomy(
|
161
|
+
taxonomy_name=self.taxonomy_name,
|
162
|
+
taxonomy_key=self.taxonomy_key,
|
163
|
+
description=self.documentation,
|
164
|
+
create=create)
|
165
|
+
|
166
|
+
return self._taxonomies[data_model]
|
167
|
+
|
168
|
+
def get_slot(self, data_model: 'DataModel'):
|
169
|
+
return SimTaxonomyEntryReference(self.get_or_create_simultan_taxonomy_entry(data_model=data_model, create=True))
|