ansys-pyensight-core 0.11.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. ansys/pyensight/core/__init__.py +41 -0
  2. ansys/pyensight/core/common.py +341 -0
  3. ansys/pyensight/core/deep_pixel_view.html +98 -0
  4. ansys/pyensight/core/dockerlauncher.py +1124 -0
  5. ansys/pyensight/core/dvs.py +872 -0
  6. ansys/pyensight/core/enscontext.py +345 -0
  7. ansys/pyensight/core/enshell_grpc.py +641 -0
  8. ansys/pyensight/core/ensight_grpc.py +874 -0
  9. ansys/pyensight/core/ensobj.py +515 -0
  10. ansys/pyensight/core/launch_ensight.py +296 -0
  11. ansys/pyensight/core/launcher.py +388 -0
  12. ansys/pyensight/core/libuserd.py +2110 -0
  13. ansys/pyensight/core/listobj.py +280 -0
  14. ansys/pyensight/core/locallauncher.py +579 -0
  15. ansys/pyensight/core/py.typed +0 -0
  16. ansys/pyensight/core/renderable.py +880 -0
  17. ansys/pyensight/core/session.py +1923 -0
  18. ansys/pyensight/core/sgeo_poll.html +24 -0
  19. ansys/pyensight/core/utils/__init__.py +21 -0
  20. ansys/pyensight/core/utils/adr.py +111 -0
  21. ansys/pyensight/core/utils/dsg_server.py +1220 -0
  22. ansys/pyensight/core/utils/export.py +606 -0
  23. ansys/pyensight/core/utils/omniverse.py +769 -0
  24. ansys/pyensight/core/utils/omniverse_cli.py +614 -0
  25. ansys/pyensight/core/utils/omniverse_dsg_server.py +1196 -0
  26. ansys/pyensight/core/utils/omniverse_glb_server.py +848 -0
  27. ansys/pyensight/core/utils/parts.py +1221 -0
  28. ansys/pyensight/core/utils/query.py +487 -0
  29. ansys/pyensight/core/utils/readers.py +300 -0
  30. ansys/pyensight/core/utils/resources/Materials/000_sky.exr +0 -0
  31. ansys/pyensight/core/utils/support.py +128 -0
  32. ansys/pyensight/core/utils/variables.py +2019 -0
  33. ansys/pyensight/core/utils/views.py +674 -0
  34. ansys_pyensight_core-0.11.0.dist-info/METADATA +309 -0
  35. ansys_pyensight_core-0.11.0.dist-info/RECORD +37 -0
  36. ansys_pyensight_core-0.11.0.dist-info/WHEEL +4 -0
  37. ansys_pyensight_core-0.11.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,280 @@
1
+ # Copyright (C) 2022 - 2026 ANSYS, Inc. and/or its affiliates.
2
+ # SPDX-License-Identifier: MIT
3
+ #
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ """ensobjlist module
24
+
25
+ Emulation of the EnSight ensobjlist class
26
+
27
+ """
28
+ from collections.abc import Iterable
29
+ import fnmatch
30
+ from typing import (
31
+ TYPE_CHECKING,
32
+ Any,
33
+ List,
34
+ Optional,
35
+ SupportsIndex,
36
+ TypeVar,
37
+ no_type_check,
38
+ overload,
39
+ )
40
+
41
+ if TYPE_CHECKING:
42
+ from ansys.pyensight.core import Session
43
+
44
+ from ansys.pyensight.core.ensobj import ENSOBJ
45
+
46
+ T = TypeVar("T")
47
+
48
+
49
+ class ensobjlist(List[T]): # noqa: N801
50
+ """Class used when returning lists of EnSight proxy objects. A subclass of 'list'.
51
+
52
+ In the EnSight object Python bindings, whenever a list is returned that
53
+ is known to exclusively contain ENSOBJ subclass objects, the ensobjlist
54
+ (list subclass) is returned instead. This class simply adds a few
55
+ ENSOBJ specific methods and some functionality to the list object.
56
+
57
+ One additional feature of the ensobjlist is that the __getitem__()
58
+ interface supports strings and lists of strings. In that situation,
59
+ the object acts as if the find() method is called.
60
+
61
+ These are equivalent
62
+
63
+ >>> a = objlist["Hello"]
64
+ >>> a = objlist.find("Hello", attr="DESCRIPTION")
65
+
66
+ These are as well
67
+
68
+ >>> a = objlist[("Hello", "Goodbye")]
69
+ >>> a = objlist.find(("Hello", "Goodbye"), attr="DESCRIPTION")
70
+
71
+ Parameters
72
+ ----------
73
+ args :
74
+ Superclass (list) arguments
75
+ kwargs :
76
+ Superclass (list) keyword arguments
77
+
78
+
79
+ """
80
+
81
+ def __init__(self, *args, session: Optional["Session"] = None, **kwargs) -> None:
82
+ super().__init__(*args, **kwargs)
83
+ self._session = session
84
+
85
+ @staticmethod
86
+ def _is_iterable(arg: Any) -> bool:
87
+ """Check if the arg is iterable, but not a string.
88
+
89
+ Parameters
90
+ ----------
91
+ arg: Any
92
+ Argument to check.
93
+
94
+ """
95
+ return isinstance(arg, Iterable) and not isinstance(arg, str)
96
+
97
+ def find(
98
+ self, value: Any, attr: Any = "DESCRIPTION", group: int = 0, wildcard: int = 0
99
+ ) -> "ensobjlist[T]":
100
+ """Find objects in the list using the ENSOBJ interface.
101
+
102
+ This method will scan the ENSOBJ subclass objects in the list and return
103
+ an ensobjlist of those matching the search criteria.
104
+
105
+ Parameters
106
+ ----------
107
+ value: Any
108
+ A single object or a tuple of objects that will be compared to the value of
109
+ an attribute accessed via the getattr() ENSOBJ interface.
110
+ attr: Any
111
+ The specific attribute (id or string) to look up using getattr().
112
+ group: int
113
+ Currently unimplemented.
114
+ wildcard: int
115
+ Instead of the comparison being done via the equals test, it will be done using
116
+ fnmatch between the string representation of the item and the value. This allows
117
+ values to be specified using glob wildcard specifications. If wildcard is set
118
+ to 1, this is a case-sensitive wildcard operation. If set to 2, the comparison
119
+ is case-insensitive. The default is not to use wildcard comparisons (0).
120
+
121
+ Returns
122
+ -------
123
+ ensobjlist[T]
124
+ An ensobjlist of the items that matched the search criteria.
125
+
126
+ """
127
+ value_list = value
128
+ if not self._is_iterable(value):
129
+ value_list = [value]
130
+ out_list: ensobjlist[Any] = ensobjlist(session=self._session)
131
+ for item in self:
132
+ if isinstance(item, ENSOBJ): # pragma: no cover
133
+ try:
134
+ item_value = item.getattr(attr)
135
+ for check_value in value_list:
136
+ if wildcard == 2:
137
+ if fnmatch.fnmatch(
138
+ str(item_value), str(check_value)
139
+ ): # pragma: no cover
140
+ out_list.append(item)
141
+ break
142
+ elif wildcard > 0:
143
+ if fnmatch.fnmatchcase(str(item_value), str(check_value)):
144
+ out_list.append(item)
145
+ break
146
+ else:
147
+ if item_value == check_value:
148
+ out_list.append(item)
149
+ break
150
+ except RuntimeError: # pragma: no cover
151
+ pass # pragma: no cover
152
+ if group:
153
+ # This is a bit of a hack, but the find() method generates a local list of
154
+ # proxy objects. We want to put that in a group. We do that by running
155
+ # a script in EnSight that creates an empty group and then adds those
156
+ # children to the group. The output becomes the remote referenced ENS_GROUP.
157
+ if self._session is not None: # pragma: no cover
158
+ ens_group_cmd = "ensight.objs.core.VPORTS.find('__unknown__', group=1)"
159
+ ens_group = self._session.cmd(ens_group_cmd)
160
+ ens_group.addchild(out_list)
161
+ out_list = ens_group
162
+ return out_list
163
+
164
+ def set_attr(self, attr: Any, value: Any) -> int:
165
+ """Set an attribute value on all contained objects
166
+
167
+ Walk the items in this object. If they are ENSOBJ subclasses, attempt to set
168
+ the specified attribute id to the specified value. Count the number of times
169
+ that operation was successful and return that number.
170
+
171
+ Parameters
172
+ ----------
173
+ attr: Any
174
+ The specific attribute (id or string) to change using setattr().
175
+ value: Any
176
+ The value to attempt to set the specified attribute to.
177
+
178
+ Returns
179
+ -------
180
+ int
181
+ The number of successful set operations.
182
+
183
+ Examples
184
+ --------
185
+ >>> session.ensight.objs.core.PARTS.set_attr("VISIBLE", True)
186
+
187
+ """
188
+ session = None
189
+ objid_list = [x.__OBJID__ for x in self if isinstance(x, ENSOBJ)]
190
+ for item in self: # pragma: no cover
191
+ if hasattr(item, "_session"): # pragma: no cover
192
+ session = item._session
193
+ break
194
+ if session: # pragma: no cover
195
+ msg = f"ensight.objs.ensobjlist(ensight.objs.wrap_id(x) for x in {objid_list}).set_attr({attr.__repr__()}, {value.__repr__()})"
196
+ return session.cmd(msg)
197
+ return 0 # pragma: no cover
198
+
199
+ def get_attr(self, attr: Any, default: Optional[Any] = None):
200
+ """Query a specific attribute for all ENSOBJ objects in the list
201
+
202
+ Walk the items in this object. If they are ENSOBJ subclasses, query the value of
203
+ the passed attribute id. If the item is not an ENSOBJ subclass or the attribute
204
+ query fails, the returned list will have the specified default value for that item.
205
+
206
+ Parameters
207
+ ----------
208
+ attr: Any
209
+ The specific attribute (id or string) to look up using getattr().
210
+ default: Any, optional
211
+ The value to return for objects that are not ENSOBJ subclasses or do not
212
+ support the specified attribute.
213
+
214
+ Returns
215
+ -------
216
+ List
217
+ A list of the attribute values for each item in this object
218
+
219
+ Examples
220
+ --------
221
+ >>> state = session.ensight.core.PARTS.get_attr(session.ensight.objs.enums.VISIBLE)
222
+
223
+ """
224
+ session = None
225
+ objid_list = [x.__OBJID__ for x in self if isinstance(x, ENSOBJ)]
226
+ for item in self: # pragma: no cover
227
+ if hasattr(item, "_session"): # pragma: no cover
228
+ session = item._session
229
+ break
230
+ value = None
231
+ if session: # pragma: no cover
232
+ if default: # pragma: no cover
233
+ msg = f"ensight.objs.ensobjlist(ensight.objs.wrap_id(x) for x in {objid_list}).get_attr({attr.__repr__()}, {default.__repr__()})" # pragma: no cover
234
+ else:
235
+ msg = f"ensight.objs.ensobjlist(ensight.objs.wrap_id(x) for x in {objid_list}).get_attr({attr.__repr__()})"
236
+ value = session.cmd(msg)
237
+ if value: # pragma: no cover
238
+ return value
239
+ return [default] * len(objid_list) # pragma: no cover
240
+
241
+ @overload
242
+ def __getitem__(self, index: SupportsIndex) -> T:
243
+ ...
244
+
245
+ @overload
246
+ def __getitem__(self, index: slice) -> List[T]:
247
+ ...
248
+
249
+ def __getitem__(self, index):
250
+ """Overload the getitem operator to allow for tuple and string DESCRIPTION queries"""
251
+ if isinstance(index, str) or isinstance(index, tuple):
252
+ return self.find(index)
253
+ return super().__getitem__(index)
254
+
255
+ def __str__(self):
256
+ ret_str = ", ".join([str(x) for x in self])
257
+ return f"[{ret_str}]"
258
+
259
+ @no_type_check
260
+ def _repr_pretty_(self, p: "pretty", cycle: bool) -> None:
261
+ """Support the pretty module for better IPython support
262
+
263
+ Parameters
264
+ ----------
265
+ p: "pretty" :
266
+ pretty flag.
267
+ cycle: bool :
268
+ cycle flag.
269
+
270
+ """
271
+ name = self.__class__.__name__
272
+ if cycle:
273
+ p.text(f"{name}(...)")
274
+ else:
275
+ with p.group(len(name) + 2, f"{name}([", "])"):
276
+ for idx, item in enumerate(self):
277
+ if idx:
278
+ p.text(",")
279
+ p.breakable()
280
+ p.pretty(item)