diff --git a/core/opengate_core/opengate_core.cpp b/core/opengate_core/opengate_core.cpp index 5f6069295..45df6d30b 100644 --- a/core/opengate_core/opengate_core.cpp +++ b/core/opengate_core/opengate_core.cpp @@ -290,6 +290,8 @@ void init_GateWeightedEdepActor(py::module &); void init_GateActorManager(py::module &); +void init_GateInternalActions(py::module &m); + // Gate filters void init_GateVFilter(py::module &); @@ -567,6 +569,7 @@ PYBIND11_MODULE(opengate_core, m) { init_GateVActor(m); init_GateWeightedEdepActor(m); init_GateActorManager(m); + init_GateInternalActions(m); init_GateVFilter(m); init_GateParticleFilter(m); init_GatePrimaryScatterFilter(m); diff --git a/core/opengate_core/opengate_lib/GateInternalActions.cpp b/core/opengate_core/opengate_lib/GateInternalActions.cpp new file mode 100644 index 000000000..1cd6be2b0 --- /dev/null +++ b/core/opengate_core/opengate_lib/GateInternalActions.cpp @@ -0,0 +1 @@ +#include "GateInternalActions.h" diff --git a/core/opengate_core/opengate_lib/GateInternalActions.h b/core/opengate_core/opengate_lib/GateInternalActions.h new file mode 100644 index 000000000..f0f8fedbb --- /dev/null +++ b/core/opengate_core/opengate_lib/GateInternalActions.h @@ -0,0 +1,18 @@ +/* -------------------------------------------------- + Copyright (C): OpenGATE Collaboration + This software is distributed under the terms + of the GNU Lesser General Public Licence (LGPL) + See LICENSE.md for further details + -------------------------------------------------- */ + +#ifndef CORE_OPENGATE_LIB_GATEINTERNALACTIONS_H +#define CORE_OPENGATE_LIB_GATEINTERNALACTIONS_H + +#include "GateVActor.h" + +class GateInternalActions : public GateVActor { +public: + using GateVActor::GateVActor; +}; + +#endif diff --git a/core/opengate_core/opengate_lib/pyGateInternalActions.cpp b/core/opengate_core/opengate_lib/pyGateInternalActions.cpp new file mode 100644 index 000000000..52115938d --- /dev/null +++ b/core/opengate_core/opengate_lib/pyGateInternalActions.cpp @@ -0,0 +1,20 @@ +/* -------------------------------------------------- + Copyright (C): OpenGATE Collaboration + This software is distributed under the terms + of the GNU Lesser General Public Licence (LGPL) + See LICENSE.md for further details + -------------------------------------------------- */ + +#include +#include + +namespace py = pybind11; + +#include "GateInternalActions.h" + +void init_GateInternalActions(py::module &m) { + py::class_, GateVActor>( + m, "GateInternalActions") + .def(py::init()); +} diff --git a/opengate/actors/base.py b/opengate/actors/base.py index 19b83a051..77253e9cb 100644 --- a/opengate/actors/base.py +++ b/opengate/actors/base.py @@ -1,6 +1,7 @@ from box import Box from functools import wraps +import opengate_core as g4 from ..definitions import __world_name__ from ..exception import fatal, GateImplementationError from ..base import GateObject, process_cls @@ -611,4 +612,27 @@ def EndSimulationAction(self): pass +class InternalActions(ActorBase, g4.GateInternalActions): + """ """ + + def __init__(self, *args, **kwargs): + ActorBase.__init__(self, *args, **kwargs) + self.__initcpp__() + + def __initcpp__(self): + g4.GateInternalActions.__init__(self, self.user_info) + + def initialize(self): + ActorBase.initialize(self) + self.InitializeUserInfo(self.user_info) + self.InitializeCpp() + + def StartSimulationAction(self): + g4.GateInternalActions.StartSimulationAction(self) + + def EndSimulationAction(self): + g4.GateInternalActions.EndSimulationAction(self) + + process_cls(ActorBase) +process_cls(InternalActions) diff --git a/opengate/managers.py b/opengate/managers.py index ffa505d1d..ad8086306 100644 --- a/opengate/managers.py +++ b/opengate/managers.py @@ -75,7 +75,7 @@ VolumeTreeRoot, ) from .actors.filters import get_filter_class, FilterBase, filter_classes -from .actors.base import ActorBase +from .actors.base import ActorBase, InternalActions from .actors.doseactors import ( DoseActor, @@ -369,6 +369,8 @@ def __init__(self, simulation, *args, **kwargs) -> None: # dictionary of actor objects. Do not fill manually. Use add_actor() method. self.actors = {} + self._add_internal_actions() + def __str__(self): s = "The actor manager contains the following actors: \n" s += self.dump_actors() @@ -474,6 +476,11 @@ def _create_actor(self, actor_type, name): ) return cls(name=name, simulation=self.simulation) + def _add_internal_actions(self): + name = "_gate_internal_actions" + self.internal_actions = InternalActions(name=name, simulation=self.simulation) + self.add_actor(self.internal_actions, name) + class PhysicsListManager(GateObject): # Names of the physics constructors that can be created dynamically