From 23d5f394619f093e2196b430a5e339312c97d039 Mon Sep 17 00:00:00 2001 From: andryblack Date: Sat, 17 Aug 2019 15:48:05 +0300 Subject: [PATCH] build and run on osx --- .travis.yml | 30 +++++++++++++++++++ Makefile | 23 ++++++++++---- src/block/block.cpp | 4 +-- src/canvas/canvas_gl.cpp | 29 +++++++++++++----- src/canvas/gl_util.cpp | 14 +++++++++ src/canvas/gl_util.hpp | 1 + src/canvas/grid.cpp | 21 +++++++++---- src/canvas/grid.hpp | 4 +++ src/canvas3d/canvas3d.cpp | 4 +++ src/imp/imp_main.cpp | 4 +++ src/pool-prj-mgr/pool-mgr/pool_remote_box.cpp | 10 +++---- src/pool-prj-mgr/pool-prj-mgr-app_win.cpp | 4 +-- src/pool/pool_manager.cpp | 2 +- src/pool/pool_parametric.cpp | 2 +- src/schematic/schematic.cpp | 2 +- src/schematic/sheet.cpp | 2 +- 16 files changed, 124 insertions(+), 32 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..d30cb3860 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,30 @@ +language: cpp + +compiler: + - clang + +osx_image: + - xcode11 + +os: + - osx + +addons: + homebrew: + packages: + - pkg-config + - gtkmm3 + - gobject-introspection + - opencascade + - libzip + - yaml-cpp + - osrf/homebrew-simulation/cppzmq + - podofo + - boost + - librsvg + - glm + - libffi + - libgit2 + +script: PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH" make -j2 + diff --git a/Makefile b/Makefile index d7c996bee..fe2bdfddb 100644 --- a/Makefile +++ b/Makefile @@ -573,9 +573,10 @@ ifneq ($(OS),Windows_NT) endif LIBS_ALL = $(LIBS_COMMON) gtkmm-3.0 epoxy cairomm-pdf-1.0 librsvg-2.0 libzmq libgit2 libcurl glm -OPTIMIZE=-fdata-sections -ffunction-sections +OPTIMIZE=-fdata-sections -ffunction-sections -O3 +#OPTIMIZE=-fdata-sections -ffunction-sections DEBUG =-g3 -CXXFLAGS =$(DEBUG) $(DEFINES) $(OPTIMIZE) $(shell $(PKGCONFIG) --cflags $(LIBS_ALL)) -MP -MMD -pthread -Wall -Wshadow -std=c++14 -O3 +CXXFLAGS =$(DEBUG) $(DEFINES) $(OPTIMIZE) $(shell $(PKGCONFIG) --cflags $(LIBS_ALL)) -MP -MMD -pthread -Wall -Wshadow -std=c++14 CFLAGS = $(filter-out -std=%,$(CXXFLAGS)) -std=c99 LDFLAGS = -lm -lpthread GLIB_COMPILE_RESOURCES = $(shell $(PKGCONFIG) --variable=glib_compile_resources gio-2.0) @@ -587,7 +588,17 @@ ifeq ($(OS),Windows_NT) else UNAME := $(shell uname) ifeq ($(UNAME), Darwin) - # do nothing on mac os + # O3 generate incompatibel frames? + OPTIMIZE=-fdata-sections -ffunction-sections -O2 + # support brew on non-standart location + BREWROOT ?= $(shell brew --prefix) + INC += -I$(BREWROOT)/include + INC_OCE = -I$(BREWROOT)/include/opencascade + LDFLAGS_OCE = -L$(BREWROOT)/lib/ -lTKSTEP -lTKernel -lTKXCAF -lTKXSBase -lTKBRep -lTKCDF -lTKXDESTEP -lTKLCAF -lTKMath -lTKMesh -lTKTopAlgo -lTKPrim -lTKBO -lTKG3d + CFLAGS += -mmacosx-version-min=10.12 + CXXFLAGS += -mmacosx-version-min=10.12 + LDFLAGS += -mmacosx-version-min=10.12 $(DEBUG) + # osrf/homebrew-simulation/cppzmq, podofo else LDFLAGS += -fuse-ld=gold endif @@ -630,7 +641,9 @@ OBJDIR = $(BUILDDIR)/obj PICOBJDIR = $(BUILDDIR)/picobj GENDIR = $(BUILDDIR)/gen MKDIR = mkdir -p +ifneq ($(VERBOSE),1) QUIET = @ +endif ECHO = @echo # Object files @@ -655,9 +668,9 @@ OBJ_GEN_PKG = $(addprefix $(OBJDIR)/,$(SRC_GEN_PKG:.cpp=.o)) INC_ROUTER = -I3rd_party/router/include/ -I3rd_party/router -I3rd_party -INC_OCE = -I/opt/opencascade/inc/ -I/mingw64/include/oce/ -I/usr/include/oce -I/usr/include/opencascade -I${CASROOT}/include/opencascade -I/usr/local/include/OpenCASCADE +INC_OCE ?= -I/opt/opencascade/inc/ -I/mingw64/include/oce/ -I/usr/include/oce -I/usr/include/opencascade -I${CASROOT}/include/opencascade -I/usr/local/include/OpenCASCADE INC_PYTHON = $(shell $(PKGCONFIG) --cflags python3) -LDFLAGS_OCE = -L /opt/opencascade/lib/ -L${CASROOT}/lib -lTKSTEP -lTKernel -lTKXCAF -lTKXSBase -lTKBRep -lTKCDF -lTKXDESTEP -lTKLCAF -lTKMath -lTKMesh -lTKTopAlgo -lTKPrim -lTKBO -lTKG3d +LDFLAGS_OCE ?= -L /opt/opencascade/lib/ -L${CASROOT}/lib -lTKSTEP -lTKernel -lTKXCAF -lTKXSBase -lTKBRep -lTKCDF -lTKXDESTEP -lTKLCAF -lTKMath -lTKMesh -lTKTopAlgo -lTKPrim -lTKBO -lTKG3d ifeq ($(OS),Windows_NT) LDFLAGS_OCE += -lTKV3d endif diff --git a/src/block/block.cpp b/src/block/block.cpp index eb36449cd..518a59083 100644 --- a/src/block/block.cpp +++ b/src/block/block.cpp @@ -57,14 +57,14 @@ Block::Block(const UUID &uu, const json &j, Pool &pool) : uuid(uu), name(j.at("n const json &o = j["group_names"]; for (auto it = o.cbegin(); it != o.cend(); ++it) { auto u = UUID(it.key()); - group_names[u] = it.value(); + group_names[u] = it.value().get(); } } if (j.count("tag_names")) { const json &o = j["tag_names"]; for (auto it = o.cbegin(); it != o.cend(); ++it) { auto u = UUID(it.key()); - tag_names[u] = it.value(); + tag_names[u] = it.value().get(); } } for (const auto &it : components) { diff --git a/src/canvas/canvas_gl.cpp b/src/canvas/canvas_gl.cpp index 6428fcd04..f3e59a9a0 100644 --- a/src/canvas/canvas_gl.cpp +++ b/src/canvas/canvas_gl.cpp @@ -33,6 +33,7 @@ CanvasGL::CanvasGL() height = 500; set_can_focus(true); + set_required_version(4, 2); property_work_layer().signal_changed().connect([this] { work_layer = property_work_layer(); request_push(); @@ -64,22 +65,33 @@ void CanvasGL::on_size_allocate(Gtk::Allocation &alloc) void CanvasGL::resize_buffers() { - GLint rb; + float sf = get_scale_factor(); + make_current(); + GLint samples = gl_clamp_samples(appearance.msaa); + +#ifdef __APPLE__ + samples = 0; // glBlitFramebuffer dnt support multisample->single sample blit +#endif + + GLint rb; glGetIntegerv(GL_RENDERBUFFER_BINDING, &rb); // save rb + glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); - glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGBA8, width * get_scale_factor(), - height * get_scale_factor()); + glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGBA8, width * sf, height * sf); glBindRenderbuffer(GL_RENDERBUFFER, stencilrenderbuffer); - glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_DEPTH24_STENCIL8, width * get_scale_factor(), - height * get_scale_factor()); + glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_DEPTH24_STENCIL8, width * sf, height * sf); + glBindRenderbuffer(GL_RENDERBUFFER, rb); + grid.set_scale_factor(sf); } void CanvasGL::on_realize() { Gtk::GLArea::on_realize(); make_current(); + gl_log_info(); + GL_CHECK_ERROR grid.realize(); GL_CHECK_ERROR @@ -131,6 +143,9 @@ bool CanvasGL::on_render(const Glib::RefPtr &context) needs_resize = false; } + float sf = get_scale_factor(); + make_current(); + GLint fb; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb); // save fb @@ -160,9 +175,7 @@ bool CanvasGL::on_render(const Glib::RefPtr &context) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb); glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - glBlitFramebuffer(0, 0, width * get_scale_factor(), height * get_scale_factor(), 0, 0, width * get_scale_factor(), - height * get_scale_factor(), GL_COLOR_BUFFER_BIT, GL_NEAREST); - + glBlitFramebuffer(0, 0, width * sf, height * sf, 0, 0, width * sf, height * sf, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBindFramebuffer(GL_FRAMEBUFFER, fb); GL_CHECK_ERROR diff --git a/src/canvas/gl_util.cpp b/src/canvas/gl_util.cpp index 2c3b7de44..a6b118d79 100644 --- a/src/canvas/gl_util.cpp +++ b/src/canvas/gl_util.cpp @@ -169,5 +169,19 @@ GLint gl_clamp_samples(GLint samples_req) return samples; } +void gl_log_info() +{ + + std::cout << "GL_RENDERER:\t\t" << reinterpret_cast(glGetString(GL_RENDERER)) << std::endl; + std::cout << "GL_VERSION:\t\t" << reinterpret_cast(glGetString(GL_VERSION)) << std::endl; + std::cout << "GL_SHADING_LANGUAGE_VERSION:\t" + << reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION)) << std::endl; + std::cout << "GL_EXTENSIONS:" << std::endl; + GLint num_extensions = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions); + for (GLint i = 0; i < num_extensions; ++i) { + std::cout << "\t" << reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)) << std::endl; + } +} } // namespace horizon diff --git a/src/canvas/gl_util.hpp b/src/canvas/gl_util.hpp index 7b9edd00c..fd79f69dc 100644 --- a/src/canvas/gl_util.hpp +++ b/src/canvas/gl_util.hpp @@ -11,6 +11,7 @@ void gl_show_error(const std::string &s); void gl_color_to_uniform_3f(GLuint loc, const class Color &c); void gl_color_to_uniform_4f(GLuint loc, const class Color &c, float alpha = 1); GLint gl_clamp_samples(GLint samples); +void gl_log_info(); #define GET_LOC(d, loc) \ do { \ diff --git a/src/canvas/grid.cpp b/src/canvas/grid.cpp index daa7c6e91..4c66a0a08 100644 --- a/src/canvas/grid.cpp +++ b/src/canvas/grid.cpp @@ -4,7 +4,7 @@ #include namespace horizon { -Grid::Grid(class CanvasGL *c) : ca(c), spacing(1.25_mm), mark_size(5) +Grid::Grid(class CanvasGL *c) : ca(c), spacing(1.25_mm), mark_size(5), grid_line_width(1.0f), cursor_line_width(4.0f) { } @@ -56,6 +56,16 @@ void Grid::realize() GET_LOC(this, color); } +void Grid::set_scale_factor(float sf) +{ + GLfloat max_width = 1.0f; + glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, &max_width); + GL_CHECK_ERROR + + grid_line_width = std::max(std::min(1 * sf, max_width), 1.0f); + cursor_line_width = std::max(std::min(4 * sf, max_width), 1.0f); +} + void Grid::render() { glUseProgram(program); @@ -88,8 +98,7 @@ void Grid::render() glUniform1f(grid_size_loc, sp); glUniform2f(grid_0_loc, grid_0.x, grid_0.y); - - glLineWidth(1 * ca->get_scale_factor()); + glLineWidth(grid_line_width); if (mark_size > 100) { glUniform1f(mark_size_loc, ca->height * 2); int n = (ca->width / ca->scale) / sp + 4; @@ -119,7 +128,7 @@ void Grid::render() auto origin_color = ca->get_color(ColorP::ORIGIN); gl_color_to_uniform_4f(color_loc, origin_color); - glLineWidth(1 * ca->get_scale_factor()); + glLineWidth(grid_line_width); glDrawArraysInstanced(GL_LINES, 0, 4, 1); glBindVertexArray(0); @@ -143,7 +152,7 @@ void Grid::render_cursor(Coord &coord) auto bgcolor = ca->get_color(ColorP::BACKGROUND); glUniform4f(color_loc, bgcolor.r, bgcolor.g, bgcolor.b, 1); - glLineWidth(4 * ca->get_scale_factor()); + glLineWidth(cursor_line_width); glDrawArrays(GL_LINES, 0, 12); Color cursor_color; @@ -154,7 +163,7 @@ void Grid::render_cursor(Coord &coord) cursor_color = ca->get_color(ColorP::CURSOR_NORMAL); } glUniform4f(color_loc, cursor_color.r, cursor_color.g, cursor_color.b, 1); - glLineWidth(1 * ca->get_scale_factor()); + glLineWidth(grid_line_width); glDrawArrays(GL_LINES, 0, 12); glBindVertexArray(0); diff --git a/src/canvas/grid.hpp b/src/canvas/grid.hpp index 36a5b5914..064327ecc 100644 --- a/src/canvas/grid.hpp +++ b/src/canvas/grid.hpp @@ -31,5 +31,9 @@ class Grid { GLuint grid_mod_loc; GLuint mark_size_loc; GLuint color_loc; + + GLfloat grid_line_width; + GLfloat cursor_line_width; + void set_scale_factor(float sf); }; } // namespace horizon diff --git a/src/canvas3d/canvas3d.cpp b/src/canvas3d/canvas3d.cpp index 9d8439a95..5c2b40af9 100644 --- a/src/canvas3d/canvas3d.cpp +++ b/src/canvas3d/canvas3d.cpp @@ -24,6 +24,7 @@ Canvas3D::Canvas3D() : Gtk::GLArea(), CanvasPatch::CanvasPatch(), cover_renderer(this), wall_renderer(this), face_renderer(this), background_renderer(this), center(0) { + set_required_version(4, 2); add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON_MOTION_MASK | Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK); @@ -233,6 +234,9 @@ void Canvas3D::resize_buffers() { GLint rb; GLint samples = gl_clamp_samples(num_samples); +#ifdef __APPLE__ + samples = 0; +#endif glGetIntegerv(GL_RENDERBUFFER_BINDING, &rb); // save rb glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGBA8, width * get_scale_factor(), diff --git a/src/imp/imp_main.cpp b/src/imp/imp_main.cpp index ba98876ff..ccea87073 100644 --- a/src/imp/imp_main.cpp +++ b/src/imp/imp_main.cpp @@ -109,6 +109,10 @@ int main(int argc, char *argv[]) std::unique_ptr imp = nullptr; if (mode_sch) { + if (filenames.size() < 2) { + std::cout << "wrong arguments number" << std::endl; + return 1; + } imp.reset(new horizon::ImpSchematic(filenames.at(0), filenames.at(1), {pool_base_path, pool_cache_path})); } else if (mode_symbol) { diff --git a/src/pool-prj-mgr/pool-mgr/pool_remote_box.cpp b/src/pool-prj-mgr/pool-mgr/pool_remote_box.cpp index 5fa274d41..3da6c5b75 100644 --- a/src/pool-prj-mgr/pool-mgr/pool_remote_box.cpp +++ b/src/pool-prj-mgr/pool-mgr/pool_remote_box.cpp @@ -290,8 +290,8 @@ PullRequestItemBox::PullRequestItemBox(BaseObjectType *cobject, const Glib::RefP number_label->set_text("#" + std::to_string(nr)); link_button->set_label("Open on GitHub"); link_button->set_uri(j.at("_links").at("html").at("href").get()); - std::string open_user = j.at("user").at("login"); - std::string created_at = j.at("created_at"); + std::string open_user = j.at("user").at("login").get(); + std::string created_at = j.at("created_at").get(); descr_label->set_text("opened by " + open_user + " on " + created_at); } @@ -711,7 +711,7 @@ void PoolRemoteBox::create_pr_thread() json user_info; try { user_info = client.login(gh_username, gh_password); - gh_username = user_info.at("login"); + gh_username = user_info.at("login").get(); git_thread_dispatcher.emit(); } catch (const std::runtime_error &e) { @@ -747,14 +747,14 @@ void PoolRemoteBox::create_pr_thread() std::string user_name; std::cout << std::setw(4) << user_info << std::endl; try { - user_email = user_info.at("email"); + user_email = user_info.at("email").get(); } catch (...) { user_email = "horizon@0x83.eu"; } try { - user_name = user_info.at("name"); + user_name = user_info.at("name").get(); } catch (...) { user_name = "horizon pool manager"; diff --git a/src/pool-prj-mgr/pool-prj-mgr-app_win.cpp b/src/pool-prj-mgr/pool-prj-mgr-app_win.cpp index 3a2cd8ef9..14dad3f27 100644 --- a/src/pool-prj-mgr/pool-prj-mgr-app_win.cpp +++ b/src/pool-prj-mgr/pool-prj-mgr-app_win.cpp @@ -550,9 +550,9 @@ void PoolProjectManagerAppWindow::update_recent_items() json k; ifs >> k; if (endswith(path, "pool.json")) - name = k.at("name"); + name = k.at("name").get(); else - name = k.at("title"); + name = k.at("title").get(); } ifs.close(); } diff --git a/src/pool/pool_manager.cpp b/src/pool/pool_manager.cpp index da58623ff..b6f8a786a 100644 --- a/src/pool/pool_manager.cpp +++ b/src/pool/pool_manager.cpp @@ -27,7 +27,7 @@ PoolManagerPool::PoolManagerPool(const std::string &bp) : base_path(bp) auto j = load_json_from_file(pool_json); uuid = j.at("uuid").get(); default_via = j.at("default_via").get(); - name = j.at("name"); + name = j.at("name").get(); if (j.count("pools_included")) { auto &o = j.at("pools_included"); for (auto &it : o) { diff --git a/src/pool/pool_parametric.cpp b/src/pool/pool_parametric.cpp index f664752a4..6c8d072d6 100644 --- a/src/pool/pool_parametric.cpp +++ b/src/pool/pool_parametric.cpp @@ -94,7 +94,7 @@ PoolParametric::Column::Column(const json &j) type(type_lut.lookup(j.at("type"))), required(j.value("required", true)) { if (type == Type::QUANTITY) { - unit = j.at("unit"); + unit = j.at("unit").get(); digits = j.value("digits", 3); use_si = j.at("use_si"); no_milli = j.value("no_milli", false); diff --git a/src/schematic/schematic.cpp b/src/schematic/schematic.cpp index c10aca47d..96a7256d8 100644 --- a/src/schematic/schematic.cpp +++ b/src/schematic/schematic.cpp @@ -62,7 +62,7 @@ Schematic::Schematic(const UUID &uu, const json &j, Block &iblock, Pool &pool) if (j.count("title_block_values")) { const json &o = j["title_block_values"]; for (auto it = o.cbegin(); it != o.cend(); ++it) { - title_block_values[it.key()] = it.value(); + title_block_values[it.key()] = it.value().get(); } } if (j.count("pdf_export_settings")) { diff --git a/src/schematic/sheet.cpp b/src/schematic/sheet.cpp index 8be48edf5..d917b869a 100644 --- a/src/schematic/sheet.cpp +++ b/src/schematic/sheet.cpp @@ -100,7 +100,7 @@ Sheet::Sheet(const UUID &uu, const json &j, Block &block, Pool &pool) if (j.count("title_block_values")) { const json &o = j["title_block_values"]; for (auto it = o.cbegin(); it != o.cend(); ++it) { - title_block_values[it.key()] = it.value(); + title_block_values[it.key()] = it.value().get(); } } }