diff options
Diffstat (limited to 'core/src/Model')
-rw-r--r-- | core/src/Model/GlobalStates.cpp | 4 | ||||
-rw-r--r-- | core/src/Model/Template/TableTemplate.cpp | 31 | ||||
-rw-r--r-- | core/src/Model/Template/TableTemplate.hpp | 53 | ||||
-rw-r--r-- | core/src/Model/Template/fwd.hpp | 4 | ||||
-rw-r--r-- | core/src/Model/Workflow/Values/BasicValues.cpp | 5 |
5 files changed, 92 insertions, 5 deletions
diff --git a/core/src/Model/GlobalStates.cpp b/core/src/Model/GlobalStates.cpp index a9b6806..2230367 100644 --- a/core/src/Model/GlobalStates.cpp +++ b/core/src/Model/GlobalStates.cpp @@ -28,7 +28,7 @@ void GlobalStates::Init(std::filesystem::path userDataDir) fs::create_directories(globalDataPath); // Reading recent projects - [&]() { + { std::ifstream ifs(globalDataPath / "recents.json"); if (!ifs) return; @@ -50,7 +50,7 @@ void GlobalStates::Init(std::filesystem::path userDataDir) }); } } - }(); + } } void GlobalStates::Shutdown() diff --git a/core/src/Model/Template/TableTemplate.cpp b/core/src/Model/Template/TableTemplate.cpp index caf0e21..0684c77 100644 --- a/core/src/Model/Template/TableTemplate.cpp +++ b/core/src/Model/Template/TableTemplate.cpp @@ -1,5 +1,7 @@ #include "TableTemplate.hpp" +#include <xlsxwriter.h> + bool TableCell::IsPrimaryCell() const { return PrimaryCellLocation == Location; @@ -117,3 +119,32 @@ TableTemplate::BreakCellsResult TableTemplate::BreakCells(Vec2i topLeft) return BCR_Success; } + +lxw_workbook* TableTemplate::InstanciateToExcelWorkbook(const TableInstanciationParameters& params) const +{ + auto workbook = workbook_new("Table.xlsx"); + InstanciateToExcelWorksheet(workbook, params); + return workbook; +} + +lxw_worksheet* TableTemplate::InstanciateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const +{ + auto worksheet = workbook_add_worksheet(workbook, "Cplt Export"); + + for (int y = 0; y < mTableHeight; ++y) { + for (int x = 0; x < mTableWidth; ++x) { + auto& cell = GetCell({ x, y }); + switch (cell.Type) { + case TableCell::ConstantCell: { + worksheet_write_string(worksheet, y, x, cell.Content.c_str(), nullptr); + } break; + + case TableCell::ParametricCell: { + // TODO + } break; + } + } + } + + return worksheet; +} diff --git a/core/src/Model/Template/TableTemplate.hpp b/core/src/Model/Template/TableTemplate.hpp index d704b1f..6454ccd 100644 --- a/core/src/Model/Template/TableTemplate.hpp +++ b/core/src/Model/Template/TableTemplate.hpp @@ -1,8 +1,10 @@ -#pragma once +#pragma once #include "Utils/Vector.hpp" #include "Utils/VectorHash.hpp" +#include "cplt_fwd.hpp" +#include <tsl/robin_map.h> #include <string> #include <vector> @@ -42,6 +44,32 @@ public: bool IsMergedCell() const; }; +/// Parameter group information for a grouped array of cells, either horizontal or vertical. +/// These cells can have "expansion behavior", i.e. when instanciating, a list of cell values would be provided by +/// the caller: +/// \code +/// [["foo", "bar", "foobar"], +/// ["a", "b", c"], +/// ["1", "2", "3"], +/// ["x", "y", "z"]] +/// // ... may be more +/// \endcode +/// +/// For a array parameter group that vertically expands, this would create 4 rows of data in the place of the +/// original parameter group. If more than one array parameter groups are on the same row, they would share space +/// between each other : +/// +/// \code +/// | 2 elements was fed to it +/// | | 1 element was fed to it +/// V V +/// {~~~~~~~~~~~~~~~~}{~~~~~~~~~~~~~~} +/// +------+---------+---------------+ +/// | Foo | Example | Another group | +/// +------+---------+---------------+ +/// | Cool | Example | | +/// +------+---------+---------------+ +/// \endcode class TableArrayParameterGroup { public: @@ -57,6 +85,26 @@ public: ExpansionDirection ExpandDirection; }; +// Forward declaration of libxlsxwriter structs +struct lxw_workbook; +struct lxw_worksheet; + +/// An object containing the necessary information to instanciate a table template. +/// \see TableTemplate +class TableInstanciationParameters +{ +private: + TableTemplate* mTemplate; + tsl::robin_map<Vec2i, std::string> ParametricCells; + +public: + // TODO +}; + +/// A table template, where individual cells can be filled by workflows instanciating this template. Merged cells, +/// parametric rows/columns, and grids are also supported. +/// +/// This current supports exporting to xlsx files. class TableTemplate { private: @@ -86,4 +134,7 @@ public: BCR_Success, }; BreakCellsResult BreakCells(Vec2i topLeft); + + lxw_workbook* InstanciateToExcelWorkbook(const TableInstanciationParameters& params) const; + lxw_worksheet* InstanciateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const; }; diff --git a/core/src/Model/Template/fwd.hpp b/core/src/Model/Template/fwd.hpp index 2bf6814..d62552f 100644 --- a/core/src/Model/Template/fwd.hpp +++ b/core/src/Model/Template/fwd.hpp @@ -2,6 +2,6 @@ // TableTemplate.hpp class TableCell; -class ConstantTableCell; -class ParametricTableCell; +class TableArrayParameterGroup; +class TableInstanciationParameters; class TableTemplate; diff --git a/core/src/Model/Workflow/Values/BasicValues.cpp b/core/src/Model/Workflow/Values/BasicValues.cpp index 93ee366..a7cf635 100644 --- a/core/src/Model/Workflow/Values/BasicValues.cpp +++ b/core/src/Model/Workflow/Values/BasicValues.cpp @@ -20,12 +20,17 @@ static std::string NumberToString(T value) constexpr auto kSize = std::numeric_limits<T>::max_digits10; char buf[kSize]; +#if PLATFORM_WIN32 auto res = std::to_chars(buf, buf + kSize, value); if (res.ec == std::errc()) { return std::string(buf, res.ptr); } else { return "<err>"; } +#else + // TODO libstdc++ doesn't have floating point charconv yet + return std::to_string(value); +#endif } std::string NumericValue::GetTruncatedString() const |