static build of nodeeditor

This commit is contained in:
Anthony Rabine 2023-05-28 14:39:09 +02:00
parent b619eaefe6
commit ceda217885
8 changed files with 84 additions and 9444 deletions

2
.gitignore vendored
View file

@ -20,3 +20,5 @@ hardware/kicad/ost-pico-addon/fp-info-cache
*.kra~
*.png~
build-story-editor-Desktop_Qt_6_5_1_GCC_64bit-Debug/

View file

@ -12,7 +12,7 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets OpenGLWidgets Multimedia OpenGL)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets OpenGLWidgets Multimedia OpenGL)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Gui OpenGLWidgets Multimedia OpenGL )
set(PROJECT_SOURCES
@ -58,9 +58,6 @@ set(PROJECT_SOURCES
src/event_node_model.cpp
src/highlighter.h
src/highlighter.cpp
src/zip.cpp
src/zip.h
src/miniz.c
src/ost-hmi.ui
src/ost-vm.ui
src/ost-data.ui
@ -80,34 +77,87 @@ include_directories(../software/chip32)
include_directories(../software/library)
add_subdirectory(QHexView)
option(BUILD_SHARED_LIBS "" OFF)
add_subdirectory(nodeeditor)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(${PROJECT_NAME}
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET ost-editor APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(${PROJECT_NAME} SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(${PROJECT_NAME}
${PROJECT_SOURCES}
)
endif()
endif()
set(CMAKE_AUTOMOC ON)
set(NODEEDITOR_SOURCE_FILES
./nodeeditor/src/AbstractGraphModel.cpp
./nodeeditor/src/AbstractNodeGeometry.cpp
./nodeeditor/src/BasicGraphicsScene.cpp
./nodeeditor/src/ConnectionGraphicsObject.cpp
./nodeeditor/src/ConnectionPainter.cpp
./nodeeditor/src/ConnectionState.cpp
./nodeeditor/src/ConnectionStyle.cpp
./nodeeditor/src/DataFlowGraphModel.cpp
./nodeeditor/src/DataFlowGraphicsScene.cpp
./nodeeditor/src/DefaultHorizontalNodeGeometry.cpp
./nodeeditor/src/DefaultVerticalNodeGeometry.cpp
./nodeeditor/src/Definitions.cpp
./nodeeditor/src/GraphicsView.cpp
./nodeeditor/src/GraphicsViewStyle.cpp
./nodeeditor/src/NodeDelegateModelRegistry.cpp
./nodeeditor/src/NodeConnectionInteraction.cpp
./nodeeditor/src/NodeDelegateModel.cpp
./nodeeditor/src/NodeGraphicsObject.cpp
./nodeeditor/src/DefaultNodePainter.cpp
./nodeeditor/src/NodeState.cpp
./nodeeditor/src/NodeStyle.cpp
./nodeeditor/src/StyleCollection.cpp
./nodeeditor/src/UndoCommands.cpp
./nodeeditor/src/locateNode.cpp
./nodeeditor/resources/resources.qrc
)
set(NODEEDITOR_HEADER_FILES
./nodeeditor/include/QtNodes/internal/AbstractGraphModel.hpp
./nodeeditor/include/QtNodes/internal/AbstractNodeGeometry.hpp
./nodeeditor/include/QtNodes/internal/AbstractNodePainter.hpp
./nodeeditor/include/QtNodes/internal/BasicGraphicsScene.hpp
./nodeeditor/include/QtNodes/internal/Compiler.hpp
./nodeeditor/include/QtNodes/internal/ConnectionGraphicsObject.hpp
./nodeeditor/include/QtNodes/internal/ConnectionIdHash.hpp
./nodeeditor/include/QtNodes/internal/ConnectionIdUtils.hpp
./nodeeditor/include/QtNodes/internal/ConnectionState.hpp
./nodeeditor/include/QtNodes/internal/ConnectionStyle.hpp
./nodeeditor/include/QtNodes/internal/DataFlowGraphicsScene.hpp
./nodeeditor/include/QtNodes/internal/DataFlowGraphModel.hpp
./nodeeditor/include/QtNodes/internal/DefaultNodePainter.hpp
./nodeeditor/include/QtNodes/internal/Definitions.hpp
./nodeeditor/include/QtNodes/internal/Export.hpp
./nodeeditor/include/QtNodes/internal/GraphicsView.hpp
./nodeeditor/include/QtNodes/internal/GraphicsViewStyle.hpp
./nodeeditor/include/QtNodes/internal/locateNode.hpp
./nodeeditor/include/QtNodes/internal/NodeData.hpp
./nodeeditor/include/QtNodes/internal/NodeDelegateModel.hpp
./nodeeditor/include/QtNodes/internal/NodeDelegateModelRegistry.hpp
./nodeeditor/include/QtNodes/internal/NodeGraphicsObject.hpp
./nodeeditor/include/QtNodes/internal/NodeState.hpp
./nodeeditor/include/QtNodes/internal/NodeStyle.hpp
./nodeeditor/include/QtNodes/internal/OperatingSystem.hpp
./nodeeditor/include/QtNodes/internal/QStringStdHash.hpp
./nodeeditor/include/QtNodes/internal/QUuidStdHash.hpp
./nodeeditor/include/QtNodes/internal/Serializable.hpp
./nodeeditor/include/QtNodes/internal/Style.hpp
./nodeeditor/include/QtNodes/internal/StyleCollection.hpp
./nodeeditor/include/QtNodes/internal/ConnectionPainter.hpp
./nodeeditor/include/QtNodes/internal/DefaultHorizontalNodeGeometry.hpp
./nodeeditor/include/QtNodes/internal/DefaultVerticalNodeGeometry.hpp
./nodeeditor/include/QtNodes/internal/NodeConnectionInteraction.hpp
./nodeeditor/include/QtNodes/internal/UndoCommands.hpp
)
qt_add_executable(${PROJECT_NAME}
MANUAL_FINALIZATION
${PROJECT_SOURCES}
${NODEEDITOR_SOURCE_FILES}
${NODEEDITOR_HEADER_FILES}
)
target_compile_definitions(${PROJECT_NAME} PUBLIC NODE_EDITOR_STATIC)
target_include_directories(${PROJECT_NAME} PUBLIC nodeeditor/include nodeeditor/include/QtNodes/internal)
target_include_directories(${PROJECT_NAME} PUBLIC ${NODE_EDITOR_HEADERS})
target_link_directories(${PROJECT_NAME} PUBLIC ${NODE_EDITOR_LIBDIR})
target_link_libraries(${PROJECT_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Core
@ -116,7 +166,6 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::OpenGLWidgets
Qt${QT_VERSION_MAJOR}::OpenGL
Qt${QT_VERSION_MAJOR}::Multimedia
QtNodes
QHexView
)

@ -1 +1 @@
Subproject commit bc72cd22267f752f6552b4f6e6c733649e54c4c2
Subproject commit 8669e1cff4ad8a47510d31ffc6dead959a4b8975

@ -1 +1 @@
Subproject commit d5250cd445a6fa2177075603f1ca5580c3498c8e
Subproject commit bf458f2e4adef93ef75eeac40b20d50ae9c50726

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,273 +0,0 @@
/**
* MIT License
* Copyright (c) 2019 Anthony Rabine
*/
#include "zip.h"
#include <fstream>
#include <cstring>
#include <functional>
#include <memory>
#include <filesystem>
static bool ensure_file_exists_and_is_readable(const char *pFilename)
{
FILE *p = nullptr;
#ifdef Q_OS_WIN
fopen_s(& p, pFilename, "rb");
#else
p = fopen(pFilename, "rb");
#endif
if (!p) {
return false;
}
fseek(p, 0, SEEK_END);
long int src_file_size = ftell(p);
fseek(p, 0, SEEK_SET);
if (src_file_size)
{
char buf[1];
if (fread(buf, 1, 1, p) != 1)
{
fclose(p);
return false;
}
}
fclose(p);
return true;
}
/*****************************************************************************/
Zip::Zip()
: mIsValid(false)
, mNumberOfFiles(0U)
{
std::memset(&mZipArchive, 0, sizeof(mZipArchive));
}
/*****************************************************************************/
Zip::~Zip()
{
Close();
}
/*****************************************************************************/
void Zip::CreateInMemory(const std::string &fileName)
{
mz_bool status = MZ_FALSE;
std::memset(&mZipArchive, 0, sizeof(mZipArchive));
status = mz_zip_writer_init_file(&mZipArchive, fileName.c_str(), 65537);
if (status)
{
mIsOpenForWriting = true;
mIsValid = true;
mIsOpen = true;
}
else
{
mIsOpenForWriting = false;
mIsValid = false;
}
}
/*****************************************************************************/
bool Zip::AddFile(const std::string &fileName, const std::string &archiveName)
{
mz_bool status = MZ_FALSE;
if (ensure_file_exists_and_is_readable(fileName.c_str()))
{
status = mz_zip_writer_add_file(&mZipArchive, archiveName.c_str(), fileName.c_str(), NULL, 0, MZ_NO_COMPRESSION);
}
return status == MZ_TRUE;
}
/*****************************************************************************/
void Zip::AddDirectory(const std::string &dirName)
{
std::string d = dirName + "/";
mz_zip_writer_add_mem(&mZipArchive, d.c_str(), NULL, 0, MZ_NO_COMPRESSION);
}
/*****************************************************************************/
std::vector<std::string> Zip::Unzip(std::string const &zipFile, const std::string &destination_dir, std::string const &password)
{
(void)(password);
std::vector<std::string> files = {};
mz_zip_archive zip_archive;
memset(&zip_archive, 0, sizeof(zip_archive));
auto status = mz_zip_reader_init_file(&zip_archive, zipFile.c_str(), 0);
if (!status) return files;
int fileCount = (int)mz_zip_reader_get_num_files(&zip_archive);
if (fileCount == 0)
{
mz_zip_reader_end(&zip_archive);
return files;
}
mz_zip_archive_file_stat file_stat;
if (!mz_zip_reader_file_stat(&zip_archive, 0, &file_stat))
{
mz_zip_reader_end(&zip_archive);
return files;
}
// Get root folder
// QFileInfo fileInfo(file_stat.m_filename);
// QFileInfo filePath(fileInfo.path());
// QString baseName = filePath.path();
// QString dstDir = QString::fromStdString(destination_dir);
// QString separator = "/";
std::string base = std::filesystem::path(file_stat.m_filename).parent_path().string();
// Get and print information about each file in the archive.
for (int i = 0; i < fileCount; i++)
{
if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat)) continue;
if (mz_zip_reader_is_file_a_directory(&zip_archive, i)) continue; // skip directories for now
std::string fileName = base + std::filesystem::path::preferred_separator + file_stat.m_filename; // make path relative
std::string destFile = destination_dir + std::filesystem::path::preferred_separator + fileName; // make full dest path
// creates the directory where the file will be decompressed
std::filesystem::create_directories(std::filesystem::path(destFile).parent_path());
// Extract file
if (mz_zip_reader_extract_to_file(&zip_archive, i, destFile.c_str(), 0))
{
files.emplace_back(destFile);
}
}
// Close the archive, freeing any resources it was using
mz_zip_reader_end(&zip_archive);
return files;
}
/*****************************************************************************/
bool Zip::Open(const std::string &zip, bool isFile)
{
mz_bool status;
mIsValid = false;
mIsOpenForWriting = true;
mNumberOfFiles = 0U;
std::memset(&mZipArchive, 0, sizeof(mZipArchive));
if (isFile)
{
// Physical file on disk
status = mz_zip_reader_init_file(&mZipArchive, zip.c_str(), 0);
}
else
{
// Zipped memory
status = mz_zip_reader_init_mem(&mZipArchive, zip.c_str(), zip.size(), 0);
}
if (status)
{
mFiles.clear();
// Get and print information about each file in the archive.
for (std::uint32_t i = 0; i < mz_zip_reader_get_num_files(&mZipArchive); i++)
{
mz_zip_archive_file_stat file_stat;
if (mz_zip_reader_file_stat(&mZipArchive, i, &file_stat))
{
mNumberOfFiles++;
mFiles.push_back(file_stat.m_filename);
//printf("Filename: \"%s\", Comment: \"%s\", Uncompressed size: %u, Compressed size: %u\n", file_stat.m_filename, file_stat.m_comment, (std::uint32_t)file_stat.m_uncomp_size, (std::uint32_t)file_stat.m_comp_size);
}
}
}
if (mNumberOfFiles == mz_zip_reader_get_num_files(&mZipArchive))
{
mIsValid = true;
mIsOpen = true;
}
return mIsValid;
}
/*****************************************************************************/
void Zip::Close()
{
if (mIsValid)
{
if (mIsOpenForWriting)
{
if (!mz_zip_writer_finalize_archive(&mZipArchive))
{
mz_zip_writer_end(&mZipArchive);
}
}
else
{
mz_zip_reader_end(&mZipArchive);
}
}
mIsOpen = false;
}
/*****************************************************************************/
struct UserData
{
char *output;
int offset;
};
static mz_bool DeflateCallback(const void *pBuf, int len, void *pUser)
{
UserData *ud = static_cast<UserData*>(pUser);
std::memcpy(ud->output + ud->offset, pBuf, len);
ud->offset += len;
(void) len;
(void) pUser;
return MZ_TRUE;
}
/*****************************************************************************/
int Zip::CompressBuffer(const char *input, size_t input_size, char *output)
{
int finalsize = -1;
tdefl_compressor Comp;
UserData ud;
ud.offset = 0U;
ud.output = output;
if (tdefl_init(&Comp, DeflateCallback, &ud, 0) == TDEFL_STATUS_OKAY)
{
if(tdefl_compress_buffer(&Comp, input, input_size, TDEFL_FINISH) == TDEFL_STATUS_DONE)
{
finalsize = ud.offset;
}
}
return finalsize;
}
/*****************************************************************************/
bool Zip::GetFile(const std::string &fileName, std::string &contents)
{
bool ret = false;
if (mIsValid)
{
size_t size;
char *p = reinterpret_cast<char *>(mz_zip_reader_extract_file_to_heap(&mZipArchive, fileName.c_str(), &size, 0));
if (p != nullptr)
{
contents.assign(p, size);
free(p);
ret = true;
}
}
return ret;
}
/*****************************************************************************/
std::vector<std::string> Zip::ListFiles()
{
return mFiles;
}
//=============================================================================
// End of file Zip.cpp
//=============================================================================

View file

@ -1,52 +0,0 @@
/**
* MIT License
* Copyright (c) 2019 Anthony Rabine
*/
#ifndef ZIP_H
#define ZIP_H
#include <cstdint>
#include <string>
#include <vector>
#include "miniz.h"
/*****************************************************************************/
class Zip
{
public:
Zip();
~Zip();
bool Open(const std::string &zip, bool isFile);
std::uint32_t NumberOfFiles() { return mNumberOfFiles; }
bool GetFile(const std::string &fileName, std::string &contents);
std::vector<std::string> ListFiles();
void Close();
bool IsOpen() const { return mIsOpen; }
bool isOpenForWriting() const { return mIsOpenForWriting; }
static int CompressBuffer(const char *input, size_t input_size, char *output);
void CreateInMemory(const std::string &fileName);
bool AddFile(const std::string &fileName, const std::string &archiveName);
void AddDirectory(const std::string &dirName);
static std::vector<std::string> Unzip(const std::string &zipFile, const std::string &destination_dir, const std::string &password);
private:
mz_zip_archive mZipArchive;
bool mIsValid;
bool mIsOpen{false};
bool mIsOpenForWriting{false};
std::uint32_t mNumberOfFiles;
std::vector<std::string> mFiles;
};
#endif // ZIP_H
//=============================================================================
// End of file Zip.cpp
//=============================================================================