Skip to content

Commit

Permalink
Gui qt (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeryStk authored Sep 17, 2024
1 parent 7334dd1 commit 7b0c124
Show file tree
Hide file tree
Showing 36 changed files with 1,527 additions and 132 deletions.
2 changes: 2 additions & 0 deletions !Format + one_header.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
call auto_format.bat
call make_one_header.bat
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ add_subdirectory(plotly_maker)
add_subdirectory(array_core)
add_subdirectory(common_utils)


add_subdirectory(gui)


set(HEADER_FILES davis.h)

# tests
enable_testing()
add_subdirectory(Tests)

include_directories(${RESOURCE_MANAGER_INCLUDE_DIRS})
rm_embed_resources(RESOURCES "plotly_maker/plotly-2.27.0.min.js")
rm_embed_resources(RESOURCES "plotly_maker/plotly-2.32.0.min.js")

add_executable("davis_launcher" davis_launcher.cpp davis.h)

Expand Down
40 changes: 38 additions & 2 deletions Tests/ArrayCoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ TEST(ArrayCore, save_to_disk_pseudo_2d) {
}
}
dv::configSaveToDisk conf;
conf.separatorOfCols = "*";
conf.separatorOfRows = "____";
conf.separatorOfCols = ";";
conf.separatorOfRows = "\n";
bool result = dv::save(vals, rows, cols, "./data/test_saving_save_to_disk_pseudo_2d.csv", conf);
EXPECT_EQ(result, true);
}
Expand Down Expand Up @@ -78,6 +78,20 @@ TEST(ArrayCore, save_to_disk_container2D) {
EXPECT_EQ(result, true);
}

TEST(ArrayCore, save_to_disk_XYdata) {
//! 1-dimensional container
vector<double> vecX;
for (size_t i = 0; i < 10; ++i) {
vecX.emplace_back(i * 2);
}
vector<double> vecY;
for (size_t i = 0; i < 10; ++i) {
vecY.emplace_back(i * 3);
}
bool result = dv::save(vecX, vecY, "./data/test_saving_save_to_disk_XYdata.csv");
EXPECT_EQ(result, true);
}

TEST(ArrayCore, universal_1d_conteiner) {
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
std::list<double> vec = {5, 34};
Expand Down Expand Up @@ -193,6 +207,28 @@ TEST(ArrayCore, showChart) {
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showChartXYfromContainerOfConteiners) {
vector<vector<double>> values;
vector<double> vecX = {5, 20, 21, 22, 50};
vector<double> vecY = {1, 2, 3, 4, 5};
values.emplace_back(vecX);
values.emplace_back(vecY);
auto config = dv::Config();
config.chart.title = "ChartXY";
config.chart.xLabel = "xLabel";
config.chart.yLabel = "yLabel";
bool result = dv::show(values, "showChartXY_ContainerOfContainers", config);
EXPECT_EQ(result, true);
}

TEST(ArrayCore, showChartXYfrom2Containers) {
vector<vector<double>> values;
vector<double> vecX = {5, 20, 21, 22, 50};
vector<double> vecY = {1, 2, 3, 4, 5};
bool result = dv::show(vecX, vecY, "showChartXY_2containers");
EXPECT_EQ(result, true);
}

TEST(ArrayCore, readAndShowMatrixFromFile) {
EXPECT_EQ(dvs::isPlotlyScriptExists(), true);
vector<vector<double>> values;
Expand Down
4 changes: 2 additions & 2 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Windows specific, for goog
# Copy plotly java script to tests
MESSAGE("_____________________ Copy Plotlylib to Tests step ___________________________________________")
if(WIN32)
file(COPY ${CMAKE_SOURCE_DIR}/plotly_maker/plotly-2.27.0.min.js DESTINATION
file(COPY ${CMAKE_SOURCE_DIR}/plotly_maker/plotly-2.32.0.min.js DESTINATION
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/davis_htmls)
file(COPY ${CMAKE_SOURCE_DIR}/plotly_maker/plotly-2.27.0.min.js DESTINATION
file(COPY ${CMAKE_SOURCE_DIR}/plotly_maker/plotly-2.32.0.min.js DESTINATION
${CMAKE_CURRENT_BINARY_DIR}/davis_htmls)
endif(WIN32)

Expand Down
48 changes: 45 additions & 3 deletions Tests/CommonUtilsTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "gtest/gtest.h"
#include "common_utils/common_utils.h"
#include <fstream>
#include <codecvt>
#include <locale>
#include <iostream>
//#include <windows.h>


using std::string;
Expand Down Expand Up @@ -80,15 +84,53 @@ TEST(CommonUtils, CreateStringFantasyArgs) {


TEST(CommonUtils, SplitString) {

auto result = dvs::split(not_filled_test_string_1, '%');

for (int i = 0; i < result.size(); ++i) {
for (size_t i = 0; i < result.size(); ++i) {
TEST_COUT << result[i] << "\n";
}
TEST_COUT << not_filled_test_string_1;
}

TEST(CommonUtils, FindSeparator) {
char sep;
dvs::find_separator("5.0;6;7;8", sep);
EXPECT_EQ(';', sep);
dvs::find_separator("5.0 6 7 8", sep);
EXPECT_EQ(' ', sep);
dvs::find_separator("5.0\t6\t7\t8", sep);
EXPECT_EQ('\t', sep);
}

TEST(CommonUtils, htmlPageNameSanitizer) {
std::vector<double> vec = {1, 2, 3, 4};
std::string name("n-a-m-e 123 e_n_d.,'/now");
std::string clearName = dvs::removeSpecialCharacters(name);
EXPECT_EQ(clearName, std::string("n-a-m-e_123_e_n_dnow"));
}

/*std::string Utf8ToCp1251(const std::string& utf8Str) {
int len = MultiByteToWideChar(CP_UTF8, 0, utf8Str.c_str(), -1, NULL, 0);
wchar_t* wstr = new wchar_t[len];
MultiByteToWideChar(CP_UTF8, 0, utf8Str.c_str(), -1, wstr, len);
len = WideCharToMultiByte(1251, 0, wstr, -1, NULL, 0, NULL, NULL);
char* cp1251 = new char[len];
WideCharToMultiByte(1251, 0, wstr, -1, cp1251, len, NULL, NULL);
std::string result(cp1251);
delete[] wstr;
delete[] cp1251;
return result;
}
TEST(CommonUtils, RussianFileC) {
string russian = "файл.txt";
auto path = Utf8ToCp1251(russian);
std::fstream file;
file.open(path, std::ios::in);
EXPECT_EQ(bool(file), true);
}*/

int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
std::ignore = RUN_ALL_TESTS();
Expand Down
95 changes: 68 additions & 27 deletions array_core/array_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ template<typename C,
typename = std::enable_if_t<std::is_convertible_v<T, double>> >
bool save(C const& container, const string& filename, const configSaveToDisk& configuration = configSaveToDisk());


//! Two 1-dimensional container for X-Y plots
template<typename C, //https://devblogs.microsoft.com/oldnewthing/20190619-00/?p=102599
typename T = std::decay_t<decltype(*begin(std::declval<C>()))>,
typename = std::enable_if_t<std::is_convertible_v<T, double>> >
bool show(C const& containerX, C const& containerY, const string& htmlPageName = dvs::kAppName, const Config& configuration = Config());

template<typename C, //https://devblogs.microsoft.com/oldnewthing/20190619-00/?p=102599
typename T = std::decay_t<decltype(*begin(std::declval<C>()))>,
typename = std::enable_if_t<std::is_convertible_v<T, double>> >
bool save(C const& containerX, C const& containerY, const string& filename, const configSaveToDisk& configuration = configSaveToDisk());


//! 2-dimensional container
template<typename C,
typename E = std::decay_t<decltype(*begin(std::declval<C>()))>,
Expand Down Expand Up @@ -147,12 +160,7 @@ bool save(const T* data, uint64_t count, const string& filename, const configSav

template<typename C, typename T, typename>
bool show(C const& container, const string& htmlPageName, const Config& configuration) {
vector<double> dblRow(container.size());
uint64_t i = 0;
for (auto v : container) {
dblRow[i] = v;
++i;
}
vector<double> dblRow = dvs::vecFromTemplate<double>(container);
bool res = false;
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_CHART)
Expand All @@ -162,35 +170,73 @@ bool show(C const& container, const string& htmlPageName, const Config& configur

template<typename C, typename T, typename>
bool save(C const& container, const string& filename, const configSaveToDisk& configuration) {
vector<T> row(container.size());
uint64_t i = 0;
for (auto v : container) {
row[i] = v;
++i;
}
vector<T> row = dvs::vecFromTemplate<T>(container);
bool res = dvs::saveVec<T>(row, filename, configuration);
return res;
}

template<typename C, typename T, typename>
bool show(C const& containerX, C const& containerY, const string& htmlPageName, const Config& configuration) {
if (containerX.size() != containerY.size()) {
return false;
}
vector<double> dblRowX = dvs::vecFromTemplate<double>(containerX);
vector<double> dblRowY = dvs::vecFromTemplate<double>(containerY);
bool res = dvs::showLineChartInBrowser(dblRowX, dblRowY, htmlPageName, configuration);
return res;
}

template<typename C, typename T, typename>
bool save(C const& containerX, C const& containerY, const string& filename, const configSaveToDisk& configuration) {
if (containerX.size() != containerY.size()) {
return false;
}
vector<T> rowX = dvs::vecFromTemplate<T>(containerX);
vector<T> rowY = dvs::vecFromTemplate<T>(containerY);
vector<vector<T>> vecVec;
vecVec.emplace_back(rowX);
vecVec.emplace_back(rowY);
configSaveToDisk newConf = configuration;
newConf.isTranspose = !configuration.isTranspose;
bool res = dvs::saveVecVec<T>(vecVec, filename, newConf);
return res;
}

template<typename C, typename E, typename T, typename >
bool show(C const& container_of_containers, const string& htmlPageName, const Config& configuration) {
vector<vector<double>> vecVecDbl;
vecVecDbl.reserve(container_of_containers.size());
for (auto row : container_of_containers) {
vector<double> dblRow(row.size());
uint64_t i = 0;
for (auto v : row) {
dblRow[i] = v;
++i;
}
vector<double> dblRow = dvs::vecFromTemplate<double>(row);
vecVecDbl.emplace_back(dblRow);
}
bool res = false;
if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_HEATMAP) {
size_t size1 = vecVecDbl.size();
size_t size2 = 0;
if (!vecVecDbl.empty()) {
size2 = vecVecDbl[0].size();
}
if ((configuration.typeVisual == VISUALTYPE_AUTO || //case when we want to plot graph with X and Y vectors
configuration.typeVisual == VISUALTYPE_CHART) &&
(size1 == 2 || size2 == 2)) { // it can be or 2-columns-data or 2-rows-data
if (size1 == 2) {
res = dvs::showLineChartInBrowser(vecVecDbl[0], vecVecDbl[1], htmlPageName, configuration);
} else if (size2 == 2) {
vector<double> xVals;
vector<double> yVals;
xVals.reserve(size1);
for (int i = 0; i < size1; ++i) {
xVals.emplace_back(vecVecDbl[i][0]);
yVals.emplace_back(vecVecDbl[i][1]);
}
res = dvs::showLineChartInBrowser(xVals, yVals, htmlPageName, configuration);
}
} else if (configuration.typeVisual == VISUALTYPE_AUTO ||
configuration.typeVisual == VISUALTYPE_HEATMAP) {
res = dvs::showHeatMapInBrowser(vecVecDbl, htmlPageName, configuration);
} else if (configuration.typeVisual == VISUALTYPE_SURFACE)
} else if (configuration.typeVisual == VISUALTYPE_SURFACE) {
res = dvs::showSurfaceInBrowser(vecVecDbl, htmlPageName, configuration);
}
return res;
}

Expand All @@ -199,12 +245,7 @@ bool save(C const& container_of_containers, const string& filename, const config
vector<vector<T>> vecVec;
vecVec.reserve(container_of_containers.size());
for (auto row : container_of_containers) {
vector<T> rowTemp(row.size());
uint64_t i = 0;
for (auto v : row) {
rowTemp[i] = v;
++i;
}
vector<T> rowTemp = dvs::vecFromTemplate<T>(row);
vecVec.emplace_back(rowTemp);
}
bool res = dvs::saveVecVec<T>(vecVec, filename, configuration);
Expand Down
4 changes: 3 additions & 1 deletion array_core/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ struct Config {
struct configSaveToDisk {
configSaveToDisk():
separatorOfRows("\n"),
separatorOfCols(";") {}
separatorOfCols(";"),
isTranspose(false) {}
std::string separatorOfRows;
std::string separatorOfCols;
bool isTranspose; //rows-cols or cols-rows
};


Expand Down
2 changes: 1 addition & 1 deletion auto_format.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off
echo davis code is formatting...
start /B astyle --project ./*.cpp,*.h
pause
ping localhost -n 3 >nul
Loading

0 comments on commit 7b0c124

Please sign in to comment.