コード例 #1
0
 private void OpenHistoryWindow()
 {
     if (Application.Current.MainWindow != this)
     {
         return;
     }
     if (theNeuronArray != null)
     {
         bool history = false;
         foreach (Neuron n in theNeuronArray.Neurons())
         {
             if (n.KeepHistory)
             {
                 history = true;
             }
         }
         if (history)
         {
             NeuronView.OpenHistoryWindow();
         }
     }
 }
コード例 #2
0
        private bool LoadFile(string fileName)
        {
            CloseAllModuleDialogs();
            CloseHistoryWindow();
            CloseNotesWindow();

            theNeuronArrayView.theSelection.selectedRectangles.Clear();
            CloseAllModuleDialogs();

            SuspendEngine();
            try
            {
                // Load the data from the XML to the Brainsim Engine.
                FileStream file = File.Open(fileName, FileMode.Open);

                XmlSerializer reader = new XmlSerializer(typeof(NeuronArray), GetModuleTypes());
                theNeuronArray = (NeuronArray)reader.Deserialize(file);
                file.Close();
            }
            catch (Exception e1)
            {
                if (e1.InnerException != null)
                {
                    MessageBox.Show("File Load failed because:\r\n " + e1.Message + "\r\nAnd:\r\n" + e1.InnerException.Message);
                }
                else
                {
                    MessageBox.Show("File Load failed because:\r\n " + e1.Message);
                }
                return(false);
            }

            for (int i = 0; i < theNeuronArray.arraySize; i++)
            {
                if (theNeuronArray.GetNeuron(i) == null)
                {
                    theNeuronArray.SetNeuron(i, new Neuron(i));
                }
                if (theNeuronArray.GetNeuron(i).CurrentCharge > 0 || theNeuronArray.GetNeuron(i).LastCharge > 0)
                {
                    theNeuronArray.AddToFiringQueue(theNeuronArray.GetNeuron(i).Id);
                }
            }
            //Update all the synapses to ensure that the synapse-from lists are correct
            foreach (Neuron n in theNeuronArray.Neurons())
            {
                if (n.SynapsesFrom != null)
                {
                    n.SynapsesFrom.Clear();
                }
            }
            foreach (Neuron n in theNeuronArray.Neurons())
            {
                if (n.Synapses != null)
                {
                    foreach (Synapse s in n.Synapses)
                    {
                        n.AddSynapse(s.TargetNeuron, s.Weight, theNeuronArray, false);
                        s.N = theNeuronArray.GetNeuron(s.TargetNeuron);
                    }
                }
                if (n.CurrentCharge >= 1 || n.LastCharge >= 1 || n.Model == Neuron.modelType.LIF)
                {
                    theNeuronArray.AddToFiringQueue(n.Id);
                }
            }

            theNeuronArray.CheckSynapseArray();
            theNeuronArrayView.Update();
            setTitleBar();
            Task.Delay(1000).ContinueWith(t => ShowDialogs());
            foreach (ModuleView na in theNeuronArray.modules)
            {
                if (na.TheModule != null)
                {
                    na.TheModule.SetUpAfterLoad();
                }
            }
            if (theNeuronArray.displayParams != null)
            {
                theNeuronArrayView.Dp = theNeuronArray.displayParams;
            }

            NeuronArrayView.SortAreas();


            Update();
            SetShowSynapsesCheckBox(theNeuronArray.ShowSynapses);
            OpenHistoryWindow();
            ResumeEngine();
            return(true);
        }