|
| 1 | +# Copyright (C) 2020 - 2024 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 | +from ansys.dpf.core.custom_container_base import CustomContainerBase |
| 24 | + |
| 25 | + |
| 26 | +class OperatorConnection(CustomContainerBase): |
| 27 | + def __init__(self, container): |
| 28 | + super().__init__(container) |
| 29 | + self._source_operator = None |
| 30 | + self._source_pin_id = None |
| 31 | + self._target_operator = None |
| 32 | + self._target_pin_id = None |
| 33 | + |
| 34 | + @property |
| 35 | + def source_operator(self): |
| 36 | + from ansys.dpf.core.dpf_operator import Operator |
| 37 | + |
| 38 | + if self._source_operator is None: |
| 39 | + self._source_operator = self._container.get_property("source_operator", Operator) |
| 40 | + |
| 41 | + return self._source_operator |
| 42 | + |
| 43 | + @property |
| 44 | + def source_pin_id(self): |
| 45 | + if self._source_pin_id is None: |
| 46 | + self._source_pin_id = self._container.get_property("source_pin_id", int) |
| 47 | + |
| 48 | + return self._source_pin_id |
| 49 | + |
| 50 | + @property |
| 51 | + def target_operator(self): |
| 52 | + from ansys.dpf.core.dpf_operator import Operator |
| 53 | + |
| 54 | + if self._target_operator is None: |
| 55 | + self._target_operator = self._container.get_property("target_operator", Operator) |
| 56 | + |
| 57 | + return self._target_operator |
| 58 | + |
| 59 | + @property |
| 60 | + def target_pin_id(self): |
| 61 | + if self._target_pin_id is None: |
| 62 | + self._target_pin_id = self._container.get_property("target_pin_id", int) |
| 63 | + |
| 64 | + return self._target_pin_id |
| 65 | + |
| 66 | + def __str__(self): |
| 67 | + from ansys.dpf.core.helpers.utils import indent |
| 68 | + |
| 69 | + indents = " " |
| 70 | + return ( |
| 71 | + "OperatorConnection with properties:\n" |
| 72 | + " - source_operator:\n" |
| 73 | + f"{indent(self.source_operator.name, indents)}\n" |
| 74 | + " - source_pin_id:\n" |
| 75 | + f"{indent(self.source_pin_id, indents)}\n" |
| 76 | + " - target_operator:\n" |
| 77 | + f"{indent(self.target_operator.name, indents)}\n" |
| 78 | + " - target_pin_id:\n" |
| 79 | + f"{indent(self.target_pin_id, indents)}" |
| 80 | + ) |
| 81 | + |
| 82 | + |
| 83 | +class OperatorConnectionsCollection: |
| 84 | + def __init__(self, collection): |
| 85 | + self._collection = collection |
| 86 | + |
| 87 | + def __len__(self): |
| 88 | + return len(self._collection) |
| 89 | + |
| 90 | + def __getitem__(self, index): |
| 91 | + return OperatorConnection(self._collection[index]) |
| 92 | + |
| 93 | + def __iter__(self): |
| 94 | + for i in range(len(self)): |
| 95 | + yield self[i] |
| 96 | + |
| 97 | + def __str__(self): |
| 98 | + from ansys.dpf.core.helpers.utils import indent |
| 99 | + |
| 100 | + indents = (" ", " - ") |
| 101 | + return "\n".join([indent(operator_connection, *indents) for operator_connection in self]) |
0 commit comments