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.
- PySimultan-0.2.1.dist-info/LICENSE.txt +17 -0
- PySimultan-0.2.1.dist-info/METADATA +36 -0
- PySimultan-0.2.1.dist-info/RECORD +82 -0
- {PySimultan-0.1.54.dist-info → PySimultan-0.2.1.dist-info}/WHEEL +1 -1
- PySimultan-0.2.1.dist-info/top_level.txt +1 -0
- {PySimultan → PySimultan2}/__init__.py +11 -6
- PySimultan2/config.py +52 -0
- PySimultan2/data_model.py +713 -0
- PySimultan2/default_types.py +507 -0
- PySimultan2/files.py +371 -0
- PySimultan2/geometry/__init__.py +4 -0
- PySimultan2/geometry/geometry_base.py +654 -0
- PySimultan2/geometry/utils.py +181 -0
- PySimultan2/multi_values.py +277 -0
- PySimultan2/object_mapper.py +200 -0
- PySimultan2/resources/AssimpNet.dll +0 -0
- PySimultan2/resources/AvalonDock.dll +0 -0
- PySimultan2/resources/BruTile.dll +0 -0
- PySimultan2/resources/ClosedXML.dll +0 -0
- PySimultan2/resources/ComponentBuilder.dll +0 -0
- PySimultan/resources/ComponentBuilder.exe.config → PySimultan2/resources/ComponentBuilder.dll.config +6 -2
- PySimultan2/resources/ComponentBuilder.runtimeconfig.json +18 -0
- {PySimultan → PySimultan2}/resources/ComponentBuilder.xml +11877 -6754
- PySimultan2/resources/ControlzEx.dll +0 -0
- PySimultan2/resources/Cyotek.Drawing.BitmapFont.dll +0 -0
- PySimultan2/resources/DocumentFormat.OpenXml.dll +0 -0
- PySimultan2/resources/ExcelNumberFormat.dll +0 -0
- PySimultan2/resources/Fluent.dll +0 -0
- PySimultan2/resources/GeometryViewer.dll +0 -0
- {PySimultan → PySimultan2}/resources/GeometryViewer.xml +2201 -1155
- PySimultan2/resources/HelixToolkit.Core.Wpf.dll +0 -0
- PySimultan2/resources/HelixToolkit.SharpDX.Core.Wpf.dll +0 -0
- PySimultan2/resources/HelixToolkit.SharpDX.Core.dll +0 -0
- PySimultan2/resources/HelixToolkit.dll +0 -0
- PySimultan2/resources/MathNet.Numerics.dll +0 -0
- PySimultan2/resources/Microsoft.AspNetCore.Authorization.dll +0 -0
- PySimultan2/resources/Microsoft.AspNetCore.Metadata.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.DependencyInjection.Abstractions.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.Logging.Abstractions.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.Options.dll +0 -0
- PySimultan2/resources/Microsoft.Extensions.Primitives.dll +0 -0
- PySimultan2/resources/Microsoft.WindowsAPICodePack.Shell.dll +0 -0
- PySimultan2/resources/Microsoft.WindowsAPICodePack.dll +0 -0
- PySimultan2/resources/Microsoft.Xaml.Behaviors.dll +0 -0
- PySimultan2/resources/Newtonsoft.Json.Bson.dll +0 -0
- PySimultan2/resources/Newtonsoft.Json.dll +0 -0
- PySimultan2/resources/SIMULTAN.AutoUpdate.Client.dll +0 -0
- PySimultan2/resources/SIMULTAN.AutoUpdate.DataTransferLibrary.dll +0 -0
- PySimultan2/resources/SIMULTAN.AutoUpdate.DataTransferLibrary.dll.config +15 -0
- PySimultan2/resources/SIMULTAN.Lang.dll +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.Lang.xml +5282 -3252
- PySimultan2/resources/SIMULTAN.Plugins.dll +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.Plugins.xml +110 -0
- PySimultan2/resources/SIMULTAN.UI.dll +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.UI.xml +10483 -4937
- PySimultan2/resources/SIMULTAN.dll +0 -0
- PySimultan2/resources/SIMULTAN.xml +34122 -0
- PySimultan2/resources/SharpDX.D3DCompiler.dll +0 -0
- PySimultan2/resources/SharpDX.DXGI.dll +0 -0
- PySimultan2/resources/SharpDX.Direct2D1.dll +0 -0
- PySimultan2/resources/SharpDX.Direct3D11.dll +0 -0
- PySimultan2/resources/SharpDX.Direct3D9.dll +0 -0
- {PySimultan → PySimultan2}/resources/SharpDX.Mathematics.dll +0 -0
- PySimultan2/resources/SharpDX.dll +0 -0
- {PySimultan → PySimultan2}/resources/SitePlanner.dll +0 -0
- {PySimultan → PySimultan2}/resources/SitePlanner.xml +959 -1110
- PySimultan2/resources/Sprache.dll +0 -0
- PySimultan2/resources/System.Data.OleDb.dll +0 -0
- PySimultan2/resources/System.Net.Http.Formatting.dll +0 -0
- PySimultan2/resources/XAMLMarkupExtensions.dll +0 -0
- PySimultan2/resources/assimp.dll +0 -0
- {PySimultan → PySimultan2}/resources/defaultsettings.xml +0 -0
- PySimultan2/simultan_object.py +366 -0
- PySimultan2/taxonomy_maps.py +169 -0
- PySimultan2/utils.py +1383 -0
- PySimultan/config.py +0 -57
- PySimultan/data_model.py +0 -376
- PySimultan/default_types.py +0 -1771
- PySimultan/geo_default_types.py +0 -763
- PySimultan/geometry.py +0 -309
- PySimultan/resources/AssimpNet.dll +0 -0
- PySimultan/resources/AssimpNet.xml +0 -12074
- PySimultan/resources/BruTile.dll +0 -0
- PySimultan/resources/BruTile.xml +0 -1845
- PySimultan/resources/ControlzEx.dll +0 -0
- PySimultan/resources/Cyotek.Drawing.BitmapFont.dll +0 -0
- PySimultan/resources/DXFImportExport.dll +0 -0
- PySimultan/resources/DotSpatial.Projections.xml +0 -5879
- PySimultan/resources/EXCELImportExport.dll +0 -0
- PySimultan/resources/Fluent.dll +0 -0
- PySimultan/resources/Fluent.xml +0 -9103
- PySimultan/resources/GeoJSON.Net.dll +0 -0
- PySimultan/resources/GeometryViewer.Data.dll +0 -0
- PySimultan/resources/GeometryViewer.Data.xml +0 -4443
- PySimultan/resources/GeometryViewer.Shared.dll +0 -0
- PySimultan/resources/GeometryViewer.Shared.xml +0 -588
- PySimultan/resources/GeometryViewer.dll +0 -0
- PySimultan/resources/HelixToolkit.Wpf.SharpDX.dll +0 -0
- PySimultan/resources/HelixToolkit.Wpf.SharpDX.xml +0 -43219
- PySimultan/resources/HelixToolkit.Wpf.dll +0 -0
- PySimultan/resources/HelixToolkit.Wpf.xml +0 -22363
- PySimultan/resources/HelixToolkit.dll +0 -0
- PySimultan/resources/HelixToolkit.xml +0 -144
- PySimultan/resources/ImportLog_SMART_CAMPUS_TU_WIEN_BIBLIOTHEK_20210305_ZONENMODELL_23_11_2021-06_54_54.txt +0 -1
- PySimultan/resources/LibGit2Sharp.dll +0 -0
- PySimultan/resources/LibGit2Sharp.dll.config +0 -4
- PySimultan/resources/LibGit2Sharp.xml +0 -13770
- PySimultan/resources/MathNet.Numerics.dll +0 -0
- PySimultan/resources/MathNet.Numerics.xml +0 -57152
- PySimultan/resources/Microsoft.WindowsAPICodePack.Shell.dll +0 -0
- PySimultan/resources/Microsoft.WindowsAPICodePack.Shell.xml +0 -25496
- PySimultan/resources/Microsoft.WindowsAPICodePack.dll +0 -0
- PySimultan/resources/Microsoft.WindowsAPICodePack.xml +0 -2934
- PySimultan/resources/Newtonsoft.Json.dll +0 -0
- PySimultan/resources/Newtonsoft.Json.xml +0 -11305
- PySimultan/resources/ParameterStructure.dll +0 -0
- PySimultan/resources/ParameterStructure.xml +0 -10750
- PySimultan/resources/SIMULTAN.AutoUpdate.Client.dll +0 -0
- PySimultan/resources/SIMULTAN.DataExchange.dll +0 -0
- PySimultan/resources/SIMULTAN.Lang.dll +0 -0
- PySimultan/resources/SIMULTAN.Legacy.dll +0 -0
- PySimultan/resources/SIMULTAN.Legacy.xml +0 -254
- PySimultan/resources/SIMULTAN.Plugins.dll +0 -0
- PySimultan/resources/SIMULTAN.Project.dll +0 -0
- PySimultan/resources/SIMULTAN.Project.dll.config +0 -11
- PySimultan/resources/SIMULTAN.UI.dll +0 -0
- PySimultan/resources/SIMULTAN.Util.dll +0 -0
- PySimultan/resources/SIMULTAN.Util.xml +0 -3430
- PySimultan/resources/SharpDX.D3DCompiler.dll +0 -0
- PySimultan/resources/SharpDX.D3DCompiler.xml +0 -5897
- PySimultan/resources/SharpDX.DXGI.dll +0 -0
- PySimultan/resources/SharpDX.DXGI.xml +0 -8737
- PySimultan/resources/SharpDX.Direct2D1.dll +0 -0
- PySimultan/resources/SharpDX.Direct2D1.xml +0 -46691
- PySimultan/resources/SharpDX.Direct3D11.dll +0 -0
- PySimultan/resources/SharpDX.Direct3D11.xml +0 -31826
- PySimultan/resources/SharpDX.Direct3D9.dll +0 -0
- PySimultan/resources/SharpDX.Direct3D9.xml +0 -36489
- PySimultan/resources/SharpDX.Mathematics.xml +0 -16449
- PySimultan/resources/SharpDX.dll +0 -0
- PySimultan/resources/Sprache.dll +0 -0
- PySimultan/resources/Sprache.xml +0 -1199
- PySimultan/resources/System.Net.Http.Formatting.dll +0 -0
- PySimultan/resources/System.Net.Http.Formatting.xml +0 -2094
- PySimultan/resources/System.Windows.Interactivity.dll +0 -0
- PySimultan/resources/TalkGit.dll +0 -0
- PySimultan/resources/TalkGit.dll.config +0 -11
- PySimultan/resources/WebServiceConnector.dll +0 -0
- PySimultan/resources/WebServiceConnector.dll.config +0 -11
- PySimultan/resources/XAMLMarkupExtensions.dll +0 -0
- PySimultan/resources/XAMLMarkupExtensions.xml +0 -862
- PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.Aero.dll +0 -0
- PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.Metro.dll +0 -0
- PySimultan/resources/Xceed.Wpf.AvalonDock.Themes.VS2010.dll +0 -0
- PySimultan/resources/Xceed.Wpf.AvalonDock.dll +0 -0
- PySimultan/resources/Xceed.Wpf.Toolkit.dll +0 -0
- PySimultan/resources/assimp.dll +0 -0
- PySimultan/resources/schema.yaml +0 -13
- PySimultan/resources/simultan_exception_07_10_2021-08_34_24.txt +0 -17
- PySimultan/resources/simultan_exception_07_10_2021-10_13_31.txt +0 -17
- PySimultan/resources/simultan_exception_11_10_2021-19_45_42.txt +0 -17
- PySimultan/resources/simultan_exception_22_11_2021-16_41_52.txt +0 -14
- PySimultan/resources/simultan_exception_22_11_2021-17_37_40.txt +0 -14
- PySimultan/simultan_geometry_utils.py +0 -81
- PySimultan/simultan_utils.py +0 -165
- PySimultan/slots.py +0 -51
- PySimultan/template_tools.py +0 -631
- PySimultan/utils.py +0 -298
- PySimultan-0.1.54.dist-info/LICENSE +0 -674
- PySimultan-0.1.54.dist-info/LICENSE.txt +0 -674
- PySimultan-0.1.54.dist-info/METADATA +0 -690
- PySimultan-0.1.54.dist-info/RECORD +0 -119
- PySimultan-0.1.54.dist-info/entry_points.txt +0 -3
- PySimultan-0.1.54.dist-info/top_level.txt +0 -1
- PySimultan-0.1.54.dist-info/zip-safe +0 -1
- {PySimultan → PySimultan2}/resources/DotSpatial.Projections.dll +0 -0
- {PySimultan → PySimultan2}/resources/GeometryViewer.dll.config +0 -0
- {PySimultan → PySimultan2}/resources/SIMULTAN.AutoUpdate.Client.dll.config +0 -0
- {PySimultan → PySimultan2}/resources/SitePlanner.dll.config +0 -0
- {PySimultan → PySimultan2}/resources/Sprache.Calc.dll +0 -0
- {PySimultan → PySimultan2}/resources/__init__.py +0 -0
- {PySimultan → PySimultan2}/resources/setup.bat +0 -0
@@ -0,0 +1,713 @@
|
|
1
|
+
import atexit
|
2
|
+
import os
|
3
|
+
import shutil
|
4
|
+
from uuid import uuid4
|
5
|
+
from colorlog import getLogger
|
6
|
+
from functools import lru_cache, reduce
|
7
|
+
from weakref import WeakSet, WeakValueDictionary
|
8
|
+
from . import config
|
9
|
+
from .utils import *
|
10
|
+
from pathlib import PosixPath, WindowsPath
|
11
|
+
from typing import Union, Tuple
|
12
|
+
|
13
|
+
|
14
|
+
# from SIMULTAN import Projects
|
15
|
+
# noinspection PyUnresolvedReferences
|
16
|
+
from SIMULTAN.Projects import ExtendedProjectData
|
17
|
+
# noinspection PyUnresolvedReferences
|
18
|
+
from SIMULTAN import Utils
|
19
|
+
# noinspection PyUnresolvedReferences
|
20
|
+
from SIMULTAN.Data import Users
|
21
|
+
# from SIMULTAN.Serializer import Projects
|
22
|
+
from SIMULTAN.Serializer.SimGeo import *
|
23
|
+
from SIMULTAN.Serializer.Projects import *
|
24
|
+
from SIMULTAN.Data.Components import SimComponent
|
25
|
+
from SIMULTAN.Data.MultiValues import SimMultiValueBigTable, SimMultiValueField3D
|
26
|
+
from SIMULTAN.Data.Assets import ResourceEntry
|
27
|
+
from SIMULTAN.Data.Geometry import OffsetAlgorithm
|
28
|
+
# from GeometryViewer.Service import *
|
29
|
+
# from SIMULTAN.UI.Services import *
|
30
|
+
from System.IO import *
|
31
|
+
from System.Collections.Generic import *
|
32
|
+
from System.Collections.Generic import List as NetList
|
33
|
+
from SIMULTAN.Data.Taxonomy import SimTaxonomyEntry, SimTaxonomyEntryReference, SimTaxonomy
|
34
|
+
from SIMULTAN.Data.Geometry import GeometryModel as NetGeometryModel
|
35
|
+
from SIMULTAN.Data.Geometry import Layer, Vertex, Edge, PEdge, Face, Volume, EdgeLoop
|
36
|
+
|
37
|
+
from System.Security import SecureString
|
38
|
+
from System import Guid
|
39
|
+
from System.IO import *
|
40
|
+
from System.Security import *
|
41
|
+
from System.Security.Cryptography import *
|
42
|
+
from System.Text import *
|
43
|
+
|
44
|
+
from .files import add_tag_to_resource
|
45
|
+
|
46
|
+
|
47
|
+
logger = getLogger('PySimultan')
|
48
|
+
|
49
|
+
|
50
|
+
class IAuthenticationServiceNew(Users.IAuthenticationService):
|
51
|
+
__namespace__ = "authenticate_namespace"
|
52
|
+
|
53
|
+
user_name = None
|
54
|
+
password = None
|
55
|
+
|
56
|
+
def Authenticate(self, user_manager, project_file):
|
57
|
+
# user_name = 'admin'
|
58
|
+
# password = 'admin'
|
59
|
+
|
60
|
+
sec_str = SecureString()
|
61
|
+
for char in self.password:
|
62
|
+
sec_str.AppendChar(char)
|
63
|
+
|
64
|
+
user = user_manager.Authenticate(self.user_name, sec_str)
|
65
|
+
|
66
|
+
user_manager.CurrentUser = user.Item1
|
67
|
+
user_manager.EncryptionKey = user.Item2
|
68
|
+
|
69
|
+
return user.Item1
|
70
|
+
|
71
|
+
|
72
|
+
data_models = WeakSet()
|
73
|
+
data_models_dict = WeakValueDictionary()
|
74
|
+
|
75
|
+
|
76
|
+
# noinspection PyUnresolvedReferences
|
77
|
+
class DataModel:
|
78
|
+
|
79
|
+
@classmethod
|
80
|
+
def create_new_project(cls, project_path: str, user_name: str = 'admin', password: str = 'admin'):
|
81
|
+
"""
|
82
|
+
Create a new project
|
83
|
+
:param project_path: Project path, e.g. 'C:/Users/username/Documents/Project1.simultan'
|
84
|
+
:param user_name:
|
85
|
+
:param password:
|
86
|
+
:return: DataModel
|
87
|
+
"""
|
88
|
+
|
89
|
+
passwordArray = Encoding.UTF8.GetBytes(password)
|
90
|
+
encryptionKey = RandomNumberGenerator.GetBytes(32)
|
91
|
+
encryptedEncryptionKey = Users.SimUsersManager.EncryptEncryptionKey(encryptionKey, passwordArray)
|
92
|
+
passwordHash = Users.SimUsersManager.HashPassword(passwordArray)
|
93
|
+
initialUser = Users.SimUser(Guid.NewGuid(),
|
94
|
+
user_name,
|
95
|
+
passwordHash,
|
96
|
+
encryptedEncryptionKey,
|
97
|
+
Users.SimUserRole.ADMINISTRATOR)
|
98
|
+
|
99
|
+
tempPath = Path.GetTempPath()
|
100
|
+
projectFile = FileInfo(project_path)
|
101
|
+
projectData = ExtendedProjectData()
|
102
|
+
|
103
|
+
projectData.UsersManager.EncryptionKey = encryptionKey
|
104
|
+
if projectFile.Exists:
|
105
|
+
projectFile.Delete()
|
106
|
+
project = ZipProjectIO.NewProject(projectFile, tempPath, projectData, initialUser)
|
107
|
+
projectFile.Refresh()
|
108
|
+
if projectFile.Exists:
|
109
|
+
print("Project created successfully")
|
110
|
+
else:
|
111
|
+
print("Failed to create project")
|
112
|
+
|
113
|
+
return cls(project_path=project_path, user_name=user_name, password=password)
|
114
|
+
|
115
|
+
def __new__(cls, *args, **kwargs):
|
116
|
+
|
117
|
+
instance = super().__new__(cls)
|
118
|
+
config.default_data_model = instance
|
119
|
+
try:
|
120
|
+
data_models.add(instance)
|
121
|
+
except Exception as e:
|
122
|
+
logger.error(f'Error adding instance {instance} to data_models: {e}')
|
123
|
+
return instance
|
124
|
+
|
125
|
+
def __init__(self, *args, **kwargs):
|
126
|
+
"""
|
127
|
+
|
128
|
+
:param args:
|
129
|
+
:param kwargs:
|
130
|
+
"""
|
131
|
+
self.user_name: str = kwargs.get('user_name', 'admin')
|
132
|
+
self.password: str = kwargs.get('password', 'admin')
|
133
|
+
|
134
|
+
self.models_dict = {}
|
135
|
+
|
136
|
+
atexit.register(self.cleanup)
|
137
|
+
|
138
|
+
self.id = uuid4()
|
139
|
+
data_models_dict[self.id] = self
|
140
|
+
self.data = None
|
141
|
+
self._project_data_manager = None
|
142
|
+
self._user = None
|
143
|
+
self._project = None
|
144
|
+
self._zip_loader = None
|
145
|
+
|
146
|
+
self.project_path = kwargs.get('project_path', None)
|
147
|
+
|
148
|
+
self.service_provider = Utils.ServicesProvider()
|
149
|
+
|
150
|
+
self.i_aut_service = IAuthenticationServiceNew
|
151
|
+
self.i_aut_service.user_name = self.user_name
|
152
|
+
self.i_aut_service.password = self.password
|
153
|
+
|
154
|
+
self.service_provider.AddService[Users.IAuthenticationService](self.i_aut_service())
|
155
|
+
|
156
|
+
# self.serv = GeometryViewerService([], self.service_provider)
|
157
|
+
# self.service_provider.AddService[IGeometryViewerService](self.serv)
|
158
|
+
|
159
|
+
self.exch = self.project.AllProjectDataManagers.ComponentGeometryExchange
|
160
|
+
# self.exch.ModelStore = self.serv
|
161
|
+
|
162
|
+
self.resources = {}
|
163
|
+
# self.models_dict = {}
|
164
|
+
#
|
165
|
+
# if self.project_data_manager.AssetManager.Resources.__len__() > 0:
|
166
|
+
# for resource in self.project_data_manager.AssetManager.Resources:
|
167
|
+
# if resource is None:
|
168
|
+
# continue
|
169
|
+
# self.resources[resource.Key] = resource
|
170
|
+
# self.models_dict[resource.Key] = None
|
171
|
+
# current_full_path = resource.CurrentFullPath
|
172
|
+
# if current_full_path == '?':
|
173
|
+
# continue
|
174
|
+
#
|
175
|
+
# if resource.Extension == '.simgeo':
|
176
|
+
# error_list = NetList[SimGeoIOError]()
|
177
|
+
#
|
178
|
+
# model = SimGeoIO.Load(resource, self.project_data_manager, error_list, OffsetAlgorithm.Full)
|
179
|
+
# self.models_dict[resource.Key] = model
|
180
|
+
# try:
|
181
|
+
# self.project_data_manager.GeometryModels.AddGeometryModel(model)
|
182
|
+
# except Exception as e:
|
183
|
+
# logger.warning(f'Error while loading Model: {model} from {model.File}: {e}. Trying reload...')
|
184
|
+
# raise e
|
185
|
+
|
186
|
+
self.ValueFields = self.project_data_manager.ValueManager.Items
|
187
|
+
self.import_data_model()
|
188
|
+
|
189
|
+
self.__mongo_instance = None
|
190
|
+
|
191
|
+
@property
|
192
|
+
def assets(self):
|
193
|
+
return self.project_data_manager.AssetManager.Resources
|
194
|
+
|
195
|
+
@property
|
196
|
+
def _mongo_instance(self):
|
197
|
+
if self.__mongo_instance is None:
|
198
|
+
self.create_mongo_instance()
|
199
|
+
return self.__mongo_instance
|
200
|
+
|
201
|
+
@_mongo_instance.setter
|
202
|
+
def _mongo_instance(self, value):
|
203
|
+
self.__mongo_instance = value
|
204
|
+
|
205
|
+
@property
|
206
|
+
def models(self):
|
207
|
+
self.models_dict = {}
|
208
|
+
|
209
|
+
if self.project_data_manager.AssetManager.Resources.__len__() > 0:
|
210
|
+
for resource in self.project_data_manager.AssetManager.Resources:
|
211
|
+
if resource is None:
|
212
|
+
continue
|
213
|
+
self.resources[resource.Key] = resource
|
214
|
+
|
215
|
+
current_full_path = resource.CurrentFullPath
|
216
|
+
if current_full_path == '?':
|
217
|
+
continue
|
218
|
+
|
219
|
+
if resource.Extension == '.simgeo':
|
220
|
+
self.models_dict[resource.Key] = None
|
221
|
+
error_list = NetList[SimGeoIOError]()
|
222
|
+
|
223
|
+
model = SimGeoIO.Load(resource, self.project_data_manager, error_list, OffsetAlgorithm.Full)
|
224
|
+
self.models_dict[resource.Key] = model
|
225
|
+
try:
|
226
|
+
self.project_data_manager.GeometryModels.AddGeometryModel(model)
|
227
|
+
except Exception as e:
|
228
|
+
logger.warning(f'Error while loading Model: {model} from {model.File}: {e}. Trying reload...')
|
229
|
+
raise e
|
230
|
+
|
231
|
+
return self.models_dict
|
232
|
+
|
233
|
+
@property
|
234
|
+
def taxonomies(self):
|
235
|
+
return self.project_data_manager.Taxonomies
|
236
|
+
|
237
|
+
@property
|
238
|
+
def value_fields(self):
|
239
|
+
return self.project_data_manager.ValueManager
|
240
|
+
|
241
|
+
@property
|
242
|
+
def project_data_manager(self):
|
243
|
+
if (self._project_data_manager) is None and (self.user is not None):
|
244
|
+
self._project_data_manager = ExtendedProjectData()
|
245
|
+
return self._project_data_manager
|
246
|
+
|
247
|
+
@project_data_manager.setter
|
248
|
+
def project_data_manager(self, value):
|
249
|
+
self._project_data_manager = value
|
250
|
+
|
251
|
+
@property
|
252
|
+
def user(self) -> Users.SimUserRole:
|
253
|
+
if self._user is None:
|
254
|
+
self._user = Users.SimUserRole.ADMINISTRATOR
|
255
|
+
return self._user
|
256
|
+
|
257
|
+
@user.setter
|
258
|
+
def user(self, value: Users.SimUserRole):
|
259
|
+
if value != self._user:
|
260
|
+
self.project_data_manager = None
|
261
|
+
self._project = None
|
262
|
+
self._user = value
|
263
|
+
|
264
|
+
@property
|
265
|
+
def project(self):
|
266
|
+
if (self._project is None) and (self.project_path is not None) and (self.project_data_manager is not None):
|
267
|
+
logger.debug('loading project')
|
268
|
+
self.project = ZipProjectIO.Load(FileInfo(self.project_path), self.project_data_manager)
|
269
|
+
exit_code = ZipProjectIO.AuthenticateUserAfterLoading(self.project,
|
270
|
+
self.project_data_manager,
|
271
|
+
self.service_provider)
|
272
|
+
if not exit_code:
|
273
|
+
logger.error('Could not open project. Wrong user or password! Exiting program...')
|
274
|
+
ZipProjectIO.OpenAfterAuthentication(self.project, self.project_data_manager)
|
275
|
+
logger.debug('project loaded successfull')
|
276
|
+
return self._project
|
277
|
+
|
278
|
+
@project.setter
|
279
|
+
def project(self, value):
|
280
|
+
self._project = value
|
281
|
+
|
282
|
+
def get_typed_data(self, mapper, create_all=False) -> list[SimultanObject]:
|
283
|
+
"""
|
284
|
+
Return the typed data from the project
|
285
|
+
:param mapper:
|
286
|
+
:param create_all: If True, all components and subcomponents will be created, else only the top level components
|
287
|
+
:return:
|
288
|
+
"""
|
289
|
+
|
290
|
+
mapper._create_all = create_all
|
291
|
+
mapper.current_data_model = self
|
292
|
+
|
293
|
+
return mapper.get_typed_data(self, create_all=create_all)
|
294
|
+
|
295
|
+
def import_data_model(self):
|
296
|
+
self.data = self.project_data_manager.Components
|
297
|
+
return self.data
|
298
|
+
|
299
|
+
def add_field(self, field: SimMultiValueField3D):
|
300
|
+
self.project_data_manager.ValueManager.Add(field)
|
301
|
+
|
302
|
+
def remove_field(self, field: SimMultiValueField3D):
|
303
|
+
self.project_data_manager.ValueManager.Remove(field)
|
304
|
+
|
305
|
+
@lru_cache(maxsize=None)
|
306
|
+
def get_geo_instance(self, file_id, type, id):
|
307
|
+
geo_model = self.models[file_id]
|
308
|
+
objects = getattr(geo_model.Geometry, type)
|
309
|
+
|
310
|
+
return next((x for x in objects.Items if x.Id == id), None)
|
311
|
+
|
312
|
+
def add_component(self, component: SimComponent):
|
313
|
+
"""
|
314
|
+
Add a component to the project
|
315
|
+
:param component:
|
316
|
+
:return:
|
317
|
+
"""
|
318
|
+
# logger.info(
|
319
|
+
# f'Adding component {component.Id} {component.Name} {type(component)} to project {self.project_path}')
|
320
|
+
if component.Id.LocalId != 0:
|
321
|
+
raise ValueError(f'Component {component.Id} already added to project {self.project_path}')
|
322
|
+
|
323
|
+
if not hasattr(component, '__added_to_data_model__'):
|
324
|
+
component.__added_to_data_model__ = True
|
325
|
+
elif component.__added_to_data_model__:
|
326
|
+
return
|
327
|
+
|
328
|
+
self.data.Add(component)
|
329
|
+
# logger.info(
|
330
|
+
# f'Added component {component.Id} {component.Name} {type(component)} to project {self.project_path}')
|
331
|
+
|
332
|
+
def create_new_component(self,
|
333
|
+
name: str,
|
334
|
+
slot: Union[None, SimTaxonomyEntry, SimTaxonomyEntryReference] = None,
|
335
|
+
add_to_project=True,
|
336
|
+
**kwargs) -> SimultanObject:
|
337
|
+
"""
|
338
|
+
Create a new component and add it to the project
|
339
|
+
:param name: Name of the component
|
340
|
+
:param slot: Slot of the component
|
341
|
+
:param add_to_project: Add the component to the project
|
342
|
+
:param kwargs:
|
343
|
+
:return: SimultanObject
|
344
|
+
"""
|
345
|
+
|
346
|
+
comp = create_component(name=name,
|
347
|
+
slot=slot,
|
348
|
+
data_model=self,
|
349
|
+
**kwargs)
|
350
|
+
if add_to_project:
|
351
|
+
self.add_component(comp)
|
352
|
+
return comp
|
353
|
+
|
354
|
+
def remove_subcomponent(self, component: SimComponent = None, index: int = None):
|
355
|
+
"""
|
356
|
+
Remove a subcomponent from a component
|
357
|
+
:param component:
|
358
|
+
:param index:
|
359
|
+
:return:
|
360
|
+
"""
|
361
|
+
if component is not None:
|
362
|
+
index = self.data.Items.IndexOf(component)
|
363
|
+
self.data.RemoveItem(index)
|
364
|
+
elif index is not None:
|
365
|
+
self.data.RemoveItem(index)
|
366
|
+
|
367
|
+
def save(self):
|
368
|
+
"""
|
369
|
+
Save the project
|
370
|
+
:return:
|
371
|
+
"""
|
372
|
+
ZipProjectIO.Save(self.project, False)
|
373
|
+
|
374
|
+
def cleanup(self):
|
375
|
+
"""
|
376
|
+
Close and cleanup project
|
377
|
+
"""
|
378
|
+
logger.info('closing project...')
|
379
|
+
try:
|
380
|
+
self._project.DisableProjectUnpackFolderWatcher()
|
381
|
+
if self._project is not None:
|
382
|
+
if self._project.IsLoaded:
|
383
|
+
ZipProjectIO.Unload(self._project)
|
384
|
+
if self._project.IsOpened:
|
385
|
+
ZipProjectIO.Close(self._project, False, True)
|
386
|
+
|
387
|
+
self._project_data_manager.Reset()
|
388
|
+
except Exception as e:
|
389
|
+
pass
|
390
|
+
|
391
|
+
# def create_new_component(self):
|
392
|
+
#
|
393
|
+
# ref_comp = self.data.Items[0]
|
394
|
+
#
|
395
|
+
# new_comp = SimComponent()
|
396
|
+
# new_comp.Name = 'Test'
|
397
|
+
#
|
398
|
+
# new_param = SimParameter('test_param', 'Unicorn', 15.268)
|
399
|
+
# new_comp.Parameters.Add(new_param)
|
400
|
+
#
|
401
|
+
# sub_new_comp = SimComponent()
|
402
|
+
# sub_new_comp.CurrentSlot = SimSlotBase(ComponentUtils.COMP_SLOT_AREAS)
|
403
|
+
# sub_new_comp.Name = 'SubTest'
|
404
|
+
#
|
405
|
+
# entry = SimChildComponentEntry(SimSlot(SimSlotBase(ComponentUtils.COMP_SLOT_AREAS), '15'),
|
406
|
+
# sub_new_comp)
|
407
|
+
# new_comp.Components.Add(entry)
|
408
|
+
#
|
409
|
+
# slot = SimSlot(ref_comp.CurrentSlot, '11')
|
410
|
+
# ComponentManagement.AddReferencedComponentSlot(new_comp, slot, self.user)
|
411
|
+
# ComponentManagement.AddReferencedComponent(new_comp, slot, ref_comp, self.user)
|
412
|
+
#
|
413
|
+
# self.add_component(new_comp)
|
414
|
+
# self.save()
|
415
|
+
#
|
416
|
+
# return new_comp
|
417
|
+
|
418
|
+
def add_component_reference(self, comp: SimComponent, ref_comp: SimComponent, slot_extension: str, slot_name: str):
|
419
|
+
"""
|
420
|
+
Add a reference to a component
|
421
|
+
:param comp: Component to add the reference
|
422
|
+
:param ref_comp: Referenced component
|
423
|
+
:param slot_extension:
|
424
|
+
:param slot_name:
|
425
|
+
:return:
|
426
|
+
"""
|
427
|
+
slot = SimSlot(slot_name, str(slot_extension))
|
428
|
+
ComponentManagement.AddReferencedComponentSlot(comp, slot, self.user)
|
429
|
+
ComponentManagement.AddReferencedComponent(comp, slot, ref_comp, self.user)
|
430
|
+
|
431
|
+
def remove_referenced_component(self, comp: SimComponent, index: int):
|
432
|
+
if index is not None:
|
433
|
+
self.data.RemoveItem(index)
|
434
|
+
elif comp is not None:
|
435
|
+
index = self.data.Items.IndexOf(comp)
|
436
|
+
self.data.RemoveItem(index)
|
437
|
+
|
438
|
+
def add_new_geometry_model(self, file_name: str, model_name: str = None, return_resource=False):
|
439
|
+
"""
|
440
|
+
Create and add a new geometry model
|
441
|
+
:param file_name: name of the created .simgeo file
|
442
|
+
:param model_name: name of the geometry model
|
443
|
+
:param return_resource: return the resource
|
444
|
+
:return: GeometryViewer.Model.GeometryModel, geo_resource
|
445
|
+
"""
|
446
|
+
geo_resource = self.add_geometry_resource(file_name)
|
447
|
+
file_info = FileInfo(geo_resource.CurrentFullPath)
|
448
|
+
try:
|
449
|
+
model = SimGeoIO.Load(file_info, self.inst, self.serv)
|
450
|
+
self.models_dict[geo_resource.Key] = model
|
451
|
+
self.serv.AddGeometryModel(model)
|
452
|
+
except ArgumentOutOfRangeException as e:
|
453
|
+
logger.warning(f'Error while loading Model: {model} from {model.File}: {e}. Trying reload...')
|
454
|
+
model = SimGeoIO.Load(file_info, self.inst, self.serv)
|
455
|
+
self.models_dict[geo_resource.Key] = model
|
456
|
+
self.serv.AddGeometryModel(model)
|
457
|
+
|
458
|
+
if model_name is not None:
|
459
|
+
model.Name = model_name
|
460
|
+
|
461
|
+
if return_resource:
|
462
|
+
return model, geo_resource
|
463
|
+
else:
|
464
|
+
return model
|
465
|
+
|
466
|
+
def add_geometry_resource(self, model_name: str):
|
467
|
+
"""
|
468
|
+
Add / create new geometry resource (.simgeo file)
|
469
|
+
:param model_name: name of the new .simgeo file without file extension; Example: 'new_model'
|
470
|
+
"""
|
471
|
+
self.service_provider.GetService[IGeometryViewerService]()
|
472
|
+
new_resource = self.project.AddEmptyGeometryResource(self.project.ProjectUnpackFolder,
|
473
|
+
model_name,
|
474
|
+
self.service_provider)
|
475
|
+
|
476
|
+
return new_resource
|
477
|
+
|
478
|
+
def add_empty_resource(self, filename: str):
|
479
|
+
"""
|
480
|
+
Add an empty resource to the project
|
481
|
+
:param file_name: name of the new resource
|
482
|
+
:return:
|
483
|
+
"""
|
484
|
+
# return self.project.AddResourceFile(FileInfo(str(filename)))
|
485
|
+
|
486
|
+
return self.project.AddEmptyResource(FileInfo(str(filename)))
|
487
|
+
|
488
|
+
def add_resource(self,
|
489
|
+
filename: Union[str, FileInfo],
|
490
|
+
tag: Union[SimTaxonomyEntry, SimTaxonomyEntryReference] = None) -> ResourceEntry:
|
491
|
+
"""
|
492
|
+
Add a new resource to the project. The resource will be copied to the project folder and added to the project
|
493
|
+
:param filename: path to the file or FileInfo object
|
494
|
+
:param tag: tag to add to the resource
|
495
|
+
:return:
|
496
|
+
"""
|
497
|
+
|
498
|
+
del_copy = False
|
499
|
+
|
500
|
+
existing_files = [x.Name for x in self.project_data_manager.AssetManager.Resources]
|
501
|
+
try:
|
502
|
+
act_filename = filename.replace('\\', os.sep)
|
503
|
+
except TypeError:
|
504
|
+
act_filename = filename
|
505
|
+
|
506
|
+
if os.path.basename(act_filename) in existing_files:
|
507
|
+
# create copy with running counter in temp dir and use this file:
|
508
|
+
counter = 1
|
509
|
+
while True:
|
510
|
+
new_filename = os.path.basename(filename) + f'({str(counter)})'
|
511
|
+
if new_filename not in existing_files and not os.path.exists(new_filename):
|
512
|
+
break
|
513
|
+
counter += 1
|
514
|
+
shutil.copy(filename, os.path.join(os.path.dirname(filename), new_filename))
|
515
|
+
filename = os.path.join(os.path.dirname(filename), new_filename)
|
516
|
+
del_copy = True
|
517
|
+
|
518
|
+
if isinstance(filename, (str, PosixPath, WindowsPath)):
|
519
|
+
filename = FileInfo(str(filename))
|
520
|
+
|
521
|
+
resource = self.project.CopyResourceAsContainedFileEntry(filename,
|
522
|
+
self.project.ProjectUnpackFolder,
|
523
|
+
'1')
|
524
|
+
|
525
|
+
if del_copy:
|
526
|
+
os.remove(str(filename))
|
527
|
+
|
528
|
+
# file_id = self.project_data_manager.AssetManager.AddResourceEntry(FileInfo(filename))
|
529
|
+
# return self.project_data_manager.AssetManager.Resources[file_id]
|
530
|
+
if tag is not None:
|
531
|
+
add_tag_to_resource(resource, tag)
|
532
|
+
|
533
|
+
return resource
|
534
|
+
|
535
|
+
def delete_resource(self, resource: Union[ResourceEntry, FileInfo, ContainedResourceFileEntry]):
|
536
|
+
"""
|
537
|
+
Delete a resource from the project and the project folder
|
538
|
+
:param resource: resource to delete
|
539
|
+
:return:
|
540
|
+
"""
|
541
|
+
|
542
|
+
if isinstance(resource, FileInfo):
|
543
|
+
resource = resource.resource_entry
|
544
|
+
|
545
|
+
success = self.project.DeleteResource(resource)
|
546
|
+
if success:
|
547
|
+
logger.info(f'Deleted resource {resource.Name} from project {self.project_path}')
|
548
|
+
else:
|
549
|
+
logger.error(f'Could not delete resource {resource.Name} from project {self.project_path}')
|
550
|
+
return success
|
551
|
+
|
552
|
+
def add_table(self, table: SimMultiValueBigTable):
|
553
|
+
self.project_data_manager.ValueManager.Add(table)
|
554
|
+
|
555
|
+
def find_components_with_taxonomy(self, taxonomy: str, component_list=None, first=False):
|
556
|
+
|
557
|
+
if component_list is None:
|
558
|
+
component_list = self.data.Items
|
559
|
+
|
560
|
+
return find_components_with_taxonomy(component_list, taxonomy, first)
|
561
|
+
|
562
|
+
def get_associated_geometry(self, component: Union[SimComponent, SimultanObject]) -> list[Tuple[Union[Layer, Vertex, Edge, PEdge, Face, Volume, EdgeLoop], NetGeometryModel]]:
|
563
|
+
|
564
|
+
ref_geometries = []
|
565
|
+
|
566
|
+
if isinstance(component, SimultanObject):
|
567
|
+
component = component._wrapped_obj
|
568
|
+
|
569
|
+
if not component.Instances:
|
570
|
+
return []
|
571
|
+
|
572
|
+
for instance in component.Instances:
|
573
|
+
for placement in instance.Placements.Items:
|
574
|
+
geo_model = next((x for x in self.models.values() if x is not None and x.File.Key == placement.FileId), None)
|
575
|
+
if geo_model is not None:
|
576
|
+
ref_geometries.append((geo_model.Geometry.GeometryFromId(placement.GeometryId), geo_model))
|
577
|
+
|
578
|
+
return ref_geometries
|
579
|
+
|
580
|
+
def get_referenced_components(self, geometry):
|
581
|
+
return list(self.exch.GetComponents(geometry))
|
582
|
+
|
583
|
+
# if geometry_model is None:
|
584
|
+
# geos = {}
|
585
|
+
# for geometry_model in self.models:
|
586
|
+
# geo = get_component_geometry(self, geometry_model, component)
|
587
|
+
# geos[geometry_model] = geo
|
588
|
+
# return geos
|
589
|
+
# else:
|
590
|
+
# return get_component_geometry(self, geometry_model, component)
|
591
|
+
|
592
|
+
def create_taxonomy(self, name: str, key: str, description: str = ''):
|
593
|
+
"""
|
594
|
+
Create a new taxonomy and add it to the project
|
595
|
+
:param name:
|
596
|
+
:param key:
|
597
|
+
:param description:
|
598
|
+
:return:
|
599
|
+
"""
|
600
|
+
return create_taxonomy(name, key, description, data_model=self)
|
601
|
+
|
602
|
+
def get_taxonomy_entry(self, key):
|
603
|
+
for entry in self.taxonomies:
|
604
|
+
if entry.Key == key:
|
605
|
+
return entry
|
606
|
+
|
607
|
+
def create_mongo_instance(self):
|
608
|
+
from .mongo_utils.base_classes import DataModel as MongoDataModel
|
609
|
+
from .redis_utils.base_classes import save_in_redis
|
610
|
+
|
611
|
+
logger.info(f'Creating mongo instance for project {self.project_data_manager.Project.Name}')
|
612
|
+
self._mongo_instance, created = MongoDataModel.get_or_create(self)
|
613
|
+
if created:
|
614
|
+
logger.info(f'Created new mongo instance for {self.project_data_manager.Project.Name}')
|
615
|
+
else:
|
616
|
+
logger.info(f'Found existing mongo instance for {self.project_data_manager.Project.Name}')
|
617
|
+
|
618
|
+
def save_in_mongodb(self, db):
|
619
|
+
"""
|
620
|
+
save the object in the mongodb database
|
621
|
+
:param db: mongodb database
|
622
|
+
:return: None
|
623
|
+
"""
|
624
|
+
self._mongo_instance.save(db)
|
625
|
+
|
626
|
+
def save_in_redis(self):
|
627
|
+
"""
|
628
|
+
save the object in the redis database
|
629
|
+
:return: None
|
630
|
+
"""
|
631
|
+
save_in_redis(self)
|
632
|
+
|
633
|
+
def get_taxonomy_entries(self):
|
634
|
+
|
635
|
+
def add_sub_entries(tax_entry, tax_entries_dict):
|
636
|
+
for sub_entry in tax_entry.Children:
|
637
|
+
tax_entries_dict[sub_entry.Key] = sub_entry
|
638
|
+
tax_entries_dict = add_sub_entries(sub_entry, taxonomy_entries)
|
639
|
+
return tax_entries_dict
|
640
|
+
|
641
|
+
taxonomy_entries = {}
|
642
|
+
for taxonomy in self.taxonomies:
|
643
|
+
taxonomy_entries[taxonomy.Key] = taxonomy
|
644
|
+
for entry in list(taxonomy.Entries):
|
645
|
+
taxonomy_entries[entry.Key] = entry
|
646
|
+
for child in entry.Children:
|
647
|
+
taxonomy_entries[child.Key] = child
|
648
|
+
taxonomy_entries = add_sub_entries(child, taxonomy_entries)
|
649
|
+
|
650
|
+
return taxonomy_entries
|
651
|
+
|
652
|
+
def create_new_geometry_model(self,
|
653
|
+
name: str) -> Tuple[NetGeometryModel, ResourceFileEntry]:
|
654
|
+
resource_file = self.project.AddEmptyGeometryResource(self._project.ProjectUnpackFolder,
|
655
|
+
name,
|
656
|
+
f'{0} ({1})',
|
657
|
+
self.project.AllProjectDataManagers.DispatcherTimerFactory)
|
658
|
+
# Load the geometry model
|
659
|
+
model_to_work_with = SimGeoIO.Load(resource_file,
|
660
|
+
self.project_data_manager,
|
661
|
+
None)
|
662
|
+
return model_to_work_with, resource_file
|
663
|
+
|
664
|
+
@lru_cache(maxsize=None)
|
665
|
+
def get_or_create_taxonomy(self, taxonomy_key: str, taxonomy_name: str = None, description='', create=True):
|
666
|
+
taxonomy = next((x for x in self.taxonomies if x.Key == taxonomy_key), None)
|
667
|
+
if taxonomy is None:
|
668
|
+
if create:
|
669
|
+
self.create_taxonomy(key=taxonomy_key, name=taxonomy_name, description=description)
|
670
|
+
else:
|
671
|
+
raise ValueError(f'Taxonomy {taxonomy_key} not found in project {self.project_path}')
|
672
|
+
|
673
|
+
return next((x for x in self.taxonomies if x.Key == taxonomy_key), None)
|
674
|
+
|
675
|
+
@lru_cache(maxsize=None)
|
676
|
+
def get_or_create_taxonomy_entry(self,
|
677
|
+
name: str,
|
678
|
+
key: str,
|
679
|
+
description: str = '',
|
680
|
+
sim_taxonomy: SimTaxonomy = None) -> SimTaxonomyEntry:
|
681
|
+
return get_or_create_taxonomy_entry(name, key, description, sim_taxonomy, data_model=self, create=True)
|
682
|
+
|
683
|
+
def __del__(self):
|
684
|
+
self.cleanup()
|
685
|
+
|
686
|
+
|
687
|
+
# if __name__ == '__main__':
|
688
|
+
#
|
689
|
+
# # create example templates
|
690
|
+
# templates = create_example_template_bim_bestand_network()
|
691
|
+
#
|
692
|
+
# # write the example templates to a file:
|
693
|
+
# with open('example_templates.yml', mode='w') as f_obj:
|
694
|
+
# yaml.dump(templates, f_obj)
|
695
|
+
#
|
696
|
+
# # load the example templates:
|
697
|
+
# templates = load_templates('example_templates.yml')
|
698
|
+
#
|
699
|
+
# # create classes from the templates:
|
700
|
+
# template_classes = create_template_classes(templates)
|
701
|
+
#
|
702
|
+
# simultan_components = create_example_simultan_components(templates, n=5)
|
703
|
+
#
|
704
|
+
# simultan_components = class_type_simultan_components(simultan_components, template_classes)
|
705
|
+
#
|
706
|
+
# # the simultan components are now of the type which is defined in the templates
|
707
|
+
# print(simultan_components)
|
708
|
+
#
|
709
|
+
# # the class typed components still keep all methods and attributes from simultan:
|
710
|
+
# print(simultan_components[0].simultan_method())
|
711
|
+
#
|
712
|
+
# # and the class typed components have the new defined method python_spec_func:
|
713
|
+
# simultan_components[10].python_spec_func()
|