text: // Copyright 2017-2020, Institute for Artificial Intelligence - University of Bremen
  // Author: Andrei Haidu (http://haidu.eu)
  
  #include "VizQ/SLVizQHighlight.h"
  #include "Knowrob/SLKnowrobManager.h"
  #include "Viz/SLVizManager.h"
  
  #if WITH_EDITOR
  #include "Engine/Selection.h"
  #include "Editor.h"
  #include "Individuals/SLIndividualUtils.h"
  #include "Individuals/Type/SLBaseIndividual.h"
  #endif // WITH_EDITOR
  
  #if WITH_EDITOR
  // Called when a property is changed in the editor
  void USLVizQHighlight::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
  {
  	Super::PostEditChangeProperty(PropertyChangedEvent);
  
  	// Get the changed property name
  	FName PropertyName = (PropertyChangedEvent.Property != NULL) ?
  		PropertyChangedEvent.Property->GetFName() : NAME_None;
  
  	/* Add selected actors ids to array */
  	if (PropertyName == GET_MEMBER_NAME_CHECKED(USLVizQHighlight, bAddSelectedButton))
  	{
  		bAddSelectedButton = false;
  		if (bOverwrite)
  		{
  			Ids.Empty();
  		}
  		for (FSelectionIterator It(GEditor->GetSelectedActorIterator()); It; ++It)
  		{
  			AActor* SelectedActor = CastChecked<AActor>(*It);
  			if (USLBaseIndividual* BI = FSLIndividualUtils::GetIndividualObject(SelectedActor))
  			{
  				if (BI->IsLoaded())
  				{
  					bEnsureUniqueness ? Ids.AddUnique(BI->GetIdValue()) : Ids.Add(BI->GetIdValue());					
  				}
  				else
  				{
  					UE_LOG(LogTemp, Warning, TEXT("%s::%d %s's individual is not loaded.."),
  						*FString(__FUNCTION__), __LINE__, *SelectedActor->GetName());
  				}
  			}
  			else
  			{
  				UE_LOG(LogTemp, Warning, TEXT("%s::%d %s has no individual representation.."),
  					*FString(__FUNCTION__), __LINE__, *SelectedActor->GetName());
  			}
  		}
  	}
  	else if (PropertyName == GET_MEMBER_NAME_CHECKED(USLVizQHighlight, bRemoveSelectedButton))
  	{
  		bRemoveSelectedButton = false;
  		for (FSelectionIterator It(GEditor->GetSelectedActorIterator()); It; ++It)
  		{
  			AActor* SelectedActor = CastChecked<AActor>(*It);
  			if (USLBaseIndividual* BI = FSLIndividualUtils::GetIndividualObject(SelectedActor))
  			{
  				if (BI->IsLoaded())
  				{
  					Ids.Remove(BI->GetIdValue());
  				}
  				else
  				{
  					UE_LOG(LogTemp, Warning, TEXT("%s::%d %s's individual is not loaded.."),
  						*FString(__FUNCTION__), __LINE__, *SelectedActor->GetName());
  				}
  			}
  			else
  			{
  				UE_LOG(LogTemp, Warning, TEXT("%s::%d %s has no individual representation.."),
  					*FString(__FUNCTION__), __LINE__, *SelectedActor->GetName());
  			}
  		}
  	}	
  }
  #endif // WITH_EDITOR
  
  // Virtual implementation of the execute function
  void USLVizQHighlight::ExecuteImpl(ASLKnowrobManager* KRManager)
  {
  	ASLVizManager* VizManager = KRManager->GetVizManager();
  	if (Action == ESLVizQHighlightAction::Highlight)
  	{
  		for (const auto& Id : Ids)
  		{
  			VizManager->HighlightIndividual(Id, Color, MaterialType);
  		}
  	}
  	else if (Action == ESLVizQHighlightAction::Remove)
  	{
  		for (const auto& Id : Ids)
  		{
  			VizManager->RemoveIndividualHighlight(Id);
  		}
  	}
  	else if (Action == ESLVizQHighlightAction::RemoveAll)
  	{
  		VizManager->RemoveAllIndividualHighlights();
  	}
  }
  