private bool SaveFile(string fileName) { SuspendEngine(); foreach (ModuleView na in theNeuronArray.modules) { if (na.TheModule != null) { try { na.TheModule.SetUpBeforeSave(); } catch (Exception e) { MessageBox.Show("SetupBeforeSave failed on module " + na.Label + ". Message: " + e.Message); } } } theNeuronArray.displayParams = theNeuronArrayView.Dp; if (XmlFile.Save(theNeuronArray, fileName)) { currentFileName = fileName; SetCurrentFileNameToProperties(); ResumeEngine(); return(true); } else { ResumeEngine(); return(false); } }
private bool SaveFile(string fileName) { SuspendEngine(); //If the path contains "bin\64\debug" change the path to the actual development location instead //because file in bin..debug can be clobbered on every rebuild. if (fileName.ToLower().Contains("bin\\x64\\debug")) { MessageBoxResult mbResult = System.Windows.MessageBox.Show(this, "Save to source folder instead?", "Save", MessageBoxButton.YesNoCancel, MessageBoxImage.Asterisk, MessageBoxResult.No); if (mbResult == MessageBoxResult.Yes) { fileName = fileName.ToLower().Replace("bin\\x64\\debug\\", ""); } if (mbResult == MessageBoxResult.Cancel) { return(false); } } foreach (ModuleView na in theNeuronArray.modules) { if (na.TheModule != null) { try { na.TheModule.SetUpBeforeSave(); } catch (Exception e) { MessageBox.Show("SetupBeforeSave failed on module " + na.Label + ". Message: " + e.Message); } } } theNeuronArray.displayParams = theNeuronArrayView.Dp; if (XmlFile.Save(theNeuronArray, fileName)) { currentFileName = fileName; SetCurrentFileNameToProperties(); ResumeEngine(); undoCountAtLastSave = theNeuronArray.GetUndoCount(); return(true); } else { ResumeEngine(); return(false); } }
private void SaveClipboardToFile(string fileName) { foreach (ModuleView na in myClipBoard.modules) { if (na.TheModule != null) { na.TheModule.SetUpBeforeSave(); } } if (XmlFile.Save(myClipBoard, fileName)) { currentFileName = fileName; } }
private void SaveFile(string fileName) { SuspendEngine(); foreach (ModuleView na in theNeuronArray.modules) { if (na.TheModule != null) { na.TheModule.SetUpBeforeSave(); } } theNeuronArray.displayParams = theNeuronArrayView.Dp; if (XmlFile.Save(theNeuronArray, fileName)) { currentFileName = fileName; SetCurrentFileNameToProperties(); } ResumeEngine(); }
//copy the selection to a clipboard public void CopyNeurons() { //get list of neurons to copy List <int> neuronsToCopy = theSelection.EnumSelectedNeurons(); theSelection.GetSelectedBoundingRectangle(out int X1o, out int Y1o, out int X2o, out int Y2o); MainWindow.myClipBoard = new NeuronArray(); NeuronArray myClipBoard; myClipBoard = MainWindow.myClipBoard; myClipBoard.Initialize((X2o - X1o + 1) * (Y2o - Y1o + 1), (Y2o - Y1o + 1), true); boundarySynapsesOut.Clear(); boundarySynapsesIn.Clear(); //copy the neurons foreach (int nID in neuronsToCopy) { int destId = GetClipboardId(X1o, Y1o, nID); //copy the source neuron to the clipboard Neuron sourceNeuron = MainWindow.theNeuronArray.GetNeuron(nID); Neuron destNeuron = sourceNeuron.Clone(); destNeuron.Owner = myClipBoard; destNeuron.Id = destId; destNeuron.Label = sourceNeuron.Label; destNeuron.ToolTip = sourceNeuron.ToolTip; destNeuron.ShowSynapses = sourceNeuron.ShowSynapses; myClipBoard.SetNeuron(destId, destNeuron); } //copy the synapses (this is two-pass so we make sure all neurons exist prior to copying foreach (int nID in neuronsToCopy) { Neuron sourceNeuron = MainWindow.theNeuronArray.GetNeuron(nID); if (MainWindow.useServers) { sourceNeuron.synapses = NeuronClient.GetSynapses(sourceNeuron.id); } int destId = GetClipboardId(X1o, Y1o, nID); Neuron destNeuron = myClipBoard.GetNeuron(destId); destNeuron.Owner = myClipBoard; if (sourceNeuron.Synapses != null) { foreach (Synapse s in sourceNeuron.Synapses) { //only copy synapses with both ends in the selection if (neuronsToCopy.Contains(s.TargetNeuron)) { destNeuron.AddSynapse(GetClipboardId(X1o, Y1o, s.TargetNeuron), s.Weight, s.model); } else { string targetName = MainWindow.theNeuronArray.GetNeuron(s.targetNeuron).label; if (targetName != "") { boundarySynapsesOut.Add(new BoundarySynapse { innerNeuronID = destNeuron.id, outerNeuronID = s.targetNeuron, weight = s.weight, model = s.model }); } } } } if (sourceNeuron.SynapsesFrom != null) { foreach (Synapse s in sourceNeuron.SynapsesFrom) { if (!neuronsToCopy.Contains(s.TargetNeuron)) { string sourceName = MainWindow.theNeuronArray.GetNeuron(s.targetNeuron).label; if (sourceName != "") { boundarySynapsesIn.Add(new BoundarySynapse { innerNeuronID = destNeuron.id, outerNeuronID = s.targetNeuron, weight = s.weight, model = s.model });; } } } } } //copy modules foreach (ModuleView mv in MainWindow.theNeuronArray.modules) { if (theSelection.NeuronInSelection(mv.FirstNeuron) > 0 && theSelection.NeuronInSelection(mv.LastNeuron) > 0) { ModuleView newMV = new ModuleView() { FirstNeuron = GetClipboardId(X1o, Y1o, mv.FirstNeuron), TheModule = mv.TheModule, Color = mv.Color, Height = mv.Height, Width = mv.Width, Label = mv.Label, ModuleTypeStr = mv.ModuleTypeStr, }; myClipBoard.modules.Add(newMV); } } XmlFile.Save(myClipBoard, "ClipBoard"); }