Skip to content

Commit

Permalink
build and run on osx
Browse files Browse the repository at this point in the history
  • Loading branch information
andryblack committed Aug 17, 2019
1 parent 50208eb commit 23d5f39
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 32 deletions.
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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

23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/block/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>();
}
}
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<std::string>();
}
}
for (const auto &it : components) {
Expand Down
29 changes: 21 additions & 8 deletions src/canvas/canvas_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -131,6 +143,9 @@ bool CanvasGL::on_render(const Glib::RefPtr<Gdk::GLContext> &context)
needs_resize = false;
}

float sf = get_scale_factor();
make_current();

GLint fb;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &fb); // save fb

Expand Down Expand Up @@ -160,9 +175,7 @@ bool CanvasGL::on_render(const Glib::RefPtr<Gdk::GLContext> &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
Expand Down
14 changes: 14 additions & 0 deletions src/canvas/gl_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(glGetString(GL_RENDERER)) << std::endl;
std::cout << "GL_VERSION:\t\t" << reinterpret_cast<const char *>(glGetString(GL_VERSION)) << std::endl;
std::cout << "GL_SHADING_LANGUAGE_VERSION:\t"
<< reinterpret_cast<const char *>(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<const char *>(glGetStringi(GL_EXTENSIONS, i)) << std::endl;
}
}

} // namespace horizon
1 change: 1 addition & 0 deletions src/canvas/gl_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand Down
21 changes: 15 additions & 6 deletions src/canvas/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <glm/gtc/type_ptr.hpp>

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)
{
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -143,7 +152,7 @@ void Grid::render_cursor(Coord<int64_t> &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;
Expand All @@ -154,7 +163,7 @@ void Grid::render_cursor(Coord<int64_t> &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);
Expand Down
4 changes: 4 additions & 0 deletions src/canvas/grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/canvas3d/canvas3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions src/imp/imp_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ int main(int argc, char *argv[])

std::unique_ptr<horizon::ImpBase> 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) {
Expand Down
10 changes: 5 additions & 5 deletions src/pool-prj-mgr/pool-mgr/pool_remote_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>());
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>();
std::string created_at = j.at("created_at").get<std::string>();
descr_label->set_text("opened by " + open_user + " on " + created_at);
}

Expand Down Expand Up @@ -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<std::string>();
git_thread_dispatcher.emit();
}
catch (const std::runtime_error &e) {
Expand Down Expand Up @@ -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<std::string>();
}
catch (...) {
user_email = "[email protected]";
}

try {
user_name = user_info.at("name");
user_name = user_info.at("name").get<std::string>();
}
catch (...) {
user_name = "horizon pool manager";
Expand Down
4 changes: 2 additions & 2 deletions src/pool-prj-mgr/pool-prj-mgr-app_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>();
else
name = k.at("title");
name = k.at("title").get<std::string>();
}
ifs.close();
}
Expand Down
2 changes: 1 addition & 1 deletion src/pool/pool_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>();
default_via = j.at("default_via").get<std::string>();
name = j.at("name");
name = j.at("name").get<std::string>();
if (j.count("pools_included")) {
auto &o = j.at("pools_included");
for (auto &it : o) {
Expand Down
2 changes: 1 addition & 1 deletion src/pool/pool_parametric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>();
digits = j.value("digits", 3);
use_si = j.at("use_si");
no_milli = j.value("no_milli", false);
Expand Down
2 changes: 1 addition & 1 deletion src/schematic/schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>();
}
}
if (j.count("pdf_export_settings")) {
Expand Down
2 changes: 1 addition & 1 deletion src/schematic/sheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>();
}
}
}
Expand Down

0 comments on commit 23d5f39

Please sign in to comment.