... | @@ -80,21 +80,43 @@ Create the Common Data Model C++ Condition |
... | @@ -80,21 +80,43 @@ Create the Common Data Model C++ Condition |
|
Now we are ready to create the C++ files specific to this condition class.
|
|
Now we are ready to create the C++ files specific to this condition class.
|
|
The easiest thing to do is to create copies of [engine/cdm/cpp/patient/conditions/SEChronicAnemia.h](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/patient/conditions/SEChronicAnemia.h) and [engine/cdm/cpp/patient/conditions/SEAcuteStress.cpp](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/patient/conditions/SEChronicAnemia.cpp) files and rename them to SE``your_condition_name``.h/.cpp Then replace the string ``AcuteStress`` with the name of your condition, then create the properties to match your condition 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/conditions/SEChronicAnemia.h](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/patient/conditions/SEChronicAnemia.h) and [engine/cdm/cpp/patient/conditions/SEAcuteStress.cpp](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/patient/conditions/SEChronicAnemia.cpp) files and rename them to SE``your_condition_name``.h/.cpp Then replace the string ``AcuteStress`` with the name of your condition, then create the properties to match your condition protobuf structure. Note the naming convention is to start each file and class name with ``SE``
|
|
|
|
|
|
Add the Common Data Model Condition to the Condition Base Class
|
|
Add the Serialization Support for your Condition Class
|
|
---------------------------------------------------------------
|
|
------------------------------------------------------
|
|
The Condition base class is responsible for translating the condition object to and from the AnyCondition object. Each condition base class will have a Load and Unload method you will need to add code to. The following files are those condition 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.
|
|
|
|
|
|
* [Environment Condition](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/system/environment/conditions/SEEnvironmentCondition.cpp)
|
|
**Headers**
|
|
* [Patient Condition](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/patient/conditions/SEPatientCondition.cpp)
|
|
|
|
|
|
|
|
In our example, for adding a patient condition we will add the following code
|
|
* [Environment Condition](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBEnvironmentConditions.h)
|
|
|
|
* [Patient Condition](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBPatientConditions.h)
|
|
|
|
|
|
|
|
In our example, for adding a patient condition we will add something like the following code to the appropriate header
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
// Forward declare
|
|
|
|
CDM_BIND_DECL2(MyNewAction)
|
|
|
|
// Methods to implement
|
|
|
|
static void Load(const cdm::MyNewConditionData& src, SEMyNewCondition& dst);
|
|
|
|
static cdm::MyNewConditionData* Unload(const SEMyNewCondition& src);
|
|
|
|
static void Serialize(const cdm::MyNewConditionData& src, SEMyNewCondition& dst);
|
|
|
|
static void Serialize(const SEMyNewCondition& src, cdm::MyNewConditionData& dst);
|
|
|
|
static void Copy(const SEMyNewCondition& src, SEMyNewCondition& dst);
|
|
|
|
```
|
|
|
|
|
|
|
|
**Code**
|
|
|
|
|
|
|
|
* [Environment Condition](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBEnvironmentConditions.cpp)
|
|
|
|
* [Patient Condition](https://gitlab.kitware.com/physiology/engine/blob/master/cdm/cpp/io/protobuf/PBPatientConditions.cpp)
|
|
|
|
|
|
|
|
Implement the newly added methods. I suggest you just copy another condition class method set and use the correct class names.
|
|
|
|
|
|
|
|
The Serialization class is also responsible for translating the condition object to and from the AnyCondition object.
|
|
|
|
You will need to update the following methods to ensure generic condition support.
|
|
|
|
|
|
```cpp
|
|
```cpp
|
|
// Add the header
|
|
|
|
#include "patient/conditions/SEMyNewCondition.h"
|
|
|
|
|
|
|
|
// Update the Load method
|
|
// Update the Load method
|
|
SEPatientCondition* SEPatientCondition::Load(const cdm::AnyPatientConditionData& any, SESubstanceManager& subMgr)
|
|
SEPatientCondition* PBPatientCondition::Load(const cdm::AnyPatientConditionData& any, SESubstanceManager& subMgr)
|
|
{
|
|
{
|
|
switch (any.Condition_case())
|
|
switch (any.Condition_case())
|
|
{
|
|
{
|
... | @@ -108,7 +130,7 @@ SEPatientCondition* SEPatientCondition::Load(const cdm::AnyPatientConditionData& |
... | @@ -108,7 +130,7 @@ SEPatientCondition* SEPatientCondition::Load(const cdm::AnyPatientConditionData& |
|
|
|
|
|
// 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::AnyPatientConditionData* SEPatientCondition::Unload(const SEPatientCondition& action)
|
|
cdm::AnyPatientConditionData* PBPatientCondition::Unload(const SEPatientCondition& action)
|
|
{
|
|
{
|
|
cdm::AnyPatientConditionData* any = new cdm::AnyPatientConditionData();
|
|
cdm::AnyPatientConditionData* any = new cdm::AnyPatientConditionData();
|
|
const SEMyNewCondition* mnc= dynamic_cast<const SEMyNewCondition*>(&action);
|
|
const SEMyNewCondition* mnc= dynamic_cast<const SEMyNewCondition*>(&action);
|
... | @@ -178,6 +200,13 @@ SEMyNewCondition* SEConditionManager::GetMyNewCondition() const |
... | @@ -178,6 +200,13 @@ SEMyNewCondition* SEConditionManager::GetMyNewCondition() const |
|
return m_MyNewCondition;
|
|
return m_MyNewCondition;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Go to the condition manager and add logic to the GetActiveConditions method
|
|
|
|
void SEConditionManager::GetActiveConditions(std::vector<const SECondition*>& conditions) const
|
|
|
|
{
|
|
|
|
if(HasMyNewCondition())
|
|
|
|
conditions.push_back(GetMyNewCondition());
|
|
|
|
}
|
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
With this file complete, the condition has been added to the Common Data Model and the engine is able to accept this condition and the engine may now implement logic based on this condition.
|
|
With this file complete, the condition has been added to the Common Data Model and the engine is able to accept this condition and the engine may now implement logic based on this condition.
|
... | | ... | |