G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
G4OCCT_STEPAssembly_impl.cc
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2// Copyright (C) 2026 G4OCCT Contributors
3
10
12
15
16#include <map>
17#include <stdexcept>
18#include <string>
19
20class G4Material;
21
22int G4OCCT_ImportSTEPAssembly(const std::string& path,
23 const std::map<std::string, G4Material*>& materials) {
24 G4OCCTMaterialMap matMap;
25 for (const auto& [stepName, g4mat] : materials) {
26 matMap.Add(stepName, g4mat);
27 }
28
29 G4OCCTAssemblyVolume* assembly = nullptr;
30 try {
31 assembly = G4OCCTAssemblyVolume::FromSTEP(path, matMap);
32 } catch (const std::exception& ex) {
33 throw std::runtime_error("G4OCCT_STEPAssembly: failed to import '" + path + "' (" + ex.what() +
34 ")");
35 }
36
37 // Extract the constituent count before releasing the assembly.
38 // G4OCCTAssemblyVolume::FromSTEP() returns a heap-allocated object owned by
39 // the caller. We only need the count here; the G4 logical volumes that
40 // FromSTEP() registered in the Geant4 volume store remain valid after this.
41 const int nConstituents = static_cast<int>(assembly->GetLogicalVolumes().size());
42 delete assembly;
43 assembly = nullptr;
44 return nConstituents;
45}
Declaration of G4OCCTAssemblyVolume.
Declaration of G4OCCTMaterialMap.
int G4OCCT_ImportSTEPAssembly(const std::string &path, const std::map< std::string, G4Material * > &materials)
Firewall bridge between the DD4hep plugin TU and G4OCCT/OCCT.
Extends Geant4's G4AssemblyVolume with an OCCT XDE label reference.
const std::map< G4String, G4OCCTLogicalVolume * > & GetLogicalVolumes() const
static G4OCCTAssemblyVolume * FromSTEP(const std::string &path, const G4OCCTMaterialMap &materialMap)
Maps STEP material names to Geant4 G4Material objects.
void Add(const G4String &stepName, G4Material *material)