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 VolumeBuilderReference;
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});
386 return {placement_configs_->rotation, placement_configs_->translation};
496 virtual DerivedPtr
ForkAndReset(
const G4String &new_name)
const;
540 std::optional<int> copy_no = std::nullopt
541 ,
const G4String &name_override =
""
542 ,
bool parent_name_was_set =
false
662 return std::static_pointer_cast<U>(base_cloned_ptr);
666 template <
typename T,
typename std::enable_if_t<std::is_base_of_v<IStructureBuilder, T>,
671 DerivedPtr MakeFinalSolid(G4String boolean_name =
"");
676 G4VSolid *GetSolidPtr()
const {
696 void StoreIStructurePtr(
const IStructurePtr &istructure_ptr);
698 void StoreBuilderView(
const BuilderView &builder_view);
702 bool explicit_copyno_set_ =
false;
703 bool explicit_physical_copy_name_set_ =
false;
704 G4String placement_name_override_ =
"";
706 void SetSolid_impl(G4VSolid *solid);
707 void SetLogicalVolume_impl(G4LogicalVolume *logical_volume);
711 static constexpr bool has_ownership_{
false};
712 static constexpr bool enable_full_lazy_builds{
true};
718 void PropagateTransform();
721 void ApplyAttributes_();
722 G4String GetPlacementBaseName()
const;
724 [[nodiscard]] G4String GetLogicVolName()
const;
727 void ValidateForPVBuild(std::string
const &site = std::string());
728 void ValidateForVolumeBuild(std::string
const &site = std::string());
729 void ValidateForBooleanBuild(std::string
const &site = std::string());
731 void ValidateSolidNotBuilt(
const std::string &operation)
const;
732 void ValidateBooleanNotBuilt(
const std::string &operation)
const;
733 void ValidateLogicalNotBuilt(
const std::string &operation)
const;
734 void ValidatePlacementNotBuilt(
const std::string &operation)
const;
737 static void make_persistent(
const std::shared_ptr<void> &obj);
739 G4ThreeVector ProvisionUnits(
const Unit3Vec &vec)
const;
744 static void NoNameCheck(
const std::string &name,
const std::string &site) {
746 throw std::runtime_error(
"Error in " + site +
" ,"
747 "for builder named: " + name +
"\n"
748 " 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.
A polymorphic, type-erased builder referencing any specialized builder.
VolumeBuilder: Common functionality for volume builder classes.
DerivedPtr ReflectZFinalSolid()
Configure final solid to be flipped in z.
BuilderView ToBuilderView() const override
~VolumeBuilder() override
Destructor Normally does not delete volume objects.
DerivedPtr SetName(const G4String &name)
SetName Sets name used for solid and derived product names.
SharedPtr< IStructureBuilder > clone_impl() const override
DerivedPtr StackPhysTransform(const UnitlessG4Transform3D &new_transform)
Like SetPhysTransform but stacks with previous transformations in order applied.
G4VSolid * SolidConstructor(const G4String &name) override=0
polymorphic access to solid construction
DerivedPtr MakePlacement()
Make a placed physical volume.
DerivedPtr AddTo(BuilderViewList &list) const
DerivedPtr MakeSolid()
Make the G4VSolid.
StructureView ToStructureView() const override
DerivedPtr StackPhysOffset(const Unit3Vec &offset={CLHEP::mm, 0, 0, 0})
Like SetPhysOffset but stacks with previous transformations in order applied.
DerivedPtr StackPhysRotation(const G4RotationMatrix &stacked_rot)
Like SetPhysRotation but stacks with previous transformations in order applied.
G4String GetBuilderName() const
friend class VolumeBuilder
DerivedPtr MakeLogicalVolume(G4Material *material=nullptr, G4String name=std::string())
Basically never needed now.
DerivedPtr ReflectZBaseSolid()
Configure base solid to be flipped BEFORE applying booleans.
DerivedPtr CopyVolumeConfigsFrom(const BuilderView &other)
Copies the LogicalVolume configuration (material, VisAttributes, etc.) from another builder.
DerivedPtr CopyPlacementConfigsFrom(const BuilderView &other)
This may help if reusing placement configs for a different shape.
AssemblyPtr CreateAssembly(G4String name)
Assembly of strucures, ie builders and/or other assemblies.
FromG4VSolidPtr CreateFromG4VSolid(G4VSolid *solid)
Constructor to make a builder from an Existing Geant solid.
DerivedPtr ForkForLogicalVolume(const G4String &new_name)
Makes final solid (including booleans) if unbuilt and copies builder with products cleared for furthe...
virtual DerivedPtr ForkAndReset(const G4String &new_name) const
Copy a configured/unbuilt Builder, with a new name.
DerivedPtr ForkForFinalSolid(const G4String &new_name)
Calls MakeSolid() and copies builder with products cleared for further construction.
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 SetColor(double r=0.5, double g=0.5, double b=0.5, double alpha=1.0)
DerivedPtr SetVisibility(bool x=true)
DerivedPtr SetAlpha(G4double alpha)
DerivedPtr SetMaterial(G4Material *material)
DerivedPtr AddBoolean(const BuilderView &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 ForceSolid(bool x=true)
DerivedPtr SetAutoCopyNo(bool set)
Enable (disable for false) auto Physical Volume numbering, on by default.
DerivedPtr SetBooleanName(const G4String &name)
Pre-set base name for logical and physical volumes.
DerivedPtr SetLogicalVolume(G4LogicalVolume *logical_volume)
Directly Provide a Logical Volume Instead of using the builder.
DerivedPtr SetSurfaceCheck(G4bool pSurfChk)
Set the surface check flag for the placement.
DerivedPtr SetMother(const BuilderView &mother)
Set the mother volume with a builder, or G4VPhysicalVolume or G4VLogicalVolume through implicit conve...
DerivedPtr SetPhysOffset(const Unit3Vec &offset={CLHEP::mm, 0, 0, 0})
Set the translation vector for placement.
DerivedPtr SetPhysTransform(const UnitlessG4Transform3D &new_transform)
Set the G4Transform3D for placment The tranformation provided is meant to be UNITLESS unless you SetD...
DerivedPtr SetCopyNo(G4int pCopyNo)
Set the copy number for the placement.
DerivedPtr OverridePlacementName(const G4String &pName)
Set the placement name for the volume.
DerivedPtr SetPhysRotation(const G4RotationMatrix &rot)
Set the rotation matrix for placement.
DerivedPtr SetAutoPlacementNaming(bool set)
Enable auto Physical Volume naming.
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,...
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 AddSubtraction(const BuilderView &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 AddUnion(const BuilderView &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 BuilderView &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< VolumeBuilderReference > BuilderView
Common interface for all volume builder types.
SharedPtr< IStructureBuilder > IStructurePtr
True polymorphic class base view for all structures Mostly for internal use.
std::vector< StructureView > StructureViewList
a user type to hold many structures
G4Transform3D UnitlessG4Transform3D
std::vector< BuilderView > BuilderViewList
a user type to hold many builders