DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
VolumeBuilderReference.cc
Go to the documentation of this file.
1
10#include "VolumeBuilderTypes.hh"
11#include "ISolidBuilder.hh"
12#include "VolumeBuilder.hh"
15#include "StructureBuilder.hpp"
16
17namespace DLG4::VolumeBuilders {
18 G4VSolid *VolumeBuilderReference::SolidConstructor(const G4String &name) {
19 if (!this->builder_configs_->istructure_ptr) {
20 throw std::runtime_error(
21 "Error in VolumeBuilderReference::VolumeBuilderReference::SolidConstructor(const G4String &name) \n"
22 "In VolumeBuilderReference::VolumeBuilderReference::SolidConstructor(const G4String &name): No solid configuration to construct on"
23 + this->builder_configs_->name);
24 }
25 return this->builder_configs_->istructure_ptr->SolidConstructor(name);
26 }
27
28
29 VolumeBuilderReference::VolumeBuilderReference(G4VSolid *solid) { // NOLINT(*-explicit-constructor)
30 // disable shared from this so we can use fluent calls... but NO CHAINING!!
32 this->SetSolid_impl(solid);
33 this->SetName(solid->GetName());
35 }
36
37 VolumeBuilderReference::VolumeBuilderReference(G4LogicalVolume *volume) { // NOLINT(*-explicit-constructor)
39 this->SetLogicalVolume_impl(volume);
40 this->SetName(volume->GetName());
42 }
43
44 VolumeBuilderReference::VolumeBuilderReference(G4VPhysicalVolume *volume) {
45 // NOLINT(*-explicit-constructor)
47 if (volume) {
48 // Extract the logical volume from the physical volume
49 G4LogicalVolume *logical = volume->GetLogicalVolume();
50 if (logical) {
51 logicvol_ptr_.LinkToRaw(logical); // error here
52 }
53 // Store the physical volume reference
54 placement_.LinkToRaw(volume);
55 this->SetName(volume->GetName());
56 }
58 }
59
61 // have the erased base clone itself:
62 auto copy = builder_configs_->istructure_ptr->clone_impl();
63 // Then have it create a builderPtr from itself:
64 auto builder_view = copy->ToBuilderView();
65 builder_view->StoreIStructurePtr(copy); // this is the owning copy.
66 builder_view->StoreBuilderView(builder_view);
67
68 //return static_cast<std::shared_ptr<ISolidBuilder>>(builder_view) ; // and return the builder
69 return builder_view; // and return the builder
70 }
71}
72
73//
SharedPtr< IStructureBuilder > clone_impl() const override
G4VSolid * SolidConstructor(const G4String &name) override
polymorphic access to solid construction
DerivedPtr SetName(const G4String &name)
SetName Sets name used for solid and derived product names.
A wrapper for std::shared_ptr that allows and facilitates many implicit(i) type conversions.