| 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 |
#include <ActionWidget.h> |
| 13 |
|
| 14 |
@if@ $userIncludesInImplementation$ |
| 15 |
// Additional includes |
| 16 |
$userIncludesInImplementation$ |
| 17 |
@endif@ |
| 18 |
|
| 19 |
@if@ $itkFilters$ |
| 20 |
// Itk includes |
| 21 |
#include <itkVTKImageToImageFilter.h> |
| 22 |
#include <itkImageToVTKImageFilter.h> |
| 23 |
#include <ItkProgressObserver.h> |
| 24 |
@endif@ |
| 25 |
|
| 26 |
@if@ $implementationIncludes$ |
| 27 |
// includes for specific types |
| 28 |
$implementationIncludes$ |
| 29 |
@endif@ |
| 30 |
|
| 31 |
@if@ $componentClass$ |
| 32 |
// This action process $componentClass$, include is required |
| 33 |
#include <$componentClass$.h> |
| 34 |
@endif@ |
| 35 |
|
| 36 |
using namespace camitk; |
| 37 |
|
| 38 |
// ------------------- Constructor ------------------- |
| 39 |
$upperCamelCase(name)$::$upperCamelCase(name)$(ActionExtension* extension) : Action(extension) { |
| 40 |
// Setting name, description and input component |
| 41 |
setName("$title(name)$"); |
| 42 |
setDescription(R"($description$)"); |
| 43 |
setComponentClassName("$componentClass$"); |
| 44 |
|
| 45 |
// Setting classification family and tags |
| 46 |
setFamily("$classification.family$"); |
| 47 |
@for@ $tag$ in $classification.tags$ |
| 48 |
addTag("$tag$"); |
| 49 |
@endfor@ |
| 50 |
|
| 51 |
// block event management |
| 52 |
initializationPending = true; |
| 53 |
|
| 54 |
@if@ $parameters$ |
| 55 |
// Setting the action's parameters |
| 56 |
Property* param; |
| 57 |
@endif@ |
| 58 |
|
| 59 |
@for@ $p$ in $parameters$ |
| 60 |
@if@ contains($p.enumValues$) |
| 61 |
param = new Property("$title(p.name)$", (int) $p.defaultValue$, tr("$p.description$"), "$p.unit$"); |
| 62 |
@else@ |
| 63 |
param = new Property("$title(p.name)$", ($p.type$) $p.defaultValue$, tr("$p.description$"), "$p.unit$"); |
| 64 |
@endif@ |
| 65 |
@if@ $p.group$ |
| 66 |
param->setGroupName("$p.group$"); |
| 67 |
@endif@ |
| 68 |
@if@ contains($p.minimum$) |
| 69 |
param->setAttribute("minimum", (double) $p.minimum$); |
| 70 |
@endif@ |
| 71 |
@if@ $p.maximum$ |
| 72 |
param->setAttribute("maximum", (double) $p.maximum$); |
| 73 |
@endif@ |
| 74 |
@if@ $p.decimals$ |
| 75 |
param->setAttribute("decimals", $p.decimals$); |
| 76 |
@endif@ |
| 77 |
@if@ $p.singleStep$ |
| 78 |
param->setAttribute("singleStep", $p.singleStep$); |
| 79 |
@endif@ |
| 80 |
@if@ $p.regExp$ |
| 81 |
param->setAttribute("regExp", QRegularExpression("$p.regExp$")); |
| 82 |
@endif@ |
| 83 |
@if@ $p.readOnly$ |
| 84 |
param->setReadOnly(true); |
| 85 |
@endif@ |
| 86 |
@if@ contains($p.enumValues$) |
| 87 |
// Set the enum type |
| 88 |
param->setEnumTypeName("$upperCamelCase(p.name)$Enum"); |
| 89 |
// Populate the enum values |
| 90 |
QStringList $lowerCamelCase(p.name)$EnumValues; |
| 91 |
@subfor@ $enumVal$ in $p.enumValues$ |
| 92 |
$lowerCamelCase(p.name)$EnumValues.append("$enumVal$"); |
| 93 |
@endsubfor@ |
| 94 |
param->setAttribute("enumNames", $lowerCamelCase(p.name)$EnumValues); |
| 95 |
@endif@ |
| 96 |
addParameter(param); |
| 97 |
@endfor@ |
| 98 |
|
| 99 |
// call user-defined init() |
| 100 |
init(); |
| 101 |
|
| 102 |
// immediately take the property changes into account |
| 103 |
setAutoUpdateProperties(true); |
| 104 |
|
| 105 |
// initialization is finish, all events are unblocked |
| 106 |
initializationPending = false; |
| 107 |
|
| 108 |
@if@ $notEmbedded$ |
| 109 |
setEmbedded(false); |
| 110 |
@endif@ |
| 111 |
} |
| 112 |
|
| 113 |
// ------------------- getWidget ------------------- |
| 114 |
QWidget* $upperCamelCase(name)$::getWidget() { |
| 115 |
@if@ contains($gui$) |
| 116 |
// $gui$ begin |
| 117 |
@endif@ |
| 118 |
@if@ equals($gui$,"No GUI") |
| 119 |
targetDefined(); |
| 120 |
return nullptr; |
| 121 |
@endif@ |
| 122 |
@if@ equals($gui$,"Custom GUI") |
| 123 |
|
| 124 |
if (actionWidget == nullptr) { |
| 125 |
// first call: check the user defined widget |
| 126 |
actionWidget = getUI(); |
| 127 |
if (actionWidget != nullptr) { |
| 128 |
targetDefined(); |
| 129 |
return actionWidget; |
| 130 |
} |
| 131 |
else { |
| 132 |
// no user defined UI, use default |
| 133 |
QWidget* defaultWidget = Action::getWidget(); |
| 134 |
targetDefined(); |
| 135 |
return defaultWidget; |
| 136 |
} |
| 137 |
} |
| 138 |
else { |
| 139 |
targetDefined(); |
| 140 |
ActionWidget* defaultActionWidget = dynamic_cast<ActionWidget*>(actionWidget); |
| 141 |
if (defaultActionWidget != nullptr) { |
| 142 |
// this is a default action widget, make sure the widget has updated targets |
| 143 |
defaultActionWidget->update(); |
| 144 |
} |
| 145 |
return actionWidget; |
| 146 |
} |
| 147 |
@endif@ |
| 148 |
@if@ equals($gui$,"Default Action GUI") |
| 149 |
// just use default behaviour |
| 150 |
bool isFirstCall = (actionWidget == nullptr); |
| 151 |
QWidget* defaultWidget = Action::getWidget(); |
| 152 |
targetDefined(); |
| 153 |
if(isFirstCall){ // Update the default UI after first call to targetDefined |
| 154 |
ActionWidget* defaultActionWidget = dynamic_cast<ActionWidget*>(defaultWidget); |
| 155 |
if (defaultActionWidget != nullptr) { |
| 156 |
// this is a default action widget, make sure the widget has updated targets |
| 157 |
defaultActionWidget->update(); |
| 158 |
} |
| 159 |
} |
| 160 |
return defaultWidget; |
| 161 |
@endif@ |
| 162 |
@if@ contains($gui$) |
| 163 |
// $gui$ end |
| 164 |
@else@ |
| 165 |
// no GUI specified: just use default behaviour |
| 166 |
bool isFirstCall = (actionWidget == nullptr); |
| 167 |
QWidget* defaultWidget = Action::getWidget(); |
| 168 |
targetDefined(); |
| 169 |
if(isFirstCall){ // Update the default UI after first call to targetDefined |
| 170 |
ActionWidget* defaultActionWidget = dynamic_cast<ActionWidget*>(defaultWidget); |
| 171 |
if (defaultActionWidget != nullptr) { |
| 172 |
// this is a default action widget, make sure the widget has updated targets |
| 173 |
defaultActionWidget->update(); |
| 174 |
} |
| 175 |
} |
| 176 |
return defaultWidget; |
| 177 |
@endif@ |
| 178 |
} |
| 179 |
|
| 180 |
// ------------------- apply ------------------- |
| 181 |
Action::ApplyStatus $upperCamelCase(name)$::apply() { |
| 182 |
// call user-defined process() |
| 183 |
return process(); |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
// ---------------------- event ---------------------------- |
| 188 |
bool $upperCamelCase(name)$::event(QEvent* e) { |
| 189 |
if (e->type() == QEvent::DynamicPropertyChange && !initializationPending) { |
| 190 |
e->accept(); |
| 191 |
QDynamicPropertyChangeEvent* changeEvent = dynamic_cast<QDynamicPropertyChangeEvent*>(e); |
| 192 |
|
| 193 |
if (changeEvent != nullptr) { |
| 194 |
// call user-defined parameterChanged() |
| 195 |
parameterChanged(changeEvent->propertyName()); |
| 196 |
return true; |
| 197 |
} |
| 198 |
else { |
| 199 |
return false; |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
// this is important to continue the process if the event is a different one |
| 204 |
return QObject::event(e); |
| 205 |
} |