50 return "Data Provider";
72 static int FilterSingleCharacter(ImGuiInputTextCallbackData* data)
74 while (data->BufTextLen > 1)
76 data->BufDirty =
true;
77 data->DeleteChars(1, 1);
84 if (ImGui::InputText(fmt::format(
"Delimiter character##{}",
size_t(
id)).c_str(), &tmpStr, ImGuiInputTextFlags_CallbackEdit, TextFilters::FilterSingleCharacter))
86 _delimiter = tmpStr.empty() ?
'\0' : tmpStr.at(0);
96 if (ImGui::InputText(fmt::format(
"Comment character##{}",
size_t(
id)).c_str(), &tmpStr, ImGuiInputTextFlags_CallbackEdit, TextFilters::FilterSingleCharacter))
98 _comment = tmpStr.empty() ?
'\0' : tmpStr.at(0);
111 if (ImGui::Checkbox(fmt::format(
"Header line##{}",
size_t(
id)).c_str(), &
_hasHeaderLine))
120 ImGui::Text(
"Amount of data lines in file: %zu",
_data.lines.size());
123 if (ImGui::BeginTable(fmt::format(
"##CSVHeaders ({})",
size_t(
id)).c_str(), 2,
124 ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
126 ImGui::TableSetupColumn(
"", ImGuiTableColumnFlags_WidthFixed);
127 ImGui::TableSetupColumn(
"Description", ImGuiTableColumnFlags_WidthFixed);
128 ImGui::TableHeadersRow();
130 for (
size_t i = 0; i <
_data.description.size(); i++)
132 ImGui::TableNextRow();
133 ImGui::TableNextColumn();
134 ImGui::Text(
"%zu", i);
135 ImGui::TableNextColumn();
136 ImGui::TextUnformatted(
_data.description[i].c_str());
162 if (j.contains(
"FileReader"))
166 if (j.contains(
"delimiter"))
170 if (j.contains(
"comment"))
174 if (j.contains(
"skipLines"))
178 if (j.contains(
"hasHeaderLine"))
188 _data.description.clear();
197 std::vector<size_t> emptyCols{};
201 if (line.empty() || line.at(0) ==
_comment) {
continue; }
204 if (!splittedData.empty()) {
_data.lines.emplace_back(); }
206 for (
size_t i = 0; i < splittedData.size(); i++)
208 const auto& cell = splittedData.at(i);
210 if (cell.empty() && std::ranges::find(emptyCols, i) == emptyCols.end())
212 emptyCols.push_back(i);
213 LOG_WARN(
"{}: Data missing in column: '{}' at: {} s and possibly afterwards, too.",
nameId(),
_data.description.at(i), splittedData.front());
219 value = std::stod(cell);
225 _data.lines.back().push_back(value);
229 LOG_TRACE(
"{}: initialize() finished. Read {} columns over {} lines.",
nameId(),
_data.description.size(),
_data.lines.size());
244 _data.description.clear();
257 for (
int i = 0; i <
_skipLines; i++) {
ignore(std::numeric_limits<std::streamsize>::max(),
'\n'); }
264 for (
auto& desc :
_data.description)
266 desc.erase(std::ranges::find_if(desc, [](
int ch) {
return std::iscntrl(ch); }), desc.end());
nlohmann::json json
json namespace
Utility class for logging to console and file.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
#define LOG_WARN
Error occurred, but a fallback option exists and program continues to work normally.
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Utility functions for working with std::strings.
static std::string type()
Returns the type of the data class.
std::variant< double, std::string > CsvElement
CSV Elements (number or if not convertible to number as std::string)
void guiConfig() override
ImGui config window which is shown on double click.
FileType determineFileType() override
Determines the type of the file.
bool initialize() override
Initialize the node.
int _skipLines
Amount of lines to skip at the start.
void deinitialize() override
Deinitialize the node.
static std::string category()
String representation of the Class Category.
CsvFile()
Default constructor.
char _comment
Comment character.
void readHeader() override
Read the Header of the file.
std::string type() const override
String representation of the Class Type.
void restore(const json &j) override
Restores the node from a json object.
~CsvFile() override
Destructor.
char _delimiter
Delimiter character.
CsvData _data
Data container.
bool _hasHeaderLine
Flag whether there is a header line at the start.
bool resetNode() override
Resets the node. It is guaranteed that the node is initialized when this is called.
static std::string typeStatic()
String representation of the Class Type.
json save() const override
Saves the node into a json object.
bool initialize()
Initialize the file reader.
void restore(const json &j)
Restores the node from a json object.
std::string _path
Path to the file.
FileType
File Type Enumeration.
auto & ignore(std::streamsize count, int delim)
Extracts and discards characters from the input stream until and including delim.
auto eof() const
Check whether the end of file is reached.
@ PATH_CHANGED
The path changed and exists.
GuiResult guiConfig(const char *vFilters, const std::vector< std::string > &extensions, size_t id, const std::string &nameId)
ImGui config.
auto & getline(std::string &str)
Reads a line from the filestream.
json save() const
Saves the node into a json object.
void deinitialize()
Deinitialize the file reader.
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
ImVec2 _guiConfigDefaultWindowSize
Node(std::string name)
Constructor.
bool doInitialize(bool wait=false)
Asks the node worker to initialize the node.
std::string nameId() const
Node name and id.
std::string name
Name of the Node.
bool doReinitialize(bool wait=false)
Asks the node worker to reinitialize the node.
bool _hasConfig
Flag if the config window should be shown.
bool InputIntL(const char *label, int *v, int v_min, int v_max, int step, int step_fast, ImGuiInputTextFlags flags)
Shows a value limited InputText GUI element for 'int'.
OutputPin * CreateOutputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier, OutputPin::PinData data=static_cast< void * >(nullptr), int idx=-1)
Create an Output Pin object.
void ApplyChanges()
Signals that there have been changes to the flow.
static std::vector< std::string > split(const std::string &str, const std::string &delimiter)
Splits a string into parts at a delimiter.