diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..a33e4c79 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 # Use the ref you want to point at + hooks: + - id: check-merge-conflict +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v16.0.6 + hooks: + - id: clang-format + types_or: [c++, c] \ No newline at end of file diff --git a/clang-format.txt b/clang-format.txt new file mode 100644 index 00000000..2303c58e --- /dev/null +++ b/clang-format.txt @@ -0,0 +1,195 @@ +--- +Language: Cpp +AccessModifierOffset: -4 +AlignAfterOpenBracket: AlwaysBreak +AlignArrayOfStructures: Right +AlignConsecutiveMacros: Consecutive +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveBitFields: Consecutive +AlignConsecutiveDeclarations: Consecutive +AlignEscapedNewlines: Left +AlignOperands: AlignAfterOperator +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: OnlyFirstIf +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __capability +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: MultiLine + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakBeforeBinaryOperators: All +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeComma +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 100 +CommentPragmas: ^NOLINT +QualifierAlignment: Right +CompactNamespaces: true +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: true +DeriveLineEnding: false +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: CurrentLine +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: true +IndentGotoLabels: false +IndentPPDirectives: BeforeHash +IndentExternBlock: NoIndent +IndentRequires: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 100 +PenaltyExcessCharacter: 10000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Left +PPIndentWidth: -1 +RawStringFormats: + - Language: Cpp + CanonicalDelimiter: '' + BasedOnStyle: '' +ReferenceAlignment: Pointer +ReflowComments: false +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: Never +SpaceBeforeParensOptions: + AfterControlStatements: false + AfterForeachMacros: false + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: false + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 3 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... + diff --git a/languages/Deutsch.json b/languages/Deutsch.json index 824caf7b..9fa30032 100644 --- a/languages/Deutsch.json +++ b/languages/Deutsch.json @@ -4,7 +4,11 @@ "height": "Höhe ", "width": "Breite" }, - "helplink": "Hilfeseite", + "savepopup": { + "new_car": "Neues Fahrzeug", + "known_cars": "Bekannte Fahrzeuge" + }, + "helplink": "Klicken Sie auf den Button um zur Hilfeseite zu gelangen", "input": { "fin": { "label": "Fin/Vin", @@ -92,4 +96,4 @@ "switchfail": "Fehler, Switchcase mit unerwarteter Auswahl", "upload_success": "Upload erfolgreich!" } -} +} \ No newline at end of file diff --git a/src/create_training_data.hpp b/src/create_training_data.hpp index 4be47e62..9eca4d3a 100644 --- a/src/create_training_data.hpp +++ b/src/create_training_data.hpp @@ -3,6 +3,7 @@ #include #include +#include "look_up_saves.hpp" #include #include #include @@ -14,93 +15,92 @@ // clang-format off #include // clang-format on - -static void show_standart_input(nlohmann::json const &language, +static void show_standart_input(nlohmann::json const &config, + nlohmann::json const &language, nlohmann::json &metadata, std::string &inputvin_string, std::string &mileage_string, std::string &comment_string) { - static char inputvin[18]; - static char mileage[10]; - static char comment[1000]; - - ImVec2 windowSize = ImGui::GetWindowSize(); - ImGui::BeginChild("trainingleft", - ImVec2(windowSize.x * 0.5f, windowSize.y * 0.8f)); - ImGui::TextUnformatted( - load_json(language, "training", "base_data").c_str()); - ImGui::InputText( - load_json(language, "input", "fin", "label").c_str(), - inputvin, sizeof(inputvin)); - ImGui::InputText( - load_json(language, "input", "mileage", "label").c_str(), - mileage, sizeof(mileage)); - static bool problem = false; - static bool maintenance = !problem; - - static bool electric_on = false; - static bool electric_off = !electric_on; - - static bool expected = true; - static bool anomaly = !expected; - ImGui::TextUnformatted( - load_json(language, "training", "reason").c_str()); - ImGui::Checkbox( - load_json(language, "training", "maintenance").c_str(), - &maintenance); - if (maintenance == problem) { - problem = !maintenance; - } - ImGui::SameLine(); - ImGui::Checkbox( - load_json(language, "training", "problem").c_str(), - &problem); - if (problem == maintenance) { - maintenance = !problem; - } - - ImGui::TextUnformatted( - load_json(language, "training", "electrical_consumer") - .c_str()); - ImGui::Checkbox( - load_json(language, "training", "switched_off").c_str(), - &electric_off); - if (electric_off == electric_on) { - electric_on = !electric_off; - } - ImGui::SameLine(); - ImGui::Checkbox( - load_json(language, "training", "switched_on").c_str(), - &electric_on); - if (electric_on == electric_off) { - electric_off = !electric_on; - } - ImGui::TextUnformatted( - load_json(language, "training", "evaluation").c_str()); - ImGui::Checkbox( - load_json(language, "training", "normal_case").c_str(), - &expected); - if (expected == anomaly) { - anomaly = !expected; - } - ImGui::SameLine(); - ImGui::Checkbox( - load_json(language, "training", "anomaly").c_str(), - &anomaly); - if (anomaly == expected) { - expected = !anomaly; - } - ImGui::InputTextMultiline( - load_json(language, "input", "comment", "label").c_str(), - comment, sizeof(comment)); - - ImGui::EndChild(); - inputvin_string = inputvin; - mileage_string = mileage; - comment_string = comment; - metadata["Elektrische Verbraucher ausgeschaltet:"] = electric_off; - metadata["Grund des Werkstattbesuchs Wartung"] = maintenance; - metadata["Anormales Verhalten"] = anomaly; + static std::string inputvin; + static char mileage[10]; + static char comment[1000]; + + ImVec2 windowSize = ImGui::GetWindowSize(); + ImGui::BeginChild("trainingleft", + ImVec2(windowSize.x * 0.5f, windowSize.y * 0.8f)); + ImGui::TextUnformatted( + load_json(language, "training", "base_data").c_str()); + inputvin = getSubdirectoriesInFolder( + language, load_json(config, "scanfolder")); + ImGui::InputText( + load_json(language, "input", "mileage", "label").c_str(), + mileage, sizeof(mileage)); + static bool problem = false; + static bool maintenance = !problem; + + static bool electric_on = false; + static bool electric_off = !electric_on; + + static bool expected = true; + static bool anomaly = !expected; + ImGui::TextUnformatted( + load_json(language, "training", "reason").c_str()); + ImGui::Checkbox( + load_json(language, "training", "maintenance").c_str(), + &maintenance); + if (maintenance == problem) { + problem = !maintenance; + } + ImGui::SameLine(); + ImGui::Checkbox( + load_json(language, "training", "problem").c_str(), + &problem); + if (problem == maintenance) { + maintenance = !problem; + } + + ImGui::TextUnformatted( + load_json(language, "training", "electrical_consumer") + .c_str()); + ImGui::Checkbox( + load_json(language, "training", "switched_off").c_str(), + &electric_off); + if (electric_off == electric_on) { + electric_on = !electric_off; + } + ImGui::SameLine(); + ImGui::Checkbox( + load_json(language, "training", "switched_on").c_str(), + &electric_on); + if (electric_on == electric_off) { + electric_off = !electric_on; + } + ImGui::TextUnformatted( + load_json(language, "training", "evaluation").c_str()); + ImGui::Checkbox( + load_json(language, "training", "normal_case").c_str(), + &expected); + if (expected == anomaly) { + anomaly = !expected; + } + ImGui::SameLine(); + ImGui::Checkbox( + load_json(language, "training", "anomaly").c_str(), + &anomaly); + if (anomaly == expected) { + expected = !anomaly; + } + ImGui::InputTextMultiline( + load_json(language, "input", "comment", "label").c_str(), + comment, sizeof(comment)); + + ImGui::EndChild(); + inputvin_string = inputvin; + mileage_string = mileage; + comment_string = comment; + metadata["Elektrische Verbraucher ausgeschaltet:"] = electric_off; + metadata["Grund des Werkstattbesuchs Wartung"] = maintenance; + metadata["Anormales Verhalten"] = anomaly; } static void selected_vcds_data(nlohmann::json const &config, @@ -108,323 +108,361 @@ static void selected_vcds_data(nlohmann::json const &config, nlohmann::json &metadata, std::string &inputvin, std::string &mileage, std::string &comment, std::string &api_message, bool &upload_success) { - ImGui::TextUnformatted( - load_json(language, "explanation", "upload", "vcds") - .c_str()); - static ImGui::FileBrowser fileBrowser; - static bool first_job = true; - - if (first_job) { - fileBrowser.SetPwd( - load_json(config, "scanfolder")); - first_job = false; + ImGui::TextUnformatted( + load_json(language, "explanation", "upload", "vcds") + .c_str()); + static ImGui::FileBrowser fileBrowser; + static bool first_job = true; + static bool flagApiSending = false; + static std::future future; + + if (first_job) { + fileBrowser.SetPwd(load_json(config, "scanfolder")); + first_job = false; + } + + static char path1[255]; + + ImGui::InputText("##path1", path1, sizeof(path1)); + ImGui::SameLine(); + if (ImGui::Button(fmt::format("{} 1", load_json( + language, "button", "file")) + .c_str())) { + fileBrowser.Open(); + } + fileBrowser.Display(); + if (fileBrowser.HasSelected()) { + std::string filepath; + for (auto const &selectedFile : fileBrowser.GetSelected()) { + if (!filepath.empty()) { + filepath += "/"; + } + filepath += selectedFile.string(); } + strcpy(path1, filepath.c_str()); - static char path1[255]; - - ImGui::InputText("##path1", path1, sizeof(path1)); - ImGui::SameLine(); - if (ImGui::Button(fmt::format("{} 1", load_json( - language, "button", "file")) - .c_str())) { - fileBrowser.Open(); - } - fileBrowser.Display(); - if (fileBrowser.HasSelected()) { - std::string filepath; - for (auto const &selectedFile : fileBrowser.GetSelected()) { - if (!filepath.empty()) { - filepath += "/"; - } - filepath += selectedFile.string(); - } - strcpy(path1, filepath.c_str()); - - fileBrowser.ClearSelected(); - } - ImGui::Columns(1); + fileBrowser.ClearSelected(); + } + ImGui::Columns(1); + using namespace std::chrono_literals; + if (!flagApiSending) { if (ImGui::Button( load_json(language, "button", "send").c_str(), ImVec2(load_json(config, "button")))) { - // Api muss angepasst werden und die funktion send to api ebenso + metadata["kommentar"] = comment; + metadata["laufleistung"] = mileage; - metadata["kommentar"] = comment; - metadata["laufleistung"] = mileage; - ImGui::Text("Loading %c", "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]); - api_message = send_to_api( + future = std::async(std::launch::async, [&] { + std::string result = send_to_api( config, path1, inputvin, load_json(language, "measuretype", "vcds"), metadata); - upload_success = true; - ImGui::CloseCurrentPopup(); + return result; + }); + flagApiSending = true; } - ImGui::EndChild(); + } + if (flagApiSending) { + ImGui::PushStyleColor( + ImGuiCol_Text, load_json(config, "text", "color", "inactive")); + if (ImGui::Button( + load_json(language, "button", "send").c_str(), + ImVec2(load_json(config, "button")))) { + } + ImGui::PopStyleColor(); + auto status = future.wait_for(10ms); + if (status == std::future_status::ready) { + upload_success = true; + flagApiSending = false; + if (future.valid()) { + api_message = future.get(); + } + ImGui::CloseCurrentPopup(); + } else { + ImGui::SameLine(); + ImGui::Text("senden... %c", "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]); + } + } + ImGui::EndChild(); } inline void selected_battery_measurement( nlohmann::json const &config, nlohmann::json const &language, nlohmann::json &metadata, std::string &inputvin, std::string &mileage, std::string &comment, std::string &api_message, bool &upload_success) { - ImGui::TextUnformatted( - load_json(language, "explanation", "upload", "battery") - .c_str()); - static ImGui::FileBrowser fileBrowser; - static bool first_job = true; - static bool flagApiSending = false; - static std::future future; - - if (first_job) { - fileBrowser.SetPwd( - load_json(config, "scanfolder")); - first_job = false; + ImGui::TextUnformatted( + load_json(language, "explanation", "upload", "battery") + .c_str()); + static ImGui::FileBrowser fileBrowser; + static bool first_job = true; + static bool flagApiSending = false; + static std::future future; + + if (first_job) { + fileBrowser.SetPwd(load_json(config, "scanfolder")); + first_job = false; + } + + static char path1[255]; + ImGui::InputText("##path1", path1, sizeof(path1)); + ImGui::SameLine(); + if (ImGui::Button(fmt::format("{} 1", load_json( + language, "button", "file")) + .c_str())) { + fileBrowser.Open(); + } + + fileBrowser.Display(); + if (fileBrowser.HasSelected()) { + std::string filepath; + for (auto const &selectedFile : fileBrowser.GetSelected()) { + if (!filepath.empty()) { + filepath += "/"; + } + filepath += selectedFile.string(); } + strcpy(path1, filepath.c_str()); - static char path1[255]; - ImGui::InputText("##path1", path1, sizeof(path1)); - ImGui::SameLine(); - if (ImGui::Button(fmt::format("{} 1", load_json( - language, "button", "file")) - .c_str())) { - fileBrowser.Open(); - } + fileBrowser.ClearSelected(); + } + ImGui::Columns(1); + using namespace std::chrono_literals; + if (!flagApiSending) { + if (ImGui::Button( + load_json(language, "button", "send").c_str(), + ImVec2(load_json(config, "button")))) { + metadata["kommentar"] = comment; + metadata["laufleistung"] = mileage; - fileBrowser.Display(); - if (fileBrowser.HasSelected()) { - std::string filepath; - for (auto const &selectedFile : fileBrowser.GetSelected()) { - if (!filepath.empty()) { - filepath += "/"; - } - filepath += selectedFile.string(); - } - strcpy(path1, filepath.c_str()); - - fileBrowser.ClearSelected(); + future = std::async(std::launch::async, [&] { + std::string result = send_to_api( + config, path1, inputvin, + load_json(language, "measuretype", "battery"), + metadata); + return result; + }); + flagApiSending = true; } - ImGui::Columns(1); - using namespace std::chrono_literals; - if (!flagApiSending) { - if (ImGui::Button( - load_json(language, "button", "send").c_str(), - ImVec2(load_json(config, "button")))) { - metadata["kommentar"] = comment; - metadata["laufleistung"] = mileage; - - future = std::async(std::launch::async, [&] { - std::string result = send_to_api( - config, path1, inputvin, - load_json(language, "measuretype", "battery"), - metadata); - return result; - }); - flagApiSending = true; - - /* - api_message = send_to_api( - config, path1, inputvin, - load_json(language, "measuretype", - "battery"), metadata); - */ - } + } + if (flagApiSending) { + ImGui::PushStyleColor( + ImGuiCol_Text, load_json(config, "text", "color", "inactive")); + if (ImGui::Button( + load_json(language, "button", "send").c_str(), + ImVec2(load_json(config, "button")))) { } - if (flagApiSending) { - ImGui::PushStyleColor( - ImGuiCol_Text, - load_json(config, "text", "color", "inactive")); - if (ImGui::Button( - load_json(language, "button", "send").c_str(), - ImVec2(load_json(config, "button")))) { - } - ImGui::PopStyleColor(); - auto status = future.wait_for(10ms); - if (status == std::future_status::ready) { - upload_success = true; - flagApiSending = false; - if (future.valid()) { - api_message = future.get(); - } - ImGui::CloseCurrentPopup(); - } else { - ImGui::SameLine(); - ImGui::Text("senden... %c", - "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]); - } + ImGui::PopStyleColor(); + auto status = future.wait_for(10ms); + if (status == std::future_status::ready) { + upload_success = true; + flagApiSending = false; + if (future.valid()) { + api_message = future.get(); + } + ImGui::CloseCurrentPopup(); + } else { + ImGui::SameLine(); + ImGui::Text("senden... %c", "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]); } - ImGui::EndChild(); + } + ImGui::EndChild(); } static void selected_compression_data( nlohmann::json const &config, nlohmann::json const &language, nlohmann::json &metadata, std::string &inputvin, std::string &mileage, std::string &comment, std::string &api_message, bool &upload_success) { - static ImGui::FileBrowser fileBrowser; - static ImGui::FileBrowser fileBrowser2; - static bool first_job = true; - - if (first_job) { - fileBrowser.SetPwd( - load_json(config, "scanfolder")); - fileBrowser2.SetPwd( - load_json(config, "scanfolder")); - first_job = false; - } - - static float z1, z2, z3, z4; - static char path1[255]; - static char path2[255]; - const std::string cylinder = - load_json(language, "training", "compression", "cylinder"); - - ImGui::TextUnformatted(load_json(language, "training", - "compression", - "max_compression") - .c_str()); - - ImGui::TextUnformatted(cylinder.c_str()); - ImGui::SameLine(); - ImGui::Text("1:"); - ImGui::SameLine(); - ImGui::InputFloat("##Zylinder1", &z1, 0.0f, 0.0f, "%.2f bar"); - ImGui::TextUnformatted(cylinder.c_str()); - ImGui::SameLine(); - ImGui::Text("2:"); - ImGui::SameLine(); - ImGui::InputFloat("##Zylinder2", &z2, 0.0f, 0.0f, "%.2f bar"); - ImGui::TextUnformatted(cylinder.c_str()); - ImGui::SameLine(); - ImGui::Text("3:"); - ImGui::SameLine(); - ImGui::InputFloat("##Zylinder3", &z3, 0.0f, 0.0f, "%.2f bar"); - ImGui::TextUnformatted(cylinder.c_str()); - ImGui::SameLine(); - ImGui::Text("4:"); - ImGui::SameLine(); - ImGui::InputFloat("##Zylinder4", &z4, 0.0f, 0.0f, "%.2f bar"); - - ImGui::Columns(2); - ImGui::TextUnformatted(load_json(language, "training", - "compression", - "ignition_suspended") - .c_str()); - ImGui::TextUnformatted(load_json(language, "training", - "compression", - "ignition_active") - .c_str()); - ImGui::NextColumn(); - - ImGui::InputText("##path1", path1, sizeof(path1)); - ImGui::SameLine(); - const std::string button1 = - load_json(language, "button", "file") + " 1"; - const std::string button2 = - load_json(language, "button", "file") + " 2"; - if (ImGui::Button(button1.c_str())) { - fileBrowser.Open(); + static ImGui::FileBrowser fileBrowser; + static ImGui::FileBrowser fileBrowser2; + static bool first_job = true; + static bool flagApiSending = false; + static std::future future; + + if (first_job) { + fileBrowser.SetPwd(load_json(config, "scanfolder")); + fileBrowser2.SetPwd(load_json(config, "scanfolder")); + first_job = false; + } + + static float z1, z2, z3, z4; + static char path1[255]; + static char path2[255]; + const std::string cylinder = + load_json(language, "training", "compression", "cylinder"); + + ImGui::TextUnformatted(load_json(language, "training", + "compression", + "max_compression") + .c_str()); + + ImGui::TextUnformatted(cylinder.c_str()); + ImGui::SameLine(); + ImGui::Text("1:"); + ImGui::SameLine(); + ImGui::InputFloat("##Zylinder1", &z1, 0.0f, 0.0f, "%.2f bar"); + ImGui::TextUnformatted(cylinder.c_str()); + ImGui::SameLine(); + ImGui::Text("2:"); + ImGui::SameLine(); + ImGui::InputFloat("##Zylinder2", &z2, 0.0f, 0.0f, "%.2f bar"); + ImGui::TextUnformatted(cylinder.c_str()); + ImGui::SameLine(); + ImGui::Text("3:"); + ImGui::SameLine(); + ImGui::InputFloat("##Zylinder3", &z3, 0.0f, 0.0f, "%.2f bar"); + ImGui::TextUnformatted(cylinder.c_str()); + ImGui::SameLine(); + ImGui::Text("4:"); + ImGui::SameLine(); + ImGui::InputFloat("##Zylinder4", &z4, 0.0f, 0.0f, "%.2f bar"); + + ImGui::Columns(2); + ImGui::TextUnformatted(load_json(language, "training", + "compression", + "ignition_suspended") + .c_str()); + ImGui::TextUnformatted(load_json(language, "training", + "compression", + "ignition_active") + .c_str()); + ImGui::NextColumn(); + + ImGui::InputText("##path1", path1, sizeof(path1)); + ImGui::SameLine(); + const std::string button1 = + load_json(language, "button", "file") + " 1"; + const std::string button2 = + load_json(language, "button", "file") + " 2"; + if (ImGui::Button(button1.c_str())) { + fileBrowser.Open(); + } + fileBrowser.Display(); + if (fileBrowser.HasSelected()) { + std::string filepath; + for (auto const &selectedFile : fileBrowser.GetSelected()) { + if (!filepath.empty()) { + filepath += "/"; + } + filepath += selectedFile.string(); } - fileBrowser.Display(); - if (fileBrowser.HasSelected()) { - std::string filepath; - for (auto const &selectedFile : fileBrowser.GetSelected()) { - if (!filepath.empty()) { - filepath += "/"; - } - filepath += selectedFile.string(); - } - strcpy(path1, filepath.c_str()); - - fileBrowser.ClearSelected(); + strcpy(path1, filepath.c_str()); + + fileBrowser.ClearSelected(); + } + + ImGui::InputText("##path2", path2, sizeof(path2)); + ImGui::SameLine(); + if (ImGui::Button(button2.c_str())) { + fileBrowser2.Open(); + } + fileBrowser2.Display(); + if (fileBrowser2.HasSelected()) { + std::string filepath; + for (auto const &selectedFile : fileBrowser2.GetSelected()) { + if (!filepath.empty()) { + filepath += "/"; + } + filepath += selectedFile.string(); } + strcpy(path2, filepath.c_str()); - ImGui::InputText("##path2", path2, sizeof(path2)); - ImGui::SameLine(); - if (ImGui::Button(button2.c_str())) { - fileBrowser2.Open(); - } - fileBrowser2.Display(); - if (fileBrowser2.HasSelected()) { - std::string filepath; - for (auto const &selectedFile : fileBrowser2.GetSelected()) { - if (!filepath.empty()) { - filepath += "/"; - } - filepath += selectedFile.string(); - } - strcpy(path2, filepath.c_str()); - - fileBrowser2.ClearSelected(); - } - ImGui::Columns(1); - + fileBrowser2.ClearSelected(); + } + ImGui::Columns(1); + using namespace std::chrono_literals; + if (!flagApiSending) { if (ImGui::Button( load_json(language, "button", "send").c_str(), ImVec2(load_json(config, "button")))) { - // Api muss angepasst werden und die funktion send to api ebenso - metadata["z1"] = z1; - metadata["z2"] = z2; - metadata["z3"] = z3; - metadata["z4"] = z4; - metadata["kommentar"] = comment; - metadata["laufleistung"] = mileage; - metadata["zündung"] = "unterdrückt"; - api_message = send_to_api( + metadata["z1"] = z1; + metadata["z2"] = z2; + metadata["z3"] = z3; + metadata["z4"] = z4; + metadata["kommentar"] = comment; + metadata["laufleistung"] = mileage; + metadata["zündung"] = "unterdrückt"; + + future = std::async(std::launch::async, [&] { + std::string result = send_to_api( config, path1, inputvin, load_json(language, "measuretype", "compression"), metadata); + metadata["zündung"] = "aktiviert"; api_message += send_to_api( config, path2, inputvin, load_json(language, "measuretype", "compression"), metadata); - upload_success = true; - ImGui::CloseCurrentPopup(); + return result; + }); + flagApiSending = true; } - ImGui::EndChild(); + } + if (flagApiSending) { + ImGui::PushStyleColor( + ImGuiCol_Text, load_json(config, "text", "color", "inactive")); + if (ImGui::Button( + load_json(language, "button", "send").c_str(), + ImVec2(load_json(config, "button")))) { + } + ImGui::PopStyleColor(); + auto status = future.wait_for(10ms); + if (status == std::future_status::ready) { + upload_success = true; + flagApiSending = false; + if (future.valid()) { + api_message = future.get(); + } + ImGui::CloseCurrentPopup(); + } else { + ImGui::SameLine(); + ImGui::Text("senden... %c", "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]); + } + } + ImGui::EndChild(); } inline void popup_create_training_data_select(nlohmann::json const &config, nlohmann::json const &language, bool &upload_success) { - static int selectedOption = 1; // Standardauswahl - const char *options[] = {"Kompressionsmessung", "Batteriemessung", - "VCDS-Datei"}; - ImGui::Combo("Messung", &selectedOption, options, IM_ARRAYSIZE(options)); - - static std::string inputvin = ""; - static std::string mileage = ""; - static std::string comment = ""; - static nlohmann::json metadata; - std::string api_message = " "; - ImGui::SetItemDefaultFocus(); - show_standart_input(language, metadata, inputvin, mileage, comment); - ImGui::SameLine(); - - ImVec2 windowSize = ImGui::GetWindowSize(); - ImGui::BeginChild("trainingright", - ImVec2(windowSize.x * 0.5f, windowSize.y * 0.8f)); - switch (selectedOption) { - case 0: - selected_compression_data(config, language, metadata, inputvin, - mileage, comment, api_message, - upload_success); - break; - case 1: - selected_battery_measurement(config, language, metadata, inputvin, - mileage, comment, api_message, - upload_success); - break; - case 2: - selected_vcds_data(config, language, metadata, inputvin, mileage, - comment, api_message, upload_success); - break; - default: - ImGui::Text("Fehler, Switchcase mit unerwarteter Auswahl"); - } - if (ImGui::Button( - load_json(language, "button", "back").c_str(), - ImVec2(load_json(config, "button")))) { - ImGui::CloseCurrentPopup(); - } - - ImGui::TextUnformatted(api_message.c_str()); + static int selectedOption = 1; // Standardauswahl + const char *options[] = {"Kompressionsmessung", "Batteriemessung", + "VCDS-Datei"}; + ImGui::Combo("Messung", &selectedOption, options, IM_ARRAYSIZE(options)); + + static std::string inputvin = ""; + static std::string mileage = ""; + static std::string comment = ""; + static nlohmann::json metadata; + std::string api_message = " "; + ImGui::SetItemDefaultFocus(); + show_standart_input(config, language, metadata, inputvin, mileage, comment); + ImGui::SameLine(); + + ImVec2 windowSize = ImGui::GetWindowSize(); + ImGui::BeginChild("trainingright", + ImVec2(windowSize.x * 0.5f, windowSize.y * 0.8f)); + switch (selectedOption) { + case 0: + selected_compression_data(config, language, metadata, inputvin, mileage, + comment, api_message, upload_success); + break; + case 1: + selected_battery_measurement(config, language, metadata, inputvin, mileage, + comment, api_message, upload_success); + break; + case 2: + selected_vcds_data(config, language, metadata, inputvin, mileage, comment, + api_message, upload_success); + break; + default: + ImGui::Text("Fehler, Switchcase mit unerwarteter Auswahl"); + } + if (ImGui::Button(load_json(language, "button", "back").c_str(), + ImVec2(load_json(config, "button")))) { + ImGui::CloseCurrentPopup(); + } + + ImGui::TextUnformatted(api_message.c_str()); } diff --git a/src/look_up_saves.hpp b/src/look_up_saves.hpp new file mode 100644 index 00000000..91e600eb --- /dev/null +++ b/src/look_up_saves.hpp @@ -0,0 +1,80 @@ +#pragma once + +#include "jasonhandler.hpp" +#include +#include +#include +#include +#include + +std::string +getSubdirectoriesInFolder(nlohmann::json language, + std::filesystem::path const &saves_folder_path) { + std::vector subdirectories; + subdirectories.push_back( + load_json(language, "savepopup", "new_car")); + if (std::filesystem::exists(saves_folder_path) && + std::filesystem::is_directory(saves_folder_path)) { + + for (const auto &entry : + std::filesystem::directory_iterator(saves_folder_path)) { + if (std::filesystem::is_directory(entry)) { + subdirectories.push_back(entry.path().filename().string()); + } + } + } + + static int selectedOption = 0; + static std::string selectedFolder = + load_json(language, "savepopup", "new_car"); + if (!subdirectories.empty()) { + + // Erstellen eines Arrays von C-Strings (char*) + char **vins = new char *[subdirectories.size()]; + for (size_t i = 0; i < subdirectories.size(); ++i) { + vins[i] = strdup(subdirectories[i].c_str()); + } + + // Verwendung von vins (char* array) mit ImGui + if (ImGui::Combo( + load_json(language, "savepopup", "known_cars").c_str(), + &selectedOption, vins, static_cast(subdirectories.size()))) { + selectedFolder = subdirectories[selectedOption]; + } + static char inputvin[18]; + const std::string newcar = + load_json(language, "savepopup", "new_car"); + + if (selectedOption == 0) { + ImGui::InputText( + load_json(language, "input", "fin", "label").c_str(), + inputvin, sizeof(inputvin)); + selectedFolder = inputvin; + } + } + + return selectedFolder; +} +std::string select_combo_from_json(nlohmann::json const &language, + std::string const &key, + int &selectedOption) { + std::string selectedmeasure; + std::vector options; + for (const auto &item : language[key]) { + options.push_back(item); + } + + // Erstellen eines Arrays von C-Strings (char*) + char **option_c = new char *[options.size()]; + for (size_t i = 0; i < options.size(); ++i) { + option_c[i] = strdup(options[i].c_str()); + } + + std::string combo_name = "##" + key; + ImGui::Combo(combo_name.c_str(), &selectedOption, option_c, + static_cast(options.size())); + + selectedmeasure = options[selectedOption]; + + return selectedmeasure; +} diff --git a/src/main.cpp b/src/main.cpp index ef1291fd..07563643 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ #include "apihandler.hpp" #include "create_training_data.hpp" #include "get_from_github.hpp" - +#include "saves_popup.hpp" #include "jasonhandler.hpp" #include "settingspopup.hpp" #include @@ -24,103 +24,136 @@ #include // clang-format on -static std::vector getAvailableLanguages( - std::string const& languageFolder) { - std::vector languages; - for (auto const& entry : - std::filesystem::directory_iterator(languageFolder)) { - if (entry.is_regular_file()) { - std::string extension = entry.path().extension().string(); - if (extension == ".json") { - std::string filename = entry.path().filename().stem().string(); - languages.push_back(filename); - } - } +namespace ImGui { +inline void SetupImGuiStyle(bool bStyleDark_, float alpha_) { + ImGuiStyle &style = ImGui::GetStyle(); + + // light style from Pacôme Danhiez (user itamago) + // https://github.com/ocornut/imgui/pull/511#issuecomment-175719267 + style.Alpha = 1.0f; + style.FrameRounding = 3.0f; + style.Colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); + style.Colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 0.94f); + // style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, + // 0.00f); + style.Colors[ImGuiCol_PopupBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.94f); + style.Colors[ImGuiCol_Border] = ImVec4(0.00f, 0.00f, 0.00f, 0.39f); + style.Colors[ImGuiCol_BorderShadow] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f); + style.Colors[ImGuiCol_FrameBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.94f); + style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); + style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); + style.Colors[ImGuiCol_TitleBg] = ImVec4(0.96f, 0.96f, 0.96f, 1.00f); + style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 1.00f, 1.00f, 0.51f); + style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.82f, 0.82f, 0.82f, 1.00f); + style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f); + style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.98f, 0.98f, 0.98f, 0.53f); + style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.69f, 0.69f, 0.69f, 1.00f); + style.Colors[ImGuiCol_ScrollbarGrabHovered] = + ImVec4(0.59f, 0.59f, 0.59f, 1.00f); + style.Colors[ImGuiCol_ScrollbarGrabActive] = + ImVec4(0.49f, 0.49f, 0.49f, 1.00f); + style.Colors[ImGuiCol_PopupBg] = ImVec4(0.86f, 0.86f, 0.86f, 0.99f); + style.Colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f); + style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + style.Colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); + style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f); + style.Colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f); + style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); + style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + // style.Colors[ImGuiCol_Column] = ImVec4(0.39f, 0.39f, + // 0.39f, 1.00f); style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.26f, + // 0.59f, 0.98f, 0.78f); style.Colors[ImGuiCol_ColumnActive] = + // ImVec4(0.26f, 0.59f, 0.98f, 1.00f); + style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f); + style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); + style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); + // style.Colors[ImGuiCol_CloseButton] = ImVec4(0.59f, 0.59f, 0.59f, + // 0.50f); style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.98f, 0.39f, + // 0.36f, 1.00f); style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.98f, + // 0.39f, 0.36f, 1.00f); + style.Colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); + style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); + style.Colors[ImGuiCol_PlotHistogramHovered] = + ImVec4(1.00f, 0.60f, 0.00f, 1.00f); + style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); + // style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, + // 0.35f); + + if (bStyleDark_) { + for (int i = 0; i < ImGuiCol_COUNT; i++) { + ImVec4 &col = style.Colors[i]; + float H, S, V; + ImGui::ColorConvertRGBtoHSV(col.x, col.y, col.z, H, S, V); + + if (S < 0.1f) { + V = 1.0f - V; + } + ImGui::ColorConvertHSVtoRGB(H, S, V, col.x, col.y, col.z); + if (col.w < 1.00f) { + col.w *= alpha_; + } } - return languages; -} - -static void save( - std::map>> const& - alignedData, - std::filesystem::path const& outFile) { - auto minSize = std::numeric_limits::max(); - - std::vector> const*> data; - - std::string fileContent; - - for (auto sep = std::string_view{}; - auto const& [device, values] : alignedData) { - fileContent += sep; - fileContent += "\""; - fileContent += fmt::format("{}-{}", device.type, device.serial); - fileContent += "\""; - sep = ","; - minSize = std::min(values.size(), minSize); - data.push_back(std::addressof(values)); + } else { + // std::cout << ImGuiCol_COUNT << std::endl; + for (int i = 0; i < ImGuiCol_COUNT; i++) { + ImVec4 &col = style.Colors[i]; + if (col.w < 1.00f) { + col.x *= alpha_; + col.y *= alpha_; + col.z *= alpha_; + col.w *= alpha_; + } } - fileContent += '\n'; - - for (std::size_t i{}; i < minSize; ++i) { - fileContent += fmt::format("{}", i); - fileContent += ","; - for (auto sep = std::string_view{}; auto const& vec : data) { - auto const dataPair = (*vec)[i]; - fileContent += sep; - if (dataPair.second) { - fileContent += fmt::format("{}", dataPair.second); - } - sep = ","; - } - fileContent += '\n'; - } - - fileContent += '\n'; - - auto path = outFile; - path.remove_filename(); - if (!std::filesystem::exists(path) && !path.empty()) { - std::filesystem::create_directories(path); + } +} +} // namespace ImGui + +static std::vector +getAvailableLanguages(std::string const &languageFolder) { + std::vector languages; + for (auto const &entry : + std::filesystem::directory_iterator(languageFolder)) { + if (entry.is_regular_file()) { + std::string extension = entry.path().extension().string(); + if (extension == ".json") { + std::string filename = entry.path().filename().stem().string(); + languages.push_back(filename); + } } - - fmt::print("start save {}\n", outFile.string()); - std::ofstream file{outFile}; - // fmt::print("{}\n", fileContent); - file << fileContent; - file.flush(); - file.close(); - - fmt::print("finished save\n"); + } + return languages; } -static void set_button_style_to(nlohmann::json const& config, - std::string const& name) { - ImGui::PushStyleColor( - ImGuiCol_Button, - ImVec4(load_json(config, "button", name, "normal"))); - ImGui::PushStyleColor( - ImGuiCol_ButtonHovered, - ImVec4(load_json(config, "button", name, "hover"))); - ImGui::PushStyleColor( - ImGuiCol_ButtonActive, - ImVec4(load_json(config, "button", name, "active"))); +static void set_button_style_to(nlohmann::json const &config, + std::string const &name) { + ImGui::PushStyleColor( + ImGuiCol_Button, + ImVec4(load_json(config, "button", name, "normal"))); + ImGui::PushStyleColor( + ImGuiCol_ButtonHovered, + ImVec4(load_json(config, "button", name, "hover"))); + ImGui::PushStyleColor( + ImGuiCol_ButtonActive, + ImVec4(load_json(config, "button", name, "active"))); } -static void load_settings(nlohmann::json const& config) { - ImGui::PushStyleColor(ImGuiCol_MenuBarBg, - ImVec4(load_json(config, "menubar", "main"))); - ImGui::PushStyleColor(ImGuiCol_PopupBg, - ImVec4(load_json(config, "menubar", "popup"))); - ImGui::PushStyleColor( - ImGuiCol_Text, - ImVec4(load_json(config, "text", "color", "normal"))); - ImGui::PushStyleColor(ImGuiCol_WindowBg, - ImVec4(load_json(config, "window", "color"))); - set_button_style_to(config, "standart"); - - ImGuiIO& io = ImGui::GetIO(); - io.FontGlobalScale = load_json(config, "text", "scale"); +static void load_settings(nlohmann::json const &config) { + ImGui::PushStyleColor(ImGuiCol_MenuBarBg, + ImVec4(load_json(config, "menubar", "main"))); + ImGui::PushStyleColor(ImGuiCol_PopupBg, + ImVec4(load_json(config, "menubar", "popup"))); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(load_json( + config, "text", "color", "normal"))); + ImGui::PushStyleColor(ImGuiCol_WindowBg, + ImVec4(load_json(config, "window", "color"))); + set_button_style_to(config, "standart"); + + ImGuiIO &io = ImGui::GetIO(); + io.FontGlobalScale = load_json(config, "text", "scale"); } // ########################################################################### @@ -128,588 +161,523 @@ static void load_settings(nlohmann::json const& config) { // ########################################################################### int main() { - nlohmann::json config; - const std::string configpath = "config/config.json"; - if (std::filesystem::exists(configpath)) { - fmt::print("found config.json\n\r"); - - } else { - fmt::print("Did not find config.json.\n Download from Github\n\r"); - update_config_from_github(); + nlohmann::json config; + const std::string configpath = "config/config.json"; + if (std::filesystem::exists(configpath)) { + fmt::print("found config.json\n\r"); + + } else { + fmt::print("Did not find config.json.\n Download from Github\n\r"); + update_config_from_github(); + } + config = load_json_file(configpath); + if (std::filesystem::exists( + load_json(config, ("languagepath")))) { + fmt::print("found language: {}\n\r", + load_json(config, ("language"))); + + } else { + fmt::print("Did not find {}.\n Download from Github\n\r", + load_json(config, ("language"))); + update_language_from_github(); + } + + std::vector availableLanguages = + getAvailableLanguages(load_json(config, ("languagepath"))); + + nlohmann::json language = + load_json_file(load_json(config, "languagepath") + + load_json(config, "language") + ".json"); + + static constexpr int VID = 0x2e8au; + static constexpr int PID = 0x000au; + // static constexpr std::size_t captureDataReserve = 1 << 26; + OmniscopeDeviceManager deviceManager{}; + std::vector> + devices; // = deviceManager.getDevices(VID, PID); + // auto newDevices = devices; + std::map> colorMap; + auto initDevices = [&]() { + devices = deviceManager.getDevices(VID, PID); + + for (auto &device : devices) { + auto id = device->getId().value(); + if (!colorMap.contains(id)) { + ImPlot::PushColormap(ImPlotColormap_Dark); + auto c = ImPlot::GetColormapColor((colorMap.size() % 7) + 1); + colorMap[id] = std::array{c.x, c.y, c.z}; + ImPlot::PopColormap(); + } + + auto &color = colorMap[id]; + device->send( + Omniscope::SetRgb{static_cast(color[0] * 255), + static_cast(color[1] * 255), + static_cast(color[2] * 255)}); } - config = load_json_file(configpath); - if (std::filesystem::exists( - load_json(config, ("languagepath")))) { - fmt::print("found language: {}\n\r", - load_json(config, ("language"))); - - } else { - fmt::print("Did not find {}.\n Download from Github\n\r", - load_json(config, ("language"))); - update_language_from_github(); - } - - std::vector availableLanguages = - getAvailableLanguages(load_json(config, ("languagepath"))); - - nlohmann::json language = - load_json_file(load_json(config, "languagepath") + - load_json(config, "language") + ".json"); - - static constexpr int VID = 0x2e8au; - static constexpr int PID = 0x000au; - // static constexpr std::size_t captureDataReserve = 1 << 26; - OmniscopeDeviceManager deviceManager{}; - std::vector> - devices; // = deviceManager.getDevices(VID, PID); - // auto newDevices = devices; - std::map> colorMap; - auto initDevices = [&]() { - devices = deviceManager.getDevices(VID, PID); - - for (auto& device : devices) { - auto id = device->getId().value(); - if (!colorMap.contains(id)) { - ImPlot::PushColormap(ImPlotColormap_Dark); - auto c = ImPlot::GetColormapColor((colorMap.size() % 7) + 1); - colorMap[id] = std::array{c.x, c.y, c.z}; - ImPlot::PopColormap(); - } - - auto& color = colorMap[id]; - device->send( - Omniscope::SetRgb{static_cast(color[0] * 255), - static_cast(color[1] * 255), - static_cast(color[2] * 255)}); + }; + + // auto startTimepoint = std::chrono::system_clock::now(); + auto now = std::chrono::system_clock::now(); + std::time_t now_time_t = std::chrono::system_clock::to_time_t(now); + std::tm now_tm = *std::gmtime(&now_time_t); + + double xmax_paused{0}; + static bool open_settings = false; + static bool upload_success = false; + static bool flagPaused = true; + static bool flagDataNotSaved = true; + static ImVec2 mainMenuBarSize; + std::optional sampler{}; + std::map>> captureData; + + std::string path; + path.resize(256); + + auto addPlots = [&, firstRun = std::set{}]( + auto const &name, auto const &plots, + auto axesSetup) mutable { + auto const plotRegion = ImGui::GetContentRegionAvail(); + if (ImPlot::BeginPlot(name, plotRegion)) { + double x_min = std::numeric_limits::max(); + double x_max = std::numeric_limits::min(); + + for (auto const &plot : plots) { + if (!plot.second.empty()) { + x_min = std::min(x_min, plot.second.front().first); + x_max = std::max(x_max, plot.second.back().first); } - }; - - // auto startTimepoint = std::chrono::system_clock::now(); - auto now = std::chrono::system_clock::now(); - std::time_t now_time_t = std::chrono::system_clock::to_time_t(now); - std::tm now_tm = *std::gmtime(&now_time_t); - - double xmax_paused{0}; - static bool open_settings = false; - static bool upload_success = false; - static bool flagPaused = true; - static bool flagDataNotSaved = true; - static ImVec2 mainMenuBarSize; - std::optional sampler{}; - std::map>> captureData; - - std::string path; - path.resize(256); - - auto addPlots = [&, firstRun = std::set{}]( - auto const& name, auto const& plots, - auto axesSetup) mutable { - auto const plotRegion = ImGui::GetContentRegionAvail(); - if (ImPlot::BeginPlot(name, plotRegion)) { - double x_min = std::numeric_limits::max(); - double x_max = std::numeric_limits::min(); - - for (auto const& plot : plots) { - if (!plot.second.empty()) { - x_min = std::min(x_min, plot.second.front().first); - x_max = std::max(x_max, plot.second.back().first); - } - } + } - axesSetup(x_min, x_max); - - auto const limits = [&]() { - if (!firstRun.contains(name)) { - firstRun.insert(name); - return ImPlotRect(x_min, x_max, 0, 0); - } - return ImPlot::GetPlotLimits(); - }(); - auto addPlot = [&](auto const& plot) { - if (!plot.second.empty()) { - auto const start = [&]() { - auto p = std::lower_bound( - plot.second.begin(), plot.second.end(), - std::pair{limits.X.Min, 0}); - if (p != plot.second.begin()) { - return p - 1; - } - return p; - }(); - - auto const end = [&]() { - auto p = std::upper_bound( - start, plot.second.end(), - std::pair{limits.X.Max, 0}); - if (p != plot.second.end()) { - return p + 1; - } - return p; - }(); - std::size_t const stride = [&]() -> std::size_t { - auto const s = - std::distance(start, end) / (plotRegion.x * 2.0); - if (1 >= s) { - return 1; - } - return static_cast(s); - }(); - - ImPlot::PlotLine( - fmt::format("{}-{}", plot.first.type, plot.first.serial) - .c_str(), - std::addressof(start->first), - std::addressof(start->second), - static_cast(std::distance(start, end)) / - stride, - 0, 0, 2 * sizeof(double) * stride); - } - }; - - for (auto const& plot : plots) { - ImPlot::SetNextLineStyle(ImVec4{colorMap[plot.first][0], - colorMap[plot.first][1], - colorMap[plot.first][2], 1.0f}); - addPlot(plot); - } + axesSetup(x_min, x_max); - ImPlot::EndPlot(); + auto const limits = [&]() { + if (!firstRun.contains(name)) { + firstRun.insert(name); + return ImPlotRect(x_min, x_max, 0, 0); } - }; - - auto render = [&]() { - load_settings(config); - ImGui::SetNextWindowPos(ImVec2(0.0f, mainMenuBarSize.y)); - ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize); - ImGui::Begin("OmniScopev2 Data Capture Tool", nullptr, - ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | - ImGuiWindowFlags_NoResize | - ImGuiWindowFlags_NoMove); // - - // ############################ Menu bar ############################## - // main menu - ImGui::BeginMainMenuBar(); - if (ImGui::BeginMenu( - load_json(language, "menubar", "menu", "label") - .c_str())) { - if (ImGui::BeginMenu(load_json(language, "menubar", - "menu", - "language_option") - .c_str())) { - for (const auto& lang : availableLanguages) { - if (ImGui::MenuItem(lang.c_str())) { - config["language"] = lang; - write_json_file(configpath, config); - } - } - - ImGui::EndMenu(); - } - if (ImGui::MenuItem(load_json(language, "menubar", - "menu", "settings") - .c_str())) { - open_settings = true; + return ImPlot::GetPlotLimits(); + }(); + auto addPlot = [&](auto const &plot) { + if (!plot.second.empty()) { + auto const start = [&]() { + auto p = + std::lower_bound(plot.second.begin(), plot.second.end(), + std::pair{limits.X.Min, 0}); + if (p != plot.second.begin()) { + return p - 1; } - - if (ImGui::MenuItem( - load_json(language, "menubar", "menu", "reset") - .c_str())) { - sampler.reset(); - devices.clear(); - deviceManager.clearDevices(); - captureData.clear(); - flagPaused = true; + return p; + }(); + + auto const end = [&]() { + auto p = + std::upper_bound(start, plot.second.end(), + std::pair{limits.X.Max, 0}); + if (p != plot.second.end()) { + return p + 1; } - ImGui::EndMenu(); - } - /* - if (ImGui::BeginMenu( - load_json(language, "menubar", "view", "label") - .c_str())) { - ImGui::EndMenu(); - }*/ - - if (ImGui::BeginMenu( - load_json(language, "menubar", "help", "label") - .c_str())) { - if (ImGui::MenuItem( - load_json(language, "helplink").c_str())) { - system(("start " + load_json(config, "helplink")) - .c_str()); + return p; + }(); + std::size_t const stride = [&]() -> std::size_t { + auto const s = std::distance(start, end) / (plotRegion.x * 2.0); + if (1 >= s) { + return 1; } - - ImGui::EndMenu(); + return static_cast(s); + }(); + + ImPlot::PlotLine( + fmt::format("{}-{}", plot.first.type, plot.first.serial).c_str(), + std::addressof(start->first), std::addressof(start->second), + static_cast(std::distance(start, end)) / stride, 0, + 0, 2 * sizeof(double) * stride); } + }; - mainMenuBarSize = ImGui::GetItemRectSize(); - ImGui::EndMainMenuBar(); + for (auto const &plot : plots) { + ImPlot::SetNextLineStyle(ImVec4{colorMap[plot.first][0], + colorMap[plot.first][1], + colorMap[plot.first][2], 1.0f}); + addPlot(plot); + } - // ############################ Live Capture - // ############################## - ImGui::BeginChild("Live Capture", ImVec2(-1, 620)); - if (sampler.has_value()) { - if (!flagPaused) { - sampler->copyOut(captureData); - } + ImPlot::EndPlot(); + } + }; + + auto render = [&]() { + load_settings(config); + ImGui::SetupImGuiStyle(false, 0.99f); + ImGui::SetNextWindowPos(ImVec2(0.0f, mainMenuBarSize.y)); + ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize); + ImGui::Begin("OmniScopev2 Data Capture Tool", nullptr, + ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | + ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove); // + + // ############################ Menu bar ############################## + // main menu + ImGui::BeginMainMenuBar(); + if (ImGui::BeginMenu( + load_json(language, "menubar", "menu", "label") + .c_str())) { + if (ImGui::BeginMenu(load_json(language, "menubar", "menu", + "language_option") + .c_str())) { + for (const auto &lang : availableLanguages) { + if (ImGui::MenuItem(lang.c_str())) { + config["language"] = lang; + write_json_file(configpath, config); + } } - addPlots( - "Aufnahme der Daten", captureData, - [&sampler, &xmax_paused](auto /*x_min*/, auto x_max) { - if (!flagPaused) { - ImPlot::SetupAxes("x [Datenpunkte]", "y [ADC Wert]", - ImPlotAxisFlags_AutoFit, - ImPlotAxisFlags_AutoFit); - ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 7500, - x_max + 7500, ImGuiCond_Always); - } else { - xmax_paused = x_max; - ImPlot::SetupAxes("x [Datenpunkte]", "y [ADC Wert]", 0, 0); - } - }); - - ImGui::EndChild(); - float optimal_buttonstripe_height; - if (load_json(config, "button", "sizey") < - (ImGui::GetTextLineHeightWithSpacing() * 1.1)) { - optimal_buttonstripe_height = - (ImGui::GetTextLineHeightWithSpacing() * 1.1); - } else { - optimal_buttonstripe_height = - load_json(config, "button", "sizey") * 1.1; - } - ImGui::BeginChild("Buttonstripe", - ImVec2(-1, optimal_buttonstripe_height), false, - ImGuiWindowFlags_NoScrollbar); + ImGui::EndMenu(); + } + if (ImGui::MenuItem( + load_json(language, "menubar", "menu", "settings") + .c_str())) { + open_settings = true; + } + + if (ImGui::MenuItem( + load_json(language, "menubar", "menu", "reset") + .c_str())) { + sampler.reset(); + devices.clear(); + deviceManager.clearDevices(); + captureData.clear(); + flagPaused = true; + } + ImGui::EndMenu(); + } + /* + if (ImGui::BeginMenu( + load_json(language, "menubar", "view", "label") + .c_str())) { + ImGui::EndMenu(); + }*/ + + if (ImGui::BeginMenu( + load_json(language, "menubar", "help", "label") + .c_str())) { + if (ImGui::MenuItem( + load_json(language, "helplink").c_str())) { + system(("start " + load_json(config, "helplink")).c_str()); + } + + ImGui::EndMenu(); + } - // ############################ Popup Speichern - // ############################## - if (ImGui::BeginPopupModal("Speichern der aufgenommenen Daten", nullptr, - ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::SetItemDefaultFocus(); - - static char inputvin[18] = ""; - static char mileage[10] = ""; - static char scantype[255] = ""; - ImGui::SetItemDefaultFocus(); - ImGui::InputText( - load_json(language, "input", "fin", "label") - .c_str(), - inputvin, sizeof(inputvin)); - ImGui::InputText( - load_json(language, "input", "scantype", "label") - .c_str(), - scantype, sizeof(scantype)); - ImGui::InputText( - load_json(language, "input", "mileage", "label") - .c_str(), - mileage, sizeof(mileage)); - - if (ImGui::Button( - load_json(language, "button", "save").c_str(), - ImVec2(load_json(config, "button")))) { - now = std::chrono::system_clock::now(); - - now_time_t = std::chrono::system_clock::to_time_t(now); - now_tm = *std::gmtime(&now_time_t); - - std::string_view path_sv{path.data()}; - std::string filename{ - fmt::format("{}-{:%Y-%m-%dT%H-%M}.csv", mileage, now)}; - std::filesystem::path path_path = path_sv; - if (captureData.empty()) { - ImGui::CloseCurrentPopup(); - } else { - // create the given folder_structure - std::filesystem::path first_folder = - load_json(config, "scanfolder"); - std::filesystem::path complete_path = - first_folder / inputvin / scantype; - std::filesystem::create_directories(complete_path); - - save(captureData, path_path / complete_path / filename); - - // nicht mehr im save-kontext, sondern in create training - // data send_to_api(config, path_path / filename, inputvin, - // scantype); - flagDataNotSaved = false; - ImGui::CloseCurrentPopup(); - } - } - ImGui::SameLine(); - if (ImGui::Button( - load_json(language, "button", "back").c_str(), - ImVec2(load_json(config, "button")))) { - ImGui::CloseCurrentPopup(); - } + mainMenuBarSize = ImGui::GetItemRectSize(); + ImGui::EndMainMenuBar(); - ImGui::EndPopup(); - } - // ############################ Popup Zurücksetzen - // ############################## - if (ImGui::BeginPopupModal("Zurücksetzen?", nullptr, - ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::SetItemDefaultFocus(); - ImGui::Text( - "Die Messung wurde nicht gespeichert!\n" - "Möchten Sie diese vor dem Löschen speichern?\n"); - if (ImGui::Button("Löschen fortsetzen", - ImVec2(load_json(config, "button")))) { - sampler.reset(); - devices.clear(); - deviceManager.clearDevices(); - captureData.clear(); - ImGui::CloseCurrentPopup(); - } - ImGui::SameLine(); - if (ImGui::Button("Zurück", - ImVec2(load_json(config, "button")))) { - ImGui::CloseCurrentPopup(); - } - ImGui::EndPopup(); - } + // ############################ Live Capture + // ############################## + ImGui::BeginChild("Live Capture", ImVec2(-1, 620)); + if (sampler.has_value()) { + if (!flagPaused) { + sampler->copyOut(captureData); + } + } - ImGui::SetNextWindowPos(ImVec2(0, 100)); - ImGui::SetNextWindowSize(ImVec2(0, 800)); - if (flagPaused) { - if (ImGui::BeginPopupModal("Erstellung Lerndatensatz", nullptr, - ImGuiWindowFlags_AlwaysAutoResize | - ImGuiWindowFlags_NoSavedSettings | - ImGuiWindowFlags_NoMove)) { - ImGui::SetItemDefaultFocus(); - - popup_create_training_data_select(config, language, - upload_success); - ImGui::EndPopup(); - } - if (upload_success == true) { - ImGui::OpenPopup("upload_success"); - } - if (ImGui::BeginPopupModal("upload_success", nullptr, - ImGuiWindowFlags_AlwaysAutoResize | - ImGuiWindowFlags_NoSavedSettings | - ImGuiWindowFlags_NoMove)) { - ImGui::TextUnformatted(load_json(language, - "training", - "upload_success") - .c_str()); - if (ImGui::Button( - load_json(language, "button", "ok") - .c_str())) { - ImGui::CloseCurrentPopup(); - upload_success = false; - } - - ImGui::SetItemDefaultFocus(); - ImGui::EndPopup(); - } - // ######################## Buttonstripe - // ################################ - // Start nur wenn Devices vorhanden sind, sonst Suche Geräte - if (!sampler.has_value()) { - if (ImGui::Button("Suche Geräte", - ImVec2(load_json(config, "button")))) { - devices.clear(); - deviceManager.clearDevices(); - initDevices(); - } - ImGui::SameLine(); - } + addPlots("Aufnahme der Daten", captureData, + [&sampler, &xmax_paused](auto /*x_min*/, auto x_max) { + if (!flagPaused) { + ImPlot::SetupAxes("x [Datenpunkte]", "y [ADC Wert]", + ImPlotAxisFlags_AutoFit, + ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisLimits(ImAxis_X1, x_max - 7500, x_max + 7500, + ImGuiCond_Always); + } else { + xmax_paused = x_max; + ImPlot::SetupAxes("x [Datenpunkte]", "y [ADC Wert]", 0, 0); + } + }); + + ImGui::EndChild(); + float optimal_buttonstripe_height; + if (load_json(config, "button", "sizey") < + (ImGui::GetTextLineHeightWithSpacing() * 1.1)) { + optimal_buttonstripe_height = + (ImGui::GetTextLineHeightWithSpacing() * 1.1); + } else { + optimal_buttonstripe_height = + load_json(config, "button", "sizey") * 1.1; + } + ImGui::BeginChild("Buttonstripe", ImVec2(-1, optimal_buttonstripe_height), + false, ImGuiWindowFlags_NoScrollbar); + + // ############################ Popup Speichern + // ############################## + if (ImGui::BeginPopupModal("Speichern der aufgenommenen Daten", nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::SetItemDefaultFocus(); + saves_popup(config, language, captureData, now, now_time_t, now_tm, path, + flagDataNotSaved); + + ImGui::SameLine(); + if (ImGui::Button( + load_json(language, "button", "back").c_str(), + ImVec2(load_json(config, "button")))) { + ImGui::CloseCurrentPopup(); + } + + ImGui::EndPopup(); + } + // ############################ Popup Zurücksetzen + // ############################## + if (ImGui::BeginPopupModal("Zurücksetzen?", nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::SetItemDefaultFocus(); + ImGui::Text("Die Messung wurde nicht gespeichert!\n" + "Möchten Sie diese vor dem Löschen speichern?\n"); + if (ImGui::Button("Löschen fortsetzen", + ImVec2(load_json(config, "button")))) { + sampler.reset(); + devices.clear(); + deviceManager.clearDevices(); + captureData.clear(); + ImGui::CloseCurrentPopup(); + } + ImGui::SameLine(); + if (ImGui::Button("Zurück", ImVec2(load_json(config, "button")))) { + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } - if (!devices.empty()) { - // ############################ Start Button - // ############################## - if (!sampler.has_value()) { - set_button_style_to(config, "start"); - if (ImGui::Button( - load_json(language, "button", "start") - .c_str(), - ImVec2(load_json(config, "button")))) { - sampler.emplace(deviceManager, std::move(devices)); - flagPaused = false; - flagDataNotSaved = true; - } - ImGui::PopStyleColor(3); - } - } - // set_button_style_to(config, "standart"); - } else { - // ############################ Stop Button - // ############################## - set_button_style_to(config, "stop"); - if (ImGui::Button( - load_json(language, "button", "stop").c_str(), - ImVec2(load_json(config, "button")))) { - flagPaused = true; - } - ImGui::PopStyleColor(3); + ImGui::SetNextWindowPos(ImVec2(0, 100)); + ImGui::SetNextWindowSize(ImVec2(0, 800)); + if (flagPaused) { + if (ImGui::BeginPopupModal("Erstellung Lerndatensatz", nullptr, + ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoSavedSettings | + ImGuiWindowFlags_NoMove)) { + ImGui::SetItemDefaultFocus(); + + popup_create_training_data_select(config, language, upload_success); + ImGui::EndPopup(); + } + if (upload_success == true) { + ImGui::OpenPopup("upload_success"); + } + if (ImGui::BeginPopupModal("upload_success", nullptr, + ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoSavedSettings | + ImGuiWindowFlags_NoMove)) { + ImGui::TextUnformatted( + load_json(language, "training", "upload_success") + .c_str()); + if (ImGui::Button( + load_json(language, "button", "ok").c_str())) { + ImGui::CloseCurrentPopup(); + upload_success = false; } - if (flagPaused) { - ImGui::SameLine(); - - // Start / Zurücksetzen der Messung bei pausierter Messung - // mit anschließender Abfrage ob die alten Daten gespeichert - // werden sollen - if (sampler.has_value()) { - ImGui::SameLine(); - set_button_style_to(config, "start"); - if (ImGui::Button("Fortsetzen", - ImVec2(load_json(config, "button")))) { - flagPaused = false; - flagDataNotSaved = true; - } - ImGui::PopStyleColor(3); - ImGui::SameLine(); - - set_button_style_to(config, "stop"); - if (ImGui::Button("Zurücksetzen", - ImVec2(load_json(config, "button")))) { - if (flagDataNotSaved) { - ImGui::OpenPopup("Zurücksetzen?"); - } else { - sampler.reset(); - devices.clear(); - deviceManager.clearDevices(); - captureData.clear(); - flagPaused = true; - } - } - ImGui::PopStyleColor(3); - } - ImGui::SameLine(); - if (ImGui::Button( - load_json(language, "button", "save").c_str(), - ImVec2(load_json(config, "button")))) { - ImGui::OpenPopup("Speichern der aufgenommenen Daten"); - } - ImGui::SameLine(); - ImGui::PushStyleColor( - ImGuiCol_Text, - load_json(config, "text", "color", "inactive")); - if (ImGui::Button( - load_json(language, "button", "analyse_data") - .c_str(), - ImVec2(load_json(config, "button")))) { - } - ImGui::PopStyleColor(); - ImGui::PushStyleColor( - ImGuiCol_Text, - load_json(config, "text", "color", "normal")); - ImGui::SameLine(); - - // ############################ Button create trainings data - // ############################## - if (ImGui::Button(load_json(language, "button", - "create_training_data") - .c_str(), - ImVec2(load_json(config, "button")))) { - ImGui::SetNextWindowPos(ImVec2(0, 0)); - ImGui::SetNextWindowSize(ImVec2(0, 0)); - ImGui::OpenPopup("Erstellung Lerndatensatz"); - } - ImGui::PopStyleColor(); - } else { - ImGui::SameLine(); - ImGui::PushStyleColor( - ImGuiCol_Text, - load_json(config, "text", "color", "inactive")); - if (ImGui::Button( - load_json(language, "button", "save").c_str(), - ImVec2(load_json(config, "button")))) { - } - ImGui::SameLine(); - if (ImGui::Button( - load_json(language, "button", "analyse_data") - .c_str(), - ImVec2(load_json(config, "button")))) { - } - ImGui::SameLine(); - if (ImGui::Button(load_json(language, "button", - "create_training_data") - .c_str(), - ImVec2(load_json(config, "button")))) { - } - ImGui::PopStyleColor(); + + ImGui::SetItemDefaultFocus(); + ImGui::EndPopup(); + } + // ######################## Buttonstripe + // ################################ + // Start nur wenn Devices vorhanden sind, sonst Suche Geräte + if (!sampler.has_value()) { + if (ImGui::Button("Suche Geräte", + ImVec2(load_json(config, "button")))) { + devices.clear(); + deviceManager.clearDevices(); + initDevices(); } - ImGui::EndChild(); - // ############################ Settings Menu + ImGui::SameLine(); + } + + if (!devices.empty()) { + // ############################ Start Button // ############################## - std::string settingstitle = - load_json(language, "settings", "title"); - if (open_settings == true) { - ImGui::OpenPopup(settingstitle.c_str()); - open_settings = false; + if (!sampler.has_value()) { + set_button_style_to(config, "start"); + if (ImGui::Button( + load_json(language, "button", "start").c_str(), + ImVec2(load_json(config, "button")))) { + sampler.emplace(deviceManager, std::move(devices)); + flagPaused = false; + flagDataNotSaved = true; + } + ImGui::PopStyleColor(3); } - if (ImGui::BeginPopupModal(settingstitle.c_str(), nullptr, - ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::SetItemDefaultFocus(); - popup_settings(config, language, configpath); - ImGui::EndPopup(); + } + // set_button_style_to(config, "standart"); + } else { + // ############################ Stop Button + // ############################## + set_button_style_to(config, "stop"); + if (ImGui::Button( + load_json(language, "button", "stop").c_str(), + ImVec2(load_json(config, "button")))) { + flagPaused = true; + } + ImGui::PopStyleColor(3); + } + if (flagPaused) { + ImGui::SameLine(); + + // Start / Zurücksetzen der Messung bei pausierter Messung + // mit anschließender Abfrage ob die alten Daten gespeichert + // werden sollen + if (sampler.has_value()) { + ImGui::SameLine(); + set_button_style_to(config, "start"); + if (ImGui::Button("Fortsetzen", + ImVec2(load_json(config, "button")))) { + flagPaused = false; + flagDataNotSaved = true; } + ImGui::PopStyleColor(3); + ImGui::SameLine(); - // ############################ Devicelist - // ############################## - ImGui::BeginChild("Devicelist", ImVec2(-1, 0)); - // ImVec2 center = ImGui::GetMainViewport()->GetCenter(); - // ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, - // ImVec2(0.5f, 0.5f)); - - ImGui::Text("gefundene Geräte:"); - if (ImGui::BeginListBox("##deviceListBox", ImVec2(1024, -1))) { - auto doDevice = [&](auto& device, auto msg) { - auto& color = colorMap[device->getId().value()]; - if (ImGui::ColorEdit3( - fmt::format( - "{:<32}", + set_button_style_to(config, "stop"); + if (ImGui::Button("Zurücksetzen", + ImVec2(load_json(config, "button")))) { + if (flagDataNotSaved) { + ImGui::OpenPopup("Zurücksetzen?"); + } else { + sampler.reset(); + devices.clear(); + deviceManager.clearDevices(); + captureData.clear(); + flagPaused = true; + } + } + ImGui::PopStyleColor(3); + } + ImGui::SameLine(); + if (ImGui::Button( + load_json(language, "button", "save").c_str(), + ImVec2(load_json(config, "button")))) { + ImGui::OpenPopup("Speichern der aufgenommenen Daten"); + } + ImGui::SameLine(); + ImGui::PushStyleColor( + ImGuiCol_Text, load_json(config, "text", "color", "inactive")); + if (ImGui::Button( + load_json(language, "button", "analyse_data") + .c_str(), + ImVec2(load_json(config, "button")))) { + } + ImGui::PopStyleColor(); + ImGui::PushStyleColor( + ImGuiCol_Text, load_json(config, "text", "color", "normal")); + ImGui::SameLine(); + + // ############################ Button create trainings data + // ############################## + if (ImGui::Button( + load_json(language, "button", "create_training_data") + .c_str(), + ImVec2(load_json(config, "button")))) { + ImGui::SetNextWindowPos(ImVec2(0, 0)); + ImGui::SetNextWindowSize(ImVec2(0, 0)); + ImGui::OpenPopup("Erstellung Lerndatensatz"); + } + ImGui::PopStyleColor(); + } else { + ImGui::SameLine(); + ImGui::PushStyleColor( + ImGuiCol_Text, load_json(config, "text", "color", "inactive")); + if (ImGui::Button( + load_json(language, "button", "save").c_str(), + ImVec2(load_json(config, "button")))) { + } + ImGui::SameLine(); + if (ImGui::Button( + load_json(language, "button", "analyse_data") + .c_str(), + ImVec2(load_json(config, "button")))) { + } + ImGui::SameLine(); + if (ImGui::Button( + load_json(language, "button", "create_training_data") + .c_str(), + ImVec2(load_json(config, "button")))) { + } + ImGui::PopStyleColor(); + } + ImGui::EndChild(); + // ############################ Settings Menu + // ############################## + std::string settingstitle = + load_json(language, "settings", "title"); + if (open_settings == true) { + ImGui::OpenPopup(settingstitle.c_str()); + open_settings = false; + } + if (ImGui::BeginPopupModal(settingstitle.c_str(), nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::SetItemDefaultFocus(); + popup_settings(config, language, configpath); + ImGui::EndPopup(); + } + + // ############################ Devicelist + // ############################## + ImGui::BeginChild("Devicelist", ImVec2(-1, 0)); + // ImVec2 center = ImGui::GetMainViewport()->GetCenter(); + // ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, + // ImVec2(0.5f, 0.5f)); + + ImGui::Text("gefundene Geräte:"); + if (ImGui::BeginListBox("##deviceListBox", ImVec2(1024, -1))) { + auto doDevice = [&](auto &device, auto msg) { + auto &color = colorMap[device->getId().value()]; + if (ImGui::ColorEdit3( + fmt::format("{:<32}", fmt::format("{}-{}", device->getId().value().type, device->getId().value().serial)) - .c_str(), - color.data(), - ImGuiColorEditFlags_NoInputs | - ImGuiColorEditFlags_NoPicker | - ImGuiColorEditFlags_NoTooltip)) { - device->send(Omniscope::SetRgb{ - static_cast(color[0] * 255), - static_cast(color[1] * 255), - static_cast(color[2] * 255)}); - } - ImGui::SameLine(); - ImGui::TextUnformatted( - fmt::format("HW: v{}.{}.{} SW: v{}.{}.{} ", - device->getId().value().hwVersion.major, - device->getId().value().hwVersion.minor, - device->getId().value().hwVersion.patch, - device->getId().value().swVersion.major, - device->getId().value().swVersion.minor, - device->getId().value().swVersion.patch) - .c_str()); - ImGui::SameLine(); - if (device->isRunning()) { - ImGui::TextUnformatted(fmt::format("{}", msg).c_str()); - } else { - ImGui::TextUnformatted(fmt::format("Fehler").c_str()); - } - }; - - if (sampler.has_value()) { - for (auto& device : sampler->sampleDevices) { - doDevice(device.first, "Messung"); - } - } else { - for (auto& device : devices) { - doDevice(device, "Bereit"); - } - } - ImGui::EndListBox(); + .c_str(), + color.data(), + ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoPicker | + ImGuiColorEditFlags_NoTooltip)) { + device->send( + Omniscope::SetRgb{static_cast(color[0] * 255), + static_cast(color[1] * 255), + static_cast(color[2] * 255)}); } - ImGui::EndChild(); ImGui::SameLine(); - ImGui::End(); - ImGui::PopStyleColor(7); - }; + ImGui::TextUnformatted( + fmt::format("HW: v{}.{}.{} SW: v{}.{}.{} ", + device->getId().value().hwVersion.major, + device->getId().value().hwVersion.minor, + device->getId().value().hwVersion.patch, + device->getId().value().swVersion.major, + device->getId().value().swVersion.minor, + device->getId().value().swVersion.patch) + .c_str()); + ImGui::SameLine(); + if (device->isRunning()) { + ImGui::TextUnformatted(fmt::format("{}", msg).c_str()); + } else { + ImGui::TextUnformatted(fmt::format("Fehler").c_str()); + } + }; - ImGuiInstance window{1920, 1080, load_json(config, "title")}; - while (window.run(render)) { + if (sampler.has_value()) { + for (auto &device : sampler->sampleDevices) { + doDevice(device.first, "Messung"); + } + } else { + for (auto &device : devices) { + doDevice(device, "Bereit"); + } + } + ImGui::EndListBox(); } - return 0; -} + ImGui::EndChild(); + ImGui::SameLine(); + ImGui::End(); + ImGui::PopStyleColor(7); + }; + + ImGuiInstance window{1920, 1080, load_json(config, "title")}; + while (window.run(render)) { + } + return 0; +} \ No newline at end of file diff --git a/src/saves_popup.hpp b/src/saves_popup.hpp new file mode 100644 index 00000000..8acfe198 --- /dev/null +++ b/src/saves_popup.hpp @@ -0,0 +1,105 @@ +#pragma once +#include "../ai_omniscope-v2-communication_sw/src/OmniscopeSampler.hpp" +#include + +static void +save(std::map>> const + &alignedData, + std::filesystem::path const &outFile) { + auto minSize = std::numeric_limits::max(); + + std::vector> const *> data; + + std::string fileContent; + + for (auto sep = std::string_view{}; + auto const &[device, values] : alignedData) { + fileContent += sep; + fileContent += "\""; + fileContent += fmt::format("{}-{}", device.type, device.serial); + fileContent += "\""; + sep = ","; + minSize = std::min(values.size(), minSize); + data.push_back(std::addressof(values)); + } + fileContent += '\n'; + + for (std::size_t i{}; i < minSize; ++i) { + fileContent += fmt::format("{}", i); + fileContent += ","; + for (auto sep = std::string_view{}; auto const &vec : data) { + auto const dataPair = (*vec)[i]; + fileContent += sep; + if (dataPair.second) { + fileContent += fmt::format("{}", dataPair.second); + } + sep = ","; + } + fileContent += '\n'; + } + + fileContent += '\n'; + + auto path = outFile; + path.remove_filename(); + if (!std::filesystem::exists(path) && !path.empty()) { + std::filesystem::create_directories(path); + } + + fmt::print("start save {}\n", outFile.string()); + std::ofstream file{outFile}; + // fmt::print("{}\n", fileContent); + file << fileContent; + file.flush(); + file.close(); + + fmt::print("finished save\n"); +} + +void saves_popup(nlohmann::json const &config, nlohmann::json const &language, + std::map>> + &captureData, + std::chrono::system_clock::time_point &now, + std::time_t &now_time_t, std::tm &now_tm, std::string &path, + bool &flagDataNotSaved) { + ImGui::SetItemDefaultFocus(); + + static std::string inputvin; + + static char mileage[10] = ""; + static char scantype[255] = ""; + + inputvin = getSubdirectoriesInFolder(language, "saves"); + ImGui::InputText( + load_json(language, "input", "scantype", "label").c_str(), + scantype, sizeof(scantype)); + ImGui::InputText( + load_json(language, "input", "mileage", "label").c_str(), + mileage, sizeof(mileage)); + + if (ImGui::Button(load_json(language, "button", "save").c_str(), + ImVec2(load_json(config, "button")))) { + flagDataNotSaved = false; + now = std::chrono::system_clock::now(); + + now_time_t = std::chrono::system_clock::to_time_t(now); + now_tm = *std::gmtime(&now_time_t); + + std::string_view path_sv{path.data()}; + std::string filename{fmt::format("{}-{:%Y-%m-%dT%H-%M}.csv", mileage, now)}; + std::filesystem::path path_path = path_sv; + if (captureData.empty()) { + ImGui::CloseCurrentPopup(); + } else { + // create the given folder_structure + std::filesystem::path first_folder = + load_json(config, "scanfolder"); + std::filesystem::path complete_path = first_folder / inputvin / scantype; + std::filesystem::create_directories(complete_path); + + save(captureData, path_path / complete_path / filename); + + ImGui::CloseCurrentPopup(); + } + } +}