/// <summary> /// Returns the specific creator of the material using the data contained in the passed parameters /// </summary> /// <param name="parameters">Material parameters</param> /// <returns>A specific instance of the material creator</returns> public static MaterialCreator GetMaterialCreatorByParams(MaterialParams parameters) { MaterialCreator creator = null; var type = parameters.TypeName; // TODO: Hide the implementation of selecting a specific creator, so that the registration of a specific type occurs somewhere in a separate place if (type == "isotropic") { creator = new IsoMaterialCreator(parameters); } else if (type == "orthotropic") { creator = new OrthoMaterialCreator(parameters); } else if (type == "anisotropic") { creator = new AnisoMaterialCreator(parameters); } else { throw new ArgumentOutOfRangeException("Unknown type of material"); } // TODO: Insert new type of materials return(creator); }
/// <summary> /// Build a set of specific materials by their IDs /// </summary> /// <param name="ids">Set of material IDs</param> /// <returns>Set of materials</returns> public MaterialSet BuildMaterials(IntSet ids) { var materials = new MaterialSet(); if (!IsValid()) { return(materials); } List <MaterialCreator> creators = new List <MaterialCreator>(); MaterialParams parameters; foreach (int id in ids) { var card = db.fillCard("Material", id); if (card != null && card[0] is string) { parameters.ID = id; parameters.TypeName = MaterialCreator.GetMaterialTypeNameBySubtype((string)card[0]); parameters.SubtypeName = (string)card[0]; parameters.Data = card; var creator = MaterialCreator.GetMaterialCreatorByParams(parameters); creators.Add(creator); } } foreach (var creator in creators) { var material = creator.BuildMaterial(); materials.Add(material); } return(materials); }