PySimultan 0.1.53__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.
Files changed (182) hide show
  1. PySimultan-0.2.dist-info/LICENSE.txt +17 -0
  2. PySimultan-0.2.dist-info/METADATA +36 -0
  3. PySimultan-0.2.dist-info/RECORD +82 -0
  4. {PySimultan-0.1.53.dist-info → PySimultan-0.2.dist-info}/WHEEL +1 -1
  5. PySimultan-0.2.dist-info/top_level.txt +1 -0
  6. {PySimultan → PySimultan2}/__init__.py +11 -6
  7. PySimultan2/config.py +52 -0
  8. PySimultan2/data_model.py +713 -0
  9. PySimultan2/default_types.py +507 -0
  10. PySimultan2/files.py +371 -0
  11. PySimultan2/geometry/__init__.py +4 -0
  12. PySimultan2/geometry/geometry_base.py +654 -0
  13. PySimultan2/geometry/utils.py +181 -0
  14. PySimultan2/multi_values.py +277 -0
  15. PySimultan2/object_mapper.py +200 -0
  16. PySimultan2/resources/AssimpNet.dll +0 -0
  17. PySimultan2/resources/AvalonDock.dll +0 -0
  18. PySimultan2/resources/BruTile.dll +0 -0
  19. PySimultan2/resources/ClosedXML.dll +0 -0
  20. PySimultan2/resources/ComponentBuilder.dll +0 -0
  21. PySimultan/resources/ComponentBuilder.exe.config → PySimultan2/resources/ComponentBuilder.dll.config +6 -2
  22. PySimultan2/resources/ComponentBuilder.runtimeconfig.json +18 -0
  23. {PySimultan → PySimultan2}/resources/ComponentBuilder.xml +11877 -6754
  24. PySimultan2/resources/ControlzEx.dll +0 -0
  25. PySimultan2/resources/Cyotek.Drawing.BitmapFont.dll +0 -0
  26. PySimultan2/resources/DocumentFormat.OpenXml.dll +0 -0
  27. PySimultan2/resources/ExcelNumberFormat.dll +0 -0
  28. PySimultan2/resources/Fluent.dll +0 -0
  29. PySimultan2/resources/GeometryViewer.dll +0 -0
  30. {PySimultan → PySimultan2}/resources/GeometryViewer.xml +2201 -1155
  31. PySimultan2/resources/HelixToolkit.Core.Wpf.dll +0 -0
  32. PySimultan2/resources/HelixToolkit.SharpDX.Core.Wpf.dll +0 -0
  33. PySimultan2/resources/HelixToolkit.SharpDX.Core.dll +0 -0
  34. PySimultan2/resources/HelixToolkit.dll +0 -0
  35. PySimultan2/resources/MathNet.Numerics.dll +0 -0
  36. PySimultan2/resources/Microsoft.AspNetCore.Authorization.dll +0 -0
  37. PySimultan2/resources/Microsoft.AspNetCore.Metadata.dll +0 -0
  38. PySimultan2/resources/Microsoft.Extensions.DependencyInjection.Abstractions.dll +0 -0
  39. PySimultan2/resources/Microsoft.Extensions.Logging.Abstractions.dll +0 -0
  40. PySimultan2/resources/Microsoft.Extensions.Options.dll +0 -0
  41. PySimultan2/resources/Microsoft.Extensions.Primitives.dll +0 -0
  42. PySimultan2/resources/Microsoft.WindowsAPICodePack.Shell.dll +0 -0
  43. PySimultan2/resources/Microsoft.WindowsAPICodePack.dll +0 -0
  44. PySimultan2/resources/Microsoft.Xaml.Behaviors.dll +0 -0
  45. PySimultan2/resources/Newtonsoft.Json.Bson.dll +0 -0
  46. PySimultan2/resources/Newtonsoft.Json.dll +0 -0
  47. PySimultan2/resources/SIMULTAN.AutoUpdate.Client.dll +0 -0
  48. PySimultan2/resources/SIMULTAN.AutoUpdate.DataTransferLibrary.dll +0 -0
  49. PySimultan2/resources/SIMULTAN.AutoUpdate.DataTransferLibrary.dll.config +15 -0
  50. PySimultan2/resources/SIMULTAN.Lang.dll +0 -0
  51. {PySimultan → PySimultan2}/resources/SIMULTAN.Lang.xml +5282 -3252
  52. PySimultan2/resources/SIMULTAN.Plugins.dll +0 -0
  53. {PySimultan → PySimultan2}/resources/SIMULTAN.Plugins.xml +110 -0
  54. PySimultan2/resources/SIMULTAN.UI.dll +0 -0
  55. {PySimultan → PySimultan2}/resources/SIMULTAN.UI.xml +10483 -4937
  56. PySimultan2/resources/SIMULTAN.dll +0 -0
  57. PySimultan2/resources/SIMULTAN.xml +34122 -0
  58. PySimultan2/resources/SharpDX.D3DCompiler.dll +0 -0
  59. PySimultan2/resources/SharpDX.DXGI.dll +0 -0
  60. PySimultan2/resources/SharpDX.Direct2D1.dll +0 -0
  61. PySimultan2/resources/SharpDX.Direct3D11.dll +0 -0
  62. PySimultan2/resources/SharpDX.Direct3D9.dll +0 -0
  63. {PySimultan → PySimultan2}/resources/SharpDX.Mathematics.dll +0 -0
  64. PySimultan2/resources/SharpDX.dll +0 -0
  65. {PySimultan → PySimultan2}/resources/SitePlanner.dll +0 -0
  66. {PySimultan → PySimultan2}/resources/SitePlanner.xml +959 -1110
  67. PySimultan2/resources/Sprache.dll +0 -0
  68. PySimultan2/resources/System.Data.OleDb.dll +0 -0
  69. PySimultan2/resources/System.Net.Http.Formatting.dll +0 -0
  70. PySimultan2/resources/XAMLMarkupExtensions.dll +0 -0
  71. PySimultan2/resources/assimp.dll +0 -0
  72. {PySimultan → PySimultan2}/resources/defaultsettings.xml +0 -0
  73. PySimultan2/simultan_object.py +366 -0
  74. PySimultan2/taxonomy_maps.py +169 -0
  75. PySimultan2/utils.py +1383 -0
  76. PySimultan/config.py +0 -57
  77. PySimultan/data_model.py +0 -376
  78. PySimultan/default_types.py +0 -1771
  79. PySimultan/geo_default_types.py +0 -763
  80. PySimultan/geometry.py +0 -309
  81. PySimultan/resources/AssimpNet.dll +0 -0
  82. PySimultan/resources/AssimpNet.xml +0 -12074
  83. PySimultan/resources/BruTile.dll +0 -0
  84. PySimultan/resources/BruTile.xml +0 -1845
  85. PySimultan/resources/ControlzEx.dll +0 -0
  86. PySimultan/resources/Cyotek.Drawing.BitmapFont.dll +0 -0
  87. PySimultan/resources/DXFImportExport.dll +0 -0
  88. PySimultan/resources/DotSpatial.Projections.xml +0 -5879
  89. PySimultan/resources/EXCELImportExport.dll +0 -0
  90. PySimultan/resources/Fluent.dll +0 -0
  91. PySimultan/resources/Fluent.xml +0 -9103
  92. PySimultan/resources/GeoJSON.Net.dll +0 -0
  93. PySimultan/resources/GeometryViewer.Data.dll +0 -0
  94. PySimultan/resources/GeometryViewer.Data.xml +0 -4443
  95. PySimultan/resources/GeometryViewer.Shared.dll +0 -0
  96. PySimultan/resources/GeometryViewer.Shared.xml +0 -588
  97. PySimultan/resources/GeometryViewer.dll +0 -0
  98. PySimultan/resources/HelixToolkit.Wpf.SharpDX.dll +0 -0
  99. PySimultan/resources/HelixToolkit.Wpf.SharpDX.xml +0 -43219
  100. PySimultan/resources/HelixToolkit.Wpf.dll +0 -0
  101. PySimultan/resources/HelixToolkit.Wpf.xml +0 -22363
  102. PySimultan/resources/HelixToolkit.dll +0 -0
  103. PySimultan/resources/HelixToolkit.xml +0 -144
  104. PySimultan/resources/ImportLog_SMART_CAMPUS_TU_WIEN_BIBLIOTHEK_20210305_ZONENMODELL_23_11_2021-06_54_54.txt +0 -1
  105. PySimultan/resources/LibGit2Sharp.dll +0 -0
  106. PySimultan/resources/LibGit2Sharp.dll.config +0 -4
  107. PySimultan/resources/LibGit2Sharp.xml +0 -13770
  108. PySimultan/resources/MathNet.Numerics.dll +0 -0
  109. PySimultan/resources/MathNet.Numerics.xml +0 -57152
  110. PySimultan/resources/Microsoft.WindowsAPICodePack.Shell.dll +0 -0
  111. PySimultan/resources/Microsoft.WindowsAPICodePack.Shell.xml +0 -25496
  112. PySimultan/resources/Microsoft.WindowsAPICodePack.dll +0 -0
  113. PySimultan/resources/Microsoft.WindowsAPICodePack.xml +0 -2934
  114. PySimultan/resources/Newtonsoft.Json.dll +0 -0
  115. PySimultan/resources/Newtonsoft.Json.xml +0 -11305
  116. PySimultan/resources/ParameterStructure.dll +0 -0
  117. PySimultan/resources/ParameterStructure.xml +0 -10750
  118. PySimultan/resources/SIMULTAN.AutoUpdate.Client.dll +0 -0
  119. PySimultan/resources/SIMULTAN.DataExchange.dll +0 -0
  120. PySimultan/resources/SIMULTAN.Lang.dll +0 -0
  121. PySimultan/resources/SIMULTAN.Legacy.dll +0 -0
  122. PySimultan/resources/SIMULTAN.Legacy.xml +0 -254
  123. PySimultan/resources/SIMULTAN.Plugins.dll +0 -0
  124. PySimultan/resources/SIMULTAN.Project.dll +0 -0
  125. PySimultan/resources/SIMULTAN.Project.dll.config +0 -11
  126. PySimultan/resources/SIMULTAN.UI.dll +0 -0
  127. PySimultan/resources/SIMULTAN.Util.dll +0 -0
  128. PySimultan/resources/SIMULTAN.Util.xml +0 -3430
  129. PySimultan/resources/SharpDX.D3DCompiler.dll +0 -0
  130. PySimultan/resources/SharpDX.D3DCompiler.xml +0 -5897
  131. PySimultan/resources/SharpDX.DXGI.dll +0 -0
  132. PySimultan/resources/SharpDX.DXGI.xml +0 -8737
  133. PySimultan/resources/SharpDX.Direct2D1.dll +0 -0
  134. PySimultan/resources/SharpDX.Direct2D1.xml +0 -46691
  135. PySimultan/resources/SharpDX.Direct3D11.dll +0 -0
  136. PySimultan/resources/SharpDX.Direct3D11.xml +0 -31826
  137. PySimultan/resources/SharpDX.Direct3D9.dll +0 -0
  138. PySimultan/resources/SharpDX.Direct3D9.xml +0 -36489
  139. PySimultan/resources/SharpDX.Mathematics.xml +0 -16449
  140. PySimultan/resources/SharpDX.dll +0 -0
  141. PySimultan/resources/Sprache.dll +0 -0
  142. PySimultan/resources/Sprache.xml +0 -1199
  143. PySimultan/resources/System.Net.Http.Formatting.dll +0 -0
  144. PySimultan/resources/System.Net.Http.Formatting.xml +0 -2094
  145. PySimultan/resources/System.Windows.Interactivity.dll +0 -0
  146. PySimultan/resources/TalkGit.dll +0 -0
  147. PySimultan/resources/TalkGit.dll.config +0 -11
  148. PySimultan/resources/WebServiceConnector.dll +0 -0
  149. PySimultan/resources/WebServiceConnector.dll.config +0 -11
  150. PySimultan/resources/XAMLMarkupExtensions.dll +0 -0
  151. PySimultan/resources/XAMLMarkupExtensions.xml +0 -862
  152. PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.Aero.dll +0 -0
  153. PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.Metro.dll +0 -0
  154. PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.VS2010.dll +0 -0
  155. PySimultan/resources/Xceed.Wpf.AvalonDock.dll +0 -0
  156. PySimultan/resources/Xceed.Wpf.Toolkit.dll +0 -0
  157. PySimultan/resources/assimp.dll +0 -0
  158. PySimultan/resources/schema.yaml +0 -13
  159. PySimultan/resources/simultan_exception_07_10_2021-08_34_24.txt +0 -17
  160. PySimultan/resources/simultan_exception_07_10_2021-10_13_31.txt +0 -17
  161. PySimultan/resources/simultan_exception_11_10_2021-19_45_42.txt +0 -17
  162. PySimultan/resources/simultan_exception_22_11_2021-16_41_52.txt +0 -14
  163. PySimultan/resources/simultan_exception_22_11_2021-17_37_40.txt +0 -14
  164. PySimultan/simultan_geometry_utils.py +0 -81
  165. PySimultan/simultan_utils.py +0 -165
  166. PySimultan/slots.py +0 -51
  167. PySimultan/template_tools.py +0 -628
  168. PySimultan/utils.py +0 -298
  169. PySimultan-0.1.53.dist-info/LICENSE +0 -674
  170. PySimultan-0.1.53.dist-info/LICENSE.txt +0 -674
  171. PySimultan-0.1.53.dist-info/METADATA +0 -690
  172. PySimultan-0.1.53.dist-info/RECORD +0 -119
  173. PySimultan-0.1.53.dist-info/entry_points.txt +0 -3
  174. PySimultan-0.1.53.dist-info/top_level.txt +0 -1
  175. PySimultan-0.1.53.dist-info/zip-safe +0 -1
  176. {PySimultan → PySimultan2}/resources/DotSpatial.Projections.dll +0 -0
  177. {PySimultan → PySimultan2}/resources/GeometryViewer.dll.config +0 -0
  178. {PySimultan → PySimultan2}/resources/SIMULTAN.AutoUpdate.Client.dll.config +0 -0
  179. {PySimultan → PySimultan2}/resources/SitePlanner.dll.config +0 -0
  180. {PySimultan → PySimultan2}/resources/Sprache.Calc.dll +0 -0
  181. {PySimultan → PySimultan2}/resources/__init__.py +0 -0
  182. {PySimultan → PySimultan2}/resources/setup.bat +0 -0
@@ -1,628 +0,0 @@
1
- from ruamel.yaml import YAML, yaml_object, add_representer
2
- from .config import yaml
3
- import io
4
- import colorlog
5
- from uuid import uuid4
6
- import typing
7
-
8
- from yamale.readers.yaml_reader import _parsers
9
- import yamale
10
-
11
-
12
- from collections import UserList
13
- from .default_types import SimultanObject
14
- from .default_types import List as SimultanList
15
- from .default_types import ValueField, BuildInFace, BuildInVolume, BuildInZone, BaseBuildInConstruction, BuildInMaterialLayer, ReferenceList
16
- from .geo_default_types import geometry_types
17
- from .geometry import GeometryModel
18
- from .utils import parse_slot
19
-
20
- from functools import lru_cache
21
-
22
- from System.Linq import Enumerable
23
- from ParameterStructure.Values import SimMultiValuePointer
24
- from ParameterStructure.Components import SimComponent
25
-
26
- from typing import List as TypeList
27
- from typing import NewType, Union
28
-
29
- try:
30
- import importlib.resources as pkg_resources
31
- except ImportError:
32
- # Try backported to PY<37 importlib_resources.
33
- import importlib_resources as pkg_resources
34
-
35
- from . import resources
36
-
37
- with pkg_resources.path(resources, 'schema.yaml') as r_path:
38
- schema_file = str(r_path)
39
-
40
-
41
- logger = colorlog.getLogger('PySimultan')
42
-
43
-
44
- template_classes = {}
45
-
46
-
47
- # create the class for the templates
48
- @yaml_object(yaml)
49
- class Template(object):
50
-
51
- yaml_tag = u'!Template:'
52
-
53
- def __init__(self, *args, **kwargs):
54
- """ Template class to define how SIMULTAN SimComponents are imported and parsed
55
-
56
- :param args:
57
- :param kwargs:
58
-
59
- @keyword template_name: Name of the Template. This name is the name of the created Python class and used for
60
- TYPE matching the SIMULTAN SimComponent
61
- @keyword template_id: ID of the template; int
62
- @keyword inherits_from: name of the python template or the template instance this template inherits from
63
- @keyword content: List of attribute names
64
- @keyword documentation: Entry to document the template; str
65
- @keyword units: units of the content. Dictionary
66
- @keyword types: Dictionary with the type of the content. if the type is 'str' get_TextValue() is returned, param.get_ValueCurrent() otherwise
67
- @keyword slots: Dictionary with the name of the content and the name of the slot where it is expected. The expected slot is a string
68
- @keyword default_slot: Default slot name for the Simultan component when new created
69
- with the slot name and the extension, seperated by a blank
70
- """
71
-
72
- self.template_name = kwargs.get('template_name', None)
73
- self.template_id = kwargs.get('template_id', None)
74
-
75
- self.inherits_from = kwargs.get('inherits_from', None)
76
-
77
- self.content = kwargs.get('content', [])
78
- self.documentation = kwargs.get('documentation', None)
79
- self.units = kwargs.get('units', {})
80
- self.types = kwargs.get('types', {})
81
-
82
- self.slots = kwargs.get('slots', {})
83
- self.synonyms = kwargs.get('synonyms', {}) # name of the attribute in the python class
84
-
85
- self.template_parser = kwargs.get('template_parser', None)
86
- self.template_class = kwargs.get('template_class', None)
87
-
88
- self.default_slot = kwargs.get('default_slot', 'Element')
89
-
90
- def write(self, filename: str = None):
91
- """
92
- write the template as .yml to a file
93
- :param filename: name and path of the file to save; Example: C:\SIMULTAN\my_template.yml
94
- :return: None
95
- """
96
- if filename is not None:
97
- yaml.dump([self], open(filename, mode='w'))
98
- else:
99
- f = io.StringIO()
100
- yaml.dump([self], f)
101
- return f.getvalue()
102
-
103
- def create_template_class(self, template_parser, template_classes):
104
- """
105
- Creates a template class for this template.
106
- :param template_parser: TemplateParser instance
107
- :param template_classes: list of template classes to inherit from (e.g. default classes)
108
- :return: TemplateClass
109
- """
110
-
111
- if (self.template_parser is template_parser) and (self.template_class is not None):
112
- return self.template_class
113
-
114
- self.template_parser = template_parser
115
-
116
- # for inheritance:
117
- # template classes must inherit from SimultanObject, UserList or ValueField
118
-
119
- if self.inherits_from is not None:
120
- if self.inherits_from in self.template_parser.bases.keys():
121
- base = template_classes[self.inherits_from]
122
-
123
- simultan_base_list = [SimultanObject, UserList, ValueField]
124
-
125
- if any([issubclass(base, x) for x in simultan_base_list]):
126
- bases = (base, )
127
- else:
128
- bases = (SimultanObject, ) + (base, )
129
- # bases = (base, ) + (SimultanObject, )
130
-
131
- # if SimultanObject in base.__bases__:
132
- # bases = (base, )
133
- # elif UserList in base.__bases__:
134
- # bases = (base, )
135
- # elif ValueField in base.__bases__:
136
- # bases = (base, )
137
- # else:
138
- # bases = (SimultanObject, ) + (base, )
139
- else:
140
- base = template_classes[self.inherits_from.template_name]
141
- bases = (base, )
142
-
143
- def new_init(self, *args, **kwargs):
144
-
145
- for i in range(self.__class__.__bases__.__len__()):
146
- self.__class__.__bases__[i].__init__(self, *args, **kwargs)
147
-
148
- else:
149
- bases = (SimultanObject, )
150
- # create the class from the template
151
-
152
- def new_init(self, *args, **kwargs):
153
-
154
- self.__class__.__bases__[0].__init__(self, *args, **kwargs)
155
-
156
- new_class_dict = {'__init__': new_init,
157
- '_template_name': self.template_name,
158
- '_template_id': self.template_id,
159
- '_documentation': self.documentation,
160
- '_content': [cont for cont in self.content],
161
- '_types': self.types,
162
- '_units': self.units,
163
- '_base': bases,
164
- '_template_parser': self.template_parser,
165
- '_slots': self.slots,
166
- '_synonyms': self.synonyms,
167
- '_default_slot': self.default_slot}
168
-
169
- new_class_dict.update(self.get_properties())
170
- new_class = type(self.template_name, bases, new_class_dict)
171
-
172
- self.template_class = new_class
173
-
174
- return new_class
175
-
176
- def get_properties(self):
177
-
178
- prop_dict = {}
179
-
180
- for prop in self.content:
181
-
182
- if prop in self.slots.keys():
183
- slot = self.slots[prop]
184
- else:
185
- slot = None
186
-
187
- syn = self.synonyms.get('prop', prop)
188
-
189
- prop_dict[syn] = add_properties(prop, syn, param_type=self.types.get(prop, None), slot=slot)
190
-
191
- return prop_dict
192
-
193
- def __getstate__(self):
194
- state = self.__dict__.copy()
195
- del state['template_parser']
196
- del state['template_class']
197
- return state
198
-
199
- def __setstate__(self, d):
200
-
201
- if 'template_name' not in d:
202
- raise Exception(f'Template missing value for template_name')
203
-
204
- if 'template_id' not in d:
205
- raise Exception(f'Template missing value for template_id')
206
-
207
- # add missing values:
208
-
209
- if 'inherits_from' not in d:
210
- d['inherits_from'] = None
211
-
212
- if 'content' not in d:
213
- d['content'] = []
214
-
215
- if 'documentation' not in d:
216
- d['documentation'] = None
217
-
218
- if 'units' not in d:
219
- d['units'] = {}
220
-
221
- if 'types' not in d:
222
- d['types'] = {}
223
-
224
- if 'types' not in d:
225
- d['types'] = {}
226
-
227
- if 'slots' not in d:
228
- d['slots'] = {}
229
-
230
- if 'default_slot' not in d:
231
- d['default_slot'] = 'Element'
232
-
233
- self.__dict__ = d
234
-
235
- self.template_parser = None
236
- self.template_class = None
237
-
238
- def __repr__(self):
239
- return f"Template '{self.template_name}': " + object.__repr__(self)
240
-
241
-
242
- yaml.constructor.yaml_constructors['!Template'] = yaml.constructor.yaml_constructors['!Template:']
243
-
244
-
245
- class TemplateParser(object):
246
-
247
- bases = {'Liste': SimultanList,
248
- 'List': SimultanList,
249
- 'ReferenceList': ReferenceList,
250
- 'ValueField': ValueField,
251
- 'Geometric Area': BuildInFace,
252
- 'Geometrische_Flächen': BuildInFace,
253
- 'Geometric Volume': BuildInVolume,
254
- 'Geometrische_Volumina': BuildInVolume,
255
- 'BuildInZone': BuildInZone,
256
- 'BuildInConstruction': BaseBuildInConstruction,
257
- 'BuildInMaterialLayer': BuildInMaterialLayer}
258
-
259
- geo_bases = {'base': geometry_types.base,
260
- 'layer': geometry_types.layer,
261
- 'vertex': geometry_types.vertex,
262
- 'edge': geometry_types.edge,
263
- 'edge_loop': geometry_types.edge_loop,
264
- 'face': geometry_types.face,
265
- 'volume': geometry_types.volume,
266
- }
267
-
268
- _create_all = False
269
-
270
- def __init__(self, *args, **kwargs):
271
-
272
- """
273
- Class which handles templates. This class generates python objects from the SIMULTAN data model for templates.
274
-
275
- @keyword templates: list of templates; if templates is None and template_filepath is defined,
276
- templates are automatically loaded
277
- @keyword template_filepath: filepath to the template (*.yml)
278
-
279
- """
280
-
281
- self._current_data_model = None
282
-
283
- self.id = uuid4()
284
-
285
- self._templates = kwargs.get('templates', None)
286
- self.template_filepath = kwargs.get('template_filepath', None)
287
-
288
- self._template_classes = kwargs.get('template_classes', None)
289
-
290
- self.data_models = kwargs.get('data_models', {})
291
-
292
- self._typed_geo_models = None
293
-
294
- template_classes[self.id] = self._template_classes
295
-
296
- self.current_data_model = kwargs.get('current_data_model', None)
297
-
298
- @property
299
- def current_data_model(self):
300
- return self._current_data_model
301
-
302
- @current_data_model.setter
303
- def current_data_model(self, value):
304
- self._current_data_model = value
305
- if self._current_data_model is None:
306
- return
307
-
308
- if self._current_data_model not in self.data_models:
309
- self.data_models[self._current_data_model.id] = self._current_data_model
310
-
311
- @property
312
- def templates(self):
313
- if self.template_filepath is None:
314
- return None
315
-
316
- if self._templates is None:
317
- self._templates = self.load_templates_from_file()
318
- return self._templates
319
-
320
- @property
321
- def template_classes(self):
322
- if self._template_classes is None:
323
- self.create_template_classes()
324
- return self._template_classes
325
-
326
- @property
327
- def typed_geo_models(self):
328
- if self._typed_geo_models is None:
329
- self._typed_geo_models = self.get_typed_geo_models()
330
- return self._typed_geo_models
331
-
332
- def get_model_by_file_id(self, id):
333
- return self.current_data_model.models_dict[id]
334
-
335
- def get_typed_model_by_file_id(self, id):
336
- return self.typed_geo_models[id]
337
-
338
- def load_templates_from_file(self, filepath=None):
339
- """
340
- Load templates from file
341
- :param filepath: filepath of the file (str)
342
- :return: templates; list of templates
343
- """
344
- if filepath is None:
345
- filepath = self.template_filepath
346
-
347
- if filepath is None:
348
- templates = []
349
- else:
350
- with open(filepath, mode='r', encoding="utf-8") as f_obj:
351
- templates = yaml.load(f_obj)
352
-
353
- return templates
354
-
355
- def create_template_classes(self) -> typing.Dict[str, str]:
356
-
357
- logger.info('\n\nCreating template-classes:\n-------------------------------------')
358
- template_classes = {**self.bases}
359
-
360
- if self.templates is not None:
361
- logger.info(f'found {self.templates.__len__()} templates')
362
-
363
- for template in self.templates:
364
-
365
- new_class = template.create_template_class(self, template_classes)
366
- template_classes[template.template_name] = new_class
367
-
368
- logger.info(f'Created template class {template.template_name}. Inherits from {template.inherits_from}')
369
-
370
- else:
371
- logger.info(f'No template file defined')
372
-
373
- self._template_classes = template_classes
374
- logger.info('template-class creation finished\n\n')
375
- return self._template_classes
376
-
377
- @lru_cache(maxsize=None)
378
- def create_python_object(self, sim_component, template_name=None):
379
-
380
- # get the template or slot
381
- # template_name = None
382
- if hasattr(sim_component, 'Parameters'):
383
- t_name = next((x.TextValue for x in sim_component.Parameters.Items if x.Name == 'TYPE'), None)
384
- if t_name is not None:
385
- template_name = t_name
386
-
387
- if (template_name is None) and (hasattr(sim_component, 'get_CurrentSlot')):
388
- template_name = sim_component.CurrentSlot.Base
389
-
390
- # if no template and no slot could be found return the plain SimComponent
391
-
392
- if template_name is None:
393
- if isinstance(sim_component, SimMultiValuePointer):
394
- template_name = 'ValueField'
395
-
396
- if template_name is None:
397
- if self._create_all:
398
- if hasattr(SimComponent, 'ContainedSimComponentsAsList'):
399
- _ = [self.create_python_object(x) for x in sim_component.Components]
400
- if hasattr(SimComponent, 'ReferencedSimComponents'):
401
- _ = [self.create_python_object(x) for x in sim_component.ReferencedComponents.Items]
402
- return sim_component
403
-
404
- if template_name not in self.template_classes.keys():
405
-
406
- # create new class for the template / slot
407
- base = SimultanObject
408
- bases = (base, )
409
-
410
- def new__init(self, *args, **kwargs):
411
- self.__class__.__bases__[0].__init__(self, *args, **kwargs)
412
-
413
- new_class_dict = {'__init__': new__init,
414
- '_template_name': template_name,
415
- '_template_id': None,
416
- '_documentation': None,
417
- '_content': None,
418
- '_types': None,
419
- '_units': None,
420
- '_base': bases,
421
- '_template_parser': self,
422
- '_slots': {}}
423
-
424
- new_class = type(template_name, bases, new_class_dict)
425
- self.template_classes[template_name] = new_class
426
-
427
- template_class = self.template_classes[template_name]
428
-
429
- # init new instance
430
- template_class._template_parser = self
431
- new_instance = template_class(wrapped_obj=sim_component,
432
- template_parser=self,
433
- data_model_id=self._current_data_model.id)
434
-
435
- # new_instance._template_parser = self
436
- return new_instance
437
-
438
- def get_typed_geo_models(self):
439
- typed_models_dict = {}
440
- for key, model in self.current_data_model.models_dict.items():
441
- if model is None:
442
- typed_models_dict[key] = None
443
- continue
444
- typed_models_dict[key] = GeometryModel(template_parser=self,
445
- wrapped_obj=model,
446
- geo_types=self.geo_bases)
447
- # models.append(GeometryModel(wrapped_obj=model))
448
- return typed_models_dict
449
-
450
- def add_new_geometry_model(self, file_name: str, model_name: str = None):
451
-
452
- model, resource = self.current_data_model.add_new_geometry_model(file_name, model_name, return_resource=True)
453
-
454
- return self.add_typed_geo_model(model, resource.Key)
455
-
456
- def add_typed_geo_model(self, model, key):
457
- """
458
- Add a geometry model as typed model
459
- :param model: ParameterStructure.Assets.ContainedResourceFileEntry
460
- :param key: resource key
461
- """
462
- if self._typed_geo_models is None:
463
- self._typed_geo_models = {}
464
-
465
- self._typed_geo_models[key] = GeometryModel(template_parser=self,
466
- wrapped_obj=model,
467
- geo_types=self.geo_bases)
468
-
469
- return self._typed_geo_models[key]
470
-
471
- def get_geo_components(self, geometry):
472
- return Enumerable.ToList[SimComponent](self.current_data_model.exch.GetComponents(geometry))
473
-
474
- def get_py_geo_components(self, geometry, template_name=None):
475
- components = Enumerable.ToList[SimComponent](self.current_data_model.exch.GetComponents(geometry))
476
- return [self.create_python_object(x, template_name=template_name) for x in components]
477
-
478
-
479
- def add_properties(prop_name: str, syn_name: str, param_type: str, slot=None) -> property:
480
- """
481
- create property for a class
482
- :param prop_name: name of the property (str)
483
- :param prop_name: name of the synonym (str)
484
- :param param_type: type of the property; if type == 'str': param.get_TextValue(); else: param.get_ValueCurrent() is returned
485
- :param slot: slot; default is None
486
- :return: property
487
- """
488
-
489
- @lru_cache()
490
- def getx(self):
491
- obj = None
492
-
493
- idx = next((i for i, x in enumerate(self._wrapped_obj.Parameters.Items) if x.Name == prop_name), None)
494
- if idx is not None:
495
- param = self._wrapped_obj.Parameters.Items[idx]
496
- obj = param.get_MultiValuePointer()
497
-
498
- if obj is None:
499
- if param_type == 'str':
500
- obj = param.get_TextValue()
501
- else:
502
- obj = param.get_ValueCurrent()
503
-
504
- if obj is None:
505
- full_slot_name = self._slots.get(prop_name, None)
506
- slot_name, slot_extension = parse_slot(full_slot_name)
507
-
508
- if full_slot_name is not None:
509
- obj = next((x.Component for x in self._wrapped_obj.Components.Items
510
- if (x.Slot.SlotBase.Base == slot_name) & (x.Slot.SlotExtension == slot_extension)),
511
- None)
512
-
513
- if obj is None:
514
- obj = next((x.Target for x in self._wrapped_obj.ReferencedComponents.Items
515
- if ' '.join([str(x.Slot.SlotBase),
516
- x.Slot.SlotExtension]) == full_slot_name),
517
- None)
518
-
519
- return self._template_parser.create_python_object(obj)
520
-
521
- def setx(self, value: Union[int, float, SimComponent, SimultanObject]):
522
- getx.cache_clear()
523
- idx = next((i for i, x in enumerate(self._wrapped_obj.Parameters.Items) if x.Name == prop_name), None)
524
-
525
- if isinstance(value, (SimComponent, SimultanObject)):
526
- # set reference or subcomponent
527
-
528
- if prop_name not in self._slots.keys():
529
- raise KeyError(f'{prop_name} not defined as slot for class {self.__class__.__name__}')
530
-
531
- full_slot_name = self._slots.get(prop_name, None)
532
- slot_name, slot_extension = parse_slot(full_slot_name)
533
-
534
- # check if slot exists:
535
- idx = self.slot_components.index[
536
- (self.slot_components.slot == slot_name) & (self.slot_components.slot_extension == slot_extension)]
537
-
538
- if idx.__len__() == 1:
539
- # if subcomponent:
540
- if self.slot_components.iloc[idx].comp_type.values == 0:
541
- if isinstance(value, SimultanObject):
542
- pass
543
-
544
- ref = next((x for x in self._wrapped_obj.Components.Items
545
- if ((x.Slot.SlotBase.Base == slot_name) & (
546
- x.Slot.SlotExtension == slot_extension))), None)
547
-
548
- if isinstance(value, SimComponent):
549
- ref.Component = value
550
- elif isinstance(value, SimultanObject):
551
- ref.Component = value._wrapped_obj
552
-
553
- # if reference:
554
- elif self.slot_components.iloc[idx].comp_type.values == 1:
555
- ref = next((x for x in self._wrapped_obj.ReferencedComponents.Items
556
- if ((x.Slot.SlotBase.Base == slot_name) & (
557
- x.Slot.SlotExtension == slot_extension))), None)
558
-
559
- if isinstance(value, SimComponent):
560
- # delete reference
561
- self.remove_component_reference(ref.reference)
562
- # add the SimComponent as sub-component
563
- self.add_sub_component(component=value,
564
- slot_name=slot_name,
565
- slot_extension=slot_extension,
566
- alter_slot=True)
567
- else:
568
- ref.Target = value._wrapped_obj
569
-
570
- # index does not exist
571
- elif idx.__len__() == 0:
572
- if isinstance(value, SimultanObject):
573
- self.add_component_reference(component=value._wrapped_obj,
574
- slot_name=slot_name,
575
- slot_extension=slot_extension)
576
- elif isinstance(value, SimComponent):
577
- self.add_sub_component(component=value, slot_name=slot_name, slot_extension=slot_extension)
578
-
579
- elif param_type == 'str':
580
- #todo: implementation for referenced parameters
581
- if self._wrapped_obj.Parameters.Items[2].GetReferencedParameter() != self._wrapped_obj.Parameters.Items[idx]:
582
- raise NotImplementedError(f'{self.name}: Param {prop_name} is a referenced Parameter. Setting referenced parameters is not yet implemented')
583
- self._wrapped_obj.Parameters.Items[idx].set_TextValue(value)
584
- elif isinstance(value, (int, float)):
585
- # todo: implementation for referenced parameters
586
- if self._wrapped_obj.Parameters.Items[2].GetReferencedParameter() != self._wrapped_obj.Parameters.Items[idx]:
587
- raise NotImplementedError(f'{self.name}: Param {prop_name} is a referenced Parameter. Setting referenced parameters is not yet implemented')
588
- self._wrapped_obj.Parameters.Items[idx].set_ValueCurrent(float(value))
589
- else:
590
- raise TypeError(
591
- f'{self.name}: Error setting parameter {prop_name} to {type(value)}. Supported types are only: int float str SimComponent SimultanObject.')
592
-
593
- def delx(self):
594
- logger.warning('delete method not implemented')
595
- raise NotImplementedError
596
-
597
- return property(getx, setx, delx, f"automatic created property")
598
-
599
-
600
- def _my_loader(f):
601
- import yaml
602
-
603
- description = []
604
-
605
- def any_constructor(loader, tag_suffix, node):
606
- if isinstance(node, yaml.MappingNode):
607
- return loader.construct_mapping(node)
608
- if isinstance(node, yaml.SequenceNode):
609
- return loader.construct_sequence(node)
610
- return loader.construct_scalar(node)
611
-
612
- yaml.add_multi_constructor('', any_constructor, Loader=yaml.SafeLoader)
613
- data = list(yaml.load_all(f, Loader=yaml.SafeLoader))
614
- return data
615
-
616
-
617
- _parsers['_my_loader'] = _my_loader
618
-
619
-
620
- class TemplateValidator(object):
621
-
622
- def __init__(self, *args, **kwargs):
623
-
624
- self.schema = yamale.make_schema(schema_file, parser='ruamel')
625
-
626
- def validate(self, yaml_file):
627
- data = yamale.make_data(yaml_file, parser='_my_loader')
628
- yamale.validate(self.schema, data)