1#ifndef DLG4_STRUCTUREBUILDER_HPP
2#define DLG4_STRUCTUREBUILDER_HPP
20#define BASE StructureBuilder<U>
21#define DERIVED typename BASE::DerivedPtr
32 BASE::StructureBuilder(
const StructureBuilder &other) :
33 builder_configs_(other.builder_configs_),
34 boolean_configs_(other.boolean_configs_),
35 lv_configs_(other.lv_configs_),
37 other.placement_configs_) {
39 builder_configs_->builder_view =
nullptr;
40 builder_configs_->istructure_ptr =
nullptr;
52 template <
typename T,
typename std::enable_if_t<std::is_base_of_v<IStructureBuilder, T>,
int>>
53 BASE::StructureBuilder(
const SharedPtr<T> &other,
SET_LINK_TYPE)
54 : builder_configs_(other->builder_configs_,
SET_LINK),
55 boolean_configs_(other->boolean_configs_,
SET_LINK),
56 lv_configs_(other->lv_configs_,
SET_LINK),
57 placement_configs_(other->placement_configs_,
SET_LINK),
58 final_solid_ptr_(other->final_solid_ptr_,
SET_LINK),
59 solid_ptr_(other->solid_ptr_,
SET_LINK),
60 logicvol_ptr_(other->logicvol_ptr_,
SET_LINK),
61 placement_(other->placement_,
SET_LINK) {
64 if (other->placement_configs_->is_builder) {
67 builder_view->StoreBuilderView(builder_view);
72 BASE::~StructureBuilder() {
75 if (!has_ownership_ && placement_configs_->is_builder) {
79 placement_.make_persistent();
86 throw std::runtime_error(
"Cannot make placement - structure was already placed");
89 if (!placement_configs_->is_builder) {
91 for (
auto &child : placement_configs_->children) {
92 auto name = this->builder_configs_->builder_view->GetPlacementBaseName();
93 child->placement_configs_->parent_name = name;
95 child->MakePlacement();
99 this->builder_configs_->builder_view->MakePlacement();
101 return this->shared_from_this();
104 template <
typename U>
107 this->MakePlacement();
108 auto clone = this->ForkForPlacement();
112 template <
typename U>
114 SetName(
const G4String &name) {
115 this->builder_configs_->builder_view->SetName(name);
116 return this->shared_from_this();
119 template <
typename U>
121 G4Material *material) {
122 if (!placement_configs_->is_builder) {
124 for (
auto &child : placement_configs_->children) {
125 child->SetMaterial(material);
129 this->builder_configs_->builder_view->SetMaterial(material);
131 return this->shared_from_this();
134 template <
typename U>
135 DERIVED BASE::SetColor(
double r,
double g,
136 double b,
double alpha) {
137 if (!placement_configs_->is_builder) {
139 for (
auto &child : placement_configs_->children) {
140 child->SetColor(r, g, b, alpha);
144 this->builder_configs_->builder_view->SetColor(r, g, b, alpha);
146 return this->shared_from_this();
149 template <
typename U>
151 const G4Colour &color) {
152 if (!placement_configs_->is_builder) {
154 for (
auto &child : placement_configs_->children) {
155 child->SetColor(color);
159 this->builder_configs_->builder_view->SetColor(color);
161 return this->shared_from_this();
164 template <
typename U>
165 DERIVED BASE::SetAlpha(G4double alpha) {
166 if (!placement_configs_->is_builder) {
168 for (
auto &child : placement_configs_->children) {
169 child->SetAlpha(alpha);
173 this->builder_configs_->builder_view->SetAlpha(alpha);
175 return this->shared_from_this();
178 template <
typename U>
179 DERIVED BASE::ForceSolid(
bool x) {
180 if (!placement_configs_->is_builder) {
182 for (
auto &child : placement_configs_->children) {
183 child->ForceSolid(x);
187 this->builder_configs_->builder_view->ForceSolid(x);
189 return this->shared_from_this();
192 template <
typename U>
194 SetVisibility(
bool is_visible) {
195 if (!placement_configs_->is_builder) {
197 for (
auto &child : placement_configs_->children) {
198 child->SetVisibility(is_visible);
202 this->builder_configs_->builder_view->SetVisibility(is_visible);
204 return this->shared_from_this();
207 template <
typename U>
209 const G4RotationMatrix &rot) {
213 this->builder_configs_->builder_view->SetPhysRotation(rot);
214 return this->shared_from_this();
217 template <
typename U>
218 DERIVED BASE::StackPhysRotation(
219 const G4RotationMatrix &stacked_rot) {
220 this->builder_configs_->builder_view->StackPhysRotation(stacked_rot);
221 auto retval = this->shared_from_this();
225 template <
typename U>
227 const Unit3Vec &offset) {
228 this->builder_configs_->builder_view->SetPhysOffset(offset);
229 return this->shared_from_this();
232 template <
typename U>
234 const Unit3Vec &offset) {
235 this->builder_configs_->builder_view->StackPhysOffset(offset);
236 return this->shared_from_this();
239 template <
typename U>
240 DERIVED BASE::SetPhysTransform(
241 const UnitlessG4Transform3D &new_transform) {
242 this->builder_configs_->builder_view->SetPhysTransform(new_transform);
243 return this->shared_from_this();
246 template <
typename U>
247 DERIVED BASE::StackPhysTransform(
248 const UnitlessG4Transform3D &stacked_transform) {
249 this->builder_configs_->builder_view->StackPhysTransform(stacked_transform);
250 return this->shared_from_this();
253 template <
typename U>
254 DERIVED BASE::OverridePlacementName(
255 const G4String &pName) {
256 this->builder_configs_->builder_view->OverridePlacementName(pName);
257 return this->shared_from_this();
260 template <
typename U>
261 DERIVED BASE::SetCopyNo(G4int pCopyNo) {
263 std::cout <<
"fixme" << std::endl;
264 return this->shared_from_this();
267 template <
typename U>
270 if (!placement_configs_->is_builder) {
272 for (
auto &child : placement_configs_->children) {
273 child->SetSurfaceCheck(pSurfChk);
277 this->builder_configs_->builder_view->SetSurfaceCheck(pSurfChk);
279 return this->shared_from_this();
282 template <
typename U>
284 const BuilderView &mother) {
285 if (!placement_configs_->is_builder) {
287 for (
auto &child : placement_configs_->children) {
288 child->SetMother(mother);
292 this->builder_configs_->builder_view->SetMother(mother);
294 return this->shared_from_this();
297 template <
typename U>
298 DERIVED BASE::SetAutoPlacementNaming(
302 this->builder_configs_->builder_view->SetAutoPlacementNaming(set);
303 return this->shared_from_this();
306 template <
typename U>
308 SetAutoCopyNo(
bool set) {
310 if (!placement_configs_->is_builder) {
312 for (
auto &child : placement_configs_->children) {
313 child->SetAutoCopyNo(set);
317 this->builder_configs_->builder_view->SetAutoCopyNo(set);
319 return this->shared_from_this();
323 template <
typename U>
324 DERIVED BASE::ForkForPlacement(
326 std::optional<int> copy_no,
const G4String &name_override) {
328 auto c1 = this->builder_configs_->builder_view->ForkForPlacement();
329 auto c2 = c1->builder_configs_->istructure_ptr;
330 auto copy = i_dynamic_pointer_cast<U>(c2);
331 if (!placement_configs_->is_builder) {
333 copy->placement_configs_->children.clear();
334 for (
auto &child : placement_configs_->children) {
335 auto builderview_clone = child->builder_configs_->builder_view->ForkForPlacement(
336 std::nullopt,
"",
true);
337 auto clone_istructure_view = builderview_clone->builder_configs_->istructure_ptr->
339 copy->placement_configs_->children.emplace_back(clone_istructure_view);
345 template <
typename U>
346 DERIVED BASE::ForkForLogicalVolume(
const G4String &new_name) {
348 auto c1 = this->builder_configs_->builder_view->ForkForLogicalVolume(new_name);
349 auto c2 = c1->builder_configs_->istructure_ptr;
350 auto copy = i_dynamic_pointer_cast<U>(c2);
351 if (!placement_configs_->is_builder) {
353 copy->placement_configs_->children.clear();
354 for (
auto &child : placement_configs_->children) {
355 auto builderview_clone = child->builder_configs_->builder_view->ForkForLogicalVolume(
357 auto clone_istructure_view = builderview_clone->builder_configs_->istructure_ptr->
359 copy->placement_configs_->children.emplace_back(clone_istructure_view);
365 template <
typename U>
366 DERIVED BASE::CopyPlacementConfigsFrom(
367 const BuilderView &other) {
369 this->builder_configs_->builder_view->CopyPlacementConfigsFrom(other);
370 return this->shared_from_this();
373 template <
typename U>
378 this->builder_configs_->builder_view->SetDefaultUnit(unit);
379 return this->shared_from_this();
383 template <
typename U>
384 G4double BASE::GetEffectiveDefaultUnit()
const {
385 return this->builder_configs_->builder_view->GetEffectiveDefaultUnit();
388 template <
typename U>
389 G4String BASE::GetBuilderName()
const {
390 return this->builder_configs_->builder_view->GetBuilderName();
393 template <
typename U>
394 BASE::StructureBuilder() {
395 lv_configs_->vis_att = G4VisAttributes(
true);
396 placement_configs_->is_builder =
false;
400 template <
typename U>
401 void BASE::ValidateForPVBuild(std::string
const &site) {
402 builder_configs_->builder_view->ValidateForPVBuild(site);
405 template <
typename U>
406 void BASE::ValidatePlacementNotBuilt(
407 const std::string &operation)
const {
408 builder_configs_->builder_view->ValidatePlacementNotBuilt(operation);
411 template <
typename U>
413 return builder_configs_->istructure_ptr->ToStructureView();
416 template <
typename U>
420 std::shared_ptr<U> builder_std_ptr =
421 std::const_pointer_cast<U>(this->shared_from_this());
422 auto x = DerivedPtr(builder_std_ptr);
427 template <
typename U>
428 SharedPtr<IStructureBuilder> BASE::clone_impl()
const {
430 const U &derived_ref =
static_cast<const U &
>(*this);
431 auto retval =
new U(derived_ref);
432 auto shared_ptr = i_shared_ptr<U>(retval);
433 BuilderView builder_view = shared_ptr->ToBuilderView();
434 builder_view->SetName(this->GetBuilderName());
436 builder_view->StoreBuilderView(builder_view);
441 template <
typename U>
442 G4String BASE::GetLogicVolName()
const {
443 return this->builder_configs_->builder_view->GetLogicVolName();
std::shared_ptr< T > shared_mutable_this(const std::enable_shared_from_this< T > *obj)
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.
SharedPtr< StructureBuilderReference > StructureView
Common interface for all structure types.