include/G4OCCT/G4OCCTMaterialMap.hh
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: LGPL-2.1-or-later | ||
| 2 | // Copyright (C) 2026 G4OCCT Contributors | ||
| 3 | |||
| 4 | /// @file G4OCCTMaterialMap.hh | ||
| 5 | /// @brief Declaration of G4OCCTMaterialMap. | ||
| 6 | |||
| 7 | #ifndef G4OCCT_G4OCCTMaterialMap_hh | ||
| 8 | #define G4OCCT_G4OCCTMaterialMap_hh | ||
| 9 | |||
| 10 | #include <G4String.hh> | ||
| 11 | |||
| 12 | #include <cstddef> | ||
| 13 | #include <map> | ||
| 14 | |||
| 15 | class G4Material; | ||
| 16 | |||
| 17 | /** | ||
| 18 | * @brief Maps STEP material names to Geant4 G4Material objects. | ||
| 19 | * | ||
| 20 | * Provides a strict, no-fallback lookup table from the material name strings | ||
| 21 | * found in a STEP file (via the XDE material attribute) to the corresponding | ||
| 22 | * Geant4 `G4Material` pointers. The design follows the material-bridging | ||
| 23 | * policy described in docs/material_bridging.md: every name encountered during | ||
| 24 | * STEP import must have a registered entry; unresolved names produce a fatal | ||
| 25 | * `G4Exception`. | ||
| 26 | * | ||
| 27 | * ### Usage | ||
| 28 | * ```cpp | ||
| 29 | * G4OCCTMaterialMap matMap; | ||
| 30 | * matMap.Add("Al 6061-T6", G4NistManager::Instance()->FindOrBuildMaterial("G4_Al")); | ||
| 31 | * matMap.Add("FR4", myFR4Material); | ||
| 32 | * | ||
| 33 | * G4Material* mat = matMap.Resolve("Al 6061-T6"); // returns the G4_Al pointer | ||
| 34 | * G4Material* unknownMat = matMap.Resolve("Unknown"); // throws fatal G4Exception | ||
| 35 | * ``` | ||
| 36 | */ | ||
| 37 | class G4OCCTMaterialMap { | ||
| 38 | public: | ||
| 39 | 47 | G4OCCTMaterialMap() = default; | |
| 40 | |||
| 41 | /** | ||
| 42 | * Register a mapping from a STEP material name to a Geant4 material. | ||
| 43 | * | ||
| 44 | * If @p stepName is already registered the previous entry is silently | ||
| 45 | * overwritten. | ||
| 46 | * | ||
| 47 | * @param stepName STEP material name string (case-sensitive). | ||
| 48 | * @param material Non-null pointer to a Geant4 material. | ||
| 49 | */ | ||
| 50 | void Add(const G4String& stepName, G4Material* material); | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Look up the Geant4 material for a given STEP material name. | ||
| 54 | * | ||
| 55 | * @param stepName STEP material name to resolve. | ||
| 56 | * @return Non-null pointer to the registered G4Material. | ||
| 57 | * @throws G4Exception (severity FatalException) if @p stepName is not | ||
| 58 | * registered. | ||
| 59 | */ | ||
| 60 | G4Material* Resolve(const G4String& stepName) const; | ||
| 61 | |||
| 62 | /** | ||
| 63 | * Return true if @p stepName has been registered. | ||
| 64 | */ | ||
| 65 | bool Contains(const G4String& stepName) const; | ||
| 66 | |||
| 67 | /** | ||
| 68 | * Return the number of registered entries. | ||
| 69 | */ | ||
| 70 | 19 | std::size_t Size() const { return fMap.size(); } | |
| 71 | |||
| 72 | /** | ||
| 73 | * Merge all entries from @p other into this map. | ||
| 74 | * | ||
| 75 | * If a STEP name already exists in this map, the entry from @p other | ||
| 76 | * overwrites it (later files win on conflict). | ||
| 77 | * | ||
| 78 | * @param other Source map whose entries are merged into this one. | ||
| 79 | */ | ||
| 80 | void Merge(const G4OCCTMaterialMap& other); | ||
| 81 | |||
| 82 | private: | ||
| 83 | std::map<G4String, G4Material*> fMap; | ||
| 84 | }; | ||
| 85 | |||
| 86 | #endif // G4OCCT_G4OCCTMaterialMap_hh | ||
| 87 |