... | @@ -82,23 +82,47 @@ Create the Common Data Model C++ Action |
... | @@ -82,23 +82,47 @@ Create the Common Data Model C++ Action |
|
Now we are ready to create the C++ files specific to this action class.
|
|
Now we are ready to create the C++ files specific to this action class.
|
|
The easiest thing to do is to create copies of [engine/cdm/cpp/patient/actions/SEAcuteStress.h](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/patient/actions/SEAcuteStress.h) and [engine/cdm/cpp/patient/actions/SEAcuteStress.cpp](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/patient/actions/SEAcuteStress.cpp) files and rename them to SE``your_action_name``.h/.cpp Then replace the string ``AcuteStress`` with the name of your action, then create the properties to match your action protobuf structure. Note the naming convention is to start each file and class name with ``SE``
|
|
The easiest thing to do is to create copies of [engine/cdm/cpp/patient/actions/SEAcuteStress.h](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/patient/actions/SEAcuteStress.h) and [engine/cdm/cpp/patient/actions/SEAcuteStress.cpp](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/patient/actions/SEAcuteStress.cpp) files and rename them to SE``your_action_name``.h/.cpp Then replace the string ``AcuteStress`` with the name of your action, then create the properties to match your action protobuf structure. Note the naming convention is to start each file and class name with ``SE``
|
|
|
|
|
|
Add the Common Data Model Action to its Action Base Class
|
|
Add the Serialization Support for your Action Class
|
|
---------------------------------------------------------
|
|
---------------------------------------------------
|
|
The Action base class is responsible for translating the action object to and from the AnyAction object. Each action base class will have a Load and Unload method you will need to add code to. The following files are those action base classes:
|
|
All CDM classes support serialization to and from a binding class.
|
|
|
|
You will need to update the appropriate binding class for your action type.
|
|
|
|
|
|
* [Anesthesia Machine Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/system/equipment/anesthesiamachine/actions/SEAnesthesiaMachineAction.cpp)
|
|
**Headers**
|
|
* [Environment Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/system/environment/actions/SEEnvironmentAction.cpp)
|
|
|
|
* [Inhaler Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/system/equipment/inhaler/actions/SEInhalerAction.cpp)
|
|
|
|
* [Patient Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/patient/actions/SEPatientAction.cpp)
|
|
|
|
|
|
|
|
In our example, for adding a patient action we will add the following code
|
|
* [Anesthesia Machine Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBAnesthesiaMachineActions.h)
|
|
|
|
* [Environment Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBEnvironmentActions.h)
|
|
|
|
* [Inhaler Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBInhalerActions.h)
|
|
|
|
* [Patient Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBInhalerActions.h)
|
|
|
|
|
|
|
|
In our example, for adding a patient action we will add something like the following code to the appropriate header
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
// Forward declare
|
|
|
|
CDM_BIND_DECL2(MyNewAction)
|
|
|
|
// Add the following methods to the class
|
|
|
|
static void Load(const cdm::MyNewActionData& src, SEMyNewAction& dst);
|
|
|
|
static cdm::MyNewActionData* Unload(const SEMyNewAction& src);
|
|
|
|
static void Serialize(const cdm::MyNewActionData& src, SEMyNewAction& dst);
|
|
|
|
static void Serialize(const SEMyNewAction& src, cdm::MyNewActionData& dst);
|
|
|
|
static void Copy(const SEMyNewAction& src, SEMyNewAction& dst);
|
|
|
|
```
|
|
|
|
|
|
|
|
**Code**
|
|
|
|
|
|
|
|
* [Anesthesia Machine Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBAnesthesiaMachineActions.cpp)
|
|
|
|
* [Environment Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBEnvironmentActions.cpp)
|
|
|
|
* [Inhaler Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBInhalerActions.cpp)
|
|
|
|
* [Patient Action](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBInhalerActions.cpp)
|
|
|
|
|
|
|
|
Implement the newly added methods. I suggest you just copy another action class method set and use the correct class names.
|
|
|
|
|
|
|
|
The Serialization class is also responsible for translating the action object to and from the AnyAction object.
|
|
|
|
You will need to update the following methods to ensure generic action support.
|
|
|
|
|
|
```cpp
|
|
```cpp
|
|
// Add the header
|
|
|
|
#include "patient/actions/SEMyNewAction.h"
|
|
|
|
|
|
|
|
// Update the Load method
|
|
// Update the Load method
|
|
SEPatientAction* SEPatientAction::Load(const cdm::AnyPatientActionData& any, SESubstanceManager& subMgr)
|
|
SEPatientAction* PBPatientAction::Load(const cdm::AnyPatientActionData& any, SESubstanceManager& subMgr)
|
|
{
|
|
{
|
|
switch (any.Action_case())
|
|
switch (any.Action_case())
|
|
{
|
|
{
|
... | @@ -113,7 +137,7 @@ SEPatientAction* SEPatientAction::Load(const cdm::AnyPatientActionData& any, SES |
... | @@ -113,7 +137,7 @@ SEPatientAction* SEPatientAction::Load(const cdm::AnyPatientActionData& any, SES |
|
|
|
|
|
// Update the Unload Method
|
|
// Update the Unload Method
|
|
// Note we will want the cast/if block to be alphabetical order
|
|
// Note we will want the cast/if block to be alphabetical order
|
|
cdm::AnyPatientActionData* SEPatientAction::Unload(const SEPatientAction& action)
|
|
cdm::AnyPatientActionData* PBPatientAction::Unload(const SEPatientAction& action)
|
|
{
|
|
{
|
|
cdm::AnyPatientActionData* any = new cdm::AnyPatientActionData();
|
|
cdm::AnyPatientActionData* any = new cdm::AnyPatientActionData();
|
|
const SEMyNewAction* a= dynamic_cast<const SEMyNewAction*>(&action);
|
|
const SEMyNewAction* a= dynamic_cast<const SEMyNewAction*>(&action);
|
... | @@ -186,6 +210,13 @@ void SEPatientActionCollection::RemoveMyNewAction() |
... | @@ -186,6 +210,13 @@ void SEPatientActionCollection::RemoveMyNewAction() |
|
{
|
|
{
|
|
SAFE_DELETE(m_MyNewAction);
|
|
SAFE_DELETE(m_MyNewAction);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Go to the appropriate action manager and add logic to the GetActiveActions method
|
|
|
|
void SEPatientActionCollection::GetActiveActions(std::vector<const SEAction*>& actions) const
|
|
|
|
{
|
|
|
|
if(HasMyNewAction())
|
|
|
|
actions.push_back(GetMyNewAction());
|
|
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
With this file complete, the action has been added to the Common Data Model and the engine is able to accept these actions and the engine may now implement logic based on this action.
|
|
With this file complete, the action has been added to the Common Data Model and the engine is able to accept these actions and the engine may now implement logic based on this action.
|
... | | ... | |