public void StartGenerateSubstructure(Configuration config) { _configuration = config; Grain newGrain = null; if (config.StructureTypeEnume == StructureTypeEnume.DualPhase) { newGrain = GetRandomGrain(); } for (int x = 1; x <= _configuration.Width; x++) { for (int y = 1; y <= _configuration.Height; y++) { var node = _mapController.GetNode(x, y); if (_selectedGrains.Any(k => k.Id == node.Id)) { if (newGrain == null) { node.Type = TypeEnum.OldGrain; _mapController.SetNode(x, y, node); } else { _mapController.SetNode(x, y, new Pix() { Color = newGrain.Color, Id = newGrain.Id, Type = TypeEnum.OldGrain, X = x, Y = y }); } } else if (node.Type == TypeEnum.Inclusion || node.Type == TypeEnum.GrainBorder) { _mapController.SetNode(x, y, node); } else { _mapController.SetNode(x, y, _mapController.GetEmptyNode(x, y)); } } } _mapController.Commit(); _endSimulation = false; _mapController.CopyMap(); if (config.StructureTypeEnume == StructureTypeEnume.DualPhase) { _selectedGrains = new List <Grain>(); _selectedGrains.Add(newGrain); } }
public void Restart() { _mapController = new MapControl(_configuration.Width, _configuration.Height); _mapController.Commit(); _endSimulation = false; _isMapEmpty = true; _selectedGrains.Clear(); }
public void Initialize(Configuration config) { if (_configuration == null || _configuration.Width != config.Width || _configuration.Width != config.Height) { _mapController = new MapControl(config.Width, config.Height); _mapController.Commit(); } else { _mapController.CopyMap(); } _configuration = config; _isMapEmpty = false; _selectedGrains.Clear(); }