Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GeoJSONSpawner Gem #93

Merged
merged 20 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Gems/GeoJSONSpawner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# Query the gem name from the gem.json file if possible
# otherwise fallback to using GeoJSONSpawner
o3de_find_ancestor_gem_root(gem_path gem_name "${CMAKE_CURRENT_SOURCE_DIR}")
if (NOT gem_name)
set(gem_name "GeoJSONSpawner")
endif()

# Fallback to using the current source CMakeLists.txt directory as the gem root path
if (NOT gem_path)
set(gem_path ${CMAKE_CURRENT_SOURCE_DIR})
endif()

set(gem_json ${gem_path}/gem.json)

o3de_restricted_path(${gem_json} gem_restricted_path gem_parent_relative_path)

o3de_pal_dir(pal_dir ${CMAKE_CURRENT_SOURCE_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")

ly_add_external_target_path(${CMAKE_CURRENT_SOURCE_DIR}/3rdParty)

add_subdirectory(Code)
228 changes: 228 additions & 0 deletions Gems/GeoJSONSpawner/Code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@

# Currently we are in the Code folder: ${CMAKE_CURRENT_LIST_DIR}
# Get the platform specific folder ${pal_dir} for the current folder: ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME}
# Note: o3de_pal_dir will take care of the details for us, as this may be a restricted platform
# in which case it will see if that platform is present here or in the restricted folder.
# i.e. It could here in our gem : Gems/GeoJSONSpawner/Code/Platform/<platorm_name> or
# <restricted_folder>/<platform_name>/Gems/GeoJSONSpawner/Code
o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")

# Now that we have the platform abstraction layer (PAL) folder for this folder, thats where we will find the
# traits for this platform. Traits for a platform are defines for things like whether or not something in this gem
# is supported by this platform.
include(${pal_dir}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)

# Check to see if building the Gem Modules are supported for the current platform
if(NOT PAL_TRAIT_GEOJSONSPAWNER_SUPPORTED)
return()
endif()

# The ${gem_name}.API target declares the common interface that users of this gem should depend on in their targets
ly_add_target(
NAME ${gem_name}.API INTERFACE
NAMESPACE Gem
FILES_CMAKE
geojsonspawner_api_files.cmake
${pal_dir}/geojsonspawner_api_files.cmake
INCLUDE_DIRECTORIES
INTERFACE
Include
BUILD_DEPENDENCIES
INTERFACE
AZ::AzCore
)

# The ${gem_name}.Private.Object target is an internal target
# It should not be used outside of this Gems CMakeLists.txt
ly_add_target(
NAME ${gem_name}.Private.Object STATIC
NAMESPACE Gem
FILES_CMAKE
geojsonspawner_private_files.cmake
${pal_dir}/geojsonspawner_private_files.cmake
TARGET_PROPERTIES
O3DE_PRIVATE_TARGET TRUE
INCLUDE_DIRECTORIES
PRIVATE
Include
Source
BUILD_DEPENDENCIES
PUBLIC
AZ::AzCore
AZ::AzFramework
PRIVATE
Gem::ROS2.Static
)

# Here add ${gem_name} target, it depends on the Private Object library and Public API interface
ly_add_target(
NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
NAMESPACE Gem
FILES_CMAKE
geojsonspawner_shared_files.cmake
${pal_dir}/geojsonspawner_shared_files.cmake
INCLUDE_DIRECTORIES
PUBLIC
Include
PRIVATE
Source
BUILD_DEPENDENCIES
PUBLIC
Gem::${gem_name}.API
PRIVATE
Gem::${gem_name}.Private.Object
)

target_depends_on_ros2_packages(${gem_name}.Private.Object std_msgs std_srvs)

# By default, we will specify that the above target ${gem_name} would be used by
# Client and Server type targets when this gem is enabled. If you don't want it
# active in Clients or Servers by default, delete one of both of the following lines:
ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name})
ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})

# For the Client and Server variants of ${gem_name} Gem, an alias to the ${gem_name}.API target will be made
ly_create_alias(NAME ${gem_name}.Clients.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
ly_create_alias(NAME ${gem_name}.Servers.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
ly_create_alias(NAME ${gem_name}.Unified.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)

# Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
# for the Clients, Servers, Unified gem variants
o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Clients Servers Unified)

# If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Editor MODULE target
if(PAL_TRAIT_BUILD_HOST_TOOLS)
# The ${gem_name}.Editor.API target can be used by other gems that want to interact with the ${gem_name}.Editor module
ly_add_target(
NAME ${gem_name}.Editor.API INTERFACE
NAMESPACE Gem
FILES_CMAKE
geojsonspawner_editor_api_files.cmake
${pal_dir}/geojsonspawner_editor_api_files.cmake
INCLUDE_DIRECTORIES
INTERFACE
Include
BUILD_DEPENDENCIES
INTERFACE
AZ::AzToolsFramework
)

# The ${gem_name}.Editor.Private.Object target is an internal target
# which is only to be used by this gems CMakeLists.txt and any subdirectories
# Other gems should not use this target
ly_add_target(
NAME ${gem_name}.Editor.Private.Object STATIC
NAMESPACE Gem
FILES_CMAKE
geojsonspawner_editor_private_files.cmake
TARGET_PROPERTIES
O3DE_PRIVATE_TARGET TRUE
INCLUDE_DIRECTORIES
PRIVATE
Include
Source
BUILD_DEPENDENCIES
PUBLIC
AZ::AzToolsFramework
$<TARGET_OBJECTS:Gem::${gem_name}.Private.Object>
PRIVATE
Gem::ROS2.Editor.Static
)

ly_add_target(
NAME ${gem_name}.Editor GEM_MODULE
NAMESPACE Gem
AUTOMOC
FILES_CMAKE
geojsonspawner_editor_shared_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
Source
PUBLIC
Include
BUILD_DEPENDENCIES
PUBLIC
Gem::${gem_name}.Editor.API
PRIVATE
Gem::${gem_name}.Editor.Private.Object
Gem::ROS2.Editor.Static
)

target_depends_on_ros2_packages(${gem_name}.Editor.Private.Object std_srvs)

# By default, we will specify that the above target ${gem_name} would be used by
# Tool and Builder type targets when this gem is enabled. If you don't want it
# active in Tools or Builders by default, delete one of both of the following lines:
ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)

# For the Tools and Builders variants of ${gem_name} Gem, an alias to the ${gem_name}.Editor API target will be made
ly_create_alias(NAME ${gem_name}.Tools.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
ly_create_alias(NAME ${gem_name}.Builders.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)

# Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
# for the Tools and Builders gem variants
o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Tools Builders)
endif()

################################################################################
# Tests
################################################################################
# See if globally, tests are supported
if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
# We globally support tests, see if we support tests on this platform for ${gem_name}.Tests
if(PAL_TRAIT_GEOJSONSPAWNER_TEST_SUPPORTED)
# We support ${gem_name}.Tests on this platform, add dependency on the Private Object target
ly_add_target(
NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
NAMESPACE Gem
FILES_CMAKE
geojsonspawner_tests_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
Tests
Source
Include
BUILD_DEPENDENCIES
PRIVATE
AZ::AzTest
AZ::AzFramework
Gem::${gem_name}.Private.Object
)

# Add ${gem_name}.Tests to googletest
ly_add_googletest(
NAME Gem::${gem_name}.Tests
)
endif()

# If we are a host platform we want to add tools test like editor tests here
if(PAL_TRAIT_BUILD_HOST_TOOLS)
# We are a host platform, see if Editor tests are supported on this platform
if(PAL_TRAIT_GEOJSONSPAWNER_EDITOR_TEST_SUPPORTED)
# We support ${gem_name}.Editor.Tests on this platform, add ${gem_name}.Editor.Tests target which depends on
# private ${gem_name}.Editor.Private.Object target
ly_add_target(
NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
NAMESPACE Gem
FILES_CMAKE
geojsonspawner_editor_tests_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
Tests
Source
Include
BUILD_DEPENDENCIES
PRIVATE
AZ::AzTest
Gem::${gem_name}.Editor.Private.Object
)

# Add ${gem_name}.Editor.Tests to googletest
ly_add_googletest(
NAME Gem::${gem_name}.Editor.Tests
)
endif()
endif()
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (C) Robotec AI - All Rights Reserved
*
* This source code is protected under international copyright law. All rights
* reserved and protected by the copyright holders.
* This file is confidential and only available to authorized individuals with the
* permission of the copyright holders. If you encounter this file and do not have
* permission, please contact the copyright holders and delete this file.
*/

#pragma once

#include <AzCore/EBus/EBus.h>

namespace GeoJSONSpawner
{
using Result = AZ::Outcome<void, AZStd::string>;
using GetIdsResult = AZ::Outcome<AZStd::string, AZStd::string>;

//! Interface for the GeoJSONSpawner
//! Used for spawning, despawning and modifying prefabs described in the GeoJSON file
class GeoJSONSpawnerRequests : public AZ::ComponentBus
{
public:
using BusIdType = AZ::EntityId;
using MutexType = AZStd::mutex;

//! Spawn prefabs based on the information in provided GeoJSON. If there are already spawned entities on the scene, Component will
//! despawn all of them before spawning new ones.
//! @param rawJsonString - raw string with a GeoJSON to spawn
virtual Result SpawnWithRawString(const AZStd::string& rawJsonString) = 0;

//! Spawn prefabs using file from a given path. If there are already spawned entities on the scene, Component will despawn all of
//! them before spawning new ones.
//! @param assetPath - path to a file with a GeoJSON to spawn
virtual Result SpawnWithAssetPath(const AZ::IO::Path& assetPath) = 0;

//! Modify spawned prefabs based on the information in provided GeoJSON. Component will despawn all entities that are associated
//! with given group ids before spawning modified ones.
//! @param rawJsonString - raw string with a GeoJSON to modify
//! If any of the given ID does not exist then modify action will be canceled
virtual Result Modify(const AZStd::string& rawJsonString) = 0;

//! Delete all prefabs spawned with GeoJSONSpawner
virtual Result DeleteAll() = 0;

//! Delete prefabs based on the information in provided GeoJSON
//! @param idsToDelete - unordered set containing IDs to delete
virtual Result DeleteById(const AZStd::unordered_set<int>& idsToDelete) = 0;

//! Get all used IDs together with a number of spawned prefabs associated with each ID
//! @return AZStd::string with all IDs that are in use with a number of prefabs associated with each ID
virtual GetIdsResult GetIds() const = 0;
};

using GeoJSONSpawnerRequestBus = AZ::EBus<GeoJSONSpawnerRequests>;

} // namespace GeoJSONSpawner
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (C) Robotec AI - All Rights Reserved
*
* This source code is protected under international copyright law. All rights
* reserved and protected by the copyright holders.
* This file is confidential and only available to authorized individuals with the
* permission of the copyright holders. If you encounter this file and do not have
* permission, please contact the copyright holders and delete this file.
*/

#pragma once

namespace GeoJSONSpawner
{
// System Component TypeIds
inline constexpr const char* GeoJSONSpawnerSystemComponentTypeId = "{CD4EB5DE-E197-433A-B651-A0507E6A7138}";
inline constexpr const char* GeoJSONSpawnerEditorSystemComponentTypeId = "{6894C22F-7C51-4C87-92E0-83D93F42252C}";

// Module derived classes TypeIds
inline constexpr const char* GeoJSONSpawnerModuleInterfaceTypeId = "{457EB65D-5DFC-4341-BDE3-79D054485C58}";
inline constexpr const char* GeoJSONSpawnerModuleTypeId = "{E56013BF-CE3A-4AA5-81AD-698844BEA7C6}";
// The Editor Module by default is mutually exclusive with the Client Module
// so they use the Same TypeId
inline constexpr const char* GeoJSONSpawnerEditorModuleTypeId = GeoJSONSpawnerModuleTypeId;

// Editor Components TypeIds
inline constexpr const char* GeoJSONSpawnerEditorComponentTypeId = "{97d8cdeb-8a82-4bb0-adc3-c42a3eac21c7}";

// Configurations TypeIds
inline constexpr const char* GeoJSONSpawnableAssetConfigurationTypeId = "{cee254bb-edc8-45b1-b85a-aaf19ec3af83}";
inline constexpr const char* GeoJSONSpawnableEntityInfoTypeId = "{170bb487-fbae-4394-8176-069045a3a316}";
inline constexpr const char* FeatureObjectInfoTypeId = "{00f38302-9f4d-4bac-805b-72a29e42a704}";

// Components TypeIds
inline constexpr const char* GeoJSONSpawnerComponentTypeId = "{839ede69-92f1-45b0-a60e-035d0b84e1fd}";

// Interface TypeIds
inline constexpr const char* GeoJSONSpawnerRequestsTypeId = "{EE523E9E-CFDF-4590-BBDE-054848BBA790}";
} // namespace GeoJSONSpawner
4 changes: 4 additions & 0 deletions Gems/GeoJSONSpawner/Code/Platform/Android/PAL_android.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

set(PAL_TRAIT_GEOJSONSPAWNER_SUPPORTED TRUE)
set(PAL_TRAIT_GEOJSONSPAWNER_TEST_SUPPORTED FALSE)
set(PAL_TRAIT_GEOJSONSPAWNER_EDITOR_TEST_SUPPORTED FALSE)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

set(FILES
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Platform specific files for Android
# i.e. ../Source/Android/GeoJSONSpawnerAndroid.cpp
# ../Source/Android/GeoJSONSpawnerAndroid.h
# ../Include/Android/GeoJSONSpawnerAndroid.h

set(FILES
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Platform specific files for Android
# i.e. ../Source/Android/GeoJSONSpawnerAndroid.cpp
# ../Source/Android/GeoJSONSpawnerAndroid.h
# ../Include/Android/GeoJSONSpawnerAndroid.h

set(FILES
)
4 changes: 4 additions & 0 deletions Gems/GeoJSONSpawner/Code/Platform/Linux/PAL_linux.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

set(PAL_TRAIT_GEOJSONSPAWNER_SUPPORTED TRUE)
set(PAL_TRAIT_GEOJSONSPAWNER_TEST_SUPPORTED FALSE)
set(PAL_TRAIT_GEOJSONSPAWNER_EDITOR_TEST_SUPPORTED FALSE)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

set(FILES
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

set(FILES
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Platform specific files for Linux
# i.e. ../Source/Linux/GeoJSONSpawnerLinux.cpp
# ../Source/Linux/GeoJSONSpawnerLinux.h
# ../Include/Linux/GeoJSONSpawnerLinux.h

set(FILES
)
Loading
Loading