public MainForm() { InitializeComponent(); // Read in data on the materials string materialFileName = Path.Combine(Resources.DataDir, "Materials.xml"); string materialSchema = Path.Combine(Resources.SchemaDir, "Materials.xsd"); MaterialsCollection materials = new MaterialsCollection(materialFileName, materialSchema); for (int i = 0; i < materials.Count; i++) { materialsListBox.Items.Add(materials[i]); } materialsListBox.SelectedIndex = 0; // Read in data on the coolers string coolerFileName = Path.Combine(Resources.DataDir, "Coolers.xml"); string coolerSchema = Path.Combine(Resources.SchemaDir, "Coolers.xsd"); CoolerCollection coolers = new CoolerCollection(coolerFileName, coolerSchema); for (int i = 0; i < coolers.Count; i++) { coolersListBox.Items.Add(coolers[i]); } coolersListBox.SelectedIndex = 0; // Ready to go - enable user to pull the trigger simulateButton.Enabled = true; }
private void initMaterials() { // Get the list of existing materials from our XML data file string materialsDataFile = Path.Combine(dataDir, "Materials.xml"); string materialsSchemaFile = Path.Combine(schemaDir, "Materials.xsd"); MaterialsCollection materials = new MaterialsCollection(materialsDataFile, materialsSchemaFile); // Persist the list in the database ISession session = null; ITransaction transaction = null; try { session = factory.OpenSession(); transaction = session.BeginTransaction(); foreach (Material m in materials) { P_Material p_mat = new P_Material(); p_mat.Name = m.Name; session.Save(p_mat); } transaction.Commit(); } catch { if (transaction != null) { transaction.Rollback(); } throw; } finally { if (session != null) { session.Close(); } } }
/// <summary> /// Read the data files and set up the MATLAB component. /// Would like to do this in a static constructor, but we don't have access to a /// HttpRequest object at that time, so it's not clear how to map the paths. /// </summary> private void init() { HttpRequest request = this.Context.Request; string dataDir = request.MapPath("Data"); string schemaDir = request.MapPath("Schema"); _logger.Debug("Loading SpecificPower.xml"); string specificPowerDataFile = Path.Combine(dataDir, "SpecificPower.xml"); string specificPowerSchemaFile = Path.Combine(schemaDir, "SpecificPower.xsd"); specificPowerData = new SpecificPowerDataManager(specificPowerDataFile, specificPowerSchemaFile); inputPowerCalc = new InputPowerCalculator(specificPowerData.Data); _logger.Debug("Loading Coolers.xml"); string coolerDataFile = Path.Combine(dataDir, "Coolers.xml"); string coolerSchemaFile = Path.Combine(schemaDir, "Coolers.xsd"); coolers = new CoolerCollection(coolerDataFile, coolerSchemaFile); foreach (Cooler c in coolers) { c.InputPowerCalculator = inputPowerCalc; } _logger.DebugFormat("{0} coolers loaded", coolers.Count); _logger.Debug("Loading Materials.xml"); string materialsDataFile = Path.Combine(dataDir, "Materials.xml"); string materialsSchemaFile = Path.Combine(schemaDir, "Materials.xsd"); materials = new MaterialsCollection(materialsDataFile, materialsSchemaFile); _logger.DebugFormat("{0} materials loaded", materials.Count); _logger.Debug("Loading Problems.xml"); string problemsDataFile = Path.Combine(dataDir, "Problems.xml"); string problemsSchemaFile = Path.Combine(schemaDir, "Problems.xsd"); problems = new ProblemCollection(problemsDataFile, problemsSchemaFile); _logger.DebugFormat("{0} problems loaded", problems.Count); _logger.Debug("Loading MathGates.xml"); string mathGateDataFile = Path.Combine(dataDir, "MathGates.xml"); string mathGateSchemaFile = Path.Combine(schemaDir, "MathGates.xsd"); mathGates = new MathGateCollection(mathGateDataFile, mathGateSchemaFile); _logger.DebugFormat("{0} math gates loaded", mathGates.Count); _logger.Debug("Initializing Optimizer"); optimizer = new Optimizer(coolers, materials); _logger.Debug("Initializaing SolutionChecker"); solutionChecker = new SolutionChecker(problems); _logger.Debug("Initializaing SteadyStateSimulator"); sim = new SteadyStateSimulator(); _logger.Debug("Initializing API"); api = new API(); }
public Material[] GetMaterials() { MaterialsCollection materials = findMaterials(); Material[] answer = new Material[materials.Count]; for (int i = 0; i < materials.Count; i++) { answer[i] = (Material)materials[i]; } return(answer); }
public double SimulatePF(double length, double crossSection, string materialName, string coolerName, double powerFactor) { try { CoolerCollection coolers = findCoolers(); Cooler cooler = (Cooler)coolers[coolerName]; MaterialsCollection materials = findMaterials(); Material material = (Material)materials[materialName]; SteadyStateSimulator ssSim = new SteadyStateSimulator(); return(ssSim.simulate(length, crossSection, material, cooler, powerFactor)); } catch (Exception ex) { throw new SoapException(ex.ToString(), new System.Xml.XmlQualifiedName("")); } }
/// <summary> /// Get a list of coolers from the serivce provider /// </summary> /// <returns>The list of coolers</returns> private Material[] findMaterials() { Material[] answer; if (direct) { string materialsFile = Path.Combine(dataDir, "Materials.xml"); string materialsSchema = Path.Combine(schemaDir, "Materials.xsd"); MaterialsCollection materials = new MaterialsCollection(materialsFile, materialsSchema); answer = new Material[materials.Count]; for (int i = 0; i < materials.Count; i++) { answer[i] = (Material)materials[i]; } } else { DesktopClient.CoolIt_Service.Material[] rawMaterials = webService.GetMaterials(); answer = new Material[rawMaterials.Length]; for (int i = 0; i < rawMaterials.Length; i++) { DesktopClient.CoolIt_Service.Material raw = rawMaterials[i]; List <DataPoint> data = new List <DataPoint>(); for (int j = 0; j < raw.MP.Length; j++) { DesktopClient.CoolIt_Service.DataPoint rawPoint = raw.MP[j]; DataPoint point = new DataPoint(rawPoint.temp, rawPoint.data); data.Add(point); } if (raw.IntegratedThermalConductivity == null) { answer[i] = new Material(raw.Name, raw.id, raw.yieldStrength, data, null, raw.price, raw.priceUnit, raw.currencyUnit); } else { List <DataPoint> integratedThermalConductivity = new List <DataPoint>(); for (int j = 0; j < raw.IntegratedThermalConductivity.Length; j++) { DesktopClient.CoolIt_Service.DataPoint rawPoint = raw.IntegratedThermalConductivity[j]; DataPoint point = new DataPoint(rawPoint.temp, rawPoint.data); integratedThermalConductivity.Add(point); } answer[i] = new Material(raw.Name, raw.id, raw.yieldStrength, data, integratedThermalConductivity, raw.price, raw.priceUnit, raw.currencyUnit); } } } return(answer); }
public void Load(MyPositionAndOrientation characterPosition) { if (!_isInitialValueSet) { // only set the position first time opened and cache. CenterPositionX = characterPosition.Position.X; CenterPositionY = characterPosition.Position.Y; CenterPositionZ = characterPosition.Position.Z; AsteroidFillType = AsteroidFillType.ByteFiller; _isInitialValueSet = true; } MaterialsCollection.Clear(); foreach (var material in SpaceEngineersCore.Resources.VoxelMaterialDefinitions) { MaterialsCollection.Add(new MaterialSelectionModel { Value = material.Id.SubtypeName, DisplayName = material.Id.SubtypeName, IsRare = material.IsRare, MinedRatio = material.MinedOreRatio }); } BaseMaterial = MaterialsCollection.FirstOrDefault(m => m.IsRare == false) ?? MaterialsCollection.FirstOrDefault(); // Voxel Map Storage, includes stock and mod asteroids. var vms = SpaceEngineersCore.Resources.VoxelMapStorageDefinitions; var contentPath = ToolboxUpdater.GetApplicationContentPath(); var list = new List <GenerateVoxelDetailModel>(); foreach (var voxelMap in vms) { var fileName = SpaceEngineersCore.GetDataPathOrDefault(voxelMap.StorageFile, Path.Combine(contentPath, voxelMap.StorageFile)); if (!File.Exists(fileName)) { continue; } var voxel = new GenerateVoxelDetailModel { Name = Path.GetFileNameWithoutExtension(voxelMap.StorageFile), SourceFilename = fileName, FileSize = new FileInfo(fileName).Length, Size = MyVoxelMap.LoadVoxelSize(fileName) }; list.Add(voxel); } // Custom voxel files directory. List <string> files = new List <string>(); if (!string.IsNullOrEmpty(GlobalSettings.Default.CustomVoxelPath) && Directory.Exists(GlobalSettings.Default.CustomVoxelPath)) { files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V1FileExtension)); files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V2FileExtension)); } list.AddRange(files.Select(file => new GenerateVoxelDetailModel { Name = Path.GetFileNameWithoutExtension(file), SourceFilename = file, FileSize = new FileInfo(file).Length, Size = MyVoxelMap.LoadVoxelSize(file) })); VoxelFileList = new ObservableCollection <GenerateVoxelDetailModel>(list.OrderBy(s => s.Name)); // Set up a default start. if (VoxelStore.Count == 0) { VoxelCollection.Add(NewDefaultVoxel(1)); } else { foreach (var item in VoxelStore) { var v1 = (AsteroidByteFillProperties)item.Clone(); v1.VoxelFile = VoxelFileList.FirstOrDefault(v => v.Name == v1.VoxelFile.Name); v1.MainMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.MainMaterial.DisplayName); v1.SecondMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.SecondMaterial.DisplayName); v1.ThirdMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.ThirdMaterial.DisplayName); v1.FourthMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.FourthMaterial.DisplayName); v1.FifthMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.FifthMaterial.DisplayName); v1.SixthMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.SixthMaterial.DisplayName); v1.SeventhMaterial = MaterialsCollection.FirstOrDefault(v => v.DisplayName == v1.SeventhMaterial.DisplayName); VoxelCollection.Add(v1); } RenumberCollection(); } for (var i = 0; i < 100; i++) { PercentList.Add(i); } }