2#ifndef VOLUMEBUILDER_HH
3#define VOLUMEBUILDER_HH
31#include <G4Material.hh>
33#include "G4VPhysicalVolume.hh"
34#include "G4UnionSolid.hh"
35#include <G4ThreeVector.hh>
38#include <unordered_map>
45 class VolumeBuilderCore;
47 class VolumeBuilderBase;
160 G4Material *material =
nullptr, G4String name = std::
string());
174 DerivedPtr
SetName(const G4String &name);
197 const
Unit3Vec &offset = {CLHEP::mm, 0, 0, 0},
198 G4RotationMatrix *rotation =
nullptr);
201 const Unit3Vec &offset = {CLHEP::mm, 0, 0, 0},
202 G4RotationMatrix *rotation =
nullptr);
205 const Unit3Vec &offset = {CLHEP::mm, 0, 0, 0},
206 G4RotationMatrix *rotation =
nullptr);
222 bool is_subtraction =
false,
223 bool is_intersection =
false,
224 const Unit3Vec &offset = {CLHEP::mm, 0, 0, 0},
225 G4RotationMatrix *rotation = nullptr
242 DerivedPtr
SetColor(
double r = 0.5,
double g = 0.5,
double b = 0.5,
double alpha = 1.0);
250 DerivedPtr
SetColor(
const G4Colour &color);
258 DerivedPtr
SetAlpha(G4double alpha);
340 DerivedPtr
SetPhysOffset(
const Unit3Vec &offset = {CLHEP::mm, 0, 0, 0});
351 DerivedPtr
StackPhysOffset(
const Unit3Vec &offset = {CLHEP::mm, 0, 0, 0});
387 return {placement_configs_->rotation, placement_configs_->translation};
498 DerivedPtr
ForkAndReset(
const G4String &new_name)
const;
542 std::optional<int> copy_no = std::nullopt
543 ,
const G4String &name_override =
""
544 ,
bool parent_name_was_set =
false
663 return std::static_pointer_cast<U>(base_cloned_ptr);
667 template <
typename T,
typename std::enable_if_t<std::is_base_of_v<IStructureBuilder, T>,
672 DerivedPtr MakeFinalSolid(G4String boolean_name =
"");
677 G4VSolid *GetSolidPtr()
const {
697 void StoreIStructurePtr(
const IStructurePtr &istructure_ptr);
703 bool explicit_copyno_set_ =
false;
704 bool explicit_physical_copy_name_set_ =
false;
705 G4String placement_name_override_ =
"";
707 void SetSolid_impl(G4VSolid *solid);
708 void SetLogicalVolume_impl(G4LogicalVolume *logical_volume);
712 static constexpr bool has_ownership_{
false};
713 static constexpr bool enable_full_lazy_builds{
true};
719 void PropagateTransform();
722 void ApplyAttributes_();
723 G4String GetPlacementBaseName()
const;
725 [[nodiscard]] G4String GetLogicVolName()
const;
728 void ValidateForPVBuild(std::string
const &site = std::string());
729 void ValidateForVolumeBuild(std::string
const &site = std::string());
730 void ValidateForBooleanBuild(std::string
const &site = std::string());
732 void ValidateSolidNotBuilt(
const std::string &operation)
const;
733 void ValidateBooleanNotBuilt(
const std::string &operation)
const;
734 void ValidateLogicalNotBuilt(
const std::string &operation)
const;
735 void ValidatePlacementNotBuilt(
const std::string &operation)
const;
738 static void make_persistent(
const std::shared_ptr<void> &obj);
740 G4ThreeVector ProvisionUnits(
const Unit3Vec &vec)
const;
745 static void NoNameCheck(
const std::string &name,
const std::string &site) {
747 throw std::runtime_error(
"Error in " + site +
" ,"
748 "for builder named: " + name +
"\n"
749 " Must provide a new name");
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.".
A 3D vector that carries its own unit information.
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 StackPhysOffset(const Unit3Vec &offset={CLHEP::mm, 0, 0, 0})
Like SetPhysOffset but stacks with previous transformations in order applied.
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 MakeLogicalVolume(G4Material *material=nullptr, G4String name=std::string())
Basically never needed now.
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 Unit3Vec &offset={CLHEP::mm, 0, 0, 0}, G4RotationMatrix *rotation=nullptr)
Add a boolean operation.
DerivedPtr SetMaterial(G4Material *material)
DerivedPtr SetVisibility(bool x=true)
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 Unit3Vec &offset={CLHEP::mm, 0, 0, 0})
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.
G4double GetEffectiveDefaultUnit() const
Get the builder default unit or global if not set.
DerivedPtr SetDefaultUnit(G4double unit)
Set the per-Builder default unit for all later non-factory offsets.
DerivedPtr AddUnion(const VolumeBuilder &other, const Unit3Vec &offset={CLHEP::mm, 0, 0, 0}, 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 Unit3Vec &offset={CLHEP::mm, 0, 0, 0}, G4RotationMatrix *rotation=nullptr)
Define combination another volume with present one, This does NOT immediately trigger a build on a pa...
DerivedPtr AddSubtraction(const VolumeBuilder &other, const Unit3Vec &offset={CLHEP::mm, 0, 0, 0}, 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