示例#1
0
        public void DeleteSelection(bool deleteBoundarySynapses = true)
        {
            MainWindow.theNeuronArray.SetUndoPoint();
            List <int> neuronsToDelete = theSelection.EnumSelectedNeurons();

            foreach (int nID in neuronsToDelete)
            {
                Neuron n = MainWindow.theNeuronArray.GetNeuron(nID);
                if (deleteBoundarySynapses)
                {
                    foreach (Synapse s in n.synapsesFrom)
                    {
                        Neuron source = MainWindow.theNeuronArray.GetNeuron(s.targetNeuron);
                        if (source != null && theSelection.NeuronInSelection(source.id) == 0)
                        {
                            source.DeleteSynapseWithUndo(n.id);
                        }
                    }
                }
                for (int i = 0; i < n.synapses.Count; i++)
                {
                    n.DeleteSynapseWithUndo(n.synapses[i].targetNeuron);
                }
                n.AddUndoInfo();
                n.CurrentCharge = 0;
                n.LastCharge    = 0;
                n.Model         = Neuron.modelType.IF;

                n.Label = "";
                n.Update();
            }
            DeleteModulesInSelection();
            Update();
        }
示例#2
0
        public void MoveOneNeuron(Neuron n, Neuron nNewLocation)
        {
            n.AddUndoInfo();
            nNewLocation.AddUndoInfo();

            //copy the neuron attributes and delete them from the old neuron.
            n.Copy(nNewLocation);
            MainWindow.theNeuronArray.SetCompleteNeuron(nNewLocation);
            if (FiringHistory.NeuronIsInFiringHistory(n.id))
            {
                FiringHistory.RemoveNeuronFromHistoryWindow(n.id);
                FiringHistory.AddNeuronToHistoryWindow(nNewLocation.id);
            }

            //for all the synapses going out this neuron, change to going from new location
            //don't use a foreach here because the body of the loop may delete a list entry
            for (int k = 0; k < n.Synapses.Count; k++)
            {
                Synapse s = n.Synapses[k];
                if (s.targetNeuron != n.id)
                {
                    nNewLocation.AddSynapseWithUndo(s.targetNeuron, s.weight, s.model);
                }
                else
                {
                    nNewLocation.AddSynapseWithUndo(nNewLocation.id, s.weight, s.model);
                }
                n.DeleteSynapseWithUndo(n.synapses[k].targetNeuron);
            }

            //for all the synapses coming into this neuron, change the synapse target to new location
            for (int k = 0; k < n.SynapsesFrom.Count; k++)
            {
                Synapse reverseSynapse = n.SynapsesFrom[k]; //(from synapses are sort-of backward
                if (reverseSynapse.targetNeuron != -1)      //?
                {
                    Neuron sourceNeuron = MainWindow.theNeuronArray.GetNeuron(reverseSynapse.targetNeuron);
                    sourceNeuron.DeleteSynapseWithUndo(n.id);
                    if (sourceNeuron.id != n.id)
                    {
                        sourceNeuron.AddSynapseWithUndo(nNewLocation.id, reverseSynapse.weight, reverseSynapse.model);
                    }
                }
            }

            n.Clear();
        }