aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Workflow
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-08-15 09:17:02 -0700
committerrtk0c <[email protected]>2021-08-15 09:17:02 -0700
commit64a6dbcfdb89a5f57d93d47a2be0c741dda4662d (patch)
tree241eaba2351f3a7e6343ce93532e19a4b93757d3 /core/src/Model/Workflow
parentf0326e5c5deca0fb719d8522b45c59364b566300 (diff)
Fix issues and cleanup
- Fix compile error on MSVC where <vector> is not included properly - Fix creating a workflow actually saves to the templates/ directory - Fix renaming assets are not saved to disk - TODO ser/deser still not working - Cleanup AssetList::* pure virtual setup (fewer splits)
Diffstat (limited to 'core/src/Model/Workflow')
-rw-r--r--core/src/Model/Workflow/Value.hpp3
-rw-r--r--core/src/Model/Workflow/Workflow.hpp31
-rw-r--r--core/src/Model/Workflow/Workflow_Main.cpp84
3 files changed, 71 insertions, 47 deletions
diff --git a/core/src/Model/Workflow/Value.hpp b/core/src/Model/Workflow/Value.hpp
index ed35349..2198674 100644
--- a/core/src/Model/Workflow/Value.hpp
+++ b/core/src/Model/Workflow/Value.hpp
@@ -1,11 +1,12 @@
#pragma once
-#include "cplt_fwd.hpp"
#include "Utils/Color.hpp"
+#include "cplt_fwd.hpp"
#include <iosfwd>
#include <memory>
#include <string>
+#include <vector>
class BaseValue
{
diff --git a/core/src/Model/Workflow/Workflow.hpp b/core/src/Model/Workflow/Workflow.hpp
index cba0d72..c156582 100644
--- a/core/src/Model/Workflow/Workflow.hpp
+++ b/core/src/Model/Workflow/Workflow.hpp
@@ -7,13 +7,13 @@
#include <imgui_node_editor.h>
#include <cstddef>
-#include <span>
#include <cstdint>
#include <filesystem>
#include <functional>
#include <iosfwd>
#include <limits>
#include <memory>
+#include <span>
#include <string>
#include <variant>
#include <vector>
@@ -41,7 +41,7 @@ public:
void DrawDebugInfo() const;
void ReadFrom(std::istream& stream);
- void WriteTo(std::ostream& stream);
+ void WriteTo(std::ostream& stream) const;
};
class WorkflowNode
@@ -285,7 +285,7 @@ public:
RR_InvalidVersion,
};
ReadResult ReadFrom(std::istream& stream);
- void WriteTo(std::ostream& stream);
+ void WriteTo(std::ostream& stream) const;
private:
std::pair<WorkflowConnection&, uint32_t> AllocWorkflowConnection();
@@ -303,21 +303,18 @@ public:
// Inherit constructors
using AssetListTyped::AssetListTyped;
-public:
- virtual void DiscoverFiles(const std::function<void(SavedAsset)>& callback) const override;
-
- virtual std::string RetrieveNameFromFile(const std::filesystem::path& file) const override;
- virtual uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const override;
- virtual std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const override;
-
- virtual void SaveEmptyInstance(const SavedAsset& asset) const override;
- virtual Workflow* CreateEmptyInstance(const SavedAsset& diskForm) const override;
+protected:
+ void DiscoverFiles(const std::function<void(SavedAsset)>& callback) const override;
- virtual Workflow* LoadImpl(const SavedAsset& diskForm) const override;
+ std::string RetrieveNameFromFile(const std::filesystem::path& file) const override;
+ uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const override;
+ std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const override;
- virtual void DisplayAssetCreator(ListState& state) override;
+ bool SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const override;
+ Workflow* LoadInstance(const SavedAsset& assetInfo) const override;
+ Workflow* CreateInstance(const SavedAsset& assetInfo) const override;
+ bool RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const override;
- virtual void SetupDetailsTable(const char* tableId) const override;
- virtual void DrawBigIcon(ListState& state, const SavedAsset& asset) const override;
- virtual void DrawDetailsTableRow(ListState& state, const SavedAsset& asset) const override;
+ void DisplayAssetCreator(ListState& state) override;
+ void DisplayDetailsTable(ListState& state) const override;
};
diff --git a/core/src/Model/Workflow/Workflow_Main.cpp b/core/src/Model/Workflow/Workflow_Main.cpp
index 2dbed58..d502413 100644
--- a/core/src/Model/Workflow/Workflow_Main.cpp
+++ b/core/src/Model/Workflow/Workflow_Main.cpp
@@ -3,8 +3,8 @@
#include "Model/GlobalStates.hpp"
#include "Model/Project.hpp"
#include "UI/UI.hpp"
-#include "Utils/UUID.hpp"
#include "Utils/I18n.hpp"
+#include "Utils/UUID.hpp"
#include <imgui.h>
#include <imgui_node_editor.h>
@@ -57,7 +57,7 @@ void WorkflowConnection::ReadFrom(std::istream& stream)
stream >> DestinationNode >> DestinationPin;
}
-void WorkflowConnection::WriteTo(std::ostream& stream)
+void WorkflowConnection::WriteTo(std::ostream& stream) const
{
stream << SourceNode << SourcePin;
stream << DestinationNode << DestinationPin;
@@ -393,7 +393,7 @@ Workflow::GlobalPinId Workflow::DisassembleGlobalPinId(ImNodes::PinId pinId)
// Therefore we encode one ourselves
// Global pin id format
- // nnnnnnnn nnnnnnnn nnnnnnnn nnnnnnnn Tppppppp pppppppp pppppppp pppppppp
+ // nnnnnnnn nnnnnnnn nnnnnnnn nnnnnnnn Tppppppp ppppppppp pppppppp pppppppp
// <------- (32 bits) node id -------> ^<------ (31 bits) pin id -------->
// | (1 bit) input (false) vs output (true)
@@ -676,7 +676,7 @@ Workflow::ReadResult Workflow::ReadFrom(std::istream& stream)
return RR_Success;
}
-void Workflow::WriteTo(std::ostream& stream)
+void Workflow::WriteTo(std::ostream& stream) const
{
// Version
stream << (uint64_t)0;
@@ -775,35 +775,63 @@ uuids::uuid WorkflowAssetList::RetrieveUuidFromFile(const fs::path& file) const
fs::path WorkflowAssetList::RetrievePathFromAsset(const SavedAsset& asset) const
{
auto fileName = uuids::to_string(asset.Uuid);
- return GetConnectedProject().GetTemplatePath(fileName);
+ return GetConnectedProject().GetWorkflowPath(fileName);
}
-void WorkflowAssetList::SaveEmptyInstance(const SavedAsset& asset) const
+bool WorkflowAssetList::SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const
{
- auto path = RetrievePathFromAsset(asset);
+ auto path = RetrievePathFromAsset(assetInfo);
std::ofstream ofs(path);
- if (!ofs) return;
- ofs << (uint64_t)asset.Name.size();
- ofs << asset.Name;
-}
+ if (!ofs) return false;
+ ofs << (uint64_t)assetInfo.Name.size();
+ ofs << assetInfo.Name;
-Workflow* WorkflowAssetList::CreateEmptyInstance(const SavedAsset& asset) const
-{
- return new Workflow();
+ if (auto workflow = static_cast<const Workflow*>(asset)) {
+ workflow->WriteTo(ofs);
+ }
+
+ return true;
}
-Workflow* WorkflowAssetList::LoadImpl(const SavedAsset& asset) const
+static std::unique_ptr<Workflow> LoadWorkflowFromFile(const fs::path& path)
{
- std::ifstream ifs(RetrievePathFromAsset(asset));
+ std::ifstream ifs(path);
if (!ifs) return nullptr;
+ // TODO fix serialization
+ uint64_t nameSize;
+ ifs >> nameSize;
+ ifs.seekg(nameSize, std::ios::end);
+
auto workflow = std::make_unique<Workflow>();
if (workflow->ReadFrom(ifs) != Workflow::RR_Success) {
return nullptr;
}
- return workflow.release();
+ return workflow;
+}
+
+Workflow* WorkflowAssetList::LoadInstance(const SavedAsset& assetInfo) const
+{
+ return ::LoadWorkflowFromFile(RetrievePathFromAsset(assetInfo)).release();
+}
+
+Workflow* WorkflowAssetList::CreateInstance(const SavedAsset& assetInfo) const
+{
+ return new Workflow();
+}
+
+bool WorkflowAssetList::RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const
+{
+ auto path = RetrievePathFromAsset(assetInfo);
+
+ auto workflow = ::LoadWorkflowFromFile(path);
+ if (!workflow) return false;
+
+ SaveInstance(assetInfo, workflow.get());
+
+ return true;
}
void WorkflowAssetList::DisplayAssetCreator(ListState& state)
@@ -863,23 +891,21 @@ void WorkflowAssetList::DisplayAssetCreator(ListState& state)
}
}
-void WorkflowAssetList::SetupDetailsTable(const char* tableId) const
+void WorkflowAssetList::DisplayDetailsTable(ListState& state) const
{
- ImGui::BeginTable(tableId, 1, ImGuiTableFlags_Borders);
+ ImGui::BeginTable("AssetDetailsTable", 1, ImGuiTableFlags_Borders);
ImGui::TableSetupColumn(I18N_TEXT("Name", L10N_NAME));
ImGui::TableHeadersRow();
-}
-void WorkflowAssetList::DrawBigIcon(ListState& state, const SavedAsset& asset) const
-{
- // TODO
-}
+ for (auto& asset : this->GetAssets()) {
+ ImGui::TableNextRow();
-void WorkflowAssetList::DrawDetailsTableRow(ListState& state, const SavedAsset& asset) const
-{
- ImGui::TableNextColumn();
- if (ImGui::Selectable(asset.Name.c_str(), state.SelectedAsset == &asset, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_DontClosePopups)) {
- state.SelectedAsset = &asset;
+ ImGui::TableNextColumn();
+ if (ImGui::Selectable(asset.Name.c_str(), state.SelectedAsset == &asset, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_DontClosePopups)) {
+ state.SelectedAsset = &asset;
+ }
}
+
+ ImGui::EndTable();
}