public void NewLib(object sender) { string startname = "New Library"; string finalname = ""; for (int i = 1; ; ++i) { bool state = CompLibrary.LibraryWindow_LoadedLibraries.Exists(x => x.name == startname + i.ToString()); if (!state) { finalname = startname + i.ToString(); break; } } CompLibrary newLib = new CompLibrary(finalname, null, false); Reload_UI(); Libraries.ui_elements.ForEach(x => { if (x.pos.parent == Libraries) { x.pos.Y -= 1000000; } }); Libraries.UpdatePos(); Libraries.UpdateSpecific(); UpdatePos(); UI_Component curUIcomp = Libraries.ui_elements[0].ui_elements.Last().cat; RenameBox1.pos = new Pos(Libraries.pos.X, (curUIcomp.absolutpos.Y - this.pos.Y), ORIGIN.DEFAULT, ORIGIN.DEFAULT, this); RenameBox1.size = curUIcomp.size; RenameBox1.value = finalname; RenameBox1.ID_Name = finalname; RenameBox1.GetsUpdated = RenameBox1.GetsDrawn = true; RenameBox1.Set2Typing(); }
public void LibFolded(object sender) { UI_Categorie <UI_Component> curUIlib = sender as UI_Categorie <UI_Component>; CompLibrary curlib = CompLibrary.AllUsedLibraries.Find(x => x.name == curUIlib.cat.ID_Name); curlib.IsFold = curUIlib.IsFold; }
public void ReloadComponentBox(object sender) { ChangedUpdate2True(); CompLibrary.ReloadComponentData(); UI_Handler.InitComponents(); string[] libfiles = (from s in CompLibrary.AllUsedLibraries select s.SaveFile).ToArray(); Sim_INF_DLL.LoadLibrarys(libfiles); //Sim_INF_DLL.GenerateDllCodeAndCompile(); }
public void EditProjectLib(object sender) { UI_Component curUIlib = sender as UI_Component; CompLibrary curlib = CompLibrary.AllUsedLibraries[curUIlib.ID]; UI_Handler.EditProjectLib.ID_Name = curlib.name; UI_Handler.EditProjectLib.GetsUpdated = UI_Handler.EditProjectLib.GetsDrawn = true; UI_Handler.EditProjectLib.pos.pos = App.mo_states.New.Position + new Point(5, 5); UI_Handler.EditProjectLib.UpdatePos(); }
public void AddComp(object sender) { UI_StringButton pressedElement = sender as UI_StringButton; string startname = "New Component"; string finalname = ""; for (int y = 1; ; y++) { bool DoesExist = false; for (int i = 0; i < CompLibrary.LibraryWindow_LoadedLibraries.Count; ++i) { bool state = CompLibrary.LibraryWindow_LoadedLibraries[i].Components.Exists(x => x.name == startname + y.ToString()); if (state) { DoesExist = true; } } if (!DoesExist) { finalname = startname + y.ToString(); break; } } CompLibrary curlib = CompLibrary.LibraryWindow_LoadedLibraries.Find(x => x.name == pressedElement.parent.ID_Name); CompData newComp = new CompData(finalname, "Other", false, false); curlib.AddComponent(newComp); Reload_UI(); Libraries.ui_elements.ForEach(x => { if (x.pos.parent == Libraries) { x.pos.Y -= 1000000; } }); Libraries.UpdatePos(); Libraries.UpdateSpecific(); UpdatePos(); UI_Component curUIcomp; int libindex_UI = Libraries.ui_elements[0].ui_elements.FindIndex(x => x.cat.ID_Name == pressedElement.parent.ID_Name); curUIcomp = Libraries.ui_elements[0].ui_elements[libindex_UI].Components.ui_elements.Last(); RenameBox2.pos = new Pos(Libraries.pos.X, (curUIcomp.absolutpos.Y - this.pos.Y), ORIGIN.DEFAULT, ORIGIN.DEFAULT, this); RenameBox2.size = curUIcomp.size; RenameBox2.value = finalname; RenameBox2.ID_Name = finalname; RenameBox2.GetsUpdated = RenameBox2.GetsDrawn = true; RenameBox2.Set2Typing(); UI_Handler.EditComp.ID_Name = curlib.name + "|" + finalname; }
public override void ChangedUpdate2True() { for (int i = 0; i < CompLibrary.AllUsedLibraries.Count; ++i) { int index = CompLibrary.LibraryWindow_LoadedLibraries.FindIndex(x => x.name == CompLibrary.AllUsedLibraries[i].name); if (index == -1) { CompLibrary newlib = new CompLibrary(null, CompLibrary.AllUsedLibraries[i].SaveFile, false); newlib.LoadFromPath(); } } Reload_UI(); base.ChangedUpdate2True(); }
public void RenameLib_Finish(object sender) { CompLibrary curlib = CompLibrary.LibraryWindow_LoadedLibraries.Find(x => x.name == RenameBox1.ID_Name); if (Libraries.ui_elements[0].ui_elements.Exists(x => x.cat.ID_Name == RenameBox1.value) && curlib.name != RenameBox1.value) { RenameBox1.IsTyping = true; return; } if (RenameBox1.value.Length > 0) { curlib.name = RenameBox1.value; } RenameBox1.GetsUpdated = RenameBox1.GetsDrawn = false; Reload_UI(); }
public static bool LoadLibrarys(params string[] paths) { List <string> missinglibraries = new List <string>(); for (int i = 0; i < paths.Length; ++i) { if (!File.Exists(paths[i])) { missinglibraries.Add(paths[i]); } } if (missinglibraries.Count > 0) { string message = "Following Libraries not found:\n"; for (int i = 0; i < missinglibraries.Count; ++i) { message += missinglibraries[i] + "\n"; } System.Windows.Forms.MessageBox.Show(message, null, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } Sim_Component.Components_Data.Clear(); CompLibrary.AllUsedLibraries.Clear(); for (int i = 0; i < paths.Length; ++i) { //if(File.Exists(paths[i])) //{ CompLibrary newlibrary = new CompLibrary(null, paths[i]); newlibrary.LoadFromPath(); //} //else //{ // System.Windows.Forms.MessageBox.Show("Library not found: \n" + paths[i], null, MessageBoxButtons.OK, MessageBoxIcon.Error); // Sim_Component.Components_Data.Clear(); // CompLibrary.AllUsedLibraries.Clear(); // UI_Handler.InitComponents(); // return -2; //} } UI_Handler.InitComponents(); GenerateDllCodeAndCompile(); return(true); }
public void Add_Library(CompLibrary libs) { UI_Categorie <UI_Component> newlib = new UI_Categorie <UI_Component>(libs.name, UI_Handler.cat_conf); newlib.cat.ID = CompLibrary.AllUsedLibraries.IndexOf(libs); newlib.cat.ID_Name = libs.name; newlib.cat.GotActivatedRight += EditProjectLib; newlib.GotFolded += LibFolded; newlib.Fold(libs.IsFold); for (int i = 0; i < libs.Components.Count; i++) { int ID = i; UI_Component cur_comp = new UI_Component(new Pos(0), new Point(20, 20), libs.Components[i].name, ID, 20, UI_Handler.componentconf); cur_comp.ID_Name = libs.name + "|" + libs.Components[i].name; cur_comp.Sort_Name = libs.Components[i].catagory + "|" + libs.Components[i].name; newlib.AddComponents(cur_comp); } newlib.SetXSize(size.X - bezelsize * 2); Libraries.ui_elements[0].Add_UI_Elements(newlib); }
public void OpenLib(object sender) { CompLibrary.LoadFrom(true); CompLibrary.AllUsedLibraries.RemoveAll(x => x.STATE == CompLibrary.LOAD_FAILED); Reload_UI(); }
public void OpenLib(object sender) { CompLibrary.LoadFrom(false); CompLibrary.LibraryWindow_LoadedLibraries.RemoveAll(x => x.STATE == CompLibrary.LOAD_FAILED); Reload_UI(); }
public static void SaveToPath(string path) { FileStream s = null; try { FileStream stream = new FileStream(path, FileMode.Create); s = stream; List <byte> bytestosave = new List <byte>(); byte[] bytearray2 = new byte[1]; int compcount = 0; int wirecount = 0; byte[] bytearray; stream.Write(BitConverter.GetBytes(Simulator.ProjectSizeX), 0, 4); stream.Write(BitConverter.GetBytes(Simulator.ProjectSizeY), 0, 4); #region Save Library & Comp Table stream.Write(BitConverter.GetBytes(CompLibrary.AllUsedLibraries.Count), 0, 4); string workingPath = SaveFile; int index = 0; for (int i = workingPath.Length - 1; i >= 0; --i) { if (workingPath[i] == '\\') { index = i; break; } } workingPath = workingPath.Remove(index, workingPath.Length - (index)); for (int i = 0; i < CompLibrary.AllUsedLibraries.Count; ++i) { CompLibrary curlib = CompLibrary.AllUsedLibraries[i]; string relPath = Extensions.MakeRelativePath(workingPath, curlib.SaveFile); string librarypath = Directory.GetCurrentDirectory() + "\\LIBRARIES\\"; bool DoesStartWith = curlib.SaveFile.StartsWith(librarypath); if (DoesStartWith) { relPath = curlib.SaveFile.Remove(0, librarypath.Length); relPath = relPath.Insert(0, "-"); } bytearray = relPath.GetBytesFromString(); stream.Write(bytearray, 0, bytearray.Length); } HashSet <int> compdatatypes = new HashSet <int>(); Sim_Component.components.ForEach(x => { if (x != null) { compdatatypes.Add(x.dataID); } }); int[] compdatatypes_array = compdatatypes.ToArray(); stream.Write(BitConverter.GetBytes(Sim_Component.Components_Data.Count), 0, 4); stream.Write(BitConverter.GetBytes(compdatatypes_array.Length), 0, 4); for (int i = 0; i < Sim_Component.Components_Data.Count; ++i) { bytearray = Sim_Component.Components_Data[i].name.GetBytesFromString(); stream.Write(bytearray, 0, bytearray.Length); } for (int i = 0; i < compdatatypes_array.Length; ++i) { stream.Write(BitConverter.GetBytes(compdatatypes_array[i]), 0, 4); } //for (int i = 0; i < Sim_Component.Components_Data.Count; ++i) //{ // int LibraryID = CompLibrary.AllLibraries.IndexOf(Sim_Component.Components_Data[i].library); // stream.Write(BitConverter.GetBytes(LibraryID), 0, 4); //} #endregion #region Save Wires wirecount = Simulator.networks.Count(x => x != null); stream.Write(BitConverter.GetBytes(wirecount), 0, 4); for (int i = 0; i < Simulator.networks.Length; ++i) { if (Simulator.networks[i] != null) { List <Line_Netw> lines = Simulator.networks[i].lines; stream.Write(BitConverter.GetBytes(lines.Count), 0, 4); for (int j = 0; j < lines.Count; ++j) { stream.Write(new byte[1] { (byte)(lines[j].layers) }, 0, 1); stream.Write(BitConverter.GetBytes(lines[j].start.X), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].start.Y), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].end.X), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].end.Y), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].dir.X), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].dir.Y), 0, 4); stream.Write(BitConverter.GetBytes(lines[j].length), 0, 4); } } } #endregion #region Save Components compcount = Sim_Component.components.Count(x => x != null); stream.Write(BitConverter.GetBytes(compcount), 0, 4); for (int i = 0; i < Sim_Component.components.Length; ++i) { if (Sim_Component.components[i] != null) { stream.Write(BitConverter.GetBytes(Sim_Component.components[i].dataID), 0, 4); stream.Write(BitConverter.GetBytes(Sim_Component.components[i].pos.X), 0, 4); stream.Write(BitConverter.GetBytes(Sim_Component.components[i].pos.Y), 0, 4); bytearray2[0] = Sim_Component.components[i].rotation; stream.Write(bytearray2, 0, 1); CompData compdata = Sim_Component.Components_Data[Sim_Component.components[i].dataID]; stream.Write(BitConverter.GetBytes(compdata.valuebox_length), 0, 4); for (int j = 0; j < compdata.valuebox_length; ++j) { stream.Write(BitConverter.GetBytes(Sim_Component.components[i].totalstates[compdata.internalstate_length + compdata.OverlaySeg_length + j]), 0, 4); } } } #endregion stream.Close(); stream.Dispose(); Console.WriteLine("Saving suceeded. Filename: {0}", path); IsUpToDate = true; } catch (Exception exp) { Console.WriteLine("Saving failed: {0}", exp); if (s != null) { s.Close(); } System.Windows.Forms.MessageBox.Show("Saving failed", null, MessageBoxButtons.OK, MessageBoxIcon.Error); } }