Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gui qt #129

Merged
merged 39 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
574764c
integrate gui
ValeryStk Jul 22, 2024
6788d60
drag and drop
ValeryStk Jul 23, 2024
5487f77
js version arg
ValeryStk Jul 23, 2024
0d10fc7
WIP
ValeryStk Jul 23, 2024
c718499
dark
AntonMrt Jul 23, 2024
514d6bf
WIP
ValeryStk Jul 24, 2024
1878566
switch from surface to heatmap
ValeryStk Jul 24, 2024
7698b90
icon + fix d&d bug
AntonMrt Jul 24, 2024
e490d95
Update davis_gui.cpp
AntonMrt Jul 24, 2024
a7818ab
WIP
ValeryStk Jul 25, 2024
bbffec8
WIP (auto separator)
ValeryStk Jul 25, 2024
34d2a02
WIP
ValeryStk Jul 26, 2024
2f4cbc6
WIP (maybe comma maybe dot)
ValeryStk Jul 26, 2024
017a308
new text
AntonMrt Aug 5, 2024
0027e50
fix find separator bug
ValeryStk Aug 6, 2024
c1ecfe9
add dv:show for XY chart
AntonMrt Aug 9, 2024
4a040e4
plotXY from file + megaBATfile (#116)
AntonMrt Aug 12, 2024
d7aef25
WIP (not working state)
remsensLDF Aug 14, 2024
2fbb8c7
Update davis_gui.cpp
ValeryStk Aug 15, 2024
bd1ec43
WIP (smart show)
ValeryStk Aug 16, 2024
4fd14dd
fix show console case
ValeryStk Aug 16, 2024
7918405
About window (#118)
AntonMrt Aug 16, 2024
b29c820
format
ValeryStk Aug 16, 2024
8a99e44
need test
ValeryStk Aug 16, 2024
b130f93
test_build
ValeryStk Aug 16, 2024
cbe2178
dv::show&save XY 2 containers
AntonMrt Aug 28, 2024
a7d4b65
bugfixes
AntonMrt Aug 28, 2024
3f3d080
refactoring in array_core + secret music
AntonMrt Sep 1, 2024
4896f77
copy button
AntonMrt Sep 1, 2024
50051ba
html page name sanitizer
AntonMrt Sep 2, 2024
9c30858
dv::save() XY data now save as 2 column
AntonMrt Sep 2, 2024
649633c
Update CMakeLists.txt
ValeryStk Sep 16, 2024
a548b12
Update CMakeLists.txt
ValeryStk Sep 16, 2024
f8a921e
Update CMakeLists.txt
ValeryStk Sep 16, 2024
8aaee66
Update CMakeLists.txt
ValeryStk Sep 16, 2024
268f554
Update CommonUtilsTest.cpp
ValeryStk Sep 16, 2024
9f9fe58
Update CMakeLists.txt
ValeryStk Sep 17, 2024
592cadb
Update CMakeLists.txt
ValeryStk Sep 17, 2024
773e2ba
Update CMakeLists.txt
ValeryStk Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading