| 1 |
$licenseComment$ |
| 2 |
|
| 3 |
// |
| 4 |
// Generated source for action "$title(name)$" |
| 5 |
// $date()$ - $time()$ |
| 6 |
// |
| 7 |
// CamiTK includes |
| 8 |
#include <Property.h> |
| 9 |
#include <Action.h> |
| 10 |
#include <Log.h> |
| 11 |
|
| 12 |
@if@ $userIncludesInImplementation$ |
| 13 |
// Additional includes |
| 14 |
$userIncludesInImplementation$ |
| 15 |
@endif@ |
| 16 |
|
| 17 |
@if@ $headerIncludes$ |
| 18 |
// Additional includes |
| 19 |
$headerIncludes$ |
| 20 |
@endif@ |
| 21 |
|
| 22 |
@if@ $implementationIncludes$ |
| 23 |
// includes for specific types |
| 24 |
$implementationIncludes$ |
| 25 |
@endif@ |
| 26 |
|
| 27 |
@if@ $itkFilters$ |
| 28 |
// Itk includes |
| 29 |
#include <itkVTKImageToImageFilter.h> |
| 30 |
#include <itkImageToVTKImageFilter.h> |
| 31 |
#include <ItkProgressObserver.h> |
| 32 |
@endif@ |
| 33 |
|
| 34 |
// You may remove this header if they are not needed |
| 35 |
#include <QVector3D> |
| 36 |
#include <QPoint> |
| 37 |
#include <QColor> |
| 38 |
|
| 39 |
@if@ $componentClass$ |
| 40 |
// This action process $componentClass$, include is required |
| 41 |
#include <$componentClass$.h> |
| 42 |
@endif@ |
| 43 |
|
| 44 |
// You can also move CamiTKActionDeclaration($upperCamelCase(name)$) to a separate |
| 45 |
// header file if you prefer (do not forget to add the header guards __$upperSnakeCase(name)$_ACTION__) |
| 46 |
CamiTKActionDeclaration($upperCamelCase(name)$) { |
| 47 |
// here add all the extra declaration required for the action processing (data, methods...) |
| 48 |
// Do not use qualified class name |
| 49 |
// E.g., use "void myMethod(...);" instead of "void $upperCamelCase(name)$::myMethod(..)" |
| 50 |
// Note: all extra declaration in this section will only be accessible from this file |
| 51 |
// You cannot declare any public/private/protected/slots/signal sections |
| 52 |
$classMembers$ |
| 53 |
} |
| 54 |
|
| 55 |
using namespace camitk; |
| 56 |
|
| 57 |
|
| 58 |
CamiTKActionImplementation($upperCamelCase(name)$) { |
| 59 |
|
| 60 |
// Do not use qualified class name |
| 61 |
// E.g., use "void myMethod(...) {..}" instead of "void $upperCamelCase(name)$::myMethod(..) {..}" |
| 62 |
|
| 63 |
// -------------------- init -------------------- |
| 64 |
void init(Action* self) { |
| 65 |
// Add initialization if required |
| 66 |
// You may comment or remove this method if your action does not required |
| 67 |
// any initialization |
| 68 |
} |
| 69 |
|
| 70 |
// -------------------- process -------------------- |
| 71 |
Action::ApplyStatus process(Action* self) { |
| 72 |
QString logMessage; |
| 73 |
logMessage = QString("Action \"%1\" called").arg(self->getName()); |
| 74 |
@if@ $parameters$ |
| 75 |
logMessage += QString(" with parameters:"); |
| 76 |
@endif@ |
| 77 |
logMessage += "\n"; |
| 78 |
|
| 79 |
// example of value retrieval |
| 80 |
@for@ $p$ in $parameters$ |
| 81 |
@if@ contains($p.enumValues$) |
| 82 |
int param$index(p)$ = self->getParameterValue("$title(p.name)$").value<int>(); // enum as an int |
| 83 |
QStringList $lowerCamelCase(p.name)$EnumValues = self->getProperty("$title(p.name)$")->getAttribute("enumNames").toStringList(); |
| 84 |
QString param$index(p)$String = $lowerCamelCase(p.name)$EnumValues.value(param$index(p)$); |
| 85 |
logMessage += QString(" - $title(p.name)$: ") + param$index(p)$String + " (value: " + QString::number(param$index(p)$) + ")\n"; |
| 86 |
@else@ |
| 87 |
$p.type$ param$index(p)$ = self->getParameterValue("$title(p.name)$").value < $p.type$ > (); |
| 88 |
logMessage += QString(" - $title(p.name)$: ") + self->getParameterValueAsString("$title(p.name)$") + "\n"; |
| 89 |
@endif@ |
| 90 |
@endfor@ |
| 91 |
// Create a warning log message for this demo (although CAMITK_TRACE_ALT |
| 92 |
// and CAMITK_INFO_ALT are usually recommended for log messages) |
| 93 |
CAMITK_WARNING_ALT(logMessage); |
| 94 |
|
| 95 |
// Process each targets |
| 96 |
@if@ $componentClass$ |
| 97 |
// example of processing |
| 98 |
for (Component* selected : self->getTargets()) { |
| 99 |
$componentClass$* input = dynamic_cast<$componentClass$*>(selected); |
| 100 |
// Here do something here input |
| 101 |
CAMITK_INFO_ALT(QString("Processing component %1...").arg(input->getName())); |
| 102 |
} |
| 103 |
@endif@ |
| 104 |
|
| 105 |
return Action::SUCCESS; |
| 106 |
} |
| 107 |
|
| 108 |
@if@ $componentClass$ |
| 109 |
// -------------------- targetDefined -------------------- |
| 110 |
void targetDefined(Action* self) { |
| 111 |
// You may comment or remove this method if your action does not required |
| 112 |
// to do something when the target is defined |
| 113 |
|
| 114 |
// example: |
| 115 |
QString logMessage = "Current targets:\n"; |
| 116 |
for(Component* selected: self->getTargets()) { |
| 117 |
$componentClass$* input = dynamic_cast <$componentClass$*>(selected); |
| 118 |
logMessage += "- Component \"" + input->getName() + "\" is a target\n"; |
| 119 |
} |
| 120 |
CAMITK_WARNING_ALT(logMessage); |
| 121 |
// If necessary you can update your custom UI depending on the current target(s) |
| 122 |
} |
| 123 |
@endif@ |
| 124 |
|
| 125 |
// -------------------- parameterChanged -------------------- |
| 126 |
void parameterChanged(Action* self, QString parameterName) { |
| 127 |
// You may comment or remove this method if your action does not required |
| 128 |
// to do something when one of the parameter's value has changed |
| 129 |
|
| 130 |
// example: |
| 131 |
CAMITK_WARNING_ALT(QString("Parameter %1 value changed to %2").arg(parameterName).arg(self->getParameterValueAsString(parameterName))) |
| 132 |
} |
| 133 |
|
| 134 |
// -------------------- getUI -------------------- |
| 135 |
QWidget* getUI(Action* self) { |
| 136 |
// You may comment or remove this method if your action |
| 137 |
// uses the default action widget |
| 138 |
|
| 139 |
// If you don't want to use the default action widget |
| 140 |
// but want to create your own action widget, |
| 141 |
// then write you UI instantiation here. |
| 142 |
// |
| 143 |
// Note: CamiTK uses a lazy instantiation pattern for |
| 144 |
// UI. This method will only be called once, when the |
| 145 |
// action is triggered. |
| 146 |
// Add other signal/slot methods to update your widget |
| 147 |
// if needed. |
| 148 |
// |
| 149 |
return nullptr; |
| 150 |
} |
| 151 |
|
| 152 |
} |