Commit b17bcd59 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

plugin interface

parent bd792845
/**
* tlibs2
* helpers
* @author Tobias Weber <tweber@ill.fr>
* @date Jan-2019
* @license GPLv3, see 'LICENSE' file
*/
#ifndef __TL2_HELPERS_H__
#define __TL2_HELPERS_H__
#include <QtCore/QLocale>
#include <locale>
namespace tl2 {
static inline void set_locales()
{
std::ios_base::sync_with_stdio(false);
::setlocale(LC_ALL, "C");
std::locale::global(std::locale("C"));
QLocale::setDefault(QLocale::C);
}
}
#endif
......@@ -5,21 +5,16 @@
* @license see 'LICENSE' file
*/
#include <locale>
#include <iostream>
#include <QtWidgets/QApplication>
#include "libs/helper.h"
#include "mainwnd.h"
int main(int argc, char** argv)
{
std::ios_base::sync_with_stdio(false);
setlocale(LC_ALL, "C");
std::locale::global(std::locale("C"));
QLocale::setDefault(QLocale::C);
tl2::set_locales();
QApplication app(argc, argv);
QSettings sett("tobis_stuff", "in20tool");
......
......@@ -9,7 +9,7 @@ project(pol)
cmake_minimum_required(VERSION 3.0)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
set(BUILD_LIB FALSE)
set(BUILD_LIB TRUE)
find_package(Boost REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets OpenGL)
......
......@@ -20,6 +20,7 @@
#include "../glplot/glplot.h"
#include "libs/_cxx20/math_algos.h"
#include "libs/helper.h"
#include <boost/version.hpp>
#include <boost/config.hpp>
......@@ -512,23 +513,13 @@ public:
// ----------------------------------------------------------------------------
static inline void set_locales()
{
std::ios_base::sync_with_stdio(false);
::setlocale(LC_ALL, "C");
std::locale::global(std::locale("C"));
QLocale::setDefault(QLocale::C);
}
#ifndef BUILD_LIB // build application
int main(int argc, char** argv)
{
set_gl_format(1, _GL_MAJ_VER, _GL_MIN_VER, 8);
set_locales();
tl2::set_locales();
auto app = std::make_unique<QApplication>(argc, argv);
auto dlg = std::make_unique<PolDlg>(nullptr);
......@@ -544,15 +535,31 @@ int main(int argc, char** argv)
#include <boost/dll/alias.hpp>
/**
* initialise plugin
*/
bool init()
{
set_gl_format(1, _GL_MAJ_VER, _GL_MIN_VER, 8);
set_locales();
tl2::set_locales();
return true;
}
/**
* plugin descriptor
* type, title, description
*/
std::tuple<std::string, std::string, std::string> descr()
{
return std::make_tuple("dlg", "Polarisation Vectors", "Calculates polarisation vectors.");
}
/**
* create the plugin main dialog
*/
std::shared_ptr<QDialog> create(QWidget *pParent)
{
//std::cout << "In " << __FUNCTION__ << std::endl;
......@@ -561,6 +568,7 @@ std::shared_ptr<QDialog> create(QWidget *pParent)
BOOST_DLL_ALIAS(init, tl_init);
BOOST_DLL_ALIAS(descr, tl_descr);
BOOST_DLL_ALIAS(create, tl_create);
......
......@@ -4,7 +4,7 @@
* @date Nov-2018
* @license GPLv3, see 'LICENSE' file
*
* g++-8 -std=c++17 -I/usr/local/include -L/usr/local/lib -o runplugin runplugin.cpp -F/usr/local/opt/qt5/lib -framework QtCore -framework QtWidgets -lboost_filesystem -lboost_system
* clang++ -std=c++17 -I/usr/local/include -L/usr/local/lib -I../.. -o runplugin runplugin.cpp -F/usr/local/opt/qt5/lib -framework QtCore -framework QtWidgets -lboost_filesystem -lboost_system
* g++ -std=c++17 -I/usr/local/include -I/usr/include/qt5 -L/usr/local/lib -fPIC -o runplugin runplugin.cpp -lQt5Core -lQt5Widgets -lboost_filesystem -lboost_system -ldl
*/
......@@ -13,21 +13,12 @@
#include <iostream>
#include <memory>
#include <boost/dll/shared_library.hpp>
static inline void set_locales()
{
std::ios_base::sync_with_stdio(false);
::setlocale(LC_ALL, "C");
std::locale::global(std::locale("C"));
QLocale::setDefault(QLocale::C);
}
#include "libs/helper.h"
int main(int argc, char** argv)
{
set_locales();
tl2::set_locales();
if(argc <= 1)
{
......@@ -57,6 +48,7 @@ int main(int argc, char** argv)
auto app = std::make_unique<QApplication>(argc, argv);
//if(auto createDlg = dll->get<QDialog*(*)(QWidget*)>("tl_create"); createDlg)
if(auto createDlg = dll->get<std::shared_ptr<QDialog>(*)(QWidget*)>("tl_create"); createDlg)
{
if(auto dlg = createDlg(nullptr); dlg)
......
......@@ -7,6 +7,9 @@
project(structfact)
cmake_minimum_required(VERSION 3.0)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
set(BUILD_LIB TRUE)
find_package(Boost REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets OpenGL)
......@@ -19,8 +22,18 @@ add_definitions(${Boost_CXX_FLAGS})
include_directories("${PROJECT_SOURCE_DIR}" "${Boost_INCLUDE_DIRS}/.." "../..")
add_executable(structfact
if(BUILD_LIB)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
add_definitions(-DBUILD_LIB)
add_library(structfact SHARED
structfact.cpp structfact.h
../glplot/glplot.cpp ../glplot/glplot.h)
else()
add_executable(structfact
structfact.cpp structfact.h
../glplot/glplot.cpp ../glplot/glplot.h)
endif()
target_link_libraries(structfact ${Boost_LIBRARIES})
qt5_use_modules(structfact Core Gui Widgets OpenGL)
......@@ -17,7 +17,6 @@
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QMessageBox>
#include <locale>
#include <iostream>
#include <fstream>
......@@ -30,6 +29,7 @@ namespace algo = boost::algorithm;
namespace pt = boost::property_tree;
#include "libs/algos.h"
#include "libs/helper.h"
#include "libs/_cxx20/math_algos.h"
//using namespace m;
using namespace m_ops;
......@@ -1094,21 +1094,15 @@ void StructFactDlg::closeEvent(QCloseEvent *evt)
// ----------------------------------------------------------------------------
static inline void set_locales()
{
std::ios_base::sync_with_stdio(false);
::setlocale(LC_ALL, "C");
std::locale::global(std::locale("C"));
QLocale::setDefault(QLocale::C);
}
// ----------------------------------------------------------------------------
#ifndef BUILD_LIB // build application
int main(int argc, char** argv)
{
set_gl_format(1, _GL_MAJ_VER, _GL_MIN_VER, 8);
set_locales();
tl2::set_locales();
auto app = std::make_unique<QApplication>(argc, argv);
auto dlg = std::make_unique<StructFactDlg>(nullptr);
......@@ -1116,4 +1110,52 @@ int main(int argc, char** argv)
return app->exec();
}
#else // build library
#include <boost/dll/alias.hpp>
/**
* initialise plugin
*/
bool init()
{
set_gl_format(1, _GL_MAJ_VER, _GL_MIN_VER, 8);
tl2::set_locales();
return true;
}
/**
* plugin descriptor
* type, title, description
*/
std::tuple<std::string, std::string, std::string> descr()
{
return std::make_tuple("dlg", "Structure Factors", "Calculates nuclear structure factors.");
}
/**
* create the plugin main dialog
*/
std::shared_ptr<QDialog> create(QWidget *pParent)
//QDialog* create(QWidget *pParent)
{
//std::cout << "In " << __FUNCTION__ << std::endl;
return std::make_shared<StructFactDlg>(pParent);
//return new StructFactDlg(pParent);
}
BOOST_DLL_ALIAS(init, tl_init);
BOOST_DLL_ALIAS(descr, tl_descr);
BOOST_DLL_ALIAS(create, tl_create);
#endif
// ----------------------------------------------------------------------------
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment