Skip to content

Commit

Permalink
Merge pull request #41 from sylvainthery/sylvain
Browse files Browse the repository at this point in the history
Sylvain
  • Loading branch information
sylvainthery authored Apr 13, 2017
2 parents ebf6353 + c20958c commit 50f9405
Show file tree
Hide file tree
Showing 40 changed files with 231 additions and 72 deletions.
26 changes: 16 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,29 @@ option(SCHNAPPS_ALIGNED_VEC3 "Use Eigen's AlignedVector3 by default." OFF)
set(SCHNAPPS_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
set(SCHNAPPS_SOURCE_DIR ${SCHNAPPS_PATH})

#### CGOGN_PATH / CGOGN_SOURCE_DIR
set(CGOGN_PATH "${SCHNAPPS_PATH}/../CGoGN_2" CACHE PATH "CGoGN root dir")
set(CGOGN_BUILD_PATH "${SCHNAPPS_PATH}/../CGoGN_2-build" CACHE PATH "CGoGN build or install dir")
set(SCHNAPPS_EXEC_NAME schnapps)

set(CGOGN_SOURCE_DIR ${CGOGN_PATH})
#### CGOGN_PATH
set(CGOGN_BUILD_OR_INSTALL_PATH "${SCHNAPPS_PATH}/../CGoGN_2-build" CACHE PATH "CGoGN build or install dir")

set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CGOGN_BUILD_PATH})
if (EXISTS "${CGOGN_BUILD_OR_INSTALL_PATH}")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CGOGN_BUILD_OR_INSTALL_PATH})
endif()

#### Build configuration
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
if (APPLE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${SCHNAPPS_EXEC_NAME}.app/Contents/MacOS//lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
endif()

include(${CGOGN_PATH}/cmake/utilities.cmake)

if(MSVC)
add_flags(CMAKE_CXX_FLAGS "/bigobj")
add_compile_options("/bigobj")
endif()

add_subdirectory(${SCHNAPPS_SOURCE_DIR}/schnapps)
19 changes: 17 additions & 2 deletions schnapps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
add_subdirectory(core)
add_subdirectory(plugins)

project(schnapps
project(${SCHNAPPS_EXEC_NAME}
LANGUAGES CXX
)

find_package(Qt5 5.4.0 COMPONENTS Widgets REQUIRED)
find_package(cgogn_core REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE main.cpp)

# with Qt >5.7 & CMake < 3.1 need c++11 option
if(NOT MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC "-std=c++11")
endif(NOT MSVC)

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${cgogn_core_INCLUDE_DIRS}>
)

target_link_libraries(${PROJECT_NAME}
schnapps_core
${Qt5Widgets_LIBRARIES}
)


if (MSVC AND (NOT CMAKE_VERSION VERSION_LESS 3.6))
set_property(DIRECTORY ${SCHNAPPS_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
endif()
4 changes: 2 additions & 2 deletions schnapps/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "_d")
target_include_directories(${PROJECT_NAME} PUBLIC
${QOGLViewer_INCLUDE_DIRS}
$<BUILD_INTERFACE:${SCHNAPPS_SOURCE_DIR}>
$<BUILD_INTERFACE:${CGOGN_SOURCE_DIR}>
$<BUILD_INTERFACE:${cgogn_core_INCLUDE_DIRS}>
${CMAKE_CURRENT_BINARY_DIR}
$<INSTALL_INTERFACE:include/schnapps/core>
)
Expand All @@ -94,7 +94,7 @@ target_link_libraries(${PROJECT_NAME}
if(WIN32)
# copying cgogn's dlls
foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
file(GLOB CGOGN_DLLS "${CGOGN_BUILD_PATH}/bin/${CONFIG}/*.dll")
file(GLOB CGOGN_DLLS "${CGOGN_BUILD_OR_INSTALL_PATH}/bin/${CONFIG}/*.dll")
file(COPY ${CGOGN_DLLS} DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CONFIG}")
endforeach()
# copying Qt's dlls
Expand Down
6 changes: 3 additions & 3 deletions schnapps/core/map_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ class MapHandler : public MapHandlerGen
return res;

const auto& names = cont->names();
res.reserve(names.size());
res.reserve(int32(names.size()));
for (const auto& name : names)
res.push_back(QString::fromStdString(name));
return res;
Expand Down Expand Up @@ -942,8 +942,8 @@ class MapHandler : public MapHandlerGen
};

#ifndef SCHNAPPS_CORE_MAPHANDLER_CPP_
extern template class SCHNAPPS_CORE_API MapHandler<CMap2>;
extern template class SCHNAPPS_CORE_API MapHandler<CMap3>;
template class SCHNAPPS_CORE_API MapHandler<CMap2>;
template class SCHNAPPS_CORE_API MapHandler<CMap3>;
#endif // SCHNAPPS_CORE_MAPHANDLER_CPP_

} // namespace schnapps
Expand Down
46 changes: 41 additions & 5 deletions schnapps/core/schnapps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
namespace schnapps
{

SCHNApps::SCHNApps(const QString& app_path, SCHNAppsWindow* window) :
SCHNApps::SCHNApps(const QString& app_path, const QString& settings_path, SCHNAppsWindow* window) :
app_path_(app_path),
settings_path_(settings_path),
first_view_(nullptr),
selected_view_(nullptr),
window_(window)
Expand All @@ -79,13 +80,15 @@ SCHNApps::SCHNApps(const QString& app_path, SCHNAppsWindow* window) :
set_selected_view(first_view_);
root_splitter_->addWidget(first_view_);

#ifdef WIN32
#if defined (WIN32)
register_plugins_directory(app_path_);
#elif defined (__APPLE__)
register_plugins_directory(app_path_ + QString("/lib"));
#else
register_plugins_directory(app_path_ + QString("/../lib"));
#endif

settings_ = Settings::from_file(app_path_ + QString("/../lib/settings.json"));
settings_ = Settings::from_file(settings_path_);
settings_->set_widget(window->settings_widget_.get());
for (const QVariant& plugin_dir_v : get_core_setting("Plugins paths").toList())
this->register_plugins_directory(plugin_dir_v.toString());
Expand All @@ -95,7 +98,13 @@ SCHNApps::SCHNApps(const QString& app_path, SCHNAppsWindow* window) :

SCHNApps::~SCHNApps()
{
settings_->to_file(app_path_ + QString("/../lib/settings.json"));
// make a copy of overwrite settings
QFile old(settings_path_);
QString copy_name = settings_path_.left(settings_path_.length()-5) + ".back.json";
old.copy(copy_name);

settings_->to_file(settings_path_);

// first safely unload every plugins (this has to be done before the views get deleted)
while (!plugins_.empty())
this->disable_plugin(plugins_.begin()->first);
Expand Down Expand Up @@ -245,14 +254,17 @@ void SCHNApps::disable_plugin(const QString& plugin_name)
(*pi->get_linked_views().begin())->unlink_plugin(pi);
}

// because plugin_name no more valid after unloading
std::string destroyed_name = plugin_name.toStdString();

// call disable() method and dereference plugin
plugin->disable();
plugins_.erase(plugin_name);

QPluginLoader loader(plugin->get_file_path());
loader.unload();

cgogn_log_info("SCHNApps::disable_plugin") << plugin_name.toStdString() << " successfully unloaded.";
cgogn_log_info("SCHNApps::disable_plugin") << destroyed_name << " successfully unloaded.";
emit(plugin_disabled(plugin.get()));
}
}
Expand Down Expand Up @@ -488,6 +500,17 @@ void SCHNApps::set_selected_view(const QString& name)
set_selected_view(v);
}


void SCHNApps::cycle_selected_view()
{
auto it = views_.find(selected_view_->get_name());
it++;
if (it == views_.end())
it = views_.begin();

set_selected_view(it->second.get());
}

View* SCHNApps::split_view(const QString& name, Qt::Orientation orientation)
{
View* new_view = add_view();
Expand Down Expand Up @@ -618,4 +641,17 @@ void SCHNApps::set_window_size(int w, int h)
window_->resize(w, h);
}


/*********************************************************
* EXPORT SETTINGS
*********************************************************/

void SCHNApps::export_settings()
{
QString filename = QFileDialog::getSaveFileName(nullptr, "Export", settings_path_, "Settings Files (*.json)");
if (! filename.isEmpty())
settings_->to_file(filename);

}

} // namespace schnapps
12 changes: 11 additions & 1 deletion schnapps/core/schnapps.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SCHNAPPS_CORE_API SCHNApps : public QObject

public:

SCHNApps(const QString& app_path, SCHNAppsWindow* window);
SCHNApps(const QString& app_path, const QString& settings_path, SCHNAppsWindow* window);
~SCHNApps();

public slots:
Expand Down Expand Up @@ -279,6 +279,11 @@ public slots:

public slots:

/**
* @brief selected view cycle thru the views
*/
void cycle_selected_view();

/**
* @brief get the selected view
*/
Expand Down Expand Up @@ -360,6 +365,10 @@ public slots:
void schnapps_window_closing();
SCHNAppsWindow* get_window() { return window_; }


public slots:
void export_settings();

signals:

void camera_added(Camera*);
Expand Down Expand Up @@ -399,6 +408,7 @@ public slots:
protected:

QString app_path_;
QString settings_path_;

std::unique_ptr<Settings> settings_;
std::unique_ptr<StatusBarOutput> status_bar_output_;
Expand Down
8 changes: 7 additions & 1 deletion schnapps/core/schnapps.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<x>0</x>
<y>0</y>
<width>1106</width>
<height>25</height>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand All @@ -33,6 +33,7 @@
<addaction name="action_TogglePluginDock"/>
<addaction name="separator"/>
<addaction name="action_Settings"/>
<addaction name="action_Export_settings"/>
<addaction name="separator"/>
<addaction name="action_Quit"/>
</widget>
Expand Down Expand Up @@ -76,6 +77,11 @@
<string>Settings</string>
</property>
</action>
<action name="action_Export_settings">
<property name="text">
<string>Export settings</string>
</property>
</action>
</widget>
<resources/>
<connections>
Expand Down
28 changes: 26 additions & 2 deletions schnapps/core/schnapps_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
#include <schnapps/core/schnapps_window.h>
#include <schnapps/core/schnapps.h>
#include <schnapps/core/settings_widget.h>
#include<QKeyEvent>


namespace schnapps
{

SCHNAppsWindow::SCHNAppsWindow(const QString& app_path) :
SCHNAppsWindow::SCHNAppsWindow(const QString& app_path, const QString& settings_path) :
QMainWindow()
{
this->setupUi(this);
Expand Down Expand Up @@ -81,7 +83,9 @@ SCHNAppsWindow::SCHNAppsWindow(const QString& app_path) :
settings_widget_ = cgogn::make_unique<SettingsWidget>();
connect(action_Settings, SIGNAL(triggered()), settings_widget_.get(), SLOT(display_setting_widget()));

schnapps_ = cgogn::make_unique<SCHNApps>(app_path, this);
schnapps_ = cgogn::make_unique<SCHNApps>(app_path, settings_path, this);

connect(action_Export_settings, SIGNAL(triggered()), schnapps_.get(), SLOT(export_settings()));
}

SCHNAppsWindow::~SCHNAppsWindow()
Expand Down Expand Up @@ -186,4 +190,24 @@ void SCHNAppsWindow::closeEvent(QCloseEvent *event)
QMainWindow::closeEvent(event);
}

void SCHNAppsWindow::keyPressEvent(QKeyEvent* event)
{
switch (event->key())
{
case Qt::Key_V:
schnapps_->cycle_selected_view();
break;
case Qt::Key_Escape:
{
QMessageBox msg_box;
msg_box.setText("Really quit SCHNApps ?");
msg_box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msg_box.setDefaultButton(QMessageBox::Ok);
if (msg_box.exec() == QMessageBox::Ok)
schnapps_->close_window();
}
break;
}
}

} // namespace schnapps
4 changes: 3 additions & 1 deletion schnapps/core/schnapps_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SCHNAPPS_CORE_API SCHNAppsWindow : public QMainWindow, public Ui::SCHNApps

public:

SCHNAppsWindow(const QString& app_path);
SCHNAppsWindow(const QString& app_path, const QString& settings_path);
~SCHNAppsWindow();

private slots:
Expand Down Expand Up @@ -97,6 +97,8 @@ private slots:

void closeEvent(QCloseEvent *event);

void keyPressEvent(QKeyEvent* event);

std::unique_ptr<SCHNApps> schnapps_;

QDockWidget* control_dock_;
Expand Down
1 change: 1 addition & 0 deletions schnapps/core/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ SCHNAPPS_CORE_API std::string cell_type_name(CellType ct)
case Face_Cell: return "Face"; break;
case Volume_Cell: return "Volume"; break;
case Unknown: return "UNKNOWN"; break;
default : return "UNKNOWN"; break;
}
#ifdef NDEBUG
return "UNKNOWN"; // little trick to avoid warning on VS
Expand Down
5 changes: 4 additions & 1 deletion schnapps/core/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void View::resizeGL(int width, int height)
QOGLViewer::resizeGL(width, height);

if (button_area_)
button_area_->set_top_right_position(width / this->pixel_ratio(), 0);
button_area_->set_top_right_position(width, 0);

if (button_area_left_)
button_area_left_->set_top_left_position(0, 0);
Expand Down Expand Up @@ -466,6 +466,9 @@ void View::keyPressEvent(QKeyEvent* event)

switch (event->key())
{
case Qt::Key_V:
schnapps_->cycle_selected_view();
break;
case Qt::Key_S:
{
save_snapshots_ = !save_snapshots_;
Expand Down
Loading

0 comments on commit 50f9405

Please sign in to comment.