QList<AMAction3*> findActionsOfType(AMAction3 *rootAction, AMAction3 *typeAction){
		QList<AMAction3*> retVal;
		AMListAction3 *castToListAction = qobject_cast<AMListAction3*>(rootAction);
		if(castToListAction){
			for(int x = 0; x < castToListAction->subActionCount(); x++){
				if(typeAction->metaObject()->className() == castToListAction->subActionAt(x)->metaObject()->className())
					retVal.append(castToListAction->subActionAt(x));
				retVal.append((findActionsOfType(castToListAction->subActionAt(x), typeAction)));
			}
		}
		return retVal;
	}
	QList<AMAction3*> findActionsWhereNameContains(AMAction3 *rootAction, const QString &searchString){
		QList<AMAction3*> retVal;
		AMListAction3 *castToListAction = qobject_cast<AMListAction3*>(rootAction);
		if(castToListAction){
			for(int x = 0; x < castToListAction->subActionCount(); x++){
				AMListAction3 *subActionToListAction = qobject_cast<AMListAction3*>(castToListAction->subActionAt(x));
				if(subActionToListAction && subActionToListAction->info()->shortDescription().contains(searchString))
					retVal.append(subActionToListAction);
				retVal.append((findActionsNamed(castToListAction->subActionAt(x), searchString)));
			}
		}
		return retVal;
	}
	QList<AMAction3*> findActionsNamed(AMAction3 *rootAction, const QString &name){
		QList<AMAction3*> retVal;
		AMListAction3 *castToListAction = qobject_cast<AMListAction3*>(rootAction);
		if(castToListAction){
			for(int x = 0; x < castToListAction->subActionCount(); x++){
				AMListAction3 *subActionToListAction = qobject_cast<AMListAction3*>(castToListAction->subActionAt(x));
				if(subActionToListAction && subActionToListAction->info()->shortDescription() == name)
					retVal.append(subActionToListAction);
				retVal.append((findActionsNamed(castToListAction->subActionAt(x), name)));
			}
		}
		return retVal;
	}
void AMScanActionControllerScanAssembler::generateActionTree(){
	actionTree_ = generateActionTreeForAxis(controls_->at(0), axes_.at(0));

	QList<AMAction3*> insertionPoints = findInsertionPoints(actionTree_);
	for(int x = 1; x < axes_.count(); x++){
		QList<AMAction3*> newInsertionPoints;
		newInsertionPoints.clear();

		for(int y = 0; y < insertionPoints.count(); y++){
			AMListAction3 *castParentToListAction = qobject_cast<AMListAction3*>(insertionPoints.at(y)->parentAction());
			if(castParentToListAction){
				int indexOfAction = castParentToListAction->indexOfSubAction(insertionPoints.at(y));
				castParentToListAction->insertSubAction(generateActionTreeForAxis(controls_->at(x), axes_.at(x)), indexOfAction);
				castParentToListAction->deleteSubAction(indexOfAction+1);
				newInsertionPoints.append(findInsertionPoints(castParentToListAction->subActionAt(indexOfAction)));
			}
		}
		insertionPoints.clear();
		insertionPoints = newInsertionPoints;
	}

	QList<AMAction3*> detectorInsertionPoints = findInsertionPoints(actionTree_);
	for(int x = 0; x < detectorInsertionPoints.count(); x++){
		AMListAction3 *castParentToListAction = qobject_cast<AMListAction3*>(detectorInsertionPoints.at(x)->parentAction());
		if(castParentToListAction){
			int indexOfAction = castParentToListAction->indexOfSubAction(detectorInsertionPoints.at(x));
			castParentToListAction->insertSubAction(generateActionListForDetectorAcquisition(), indexOfAction);
			castParentToListAction->deleteSubAction(indexOfAction+1);
		}
	}

	AMListAction3 *castRetValToListAction = qobject_cast<AMListAction3*>(actionTree_);
	if(castRetValToListAction){
		AMListAction3 *castFirstToListAction = qobject_cast<AMListAction3*>(castRetValToListAction->subActionAt(1));
		if(castFirstToListAction)
			castFirstToListAction->addSubAction(generateActionListForDetectorInitialization());

		AMListAction3 *castLastToListAction = qobject_cast<AMListAction3*>(castRetValToListAction->subActionAt(castRetValToListAction->subActionCount()-2));
		if(castLastToListAction)
			castLastToListAction->addSubAction(generateActionListForDetectorCleanup());
	}

	emit actionTreeGenerated(actionTree_);
}