PySimultan 0.1.54__py3-none-any.whl → 0.2.1__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.1.dist-info/LICENSE.txt +17 -0
  2. PySimultan-0.2.1.dist-info/METADATA +36 -0
  3. PySimultan-0.2.1.dist-info/RECORD +82 -0
  4. {PySimultan-0.1.54.dist-info → PySimultan-0.2.1.dist-info}/WHEEL +1 -1
  5. PySimultan-0.2.1.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 -631
  168. PySimultan/utils.py +0 -298
  169. PySimultan-0.1.54.dist-info/LICENSE +0 -674
  170. PySimultan-0.1.54.dist-info/LICENSE.txt +0 -674
  171. PySimultan-0.1.54.dist-info/METADATA +0 -690
  172. PySimultan-0.1.54.dist-info/RECORD +0 -119
  173. PySimultan-0.1.54.dist-info/entry_points.txt +0 -3
  174. PySimultan-0.1.54.dist-info/top_level.txt +0 -1
  175. PySimultan-0.1.54.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,631 +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 None) and (self.template_name in self.template_parser.bases.keys()):
120
- self.inherits_from = self.template_name
121
-
122
- if self.inherits_from is not None:
123
- if self.inherits_from in self.template_parser.bases.keys():
124
- base = template_classes[self.inherits_from]
125
-
126
- simultan_base_list = [SimultanObject, UserList, ValueField]
127
-
128
- if any([issubclass(base, x) for x in simultan_base_list]):
129
- bases = (base, )
130
- else:
131
- bases = (SimultanObject, ) + (base, )
132
- # bases = (base, ) + (SimultanObject, )
133
-
134
- # if SimultanObject in base.__bases__:
135
- # bases = (base, )
136
- # elif UserList in base.__bases__:
137
- # bases = (base, )
138
- # elif ValueField in base.__bases__:
139
- # bases = (base, )
140
- # else:
141
- # bases = (SimultanObject, ) + (base, )
142
- else:
143
- base = template_classes[self.inherits_from.template_name]
144
- bases = (base, )
145
-
146
- def new_init(self, *args, **kwargs):
147
-
148
- for i in range(self.__class__.__bases__.__len__()):
149
- self.__class__.__bases__[i].__init__(self, *args, **kwargs)
150
-
151
- else:
152
- bases = (SimultanObject, )
153
- # create the class from the template
154
-
155
- def new_init(self, *args, **kwargs):
156
-
157
- self.__class__.__bases__[0].__init__(self, *args, **kwargs)
158
-
159
- new_class_dict = {'__init__': new_init,
160
- '_template_name': self.template_name,
161
- '_template_id': self.template_id,
162
- '_documentation': self.documentation,
163
- '_content': [cont for cont in self.content],
164
- '_types': self.types,
165
- '_units': self.units,
166
- '_base': bases,
167
- '_template_parser': self.template_parser,
168
- '_slots': self.slots,
169
- '_synonyms': self.synonyms,
170
- '_default_slot': self.default_slot}
171
-
172
- new_class_dict.update(self.get_properties())
173
- new_class = type(self.template_name, bases, new_class_dict)
174
-
175
- self.template_class = new_class
176
-
177
- return new_class
178
-
179
- def get_properties(self):
180
-
181
- prop_dict = {}
182
-
183
- for prop in self.content:
184
-
185
- if prop in self.slots.keys():
186
- slot = self.slots[prop]
187
- else:
188
- slot = None
189
-
190
- syn = self.synonyms.get('prop', prop)
191
-
192
- prop_dict[syn] = add_properties(prop, syn, param_type=self.types.get(prop, None), slot=slot)
193
-
194
- return prop_dict
195
-
196
- def __getstate__(self):
197
- state = self.__dict__.copy()
198
- del state['template_parser']
199
- del state['template_class']
200
- return state
201
-
202
- def __setstate__(self, d):
203
-
204
- if 'template_name' not in d:
205
- raise Exception(f'Template missing value for template_name')
206
-
207
- if 'template_id' not in d:
208
- raise Exception(f'Template missing value for template_id')
209
-
210
- # add missing values:
211
-
212
- if 'inherits_from' not in d:
213
- d['inherits_from'] = None
214
-
215
- if 'content' not in d:
216
- d['content'] = []
217
-
218
- if 'documentation' not in d:
219
- d['documentation'] = None
220
-
221
- if 'units' not in d:
222
- d['units'] = {}
223
-
224
- if 'types' not in d:
225
- d['types'] = {}
226
-
227
- if 'types' not in d:
228
- d['types'] = {}
229
-
230
- if 'slots' not in d:
231
- d['slots'] = {}
232
-
233
- if 'default_slot' not in d:
234
- d['default_slot'] = 'Element'
235
-
236
- self.__dict__ = d
237
-
238
- self.template_parser = None
239
- self.template_class = None
240
-
241
- def __repr__(self):
242
- return f"Template '{self.template_name}': " + object.__repr__(self)
243
-
244
-
245
- yaml.constructor.yaml_constructors['!Template'] = yaml.constructor.yaml_constructors['!Template:']
246
-
247
-
248
- class TemplateParser(object):
249
-
250
- bases = {'Liste': SimultanList,
251
- 'List': SimultanList,
252
- 'ReferenceList': ReferenceList,
253
- 'ValueField': ValueField,
254
- 'Geometric Area': BuildInFace,
255
- 'Geometrische_Flächen': BuildInFace,
256
- 'Geometric Volume': BuildInVolume,
257
- 'Geometrische_Volumina': BuildInVolume,
258
- 'BuildInZone': BuildInZone,
259
- 'BuildInConstruction': BaseBuildInConstruction,
260
- 'BuildInMaterialLayer': BuildInMaterialLayer}
261
-
262
- geo_bases = {'base': geometry_types.base,
263
- 'layer': geometry_types.layer,
264
- 'vertex': geometry_types.vertex,
265
- 'edge': geometry_types.edge,
266
- 'edge_loop': geometry_types.edge_loop,
267
- 'face': geometry_types.face,
268
- 'volume': geometry_types.volume,
269
- }
270
-
271
- _create_all = False
272
-
273
- def __init__(self, *args, **kwargs):
274
-
275
- """
276
- Class which handles templates. This class generates python objects from the SIMULTAN data model for templates.
277
-
278
- @keyword templates: list of templates; if templates is None and template_filepath is defined,
279
- templates are automatically loaded
280
- @keyword template_filepath: filepath to the template (*.yml)
281
-
282
- """
283
-
284
- self._current_data_model = None
285
-
286
- self.id = uuid4()
287
-
288
- self._templates = kwargs.get('templates', None)
289
- self.template_filepath = kwargs.get('template_filepath', None)
290
-
291
- self._template_classes = kwargs.get('template_classes', None)
292
-
293
- self.data_models = kwargs.get('data_models', {})
294
-
295
- self._typed_geo_models = None
296
-
297
- template_classes[self.id] = self._template_classes
298
-
299
- self.current_data_model = kwargs.get('current_data_model', None)
300
-
301
- @property
302
- def current_data_model(self):
303
- return self._current_data_model
304
-
305
- @current_data_model.setter
306
- def current_data_model(self, value):
307
- self._current_data_model = value
308
- if self._current_data_model is None:
309
- return
310
-
311
- if self._current_data_model not in self.data_models:
312
- self.data_models[self._current_data_model.id] = self._current_data_model
313
-
314
- @property
315
- def templates(self):
316
- if self.template_filepath is None:
317
- return None
318
-
319
- if self._templates is None:
320
- self._templates = self.load_templates_from_file()
321
- return self._templates
322
-
323
- @property
324
- def template_classes(self):
325
- if self._template_classes is None:
326
- self.create_template_classes()
327
- return self._template_classes
328
-
329
- @property
330
- def typed_geo_models(self):
331
- if self._typed_geo_models is None:
332
- self._typed_geo_models = self.get_typed_geo_models()
333
- return self._typed_geo_models
334
-
335
- def get_model_by_file_id(self, id):
336
- return self.current_data_model.models_dict[id]
337
-
338
- def get_typed_model_by_file_id(self, id):
339
- return self.typed_geo_models[id]
340
-
341
- def load_templates_from_file(self, filepath=None):
342
- """
343
- Load templates from file
344
- :param filepath: filepath of the file (str)
345
- :return: templates; list of templates
346
- """
347
- if filepath is None:
348
- filepath = self.template_filepath
349
-
350
- if filepath is None:
351
- templates = []
352
- else:
353
- with open(filepath, mode='r', encoding="utf-8") as f_obj:
354
- templates = yaml.load(f_obj)
355
-
356
- return templates
357
-
358
- def create_template_classes(self) -> typing.Dict[str, str]:
359
-
360
- logger.info('\n\nCreating template-classes:\n-------------------------------------')
361
- template_classes = {**self.bases}
362
-
363
- if self.templates is not None:
364
- logger.info(f'found {self.templates.__len__()} templates')
365
-
366
- for template in self.templates:
367
-
368
- new_class = template.create_template_class(self, template_classes)
369
- template_classes[template.template_name] = new_class
370
-
371
- logger.info(f'Created template class {template.template_name}. Inherits from {template.inherits_from}')
372
-
373
- else:
374
- logger.info(f'No template file defined')
375
-
376
- self._template_classes = template_classes
377
- logger.info('template-class creation finished\n\n')
378
- return self._template_classes
379
-
380
- @lru_cache(maxsize=None)
381
- def create_python_object(self, sim_component, template_name=None):
382
-
383
- # get the template or slot
384
- # template_name = None
385
- if hasattr(sim_component, 'Parameters'):
386
- t_name = next((x.TextValue for x in sim_component.Parameters.Items if x.Name == 'TYPE'), None)
387
- if t_name is not None:
388
- template_name = t_name
389
-
390
- if (template_name is None) and (hasattr(sim_component, 'get_CurrentSlot')):
391
- template_name = sim_component.CurrentSlot.Base
392
-
393
- # if no template and no slot could be found return the plain SimComponent
394
-
395
- if template_name is None:
396
- if isinstance(sim_component, SimMultiValuePointer):
397
- template_name = 'ValueField'
398
-
399
- if template_name is None:
400
- if self._create_all:
401
- if hasattr(SimComponent, 'ContainedSimComponentsAsList'):
402
- _ = [self.create_python_object(x) for x in sim_component.Components]
403
- if hasattr(SimComponent, 'ReferencedSimComponents'):
404
- _ = [self.create_python_object(x) for x in sim_component.ReferencedComponents.Items]
405
- return sim_component
406
-
407
- if template_name not in self.template_classes.keys():
408
-
409
- # create new class for the template / slot
410
- base = SimultanObject
411
- bases = (base, )
412
-
413
- def new__init(self, *args, **kwargs):
414
- self.__class__.__bases__[0].__init__(self, *args, **kwargs)
415
-
416
- new_class_dict = {'__init__': new__init,
417
- '_template_name': template_name,
418
- '_template_id': None,
419
- '_documentation': None,
420
- '_content': None,
421
- '_types': None,
422
- '_units': None,
423
- '_base': bases,
424
- '_template_parser': self,
425
- '_slots': {}}
426
-
427
- new_class = type(template_name, bases, new_class_dict)
428
- self.template_classes[template_name] = new_class
429
-
430
- template_class = self.template_classes[template_name]
431
-
432
- # init new instance
433
- template_class._template_parser = self
434
- new_instance = template_class(wrapped_obj=sim_component,
435
- template_parser=self,
436
- data_model_id=self._current_data_model.id)
437
-
438
- # new_instance._template_parser = self
439
- return new_instance
440
-
441
- def get_typed_geo_models(self):
442
- typed_models_dict = {}
443
- for key, model in self.current_data_model.models_dict.items():
444
- if model is None:
445
- typed_models_dict[key] = None
446
- continue
447
- typed_models_dict[key] = GeometryModel(template_parser=self,
448
- wrapped_obj=model,
449
- geo_types=self.geo_bases)
450
- # models.append(GeometryModel(wrapped_obj=model))
451
- return typed_models_dict
452
-
453
- def add_new_geometry_model(self, file_name: str, model_name: str = None):
454
-
455
- model, resource = self.current_data_model.add_new_geometry_model(file_name, model_name, return_resource=True)
456
-
457
- return self.add_typed_geo_model(model, resource.Key)
458
-
459
- def add_typed_geo_model(self, model, key):
460
- """
461
- Add a geometry model as typed model
462
- :param model: ParameterStructure.Assets.ContainedResourceFileEntry
463
- :param key: resource key
464
- """
465
- if self._typed_geo_models is None:
466
- self._typed_geo_models = {}
467
-
468
- self._typed_geo_models[key] = GeometryModel(template_parser=self,
469
- wrapped_obj=model,
470
- geo_types=self.geo_bases)
471
-
472
- return self._typed_geo_models[key]
473
-
474
- def get_geo_components(self, geometry):
475
- return Enumerable.ToList[SimComponent](self.current_data_model.exch.GetComponents(geometry))
476
-
477
- def get_py_geo_components(self, geometry, template_name=None):
478
- components = Enumerable.ToList[SimComponent](self.current_data_model.exch.GetComponents(geometry))
479
- return [self.create_python_object(x, template_name=template_name) for x in components]
480
-
481
-
482
- def add_properties(prop_name: str, syn_name: str, param_type: str, slot=None) -> property:
483
- """
484
- create property for a class
485
- :param prop_name: name of the property (str)
486
- :param prop_name: name of the synonym (str)
487
- :param param_type: type of the property; if type == 'str': param.get_TextValue(); else: param.get_ValueCurrent() is returned
488
- :param slot: slot; default is None
489
- :return: property
490
- """
491
-
492
- @lru_cache()
493
- def getx(self):
494
- obj = None
495
-
496
- idx = next((i for i, x in enumerate(self._wrapped_obj.Parameters.Items) if x.Name == prop_name), None)
497
- if idx is not None:
498
- param = self._wrapped_obj.Parameters.Items[idx]
499
- obj = param.get_MultiValuePointer()
500
-
501
- if obj is None:
502
- if param_type == 'str':
503
- obj = param.get_TextValue()
504
- else:
505
- obj = param.get_ValueCurrent()
506
-
507
- if obj is None:
508
- full_slot_name = self._slots.get(prop_name, None)
509
- slot_name, slot_extension = parse_slot(full_slot_name)
510
-
511
- if full_slot_name is not None:
512
- obj = next((x.Component for x in self._wrapped_obj.Components.Items
513
- if (x.Slot.SlotBase.Base == slot_name) & (x.Slot.SlotExtension == slot_extension)),
514
- None)
515
-
516
- if obj is None:
517
- obj = next((x.Target for x in self._wrapped_obj.ReferencedComponents.Items
518
- if ' '.join([str(x.Slot.SlotBase),
519
- x.Slot.SlotExtension]) == full_slot_name),
520
- None)
521
-
522
- return self._template_parser.create_python_object(obj)
523
-
524
- def setx(self, value: Union[int, float, SimComponent, SimultanObject]):
525
- getx.cache_clear()
526
- idx = next((i for i, x in enumerate(self._wrapped_obj.Parameters.Items) if x.Name == prop_name), None)
527
-
528
- if isinstance(value, (SimComponent, SimultanObject)):
529
- # set reference or subcomponent
530
-
531
- if prop_name not in self._slots.keys():
532
- raise KeyError(f'{prop_name} not defined as slot for class {self.__class__.__name__}')
533
-
534
- full_slot_name = self._slots.get(prop_name, None)
535
- slot_name, slot_extension = parse_slot(full_slot_name)
536
-
537
- # check if slot exists:
538
- idx = self.slot_components.index[
539
- (self.slot_components.slot == slot_name) & (self.slot_components.slot_extension == slot_extension)]
540
-
541
- if idx.__len__() == 1:
542
- # if subcomponent:
543
- if self.slot_components.iloc[idx].comp_type.values == 0:
544
- if isinstance(value, SimultanObject):
545
- pass
546
-
547
- ref = next((x for x in self._wrapped_obj.Components.Items
548
- if ((x.Slot.SlotBase.Base == slot_name) & (
549
- x.Slot.SlotExtension == slot_extension))), None)
550
-
551
- if isinstance(value, SimComponent):
552
- ref.Component = value
553
- elif isinstance(value, SimultanObject):
554
- ref.Component = value._wrapped_obj
555
-
556
- # if reference:
557
- elif self.slot_components.iloc[idx].comp_type.values == 1:
558
- ref = next((x for x in self._wrapped_obj.ReferencedComponents.Items
559
- if ((x.Slot.SlotBase.Base == slot_name) & (
560
- x.Slot.SlotExtension == slot_extension))), None)
561
-
562
- if isinstance(value, SimComponent):
563
- # delete reference
564
- self.remove_component_reference(ref.reference)
565
- # add the SimComponent as sub-component
566
- self.add_sub_component(component=value,
567
- slot_name=slot_name,
568
- slot_extension=slot_extension,
569
- alter_slot=True)
570
- else:
571
- ref.Target = value._wrapped_obj
572
-
573
- # index does not exist
574
- elif idx.__len__() == 0:
575
- if isinstance(value, SimultanObject):
576
- self.add_component_reference(component=value._wrapped_obj,
577
- slot_name=slot_name,
578
- slot_extension=slot_extension)
579
- elif isinstance(value, SimComponent):
580
- self.add_sub_component(component=value, slot_name=slot_name, slot_extension=slot_extension)
581
-
582
- elif param_type == 'str':
583
- #todo: implementation for referenced parameters
584
- if self._wrapped_obj.Parameters.Items[2].GetReferencedParameter() != self._wrapped_obj.Parameters.Items[idx]:
585
- raise NotImplementedError(f'{self.name}: Param {prop_name} is a referenced Parameter. Setting referenced parameters is not yet implemented')
586
- self._wrapped_obj.Parameters.Items[idx].set_TextValue(value)
587
- elif isinstance(value, (int, float)):
588
- # todo: implementation for referenced parameters
589
- if self._wrapped_obj.Parameters.Items[2].GetReferencedParameter() != self._wrapped_obj.Parameters.Items[idx]:
590
- raise NotImplementedError(f'{self.name}: Param {prop_name} is a referenced Parameter. Setting referenced parameters is not yet implemented')
591
- self._wrapped_obj.Parameters.Items[idx].set_ValueCurrent(float(value))
592
- else:
593
- raise TypeError(
594
- f'{self.name}: Error setting parameter {prop_name} to {type(value)}. Supported types are only: int float str SimComponent SimultanObject.')
595
-
596
- def delx(self):
597
- logger.warning('delete method not implemented')
598
- raise NotImplementedError
599
-
600
- return property(getx, setx, delx, f"automatic created property")
601
-
602
-
603
- def _my_loader(f):
604
- import yaml
605
-
606
- description = []
607
-
608
- def any_constructor(loader, tag_suffix, node):
609
- if isinstance(node, yaml.MappingNode):
610
- return loader.construct_mapping(node)
611
- if isinstance(node, yaml.SequenceNode):
612
- return loader.construct_sequence(node)
613
- return loader.construct_scalar(node)
614
-
615
- yaml.add_multi_constructor('', any_constructor, Loader=yaml.SafeLoader)
616
- data = list(yaml.load_all(f, Loader=yaml.SafeLoader))
617
- return data
618
-
619
-
620
- _parsers['_my_loader'] = _my_loader
621
-
622
-
623
- class TemplateValidator(object):
624
-
625
- def __init__(self, *args, **kwargs):
626
-
627
- self.schema = yamale.make_schema(schema_file, parser='ruamel')
628
-
629
- def validate(self, yaml_file):
630
- data = yamale.make_data(yaml_file, parser='_my_loader')
631
- yamale.validate(self.schema, data)