aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/Model')
-rw-r--r--core/src/Model/Project.hpp2
-rw-r--r--core/src/Model/Template/TableTemplate.cpp17
-rw-r--r--core/src/Model/Template/TableTemplate.hpp23
-rw-r--r--core/src/Model/Template/Template.hpp4
-rw-r--r--core/src/Model/Template/Template_Main.cpp2
-rw-r--r--core/src/Model/Workflow/Values/BasicValues.cpp16
-rw-r--r--core/src/Model/Workflow/Workflow.hpp44
-rw-r--r--core/src/Model/Workflow/Workflow_Main.cpp16
8 files changed, 71 insertions, 53 deletions
diff --git a/core/src/Model/Project.hpp b/core/src/Model/Project.hpp
index bce58c2..1eca09d 100644
--- a/core/src/Model/Project.hpp
+++ b/core/src/Model/Project.hpp
@@ -59,7 +59,7 @@ public:
const tsl::array_map<char, TemplateInfo>& GetTemplates() const;
std::unique_ptr<Template> LoadTemplate(std::string_view name);
- bool InsertTemplate(std::string_view name, TemplateInfo info);
+ TemplateInfo* InsertTemplate(std::string_view name, TemplateInfo info);
bool RemoveTemplate(std::string_view name);
bool RenameTemplate(std::string_view oldName, std::string_view newName);
diff --git a/core/src/Model/Template/TableTemplate.cpp b/core/src/Model/Template/TableTemplate.cpp
index 0ad1cca..b8444b7 100644
--- a/core/src/Model/Template/TableTemplate.cpp
+++ b/core/src/Model/Template/TableTemplate.cpp
@@ -1,6 +1,7 @@
#include "TableTemplate.hpp"
#include <xlsxwriter.h>
+#include <iostream>
#include <map>
bool TableCell::IsDataHoldingCell() const
@@ -189,14 +190,14 @@ TableTemplate::BreakCellsResult TableTemplate::BreakCells(Vec2i topLeft)
return BCR_Success;
}
-lxw_workbook* TableTemplate::InstanciateToExcelWorkbook(const TableInstanciationParameters& params) const
+lxw_workbook* TableTemplate::InstantiateToExcelWorkbook(const TableInstanciationParameters& params) const
{
auto workbook = workbook_new("Table.xlsx");
- InstanciateToExcelWorksheet(workbook, params);
+ InstantiateToExcelWorksheet(workbook, params);
return workbook;
}
-lxw_worksheet* TableTemplate::InstanciateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const
+lxw_worksheet* TableTemplate::InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const
{
auto worksheet = workbook_add_worksheet(workbook, "CpltExport.xlsx");
@@ -301,3 +302,13 @@ lxw_worksheet* TableTemplate::InstanciateToExcelWorksheet(lxw_workbook* workbook
return worksheet;
}
+Template::ReadResult TableTemplate::ReadFrom(std::istream& stream)
+{
+ // TODO
+ return ReadResult::RR_Success;
+}
+
+void TableTemplate::WriteTo(std::ostream& stream) const
+{
+ // TODO
+}
diff --git a/core/src/Model/Template/TableTemplate.hpp b/core/src/Model/Template/TableTemplate.hpp
index 688192a..f7a79e9 100644
--- a/core/src/Model/Template/TableTemplate.hpp
+++ b/core/src/Model/Template/TableTemplate.hpp
@@ -34,12 +34,12 @@ public:
Vec2i Location;
/// Location of the primary (top left) cell, if this cell is a part of a merged group.
/// Otherwise, either component of this field shall be -1.
- Vec2i PrimaryCellLocation;
- int SpanX;
- int SpanY;
- TextAlignment HorizontalAlignment = AlignAxisMin;
- TextAlignment VerticalAlignment = AlignAxisMin;
- CellType Type;
+ Vec2i PrimaryCellLocation{ -1, -1 };
+ int SpanX = 0;
+ int SpanY = 0;
+ TextAlignment HorizontalAlignment = AlignCenter;
+ TextAlignment VerticalAlignment = AlignCenter;
+ CellType Type = ConstantCell;
/// The id of the group description object, if this cell isn't a constant or singluar parameter cell. Otherwise, this value is -1.
int DataId = -1;
@@ -56,7 +56,7 @@ public:
// TODO support horizontal filling order
/// Parameter group information for a grouped array of cells. When instanciated, an array of 0 or more
/// elements shall be provided by the user, which will replace the group of templated cells with a list
-/// of rows, each instanciated with the n-th element in the provided array.
+/// of rows, each instantiated with the n-th element in the provided array.
/// \code
/// [["foo", "bar", "foobar"],
/// ["a", "b", c"],
@@ -124,7 +124,7 @@ public:
const TableTemplate& GetTable() const;
};
-/// A table template, where individual cells can be filled by workflows instanciating this template. Merged cells,
+/// A table template, where individual cells can be filled by workflows instantiating this template. Merged cells,
/// parametric rows/columns, and grids are also supported.
///
/// This current supports exporting to xlsx files.
@@ -163,6 +163,9 @@ public:
};
BreakCellsResult BreakCells(Vec2i topLeft);
- lxw_workbook* InstanciateToExcelWorkbook(const TableInstanciationParameters& params) const;
- lxw_worksheet* InstanciateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const;
+ lxw_workbook* InstantiateToExcelWorkbook(const TableInstanciationParameters& params) const;
+ lxw_worksheet* InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const;
+
+ virtual ReadResult ReadFrom(std::istream& stream) override;
+ virtual void WriteTo(std::ostream& stream) const override;
};
diff --git a/core/src/Model/Template/Template.hpp b/core/src/Model/Template/Template.hpp
index 0901a1b..f7dd898 100644
--- a/core/src/Model/Template/Template.hpp
+++ b/core/src/Model/Template/Template.hpp
@@ -29,8 +29,8 @@ public:
RR_Success,
RR_InvalidFormat,
};
- ReadResult ReadFrom(std::istream& stream) = 0;
- void WriteTo(std::ostream& stream) const = 0;
+ virtual ReadResult ReadFrom(std::istream& stream) = 0;
+ virtual void WriteTo(std::ostream& stream) const = 0;
};
class TemplateInfo
diff --git a/core/src/Model/Template/Template_Main.cpp b/core/src/Model/Template/Template_Main.cpp
index eeb6871..08437b7 100644
--- a/core/src/Model/Template/Template_Main.cpp
+++ b/core/src/Model/Template/Template_Main.cpp
@@ -2,4 +2,6 @@
std::unique_ptr<Template> TemplateInfo::LoadFromDisk() const
{
+ // TODO
+ return nullptr;
}
diff --git a/core/src/Model/Workflow/Values/BasicValues.cpp b/core/src/Model/Workflow/Values/BasicValues.cpp
index a7cf635..748c652 100644
--- a/core/src/Model/Workflow/Values/BasicValues.cpp
+++ b/core/src/Model/Workflow/Values/BasicValues.cpp
@@ -14,14 +14,13 @@ NumericValue::NumericValue()
{
}
-template <class T>
+template <class T, int kMaxSize>
static std::string NumberToString(T value)
{
- constexpr auto kSize = std::numeric_limits<T>::max_digits10;
- char buf[kSize];
+ char buf[kMaxSize];
#if PLATFORM_WIN32
- auto res = std::to_chars(buf, buf + kSize, value);
+ auto res = std::to_chars(buf, buf + kMaxSize, value);
if (res.ec == std::errc()) {
return std::string(buf, res.ptr);
} else {
@@ -35,17 +34,20 @@ static std::string NumberToString(T value)
std::string NumericValue::GetTruncatedString() const
{
- return ::NumberToString((int64_t)mValue);
+ constexpr auto kMaxSize = std::numeric_limits<int64_t>::digits10;
+ return ::NumberToString<int64_t, kMaxSize>((int64_t)mValue);
}
std::string NumericValue::GetRoundedString() const
{
- return ::NumberToString((int64_t)std::round(mValue));
+ constexpr auto kMaxSize = std::numeric_limits<int64_t>::digits10;
+ return ::NumberToString<int64_t, kMaxSize>((int64_t)std::round(mValue));
}
std::string NumericValue::GetString() const
{
- return ::NumberToString(mValue);
+ constexpr auto kMaxSize = std::numeric_limits<double>::max_digits10;
+ return ::NumberToString<double, kMaxSize>(mValue);
}
int64_t NumericValue::GetInt() const
diff --git a/core/src/Model/Workflow/Workflow.hpp b/core/src/Model/Workflow/Workflow.hpp
index ded9bfb..161400e 100644
--- a/core/src/Model/Workflow/Workflow.hpp
+++ b/core/src/Model/Workflow/Workflow.hpp
@@ -5,6 +5,7 @@
#include "cplt_fwd.hpp"
#include <imgui_node_editor.h>
+#include <any>
#include <cstddef>
#include <cstdint>
#include <filesystem>
@@ -240,34 +241,27 @@ public:
/* Graph rebuild */
- struct GraphUpdateResult
+ enum GraphUpdateResult
{
- struct Success
- {
- };
-
- struct NoWorkToDo
- {
- };
-
- struct UnsatisfiedDependencies
- {
- std::vector<uint32_t> UnsatisfiedNodes;
- };
-
- struct UnreachableNodes
- {
- std::vector<uint32_t> UnreachableNodes;
- };
-
- using T = std::variant<
- Success,
- NoWorkToDo,
- UnsatisfiedDependencies,
- UnreachableNodes>;
+ /// Successfully rebuilt graph dependent data.
+ /// Details: nothing is written.
+ GUR_Success,
+ /// Nothing has changed since last time UpdateGraph() was called.
+ /// Details: nothing is written.
+ GUR_NoWorkToDo,
+ /// Details: list of nodes is written.
+ GUR_UnsatisfiedDependencies,
+ /// Details: list of nodes is written.
+ GUR_UnreachableNodes,
};
- GraphUpdateResult::T UpdateGraph();
+ using GraphUpdateDetails = std::variant<
+ // Case: nothing
+ std::monostate,
+ // Case: list of nodes (ids)
+ std::vector<uint32_t>>;
+
+ GraphUpdateResult UpdateGraph(GraphUpdateDetails* details = nullptr);
/* Serialization */
diff --git a/core/src/Model/Workflow/Workflow_Main.cpp b/core/src/Model/Workflow/Workflow_Main.cpp
index bfe007c..61cd510 100644
--- a/core/src/Model/Workflow/Workflow_Main.cpp
+++ b/core/src/Model/Workflow/Workflow_Main.cpp
@@ -524,10 +524,10 @@ bool Workflow::DisconnectByDestination(WorkflowNode& destinationNode, uint32_t d
return true;
}
-Workflow::GraphUpdateResult::T Workflow::UpdateGraph()
+Workflow::GraphUpdateResult Workflow::UpdateGraph(GraphUpdateDetails* details)
{
if (!mDepthsDirty) {
- return GraphUpdateResult::NoWorkToDo{};
+ return GUR_NoWorkToDo;
}
// Terminology:
@@ -577,7 +577,10 @@ Workflow::GraphUpdateResult::T Workflow::UpdateGraph()
}
if (!unsatisfiedNodes.empty()) {
- return GraphUpdateResult::UnsatisfiedDependencies{ std::move(unsatisfiedNodes) };
+ if (details) {
+ details->emplace<decltype(unsatisfiedNodes)>(std::move(unsatisfiedNodes));
+ }
+ return GUR_UnsatisfiedDependencies;
}
}
@@ -624,10 +627,13 @@ Workflow::GraphUpdateResult::T Workflow::UpdateGraph()
unreachableNodes.push_back(i);
}
- return GraphUpdateResult::UnreachableNodes{ std::move(unreachableNodes) };
+ if (details) {
+ details->emplace<decltype(unreachableNodes)>(std::move(unreachableNodes));
+ }
+ return GUR_UnreachableNodes;
}
- return GraphUpdateResult::Success{};
+ return GUR_Success;
}
Workflow::ReadResult Workflow::ReadFrom(std::istream& stream)