forked from pedroCabrera/PyFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New while loop. Convex hull stuff moved to own class, to be inherited…
… by nodes.
- Loading branch information
ilgar
committed
Aug 17, 2019
1 parent
94fc7d9
commit 172569e
Showing
15 changed files
with
376 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
## Copyright 2015-2019 Ilgar Lunin, Pedro Cabrera | ||
|
||
## Licensed under the Apache License, Version 2.0 (the "License"); | ||
## you may not use this file except in compliance with the License. | ||
## You may obtain a copy of the License at | ||
|
||
## http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
## Unless required by applicable law or agreed to in writing, software | ||
## distributed under the License is distributed on an "AS IS" BASIS, | ||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
## See the License for the specific language governing permissions and | ||
## limitations under the License. | ||
|
||
|
||
from PyFlow.Core.Common import * | ||
from PyFlow.Core.PathsRegistry import PathsRegistry | ||
from PyFlow.Core.NodeBase import NodePinsSuggestionsHelper | ||
from PyFlow.Core import NodeBase | ||
from PyFlow.Packages.PyFlowBase.Nodes import FLOW_CONTROL_COLOR | ||
|
||
|
||
class loopEnd(NodeBase): | ||
def __init__(self, name): | ||
super(loopEnd, self).__init__(name) | ||
self.inExec = self.createInputPin(DEFAULT_IN_EXEC_NAME, 'ExecPin', None, self.compute) | ||
self.loopBeginNode = self.createInputPin('Paired block', 'StringPin') | ||
self.loopBeginNode.setInputWidgetVariant("ObjectPathWIdget") | ||
self.completed = self.createOutputPin('Completed', 'ExecPin') | ||
self.headerColor = FLOW_CONTROL_COLOR | ||
|
||
@staticmethod | ||
def pinTypeHints(): | ||
helper = NodePinsSuggestionsHelper() | ||
helper.addInputDataType('ExecPin') | ||
helper.addInputDataType('StringPin') | ||
helper.addInputStruct(PinStructure.Single) | ||
return helper | ||
|
||
@staticmethod | ||
def category(): | ||
return 'FlowControl' | ||
|
||
@staticmethod | ||
def keywords(): | ||
return ['iter', 'end'] | ||
|
||
@staticmethod | ||
def description(): | ||
return 'For loop end block' | ||
|
||
def compute(self, *args, **kwargs): | ||
node = PathsRegistry().getEntity(self.loopBeginNode.getData()) | ||
if node is not None: | ||
if node.graph() == self.graph(): | ||
if node.loopEndNode.getData() != self.path(): | ||
self.setError("Invalid pair") | ||
return | ||
node.onNext() | ||
else: | ||
err = "block ends in different graphs" | ||
node.setError(err) | ||
self.setError(err) | ||
else: | ||
self.setError("Pair {} not found".format(self.loopBeginNode.getData())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
## Copyright 2015-2019 Ilgar Lunin, Pedro Cabrera | ||
|
||
## Licensed under the Apache License, Version 2.0 (the "License"); | ||
## you may not use this file except in compliance with the License. | ||
## You may obtain a copy of the License at | ||
|
||
## http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
## Unless required by applicable law or agreed to in writing, software | ||
## distributed under the License is distributed on an "AS IS" BASIS, | ||
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
## See the License for the specific language governing permissions and | ||
## limitations under the License. | ||
|
||
|
||
from PyFlow.Core import NodeBase | ||
from PyFlow.Core.PathsRegistry import PathsRegistry | ||
from PyFlow.Core.NodeBase import NodePinsSuggestionsHelper | ||
from PyFlow.Core.Common import * | ||
from PyFlow.Packages.PyFlowBase.Nodes import FLOW_CONTROL_COLOR | ||
|
||
|
||
class whileLoopBegin(NodeBase): | ||
def __init__(self, name): | ||
super(whileLoopBegin, self).__init__(name) | ||
self.lastCondition = False | ||
self.inExec = self.createInputPin('inExec', 'ExecPin', None, self.compute) | ||
self.condition = self.createInputPin('Condition', 'BoolPin') | ||
self.loopEndNode = self.createInputPin('Paired block', 'StringPin') | ||
self.loopEndNode.setInputWidgetVariant("ObjectPathWIdget") | ||
|
||
self.loopBody = self.createOutputPin('LoopBody', 'ExecPin') | ||
self.headerColor = FLOW_CONTROL_COLOR | ||
|
||
@staticmethod | ||
def pinTypeHints(): | ||
helper = NodePinsSuggestionsHelper() | ||
helper.addInputDataType('ExecPin') | ||
helper.addInputDataType('BoolPin') | ||
helper.addOutputDataType('ExecPin') | ||
helper.addInputStruct(PinStructure.Single) | ||
helper.addOutputStruct(PinStructure.Single) | ||
return helper | ||
|
||
@staticmethod | ||
def category(): | ||
return 'FlowControl' | ||
|
||
@staticmethod | ||
def keywords(): | ||
return ['iter'] | ||
|
||
@staticmethod | ||
def description(): | ||
return 'While loop begin block' | ||
|
||
def onNext(self, *args, **kwargs): | ||
currentCondition = self.condition.getData() | ||
if currentCondition: | ||
self.loopBody.call(*args, **kwargs) | ||
if self.lastCondition is True and currentCondition is False: | ||
endNodePath = self.loopEndNode.getData() | ||
loopEndNode = PathsRegistry().getEntity(endNodePath) | ||
loopEndNode.completed.call() | ||
self.lastCondition = False | ||
return | ||
self.lastCondition = currentCondition | ||
|
||
def compute(self, *args, **kwargs): | ||
endNodePath = self.loopEndNode.getData() | ||
loopEndNode = PathsRegistry().getEntity(endNodePath) | ||
if loopEndNode is not None: | ||
if loopEndNode.loopBeginNode.getData() != self.path(): | ||
self.setError("Invalid pair") | ||
return | ||
if self.graph() is not loopEndNode.graph(): | ||
err = "block ends in different graphs" | ||
self.setError(err) | ||
loopEndNode.setError(err) | ||
return | ||
else: | ||
self.setError("Pair {} not found".format(endNodePath)) | ||
return | ||
|
||
self.onNext(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.