Skip to content

Commit

Permalink
Merge pull request #3 from cgalvan/cgalvan/AddedPythonShapeExample
Browse files Browse the repository at this point in the history
Added Python version of the Shape Example.
  • Loading branch information
cgalvan authored Nov 1, 2021
2 parents 2686bab + 3caeda7 commit 148c0f7
Show file tree
Hide file tree
Showing 28 changed files with 519 additions and 0 deletions.
7 changes: 7 additions & 0 deletions py_gems/PyShapeExample/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

set(o3de_gem_path ${CMAKE_CURRENT_LIST_DIR})
set(o3de_gem_json ${o3de_gem_path}/gem.json)
o3de_read_json_key(o3de_gem_name ${o3de_gem_json} "gem_name")
o3de_restricted_path(${o3de_gem_json} o3de_gem_restricted_path)

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

# 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: ly_get_list_relative_pal_filename 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/PyShapeExample/Code/Platform/<platorm_name> or
# <restricted_folder>/<platform_name>/Gems/PyShapeExample/Code
ly_get_list_relative_pal_filename(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} ${o3de_gem_restricted_path} ${o3de_gem_path} ${o3de_gem_name})

# 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)


# If we are on a host platform, we want to add the host tools targets like the PyShapeExample.Editor target which
# will also depend on PyShapeExample.Static
if(PAL_TRAIT_BUILD_HOST_TOOLS)
ly_add_target(
NAME PyShapeExample.Editor.Static STATIC
NAMESPACE Gem
AUTORCC
FILES_CMAKE
pyshapeexample_editor_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
Source
PUBLIC
Include
BUILD_DEPENDENCIES
PUBLIC
AZ::AzToolsFramework
)

ly_add_target(
NAME PyShapeExample.Editor GEM_MODULE
NAMESPACE Gem
AUTOMOC
FILES_CMAKE
pyshapeexample_editor_shared_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
Source
PUBLIC
Include
BUILD_DEPENDENCIES
PUBLIC
Gem::PyShapeExample.Editor.Static
)

# By default, we will specify that the above target PyShapeExample 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 PyShapeExample.Tools NAMESPACE Gem TARGETS Gem::PyShapeExample.Editor)
ly_create_alias(NAME PyShapeExample.Builders NAMESPACE Gem TARGETS Gem::PyShapeExample.Editor)


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 PyShapeExample.Static

# If we are a host platform we want to add tools test like editor tests here
if(PAL_TRAIT_BUILD_HOST_TOOLS)
endif()
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

#pragma once

#include <AzCore/EBus/EBus.h>
#include <AzCore/Interface/Interface.h>

namespace PyShapeExample
{
class PyShapeExampleRequests
{
public:
AZ_RTTI(PyShapeExampleRequests, "{fc0caa1d-9f70-48be-b78a-fcdc853c87e2}");
virtual ~PyShapeExampleRequests() = default;
// Put your public methods here
};

class PyShapeExampleBusTraits
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////
};

using PyShapeExampleRequestBus = AZ::EBus<PyShapeExampleRequests, PyShapeExampleBusTraits>;
using PyShapeExampleInterface = AZ::Interface<PyShapeExampleRequests>;

} // namespace PyShapeExample
4 changes: 4 additions & 0 deletions py_gems/PyShapeExample/Code/Platform/Linux/PAL_linux.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

set(PAL_TRAIT_PYSHAPEEXAMPLE_SUPPORTED TRUE)
set(PAL_TRAIT_PYSHAPEEXAMPLE_TEST_SUPPORTED TRUE)
set(PAL_TRAIT_PYSHAPEEXAMPLE_EDITOR_TEST_SUPPORTED TRUE)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

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

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/PyShapeExampleLinux.cpp
# ../Source/Linux/PyShapeExampleLinux.h
# ../Include/Linux/PyShapeExampleLinux.h

set(FILES
)
4 changes: 4 additions & 0 deletions py_gems/PyShapeExample/Code/Platform/Mac/PAL_mac.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

set(PAL_TRAIT_PYSHAPEEXAMPLE_SUPPORTED TRUE)
set(PAL_TRAIT_PYSHAPEEXAMPLE_TEST_SUPPORTED TRUE)
set(PAL_TRAIT_PYSHAPEEXAMPLE_EDITOR_TEST_SUPPORTED TRUE)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Platform specific files for Mac
# i.e. ../Source/Mac/PyShapeExampleMac.cpp
# ../Source/Mac/PyShapeExampleMac.h
# ../Include/Mac/PyShapeExampleMac.h

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

# Platform specific files for Mac
# i.e. ../Source/Mac/PyShapeExampleMac.cpp
# ../Source/Mac/PyShapeExampleMac.h
# ../Include/Mac/PyShapeExampleMac.h

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

set(PAL_TRAIT_PYSHAPEEXAMPLE_SUPPORTED TRUE)
set(PAL_TRAIT_PYSHAPEEXAMPLE_TEST_SUPPORTED TRUE)
set(PAL_TRAIT_PYSHAPEEXAMPLE_EDITOR_TEST_SUPPORTED TRUE)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

# Platform specific files for Windows
# i.e. ../Source/Windows/PyShapeExampleWindows.cpp
# ../Source/Windows/PyShapeExampleWindows.h
# ../Include/Windows/PyShapeExampleWindows.h

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

# Platform specific files for Windows
# i.e. ../Source/Windows/PyShapeExampleWindows.cpp
# ../Source/Windows/PyShapeExampleWindows.h
# ../Include/Windows/PyShapeExampleWindows.h

set(FILES
)
5 changes: 5 additions & 0 deletions py_gems/PyShapeExample/Code/Source/PyShapeExample.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/PyShapeExample">
<file alias="toolbar_icon.svg">toolbar_icon.svg</file>
</qresource>
</RCC>
46 changes: 46 additions & 0 deletions py_gems/PyShapeExample/Code/Source/PyShapeExampleEditorModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

#include <PyShapeExampleModuleInterface.h>
#include <PyShapeExampleEditorSystemComponent.h>

void InitPyShapeExampleResources()
{
// We must register our Qt resources (.qrc file) since this is being loaded from a separate module (gem)
Q_INIT_RESOURCE(PyShapeExample);
}

namespace PyShapeExample
{
class PyShapeExampleEditorModule
: public PyShapeExampleModuleInterface
{
public:
AZ_RTTI(PyShapeExampleEditorModule, "{cebbfc02-eab9-4c61-b0de-31795b1c044a}", PyShapeExampleModuleInterface);
AZ_CLASS_ALLOCATOR(PyShapeExampleEditorModule, AZ::SystemAllocator, 0);

PyShapeExampleEditorModule()
{
InitPyShapeExampleResources();

// Push results of [MyComponent]::CreateDescriptor() into m_descriptors here.
// Add ALL components descriptors associated with this gem to m_descriptors.
// This will associate the AzTypeInfo information for the components with the the SerializeContext, BehaviorContext and EditContext.
// This happens through the [MyComponent]::Reflect() function.
m_descriptors.insert(m_descriptors.end(), {
PyShapeExampleEditorSystemComponent::CreateDescriptor(),
});
}

/**
* Add required SystemComponents to the SystemEntity.
* Non-SystemComponents should not be added here
*/
AZ::ComponentTypeList GetRequiredSystemComponents() const override
{
return AZ::ComponentTypeList {
azrtti_typeid<PyShapeExampleEditorSystemComponent>(),
};
}
};
}// namespace PyShapeExample

AZ_DECLARE_MODULE_CLASS(Gem_PyShapeExample, PyShapeExample::PyShapeExampleEditorModule)
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

#include <AzCore/Serialization/SerializeContext.h>
#include <PyShapeExampleEditorSystemComponent.h>

namespace PyShapeExample
{
void PyShapeExampleEditorSystemComponent::Reflect(AZ::ReflectContext* context)
{
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<PyShapeExampleEditorSystemComponent, AZ::Component>();
}
}

PyShapeExampleEditorSystemComponent::PyShapeExampleEditorSystemComponent()
{
if (PyShapeExampleInterface::Get() == nullptr)
{
PyShapeExampleInterface::Register(this);
}
}

PyShapeExampleEditorSystemComponent::~PyShapeExampleEditorSystemComponent()
{
if (PyShapeExampleInterface::Get() == this)
{
PyShapeExampleInterface::Unregister(this);
}
}

void PyShapeExampleEditorSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC_CE("PyShapeExampleEditorService"));
}

void PyShapeExampleEditorSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC_CE("PyShapeExampleEditorService"));
}

void PyShapeExampleEditorSystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
{
}

void PyShapeExampleEditorSystemComponent::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
{
}

void PyShapeExampleEditorSystemComponent::Activate()
{
PyShapeExampleRequestBus::Handler::BusConnect();
AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
}

void PyShapeExampleEditorSystemComponent::Deactivate()
{
AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
PyShapeExampleRequestBus::Handler::BusDisconnect();
}

} // namespace PyShapeExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

#pragma once
#include <AzCore/Component/Component.h>
#include <PyShapeExample/PyShapeExampleBus.h>

#include <AzToolsFramework/Entity/EditorEntityContextBus.h>

namespace PyShapeExample
{
/// System component for PyShapeExample editor
class PyShapeExampleEditorSystemComponent
: public PyShapeExampleRequestBus::Handler
, private AzToolsFramework::EditorEvents::Bus::Handler
, public AZ::Component
{
public:
AZ_COMPONENT(PyShapeExampleEditorSystemComponent, "{a4475498-5700-4502-885b-3406dc685a4c}");
static void Reflect(AZ::ReflectContext* context);

PyShapeExampleEditorSystemComponent();
~PyShapeExampleEditorSystemComponent();

private:
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);

// AZ::Component
void Activate();
void Deactivate();
};
} // namespace PyShapeExample
27 changes: 27 additions & 0 deletions py_gems/PyShapeExample/Code/Source/PyShapeExampleModuleInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/Module/Module.h>

namespace PyShapeExample
{
class PyShapeExampleModuleInterface
: public AZ::Module
{
public:
AZ_RTTI(PyShapeExampleModuleInterface, "{f8731810-a6e3-403d-af72-ee81424ef59c}", AZ::Module);
AZ_CLASS_ALLOCATOR(PyShapeExampleModuleInterface, AZ::SystemAllocator, 0);

PyShapeExampleModuleInterface()
{
}

/**
* Add required SystemComponents to the SystemEntity.
*/
AZ::ComponentTypeList GetRequiredSystemComponents() const override
{
return AZ::ComponentTypeList{
};
}
};
}// namespace PyShapeExample
1 change: 1 addition & 0 deletions py_gems/PyShapeExample/Code/Source/toolbar_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#include <AzTest/AzTest.h>

AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);
8 changes: 8 additions & 0 deletions py_gems/PyShapeExample/Code/pyshapeexample_editor_files.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

set(FILES
Include/PyShapeExample/PyShapeExampleBus.h
Source/PyShapeExampleModuleInterface.h
Source/PyShapeExampleEditorSystemComponent.cpp
Source/PyShapeExampleEditorSystemComponent.h
Source/PyShapeExample.qrc
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

set(FILES
Source/PyShapeExampleEditorModule.cpp
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

set(FILES
Tests/PyShapeExampleEditorTest.cpp
)
9 changes: 9 additions & 0 deletions py_gems/PyShapeExample/Editor/Scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Copyright (c) Contributors to the Open 3D Engine Project.
For complete copyright and license terms please see the LICENSE at the root of this distribution.
SPDX-License-Identifier: Apache-2.0 OR MIT
"""
# -------------------------------------------------------------------------

__ALL__ = ['bootstrap','pyshapeexample_dialog']
Binary file not shown.
Loading

0 comments on commit 148c0f7

Please sign in to comment.