| 1 |
$licenseComment$ |
| 2 |
#include "$upperCamelCase(name)$.h" |
| 3 |
|
| 4 |
// |
| 5 |
// Generated source for action "$title(name)$" |
| 6 |
// $date()$ - $time()$ |
| 7 |
// |
| 8 |
|
| 9 |
// CamiTK includes |
| 10 |
#include <Property.h> |
| 11 |
#include <Log.h> |
| 12 |
|
| 13 |
@if@ $userIncludesInImplementation$ |
| 14 |
// Additional includes |
| 15 |
$userIncludesInImplementation$ |
| 16 |
@endif@ |
| 17 |
|
| 18 |
@if@ $itkFilters$ |
| 19 |
// Itk includes |
| 20 |
#include <itkVTKImageToImageFilter.h> |
| 21 |
#include <itkImageToVTKImageFilter.h> |
| 22 |
#include <ItkProgressObserver.h> |
| 23 |
@endif@ |
| 24 |
|
| 25 |
@if@ $implementationIncludes$ |
| 26 |
// includes for specific types |
| 27 |
$implementationIncludes$ |
| 28 |
@endif@ |
| 29 |
|
| 30 |
@if@ $componentClass$ |
| 31 |
// This action process $componentClass$, include is required |
| 32 |
#include <$componentClass$.h> |
| 33 |
@endif@ |
| 34 |
|
| 35 |
using namespace camitk; |
| 36 |
|
| 37 |
// -------------------- init -------------------- |
| 38 |
void $upperCamelCase(name)$::init() { |
| 39 |
// Add initialization if required |
| 40 |
// |
| 41 |
// Note: use the "classMembers" field of the $name$ action in |
| 42 |
// the .camitk JSON file to declare additional private, |
| 43 |
// public, or signal/slot members. |
| 44 |
} |
| 45 |
|
| 46 |
// -------------------- process -------------------- |
| 47 |
Action::ApplyStatus $upperCamelCase(name)$::process() { |
| 48 |
QString logMessage; |
| 49 |
logMessage = tr("Action \"$title(name)$\" called"); |
| 50 |
@if@ $parameters$ |
| 51 |
logMessage += tr(" with parameters:"); |
| 52 |
@endif@ |
| 53 |
logMessage += "\n"; |
| 54 |
|
| 55 |
// example of value retrieval |
| 56 |
@for@ $p$ in $parameters$ |
| 57 |
@if@ contains($p.enumValues$) |
| 58 |
int param$index(p)$ = getParameterValue("$title(p.name)$").value<int>(); // enum as an int |
| 59 |
QStringList $lowerCamelCase(p.name)$EnumValues = getProperty("$title(p.name)$")->getAttribute("enumNames").toStringList(); |
| 60 |
QString param$index(p)$String = $lowerCamelCase(p.name)$EnumValues.value(param$index(p)$); |
| 61 |
logMessage += QString(" - $title(p.name)$: ") + param$index(p)$String + " (value: " + QString::number(param$index(p)$) + ")\n"; |
| 62 |
@else@ |
| 63 |
$p.type$ param$index(p)$ = getParameterValue("$title(p.name)$").value<$p.type$>(); |
| 64 |
logMessage += QString(" - $title(p.name)$: ") + getParameterValueAsString("$title(p.name)$") + "\n"; |
| 65 |
@endif@ |
| 66 |
@endfor@ |
| 67 |
// Create a warning log message for this demo (although CAMITK_TRACE |
| 68 |
// and CAMITK_INFO are usually recommended for log messages) |
| 69 |
CAMITK_WARNING(logMessage); |
| 70 |
|
| 71 |
// Process each targets |
| 72 |
@if@ $componentClass$ |
| 73 |
// example of processing |
| 74 |
for(Component* selected: getTargets()) { |
| 75 |
$componentClass$* input = dynamic_cast <$componentClass$*>(selected); |
| 76 |
// Here do something here input |
| 77 |
CAMITK_INFO(QString("Processing component %1...").arg(input->getName())); |
| 78 |
} |
| 79 |
@endif@ |
| 80 |
|
| 81 |
return SUCCESS; |
| 82 |
} |
| 83 |
|
| 84 |
// -------------------- targetDefined -------------------- |
| 85 |
void $upperCamelCase(name)$::targetDefined() { |
| 86 |
@if@ $componentClass$ |
| 87 |
// example of processing |
| 88 |
QString logMessage = "Current targets:\n"; |
| 89 |
for(Component* selected: getTargets()) { |
| 90 |
$componentClass$* input = dynamic_cast <$componentClass$*>(selected); |
| 91 |
logMessage += "- Component \"" + input->getName() + "\" is a target\n"; |
| 92 |
} |
| 93 |
CAMITK_WARNING(logMessage); |
| 94 |
@endif@ |
| 95 |
@if@ equals($gui$,"Custom GUI") |
| 96 |
// If necessary you can update your custom UI depending on the current target(s) |
| 97 |
@endif@ |
| 98 |
} |
| 99 |
|
| 100 |
// -------------------- parameterChanged -------------------- |
| 101 |
void $upperCamelCase(name)$::parameterChanged(QString parameterName) { |
| 102 |
// Here do something when the given parameter has changed |
| 103 |
CAMITK_WARNING(QString("Parameter %1 value changed to %2").arg(parameterName).arg(getParameterValueAsString(parameterName))) |
| 104 |
} |
| 105 |
|
| 106 |
@if@ equals($gui$,"Custom GUI") |
| 107 |
// -------------------- getUI -------------------- |
| 108 |
QWidget* $upperCamelCase(name)$::getUI() { |
| 109 |
// This is where you need to instantiate and manage |
| 110 |
// your custom GUI |
| 111 |
// |
| 112 |
// Note: this method will only be called once, |
| 113 |
// at the first triggering of the action just |
| 114 |
// before the first targetDefined() call. |
| 115 |
// You need to use signal/slot to update your widget |
| 116 |
// in another part of your code. |
| 117 |
// |
| 118 |
return nullptr; |
| 119 |
} |
| 120 |
@endif@ |