Skip to content

Commit 7414859

Browse files
feat: add Operator.id property
feat: add ability to connect operator as input
1 parent 87aacb8 commit 7414859

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/ansys/dpf/core/dpf_operator.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def __init__(self, name=None, config=None, server=None, operator=None):
127127
self._internal_obj = None
128128
self._description = None
129129
self._inputs = None
130+
self._id = None
130131

131132
# step 1: get server
132133
self._server = server_module.get_or_create_server(
@@ -241,7 +242,7 @@ def progress_bar(self) -> bool:
241242
def progress_bar(self, value: bool) -> None:
242243
self._progress_bar = value
243244

244-
def connect(self, pin, inpt, pin_out=0):
245+
def connect(self, pin, inpt, pin_out=0, operator_as_input=False):
245246
"""Connect an input on the operator using a pin number.
246247
247248
Parameters
@@ -275,7 +276,10 @@ def connect(self, pin, inpt, pin_out=0):
275276
if inpt is self:
276277
raise ValueError("Cannot connect to itself.")
277278
elif isinstance(inpt, Operator):
278-
self._api.operator_connect_operator_output(self, pin, inpt, pin_out)
279+
if operator_as_input:
280+
self._api.operator_connect_operator_as_input(self, pin, inpt)
281+
else:
282+
self._api.operator_connect_operator_output(self, pin, inpt, pin_out)
279283
elif isinstance(inpt, Output):
280284
self._api.operator_connect_operator_output(self, pin, inpt._operator, inpt._pin)
281285
elif isinstance(inpt, list):
@@ -657,6 +661,15 @@ def config(self, value):
657661
"""
658662
self._api.operator_set_config(self, value)
659663

664+
@property
665+
def id(self):
666+
if self._id is None:
667+
operator_id_op = Operator("operator_id")
668+
operator_id_op.inputs.operator.connect(self, operator_as_input=True)
669+
self._id = operator_id_op.outputs.id()
670+
671+
return self._id
672+
660673
@property
661674
def inputs(self):
662675
"""Inputs connected to the operator.

src/ansys/dpf/core/inputs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(self, spec, pin, operator, count_ellipsis=-1):
7070
self.name += str(self._count_ellipsis + 1)
7171
self._update_doc_str(docstr, self.name)
7272

73-
def connect(self, inpt):
73+
def connect(self, inpt, operator_as_input=False):
7474
"""Connect any input (entity or operator output) to a specified input pin of this operator.
7575
7676
Parameters
@@ -85,7 +85,7 @@ def connect(self, inpt):
8585
# always convert ranges to lists
8686
if isinstance(inpt, range):
8787
inpt = list(inpt)
88-
elif isinstance(inpt, core.Operator):
88+
elif not operator_as_input and isinstance(inpt, core.Operator):
8989
if hasattr(inpt, "outputs"):
9090
inpt = inpt.outputs
9191
else:
@@ -150,7 +150,7 @@ def connect(self, inpt):
150150
corresponding_pins[0][1]: weakref.ref(inpt)
151151
}
152152
else:
153-
self._operator().connect(self._pin, inpt)
153+
self._operator().connect(self._pin, inpt, operator_as_input=operator_as_input)
154154
self._operator().inputs._connected_inputs[self._pin] = (
155155
weakref.ref(inpt) if hasattr(inpt, "__weakref__") else inpt
156156
)

0 commit comments

Comments
 (0)