2#ifndef VOLUMEBUILDER_HH
3#define VOLUMEBUILDER_HH
32#include <G4Material.hh>
34#include "G4VPhysicalVolume.hh"
35#include "G4UnionSolid.hh"
36#include <G4ThreeVector.hh>
39#include <unordered_map>
46 class VolumeBuilderCore;
48 class VolumeBuilderBase;
161 const
VBHelpers::G4MaterialPtrOrString &material = {}, G4String name = std::string());
175 DerivedPtr
SetName(
const G4String &name);
199 G4RotationMatrix *rotation =
nullptr);
203 G4RotationMatrix *rotation =
nullptr);
207 G4RotationMatrix *rotation =
nullptr);
223 bool is_subtraction =
false,
224 bool is_intersection =
false,
226 G4RotationMatrix *rotation = nullptr
243 DerivedPtr
SetColor(
double r = 0.5,
double g = 0.5,
double b = 0.5,
double alpha = 1.0);
251 DerivedPtr
SetColor(
const G4Colour &color);
259 DerivedPtr
SetAlpha(G4double alpha);
388 return {placement_configs_->rotation, placement_configs_->translation};
499 DerivedPtr
ForkAndReset(
const G4String &new_name)
const;
543 std::optional<int> copy_no = std::nullopt
544 ,
const G4String &name_override =
""
545 ,
bool parent_name_was_set =
false
664 return std::static_pointer_cast<U>(base_cloned_ptr);
668 template <
typename T,
typename std::enable_if_t<std::is_base_of_v<IStructureBuilder, T>,
673 DerivedPtr MakeFinalSolid(G4String boolean_name =
"");
678 G4VSolid *GetSolidPtr()
const {
698 void StoreIStructurePtr(
const IStructurePtr &istructure_ptr);
704 bool explicit_copyno_set_ =
false;
705 bool explicit_physical_copy_name_set_ =
false;
706 G4String placement_name_override_ =
"";
708 void SetSolid_impl(G4VSolid *solid);
709 void SetLogicalVolume_impl(G4LogicalVolume *logical_volume);
713 static constexpr bool has_ownership_{
false};
714 static constexpr bool enable_full_lazy_builds{
true};
720 void PropagateTransform();
723 void ApplyAttributes_();
724 G4String GetPlacementBaseName()
const;
726 [[nodiscard]] G4String GetLogicVolName()
const;
729 void ValidateForPVBuild(std::string
const &site = std::string());
730 void ValidateForVolumeBuild(std::string
const &site = std::string());
731 void ValidateForBooleanBuild(std::string
const &site = std::string());
733 void ValidateSolidNotBuilt(
const std::string &operation)
const;
734 void ValidateBooleanNotBuilt(
const std::string &operation)
const;
735 void ValidateLogicalNotBuilt(
const std::string &operation)
const;
736 void ValidatePlacementNotBuilt(
const std::string &operation)
const;
739 static void make_persistent(
const std::shared_ptr<void> &obj);
746 static void NoNameCheck(
const std::string &name,
const std::string &site) {
748 throw std::runtime_error(
"Error in " + site +
" ,"
749 "for builder named: " + name +
"\n"
750 " Must provide a new name");
A 3D vector that manages unit policy for parameter passing If constructed with a unit,...
A type-erased (data shared view) view of a builder or assembly, ie a "structure.".
Builder class for simple Box solids.
A solid buider class that just wrap an existing G4VSolid.
Builder class for RZ mult-plane defined solids.
A type-erased (data shared view) view of a builder or assembly, ie a "structure.".
A type-erased (data shared view) view of a builder or assembly, ie a "structure.".
VolumeBuilder: Common functionality for volume builder classes.
~VolumeBuilderBase() override
Destructor Normally does not delete volume objects.
DerivedPtr MakeSolid()
Make the G4VSolid.
SharedPtr< IStructureBuilder > clone_impl() const override
G4VSolid * SolidConstructor(const G4String &name) override=0
polymorphic access to solid construction
DerivedPtr SetName(const G4String &name)
SetName Sets name used for solid and derived product names.
friend class VolumeBuilderBase
DerivedPtr MakeLogicalVolume(const VBHelpers::G4MaterialPtrOrString &material={}, G4String name=std::string())
Basically never needed now.
DerivedPtr AddTo(BuilderViewList &list) const
DerivedPtr MakePlacement()
Make a placed physical volume.
DerivedPtr StackPhysRotation(const G4RotationMatrix &stacked_rot)
Like SetPhysRotation but stacks with previous transformations in order applied.
G4String GetBuilderName() const
DerivedPtr StackPhysOffset(const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm})
Like SetPhysOffset but stacks with previous transformations in order applied.
DerivedPtr StackPhysTransform(const UnitlessG4Transform3D &new_transform)
Like SetPhysTransform but stacks with previous transformations in order applied.
A polymorphic, type-erased "view" of any specialized builder.
DerivedPtr CopyPlacementConfigsFrom(const VolumeBuilder &other)
This may help if reusing placement configs for a different shape.
DerivedPtr CopyVolumeConfigsFrom(const VolumeBuilder &other)
Copies the LogicalVolume configuration (material, VisAttributes, etc.) from another builder.
FromG4VSolid CreateFromG4VSolid(G4VSolid *solid)
Constructor to make a builder from an Existing Geant solid.
Assembly CreateAssembly(G4String name)
Assembly of strucures, ie builders and/or other assemblies.
DerivedPtr ForkForLogicalVolume(const G4String &new_name)
Makes final solid (including booleans) if unbuilt and copies builder with products cleared for furthe...
DerivedPtr ForkForPlacement(std::optional< int > copy_no=std::nullopt, const G4String &name_override="", bool parent_name_was_set=false)
Calls MakeLogicalVolume() and creates a new builder instance with a copy of all placement-related con...
DerivedPtr ForkForFinalSolid(const G4String &new_name)
Calls MakeSolid() and copies builder with products cleared for further construction.
DerivedPtr ForkAndReset(const G4String &new_name) const
Copy a configured/unbuilt Builder, with a new name.
DerivedPtr SetAlpha(G4double alpha)
DerivedPtr ForceSolid(bool x=true)
DerivedPtr SetColor(double r=0.5, double g=0.5, double b=0.5, double alpha=1.0)
DerivedPtr AddBoolean(const VolumeBuilder &other, bool is_subtraction=false, bool is_intersection=false, const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm}, G4RotationMatrix *rotation=nullptr)
Add a boolean operation.
DerivedPtr SetVisibility(bool x=true)
DerivedPtr SetMaterial(const VBHelpers::G4MaterialPtrOrString &material)
DerivedPtr SetMother(const VolumeBuilder &mother)
Set the mother volume with a builder, or G4VPhysicalVolume or G4VLogicalVolume through implicit conve...
DerivedPtr SetSurfaceCheck(G4bool pSurfChk)
Set the surface check flag for the placement.
DerivedPtr SetAutoPlacementNaming(bool set)
Enable auto Physical Volume naming.
DerivedPtr SetBooleanName(const G4String &name)
Pre-set base name for logical and physical volumes.
DerivedPtr SetPhysTransform(const UnitlessG4Transform3D &new_transform)
Set the G4Transform3D for placment.
DerivedPtr SetLogicalVolume(G4LogicalVolume *logical_volume)
Directly Provide a Logical Volume Instead of using the builder.
DerivedPtr SetPhysRotation(const G4RotationMatrix &rot)
Set the rotation matrix for placement.
DerivedPtr SetPhysOffset(const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm})
Set the translation vector for placement.
DerivedPtr OverridePlacementName(const G4String &pName)
Set the placement name for the volume.
DerivedPtr SetCopyNo(G4int pCopyNo)
Set the copy number for the placement.
G4Transform3D GetPhysTransform() const final
A helper to get the Physical Volume transform with units applied This is built from rotation and tran...
DerivedPtr PlaceAndFork()
An alias for MakePlacement and ForkForPlacement Used for one or many unaltered placments in sequence,...
DerivedPtr SetAutoCopyNo(bool set)
Enable (disable for false) auto Physical Volume numbering, on by default.
G4VSolid * GetFinalSolid() final
Gets a complete final built Solid, including configured Boolean operaions if any.
G4LogicalVolume * GetLogicalVolume() final
Gets a built LogicalVolume, builds default if not built yet.
G4VPhysicalVolume * GetPlacement() final
Gets the (last) placed physical volume.
G4VSolid * GetBaseSolid() final
You probably want GetSolid() instead!!! This Gets a built Solid, BUT NOT final Boolean.
DerivedPtr SetDefaultUnit(Length unit)
Set the per-Builder default unit for all later non-factory offsets.
Length GetEffectiveDefaultUnit() const
Get the builder default unit or global if not set.
DerivedPtr AddSubtraction(const VolumeBuilder &other, const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm}, G4RotationMatrix *rotation=nullptr)
Define combination another volume with present one, This does NOT immediately trigger a build on a pa...
DerivedPtr AddIntersection(const VolumeBuilder &other, const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm}, G4RotationMatrix *rotation=nullptr)
Define combination another volume with present one, This does NOT immediately trigger a build on a pa...
DerivedPtr AddUnion(const VolumeBuilder &other, const DLG4::VolumeBuilders::ThreeVecDimensioner &offset={0, 0, 0, VB::Length::mm}, G4RotationMatrix *rotation=nullptr)
Define combination another volume with present one, This does NOT immediately trigger a build on a pa...
SharedPtr< VolumeBuilderCore > VolumeBuilder
SharedPtr< IStructureBuilder > IStructurePtr
True polymorphic class base view for all structures Mostly for internal use.
G4Transform3D UnitlessG4Transform3D
std::vector< VolumeBuilder > BuilderViewList
a user type to hold many builders
std::vector< StructureBuilder > StructureViewList
a user type to hold many structures