Merge branch 'main' into hultonha_LYN-2772_whitebox-atom

This commit is contained in:
hultonha
2021-04-22 15:41:46 +01:00
5 changed files with 186 additions and 27 deletions
@@ -0,0 +1,46 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/Debug/TraceMessageBus.h>
#include <AzCore/std/containers/list.h>
#include <AzCore/std/string/string.h>
namespace AtomToolsFramework
{
// Records all TraceMessageBus activity to a string
class TraceRecorder : private AZ::Debug::TraceMessageBus::Handler
{
public:
AZ_TYPE_INFO(AtomToolsFramework::TraceRecorder, "{7B49AFD0-D0AB-4CB7-A4B5-6D88D30DCBFD}");
TraceRecorder(size_t maxMessageCount = std::numeric_limits<size_t>::max());
~TraceRecorder();
//! Get the combined output of all messages
AZStd::string GetDump() const;
private:
//////////////////////////////////////////////////////////////////////////
// AZ::Debug::TraceMessageBus::Handler overrides...
bool OnAssert(const char* /*message*/) override;
bool OnException(const char* /*message*/) override;
bool OnError(const char* /*window*/, const char* /*message*/) override;
bool OnWarning(const char* /*window*/, const char* /*message*/) override;
bool OnPrintf(const char* /*window*/, const char* /*message*/) override;
//////////////////////////////////////////////////////////////////////////
size_t m_maxMessageCount = std::numeric_limits<size_t>::max();
AZStd::list<AZStd::string> m_messages;
};
} // namespace AtomToolsFramework
@@ -0,0 +1,81 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AtomToolsFramework/Debug/TraceRecorder.h>
#include <AzCore/StringFunc/StringFunc.h>
namespace AtomToolsFramework
{
TraceRecorder::TraceRecorder(size_t maxMessageCount)
: m_maxMessageCount(maxMessageCount)
{
AZ::Debug::TraceMessageBus::Handler::BusConnect();
}
TraceRecorder::~TraceRecorder()
{
AZ::Debug::TraceMessageBus::Handler::BusDisconnect();
}
AZStd::string TraceRecorder::GetDump() const
{
AZStd::string dump;
AZ::StringFunc::Join(dump, m_messages.begin(), m_messages.end(), "\n");
return dump;
}
bool TraceRecorder::OnAssert(const char* message)
{
if (m_messages.size() < m_maxMessageCount)
{
m_messages.push_back(AZStd::string::format("Assert: %s", message));
}
return false;
}
bool TraceRecorder::OnException(const char* message)
{
if (m_messages.size() < m_maxMessageCount)
{
m_messages.push_back(AZStd::string::format("Exception: %s", message));
}
return false;
}
bool TraceRecorder::OnError(const char* /*window*/, const char* message)
{
if (m_messages.size() < m_maxMessageCount)
{
m_messages.push_back(AZStd::string::format("Error: %s", message));
}
return false;
}
bool TraceRecorder::OnWarning(const char* /*window*/, const char* message)
{
if (m_messages.size() < m_maxMessageCount)
{
m_messages.push_back(AZStd::string::format("Warning: %s", message));
}
return false;
}
bool TraceRecorder::OnPrintf(const char* /*window*/, const char* message)
{
if (m_messages.size() < m_maxMessageCount)
{
m_messages.push_back(AZStd::string::format("%s", message));
}
return false;
}
} // namespace AtomToolsFramework
@@ -10,6 +10,7 @@
#
set(FILES
Include/AtomToolsFramework/Debug/TraceRecorder.h
Include/AtomToolsFramework/DynamicProperty/DynamicProperty.h
Include/AtomToolsFramework/DynamicProperty/DynamicPropertyGroup.h
Include/AtomToolsFramework/Inspector/InspectorWidget.h
@@ -21,6 +22,7 @@ set(FILES
Include/AtomToolsFramework/Util/MaterialPropertyUtil.h
Include/AtomToolsFramework/Util/Util.h
Include/AtomToolsFramework/Viewport/RenderViewportWidget.h
Source/Debug/TraceRecorder.cpp
Source/DynamicProperty/DynamicProperty.cpp
Source/DynamicProperty/DynamicPropertyGroup.cpp
Source/Inspector/InspectorWidget.cpp
@@ -12,32 +12,29 @@
#include <Document/MaterialDocumentSystemComponent.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzFramework/Asset/AssetSystemBus.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
#include <AzToolsFramework/AssetBrowser/AssetSelectionModel.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
#include <AzToolsFramework/API/ViewPaneOptions.h>
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
#include <AtomToolsFramework/Util/Util.h>
#include <Atom/Document/MaterialDocumentNotificationBus.h>
#include <Atom/Document/MaterialDocumentRequestBus.h>
#include <Atom/Document/MaterialDocumentSystemRequestBus.h>
#include <Atom/RPI.Edit/Material/MaterialSourceData.h>
#include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
#include <Atom/Document/MaterialDocumentSystemRequestBus.h>
#include <Atom/Document/MaterialDocumentRequestBus.h>
#include <Atom/Document/MaterialDocumentNotificationBus.h>
#include <AtomToolsFramework/Debug/TraceRecorder.h>
#include <AtomToolsFramework/Util/Util.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzFramework/Asset/AssetSystemBus.h>
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
#include <AzToolsFramework/API/ViewPaneOptions.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
#include <AzToolsFramework/AssetBrowser/AssetSelectionModel.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT
#include <QApplication>
#include <QFileDialog>
#include <QMessageBox>
#include <QString>
#include <QStyle>
#include <QMessageBox>
#include <QFileDialog>
AZ_POP_DISABLE_WARNING
namespace MaterialEditor
@@ -212,11 +209,15 @@ namespace MaterialEditor
QString("Would you like to reopen the document:\n%1?").arg(documentPath.c_str()),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
{
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool openResult = false;
MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Open, documentPath);
if (!openResult)
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be opened:\n%1").arg(documentPath.c_str()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be opened"),
QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId);
}
}
@@ -232,11 +233,15 @@ namespace MaterialEditor
QString("Would you like to update the document with these changes:\n%1?").arg(documentPath.c_str()),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
{
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool openResult = false;
MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Rebuild);
if (!openResult)
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be opened:\n%1").arg(documentPath.c_str()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be opened"),
QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId);
}
}
@@ -308,11 +313,15 @@ namespace MaterialEditor
}
}
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool closeResult = true;
MaterialDocumentRequestBus::EventResult(closeResult, documentId, &MaterialDocumentRequestBus::Events::Close);
if (!closeResult)
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be closed:\n%1").arg(documentPath.c_str()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be closed"),
QString("Failed to close: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
@@ -370,11 +379,15 @@ namespace MaterialEditor
return false;
}
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool result = false;
MaterialDocumentRequestBus::EventResult(result, documentId, &MaterialDocumentRequestBus::Events::Save);
if (!result)
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be saved:\n%1").arg(saveMaterialPath.c_str()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveMaterialPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
@@ -396,11 +409,15 @@ namespace MaterialEditor
return false;
}
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool result = false;
MaterialDocumentRequestBus::EventResult(result, documentId, &MaterialDocumentRequestBus::Events::SaveAsCopy, saveMaterialPath);
if (!result)
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be saved:\n%1").arg(saveMaterialPath.c_str()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveMaterialPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
@@ -422,11 +439,15 @@ namespace MaterialEditor
return false;
}
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
bool result = false;
MaterialDocumentRequestBus::EventResult(result, documentId, &MaterialDocumentRequestBus::Events::SaveAsChild, saveMaterialPath);
if (!result)
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be saved:\n%1").arg(saveMaterialPath.c_str()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be saved"),
QString("Failed to save: \n%1\n\n%2").arg(saveMaterialPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return false;
}
@@ -476,19 +497,27 @@ namespace MaterialEditor
}
}
AtomToolsFramework::TraceRecorder traceRecorder(m_maxMessageBoxLineCount);
AZ::Uuid documentId = AZ::Uuid::CreateNull();
MaterialDocumentSystemRequestBus::BroadcastResult(documentId, &MaterialDocumentSystemRequestBus::Events::CreateDocument);
if (documentId.IsNull())
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be created:\n%1").arg(requestedPath.c_str()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be created"),
QString("Failed to create: \n%1\n\n%2").arg(requestedPath.c_str()).arg(traceRecorder.GetDump().c_str()));
return AZ::Uuid::CreateNull();
}
traceRecorder.GetDump().clear();
bool openResult = false;
MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Open, requestedPath);
if (!openResult)
{
QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be opened:\n%1").arg(requestedPath.c_str()));
QMessageBox::critical(
QApplication::activeWindow(), QString("Material document could not be opened"),
QString("Failed to open: \n%1\n\n%2").arg(requestedPath.c_str()).arg(traceRecorder.GetDump().c_str()));
MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::DestroyDocument, documentId);
return AZ::Uuid::CreateNull();
}
@@ -98,5 +98,6 @@ namespace MaterialEditor
AZStd::unordered_set<AZ::Uuid> m_documentIdsToRebuild;
AZStd::unordered_set<AZ::Uuid> m_documentIdsToReopen;
AZStd::unique_ptr<MaterialEditorSettings> m_settings;
const size_t m_maxMessageBoxLineCount = 15;
};
}