From b76dc184b35f7259f0733ce7cb09098ecdf55248 Mon Sep 17 00:00:00 2001 From: James Grogan Date: Mon, 16 Jan 2023 12:36:02 +0000 Subject: [PATCH] Fix up linux build. --- .../src/visuals/BlochSphereNode.h | 32 +++++++++---------- .../test/TestBlochSphereNode.cpp | 22 +++++++------ src/core/encoding/UnicodeUtils.cpp | 3 +- src/core/memory/SharedMemory.cpp | 4 ++- src/fonts/FreeTypeFontEngine.cpp | 7 ++-- src/fonts/FreeTypeFontEngine.h | 3 +- src/geometry/grid/TypedGrid.h | 24 ++++++++------ src/graphics/opengl/OpenGlFontTexture.cpp | 3 +- src/graphics/opengl/OpenGlMeshPainter.cpp | 6 ++-- src/graphics/opengl/OpenGlMeshPainter.h | 2 +- src/graphics/opengl/OpenGlPainter.cpp | 4 +-- src/image/Image.cpp | 2 ++ src/image/png/BasicPngWriter.h | 4 +-- src/image/png/PngWriter.cpp | 4 +-- src/mesh/AbstractMesh.cpp | 3 +- src/network/NetworkManager.cpp | 2 +- src/windows/ui_interfaces/x11/XcbImage.h | 3 +- .../ui_interfaces/x11/XcbInterface.cpp | 6 ++-- src/windows/ui_interfaces/x11/XcbInterface.h | 2 +- src/windows/ui_interfaces/x11/XcbWindow.cpp | 2 +- test/ui_test_runner.cpp | 14 +++++--- 21 files changed, 86 insertions(+), 66 deletions(-) diff --git a/plugins/quantum_computing/src/visuals/BlochSphereNode.h b/plugins/quantum_computing/src/visuals/BlochSphereNode.h index 9ac889c..c5280fe 100644 --- a/plugins/quantum_computing/src/visuals/BlochSphereNode.h +++ b/plugins/quantum_computing/src/visuals/BlochSphereNode.h @@ -11,24 +11,24 @@ class LineNode; class BlochSphereNode : public AbstractVisualNode { public: - BlochSphereNode(const Point& location); + BlochSphereNode(const Point& location); - void setContent(BlochSphere* content); + void setContent(BlochSphere* content); - void update(SceneInfo* sceneInfo) override; + void update(SceneInfo* sceneInfo) override; - void setSize(double size); + void setSize(double size); private: - double mSize{ 1.0 }; - bool mContentDirty{ true }; - BlochSphere* mContent{ nullptr }; + double mSize{ 1.0 }; + bool mContentDirty{ true }; + BlochSphere* mContent{ nullptr }; - std::unique_ptr mOuterCircle; - std::unique_ptr mInnerCircle; - std::unique_ptr mCentreCircle; - std::unique_ptr mStateMarkerCircle; - std::unique_ptr mXAxis; - std::unique_ptr mYAxis; - std::unique_ptr mZAxis; - std::unique_ptr mStateVector; -}; \ No newline at end of file + std::unique_ptr mOuterCircle; + std::unique_ptr mInnerCircle; + std::unique_ptr mCentreCircle; + std::unique_ptr mStateMarkerCircle; + std::unique_ptr mXAxis; + std::unique_ptr mYAxis; + std::unique_ptr mZAxis; + std::unique_ptr mStateVector; +}; diff --git a/plugins/quantum_computing/test/TestBlochSphereNode.cpp b/plugins/quantum_computing/test/TestBlochSphereNode.cpp index f7ffc87..e955870 100644 --- a/plugins/quantum_computing/test/TestBlochSphereNode.cpp +++ b/plugins/quantum_computing/test/TestBlochSphereNode.cpp @@ -3,21 +3,23 @@ #include "TestRenderUtils.h" #include "BlochSphereNode.h" +#include "CircleNode.h" +#include "LineNode.h" #include "BlochSphere.h" TEST_CASE(TestBlochSphereNode, "quantum_computing") { - TestRenderer renderer(100, 100); + TestRenderer renderer(100, 100); - auto node = std::make_unique(Point(0.5, 0.5)); + auto node = std::make_unique(Point(0.5, 0.5)); - Qubit state({ 1.0, 0.0 }, { 0.0, 0.0 }); + Qubit state({ 1.0, 0.0 }, { 0.0, 0.0 }); - auto bloch_sphere = std::make_unique(state); - - node->setSize(100); - node->setContent(bloch_sphere.get()); + auto bloch_sphere = std::make_unique(state); - renderer.getScene()->addNode(node.get()); - renderer.writeSvg(TestUtils::getTestOutputDir(__FILE__) / "bloch_sphere.svg"); -} \ No newline at end of file + node->setSize(100); + node->setContent(bloch_sphere.get()); + + renderer.getScene()->addNode(node.get()); + renderer.writeSvg(TestUtils::getTestOutputDir(__FILE__) / "bloch_sphere.svg"); +} diff --git a/src/core/encoding/UnicodeUtils.cpp b/src/core/encoding/UnicodeUtils.cpp index 5853d4d..a6e8937 100644 --- a/src/core/encoding/UnicodeUtils.cpp +++ b/src/core/encoding/UnicodeUtils.cpp @@ -3,6 +3,7 @@ #include "Win32BaseIncludes.h" #include +#include std::string UnicodeUtils::utf16ToUtf8String(const std::wstring& input) { @@ -37,4 +38,4 @@ std::wstring UnicodeUtils::utf8ToUtf16WString(const std::string& input) #else throw std::logic_error("Not implemented"); #endif -} \ No newline at end of file +} diff --git a/src/core/memory/SharedMemory.cpp b/src/core/memory/SharedMemory.cpp index 2ccd7f3..5cb9901 100644 --- a/src/core/memory/SharedMemory.cpp +++ b/src/core/memory/SharedMemory.cpp @@ -10,7 +10,7 @@ #include #endif -void SharedMemory::allocate(const std::string& namePrefix, std::size_t) +void SharedMemory::allocate(const std::string& namePrefix, std::size_t size) { createFile(namePrefix); @@ -30,6 +30,8 @@ void SharedMemory::allocate(const std::string& namePrefix, std::size_t) close(mFileDescriptor); mIsValid = false; } +#else + (void)(size); #endif } diff --git a/src/fonts/FreeTypeFontEngine.cpp b/src/fonts/FreeTypeFontEngine.cpp index 94d33a4..3187832 100644 --- a/src/fonts/FreeTypeFontEngine.cpp +++ b/src/fonts/FreeTypeFontEngine.cpp @@ -1,6 +1,7 @@ #include "FreeTypeFontEngine.h" #include "Image.h" +#include "Grid.h" #include "FileLogger.h" #include "FontGlyph.h" @@ -20,7 +21,7 @@ void FreeTypeFontEngine::initialize() } } -void FreeTypeFontEngine::loadFontFace(const std::filesystem::path& fontFile, int penSize) +void FreeTypeFontEngine::loadFontFace(const std::filesystem::path& fontFile, float penSize) { if (!mLibrary) { @@ -78,7 +79,7 @@ std::unique_ptr FreeTypeFontEngine::loadGlyph(uint32_t charCode) auto rows = mWorkingFontFace->glyph->bitmap.rows; auto columns = mWorkingFontFace->glyph->bitmap.width; - auto image = std::make_unique> (columns, rows); + auto image = std::make_unique(columns, rows); unsigned counter = 0; std::vector data(rows*columns, 0); @@ -90,7 +91,7 @@ std::unique_ptr FreeTypeFontEngine::loadGlyph(uint32_t charCode) counter++; } } - image->setData(data); + image->getGridT()->setData(data); auto glyph = std::make_unique(mWorkingFontFace->glyph->bitmap.width, mWorkingFontFace->glyph->bitmap.rows, mWorkingFontFace->glyph->bitmap_left, diff --git a/src/fonts/FreeTypeFontEngine.h b/src/fonts/FreeTypeFontEngine.h index b84572d..5c77d08 100644 --- a/src/fonts/FreeTypeFontEngine.h +++ b/src/fonts/FreeTypeFontEngine.h @@ -4,7 +4,6 @@ #include "Image.h" -template class Image; #include @@ -17,7 +16,7 @@ public: void initialize() override; - void loadFontFace(const std::filesystem::path& fontFile, int penSize = 16) override; + void loadFontFace(const std::filesystem::path& fontFile, float penSize = 16) override; std::unique_ptr loadGlyph(uint32_t charCode) override; diff --git a/src/geometry/grid/TypedGrid.h b/src/geometry/grid/TypedGrid.h index 13aab21..6e0df7a 100644 --- a/src/geometry/grid/TypedGrid.h +++ b/src/geometry/grid/TypedGrid.h @@ -9,16 +9,22 @@ template class TypedGrid : public AbstractGrid { public: - TypedGrid(const Bounds& bounds, std::size_t numPointsX, std::size_t numPointsY, std::size_t numPointsZ = 1) - : AbstractGrid(bounds, numPointsX, numPointsY, numPointsZ), - mData(std::make_unique >()) - { - } + TypedGrid(const Bounds& bounds, std::size_t numPointsX, std::size_t numPointsY, std::size_t numPointsZ = 1) + : AbstractGrid(bounds, numPointsX, numPointsY, numPointsZ), + mData(std::make_unique >()) + { + } - virtual T getItem(std::size_t idx, std::size_t jdx, std::size_t kdx) const = 0; + virtual ~TypedGrid() = default; - virtual void setItem(std::size_t idx, std::size_t jdx, std::size_t kdx, const T& value) = 0; + virtual T getItem(std::size_t idx, std::size_t jdx, std::size_t kdx) const = 0; + virtual void setItem(std::size_t idx, std::size_t jdx, std::size_t kdx, const T& value) = 0; + + List* getInternalData() const + { + return mData.get(); + } protected: - std::unique_ptr > mData; -}; \ No newline at end of file + std::unique_ptr > mData; +}; diff --git a/src/graphics/opengl/OpenGlFontTexture.cpp b/src/graphics/opengl/OpenGlFontTexture.cpp index 8ae5134..232efae 100644 --- a/src/graphics/opengl/OpenGlFontTexture.cpp +++ b/src/graphics/opengl/OpenGlFontTexture.cpp @@ -1,6 +1,7 @@ #include "OpenGlFontTexture.h" #include "FontGlyph.h" +#include "Grid.h" #include "Image.h" #define GL_GLEXT_PROTOTYPES @@ -14,7 +15,7 @@ OpenGlFontTexture::OpenGlFontTexture(FontGlyph* glyph) glGenTextures(1, &mHandle); glBindTexture(GL_TEXTURE_2D, mHandle); - auto buffer = glyph->getImage()->getDataPtr(); + auto buffer = glyph->getImage()->getGridT()->getInternalData()->getDataPtr(); glTexImage2D( GL_TEXTURE_2D, diff --git a/src/graphics/opengl/OpenGlMeshPainter.cpp b/src/graphics/opengl/OpenGlMeshPainter.cpp index 098d300..20de4b8 100644 --- a/src/graphics/opengl/OpenGlMeshPainter.cpp +++ b/src/graphics/opengl/OpenGlMeshPainter.cpp @@ -45,7 +45,7 @@ void OpenGlMeshPainter::initializeBuffers() glGenVertexArrays(1, &mVertexArray); } -void OpenGlMeshPainter::paint(const std::vector& verts, const std::vector& elements, const std::vector& color, bool lines) +void OpenGlMeshPainter::paint(const std::vector& verts, const std::vector& elements, const std::vector& color, bool lines) { glBindVertexArray(mVertexArray); @@ -113,7 +113,7 @@ void OpenGlMeshPainter::paint(SceneModel* model, DrawingContext* context) } - std::vector indices; + std::vector indices; const bool line_mesh = model->getMesh()->getType() == AbstractMesh::MeshType::LINE; if (line_mesh) { @@ -124,7 +124,7 @@ void OpenGlMeshPainter::paint(SceneModel* model, DrawingContext* context) indices = dynamic_cast(model->getMesh())->getFaceNodeIds(); } - auto model_color = model->getColor().getAsVectorDouble(); + auto model_color = model->getFillColor().getAsVectorDouble(); std::vector color = {float(model_color[0]), float(model_color[1]), float(model_color[2]), float(model_color[3])}; paint(vertices, indices, color, line_mesh); diff --git a/src/graphics/opengl/OpenGlMeshPainter.h b/src/graphics/opengl/OpenGlMeshPainter.h index 92521b3..0e1d8df 100644 --- a/src/graphics/opengl/OpenGlMeshPainter.h +++ b/src/graphics/opengl/OpenGlMeshPainter.h @@ -18,7 +18,7 @@ private: void initializeShader(); void initializeBuffers(); - void paint(const std::vector& verts, const std::vector& elements, const std::vector& color, bool lines = false); + void paint(const std::vector& verts, const std::vector& elements, const std::vector& color, bool lines = false); unsigned mVertexBuffer{0}; unsigned mElementBuffer{0}; diff --git a/src/graphics/opengl/OpenGlPainter.cpp b/src/graphics/opengl/OpenGlPainter.cpp index d6110f3..de32035 100644 --- a/src/graphics/opengl/OpenGlPainter.cpp +++ b/src/graphics/opengl/OpenGlPainter.cpp @@ -32,7 +32,7 @@ #include OpenGlPainter::OpenGlPainter(DrawingContext* context) - : AbstractPainter(context) + : AbstractPainter(context), mMeshPainter(std::make_unique()), mTextPainter(std::make_unique()) { @@ -41,7 +41,7 @@ OpenGlPainter::OpenGlPainter(DrawingContext* context) void OpenGlPainter::paint() { - auto surface = context->getSurface(); + auto surface = mDrawingContext->getSurface(); const auto width = double(surface->getWidth()); const auto height = double(surface->getHeight()); diff --git a/src/image/Image.cpp b/src/image/Image.cpp index 14ba182..6724419 100644 --- a/src/image/Image.cpp +++ b/src/image/Image.cpp @@ -84,7 +84,9 @@ PlatformImage* Image::getPlatformImage() { if (!mPlatformImage) { +#ifdef _WIN32 mPlatformImage = std::make_unique(this); +#endif } return mPlatformImage.get(); } diff --git a/src/image/png/BasicPngWriter.h b/src/image/png/BasicPngWriter.h index 5331e6f..ee2e051 100644 --- a/src/image/png/BasicPngWriter.h +++ b/src/image/png/BasicPngWriter.h @@ -20,7 +20,7 @@ class BasicPngWriter : public IImageWriter public: BasicPngWriter(); - ~BasicPngWriter(); + virtual ~BasicPngWriter(); static std::unique_ptr Create(); @@ -49,4 +49,4 @@ private: PngHeader mPngHeader; Deflate::CompressionMethod mCompressionMethod{ Deflate::CompressionMethod::DYNAMIC_HUFFMAN }; -}; \ No newline at end of file +}; diff --git a/src/image/png/PngWriter.cpp b/src/image/png/PngWriter.cpp index c81a942..e8744de 100644 --- a/src/image/png/PngWriter.cpp +++ b/src/image/png/PngWriter.cpp @@ -12,7 +12,7 @@ PngWriter::PngWriter() #ifdef _WIN32 mWriterImpl = std::make_unique(mFormat); #else - mWriterImpl = std::make_unique(mFormat); + mWriterImpl = std::make_unique(); #endif } @@ -29,4 +29,4 @@ std::unique_ptr PngWriter::Create() void PngWriter::write(const Path& path, Image* image) { mWriterImpl->write(path, image); -} \ No newline at end of file +} diff --git a/src/mesh/AbstractMesh.cpp b/src/mesh/AbstractMesh.cpp index d6c15e2..0918906 100644 --- a/src/mesh/AbstractMesh.cpp +++ b/src/mesh/AbstractMesh.cpp @@ -61,7 +61,8 @@ void AbstractMesh::transform(const Transform& transform) void AbstractMesh::translate(double offsetX, double offsetY, double offsetZ) { - Transform transform({ -offsetX, -offsetY, -offsetZ }); + const Point loc {-offsetX, -offsetY, -offsetZ}; + Transform transform(loc); for (auto& node : mNodes) { node->apply(transform); diff --git a/src/network/NetworkManager.cpp b/src/network/NetworkManager.cpp index 61ea732..6681974 100644 --- a/src/network/NetworkManager.cpp +++ b/src/network/NetworkManager.cpp @@ -40,7 +40,7 @@ void NetworkManager::runHttpServer(AbstractWebApp* webApp) #else if (!mSocketInterface) { - Initialize(); + initialize(); } auto socket = Socket::Create(); diff --git a/src/windows/ui_interfaces/x11/XcbImage.h b/src/windows/ui_interfaces/x11/XcbImage.h index c24b650..8dc5c1b 100644 --- a/src/windows/ui_interfaces/x11/XcbImage.h +++ b/src/windows/ui_interfaces/x11/XcbImage.h @@ -3,6 +3,7 @@ #include #include "Window.h" +#include "Grid.h" #include "XcbWindow.h" #include "Image.h" @@ -28,7 +29,7 @@ public: const auto h = window->getHeight(); //auto data = const_cast(backing_image->getDataPtr()); - auto data = backing_image->getData(); + auto data = backing_image->getGridT()->getInternalData()->getData(); unsigned char* converted = &data[0]; mXImage = xcb_image_create_native(connection, w, h, XCB_IMAGE_FORMAT_Z_PIXMAP, screen->root_depth, converted, w*h*4, converted); diff --git a/src/windows/ui_interfaces/x11/XcbInterface.cpp b/src/windows/ui_interfaces/x11/XcbInterface.cpp index 24da469..1d4b4a7 100644 --- a/src/windows/ui_interfaces/x11/XcbInterface.cpp +++ b/src/windows/ui_interfaces/x11/XcbInterface.cpp @@ -46,8 +46,8 @@ namespace { } _xkb_event; } -XcbInterface::XcbInterface(DesktopManager* desktopManager, std::unique_ptr fontsManager, bool useHardware) - : AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware), +XcbInterface::XcbInterface(DesktopManager* desktopManager, bool useHardware) + : AbstractUIInterface(desktopManager, useHardware), mEventInterface(XcbEventInterface::Create()), mExtensionInterface(std::make_unique()) { @@ -177,7 +177,7 @@ uint32_t XcbInterface::getEventMask() void XcbInterface::addWindow(mt::Window* window) { auto screen = mDesktopManager->getDefaultScreen(); - XcbWindow::add(window, mConnection, screen, getEventMask(), mFontsManager.get(), mGlInterface.get()); + XcbWindow::add(window, mConnection, screen, getEventMask(), mDesktopManager->getFontsManager(), mGlInterface.get()); } void XcbInterface::onPaint() diff --git a/src/windows/ui_interfaces/x11/XcbInterface.h b/src/windows/ui_interfaces/x11/XcbInterface.h index d8ef107..e749fcf 100644 --- a/src/windows/ui_interfaces/x11/XcbInterface.h +++ b/src/windows/ui_interfaces/x11/XcbInterface.h @@ -27,7 +27,7 @@ namespace mt class XcbInterface : public AbstractUIInterface { public: - XcbInterface(DesktopManager* desktopManager, std::unique_ptr fontsManager, bool useHardware = true); + XcbInterface(DesktopManager* desktopManager, bool useHardware = true); ~XcbInterface(); diff --git a/src/windows/ui_interfaces/x11/XcbWindow.cpp b/src/windows/ui_interfaces/x11/XcbWindow.cpp index 3f09357..d2ffad5 100644 --- a/src/windows/ui_interfaces/x11/XcbWindow.cpp +++ b/src/windows/ui_interfaces/x11/XcbWindow.cpp @@ -69,7 +69,7 @@ void XcbWindow::add(mt::Window* window, xcb_connection_t* connection, mt::Screen auto xcb_window = std::make_unique(window, hwnd, connection, xcbGlInterface); const auto drawing_mode = xcbGlInterface ? DrawingMode::GRAPH : DrawingMode::RASTER; - window->setPlatformWindow(std::move(xcb_window), fontsManager, drawing_mode); + window->setPlatformWindow(std::move(xcb_window)); } int XcbWindow::getHandle() const diff --git a/test/ui_test_runner.cpp b/test/ui_test_runner.cpp index 6f6f5f7..64961d3 100644 --- a/test/ui_test_runner.cpp +++ b/test/ui_test_runner.cpp @@ -19,9 +19,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine std::cout.rdbuf(out.rdbuf()); CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); - - auto args = CommandLineArgs::Create(); - CommandLineArgs::initialize(args.get()); + + auto args = CommandLineArgs::Create(); + CommandLineArgs::initialize(args.get()); const auto user_args = args->getUserArgs(); @@ -34,12 +34,16 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine main_app->initialize(std::move(args), std::move(applicationContext)); auto gui_app = std::make_unique(nullptr, std::move(main_app)); - + #else int main(int argc, char *argv[]) { - auto args = CommandLineArgs::Create(); + auto args = CommandLineArgs::Create(); args->process(argc, argv); + auto user_args = args->getArgs(); + + auto gui_app = std::make_unique(std::move(args)); + #endif TestCaseRunner::getInstance().setTestApplication(gui_app.get());