#!/usr/bin/python3
# This file was automatically generated from drawio2cbd with the command:
#   /home/red/git/DrawioConvert/__main__.py -F CBD -e LotkeVolterra -vaSrg -E delta=0.1 -t 100 diagram.io

from pyCBD.Core import *
from pyCBD.lib.std import *
from pyCBD.lib.endpoints import SignalCollectorBlock

DELTA_T = 0.1

class LotkeVolterra(CBD):
    def __init__(self, block_name, alpha=(1.5), beta=(0.7), delta=(0.2), gamma=(0.2)):
        CBD.__init__(self, block_name, input_ports=[], output_ports=["rabbits", "foxes"])

        # Create the Blocks
        self.addBlock(ConstantBlock("alpha", value=(alpha)))
        self.addBlock(ConstantBlock("gamma", value=(-gamma)))
        self.addBlock(ConstantBlock("delta", value=(delta)))
        self.addBlock(ProductBlock("ax"))
        self.addBlock(IntegratorBlock("x"))
        self.addBlock(IntegratorBlock("y"))
        self.addBlock(ProductBlock("xy"))
        self.addBlock(ConstantBlock("beta", value=(-beta)))
        self.addBlock(ProductBlock("gy"))
        self.addBlock(AdderBlock("sum1"))
        self.addBlock(ProductBlock("bxy"))
        self.addBlock(ProductBlock("dxy"))
        self.addBlock(AdderBlock("sum2"))
        self.addBlock(ConstantBlock("IC", value=(10)))
        # self.addBlock(SignalCollectorBlock("rabbits"))
        # self.addBlock(SignalCollectorBlock("foxes"))

        # Create the Connections
        self.addConnection("x", "ax", input_port_name='IN2', output_port_name='OUT1')
        self.addConnection("x", "xy", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("y", "xy", input_port_name='IN2', output_port_name='OUT1')
        self.addConnection("y", "gy", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("gamma", "gy", input_port_name='IN2', output_port_name='OUT1')
        self.addConnection("xy", "bxy", input_port_name='IN2', output_port_name='OUT1')
        self.addConnection("xy", "dxy", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("beta", "bxy", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("alpha", "ax", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("ax", "sum1", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("bxy", "sum1", input_port_name='IN2', output_port_name='OUT1')
        self.addConnection("sum1", "x", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("sum1", "rabbits", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("delta", "dxy", input_port_name='IN2', output_port_name='OUT1')
        self.addConnection("dxy", "sum2", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("gy", "sum2", input_port_name='IN2', output_port_name='OUT1')
        self.addConnection("sum2", "y", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("sum2", "foxes", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("IC", "y", input_port_name='IC', output_port_name='OUT1')
        self.addConnection("IC", "x", input_port_name='IC', output_port_name='OUT1')


class SinGen(CBD):
    def __init__(self, block_name):
        CBD.__init__(self, block_name, input_ports=[], output_ports=[])

        # Create the Blocks
        self.addBlock(TimeBlock("time"))
        self.addBlock(GenericBlock("sin", block_operator=("sin")))
        self.addBlock(SignalCollectorBlock("mySin"))

        # Create the Connections
        self.addConnection("time", "sin", input_port_name='IN1', output_port_name='OUT1')
        self.addConnection("sin", "mySin", input_port_name='IN1', output_port_name='OUT1')


