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); } }