Form for genome visualization. This is used for displaying genome's directly (e.g. a neural net structure), or some other type of visualization that uses the genome, e.g. a task view that shows how the genome performs on some task.
Inheritance: Form
    private void cmbExperiments_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Clear any existing references, as these are specific to each experiment.
        _neatExperiment = null;
        _experimentUI   = null;

        // Close the genome form if it is open, as the content of this form is specific to each experiment.
        GenomeForm bestGenomeForm = _bestGenomeForm;

        if (bestGenomeForm is not null)
        {
            // Note. This will trigger the FormClosed event which will do further clean-up; Close() will also Dispose() the form.
            bestGenomeForm.Close();
        }
    }
    private void bestGenomeToolStripMenuItem_Click(object sender, EventArgs e)
    {
        IExperimentUI experimentUI = GetExperimentUI();

        if (experimentUI is null)
        {
            return;
        }

        GenomeControl genomeCtrl = experimentUI.CreateGenomeControl();

        if (experimentUI is null)
        {
            return;
        }

        // Create form.
        _bestGenomeForm = new GenomeForm("Best Genome", genomeCtrl);

        // Attach an event handler to update this main form when the genome form is closed.
        _bestGenomeForm.FormClosed += new FormClosedEventHandler(delegate(object senderObj, FormClosedEventArgs eArgs)
        {
            _bestGenomeForm = null;
            bestGenomeToolStripMenuItem.Enabled = true;
        });

        // Prevent creation of more then one instance of the genome form.
        bestGenomeToolStripMenuItem.Enabled = false;

        // Get the current best genome.
        NeatGenome <double> bestGenome = _neatPop?.BestGenome;

        if (bestGenome is not null)
        {
            // Set the form's current genome. If the EA is running it will be set shortly anyway, but this ensures we
            // see a genome right away, regardless of whether the EA is running or not.
            _bestGenomeForm.Genome = bestGenome;
        }

        // Show the form.
        _bestGenomeForm.Show(this);
    }